[clang] 3732f4e - [OPENMP]Add extra checks and initialization for clause modifier.
Alexey Bataev via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 24 13:13:36 PST 2019
Author: Alexey Bataev
Date: 2019-12-24T16:12:28-05:00
New Revision: 3732f4e093f9aed7aad9740e460e00a248f28572
URL: https://github.com/llvm/llvm-project/commit/3732f4e093f9aed7aad9740e460e00a248f28572
DIFF: https://github.com/llvm/llvm-project/commit/3732f4e093f9aed7aad9740e460e00a248f28572.diff
LOG: [OPENMP]Add extra checks and initialization for clause modifier.
Added initialization of the extra modifier to silence sanitizer. Added
extra checks to avoid such trouble in future.
Added:
Modified:
clang/lib/Parse/ParseOpenMP.cpp
clang/lib/Sema/SemaOpenMP.cpp
Removed:
################################################################################
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 3e8c75b201a8..a62c68b39f1a 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -735,10 +735,12 @@ static bool parseDeclareSimdClauses(
CKind == OMPC_linear) {
Parser::OpenMPVarListDataTy Data;
SmallVectorImpl<Expr *> *Vars = &Uniforms;
- if (CKind == OMPC_aligned)
+ if (CKind == OMPC_aligned) {
Vars = &Aligneds;
- else if (CKind == OMPC_linear)
+ } else if (CKind == OMPC_linear) {
+ Data.ExtraModifier = OMPC_LINEAR_val;
Vars = &Linears;
+ }
P.ConsumeToken();
if (P.ParseOpenMPVarList(OMPD_declare_simd,
@@ -747,6 +749,9 @@ static bool parseDeclareSimdClauses(
if (CKind == OMPC_aligned) {
Alignments.append(Aligneds.size() - Alignments.size(), Data.TailExpr);
} else if (CKind == OMPC_linear) {
+ assert(0 <= Data.ExtraModifier &&
+ Data.ExtraModifier <= OMPC_LINEAR_unknown &&
+ "Unexpected linear modifier.");
if (P.getActions().CheckOpenMPLinearModifier(
static_cast<OpenMPLinearClauseKind>(Data.ExtraModifier),
Data.DepLinMapLastLoc))
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 404ca5028de5..f19cf4304f5e 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -12418,6 +12418,8 @@ OMPClause *Sema::ActOnOpenMPVarListClause(
Res = ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, EndLoc);
break;
case OMPC_lastprivate:
+ assert(0 <= ExtraModifier && ExtraModifier <= OMPC_LASTPRIVATE_unknown &&
+ "Unexpected lastprivate modifier.");
Res = ActOnOpenMPLastprivateClause(
VarList, static_cast<OpenMPLastprivateModifier>(ExtraModifier),
DepLinMapLastLoc, ColonLoc, StartLoc, LParenLoc, EndLoc);
@@ -12441,6 +12443,8 @@ OMPClause *Sema::ActOnOpenMPVarListClause(
ReductionOrMapperId);
break;
case OMPC_linear:
+ assert(0 <= ExtraModifier && ExtraModifier <= OMPC_LINEAR_unknown &&
+ "Unexpected linear modifier.");
Res = ActOnOpenMPLinearClause(
VarList, TailExpr, StartLoc, LParenLoc,
static_cast<OpenMPLinearClauseKind>(ExtraModifier), DepLinMapLastLoc,
@@ -12460,11 +12464,15 @@ OMPClause *Sema::ActOnOpenMPVarListClause(
Res = ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc, EndLoc);
break;
case OMPC_depend:
+ assert(0 <= ExtraModifier && ExtraModifier <= OMPC_DEPEND_unknown &&
+ "Unexpected depend modifier.");
Res = ActOnOpenMPDependClause(
static_cast<OpenMPDependClauseKind>(ExtraModifier), DepLinMapLastLoc,
ColonLoc, VarList, StartLoc, LParenLoc, EndLoc);
break;
case OMPC_map:
+ assert(0 <= ExtraModifier && ExtraModifier <= OMPC_MAP_unknown &&
+ "Unexpected map modifier.");
Res = ActOnOpenMPMapClause(
MapTypeModifiers, MapTypeModifiersLoc, ReductionOrMapperIdScopeSpec,
ReductionOrMapperId, static_cast<OpenMPMapClauseKind>(ExtraModifier),
More information about the cfe-commits
mailing list