Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Clang][OpenMP] fixed crash due to invalid binary expression in checking atomic semantics #71480

Merged
merged 2 commits into from
Nov 7, 2023

Conversation

sun-jacobi
Copy link
Member

This PR fixes #69069 .

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:openmp OpenMP related changes to Clang labels Nov 7, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Nov 7, 2023

@llvm/pr-subscribers-clang

Author: Chia (sun-jacobi)

Changes

This PR fixes #69069 .


Full diff: https://github.com/llvm/llvm-project/pull/71480.diff

1 Files Affected:

  • (modified) clang/lib/Sema/SemaOpenMP.cpp (+7)
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;

@shiltian
Copy link
Contributor

shiltian commented Nov 7, 2023

This doesn't look like the right place to fix this issue to me. @alexey-bataev might have better suggestion.

@shiltian shiltian changed the title [Clang][OpenMP]: fixed crash due to invalid binary expression in checking atomic semantics [Clang][OpenMP] fixed crash due to invalid binary expression in checking atomic semantics Nov 7, 2023
@sun-jacobi
Copy link
Member Author

sun-jacobi commented Nov 7, 2023

This doesn't look like the right place to fix this issue to me. @alexey-bataev might have better suggestion.

The crash occurs at

Checker.getX()->Profile(XId, Context, /*Canonical=*/true);

The reason why I fixed the issue like this is that, I think here IsUpdateExprFound
https://github.com/llvm/llvm-project/blob/d34a10a47d25103725174c62ed5e84e8ca380249/clang/lib/Sema/SemaOpenMP.cpp#L13000C15-L13000C32
should not be true, since the second statement (or expression) is invalid expression.

The IsUpdateExprFound comes from

bool IsUpdateExprFound = !Checker.checkStatement(Second);

This function returns false, then the IsUpdateExprFound will be true. This is the reason why I fixed this function

@sun-jacobi
Copy link
Member Author

Moreover, in the original implementation, the checkStatement return false if and only if there is no error in the statement.
The question is whether checkStatement should consider a statement, which contains semantic errors not related to the atomic directive, as a NoError statement.

In my opinion, for such a case, it should be considered as an invalid statement.

Copy link
Member

@alexey-bataev alexey-bataev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like correct fix to me.

@shiltian shiltian merged commit d180cfb into llvm:main Nov 7, 2023
3 checks passed
@shiltian
Copy link
Contributor

shiltian commented Nov 7, 2023

I have merged it given our front end expert @alexey-bataev has approved it.

@sun-jacobi sun-jacobi deleted the 69069-openmp-assertion-const branch November 8, 2023 01:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:openmp OpenMP related changes to Clang clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Clang][OpenMP] Assertion `detail::isPresent(Val) && "dyn_cast on a non-existent value"' failed.
4 participants