]> granicus.if.org Git - clang/commitdiff
[OpenCL] Allow explicit cast of 0 to event_t.
authorYaxun Liu <Yaxun.Liu@amd.com>
Fri, 20 May 2016 17:18:16 +0000 (17:18 +0000)
committerYaxun Liu <Yaxun.Liu@amd.com>
Fri, 20 May 2016 17:18:16 +0000 (17:18 +0000)
Patch by Aaron Enye Shi.

Differential Revision: http://reviews.llvm.org/D17578

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@270238 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaCast.cpp
test/CodeGenOpenCL/event_t.cl
test/SemaOpenCL/event_t.cl

index 42de37a4beede007fee2f0d982631ff9f50947eb..3692166a2fd1c63f3626de6a07e462f4b84d2da4 100644 (file)
@@ -7821,6 +7821,8 @@ def err_sampler_argument_required : Error<
   "sampler_t variable required - got %0">;
 def err_wrong_sampler_addressspace: Error<
   "sampler type cannot be used with the __local and __global address space qualifiers">;
+def error_opencl_cast_non_zero_to_event_t : Error<
+  "cannot cast non-zero value '%0' to 'event_t'">;
 def err_opencl_global_invalid_addr_space : Error<
   "%select{program scope|static local|extern}0 variable must reside in %1 address space">;
 def err_missing_actual_pipe_type : Error<
index 1d95b1f9f18390c7d37587459ebbfa07fc9ec495..7239d44ca232bf29ab15b5f574c2ef775c69d90e 100644 (file)
@@ -2441,6 +2441,22 @@ void CastOperation::CheckCStyleCast() {
       return;
     }
 
+    // OpenCL v2.0 s6.13.10 - Allow casts from '0' to event_t type.
+    if (Self.getLangOpts().OpenCL && DestType->isEventT()) {
+      llvm::APSInt CastInt;
+      if (SrcExpr.get()->EvaluateAsInt(CastInt, Self.Context)) {
+        if (0 == CastInt) {
+          Kind = CK_ZeroToOCLEvent;
+          return;
+        }
+        Self.Diag(OpRange.getBegin(),
+                  diag::error_opencl_cast_non_zero_to_event_t)
+                  << CastInt.toString(10) << SrcExpr.get()->getSourceRange();
+        SrcExpr = ExprError();
+        return;
+      }
+    }
+
     // Reject any other conversions to non-scalar types.
     Self.Diag(OpRange.getBegin(), diag::err_typecheck_cond_expect_scalar)
       << DestType << SrcExpr.get()->getSourceRange();
index a84d8bb610c07cc6517c9acee5919e3d0ba62ba4..aad441f35fd7a06fb796c4eedf57b46f52f5da17 100644 (file)
@@ -8,5 +8,7 @@ void kernel ker() {
   foo(e);
 // CHECK: call {{.*}}void @foo(%opencl.event_t* %
   foo(0);
+// CHECK: call {{.*}}void @foo(%opencl.event_t* null)
+  foo((event_t)0);
 // CHECK: call {{.*}}void @foo(%opencl.event_t* null)
 }
index 3c4b45b9232179ff82187ef855f0ed8e7aa82687..990c06340942cf2353c4d65c875ea17e7c5d1829 100644 (file)
@@ -14,5 +14,6 @@ void kernel ker(event_t argevt) { // expected-error {{'event_t' cannot be used a
   foo(e);
   foo(0);
   foo(5); // expected-error {{passing 'int' to parameter of incompatible type 'event_t'}}
+  foo((event_t)1); // expected-error {{cannot cast non-zero value '1' to 'event_t'}}
 }