[PATCH] Fix getOrInsertGlobal dropping the address space.
Matt Arsenault
Matthew.Arsenault at amd.com
Fri Sep 27 18:04:24 PDT 2013
Currently it will insert an illegal bitcast.
Arguably, the address space argument should be
added for the creation case.
http://llvm-reviews.chandlerc.com/D1781
Files:
lib/IR/Module.cpp
unittests/IR/ValueTest.cpp
Index: lib/IR/Module.cpp
===================================================================
--- lib/IR/Module.cpp
+++ lib/IR/Module.cpp
@@ -260,7 +260,8 @@
// If the variable exists but has the wrong type, return a bitcast to the
// right type.
- if (GV->getType() != PointerType::getUnqual(Ty))
+ Type *GVTy = GV->getType();
+ if (GV->getType() != PointerType::get(Ty, GVTy->getPointerAddressSpace()))
return ConstantExpr::getBitCast(GV, PointerType::getUnqual(Ty));
// Otherwise, we just found the existing function or a prototype.
Index: unittests/IR/ValueTest.cpp
===================================================================
--- unittests/IR/ValueTest.cpp
+++ unittests/IR/ValueTest.cpp
@@ -43,4 +43,24 @@
EXPECT_TRUE(F->arg_begin()->isUsedInBasicBlock(F->begin()));
}
+TEST(GlobalTest, CreateAddressSpace) {
+ LLVMContext &Ctx = getGlobalContext();
+ OwningPtr<Module> M(new Module("TestModule", Ctx));
+ Type *Int32Ty = Type::getInt32Ty(Ctx);
+
+ GlobalVariable *Dummy0
+ = new GlobalVariable(*M,
+ Int32Ty,
+ true,
+ GlobalValue::ExternalLinkage,
+ Constant::getAllOnesValue(Int32Ty),
+ "dummy",
+ 0,
+ GlobalVariable::NotThreadLocal,
+ 1);
+
+ // Make sure the address space isn't dropped when returning this.
+ Constant *Dummy1 = M->getOrInsertGlobal("dummy", Int32Ty);
+ EXPECT_EQ(Dummy0, Dummy1);
+}
} // end anonymous namespace
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1781.1.patch
Type: text/x-patch
Size: 1578 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130927/4512b001/attachment.bin>
More information about the llvm-commits
mailing list