r198264 - [OpenCL] Produce an error, instead of a warning, for sizeof(void) in OpenCL.
Joey Gouly
joey.gouly at gmail.com
Tue Dec 31 07:47:49 PST 2013
Author: joey
Date: Tue Dec 31 09:47:49 2013
New Revision: 198264
URL: http://llvm.org/viewvc/llvm-project?rev=198264&view=rev
Log:
[OpenCL] Produce an error, instead of a warning, for sizeof(void) in OpenCL.
Patch by joey.gouly at arm.com
Added:
cfe/trunk/test/SemaOpenCL/sizeof.cl
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaExpr.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=198264&r1=198263&r2=198264&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Dec 31 09:47:49 2013
@@ -4243,6 +4243,8 @@ def ext_sizeof_alignof_function_type : E
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">;
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=198264&r1=198263&r2=198264&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Dec 31 09:47:49 2013
@@ -3244,9 +3244,12 @@ static bool CheckExtensionTraitOperandTy
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;
}
Added: cfe/trunk/test/SemaOpenCL/sizeof.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/sizeof.cl?rev=198264&view=auto
==============================================================================
--- cfe/trunk/test/SemaOpenCL/sizeof.cl (added)
+++ cfe/trunk/test/SemaOpenCL/sizeof.cl Tue Dec 31 09:47:49 2013
@@ -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}}
+}
More information about the cfe-commits
mailing list