Small fix for bug 18635.

(clang crashed in CodeGen in llvm::Module::getNamedValue on
 thread_local std::unique_ptr<int>).
Differential Revision: http://reviews.llvm.org/D5353

llvm-svn: 218503
This commit is contained in:
Alexander Musman 2014-09-26 06:28:25 +00:00
parent 56167c3e95
commit f94c318ea0
2 changed files with 30 additions and 7 deletions

View File

@ -235,7 +235,7 @@ public:
llvm::Constant *dtor, llvm::Constant *addr) override;
llvm::Function *getOrCreateThreadLocalWrapper(const VarDecl *VD,
llvm::GlobalVariable *Var);
llvm::Value *Val);
void EmitThreadLocalInitFuncs(
ArrayRef<std::pair<const VarDecl *, llvm::GlobalVariable *> > Decls,
llvm::Function *InitFunc) override;
@ -1870,7 +1870,7 @@ getThreadLocalWrapperLinkage(const VarDecl *VD, CodeGen::CodeGenModule &CGM) {
llvm::Function *
ItaniumCXXABI::getOrCreateThreadLocalWrapper(const VarDecl *VD,
llvm::GlobalVariable *Var) {
llvm::Value *Val) {
// Mangle the name for the thread_local wrapper function.
SmallString<256> WrapperName;
{
@ -1879,10 +1879,10 @@ ItaniumCXXABI::getOrCreateThreadLocalWrapper(const VarDecl *VD,
Out.flush();
}
if (llvm::Value *V = Var->getParent()->getNamedValue(WrapperName))
if (llvm::Value *V = CGM.getModule().getNamedValue(WrapperName))
return cast<llvm::Function>(V);
llvm::Type *RetTy = Var->getType();
llvm::Type *RetTy = Val->getType();
if (VD->getType()->isReferenceType())
RetTy = RetTy->getPointerElementType();
@ -1970,7 +1970,9 @@ void ItaniumCXXABI::EmitThreadLocalInitFuncs(
LI->setAlignment(CGM.getContext().getDeclAlign(VD).getQuantity());
Val = LI;
}
if (Val->getType() != Wrapper->getReturnType())
Val = Builder.CreatePointerBitCastOrAddrSpaceCast(
Val, Wrapper->getReturnType(), "");
Builder.CreateRet(Val);
}
}
@ -1981,8 +1983,7 @@ LValue ItaniumCXXABI::EmitThreadLocalVarDeclLValue(CodeGenFunction &CGF,
QualType T = VD->getType();
llvm::Type *Ty = CGF.getTypes().ConvertTypeForMem(T);
llvm::Value *Val = CGF.CGM.GetAddrOfGlobalVar(VD, Ty);
llvm::Function *Wrapper =
getOrCreateThreadLocalWrapper(VD, cast<llvm::GlobalVariable>(Val));
llvm::Function *Wrapper = getOrCreateThreadLocalWrapper(VD, Val);
Val = CGF.Builder.CreateCall(Wrapper);

View File

@ -0,0 +1,22 @@
// RUN: %clang_cc1 -emit-llvm -std=c++11 -triple x86_64-pc-linux-gnu -o- %s | FileCheck %s
// Global @x:
// CHECK: [[X_GLOBAL:@[^ ]+]]{{.*}}thread_local global
// returned somewhere in TLS wrapper:
// CHECK: ret{{.*}}[[X_GLOBAL]]
template <typename T> class unique_ptr {
template <typename F, typename S> struct pair {
F first;
S second;
};
pair<T *, int> data;
public:
constexpr unique_ptr() noexcept : data() {}
explicit unique_ptr(T *p) noexcept : data() {}
};
thread_local unique_ptr<int> x;
int main() { x = unique_ptr<int>(new int(5)); }