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