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