From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 06C603858CDB; Fri, 12 Apr 2024 02:22:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 06C603858CDB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1712888548; bh=EHVUCAh3tStJy00+ovzNSzoglsZbHWvoI3wB3XE5DB0=; h=From:To:Subject:Date:From; b=sMFRo3j9T38u/nw2cxXV7mfidvrg/iKnSG8bsUdUwf48+Rt5o1/VdBnmFXMp67ehm 3/FECKVmsktYaQQlohJE0XueozsbaJfK/cGWDgZxCASvPQ0AtAML4yFqqFy9FF5dyJ R2mLT+pyT0pf9WzOynEy3DoIJI9SKg7ls9OcywPE= From: "lin1.hu at intel dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/114700] New: Front-end optimization generates wrong code with -ftrapv. Date: Fri, 12 Apr 2024 02:22:27 +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: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: lin1.hu at intel 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 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=3D114700 Bug ID: 114700 Summary: Front-end optimization generates wrong code with -ftrapv. Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: lin1.hu at intel dot com Target Milestone: --- We test GCC vs Clang with -ftrapv, and test is=20 z =3D c - y - c + a + y - b; https://godbolt.org/z/EW1xTsazG We think the clang is right, the overflow judgment should be performed after each operation. But the front-end generates a - b directly, looks like ther= e's a bug in the front-end's handling of -ftrapv. -ftrapv This option generates traps for signed overflow on addition, subtraction, multiplication operations. The options -ftrapv and -fwrapv override each ot= her, so using -ftrapv -fwrapv on the command-line results in -fwrapv being effective. Note that only active options override, so using -ftrapv -fwrapv -fno-wrapv on the command-line results in -ftrapv being effective. We have another question, we found the front-end won't optimize z =3D c - y= + a - c, while z =3D c - y - c + a will, is this for any particular reason or is = it a bug?=