Skip to content

Commit 070d0d5

Browse files
[SPIRV] Correct local variable declaration scope (microsoft#7046)
Recent changes to the debug information generated by the wrapper function lacked one fix. This produced mismatches between function parameter DebugLocalVariable's and DebugDeclare instructions. Following wrapper generation, the DebugScope should be set to src_main, not the wrapper. This PR corrects this oversight.
1 parent d6d0b45 commit 070d0d5

8 files changed

+41
-38
lines changed

tools/clang/lib/SPIRV/SpirvEmitter.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1487,7 +1487,11 @@ void SpirvEmitter::doFunctionDecl(const FunctionDecl *decl) {
14871487
}
14881488

14891489
if (spirvOptions.debugInfoRich) {
1490-
spvContext.pushDebugLexicalScope(info, debugFunction);
1490+
if (srcDebugFunction) {
1491+
spvContext.pushDebugLexicalScope(info, srcDebugFunction);
1492+
} else {
1493+
spvContext.pushDebugLexicalScope(info, debugFunction);
1494+
}
14911495
}
14921496

14931497
const QualType retType =

tools/clang/test/CodeGenSPIRV/rich.debug.debugscope.hlsl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22

33
// CHECK: [[set:%[0-9]+]] = OpExtInstImport "OpenCL.DebugInfo.100"
44
// CHECK: [[compUnit:%[0-9]+]] = OpExtInst %void [[set]] DebugCompilationUnit
5-
// CHECK: [[main:%[0-9]+]] = OpExtInst %void [[set]] DebugFunction
6-
// CHECK: [[mainFnLexBlock:%[0-9]+]] = OpExtInst %void [[set]] DebugLexicalBlock {{%[0-9]+}} 17 1 [[main]]
7-
// CHECK: [[whileLoopLexBlock:%[0-9]+]] = OpExtInst %void [[set]] DebugLexicalBlock {{%[0-9]+}} 37 3 [[mainFnLexBlock]]
5+
// CHECK: [[srcMain:%[0-9]+]] = OpExtInst %void [[set]] DebugFunction
6+
// CHECK: [[srcMainFnLexBlock:%[0-9]+]] = OpExtInst %void [[set]] DebugLexicalBlock {{%[0-9]+}} 17 1 [[srcMain]]
7+
// CHECK: [[whileLoopLexBlock:%[0-9]+]] = OpExtInst %void [[set]] DebugLexicalBlock {{%[0-9]+}} 37 3 [[srcMainFnLexBlock]]
88
// CHECK: [[ifStmtLexBlock:%[0-9]+]] = OpExtInst %void [[set]] DebugLexicalBlock {{%[0-9]+}} 44 20 [[whileLoopLexBlock]]
99
// CHECK: [[tempLexBlock:%[0-9]+]] = OpExtInst %void [[set]] DebugLexicalBlock {{%[0-9]+}} 49 7 [[ifStmtLexBlock]]
10-
// CHECK: [[forLoopLexBlock:%[0-9]+]] = OpExtInst %void [[set]] DebugLexicalBlock {{%[0-9]+}} 22 12 [[mainFnLexBlock]]
11-
// CHECK: [[srcMain:%[0-9]+]] = OpExtInst %void [[set]] DebugFunction
10+
// CHECK: [[forLoopLexBlock:%[0-9]+]] = OpExtInst %void [[set]] DebugLexicalBlock {{%[0-9]+}} 22 12 [[srcMainFnLexBlock]]
11+
// CHECK: [[main:%[0-9]+]] = OpExtInst %void [[set]] DebugFunction
1212

1313
float4 main(float4 color : COLOR) : SV_TARGET
1414
// CHECK: %main = OpFunction
1515
// CHECK: %src_main = OpFunction
1616
// CHECK-NEXT: {{%[0-9]+}} = OpExtInst %void [[set]] DebugScope [[srcMain]]
1717
{
1818
// CHECK: %bb_entry = OpLabel
19-
// CHECK-NEXT: {{%[0-9]+}} = OpExtInst %void [[set]] DebugScope [[mainFnLexBlock]]
19+
// CHECK-NEXT: {{%[0-9]+}} = OpExtInst %void [[set]] DebugScope [[srcMainFnLexBlock]]
2020

2121
float4 c = 0.xxxx;
2222
for (;;) {
@@ -26,13 +26,13 @@ float4 main(float4 color : COLOR) : SV_TARGET
2626
float4 b = 1.xxxx;
2727
c = c + a + b;
2828
// CHECK: %for_continue = OpLabel
29-
// CHECK-NEXT: {{%[0-9]+}} = OpExtInst %void [[set]] DebugScope [[mainFnLexBlock]]
29+
// CHECK-NEXT: {{%[0-9]+}} = OpExtInst %void [[set]] DebugScope [[srcMainFnLexBlock]]
3030
}
3131
// CHECK: %for_merge = OpLabel
32-
// CHECK-NEXT: {{%[0-9]+}} = OpExtInst %void [[set]] DebugScope [[mainFnLexBlock]]
32+
// CHECK-NEXT: {{%[0-9]+}} = OpExtInst %void [[set]] DebugScope [[srcMainFnLexBlock]]
3333

3434
// CHECK: %while_check = OpLabel
35-
// CHECK-NEXT: {{%[0-9]+}} = OpExtInst %void [[set]] DebugScope [[mainFnLexBlock]]
35+
// CHECK-NEXT: {{%[0-9]+}} = OpExtInst %void [[set]] DebugScope [[srcMainFnLexBlock]]
3636
while (c.x)
3737
{
3838
// CHECK: %while_body = OpLabel
@@ -54,10 +54,10 @@ float4 main(float4 color : COLOR) : SV_TARGET
5454
// CHECK-NEXT: {{%[0-9]+}} = OpExtInst %void [[set]] DebugScope [[whileLoopLexBlock]]
5555

5656
// CHECK:%while_continue = OpLabel
57-
// CHECK-NEXT: {{%[0-9]+}} = OpExtInst %void [[set]] DebugScope [[mainFnLexBlock]]
57+
// CHECK-NEXT: {{%[0-9]+}} = OpExtInst %void [[set]] DebugScope [[srcMainFnLexBlock]]
5858
}
5959
// CHECK: %while_merge = OpLabel
60-
// CHECK-NEXT: {{%[0-9]+}} = OpExtInst %void [[set]] DebugScope [[mainFnLexBlock]]
60+
// CHECK-NEXT: {{%[0-9]+}} = OpExtInst %void [[set]] DebugScope [[srcMainFnLexBlock]]
6161

6262
return color + c;
6363
}

tools/clang/test/CodeGenSPIRV/rich.debug.function.param.hlsl

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,20 @@
77
// CHECK: [[emptyStr:%[0-9]+]] = OpString ""
88
// CHECK: [[y:%[0-9]+]] = OpString "y"
99
// CHECK: [[x:%[0-9]+]] = OpString "x"
10-
// CHECK: [[mainName:%[0-9]+]] = OpString "wrapper"
11-
// CHECK: [[color:%[0-9]+]] = OpString "color"
1210
// CHECK: [[srcMainName:%[0-9]+]] = OpString "main"
11+
// CHECK: [[color:%[0-9]+]] = OpString "color"
12+
// CHECK: [[mainName:%[0-9]+]] = OpString "wrapper"
1313

1414
// CHECK: [[int:%[0-9]+]] = OpExtInst %void [[set]] DebugTypeBasic {{%[0-9]+}} %uint_32 Signed
1515
// CHECK: [[float:%[0-9]+]] = OpExtInst %void [[set]] DebugTypeBasic {{%[0-9]+}} %uint_32 Float
1616
// CHECK: [[source:%[0-9]+]] = OpExtInst %void [[set]] DebugSource
17-
// CHECK: [[foo:%[0-9]+]] = OpExtInst %void [[set]] DebugFunction [[fooName]] {{%[0-9]+}} [[source]] 25 1 {{%[0-9]+}} [[emptyStr]] FlagIsProtected|FlagIsPrivate 26 %foo
18-
// CHECK: {{%[0-9]+}} = OpExtInst %void [[set]] DebugLocalVariable [[y]] [[float]] [[source]] 25 23 [[foo]] FlagIsLocal 2
19-
// CHECK: {{%[0-9]+}} = OpExtInst %void [[set]] DebugLocalVariable [[x]] [[int]] [[source]] 25 14 [[foo]] FlagIsLocal 1
20-
// CHECK: [[srcMain:%[0-9]+]] = OpExtInst %void [[set]] DebugFunction [[mainName]] {{%[0-9]+}} [[source]] 30 1 {{%[0-9]+}} [[emptyStr]] FlagIsProtected|FlagIsPrivate 31 %main
17+
// CHECK: [[foo:%[0-9]+]] = OpExtInst %void [[set]] DebugFunction [[fooName]] {{%[0-9]+}} [[source]] 24 1 {{%[0-9]+}} [[emptyStr]] FlagIsProtected|FlagIsPrivate 25 %foo
18+
// CHECK: {{%[0-9]+}} = OpExtInst %void [[set]] DebugLocalVariable [[y]] [[float]] [[source]] 24 23 [[foo]] FlagIsLocal 2
19+
// CHECK: {{%[0-9]+}} = OpExtInst %void [[set]] DebugLocalVariable [[x]] [[int]] [[source]] 24 14 [[foo]] FlagIsLocal 1
2120
// CHECK: [[float4:%[0-9]+]] = OpExtInst %void [[set]] DebugTypeVector [[float]] 4
22-
// CHECK: {{%[0-9]+}} = OpExtInst %void [[set]] DebugLocalVariable [[color]] [[float4]] [[source]] 30 20 [[srcMain]] FlagIsLocal 1
23-
// CHECK: [[main:%[0-9]+]] = OpExtInst %void [[set]] DebugFunction [[srcMainName]] {{%[0-9]+}} [[source]] 30 1 {{%[0-9]+}} [[emptyStr]] FlagIsProtected|FlagIsPrivate 31 %src_main
24-
21+
// CHECK: [[srcMain:%[0-9]+]] = OpExtInst %void [[set]] DebugFunction [[srcMainName]] {{%[0-9]+}} [[source]] 29 1 {{%[0-9]+}} [[emptyStr]] FlagIsProtected|FlagIsPrivate 30 %src_main
22+
// CHECK: {{%[0-9]+}} = OpExtInst %void [[set]] DebugLocalVariable [[color]] [[float4]] [[source]] 29 20 [[srcMain]] FlagIsLocal 1
23+
// CHECK: [[main:%[0-9]+]] = OpExtInst %void [[set]] DebugFunction [[mainName]] {{%[0-9]+}} [[source]] 29 1 {{%[0-9]+}} [[emptyStr]] FlagIsProtected|FlagIsPrivate 30 %main
2524
void foo(int x, float y)
2625
{
2726
x = x + y;

tools/clang/test/CodeGenSPIRV/rich.debug.global-variable.hlsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
// CHECK: [[varNameCond:%[0-9]+]] = OpString "cond"
55
// CHECK: [[varNameC:%[0-9]+]] = OpString "c"
66

7-
// CHECK: [[source:%[0-9]+]] = OpExtInst %void [[set]] DebugSource
8-
// CHECK: [[compileUnit:%[0-9]+]] = OpExtInst %void [[set]] DebugCompilationUnit 1 4 [[source]] HLSL
97
// CHECK: [[floatType:%[0-9]+]] = OpExtInst %void [[set]] DebugTypeBasic {{%[0-9]+}} %uint_32 Float
108
// CHECK: [[float4Type:%[0-9]+]] = OpExtInst %void [[set]] DebugTypeVector [[floatType]] 4
9+
// CHECK: [[source:%[0-9]+]] = OpExtInst %void [[set]] DebugSource
10+
// CHECK: [[compileUnit:%[0-9]+]] = OpExtInst %void [[set]] DebugCompilationUnit 1 4 [[source]] HLSL
1111
// CHECK: [[boolType:%[0-9]+]] = OpExtInst %void [[set]] DebugTypeBasic {{%[0-9]+}} %uint_32 Boolean
1212

1313
// CHECK: {{%[0-9]+}} = OpExtInst %void [[set]] DebugGlobalVariable [[varNameCond]] [[boolType]] [[source]] 17 13 [[compileUnit]] [[varNameCond]] %cond FlagIsDefinition

tools/clang/test/CodeGenSPIRV/rich.debug.local-variable.hlsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
// CHECK: [[varNameC:%[0-9]+]] = OpString "c"
88

99
// CHECK: [[uintType:%[0-9]+]] = OpExtInst %void [[set]] DebugTypeBasic {{%[0-9]+}} %uint_32 Unsigned
10+
// CHECK: [[floatType:%[0-9]+]] = OpExtInst %void [[set]] DebugTypeBasic {{%[0-9]+}} %uint_32 Float
11+
// CHECK: [[float4Type:%[0-9]+]] = OpExtInst %void [[set]] DebugTypeVector [[floatType]] 4
1012
// CHECK: [[source:%[0-9]+]] = OpExtInst %void [[set]] DebugSource
1113
// CHECK: [[compileUnit:%[0-9]+]] = OpExtInst %void [[set]] DebugCompilationUnit 1 4 [[source]] HLSL
1214
// CHECK: [[main:%[0-9]+]] = OpExtInst %void [[set]] DebugFunction
@@ -23,8 +25,6 @@
2325
// CHECK: [[boolType:%[0-9]+]] = OpExtInst %void [[set]] DebugTypeBasic {{%[0-9]+}} %uint_32 Boolean
2426
// CHECK: {{%[0-9]+}} = OpExtInst %void [[set]] DebugLocalVariable [[varNameCond]] [[boolType]] [[source]] 34 8 [[mainFnLexBlock]] FlagIsLocal
2527

26-
// CHECK: [[floatType:%[0-9]+]] = OpExtInst %void [[set]] DebugTypeBasic {{%[0-9]+}} %uint_32 Float
27-
// CHECK: [[float4Type:%[0-9]+]] = OpExtInst %void [[set]] DebugTypeVector [[floatType]] 4
2828
// CHECK: {{%[0-9]+}} = OpExtInst %void [[set]] DebugLocalVariable [[varNameC]] [[float4Type]] [[source]] 33 10 [[mainFnLexBlock]] FlagIsLocal
2929

3030

tools/clang/test/CodeGenSPIRV/rich.debug.type.float.hlsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
// CHECK: [[set:%[0-9]+]] = OpExtInstImport "OpenCL.DebugInfo.100"
44
// CHECK: [[float64Name:%[0-9]+]] = OpString "float64_t"
5-
// CHECK: [[float16Name:%[0-9]+]] = OpString "float16_t"
65
// CHECK: [[floatName:%[0-9]+]] = OpString "float"
6+
// CHECK: [[float16Name:%[0-9]+]] = OpString "float16_t"
77
// CHECK: {{%[0-9]+}} = OpExtInst %void [[set]] DebugTypeBasic [[float64Name]] %uint_64 Float
8-
// CHECK: {{%[0-9]+}} = OpExtInst %void [[set]] DebugTypeBasic [[float16Name]] %uint_16 Float
98
// CHECK: {{%[0-9]+}} = OpExtInst %void [[set]] DebugTypeBasic [[floatName]] %uint_32 Float
9+
// CHECK: {{%[0-9]+}} = OpExtInst %void [[set]] DebugTypeBasic [[float16Name]] %uint_16 Float
1010

1111
float4 main(float4 color : COLOR) : SV_TARGET {
1212
float a = 0;

tools/clang/test/CodeGenSPIRV/rich.debug.vulkan.member.function.param.hlsl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,34 @@
1515
// CHECK-DAG: [[strFoo:%[0-9]+]] = OpString "foo"
1616
// CHECK-DAG: [[strFunc1:%[0-9]+]] = OpString "foo.func1"
1717

18+
1819
// CHECK: [[int:%[0-9]+]] = OpExtInst %void [[set]] DebugTypeBasic [[strInt]] %uint_32 %uint_4 %uint_0
1920
// CHECK: [[unit:%[0-9]+]] = OpExtInst %void [[set]] DebugCompilationUnit %uint_1 %uint_4 {{%[0-9]+}} %uint_5
2021

2122
struct foo {
2223

23-
// CHECK: [[a:%[0-9]+]] = OpExtInst %void [[set]] DebugTypeMember [[strA]] [[int]] {{%[0-9]+}} %uint_24 %uint_7 %uint_0 %uint_32 %uint_3
24+
// CHECK: [[a:%[0-9]+]] = OpExtInst %void [[set]] DebugTypeMember [[strA]] [[int]] {{%[0-9]+}} %uint_25 %uint_7 %uint_0 %uint_32 %uint_3
2425
int a;
2526

2627
// CHECK: [[float:%[0-9]+]] = OpExtInst %void [[set]] DebugTypeBasic [[strFloat]] %uint_32 %uint_3 %uint_0
2728
// CHECK: [[v4f:%[0-9]+]] = OpExtInst %void [[set]] DebugTypeVector [[float]] %uint_4
28-
// CHECK: [[b:%[0-9]+]] = OpExtInst %void [[set]] DebugTypeMember [[strB]] [[v4f]] {{%[0-9]+}} %uint_29 %uint_10 %uint_32 %uint_128 %uint_3
29+
// CHECK: [[b:%[0-9]+]] = OpExtInst %void [[set]] DebugTypeMember [[strB]] [[v4f]] {{%[0-9]+}} %uint_30 %uint_10 %uint_32 %uint_128 %uint_3
2930
float4 b;
3031

3132
// CHECK: [[bool:%[0-9]+]] = OpExtInst %void [[set]] DebugTypeBasic [[strBool]] %uint_32 %uint_2 %uint_0
32-
// CHECK: [[c:%[0-9]+]] = OpExtInst %void [[set]] DebugTypeMember [[strC]] [[bool]] {{%[0-9]+}} %uint_33 %uint_8 %uint_160 %uint_32 %uint_3
33+
// CHECK: [[c:%[0-9]+]] = OpExtInst %void [[set]] DebugTypeMember [[strC]] [[bool]] {{%[0-9]+}} %uint_34 %uint_8 %uint_160 %uint_32 %uint_3
3334
bool c;
3435

35-
// CHECK: [[func0t:%[0-9]+]] = OpExtInstWithForwardRefsKHR %void [[set]] DebugTypeFunction %uint_3 %void [[foo:%[0-9]+]] {{%[0-9]+}}
36-
// CHECK: [[func0:%[0-9]+]] = OpExtInstWithForwardRefsKHR %void [[set]] DebugFunction [[strFunc0]] [[func0t]] {{%[0-9]+}} %uint_39 %uint_3 [[foo]] {{%[0-9]+}} %uint_3 %uint_39
37-
// CHECK: [[foo]] = OpExtInstWithForwardRefsKHR %void [[set]] DebugTypeComposite [[strFoo]] %uint_1 {{%[0-9]+}} %uint_21 %uint_8 [[unit]] [[strFoo]] %uint_192 %uint_3 [[a]] [[b]] [[c]] [[func0]] [[func1:%[0-9]+]]
38-
3936
void func0(float arg) {
4037
b.x = arg;
4138
}
4239

40+
// CHECK: [[func0t:%[0-9]+]] = OpExtInstWithForwardRefsKHR %void [[set]] DebugTypeFunction %uint_3 %void [[foo:%[0-9]+]] {{%[0-9]+}}
41+
// CHECK: [[func0:%[0-9]+]] = OpExtInstWithForwardRefsKHR %void [[set]] DebugFunction [[strFunc0]] [[func0t]] {{%[0-9]+}} %uint_36 %uint_3 [[foo]] {{%[0-9]+}} %uint_3 %uint_36
42+
// CHECK: [[foo]] = OpExtInstWithForwardRefsKHR %void [[set]] DebugTypeComposite [[strFoo]] %uint_1 {{%[0-9]+}} %uint_22 %uint_8 [[unit:%[0-9]+]] [[strFoo]] %uint_192 %uint_3 [[a:%[0-9]+]] [[b:%[0-9]+]] [[c:%[0-9]+]] [[func0]] [[func1:%[0-9]+]]
4343

4444
// CHECK: [[func1t:%[0-9]+]] = OpExtInst %void [[set]] DebugTypeFunction %uint_3 [[int]] [[foo:%[0-9]+]] [[int]] [[float]] [[bool]]
45-
// CHECK: [[func1]] = OpExtInst %void [[set]] DebugFunction [[strFunc1]] [[func1t]] {{%[0-9]+}} %uint_46 %uint_3 [[foo]] {{%[0-9]+}} %uint_3 %uint_46
45+
// CHECK: [[func1:%[0-9]+]] = OpExtInst %void [[set]] DebugFunction [[strFunc1]] [[func1t]] {{%[0-9]+}} %uint_46 %uint_3 [[foo]] {{%[0-9]+}} %uint_3 %uint_46
4646
int func1(int arg0, float arg1, bool arg2) {
4747
a = arg0;
4848
b.y = arg1;

tools/clang/test/CodeGenSPIRV/shader.debug.function.hlsl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
// CHECK: [[set:%[0-9]+]] = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
66
// CHECK: [[fooName:%[0-9]+]] = OpString "foo"
77
// CHECK: [[emptyStr:%[0-9]+]] = OpString ""
8+
// CHECK: [[srcMainName:%[0-9]+]] = OpString "main"
89
// CHECK: [[mainName:%[0-9]+]] = OpString "wrapper"
910
// CHECK: [[clOpts:%[0-9]+]] = OpString " -E main -T ps_6_0 -spirv -fcgl -fspv-debug=vulkan
10-
// CHECK: [[srcMainName:%[0-9]+]] = OpString "main"
1111

1212
// CHECK: [[int:%[0-9]+]] = OpExtInst %void [[set]] DebugTypeBasic {{%[0-9]+}} %uint_32 %uint_4 %uint_0
1313
// CHECK: [[float:%[0-9]+]] = OpExtInst %void [[set]] DebugTypeBasic {{%[0-9]+}} %uint_32 %uint_3 %uint_0
@@ -18,11 +18,11 @@
1818

1919
// Check DebugFunction instructions
2020
//
21-
// CHECK: [[mainFnType:%[0-9]+]] = OpExtInst %void [[set]] DebugTypeFunction %uint_3 %void
22-
// CHECK: [[mainDbgFn:%[0-9]+]] = OpExtInst %void [[set]] DebugFunction [[mainName]] [[mainFnType]] [[source]] %uint_46 %uint_1 [[compilationUnit]] [[emptyStr]] %uint_3 %uint_47
2321
// CHECK: [[float4:%[0-9]+]] = OpExtInst %void [[set]] DebugTypeVector [[float]] %uint_4
2422
// CHECK: [[srcMainFnType:%[0-9]+]] = OpExtInst %void [[set]] DebugTypeFunction %uint_3 [[float4]] [[float4]]
2523
// CHECK: [[srcMainDbgFn:%[0-9]+]] = OpExtInst %void [[set]] DebugFunction [[srcMainName]] [[srcMainFnType]] [[source]] %uint_46 %uint_1 [[compilationUnit]] [[emptyStr]] %uint_3 %uint_47
24+
// CHECK: [[mainFnType:%[0-9]+]] = OpExtInst %void [[set]] DebugTypeFunction %uint_3 %void
25+
// CHECK: [[mainDbgFn:%[0-9]+]] = OpExtInst %void [[set]] DebugFunction [[mainName]] [[mainFnType]] [[source]] %uint_46 %uint_1 [[compilationUnit]] [[emptyStr]] %uint_3 %uint_47
2626
// CHECK: [[mainDbgEp:%[0-9]+]] = OpExtInst %void [[set]] DebugEntryPoint [[mainDbgFn]] [[compilationUnit]] {{%[0-9]+}} [[clOpts]]
2727

2828
// Check DebugFunctionDefinition is in main

0 commit comments

Comments
 (0)