diff options
author | Richard Biener <rguenther@suse.de> | 2023-11-03 08:11:05 +0100 |
---|---|---|
committer | Richard Biener <rguenther@suse.de> | 2023-11-06 08:24:34 +0100 |
commit | 442715708911ed6cc6f3785e3996a62f5ee7f21f (patch) | |
tree | 78aabbd6ceaf76b99ed0489761cf69244597cdaf | |
parent | b2075291af8810794c7184fd125b991c2341cb1e (diff) | |
download | gcc-442715708911ed6cc6f3785e3996a62f5ee7f21f.zip gcc-442715708911ed6cc6f3785e3996a62f5ee7f21f.tar.gz gcc-442715708911ed6cc6f3785e3996a62f5ee7f21f.tar.bz2 |
middle-end/112296 - __builtin_constant_p and side-effects
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.
-rw-r--r-- | gcc/doc/extend.texi | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index fa74028..c8fc4e3 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, |