[cfe-commits] r69542 - in /cfe/trunk: include/clang/Basic/DiagnosticParseKinds.td include/clang/Basic/DiagnosticSemaKinds.td lib/Parse/DeclSpec.cpp lib/Sema/SemaDecl.cpp
Eli Friedman
eli.friedman at gmail.com
Sun Apr 19 13:27:55 PDT 2009
Author: efriedma
Date: Sun Apr 19 15:27:55 2009
New Revision: 69542
URL: http://llvm.org/viewvc/llvm-project?rev=69542&view=rev
Log:
Add more thorough/correct checking for invalid __thread specifiers.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Parse/DeclSpec.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=69542&r1=69541&r2=69542&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Sun Apr 19 15:27:55 2009
@@ -35,7 +35,6 @@
def err_invalid_long_spec : Error<"'long %0' is invalid">;
def err_invalid_longlong_spec : Error<"'long long %0' is invalid">;
def err_invalid_complex_spec : Error<"'_Complex %0' is invalid">;
-def err_invalid_thread_spec : Error<"'__thread %0' is invalid">;
def ext_ident_list_in_param : Extension<
"type-less parameter names in function declaration">;
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=69542&r1=69541&r2=69542&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sun Apr 19 15:27:55 2009
@@ -93,6 +93,11 @@
def err_inline_non_function : Error<
"'inline' can only appear on functions">;
+def err_invalid_thread : Error<
+ "'__thread' is only allowed on variable declarations">;
+def err_thread_non_global : Error<
+ "'__thread' variables must have global storage">;
+
/// Built-in functions.
def ext_implicit_lib_function_decl : ExtWarn<
"implicitly declaring C library function '%0' with type %1">;
@@ -743,6 +748,10 @@
"static declaration of %0 follows non-static declaration">;
def err_non_static_static : Error<
"non-static declaration of %0 follows static declaration">;
+def err_non_thread_thread : Error<
+ "non-thread-local declaration of %0 follows thread-local declaration">;
+def err_thread_non_thread : Error<
+ "thread-local declaration of %0 follows non-thread-local declaration">;
def err_redefinition_different_type : Error<
"redefinition of %0 with a different type">;
def err_redefinition_different_kind : Error<
Modified: cfe/trunk/lib/Parse/DeclSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/DeclSpec.cpp?rev=69542&r1=69541&r2=69542&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/DeclSpec.cpp (original)
+++ cfe/trunk/lib/Parse/DeclSpec.cpp Sun Apr 19 15:27:55 2009
@@ -94,6 +94,7 @@
case DeclSpec::SCS_static: return "static";
case DeclSpec::SCS_auto: return "auto";
case DeclSpec::SCS_register: return "register";
+ case DeclSpec::SCS_private_extern: return "__private_extern__";
case DeclSpec::SCS_mutable: return "mutable";
}
}
@@ -345,18 +346,6 @@
TypeSpecComplex = TSC_unspecified;
}
}
-
- // Verify __thread.
- if (SCS_thread_specified) {
- if (StorageClassSpec == SCS_unspecified) {
- StorageClassSpec = SCS_extern; // '__thread int' -> 'extern __thread int'
- } else if (StorageClassSpec != SCS_extern &&
- StorageClassSpec != SCS_static) {
- Diag(D, getStorageClassSpecLoc(), SrcMgr, diag::err_invalid_thread_spec)
- << getSpecifierName((SCS)StorageClassSpec);
- SCS_thread_specified = false;
- }
- }
// Okay, now we can infer the real type.
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=69542&r1=69541&r2=69542&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sun Apr 19 15:27:55 2009
@@ -917,6 +917,14 @@
return true;
}
+ if (New->isThreadSpecified() && !Old->isThreadSpecified()) {
+ Diag(New->getLocation(), diag::err_thread_non_thread) << New->getDeclName();
+ Diag(Old->getLocation(), diag::note_previous_definition);
+ } else if (!New->isThreadSpecified() && Old->isThreadSpecified()) {
+ Diag(New->getLocation(), diag::err_non_thread_thread) << New->getDeclName();
+ Diag(Old->getLocation(), diag::note_previous_definition);
+ }
+
// Keep a chain of previous declarations.
New->setPreviousDeclaration(Old);
@@ -962,6 +970,7 @@
// FIXME: Error on auto/register at file scope
// FIXME: Error on inline/virtual/explicit
// FIXME: Error on invalid restrict
+ // FIXME: Warn on useless __thread
// FIXME: Warn on useless const/volatile
// FIXME: Warn on useless static/extern/typedef/private_extern/mutable
// FIXME: Warn on useless attributes
@@ -1551,6 +1560,9 @@
DiagnoseFunctionSpecifiers(D);
+ if (D.getDeclSpec().isThreadSpecified())
+ Diag(D.getDeclSpec().getThreadSpecLoc(), diag::err_invalid_thread);
+
TypedefDecl *NewTD = ParseTypedefDecl(S, D, R);
if (!NewTD) return 0;
@@ -1694,7 +1706,6 @@
DiagnoseFunctionSpecifiers(D);
- bool ThreadSpecified = D.getDeclSpec().isThreadSpecified();
if (!DC->isRecord() && S->getFnParent() == 0) {
// C99 6.9p2: The storage-class specifiers auto and register shall not
// appear in the declaration specifiers in an external declaration.
@@ -1719,7 +1730,13 @@
II, R, SC,
// FIXME: Move to DeclGroup...
D.getDeclSpec().getSourceRange().getBegin());
- NewVD->setThreadSpecified(ThreadSpecified);
+
+ if (D.getDeclSpec().isThreadSpecified()) {
+ if (NewVD->hasLocalStorage())
+ Diag(D.getDeclSpec().getThreadSpecLoc(), diag::err_thread_non_global);
+ else
+ NewVD->setThreadSpecified(true);
+ }
// Set the lexical context. If the declarator has a C++ scope specifier, the
// lexical context will be different from the semantic context.
@@ -1913,6 +1930,9 @@
case DeclSpec::SCS_private_extern: SC = FunctionDecl::PrivateExtern;break;
}
+ if (D.getDeclSpec().isThreadSpecified())
+ Diag(D.getDeclSpec().getThreadSpecLoc(), diag::err_invalid_thread);
+
bool isInline = D.getDeclSpec().isInlineSpecified();
bool isVirtual = D.getDeclSpec().isVirtualSpecified();
bool isExplicit = D.getDeclSpec().isExplicitSpecified();
@@ -2683,11 +2703,10 @@
diag::err_invalid_storage_class_in_func_decl);
D.getMutableDeclSpec().ClearStorageClassSpecs();
}
- if (DS.isThreadSpecified()) {
- Diag(DS.getThreadSpecLoc(),
- diag::err_invalid_storage_class_in_func_decl);
- D.getMutableDeclSpec().ClearStorageClassSpecs();
- }
+
+ if (D.getDeclSpec().isThreadSpecified())
+ Diag(D.getDeclSpec().getThreadSpecLoc(), diag::err_invalid_thread);
+
DiagnoseFunctionSpecifiers(D);
// Check that there are no default arguments inside the type of this
@@ -3574,6 +3593,9 @@
DiagnoseFunctionSpecifiers(D);
+ if (D.getDeclSpec().isThreadSpecified())
+ Diag(D.getDeclSpec().getThreadSpecLoc(), diag::err_invalid_thread);
+
NamedDecl *PrevDecl = LookupName(S, II, LookupMemberName, true);
if (PrevDecl && !isDeclInScope(PrevDecl, Record, S))
PrevDecl = 0;
More information about the cfe-commits
mailing list