From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A906D3858432; Fri, 12 Apr 2024 07:12:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A906D3858432 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1712905973; bh=+HIxPV6Q2YQvCItHy6UXOgAgUMlrPe0/f0KQZvqFFpU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=iSa6kDzVLmyJeBKVmKmxbNjCxNWO1wEYc1YeIvJcDh/4uRjh1iysMh6BlvrI2Ih19 QXZIiRNi+lyxB4yJeP/0o5leNz70ixMV0TSmzT9iyPbDIYlUoc1j5BWbpwBTCiVFTq bYX7tJpiefXqWLCmVxoRgfkyoCezjm6cjJyf3JC4= From: "lin1.hu at intel dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/114700] Front-end optimization generates wrong code with -fsanitize=undefined Date: Fri, 12 Apr 2024 07:12:52 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end 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: Message-ID: In-Reply-To: References: 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 --- Comment #12 from Hu Lin --- (In reply to Hu Lin from comment #11) > (In reply to Richard Biener from comment #9) > > That that GCC doesn't promise that -ftrapv preserves all overflows and > > traps, it merely guarantees that all overflows that actually happen tra= p.=20 > > So GCC is fine to contract some expressions where the overall number of > > overflows can only > > decrease. > >=20 > > That's not a bug with -ftrapv. > >=20 > > It is considered a bug with -fsanitize=3Dundefined though. >=20 > I think it doesn't mean that's not a bug with -ftrapv, it should preserve > all overflow traps. Because it doesn't work, we use -fsanitize=3Dundefined > instead of it. >=20 > refer: Gcc's trapv is known not always to work correctly. >=20 > The current behavior is correct for -fsanitize=3Dundefined, because the > integer signed overflow is well-defined, so GCC can eliminate some > variables. I just think GCC can optimize `z =3D c - y - c + a + y - b`= to > `z =3D a - b`. But it doesn't mean is a bug for -fsanitize=3Dundefined. I was wrong about signed overflow, it's undefined behavior in c++20 (https://en.cppreference.com/w/cpp/language/ub). If I'm not mistaken about = the source=EF=BC=8C it's a bug.=