1 // RUN: %clang_cc1 %s -S -emit-llvm -triple x86_64-unknown-linux-gnu -o - | FileCheck %s 2 3 //CHECK: @[[STR:.*]] = private unnamed_addr constant [5 x i8] c"test\00", section "llvm.metadata" 4 //CHECK: @[[STR1:.*]] = private unnamed_addr constant [{{.*}} x i8] c"{{.*}}attr-annotate.cpp\00", section "llvm.metadata" 5 //CHECK: @[[STR2:.*]] = private unnamed_addr constant [4 x i8] c"abc\00", align 1 6 //CHECK: @[[ARGS:.*]] = private unnamed_addr constant { i32, i8*, i32 } { i32 9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @[[STR2:.*]], i32 0, i32 0), i32 8 }, section "llvm.metadata" 7 //CHECK: @[[ARGS2:.*]] = private unnamed_addr constant { %struct.Struct } { %struct.Struct { i32* getelementptr inbounds ([2 x i32], [2 x i32]* @_ZN1AIjLj9EE2SVE, i32 0, i32 0), i32* bitcast (i8* getelementptr (i8, i8* bitcast ([2 x i32]* @_ZN1AIjLj9EE2SVE to i8*), i64 4) to i32*) } }, section "llvm.metadata" 8 //CHECK: @[[VANN0:.*]] = private unnamed_addr constant [8 x i8] c"v_ann_0\00", section "llvm.metadata" 9 //CHECK: @[[B_ARG_IMM_7:.*]] = private unnamed_addr constant { i8*, i32, i32 } { i8* getelementptr inbounds ([4 x i8], [4 x i8]* @[[STR2]], i32 0, i32 0), i32 90, i32 7 }, section "llvm.metadata" 10 //CHECK: @[[VANN1:.*]] = private unnamed_addr constant [8 x i8] c"v_ann_1\00", section "llvm.metadata" 11 //CHECK: @[[VAAN1_ARG_IMM9:.*]] = private unnamed_addr constant { i32 } { i32 9 }, section "llvm.metadata" 12 //CHECK: @[[B_ARG_IMM_NEG1:.*]] = private unnamed_addr constant { i8*, i32, i64 } { i8* getelementptr inbounds ([4 x i8], [4 x i8]* @[[STR2]], i32 0, i32 0), i32 90, i64 -1 }, section "llvm.metadata" 13 //CHECK: @llvm.global.annotations = appending global [2 x { i8*, i8*, i8*, i32, i8* }] [{ i8*, i8*, i8*, i32, i8* } { i8* bitcast (void (%struct.A*)* @_ZN1AIjLj9EE4testILi8EEEvv to i8*), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @[[STR]], i32 0, i32 0), i8* getelementptr inbounds ([{{.*}} x i8], [{{.*}} x i8]* @[[STR1]], i32 0, i32 0), i32 {{.*}}, i8* bitcast ({ i32, i8*, i32 }* @[[ARGS]] to i8*) }, { i8*, i8*, i8*, i32, i8* } { i8* bitcast (void (%struct.A*)* @_ZN1AIjLj9EE5test2Ev to i8*), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @[[STR]], i32 0, i32 0), i8* getelementptr inbounds ([{{.*}} x i8], [{{.*}} x i8]* @[[STR1]], i32 0, i32 0), i32 {{.*}}, i8* bitcast ({ %struct.Struct }* @[[ARGS2]] to i8*) }] 14 15 constexpr const char* str() { 16 return "abc"; 17 } 18 19 template<typename T> 20 struct Struct { 21 T t1; 22 T t2; 23 }; 24 25 template<typename T, T V> 26 struct A { 27 static constexpr const T SV[] = {V, V + 1}; 28 template <int I> __attribute__((annotate("test", V, str(), I))) void test() {} 29 __attribute__((annotate("test", Struct<const T*>{&SV[0], &SV[1]}))) void test2() {} 30 }; 31 32 void t() { 33 A<unsigned, 9> a; 34 a.test<8>(); 35 a.test2(); 36 } 37 38 template<typename T, T V> 39 struct B { 40 template<typename T1, T1 V1> 41 struct foo { 42 int v __attribute__((annotate("v_ann_0", str(), 90, V))) __attribute__((annotate("v_ann_1", V1))); 43 }; 44 }; 45 46 static B<int long, -1>::foo<unsigned, 9> gf; 47 48 // CHECK-LABEL: @main( 49 // CHECK-NEXT: entry: 50 // CHECK-NEXT: [[RETVAL:%.*]] = alloca i32, align 4 51 // CHECK-NEXT: [[ARGC_ADDR:%.*]] = alloca i32, align 4 52 // CHECK-NEXT: [[ARGV_ADDR:%.*]] = alloca i8**, align 8 53 // CHECK-NEXT: [[F:%.*]] = alloca %"struct.B<int, 7>::foo", align 4 54 // CHECK-NEXT: store i32 0, i32* [[RETVAL]], align 4 55 // CHECK-NEXT: store i32 [[ARGC:%.*]], i32* [[ARGC_ADDR]], align 4 56 // CHECK-NEXT: store i8** [[ARGV:%.*]], i8*** [[ARGV_ADDR]], align 8 57 // CHECK-NEXT: [[TMP0:%.*]] = load i32, i32* [[ARGC_ADDR]], align 4 58 // CHECK-NEXT: [[V:%.*]] = getelementptr inbounds %"struct.B<int, 7>::foo", %"struct.B<int, 7>::foo"* [[F]], i32 0, i32 0 59 // CHECK-NEXT: [[TMP1:%.*]] = bitcast i32* [[V]] to i8* 60 // CHECK-NEXT: [[TMP2:%.*]] = call i8* @llvm.ptr.annotation.p0i8(i8* [[TMP1]], i8* getelementptr inbounds ([8 x i8], [8 x i8]* @[[VANN0]], i32 0, i32 0), i8* getelementptr inbounds ([{{.*}} x i8], [{{.*}} x i8]* @.str.1, i32 0, i32 0), i32 {{.*}}, i8* bitcast ({ i8*, i32, i32 }* @[[B_ARG_IMM_7]] to i8*)) 61 // CHECK-NEXT: [[TMP3:%.*]] = bitcast i8* [[TMP2]] to i32* 62 // CHECK-NEXT: [[TMP4:%.*]] = bitcast i32* [[TMP3]] to i8* 63 // CHECK-NEXT: [[TMP5:%.*]] = call i8* @llvm.ptr.annotation.p0i8(i8* [[TMP4]], i8* getelementptr inbounds ([8 x i8], [8 x i8]* @[[VANN1]], i32 0, i32 0), i8* getelementptr inbounds ([{{.*}} x i8], [{{.*}} x i8]* @.str.1, i32 0, i32 0), i32 {{.*}}, i8* bitcast ({ i32 }* @[[VAAN1_ARG_IMM9]] to i8*)) 64 // CHECK-NEXT: [[TMP6:%.*]] = bitcast i8* [[TMP5]] to i32* 65 // CHECK-NEXT: store i32 [[TMP0]], i32* [[TMP6]], align 4 66 // CHECK-NEXT: [[TMP7:%.*]] = load i32, i32* [[ARGC_ADDR]], align 4 67 // CHECK-NEXT: [[TMP8:%.*]] = call i8* @llvm.ptr.annotation.p0i8(i8* bitcast (%"struct.B<long, -1>::foo"* @_ZL2gf to i8*), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @[[VANN0]], i32 0, i32 0), i8* getelementptr inbounds ([{{.*}} x i8], [{{.*}} x i8]* @.str.1, i32 0, i32 0), i32 {{.*}}, i8* bitcast ({ i8*, i32, i64 }* @[[B_ARG_IMM_NEG1]] to i8*)) 68 // CHECK-NEXT: [[TMP9:%.*]] = bitcast i8* [[TMP8]] to i32* 69 // CHECK-NEXT: [[TMP10:%.*]] = bitcast i32* [[TMP9]] to i8* 70 // CHECK-NEXT: [[TMP11:%.*]] = call i8* @llvm.ptr.annotation.p0i8(i8* [[TMP10]], i8* getelementptr inbounds ([8 x i8], [8 x i8]* @[[VANN1]], i32 0, i32 0), i8* getelementptr inbounds ([{{.*}} x i8], [{{.*}} x i8]* @.str.1, i32 0, i32 0), i32 {{.*}}, i8* bitcast ({ i32 }* @[[VAAN1_ARG_IMM9]] to i8*)) 71 // CHECK-NEXT: [[TMP12:%.*]] = bitcast i8* [[TMP11]] to i32* 72 // CHECK-NEXT: store i32 [[TMP7]], i32* [[TMP12]], align 4 73 // CHECK-NEXT: ret i32 0 74 // 75 int main(int argc, char **argv) { 76 B<int, 7>::foo<unsigned, 9> f; 77 f.v = argc; 78 gf.v = argc; 79 return 0; 80 } 81