A function that only references itself should issue a unused function warning:
Function Foo Call ${__FUNCTION__} FunctionEnd
Patch:
Index: Source/build.cpp =================================================================== --- Source/build.cpp (revision 6538) +++ Source/build.cpp (working copy) @@ -1458,7 +1458,7 @@ return 0; } -int CEXEBuild::resolve_call_int(const TCHAR *fn, const TCHAR *str, int fptr, int *ofs) +int CEXEBuild::resolve_call_int(const TCHAR *fn, const TCHAR *str, int fptr, int *ofs, section*caller) { if (fptr < 0) return 0; int nf=cur_functions->getlen()/sizeof(section); @@ -1468,7 +1468,8 @@ if (sec->name_ptr>0 && sec->name_ptr == fptr) { ofs[0]=sec->code; - sec->flags++; + if (caller != sec) // Don't increase refcount for "Call ${__FUNCTION__}" recursive functions + sec->flags++; return 0; } sec++; @@ -1477,8 +1478,12 @@ ERROR_MSG(_T("Note: uninstall functions must begin with \"un.\", and install functions must not\n")); return 1; } +int CEXEBuild::resolve_call_int(const TCHAR *fn, const TCHAR *str, int fptr, int *ofs) +{ + return resolve_call_int(fn, str, fptr, ofs, 0); +} -int CEXEBuild::resolve_instruction(const TCHAR *fn, const TCHAR *str, entry *w, int offs, int start, int end) +int CEXEBuild::resolve_instruction(const TCHAR *fn, const TCHAR *str, entry *w, int offs, int start, int end, section*caller) { if (w->which == EW_NOP) { @@ -1531,7 +1536,7 @@ } else { - if (w->offsets[0] >= 0 && resolve_call_int(fn,str,w->offsets[0],w->offsets)) return 1; + if (w->offsets[0] >= 0 && resolve_call_int(fn,str,w->offsets[0],w->offsets, caller)) return 1; // if w->offsets[0] >= 0, EW_CALL requires that it 1-based. // otherwise, if < 0, it needs an increment anyway (since it // was encoded with a -2 base, to prevent it looking like an @@ -1562,6 +1567,10 @@ #endif return 0; } +int CEXEBuild::resolve_instruction(const TCHAR *fn, const TCHAR *str, entry *w, int offs, int start, int end) +{ + return resolve_instruction(fn,str,w,offs,start,end,0); +} int CEXEBuild::resolve_coderefs(const TCHAR *str) { @@ -1577,7 +1586,7 @@ { TCHAR fname[1024]; wsprintf(fname,_T("function \"%") NPRIs _T("\""),ns_func.get()+sec->name_ptr); - if (resolve_instruction(fname,str,w+x,x,sec->code,sec->code+sec->code_size)) return 1; + if (resolve_instruction(fname,str,w+x,x,sec->code,sec->code+sec->code_size,sec)) return 1; } sec++; } Index: Source/build.h =================================================================== --- Source/build.h (revision 6541) +++ Source/build.h (working copy) @@ -298,7 +298,9 @@ int UpdatePEHeader(); int resolve_jump_int(const TCHAR *fn, int *a, int offs, int start, int end); + int resolve_call_int(const TCHAR *fn, const TCHAR *str, int fptr, int *ofs, section*caller); int resolve_call_int(const TCHAR *fn, const TCHAR *str, int fptr, int *ofs); + int resolve_instruction(const TCHAR *fn, const TCHAR *str, entry *w, int offs, int start, int end, section*caller); int resolve_instruction(const TCHAR *fn, const TCHAR *str, entry *w, int offs, int start, int end); int resolve_coderefs(const TCHAR *str);
I'm not sure if this is the best way to deal with this but dealing with it in TOK_CALL does not seem possible.