https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78993

            Bug ID: 78993
           Summary: False positive from -Wmaybe-uninitialized
           Product: gcc
           Version: 7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dmalcolm at gcc dot gnu.org
  Target Milestone: ---

Created attachment 40461
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=40461&action=edit
Reproducer, based on input.c

As noted in the thread at:
  https://gcc.gnu.org/ml/gcc-patches/2017-01/msg00049.html
there's a false positive at -O3 from -Wmaybe-uninitialized in gcc's input.c

I'm attaching a minimized reproducer.

$ g++ (GCC) 7.0.0 20161221 (experimental)
$ g++ -c input.cc -O3 -Wall
input.cc: In function ‘void assert_char_at_range(location_t, int, int, int,
int)’:
input.cc:85:56: warning: ‘*((void*)& actual_range +4)’ may be used
uninitialized in this function [-Wmaybe-uninitialized]
     loc = get_location_from_adhoc_loc (line_table, loc);
                                                        ^
input.cc:96:16: note: ‘*((void*)& actual_range +4)’ was declared here
   source_range actual_range;
                ^~~~~~~~~~~~
input.cc:85:56: warning: ‘actual_range’ may be used uninitialized in this
function [-Wmaybe-uninitialized]
     loc = get_location_from_adhoc_loc (line_table, loc);
                                                        ^
input.cc:96:16: note: ‘actual_range’ was declared here
   source_range actual_range;
                ^~~~~~~~~~~~

This appears to be a false positive: to access fields of actual_range,
execution needs to get past:

  const char *err = get_source_range_for_char (idx, &actual_range);
  if (should_have_column_data_p (strloc))
    {
      if (err)
        fail ();
    }
  else
    return;

  *access happens here*

Given that fail is no-return, the only way to reach the access is for "err" to
be NULL.

Looking at a gimple dump, get_source_range_for_char has been inlined.
This can only return NULL if actual_range is written to, but presumably during
optimization we somehow lose track of this invariant
(or I'm misreading the code...)

Also, the location for the warning is odd: it's reported as within
assert_char_at_range, but the location given is within
should_have_column_data_p.

Reply via email to