Hi!
The PR complains that for the __builtin_stdc_bit_* "builtins" the
diagnostics doesn't mention the name of the builtin the user used, but
instead __builtin_{clz,ctz,popcount}g instead (which is what the FE
immediately lowers it to).
The following patch repeats the checks from check_builtin_function_arguments
which are there done on BUILT_IN_{CLZ,CTZ,POPCOUNT}G, such that they
diagnose it with the name of the "builtin" user actually used before it
is gone.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
2024-02-23 Jakub Jelinek
PR c/114042
* c-parser.cc (c_parser_postfix_expression): Diagnose
__builtin_stdc_bit_* argument with ENUMERAL_TYPE or BOOLEAN_TYPE
type or if signed here rather than on the replacement builtins
in check_builtin_function_arguments.
* gcc.dg/builtin-stdc-bit-2.c: Adjust testcase for actual builtin
names rather than names of builtin replacements.
--- gcc/c/c-parser.cc.jj2024-02-22 16:11:05.320795586 +0100
+++ gcc/c/c-parser.cc 2024-02-22 18:21:03.789602019 +0100
@@ -11860,6 +11860,27 @@ c_parser_postfix_expression (c_parser *p
expr.set_error ();
break;
}
+ if (TREE_CODE (TREE_TYPE (arg_p->value)) == ENUMERAL_TYPE)
+ {
+ error_at (loc, "argument %u in call to function "
+ "%qs has enumerated type", 1, name);
+ expr.set_error ();
+ break;
+ }
+ if (TREE_CODE (TREE_TYPE (arg_p->value)) == BOOLEAN_TYPE)
+ {
+ error_at (loc, "argument %u in call to function "
+ "%qs has boolean type", 1, name);
+ expr.set_error ();
+ break;
+ }
+ if (!TYPE_UNSIGNED (TREE_TYPE (arg_p->value)))
+ {
+ error_at (loc, "argument 1 in call to function "
+ "%qs has signed type", name);
+ expr.set_error ();
+ break;
+ }
tree arg = arg_p->value;
tree type = TYPE_MAIN_VARIANT (TREE_TYPE (arg));
/* Expand:
--- gcc/testsuite/gcc.dg/builtin-stdc-bit-2.c.jj2023-11-23
10:32:33.385984072 +0100
+++ gcc/testsuite/gcc.dg/builtin-stdc-bit-2.c 2024-02-22 18:25:20.585105224
+0100
@@ -14,9 +14,9 @@ foo (void)
__builtin_stdc_leading_zeros ((struct S) { 0 }); /* { dg-error
"'__builtin_stdc_leading_zeros' operand not an integral type" } */
__builtin_stdc_leading_zeros (); /* { dg-error "wrong number of
arguments to '__builtin_stdc_leading_zeros'" } */
__builtin_stdc_leading_zeros (0U, 0U); /* { dg-error "wrong number of
arguments to '__builtin_stdc_leading_zeros'" } */
- __builtin_stdc_leading_zeros ((_Bool) 0);/* { dg-error "argument 1 in
call to function '__builtin_clzg' has boolean type" } */
- __builtin_stdc_leading_zeros ((enum E) E0); /* { dg-error "argument 1 in
call to function '__builtin_clzg' has enumerated type" } */
- __builtin_stdc_leading_zeros (0);/* { dg-error "argument 1 in
call to function '__builtin_clzg' has signed type" } */
+ __builtin_stdc_leading_zeros ((_Bool) 0);/* { dg-error "argument 1 in
call to function '__builtin_stdc_leading_zeros' has boolean type" } */
+ __builtin_stdc_leading_zeros ((enum E) E0); /* { dg-error "argument 1 in
call to function '__builtin_stdc_leading_zeros' has enumerated type" } */
+ __builtin_stdc_leading_zeros (0);/* { dg-error "argument 1 in
call to function '__builtin_stdc_leading_zeros' has signed type" } */
__builtin_stdc_leading_ones (0.0f); /* { dg-error
"'__builtin_stdc_leading_ones' operand not an integral type" } */
__builtin_stdc_leading_ones (0.0); /* { dg-error
"'__builtin_stdc_leading_ones' operand not an integral type" } */
__builtin_stdc_leading_ones (0.0L); /* { dg-error
"'__builtin_stdc_leading_ones' operand not an integral type" } */
@@ -24,9 +24,9 @@ foo (void)
__builtin_stdc_leading_ones ((struct S) { 0 }); /* { dg-error
"'__builtin_stdc_leading_ones' operand not an integral type" } */
__builtin_stdc_leading_ones (); /* { dg-error "wrong number of
arguments to '__builtin_stdc_leading_ones'" } */
__builtin_stdc_leading_ones (0U, 0U);/* { dg-error "wrong number of
arguments to '__builtin_stdc_leading_ones'" } */
- __builtin_stdc_leading_ones ((_Bool) 0); /* { dg-error "argument 1 in
call to function '__builtin_clzg' has boolean type" } */
- __builtin_stdc_leading_ones ((enum E) E0); /* { dg-error "argument 1 in
call to function '__builtin_clzg' has enumerated type" } */
- __builtin_stdc_leading_ones (0); /* { dg-error "argument 1 in
call to function '__builtin_clzg' has signed type" } */
+ __builtin_stdc_leading_ones ((_Bool) 0); /* { dg-error "argument 1 in
call to function '__builtin_stdc_leading_ones' has