Common Var(warn_coverage_mismatch) Init(1) Warning
Warn in case profiles in -fprofile-use do not match.
+Wcoverage-invalid-line-number
+Common Var(warn_coverage_invalid_linenum) Init(1) Warning
+Warn in case a function ends earlier than it begins due to an invalid linenum macros.
+
Wmissing-profile
Common Var(warn_missing_profile) Init(1) Warning
Warn in case profiles in -fprofile-use do not exist.
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
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);
case of very minor changes such as bug fixes to an existing code-base.
Completely disabling the warning is not recommended.
+@item -Wno-coverage-invalid-line-number
+@opindex Wno-coverage-invalid-line-number
+@opindex Wcoverage-invalid-line-number
+Warn in case a function ends earlier than it begins due
+to an invalid linenum macros. The warning is emitted only
+with @option{--coverage} enabled.
+ By default, this warning is enabled and is treated as an
+error. @option{-Wno-coverage-invalid-line-number} can be used to disable the
+warning or @option{-Wno-error=coverage-invalid-line-number} can be used to
+disable the error.
+
@item -Wno-cpp
@r{(C, Objective-C, C++, Objective-C++ and Fortran only)}
@opindex Wno-cpp
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "--coverage -Wno-error=coverage-invalid-line-number" } */
+
+void
+foo() // { dg-warning "function starts on a higher line number than it ends" }
+{
+#line 1
+}
+
+int main()
+{
+ foo ();
+}
/* Enable -Werror=coverage-mismatch when -Werror and -Wno-error
have not been set. */
- if (!global_options_set.x_warnings_are_errors
- && warn_coverage_mismatch
- && (global_dc->classify_diagnostic[OPT_Wcoverage_mismatch] ==
- DK_UNSPECIFIED))
- diagnostic_classify_diagnostic (global_dc, OPT_Wcoverage_mismatch,
- DK_ERROR, UNKNOWN_LOCATION);
+ if (!global_options_set.x_warnings_are_errors)
+ {
+ if (warn_coverage_mismatch
+ && (global_dc->classify_diagnostic[OPT_Wcoverage_mismatch] ==
+ DK_UNSPECIFIED))
+ diagnostic_classify_diagnostic (global_dc, OPT_Wcoverage_mismatch,
+ DK_ERROR, UNKNOWN_LOCATION);
+ if (warn_coverage_invalid_linenum
+ && (global_dc->classify_diagnostic[OPT_Wcoverage_invalid_line_number] ==
+ DK_UNSPECIFIED))
+ diagnostic_classify_diagnostic (global_dc, OPT_Wcoverage_invalid_line_number,
+ DK_ERROR, UNKNOWN_LOCATION);
+ }
/* Save the current optimization options. */
optimization_default_node