From: Joey Gouly Date: Tue, 31 Dec 2013 15:47:49 +0000 (+0000) Subject: [OpenCL] Produce an error, instead of a warning, for sizeof(void) in OpenCL. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f1c0e483721aca10816403cc91f03ed5db876a98;p=clang [OpenCL] Produce an error, instead of a warning, for sizeof(void) in OpenCL. Patch by joey.gouly@arm.com git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@198264 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 5a868cf25d..bbef89d5b8 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -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; +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">; diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 3ead6ec984..5fd65f53f4 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -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/test/SemaOpenCL/sizeof.cl b/test/SemaOpenCL/sizeof.cl new file mode 100644 index 0000000000..69fc4309ce --- /dev/null +++ b/test/SemaOpenCL/sizeof.cl @@ -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}} +}