Skip to content

Commit 953d675

Browse files
authored
Fix accsessing "PresentModifierLocs" array beyond its end. (#73579)
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 beyond array end. To fix this using OMPC_DEFAULTMAP_unknow instead OMPC_DEFAULTMAP_poiner.
1 parent db96a9c commit 953d675

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ class DSAStackTy {
161161
LoopControlVariablesMapTy LCVMap;
162162
DefaultDataSharingAttributes DefaultAttr = DSA_unspecified;
163163
SourceLocation DefaultAttrLoc;
164-
DefaultmapInfo DefaultmapMap[OMPC_DEFAULTMAP_unknown];
164+
DefaultmapInfo DefaultmapMap[OMPC_DEFAULTMAP_unknown + 1];
165165
OpenMPDirectiveKind Directive = OMPD_unknown;
166166
/// GenericLoopDirective with bind clause is mapped to other directives,
167167
/// like for, distribute and simd. Presently, set MappedDirective to
@@ -3689,7 +3689,7 @@ class DSAAttrChecker final : public StmtVisitor<DSAAttrChecker, void> {
36893689
bool ErrorFound = false;
36903690
bool TryCaptureCXXThisMembers = false;
36913691
CapturedStmt *CS = nullptr;
3692-
const static unsigned DefaultmapKindNum = OMPC_DEFAULTMAP_pointer + 1;
3692+
const static unsigned DefaultmapKindNum = OMPC_DEFAULTMAP_unknown + 1;
36933693
llvm::SmallVector<Expr *, 4> ImplicitFirstprivate;
36943694
llvm::SmallVector<Expr *, 4> ImplicitPrivate;
36953695
llvm::SmallVector<Expr *, 4> ImplicitMap[DefaultmapKindNum][OMPC_MAP_delete];
@@ -6276,7 +6276,7 @@ StmtResult Sema::ActOnOpenMPExecutableDirective(
62766276
SmallVector<Expr *, 4> ImplicitPrivates(
62776277
DSAChecker.getImplicitPrivate().begin(),
62786278
DSAChecker.getImplicitPrivate().end());
6279-
const unsigned DefaultmapKindNum = OMPC_DEFAULTMAP_pointer + 1;
6279+
const unsigned DefaultmapKindNum = OMPC_DEFAULTMAP_unknown + 1;
62806280
SmallVector<Expr *, 4> ImplicitMaps[DefaultmapKindNum][OMPC_MAP_delete];
62816281
SmallVector<OpenMPMapModifierKind, NumberOfOMPMapClauseModifiers>
62826282
ImplicitMapModifiers[DefaultmapKindNum];

clang/test/OpenMP/target_ast_print.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,8 @@ T tmain(T argc, T *argv) {
11101110
foo();
11111111
#pragma omp target thread_limit(C)
11121112
foo();
1113+
#pragma omp target defaultmap(present)
1114+
foo();
11131115

11141116
return 0;
11151117
}
@@ -1123,6 +1125,8 @@ T tmain(T argc, T *argv) {
11231125
// OMP51-NEXT: foo()
11241126
// OMP51-NEXT: #pragma omp target thread_limit(C)
11251127
// OMP51-NEXT: foo()
1128+
// OMP51-NEXT: #pragma omp target defaultmap(present)
1129+
// OMP51-NEXT: foo()
11261130

11271131
// OMP51-LABEL: int main(int argc, char **argv) {
11281132
int main (int argc, char **argv) {

0 commit comments

Comments
 (0)