From a9029a33ffe5cd458b51b18f7faf5d1c844f4bb4 Mon Sep 17 00:00:00 2001 From: Arthur Eubanks Date: Sat, 12 Feb 2022 17:37:20 -0800 Subject: [OpaquePtr][ValueTracking] Check GEP source element type in isPointerOffset() Fixes a MemCpyOpt miscompile with opaque pointers. This function can be further cleaned up, but let's just fix the miscompile first. Reviewed By: #opaque-pointers, nikic Differential Revision: https://reviews.llvm.org/D119652 --- llvm/lib/Analysis/ValueTracking.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'llvm/lib/Analysis/ValueTracking.cpp') diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 236db5e..2fd4565 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -7136,7 +7136,8 @@ Optional llvm::isPointerOffset(const Value *Ptr1, const Value *Ptr2, // potentially variable) indices. After that they handle some constant // offset, which determines their offset from each other. At this point, we // handle no other case. - if (!GEP1 || !GEP2 || GEP1->getOperand(0) != GEP2->getOperand(0)) + if (!GEP1 || !GEP2 || GEP1->getOperand(0) != GEP2->getOperand(0) || + GEP1->getSourceElementType() != GEP2->getSourceElementType()) return None; // Skip any common indices and track the GEP types. -- cgit v1.1