public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/110228] New: [14 Regression] llvm-16 miscompilation on small case switch, minimized
@ 2023-06-12 17:19 slyfox at gcc dot gnu.org
  2023-06-12 17:27 ` [Bug middle-end/110228] " pinskia at gcc dot gnu.org
                   ` (36 more replies)
  0 siblings, 37 replies; 38+ messages in thread
From: slyfox at gcc dot gnu.org @ 2023-06-12 17:19 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110228
           Summary: [14 Regression] llvm-16 miscompilation on small case
                    switch, minimized
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: slyfox at gcc dot gnu.org
  Target Milestone: ---

I initially observed the failure as an llvm-16 (and older) single test failure
when built by r14-1704-gff83d1b47aadcd : 

    - TEST 'LLVM :: ExecutionEngine/JITLink/X86/MachO_weak_references.s' FAILED

It is caused by  ObjectLinkingLayerJITLinkContext::lookup() miscompilation.

I extracted the following minimized example from it:

#include <vector>

using M = std::vector<unsigned>;

static M s_lm{1};

__attribute__((noipa))
static const M & clm(void) {
    return s_lm;
}

__attribute__((noipa))
static void bug(unsigned * p) {
    const M & Symbols = clm();

    for (unsigned v : Symbols) {
      int LookupFlags;
      switch (v) {
      // never used
      case 0:
        LookupFlags = 0;
        break;
      // always executed for a given input
      case 1:
        LookupFlags = 1;
        break;
      }
      *p = LookupFlags;
    }
}

__attribute__((noipa))
int main() {
    unsigned r = 42;
    bug(&r);
    if (r != 1) __builtin_trap();
}

Triggering:

$ g++ bug.cc -o bug -O1 -std=c++11 && ./bug
Illegal instruction (core dumped)
$ g++ bug.cc -o bug -O0 -std=c++11 && ./bug

Note: the program traverses vector of 1 element of value 1. Somehow on -O1 it
manages to miss `LookupFlags = 1;` store and does something else.

$ g++ -v
Using built-in specs.
COLLECT_GCC=/<<NIX>>/gcc-14.0.0/bin/g++
COLLECT_LTO_WRAPPER=/<<NIX>>/gcc-14.0.0/libexec/gcc/x86_64-unknown-linux-gnu/14.0.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with:
--with-gmp-include=/0wz52f16y71ywjvc2rs9r7lw2axyl3fw3jma12azg88jia6k1srk/include
--with-gmp-lib=/1ri6zpg87f38gjqjg3hxxfwg9i4fk3hwr1d4c8saiic61pkmzvza/lib
--with-mpfr-include=/18rzsbmvdk9f7qcy0iynsiabalafwfhjjv9i38q7h5ckvz3z86hz/include
--with-mpfr-lib=/1dza8r46l2racn05l78c9iy3ibj1mp02bn45cwrfrg2rxqf05icg/lib
--with-mpc=/1pg6d47qa8b4l9mq51cvzkkd1jjjbqbvmlm6c9cyzw3kmsf4a10i
--with-native-system-header-dir=/16q46gpr64lcgbhkdnyigap3mc07g762vn2ckl6zqa12c1ww1kmp/include
--with-build-sysroot=/ --program-prefix= --enable-lto --disable-libstdcxx-pch
--without-included-gettext --with-system-zlib --enable-checking=release
--enable-static --enable-languages=c,c++ --disable-multilib --enable-plugin
--disable-libcc1
--with-isl=/16g549izckw0akjcgs6x4rps7swlqi0ff8i4xfs4cj36l7kdilpv
--disable-bootstrap --build=x86_64-unknown-linux-gnu
--host=x86_64-unknown-linux-gnu --target=x86_64-unknown-linux-gnu
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 14.0.0 99999999 (experimental) (GCC)

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

end of thread, other threads:[~2023-07-05  8:24 UTC | newest]

Thread overview: 38+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-12 17:19 [Bug middle-end/110228] New: [14 Regression] llvm-16 miscompilation on small case switch, minimized slyfox at gcc dot gnu.org
2023-06-12 17:27 ` [Bug middle-end/110228] " pinskia at gcc dot gnu.org
2023-06-12 17:30 ` pinskia at gcc dot gnu.org
2023-06-12 17:32 ` pinskia at gcc dot gnu.org
2023-06-12 17:39 ` pinskia at gcc dot gnu.org
2023-06-12 17:45 ` pinskia at gcc dot gnu.org
2023-06-12 17:49 ` pinskia at gcc dot gnu.org
2023-06-12 19:03 ` [Bug middle-end/110228] [14 Regression] llvm-16 miscompiled due to an maybe uninitialized and optimizations saying that the uninitialized has a nonzero bits of 1 pinskia at gcc dot gnu.org
2023-06-12 19:17 ` pinskia at gcc dot gnu.org
2023-06-15  4:50 ` pinskia at gcc dot gnu.org
2023-06-16 22:18 ` pinskia at gcc dot gnu.org
2023-06-16 22:23 ` pinskia at gcc dot gnu.org
2023-06-17 17:52 ` pinskia at gcc dot gnu.org
2023-06-17 20:52 ` pinskia at gcc dot gnu.org
2023-06-17 20:56 ` slyfox at gcc dot gnu.org
2023-06-17 21:04 ` jakub at gcc dot gnu.org
2023-06-17 21:38 ` [Bug middle-end/110228] [13/14 " pinskia at gcc dot gnu.org
2023-06-20  8:38 ` aldyh at gcc dot gnu.org
2023-06-24  0:01 ` [Bug middle-end/110228] [13/14 Regression] llvm-16 miscompiled due to an maybe uninitialized variable pinskia at gcc dot gnu.org
2023-06-30  2:19 ` pinskia at gcc dot gnu.org
2023-07-01  5:24 ` pinskia at gcc dot gnu.org
2023-07-01 21:37 ` zhendong.su at inf dot ethz.ch
2023-07-01 21:40 ` pinskia at gcc dot gnu.org
2023-07-01 21:50 ` pinskia at gcc dot gnu.org
2023-07-03 21:04 ` slyfox at gcc dot gnu.org
2023-07-03 21:52 ` slyfox at gcc dot gnu.org
2023-07-04  6:33 ` rguenth at gcc dot gnu.org
2023-07-04  6:54 ` rguenth at gcc dot gnu.org
2023-07-04  9:15 ` cvs-commit at gcc dot gnu.org
2023-07-04  9:18 ` rguenth at gcc dot gnu.org
2023-07-04 10:06 ` zhendong.su at inf dot ethz.ch
2023-07-04 10:28 ` rguenth at gcc dot gnu.org
2023-07-04 13:36 ` slyfox at gcc dot gnu.org
2023-07-04 13:41 ` rguenther at suse dot de
2023-07-04 15:11 ` slyfox at gcc dot gnu.org
2023-07-05  7:29 ` [Bug middle-end/110228] [13 " rguenth at gcc dot gnu.org
2023-07-05  8:23 ` cvs-commit at gcc dot gnu.org
2023-07-05  8:24 ` 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).