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

Eduard Zingerman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 2 07:35:00 PDT 2023


eddyz87 added a comment.

This error could be detected using the following test case:

  $ cat test2.c
  ; ModuleID = 'test2.c'
  source_filename = "test2.c"
  target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128"
  target triple = "bpf"
  
  ; Function Attrs: noinline nounwind optnone
  define dso_local i64 @foo() {
  entry:
    ret i64 42
  }
  
  !llvm.dbg.cu = !{!0}
  !llvm.module.flags = !{!2, !3, !4, !5}
  
  !0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "foo", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
  !1 = !DIFile(filename: "file.c", directory: "/some/dir", checksumkind: CSK_MD5, checksum: "f58a7abbd9253986370acb1013fc9e55")
  !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 (/home/eddy/work/llvm-project/clang 61cd4a1d35aa7c0f7b312b8f43ed3bff33f20d55)"}
  
  $ llc test2.ll -o /dev/null
  /home/eddy/work/llvm-project/llvm/lib/Target/BPF/BTFDebug.cpp:1640:42: runtime error: member call on null pointer of type 'llvm::DISubprogram'
  SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /home/eddy/work/llvm-project/llvm/lib/Target/BPF/BTFDebug.cpp:1640:42 in 

Necessary conditions are: module with debug attributes (llvm.dbg.cu -> DICompileUnit) and a function and instruction w/o debug metadata. I think such test case should be added to the suite.
Also, I don't see a point in reporting this (either as warning or as error). Absence of DISubprogram is ignored in `BTFDebug::processFuncPrototypes` and it two other places `getSubprogram()` can't return null. I think the following patch should suffice:

  diff --git a/llvm/lib/Target/BPF/BTFDebug.cpp b/llvm/lib/Target/BPF/BTFDebug.cpp
  index d886edaff555..6df421934b70 100644
  --- a/llvm/lib/Target/BPF/BTFDebug.cpp
  +++ b/llvm/lib/Target/BPF/BTFDebug.cpp
  @@ -1634,8 +1635,8 @@ void BTFDebug::beginInstruction(const MachineInstr *MI) {
     if (!DL || PrevInstLoc == DL) {
       // 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();
  +    DISubprogram *S = MI->getMF()->getFunction().getSubprogram();
  +    if (!LineInfoGenerated && S) {
         MCSymbol *FuncLabel = Asm->getFunctionBegin();
         constructLineInfo(S, FuncLabel, S->getLine(), 0);
         LineInfoGenerated = true;


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156446



More information about the llvm-commits mailing list