diff --git a/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp b/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp --- a/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp +++ b/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp @@ -1392,17 +1392,23 @@ return I < 0 ? ~(U << 1) : U << 1; } -static uint64_t rotateSign(DISubrange::BoundType Val) { - return rotateSign(Val.get()->getValue()); -} - void DXILBitcodeWriter::writeDISubrange(const DISubrange *N, SmallVectorImpl &Record, unsigned Abbrev) { Record.push_back(N->isDistinct()); + + // TODO: Do we need to handle DIExpression here? What about cases where Count + // isn't specified but UpperBound and such are? + ConstantInt *Count = N->getCount().dyn_cast(); + assert(Count && "Count is missing or not ConstantInt"); + Record.push_back(Count->getValue().getSExtValue()); + + // TODO: Similarly, DIExpression is allowed here now + DISubrange::BoundType LowerBound = N->getLowerBound(); + assert((LowerBound.isNull() || LowerBound.is()) && + "Lower bound provided but not ConstantInt"); Record.push_back( - N->getCount().get()->getValue().getSExtValue()); - Record.push_back(rotateSign(N->getLowerBound())); + LowerBound ? rotateSign(LowerBound.get()->getValue()) : 0); Stream.EmitRecord(bitc::METADATA_SUBRANGE, Record, Abbrev); Record.clear(); diff --git a/llvm/test/tools/dxil-dis/di-subrange.ll b/llvm/test/tools/dxil-dis/di-subrange.ll new file mode 100644 --- /dev/null +++ b/llvm/test/tools/dxil-dis/di-subrange.ll @@ -0,0 +1,28 @@ +; RUN: llc --filetype=obj %s -o - | dxil-dis -o - | FileCheck %s +target triple = "dxil-unknown-shadermodel6.7-library" + +!llvm.module.flags = !{!0, !1} +!llvm.dbg.cu = !{!2} + +!0 = !{i32 7, !"Dwarf Version", i32 2} +!1 = !{i32 2, !"Debug Info Version", i32 3} +!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "xyz", isOptimized: true, runtimeVersion: 0, emissionKind: 1, retainedTypes: !4) +!3 = !DIFile(filename: "input.hlsl", directory: "/some/path") +!4 = !{!5} +!5 = !DICompositeType(tag: DW_TAG_array_type, baseType: !6, size: 128, flags: DIFlagVector, elements: !7) +!6 = !DIBasicType(name: "float", size: 32, encoding: DW_ATE_float) +!7 = !{!8} +!8 = !DISubrange(count: 3) + +; CHECK: !llvm.module.flags = !{!0, !1} +; CHECK: !llvm.dbg.cu = !{!2} + +; CHECK: !0 = !{i32 7, !"Dwarf Version", i32 2} +; CHECK: !1 = !{i32 2, !"Debug Info Version", i32 3} +; CHECK: !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "xyz", isOptimized: true, runtimeVersion: 0, emissionKind: 1, retainedTypes: !4) +; CHECK: !3 = !DIFile(filename: "input.hlsl", directory: "/some/path") +; CHECK: !4 = !{!5} +; CHECK: !5 = !DICompositeType(tag: DW_TAG_array_type, baseType: !6, size: 128, flags: DIFlagVector, elements: !7) +; CHECK: !6 = !DIBasicType(name: "float", size: 32, encoding: DW_ATE_float) +; CHECK: !7 = !{!8} +; CHECK: !8 = !DISubrange(count: 3)