summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManoj Gupta <manojgupta@google.com>2018-07-23 21:20:00 +0000
committerManoj Gupta <manojgupta@google.com>2018-07-23 21:20:00 +0000
commitf9f50f634d4d6cae8d844b5a7b764e1159dce8e4 (patch)
tree3b0ccd12702e3591443a9c74aa9e6f49b06f7925
parent9df80e8248e23f779e396fdd6994b7c2346d937f (diff)
downloadbcm5719-llvm-f9f50f634d4d6cae8d844b5a7b764e1159dce8e4.tar.gz
bcm5719-llvm-f9f50f634d4d6cae8d844b5a7b764e1159dce8e4.zip
ConstantFolding: Avoid a crash.
Summary: Check if the parent basic block and caller exists before calling CS.getCaller when constant folding strip.invariant.group instrinsic. This avoids a crash when the function containing the intrinsic is being inlined. The instruction is checked for any simplifiction but has not yet been added to a basic block. Reviewers: Prazek, rsmith, efriedma Reviewed By: efriedma Subscribers: eraman, llvm-commits Differential Revision: https://reviews.llvm.org/D49690 llvm-svn: 337742
-rw-r--r--llvm/lib/Analysis/ConstantFolding.cpp19
-rw-r--r--llvm/test/Transforms/Inline/inline_inv_group.ll19
2 files changed, 32 insertions, 6 deletions
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index a49007ee499..c5281c57bc1 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -1603,14 +1603,21 @@ Constant *ConstantFoldScalarCall(StringRef Name, unsigned IntrinsicID, Type *Ty,
return Operands[0];
}
- if (isa<ConstantPointerNull>(Operands[0]) &&
- !NullPointerIsDefined(
- CS.getCaller(), Operands[0]->getType()->getPointerAddressSpace())) {
+ if (isa<ConstantPointerNull>(Operands[0])) {
// launder(null) == null == strip(null) iff in addrspace 0
if (IntrinsicID == Intrinsic::launder_invariant_group ||
- IntrinsicID == Intrinsic::strip_invariant_group)
- return Operands[0];
- return nullptr;
+ IntrinsicID == Intrinsic::strip_invariant_group) {
+ // If instruction is not yet put in a basic block (e.g. when cloning
+ // a function during inlining), CS caller may not be available.
+ // So check CS's BB first before querying CS.getCaller.
+ const Function *Caller = CS.getParent() ? CS.getCaller() : nullptr;
+ if (Caller &&
+ !NullPointerIsDefined(
+ Caller, Operands[0]->getType()->getPointerAddressSpace())) {
+ return Operands[0];
+ }
+ return nullptr;
+ }
}
if (auto *Op = dyn_cast<ConstantFP>(Operands[0])) {
diff --git a/llvm/test/Transforms/Inline/inline_inv_group.ll b/llvm/test/Transforms/Inline/inline_inv_group.ll
new file mode 100644
index 00000000000..c33048d7127
--- /dev/null
+++ b/llvm/test/Transforms/Inline/inline_inv_group.ll
@@ -0,0 +1,19 @@
+; RUN: opt < %s -inline -S | FileCheck %s
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define i8* @callee() alwaysinline {
+; CHECK-LABEL: define i8* @callee()
+ %1 = call i8* @llvm.strip.invariant.group.p0i8(i8* null)
+ ret i8* %1
+}
+
+define i8* @caller() {
+; CHECK-LABEL: define i8* @caller()
+; CHECK-NEXT: call i8* @llvm.strip.invariant.group.p0i8(i8* null)
+ %1 = call i8* @callee()
+ ret i8* %1
+}
+
+declare i8* @llvm.strip.invariant.group.p0i8(i8*)
OpenPOWER on IntegriCloud