Skip to content

Commit e594c45

Browse files
authored
[MLIR][LLVM] Drop unsupported DISubranges while importing (#67712)
This revision ensures that unsuppoert DISubranges are properly skipped instead of being transformed into invalid metadata.
1 parent 38018ec commit e594c45

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

mlir/lib/Target/LLVMIR/DebugImporter.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,15 @@ DISubrangeAttr DebugImporter::translateImpl(llvm::DISubrange *node) {
159159
constInt->getSExtValue());
160160
return IntegerAttr();
161161
};
162-
return DISubrangeAttr::get(context, getIntegerAttrOrNull(node->getCount()),
163-
getIntegerAttrOrNull(node->getLowerBound()),
164-
getIntegerAttrOrNull(node->getUpperBound()),
165-
getIntegerAttrOrNull(node->getStride()));
162+
IntegerAttr count = getIntegerAttrOrNull(node->getCount());
163+
IntegerAttr upperBound = getIntegerAttrOrNull(node->getUpperBound());
164+
// Either count or the upper bound needs to be present. Otherwise, the
165+
// metadata is invalid. The conversion might fail due to unsupported DI nodes.
166+
if (!count && !upperBound)
167+
return {};
168+
return DISubrangeAttr::get(
169+
context, count, getIntegerAttrOrNull(node->getLowerBound()), upperBound,
170+
getIntegerAttrOrNull(node->getStride()));
166171
}
167172

168173
DISubroutineTypeAttr

mlir/test/Target/LLVMIR/Import/debug-info.ll

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ define void @derived_type() !dbg !3 {
163163
; CHECK-DAG: #[[COMP2:.+]] = #llvm.di_composite_type<{{.*}}, file = #[[FILE]], scope = #[[FILE]], baseType = #[[INT]]>
164164
; CHECK-DAG: #[[COMP3:.+]] = #llvm.di_composite_type<{{.*}}, flags = Vector, elements = #llvm.di_subrange<count = 4 : i64>>
165165
; CHECK-DAG: #[[COMP4:.+]] = #llvm.di_composite_type<{{.*}}, flags = Vector, elements = #llvm.di_subrange<lowerBound = 0 : i64, upperBound = 4 : i64, stride = 1 : i64>>
166-
; CHECK-DAG: #llvm.di_subroutine_type<types = #[[COMP1]], #[[COMP2]], #[[COMP3]], #[[COMP4]]>
166+
; CHECK-DAG: #[[COMP5:.+]] = #llvm.di_composite_type<{{.*}}, flags = Vector>
167+
; CHECK-DAG: #llvm.di_subroutine_type<types = #[[COMP1]], #[[COMP2]], #[[COMP3]], #[[COMP4]], #[[COMP5]]>
167168

168169
define void @composite_type() !dbg !3 {
169170
ret void
@@ -176,7 +177,7 @@ define void @composite_type() !dbg !3 {
176177
!2 = !DIFile(filename: "debug-info.ll", directory: "/")
177178
!3 = distinct !DISubprogram(name: "composite_type", scope: !2, file: !2, spFlags: DISPFlagDefinition, unit: !1, type: !4)
178179
!4 = !DISubroutineType(types: !5)
179-
!5 = !{!7, !8, !9, !10}
180+
!5 = !{!7, !8, !9, !10, !18}
180181
!6 = !DIBasicType(name: "int")
181182
!7 = !DICompositeType(tag: DW_TAG_array_type, name: "array1", line: 10, size: 128, align: 32)
182183
!8 = !DICompositeType(tag: DW_TAG_array_type, name: "array2", file: !2, scope: !2, baseType: !6)
@@ -187,6 +188,12 @@ define void @composite_type() !dbg !3 {
187188
!13 = !{!11}
188189
!14 = !{!12}
189190

191+
; Verifies that unsupported subrange nodes are skipped.
192+
!15 = !DISubrange(count: !16)
193+
!16 = !DILocalVariable(scope: !3, name: "size")
194+
!17 = !{!15}
195+
!18 = !DICompositeType(tag: DW_TAG_array_type, name: "unsupported_elements", flags: DIFlagVector, elements: !17)
196+
190197
; // -----
191198

192199
; CHECK-DAG: #[[FILE:.+]] = #llvm.di_file<"debug-info.ll" in "/">

0 commit comments

Comments
 (0)