Skip to content

Commit

Permalink
[Clang][OpenMP] fixed crash due to invalid binary expression in check…
Browse files Browse the repository at this point in the history
…ing atomic semantics (#71480)

This PR fixes #69069 .
  • Loading branch information
sun-jacobi authored Nov 7, 2023
1 parent ded0d7b commit d180cfb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions clang/lib/Sema/SemaOpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11605,6 +11605,9 @@ class OpenMPAtomicUpdateChecker {
/// RHS binary operation does not have reference to the updated LHS
/// part.
NotAnUpdateExpression,
/// An expression contains semantical error not related to
/// 'omp atomic [update]'
NotAValidExpression,
/// No errors is found.
NoError
};
Expand Down Expand Up @@ -11782,6 +11785,10 @@ bool OpenMPAtomicUpdateChecker::checkStatement(Stmt *S, unsigned DiagId,
ErrorFound = NotABinaryOrUnaryExpression;
NoteLoc = ErrorLoc = AtomicBody->getExprLoc();
NoteRange = ErrorRange = AtomicBody->getSourceRange();
} else if (AtomicBody->containsErrors()) {
ErrorFound = NotAValidExpression;
NoteLoc = ErrorLoc = AtomicBody->getExprLoc();
NoteRange = ErrorRange = AtomicBody->getSourceRange();
}
} else {
ErrorFound = NotAScalarType;
Expand Down
12 changes: 12 additions & 0 deletions clang/test/SemaOpenMP/atomic-capture-const-no-crash.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// RUN: %clang_cc1 -fopenmp-simd -fsyntax-only -verify %s
// see https://github.com/llvm/llvm-project/issues/69069
// or https://github.com/llvm/llvm-project/pull/71480

void test() {
int v; const int x; // expected-note {{variable 'x' declared const here}}
#pragma omp atomic capture
{
v = x;
x = 1; // expected-error {{cannot assign to variable 'x' with const-qualified type 'const int'}}
}
}

0 comments on commit d180cfb

Please sign in to comment.