From 6ba3079dce89d9b63bf5dbd5e320ea2bf96f196b Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Wed, 17 Mar 2021 16:36:44 +0100 Subject: Come up with startswith function. gcc/ada/ChangeLog: * gcc-interface/utils.c (def_builtin_1): Use startswith function instead of strncmp. gcc/analyzer/ChangeLog: * sm-file.cc (is_file_using_fn_p): Use startswith function instead of strncmp. gcc/ChangeLog: * builtins.c (is_builtin_name): Use startswith function instead of strncmp. * collect2.c (main): Likewise. (has_lto_section): Likewise. (scan_libraries): Likewise. * coverage.c (coverage_checksum_string): Likewise. (coverage_init): Likewise. * dwarf2out.c (is_cxx): Likewise. (gen_compile_unit_die): Likewise. * gcc-ar.c (main): Likewise. * gcc.c (init_spec): Likewise. (read_specs): Likewise. (execute): Likewise. (check_live_switch): Likewise. * genattrtab.c (write_attr_case): Likewise. (IS_ATTR_GROUP): Likewise. * gencfn-macros.c (main): Likewise. * gengtype.c (type_for_name): Likewise. (gen_rtx_next): Likewise. (get_file_langdir): Likewise. (write_local): Likewise. * genmatch.c (get_operator): Likewise. (get_operand_type): Likewise. (expr::gen_transform): Likewise. * genoutput.c (validate_optab_operands): Likewise. * incpath.c (add_sysroot_to_chain): Likewise. * langhooks.c (lang_GNU_C): Likewise. (lang_GNU_CXX): Likewise. (lang_GNU_Fortran): Likewise. (lang_GNU_OBJC): Likewise. * lto-wrapper.c (run_gcc): Likewise. * omp-general.c (omp_max_simt_vf): Likewise. * omp-low.c (omp_runtime_api_call): Likewise. * opts-common.c (parse_options_from_collect_gcc_options): Likewise. * read-rtl-function.c (function_reader::read_rtx_operand_r): Likewise. * real.c (real_from_string): Likewise. * selftest.c (assert_str_startswith): Likewise. * timevar.c (timer::validate_phases): Likewise. * tree.c (get_file_function_name): Likewise. * ubsan.c (ubsan_use_new_style_p): Likewise. * varasm.c (default_function_rodata_section): Likewise. (incorporeal_function_p): Likewise. (default_section_type_flags): Likewise. * system.h (startswith): Define startswith. gcc/c-family/ChangeLog: * c-ada-spec.c (print_destructor): Use startswith function instead of strncmp. (dump_ada_declaration): Likewise. * c-common.c (disable_builtin_function): Likewise. (def_builtin_1): Likewise. * c-format.c (check_tokens): Likewise. (check_plain): Likewise. (convert_format_name_to_system_name): Likewise. gcc/c/ChangeLog: * c-aux-info.c (affix_data_type): Use startswith function instead of strncmp. * c-typeck.c (build_function_call_vec): Likewise. * gimple-parser.c (c_parser_gimple_parse_bb_spec): Likewise. gcc/cp/ChangeLog: * decl.c (duplicate_decls): Use startswith function instead of strncmp. (cxx_builtin_function): Likewise. (omp_declare_variant_finalize_one): Likewise. (grokfndecl): Likewise. * error.c (dump_decl_name): Likewise. * mangle.c (find_decomp_unqualified_name): Likewise. (write_guarded_var_name): Likewise. (decl_tls_wrapper_p): Likewise. * parser.c (cp_parser_simple_type_specifier): Likewise. (cp_parser_tx_qualifier_opt): Likewise. * pt.c (template_parm_object_p): Likewise. (dguide_name_p): Likewise. gcc/d/ChangeLog: * d-builtins.cc (do_build_builtin_fn): Use startswith function instead of strncmp. * dmd/dinterpret.c (evaluateIfBuiltin): Likewise. * dmd/dmangle.c: Likewise. * dmd/hdrgen.c: Likewise. * dmd/identifier.c (Identifier::toHChars2): Likewise. gcc/fortran/ChangeLog: * decl.c (variable_decl): Use startswith function instead of strncmp. (gfc_match_end): Likewise. * gfortran.h (gfc_str_startswith): Likewise. * module.c (load_omp_udrs): Likewise. (read_module): Likewise. * options.c (gfc_handle_runtime_check_option): Likewise. * primary.c (match_arg_list_function): Likewise. * trans-decl.c (gfc_get_symbol_decl): Likewise. * trans-expr.c (gfc_conv_procedure_call): Likewise. * trans-intrinsic.c (gfc_conv_ieee_arithmetic_function): Likewise. gcc/go/ChangeLog: * gofrontend/runtime.cc (Runtime::name_to_code): Use startswith function instead of strncmp. gcc/objc/ChangeLog: * objc-act.c (objc_string_ref_type_p): Use startswith function instead of strncmp. * objc-encoding.c (encode_type): Likewise. * objc-next-runtime-abi-02.c (has_load_impl): Likewise. --- gcc/coverage.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'gcc/coverage.c') diff --git a/gcc/coverage.c b/gcc/coverage.c index dc9ea6f..5a344cd 100644 --- a/gcc/coverage.c +++ b/gcc/coverage.c @@ -488,9 +488,9 @@ coverage_checksum_string (unsigned chksum, const char *string) for (i = 0; string[i]; i++) { int offset = 0; - if (!strncmp (string + i, "_GLOBAL__N_", 11)) + if (startswith (string + i, "_GLOBAL__N_")) offset = 11; - if (!strncmp (string + i, "_GLOBAL__", 9)) + if (startswith (string + i, "_GLOBAL__")) offset = 9; /* C++ namespaces do have scheme: @@ -1256,8 +1256,7 @@ coverage_init (const char *filename) filename = concat (getpwd (), separator, filename, NULL); if (profile_prefix_path) { - if (!strncmp (filename, profile_prefix_path, - strlen (profile_prefix_path))) + if (startswith (filename, profile_prefix_path)) { filename += strlen (profile_prefix_path); while (*filename == *separator) -- cgit v1.1 From 8bf728aecc4fea46b4490e950b9ae229f90597b0 Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Tue, 1 Jun 2021 15:13:18 +0200 Subject: Introduce -Wcoverage-invalid-line-number PR gcov-profile/100788 gcc/ChangeLog: * common.opt: Add new option. * coverage.c (coverage_begin_function): Emit warning instead on the internal compiler error. * doc/invoke.texi: Document the option. * toplev.c (process_options): Enable it by default. gcc/testsuite/ChangeLog: * gcc.dg/pr100788.c: New test. --- gcc/coverage.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) (limited to 'gcc/coverage.c') diff --git a/gcc/coverage.c b/gcc/coverage.c index 5a344cd..dfc8108 100644 --- a/gcc/coverage.c +++ b/gcc/coverage.c @@ -622,18 +622,16 @@ coverage_compute_cfg_checksum (struct function *fn) int coverage_begin_function (unsigned lineno_checksum, unsigned cfg_checksum) { - expanded_location xloc; - unsigned long offset; - /* We don't need to output .gcno file unless we're under -ftest-coverage (e.g. -fprofile-arcs/generate/use don't need .gcno to work). */ if (no_coverage || !bbg_file_name) return 0; - xloc = expand_location (DECL_SOURCE_LOCATION (current_function_decl)); + expanded_location startloc + = expand_location (DECL_SOURCE_LOCATION (current_function_decl)); /* Announce function */ - offset = gcov_write_tag (GCOV_TAG_FUNCTION); + unsigned long offset = gcov_write_tag (GCOV_TAG_FUNCTION); if (param_profile_func_internal_id) gcov_write_unsigned (current_function_funcdef_no + 1); else @@ -650,16 +648,27 @@ coverage_begin_function (unsigned lineno_checksum, unsigned cfg_checksum) gcov_write_unsigned (DECL_ARTIFICIAL (current_function_decl) && !DECL_FUNCTION_VERSIONED (current_function_decl) && !DECL_LAMBDA_FUNCTION_P (current_function_decl)); - gcov_write_filename (xloc.file); - gcov_write_unsigned (xloc.line); - gcov_write_unsigned (xloc.column); + gcov_write_filename (startloc.file); + gcov_write_unsigned (startloc.line); + gcov_write_unsigned (startloc.column); expanded_location endloc = expand_location (cfun->function_end_locus); /* Function can start in a single file and end in another one. */ - int end_line = endloc.file == xloc.file ? endloc.line : xloc.line; - int end_column = endloc.file == xloc.file ? endloc.column: xloc.column; - gcc_assert (xloc.line <= end_line); + int end_line + = endloc.file == startloc.file ? endloc.line : startloc.line; + int end_column + = endloc.file == startloc.file ? endloc.column: startloc.column; + + if (startloc.line > end_line) + { + warning_at (DECL_SOURCE_LOCATION (current_function_decl), + OPT_Wcoverage_invalid_line_number, + "function starts on a higher line number than it ends"); + end_line = startloc.line; + end_column = startloc.column; + } + gcov_write_unsigned (end_line); gcov_write_unsigned (end_column); gcov_write_length (offset); -- cgit v1.1 From f8884b9c51faea329196bf5914bcd2d700622c38 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Wed, 14 Jul 2021 09:40:11 +0200 Subject: gcov: Fix use of profile info section If the -fprofile-info-section is used, then the gcov information is registered in a linker set. This is done by build_gcov_info_var_registration(). The compiler generated object placed in the section was not marked as referenced, so once optimization was enabled, this object was optimized away. Mark it as referenced. gcc/ * coverage.c (build_gcov_info_var_registration): Mark the object placed in the linker set as referenced so that it does not get optimized away. --- gcc/coverage.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'gcc/coverage.c') diff --git a/gcc/coverage.c b/gcc/coverage.c index dfc8108..ac9a9fd 100644 --- a/gcc/coverage.c +++ b/gcc/coverage.c @@ -50,6 +50,7 @@ along with GCC; see the file COPYING3. If not see #include "auto-profile.h" #include "profile.h" #include "diagnostic.h" +#include "varasm.h" #include "gcov-io.c" @@ -1121,6 +1122,7 @@ build_gcov_info_var_registration (tree gcov_info_type) DECL_NAME (var) = get_identifier (name_buf); get_section (profile_info_section, SECTION_UNNAMED, NULL); set_decl_section_name (var, profile_info_section); + mark_decl_referenced (var); DECL_INITIAL (var) = build_fold_addr_expr (gcov_info_var); varpool_node::finalize_decl (var); } -- cgit v1.1 From 8cdcea51c0fd753e6a652c9b236e91b3a6e0911c Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Mon, 9 Aug 2021 09:06:14 +0200 Subject: gcov: Add TARGET_GCOV_TYPE_SIZE target hook If -fprofile-update=atomic is used, then the target must provide atomic operations for the counters of the type returned by get_gcov_type(). This is a 64-bit type for targets which have a 64-bit long long type. On 32-bit targets this could be an issue since they may not provide 64-bit atomic operations. Allow targets to override the default type size with the new TARGET_GCOV_TYPE_SIZE target hook. If a 32-bit gcov type size is used, then there is currently a warning in libgcov-driver.c in a dead code block due to sizeof (counter) == sizeof (gcov_unsigned_t): libgcc/libgcov-driver.c: In function 'dump_counter': libgcc/libgcov-driver.c:401:46: warning: right shift count >= width of type [-Wshift-count-overflow] 401 | dump_unsigned ((gcov_unsigned_t)(counter >> 32), dump_fn, arg); | ^~ gcc/c-family/ * c-cppbuiltin.c (c_cpp_builtins): Define __LIBGCC_GCOV_TYPE_SIZE if flag_building_libgcc is true. gcc/ * config/sparc/rtemself.h (SPARC_GCOV_TYPE_SIZE): Define. * config/sparc/sparc.c (sparc_gcov_type_size): New. (TARGET_GCOV_TYPE_SIZE): Redefine if SPARC_GCOV_TYPE_SIZE is defined. * coverage.c (get_gcov_type): Use targetm.gcov_type_size(). * doc/tm.texi (TARGET_GCOV_TYPE_SIZE): Add hook under "Misc". * doc/tm.texi.in: Regenerate. * target.def (gcov_type_size): New target hook. * targhooks.c (default_gcov_type_size): New. * targhooks.h (default_gcov_type_size): Declare. * tree-profile.c (gimple_gen_edge_profiler): Use precision of gcov_type_node. (gimple_gen_time_profiler): Likewise. libgcc/ * libgcov.h (gcov_type): Define using __LIBGCC_GCOV_TYPE_SIZE. (gcov_type_unsigned): Likewise. --- gcc/coverage.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gcc/coverage.c') diff --git a/gcc/coverage.c b/gcc/coverage.c index ac9a9fd..10d7f83 100644 --- a/gcc/coverage.c +++ b/gcc/coverage.c @@ -146,7 +146,7 @@ tree get_gcov_type (void) { scalar_int_mode mode - = smallest_int_mode_for_size (LONG_LONG_TYPE_SIZE > 32 ? 64 : 32); + = smallest_int_mode_for_size (targetm.gcov_type_size ()); return lang_hooks.types.type_for_mode (mode, false); } -- cgit v1.1