From 03c7149db6ec3c8a70baac1f8f8fa7d0773de3f0 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Thu, 23 Nov 2023 10:12:30 +0100 Subject: c: Add __builtin_stdc_* builtins As discussed in the https://sourceware.org/pipermail/libc-alpha/2023-November/152756.html thread, including e.g. https://sourceware.org/pipermail/libc-alpha/2023-November/152795.html patch, while one can use the new __builtin_{clz,ctz,popcount}g builtins to implement the stdbit.h type-generic macros, there are certain problems with that implementation if those macros must be usable outside of function bodies (e.g. int a = sizeof (stdc_bit_floor (0ULL));), must not evaluate their arguments multiple times and especially for deep stdc_* macro nesting don't expand the argument more than once. Plus ideally are usable in constant expressions for all the types if they have constant arguments. The above second URL satisfies it all but the last two (the last one satisfies for many of them). While we could get away with just adding __biultin_stdc_bit_{ceil,floor,width} which are complicated and 2 further extensions (some way to say that __builtin_c{l,t}zg should imply bit precision of the first argument for the second argument without using __builtin_popcountg ((__typeof (x)) -1) in there because that causes another expansion of the macro argument and say __builtin_bit_complement type-generic builtin which would be like (__typeof (x)) ~(x)), it was decided we want to implement builtins for all the stdc type-generic macros. As we are close to running out of 8-bit enum rid (when adding the 14 new RID_* we have 7 too many), this patch implements those 14 keywords using a single RID_BUILTIN_STDC and simply in the rare case this is being parsed check values of 1-2 characters from the builtin names to see which one it is. 2023-11-23 Jakub Jelinek gcc/ * doc/extend.texi (__builtin_stdc_bit_ceil, __builtin_stdc_bit_floor, __builtin_stdc_bit_width, __builtin_stdc_count_ones, __builtin_stdc_count_zeros, __builtin_stdc_first_leading_one, __builtin_stdc_first_leading_zero, __builtin_stdc_first_trailing_one, __builtin_stdc_first_trailing_zero, __builtin_stdc_has_single_bit, __builtin_stdc_leading_ones, __builtin_stdc_leading_zeros, __builtin_stdc_trailing_ones, __builtin_stdc_trailing_zeros): Document. gcc/c-family/ * c-common.h (enum rid): Add RID_BUILTIN_STDC: New. * c-common.cc (c_common_reswords): Add __builtin_stdc_bit_ceil, __builtin_stdc_bit_floor, __builtin_stdc_bit_width, __builtin_stdc_count_ones, __builtin_stdc_count_zeros, __builtin_stdc_first_leading_one, __builtin_stdc_first_leading_zero, __builtin_stdc_first_trailing_one, __builtin_stdc_first_trailing_zero, __builtin_stdc_has_single_bit, __builtin_stdc_leading_ones, __builtin_stdc_leading_zeros, __builtin_stdc_trailing_ones and __builtin_stdc_trailing_zeros. Move __builtin_assoc_barrier alphabetically earlier. gcc/c/ * c-parser.cc (c_parser_postfix_expression): Handle RID_BUILTIN_STDC. * c-decl.cc (names_builtin_p): Likewise. gcc/testsuite/ * gcc.dg/builtin-stdc-bit-1.c: New test. * gcc.dg/builtin-stdc-bit-2.c: New test. --- gcc/c/c-decl.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'gcc/c/c-decl.cc') diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc index 64d3a94..439a312 100644 --- a/gcc/c/c-decl.cc +++ b/gcc/c/c-decl.cc @@ -11370,11 +11370,12 @@ names_builtin_p (const char *name) functions. */ switch (C_RID_CODE (id)) { + case RID_BUILTIN_ASSOC_BARRIER: case RID_BUILTIN_CONVERTVECTOR: case RID_BUILTIN_HAS_ATTRIBUTE: case RID_BUILTIN_SHUFFLE: case RID_BUILTIN_SHUFFLEVECTOR: - case RID_BUILTIN_ASSOC_BARRIER: + case RID_BUILTIN_STDC: case RID_CHOOSE_EXPR: case RID_OFFSETOF: case RID_TYPES_COMPATIBLE_P: -- cgit v1.1