| 1 |
// Address: https://github.com/llvm/llvm-project/issues/60693 |
| 2 |
// |
| 3 |
// RUN: rm -rf %t |
| 4 |
// RUN: mkdir -p %t |
| 5 |
// RUN: split-file %s %t |
| 6 |
// |
| 7 |
// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/a.cppm -emit-module-interface -o %t/a.pcm |
| 8 |
// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple -fmodule-file=a=%t/a.pcm %t/c.cpp -emit-llvm -disable-llvm-passes -o - | FileCheck %t/c.cpp |
| 9 |
|
| 10 |
// Test again with reduced BMI |
| 11 |
// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/a.cppm -emit-reduced-module-interface -o %t/a.pcm |
| 12 |
// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple -fmodule-file=a=%t/a.pcm %t/c.cpp -emit-llvm -disable-llvm-passes -o - | FileCheck %t/c.cpp |
| 13 |
|
| 14 |
//--- a.cppm |
| 15 |
export module a; |
| 16 |
|
| 17 |
constexpr bool f() { |
| 18 |
for (unsigned n = 0; n != 10; ++n) { |
| 19 |
} |
| 20 |
return true; |
| 21 |
} |
| 22 |
|
| 23 |
template <typename T> |
| 24 |
struct u { |
| 25 |
T unit() { |
| 26 |
return T(); |
| 27 |
} |
| 28 |
}; |
| 29 |
|
| 30 |
export template<typename T> |
| 31 |
struct s { |
| 32 |
static constexpr auto a = f(); |
| 33 |
static constexpr auto b = f(); |
| 34 |
static constexpr auto c = f(); |
| 35 |
static constexpr auto d = f(); |
| 36 |
int foo() { |
| 37 |
return 43; |
| 38 |
} |
| 39 |
int bar() { |
| 40 |
return 44; |
| 41 |
} |
| 42 |
T zoo() { |
| 43 |
return u<T>().unit(); |
| 44 |
} |
| 45 |
}; |
| 46 |
|
| 47 |
template struct s<int>; |
| 48 |
template struct s<long>; |
| 49 |
|
| 50 |
//--- c.cpp |
| 51 |
import a; |
| 52 |
|
| 53 |
extern "C" int use() { |
| 54 |
s<int> _; |
| 55 |
return _.a + _.b + _.c + _.d; |
| 56 |
} |
| 57 |
|
| 58 |
extern "C" long use2() { |
| 59 |
s<long> _; |
| 60 |
return _.foo(); |
| 61 |
} |
| 62 |
|
| 63 |
extern "C" long use3() { |
| 64 |
s<long> _; |
| 65 |
return _.zoo(); |
| 66 |
} |
| 67 |
|
| 68 |
// CHECK: define{{.*}}@use( |
| 69 |
// CHECK-NOT: } |
| 70 |
// CHECK: ret{{.*}} 4 |
| 71 |
|
| 72 |
// CHECK: declare{{.*}}@_ZNW1a1sIlE3fooEv |
| 73 |
// CHECK-NOT: _ZNW1a1sIlE3barEv |
| 74 |
// CHECK: declare{{.*}}_ZNW1a1sIlE3zooEv |