<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </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 - Ternary operator not supported using OpenCL style vectors in C++ program while docs imply this is supported."
   href="https://bugs.llvm.org/show_bug.cgi?id=33103">33103</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Ternary operator not supported using OpenCL style vectors in C++ program while docs imply this is supported.
          </td>
        </tr>

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

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

        <tr>
          <th>Hardware</th>
          <td>All
          </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>zalman@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The table at:
    <a href="https://clang.llvm.org/docs/LanguageExtensions.html#vector-operations">https://clang.llvm.org/docs/LanguageExtensions.html#vector-operations</a>
seems to be a list of which operators work with vectors declared as a certain
type of vector in clang. That is if I declare an OpenCL style vector, I would
expect the operators under the OpenCL column to work. The ternary operator does
not appear to work as it would in OpenCL.

The following program:
[
typedef int int4  __attribute__((ext_vector_type(4)));
typedef float float2  __attribute__((ext_vector_type(2)));
typedef float float4  __attribute__((ext_vector_type(4)));

// This compiles, indicating OpenCL extensions are at least partially supported
by default
float2 test_vec_components(float4 input) {
    return input.xy;
}

float4 test_ternary(float4 a, float4 b, int4 mask) {
  return mask ? a  : b;
}
]

gives the error:
[
/tmp/llvm_bug.cpp:10:10: error: value of type 'int4' (vector of 4 'int' values)
is not contextually convertible to 'bool'
  return mask ? a  : b;
]

Either the table above should be clarified or this error should not arise.

Note also the latest version of gcc supports the ternary operator using its
vector extensions. There are likely other bugs to be filed on clang's support
for gcc style vectors not matching what the latest gcc does, but I'm not well
versed enough in the goals to do so.

Clang version:

clang version 5.0.0 (<a href="http://llvm.org/git/clang.git">http://llvm.org/git/clang.git</a>
ea3a0ef86d3f4d8f859f9eca4ef97134484c2610) (<a href="http://llvm.org/git/llvm.git">http://llvm.org/git/llvm.git</a>
7d7f10bcdd4eeade10d64fee424260318f624127)
Target: x86_64-unknown-linux-gnu</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>