From: Andy Gibbs Date: Mon, 22 Feb 2016 13:00:43 +0000 (+0000) Subject: Make Sema::CheckFormatString a static function inside SemaChecking.cpp X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=325b74973baa2e867990cb9bc19cc0db7a9343a9;p=clang Make Sema::CheckFormatString a static function inside SemaChecking.cpp No functionality change. Change at the request of Richard Trieu, see http://reviews.llvm.org/D15636#357858. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@261522 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index bfba7b11ef..9d733ca032 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -9111,13 +9111,6 @@ public: }; static FormatStringType GetFormatStringType(const FormatAttr *Format); - void CheckFormatString(const StringLiteral *FExpr, const Expr *OrigFormatExpr, - ArrayRef Args, bool HasVAListArg, - unsigned format_idx, unsigned firstDataArg, - FormatStringType Type, bool inFunctionCall, - VariadicCallType CallType, - llvm::SmallBitVector &CheckedVarArgs); - bool FormatStringHasSArg(const StringLiteral *FExpr); static bool GetFormatNSStringIdx(const FormatAttr *Format, unsigned &Idx); diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index 4a9df07bc4..a1f975a826 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -3265,6 +3265,16 @@ enum StringLiteralCheckType { }; } // end anonymous namespace +static void CheckFormatString(Sema &S, const StringLiteral *FExpr, + const Expr *OrigFormatExpr, + ArrayRef Args, + bool HasVAListArg, unsigned format_idx, + unsigned firstDataArg, + Sema::FormatStringType Type, + bool inFunctionCall, + Sema::VariadicCallType CallType, + llvm::SmallBitVector &CheckedVarArgs); + // Determine if an expression is a string literal or constant string. // If this function returns false on the arguments to a function expecting a // format string, we will usually need to emit a warning. @@ -3437,8 +3447,9 @@ checkFormatStringExpr(Sema &S, const Expr *E, ArrayRef Args, StrE = cast(E); if (StrE) { - S.CheckFormatString(StrE, E, Args, HasVAListArg, format_idx, firstDataArg, - Type, InFunctionCall, CallType, CheckedVarArgs); + CheckFormatString(S, StrE, E, Args, HasVAListArg, format_idx, + firstDataArg, Type, InFunctionCall, CallType, + CheckedVarArgs); return SLCT_CheckedLiteral; } @@ -4906,27 +4917,30 @@ bool CheckScanfHandler::HandleScanfSpecifier( return true; } -void Sema::CheckFormatString(const StringLiteral *FExpr, - const Expr *OrigFormatExpr, - ArrayRef Args, - bool HasVAListArg, unsigned format_idx, - unsigned firstDataArg, FormatStringType Type, - bool inFunctionCall, VariadicCallType CallType, - llvm::SmallBitVector &CheckedVarArgs) { +static void CheckFormatString(Sema &S, const StringLiteral *FExpr, + const Expr *OrigFormatExpr, + ArrayRef Args, + bool HasVAListArg, unsigned format_idx, + unsigned firstDataArg, + Sema::FormatStringType Type, + bool inFunctionCall, + Sema::VariadicCallType CallType, + llvm::SmallBitVector &CheckedVarArgs) { // CHECK: is the format string a wide literal? if (!FExpr->isAscii() && !FExpr->isUTF8()) { CheckFormatHandler::EmitFormatDiagnostic( - *this, inFunctionCall, Args[format_idx], - PDiag(diag::warn_format_string_is_wide_literal), FExpr->getLocStart(), + S, inFunctionCall, Args[format_idx], + S.PDiag(diag::warn_format_string_is_wide_literal), FExpr->getLocStart(), /*IsStringLocation*/true, OrigFormatExpr->getSourceRange()); return; } - + // Str - The format string. NOTE: this is NOT null-terminated! StringRef StrRef = FExpr->getString(); const char *Str = StrRef.data(); // Account for cases where the string literal is truncated in a declaration. - const ConstantArrayType *T = Context.getAsConstantArrayType(FExpr->getType()); + const ConstantArrayType *T = + S.Context.getAsConstantArrayType(FExpr->getType()); assert(T && "String literal not of constant array type!"); size_t TypeSize = T->getSize().getZExtValue(); size_t StrLen = std::min(std::max(TypeSize, size_t(1)) - 1, StrRef.size()); @@ -4937,8 +4951,8 @@ void Sema::CheckFormatString(const StringLiteral *FExpr, if (TypeSize <= StrRef.size() && StrRef.substr(0, TypeSize).find('\0') == StringRef::npos) { CheckFormatHandler::EmitFormatDiagnostic( - *this, inFunctionCall, Args[format_idx], - PDiag(diag::warn_printf_format_string_not_null_terminated), + S, inFunctionCall, Args[format_idx], + S.PDiag(diag::warn_printf_format_string_not_null_terminated), FExpr->getLocStart(), /*IsStringLocation=*/true, OrigFormatExpr->getSourceRange()); return; @@ -4947,32 +4961,33 @@ void Sema::CheckFormatString(const StringLiteral *FExpr, // CHECK: empty format string? if (StrLen == 0 && numDataArgs > 0) { CheckFormatHandler::EmitFormatDiagnostic( - *this, inFunctionCall, Args[format_idx], - PDiag(diag::warn_empty_format_string), FExpr->getLocStart(), + S, inFunctionCall, Args[format_idx], + S.PDiag(diag::warn_empty_format_string), FExpr->getLocStart(), /*IsStringLocation*/true, OrigFormatExpr->getSourceRange()); return; } - - if (Type == FST_Printf || Type == FST_NSString || - Type == FST_FreeBSDKPrintf || Type == FST_OSTrace) { - CheckPrintfHandler H(*this, FExpr, OrigFormatExpr, firstDataArg, - numDataArgs, (Type == FST_NSString || Type == FST_OSTrace), + + if (Type == Sema::FST_Printf || Type == Sema::FST_NSString || + Type == Sema::FST_FreeBSDKPrintf || Type == Sema::FST_OSTrace) { + CheckPrintfHandler H(S, FExpr, OrigFormatExpr, firstDataArg, + numDataArgs, (Type == Sema::FST_NSString || + Type == Sema::FST_OSTrace), Str, HasVAListArg, Args, format_idx, inFunctionCall, CallType, CheckedVarArgs); - + if (!analyze_format_string::ParsePrintfString(H, Str, Str + StrLen, - getLangOpts(), - Context.getTargetInfo(), - Type == FST_FreeBSDKPrintf)) + S.getLangOpts(), + S.Context.getTargetInfo(), + Type == Sema::FST_FreeBSDKPrintf)) H.DoneProcessing(); - } else if (Type == FST_Scanf) { - CheckScanfHandler H(*this, FExpr, OrigFormatExpr, firstDataArg, numDataArgs, + } else if (Type == Sema::FST_Scanf) { + CheckScanfHandler H(S, FExpr, OrigFormatExpr, firstDataArg, numDataArgs, Str, HasVAListArg, Args, format_idx, inFunctionCall, CallType, CheckedVarArgs); - + if (!analyze_format_string::ParseScanfString(H, Str, Str + StrLen, - getLangOpts(), - Context.getTargetInfo())) + S.getLangOpts(), + S.Context.getTargetInfo())) H.DoneProcessing(); } // TODO: handle other formats }