summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKeno Fischer <kfischer@college.harvard.edu>2016-01-14 19:12:27 +0000
committerKeno Fischer <kfischer@college.harvard.edu>2016-01-14 19:12:27 +0000
commit1dd319f3b6e4ecee804a0e0e21ae38f85790f188 (patch)
treedb13d2583ae93c404811f92df5a8a806082355c6
parent9b0cfe25107d0b1ac08fea712a909c988eb4cc09 (diff)
downloadbcm5719-llvm-1dd319f3b6e4ecee804a0e0e21ae38f85790f188.tar.gz
bcm5719-llvm-1dd319f3b6e4ecee804a0e0e21ae38f85790f188.zip
[Utils] Fix incorrect dbg.declare store conversion
Summary: The dbg.declare -> dbg.value conversion did not check which operand of the store instruction the alloca was passed to. As a result code that stored the address of an alloca, rather than storing to the alloca, would still trigger the conversion routine, leading to the insertion of an incorrect dbg.value intrinsic. Reviewers: aprantl Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D16169 llvm-svn: 257787
-rw-r--r--llvm/lib/Transforms/Utils/Local.cpp13
-rw-r--r--llvm/test/Transforms/Util/store-first-op.ll36
2 files changed, 44 insertions, 5 deletions
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index d2793e5ecb5..e28232c4201 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -1133,12 +1133,14 @@ bool llvm::LowerDbgDeclare(Function &F) {
// the stack slot (and at a lexical-scope granularity). Later
// passes will attempt to elide the stack slot.
if (AI && !isArray(AI)) {
- for (User *U : AI->users())
- if (StoreInst *SI = dyn_cast<StoreInst>(U))
- ConvertDebugDeclareToDebugValue(DDI, SI, DIB);
- else if (LoadInst *LI = dyn_cast<LoadInst>(U))
+ for (auto &AIUse : AI->uses()) {
+ User *U = AIUse.getUser();
+ if (StoreInst *SI = dyn_cast<StoreInst>(U)) {
+ if (AIUse.getOperandNo() == 1)
+ ConvertDebugDeclareToDebugValue(DDI, SI, DIB);
+ } else if (LoadInst *LI = dyn_cast<LoadInst>(U)) {
ConvertDebugDeclareToDebugValue(DDI, LI, DIB);
- else if (CallInst *CI = dyn_cast<CallInst>(U)) {
+ } else if (CallInst *CI = dyn_cast<CallInst>(U)) {
// This is a call by-value or some other instruction that
// takes a pointer to the variable. Insert a *value*
// intrinsic that describes the alloca.
@@ -1150,6 +1152,7 @@ bool llvm::LowerDbgDeclare(Function &F) {
DIB.createExpression(NewDIExpr),
DDI->getDebugLoc(), CI);
}
+ }
DDI->eraseFromParent();
}
}
diff --git a/llvm/test/Transforms/Util/store-first-op.ll b/llvm/test/Transforms/Util/store-first-op.ll
new file mode 100644
index 00000000000..9718fdd9c1f
--- /dev/null
+++ b/llvm/test/Transforms/Util/store-first-op.ll
@@ -0,0 +1,36 @@
+; RUN: opt -instcombine -S %s | FileCheck %s
+
+%foo = type { i8 }
+
+; Function Attrs: nounwind uwtable
+define void @_ZN4llvm13ScaledNumbers10multiply64Emm() {
+entry:
+ %getU = alloca %foo, align 1
+; This is supposed to make sure that the declare conversion, does not accidentally think the store OF
+; %getU is a store TO %getU. There are valid reasons to have an llvm.dbg.value here, but if the pass
+; is changed to emit such, a more specific check should be added to make sure that any llvm.dbg.value
+; is correct.
+; CHECK-NOT: @llvm.dbg.value(metadata %foo* %getU
+ call void @llvm.dbg.declare(metadata %foo* %getU, metadata !3, metadata !6), !dbg !7
+ store %foo* %getU, %foo** undef, align 8, !tbaa !8
+ unreachable
+}
+
+; Function Attrs: nounwind readnone
+declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
+
+attributes #1 = { nounwind readnone }
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!2}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.8.0 (https://github.com/llvm-mirror/clang 89dda3855cda574f355e6defa1d77bdae5053994) (llvm/trunk 257597)", isOptimized: true, runtimeVersion: 0, emissionKind: 1)
+!1 = !DIFile(filename: "none", directory: ".")
+!2 = !{i32 2, !"Debug Info Version", i32 3}
+!3 = !DILocalVariable(name: "getU", scope: !4, file: !1, line: 25, type: !5)
+!4 = distinct !DISubprogram(name: "multiply64", linkageName: "_ZN4llvm13ScaledNumbers10multiply64Emm", scope: null, file: !1, line: 22, isLocal: false, isDefinition: true, scopeLine: 23, flags: DIFlagPrototyped, isOptimized: true)
+!5 = !DICompositeType(tag: DW_TAG_class_type, scope: !4, file: !1, line: 25, size: 8, align: 8)
+!6 = !DIExpression()
+!7 = !DILocation(line: 25, column: 8, scope: !4)
+!8 = !{!9, !9, i64 0}
+!9 = !{i64 0}
OpenPOWER on IntegriCloud