From 1d58cdbf4e1737438f0cf94a3d6f827c1b03a39f Mon Sep 17 00:00:00 2001 From: Joey Gouly Date: Thu, 17 Jan 2013 17:35:00 +0000 Subject: [PATCH] Add some semantic checks for OpenCL. Variadic macros, VLAs and bitfields are not supported. llvm-svn: 172732 --- clang/include/clang/Basic/DiagnosticLexKinds.td | 3 +++ clang/include/clang/Basic/DiagnosticSemaKinds.td | 4 ++++ clang/lib/Lex/PPDirectives.cpp | 6 ++++++ clang/lib/Sema/SemaDecl.cpp | 6 ++++++ clang/lib/Sema/SemaType.cpp | 6 ++++++ clang/test/Preprocessor/macro_variadic.cl | 3 +++ clang/test/SemaOpenCL/unsupported.cl | 9 +++++++++ 7 files changed, 37 insertions(+) create mode 100644 clang/test/Preprocessor/macro_variadic.cl create mode 100644 clang/test/SemaOpenCL/unsupported.cl diff --git a/clang/include/clang/Basic/DiagnosticLexKinds.td b/clang/include/clang/Basic/DiagnosticLexKinds.td index 59c6ce7..90012fa 100644 --- a/clang/include/clang/Basic/DiagnosticLexKinds.td +++ b/clang/include/clang/Basic/DiagnosticLexKinds.td @@ -284,6 +284,9 @@ def warn_cxx98_compat_empty_fnmacro_arg : Warning< InGroup, DefaultIgnore; def note_macro_here : Note<"macro %0 defined here">; +def err_pp_opencl_variadic_macros : + Error<"variadic macros not supported in OpenCL">; + def err_pp_invalid_directive : Error<"invalid preprocessing directive">; def err_pp_directive_required : Error< "%0 must be used within a preprocessing directive">; diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index ae88e9e..81212e6 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -6066,6 +6066,10 @@ def err_static_kernel : Error< "kernel functions cannot be declared static">; def err_static_function_scope : Error< "variables in function scope cannot be declared static">; +def err_opencl_bitfields : Error< + "bitfields are not supported in OpenCL">; +def err_opencl_vla : Error< + "variable length arrays are not supported in OpenCL">; } // end of sema category diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index 7e46a9c..156ebd2 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -1649,6 +1649,12 @@ bool Preprocessor::ReadMacroDefinitionArgList(MacroInfo *MI, Token &Tok) { diag::warn_cxx98_compat_variadic_macro : diag::ext_variadic_macro); + // OpenCL v1.2 s6.9.e: variadic macros are not supported. + if (LangOpts.OpenCL) { + Diag(Tok, diag::err_pp_opencl_variadic_macros); + return true; + } + // Lex the token after the identifier. LexUnexpandedToken(Tok); if (Tok.isNot(tok::r_paren)) { diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 728a58e..a13d8b3 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -9871,6 +9871,12 @@ FieldDecl *Sema::CheckFieldDecl(DeclarationName Name, QualType T, } } + // OpenCL v1.2 s6.9.c: bitfields are not supported. + if (BitWidth && getLangOpts().OpenCL) { + Diag(Loc, diag::err_opencl_bitfields); + InvalidDecl = true; + } + // C99 6.7.2.1p8: A member of a structure or union may have any type other // than a variably modified type. if (!InvalidDecl && T->isVariablyModifiedType()) { diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index 7029543..15aa39b 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -1460,6 +1460,12 @@ QualType Sema::BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM, T = Context.getConstantArrayType(T, ConstVal, ASM, Quals); } + + // OpenCL v1.2 s6.9.d: variable length arrays are not supported. + if (getLangOpts().OpenCL && T->isVariableArrayType()) { + Diag(Loc, diag::err_opencl_vla); + return QualType(); + } // If this is not C99, extwarn about VLA's and C99 array size modifiers. if (!getLangOpts().C99) { if (T->isVariableArrayType()) { diff --git a/clang/test/Preprocessor/macro_variadic.cl b/clang/test/Preprocessor/macro_variadic.cl new file mode 100644 index 0000000..e4c5566 --- /dev/null +++ b/clang/test/Preprocessor/macro_variadic.cl @@ -0,0 +1,3 @@ +// RUN: %clang_cc1 -verify %s + +#define X(...) 1 // expected-error {{variadic macros not supported in OpenCL}} diff --git a/clang/test/SemaOpenCL/unsupported.cl b/clang/test/SemaOpenCL/unsupported.cl new file mode 100644 index 0000000..bb9da4b --- /dev/null +++ b/clang/test/SemaOpenCL/unsupported.cl @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -verify %s + +struct { + int a : 1; // expected-error {{bitfields are not supported in OpenCL}} +}; + +void no_vla(int n) { + int a[n]; // expected-error {{variable length arrays are not supported in OpenCL}} +} -- 2.7.4