[clang] b612143 - [C++20] Fix a crash with modules.

Utkarsh Saxena via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 2 08:07:03 PST 2023


Author: Utkarsh Saxena
Date: 2023-02-02T17:06:43+01:00
New Revision: b6121432da79c4b3d21f191864ff6c583e2e62eb

URL: https://github.com/llvm/llvm-project/commit/b6121432da79c4b3d21f191864ff6c583e2e62eb
DIFF: https://github.com/llvm/llvm-project/commit/b6121432da79c4b3d21f191864ff6c583e2e62eb.diff

LOG: [C++20] Fix a crash with modules.

Differential Revision: https://reviews.llvm.org/D142384

Added: 
    

Modified: 
    clang/lib/AST/Decl.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index e60cc28f6e0f6..51cff6c54a6a5 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -4770,7 +4770,10 @@ bool RecordDecl::isOrContainsUnion() const {
 RecordDecl::field_iterator RecordDecl::field_begin() const {
   if (hasExternalLexicalStorage() && !hasLoadedFieldsFromExternalStorage())
     LoadFieldsFromExternalStorage();
-
+  // This is necessary for correctness for C++ with modules.
+  // FIXME: Come up with a test case that breaks without definition.
+  if (RecordDecl *D = getDefinition(); D && D != this)
+    return D->field_begin();
   return field_iterator(decl_iterator(FirstDecl));
 }
 


        


More information about the cfe-commits mailing list