Skip to content

Commit 885f13a

Browse files
LU-JOHNsys-ce-bb
authored andcommitted
Guard DebugGlobalVariable's usage of Variable field with nonsemantic check (#2322)
Guard placing a DIExpression in SPIR-V's DebugGlobalVariable's Variable field with a nonsemantic check. Signed-off-by: Lu, John <[email protected]> Original commit: KhronosGroup/SPIRV-LLVM-Translator@e329f28
1 parent d80f00f commit 885f13a

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

llvm-spirv/lib/SPIRV/LLVMToSPIRVDbgTran.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1186,7 +1186,7 @@ LLVMToSPIRVDbgTran::transDbgGlobalVariable(const DIGlobalVariable *GV) {
11861186
Ops.push_back(transDbgEntry(StaticMember)->getId());
11871187

11881188
// Check if Ops[VariableIdx] has no information
1189-
if (Ops[VariableIdx] == getDebugInfoNoneId()) {
1189+
if (isNonSemanticDebugInfo() && Ops[VariableIdx] == getDebugInfoNoneId()) {
11901190
// Check if GV has an associated GVE with a non-empty DIExpression.
11911191
// The non-empty DIExpression gives the initial value of the GV.
11921192
for (const DIGlobalVariableExpression *GVE : DIF.global_variables()) {

llvm-spirv/test/DebugInfo/DebugInfo-GV-with-DIE.ll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
;; Ensure that DIExpressions are preserved in DIGlobalVariableExpressions
2+
;; if nonsemantic debug info is enabled.
23
;; This utilizes SPIRV DebugGlobalVariable's Variable field to hold the
34
;; DIExpression.
45

@@ -24,6 +25,14 @@
2425
; CHECK-LLVM: ![[#]] = !DIGlobalVariableExpression(var: ![[#GV:]], expr: !DIExpression(DW_OP_constu, 1, DW_OP_stack_value))
2526
; CHECK-LLVM: ![[#GV]] = distinct !DIGlobalVariable(name: "true", scope: ![[#]], file: ![[#]], line: 3777, type: ![[#]], isLocal: true, isDefinition: true)
2627

28+
;; Ensure SPIR-V DebugGlobalVariable's Variable field does not hold a DIExpression if nonsemantic debug info is not enabled
29+
30+
; RUN: llvm-spirv -o %t.spt %t.bc -spirv-text
31+
; RUN: FileCheck %s --input-file %t.spt --check-prefix CHECK-NONE-SPIRV
32+
33+
; CHECK-NONE-SPIRV: [[DEBUG_INFO_NONE:[0-9]+]] [[#]] DebugInfoNone
34+
; CHECK-NONE-SPIRV: [[#]] [[#]] DebugGlobalVariable [[#]] [[#]] [[#]] [[#]] [[#]] [[#]] [[#]] [[DEBUG_INFO_NONE]] [[#]] {{$}}
35+
2736
!llvm.module.flags = !{!0, !1}
2837
!llvm.dbg.cu = !{!2}
2938

llvm-spirv/test/DebugInfo/DebugInfo-GV-with-SMD-and-DIE.ll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
;; Ensure that DIExpressions are preserved in DIGlobalVariableExpressions
2+
;; if nonsemantic debug info is enabled
23
;; when a Static Member Declaration is also needed.
34
;; This utilizes SPIRV DebugGlobalVariable's Variable field to hold the
45
;; DIExpression.
@@ -38,6 +39,15 @@
3839
; CHECK-LLVM: ![[#ELEMENTS]] = !{![[#DECLARATION]]}
3940
; CHECK-LLVM: ![[#BASETYPE]] = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
4041

42+
;; Ensure SPIR-V DebugGlobalVariable's Variable field does not hold a DIExpression if nonsemantic debug info is not enabled
43+
44+
; RUN: llvm-spirv -o %t.spt %t.bc -spirv-text
45+
; RUN: FileCheck %s --input-file %t.spt --check-prefix CHECK-NONE-SPIRV
46+
47+
; CHECK-NONE-SPIRV-DAG: [[TYPE_MEMBER:[0-9]+]] [[#]] DebugTypeMember [[#]] [[#]] [[#]] [[#]]
48+
; CHECK-NONE-SPIRV-DAG: [[DEBUG_INFO_NONE:[0-9]+]] [[#]] DebugInfoNone
49+
; CHECK-NONE-SPIRV: [[#]] [[#]] DebugGlobalVariable [[#]] [[#]] [[#]] [[#]] [[#]] [[#]] [[#]] [[DEBUG_INFO_NONE]] [[#]] [[TYPE_MEMBER]] {{$}}
50+
4151
!llvm.module.flags = !{!0, !1}
4252
!llvm.dbg.cu = !{!2}
4353

0 commit comments

Comments
 (0)