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

            Bug ID: 99945
           Summary: missing maybe-uninitialized warning when using a
                    cleanup function
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vincent-gcc at vinc17 dot net
  Target Milestone: ---

Consider the following testcase:

int foo1 (void);
int foo2 (int);

#ifdef D
#define N
#else
#define N !
#endif

int bar (void)
{
  int i;
  auto void cf (int *t) { foo2 (i); }
  int t __attribute__ ((cleanup (cf)));

  t = 0;

  if (foo1 ())
    i = foo1 ();

  i = N foo1 () || i;
  foo2 (i);

  return 0;
}

With a GCC snapshot built a few hours ago from the master branch on x86_64:

cventin% gcc --version
gcc (GCC) 11.0.1 20210406 (experimental)

cventin% gcc -Werror=maybe-uninitialized -O2 -c file.c                         
cventin% gcc -Werror=maybe-uninitialized -O2 -c file.c -DD
cventin% gcc -Werror=maybe-uninitialized -O2 -c file.c -fsanitize=undefined
cventin% gcc -Werror=maybe-uninitialized -O2 -c file.c -fsanitize=undefined -DD
file.c: In function ‘bar’:
file.c:21:17: error: ‘FRAME.1.i’ may be used uninitialized
[-Werror=maybe-uninitialized]
   21 |   i = N foo1 () || i;
      |         ~~~~~~~~^~~~
file.c:10:5: note: ‘FRAME.1’ declared here
   10 | int bar (void)
      |     ^~~
cc1: some warnings being treated as errors

Except in the last case, the warning is missing, though -fsanitize=undefined
should have no influence, and whether one does "! foo1 ()" or "foo1 ()" should
have no effects either.

Reply via email to