# HG changeset patch # User Tomas Lindquist Olsen # Date 1249570363 -7200 # Node ID f1f33c8dcd900ae42f7221137d426c1d4dc05186 # Parent c03d164e96d99862adac53d1965c9fc27273e69b Added framework for writing a static printf call checker for bearophile to implement. diff -r c03d164e96d9 -r f1f33c8dcd90 gen/toir.cpp --- a/gen/toir.cpp Tue Aug 04 12:21:59 2009 +0200 +++ b/gen/toir.cpp Thu Aug 06 16:52:43 2009 +0200 @@ -11,6 +11,7 @@ #include #include "gen/llvm.h" +#include "llvm/Support/CommandLine.h" #include "attrib.h" #include "init.h" @@ -38,9 +39,14 @@ #include "gen/todebug.h" #include "gen/nested.h" #include "gen/utils.h" +#include "gen/warnings.h" #include "llvm/Support/ManagedStatic.h" +llvm::cl::opt checkPrintf("check-printf-calls", + llvm::cl::desc("Validate printf call format strings against arguments"), + llvm::cl::ZeroOrMore); + ////////////////////////////////////////////////////////////////////////////////////////// void Expression::cacheLvalue(IRState* irs) @@ -784,6 +790,16 @@ if (dfnval && dfnval->func) { FuncDeclaration* fndecl = dfnval->func; + + // as requested by bearophile, see if it's a C printf call and that it's valid. + if (global.params.warnings && checkPrintf) + { + if (fndecl->linkage == LINKc && strcmp(fndecl->ident->string, "printf") == 0) + { + warnInvalidPrintfCall(loc, (Expression*)arguments->data[0], arguments->dim); + } + } + // va_start instruction if (fndecl->llvmInternal == LLVMva_start) { // llvm doesn't need the second param hence the override