http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54224
--- Comment #5 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-08-16 09:56:51 UTC --- > c) For the program in comment 0, one enters rtx_for_function_call [...] > However, that function is called *AFTER* check_global_declaration_1 and comes > thus too late. check_global_declaration_1 is called write_global_declarations via compile_file via do_compile While rtx_for_function_call is later also called via write_global_declarations -> finalize_compilation_unit -> output_in_order -> expand_function -> execute_pass_list -> execute_one_pass -> ... -> expand_call_stmt -> ... In C, one has the same order - except that TREE_USED is already set. My impression is that in C it gets set when the DECL is 'created' in the caller. * * * Hence, I think one should think of handling it on Fortran FE level by setting USE_TREE. For procedures, I think we need to cover procedure calls, proc-pointer assignments and proc-pointer assignments via initializers and default initializers. On tree level, we could either plug into gfc_trans_pointer_assignment and conv_function_val - or make some use of attr.referenced (though, the latter seems to be also set for uncalled functions). Not as important as we do not currently get a bogus warning, but still nice to have: A warning for PRIVATE module variables. For module m private integer, save :: var ! = 5 end module m we always set TREE_USED in gfc_finish_var_decl. One could check whether simply not doing so for private variables is sufficient to get a warning, but I am not sure whether we won't run into the problem of getting the diagnostic in check_global_declaration_1 sym->referenced is always set: It is set before gfc_create_module_variable and it is unconditionally set in that function. (EQUIVALENCE with PRIVATE/PUBLIC has to be handled as well.)