[PATCH] D156446: [BPF] Emit better error on missing line info

Tamir Duberstein via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 2 11:47:16 PDT 2023


tamird updated this revision to Diff 546565.
tamird added a comment.
Herald added a subscriber: ormris.

Avoid crash, add test.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156446/new/

https://reviews.llvm.org/D156446

Files:
  llvm/lib/Target/BPF/BTFDebug.cpp
  llvm/test/CodeGen/BPF/BTF/incomplete-debuginfo.ll


Index: llvm/test/CodeGen/BPF/BTF/incomplete-debuginfo.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/BPF/BTF/incomplete-debuginfo.ll
@@ -0,0 +1,55 @@
+; RUN: llc -march=bpfel -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s
+; RUN: llc -march=bpfeb -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s
+;
+; Source code:
+;   unsigned long foo(void) {
+;     return 42;
+;   }
+;   unsigned long bar(void) {
+;     return 1337;
+;   }
+; Compilation flag:
+;   clang -target bpf -O2 -g -S -emit-llvm test.c -o - | sed -E 's/,? !dbg !(7|11)//'
+
+; Function Attrs: noinline nounwind optnone
+define dso_local i64 @foo() #0 {
+entry:
+  ret i64 42
+}
+
+; Function Attrs: noinline nounwind optnone
+define dso_local i64 @bar() #0 !dbg !12 {
+entry:
+  ret i64 1337, !dbg !13
+}
+
+; CHECK: .section        .BTF,"", at progbits
+; CHECK: .long   0                               # BTF_KIND_FUNC_PROTO(id = 1)
+; CHECK: .long   1                               # BTF_KIND_INT(id = 2)
+; CHECK: .long   15                              # BTF_KIND_FUNC(id = 3)
+; CHECK: .byte   0                               # string offset=0
+; CHECK: .ascii  "unsigned long"                 # string offset=1
+; CHECK: .ascii  "bar"                           # string offset=15
+; CHECK: .ascii  ".text"                         # string offset=19
+; CHECK: .ascii  "  return 1337;"                # string offset=69
+
+attributes #0 = { noinline nounwind optnone "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!2, !3, !4, !5}
+!llvm.ident = !{!6}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang version 18.0.0 (https://github.com/llvm/llvm-project.git 8031b3f2c40d3fe622648b6731a0ae1dc3f37860)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "test.c", directory: "/home/tamird/src/llvm-project-latest", checksumkind: CSK_MD5, checksum: "20bd72139e533d6aed61683730100513")
+!2 = !{i32 7, !"Dwarf Version", i32 5}
+!3 = !{i32 2, !"Debug Info Version", i32 3}
+!4 = !{i32 1, !"wchar_size", i32 4}
+!5 = !{i32 7, !"frame-pointer", i32 2}
+!6 = !{!"clang version 18.0.0 (https://github.com/llvm/llvm-project.git 8031b3f2c40d3fe622648b6731a0ae1dc3f37860)"}
+!7 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 1, type: !8, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0)
+!8 = !DISubroutineType(types: !9)
+!9 = !{!10}
+!10 = !DIBasicType(name: "unsigned long", size: 64, encoding: DW_ATE_unsigned)
+!11 = !DILocation(line: 2, column: 3, scope: !7)
+!12 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 5, type: !8, scopeLine: 5, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0)
+!13 = !DILocation(line: 6, column: 3, scope: !12)
Index: llvm/lib/Target/BPF/BTFDebug.cpp
===================================================================
--- llvm/lib/Target/BPF/BTFDebug.cpp
+++ llvm/lib/Target/BPF/BTFDebug.cpp
@@ -18,6 +18,7 @@
 #include "llvm/CodeGen/AsmPrinter.h"
 #include "llvm/CodeGen/MachineModuleInfo.h"
 #include "llvm/CodeGen/MachineOperand.h"
+#include "llvm/IR/DebugInfoMetadata.h"
 #include "llvm/MC/MCContext.h"
 #include "llvm/MC/MCObjectFileInfo.h"
 #include "llvm/MC/MCSectionELF.h"
@@ -1371,7 +1372,11 @@
     // This instruction will be skipped, no LineInfo has
     // been generated, construct one based on function signature.
     if (LineInfoGenerated == false) {
-      auto *S = MI->getMF()->getFunction().getSubprogram();
+      const Function &F = MI->getMF()->getFunction();
+      const DISubprogram *const S = F.getSubprogram();
+      if (!S) {
+        return;
+      }
       MCSymbol *FuncLabel = Asm->getFunctionBegin();
       constructLineInfo(S->getFile(), FuncLabel, S->getLine(), 0);
       LineInfoGenerated = true;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156446.546565.patch
Type: text/x-patch
Size: 3990 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230802/b68cedb2/attachment.bin>


More information about the llvm-commits mailing list