<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 - __builtin_astype doesn't work with template parameters"
   href="https://bugs.llvm.org/show_bug.cgi?id=47979">47979</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>__builtin_astype doesn't work with template parameters
          </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>Linux
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>enhancement
          </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>marco.antognini@arm.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>anastasia.stulova@arm.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>In C++ for OpenCL, when using as_typen (e.g. as_int2) or __builtin_astype with
a template parameter, Clang crashes.

int2 foo(long x) { return as_int2(x); }

template <typename T>
auto bar(T x) {
    return as_int2(x); // CRASH
    return __builtin_astype(x, int2); // CRASH
    return foo(x); // works
}

auto foobar(long x) { return bar(x); }

<a href="https://godbolt.org/z/W6cfEK">https://godbolt.org/z/W6cfEK</a>

The crash seems to happen in:

 #5 0x0000556683bca77c clang::ASTContext::getTypeInfoImpl(clang::Type const*)
const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x543d77c)

Note: as_typen is implemented in terms of __builtin_astype.</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>