Skip to content

Commit fc69ad0

Browse files
committed
[codeview] Workaround for PR43479, don't re-emit instr labels
Summary: In the long run we should come up with another mechanism for marking call instructions as heap allocation sites, and remove this workaround. For now, we've had two bug reports about this, so let's apply this workaround. SLH (the other client of instruction labels) probably has the same bug, but the solution there is more likely to be to mark the call instruction as not duplicatable, which doesn't work for debug info. Reviewers: akhuang Subscribers: aprantl, hiraditya, aganea, chandlerc, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D69068 llvm-svn: 375137
1 parent d4b7a60 commit fc69ad0

File tree

2 files changed

+93
-4
lines changed

2 files changed

+93
-4
lines changed

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,9 +1065,13 @@ void AsmPrinter::EmitFunctionBody() {
10651065
++NumInstsInFunction;
10661066
}
10671067

1068-
// If there is a pre-instruction symbol, emit a label for it here.
1068+
// If there is a pre-instruction symbol, emit a label for it here. If the
1069+
// instruction was duplicated and the label has already been emitted,
1070+
// don't re-emit the same label.
1071+
// FIXME: Consider strengthening that to an assertion.
10691072
if (MCSymbol *S = MI.getPreInstrSymbol())
1070-
OutStreamer->EmitLabel(S);
1073+
if (S->isUndefined())
1074+
OutStreamer->EmitLabel(S);
10711075

10721076
if (ShouldPrintDebugScopes) {
10731077
for (const HandlerInfo &HI : Handlers) {
@@ -1120,9 +1124,13 @@ void AsmPrinter::EmitFunctionBody() {
11201124
break;
11211125
}
11221126

1123-
// If there is a post-instruction symbol, emit a label for it here.
1127+
// If there is a post-instruction symbol, emit a label for it here. If
1128+
// the instruction was duplicated and the label has already been emitted,
1129+
// don't re-emit the same label.
1130+
// FIXME: Consider strengthening that to an assertion.
11241131
if (MCSymbol *S = MI.getPostInstrSymbol())
1125-
OutStreamer->EmitLabel(S);
1132+
if (S->isUndefined())
1133+
OutStreamer->EmitLabel(S);
11261134

11271135
if (ShouldPrintDebugScopes) {
11281136
for (const HandlerInfo &HI : Handlers) {
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
; RUN: llc < %s -tail-dup-placement-threshold=4 | FileCheck %s
2+
3+
; Based on test case from PR43695:
4+
; __declspec(allocator) void *alloc(unsigned int size);
5+
; void f2();
6+
; void f1(unsigned int *size_ptr) {
7+
; void *hg = alloc(size_ptr ? *size_ptr : 1UL);
8+
; f2();
9+
; }
10+
11+
; In this case, block placement duplicates the heap allocation site. For now,
12+
; LLVM drops the labels from one call site. Eventually, we should track both.
13+
14+
; ModuleID = 't.cpp'
15+
source_filename = "t.cpp"
16+
target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
17+
target triple = "x86_64-pc-windows-msvc19.22.27905"
18+
19+
define dso_local void @taildupit(i32* readonly %size_ptr) !dbg !8 {
20+
entry:
21+
call void @llvm.dbg.value(metadata i32* %size_ptr, metadata !14, metadata !DIExpression()), !dbg !17
22+
%tobool = icmp eq i32* %size_ptr, null, !dbg !18
23+
br i1 %tobool, label %cond.end, label %cond.true, !dbg !18
24+
25+
cond.true: ; preds = %entry
26+
%0 = load i32, i32* %size_ptr, align 4, !dbg !18, !tbaa !19
27+
br label %cond.end, !dbg !18
28+
29+
cond.end: ; preds = %entry, %cond.true
30+
%cond = phi i32 [ %0, %cond.true ], [ 1, %entry ], !dbg !18
31+
%call = tail call i8* @alloc(i32 %cond), !dbg !18, !heapallocsite !2
32+
call void @llvm.dbg.value(metadata i8* %call, metadata !15, metadata !DIExpression()), !dbg !17
33+
tail call void @f2(), !dbg !23
34+
ret void, !dbg !24
35+
}
36+
37+
; CHECK-LABEL: taildupit: # @taildupit
38+
; CHECK: testq
39+
; CHECK: je
40+
; CHECK: .Lheapallocsite0:
41+
; CHECK: callq alloc
42+
; CHECK: .Lheapallocsite1:
43+
; CHECK: jmp f2 # TAILCALL
44+
; CHECK-NOT: Lheapallocsite
45+
; CHECK: callq alloc
46+
; CHECK-NOT: Lheapallocsite
47+
; CHECK: jmp f2 # TAILCALL
48+
49+
declare dso_local i8* @alloc(i32)
50+
51+
declare dso_local void @f2()
52+
53+
declare void @llvm.dbg.value(metadata, metadata, metadata)
54+
55+
!llvm.dbg.cu = !{!0}
56+
!llvm.module.flags = !{!3, !4, !5, !6}
57+
58+
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 10.0.0 (git@github.com:llvm/llvm-project.git 0650355c09ab8e6605ae37b818270a7a7c8ce2c7)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
59+
!1 = !DIFile(filename: "t.cpp", directory: "C:\\src\\llvm-project\\build", checksumkind: CSK_MD5, checksum: "b227901e92d848fa564190b0762d757c")
60+
!2 = !{}
61+
!3 = !{i32 2, !"CodeView", i32 1}
62+
!4 = !{i32 2, !"Debug Info Version", i32 3}
63+
!5 = !{i32 1, !"wchar_size", i32 2}
64+
!6 = !{i32 7, !"PIC Level", i32 2}
65+
!8 = distinct !DISubprogram(name: "f1", linkageName: "?f1@@YAXPEAI@Z", scope: !1, file: !1, line: 5, type: !9, scopeLine: 5, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !13)
66+
!9 = !DISubroutineType(types: !10)
67+
!10 = !{null, !11}
68+
!11 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64)
69+
!12 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
70+
!13 = !{!14, !15}
71+
!14 = !DILocalVariable(name: "size_ptr", arg: 1, scope: !8, file: !1, line: 5, type: !11)
72+
!15 = !DILocalVariable(name: "hg", scope: !8, file: !1, line: 6, type: !16)
73+
!16 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)
74+
!17 = !DILocation(line: 0, scope: !8)
75+
!18 = !DILocation(line: 6, scope: !8)
76+
!19 = !{!20, !20, i64 0}
77+
!20 = !{!"int", !21, i64 0}
78+
!21 = !{!"omnipotent char", !22, i64 0}
79+
!22 = !{!"Simple C++ TBAA"}
80+
!23 = !DILocation(line: 7, scope: !8)
81+
!24 = !DILocation(line: 8, scope: !8)

0 commit comments

Comments
 (0)