Re: Pointer subtraction with a null pointer
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Andres Freund <andres@anarazel.de>
Cc: pgsql-hackers@lists.postgresql.org, Robert Haas <robertmhaas@gmail.com>,
Thomas Munro <thomas.munro@gmail.com>
Date: 2022-03-26T17:51:07Z
Lists: pgsql-hackers
Attachments
- silence-null-subtraction-warning-1.patch (text/x-diff) patch
I wrote: > clang is complaining about the subtraction despite it being inside > a conditional arm that cannot be reached when val is null. It's hard > to see how that isn't a flat-out compiler bug. > However, granting that it isn't going to get fixed right away, > we could replace these call sites with "relptr_store_null()", > and maybe get rid of the conditional in relptr_store(). I've confirmed that the attached silences the warning with clang 13.0.0 (on Fedora 35). The store_null notation is not awful, perhaps; it makes those lines shorter and more readable. I'm a bit less enthused about removing the conditional in relptr_store, as that forces re-introducing it at a couple of call sites. Perhaps we should leave relptr_store alone ... but then the reason for relptr_store_null is hard to explain except as a workaround for a broken compiler. I changed the comment suggesting that you could use relptrs with the "process address space" as a base, because that would presumably mean base == NULL which is going to draw the same warning. regards, tom lane
Commits
-
Suppress compiler warning in relptr_store().
- e07d4ddc55fd 15.0 landed
- 403a8c76293b 10.21 landed
- a2a1aa830a1c 11.16 landed
- cb8586d0514b 12.11 landed
- 4fbbea2c1934 13.7 landed
- 0144c9c7e73d 14.3 landed