public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/113676] New: Miscompilation tree-vrp __builtin_unreachable
@ 2024-01-31  0:54 magnus.hegdahl at gmail dot com
  2024-01-31  1:13 ` [Bug tree-optimization/113676] [11/12 Regression] " pinskia at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: magnus.hegdahl at gmail dot com @ 2024-01-31  0:54 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113676

            Bug ID: 113676
           Summary: Miscompilation tree-vrp __builtin_unreachable
           Product: gcc
           Version: 12.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: magnus.hegdahl at gmail dot com
  Target Milestone: ---

Compiling the following code with -O1 -ftree-vrp or higher on GCC 10 or 12
results in a program that segfaults when argc >= 2.

#include <bit>
#include <vector>

auto main(int argc, char **) -> int {
    auto rounded_n = std::bit_ceil(static_cast<unsigned>(argc));
    auto a = std::vector<int>(2UL * rounded_n);

    for (std::size_t i = rounded_n; i-- > 1;) {
        if (!(0 < i && i < rounded_n)) __builtin_unreachable();
        a[i] = 0;
    }
}

If __builtin_unreachable is replaced by for example __builtin_trap, there is no
bug.
I could not reproduce this in GCC 11 or 13.

https://godbolt.org/z/dvEWKzWTh

Disassembly of the loop body:
.L6:
        mov     DWORD PTR [rdi+rdx*4], 0
        sub     rdx, 1
        jmp     .L6

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-06-20  9:14 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-31  0:54 [Bug tree-optimization/113676] New: Miscompilation tree-vrp __builtin_unreachable magnus.hegdahl at gmail dot com
2024-01-31  1:13 ` [Bug tree-optimization/113676] [11/12 Regression] " pinskia at gcc dot gnu.org
2024-01-31  8:25 ` [Bug tree-optimization/113676] [12 " rguenth at gcc dot gnu.org
2024-01-31  9:13 ` magnus.hegdahl at gmail dot com
2024-01-31  9:40 ` jakub at gcc dot gnu.org
2024-01-31  9:44 ` jakub at gcc dot gnu.org
2024-06-20  9:14 ` rguenth at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).