[cfe-commits] r125399 - in /cfe/trunk: include/clang/Basic/DiagnosticParseKinds.td include/clang/Sema/DeclSpec.h lib/Parse/ParseDecl.cpp lib/Sema/DeclSpec.cpp lib/Sema/SemaDecl.cpp test/Parser/cl_storage_class.cl test/lit.cfg
Peter Collingbourne
peter at pcc.me.uk
Fri Feb 11 11:59:55 PST 2011
Author: pcc
Date: Fri Feb 11 13:59:54 2011
New Revision: 125399
URL: http://llvm.org/viewvc/llvm-project?rev=125399&view=rev
Log:
Reject forbidden storage class specifiers in OpenCL. Patch by George Russell!
Added:
cfe/trunk/test/Parser/cl_storage_class.cl
Modified:
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
cfe/trunk/include/clang/Sema/DeclSpec.h
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Sema/DeclSpec.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/lit.cfg
Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=125399&r1=125398&r2=125399&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Fri Feb 11 13:59:54 2011
@@ -443,5 +443,9 @@
def warn_pragma_unused_expected_punc : Warning<
"expected ')' or ',' in '#pragma unused'">;
+// OpenCL Section 6.8.g
+def err_not_opencl_storage_class_specifier : Error<
+ "OpenCL does not support the '%0' storage class specifier">;
+
} // end of Parse Issue category.
} // end of Parser diagnostics
Modified: cfe/trunk/include/clang/Sema/DeclSpec.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/DeclSpec.h?rev=125399&r1=125398&r2=125399&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/DeclSpec.h (original)
+++ cfe/trunk/include/clang/Sema/DeclSpec.h Fri Feb 11 13:59:54 2011
@@ -403,7 +403,7 @@
/// TODO: use a more general approach that still allows these
/// diagnostics to be ignored when desired.
bool SetStorageClassSpec(SCS S, SourceLocation Loc, const char *&PrevSpec,
- unsigned &DiagID);
+ unsigned &DiagID, const LangOptions &Lang);
bool SetStorageClassSpecThread(SourceLocation Loc, const char *&PrevSpec,
unsigned &DiagID);
bool SetTypeSpecWidth(TSW W, SourceLocation Loc, const char *&PrevSpec,
Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=125399&r1=125398&r2=125399&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Fri Feb 11 13:59:54 2011
@@ -1204,23 +1204,23 @@
// storage-class-specifier
case tok::kw_typedef:
isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_typedef, Loc, PrevSpec,
- DiagID);
+ DiagID, getLang());
break;
case tok::kw_extern:
if (DS.isThreadSpecified())
Diag(Tok, diag::ext_thread_before) << "extern";
isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_extern, Loc, PrevSpec,
- DiagID);
+ DiagID, getLang());
break;
case tok::kw___private_extern__:
isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_private_extern, Loc,
- PrevSpec, DiagID);
+ PrevSpec, DiagID, getLang());
break;
case tok::kw_static:
if (DS.isThreadSpecified())
Diag(Tok, diag::ext_thread_before) << "static";
isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_static, Loc, PrevSpec,
- DiagID);
+ DiagID, getLang());
break;
case tok::kw_auto:
if (getLang().CPlusPlus0x)
@@ -1228,15 +1228,15 @@
DiagID);
else
isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_auto, Loc, PrevSpec,
- DiagID);
+ DiagID, getLang());
break;
case tok::kw_register:
isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_register, Loc, PrevSpec,
- DiagID);
+ DiagID, getLang());
break;
case tok::kw_mutable:
isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_mutable, Loc, PrevSpec,
- DiagID);
+ DiagID, getLang());
break;
case tok::kw___thread:
isInvalid = DS.SetStorageClassSpecThread(Loc, PrevSpec, DiagID);
Modified: cfe/trunk/lib/Sema/DeclSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/DeclSpec.cpp?rev=125399&r1=125398&r2=125399&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/DeclSpec.cpp (original)
+++ cfe/trunk/lib/Sema/DeclSpec.cpp Fri Feb 11 13:59:54 2011
@@ -226,7 +226,25 @@
bool DeclSpec::SetStorageClassSpec(SCS S, SourceLocation Loc,
const char *&PrevSpec,
- unsigned &DiagID) {
+ unsigned &DiagID,
+ const LangOptions &Lang) {
+ // OpenCL prohibits extern, auto, register, and static
+ // It seems sensible to prohibit private_extern too
+ if (Lang.OpenCL) {
+ switch (S) {
+ case SCS_extern:
+ case SCS_private_extern:
+ case SCS_auto:
+ case SCS_register:
+ case SCS_static:
+ DiagID = diag::err_not_opencl_storage_class_specifier;
+ PrevSpec = getSpecifierName(S);
+ return true;
+ default:
+ break;
+ }
+ }
+
if (StorageClassSpec != SCS_unspecified) {
// Changing storage class is allowed only if the previous one
// was the 'extern' that is part of a linkage specification and
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=125399&r1=125398&r2=125399&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Feb 11 13:59:54 2011
@@ -1922,7 +1922,7 @@
// Recover by adding 'static'.
DS.SetStorageClassSpec(DeclSpec::SCS_static, SourceLocation(),
- PrevSpec, DiagID);
+ PrevSpec, DiagID, getLangOptions());
}
// C++ [class.union]p3:
// A storage class is not allowed in a declaration of an
@@ -1935,7 +1935,7 @@
// Recover by removing the storage specifier.
DS.SetStorageClassSpec(DeclSpec::SCS_unspecified, SourceLocation(),
- PrevSpec, DiagID);
+ PrevSpec, DiagID, getLangOptions());
}
// C++ [class.union]p2:
Added: cfe/trunk/test/Parser/cl_storage_class.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cl_storage_class.cl?rev=125399&view=auto
==============================================================================
--- cfe/trunk/test/Parser/cl_storage_class.cl (added)
+++ cfe/trunk/test/Parser/cl_storage_class.cl Fri Feb 11 13:59:54 2011
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 %s -x cl -verify -fsyntax-only
+
+void test_storage_class_specs()
+{
+ static int a; // expected-error {{OpenCL does not support the 'static' storage class specifier}}
+ register int b; // expected-error {{OpenCL does not support the 'register' storage class specifier}}
+ extern int c; // expected-error {{OpenCL does not support the 'extern' storage class specifier}}
+ auto int d; // expected-error {{OpenCL does not support the 'auto' storage class specifier}}
+}
Modified: cfe/trunk/test/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/lit.cfg?rev=125399&r1=125398&r2=125399&view=diff
==============================================================================
--- cfe/trunk/test/lit.cfg (original)
+++ cfe/trunk/test/lit.cfg Fri Feb 11 13:59:54 2011
@@ -28,7 +28,7 @@
config.test_format = lit.formats.ShTest(execute_external)
# suffixes: A list of file extensions to treat as test files.
-config.suffixes = ['.c', '.cpp', '.m', '.mm', '.cu', '.ll']
+config.suffixes = ['.c', '.cpp', '.m', '.mm', '.cu', '.ll', '.cl']
# test_source_root: The root path where tests are located.
config.test_source_root = os.path.dirname(__file__)
More information about the cfe-commits
mailing list