[cfe-commits] r74413 - in /cfe/trunk: lib/Sema/SemaChecking.cpp test/Sema/format-attr-pr4470.c
Anders Carlsson
andersca at mac.com
Sun Jun 28 12:55:59 PDT 2009
Author: andersca
Date: Sun Jun 28 14:55:58 2009
New Revision: 74413
URL: http://llvm.org/viewvc/llvm-project?rev=74413&view=rev
Log:
Move the check for vprintf* functions inside of SemaCheckStringLiteral. Fixes PR4470.
Added:
cfe/trunk/test/Sema/format-attr-pr4470.c
Modified:
cfe/trunk/lib/Sema/SemaChecking.cpp
Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=74413&r1=74412&r2=74413&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Sun Jun 28 14:55:58 2009
@@ -717,8 +717,6 @@
if (E->isTypeDependent() || E->isValueDependent())
return false;
- E = E->IgnoreParenCasts();
-
switch (E->getStmtClass()) {
case Stmt::ConditionalOperatorClass: {
const ConditionalOperator *C = cast<ConditionalOperator>(E);
@@ -763,6 +761,28 @@
return SemaCheckStringLiteral(Init, TheCall,
HasVAListArg, format_idx, firstDataArg);
}
+
+ // 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 (isa<ParmVarDecl>(VD))
+ return true;
}
return false;
@@ -901,29 +921,6 @@
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;
-
// If there are no arguments specified, warn with -Wformat-security, otherwise
// warn only with -Wformat-nonliteral.
if (TheCall->getNumArgs() == format_idx+1)
Added: cfe/trunk/test/Sema/format-attr-pr4470.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/format-attr-pr4470.c?rev=74413&view=auto
==============================================================================
--- cfe/trunk/test/Sema/format-attr-pr4470.c (added)
+++ cfe/trunk/test/Sema/format-attr-pr4470.c Sun Jun 28 14:55:58 2009
@@ -0,0 +1,11 @@
+// RUN: clang-cc -fsyntax-only -verify -Wformat=2 %s
+
+#include <stdio.h>
+
+const char *foo(const char *format) __attribute__((format_arg(1)));
+
+void __attribute__((format(printf, 1, 0)))
+foo2(const char *fmt, va_list va)
+{
+ vprintf(foo(fmt), va);
+}
More information about the cfe-commits
mailing list