bool structured_block = false;
bool swapped = false;
bool seq_cst = false;
+ bool non_lvalue_p;
if (c_parser_next_token_is (parser, CPP_NAME))
{
{
case OMP_ATOMIC_READ:
case NOP_EXPR: /* atomic write */
- v = c_parser_unary_expression (parser).value;
+ v = c_parser_cast_expression (parser, NULL).value;
+ non_lvalue_p = !lvalue_p (v);
v = c_fully_fold (v, false, NULL);
if (v == error_mark_node)
goto saw_error;
+ if (non_lvalue_p)
+ v = non_lvalue (v);
loc = c_parser_peek_token (parser)->location;
if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
goto saw_error;
if (code == NOP_EXPR)
- lhs = c_parser_expression (parser).value;
+ {
+ lhs = c_parser_expression (parser).value;
+ lhs = c_fully_fold (lhs, false, NULL);
+ if (lhs == error_mark_node)
+ goto saw_error;
+ }
else
- lhs = c_parser_unary_expression (parser).value;
- lhs = c_fully_fold (lhs, false, NULL);
- if (lhs == error_mark_node)
- goto saw_error;
+ {
+ lhs = c_parser_cast_expression (parser, NULL).value;
+ non_lvalue_p = !lvalue_p (lhs);
+ lhs = c_fully_fold (lhs, false, NULL);
+ if (lhs == error_mark_node)
+ goto saw_error;
+ if (non_lvalue_p)
+ lhs = non_lvalue (lhs);
+ }
if (code == NOP_EXPR)
{
/* atomic write is represented by OMP_ATOMIC with NOP_EXPR
}
else
{
- v = c_parser_unary_expression (parser).value;
+ v = c_parser_cast_expression (parser, NULL).value;
+ non_lvalue_p = !lvalue_p (v);
v = c_fully_fold (v, false, NULL);
if (v == error_mark_node)
goto saw_error;
+ if (non_lvalue_p)
+ v = non_lvalue (v);
if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
goto saw_error;
}
old or new x should be captured. */
restart:
eloc = c_parser_peek_token (parser)->location;
- expr = c_parser_unary_expression (parser);
+ expr = c_parser_cast_expression (parser, NULL);
lhs = expr.value;
expr = default_function_array_conversion (eloc, expr);
unfolded_lhs = expr.value;
}
/* FALLTHRU */
default:
+ if (!lvalue_p (unfolded_lhs))
+ lhs = non_lvalue (lhs);
switch (c_parser_peek_token (parser)->type)
{
case CPP_MULT_EQ:
{
if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
goto saw_error;
- v = c_parser_unary_expression (parser).value;
+ v = c_parser_cast_expression (parser, NULL).value;
+ non_lvalue_p = !lvalue_p (v);
v = c_fully_fold (v, false, NULL);
if (v == error_mark_node)
goto saw_error;
+ if (non_lvalue_p)
+ v = non_lvalue (v);
if (!c_parser_require (parser, CPP_EQ, "expected %<=%>"))
goto saw_error;
eloc = c_parser_peek_token (parser)->location;
- expr = c_parser_unary_expression (parser);
+ expr = c_parser_cast_expression (parser, NULL);
lhs1 = expr.value;
expr = default_function_array_read_conversion (eloc, expr);
unfolded_lhs1 = expr.value;
lhs1 = c_fully_fold (lhs1, false, NULL);
if (lhs1 == error_mark_node)
goto saw_error;
+ if (!lvalue_p (unfolded_lhs1))
+ lhs1 = non_lvalue (lhs1);
}
if (structured_block)
{
--- /dev/null
+/* PR c/67495 */
+/* { dg-do compile } */
+/* { dg-options "-fopenmp" } */
+
+int a, b, c;
+
+void
+foo (void)
+{
+#pragma omp atomic capture
+ a = (float)a + b; /* { dg-error "invalid operator" } */
+#pragma omp atomic read
+ (float) a = b; /* { dg-error "lvalue required" } */
+#pragma omp atomic write
+ (float) a = b; /* { dg-error "lvalue required" } */
+#pragma omp atomic read
+ a = (float) b; /* { dg-error "lvalue required" } */
+#pragma omp atomic capture
+ (float) a = b += c; /* { dg-error "lvalue required" } */
+#pragma omp atomic capture
+ { a += b; (float) c = a; } /* { dg-error "lvalue required" } */
+#pragma omp atomic capture
+ { a += b; c = (float) a; } /* { dg-error "uses two different expressions for memory" } */
+#pragma omp atomic capture
+ a = (int)a + b; /* { dg-error "invalid operator" } */
+#pragma omp atomic read
+ (int) a = b; /* { dg-error "lvalue required" } */
+#pragma omp atomic write
+ (int) a = b; /* { dg-error "lvalue required" } */
+#pragma omp atomic read
+ a = (int) b; /* { dg-error "lvalue required" } */
+#pragma omp atomic capture
+ (int) a = b += c; /* { dg-error "lvalue required" } */
+#pragma omp atomic capture
+ { a += b; (int) c = a; } /* { dg-error "lvalue required" } */
+#pragma omp atomic capture
+ { a += b; c = (int) a; } /* { dg-error "lvalue required" } */
+}