-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[DebugInfo] getMergedLocation: match scopes based on their location #132286
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
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e655d17
[DebugInfo] getMergedLocation: match scopes based on their location
dzhidzhoev 444f5ad
Use std::pair instead of std::tuple
dzhidzhoev 193b071
Reduced *.ll tests.
dzhidzhoev cc6ec66
Reduce merge-nested-block-loc.ll
dzhidzhoev 1004659
Fix test comment
dzhidzhoev 9f51ebf
Next iteration of the algorithm
dzhidzhoev 326dd47
Remove GetLocForBlockFile
dzhidzhoev 4734fd7
Cleanup MetadataTest
dzhidzhoev 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
; RUN: opt -mtriple=aarch64-unknown-linux-gnu -S %s -passes=sroa -o - | FileCheck %s | ||
|
||
; In this test we want to ensure that the merged location of phi instruction | ||
; belongs to the correct scope (DILexicalBlockFile), so that line number | ||
; of that location belongs to the corresponding file. | ||
|
||
; Generated with clang from | ||
; # 1 "1.c" 1 | ||
; # 1 "1.c" 2 | ||
; int foo(int a) { | ||
; int i = 0; | ||
; if ((a & 1) == 1) { | ||
; a -= 1; | ||
; # 1 "m.c" 1 | ||
; # 40 "m.c" | ||
; i += a; | ||
; i -= 10*a; | ||
; i *= a*a; | ||
; # 6 "1.c" 2 | ||
; } else { | ||
; a += 3; | ||
; # 1 "m.c" 1 | ||
; # 40 "m.c" | ||
; i += a; | ||
; i -= 10*a; | ||
; i *= a*a; | ||
; # 9 "1.c" 2 | ||
; } | ||
; return i; | ||
; } | ||
|
||
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32" | ||
target triple = "aarch64-unknown-linux-gnu" | ||
|
||
define i32 @foo() !dbg !3 { | ||
; CHECK: phi i32 {{.*}}, !dbg [[PHILOC:![0-9]+]] | ||
; | ||
entry: | ||
%i = alloca i32, align 4 | ||
br i1 false, label %if.then, label %if.else | ||
|
||
if.then: ; preds = %entry | ||
store i32 1, ptr %i, align 4, !dbg !7 | ||
br label %if.end | ||
|
||
if.else: ; preds = %entry | ||
store i32 0, ptr %i, align 4, !dbg !12 | ||
br label %if.end | ||
|
||
if.end: ; preds = %if.else, %if.then | ||
%0 = load i32, ptr %i, align 4 | ||
ret i32 0 | ||
} | ||
|
||
!llvm.dbg.cu = !{!0} | ||
!llvm.module.flags = !{!2} | ||
|
||
!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang version 21.0.0git", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None) | ||
!1 = !DIFile(filename: "repro.c", directory: "") | ||
!2 = !{i32 2, !"Debug Info Version", i32 3} | ||
!3 = distinct !DISubprogram(name: "foo", scope: !4, file: !4, line: 1, type: !5, scopeLine: 1, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !6) | ||
!4 = !DIFile(filename: "1.c", directory: "") | ||
!5 = !DISubroutineType(types: !6) | ||
!6 = !{} | ||
!7 = !DILocation(line: 42, column: 3, scope: !8) | ||
!8 = !DILexicalBlockFile(scope: !10, file: !9, discriminator: 0) | ||
!9 = !DIFile(filename: "m.c", directory: "") | ||
!10 = distinct !DILexicalBlock(scope: !11, file: !4, line: 3, column: 21) | ||
!11 = distinct !DILexicalBlock(scope: !3, file: !4, line: 3, column: 7) | ||
!12 = !DILocation(line: 42, column: 3, scope: !13) | ||
!13 = !DILexicalBlockFile(scope: !14, file: !9, discriminator: 0) | ||
!14 = distinct !DILexicalBlock(scope: !11, file: !4, line: 6, column: 9) | ||
|
||
; CHECK: [[SP:![0-9]+]] = distinct !DISubprogram(name: "foo", scope: [[FILE1:![0-9]+]], file: [[FILE1]], line: 1 | ||
; CHECK: [[FILE1]] = !DIFile(filename: "1.c", directory: "") | ||
; CHECK: [[PHILOC]] = !DILocation(line: 42, column: 3, scope: [[LBF:![0-9]+]]) | ||
; CHECK: [[LBF]] = !DILexicalBlockFile(scope: [[LB:![0-9]+]], file: [[FILE2:![0-9]+]], discriminator: 0) | ||
; CHECK: [[FILE2]] = !DIFile(filename: "m.c", directory: "") | ||
; CHECK: [[LB]] = distinct !DILexicalBlock(scope: [[SP]], file: [[FILE1]], line: 3, column: 7) |
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,130 @@ | ||
; RUN: opt -mtriple=aarch64-unknown-linux-gnu -S %s -passes=sroa -o - | FileCheck %s | ||
|
||
; In this test we want to ensure that getMergedLocations uses common include | ||
; location if incoming locations belong to different files. | ||
; The location of phi instruction merged from locations of %mul3 and %mul10 | ||
; should be the location of do-loop lexical block from y.c. | ||
|
||
; Generated with clang from | ||
; | ||
; main.c: | ||
; int foo(int a) { | ||
; int i = 0; | ||
; if ((a & 1) == 1) { | ||
; a -= 1; | ||
; #define A | ||
; #include "y.c" | ||
; } else { | ||
; a += 3; | ||
; #undef A | ||
; #include "y.c" | ||
; } | ||
; return i; | ||
; } | ||
; | ||
; y.c: | ||
; # 300 "y.c" 1 | ||
; do { | ||
; #ifdef A | ||
; #include "z1.c" | ||
; #else | ||
; #include "z2.c" | ||
; #endif | ||
; } while (0); | ||
; | ||
; z1.c: | ||
; # 100 "z1.c" 1 | ||
; i += a; | ||
; i -= 10*a; | ||
; i *= a*a; | ||
; | ||
; z2.c: | ||
; # 200 "z1.c" 1 | ||
; i += a; | ||
; i -= 10*a; | ||
; i *= a*a; | ||
; | ||
; Preprocessed source: | ||
; | ||
; # 1 "main.c" | ||
; int foo(int a) { | ||
; int i = 0; | ||
; if ((a & 1) == 1) { | ||
; a -= 1; | ||
; # 300 "y.c" 1 | ||
; do { | ||
; # 100 "z1.c" 1 | ||
; i += a; | ||
; i -= 10*a; | ||
; i *= a*a; | ||
; # 303 "y.c" 2 | ||
; } while (0); | ||
; # 7 "main.c" 2 | ||
; } else { | ||
; a += 3; | ||
; # 300 "y.c" 1 | ||
; do { | ||
; # 200 "z2.c" 1 | ||
; i += a; | ||
; i -= 10*a; | ||
; i *= a*a; | ||
; # 305 "y.c" 2 | ||
; } while (0); | ||
; # 11 "main.c" 2 | ||
; } | ||
; return i; | ||
; } | ||
|
||
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-n32:64-S128-Fn32" | ||
target triple = "arm64-apple-macosx15.0.0" | ||
|
||
define i32 @foo() !dbg !3 { | ||
; CHECK: phi i32 {{.*}}, !dbg [[PHILOC:![0-9]+]] | ||
; | ||
entry: | ||
%i = alloca i32, align 4 | ||
br i1 false, label %do.body, label %if.else | ||
|
||
do.body: ; preds = %entry | ||
store i32 1, ptr %i, align 4, !dbg !6 | ||
br label %if.end | ||
|
||
if.else: ; preds = %entry | ||
store i32 0, ptr %i, align 4, !dbg !14 | ||
br label %if.end | ||
|
||
if.end: ; preds = %if.else, %do.body | ||
%0 = load i32, ptr %i, align 4 | ||
ret i32 0 | ||
} | ||
|
||
!llvm.dbg.cu = !{!0} | ||
!llvm.module.flags = !{!2} | ||
|
||
!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang version 21.0.0git", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: Apple, sysroot: "/") | ||
!1 = !DIFile(filename: "main.c", directory: "") | ||
!2 = !{i32 2, !"Debug Info Version", i32 3} | ||
!3 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 1, type: !4, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !5) | ||
!4 = !DISubroutineType(types: !5) | ||
!5 = !{} | ||
!6 = !DILocation(line: 102, column: 3, scope: !7) | ||
!7 = !DILexicalBlockFile(scope: !9, file: !8, discriminator: 0) | ||
!8 = !DIFile(filename: "z1.c", directory: "") | ||
!9 = distinct !DILexicalBlock(scope: !11, file: !10, line: 300, column: 4) | ||
!10 = !DIFile(filename: "y.c", directory: "") | ||
!11 = !DILexicalBlockFile(scope: !12, file: !10, discriminator: 0) | ||
!12 = distinct !DILexicalBlock(scope: !13, file: !1, line: 3, column: 21) | ||
!13 = distinct !DILexicalBlock(scope: !3, file: !1, line: 3, column: 7) | ||
!14 = !DILocation(line: 202, column: 3, scope: !15) | ||
!15 = !DILexicalBlockFile(scope: !17, file: !16, discriminator: 0) | ||
!16 = !DIFile(filename: "z2.c", directory: "") | ||
!17 = distinct !DILexicalBlock(scope: !18, file: !10, line: 300, column: 4) | ||
!18 = !DILexicalBlockFile(scope: !19, file: !10, discriminator: 0) | ||
!19 = distinct !DILexicalBlock(scope: !13, file: !1, line: 7, column: 9) | ||
|
||
; CHECK: [[FILE_MAIN:![0-9]+]] = !DIFile(filename: "main.c" | ||
; CHECK: [[SP:![0-9]+]] = distinct !DISubprogram(name: "foo", scope: [[FILE_MAIN]], file: [[FILE_MAIN]], line: 1 | ||
; CHECK: [[PHILOC]] = !DILocation(line: 300, column: 4, scope: [[BLOCK_Y:![0-9]+]]) | ||
; CHECK-NEXT: [[BLOCK_Y]] = !DILexicalBlock(scope: [[BLOCK_MAIN:![0-9]+]], file: [[FILE_Y:![0-9]+]], line: 300, column: 4) | ||
; CHECK-NEXT: [[FILE_Y]] = !DIFile(filename: "y.c" | ||
; CHECK: [[BLOCK_MAIN]] = distinct !DILexicalBlock(scope: [[SP]], file: [[FILE_MAIN]], line: 3, column: 7) |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can imagine a small optimization where for this second search, we cap the search up through
L1
's scope chain atScope
, i.e. we never consider any parent scopes ofScope
; but that's a minor point that may not be worth making the code less legible for and this patch doesn't noticeably affect performance, so it's not necessary to merge this.