[llvm-branch-commits] [llvm] f3e3c5a - [BPF] Don't crash on missing line info

Tobias Hieta via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Aug 14 01:36:55 PDT 2023


Author: Tamir Duberstein
Date: 2023-08-14T10:34:02+02:00
New Revision: f3e3c5a922c72c2b483f2ec6dc1dfdb938382203

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

LOG: [BPF] Don't crash on missing line info

When compiling Rust code we may end up with calls to functions provided
by other code units. Presently this code crashes on a null pointer
dereference - this patch avoids that crash and adds a test.

Reviewed By: ast

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

(cherry picked from commit 055893beacb34441467eb997a270a620c57c138f)

Added: 
    llvm/test/CodeGen/BPF/BTF/incomplete-debuginfo.ll

Modified: 
    llvm/lib/Target/BPF/BTFDebug.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/BPF/BTFDebug.cpp b/llvm/lib/Target/BPF/BTFDebug.cpp
index 485ba88a4654b7..3c1422b0e1a2a3 100644
--- a/llvm/lib/Target/BPF/BTFDebug.cpp
+++ b/llvm/lib/Target/BPF/BTFDebug.cpp
@@ -1368,6 +1368,8 @@ void BTFDebug::beginInstruction(const MachineInstr *MI) {
     // been generated, construct one based on function signature.
     if (LineInfoGenerated == false) {
       auto *S = MI->getMF()->getFunction().getSubprogram();
+      if (!S)
+        return;
       MCSymbol *FuncLabel = Asm->getFunctionBegin();
       constructLineInfo(S, FuncLabel, S->getLine(), 0);
       LineInfoGenerated = true;

diff  --git a/llvm/test/CodeGen/BPF/BTF/incomplete-debuginfo.ll b/llvm/test/CodeGen/BPF/BTF/incomplete-debuginfo.ll
new file mode 100644
index 00000000000000..aa5167b6284f9c
--- /dev/null
+++ b/llvm/test/CodeGen/BPF/BTF/incomplete-debuginfo.ll
@@ -0,0 +1,54 @@
+; 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
+
+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)


        


More information about the llvm-branch-commits mailing list