[Mlir-commits] [llvm] [mlir] Introduce and use Verifier::visitDIType (PR #189067)
Tom Tromey
llvmlistbot at llvm.org
Wed Apr 1 13:59:32 PDT 2026
https://github.com/tromey updated https://github.com/llvm/llvm-project/pull/189067
>From 2de749ab5372618a823aafb7ac6a2094837e3f7c Mon Sep 17 00:00:00 2001
From: Tom Tromey <tromey at adacore.com>
Date: Fri, 27 Mar 2026 11:28:18 -0600
Subject: [PATCH] Introduce and use Verifier::visitDIType
This adds a new method Verifier::visitDIType, and then changes method
for subclasses of DIType to call it. The new method just dispatches
to DIScope and adds a file/line check inspired by
Verifier::visitDISubprogram.
---
llvm/lib/IR/Verifier.cpp | 25 ++++++++++++++-----
.../Verifier/dbg-type-line-without-file.ll | 13 ++++++++++
mlir/test/Target/LLVMIR/Import/debug-info.ll | 4 +--
3 files changed, 34 insertions(+), 8 deletions(-)
create mode 100644 llvm/test/Verifier/dbg-type-line-without-file.ll
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index abda69304b7e4..cf9131c66d6c3 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -553,6 +553,7 @@ class Verifier : public InstVisitor<Verifier>, VerifierSupport {
template <class Ty> bool isValidMetadataArray(const MDTuple &N);
#define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) void visit##CLASS(const CLASS &N);
#include "llvm/IR/Metadata.def"
+ void visitDIType(const DIType &N);
void visitDIScope(const DIScope &N);
void visitDIVariable(const DIVariable &N);
void visitDILexicalBlockBase(const DILexicalBlockBase &N);
@@ -1221,7 +1222,16 @@ void Verifier::visitDIScope(const DIScope &N) {
CheckDI(isa<DIFile>(F), "invalid file", &N, F);
}
+void Verifier::visitDIType(const DIType &N) {
+ CheckDI(isScope(N.getRawScope()), "invalid scope", &N, N.getRawScope());
+ visitDIScope(N);
+ CheckDI(N.getRawFile() || N.getLine() == 0, "line specified with no file", &N,
+ N.getLine());
+}
+
void Verifier::visitDISubrangeType(const DISubrangeType &N) {
+ visitDIType(N);
+
CheckDI(N.getTag() == dwarf::DW_TAG_subrange_type, "invalid tag", &N);
auto *BaseType = N.getRawBaseType();
CheckDI(!BaseType || isType(BaseType), "BaseType must be a type");
@@ -1308,6 +1318,8 @@ void Verifier::visitDIEnumerator(const DIEnumerator &N) {
}
void Verifier::visitDIBasicType(const DIBasicType &N) {
+ visitDIType(N);
+
CheckDI(N.getTag() == dwarf::DW_TAG_base_type ||
N.getTag() == dwarf::DW_TAG_unspecified_type ||
N.getTag() == dwarf::DW_TAG_string_type,
@@ -1338,14 +1350,16 @@ void Verifier::visitDIFixedPointType(const DIFixedPointType &N) {
}
void Verifier::visitDIStringType(const DIStringType &N) {
+ visitDIType(N);
+
CheckDI(N.getTag() == dwarf::DW_TAG_string_type, "invalid tag", &N);
CheckDI(!(N.isBigEndian() && N.isLittleEndian()), "has conflicting flags",
&N);
}
void Verifier::visitDIDerivedType(const DIDerivedType &N) {
- // Common scope checks.
- visitDIScope(N);
+ // Common type checks.
+ visitDIType(N);
CheckDI(N.getTag() == dwarf::DW_TAG_typedef ||
N.getTag() == dwarf::DW_TAG_pointer_type ||
@@ -1411,7 +1425,6 @@ void Verifier::visitDIDerivedType(const DIDerivedType &N) {
}
}
- CheckDI(isScope(N.getRawScope()), "invalid scope", &N, N.getRawScope());
CheckDI(isType(N.getRawBaseType()), "invalid base type", &N,
N.getRawBaseType());
@@ -1447,8 +1460,8 @@ void Verifier::visitTemplateParams(const MDNode &N, const Metadata &RawParams) {
}
void Verifier::visitDICompositeType(const DICompositeType &N) {
- // Common scope checks.
- visitDIScope(N);
+ // Common type checks.
+ visitDIType(N);
CheckDI(N.getTag() == dwarf::DW_TAG_array_type ||
N.getTag() == dwarf::DW_TAG_structure_type ||
@@ -1460,7 +1473,6 @@ void Verifier::visitDICompositeType(const DICompositeType &N) {
N.getTag() == dwarf::DW_TAG_namelist,
"invalid tag", &N);
- CheckDI(isScope(N.getRawScope()), "invalid scope", &N, N.getRawScope());
CheckDI(isType(N.getRawBaseType()), "invalid base type", &N,
N.getRawBaseType());
@@ -1522,6 +1534,7 @@ void Verifier::visitDICompositeType(const DICompositeType &N) {
}
void Verifier::visitDISubroutineType(const DISubroutineType &N) {
+ visitDIType(N);
CheckDI(N.getTag() == dwarf::DW_TAG_subroutine_type, "invalid tag", &N);
if (auto *Types = N.getRawTypeArray()) {
CheckDI(isa<MDTuple>(Types), "invalid composite elements", &N, Types);
diff --git a/llvm/test/Verifier/dbg-type-line-without-file.ll b/llvm/test/Verifier/dbg-type-line-without-file.ll
new file mode 100644
index 0000000000000..bfa9e47ea215b
--- /dev/null
+++ b/llvm/test/Verifier/dbg-type-line-without-file.ll
@@ -0,0 +1,13 @@
+; RUN: llvm-as -disable-output <%s 2>&1 | FileCheck %s
+; CHECK: line specified with no file
+; CHECK: warning: ignoring invalid debug info
+
+!llvm.module.flags = !{!0}
+!llvm.dbg.cu = !{!1}
+
+!0 = !{i32 2, !"Debug Info Version", i32 3}
+!1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, retainedTypes: !3)
+!2 = !DIFile(filename: "foo.c", directory: "")
+!3 = !{!4}
+!4 = !DICompositeType(tag: DW_TAG_array_type, name: "array1", line: 10, size: 128, align: 32, baseType: !5)
+!5 = !DIBasicType(name: "int")
diff --git a/mlir/test/Target/LLVMIR/Import/debug-info.ll b/mlir/test/Target/LLVMIR/Import/debug-info.ll
index bc65188faa482..d6e24d0c3dfbc 100644
--- a/mlir/test/Target/LLVMIR/Import/debug-info.ll
+++ b/mlir/test/Target/LLVMIR/Import/debug-info.ll
@@ -166,7 +166,7 @@ define void @derived_type() !dbg !3 {
; CHECK-DAG: #[[FILE:.+]] = #llvm.di_file<"debug-info.ll" in "/">
; CHECK-DAG: #[[VAR:.+]] = #llvm.di_local_variable<{{.*}}name = "size">
; CHECK-DAG: #[[GV:.+]] = #llvm.di_global_variable<{{.*}}name = "gv"{{.*}}>
-; CHECK-DAG: #[[COMP1:.+]] = #llvm.di_composite_type<tag = DW_TAG_array_type, name = "array1", line = 10, baseType = #[[INT]], sizeInBits = 128, alignInBits = 32>
+; CHECK-DAG: #[[COMP1:.+]] = #llvm.di_composite_type<tag = DW_TAG_array_type, name = "array1", file = #[[FILE]], line = 10, baseType = #[[INT]], sizeInBits = 128, alignInBits = 32>
; CHECK-DAG: #[[COMP2:.+]] = #llvm.di_composite_type<{{.*}}, file = #[[FILE]], scope = #[[FILE]], baseType = #[[INT]]>
; CHECK-DAG: #[[COMP3:.+]] = #llvm.di_composite_type<{{.*}}, flags = Vector, elements = #llvm.di_subrange<count = 4 : i64>>
; CHECK-DAG: #[[COMP4:.+]] = #llvm.di_composite_type<{{.*}}, flags = Vector, elements = #llvm.di_subrange<lowerBound = 0 : i64, upperBound = 4 : i64, stride = 1 : i64>>
@@ -190,7 +190,7 @@ define void @composite_type() !dbg !3 {
!4 = !DISubroutineType(types: !5)
!5 = !{!7, !8, !9, !10, !18, !22, !24}
!6 = !DIBasicType(name: "int")
-!7 = !DICompositeType(tag: DW_TAG_array_type, name: "array1", line: 10, size: 128, align: 32, baseType: !6)
+!7 = !DICompositeType(tag: DW_TAG_array_type, name: "array1", file: !2, line: 10, size: 128, align: 32, baseType: !6)
!8 = !DICompositeType(tag: DW_TAG_array_type, name: "array2", file: !2, scope: !2, baseType: !6)
!9 = !DICompositeType(tag: DW_TAG_array_type, name: "array3", flags: DIFlagVector, elements: !13, baseType: !6)
!10 = !DICompositeType(tag: DW_TAG_array_type, name: "array4", flags: DIFlagVector, elements: !14, baseType: !6)
More information about the Mlir-commits
mailing list