From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id C95013858C39; Mon, 12 Jun 2023 17:19:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C95013858C39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686590370; bh=9fPACxe/zGVXN1UBKbFEzMbaWQ+Z7ubDsXXZNz7vPEc=; h=From:To:Subject:Date:From; b=rn1xTiKQWDa3j1QHPoofhBcsqkQZz1MdkCIfzjvyBsnBFGQVLraVleX3tRTb3Nlxh un1oIYm96+lIN9NJK0SDFmPHX70yfKtXsHB6zq3/1Uo2w8etU12eoy7FDqxsssobVK ms0WEADjj83bO7MozZYRZ1w53DaD4imxKi7eRN4o= From: "slyfox at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/110228] New: [14 Regression] llvm-16 miscompilation on small case switch, minimized Date: Mon, 12 Jun 2023 17:19:29 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: slyfox at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D110228 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 fail= ure when built by r14-1704-gff83d1b47aadcd :=20 - TEST 'LLVM :: ExecutionEngine/JITLink/X86/MachO_weak_references.s' FA= ILED It is caused by ObjectLinkingLayerJITLinkContext::lookup() miscompilation. I extracted the following minimized example from it: #include using M =3D std::vector; 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 =3D clm(); for (unsigned v : Symbols) { int LookupFlags; switch (v) { // never used case 0: LookupFlags =3D 0; break; // always executed for a given input case 1: LookupFlags =3D 1; break; } *p =3D LookupFlags; } } __attribute__((noipa)) int main() { unsigned r =3D 42; bug(&r); if (r !=3D 1) __builtin_trap(); } Triggering: $ g++ bug.cc -o bug -O1 -std=3Dc++11 && ./bug Illegal instruction (core dumped) $ g++ bug.cc -o bug -O0 -std=3Dc++11 && ./bug Note: the program traverses vector of 1 element of value 1. Somehow on -O1 = it manages to miss `LookupFlags =3D 1;` store and does something else. $ g++ -v Using built-in specs. COLLECT_GCC=3D/<>/gcc-14.0.0/bin/g++ COLLECT_LTO_WRAPPER=3D/<>/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=3D/0wz52f16y71ywjvc2rs9r7lw2axyl3fw3jma12azg88jia6k1srk/= include --with-gmp-lib=3D/1ri6zpg87f38gjqjg3hxxfwg9i4fk3hwr1d4c8saiic61pkmzvza/lib --with-mpfr-include=3D/18rzsbmvdk9f7qcy0iynsiabalafwfhjjv9i38q7h5ckvz3z86hz= /include --with-mpfr-lib=3D/1dza8r46l2racn05l78c9iy3ibj1mp02bn45cwrfrg2rxqf05icg/lib --with-mpc=3D/1pg6d47qa8b4l9mq51cvzkkd1jjjbqbvmlm6c9cyzw3kmsf4a10i --with-native-system-header-dir=3D/16q46gpr64lcgbhkdnyigap3mc07g762vn2ckl6z= qa12c1ww1kmp/include --with-build-sysroot=3D/ --program-prefix=3D --enable-lto --disable-libstdc= xx-pch --without-included-gettext --with-system-zlib --enable-checking=3Drelease --enable-static --enable-languages=3Dc,c++ --disable-multilib --enable-plug= in --disable-libcc1 --with-isl=3D/16g549izckw0akjcgs6x4rps7swlqi0ff8i4xfs4cj36l7kdilpv --disable-bootstrap --build=3Dx86_64-unknown-linux-gnu --host=3Dx86_64-unknown-linux-gnu --target=3Dx86_64-unknown-linux-gnu Thread model: posix Supported LTO compression algorithms: zlib gcc version 14.0.0 99999999 (experimental) (GCC)=