llvm.org GIT mirror llvm / 3c7da1c
[ArgumentPromotion] Change use of removed argument in llvm.dbg.value to undef Summary: This solves PR33641. When removing a dead argument we must also handle possibly existing calls to llvm.dbg.value that use the removed argument. Now we change the use of the otherwise dead argument to an undef for some other pass to cleanup later. If the calls are left untouched, they will later on cause errors: "function-local metadata used in wrong function" since the ArgumentPromotion rewrites the code by creating a new function with the wanted signature, but the metadata is not recreated so the new function may then erroneously use metadata from the old function. Reviewers: mstorsjo, rnk, arsenm Reviewed By: rnk Subscribers: wdng, llvm-commits Differential Revision: https://reviews.llvm.org/D34874 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@307521 91177308-0d34-0410-b5e6-96231b3b80d8 Mikael Holmen 2 years ago
2 changed file(s) with 42 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
123123 } else if (I->use_empty()) {
124124 // Dead argument (which are always marked as promotable)
125125 ++NumArgumentsDead;
126
127 // There may be remaining metadata uses of the argument for things like
128 // llvm.dbg.value. Replace them with undef.
129 I->replaceAllUsesWith(UndefValue::get(I->getType()));
126130 } else {
127131 // Okay, this is being promoted. This means that the only uses are loads
128132 // or GEPs which are only used by loads
0 ; RUN: opt -argpromotion -verify -dse -S %s -o - | FileCheck %s
1
2 ; Fix for PR33641. ArgumentPromotion removed the argument to bar but left the call to
3 ; dbg.value which still used the removed argument.
4
5 %p_t = type i16*
6 %fun_t = type void (%p_t)*
7
8 define void @foo() {
9 %tmp = alloca %fun_t
10 store %fun_t @bar, %fun_t* %tmp
11 ret void
12 }
13
14 define internal void @bar(%p_t %p) {
15 call void @llvm.dbg.value(metadata %p_t %p, i64 0, metadata !4, metadata !5), !dbg !6
16 ret void
17 }
18
19 declare void @llvm.dbg.value(metadata, i64, metadata, metadata)
20
21 !llvm.dbg.cu = !{!0}
22 !llvm.module.flags = !{!2}
23
24 !0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1)
25 !1 = !DIFile(filename: "test.c", directory: "")
26 !2 = !{i32 2, !"Debug Info Version", i32 3}
27 !3 = distinct !DISubprogram(name: "bar", unit: !0)
28 !4 = !DILocalVariable(name: "p", scope: !3)
29 !5 = !DIExpression()
30 !6 = !DILocation(line: 1, column: 1, scope: !3)
31
32 ; The %p argument should be removed, and the use of it in dbg.value should be
33 ; changed to undef.
34 ; CHECK: define internal void @bar() {
35 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i16* undef
36 ; CHECK-NEXT: ret void
37 ; CHECK-NEXT: }