From: Chris Lattner Date: Fri, 28 Dec 2007 05:38:24 +0000 (+0000) Subject: various cleanups. Use IgnoreParenCasts instead of inlined versions. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=998568f24d6665b8a9bf26b42a04e5f80d14668f;p=clang various cleanups. Use IgnoreParenCasts instead of inlined versions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45382 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Sema/SemaChecking.cpp b/Sema/SemaChecking.cpp index d7b8de2f15..29d4e79814 100644 --- a/Sema/SemaChecking.cpp +++ b/Sema/SemaChecking.cpp @@ -88,15 +88,7 @@ Sema::CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall) { /// CheckBuiltinCFStringArgument - Checks that the argument to the builtin /// CFString constructor is correct bool Sema::CheckBuiltinCFStringArgument(Expr* Arg) { - // FIXME: This should go in a helper. - while (1) { - if (ParenExpr *PE = dyn_cast(Arg)) - Arg = PE->getSubExpr(); - else if (ImplicitCastExpr *ICE = dyn_cast(Arg)) - Arg = ICE->getSubExpr(); - else - break; - } + Arg = IgnoreParenCasts(Arg); StringLiteral *Literal = dyn_cast(Arg); @@ -265,16 +257,7 @@ Sema::CheckPrintfArguments(CallExpr *TheCall, bool HasVAListArg, return; } - Expr *OrigFormatExpr = TheCall->getArg(format_idx); - // FIXME: This should go in a helper. - while (1) { - if (ParenExpr *PE = dyn_cast(OrigFormatExpr)) - OrigFormatExpr = PE->getSubExpr(); - else if (ImplicitCastExpr *ICE = dyn_cast(OrigFormatExpr)) - OrigFormatExpr = ICE->getSubExpr(); - else - break; - } + Expr *OrigFormatExpr = IgnoreParenCasts(TheCall->getArg(format_idx)); // CHECK: format string is not a string literal. // @@ -284,7 +267,6 @@ Sema::CheckPrintfArguments(CallExpr *TheCall, bool HasVAListArg, // the compiler and thereby (2) can practically remove the source of // many format string exploits. StringLiteral *FExpr = dyn_cast(OrigFormatExpr); - if (FExpr == NULL) { // For vprintf* functions (i.e., HasVAListArg==true), we add a // special check to see if the format string is a function parameter @@ -305,8 +287,8 @@ Sema::CheckPrintfArguments(CallExpr *TheCall, bool HasVAListArg, // if the argument is a DeclRefExpr that references a parameter. We'll // add proper support for checking the attribute later. if (HasVAListArg) - if (DeclRefExpr* DR = dyn_cast(IgnoreParen(OrigFormatExpr))) - if (isa(DR->getDecl())) + if (DeclRefExpr* DR = dyn_cast(OrigFormatExpr)) + if (isa(DR->getDecl())) return; Diag(TheCall->getArg(format_idx)->getLocStart(), @@ -358,7 +340,7 @@ Sema::CheckPrintfArguments(CallExpr *TheCall, bool HasVAListArg, unsigned LastConversionIdx = 0; for (; StrIdx < StrLen; ++StrIdx) { - + // Is the number of detected conversion conversions greater than // the number of matching data arguments? If so, stop. if (!HasVAListArg && numConversions > numDataArgs) break; @@ -367,10 +349,8 @@ Sema::CheckPrintfArguments(CallExpr *TheCall, bool HasVAListArg, if (Str[StrIdx] == '\0') { // The string returned by getStrData() is not null-terminated, // so the presence of a null character is likely an error. - SourceLocation Loc = FExpr->getLocStart(); - Loc = PP.AdvanceToTokenCharacter(Loc, StrIdx+1); - - Diag(Loc, diag::warn_printf_format_string_contains_null_char, + Diag(PP.AdvanceToTokenCharacter(FExpr->getLocStart(), StrIdx+1), + diag::warn_printf_format_string_contains_null_char, Fn->getSourceRange()); return; } @@ -391,7 +371,6 @@ Sema::CheckPrintfArguments(CallExpr *TheCall, bool HasVAListArg, ++numConversions; if (!HasVAListArg && numConversions > numDataArgs) { - SourceLocation Loc = FExpr->getLocStart(); Loc = PP.AdvanceToTokenCharacter(Loc, StrIdx+1); @@ -489,7 +468,6 @@ Sema::CheckPrintfArguments(CallExpr *TheCall, bool HasVAListArg, LastConversionIdx = StrIdx; ++numConversions; } - break; default: diff --git a/Sema/SemaUtil.h b/Sema/SemaUtil.h index 2932862e91..b167346fb4 100644 --- a/Sema/SemaUtil.h +++ b/Sema/SemaUtil.h @@ -38,10 +38,8 @@ static inline Expr* IgnoreParenCasts(Expr* E) { else if (ImplicitCastExpr* P = dyn_cast(E)) E = P->getSubExpr(); else - break; + return E; } - - return E; } /// Utility method to determine if a CallExpr is a call to a builtin.