[clang] Use range-based for to iterate over fields in record layout, NFC (PR #122029)

Reid Kleckner via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 9 11:09:42 PST 2025


================
@@ -3115,7 +3115,19 @@ class FieldDecl : public DeclaratorDecl, public Mergeable<FieldDecl> {
 
   /// Returns the index of this field within its record,
   /// as appropriate for passing to ASTRecordLayout::getFieldOffset.
-  unsigned getFieldIndex() const;
+  unsigned getFieldIndex() const {
+    const FieldDecl *C = getCanonicalDecl();
+    if (C->CachedFieldIndex == 0)
----------------
rnk wrote:

I'm reasonably confident that that is the case, every canonical decl in the declaration chain is the same at any point in time. I think the surprising thing about canonical declarations is that they can *change* when modules are lazily loaded, and that has bit me in the past when attempting to apply attributes to canonical declarations.

https://github.com/llvm/llvm-project/pull/122029


More information about the cfe-commits mailing list