[llvm] 2ee4d03 - [Verifier] definition subprograms cannot be nested within DICompositeType when enabling ODR.

via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 25 15:08:45 PDT 2023


Author: DianQK
Date: 2023-07-26T06:08:32+08:00
New Revision: 2ee4d0386c783f58abe708298228de648239b435

URL: https://github.com/llvm/llvm-project/commit/2ee4d0386c783f58abe708298228de648239b435
DIFF: https://github.com/llvm/llvm-project/commit/2ee4d0386c783f58abe708298228de648239b435.diff

LOG: [Verifier] definition subprograms cannot be nested within DICompositeType when enabling ODR.

Resolve https://github.com/llvm/llvm-project/issues/61932. We should add the validation.

LLVM can't handle IR where subprogram definitions are nested within DICompositeType when doing LTO builds, because there's no good way to cross the CU boundary to insert a nested DISubprogram definition in one CU into a type defined in another CU.

The test cases `cross-cu-inlining-2.ll` and `cross-cu-inlining-ranges.ll` can be deleted. In the `cross-cu-inlining-2.ll`, the low pc and high pc of the CU are also incorrect.

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D152095

Added: 
    llvm/test/Verifier/disubprogram-declaration-within-struct-2.ll
    llvm/test/Verifier/disubprogram-declaration-within-struct.ll

Modified: 
    llvm/lib/IR/Verifier.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 1408ce293ca654..ebd133a4aa61c2 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -1429,6 +1429,15 @@ void Verifier::visitDISubprogram(const DISubprogram &N) {
     CheckDI(N.isDistinct(), "subprogram definitions must be distinct", &N);
     CheckDI(Unit, "subprogram definitions must have a compile unit", &N);
     CheckDI(isa<DICompileUnit>(Unit), "invalid unit type", &N, Unit);
+    // There's no good way to cross the CU boundary to insert a nested
+    // DISubprogram definition in one CU into a type defined in another CU.
+    auto *CT = dyn_cast_or_null<DICompositeType>(N.getRawScope());
+    if (CT && CT->getRawIdentifier() &&
+        M.getContext().isODRUniquingDebugTypes())
+      CheckDI(N.getDeclaration(),
+              "definition subprograms cannot be nested within DICompositeType "
+              "when enabling ODR",
+              &N);
     if (N.getFile())
       verifySourceDebugInfo(*N.getUnit(), *N.getFile());
   } else {

diff  --git a/llvm/test/Verifier/disubprogram-declaration-within-struct-2.ll b/llvm/test/Verifier/disubprogram-declaration-within-struct-2.ll
new file mode 100644
index 00000000000000..e015f7e38f3161
--- /dev/null
+++ b/llvm/test/Verifier/disubprogram-declaration-within-struct-2.ll
@@ -0,0 +1,43 @@
+; RUN: opt -passes=verify -S < %s 2>&1 | FileCheck %s
+; RUN: opt -passes=verify -S --disable-debug-info-type-map < %s | FileCheck --check-prefix=CHECK-NOT-ODR %s
+
+; Same content as the disubprogram-declaration-within-struct.ll file, except the `identifier` for `DICompositeType` is removed.
+
+; ModuleID = 'foo.7e668e4a-cgu.0'
+source_filename = "foo.7e668e4a-cgu.0"
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+; foo::Foo::bar
+; Function Attrs: nonlazybind uwtable
+define void @_ZN3foo3Foo3bar17h32d65c44145019c8E() unnamed_addr #0 !dbg !6 {
+start:
+  ret void, !dbg !14
+}
+
+attributes #0 = { nonlazybind uwtable "probe-stack"="__rust_probestack" "target-cpu"="x86-64" }
+
+!llvm.module.flags = !{!0, !1, !2, !3}
+!llvm.dbg.cu = !{!4}
+
+!0 = !{i32 7, !"PIC Level", i32 2}
+!1 = !{i32 2, !"RtLibUseGOT", i32 1}
+!2 = !{i32 2, !"Dwarf Version", i32 4}
+!3 = !{i32 2, !"Debug Info Version", i32 3}
+!4 = distinct !DICompileUnit(language: DW_LANG_Rust, file: !5, producer: "clang LLVM (rustc version 1.69.0 (84c898d65 2023-04-16))", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false)
+!5 = !DIFile(filename: "foo.rs/@/foo.7e668e4a-cgu.0", directory: "/tmp")
+!6 = distinct !DISubprogram(name: "bar", linkageName: "_ZN3foo3Foo3bar17h32d65c44145019c8E", scope: !8, file: !7, line: 4, type: !12, scopeLine: 4, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !4, templateParams: !11, retainedNodes: !11)
+!7 = !DIFile(filename: "foo.rs", directory: "/tmp", checksumkind: CSK_MD5, checksum: "427d9b572596c2f310b6185a1781f222")
+!8 = !DICompositeType(tag: DW_TAG_structure_type, name: "Foo", scope: !10, file: !9, align: 8, elements: !11)
+!9 = !DIFile(filename: "<unknown>", directory: "")
+!10 = !DINamespace(name: "foo", scope: null)
+!11 = !{}
+!12 = !DISubroutineType(types: !13)
+!13 = !{null}
+!14 = !DILocation(line: 6, column: 6, scope: !6)
+
+; CHECK-NOT: definition subprograms cannot be nested within DICompositeType when enabling ODR
+; CHECK-NOT: warning: ignoring invalid debug info
+
+; CHECK-NOT-ODR-NOT: definition subprograms cannot be nested within DICompositeType when enabling ODR
+; CHECK-NOT-ODR-NOT: warning: ignoring invalid debug info

