Преглед изворни кода

[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
Joey Gouly пре 11 година
родитељ
комит
f1c0e48372
3 измењених фајлова са 12 додато и 2 уклоњено
  1. 2 0
      include/clang/Basic/DiagnosticSemaKinds.td
  2. 5 2
      lib/Sema/SemaExpr.cpp
  3. 5 0
      test/SemaOpenCL/sizeof.cl

+ 2 - 0
include/clang/Basic/DiagnosticSemaKinds.td

@@ -4243,6 +4243,8 @@ def ext_sizeof_alignof_function_type : Extension<
 def ext_sizeof_alignof_void_type : Extension<
 def ext_sizeof_alignof_void_type : Extension<
   "invalid application of '%select{sizeof|alignof|vec_step}0' to a void "
   "invalid application of '%select{sizeof|alignof|vec_step}0' to a void "
   "type">, InGroup<PointerArith>;
   "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<
 def err_sizeof_alignof_incomplete_type : Error<
   "invalid application of '%select{sizeof|alignof|vec_step}0' to an "
   "invalid application of '%select{sizeof|alignof|vec_step}0' to an "
   "incomplete type %1">;
   "incomplete type %1">;

+ 5 - 2
lib/Sema/SemaExpr.cpp

@@ -3244,9 +3244,12 @@ static bool CheckExtensionTraitOperandType(Sema &S, QualType T,
     return false;
     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()) {
   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;
     return false;
   }
   }
 
 

+ 5 - 0
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}}
+}