From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 59EE53858C56; Sun, 27 Mar 2022 23:22:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 59EE53858C56 From: "dlong at cadence dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/105071] New: Incorrect code with -Os and complex Date: Sun, 27 Mar 2022 23:22:11 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 9.3.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: dlong at cadence dot com 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 27 Mar 2022 23:22:11 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105071 Bug ID: 105071 Summary: Incorrect code with -Os and complex Product: gcc Version: 9.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: dlong at cadence dot com Target Milestone: --- Created attachment 52691 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D52691&action=3Dedit .ii file for test case 64-bit Intel, RedHat Enterprise Linux 7.4 $ cat foo.cc #include #include using namespace std; void broken(complex x) { complex x2=3Dx*x; complex x3=3Dx2*x; complex x4=3Dx3*x; complex x5=3Dx4*x; complex d=3D1.0+2.0/x+4.0/x2+8.0/x3+16.0/x4+32.0/x5; fprintf(stderr, "%e%+ej\n", real(d), imag(d)); } int main(int argc, char **argv) { broken(complex(1.0, 0.000000e+00)); return 0; } $ g++-9 -Wall -o foo foo.cc && ./foo # correct 6.300000e+01+0.000000e+00j $ g++-9 -Wall -O2 -o foo foo.cc && ./foo # also correct 6.300000e+01+0.000000e+00j $ g++-9 -Wall -Os -o foo foo.cc && ./foo # wrong 1.000000e+00+0.000000e+00j If the +32.0/x5 at the end of the computation of d is omitted, then -Os also gives the correct result. $ g++-9 -v Using built-in specs. COLLECT_GCC=3Dg++-9 COLLECT_LTO_WRAPPER=3D/grid/common/pkgsData/gcc-v9.3.0p3/Linux/RHEL7.0-2017= -x86_64/libexec/gcc/x86_64-redhat-linux/9.3.0/lto-wrapper Target: x86_64-redhat-linux Configured with: /tmp/gcc-v9.3.0p3/gcc.source/configure --prefix=3D/grid/common/pkgsData/gcc-v9.3.0p3/Linux/RHEL7.0-2017-x86_64 --with-pkgversion=3DCadence --disable-libgcj --enable-threads=3Dposix --enable-shared --enable-checking=3Drelease --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --with-linker-hash-style=3Dgnu --enable-languages=3Dc,c++,fortran --disable= -nls --enable-gnu-unique-object --enable-bootstrap --enable-plugin --enable-initfini-array --enable-linker-build-id --enable-gnu-indirect-func= tion --enable-install-libiberty --with-ld=3D/grid/common/pkgsData/gcc-v9.3.0p3/Linux/RHEL7.0-2017-x86_64/bi= n/ld --with-as=3D/grid/common/pkgsData/gcc-v9.3.0p3/Linux/RHEL7.0-2017-x86_64/bi= n/as --build=3Dx86_64-redhat-linux --host=3Dx86_64-redhat-linux --with-tune=3Dge= neric --enable-multiarch Thread model: posix gcc version 9.3.0 (Cadence)=