@@ -268,37 +268,17 @@ class alignas(8) Decl {
268
268
// / }
269
269
// / void A::f(); // SemanticDC == namespace 'A'
270
270
// / // LexicalDC == global namespace
271
+ llvm::PointerUnion<DeclContext*, MultipleDC*> DeclCtx;
271
272
272
- // Compress the InvalidDecl and HasAttrs bits into DeclCtx to keep Decl below
273
- // 32 bytes in size
274
- llvm::PointerIntPair<
275
- llvm::PointerIntPair<llvm::PointerUnion<DeclContext *, MultipleDC *>, 1 ,
276
- bool >,
277
- 1 , bool >
278
- DeclCtxWithInvalidDeclAndHasAttrs;
279
-
280
- bool isInSemaDC () const {
281
- return DeclCtxWithInvalidDeclAndHasAttrs.getPointer ()
282
- .getPointer ()
283
- .is <DeclContext *>();
284
- }
285
-
286
- bool isOutOfSemaDC () const {
287
- return DeclCtxWithInvalidDeclAndHasAttrs.getPointer ()
288
- .getPointer ()
289
- .is <MultipleDC *>();
290
- }
273
+ bool isInSemaDC () const { return DeclCtx.is <DeclContext*>(); }
274
+ bool isOutOfSemaDC () const { return DeclCtx.is <MultipleDC*>(); }
291
275
292
276
MultipleDC *getMultipleDC () const {
293
- return DeclCtxWithInvalidDeclAndHasAttrs.getPointer ()
294
- .getPointer ()
295
- .get <MultipleDC *>();
277
+ return DeclCtx.get <MultipleDC*>();
296
278
}
297
279
298
280
DeclContext *getSemanticDC () const {
299
- return DeclCtxWithInvalidDeclAndHasAttrs.getPointer ()
300
- .getPointer ()
301
- .get <DeclContext *>();
281
+ return DeclCtx.get <DeclContext*>();
302
282
}
303
283
304
284
// / Loc - The location of this decl.
@@ -308,6 +288,14 @@ class alignas(8) Decl {
308
288
LLVM_PREFERRED_TYPE (Kind)
309
289
unsigned DeclKind : 7 ;
310
290
291
+ // / InvalidDecl - This indicates a semantic error occurred.
292
+ LLVM_PREFERRED_TYPE (bool )
293
+ unsigned InvalidDecl : 1 ;
294
+
295
+ // / HasAttrs - This indicates whether the decl has attributes or not.
296
+ LLVM_PREFERRED_TYPE (bool )
297
+ unsigned HasAttrs : 1 ;
298
+
311
299
// / Implicit - Whether this declaration was implicitly generated by
312
300
// / the implementation rather than explicitly written by the user.
313
301
LLVM_PREFERRED_TYPE (bool )
@@ -405,22 +393,21 @@ class alignas(8) Decl {
405
393
protected:
406
394
Decl (Kind DK, DeclContext *DC, SourceLocation L)
407
395
: NextInContextAndBits (nullptr , getModuleOwnershipKindForChildOf (DC)),
408
- DeclCtxWithInvalidDeclAndHasAttrs ({DC, false }, false ), Loc (L ),
409
- DeclKind (DK), Implicit (false ), Used (false ), Referenced (false ),
396
+ DeclCtx (DC), Loc (L), DeclKind (DK), InvalidDecl ( false ), HasAttrs ( false ),
397
+ Implicit (false ), Used (false ), Referenced (false ),
410
398
TopLevelDeclInObjCContainer (false ), Access (AS_none), FromASTFile (0 ),
411
399
IdentifierNamespace (getIdentifierNamespaceForKind (DK)),
412
400
CacheValidAndLinkage (llvm::to_underlying (Linkage::Invalid)) {
413
- if (StatisticsEnabled)
414
- add (DK);
401
+ if (StatisticsEnabled) add (DK);
415
402
}
416
403
417
404
Decl (Kind DK, EmptyShell Empty)
418
- : DeclKind (DK), Implicit (false ), Used (false ), Referenced (false ),
419
- TopLevelDeclInObjCContainer (false ), Access (AS_none), FromASTFile (0 ),
405
+ : DeclKind (DK), InvalidDecl (false ), HasAttrs (false ), Implicit (false ),
406
+ Used (false ), Referenced (false ), TopLevelDeclInObjCContainer (false ),
407
+ Access (AS_none), FromASTFile (0 ),
420
408
IdentifierNamespace (getIdentifierNamespaceForKind (DK)),
421
409
CacheValidAndLinkage (llvm::to_underlying (Linkage::Invalid)) {
422
- if (StatisticsEnabled)
423
- add (DK);
410
+ if (StatisticsEnabled) add (DK);
424
411
}
425
412
426
413
virtual ~Decl ();
@@ -533,9 +520,7 @@ class alignas(8) Decl {
533
520
return AccessSpecifier (Access);
534
521
}
535
522
536
- bool hasAttrs () const {
537
- return DeclCtxWithInvalidDeclAndHasAttrs.getPointer ().getInt ();
538
- }
523
+ bool hasAttrs () const { return HasAttrs; }
539
524
540
525
void setAttrs (const AttrVec& Attrs) {
541
526
return setAttrsImpl (Attrs, getASTContext ());
@@ -564,17 +549,13 @@ class alignas(8) Decl {
564
549
}
565
550
566
551
template <typename ... Ts> void dropAttrs () {
567
- if (!hasAttrs ())
568
- return ;
552
+ if (!HasAttrs) return ;
569
553
570
554
AttrVec &Vec = getAttrs ();
571
555
llvm::erase_if (Vec, [](Attr *A) { return isa<Ts...>(A); });
572
556
573
- if (Vec.empty ()) {
574
- auto InnerPtr = DeclCtxWithInvalidDeclAndHasAttrs.getPointer ();
575
- InnerPtr.setInt (false );
576
- DeclCtxWithInvalidDeclAndHasAttrs.setPointer (InnerPtr);
577
- }
557
+ if (Vec.empty ())
558
+ HasAttrs = false ;
578
559
}
579
560
580
561
template <typename T> void dropAttr () { dropAttrs<T>(); }
@@ -609,10 +590,7 @@ class alignas(8) Decl {
609
590
// / setInvalidDecl - Indicates the Decl had a semantic error. This
610
591
// / allows for graceful error recovery.
611
592
void setInvalidDecl (bool Invalid = true );
612
-
613
- bool isInvalidDecl () const {
614
- return DeclCtxWithInvalidDeclAndHasAttrs.getInt ();
615
- }
593
+ bool isInvalidDecl () const { return (bool ) InvalidDecl; }
616
594
617
595
// / isImplicit - Indicates whether the declaration was implicitly
618
596
// / generated by the implementation. If false, this declaration
0 commit comments