[llvm-bugs] [Bug 47588] New: Clang crashes when compiling __builtin_assume_aligned() with non-integer-constant alignment

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Sep 19 18:39:10 PDT 2020


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

            Bug ID: 47588
           Summary: Clang crashes when compiling
                    __builtin_assume_aligned() with non-integer-constant
                    alignment
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: bugsbugs at code.daltonmwoodard.com
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
                    neeilans at live.com, richard-llvm at metafoo.co.uk

Created attachment 23985
  --> https://bugs.llvm.org/attachment.cgi?id=23985&action=edit
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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200920/6c04d80a/attachment-0001.html>


More information about the llvm-bugs mailing list