https://gcc.gnu.org/bugzilla/show_bug.cgi?id=129274
Bug ID: 129274
Summary: RFE: precision of wording for analyzer events that are
implied by other events
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: analyzer
Assignee: dmalcolm at gcc dot gnu.org
Reporter: dmalcolm at gcc dot gnu.org
Target Milestone: ---
Splitting out from PR analyzer/129095:
For https://godbolt.org/z/jonfoM7KE we now emit:
<source>: In function 'main':
<source>:50:9: warning: 'bind' on possibly invalid file descriptor 'server_fd'
[-Wanalyzer-fd-use-without-check]
50 | if (bind(server_fd, (struct sockaddr *)&address, sizeof(address)) <
0) {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'main': event 1
40 | if ((server_fd = socket(AF_INET, SOCK_STREAM, 0)) == 0) {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| |
| (1) when 'socket' fails (returning -1)
'main': event 2
40 | if ((server_fd = socket(AF_INET, SOCK_STREAM, 0)) == 0) {
| ^
| |
| (2) following 'false' branch (when 'server_fd != 0')... ─>─┐
| │
'main': events 3-4
| │
|┌──────────────────────────────────────────────────────────────────┘
46 |│ address.sin_family = AF_INET;
|│ ^
|│ |
|└──────────────────────>(3) ...to here
......
50 | if (bind(server_fd, (struct sockaddr *)&address, sizeof(address)) <
0) {
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| |
| (4) ⚠️ 'server_fd' could be invalid
Compiler returned: 0
which clarifies the return value from socket, but event (2) reads:
(2) following 'false' branch (when 'server_fd != 0')...
This condition is implied by event (1), so for this case it would be better to
write something like:
(2) following 'false' branch (since 'server_fd != 0')...
(note the "when" would become "since"), since on this path we know the value of
server_fd and it's implied by event (1).
Other ideas:
Showing the "implied-by-event" in the affected event:
(2) following 'false' branch (since 'server_fd != 0' due to (1))...
or:
(2) following 'false' branch due to (1) (since 'server_fd != 0')...
Showing the value:
(2) 'server_fd' == '-1' from (1)
(3) following 'false' branch (since 'server_fd != 0')...