This is the mail archive of the gcc-patches@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]

Re: [PATCH] Fix caret locations in format_type_warning (PR c/72857)


On Wed, 2016-08-17 at 09:51 -0400, David Malcolm wrote:
> On Wed, 2016-08-17 at 10:12 +0200, Andreas Schwab wrote:
> > ../../gcc/input.c:1470:1: error: 'const char*
> > get_source_range_for_char(cpp_reader*, string_concat_db*,
> > location_t,
> > cpp_ttype, int, source_range*)' defined but not used [
> > -Werror=unused
> > -function]
> >  get_source_range_for_char (cpp_reader *pfile,
> >  ^~~~~~~~~~~~~~~~~~~~~~~~~
> 
> I'm guessing you have a --enable-checking=release build, and that
> this
> is happening in stage2.  My testing was with a debug build.
> 
> Sorry about this.
> 
> Does the attached patch fix it for you?  (I verified that it builds
> without warnings with both plain and --enable-checking=release
> configurations; bootstrapping it now)

That one didn't actually bootstrap for me, due to:

In file included from ../../../src/gcc/input.c:25:0:
../../../src/gcc/selftest.h: In function ‘void selftest::assert_num_substring_ranges(const selftest::location&, selftest::lexer_test&, location_t, cpp_ttype, int)’:
../../../src/gcc/selftest.h:155:3: error: ‘actual_num_ranges’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
   if ((EXPECTED) == (ACTUAL))           \
   ^~
../../../src/gcc/input.c:2084:7: note: ‘actual_num_ranges’ was declared here
   int actual_num_ranges;
       ^~~~~~~~~~~~~~~~~
cc1plus: all warnings being treated as errors

apparently due to get_num_source_ranges_for_substring being inlined
into assert_num_substring_ranges, and then the logic being too
complicated for -Wmaybe-uninitialized to follow.  I was able to satisfy
a reduced version of the function that demonstrated the false warning
by adding "noreturn" to selftest::fail, but not the full version, so as
a simple fix, I've initialized actual_num_ranges to a dummy value.

I've committed the attached fix to trunk (as r239550), having verified
bootstrap&regrtest on x86_64-pc-linux-gnu (debug build), and verified
the absence of warnings with a release build.

Sorry again about the breakage.
Dave

From 9c9f9e1c3ff1be538f77c32b9d1cf53baae5e577 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Wed, 17 Aug 2016 10:13:20 -0400
Subject: [PATCH] input.c: move test functions within #CHECKING_P and into selftest::

gcc/ChangeLog:
	* input.c (get_source_range_for_char): Rename to...
	(selftest::get_source_range_for_char): ...this, and move within
	the #if CHECKING_P guard.
	(get_num_source_ranges_for_substring): Rename to...
	(selftest::get_num_source_ranges_for_substring): ...this, move
	within the #if CHECKING_P guard, and make static.
	(selftest::assert_num_substring_ranges): Initialize
	actual_num_ranges.
---
 gcc/input.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/gcc/input.c b/gcc/input.c
index 653e54d..cfc62f3 100644
--- a/gcc/input.c
+++ b/gcc/input.c
@@ -1454,6 +1454,12 @@ get_source_location_for_substring (cpp_reader *pfile,
   return NULL;
 }
 
+#if CHECKING_P
+
+namespace selftest {
+
+/* Selftests of location handling.  */
+
 /* Attempt to populate *OUT_RANGE with source location information on the
    given character within the string literal found at STRLOC.
    CHAR_IDX refers to an offset within the execution character set.
@@ -1493,7 +1499,7 @@ get_source_range_for_char (cpp_reader *pfile,
 /* As get_source_range_for_char, but write to *OUT the number
    of ranges that are available.  */
 
-const char *
+static const char *
 get_num_source_ranges_for_substring (cpp_reader *pfile,
 				     string_concat_db *concats,
 				     location_t strloc,
@@ -1513,12 +1519,6 @@ get_num_source_ranges_for_substring (cpp_reader *pfile,
   return NULL;
 }
 
-#if CHECKING_P
-
-namespace selftest {
-
-/* Selftests of location handling.  */
-
 /* A class for writing out a temporary sourcefile for use in selftests
    of input handling.  */
 
@@ -2081,7 +2081,7 @@ assert_num_substring_ranges (const location &loc,
   cpp_reader *pfile = test.m_parser;
   string_concat_db *concats = &test.m_concats;
 
-  int actual_num_ranges;
+  int actual_num_ranges = -1;
   const char *err
     = get_num_source_ranges_for_substring (pfile, concats, strloc, type,
 					   &actual_num_ranges);
-- 
1.8.5.3


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