diff options
author | Nikita Popov <npopov@redhat.com> | 2023-01-30 15:30:20 +0100 |
---|---|---|
committer | Nikita Popov <npopov@redhat.com> | 2023-01-31 11:33:00 +0100 |
commit | 5f01a626dd0615df49773d419c75aeb33666ee83 (patch) | |
tree | dce5022cbbc8878bca52ab1bb5ecbfba96937d05 /llvm/lib/IR/ConstantFold.cpp | |
parent | 5170610b5789cde77a948fe57a715c512dcfe350 (diff) | |
download | llvm-5f01a626dd0615df49773d419c75aeb33666ee83.zip llvm-5f01a626dd0615df49773d419c75aeb33666ee83.tar.gz llvm-5f01a626dd0615df49773d419c75aeb33666ee83.tar.bz2 |
[ConstantFold] Fix inbounds inference on mismatching source element type
When inferring that a GEP of a global variable is inbounds because
there is no notional overindexing, we need to check that the
global value type and the GEP source element type match.
This was not necessary with typed pointers (because we would have
a bitcast in between), but is necessary with opaque pointers.
We should be able to recover some of the safe cases by performing
an offset based inbounds inference in DL-aware ConstantFolding.
Diffstat (limited to 'llvm/lib/IR/ConstantFold.cpp')
-rw-r--r-- | llvm/lib/IR/ConstantFold.cpp | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp index f84fe79..5fa56d3 100644 --- a/llvm/lib/IR/ConstantFold.cpp +++ b/llvm/lib/IR/ConstantFold.cpp @@ -2280,7 +2280,8 @@ Constant *llvm::ConstantFoldGetElementPtr(Type *PointeeTy, Constant *C, // check for the "inbounds" property. if (!Unknown && !InBounds) if (auto *GV = dyn_cast<GlobalVariable>(C)) - if (!GV->hasExternalWeakLinkage() && isInBoundsIndices(Idxs)) + if (!GV->hasExternalWeakLinkage() && GV->getValueType() == PointeeTy && + isInBoundsIndices(Idxs)) return ConstantExpr::getGetElementPtr(PointeeTy, C, Idxs, /*InBounds=*/true, InRangeIndex); |