From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2a07:de40:b251:101:10:150:64:1]) by sourceware.org (Postfix) with ESMTPS id 57EF73858CDA for ; Tue, 9 Apr 2024 07:40:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 57EF73858CDA Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 57EF73858CDA Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712648425; cv=none; b=dqm8EiPje4sTT21I39329O7QKT7Ir3ufHBlJRSQ7fhqQjkrorwjGSQ1EkW7Oux+RnFREeAdFsUYyOpMTRPGxizUg85FnJPFE3KbxbX3o4E+kilZ9L5qGY4MFkVW5eefJXs61btxmPFj2KSoeGpxSbjmNbQxPO9VSKdxDyQHMH2U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712648425; c=relaxed/simple; bh=jJ39KInOQeILmC4mL78uwl9DEReEc5v37yseFsU1YAY=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:Message-ID:MIME-Version; b=a9JSJR25xv7lHyV6j5cAjQ9PWXGArYBdCatq4694dmv6NSNnvYC7Dve7MPvOAnGQ3q2JY5b8k5NER3S4KHcAdynkOk3JbFYvTRlgLnDTZBy7hbLZSKti3aO9OzC6F2VZ3019ZQ1atE3cIy2lkwNQX9+QMZro+1rXkIyjKtgGWYc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from [10.168.5.241] (unknown [10.168.5.241]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 2BEF933888; Tue, 9 Apr 2024 07:40:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1712648423; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=vhV8+0YCDbTMu9iZ0X9WPdWQHZvEgQYeuaiLNtKkoPg=; b=Sz81FQlsAYP6PVZSFtywGmCOG2eAyhW3ggzb+QqeNF+kun+shpqPQdh07ZTGz+p57diztI 47g2ZsCr4c10zAcQwOFNmvSCIshwsePSyfJvWfKF3BDRZq/XSF/4cfF1FDDkz3bIqSHdIQ 3wSbGZz3wRn3iDWQHDAT94XzM2J9O4I= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1712648423; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=vhV8+0YCDbTMu9iZ0X9WPdWQHZvEgQYeuaiLNtKkoPg=; b=HsicI/kTNDi78HRO+QvCN6Cs1y7P/wxJm3m98BvNjDWKBHnq9dGyUy9+8i78xm5O/6r9Sa hXSGeugw2+MkGZBQ== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1712648423; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=vhV8+0YCDbTMu9iZ0X9WPdWQHZvEgQYeuaiLNtKkoPg=; b=Sz81FQlsAYP6PVZSFtywGmCOG2eAyhW3ggzb+QqeNF+kun+shpqPQdh07ZTGz+p57diztI 47g2ZsCr4c10zAcQwOFNmvSCIshwsePSyfJvWfKF3BDRZq/XSF/4cfF1FDDkz3bIqSHdIQ 3wSbGZz3wRn3iDWQHDAT94XzM2J9O4I= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1712648423; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=vhV8+0YCDbTMu9iZ0X9WPdWQHZvEgQYeuaiLNtKkoPg=; b=HsicI/kTNDi78HRO+QvCN6Cs1y7P/wxJm3m98BvNjDWKBHnq9dGyUy9+8i78xm5O/6r9Sa hXSGeugw2+MkGZBQ== Date: Tue, 9 Apr 2024 09:40:23 +0200 (CEST) From: Richard Biener To: =?ISO-8859-15?Q?J=F8rgen_Kvalsvik?= cc: gcc-patches@gcc.gnu.org, hjl.tools@gmail.com, hubicka@ucw.cz, sam@gentoo.org Subject: Re: [PATCH 2/2] Generate constant at start of loop, without UB In-Reply-To: <20240408141815.127984-3-j@lambda.is> Message-ID: <7347942r-5rs7-7136-93s8-7r28172nr8r1@fhfr.qr> References: <20240408141815.127984-1-j@lambda.is> <20240408141815.127984-3-j@lambda.is> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="8323328-2087108196-1712648423=:8691" X-Spam-Score: -1.80 X-Spam-Level: X-Spamd-Result: default: False [-1.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; SUSPICIOUS_RECIPS(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; CTYPE_MIXED_BOGUS(1.00)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[multipart/mixed,text/plain]; MIME_TRACE(0.00)[0:+,1:+]; ARC_NA(0.00)[]; MISSING_XM_UA(0.00)[]; TAGGED_RCPT(0.00)[]; TO_DN_SOME(0.00)[]; RCVD_COUNT_ZERO(0.00)[0]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FROM_HAS_DN(0.00)[]; FREEMAIL_CC(0.00)[gcc.gnu.org,gmail.com,ucw.cz,gentoo.org]; RCPT_COUNT_FIVE(0.00)[5]; FROM_EQ_ENVFROM(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[tree-profile.cc:url,suse.de:email] X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,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: This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323328-2087108196-1712648423=:8691 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 8BIT On Mon, 8 Apr 2024, Jørgen Kvalsvik wrote: > Generating the constants used for recording the edges taken for > condition coverage would trigger undefined behavior when an expression > had exactly 64 (== sizeof (1ULL)) conditions, as it would generate the > constant for the next iteration at the end of the loop body, even if there > was never a next iteration. By moving the check and constant generation > to the top of the loop and hoisting the increment flag there is no > opportunity for UB. OK. Thanks, Richard. > PR 114627 > > gcc/ChangeLog: > > * tree-profile.cc (instrument_decisions): Generate constant > at the start of loop. > --- > gcc/tree-profile.cc | 20 +++++++++++++++----- > 1 file changed, 15 insertions(+), 5 deletions(-) > > diff --git a/gcc/tree-profile.cc b/gcc/tree-profile.cc > index 33ff550a7bc..e58f5c83472 100644 > --- a/gcc/tree-profile.cc > +++ b/gcc/tree-profile.cc > @@ -1049,6 +1049,7 @@ instrument_decisions (array_slice expr, size_t condno, > zerocounter[2] = zero; > > unsigned xi = 0; > + bool increment = false; > tree rhs = build_int_cst (gcov_type_node, 1ULL << xi); > for (basic_block current : expr) > { > @@ -1057,7 +1058,14 @@ instrument_decisions (array_slice expr, size_t condno, > candidates.safe_push (zerocounter); > counters prev = resolve_counters (candidates); > > - int increment = 0; > + if (increment) > + { > + xi += 1; > + gcc_checking_assert (xi < sizeof (uint64_t) * BITS_PER_UNIT); > + rhs = build_int_cst (gcov_type_node, 1ULL << xi); > + increment = false; > + } > + > for (edge e : current->succs) > { > counters next = prev; > @@ -1072,7 +1080,7 @@ instrument_decisions (array_slice expr, size_t condno, > tree m = build_int_cst (gcov_type_node, masks[2*xi + k]); > next[2] = emit_bitwise_op (e, prev[2], BIT_IOR_EXPR, m); > } > - increment = 1; > + increment = true; > } > else if (e->flags & EDGE_COMPLEX) > { > @@ -1085,11 +1093,13 @@ instrument_decisions (array_slice expr, size_t condno, > } > table.get_or_insert (e->dest).safe_push (next); > } > - xi += increment; > - if (increment) > - rhs = build_int_cst (gcov_type_node, 1ULL << xi); > } > > + /* Since this is also the return value, the number of conditions, make sure > + to include the increment of the last basic block. */ > + if (increment) > + xi += 1; > + > gcc_assert (xi == bitmap_count_bits (core)); > > const tree relaxed = build_int_cst (integer_type_node, MEMMODEL_RELAXED); > -- Richard Biener SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg, Germany; GF: Ivo Totev, Andrew McDonald, Werner Knoblich; (HRB 36809, AG Nuernberg) --8323328-2087108196-1712648423=:8691--