[clang] 1ecc5ae - [Serialization] Register Speical types before register decls

Chuanqi Xu via cfe-commits cfe-commits at lists.llvm.org
Sun Jun 23 20:13:51 PDT 2024


Author: Chuanqi Xu
Date: 2024-06-24T11:08:46+08:00
New Revision: 1ecc5ae13b9061cfb37ef0c409c8a4fc4bad42c9

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

LOG: [Serialization] Register Speical types before register decls

We will only regsiter top level types and decls in ASTWriter and
we will register the sub types and decls during the process of writing
types and decls. So that the ID for the types in the sub level can be
different if the writing decl process changes the order of the to-be-
emitted type queues. This is not ideal since it causes unnecessary
changes especially in no transitive changes model.

This patch migrates the issue by regsitering special types before
regsitering decls. This make sure that the special types in the 2nd
top level can be registered early than the decls. But it might still be
problematic if there are more levels in the special types. Luckily we
just don't have such special types.

Added: 
    clang/test/Modules/no-transitive-decl-change-2.cppm

Modified: 
    clang/lib/Serialization/ASTWriter.cpp
    clang/test/Modules/no-implicit-declarations.cppm

Removed: 
    


################################################################################
diff  --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp
index d99d85652c7b7..5b39055cf9f27 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -5387,6 +5387,17 @@ ASTFileSignature ASTWriter::WriteASTCore(Sema &SemaRef, StringRef isysroot,
     }
   }
 
+  // Form the record of special types.
+  RecordData SpecialTypes;
+  AddTypeRef(Context.getRawCFConstantStringType(), SpecialTypes);
+  AddTypeRef(Context.getFILEType(), SpecialTypes);
+  AddTypeRef(Context.getjmp_bufType(), SpecialTypes);
+  AddTypeRef(Context.getsigjmp_bufType(), SpecialTypes);
+  AddTypeRef(Context.ObjCIdRedefinitionType, SpecialTypes);
+  AddTypeRef(Context.ObjCClassRedefinitionType, SpecialTypes);
+  AddTypeRef(Context.ObjCSelRedefinitionType, SpecialTypes);
+  AddTypeRef(Context.getucontext_tType(), SpecialTypes);
+
   PrepareWritingSpecialDecls(SemaRef);
 
   // Write the control block
@@ -5418,17 +5429,6 @@ ASTFileSignature ASTWriter::WriteASTCore(Sema &SemaRef, StringRef isysroot,
   for (auto &Selector : AllSelectors)
     SemaRef.ObjC().updateOutOfDateSelector(Selector);
 
-  // Form the record of special types.
-  RecordData SpecialTypes;
-  AddTypeRef(Context.getRawCFConstantStringType(), SpecialTypes);
-  AddTypeRef(Context.getFILEType(), SpecialTypes);
-  AddTypeRef(Context.getjmp_bufType(), SpecialTypes);
-  AddTypeRef(Context.getsigjmp_bufType(), SpecialTypes);
-  AddTypeRef(Context.ObjCIdRedefinitionType, SpecialTypes);
-  AddTypeRef(Context.ObjCClassRedefinitionType, SpecialTypes);
-  AddTypeRef(Context.ObjCSelRedefinitionType, SpecialTypes);
-  AddTypeRef(Context.getucontext_tType(), SpecialTypes);
-
   if (Chain) {
     // Write the mapping information describing our module dependencies and how
     // each of those modules were mapped into our own offset/ID space, so that

diff  --git a/clang/test/Modules/no-implicit-declarations.cppm b/clang/test/Modules/no-implicit-declarations.cppm
index 79c3c5e76f63e..a5129d40194d3 100644
--- a/clang/test/Modules/no-implicit-declarations.cppm
+++ b/clang/test/Modules/no-implicit-declarations.cppm
@@ -16,11 +16,11 @@ export int a = 43;
 
 // CHECK:  <DECLTYPES_BLOCK
 // CHECK-NOT: <DECL_TYPEDEF
+// CHECK:    <TYPE_TYPEDEF
 // CHECK:    <DECL_CONTEXT_LEXICAL
 // CHECK:    <DECL_EXPORT
-// CHECK:    <TYPE_TYPEDEF
+// CHECK:    <TYPE_RECORD
 // CHECK:    <DECL_VAR
 // CHECK:    <EXPR_INTEGER_LITERAL
 // CHECK:    <STMT_STOP
-// CHECK:    <TYPE_RECORD
 // CHECK:  </DECLTYPES_BLOCK>

diff  --git a/clang/test/Modules/no-transitive-decl-change-2.cppm b/clang/test/Modules/no-transitive-decl-change-2.cppm
new file mode 100644
index 0000000000000..fe29d9169201d
--- /dev/null
+++ b/clang/test/Modules/no-transitive-decl-change-2.cppm
@@ -0,0 +1,28 @@
+// Test that adding a new unused decl within reduced BMI may not produce a transitive change.
+//
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 -emit-reduced-module-interface %t/A.cppm -o %t/A.pcm
+// RUN: %clang_cc1 -std=c++20 -emit-reduced-module-interface %t/B.cppm -o %t/B.pcm \
+// RUN:     -fmodule-file=A=%t/A.pcm
+//
+// RUN: %clang_cc1 -std=c++20 -emit-reduced-module-interface %t/A.v1.cppm -o %t/A.v1.pcm
+// RUN: %clang_cc1 -std=c++20 -emit-reduced-module-interface %t/B.cppm -o %t/B.v1.pcm \
+// RUN:     -fmodule-file=A=%t/A.v1.pcm
+//
+// RUN: 
diff  %t/B.pcm %t/B.v1.pcm &> /dev/null
+
+//--- A.cppm
+export module A;
+export int a() { return 44; }
+
+//--- A.v1.cppm
+export module A;
+int a_impl() { return 48; }
+export int a() { return a_impl(); }
+
+//--- B.cppm
+export module B;
+import A;
+export int b() { return a(); }


        


More information about the cfe-commits mailing list