[clang] [Clang][OpenMP]: fixed crash due to invalid binary expression in checking atomic semantics (PR #71480)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 6 20:02:44 PST 2023
https://github.com/sun-jacobi updated https://github.com/llvm/llvm-project/pull/71480
>From 265c0586330a678ef61a64c9610cf0ee7c51367f Mon Sep 17 00:00:00 2001
From: sun-jacobi <sun1011jacobi at gmail.com>
Date: Tue, 7 Nov 2023 12:06:28 +0900
Subject: [PATCH 1/2] [Clang][OpenMP]: fixed crash due to invalid binary
expression in atomic semantic checker
---
clang/lib/Sema/SemaOpenMP.cpp | 7 +++++++
1 file changed, 7 insertions(+)
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;
>From 502a90849388fe15c595fa57ab2c280b763a7d1d Mon Sep 17 00:00:00 2001
From: sun-jacobi <sun1011jacobi at gmail.com>
Date: Tue, 7 Nov 2023 13:02:11 +0900
Subject: [PATCH 2/2] [Clang][OpenMP]: add tests for PR #71480
---
.../test/SemaOpenMP/atomic-capture-const-no-crash.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
create mode 100644 clang/test/SemaOpenMP/atomic-capture-const-no-crash.c
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