<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - [OpenCL 2.0] Wrong implicit cast from pipe built-in functions."
   href="https://llvm.org/bugs/show_bug.cgi?id=30219">30219</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[OpenCL 2.0] Wrong implicit cast from pipe built-in functions.
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>OpenCL
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>aleksey.bader@mail.ru
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Here is an example that exposes the issue:

__kernel void testKernel(__global int *status, write_only pipe int tested_pipe)
{
    *status = 0;
    int value = 2;

    if (write_pipe(tested_pipe, &value)) { *status = 2; return; }
}

Error message I get in Release mode on the trunk:

Branch condition is not 'i1' type!
  br i32 %5, label %6, label %8
  %5 = call i32 @__write_pipe_2(%opencl.pipe_t addrspace(1)* %3, i8
addrspace(4)* %4, i32 4, i32 4)
fatal error: error in backend: Broken function found, compilation aborted!

In Debug mode clang crashes in
clang::CodeGen::CodeGenFunction::EmitBranchOnBoolExpr function.

It looks like a bug in the parser. Here is the expression passed to that
function:
CallExpr 0x7aed540 '_Bool'
|-ImplicitCastExpr 0x7aed528 'int (*)()' <BuiltinFnToFnPtr>
| `-DeclRefExpr 0x7aed438 '<builtin fn type>' Function 0x7aed358 'write_pipe'
'int ()'
|-DeclRefExpr 0x7aed460 'pipe int' lvalue ParmVar 0x7aecfe0 'tested_pipe' 'pipe
int'
`-UnaryOperator 0x7aed4d8 'int *' prefix '&'
  `-DeclRefExpr 0x7aed488 'int' lvalue Var 0x7aed298 'value' 'int'

This looks wrong. There should be built-in call and implicit cast of resulting
integer to boolean value.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>