[PATCH] D17578: [OpenCL]Allowing explicit conversion of "0" to event_t type

Aaron En Ye Shi via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 24 12:04:10 PST 2016


ashi1 created this revision.
ashi1 added reviewers: Anastasia, pxli168, yaxunl.
ashi1 added subscribers: pekka.jaaskelainen, tstellarAMD, cfe-commits.

This patch will allow the cast of 0 to event_t type.

http://reviews.llvm.org/D17578

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

Index: test/CodeGenOpenCL/event_t.cl
===================================================================
--- test/CodeGenOpenCL/event_t.cl
+++ test/CodeGenOpenCL/event_t.cl
@@ -9,4 +9,6 @@
 // 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: lib/Sema/SemaCast.cpp
===================================================================
--- lib/Sema/SemaCast.cpp
+++ lib/Sema/SemaCast.cpp
@@ -2313,6 +2313,23 @@
       return;
     }
 
+    // for OpenCL, allow casts from '0' to event_t type
+    if ((Self.getLangOpts().OpenCL) && DestType->isEventT()) {
+          llvm::APSInt intValue;
+      if(SrcExpr.get()->EvaluateAsInt(intValue, Self.getASTContext())) {
+        if(0 == intValue) {
+          Kind = CK_IntegralToPointer;
+          return;
+        } else {
+        Self.Diag(OpRange.getBegin(),
+                  diag::error_opencl_cast_non_zero_to_event_t)
+                  << intValue.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: include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -7676,7 +7676,9 @@
 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">;
+  "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<
   "program scope variable must reside in %0 address space">;
 def err_missing_actual_pipe_type : Error<


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17578.48966.patch
Type: text/x-patch
Size: 2172 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160224/fb5f35b1/attachment.bin>


More information about the cfe-commits mailing list