aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaChecking.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-04-29 04:49:34 +0000
committerChris Lattner <sabre@nondot.org>2009-04-29 04:49:34 +0000
commit1cd3e1f72c3a1c256fb6a5c3d4512bca1f1b751d (patch)
tree7bd69b613452116595403d9f87ae8d46f1ca5932 /lib/Sema/SemaChecking.cpp
parent8746414a93c2d7f73c1ae50a8d005de7ee0743d6 (diff)
code simplification, no functionality change.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70367 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaChecking.cpp')
-rw-r--r--lib/Sema/SemaChecking.cpp63
1 files changed, 30 insertions, 33 deletions
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp
index 7d54dc0c5f..d355ba4e99 100644
--- a/lib/Sema/SemaChecking.cpp
+++ b/lib/Sema/SemaChecking.cpp
@@ -577,39 +577,36 @@ Sema::CheckPrintfArguments(const CallExpr *TheCall, bool HasVAListArg,
// C string (e.g. "%d")
// ObjC string uses the same format specifiers as C string, so we can use
// the same format string checking logic for both ObjC and C strings.
- bool isFExpr = SemaCheckStringLiteral(OrigFormatExpr, TheCall,
- HasVAListArg, format_idx,
- firstDataArg);
-
- if (!isFExpr) {
- // For vprintf* functions (i.e., HasVAListArg==true), we add a
- // special check to see if the format string is a function parameter
- // of the function calling the printf function. If the function
- // has an attribute indicating it is a printf-like function, then we
- // should suppress warnings concerning non-literals being used in a call
- // to a vprintf function. For example:
- //
- // void
- // logmessage(char const *fmt __attribute__ (format (printf, 1, 2)), ...) {
- // va_list ap;
- // va_start(ap, fmt);
- // vprintf(fmt, ap); // Do NOT emit a warning about "fmt".
- // ...
- //
- //
- // FIXME: We don't have full attribute support yet, so just check to see
- // if the argument is a DeclRefExpr that references a parameter. We'll
- // add proper support for checking the attribute later.
- if (HasVAListArg)
- if (const DeclRefExpr* DR = dyn_cast<DeclRefExpr>(OrigFormatExpr))
- if (isa<ParmVarDecl>(DR->getDecl()))
- return;
-
- Diag(TheCall->getArg(format_idx)->getLocStart(),
- diag::warn_printf_not_string_constant)
- << OrigFormatExpr->getSourceRange();
- return;
- }
+ if (SemaCheckStringLiteral(OrigFormatExpr, TheCall, HasVAListArg, format_idx,
+ firstDataArg))
+ return; // Literal format string found, check done!
+
+ // For vprintf* functions (i.e., HasVAListArg==true), we add a
+ // special check to see if the format string is a function parameter
+ // of the function calling the printf function. If the function
+ // has an attribute indicating it is a printf-like function, then we
+ // should suppress warnings concerning non-literals being used in a call
+ // to a vprintf function. For example:
+ //
+ // void
+ // logmessage(char const *fmt __attribute__ (format (printf, 1, 2)), ...) {
+ // va_list ap;
+ // va_start(ap, fmt);
+ // vprintf(fmt, ap); // Do NOT emit a warning about "fmt".
+ // ...
+ //
+ //
+ // FIXME: We don't have full attribute support yet, so just check to see
+ // if the argument is a DeclRefExpr that references a parameter. We'll
+ // add proper support for checking the attribute later.
+ if (HasVAListArg)
+ if (const DeclRefExpr *DR = dyn_cast<DeclRefExpr>(OrigFormatExpr))
+ if (isa<ParmVarDecl>(DR->getDecl()))
+ return;
+
+ Diag(TheCall->getArg(format_idx)->getLocStart(),
+ diag::warn_printf_not_string_constant)
+ << OrigFormatExpr->getSourceRange();
}
void Sema::CheckPrintfString(const StringLiteral *FExpr,