Mercurial > projects > ldc
changeset 1567:f1f33c8dcd90
Added framework for writing a static printf call checker for bearophile to implement.
author | Tomas Lindquist Olsen <tomas.l.olsen gmail com> |
---|---|
date | Thu, 06 Aug 2009 16:52:43 +0200 |
parents | c03d164e96d9 |
children | a591aa6bd6dc |
files | gen/toir.cpp |
diffstat | 1 files changed, 16 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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 <fstream> #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<bool> 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