[clang] [Clang][OpenMP] Fix crash on `atomic` with an erroneous statement (PR #228914)
Oliver Hunt via cfe-commits
cfe-commits at lists.llvm.org
Sun Oct 18 13:48:24 PDT 2026
================
@@ -397,6 +397,84 @@ void hint(void) {
a += 1;
}
+void gh107979(void) {
+ int x = 0, v = 0;
+#pragma omp atomic
+ // expected-error at +2 {{the statement for 'atomic' must be an expression statement of form '++x;', '--x;', 'x++;', 'x--;', 'x binop= expr;', 'x = x binop expr' or 'x = expr binop x', where x is an lvalue expression with scalar type}}
+ // expected-note at +1 {{expected a valid expression}}
+ 0--; // expected-error {{expression is not assignable}}
+#pragma omp atomic
+ // expected-error at +2 {{the statement for 'atomic' must be an expression statement of form '++x;', '--x;', 'x++;', 'x--;', 'x binop= expr;', 'x = x binop expr' or 'x = expr binop x', where x is an lvalue expression with scalar type}}
+ // expected-note at +1 {{expected a valid expression}}
+ --0; // expected-error {{expression is not assignable}}
+#pragma omp atomic
+ // expected-error at +2 {{the statement for 'atomic' must be an expression statement of form '++x;', '--x;', 'x++;', 'x--;', 'x binop= expr;', 'x = x binop expr' or 'x = expr binop x', where x is an lvalue expression with scalar type}}
+ // expected-note at +1 {{expected a valid expression}}
+ 0++; // expected-error {{expression is not assignable}}
+#pragma omp atomic update
+ // expected-error at +2 {{the statement for 'atomic update' must be an expression statement of form '++x;', '--x;', 'x++;', 'x--;', 'x binop= expr;', 'x = x binop expr' or 'x = expr binop x', where x is an lvalue expression with scalar type}}
+ // expected-note at +1 {{expected a valid expression}}
+ 0 += 1; // expected-error {{expression is not assignable}}
----------------
ojhunt wrote:
Your initial fuzzer found failure was `0--` that is only one possible error, you should consider others.
One of the most obvious problems is that I think you drop diagnostics after an error has occurred:
```cpp
int x = 0, v = 0--;
#pragma omp atomic capture
{ x = v; v++; }
```
https://github.com/llvm/llvm-project/pull/228914
More information about the cfe-commits
mailing list