r181113 - In VarDecl nodes, store the thread storage class specifier as written.
Enea Zaffanella
zaffanella at cs.unipr.it
Sat May 4 01:27:08 PDT 2013
Author: enea
Date: Sat May 4 03:27:07 2013
New Revision: 181113
URL: http://llvm.org/viewvc/llvm-project?rev=181113&view=rev
Log:
In VarDecl nodes, store the thread storage class specifier as written.
Modified:
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/include/clang/Basic/Specifiers.h
cfe/trunk/include/clang/Sema/DeclSpec.h
cfe/trunk/lib/AST/DeclPrinter.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
cfe/trunk/test/SemaCXX/cxx11-ast-print.cpp
Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=181113&r1=181112&r2=181113&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Sat May 4 03:27:07 2013
@@ -667,7 +667,7 @@ private:
friend class ASTDeclReader;
unsigned SClass : 3;
- unsigned TLSKind : 2;
+ unsigned TSCSpec : 2;
unsigned InitStyle : 2;
/// \brief Whether this variable is the exception variable in a C++ catch
@@ -774,9 +774,23 @@ public:
}
void setStorageClass(StorageClass SC);
- void setTLSKind(TLSKind TLS) { VarDeclBits.TLSKind = TLS; }
+ void setTSCSpec(ThreadStorageClassSpecifier TSC) {
+ VarDeclBits.TSCSpec = TSC;
+ }
+ ThreadStorageClassSpecifier getTSCSpec() const {
+ return static_cast<ThreadStorageClassSpecifier>(VarDeclBits.TSCSpec);
+ }
TLSKind getTLSKind() const {
- return static_cast<TLSKind>(VarDeclBits.TLSKind);
+ switch (VarDeclBits.TSCSpec) {
+ case TSCS_unspecified:
+ return TLS_None;
+ case TSCS___thread: // Fall through.
+ case TSCS__Thread_local:
+ return TLS_Static;
+ case TSCS_thread_local:
+ return TLS_Dynamic;
+ }
+ llvm_unreachable("Unknown thread storage class specifier!");
}
/// hasLocalStorage - Returns true if a variable with function scope
Modified: cfe/trunk/include/clang/Basic/Specifiers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Specifiers.h?rev=181113&r1=181112&r2=181113&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Specifiers.h (original)
+++ cfe/trunk/include/clang/Basic/Specifiers.h Sat May 4 03:27:07 2013
@@ -154,6 +154,19 @@ namespace clang {
TSK_ExplicitInstantiationDefinition
};
+ /// \brief Thread storage-class-specifier.
+ enum ThreadStorageClassSpecifier {
+ TSCS_unspecified,
+ /// GNU __thread.
+ TSCS___thread,
+ /// C++11 thread_local. Implies 'static' at block scope, but not at
+ /// class scope.
+ TSCS_thread_local,
+ /// C11 _Thread_local. Must be combined with either 'static' or 'extern'
+ /// if used at block scope.
+ TSCS__Thread_local
+ };
+
/// \brief Storage classes.
enum StorageClass {
// These are legal on both functions and variables.
Modified: cfe/trunk/include/clang/Sema/DeclSpec.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/DeclSpec.h?rev=181113&r1=181112&r2=181113&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/DeclSpec.h (original)
+++ cfe/trunk/include/clang/Sema/DeclSpec.h Sat May 4 03:27:07 2013
@@ -226,19 +226,14 @@ public:
SCS_private_extern,
SCS_mutable
};
- /// \brief Thread storage-class-specifier. These can be combined with
- /// SCS_extern and SCS_static.
- enum TSCS {
- TSCS_unspecified,
- /// GNU __thread.
- TSCS___thread,
- /// C++11 thread_local. Implies 'static' at block scope, but not at
- /// class scope.
- TSCS_thread_local,
- /// C11 _Thread_local. Must be combined with either 'static' or 'extern'
- /// if used at block scope.
- TSCS__Thread_local
- };
+
+ // Import thread storage class specifier enumeration and constants.
+ // These can be combined with SCS_extern and SCS_static.
+ typedef ThreadStorageClassSpecifier TSCS;
+ static const TSCS TSCS_unspecified = clang::TSCS_unspecified;
+ static const TSCS TSCS___thread = clang::TSCS___thread;
+ static const TSCS TSCS_thread_local = clang::TSCS_thread_local;
+ static const TSCS TSCS__Thread_local = clang::TSCS__Thread_local;
// Import type specifier width enumeration and constants.
typedef TypeSpecifierWidth TSW;
Modified: cfe/trunk/lib/AST/DeclPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclPrinter.cpp?rev=181113&r1=181112&r2=181113&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclPrinter.cpp (original)
+++ cfe/trunk/lib/AST/DeclPrinter.cpp Sat May 4 03:27:07 2013
@@ -647,13 +647,16 @@ void DeclPrinter::VisitVarDecl(VarDecl *
if (SC != SC_None)
Out << VarDecl::getStorageClassSpecifierString(SC) << " ";
- switch (D->getTLSKind()) {
- case VarDecl::TLS_None:
+ switch (D->getTSCSpec()) {
+ case TSCS_unspecified:
break;
- case VarDecl::TLS_Static:
+ case TSCS___thread:
+ Out << "__thread ";
+ break;
+ case TSCS__Thread_local:
Out << "_Thread_local ";
break;
- case VarDecl::TLS_Dynamic:
+ case TSCS_thread_local:
Out << "thread_local ";
break;
}
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=181113&r1=181112&r2=181113&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Sat May 4 03:27:07 2013
@@ -1623,7 +1623,7 @@ CodeGenModule::MaybeEmitGlobalStdInitial
D->getLocStart(), D->getLocation(),
name, arrayType, sourceInfo,
SC_Static);
- backingArray->setTLSKind(D->getTLSKind());
+ backingArray->setTSCSpec(D->getTSCSpec());
// Now clone the InitListExpr to initialize the array instead.
// Incredible hack: we want to use the existing InitListExpr here, so we need
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=181113&r1=181112&r2=181113&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sat May 4 03:27:07 2013
@@ -4897,9 +4897,7 @@ Sema::ActOnVariableDeclarator(Scope *S,
Diag(D.getDeclSpec().getThreadStorageClassSpecLoc(),
diag::err_thread_unsupported);
else
- NewVD->setTLSKind(TSCS == DeclSpec::TSCS_thread_local
- ? VarDecl::TLS_Dynamic
- : VarDecl::TLS_Static);
+ NewVD->setTSCSpec(TSCS);
}
// C99 6.7.4p3
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=181113&r1=181112&r2=181113&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Sat May 4 03:27:07 2013
@@ -339,7 +339,7 @@ Decl *TemplateDeclInstantiator::VisitVar
D->getLocation(), D->getIdentifier(),
DI->getType(), DI,
D->getStorageClass());
- Var->setTLSKind(D->getTLSKind());
+ Var->setTSCSpec(D->getTSCSpec());
Var->setInitStyle(D->getInitStyle());
Var->setCXXForRangeDecl(D->isCXXForRangeDecl());
Var->setConstexpr(D->isConstexpr());
Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=181113&r1=181112&r2=181113&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Sat May 4 03:27:07 2013
@@ -904,7 +904,7 @@ void ASTDeclReader::VisitVarDecl(VarDecl
VisitDeclaratorDecl(VD);
VD->VarDeclBits.SClass = (StorageClass)Record[Idx++];
- VD->VarDeclBits.TLSKind = Record[Idx++];
+ VD->VarDeclBits.TSCSpec = Record[Idx++];
VD->VarDeclBits.InitStyle = Record[Idx++];
VD->VarDeclBits.ExceptionVar = Record[Idx++];
VD->VarDeclBits.NRVOVariable = Record[Idx++];
Modified: cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterDecl.cpp?rev=181113&r1=181112&r2=181113&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriterDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriterDecl.cpp Sat May 4 03:27:07 2013
@@ -687,7 +687,7 @@ void ASTDeclWriter::VisitVarDecl(VarDecl
VisitRedeclarable(D);
VisitDeclaratorDecl(D);
Record.push_back(D->getStorageClass());
- Record.push_back(D->getTLSKind());
+ Record.push_back(D->getTSCSpec());
Record.push_back(D->getInitStyle());
Record.push_back(D->isExceptionVariable());
Record.push_back(D->isNRVOVariable());
@@ -776,7 +776,7 @@ void ASTDeclWriter::VisitParmVarDecl(Par
// Check things we know are true of *every* PARM_VAR_DECL, which is more than
// just us assuming it.
- assert(!D->getTLSKind() && "PARM_VAR_DECL can't use TLS");
+ assert(!D->getTSCSpec() && "PARM_VAR_DECL can't use TLS");
assert(D->getAccess() == AS_none && "PARM_VAR_DECL can't be public/private");
assert(!D->isExceptionVariable() && "PARM_VAR_DECL can't be exception var");
assert(D->getPreviousDecl() == 0 && "PARM_VAR_DECL can't be redecl");
@@ -1534,7 +1534,7 @@ void ASTWriter::WriteDeclsBlockAbbrevs()
Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
// VarDecl
Abv->Add(BitCodeAbbrevOp(0)); // StorageClass
- Abv->Add(BitCodeAbbrevOp(0)); // getTLSKind
+ Abv->Add(BitCodeAbbrevOp(0)); // getTSCSpec
Abv->Add(BitCodeAbbrevOp(0)); // hasCXXDirectInitializer
Abv->Add(BitCodeAbbrevOp(0)); // isExceptionVariable
Abv->Add(BitCodeAbbrevOp(0)); // isNRVOVariable
@@ -1613,7 +1613,7 @@ void ASTWriter::WriteDeclsBlockAbbrevs()
Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
// VarDecl
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // StorageClass
- Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // getTLSKind
+ Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // getTSCSpec
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // CXXDirectInitializer
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isExceptionVariable
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isNRVOVariable
Modified: cfe/trunk/test/SemaCXX/cxx11-ast-print.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx11-ast-print.cpp?rev=181113&r1=181112&r2=181113&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/cxx11-ast-print.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx11-ast-print.cpp Sat May 4 03:27:07 2013
@@ -41,3 +41,12 @@ const char *p10 = 3.300e+15_fritz;
// CHECK: ;
;
// CHECK-NOT: ;
+
+
+// CHECK: __thread int gnu_tl;
+// CHECK: _Thread_local int c11_tl;
+// CHECK: thread_local int cxx11_tl;
+__thread int gnu_tl;
+_Thread_local int c11_tl;
+thread_local int cxx11_tl;
+
More information about the cfe-commits
mailing list