116 lines · cpp
1// Test debug info for intermediate value of a chained pointer deferencing2// expression when the flag -fdebug-info-for-pointer-type is enabled.3// RUN: %clang_cc1 -emit-llvm -triple x86_64-linux-gnu %s -fdebug-info-for-profiling -debug-info-kind=constructor -o - | FileCheck %s4 5class A {6public:7 int i;8 char c;9 void *p;10 int arr[3];11};12 13class B {14public:15 A* a;16};17 18class C {19public:20 B* b;21 A* a;22 A arr[10];23};24 25// CHECK-LABEL: define dso_local noundef i32 @{{.*}}func1{{.*}}(26// CHECK: [[A_ADDR:%.*]] = getelementptr inbounds nuw %class.B, ptr {{%.*}}, i32 0, i32 0, !dbg [[DBG1:![0-9]+]]27// CHECK-NEXT: [[A:%.*]] = load ptr, ptr [[A_ADDR]], align {{.*}}, !dbg [[DBG1]]28// CHECK-NEXT: #dbg_value(ptr [[A]], [[META1:![0-9]+]], !DIExpression(), [[DBG1]])29// CHECK-NEXT: {{%.*}} = getelementptr inbounds nuw %class.A, ptr [[A]], i32 0, i32 0,30int func1(B *b) {31 return b->a->i;32}33 34// Should generate a pseudo variable when pointer is type-casted.35// CHECK-LABEL: define dso_local noundef ptr @{{.*}}func2{{.*}}(36// CHECK: #dbg_declare(ptr [[B_ADDR:%.*]], [[META2:![0-9]+]], !DIExpression(),37// CHECK-NEXT: [[B:%.*]] = load ptr, ptr [[B_ADDR]],38// CHECK-NEXT: #dbg_value(ptr [[B]], [[META3:![0-9]+]], !DIExpression(),39// CHECK-NEXT: {{%.*}} = getelementptr inbounds nuw %class.B, ptr [[B]], i32 0,40A* func2(void *b) {41 return ((B*)b)->a;42}43 44// Should not generate pseudo variable in this case.45// CHECK-LABEL: define dso_local noundef i32 @{{.*}}func3{{.*}}(46// CHECK: #dbg_declare(ptr [[B_ADDR:%.*]], [[META4:![0-9]+]], !DIExpression(),47// CHECK: #dbg_declare(ptr [[LOCAL1:%.*]], [[META5:![0-9]+]], !DIExpression(),48// CHECK-NOT: #dbg_value(ptr49int func3(B *b) {50 A *local1 = b->a;51 return local1->i;52}53 54// CHECK-LABEL: define dso_local noundef signext i8 @{{.*}}func4{{.*}}(55// CHECK: [[A_ADDR:%.*]] = getelementptr inbounds nuw %class.C, ptr {{%.*}}, i32 0, i32 156// CHECK-NEXT: [[A:%.*]] = load ptr, ptr [[A_ADDR]],57// CHECK-NEXT: #dbg_value(ptr [[A]], [[META6:![0-9]+]], !DIExpression(),58// CHECK-NEXT: {{%.*}} = getelementptr inbounds nuw %class.A, ptr [[A]], i32 0, i32 0,59// CHECK: [[CALL:%.*]] = call noundef ptr @{{.*}}foo{{.*}}(60// CHECK-NEXT: #dbg_value(ptr [[CALL]], [[META6]], !DIExpression(),61// CHECK-NEXT: [[I1:%.*]] = getelementptr inbounds nuw %class.A, ptr [[CALL]], i32 0, i32 162char func4(C *c) {63 extern A* foo(int x);64 return foo(c->a->i)->c;65}66 67// CHECK-LABEL: define dso_local noundef signext i8 @{{.*}}func5{{.*}}(68// CHECK: #dbg_declare(ptr {{%.*}}, [[META7:![0-9]+]], !DIExpression(),69// CHECK: #dbg_declare(ptr {{%.*}}, [[META8:![0-9]+]], !DIExpression(),70// CHECK: [[A_ADDR:%.*]] = getelementptr inbounds %class.A, ptr {{%.*}}, i64 {{%.*}},71// CHECK-NEXT: #dbg_value(ptr [[A_ADDR]], [[META9:![0-9]+]], !DIExpression(),72// CHECK-NEXT: {{%.*}} = getelementptr inbounds nuw %class.A, ptr [[A_ADDR]], i32 0, i32 1,73char func5(void *arr, int n) {74 return ((A*)arr)[n].c;75}76 77// CHECK-LABEL: define dso_local noundef i32 @{{.*}}func6{{.*}}(78// CHECK: #dbg_declare(ptr {{%.*}}, [[META10:![0-9]+]], !DIExpression(),79// CHECK: #dbg_value(ptr {{%.*}}, [[META11:![0-9]+]], !DIExpression(),80int func6(B &b) {81 return reinterpret_cast<A&>(b).i;82}83 84// CHECK-LABEL: define dso_local noundef i32 @{{.*}}global{{.*}}(85// CHECK: [[GA:%.*]] = load ptr, ptr @ga86// CHECK-NEXT: #dbg_value(ptr [[GA]], [[META12:![0-9]+]], !DIExpression(),87A *ga;88int global() {89 return ga->i;90}91 92 93// CHECK-DAG: [[META_A:![0-9]+]] = distinct !DICompositeType(tag: DW_TAG_class_type, name: "A",94// CHECK-DAG: [[META_AP:![0-9]+]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: [[META_A]],95// CHECK-DAG: [[META_B:![0-9]+]] = distinct !DICompositeType(tag: DW_TAG_class_type, name: "B",96// CHECK-DAG: [[META_BP:![0-9]+]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: [[META_B]],97// CHECK-DAG: [[META_C:![0-9]+]] = distinct !DICompositeType(tag: DW_TAG_class_type, name: "C",98// CHECK-DAG: [[META_CP:![0-9]+]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: [[META_C]],99// CHECK-DAG: [[META_VP:![0-9]+]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null,100// CHECK-DAG: [[META_I32:![0-9]+]] = !DIBasicType(name: "int", size: 32,101// CHECK-DAG: [[META_BR:![0-9]+]] = !DIDerivedType(tag: DW_TAG_reference_type, baseType: [[META_B]],102 103// CHECK-DAG: [[DBG1]] = !DILocation(line: 31, column: 13,104// CHECK-DAG: [[META1]] = !DILocalVariable(scope: {{.*}}, type: [[META_AP]], flags: DIFlagArtificial)105// CHECK-DAG: [[META2]] = !DILocalVariable(name: "b", arg: 1, scope: {{.*}}, file: {{.*}}, line: 40, type: [[META_VP]])106// CHECK-DAG: [[META3]] = !DILocalVariable(scope: {{.*}}, type: [[META_BP]], flags: DIFlagArtificial)107// CHECK-DAG: [[META4]] = !DILocalVariable(name: "b", arg: 1, scope: {{.*}}, file: {{.*}}, line: 49, type: [[META_BP]])108// CHECK-DAG: [[META5]] = !DILocalVariable(name: "local1", scope: {{.*}}, file: {{.*}}, line: 50, type: [[META_AP]])109// CHECK-DAG: [[META6]] = !DILocalVariable(scope: {{.*}}, type: [[META_AP]], flags: DIFlagArtificial)110// CHECK-DAG: [[META7]] = !DILocalVariable(name: "arr", arg: 1, scope: {{.*}}, file: {{.*}}, line: 73, type: [[META_VP]])111// CHECK-DAG: [[META8]] = !DILocalVariable(name: "n", arg: 2, scope: {{.*}}, file: {{.*}}, line: 73, type: [[META_I32]])112// CHECK-DAG: [[META9]] = !DILocalVariable(scope: {{.*}}, type: [[META_AP]], flags: DIFlagArtificial)113// CHECK-DAG: [[META10]] = !DILocalVariable(name: "b", arg: 1, scope: {{.*}}, file: {{.*}}, line: 80, type: [[META_BR]])114// CHECK-DAG: [[META11]] = !DILocalVariable(scope: {{.*}}, type: [[META_AP]], flags: DIFlagArtificial)115// CHECK-DAG: [[META12]] = !DILocalVariable(scope: {{.*}}, type: [[META_AP]], flags: DIFlagArtificial)116