1 // RUN: %clang_cc1 -std=c++1z -fblocks %s -triple x86_64-unknown-unknown -emit-llvm -o - | FileCheck %s
4 extern "C" const volatile void* volatile ptr_sink
= nullptr;
11 constexpr int get_line_constexpr(int l
= __builtin_LINE()) {
15 int get_line_nonconstexpr(int l
= __builtin_LINE()) {
20 int get_line(int l
= __builtin_LINE()) {
24 int get_line2(int l
= get_line()) { return l
; }
27 // CHECK: @global_one ={{.*}} global i32 [[@LINE+1]], align 4
28 int global_one
= __builtin_LINE();
29 // CHECK-NEXT: @global_two ={{.*}} global i32 [[@LINE+1]], align 4
30 int global_two
= get_line_constexpr();
31 // CHECK: @_ZL12global_three = internal constant i32 [[@LINE+1]], align 4
32 const int global_three(get_line_constexpr());
34 // CHECK-LABEL: define internal void @__cxx_global_var_init
35 // CHECK: %call = call noundef i32 @_Z21get_line_nonconstexpri(i32 noundef [[@LINE+2]])
36 // CHECK-NEXT: store i32 %call, ptr @global_four, align 4
37 int global_four
= get_line_nonconstexpr();
40 int Init
= __builtin_LINE();
41 int Init2
= get_line2();
43 constexpr InClassInit(Tag1
, int l
= __builtin_LINE()) : Init(l
), Init2(l
) {}
44 constexpr InClassInit(Tag2
) : Init(__builtin_LINE()), Init2(__builtin_LINE()) {}
45 InClassInit(Tag3
, int l
= __builtin_LINE());
46 InClassInit(Tag4
, int l
= get_line2());
48 static void test_class();
50 // CHECK-LABEL: define{{.*}} void @_ZN11InClassInit10test_classEv()
51 void InClassInit::test_class() {
52 // CHECK: call void @_ZN11InClassInitC1Ev(ptr {{[^,]*}} %test_one)
54 // CHECK-NEXT: call void @_ZN11InClassInitC1E4Tag1i(ptr {{[^,]*}} %test_two, i32 noundef [[@LINE+1]])
55 InClassInit test_two
{Tag1
{}};
56 // CHECK-NEXT: call void @_ZN11InClassInitC1E4Tag2(ptr {{[^,]*}} %test_three)
57 InClassInit test_three
{Tag2
{}};
58 // CHECK-NEXT: call void @_ZN11InClassInitC1E4Tag3i(ptr {{[^,]*}} %test_four, i32 noundef [[@LINE+1]])
59 InClassInit
test_four(Tag3
{});
60 // CHECK-NEXT: %[[CALL:.+]] = call noundef i32 @_Z8get_linei(i32 noundef [[@LINE+3]])
61 // CHECK-NEXT: %[[CALL2:.+]] = call noundef i32 @_Z9get_line2i(i32 noundef %[[CALL]])
62 // CHECK-NEXT: call void @_ZN11InClassInitC1E4Tag4i(ptr {{[^,]*}} %test_five, i32 noundef %[[CALL2]])
63 InClassInit
test_five(Tag4
{});
66 // CHECK-LABEL: define{{.*}} void @_ZN11InClassInitC2Ev
67 // CHECK: store i32 [[@LINE+4]], ptr %Init, align 4
68 // CHECK: %call = call noundef i32 @_Z8get_linei(i32 noundef [[@LINE+3]])
69 // CHECK-NEXT: %call2 = call noundef i32 @_Z9get_line2i(i32 noundef %call)
70 // CHECK-NEXT: store i32 %call2, ptr %Init2, align 4
71 InClassInit::InClassInit() = default;
73 InClassInit::InClassInit(Tag3
, int l
) : Init(l
) {}
75 // CHECK-LABEL: define{{.*}} void @_ZN11InClassInitC2E4Tag4i(ptr {{[^,]*}} %this, i32 noundef %arg)
76 // CHECK: %[[TEMP:.+]] = load i32, ptr %arg.addr, align 4
77 // CHECK-NEXT: store i32 %[[TEMP]], ptr %Init, align 4
78 // CHECK: %[[CALL:.+]] = call noundef i32 @_Z8get_linei(i32 noundef [[@LINE+3]])
79 // CHECK-NEXT: %[[CALL2:.+]] = call noundef i32 @_Z9get_line2i(i32 noundef %[[CALL]])
80 // CHECK-NEXT: store i32 %[[CALL2]], ptr %Init2, align 4
81 InClassInit::InClassInit(Tag4
, int arg
) : Init(arg
) {}
83 // CHECK-LABEL: define{{.*}} void @_Z13get_line_testv()
84 void get_line_test() {
85 // CHECK: %[[CALL:.+]] = call noundef i32 @_Z8get_linei(i32 noundef [[@LINE+2]])
86 // CHECK-NEXT: store i32 %[[CALL]], ptr @sink, align 4
88 // CHECK-NEXT: store i32 [[@LINE+1]], ptr @sink, align 4
89 sink
= __builtin_LINE();
90 ptr_sink
= &global_three
;
94 const int N
[] = {__builtin_LINE(), get_line_constexpr()};