[cfe-commits] r69545 - in /cfe/trunk: lib/CodeGen/CGDecl.cpp lib/CodeGen/CodeGenModule.cpp test/CodeGen/thread-specifier.c
Eli Friedman
eli.friedman at gmail.com
Sun Apr 19 14:05:04 PDT 2009
Author: efriedma
Date: Sun Apr 19 16:05:03 2009
New Revision: 69545
URL: http://llvm.org/viewvc/llvm-project?rev=69545&view=rev
Log:
PR3853: Add CodeGen support for __thread.
Added:
cfe/trunk/test/CodeGen/thread-specifier.c
Modified:
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=69545&r1=69544&r2=69545&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Sun Apr 19 16:05:03 2009
@@ -63,10 +63,6 @@
if (D.hasAttr<AsmLabelAttr>())
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 @@
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 @@
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
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=69545&r1=69544&r2=69545&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Sun Apr 19 16:05:03 2009
@@ -656,10 +656,6 @@
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 @@
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 @@
if (D->hasAttr<WeakAttr>() || D->hasAttr<WeakImportAttr>())
GV->setLinkage(llvm::GlobalValue::ExternalWeakLinkage);
+
+ GV->setThreadLocal(D->isThreadSpecified());
}
return Entry = GV;
Added: cfe/trunk/test/CodeGen/thread-specifier.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/thread-specifier.c?rev=69545&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/thread-specifier.c (added)
+++ cfe/trunk/test/CodeGen/thread-specifier.c Sun Apr 19 16:05:03 2009
@@ -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};
+}
+
More information about the cfe-commits
mailing list