comparison gen/toir.cpp @ 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 1d5c3354b3c2
children 755abafbf25d
comparison
equal deleted inserted replaced
1566:c03d164e96d9 1567:f1f33c8dcd90
9 #include <stdio.h> 9 #include <stdio.h>
10 #include <math.h> 10 #include <math.h>
11 #include <fstream> 11 #include <fstream>
12 12
13 #include "gen/llvm.h" 13 #include "gen/llvm.h"
14 #include "llvm/Support/CommandLine.h"
14 15
15 #include "attrib.h" 16 #include "attrib.h"
16 #include "init.h" 17 #include "init.h"
17 #include "mtype.h" 18 #include "mtype.h"
18 #include "template.h" 19 #include "template.h"
36 #include "gen/aa.h" 37 #include "gen/aa.h"
37 #include "gen/functions.h" 38 #include "gen/functions.h"
38 #include "gen/todebug.h" 39 #include "gen/todebug.h"
39 #include "gen/nested.h" 40 #include "gen/nested.h"
40 #include "gen/utils.h" 41 #include "gen/utils.h"
42 #include "gen/warnings.h"
41 43
42 #include "llvm/Support/ManagedStatic.h" 44 #include "llvm/Support/ManagedStatic.h"
45
46 llvm::cl::opt<bool> checkPrintf("check-printf-calls",
47 llvm::cl::desc("Validate printf call format strings against arguments"),
48 llvm::cl::ZeroOrMore);
43 49
44 ////////////////////////////////////////////////////////////////////////////////////////// 50 //////////////////////////////////////////////////////////////////////////////////////////
45 51
46 void Expression::cacheLvalue(IRState* irs) 52 void Expression::cacheLvalue(IRState* irs)
47 { 53 {
782 // handle magic intrinsics (mapping to instructions) 788 // handle magic intrinsics (mapping to instructions)
783 bool va_intrinsic = false; 789 bool va_intrinsic = false;
784 if (dfnval && dfnval->func) 790 if (dfnval && dfnval->func)
785 { 791 {
786 FuncDeclaration* fndecl = dfnval->func; 792 FuncDeclaration* fndecl = dfnval->func;
793
794 // as requested by bearophile, see if it's a C printf call and that it's valid.
795 if (global.params.warnings && checkPrintf)
796 {
797 if (fndecl->linkage == LINKc && strcmp(fndecl->ident->string, "printf") == 0)
798 {
799 warnInvalidPrintfCall(loc, (Expression*)arguments->data[0], arguments->dim);
800 }
801 }
802
787 // va_start instruction 803 // va_start instruction
788 if (fndecl->llvmInternal == LLVMva_start) { 804 if (fndecl->llvmInternal == LLVMva_start) {
789 // llvm doesn't need the second param hence the override 805 // llvm doesn't need the second param hence the override
790 Expression* exp = (Expression*)arguments->data[0]; 806 Expression* exp = (Expression*)arguments->data[0];
791 DValue* expv = exp->toElem(p); 807 DValue* expv = exp->toElem(p);