aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/Module.cpp
diff options
context:
space:
mode:
authorMatt Arsenault <Matthew.Arsenault@amd.com>2013-09-30 21:23:03 +0000
committerMatt Arsenault <Matthew.Arsenault@amd.com>2013-09-30 21:23:03 +0000
commit27e783e90d435e56033b14ad841bc7384d321c38 (patch)
treef63199956928feb9d4847164063bbc424a573fdf /llvm/lib/IR/Module.cpp
parent8468062c6e9b04030f16668994fca00b722028c3 (diff)
downloadllvm-27e783e90d435e56033b14ad841bc7384d321c38.zip
llvm-27e783e90d435e56033b14ad841bc7384d321c38.tar.gz
llvm-27e783e90d435e56033b14ad841bc7384d321c38.tar.bz2
Fix getOrInsertGlobal dropping the address space.
Currently it will insert an illegal bitcast. Arguably, the address space argument should be added for the creation case. llvm-svn: 191702
Diffstat (limited to 'llvm/lib/IR/Module.cpp')
-rw-r--r--llvm/lib/IR/Module.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/llvm/lib/IR/Module.cpp b/llvm/lib/IR/Module.cpp
index ba4ee7f..f200da8 100644
--- a/llvm/lib/IR/Module.cpp
+++ b/llvm/lib/IR/Module.cpp
@@ -260,8 +260,10 @@ Constant *Module::getOrInsertGlobal(StringRef Name, Type *Ty) {
// If the variable exists but has the wrong type, return a bitcast to the
// right type.
- if (GV->getType() != PointerType::getUnqual(Ty))
- return ConstantExpr::getBitCast(GV, PointerType::getUnqual(Ty));
+ Type *GVTy = GV->getType();
+ PointerType *PTy = PointerType::get(Ty, GVTy->getPointerAddressSpace());
+ if (GV->getType() != PTy)
+ return ConstantExpr::getBitCast(GV, PTy);
// Otherwise, we just found the existing function or a prototype.
return GV;