Hi,

This patch allows OpenCL programs to cast 0 as event_t e.g.

void foo(event_t e);

foo((event_t)0);

This is allowed by the OpenCL specification.

If this patch is approved, would it be OK to merge it to the
3.5 branch?

Thanks,
Tom
>From 8f71329e1745a640608f91b80e0f2e3a37805113 Mon Sep 17 00:00:00 2001
From: Tom Stellard <[email protected]>
Date: Fri, 8 Aug 2014 12:06:45 -0400
Subject: [PATCH] Sema: Allow casting 0 to OpenCL builtin type event_t

---
 lib/Sema/SemaCast.cpp         | 8 ++++++++
 test/CodeGenOpenCL/event_t.cl | 2 ++
 2 files changed, 10 insertions(+)

diff --git a/lib/Sema/SemaCast.cpp b/lib/Sema/SemaCast.cpp
index ae5436c..7ec17dc 100644
--- a/lib/Sema/SemaCast.cpp
+++ b/lib/Sema/SemaCast.cpp
@@ -2211,6 +2211,14 @@ void CastOperation::CheckCStyleCast() {
     }
   }
 
+  // OpenCL: casting zero to event_t should be allowed
+  if (Self.getLangOpts().OpenCL && DestType->isEventT() &&
+      SrcExpr.get()->isIntegerConstantExpr(Self.Context) &&
+      SrcExpr.get()->EvaluateKnownConstInt(Self.Context) == 0) {
+      Kind = CK_ZeroToOCLEvent;
+    return;
+  }
+
   if (Self.RequireCompleteType(OpRange.getBegin(), DestType,
                                diag::err_typecheck_cast_to_incomplete)) {
     SrcExpr = ExprError();
diff --git a/test/CodeGenOpenCL/event_t.cl b/test/CodeGenOpenCL/event_t.cl
index ddf12a9..c1b6dd1 100644
--- a/test/CodeGenOpenCL/event_t.cl
+++ b/test/CodeGenOpenCL/event_t.cl
@@ -9,4 +9,6 @@ void kernel ker() {
 // 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)
 }
-- 
1.8.1.5

_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to