From patchwork Fri Nov 3 07:11:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 161179 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp849425vqu; Fri, 3 Nov 2023 00:11:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IELDaKdXw4zM0HMqFc4BJ5HXe78t7owBsOlH1kwHm+eeXXQ3mlCUp1OlreZNMpVXFyLgCYN X-Received: by 2002:ac8:7f83:0:b0:417:b970:f2a4 with SMTP id z3-20020ac87f83000000b00417b970f2a4mr25139311qtj.1.1698995499103; Fri, 03 Nov 2023 00:11:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698995499; cv=pass; d=google.com; s=arc-20160816; b=KdwUVfzijBJjFlWHLpzd8LjQmeU3x3G/qBjICPEs3ePexxguIfat18PogkIlFhFQmq MOdBtuka9PRPkxRB6Wb9KjtzFIOX/nkKKsc5gB3LcJdJQSDc3c9opDZ/55pnK2cGrY4s RNOgd7i0QIu4HJ2pzF3DqbTZp/qWfesbW5mjScuBvlW7SY+uNho6mPYXS4IlIMF7LBJU ALwgVoCUJ6LHC4RgyZVRW2m2F5ShglDsV5tfd3DO5VsNXbDVPIlvG0QCCKc9OD8biBZy vlSrFM9q6fLRAESwq4TEym7Kezeb6bVjG1jyMbPSBvklT5GuQv2Z2NAfpkAeopng/H5a OQvQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:message-id:mime-version:subject :cc:to:from:date:dkim-signature:dkim-signature:arc-filter :dmarc-filter:delivered-to; bh=ZV945NJh6VgGc5Lh0R5ds2Lxobf83+nR6U6JmESEu5E=; fh=gSYembJIQudd+PvT0IV+g5bEjdJejrB7/Kk1rZi5kHg=; b=nncRVlkQuqDC4dsJlN0pVWmfHx1zqSKYsdiUnQlhGQBq+ZGTWMxzvMQGji1tyOgYdr ucTk5dW7UReUlyLsoeZocHekI8Nuu5OUwxlVb7Hh4FzYEiaJUdJuiqI+IIQ8jqjx7OzH ixp27G3r/AxuuLS0w4QbIauPxq/PLNUwK/Bu0Jvhzu/O8FAsFAMFjnrpBl81ntnEVZgJ k+h3bwZwCCnPSiSyfiSNc6dQ43AMV3W2Cf9niXl7qSt0hubNO+Jcn/Vwn4kjYCbMgWgD 9OZbiKC0HRdenVA14w4jqKnzwGhgGHkayuy6SDPq6TKCWrMxvEN3U1h22fgT/D6sHWxu JdjQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=zr4B9lRY; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id h12-20020ac8584c000000b0041973635d5dsi1022082qth.489.2023.11.03.00.11.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 00:11:39 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=zr4B9lRY; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D967A385842A for ; Fri, 3 Nov 2023 07:11:38 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781525904637487880 X-GMAIL-MSGID: 1781525904637487880 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,