]> granicus.if.org Git - clang/commitdiff
[OpenCL] Fix pipe built-in functions return type.
authorAlexey Bader <aleksey.bader@mail.ru>
Wed, 7 Sep 2016 10:32:03 +0000 (10:32 +0000)
committerAlexey Bader <aleksey.bader@mail.ru>
Wed, 7 Sep 2016 10:32:03 +0000 (10:32 +0000)
By default return type of call expressions calling built-in
functions is set to bool.

Fixes https://llvm.org/bugs/show_bug.cgi?id=30219.

Reviewers: Anastasia

Subscribers: dmitry, cfe-commits, yaxunl

Differential Revision: https://reviews.llvm.org/D24136

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

lib/Sema/SemaChecking.cpp
test/CodeGenOpenCL/pipe_builtin.cl

index 6edb251c55bfdd59b54d141cad64d16702a7af19..81dc23724e929f7f36673aa425f2f52f33e6017e 100644 (file)
@@ -1020,6 +1020,7 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID,
     // check for the argument.
     if (SemaBuiltinRWPipe(*this, TheCall))
       return ExprError();
+    TheCall->setType(Context.IntTy);
     break;
   case Builtin::BIreserve_read_pipe:
   case Builtin::BIreserve_write_pipe:
@@ -1047,6 +1048,7 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID,
   case Builtin::BIget_pipe_max_packets:
     if (SemaBuiltinPipePackets(*this, TheCall))
       return ExprError();
+    TheCall->setType(Context.UnsignedIntTy);
     break;
   case Builtin::BIto_global:
   case Builtin::BIto_local:
index db6893ebf55d6aafaeba70dd75f79a44fced1779..602fd6ce579a6bbe9ec38f786c900c0099a78c4f 100644 (file)
@@ -59,3 +59,19 @@ void test7(write_only pipe int p, global int *ptr) {
   // CHECK: call i32 @__get_pipe_max_packets(%opencl.pipe_t* %{{.*}})
   *ptr = get_pipe_max_packets(p);
 }
+
+void test8(read_only pipe int r, write_only pipe int w, global int *ptr) {
+  // verify that return type is correctly casted to i1 value
+  // CHECK: %[[R:[0-9]+]] = call i32 @__read_pipe_2
+  // CHECK: icmp ne i32 %[[R]], 0
+  if (read_pipe(r, ptr)) *ptr = -1;
+  // CHECK: %[[W:[0-9]+]] = call i32 @__write_pipe_2
+  // CHECK: icmp ne i32 %[[W]], 0
+  if (write_pipe(w, ptr)) *ptr = -1;
+  // CHECK: %[[N:[0-9]+]] = call i32 @__get_pipe_num_packets
+  // CHECK: icmp ne i32 %[[N]], 0
+  if (get_pipe_num_packets(r)) *ptr = -1;
+  // CHECK: %[[M:[0-9]+]] = call i32 @__get_pipe_max_packets
+  // CHECK: icmp ne i32 %[[M]], 0
+  if (get_pipe_max_packets(w)) *ptr = -1;
+}