Skip to content

Commit

Permalink
Guard DebugGlobalVariable's usage of Variable field with nonsemantic …
Browse files Browse the repository at this point in the history
…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]>
  • Loading branch information
LU-JOHN authored Feb 1, 2024
1 parent a1b1f49 commit e329f28
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/SPIRV/LLVMToSPIRVDbgTran.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,7 @@ LLVMToSPIRVDbgTran::transDbgGlobalVariable(const DIGlobalVariable *GV) {
Ops.push_back(transDbgEntry(StaticMember)->getId());

// Check if Ops[VariableIdx] has no information
if (Ops[VariableIdx] == getDebugInfoNoneId()) {
if (isNonSemanticDebugInfo() && Ops[VariableIdx] == getDebugInfoNoneId()) {
// Check if GV has an associated GVE with a non-empty DIExpression.
// The non-empty DIExpression gives the initial value of the GV.
for (const DIGlobalVariableExpression *GVE : DIF.global_variables()) {
Expand Down
9 changes: 9 additions & 0 deletions test/DebugInfo/DebugInfo-GV-with-DIE.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
;; Ensure that DIExpressions are preserved in DIGlobalVariableExpressions
;; if nonsemantic debug info is enabled.
;; This utilizes SPIRV DebugGlobalVariable's Variable field to hold the
;; DIExpression.

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

;; Ensure SPIR-V DebugGlobalVariable's Variable field does not hold a DIExpression if nonsemantic debug info is not enabled

; RUN: llvm-spirv -o %t.spt %t.bc -spirv-text
; RUN: FileCheck %s --input-file %t.spt --check-prefix CHECK-NONE-SPIRV

; CHECK-NONE-SPIRV: [[DEBUG_INFO_NONE:[0-9]+]] [[#]] DebugInfoNone
; CHECK-NONE-SPIRV: [[#]] [[#]] DebugGlobalVariable [[#]] [[#]] [[#]] [[#]] [[#]] [[#]] [[#]] [[DEBUG_INFO_NONE]] [[#]] {{$}}

!llvm.module.flags = !{!0, !1}
!llvm.dbg.cu = !{!2}

Expand Down
10 changes: 10 additions & 0 deletions test/DebugInfo/DebugInfo-GV-with-SMD-and-DIE.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
;; Ensure that DIExpressions are preserved in DIGlobalVariableExpressions
;; if nonsemantic debug info is enabled
;; when a Static Member Declaration is also needed.
;; This utilizes SPIRV DebugGlobalVariable's Variable field to hold the
;; DIExpression.
Expand Down Expand Up @@ -38,6 +39,15 @@
; CHECK-LLVM: ![[#ELEMENTS]] = !{![[#DECLARATION]]}
; CHECK-LLVM: ![[#BASETYPE]] = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)

;; Ensure SPIR-V DebugGlobalVariable's Variable field does not hold a DIExpression if nonsemantic debug info is not enabled

; RUN: llvm-spirv -o %t.spt %t.bc -spirv-text
; RUN: FileCheck %s --input-file %t.spt --check-prefix CHECK-NONE-SPIRV

; CHECK-NONE-SPIRV-DAG: [[TYPE_MEMBER:[0-9]+]] [[#]] DebugTypeMember [[#]] [[#]] [[#]] [[#]]
; CHECK-NONE-SPIRV-DAG: [[DEBUG_INFO_NONE:[0-9]+]] [[#]] DebugInfoNone
; CHECK-NONE-SPIRV: [[#]] [[#]] DebugGlobalVariable [[#]] [[#]] [[#]] [[#]] [[#]] [[#]] [[#]] [[DEBUG_INFO_NONE]] [[#]] [[TYPE_MEMBER]] {{$}}

!llvm.module.flags = !{!0, !1}
!llvm.dbg.cu = !{!2}

Expand Down

0 comments on commit e329f28

Please sign in to comment.