[PATCH] D113741: [RFC][DwarfDebug][AsmPrinter] Support emitting function-local declaration for a lexical block

David Blaikie via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 22 10:53:26 PST 2021


dblaikie added a comment.

OK, think I've got it now.

It requires `splitDebugInlining=false` in the source CU, and `true' in the destination CU. Needs a local using decl in the source CU and some function import from source to destination CU.

This example, compiled at `-O1` does the trick:

  ; ModuleID = 'ab.bc'
  source_filename = "llvm-link"
  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"
  
  %"struct.ns::t1" = type { i8 }
  
  ; Function Attrs: mustprogress uwtable
  define available_externally dso_local void @_Z2f1v() #0 !dbg !4 {
  entry:
    %v1 = alloca %"struct.ns::t1", align 1
    call void @llvm.dbg.declare(metadata %"struct.ns::t1"* %v1, metadata !21, metadata !DIExpression()), !dbg !22
    call void @_Z3pinv(), !dbg !23
    ret void, !dbg !24
  }
  
  ; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
  declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
  
  declare dso_local void @_Z3pinv() #2
  
  ; Function Attrs: mustprogress norecurse uwtable
  define dso_local i32 @main() #3 !dbg !25 {
  entry:
    call void @_Z2f1v(), !dbg !29
    ret i32 0, !dbg !30
  }
  
  attributes #0 = { mustprogress uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
  attributes #1 = { nofree nosync nounwind readnone speculatable willreturn }
  attributes #2 = { "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
  attributes #3 = { mustprogress norecurse uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
  
  !llvm.dbg.cu = !{!0, !10}
  !llvm.ident = !{!12, !12}
  !llvm.module.flags = !{!13, !14, !15, !16, !17}
  
  !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 14.0.0 (git at github.com:llvm/llvm-project.git 75b622a7959479ccdb758ebe0973061b7b4fcacd)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, imports: !2, splitDebugInlining: false, nameTableKind: GNU)
  !1 = !DIFile(filename: "a.cpp", directory: "/usr/local/google/home/blaikie/dev/scratch")
  !2 = !{!3}
  !3 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !4, entity: !8, file: !1, line: 3)
  !4 = distinct !DISubprogram(name: "f1", linkageName: "_Z2f1v", scope: !1, file: !1, line: 3, type: !5, scopeLine: 3, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !7)
  !5 = !DISubroutineType(types: !6)
  !6 = !{null}
  !7 = !{}
  !8 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "t1", scope: !9, file: !1, line: 1, size: 8, flags: DIFlagTypePassByValue, elements: !7, identifier: "_ZTSN2ns2t1E")
  !9 = !DINamespace(name: "ns", scope: null)
  !10 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !11, producer: "clang version 14.0.0 (git at github.com:llvm/llvm-project.git 75b622a7959479ccdb758ebe0973061b7b4fcacd)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: true, nameTableKind: GNU)
  !11 = !DIFile(filename: "b.cpp", directory: "/usr/local/google/home/blaikie/dev/scratch")
  !12 = !{!"clang version 14.0.0 (git at github.com:llvm/llvm-project.git 75b622a7959479ccdb758ebe0973061b7b4fcacd)"}
  !13 = !{i32 7, !"Dwarf Version", i32 4}
  !14 = !{i32 2, !"Debug Info Version", i32 3}
  !15 = !{i32 1, !"wchar_size", i32 4}
  !16 = !{i32 7, !"uwtable", i32 1}
  !17 = !{i32 7, !"frame-pointer", i32 2}
  !18 = distinct !DISubprogram(name: "f2", linkageName: "_Z2f2v", scope: !1, file: !1, line: 4, type: !5, scopeLine: 4, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !7)
  !19 = !DILocation(line: 4, column: 13, scope: !18)
  !20 = !DILocation(line: 4, column: 19, scope: !18)
  !21 = !DILocalVariable(name: "v1", scope: !4, file: !1, line: 3, type: !8)
  !22 = !DILocation(line: 3, column: 37, scope: !4)
  !23 = !DILocation(line: 3, column: 41, scope: !4)
  !24 = !DILocation(line: 3, column: 48, scope: !4)
  !25 = distinct !DISubprogram(name: "main", scope: !11, file: !11, line: 2, type: !26, scopeLine: 2, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !10, retainedNodes: !7)
  !26 = !DISubroutineType(types: !27)
  !27 = !{!28}
  !28 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
  !29 = !DILocation(line: 3, column: 3, scope: !25)
  !30 = !DILocation(line: 4, column: 1, scope: !25)

I'll look into reverting this (& dependent patches) after lunch to unblock the main branch - but happy to work with you/continue to work on this to figure out how to address the issue. It may be a latent bug of my own creation regarding testing the `splitDwarfInilning` property on the wrong CU or something.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113741



More information about the llvm-commits mailing list