|
From: David Y. <dav...@in...> - 2011-05-06 16:04:10
|
This patch makes cli-be to automatically fix some missing prototypes that can be found in old style C code (unfortunately, it is very common in SPEC).
It applies when there is no explicit prototype, but DECL_ARGUMENTS still holds the actual list of arguments. This is the case of the following declaration:
void foo (arg)
double arg;
{ }
// Somewhere below
foo (10); --> guessed as 'int foo (int)'
In this situations, we restore the prototype from the function definition. That is, we update TREE_TYPE of the corresponding function with a new type description built from the actual function definition. (Note that in absence of prototype, TYPE_ARG_TYPES (TREE_TYPE (func)) is null)
The changes are in:
missing-protos.c:
The function 'fix_missing_prototype()' is implemented here. This function performs the actual work.
The already existing pass missing_protos is also implemented in this file. I don't really understand what this pass is doing, or even if it can conflict with my proposal (does any one know?).
I just chose this file because the name suggest a good emplacement for the new function, even if this pass is doing something very different.
gimple-to-cil.c:
gimple_to_cil() -> Fix current_function_decl prototype if applies (some times it does).
gen_call_expr() -> Fix callee prototype.
-- Some "name resolution" errors are avoided
-- The arguments are properly cast (when necessary)
emit-cil.c:
dump_fun_type() -> fix the prototype of the function being dumped.
-- Some "name resolution" errors are avoided
I hope to do not introduce any side effect as consequence of this patch. I already did many tests, if somebody finds something weird, please tell me.
David
|