public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/95594] New: overzealous -Wmaybe-uninitialized calling a function with an empty range of const pointers
@ 2020-06-09  0:08 msebor at gcc dot gnu.org
  0 siblings, 0 replies; only message in thread
From: msebor at gcc dot gnu.org @ 2020-06-09  0:08 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 95594
           Summary: overzealous -Wmaybe-uninitialized calling a function
                    with an empty range of const pointers
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

The recent enhancement to -Wuninitialized (PR 10138) is overly strict: it
triggers for calls to functions with a pair of pointers (at least one const)
delineating a slice of an array.

For example, while the warning doesn't trigger in g() below it does trigger in
h(), even though the call is safe.  Passing such slices is not entirely
uncommon.  For example, the C++ class member functions in() and out() are
declared like so:

  result codevt::out (stateT& state,
                      const internT* from, const internT* from_end, const
internT*& from_next,
                      externT*to, externT* to_end, externT*& to_next) const;

and can be called with empty ranges.

A test case for the idiom is below:

$ cat q.c && /build/gcc-master/gcc/xgcc -B /build/gcc-master/gcc -O2 -S -Wall
-Wextra q.c
__attribute__ ((noipa)) void
f (void *to, const void *to_end)
{
  __builtin_memset (to, 0, to_end - to);
}

void g (void)
{
  int i;
  f (&i, &i + 1);  // no warning (good)
  // ...
}

void h (void)
{
  int a[2];
  f (a, a);        // -Wmaybe-uninitialized
  // ...
}

q.c: In function ‘h’:
q.c:17:3: warning: ‘a’ may be used uninitialized [-Wmaybe-uninitialized]
   17 |   f (a, a);        // -Wmaybe-uninitialized
      |   ^~~~~~~~
q.c:2:1: note: by argument 2 of type ‘const void *’ to ‘f’ declared here
    2 | f (void *to, const void *to_end)
      | ^
q.c:16:7: note: ‘a’ declared here
   16 |   int a[2];
      |       ^

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-06-09  0:08 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-09  0:08 [Bug middle-end/95594] New: overzealous -Wmaybe-uninitialized calling a function with an empty range of const pointers msebor at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).