#1006803 -Wuse-after-free: spurious warning

Package:
gcc-12
Source:
gcc-12
Description:
GNU C compiler
Submitter:
Bill Allombert
Date:
2022-03-05 13:03:03 UTC
Severity:
normal
#1006803#5
Date:
2022-03-05 12:59:13 UTC
From:
To:
Package: gcc-12
Version: 12-20220302-1
Severity: normal

Dear GCC maintainers,

The following sample code gives a spurious warning with gcc-12:

gcc-12 -c -O3 -Wall test.c
test.c: In function ‘fun’:
test.c:5:25: warning: pointer ‘old’ used after ‘realloc’
[-Wuse-after-free]
    5 |   unsigned long  s = new-old;
      |                      ~~~^~~~
test.c:4:15: note: call to ‘realloc’ here
    4 |   void *new = realloc(old, n);
      |               ^~~~~~~~~~~~~~~

It should check that "old" is dereferenced.

Cheers,