[cfe-commits] r172732 - in /cfe/trunk: include/clang/Basic/DiagnosticLexKinds.td include/clang/Basic/DiagnosticSemaKinds.td lib/Lex/PPDirectives.cpp lib/Sema/SemaDecl.cpp lib/Sema/SemaType.cpp test/Preprocessor/macro_variadic.cl test/SemaOpenCL/unsupported.cl

Joey Gouly joey.gouly at arm.com
Thu Jan 17 09:35:00 PST 2013


Author: joey
Date: Thu Jan 17 11:35:00 2013
New Revision: 172732

URL: http://llvm.org/viewvc/llvm-project?rev=172732&view=rev
Log:
Add some semantic checks for OpenCL. Variadic macros, VLAs and bitfields are not supported.

Added:
    cfe/trunk/test/Preprocessor/macro_variadic.cl
    cfe/trunk/test/SemaOpenCL/unsupported.cl
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Lex/PPDirectives.cpp
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/lib/Sema/SemaType.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td?rev=172732&r1=172731&r2=172732&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td Thu Jan 17 11:35:00 2013
@@ -284,6 +284,9 @@
   InGroup<CXX98CompatPedantic>, 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">;

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=172732&r1=172731&r2=172732&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Jan 17 11:35:00 2013
@@ -6066,6 +6066,10 @@
   "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
 

Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=172732&r1=172731&r2=172732&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Thu Jan 17 11:35:00 2013
@@ -1649,6 +1649,12 @@
              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)) {

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=172732&r1=172731&r2=172732&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Jan 17 11:35:00 2013
@@ -9871,6 +9871,12 @@
     }
   }
 
+  // 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()) {

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=172732&r1=172731&r2=172732&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Thu Jan 17 11:35:00 2013
@@ -1460,6 +1460,12 @@
 
     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()) {

Added: cfe/trunk/test/Preprocessor/macro_variadic.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/macro_variadic.cl?rev=172732&view=auto
==============================================================================
--- cfe/trunk/test/Preprocessor/macro_variadic.cl (added)
+++ cfe/trunk/test/Preprocessor/macro_variadic.cl Thu Jan 17 11:35:00 2013
@@ -0,0 +1,3 @@
+// RUN: %clang_cc1 -verify %s
+
+#define X(...) 1 // expected-error {{variadic macros not supported in OpenCL}}

Added: cfe/trunk/test/SemaOpenCL/unsupported.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/unsupported.cl?rev=172732&view=auto
==============================================================================
--- cfe/trunk/test/SemaOpenCL/unsupported.cl (added)
+++ cfe/trunk/test/SemaOpenCL/unsupported.cl Thu Jan 17 11:35:00 2013
@@ -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}}
+}





More information about the cfe-commits mailing list