[RFC] Adding a new attribute to function param to mark it as constant
Segher Boessenkool
segher@kernel.crashing.org
Tue Aug 3 21:55:38 GMT 2021
Hi!
On Fri, Jul 23, 2021 at 04:23:42PM +0530, Prathamesh Kulkarni via Gcc wrote:
> The constraint here is that, vshl_n<type> intrinsics require that the
> second arg (__b),
> should be an immediate value.
Something that matches the "n" constraint, not necessarily a literal,
but stricter than just "immediate". It probably is a good idea to allow
only "integer constant expression"s, so that the validity of the source
code does not depend on what the optimisers do with the code.
> As Richard suggested, sth like:
> void foo(int x __attribute__((literal_constant (min_val, max_val)));
The Linux kernel has a macro __is_constexpr to test if something is an
integer constant expression, see <linux/const.h> . That is a much
better idea imo. There could be a builtin for that of course, but an
attribute is less powerful, less usable, less useful.
Segher
More information about the Gcc
mailing list