From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id 6B2033858D39 for ; Wed, 19 Oct 2022 08:20:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6B2033858D39 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 29891201DE; Wed, 19 Oct 2022 08:20:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1666167639; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rVmqSLiCWjHQPuKbD8U5JOXs2XZlAcfjft7ciogqt3E=; b=g/he5Q8kdqbggxBHk+ivRbSS9gMpScluT+eaGlTTQVflVJyboYgKTupiHRVSpZK7zhh630 yhVsND/JExWqrPVBBDHtZH8qau+6twTHBlkZ74nXsWc3Iz9ukTOz30LlYV8w+S43ua0xPk ovPa+e2lRmvBPyu5D69clunxqUIT71c= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1666167639; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rVmqSLiCWjHQPuKbD8U5JOXs2XZlAcfjft7ciogqt3E=; b=HDS7lncKaJ7Vtl7Q1rhoMLLSoKifLTCK4Xdi9f7Fw7oYczNskBK+8o7lCkjvUURi8qAQoN cPwem2k26t0C59DQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 0F8A213345; Wed, 19 Oct 2022 08:20:39 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id QQW/A1ezT2OvWwAAMHmgww (envelope-from ); Wed, 19 Oct 2022 08:20:39 +0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: Richard Biener Mime-Version: 1.0 (1.0) Subject: Re: [PATCH] match.pd: Add 2 TYPE_OVERFLOW_SANITIZED checks [PR106990] Date: Wed, 19 Oct 2022 10:20:38 +0200 Message-Id: References: Cc: gcc-patches@gcc.gnu.org In-Reply-To: To: Jakub Jelinek X-Mailer: iPhone Mail (19H12) X-Spam-Status: No, score=-6.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: > Am 19.10.2022 um 10:02 schrieb Jakub Jelinek : >=20 > =EF=BB=BFHi! >=20 > As requested in the PR, this adds 2 TYPE_OVERFLOW_SANITIZED checks > and corresponding testcase. >=20 > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? Ok. Thanks, Richard=20 > 2022-10-19 Jakub Jelinek >=20 > PR tree-optimization/106990 > * match.pd ((~X - ~Y) -> Y - X, -x & 1 -> x & 1): Guard with > !TYPE_OVERFLOW_SANITIZED (type). >=20 > * c-c++-common/ubsan/pr106990.c: New test. >=20 > --- gcc/match.pd.jj 2022-10-13 15:51:08.928071208 +0200 > +++ gcc/match.pd 2022-10-18 16:01:12.145705958 +0200 > @@ -1331,8 +1331,9 @@ (define_operator_list SYNC_FETCH_AND_AND > /* (~X - ~Y) -> Y - X. */ > (simplify > (minus (bit_not @0) (bit_not @1)) > - (with { tree utype =3D unsigned_type_for (type); } > - (convert (minus (convert:utype @1) (convert:utype @0))))) > + (if (!TYPE_OVERFLOW_SANITIZED (type)) > + (with { tree utype =3D unsigned_type_for (type); } > + (convert (minus (convert:utype @1) (convert:utype @0)))))) >=20 > /* ~(X - Y) -> ~X + Y. */ > (simplify > @@ -8176,5 +8177,6 @@ and, >=20 > /* -x & 1 -> x & 1. */ > (simplify=20 > - (bit_and (negate @0) integer_onep@1) > - (bit_and @0 @1)) > + (bit_and (negate @0) integer_onep@1) > + (if (!TYPE_OVERFLOW_SANITIZED (type)) > + (bit_and @0 @1))) > --- gcc/testsuite/c-c++-common/ubsan/pr106990.c.jj 2022-10-18 15:56:20.= 260656260 +0200 > +++ gcc/testsuite/c-c++-common/ubsan/pr106990.c 2022-10-18 16:17:37.295= 403933 +0200 > @@ -0,0 +1,29 @@ > +/* PR tree-optimization/106990 */ > +/* { dg-do run { target int32 } } */ > +/* { dg-options "-fsanitize=3Dsigned-integer-overflow" } */ > + > +__attribute__((noipa)) int > +foo (void) > +{ > + int x =3D -1956816001; > + int y =3D 1999200512; > + return ~x - ~y; > +} > + > +__attribute__((noipa)) int > +bar (void) > +{ > + int x =3D -__INT_MAX__ - 1; > + return -x & 1; > +} > + > +int > +main () > +{ > + foo (); > + bar (); > + return 0; > +} > + > +/* { dg-output "signed integer overflow: 1956816000 - -1999200513 cannot b= e represented in type 'int'\[^\n\r]*(\n|\r\n|\r)" } */ > +/* { dg-output "\[^\n\r]*negation of -2147483648 cannot be represented in= type 'int'; cast to an unsigned type to negate this value to itself" } */ >=20 > Jakub >=20