diff options
author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2014-08-16 01:54:32 +0000 |
---|---|---|
committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2014-08-16 01:54:32 +0000 |
commit | 0c39d40c8b1e3ef028b4082593896e24633a66d7 (patch) | |
tree | b70be8489bdd6a050bc50bc3497cf9f585fa3e48 /llvm/lib/IR/ConstantFold.cpp | |
parent | 1b44db22c6e378080539a35ce1fd1f9b1f85c9b1 (diff) | |
download | llvm-0c39d40c8b1e3ef028b4082593896e24633a66d7.zip llvm-0c39d40c8b1e3ef028b4082593896e24633a66d7.tar.gz llvm-0c39d40c8b1e3ef028b4082593896e24633a66d7.tar.bz2 |
IR: Don't add inbounds to GEPs of extern_weak variables
Global variables that have `extern_weak` linkage may be null, so it's
incorrect to add `inbounds` when constant folding.
This also fixes a bug when parsing global aliases, whose forward
reference placeholders are global variables with `extern_weak` linkage.
If GEPs to these aliases are encountered before the alias itself, the
GEPs would incorrectly gain the `inbounds` keyword as well.
llvm-svn: 215803
Diffstat (limited to 'llvm/lib/IR/ConstantFold.cpp')
-rw-r--r-- | llvm/lib/IR/ConstantFold.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp index 395ac39..9124c11 100644 --- a/llvm/lib/IR/ConstantFold.cpp +++ b/llvm/lib/IR/ConstantFold.cpp @@ -2144,9 +2144,10 @@ static Constant *ConstantFoldGetElementPtrImpl(Constant *C, // If all indices are known integers and normalized, we can do a simple // check for the "inbounds" property. - if (!Unknown && !inBounds && - isa<GlobalVariable>(C) && isInBoundsIndices(Idxs)) - return ConstantExpr::getInBoundsGetElementPtr(C, Idxs); + if (!Unknown && !inBounds) + if (auto *GV = dyn_cast<GlobalVariable>(C)) + if (!GV->hasExternalWeakLinkage() && isInBoundsIndices(Idxs)) + return ConstantExpr::getInBoundsGetElementPtr(C, Idxs); return nullptr; } |