public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "magnus.hegdahl at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/113676] [12 Regression] Miscompilation tree-vrp __builtin_unreachable
Date: Wed, 31 Jan 2024 09:13:44 +0000	[thread overview]
Message-ID: <bug-113676-4-USlhl64DcM@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-113676-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #2 from Magnus Hokland Hegdahl <magnus.hegdahl at gmail dot com> ---
Hi, here's a version that doesn't need -std=c++20 or argv:

https://godbolt.org/z/Y9ooY998e

#include <vector>

constexpr auto bit_ceil(unsigned x) -> unsigned {
    if (x <= 1) return 1U;
    int w = 32 - __builtin_clz(x - 1);
    return 1U << w;
}

int main(int argc, char **) {
    auto rounded_n = bit_ceil(static_cast<unsigned>(argc + 1));
    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;
    }
}

Exact compile command used with g++-12 (GCC) 12.3.0 on arch linux, x86_64:
g++-12 -O1 -ftree-vrp main.cpp

  parent reply	other threads:[~2024-01-31  9:13 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-31  0:54 [Bug tree-optimization/113676] New: " 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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-113676-4-USlhl64DcM@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).