aboutsummaryrefslogtreecommitdiff
path: root/Sema/SemaChecking.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-12-28 05:38:24 +0000
committerChris Lattner <sabre@nondot.org>2007-12-28 05:38:24 +0000
commit998568f24d6665b8a9bf26b42a04e5f80d14668f (patch)
treeccff792e443c0c5bdf9dcc2281ebbce73395b50e /Sema/SemaChecking.cpp
parentfae3f1f6565c74d3238747b58357a6e56fbb0e9c (diff)
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
Diffstat (limited to 'Sema/SemaChecking.cpp')
-rw-r--r--Sema/SemaChecking.cpp36
1 files changed, 7 insertions, 29 deletions
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<ParenExpr>(Arg))
- Arg = PE->getSubExpr();
- else if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Arg))
- Arg = ICE->getSubExpr();
- else
- break;
- }
+ Arg = IgnoreParenCasts(Arg);
StringLiteral *Literal = dyn_cast<StringLiteral>(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<ParenExpr>(OrigFormatExpr))
- OrigFormatExpr = PE->getSubExpr();
- else if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(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<StringLiteral>(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<DeclRefExpr>(IgnoreParen(OrigFormatExpr)))
- if (isa<ParmVarDecl>(DR->getDecl()))
+ if (DeclRefExpr* DR = dyn_cast<DeclRefExpr>(OrigFormatExpr))
+ if (isa<ParmVarDecl>(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: