[llvm] 2b8d706 - [IR] GetUnderlyingObject(), stripPointerCastsAndOffsets(): don't crash on `bitcast <1 x i8*> to i8*`
Roman Lebedev via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 24 14:59:23 PDT 2020
Author: Roman Lebedev
Date: 2020-06-25T00:58:53+03:00
New Revision: 2b8d706b19c0e049da3eb62572b08af72ba2e5e6
URL: https://github.com/llvm/llvm-project/commit/2b8d706b19c0e049da3eb62572b08af72ba2e5e6
DIFF: https://github.com/llvm/llvm-project/commit/2b8d706b19c0e049da3eb62572b08af72ba2e5e6.diff
LOG: [IR] GetUnderlyingObject(), stripPointerCastsAndOffsets(): don't crash on `bitcast <1 x i8*> to i8*`
I'm not sure how to write standalone tests for each of two changes here.
If either one of these two fixes is missing, the test fill crash.
Added:
llvm/test/Transforms/InstSimplify/icmp.ll
Modified:
llvm/lib/Analysis/ValueTracking.cpp
llvm/lib/IR/Value.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 927add44dda3..9db6aabc728f 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -4147,6 +4147,8 @@ Value *llvm::GetUnderlyingObject(Value *V, const DataLayout &DL,
} else if (Operator::getOpcode(V) == Instruction::BitCast ||
Operator::getOpcode(V) == Instruction::AddrSpaceCast) {
V = cast<Operator>(V)->getOperand(0);
+ if (!V->getType()->isPointerTy())
+ return V;
} else if (GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) {
if (GA->isInterposable())
return V;
diff --git a/llvm/lib/IR/Value.cpp b/llvm/lib/IR/Value.cpp
index 0fd147c3a44d..e264eb1f7d72 100644
--- a/llvm/lib/IR/Value.cpp
+++ b/llvm/lib/IR/Value.cpp
@@ -552,6 +552,8 @@ static const Value *stripPointerCastsAndOffsets(
V = GEP->getPointerOperand();
} else if (Operator::getOpcode(V) == Instruction::BitCast) {
V = cast<Operator>(V)->getOperand(0);
+ if (!V->getType()->isPointerTy())
+ return V;
} else if (StripKind != PSK_ZeroIndicesSameRepresentation &&
Operator::getOpcode(V) == Instruction::AddrSpaceCast) {
// TODO: If we know an address space cast will not change the
diff --git a/llvm/test/Transforms/InstSimplify/icmp.ll b/llvm/test/Transforms/InstSimplify/icmp.ll
new file mode 100644
index 000000000000..489f73c9495c
--- /dev/null
+++ b/llvm/test/Transforms/InstSimplify/icmp.ll
@@ -0,0 +1,14 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -instsimplify -S | FileCheck %s
+
+target datalayout = "e-p:64:64:64-p1:16:16:16-p2:32:32:32-p3:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+
+declare void @usei8ptr(i8* %ptr)
+
+; Ensure that we do not crash when looking at such a weird bitcast.
+define i1 @bitcast_from_single_element_pointer_vector_to_pointer(<1 x i8*> %ptr1vec, i8* %ptr2) {
+ %ptr1 = bitcast <1 x i8*> %ptr1vec to i8*
+ call void @usei8ptr(i8* %ptr1)
+ %cmp = icmp eq i8* %ptr1, %ptr2
+ ret i1 %cmp
+}
More information about the llvm-commits
mailing list