From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 71B293858D32; Sun, 30 Oct 2022 22:10:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 71B293858D32 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667167827; bh=5FDzY06nbcCOsUF08WSN3dauK57dyNLYSJDA1ldIVHs=; h=From:To:Subject:Date:From; b=U4diPax8rEE39TQX0xzZ1d1TVNGgmcZVxhWvL6VqPgDwuxefU0eK6P1HmXLtvksYJ l51I+MgWOFVtiJkQ0cMMUVdLjQHP5rKA9UYN0CIBgx8eYoRo62dzc62C/NbvPg10fr gba1QJcfP5PqPxp2c3+alG7L/EielAWliGKuBxpk= From: "volker.weissmann at gmx dot de" To: gcc-bugs@gcc.gnu.org Subject: [Bug translation/107467] New: Miscompilation involing -Os , -flto and -fno-strict-aliasing Date: Sun, 30 Oct 2022 22:10:16 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: translation X-Bugzilla-Version: 12.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: volker.weissmann at gmx dot de 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 attachments.created 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=3D107467 Bug ID: 107467 Summary: Miscompilation involing -Os , -flto and -fno-strict-aliasing Product: gcc Version: 12.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: translation Assignee: unassigned at gcc dot gnu.org Reporter: volker.weissmann at gmx dot de Target Milestone: --- Created attachment 53798 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D53798&action=3Dedit Source Code g++ -g Record.cpp -c -fPIC -Os -flto g++ -g -shared Record.o -fno-strict-aliasing -o librecord.so g++ main.cpp -L. -lrecord LD_LIBRARY_PATH=3D$PWD ./a.out This sometimes prints 1 and sometimes prints 0. If I remove the -fno-strict-aliasing flag of the second g++ command, or add= it to the first g++ command, it always prints 1. There is no violation of the strict-aliasing rule in Record.cpp, at least n= one that I could spot. If you are afraid of non-reproducibility, fear not, the generated assembly = is the same every time, and is obviously wrong: The method Combined::clashy() is missing a call to get_const objdump librecord.so --disassemble=3D_ZN8CombinedI10OtherClassE6clashyEv.is= ra.0 000000000000113e <_ZN8CombinedI10OtherClassE6clashyEv.isra.0>: 113e: 48 83 ec 38 sub $0x38,%rsp 1142: 64 48 8b 04 25 28 00 mov %fs:0x28,%rax 1149: 00 00=20 114b: 48 89 44 24 28 mov %rax,0x28(%rsp) 1150: 31 c0 xor %eax,%eax 1152: 48 8d 74 24 18 lea 0x18(%rsp),%rsi 1157: 48 8d 7c 24 08 lea 0x8(%rsp),%rdi 115c: e8 b9 ff ff ff call 111a <_Z13compare_pairsIP10OtherClassEbRKSt4pairIiT_ES6_> 1161: 48 8b 54 24 28 mov 0x28(%rsp),%rdx 1166: 64 48 2b 14 25 28 00 sub %fs:0x28,%rdx 116d: 00 00=20 116f: 74 05 je 1176 <_ZN8CombinedI10OtherClassE6clashyEv.isra.0+0x38> 1171: e8 ca fe ff ff call 1040 <__stack_chk_fail@plt> 1176: 48 83 c4 38 add $0x38,%rsp 117a: c3 ret The almost identical Combined::clashy() gets compiled correctly: objdump librecord.so --disassemble=3D_ZN8CombinedI9SomeClassE6clashyEv.isra= .0 000000000000117c <_ZN8CombinedI9SomeClassE6clashyEv.isra.0>: 117c: 48 83 ec 38 sub $0x38,%rsp 1180: 64 48 8b 04 25 28 00 mov %fs:0x28,%rax 1187: 00 00=20 1189: 48 89 44 24 28 mov %rax,0x28(%rsp) 118e: 31 c0 xor %eax,%eax 1190: 48 8d 74 24 18 lea 0x18(%rsp),%rsi 1195: 48 8d 7c 24 08 lea 0x8(%rsp),%rdi 119a: e8 97 ff ff ff call 1136 <_ZN8CombinedI9SomeClassE9get_constEv.constprop.0> 119f: 48 89 54 24 20 mov %rdx,0x20(%rsp) 11a4: 89 44 24 18 mov %eax,0x18(%rsp) 11a8: e8 89 ff ff ff call 1136 <_ZN8CombinedI9SomeClassE9get_constEv.constprop.0> 11ad: 48 89 54 24 10 mov %rdx,0x10(%rsp) 11b2: 89 44 24 08 mov %eax,0x8(%rsp) 11b6: e8 5f ff ff ff call 111a <_Z13compare_pairsIP10OtherClassEbRKSt4pairIiT_ES6_> 11bb: 48 8b 54 24 28 mov 0x28(%rsp),%rdx 11c0: 64 48 2b 14 25 28 00 sub %fs:0x28,%rdx 11c7: 00 00=20 11c9: 74 05 je 11d0 <_ZN8CombinedI9SomeClassE6clashyEv.isra.0+0x54> 11cb: e8 70 fe ff ff call 1040 <__stack_chk_fail@plt> 11d0: 48 83 c4 38 add $0x38,%rsp 11d4: c3 ret $ gcc -v=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 Using built-in specs. COLLECT_GCC=3Dgcc COLLECT_LTO_WRAPPER=3D/usr/lib/gcc/x86_64-pc-linux-gnu/12.2.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: /build/gcc/src/gcc/configure --enable-languages=3Dc,c++,ada,fortran,go,lto,objc,obj-c++,d --enable-boots= trap --prefix=3D/usr --libdir=3D/usr/lib --libexecdir=3D/usr/lib --mandir=3D/usr= /share/man --infodir=3D/usr/share/info --with-bugurl=3Dhttps://bugs.archlinux.org/ --with-build-config=3Dbootstrap-lto --with-linker-hash-style=3Dgnu --with-system-zlib --enable-__cxa_atexit --enable-cet=3Dauto --enable-checking=3Drelease --enable-clocale=3Dgnu --enable-default-pie --enable-default-ssp --enable-gnu-indirect-function --enable-gnu-unique-obj= ect --enable-libstdcxx-backtrace --enable-link-serialization=3D1 --enable-linker-build-id --enable-lto --enable-multilib --enable-plugin --enable-shared --enable-threads=3Dposix --disable-libssp --disable-libstdc= xx-pch --disable-werror Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 12.2.0 (GCC)=20 $ cat main.cpp void other_func(); int main() { other_func(); }=