From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E2F093858403; Fri, 12 Apr 2024 10:25:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E2F093858403 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1712917502; bh=k9NF+4xmbN8ywEp8ZHgDbrzVPpCVRR/l1cizxhKifd8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=sAXEYzAfGME1XVT7tOjp+CYjmlKNguxafDv0KDQGHJK0LJUAgmTbxjI0bc8Erj8by gaorB9UaM7o1hz5t5D+A0rge5PCWnoskNU2unEECoHGXq/ozCQSMXv50y0shxeyHlu LK3YcaLg2yrZRe74kUmTY7k9ZcbRRA1jKUQShBQQ= From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/114700] middle-end optimization generates wrong code with -fsanitize=undefined Date: Fri, 12 Apr 2024 10:25:02 +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: jakub 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: 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 #16 from Jakub Jelinek --- (In reply to Hu Lin from comment #11) > 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. No, -ftrapv isn't a debugging tool. There is no overflow in the expression that GCC actually evaluates (into which the expression has been optimized). If you have overflow in an expression that is never used, GCC with -ftrapv = will also eliminate it as unused and won't diagnose the trap. -fsanitize=3Dundefined behaves in that case actually the same with -O1 and = higher (intentionally, to decrease the cost of the sanitization). So, one needs to use -O0 -fsanitize=3Dundefined to get as many cases of UB in the program diagnosed as possible.=