From 00e65b2afe5861942dcfbb5e18e6aab187125276 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Fri, 15 Nov 2013 02:19:52 +0000 Subject: Fix test failures after addrspacecast added. Bitcasts between address spaces are no longer allowed. llvm-svn: 194765 --- clang/lib/CodeGen/CodeGenModule.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'clang/lib/CodeGen/CodeGenModule.cpp') diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index da54de0..f5fdfdb 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -1557,6 +1557,9 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef MangledName, return Entry; // Make sure the result is of the correct type. + if (Entry->getType()->getAddressSpace() != Ty->getAddressSpace()) + return llvm::ConstantExpr::getAddrSpaceCast(Entry, Ty); + return llvm::ConstantExpr::getBitCast(Entry, Ty); } @@ -1607,9 +1610,9 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef MangledName, } if (AddrSpace != Ty->getAddressSpace()) - return llvm::ConstantExpr::getBitCast(GV, Ty); - else - return GV; + return llvm::ConstantExpr::getAddrSpaceCast(GV, Ty); + + return GV; } @@ -1802,7 +1805,8 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D) { // Strip off a bitcast if we got one back. if (llvm::ConstantExpr *CE = dyn_cast(Entry)) { assert(CE->getOpcode() == llvm::Instruction::BitCast || - // all zero index gep. + CE->getOpcode() == llvm::Instruction::AddrSpaceCast || + // All zero index gep. CE->getOpcode() == llvm::Instruction::GetElementPtr); Entry = CE->getOperand(0); } -- cgit v1.1