This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Building GCC with -Wmissing-declarations and addressing its warnings


Hi everyone,

I noticed that the GCC build process currently only uses the
-Wmissing-prototypes flag, and not the -Wmissing-declarations flag.
It seems that the former flag only works on C source files, which
means that GCC's source files no longer benefit from this flag as they
are now  C++ files.  The right flag to use, in this case, is
-Wmissing-declarations, which works on both C and C++ source files.  I
decided to build GCC with this flag to see what kinds of warnings
popped up, and to use these warnings to clean up the GCC source.

I sifted through all the new warnings generated by
-Wmissing-declarations during the build process and fixed the ones
whose fixes were obvious.  Most of my fixes are on global (non-debug)
functions that are only referenced in the compilation unit in which
they are defined.  To fix these functions and to silence their
warnings I have simply gave them static linkage.  The rest of the
fixes are on global function definitions whose declaration exists in a
header file that was not included by the source file.  To fix up these
functions I simply included the relevant header file.

The -Wmissing-declarations warnings that I did _not_ address are those
emitted from the autogenerated gengtype header files, because their
fixes are not trivial to me.  They look like:

In file included from ../../gcc/gcc/c/c-parser.c:14162:0:
./gt-c-c-parser.h: In function 'void gt_ggc_mx(c_token&)':
./gt-c-c-parser.h:50:1: warning: no previous declaration for 'void
gt_ggc_mx(c_token&)' [-Wmissing-declarations]
 gt_ggc_mx (struct c_token& x_r ATTRIBUTE_UNUSED)

I have also not addressed some of such warnings in predict.c and
config/i386/i386.c because their fixes are not trivial to me either.
Furthermore, I was not able to mark "static" any function that was
used as a template argument to hash_table::traverse<Type, Callback>()
because it seems that C++98 requires template argument pointers to
have external linkage.  (The C++11 standard relaxes this restriction,
it seems.)  The file var-tracking.c has many of such functions.

Since I do not yet have a copyright assignment filed for GCC, I have
omitted an actual code patch and instead provide you with a changelog
that could be used to reconstruct the patch 100% if anyone is so
inclined.  Once my copyright assignment is filed, I will properly
submit this patch if it is not yet done so by somebody else.

On a related note, would a patch to officially enable
-Wmissing-declarations in the build process be well regarded?  Since
-Wmissing-prototypes is currently enabled, I assume it is the
intention of the GCC devs to address these warnings, and that during
the transition from a C to C++ bootstrap compiler a small oversight
was made (that -Wmissing-prototypes is a no-op against C++ source
files).  If the answer to the previous question is "yes" then how
would one go about addressing the above gengtype-related warnings, if
at all?

Thanks for your time,
Patrick

        * asan.c (asan_mem_ref_get_end): Make static.
        * calls.c: Include calls.h.
        * cfgexpand.c: Include cfgexpand.h.
        * cfgloop.c: Include tree-ssa-loop-niter.h.
        * cfgraphunit.c (decide_is_symbol_needed): Make static.
        * config/i386/i386.c (make_pass_insert_vzeroupper): Likewise.
        (ix86_avx_emit_vzeroupper): Likewise.
        * dwarf2out.c (init_addr_table_entry): Likewise.
        * gimple-builder.c: Include gimple-builder.h.
        * gimple-ssa-isolate-paths.c (isolate_path): Make static.
        * graphite.c (graphite_transform_loops): Likewise.
        * internal-fn.c (ubsan_expand_si_overflow_addsub_check): Make
        static.
        (ubsan_expand_si_overflow_neg_check): Likewise.
        (ubsan_expand_si_overflow_mul_check): Likewise.
        * ipa-devirt.c (hash_type_name): Likewise.
        (likely_target_p): Likewise.
        * ipa-inline-analysis.c (simple_edge_hints): Likewise.
        * ipa-profile.c (cmp_counts): Likewise.
        (contains_hot_call_p): Likewise.
        * ipa-prop.c (ipa_alloc_node_params): Likewise.
        (write_agg_replacement_chain): Likewise.
        * ipa.c (can_replace_by_local_alias): Likewise.
        * lto-streamer-out.c (output_symbol_p): Likewise.
        * omp-low.c (simd_clone_vector_of_formal_parm_types): Likewise.
        * print-tree.c: Include print-tree.h.
        * stmt.c: Include stmt.h.
        * stringpool.c: Include stringpool.h.
        * tree-cfg-cleanup.c: Include tree-cfg-cleanup.h.
        * tree-inline.c (redirect_all_calls): Make static.
        (freqs_to_count): Likewise.
        * tree-nested.c: Include tree-nested.h.
        * tree-predcom.c (tree_predictive_commoning): Make static.
        * tree-sra.c (ipa_sra_modify_function_body): Likewise.
        * tree-ssa-loop-im.c (movement_possibility): Likewise.
        (tree_ssa_lim): Likewise.
        * tree-ssa-loop-ivcanon.c (canonicalize_induction_variables):
        Likewise.
        (tree_unroll_loops_completely): Likewise.
        * tree-ssa-loop-prefetch.c (tree_ssa_prefetch_arrays):
        Likewise.
        * tree-ssa-loop-unswitch.c (tree_ssa_unswitch_loops): Likewise.
        * tree-ssa-threadupdate.c (ssa_fix_duplicate_block_edges):
        Likewise.
        * tree-vect-loop-manip.c (vect_create_cond_for_alias_checks):
        Likewise.
        * ubsan.c (tree_type_map_hash): Likewise.
        * varpool.c (varpool_call_variable_insertion_hooks): Likewise.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]