| 1 |
// RUN: %clang_cc1 -std=c++23 %s -emit-llvm -o - | FileCheck %s |
| 2 |
// RUN: %clang_cc1 -std=c++23 %s -emit-llvm -o - -fexperimental-new-constant-interpreter | FileCheck %s |
| 3 |
|
| 4 |
void should_be_used_1(); |
| 5 |
void should_be_used_2(); |
| 6 |
void should_be_used_3(); |
| 7 |
constexpr void should_not_be_used() {} |
| 8 |
|
| 9 |
constexpr void f() { |
| 10 |
if consteval { |
| 11 |
should_not_be_used(); // CHECK-NOT: call {{.*}}should_not_be_used |
| 12 |
} else { |
| 13 |
should_be_used_1(); // CHECK: call {{.*}}should_be_used_1 |
| 14 |
} |
| 15 |
|
| 16 |
if !consteval { |
| 17 |
should_be_used_2(); // CHECK: call {{.*}}should_be_used_2 |
| 18 |
} |
| 19 |
|
| 20 |
if !consteval { |
| 21 |
should_be_used_3(); // CHECK: call {{.*}}should_be_used_3 |
| 22 |
} else { |
| 23 |
should_not_be_used(); // CHECK-NOT: call {{.*}}should_not_be_used |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
void g() { |
| 28 |
f(); |
| 29 |
} |
| 30 |
|
| 31 |
namespace GH55638 { |
| 32 |
|
| 33 |
constexpr bool is_constant_evaluated() noexcept { |
| 34 |
if consteval { return true; } else { return false; } |
| 35 |
} |
| 36 |
|
| 37 |
constexpr int compiletime(int) { |
| 38 |
return 2; |
| 39 |
} |
| 40 |
|
| 41 |
constexpr int runtime(int) { |
| 42 |
return 1; |
| 43 |
} |
| 44 |
|
| 45 |
constexpr int test(int x) { |
| 46 |
if(is_constant_evaluated()) |
| 47 |
return compiletime(x); // CHECK-NOT: call {{.*}}compiletime |
| 48 |
return runtime(x); // CHECK: call {{.*}}runtime |
| 49 |
} |
| 50 |
|
| 51 |
int f(int x) { |
| 52 |
x = test(x); |
| 53 |
return x; |
| 54 |
} |
| 55 |
|
| 56 |
} |