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

Fix accsessing "PresentModifierLocs" array beyond its end. #73579

Merged
merged 1 commit into from
Nov 29, 2023

Conversation

jyu2-git
Copy link
Contributor

Currently PresentModifierLocs defined with size DefaultmapKindNum; where DefaultmapKindNum = OMPC_DEFAULTMAP_pointer + 1

Before 5.0 variable-category can not be omitted. For the test like #pragma omp target map(tofrom: errors) defaultmap(present)

error would be mitted.

After 5.0 that is allowd.

When try to:
PresentModifierLocs[DMC->getDefaultmapKind()] =
DMC->getDefaultmapModifierLoc();
It is accessed beyound array end.

Currently PresentModifierLocs defined with size DefaultmapKindNum;
where DefaultmapKindNum = OMPC_DEFAULTMAP_pointer + 1

Before 5.0 variable-category can not be omitted. For the test like
\#pragma omp target map(tofrom: errors) defaultmap(present)

error would be mitted.

After 5.0 that is allowd.

When try to:
PresentModifierLocs[DMC->getDefaultmapKind()] =
              DMC->getDefaultmapModifierLoc();
It is accessed beyound array end.
@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 27, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Nov 27, 2023

@llvm/pr-subscribers-clang

Author: None (jyu2-git)

Changes

Currently PresentModifierLocs defined with size DefaultmapKindNum; where DefaultmapKindNum = OMPC_DEFAULTMAP_pointer + 1

Before 5.0 variable-category can not be omitted. For the test like #pragma omp target map(tofrom: errors) defaultmap(present)

error would be mitted.

After 5.0 that is allowd.

When try to:
PresentModifierLocs[DMC->getDefaultmapKind()] =
DMC->getDefaultmapModifierLoc();
It is accessed beyound array end.


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

2 Files Affected:

  • (modified) clang/lib/Sema/SemaOpenMP.cpp (+3-3)
  • (modified) clang/test/OpenMP/target_ast_print.cpp (+4)
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 3a5f4b12ce29621..e400f248d15aa34 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -161,7 +161,7 @@ class DSAStackTy {
     LoopControlVariablesMapTy LCVMap;
     DefaultDataSharingAttributes DefaultAttr = DSA_unspecified;
     SourceLocation DefaultAttrLoc;
-    DefaultmapInfo DefaultmapMap[OMPC_DEFAULTMAP_unknown];
+    DefaultmapInfo DefaultmapMap[OMPC_DEFAULTMAP_unknown + 1];
     OpenMPDirectiveKind Directive = OMPD_unknown;
     /// GenericLoopDirective with bind clause is mapped to other directives,
     /// like for, distribute and simd. Presently, set MappedDirective to
@@ -3689,7 +3689,7 @@ class DSAAttrChecker final : public StmtVisitor<DSAAttrChecker, void> {
   bool ErrorFound = false;
   bool TryCaptureCXXThisMembers = false;
   CapturedStmt *CS = nullptr;
-  const static unsigned DefaultmapKindNum = OMPC_DEFAULTMAP_pointer + 1;
+  const static unsigned DefaultmapKindNum = OMPC_DEFAULTMAP_unknown + 1;
   llvm::SmallVector<Expr *, 4> ImplicitFirstprivate;
   llvm::SmallVector<Expr *, 4> ImplicitPrivate;
   llvm::SmallVector<Expr *, 4> ImplicitMap[DefaultmapKindNum][OMPC_MAP_delete];
@@ -6276,7 +6276,7 @@ StmtResult Sema::ActOnOpenMPExecutableDirective(
     SmallVector<Expr *, 4> ImplicitPrivates(
         DSAChecker.getImplicitPrivate().begin(),
         DSAChecker.getImplicitPrivate().end());
-    const unsigned DefaultmapKindNum = OMPC_DEFAULTMAP_pointer + 1;
+    const unsigned DefaultmapKindNum = OMPC_DEFAULTMAP_unknown + 1;
     SmallVector<Expr *, 4> ImplicitMaps[DefaultmapKindNum][OMPC_MAP_delete];
     SmallVector<OpenMPMapModifierKind, NumberOfOMPMapClauseModifiers>
         ImplicitMapModifiers[DefaultmapKindNum];
diff --git a/clang/test/OpenMP/target_ast_print.cpp b/clang/test/OpenMP/target_ast_print.cpp
index d3daed053cc2ea5..45907e93321a824 100644
--- a/clang/test/OpenMP/target_ast_print.cpp
+++ b/clang/test/OpenMP/target_ast_print.cpp
@@ -1110,6 +1110,8 @@ T tmain(T argc, T *argv) {
   foo();
   #pragma omp target thread_limit(C)
   foo();
+  #pragma omp target defaultmap(present)
+  foo();
 
   return 0;
 }
@@ -1123,6 +1125,8 @@ T tmain(T argc, T *argv) {
 // OMP51-NEXT: foo()
 // OMP51-NEXT: #pragma omp target thread_limit(C)
 // OMP51-NEXT: foo()
+// OMP51-NEXT: #pragma omp target defaultmap(present)
+// OMP51-NEXT: foo()
 
 // OMP51-LABEL: int main(int argc, char **argv) {
 int main (int argc, char **argv) {

@jyu2-git jyu2-git merged commit 953d675 into llvm:main Nov 29, 2023
6 checks passed
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.

None yet

3 participants