https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124283
Bug ID: 124283
Summary: Missing -Wmaybe-uninitialized warning with cleanup
function
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: vincent-gcc at vinc17 dot net
Target Milestone: ---
Missing -Wmaybe-uninitialized warning with "gcc-snapshot -Wall -O2 -c tst.c"
using
gcc (Debian 20260216-1) 16.0.1 20260216 (experimental) [trunk
r16-7529-g5388fd3a3b6]
on the following code:
void f (int);
int g (int r)
{
int res;
auto void log_cleanup (int *time);
void log_cleanup (int *time) { f (res); }
int log_time __attribute__ ((cleanup (log_cleanup)));
log_time = 0;
if (r == 0)
{
// f (res);
return 1;
}
if (r == 1)
{
res = 0;
}
return 0;
}
If I uncomment the "f (res);", I get a warning as expected:
tst.c: In function 'g':
tst.c:11:7: warning: 'FRAME.res' may be used uninitialized
[-Wmaybe-uninitialized]
11 | f (res);
| ^~~~~~~
tst.c:2:5: note: 'FRAME.res' was declared here
2 | int g (int r)
| ^
Ditto if I comment out the "res = 0;", with this time a -Wuninitialized
warning:
In function 'log_cleanup',
inlined from 'g' at tst.c:7:7:
tst.c:6:34: warning: 'FRAME.res' is used uninitialized [-Wuninitialized]
6 | void log_cleanup (int *time) { f (res); }
| ^~~~~~~
tst.c: In function 'g':
tst.c:2:5: note: 'FRAME.res' was declared here
2 | int g (int r)
| ^
Bug found with MPFR master-12941-140092bb9 under Debian/unstable, using
./configure --enable-logging CC=gcc-snapshot CFLAGS="-Wall -O2"
cd src
make round_prec.o
(and adding --enable-assert=full makes the warning appear).