From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from nikam.ms.mff.cuni.cz (nikam.ms.mff.cuni.cz [195.113.20.16]) by sourceware.org (Postfix) with ESMTPS id B579A39450EB for ; Wed, 23 Sep 2020 12:32:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B579A39450EB Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=ucw.cz Authentication-Results: sourceware.org; spf=none smtp.mailfrom=hubicka@kam.mff.cuni.cz Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 79EBA28087C; Wed, 23 Sep 2020 14:32:01 +0200 (CEST) Date: Wed, 23 Sep 2020 14:32:01 +0200 From: Jan Hubicka To: Martin =?iso-8859-2?Q?Li=B9ka?= Cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH] Fix UBSAN errors in ipa-cp. Message-ID: <20200923123201.GB41023@kam.mff.cuni.cz> References: <7115ce43-bf35-c6e4-46b6-56b386e5cb34@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7115ce43-bf35-c6e4-46b6-56b386e5cb34@suse.cz> User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-15.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Sep 2020 12:32:05 -0000 > I see the following UBSAN errors: > > ./xgcc -B. /home/marxin/Programming/gcc/gcc/testsuite/g++.dg/ipa/pr96806.C -std=c++11 -O -fipa-cp -fipa-cp-clone --param=ipa-cp-max-recursive-depth=94 --param=logical-op-non-short-circuit=0 > /home/marxin/Programming/gcc2/gcc/ipa-cp.c:3866:20: runtime error: signed integer overflow: 64 + 2147483584 cannot be represented in type 'int' > /home/marxin/Programming/gcc2/gcc/ipa-cp.c:3843:16: runtime error: signed integer overflow: -2147483648 + -2147483648 cannot be represented in type 'int' > /home/marxin/Programming/gcc2/gcc/ipa-cp.c:3864:20: runtime error: signed integer overflow: 1 + 2147483647 cannot be represented in type 'int' > > Patch can bootstrap on x86_64-linux-gnu and survives regression tests. > > Ready to be installed? > Thanks, > Martin > > gcc/ChangeLog: > > * ipa-cp.c (safe_add): Handle also very small negative values. > (value_topo_info::propagate_effects): Use properly safe_add. Perhaps it is time to turn the profile count scaled valued to sreals like we do in inline heuristics and other places? Honza > --- > gcc/ipa-cp.c | 11 +++++++---- > 1 file changed, 7 insertions(+), 4 deletions(-) > > diff --git a/gcc/ipa-cp.c b/gcc/ipa-cp.c > index b3e7d41ea10..e39ee28726d 100644 > --- a/gcc/ipa-cp.c > +++ b/gcc/ipa-cp.c > @@ -3832,13 +3832,15 @@ propagate_constants_topo (class ipa_topo_info *topo) > /* Return the sum of A and B if none of them is bigger than INT_MAX/2, return > - the bigger one if otherwise. */ > + the bigger one if otherwise. Similarly for negative numbers. */ > static int > safe_add (int a, int b) > { > if (a > INT_MAX/2 || b > INT_MAX/2) > return a > b ? a : b; > + else if (a < -INT_MAX/2 || b < -INT_MAX/2) > + return a > b ? b : a; > else > return a + b; > } > @@ -3861,9 +3863,10 @@ value_topo_info::propagate_effects () > for (val = base; val; val = val->scc_next) > { > - time = safe_add (time, > - val->local_time_benefit + val->prop_time_benefit); > - size = safe_add (size, val->local_size_cost + val->prop_size_cost); > + time = safe_add (time, val->local_time_benefit); > + time = safe_add (time, val->prop_time_benefit); > + size = safe_add (size, val->local_size_cost); > + size = safe_add (size, val->prop_size_cost); > } > for (val = base; val; val = val->scc_next) > -- > 2.28.0 >