From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 00EC63856DFB for ; Fri, 3 Nov 2023 07:11:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 00EC63856DFB 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 00EC63856DFB Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.220.29 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698995477; cv=none; b=mhZJhe5GzLJ/Iuv2ckGXnXLi3CDbMbhH+n9lxmNhSiaxTolnPVYr4it6ErwoffT58JV+tHFvVV4bluJjlKwhr6zO3ufNgKRMK0126w44XTQ83aLxpz3c1vQ8D/2UCbaTBK+fezK5j3mp8hDIjwr+g8LjqI6NLIU5B3ImxxZWJJY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698995477; c=relaxed/simple; bh=SwyFV1381AMRurR6lz4qCkpmY6N9CU+tgpNWikgJwoA=; h=DKIM-Signature:DKIM-Signature:Date:From:To:Subject:MIME-Version: Message-Id; b=qh49xmcaso0kXClt5sHPSvN1e5y8XZd9EUAIsXnJwSIRyFETv1JEiPl2xl9Qk/XozkpfSPPwpBzOFyNqHyQ5qGEQMM7Q80gx1iC4KuCfqrUTmJGenYG6la535KyPINLwch5n4dTlSz0Yvqfr84qhj9mODoVFzthjk9nrkAses30= ARC-Authentication-Results: i=1; server2.sourceware.org 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 03EAB1F388; Fri, 3 Nov 2023 07:11:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1698995466; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=ZV945NJh6VgGc5Lh0R5ds2Lxobf83+nR6U6JmESEu5E=; b=zr4B9lRYrD7czbTh9MrxtM3pKhAjBvYJq048nR0mLs20p4j9T2ohWGMZml/emU/PVYqDBO ZvAHz5KgGK/wiV7ZdTJyg+aZo+Kknd8j4zAOKYAVp1WG1P7otRoVMtiFf59zL8ELzaQ8i0 51tLpwm25SCPh5TfVPibGhtLDywr+5w= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1698995466; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=ZV945NJh6VgGc5Lh0R5ds2Lxobf83+nR6U6JmESEu5E=; b=DNCcBhAUKxfXWmL6W8aNEr4bOjIyq11KyeVwxN7YUTnRb7RS7IsNb9gypv0Anqq70pAkMl FVsKqh2mZz4RcxCw== 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 DE25413907; Fri, 3 Nov 2023 07:11:05 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id Ju/tNAmdRGV9NAAAMHmgww (envelope-from ); Fri, 03 Nov 2023 07:11:05 +0000 Date: Fri, 3 Nov 2023 08:11:05 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org cc: "Joseph S. Myers" Subject: [PATCH] [doc] middle-end/112296 - __builtin_constant_p and side-effects MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Message-Id: <20231103071105.DE25413907@imap2.suse-dmz.suse.de> X-Spam-Status: No, score=-11.5 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,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: 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? Shall we diagnose arguments with side-effects? It seems to me such use is usually unintended? I think rather than dropping side-effects as a side-effect of folding the frontend should discard them at parsing time instead, no? Thanks, Richard. PR middle-end/112296 * doc/extend.texi (__builtin_constant_p): Clarify that side-effects are discarded. --- gcc/doc/extend.texi | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index fa7402813e7..c8fc4e391b5 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -14296,14 +14296,16 @@ an error if there is no such function. @defbuiltin{int __builtin_constant_p (@var{exp})} You can use the built-in function @code{__builtin_constant_p} to -determine if a value is known to be constant at compile time and hence -that GCC can perform constant-folding on expressions involving that -value. The argument of the function is the value to test. The function +determine if the expression @var{exp} is known to be constant at +compile time and hence that GCC can perform constant-folding on expressions +involving that value. The argument of the function is the expression to test. +The expression is not evaluated, side-effects are discarded. The function returns the integer 1 if the argument is known to be a compile-time -constant and 0 if it is not known to be a compile-time constant. A -return of 0 does not indicate that the value is @emph{not} a constant, -but merely that GCC cannot prove it is a constant with the specified -value of the @option{-O} option. +constant and 0 if it is not known to be a compile-time constant. +Any expression that has side-effects makes the function return 0. +A return of 0 does not indicate that the expression is @emph{not} a constant, +but merely that GCC cannot prove it is a constant within the constraints +of the active set of optimization options. You typically use this function in an embedded application where memory is a critical resource. If you have some complex calculation, -- 2.35.3