False positive warning in verify_heapam.c with GCC 03

From: Maxim Orlov <orlovmg(at)gmail(dot)com>
To: Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: False positive warning in verify_heapam.c with GCC 03
Date: 2022-12-27 15:35:37
Message-ID: CACG=ezb9umUU4ETZthFVotqX7qpTVFM+UV-awbaMky3hUMqQag@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 Content-Type Size
0002-Init-status-var-in-get_xid_status.patch application/octet-stream 828 bytes
0001-Force-inline-of-get_xid_status.patch application/octet-stream 1.3 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Jelte Fennema 2022-12-27 15:54:46 [PATCH] Support using "all" for the db user in pg_ident.conf
Previous Message Tom Lane 2022-12-27 15:31:20 Re: Making Vars outer-join aware