xref: /llvm-project/clang/test/CodeGenCXX/default-arguments-with-immediate.cpp (revision ca619613801233ef2def8c3cc7d311d5ed0033cb)
1 // RUN: %clang_cc1 -std=c++2a -triple x86_64-elf-gnu %s -emit-llvm -o - | FileCheck %s
2 
immediate()3 consteval int immediate() { return 0;}
4 static int ext();
5 void f(int a = immediate() + ext());
6 
test_function()7 void test_function() {
8     f();
9     f(0);
10     // CHECK: call noundef i32 @_ZL3extv()
11     // CHECK: add
12     // CHECK: call {{.*}} @_Z1fi
13     // CHECK: call {{.*}} @_Z1fi
14 }
15 
16 // CHECK: define {{.*}} i32 @_ZL3extv()
17 
18 static constexpr int not_immediate();
19 struct A {
20     int a = immediate() + not_immediate();
21 };
22 
test_member()23 void test_member() {
24     // CHECK: call void @_ZN1AC2Ev
25     A defaulted;
26     // CHECK-NOT: call void @_ZN1AC2Ev
27     A provided{0};
28 }
29 
30 // CHECK: define {{.*}} void @_ZN1AC2Ev{{.*}}
31 // CHECK: %call = call noundef i32 @_ZL13not_immediatev()
32 
never_referenced()33 int never_referenced() {return 42;};
34 
35 
36 namespace not_used {
37 
38 struct A {
39     int a = immediate() + never_referenced();
40 };
41 void f(int a = immediate() + never_referenced());
42 
g()43 void g() {
44     A a{0};
45     f(0);
46 }
47 
48 }
49 
ext()50 static int ext() {return 0;}
not_immediate()51 static constexpr int not_immediate() {return 0;}
52 
53 // CHECK-NOT: define {{.*}} i32 _ZL16never_referencedv()(
54 // CHECK: define {{.*}} i32 @_ZL13not_immediatev()
55