-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Add option to generate additional debug info for expression dereferencing pointer to pointers. #81545
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add option to generate additional debug info for expression dereferencing pointer to pointers. #81545
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f2c8275
Add option to generate additional info for expression containing poin…
huangjd 95235b9
Code cleanup
huangjd 37d3c1b
Rewrite code to emit debug info for pointer instead of pointee, as
huangjd 75faf06
More precise debug loc
huangjd 404bd99
Correct debug type info for "a.b" expr
huangjd 630137e
Add test case
huangjd 6a1e4e8
Handle case for invoke instruction, and the instruction for which pseudo
huangjd a0dab26
Fix incorrect debug loc after builder emits pseudo variable in some
huangjd 4f6750b
Merge this feature into -fdebug-info-for-profiling option instead of
huangjd 87e89d1
Added more safeguards for invalid debug location from source
huangjd 4c2369d
Changed pseudo variable declaration to be compliant with DWARF standard
huangjd 6c77216
code cleanup
huangjd 8ba3e3c
Removed line info for pseudo varaible because they are not needed
huangjd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
// Test debug info for intermediate value of a chained pointer deferencing | ||
// expression when the flag -fdebug-info-for-pointer-type is enabled. | ||
// RUN: %clang_cc1 %s -fdebug-info-for-profiling -debug-info-kind=constructor -S -emit-llvm -o - | FileCheck %s | ||
|
||
class A { | ||
public: | ||
int i; | ||
char c; | ||
void *p; | ||
int arr[3]; | ||
}; | ||
|
||
class B { | ||
public: | ||
A* a; | ||
}; | ||
|
||
class C { | ||
public: | ||
B* b; | ||
A* a; | ||
A arr[10]; | ||
}; | ||
|
||
// CHECK-LABEL: define dso_local noundef i32 @{{.*}}func1{{.*}}( | ||
// CHECK: [[A_ADDR:%.*]] = getelementptr inbounds %class.B, ptr {{%.*}}, i32 0, i32 0, !dbg [[DBG1:![0-9]+]] | ||
// CHECK-NEXT: [[A:%.*]] = load ptr, ptr [[A_ADDR]], align {{.*}}, !dbg [[DBG1]] | ||
// CHECK-NEXT: [[PSEUDO1:%.*]] = alloca ptr, align {{.*}}, !dbg [[DBG1]] | ||
// CHECK-NEXT: store ptr [[A]], ptr [[PSEUDO1]], align {{.*}}, !dbg [[DBG1]] | ||
// CHECK-NEXT: call void @llvm.dbg.declare(metadata ptr [[PSEUDO1]], metadata [[META1:![0-9]+]], metadata !DIExpression()), !dbg [[DBG1]] | ||
// CHECK-NEXT: [[TMP1:%.*]] = load ptr, ptr [[PSEUDO1]], align {{.*}}, !dbg [[DBG1]] | ||
// CHECK-NEXT: {{%.*}} = getelementptr inbounds %class.A, ptr [[TMP1]], i32 0, i32 0, | ||
int func1(B *b) { | ||
return b->a->i; | ||
} | ||
|
||
// Should generate a pseudo variable when pointer is type-casted. | ||
// CHECK-LABEL: define dso_local noundef ptr @{{.*}}func2{{.*}}( | ||
// CHECK: call void @llvm.dbg.declare(metadata ptr [[B_ADDR:%.*]], metadata [[META2:![0-9]+]], metadata !DIExpression()) | ||
// CHECK-NEXT: [[B:%.*]] = load ptr, ptr [[B_ADDR]], | ||
// CHECK-NEXT: [[PSEUDO1:%.*]] = alloca ptr, | ||
// CHECK-NEXT: store ptr [[B]], ptr [[PSEUDO1]], | ||
// CHECK-NEXT: call void @llvm.dbg.declare(metadata ptr [[PSEUDO1]], metadata [[META3:![0-9]+]], metadata !DIExpression()) | ||
// CHECK-NEXT: [[TMP1:%.*]] = load ptr, ptr [[PSEUDO1]], | ||
// CHECK-NEXT: {{%.*}} = getelementptr inbounds %class.B, ptr [[TMP1]], i32 0, | ||
A* func2(void *b) { | ||
return ((B*)b)->a; | ||
} | ||
|
||
// Should not generate pseudo variable in this case. | ||
// CHECK-LABEL: define dso_local noundef i32 @{{.*}}func3{{.*}}( | ||
// CHECK: call void @llvm.dbg.declare(metadata ptr [[B_ADDR:%.*]], metadata [[META4:![0-9]+]], metadata !DIExpression()) | ||
// CHECK: call void @llvm.dbg.declare(metadata ptr [[LOCAL1:%.*]], metadata [[META5:![0-9]+]], metadata !DIExpression()) | ||
// CHECK-NOT: call void @llvm.dbg.declare(metadata ptr | ||
int func3(B *b) { | ||
A *local1 = b->a; | ||
return local1->i; | ||
} | ||
|
||
// CHECK-LABEL: define dso_local noundef signext i8 @{{.*}}func4{{.*}}( | ||
// CHECK: [[A_ADDR:%.*]] = getelementptr inbounds %class.C, ptr {{%.*}}, i32 0, i32 1 | ||
// CHECK-NEXT: [[A:%.*]] = load ptr, ptr [[A_ADDR]], | ||
// CHECK-NEXT: [[PSEUDO1:%.*]] = alloca ptr, | ||
// CHECK-NEXT: store ptr [[A]], ptr [[PSEUDO1]], | ||
// CHECK-NEXT: call void @llvm.dbg.declare(metadata ptr [[PSEUDO1]], metadata [[META6:![0-9]+]], metadata !DIExpression()) | ||
// CHECK-NEXT: [[TMP1:%.*]] = load ptr, ptr [[PSEUDO1]], | ||
// CHECK-NEXT: {{%.*}} = getelementptr inbounds %class.A, ptr [[TMP1]], i32 0, i32 0, | ||
// CHECK: [[CALL:%.*]] = call noundef ptr @{{.*}}foo{{.*}}( | ||
// CHECK-NEXT: [[PSEUDO2:%.*]] = alloca ptr, | ||
// CHECK-NEXT: store ptr [[CALL]], ptr [[PSEUDO2]] | ||
// CHECK-NEXT: call void @llvm.dbg.declare(metadata ptr [[PSEUDO2]], metadata [[META6]], metadata !DIExpression()) | ||
// CHECK-NEXT: [[TMP2:%.*]] = load ptr, ptr [[PSEUDO2]] | ||
// CHECK-NEXT: [[I1:%.*]] = getelementptr inbounds %class.A, ptr [[TMP2]], i32 0, i32 1 | ||
char func4(C *c) { | ||
extern A* foo(int x); | ||
return foo(c->a->i)->c; | ||
} | ||
|
||
// CHECK-LABEL: define dso_local noundef signext i8 @{{.*}}func5{{.*}}( | ||
// CHECK: call void @llvm.dbg.declare(metadata ptr {{%.*}}, metadata [[META7:![0-9]+]], metadata !DIExpression()) | ||
// CHECK: call void @llvm.dbg.declare(metadata ptr {{%.*}}, metadata [[META8:![0-9]+]], metadata !DIExpression()) | ||
// CHECK: [[A_ADDR:%.*]] = getelementptr inbounds %class.A, ptr {{%.*}}, i64 {{%.*}}, | ||
// CHECK-NEXT: [[PSEUDO1:%.*]] = alloca ptr, | ||
// CHECK-NEXT: store ptr [[A_ADDR]], ptr [[PSEUDO1]], | ||
// CHECK-NEXT: call void @llvm.dbg.declare(metadata ptr [[PSEUDO1]], metadata [[META9:![0-9]+]], metadata !DIExpression()) | ||
// CHECK-NEXT: [[TMP1:%.*]] = load ptr, ptr [[PSEUDO1]], | ||
// CHECK-NEXT: {{%.*}} = getelementptr inbounds %class.A, ptr [[TMP1]], i32 0, i32 1, | ||
char func5(void *arr, int n) { | ||
return ((A*)arr)[n].c; | ||
} | ||
|
||
// CHECK-LABEL: define dso_local noundef i32 @{{.*}}func6{{.*}}( | ||
// CHECK: call void @llvm.dbg.declare(metadata ptr {{%.*}}, metadata [[META10:![0-9]+]], metadata !DIExpression()) | ||
// CHECK: call void @llvm.dbg.declare(metadata ptr {{%.*}}, metadata [[META11:![0-9]+]], metadata !DIExpression()) | ||
int func6(B &b) { | ||
return reinterpret_cast<A&>(b).i; | ||
} | ||
|
||
// CHECK-DAG: [[META_A:![0-9]+]] = distinct !DICompositeType(tag: DW_TAG_class_type, name: "A", | ||
// CHECK-DAG: [[META_AP:![0-9]+]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: [[META_A]], | ||
// CHECK-DAG: [[META_B:![0-9]+]] = distinct !DICompositeType(tag: DW_TAG_class_type, name: "B", | ||
// CHECK-DAG: [[META_BP:![0-9]+]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: [[META_B]], | ||
// CHECK-DAG: [[META_C:![0-9]+]] = distinct !DICompositeType(tag: DW_TAG_class_type, name: "C", | ||
// CHECK-DAG: [[META_CP:![0-9]+]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: [[META_C]], | ||
// CHECK-DAG: [[META_VP:![0-9]+]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, | ||
// CHECK-DAG: [[META_I32:![0-9]+]] = !DIBasicType(name: "int", size: 32, | ||
// CHECK-DAG: [[META_BR:![0-9]+]] = !DIDerivedType(tag: DW_TAG_reference_type, baseType: [[META_B]], | ||
|
||
// CHECK-DAG: [[DBG1]] = !DILocation(line: 34, column: 13, | ||
// CHECK-DAG: [[META1]] = !DILocalVariable(scope: {{.*}}, type: [[META_AP]], flags: DIFlagArtificial) | ||
// CHECK-DAG: [[META2]] = !DILocalVariable(name: "b", arg: 1, scope: {{.*}}, file: {{.*}}, line: 46, type: [[META_VP]]) | ||
// CHECK-DAG: [[META3]] = !DILocalVariable(scope: {{.*}}, type: [[META_BP]], flags: DIFlagArtificial) | ||
// CHECK-DAG: [[META4]] = !DILocalVariable(name: "b", arg: 1, scope: {{.*}}, file: {{.*}}, line: 55, type: [[META_BP]]) | ||
// CHECK-DAG: [[META5]] = !DILocalVariable(name: "local1", scope: {{.*}}, file: {{.*}}, line: 56, type: [[META_AP]]) | ||
// CHECK-DAG: [[META6]] = !DILocalVariable(scope: {{.*}}, type: [[META_AP]], flags: DIFlagArtificial) | ||
// CHECK-DAG: [[META7]] = !DILocalVariable(name: "arr", arg: 1, scope: {{.*}}, file: {{.*}}, line: 88, type: [[META_VP]]) | ||
// CHECK-DAG: [[META8]] = !DILocalVariable(name: "n", arg: 2, scope: {{.*}}, file: {{.*}}, line: 88, type: [[META_I32]]) | ||
// CHECK-DAG: [[META9]] = !DILocalVariable(scope: {{.*}}, type: [[META_AP]], flags: DIFlagArtificial) | ||
// CHECK-DAG: [[META10]] = !DILocalVariable(name: "b", arg: 1, scope: {{.*}}, file: {{.*}}, line: 95, type: [[META_BR]]) | ||
// CHECK-DAG: [[META11]] = !DILocalVariable(scope: {{.*}}, type: [[META_AP]], flags: DIFlagArtificial) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.