[llvm] dd75a6b - [DWARF][FIX] Try not to crash for nvptx with missing debug information

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 19 16:40:56 PST 2022


Author: Johannes Doerfert
Date: 2022-01-19T18:40:13-06:00
New Revision: dd75a6b2ae5c9c6628fb855473dc2f31073440d0

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

LOG: [DWARF][FIX] Try not to crash for nvptx with missing debug information

This prevents crashes in the OpenMP offload pipeline as not everything
is properly annotated with debug information, e.g., the runtimes we link
in. While we might want to have them annotated, it seems to be generally
useful to gracefully handle missing debug info rather than crashing.

TODO: A test is missing and can hopefully be distilled prior to landing.

This fixes #51079.

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

Added: 
    llvm/test/DebugInfo/NVPTX/crash-missing-DISubprogram.ll

Modified: 
    llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index f13b8f733e202..4f3f798fe6f80 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -247,6 +247,11 @@ void AsmPrinter::emitInitialRawDwarfLocDirective(const MachineFunction &MF) {
   if (DD) {
     assert(OutStreamer->hasRawTextSupport() &&
            "Expected assembly output mode.");
+    // This is NVPTX specific and it's unclear why.
+    // PR51079: If we have code without debug information we need to give up.
+    DISubprogram *MFSP = MF.getFunction().getSubprogram();
+    if (!MFSP)
+      return;
     (void)DD->emitInitialLocDirective(MF, /*CUID=*/0);
   }
 }

diff  --git a/llvm/test/DebugInfo/NVPTX/crash-missing-DISubprogram.ll b/llvm/test/DebugInfo/NVPTX/crash-missing-DISubprogram.ll
new file mode 100644
index 0000000000000..38ccea85fba6e
--- /dev/null
+++ b/llvm/test/DebugInfo/NVPTX/crash-missing-DISubprogram.ll
@@ -0,0 +1,27 @@
+; RUN: llc < %s -mtriple=nvptx64-nvidia-cuda
+; Don't crash for a function w/o debug info that contains an instruction w/
+; debug info.
+; Reported as #51079
+
+define weak void @test() {
+  ret void, !dbg !10
+}
+
+!llvm.module.flags = !{!0, !1, !2, !3, !4, !5, !6, !7}
+!llvm.dbg.cu = !{!8}
+
+!0 = !{i32 2, !"SDK Version", [2 x i32] [i32 11, i32 4]}
+!1 = !{i32 7, !"Dwarf Version", i32 2}
+!2 = !{i32 2, !"Debug Info Version", i32 3}
+!3 = !{i32 1, !"wchar_size", i32 4}
+!4 = !{i32 7, !"openmp", i32 50}
+!5 = !{i32 7, !"openmp-device", i32 50}
+!6 = !{i32 7, !"PIC Level", i32 2}
+!7 = !{i32 7, !"frame-pointer", i32 2}
+!8 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !9, producer: "clang version 14.0.0 (https://github.com/llvm/llvm-project.git a0262043bb87fdef68c817722de320a5dd9eb9c9)", isOptimized: true, runtimeVersion: 0, emissionKind: DebugDirectivesOnly, splitDebugInlining: false, nameTableKind: None)
+!9 = !DIFile(filename: "test_omp_complex_reduction.cpp", directory: "/gpfs/jlse-fs0/users/jdoerfert/build/miniqmc-trunk/src/Platforms/tests/OMPTarget")
+!10 = !DILocation(line: 69, column: 18, scope: !11)
+!11 = distinct !DISubprogram(name: "__omp_outlined__1", scope: !12, file: !12, line: 68, type: !13, scopeLine: 68, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !8, retainedNodes: !14)
+!12 = !DIFile(filename: "projects/benchmarks/miniqmc/src/Platforms/tests/OMPTarget/test_omp_complex_reduction.cpp", directory: "/gpfs/jlse-fs0/users/jdoerfert")
+!13 = !DISubroutineType(types: !14)
+!14 = !{}


        


More information about the llvm-commits mailing list