https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95378
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Every __atomic_xxx built-in has the same problem. They'll all accept
cv-qualified types as output parameters.
This seems to fix it, but I'll finish testing it and submit it tomorrow:
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -6903,6 +6903,8 @@ get_atomic_generic_size (location_t loc, tree function,
{
unsigned int n_param;
unsigned int n_model;
+ unsigned int n_first_output = 0;
+ unsigned int n_last_output = 0;
unsigned int x;
int size_0;
tree type_0;
@@ -6915,11 +6917,14 @@ get_atomic_generic_size (location_t loc, tree function,
n_model = 1;
break;
case BUILT_IN_ATOMIC_LOAD:
+ n_first_output = n_last_output = 1;
+ /* fallthrough */
case BUILT_IN_ATOMIC_STORE:
n_param = 3;
n_model = 1;
break;
case BUILT_IN_ATOMIC_COMPARE_EXCHANGE:
+ n_last_output = 1;
n_param = 6;
n_model = 2;
break;
@@ -7010,6 +7015,23 @@ get_atomic_generic_size (location_t loc, tree function,
function);
return 0;
}
+
+ if (x >= n_first_output && x <= n_last_output)
+ {
+ tree type = TREE_TYPE (TREE_TYPE ((*params)[x]));
+ if (TYPE_QUALS (type) & (TYPE_QUAL_CONST|TYPE_QUAL_VOLATILE))
+ {
+ if (c_dialect_cxx ())
+ {
+ error_at (loc, "argument %d of %qE must not be a pointer to "
+ "a cv-qualified type", x + 1, function);
+ return 0;
+ }
+ else
+ pedwarn (loc, OPT_Wincompatible_pointer_types, "argument %d "
+ "of %qE discards qualifiers", x + 1, function);
+ }
+ }
}
/* Check memory model parameters for validity. */