From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 80BD23858D34; Mon, 15 Apr 2024 07:44:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 80BD23858D34 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1713167055; bh=C+mtjc4sPpqczzsqgpMMY9Cd0mdEzzSiHhwxtdcywkI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=oK0RkpqiYSlyZHVrARL4tMQuZZ6U6cRhUIgbqKP0xIwO378z5UNerkcF910It8tXv mRJVZ3NYiV6HYzsbxoXMaQnohD3ueYk1LZEDglZqxD0P23cYR1WwfUNui1dy7SJrnY S8zp+UhvYe4Jj8kRWzyDS4T33ujjpar7RqMdITV4= From: "lin1.hu at intel dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/114700] middle-end optimization generates causes -fsanitize=undefined not to happen in some cases Date: Mon, 15 Apr 2024 07:44:14 +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 #19 from Hu Lin --- (In reply to Jakub Jelinek from comment #18) > (In reply to Hu Lin from comment #17) > > (In reply to Jakub Jelinek from comment #16) > > >=20 > > > No, -ftrapv isn't a debugging tool. There is no overflow in the expr= ession > > > that GCC actually evaluates (into which the expression has been optim= ized). > > > If you have overflow in an expression that is never used, GCC with -f= trapv > > > will also > > > eliminate it as unused and won't diagnose the trap. > > > -fsanitize=3Dundefined behaves in that case actually the same with -O= 1 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. > >=20 > > OK, that look like GCC's -ftrapv is not the same as clang's. Then my ad= ded > > condition should be (optimize || !TYPE_OVERFLOW_SANITIZED (type)).=20 >=20 > Why? Just !TYPE_OVERFLOW_SANITIZED (type). >=20 OK, so the part is one of your suggestions on how to test UB in a program.= =20 I have another question, -fsanitize=3Dundefined disable this optimization, = but you said -ftrapv won't diagnose the trap. Why is the logic here different f= or these two options=EF=BC=9F >=20 > TYPE_OVERFLOW_SANITIZED is > #define TYPE_OVERFLOW_SANITIZED(TYPE) \ > (INTEGRAL_TYPE_P (TYPE) \ > && !TYPE_OVERFLOW_WRAPS (TYPE) \ > && (flag_sanitize & SANITIZE_SI_OVERFLOW)) > so, it isn't true for non-integral types, nor for TYPE_OVERFLOW_WRAPS typ= es. > So, if you want to avoid the (view_convert (negate @1)), just add (if > !TYPE_OVERFLOW_SANITIZED (type)) above the (view_convert (negate @1)). B= ut > in each case, you want to be careful which exact type you want to check, > type is the type of > the outermost expression, otherwise TREE_TYPE (@0) etc. Thanks for your advice.=