Skip to content

Commit b42cc9a

Browse files
KornevNikitavmaksimo
authored andcommitted
Fix wrong DICompositeType size
If count = -1 we shouldln't cast it to unsigned Original commit: KhronosGroup/SPIRV-LLVM-Translator@1c0bc1c
1 parent 128e55a commit b42cc9a

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

llvm-spirv/lib/SPIRV/SPIRVToLLVMDbgTran.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@ SPIRVToLLVMDbgTran::transTypeArray(const SPIRVExtInst *DebugInst) {
237237
Subscripts.push_back(
238238
Builder.getOrCreateSubrange(CountAsMD, nullptr, nullptr, nullptr));
239239
}
240-
TotalCount *= static_cast<uint64_t>(Count);
240+
// Count = -1 means that the array is empty
241+
TotalCount *= Count > 0 ? static_cast<size_t>(Count) : 0;
241242
continue;
242243
}
243244
}

llvm-spirv/test/DebugInfo/DebugInfoSubrange.ll

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99

1010
; CHECK-SPIRV: String [[#VarNameId:]] "A$1$upperbound"
1111
; CHECK-SPIRV: [[#FuncNameId:]] "random_fill_sp"
12-
; CHECK-SPIRV: TypeInt [[#TypeIntId:]] 64 0
13-
; CHECK-SPIRV: Constant [[#TypeIntId]] [[#LowerBoundId:]] 1 0
12+
; CHECK-SPIRV: TypeInt [[#TypeInt64Id:]] 64 0
13+
; CHECK-SPIRV: Constant [[#TypeInt64Id]] [[#LowerBoundId:]] 1 0
14+
; CHECK-SPIRV: Constant [[#TypeInt64Id]] [[#NegativeCount:]] 4294967295 4294967295
15+
1416
; CHECK-SPIRV: [[#DbgFuncId:]] [[#]] DebugFunction [[#FuncNameId]]
1517
; CHECK-SPIRV: [[#DbgTemplateId:]] [[#]] DebugTemplate [[#DbgFuncId]]
1618
; CHECK-SPIRV: [[#]] [[#DbgLocVarId:]] [[#]] DebugLocalVariable [[#VarNameId]] [[#]] [[#]] [[#]] [[#]] [[#DbgTemplateId]]
@@ -19,6 +21,8 @@
1921
; CHECK-SPIRV: [[#DbgExprId:]] [[#]] DebugExpression
2022
; CHECK-SPIRV: DebugTypeArray [[#]] [[#DbgExprId]] [[#DbgExprId]]
2123

24+
; CHECK-SPIRV: DebugTypeArray [[#]] [[#NegativeCount]] [[#]]
25+
2226
; CHECK-LLVM: !DICompositeType(tag: DW_TAG_array_type, baseType: ![[#BaseType:]], size: 32, elements: ![[#Subrange1:]])
2327
; CHECK-LLVM: [[#BaseType]] = !DIBasicType(name: "REAL*4", size: 32, encoding: DW_ATE_float)
2428
; CHECK-LLVM: [[#Subrange1]] = !{![[#Subrange2:]]}
@@ -31,6 +35,11 @@
3135

3236
; CHECK-LLVM: !DISubrange(count: 1000, lowerBound: 1)
3337

38+
; CHECK-LLVM: !DICompositeType(tag: DW_TAG_array_type, baseType: ![[#BaseType:]], elements: ![[#Subrage:]])
39+
; CHECK-LLVM: ![[#BaseType]] = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
40+
; CHECK-LLVM: ![[#Subrage]] = !{![[#Subrage:]]}
41+
; CHECK-LLVM: ![[#Subrage]] = !DISubrange(count: -1
42+
3443
; ModuleID = 'DebugInfoSubrangeUpperBound.bc'
3544
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024"
3645
target triple = "spir64-unknown-unknown"
@@ -40,12 +49,13 @@ target triple = "spir64-unknown-unknown"
4049
%structtype2 = type { i64, i64, i64 }
4150

4251
; Function Attrs: noinline nounwind
43-
define spir_kernel void @__omp_offloading_811_198142f_random_fill_sp_l25(%structtype* byval(%structtype) %"ascast$val", [1000 x i32] addrspace(1)* noalias %"ascastB$val") #0 !kernel_arg_addr_space !9 !kernel_arg_access_qual !10 !kernel_arg_type !11 !kernel_arg_type_qual !12 !kernel_arg_base_type !11 {
52+
define spir_kernel void @__omp_offloading_811_198142f_random_fill_sp_l25(i32 addrspace(1)* noalias %0, %structtype* byval(%structtype) %"ascast$val", [1000 x i32] addrspace(1)* noalias %"ascastB$val") #0 !kernel_arg_addr_space !9 !kernel_arg_access_qual !10 !kernel_arg_type !11 !kernel_arg_type_qual !12 !kernel_arg_base_type !11 {
4453
newFuncRoot:
4554
%.ascast = bitcast %structtype* %"ascast$val" to %"QNCA_a0$float"*
4655
call void @llvm.dbg.value(metadata %"QNCA_a0$float"* %.ascast, metadata !13, metadata !DIExpression(DW_OP_deref)), !dbg !27
4756
call void @llvm.dbg.value(metadata %"QNCA_a0$float"* %.ascast, metadata !28, metadata !DIExpression(DW_OP_deref)), !dbg !42
48-
call void @llvm.dbg.value(metadata [1000 x i32] addrspace(1)* %"ascastB$val", metadata !47, metadata !DIExpression(DW_OP_deref)), !dbg !56
57+
call void @llvm.dbg.value(metadata [1000 x i32] addrspace(1)* %"ascastB$val", metadata !47, metadata !DIExpression(DW_OP_deref)), !dbg !51
58+
call void @llvm.dbg.value(metadata i32 addrspace(1)* %0, metadata !54, metadata !DIExpression(DW_OP_deref)), !dbg !59
4959
ret void
5060
}
5161

@@ -117,4 +127,12 @@ attributes #1 = { nofree nosync nounwind readnone speculatable willreturn }
117127
!48 = !DICompositeType(tag: DW_TAG_array_type, baseType: !43, elements: !49)
118128
!49 = !{!50}
119129
!50 = !DISubrange(count: 1000, lowerBound: 1)
120-
!56 = !DILocation(line: 27, column: 24, scope: !46)
130+
!51 = !DILocation(line: 27, column: 24, scope: !46)
131+
!52 = distinct !DISubprogram(name: "test", scope: !3, file: !3, line: 51, type: !53, scopeLine: 51, flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !2)
132+
!53 = !DISubroutineType(types: !7)
133+
!54 = !DILocalVariable(name: "isHost", scope: !52, file: !3, line: 34, type: !55)
134+
!55 = !DICompositeType(tag: DW_TAG_array_type, baseType: !56, elements: !57)
135+
!56 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
136+
!57 = !{!58}
137+
!58 = !DISubrange(count: -1)
138+
!59 = !DILocation(line: 34, column: 33, scope: !52)

0 commit comments

Comments
 (0)