From 56ebe5082da7411fb37479e230b52735f77cff35 Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Sun, 19 Apr 2009 21:05:03 +0000 Subject: [PATCH] PR3853: Add CodeGen support for __thread. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69545 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGDecl.cpp | 9 +++------ lib/CodeGen/CodeGenModule.cpp | 8 +++----- test/CodeGen/thread-specifier.c | 10 ++++++++++ 3 files changed, 16 insertions(+), 11 deletions(-) create mode 100644 test/CodeGen/thread-specifier.c diff --git a/lib/CodeGen/CGDecl.cpp b/lib/CodeGen/CGDecl.cpp index c9e47eba77..681d8f68af 100644 --- a/lib/CodeGen/CGDecl.cpp +++ b/lib/CodeGen/CGDecl.cpp @@ -63,10 +63,6 @@ void CodeGenFunction::EmitBlockVarDecl(const VarDecl &D) { if (D.hasAttr()) CGM.ErrorUnsupported(&D, "__asm__"); - // We don't support __thread yet. - if (D.isThreadSpecified()) - CGM.ErrorUnsupported(&D, "thread local ('__thread') variable", true); - switch (D.getStorageClass()) { case VarDecl::None: case VarDecl::Auto: @@ -110,7 +106,8 @@ CodeGenFunction::CreateStaticBlockVarDecl(const VarDecl &D, const llvm::Type *LTy = CGM.getTypes().ConvertTypeForMem(Ty); return new llvm::GlobalVariable(LTy, Ty.isConstant(getContext()), Linkage, llvm::Constant::getNullValue(LTy), Name, - &CGM.getModule(), 0, Ty.getAddressSpace()); + &CGM.getModule(), D.isThreadSpecified(), + Ty.getAddressSpace()); } void CodeGenFunction::EmitStaticBlockVarDecl(const VarDecl &D) { @@ -145,7 +142,7 @@ void CodeGenFunction::EmitStaticBlockVarDecl(const VarDecl &D) { GV = new llvm::GlobalVariable(Init->getType(), OldGV->isConstant(), OldGV->getLinkage(), Init, "", - &CGM.getModule(), 0, + &CGM.getModule(), D.isThreadSpecified(), D.getType().getAddressSpace()); // Steal the name of the old global diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index a517d81545..1a52ba2ab1 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -656,10 +656,6 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMGlobal(const char *MangledName, return llvm::ConstantExpr::getBitCast(Entry, Ty); } - // We don't support __thread yet. - if (D && D->isThreadSpecified()) - ErrorUnsupported(D, "thread local ('__thread') variable", true); - // This is the first use or definition of a mangled name. If there is a // deferred decl with this name, remember that we need to emit it at the end // of the file. @@ -676,7 +672,7 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMGlobal(const char *MangledName, new llvm::GlobalVariable(Ty->getElementType(), false, llvm::GlobalValue::ExternalLinkage, 0, "", &getModule(), - 0, Ty->getAddressSpace()); + false, Ty->getAddressSpace()); GV->setName(MangledName); // Handle things which are present even on external declarations. @@ -691,6 +687,8 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMGlobal(const char *MangledName, if (D->hasAttr() || D->hasAttr()) GV->setLinkage(llvm::GlobalValue::ExternalWeakLinkage); + + GV->setThreadLocal(D->isThreadSpecified()); } return Entry = GV; diff --git a/test/CodeGen/thread-specifier.c b/test/CodeGen/thread-specifier.c new file mode 100644 index 0000000000..08992a6e22 --- /dev/null +++ b/test/CodeGen/thread-specifier.c @@ -0,0 +1,10 @@ +// RUN: clang-cc -emit-llvm -o - %s | grep thread_local | count 4 + +__thread int a; +extern __thread int b; +int c() { return &b; } +int d() { + __thread static int e; + __thread static union {float a; int b;} f = {.b = 1}; +} + -- 2.40.0