[OpenCL] Produce an error, instead of a warning, for sizeof(void) in OpenCL.
authorJoey Gouly <joey.gouly@gmail.com>
Tue, 31 Dec 2013 15:47:49 +0000 (15:47 +0000)
committerJoey Gouly <joey.gouly@gmail.com>
Tue, 31 Dec 2013 15:47:49 +0000 (15:47 +0000)
Patch by joey.gouly@arm.com

llvm-svn: 198264

clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaExpr.cpp
clang/test/SemaOpenCL/sizeof.cl [new file with mode: 0644]

index 5a868cf..bbef89d 100644 (file)
@@ -4243,6 +4243,8 @@ def ext_sizeof_alignof_function_type : Extension<
 def ext_sizeof_alignof_void_type : Extension<
   "invalid application of '%select{sizeof|alignof|vec_step}0' to a void "
   "type">, InGroup<PointerArith>;
+def err_opencl_sizeof_alignof_type : Error<
+  "invalid application of '%select{sizeof|alignof|vec_step}0' to a void type">;
 def err_sizeof_alignof_incomplete_type : Error<
   "invalid application of '%select{sizeof|alignof|vec_step}0' to an "
   "incomplete type %1">;
index 3ead6ec..5fd65f5 100644 (file)
@@ -3244,9 +3244,12 @@ static bool CheckExtensionTraitOperandType(Sema &S, QualType T,
     return false;
   }
 
-  // Allow sizeof(void)/alignof(void) as an extension.
+  // Allow sizeof(void)/alignof(void) as an extension, unless in OpenCL where
+  // this is an error (OpenCL v1.1 s6.3.k)
   if (T->isVoidType()) {
-    S.Diag(Loc, diag::ext_sizeof_alignof_void_type) << TraitKind << ArgRange;
+    unsigned DiagID = S.LangOpts.OpenCL ? diag::err_opencl_sizeof_alignof_type
+                                        : diag::ext_sizeof_alignof_void_type;
+    S.Diag(Loc, DiagID) << TraitKind << ArgRange;
     return false;
   }
 
diff --git a/clang/test/SemaOpenCL/sizeof.cl b/clang/test/SemaOpenCL/sizeof.cl
new file mode 100644 (file)
index 0000000..69fc430
--- /dev/null
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+kernel void test(global int* buf) {
+  buf[0] = sizeof(void); // expected-error {{invalid application of 'sizeof' to a void type}}
+}