[clang] [llvm] [Clang][AST][NFCI] Make Decl reference attributes directly (PR #219138)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 27 08:18:44 PDT 2026
erichkeane wrote:
> FYI, Erich and I dumped the layout.
>
> ```
> *** Dumping AST Record Layout
> 0 | class clang::Decl
> 0 | (Decl vtable pointer)
> 8 | class llvm::PointerIntPair<class clang::Decl *, 3, enum clang::Decl::ModuleOwnershipKind> NextInContextAndBits
> 8 | struct llvm::detail::PunnedPointer<class clang::Decl *> Value
> 8 | unsigned char[8] Data
> 16 | class llvm::PointerUnion<class clang::DeclContext *, struct clang::Decl::MultipleDC *> DeclCtx
> 16 | class llvm::pointer_union_detail::PointerUnionMembers<class llvm::PointerUnion<class clang::DeclContext *, struct clang::Decl::MultipleDC *>, 0, class clang::DeclContext *, struct clang::Decl::MultipleDC *> (base)
> 16 | class llvm::pointer_union_detail::PointerUnionMembers<class llvm::PointerUnion<class clang::DeclContext *, struct clang::Decl::MultipleDC *>, 1, struct clang::Decl::MultipleDC *> (base)
> 16 | class llvm::pointer_union_detail::PointerUnionMembers<class llvm::PointerUnion<class clang::DeclContext *, struct clang::Decl::MultipleDC *>, 2> (base)
> 16 | struct llvm::detail::PunnedPointer<void *> Val
> 16 | unsigned char[8] Data
> 24 | class clang::SourceLocation Loc
> 24 | UIntTy ID
> 28:0-6 | unsigned int DeclKind
> 28:7-7 | unsigned int InvalidDecl
> 29:0-0 | unsigned int HasAttrs
> 29:1-1 | unsigned int Implicit
> 29:2-2 | unsigned int Used
> 29:3-3 | unsigned int Referenced
> 29:4-4 | unsigned int TopLevelDeclInObjCContainer
> 29:5-6 | unsigned int Access
> 29:7-7 | unsigned int FromASTFile
> 30:0-13 | unsigned int IdentifierNamespace
> 32:0-2 | unsigned int CacheValidAndLinkage
> | [sizeof=40, dsize=33, align=8,
> | nvsize=33, nvalign=8]
> ```
>
> Based on that, the change probably makes sense. We should note that we are gonna be pretty bit-starved afterwards, the new pointer could have its alignment bits stolen and we probably can reduce IdentifierNamespace by a couple of bits, but that's it
IMO, we are LONG overdue for removing the `NextInContext` and replace it with a collection of some sort in `DeclContext`. The linked-list functionality has some distinct problems (costing us a pointer in EVERY decl is just the beginning, we end up having to instantiate stuff we otherwise don't need to as a result), but it is a pretty big task. AFTER this patch, it doesn't actually save us anything anymore I think (since we still have the `ModuleOwnershipKind` in there that we would need to add to the bitfield), but it would free up a TON of bits.
https://github.com/llvm/llvm-project/pull/219138
More information about the cfe-commits
mailing list