Skip to content

Commit ce01788

Browse files
Merge pull request #2693 from adrian-prantl/75341300
Support !heapallocsite attachments in stripNonLineTableDebugInfo().
2 parents 853072e + 9aaa03a commit ce01788

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

llvm/lib/IR/DebugInfo.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,9 @@ bool llvm::stripDebugInfo(Function &F) {
345345
if (NewLoopID != LoopID)
346346
I.setMetadata(LLVMContext::MD_loop, NewLoopID);
347347
}
348+
// Strip heapallocsite attachments, they point into the DIType system.
349+
if (I.hasMetadataOtherThanDebugLoc())
350+
I.setMetadata("heapallocsite", nullptr);
348351
}
349352
}
350353
return Changed;
@@ -658,6 +661,10 @@ bool llvm::stripNonLineTableDebugInfo(Module &M) {
658661
updateLoopMetadataDebugLocations(I, [&](const DILocation &Loc) {
659662
return remapDebugLoc(&Loc).get();
660663
});
664+
665+
// Strip heapallocsite attachments, they point into the DIType system.
666+
if (I.hasMetadataOtherThanDebugLoc())
667+
I.setMetadata("heapallocsite", nullptr);
661668
}
662669
}
663670
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
; RUN: opt -S -strip-nonlinetable-debuginfo %s -o - | FileCheck %s
2+
; RUN: opt -S -strip-debug %s -o - | FileCheck %s
3+
; int *get() { return new int[256]; }
4+
; ModuleID = '/tmp/heapallocsite.cpp'
5+
source_filename = "/tmp/heapallocsite.cpp"
6+
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
7+
target triple = "x86_64-apple-macosx11.0.0"
8+
9+
; Function Attrs: noinline optnone ssp uwtable mustprogress
10+
define dso_local i32* @_Z3getv() #0 !dbg !8 {
11+
entry:
12+
; CHECK-LABEL: entry:
13+
; CHECK-NOT: !heapallocsite
14+
%call = call noalias nonnull i8* @_Znam(i64 1024) #2, !dbg !14, !heapallocsite !13
15+
%0 = bitcast i8* %call to i32*, !dbg !14
16+
ret i32* %0, !dbg !15
17+
}
18+
19+
; Function Attrs: nobuiltin allocsize(0)
20+
declare nonnull i8* @_Znam(i64) #1
21+
22+
attributes #0 = { noinline optnone ssp uwtable }
23+
attributes #1 = { nobuiltin allocsize(0) "frame-pointer"="all" }
24+
attributes #2 = { builtin allocsize(0) }
25+
26+
!llvm.dbg.cu = !{!0}
27+
!llvm.module.flags = !{!3, !4, !5, !6}
28+
!llvm.ident = !{!7}
29+
30+
; CHECK-LABEL: !llvm.ident
31+
; CHECK-NOT: !DIBasicType(name: "int"
32+
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 13.0.0 ([email protected]:llvm/llvm-project 6d4ce49dae17715de502acbd50ab4c9b3c18215b)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None, sysroot: "/")
33+
!1 = !DIFile(filename: "/tmp/heapallocsite.cpp", directory: "/Volumes/Data/llvm-project")
34+
!2 = !{}
35+
!3 = !{i32 7, !"Dwarf Version", i32 4}
36+
!4 = !{i32 2, !"Debug Info Version", i32 3}
37+
!5 = !{i32 1, !"wchar_size", i32 4}
38+
!6 = !{i32 7, !"PIC Level", i32 2}
39+
!7 = !{!"clang version 13.0.0 ([email protected]:llvm/llvm-project 6d4ce49dae17715de502acbd50ab4c9b3c18215b)"}
40+
!8 = distinct !DISubprogram(name: "get", linkageName: "_Z3getv", scope: !9, file: !9, line: 1, type: !10, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
41+
!9 = !DIFile(filename: "/tmp/heapallocsite.cpp", directory: "")
42+
!10 = !DISubroutineType(types: !11)
43+
!11 = !{!12}
44+
!12 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !13, size: 64)
45+
!13 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
46+
!14 = !DILocation(line: 1, column: 21, scope: !8)
47+
!15 = !DILocation(line: 1, column: 14, scope: !8)

0 commit comments

Comments
 (0)