diff options
author | Matt Arsenault <Matthew.Arsenault@amd.com> | 2013-09-30 21:23:03 +0000 |
---|---|---|
committer | Matt Arsenault <Matthew.Arsenault@amd.com> | 2013-09-30 21:23:03 +0000 |
commit | 2ebcd57e6adf2dc951eb7ad5f42952961f1a60c9 (patch) | |
tree | bb81d00fa401a9d621e5d022c3b2f8ed1c0b37f2 /unittests/IR | |
parent | 3ca8f2e5d5d8cb0551b42ef89deaaadd9c4cb067 (diff) | |
download | external_llvm-2ebcd57e6adf2dc951eb7ad5f42952961f1a60c9.zip external_llvm-2ebcd57e6adf2dc951eb7ad5f42952961f1a60c9.tar.gz external_llvm-2ebcd57e6adf2dc951eb7ad5f42952961f1a60c9.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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@191702 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/IR')
-rw-r--r-- | unittests/IR/ValueTest.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/unittests/IR/ValueTest.cpp b/unittests/IR/ValueTest.cpp index 52efb1a..ebe23e8 100644 --- a/unittests/IR/ValueTest.cpp +++ b/unittests/IR/ValueTest.cpp @@ -43,4 +43,44 @@ TEST(ValueTest, UsedInBasicBlock) { EXPECT_TRUE(F->arg_begin()->isUsedInBasicBlock(F->begin())); } +TEST(GlobalTest, CreateAddressSpace) { + LLVMContext &Ctx = getGlobalContext(); + OwningPtr<Module> M(new Module("TestModule", Ctx)); + Type *Int8Ty = Type::getInt8Ty(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); + EXPECT_EQ(1u, Dummy1->getType()->getPointerAddressSpace()); + + + // This one requires a bitcast, but the address space must also stay the same. + GlobalVariable *DummyCast0 + = new GlobalVariable(*M, + Int32Ty, + true, + GlobalValue::ExternalLinkage, + Constant::getAllOnesValue(Int32Ty), + "dummy_cast", + 0, + GlobalVariable::NotThreadLocal, + 1); + + // Make sure the address space isn't dropped when returning this. + Constant *DummyCast1 = M->getOrInsertGlobal("dummy_cast", Int8Ty); + EXPECT_EQ(1u, DummyCast1->getType()->getPointerAddressSpace()); + EXPECT_NE(DummyCast0, DummyCast1) << *DummyCast1; +} } // end anonymous namespace |