Added framework for writing a static printf call checker for bearophile to implement.

This commit is contained in:
Tomas Lindquist Olsen
2009-08-06 16:52:43 +02:00
parent e05d3d8c3a
commit 84f820b442

View File

@@ -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 @@ DValue* CallExp::toElem(IRState* p)
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