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 76D1C3865C36 for ; Mon, 6 Nov 2023 07:41:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 76D1C3865C36 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 76D1C3865C36 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:67c:2178:6::1d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699256511; cv=none; b=qSiCC3z5l5+GXfsW2Lwhdq4/nJTmWqdIbWLgsQLuZ8AusXbgeNyfkjtdhBmt7j0vYFHqW2eilZrvab5wmVKj9z0g5T2fWOQPAZk1cmc83fS1ca11ODIeahoCCT8j2f2TUlw3k8hdOMA07iiZueZGT6/xejDKSxGi/3QRtxEsVAc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699256511; c=relaxed/simple; bh=JajifXM+/f8+zmO4AxrA1isvU3YL830j6ETVTCOsWgc=; h=DKIM-Signature:DKIM-Signature:Date:From:To:Subject:Message-ID: MIME-Version; b=BND9+sJdnakghUNub7AJ23KJAWEa02xcA/uF5wy6IbHT07vpGdKFtbSDQdomjxgyMfdd0D4cU5+rVYFHj3EX6KjuS2SpFMtNXwfYc1We1G/KOqNC/Ek/9XE1ORCBkuUpJ2rakEwr+MpikFBmmiCLt9Fi9UQgFs6JUQ5E3dw4qfs= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 9481C1F38A; Mon, 6 Nov 2023 07:41:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1699256509; 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=i//JzFgi1EO13/SN1LIpVWmS4KcUZAzeLwNVZJEyTus=; b=CkyU72XOSkJgjFxMehh+uekLazLKOXulxbuoigQrn5DOWAgsH0LLrRRAOM7zhG/0mtOW37 YLgdC6t62AAKAqw16WUl02Pnw45v4QPsdH6RYm/dFHR+CIA5XUHssq87Wazoep6bLZ+Lwu nAlDcqWTvChkH+usMBopIYgbfYqQPLo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1699256509; 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=i//JzFgi1EO13/SN1LIpVWmS4KcUZAzeLwNVZJEyTus=; b=XrzjaXKE8RnkYad+4PH0aWPNIrV2jRwQ1jQLtgvkwV2+3AZx6xOQNFfEVPJysLKP0NDFlZ zwZ0ZyrgOkwMLtAA== Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 588BF2C171; Mon, 6 Nov 2023 07:41:49 +0000 (UTC) Date: Mon, 6 Nov 2023 07:41:49 +0000 (UTC) From: Richard Biener To: Joseph Myers cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH] [doc] middle-end/112296 - __builtin_constant_p and side-effects In-Reply-To: Message-ID: References: <20231103071105.DE25413907@imap2.suse-dmz.suse.de> User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE 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: On Fri, 3 Nov 2023, Joseph Myers wrote: > On Fri, 3 Nov 2023, Richard Biener wrote: > > > The following tries to clarify the __builtin_constant_p documentation, > > stating that the argument expression is not evaluated and side-effects > > are discarded. I'm struggling to find the correct terms matching > > what the C language standard would call things so I'd appreciate > > some help here. > > > > OK for trunk? > > OK. Pushed. > > Shall we diagnose arguments with side-effects? It seems to me > > such use is usually unintended? I think rather than dropping > > The traditional use is definitely in macros to choose between code for > constant arguments (evaluating them more than once) and maybe-out-of-line > code for non-constant arguments (evaluating them exactly once), in which > case having a side effect is definitely OK. I was wondering about literally writing if (__builtin_constant_p (++x)) { ... } else { ... } which would have the surprising effects that a) it always evaluates to false, b) the side-effect to 'x' is discarded. > > side-effects as a side-effect of folding the frontend should > > discard them at parsing time instead, no? > > I suppose the original expression needs to remain around in some form > until the latest point at which optimizers might decide to evaluate > __builtin_constant_p to true. Although cases with possible side effects > might well be optimized to false earlier; the interesting cases for > deciding later are e.g. __builtin_constant_p called on an argument to an > inline function (no side effects for __builtin_constant_p to discard, > whether or not there are side effects in the caller from evaluating the > expression passed to the function). Yes, maybe we can improve here but as of now arguments with side-effects will always result in a 'false' assessment as to __builtin_constant_p, so the behavior is hardly useful apart from having "correct" behavior for the traditional macro case. Richard.