Skip to content

Commit d180cfb

Browse files
authored
[Clang][OpenMP] fixed crash due to invalid binary expression in checking atomic semantics (#71480)
This PR fixes #69069 .
1 parent ded0d7b commit d180cfb

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11605,6 +11605,9 @@ class OpenMPAtomicUpdateChecker {
1160511605
/// RHS binary operation does not have reference to the updated LHS
1160611606
/// part.
1160711607
NotAnUpdateExpression,
11608+
/// An expression contains semantical error not related to
11609+
/// 'omp atomic [update]'
11610+
NotAValidExpression,
1160811611
/// No errors is found.
1160911612
NoError
1161011613
};
@@ -11782,6 +11785,10 @@ bool OpenMPAtomicUpdateChecker::checkStatement(Stmt *S, unsigned DiagId,
1178211785
ErrorFound = NotABinaryOrUnaryExpression;
1178311786
NoteLoc = ErrorLoc = AtomicBody->getExprLoc();
1178411787
NoteRange = ErrorRange = AtomicBody->getSourceRange();
11788+
} else if (AtomicBody->containsErrors()) {
11789+
ErrorFound = NotAValidExpression;
11790+
NoteLoc = ErrorLoc = AtomicBody->getExprLoc();
11791+
NoteRange = ErrorRange = AtomicBody->getSourceRange();
1178511792
}
1178611793
} else {
1178711794
ErrorFound = NotAScalarType;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %clang_cc1 -fopenmp-simd -fsyntax-only -verify %s
2+
// see https://github.com/llvm/llvm-project/issues/69069
3+
// or https://github.com/llvm/llvm-project/pull/71480
4+
5+
void test() {
6+
int v; const int x; // expected-note {{variable 'x' declared const here}}
7+
#pragma omp atomic capture
8+
{
9+
v = x;
10+
x = 1; // expected-error {{cannot assign to variable 'x' with const-qualified type 'const int'}}
11+
}
12+
}

0 commit comments

Comments
 (0)