<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 - Clang crashes when compiling __builtin_assume_aligned() with non-integer-constant alignment"
   href="https://bugs.llvm.org/show_bug.cgi?id=47588">47588</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Clang crashes when compiling __builtin_assume_aligned() with non-integer-constant alignment
          </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>normal
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>-New Bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>bugsbugs@code.daltonmwoodard.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=23985" name="attach_23985" title="Clang stacktrace">attachment 23985</a> <a href="attachment.cgi?id=23985&action=edit" title="Clang stacktrace">[details]</a></span>
Clang stacktrace

The following reliably leads to a crash within Clang (current trunk, 12.0
series as provided on compiler explorer). This is the most reduced from of the
crash I could come up with, but it was originally discovered in a larger
program source I'm not able to attach here.

// main.c
constexpr unsigned long long a() { return 4; }

int main()
{
    int i = 0;
    (void)__builtin_assume_aligned(&i, a());
}

I've backtested this and it seems to first reproduce in Clang 10.0. Note, the
following snippets containing alternative formulations do _not_ lead to a
crash.

// main.c (crash negative)
constexpr unsigned long long a = 4;

int main()
{
    int i = 0;
    (void)__builtin_assume_aligned(&i, a);
}

// main.c (crash negative)
struct a { static constexpr unsigned long long value = 4; };

int main()
{
    int i = 0;
    (void)__builtin_assume_aligned(&i, a::value);
}

Also note that when the `constexpr` is removed from the declaration of a(),
Clang does not crash and correctly diagnoses it as an error with:

<source>:6:11: error: argument to '__builtin_assume_aligned' must be a constant
integer

    (void)__builtin_assume_aligned(&i, a());

Noting this just for completeness, but it's what I expected since the stack
trace is pointing to LLVM IR generation.</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>