forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 2
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] [Reduced BMI] Generate the function body from impli…
…citly instantiated class and constant variables After this patch, we will generate the function body from implicitly instantiated class. This is important for consumers with same template arguments. Otherwise the consumers won't see the function body. Since the consumers won't instantiate the templates again if they find an instantiation. Also we will generate the variable definition if the variable is non-inline but known as constant. Such variables may not affect the ABI, but they may get involved into the compile time constant computation in the consumer's code. So we have to generate such definitions.
- Loading branch information
1 parent
34ba907
commit 2582965
Showing
2 changed files
with
48 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Although the reduced BMI are not designed to be generated, | ||
// it is helpful for testing whether we've reduced the definitions. | ||
// | ||
// RUN: rm -rf %t | ||
// RUN: mkdir -p %t | ||
// RUN: split-file %s %t | ||
// | ||
// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/a.cppm \ | ||
// RUN: -emit-reduced-module-interface -o %t/a.pcm | ||
// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/b.cpp \ | ||
// RUN: -fmodule-file=a=%t/a.pcm -S -emit-llvm -o - \ | ||
// RUN: | FileCheck %t/b.cpp | ||
|
||
//--- a.cppm | ||
export module a; | ||
|
||
export template <class T> | ||
class A { | ||
public: | ||
int member() { | ||
return 43; | ||
} | ||
}; | ||
|
||
// Instantiate `A<int>::member()`. | ||
export int a_member = A<int>().member(); | ||
|
||
export const int a = 43; | ||
|
||
//--- b.cpp | ||
import a; | ||
|
||
static_assert(a == 43); | ||
|
||
int b() { | ||
A<int> a; | ||
return a.member(); | ||
} | ||
|
||
// CHECK: define{{.*}}@_ZNW1a1AIiE6memberEv |