[cfe-commits] r74369 - in /cfe/trunk: lib/Sema/SemaChecking.cpp test/Sema/attr-format_arg.c
Anders Carlsson
andersca at mac.com
Fri Jun 26 21:05:34 PDT 2009
Author: andersca
Date: Fri Jun 26 23:05:33 2009
New Revision: 74369
URL: http://llvm.org/viewvc/llvm-project?rev=74369&view=rev
Log:
Implement support for the format_arg attribute. Fixes PR4442.
Added:
cfe/trunk/test/Sema/attr-format_arg.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=74369&r1=74368&r2=74369&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Fri Jun 26 23:05:33 2009
@@ -717,6 +717,8 @@
if (E->isTypeDependent() || E->isValueDependent())
return false;
+ E = E->IgnoreParenCasts();
+
switch (E->getStmtClass()) {
case Stmt::ConditionalOperatorClass: {
const ConditionalOperator *C = cast<ConditionalOperator>(E);
@@ -766,6 +768,25 @@
return false;
}
+ case Stmt::CallExprClass: {
+ const CallExpr *CE = cast<CallExpr>(E);
+ if (const ImplicitCastExpr *ICE
+ = dyn_cast<ImplicitCastExpr>(CE->getCallee())) {
+ if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(ICE->getSubExpr())) {
+ if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(DRE->getDecl())) {
+ if (const FormatArgAttr *FA = FD->getAttr<FormatArgAttr>(Context)) {
+ unsigned ArgIndex = FA->getFormatIdx();
+ const Expr *Arg = CE->getArg(ArgIndex - 1);
+
+ return SemaCheckStringLiteral(Arg, TheCall, HasVAListArg,
+ format_idx, firstDataArg);
+ }
+ }
+ }
+ }
+
+ return false;
+ }
case Stmt::ObjCStringLiteralClass:
case Stmt::StringLiteralClass: {
const StringLiteral *StrE = NULL;
Added: cfe/trunk/test/Sema/attr-format_arg.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-format_arg.c?rev=74369&view=auto
==============================================================================
--- cfe/trunk/test/Sema/attr-format_arg.c (added)
+++ cfe/trunk/test/Sema/attr-format_arg.c Fri Jun 26 23:05:33 2009
@@ -0,0 +1,11 @@
+#include <stdio.h>
+
+const char* f(const char *s) __attribute__((format_arg(1)));
+
+void g(const char *s) {
+ printf("%d", 123);
+ printf("%d %d", 123); // expected-warning{{more '%' conversions than data arguments}}
+
+ printf(f("%d"), 123);
+ printf(f("%d %d"), 123); // expected-warning{{more '%' conversions than data arguments}}
+}
More information about the cfe-commits
mailing list