[clang] d180cfb - [Clang][OpenMP] fixed crash due to invalid binary expression in checking atomic semantics (#71480)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 7 07:41:54 PST 2023
Author: Chia
Date: 2023-11-07T10:41:50-05:00
New Revision: d180cfb37d0d1ae1e9dadd13debc49c80d52eda4
URL: https://github.com/llvm/llvm-project/commit/d180cfb37d0d1ae1e9dadd13debc49c80d52eda4
DIFF: https://github.com/llvm/llvm-project/commit/d180cfb37d0d1ae1e9dadd13debc49c80d52eda4.diff
LOG: [Clang][OpenMP] fixed crash due to invalid binary expression in checking atomic semantics (#71480)
This PR fixes https://github.com/llvm/llvm-project/issues/69069 .
Added:
clang/test/SemaOpenMP/atomic-capture-const-no-crash.c
Modified:
clang/lib/Sema/SemaOpenMP.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 1bd34f73e5f7e00..e05fa54d8118319 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -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
};
@@ -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;
diff --git a/clang/test/SemaOpenMP/atomic-capture-const-no-crash.c b/clang/test/SemaOpenMP/atomic-capture-const-no-crash.c
new file mode 100644
index 000000000000000..8739d5c088c1393
--- /dev/null
+++ b/clang/test/SemaOpenMP/atomic-capture-const-no-crash.c
@@ -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'}}
+ }
+}
\ No newline at end of file
More information about the cfe-commits
mailing list