r369954 - Diagnose use of _Thread_local as an extension when not in C11 mode.
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 26 12:44:07 PDT 2019
Author: aaronballman
Date: Mon Aug 26 12:44:07 2019
New Revision: 369954
URL: http://llvm.org/viewvc/llvm-project?rev=369954&view=rev
Log:
Diagnose use of _Thread_local as an extension when not in C11 mode.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Parse/ParseExpr.cpp
cfe/trunk/test/PCH/thread-local.cpp
cfe/trunk/test/Sema/thread-specifier.c
cfe/trunk/test/SemaOpenCLCXX/restricted.cl
Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=369954&r1=369953&r2=369954&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Mon Aug 26 12:44:07 2019
@@ -126,7 +126,7 @@ def err_duplicate_default_assoc : Error<
def note_previous_default_assoc : Note<
"previous default generic association is here">;
-def ext_c11_alignment : Extension<
+def ext_c11_feature : Extension<
"%0 is a C11-specific feature">, InGroup<C11>;
def ext_c11_noreturn : Extension<
Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=369954&r1=369953&r2=369954&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Mon Aug 26 12:44:07 2019
@@ -3574,6 +3574,8 @@ void Parser::ParseDeclarationSpecifiers(
isStorageClass = true;
break;
case tok::kw__Thread_local:
+ if (!getLangOpts().C11)
+ Diag(Tok, diag::ext_c11_feature) << Tok.getName();
isInvalid = DS.SetStorageClassSpecThread(DeclSpec::TSCS__Thread_local,
Loc, PrevSpec, DiagID);
isStorageClass = true;
@@ -3631,7 +3633,7 @@ void Parser::ParseDeclarationSpecifiers(
// alignment-specifier
case tok::kw__Alignas:
if (!getLangOpts().C11)
- Diag(Tok, diag::ext_c11_alignment) << Tok.getName();
+ Diag(Tok, diag::ext_c11_feature) << Tok.getName();
ParseAlignmentSpecifier(DS.getAttributes());
continue;
Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=369954&r1=369953&r2=369954&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExpr.cpp Mon Aug 26 12:44:07 2019
@@ -1191,7 +1191,7 @@ ExprResult Parser::ParseCastExpression(b
}
case tok::kw__Alignof: // unary-expression: '_Alignof' '(' type-name ')'
if (!getLangOpts().C11)
- Diag(Tok, diag::ext_c11_alignment) << Tok.getName();
+ Diag(Tok, diag::ext_c11_feature) << Tok.getName();
LLVM_FALLTHROUGH;
case tok::kw_alignof: // unary-expression: 'alignof' '(' type-id ')'
case tok::kw___alignof: // unary-expression: '__alignof' unary-expression
Modified: cfe/trunk/test/PCH/thread-local.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/thread-local.cpp?rev=369954&r1=369953&r2=369954&view=diff
==============================================================================
--- cfe/trunk/test/PCH/thread-local.cpp (original)
+++ cfe/trunk/test/PCH/thread-local.cpp Mon Aug 26 12:44:07 2019
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -pedantic-errors -std=c++11 -triple x86_64-linux-gnu -emit-pch %s -o %t
-// RUN: %clang_cc1 -pedantic-errors -std=c++11 -triple x86_64-linux-gnu -include-pch %t -verify %s
+// RUN: %clang_cc1 -pedantic-errors -Wno-c11-extensions -std=c++11 -triple x86_64-linux-gnu -emit-pch %s -o %t
+// RUN: %clang_cc1 -pedantic-errors -Wno-c11-extensions -std=c++11 -triple x86_64-linux-gnu -include-pch %t -verify %s
// REQUIRES: x86-registered-target
#ifndef HEADER_INCLUDED
Modified: cfe/trunk/test/Sema/thread-specifier.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/thread-specifier.c?rev=369954&r1=369953&r2=369954&view=diff
==============================================================================
--- cfe/trunk/test/Sema/thread-specifier.c (original)
+++ cfe/trunk/test/Sema/thread-specifier.c Mon Aug 26 12:44:07 2019
@@ -1,25 +1,26 @@
// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -Wno-private-extern -verify -pedantic %s -DGNU
// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -Wno-private-extern -verify -pedantic -x c++ %s -DGNU -std=c++98
-// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -Wno-private-extern -verify -pedantic %s -DC11 -D__thread=_Thread_local
-// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -Wno-private-extern -verify -pedantic -x c++ %s -DC11 -D__thread=_Thread_local -std=c++98
+// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -Wno-private-extern -verify -pedantic %s -std=c11 -DC11 -D__thread=_Thread_local
+// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -Wno-private-extern -verify=expected,thread-local -pedantic -x c++ %s -DC11 -D__thread=_Thread_local -std=c++98
// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -Wno-private-extern -verify -pedantic -x c++ %s -DCXX11 -D__thread=thread_local -std=c++11 -Wno-deprecated
-// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -Wno-private-extern -verify -pedantic -x c++ %s -DC11 -D__thread=_Thread_local -std=c++11 -Wno-deprecated
+// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -Wno-private-extern -verify=expected,thread-local -pedantic -x c++ %s -DC11 -D__thread=_Thread_local -std=c++11 -Wno-deprecated
+// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -Wno-private-extern -verify=expected,thread-local -pedantic %s -std=c99 -D__thread=_Thread_local -DC99
#ifdef __cplusplus
// In C++, we define __private_extern__ to extern.
#undef __private_extern__
#endif
-__thread int t1;
-__thread extern int t2;
-__thread static int t3;
+__thread int t1; // thread-local-warning {{_Thread_local is a C11-specific feature}}
+__thread extern int t2; // thread-local-warning {{_Thread_local is a C11-specific feature}}
+__thread static int t3; // thread-local-warning {{_Thread_local is a C11-specific feature}}
#ifdef GNU
// expected-warning at -3 {{'__thread' before 'extern'}}
// expected-warning at -3 {{'__thread' before 'static'}}
#endif
-__thread __private_extern__ int t4;
-struct t5 { __thread int x; };
+__thread __private_extern__ int t4; // thread-local-warning {{_Thread_local is a C11-specific feature}}
+struct t5 { __thread int x; }; // thread-local-warning {{_Thread_local is a C11-specific feature}}
#ifdef __cplusplus
// expected-error-re at -2 {{'{{__thread|_Thread_local|thread_local}}' is only allowed on variable declarations}}
#else
@@ -27,51 +28,63 @@ struct t5 { __thread int x; };
// expected-error at -5 {{type name does not allow storage class to be specified}}
#endif
-__thread int t6();
+__thread int t6(); // thread-local-warning {{_Thread_local is a C11-specific feature}}
#if defined(GNU)
// expected-error at -2 {{'__thread' is only allowed on variable declarations}}
-#elif defined(C11)
+#elif defined(C11) || defined(C99)
// expected-error at -4 {{'_Thread_local' is only allowed on variable declarations}}
#else
// expected-error at -6 {{'thread_local' is only allowed on variable declarations}}
#endif
-int f(__thread int t7) { // expected-error {{' is only allowed on variable declarations}}
- __thread int t8;
+int f(__thread int t7) { // expected-error {{' is only allowed on variable declarations}} \
+ // thread-local-warning {{_Thread_local is a C11-specific feature}}
+ __thread int t8; // thread-local-warning {{_Thread_local is a C11-specific feature}}
#if defined(GNU)
// expected-error at -2 {{'__thread' variables must have global storage}}
-#elif defined(C11)
+#elif defined(C11) || defined(C99)
// expected-error at -4 {{'_Thread_local' variables must have global storage}}
#endif
- extern __thread int t9;
- static __thread int t10;
- __thread __private_extern__ int t11;
+ extern __thread int t9; // thread-local-warning {{_Thread_local is a C11-specific feature}}
+ static __thread int t10; // thread-local-warning {{_Thread_local is a C11-specific feature}}
+ __thread __private_extern__ int t11; // thread-local-warning {{_Thread_local is a C11-specific feature}}
#if __cplusplus < 201103L
- __thread auto int t12a; // expected-error-re {{cannot combine with previous '{{__thread|_Thread_local}}' declaration specifier}}
- auto __thread int t12b; // expected-error {{cannot combine with previous 'auto' declaration specifier}}
+ __thread auto int t12a; // expected-error-re {{cannot combine with previous '{{__thread|_Thread_local}}' declaration specifier}} \
+ // thread-local-warning {{_Thread_local is a C11-specific feature}}
+ auto __thread int t12b; // expected-error {{cannot combine with previous 'auto' declaration specifier}} \
+ // thread-local-warning {{_Thread_local is a C11-specific feature}}
#elif !defined(CXX11)
- __thread auto t12a = 0; // expected-error {{'_Thread_local' variables must have global storage}}
- auto __thread t12b = 0; // expected-error {{'_Thread_local' variables must have global storage}}
-#endif
- __thread register int t13a; // expected-error-re {{cannot combine with previous '{{__thread|_Thread_local|thread_local}}' declaration specifier}}
- register __thread int t13b; // expected-error {{cannot combine with previous 'register' declaration specifier}}
+ __thread auto t12a = 0; // expected-error {{'_Thread_local' variables must have global storage}} \
+ // thread-local-warning {{_Thread_local is a C11-specific feature}}
+ auto __thread t12b = 0; // expected-error {{'_Thread_local' variables must have global storage}} \
+ // thread-local-warning {{_Thread_local is a C11-specific feature}}
+#endif
+ __thread register int t13a; // expected-error-re {{cannot combine with previous '{{__thread|_Thread_local|thread_local}}' declaration specifier}} \
+ // thread-local-warning {{_Thread_local is a C11-specific feature}}
+ register __thread int t13b; // expected-error {{cannot combine with previous 'register' declaration specifier}} \
+ // thread-local-warning {{_Thread_local is a C11-specific feature}}
}
-__thread typedef int t14; // expected-error-re {{cannot combine with previous '{{__thread|_Thread_local|thread_local}}' declaration specifier}}
-__thread int t15; // expected-note {{previous definition is here}}
+__thread typedef int t14; // expected-error-re {{cannot combine with previous '{{__thread|_Thread_local|thread_local}}' declaration specifier}} \
+ // thread-local-warning {{_Thread_local is a C11-specific feature}}
+__thread int t15; // expected-note {{previous definition is here}} \
+ // thread-local-warning {{_Thread_local is a C11-specific feature}}
extern int t15; // expected-error {{non-thread-local declaration of 't15' follows thread-local declaration}}
extern int t16; // expected-note {{previous declaration is here}}
-__thread int t16; // expected-error {{thread-local declaration of 't16' follows non-thread-local declaration}}
+__thread int t16; // expected-error {{thread-local declaration of 't16' follows non-thread-local declaration}} \
+ // thread-local-warning {{_Thread_local is a C11-specific feature}}
#ifdef CXX11
extern thread_local int t17; // expected-note {{previous declaration is here}}
-_Thread_local int t17; // expected-error {{thread-local declaration of 't17' with static initialization follows declaration with dynamic initialization}}
-extern _Thread_local int t18; // expected-note {{previous declaration is here}}
+_Thread_local int t17; // expected-error {{thread-local declaration of 't17' with static initialization follows declaration with dynamic initialization}} \
+ // expected-warning {{_Thread_local is a C11-specific feature}}
+extern _Thread_local int t18; // expected-note {{previous declaration is here}} \
+ // expected-warning {{_Thread_local is a C11-specific feature}}
thread_local int t18; // expected-error {{thread-local declaration of 't18' with dynamic initialization follows declaration with static initialization}}
#endif
// PR13720
-__thread int thread_int;
+__thread int thread_int; // thread-local-warning {{_Thread_local is a C11-specific feature}}
int *thread_int_ptr = &thread_int;
#ifndef __cplusplus
// expected-error at -2 {{initializer element is not a compile-time constant}}
@@ -84,7 +97,7 @@ constexpr int *thread_int_ptr_2 = &threa
#endif
int non_const();
-__thread int non_const_init = non_const();
+__thread int non_const_init = non_const(); // thread-local-warning {{_Thread_local is a C11-specific feature}}
#if !defined(__cplusplus)
// expected-error at -2 {{initializer element is not a compile-time constant}}
#elif !defined(CXX11)
@@ -98,7 +111,7 @@ __thread int non_const_init = non_const(
struct S {
~S();
};
-__thread S s;
+__thread S s; // thread-local-warning {{_Thread_local is a C11-specific feature}}
#if !defined(CXX11)
// expected-error at -2 {{type of thread-local variable has non-trivial destruction}}
#if __cplusplus >= 201103L
@@ -111,7 +124,7 @@ __thread S s;
struct HasCtor {
HasCtor();
};
-__thread HasCtor var_with_ctor;
+__thread HasCtor var_with_ctor; // thread-local-warning {{_Thread_local is a C11-specific feature}}
#if !defined(CXX11)
// expected-error at -2 {{initializer for thread-local variable must be a constant expression}}
#if __cplusplus >= 201103L
@@ -120,4 +133,4 @@ __thread HasCtor var_with_ctor;
#endif
#endif
-__thread int aggregate[10] = {0};
+__thread int aggregate[10] = {0}; // thread-local-warning {{_Thread_local is a C11-specific feature}}
Modified: cfe/trunk/test/SemaOpenCLCXX/restricted.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCLCXX/restricted.cl?rev=369954&r1=369953&r2=369954&view=diff
==============================================================================
--- cfe/trunk/test/SemaOpenCLCXX/restricted.cl (original)
+++ cfe/trunk/test/SemaOpenCLCXX/restricted.cl Mon Aug 26 12:44:07 2019
@@ -31,6 +31,8 @@ B *test_dynamic_cast(B *p) {
// Test storage class qualifiers.
__constant _Thread_local int a = 1;
// expected-error at -1 {{C++ for OpenCL version 1.0 does not support the '_Thread_local' storage class specifier}}
+// expected-warning at -2 {{_Thread_local is a C11-specific feature}}
+
__constant __thread int b = 2;
// expected-error at -1 {{C++ for OpenCL version 1.0 does not support the '__thread' storage class specifier}}
kernel void test_storage_classes() {
More information about the cfe-commits
mailing list