llvm-project/clang/test/Modules/no-external-identifier-id.cppm
Chuanqi Xu fa20184a8f [C++20] [Modules] [Serialization] Don't reuse type ID and identifier ID from imported modules
To support no-transitive-change model for named modules, we can't reuse
type ID and identifier ID from imported modules arbitrarily. Since the
theory for no-transitive-change model is,
for a user of a named module, the user can only access the
indirectly imported decls via the directly imported module. So that it is
possible to control what matters to the users when writing the module.

And it will be unsafe to do so if the users can reuse the type IDs and
identifier IDs from the indirectly imported modules not via the directly
imported modules.

So in this patch, we don't reuse the type ID and identifier ID in the
AST writer to avoid the problematic case.
2024-06-25 15:04:32 +08:00

38 lines
1011 B
C++

// Testing that we won't record the identifier ID from external modules.
//
// RUN: rm -rf %t
// RUN: split-file %s %t
// RUN: cd %t
//
// RUN: %clang_cc1 -std=c++20 %t/a.cppm -emit-module-interface -o %t/a.pcm
// RUN: %clang_cc1 -std=c++20 %t/b.cppm -emit-module-interface -o %t/b.pcm \
// RUN: -fmodule-file=a=%t/a.pcm
// RUN: llvm-bcanalyzer --dump --disable-histogram %t/b.pcm | FileCheck %t/b.cppm
//
// RUN: %clang_cc1 -std=c++20 %t/a.v1.cppm -emit-module-interface -o %t/a.v1.pcm
// RUN: %clang_cc1 -std=c++20 %t/b.cppm -emit-module-interface -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 inline int a() {
int foo = 43;
return foo;
}
//--- b.cppm
export module b;
import a;
export inline int b() {
int foo = 43;
return foo;
}
// CHECK: <DECL_VAR {{.*}} op5=4
//--- a.v1.cppm
// We remove the unused the function and testing if the format of the BMI of B will change.
export module a;