Skip to content

Commit d2cbfcb

Browse files
committed
Address review comments
Signed-off-by: yronglin <[email protected]>
1 parent c57b2c7 commit d2cbfcb

File tree

5 files changed

+13
-14
lines changed

5 files changed

+13
-14
lines changed

clang/include/clang/Sema/Sema.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5469,8 +5469,7 @@ class Sema final : public SemaBase {
54695469
ExprResult ActOnPredefinedExpr(SourceLocation Loc, tok::TokenKind Kind);
54705470
ExprResult ActOnIntegerConstant(SourceLocation Loc, uint64_t Val);
54715471

5472-
bool CheckLoopHintExpr(Expr *E, SourceLocation Loc,
5473-
const IdentifierInfo *PragmaNameInfo);
5472+
bool CheckLoopHintExpr(Expr *E, SourceLocation Loc, bool AllowZero);
54745473

54755474
ExprResult ActOnNumericConstant(const Token &Tok, Scope *UDLScope = nullptr);
54765475
ExprResult ActOnCharacterConstant(const Token &Tok,

clang/lib/Parse/ParsePragma.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,7 +1570,7 @@ bool Parser::HandlePragmaLoopHint(LoopHint &Hint) {
15701570

15711571
if (Arg2Error || R.isInvalid() ||
15721572
Actions.CheckLoopHintExpr(R.get(), Toks[0].getLocation(),
1573-
PragmaNameInfo))
1573+
/*AllowZero=*/false))
15741574
return false;
15751575

15761576
// Argument is a constant expression with an integer type.
@@ -1594,8 +1594,9 @@ bool Parser::HandlePragmaLoopHint(LoopHint &Hint) {
15941594

15951595
ConsumeToken(); // Consume the constant expression eof terminator.
15961596

1597-
if (R.isInvalid() || Actions.CheckLoopHintExpr(
1598-
R.get(), Toks[0].getLocation(), PragmaNameInfo))
1597+
if (R.isInvalid() ||
1598+
Actions.CheckLoopHintExpr(R.get(), Toks[0].getLocation(),
1599+
/*AllowZero=*/true))
15991600
return false;
16001601

16011602
// Argument is a constant expression with an integer type.

clang/lib/Sema/SemaExpr.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3885,8 +3885,7 @@ static Expr *BuildFloatingLiteral(Sema &S, NumericLiteralParser &Literal,
38853885
return FloatingLiteral::Create(S.Context, Val, isExact, Ty, Loc);
38863886
}
38873887

3888-
bool Sema::CheckLoopHintExpr(Expr *E, SourceLocation Loc,
3889-
const IdentifierInfo *PragmaNameInfo) {
3888+
bool Sema::CheckLoopHintExpr(Expr *E, SourceLocation Loc, bool AllowZero) {
38903889
assert(E && "Invalid expression");
38913890

38923891
if (E->isValueDependent())
@@ -3909,9 +3908,8 @@ bool Sema::CheckLoopHintExpr(Expr *E, SourceLocation Loc,
39093908
// "The values of 0 and 1 block any unrolling of the loop."
39103909
// The values doesn't have to be strictly positive in '#pragma GCC unroll' and
39113910
// '#pragma unroll' cases.
3912-
bool ValueIsPositive = PragmaNameInfo->isStr("unroll")
3913-
? ValueAPS.isNonNegative()
3914-
: ValueAPS.isStrictlyPositive();
3911+
bool ValueIsPositive =
3912+
AllowZero ? ValueAPS.isNonNegative() : ValueAPS.isStrictlyPositive();
39153913
if (!ValueIsPositive || ValueAPS.getActiveBits() > 31) {
39163914
Diag(E->getExprLoc(), diag::err_pragma_loop_invalid_argument_value)
39173915
<< toString(ValueAPS, 10) << ValueIsPositive;

clang/lib/Sema/SemaStmtAttr.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ static Attr *handleLoopHintAttr(Sema &S, Stmt *St, const ParsedAttr &A,
150150
if (Option == LoopHintAttr::VectorizeWidth) {
151151
assert((ValueExpr || (StateLoc && StateLoc->Ident)) &&
152152
"Attribute must have a valid value expression or argument.");
153-
if (ValueExpr &&
154-
S.CheckLoopHintExpr(ValueExpr, St->getBeginLoc(), OptionLoc->Ident))
153+
if (ValueExpr && S.CheckLoopHintExpr(ValueExpr, St->getBeginLoc(),
154+
/*AllowZero=*/false))
155155
return nullptr;
156156
if (StateLoc && StateLoc->Ident && StateLoc->Ident->isStr("scalable"))
157157
State = LoopHintAttr::ScalableWidth;
@@ -161,7 +161,8 @@ static Attr *handleLoopHintAttr(Sema &S, Stmt *St, const ParsedAttr &A,
161161
Option == LoopHintAttr::UnrollCount ||
162162
Option == LoopHintAttr::PipelineInitiationInterval) {
163163
assert(ValueExpr && "Attribute must have a valid value expression.");
164-
if (S.CheckLoopHintExpr(ValueExpr, St->getBeginLoc(), OptionLoc->Ident))
164+
if (S.CheckLoopHintExpr(ValueExpr, St->getBeginLoc(),
165+
/*AllowZero=*/false))
165166
return nullptr;
166167
State = LoopHintAttr::Numeric;
167168
} else if (Option == LoopHintAttr::Vectorize ||

clang/lib/Sema/SemaTemplateInstantiate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2151,7 +2151,7 @@ TemplateInstantiator::TransformLoopHintAttr(const LoopHintAttr *LH) {
21512151

21522152
// Generate error if there is a problem with the value.
21532153
if (getSema().CheckLoopHintExpr(TransformedExpr, LH->getLocation(),
2154-
LH->getAttrName()))
2154+
LH->getOption() == LoopHintAttr::UnrollCount))
21552155
return LH;
21562156

21572157
// Create new LoopHintValueAttr with integral expression in place of the

0 commit comments

Comments
 (0)