Skip to content

Commit 9263e90

Browse files
MrSidimsjsji
authored andcommitted
Fix DebugTypeSubrange parameters order (#2076)
Count should be the 3rd parameter. Signed-off-by: Sidorov, Dmitry <[email protected]> Original commit: KhronosGroup/SPIRV-LLVM-Translator@fca2a3a
1 parent cf9e9d5 commit 9263e90

File tree

5 files changed

+27
-18
lines changed

5 files changed

+27
-18
lines changed

llvm-spirv/lib/SPIRV/LLVMToSPIRVDbgTran.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ LLVMToSPIRVDbgTran::transDbgArrayTypeDynamic(const DICompositeType *AT) {
772772

773773
SPIRVEntry *LLVMToSPIRVDbgTran::transDbgSubrangeType(const DISubrange *ST) {
774774
using namespace SPIRVDebug::Operand::TypeSubrange;
775-
SPIRVWordVec Ops(OperandCount);
775+
SPIRVWordVec Ops(MinOperandCount);
776776
auto TransOperand = [&Ops, this, ST](int Idx) -> void {
777777
Metadata *RawNode = nullptr;
778778
switch (Idx) {
@@ -785,9 +785,6 @@ SPIRVEntry *LLVMToSPIRVDbgTran::transDbgSubrangeType(const DISubrange *ST) {
785785
case CountIdx:
786786
RawNode = ST->getRawCountNode();
787787
break;
788-
case StrideIdx:
789-
RawNode = ST->getRawStride();
790-
break;
791788
}
792789
if (!RawNode) {
793790
Ops[Idx] = getDebugInfoNoneId();
@@ -815,8 +812,17 @@ SPIRVEntry *LLVMToSPIRVDbgTran::transDbgSubrangeType(const DISubrange *ST) {
815812
: getDebugInfoNoneId();
816813
}
817814
};
818-
for (int Idx = CountIdx; Idx < OperandCount; ++Idx)
815+
for (int Idx = 0; Idx < MinOperandCount; ++Idx)
819816
TransOperand(Idx);
817+
if (auto *RawNode = ST->getRawStride()) {
818+
Ops.resize(MaxOperandCount);
819+
if (auto *Node = dyn_cast<MDNode>(RawNode))
820+
Ops[StrideIdx] = transDbgEntry(Node)->getId();
821+
else
822+
Ops[StrideIdx] =
823+
SPIRVWriter->transValue(ST->getStride().get<ConstantInt *>(), nullptr)
824+
->getId();
825+
}
820826
return BM->addDebugInfo(SPIRVDebug::TypeSubrange, getVoidTy(), Ops);
821827
}
822828

llvm-spirv/lib/SPIRV/SPIRVToLLVMDbgTran.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -556,8 +556,9 @@ DISubrange *
556556
SPIRVToLLVMDbgTran::transTypeSubrange(const SPIRVExtInst *DebugInst) {
557557
using namespace SPIRVDebug::Operand::TypeSubrange;
558558
const SPIRVWordVec &Ops = DebugInst->getArguments();
559-
assert(Ops.size() == OperandCount && "Invalid number of operands");
560-
std::vector<Metadata *> TranslatedOps(OperandCount, nullptr);
559+
assert((Ops.size() == MinOperandCount || Ops.size() == MaxOperandCount) &&
560+
"Invalid number of operands");
561+
std::vector<Metadata *> TranslatedOps(MaxOperandCount, nullptr);
561562
auto TransOperand = [&Ops, &TranslatedOps, this](int Idx) -> void {
562563
if (!getDbgInst<SPIRVDebug::DebugInfoNone>(Ops[Idx])) {
563564
if (auto *GlobalVar = getDbgInst<SPIRVDebug::GlobalVariable>(Ops[Idx])) {
@@ -576,10 +577,11 @@ SPIRVToLLVMDbgTran::transTypeSubrange(const SPIRVExtInst *DebugInst) {
576577
}
577578
}
578579
};
579-
for (int Idx = CountIdx; Idx < OperandCount; ++Idx)
580+
for (size_t Idx = 0; Idx < Ops.size(); ++Idx)
580581
TransOperand(Idx);
581582
return getDIBuilder(DebugInst).getOrCreateSubrange(
582-
TranslatedOps[0], TranslatedOps[1], TranslatedOps[2], TranslatedOps[3]);
583+
TranslatedOps[CountIdx], TranslatedOps[LowerBoundIdx],
584+
TranslatedOps[UpperBoundIdx], TranslatedOps[StrideIdx]);
583585
}
584586

585587
DIStringType *

llvm-spirv/lib/SPIRV/libSPIRV/SPIRV.debug.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -396,11 +396,12 @@ namespace TypeVector = TypeArray;
396396

397397
namespace TypeSubrange {
398398
enum {
399-
CountIdx = 0,
400-
LowerBoundIdx = 1,
401-
UpperBoundIdx = 2,
399+
LowerBoundIdx = 0,
400+
UpperBoundIdx = 1,
401+
CountIdx = 2,
402402
StrideIdx = 3,
403-
OperandCount = 4
403+
MinOperandCount = 3,
404+
MaxOperandCount = 4
404405
};
405406
}
406407

llvm-spirv/test/DebugInfo/NonSemantic/Shader200/DebugInfoSubrange.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@
2828
; CHECK-SPIRV: [[#DebugFuncId:]] [[#EISId]] DebugFunction
2929
; CHECK-SPIRV: [[#LocalVarId:]] [[#EISId]] DebugLocalVariable [[#LocalVarNameId]] [[#]] [[#]] [[#]] [[#]] [[#DebugFuncId]]
3030
; CHECK-SPIRV: [[#DebugTypeTemplate:]] [[#EISId]] DebugTypeTemplate [[#DebugFuncId]]
31-
; CHECK-SPIRV: [[#EISId]] DebugTypeSubrange [[#DINoneId]] [[#Constant1Id]] [[#LocalVarId]] [[#DINoneId]]
31+
; CHECK-SPIRV: [[#EISId]] DebugTypeSubrange [[#Constant1Id]] [[#LocalVarId]] [[#DINoneId]] {{$}}
3232

3333
; CHECK-SPIRV: [[#DIExprId:]] [[#EISId]] DebugExpression
34-
; CHECK-SPIRV: [[#EISId]] DebugTypeSubrange [[#DINoneId]] [[#DIExprId]] [[#DIExprId]] [[#DINoneId]]
34+
; CHECK-SPIRV: [[#EISId]] DebugTypeSubrange [[#DIExprId]] [[#DIExprId]] [[#DINoneId]] {{$}}
3535

36-
; CHECK-SPIRV: [[#EISId]] DebugTypeSubrange [[#Constant1000Id]] [[#Constant1Id]] [[#DINoneId]] [[#DINoneId]]
36+
; CHECK-SPIRV: [[#EISId]] DebugTypeSubrange [[#Constant1Id]] [[#DINoneId]] [[#Constant1000Id]] {{$}}
3737

3838
; CHECK-SPIRV: [[#EISId]] DebugLine [[#]] [[#Constant15Id]] [[#Constant15Id]] [[#Constant67Id]] [[#Constant68Id]]
3939
; CHECK-SPIRV: [[#EISId]] DebugLine [[#]] [[#Constant27Id]] [[#Constant27Id]] [[#Constant24Id]] [[#Constant25Id]]

llvm-spirv/test/DebugInfo/NonSemantic/Shader200/FortranDynamicArrayExpr.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
; CHECK-SPIRV: ExtInst [[#VoidT]] [[#DbgExprAssociated:]] [[#Import]] DebugExpression [[#]] [[#]] [[#]] [[#]] {{$}}
2626
; CHECK-SPIRV: ExtInst [[#VoidT]] [[#DbgExprLowerBound:]] [[#Import]] DebugExpression [[#]] [[#]] [[#]] {{$}}
2727
; CHECK-SPIRV: ExtInst [[#VoidT]] [[#DbgExprUpperBound:]] [[#Import]] DebugExpression [[#]] [[#]] [[#]] [[#]] [[#]] [[#]] [[#]] [[#]] [[#]] {{$}}
28-
; CHECK-SPIRV: ExtInst [[#VoidT]] [[#DbgExprCount:]] [[#Import]] DebugExpression [[#]] [[#]] [[#]] {{$}}
29-
; CHECK-SPIRV: ExtInst [[#VoidT]] [[#DbgSubRangeId:]] [[#Import]] DebugTypeSubrange [[#DbgInfoNone]] [[#DbgExprLowerBound]] [[#DbgExprUpperBound]] [[#DbgExprCount]]
28+
; CHECK-SPIRV: ExtInst [[#VoidT]] [[#DbgExprStride:]] [[#Import]] DebugExpression [[#]] [[#]] [[#]] {{$}}
29+
; CHECK-SPIRV: ExtInst [[#VoidT]] [[#DbgSubRangeId:]] [[#Import]] DebugTypeSubrange [[#DbgExprLowerBound]] [[#DbgExprUpperBound]] [[#DbgInfoNone]] [[#DbgExprStride]]
3030
; CHECK-SPIRV: ExtInst [[#VoidT]] [[#DbgArrayId:]] [[#Import]] DebugTypeArrayDynamic [[#ArrayBasicT]] [[#DbgExprLocation]] [[#DbgExprAssociated]] [[#DbgInfoNone]] [[#DbgInfoNone]] [[#DbgSubRangeId]]
3131

3232
; CHECK-LLVM: %[[#Array:]] = alloca

0 commit comments

Comments
 (0)