-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[C++20] [Modules] Don't generate unused variables in other module units
even if its initializer has side effects Close #61892 The variables whose initializer has side effects will be emitted even if it is not used. But it shouldn't be true after we introduced modules. The variables in other modules shouldn't be emitted if it is not used even if its initializer has size effects. Also this patch rename `Decl::isInCurrentModuleUnit` to `Decl::isInAnotherModuleUnit` to make it closer to the semantics.
- Loading branch information
1 parent
7591a7b
commit b6c7177
Showing
7 changed files
with
83 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// RUN: rm -rf %t | ||
// RUN: mkdir -p %t | ||
// RUN: split-file %s %t | ||
// | ||
// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple \ | ||
// RUN: -emit-module-interface %t/a.cppm -o %t/a.pcm | ||
// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple \ | ||
// RUN: %t/b.cpp -fmodule-file=a=%t/a.pcm -disable-llvm-passes \ | ||
// RUN: -emit-llvm -o - | FileCheck %t/b.cpp | ||
// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple \ | ||
// RUN: %t/c.cpp -fmodule-file=a=%t/a.pcm -disable-llvm-passes \ | ||
// RUN: -emit-llvm -o - | FileCheck %t/c.cpp | ||
|
||
//--- a.cppm | ||
export module a; | ||
|
||
struct integer { | ||
explicit operator int() const { | ||
return 0; | ||
} | ||
}; | ||
|
||
export template<typename> | ||
int a = static_cast<int>(integer()); | ||
|
||
struct s { | ||
~s(); | ||
operator int() const; | ||
}; | ||
|
||
export template<typename> | ||
auto d = s(); | ||
|
||
int aa() { | ||
return a<void> + d<void>; | ||
} | ||
|
||
int dynamic_func(); | ||
export inline int dynamic_var = dynamic_func(); | ||
|
||
//--- b.cpp | ||
import a; | ||
|
||
void b() {} | ||
|
||
// CHECK-NOT: @_ZW1a1dIvE = | ||
// CHECK-NOT: @_ZGVW1a1dIvE = | ||
// CHECK-NOT: @_ZW1a11dynamic_var = | ||
// CHECK-NOT: @_ZGVW1a11dynamic_var = | ||
// CHECK-NOT: @_ZW1a1aIvE = | ||
// CHECK-NOT: @_ZGVW1a1aIvE = | ||
|
||
//--- c.cpp | ||
import a; | ||
int c() { | ||
return a<void> + d<void> + dynamic_var; | ||
} | ||
|
||
// The used variables are generated normally | ||
// CHECK-DAG: @_ZW1a1aIvE = | ||
// CHECK-DAG: @_ZW1a1dIvE = | ||
// CHECK-DAG: @_ZW1a11dynamic_var = linkonce_odr | ||
// CHECK-DAG: @_ZGVW1a1aIvE = | ||
// CHECk-DAG: @_ZGVW1a1dIvE = | ||
// CHECK-DAG: @_ZGVW1a11dynamic_var = linkonce_odr |