{
unsigned int n_param;
unsigned int n_model;
+ unsigned int outputs = 0; // bitset of output parameters
unsigned int x;
int size_0;
tree type_0;
case BUILT_IN_ATOMIC_EXCHANGE:
n_param = 4;
n_model = 1;
+ outputs = 5;
break;
case BUILT_IN_ATOMIC_LOAD:
+ n_param = 3;
+ n_model = 1;
+ outputs = 2;
+ break;
case BUILT_IN_ATOMIC_STORE:
n_param = 3;
n_model = 1;
+ outputs = 1;
break;
case BUILT_IN_ATOMIC_COMPARE_EXCHANGE:
n_param = 6;
n_model = 2;
+ outputs = 3;
break;
default:
gcc_unreachable ();
function);
return 0;
}
+
+ {
+ auto_diagnostic_group d;
+ int quals = TYPE_QUALS (TREE_TYPE (type));
+ /* Must not write to an argument of a const-qualified type. */
+ if (outputs & (1 << x) && quals & TYPE_QUAL_CONST)
+ {
+ if (c_dialect_cxx ())
+ {
+ error_at (loc, "argument %d of %qE must not be a pointer to "
+ "a %<const%> type", x + 1, function);
+ return 0;
+ }
+ else
+ pedwarn (loc, OPT_Wincompatible_pointer_types, "argument %d "
+ "of %qE discards %<const%> qualifier", x + 1,
+ function);
+ }
+ /* Only the first argument is allowed to be volatile. */
+ if (x > 0 && quals & TYPE_QUAL_VOLATILE)
+ {
+ if (c_dialect_cxx ())
+ {
+ error_at (loc, "argument %d of %qE must not be a pointer to "
+ "a %<volatile%> type", x + 1, function);
+ return 0;
+ }
+ else
+ pedwarn (loc, OPT_Wincompatible_pointer_types, "argument %d "
+ "of %qE discards %<volatile%> qualifier", x + 1,
+ function);
+ }
+ }
}
/* Check memory model parameters for validity. */
--- /dev/null
+/* { dg-do compile } */
+
+#define seq_cst __ATOMIC_SEQ_CST
+
+extern int *i;
+extern int *j;
+extern const int *c;
+extern volatile int *v;
+extern const volatile int *cv;
+
+void
+load()
+{
+ __atomic_load(c, i, seq_cst);
+ __atomic_load(cv, i, seq_cst);
+
+ __atomic_load(i, c, seq_cst);
+ /* { dg-error "argument 2 of '__atomic_load' must not be a pointer to a 'const' type" "" { target c++ } .-1 } */
+ /* { dg-warning "argument 2 of '__atomic_load' discards 'const' qualifier" "" { target c } .-2 } */
+ __atomic_load(i, v, seq_cst);
+ /* { dg-error "argument 2 of '__atomic_load' must not be a pointer to a 'volatile' type" "" { target c++ } .-1 } */
+ /* { dg-warning "argument 2 of '__atomic_load' discards 'volatile' qualifier" "" { target c } .-2 } */
+ __atomic_load(i, cv, seq_cst);
+ /* { dg-error "argument 2 of '__atomic_load' must not be a pointer to a 'const' type" "" { target c++ } .-1 } */
+ /* { dg-warning "argument 2 of '__atomic_load' discards 'const' qualifier" "" { target c } .-2 } */
+ /* { dg-warning "argument 2 of '__atomic_load' discards 'volatile' qualifier" "" { target c } .-3 } */
+}
+
+void
+store()
+{
+ __atomic_store(i, c, seq_cst);
+ __atomic_store(v, c, seq_cst);
+
+ __atomic_store(c, i, seq_cst);
+ /* { dg-error "argument 1 of '__atomic_store' must not be a pointer to a 'const' type" "" { target c++ } .-1 } */
+ /* { dg-warning "argument 1 of '__atomic_store' discards 'const' qualifier" "" { target c } .-2 } */
+ __atomic_store(cv, i, seq_cst);
+ /* { dg-error "argument 1 of '__atomic_store' must not be a pointer to a 'const' type" "" { target c++ } .-1 } */
+ /* { dg-warning "argument 1 of '__atomic_store' discards 'const' qualifier" "" { target c } .-2 } */
+
+ __atomic_store(i, v, seq_cst);
+ /* { dg-error "argument 2 of '__atomic_store' must not be a pointer to a 'volatile' type" "" { target c++ } .-1 } */
+ /* { dg-warning "argument 2 of '__atomic_store' discards 'volatile' qualifier" "" { target c } .-2 } */
+}
+
+void
+exchange()
+{
+ __atomic_exchange(i, c, j, seq_cst);
+ __atomic_exchange(v, i, j, seq_cst);
+ __atomic_exchange(v, c, j, seq_cst);
+
+ __atomic_exchange(c, i, j, seq_cst);
+ /* { dg-error "argument 1 of '__atomic_exchange' must not be a pointer to a 'const' type" "" { target c++ } .-1 } */
+ /* { dg-warning "argument 1 of '__atomic_exchange' discards 'const' qualifier" "" { target c } .-2 } */
+ __atomic_exchange(cv, i, j, seq_cst);
+ /* { dg-error "argument 1 of '__atomic_exchange' must not be a pointer to a 'const' type" "" { target c++ } .-1 } */
+ /* { dg-warning "argument 1 of '__atomic_exchange' discards 'const' qualifier" "" { target c } .-2 } */
+
+ __atomic_exchange(i, v, j, seq_cst);
+ /* { dg-error "argument 2 of '__atomic_exchange' must not be a pointer to a 'volatile' type" "" { target c++ } .-1 } */
+ /* { dg-warning "argument 2 of '__atomic_exchange' discards 'volatile' qualifier" "" { target c } .-2 } */
+ __atomic_exchange(i, cv, j, seq_cst);
+ /* { dg-error "argument 2 of '__atomic_exchange' must not be a pointer to a 'volatile' type" "" { target c++ } .-1 } */
+ /* { dg-warning "argument 2 of '__atomic_exchange' discards 'volatile' qualifier" "" { target c } .-2 } */
+
+ __atomic_exchange(i, j, c, seq_cst);
+ /* { dg-error "argument 3 of '__atomic_exchange' must not be a pointer to a 'const' type" "" { target c++ } .-1 } */
+ /* { dg-warning "argument 3 of '__atomic_exchange' discards 'const' qualifier" "" { target c } .-2 } */
+ __atomic_exchange(i, j, v, seq_cst);
+ /* { dg-error "argument 3 of '__atomic_exchange' must not be a pointer to a 'volatile' type" "" { target c++ } .-1 } */
+ /* { dg-warning "argument 3 of '__atomic_exchange' discards 'volatile' qualifier" "" { target c } .-2 } */
+ __atomic_exchange(i, j, cv, seq_cst);
+ /* { dg-error "argument 3 of '__atomic_exchange' must not be a pointer to a 'const' type" "" { target c++ } .-1 } */
+ /* { dg-warning "argument 3 of '__atomic_exchange' discards 'const' qualifier" "" { target c } .-2 } */
+ /* { dg-warning "argument 3 of '__atomic_exchange' discards 'volatile' qualifier" "" { target c } .-3 } */
+}
+
+void
+compare_exchange()
+{
+ __atomic_compare_exchange(i, j, c, 1, seq_cst, seq_cst);
+ __atomic_compare_exchange(v, i, j, 1, seq_cst, seq_cst);
+ __atomic_compare_exchange(v, i, c, 1, seq_cst, seq_cst);
+
+ __atomic_compare_exchange(c, i, j, 1, seq_cst, seq_cst);
+ /* { dg-error "argument 1 of '__atomic_compare_exchange' must not be a pointer to a 'const' type" "" { target c++ } .-1 } */
+ /* { dg-warning "argument 1 of '__atomic_compare_exchange' discards 'const' qualifier" "" { target c } .-2 } */
+ __atomic_compare_exchange(cv, i, j, 1, seq_cst, seq_cst);
+ /* { dg-error "argument 1 of '__atomic_compare_exchange' must not be a pointer to a 'const' type" "" { target c++ } .-1 } */
+ /* { dg-warning "argument 1 of '__atomic_compare_exchange' discards 'const' qualifier" "" { target c } .-2 } */
+
+ __atomic_compare_exchange(i, c, j, 1, seq_cst, seq_cst);
+ /* { dg-error "argument 2 of '__atomic_compare_exchange' must not be a pointer to a 'const' type" "" { target c++ } .-1 } */
+ /* { dg-warning "argument 2 of '__atomic_compare_exchange' discards 'const' qualifier" "" { target c } .-2 } */
+ __atomic_compare_exchange(i, v, j, 1, seq_cst, seq_cst);
+ /* { dg-error "argument 2 of '__atomic_compare_exchange' must not be a pointer to a 'volatile' type" "" { target c++ } .-1 } */
+ /* { dg-warning "argument 2 of '__atomic_compare_exchange' discards 'volatile' qualifier" "" { target c } .-2 } */
+ __atomic_compare_exchange(i, cv, j, 1, seq_cst, seq_cst);
+ /* { dg-error "argument 2 of '__atomic_compare_exchange' must not be a pointer to a 'const' type" "" { target c++ } .-1 } */
+ /* { dg-warning "argument 2 of '__atomic_compare_exchange' discards 'const" "" { target c } .-2 } */
+ /* { dg-warning "argument 2 of '__atomic_compare_exchange' discards 'volatile' qualifier" "" { target c } .-3 } */
+
+ __atomic_compare_exchange(i, j, v, 1, seq_cst, seq_cst);
+ /* { dg-error "argument 3 of '__atomic_compare_exchange' must not be a pointer to a 'volatile' type" "" { target c++ } .-1 } */
+ /* { dg-warning "argument 3 of '__atomic_compare_exchange' discards 'volatile' qualifier" "" { target c } .-2 } */
+ __atomic_compare_exchange(i, j, cv, 1, seq_cst, seq_cst);
+ /* { dg-error "argument 3 of '__atomic_compare_exchange' must not be a pointer to a 'volatile' type" "" { target c++ } .-1 } */
+ /* { dg-warning "argument 3 of '__atomic_compare_exchange' discards 'volatile' qualifier" "" { target c } .-2 } */
+}