diff  --git a/llvm/test/Verifier/disubprogram-declaration-within-struct.ll b/llvm/test/Verifier/disubprogram-declaration-within-struct.ll
new file mode 100644
index 00000000000000..ffaba1392316ea
--- /dev/null
+++ b/llvm/test/Verifier/disubprogram-declaration-within-struct.ll
@@ -0,0 +1,47 @@
+; RUN: opt -passes=verify -disable-output < %s 2>&1 | FileCheck %s
+; RUN: opt -passes=verify -S --disable-debug-info-type-map < %s | FileCheck --check-prefix=CHECK-NOT-ODR %s
+
+; The Rust source:
+; pub struct Foo;
+; impl Foo {
+;   pub fn bar() {}
+; }
+
+; ModuleID = 'foo.7e668e4a-cgu.0'
+source_filename = "foo.7e668e4a-cgu.0"
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+; foo::Foo::bar
+; Function Attrs: nonlazybind uwtable
+define void @_ZN3foo3Foo3bar17h32d65c44145019c8E() unnamed_addr #0 !dbg !6 {
+start:
+  ret void, !dbg !14
+}
+
+attributes #0 = { nonlazybind uwtable "probe-stack"="__rust_probestack" "target-cpu"="x86-64" }
+
+!llvm.module.flags = !{!0, !1, !2, !3}
+!llvm.dbg.cu = !{!4}
+
+!0 = !{i32 7, !"PIC Level", i32 2}
+!1 = !{i32 2, !"RtLibUseGOT", i32 1}
+!2 = !{i32 2, !"Dwarf Version", i32 4}
+!3 = !{i32 2, !"Debug Info Version", i32 3}
+!4 = distinct !DICompileUnit(language: DW_LANG_Rust, file: !5, producer: "clang LLVM (rustc version 1.69.0 (84c898d65 2023-04-16))", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false)
+!5 = !DIFile(filename: "foo.rs/@/foo.7e668e4a-cgu.0", directory: "/tmp")
+!6 = distinct !DISubprogram(name: "bar", linkageName: "_ZN3foo3Foo3bar17h32d65c44145019c8E", scope: !8, file: !7, line: 4, type: !12, scopeLine: 4, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !4, templateParams: !11, retainedNodes: !11)
+!7 = !DIFile(filename: "foo.rs", directory: "/tmp", checksumkind: CSK_MD5, checksum: "427d9b572596c2f310b6185a1781f222")
+!8 = !DICompositeType(tag: DW_TAG_structure_type, name: "Foo", scope: !10, file: !9, align: 8, elements: !11, identifier: "a8fd67db4e906c9c4aceea39cb8b0f61")
+!9 = !DIFile(filename: "<unknown>", directory: "")
+!10 = !DINamespace(name: "foo", scope: null)
+!11 = !{}
+!12 = !DISubroutineType(types: !13)
+!13 = !{null}
+!14 = !DILocation(line: 6, column: 6, scope: !6)
+
+; CHECK: definition subprograms cannot be nested within DICompositeType when enabling ODR
+; CHECK: warning: ignoring invalid debug info
+
+; CHECK-NOT-ODR-NOT: definition subprograms cannot be nested within DICompositeType when enabling ODR
+; CHECK-NOT-ODR-NOT: warning: ignoring invalid debug info


        


More information about the llvm-commits mailing list