From 1cd3e1f72c3a1c256fb6a5c3d4512bca1f1b751d Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 29 Apr 2009 04:49:34 +0000 Subject: [PATCH] code simplification, no functionality change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70367 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaChecking.cpp | 63 +++++++++++++++++++-------------------- 1 file 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(OrigFormatExpr)) - if (isa(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(OrigFormatExpr)) + if (isa(DR->getDecl())) + return; + + Diag(TheCall->getArg(format_idx)->getLocStart(), + diag::warn_printf_not_string_constant) + << OrigFormatExpr->getSourceRange(); } void Sema::CheckPrintfString(const StringLiteral *FExpr, -- 2.40.0