From 427d5c99b0408e4ca472b8a65d1fbd15261d7d1a Mon Sep 17 00:00:00 2001 From: Eli Bendersky Date: Thu, 19 Jun 2014 18:30:15 +0000 Subject: 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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@211292 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaStmtAttr.cpp | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) (limited to 'lib/Sema/SemaStmtAttr.cpp') diff --git a/lib/Sema/SemaStmtAttr.cpp b/lib/Sema/SemaStmtAttr.cpp index c0b5ede526..44169c2fdc 100644 --- a/lib/Sema/SemaStmtAttr.cpp +++ b/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 -- cgit v1.2.1