False positive warning in verify_heapam.c with GCC 03 - Mailing list pgsql-hackers

From Maxim Orlov
Subject False positive warning in verify_heapam.c with GCC 03
Date
Msg-id CACG=ezb9umUU4ETZthFVotqX7qpTVFM+UV-awbaMky3hUMqQag@mail.gmail.com
Whole thread Raw
List pgsql-hackers
Hi!

While playing with some unrelated to the topic stuff, I've noticed a strange warning from verify_heapam.c:730:25:
warning: ‘xmax_status’ may be used uninitialized in this function.

This happens only when get_xid_status is inlined, and only in GCC with O3. I use a GCC version 11.3.0.

For the purpose of investigation, I've created a PFA patch to force get_xid_status inline.

$ CFLAGS="-O3" ./configure -q && make -s -j12 >/dev/null && make -s -j12 -C contrib
verify_heapam.c: In function ‘check_tuple_visibility’:
verify_heapam.c:730:25: warning: ‘xmax_status’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  730 |         XidCommitStatus xmax_status;
      |                         ^~~~~~~~~~~
verify_heapam.c:909:25: warning: ‘xmin_status’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  909 |                 else if (xmin_status != XID_COMMITTED)
      |

I believe, this warning is false positive, since mentioned row is unreachable. If xid is invalid, we return from get_xid_status
XID_INVALID and could not pass
 770 ········if (HeapTupleHeaderXminInvalid(tuphdr))
 771 ············return false;·······/* inserter aborted, don't check */

So, I think this warning is false positive. On the other hand, we could simply init status variable in get_xid_status and
make this code more errors/warnings safe. Thoughts?

--
Best regards,
Maxim Orlov.
Attachment

pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Making Vars outer-join aware
Next
From: Jelte Fennema
Date:
Subject: [PATCH] Support using "all" for the db user in pg_ident.conf