| 1 |
// RUN: rm -rf %t |
| 2 |
// RUN: mkdir -p %t |
| 3 |
// RUN: split-file %s %t |
| 4 |
// |
| 5 |
// RUN: %clang_cc1 -std=c++20 %t/flyweight.cppm -emit-reduced-module-interface -o %t/flyweight.pcm |
| 6 |
// RUN: %clang_cc1 -std=c++20 %t/account.cppm -emit-reduced-module-interface -o %t/account.pcm -fprebuilt-module-path=%t |
| 7 |
// RUN: %clang_cc1 -std=c++20 %t/core.cppm -emit-reduced-module-interface -o %t/core.pcm -fprebuilt-module-path=%t |
| 8 |
// RUN: %clang_cc1 -std=c++20 %t/core.cppm -fprebuilt-module-path=%t -emit-llvm -disable-llvm-passes -o - | FileCheck %t/core.cppm |
| 9 |
|
| 10 |
//--- flyweight.cppm |
| 11 |
module; |
| 12 |
template <typename> struct flyweight_core { |
| 13 |
static bool init() { (void)__builtin_operator_new(2); return true; } |
| 14 |
static bool static_initializer; |
| 15 |
}; |
| 16 |
template <typename T> bool flyweight_core<T>::static_initializer = init(); |
| 17 |
export module flyweight; |
| 18 |
export template <class> void flyweight() { |
| 19 |
(void)flyweight_core<int>::static_initializer; |
| 20 |
} |
| 21 |
|
| 22 |
//--- account.cppm |
| 23 |
export module account; |
| 24 |
import flyweight; |
| 25 |
export void account() { |
| 26 |
(void)::flyweight<int>; |
| 27 |
} |
| 28 |
|
| 29 |
//--- core.cppm |
| 30 |
export module core; |
| 31 |
import account; |
| 32 |
|
| 33 |
extern "C" void core() {} |
| 34 |
|
| 35 |
// Fine enough to check it won't crash. |
| 36 |
// CHECK-NOT: init |
| 37 |
// CHECK-NOT: static_initializer |
| 38 |
// CHECK: define {{.*}}@core( |