summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaStmtAttr.cpp
diff options
context:
space:
mode:
authorEli Bendersky <eliben@google.com>2014-06-19 18:30:15 +0000
committerEli Bendersky <eliben@google.com>2014-06-19 18:30:15 +0000
commitf637790102ea414da2c43fb1c5f6d2aab9d354c7 (patch)
treea84bb08d3c9e98265e3b37bfa209f5ed265649c4 /clang/lib/Sema/SemaStmtAttr.cpp
parentdf4d5efc7c70b902d2b2083fcdbc37f44ef81c4e (diff)
downloadbcm5719-llvm-f637790102ea414da2c43fb1c5f6d2aab9d354c7.tar.gz
bcm5719-llvm-f637790102ea414da2c43fb1c5f6d2aab9d354c7.zip
Fix PR20069: bad loop pragma arguments crash FE
This patch fixes a crash when handling malformed arguments to loop pragmas such as: "#pragma clang loop vectorize(()". Essentially any argument which is not an identifier or constant resulted in a crash. This patch also changes a couple of the error messages which weren't quite correct. New behavior with this patch vs old behavior: #pragma clang loop vectorize(1) OLD: error: missing keyword; expected 'enable' or 'disable' NEW: error: invalid argument; expected 'enable' or 'disable' #pragma clang loop vectorize() OLD: error: expected ')' NEW: error: missing argument to loop pragma 'vectorize' #pragma clang loop vectorize_width(bad) OLD: error: missing value; expected a positive integer value NEW: error: invalid argument; expected a positive integer value #pragma clang loop vectorize(bad) OLD: invalid keyword 'bad'; expected 'enable' or 'disable' NEW: error: invalid argument; expected 'enable' or 'disable' http://reviews.llvm.org/D4197 Patch by Mark Heffernan llvm-svn: 211292
Diffstat (limited to 'clang/lib/Sema/SemaStmtAttr.cpp')
-rw-r--r--clang/lib/Sema/SemaStmtAttr.cpp19
1 files changed, 5 insertions, 14 deletions
diff --git a/clang/lib/Sema/SemaStmtAttr.cpp b/clang/lib/Sema/SemaStmtAttr.cpp
index c0b5ede526c..44169c2fdce 100644
--- a/clang/lib/Sema/SemaStmtAttr.cpp
+++ b/clang/lib/Sema/SemaStmtAttr.cpp
@@ -75,18 +75,15 @@ static Attr *handleLoopHintAttr(Sema &S, Stmt *St, const AttributeList &A,
if (Option == LoopHintAttr::Vectorize || Option == LoopHintAttr::Interleave ||
Option == LoopHintAttr::Unroll) {
if (!ValueInfo) {
- S.Diag(ValueLoc->Loc, diag::err_pragma_loop_invalid_keyword)
- << /*MissingKeyword=*/true << "";
+ S.Diag(ValueLoc->Loc, diag::err_pragma_loop_invalid_keyword);
return nullptr;
}
-
if (ValueInfo->isStr("disable"))
ValueInt = 0;
else if (ValueInfo->isStr("enable"))
ValueInt = 1;
else {
- S.Diag(ValueLoc->Loc, diag::err_pragma_loop_invalid_keyword)
- << /*MissingKeyword=*/false << ValueInfo;
+ S.Diag(ValueLoc->Loc, diag::err_pragma_loop_invalid_keyword);
return nullptr;
}
} else if (Option == LoopHintAttr::VectorizeWidth ||
@@ -95,15 +92,9 @@ static Attr *handleLoopHintAttr(Sema &S, Stmt *St, const AttributeList &A,
// FIXME: We should support template parameters for the loop hint value.
// See bug report #19610.
llvm::APSInt ValueAPS;
- if (!ValueExpr || !ValueExpr->isIntegerConstantExpr(ValueAPS, S.Context)) {
- S.Diag(ValueLoc->Loc, diag::err_pragma_loop_invalid_value)
- << /*MissingValue=*/true << "";
- return nullptr;
- }
-
- if ((ValueInt = ValueAPS.getSExtValue()) < 1) {
- S.Diag(ValueLoc->Loc, diag::err_pragma_loop_invalid_value)
- << /*MissingValue=*/false << ValueInt;
+ if (!ValueExpr || !ValueExpr->isIntegerConstantExpr(ValueAPS, S.Context) ||
+ (ValueInt = ValueAPS.getSExtValue()) < 1) {
+ S.Diag(ValueLoc->Loc, diag::err_pragma_loop_invalid_value);
return nullptr;
}
} else
OpenPOWER on IntegriCloud