From: "Óscar Fuentes" <ofv@wanadoo.es>
To: emacs-devel@gnu.org
Subject: Re: Warnings in mingw64 builds on master
Date: Sun, 16 Aug 2020 18:45:31 +0200 [thread overview]
Message-ID: <87tux2sfo4.fsf@telefonica.net> (raw)
In-Reply-To: 83eeo6irap.fsf@gnu.org
Eli Zaretskii <eliz@gnu.org> writes:
>> >> if none of those conditions are true
>> >
>> > That cannot happen.
>>
>> True, but it requires deeper analysis for the compiler to prove it.
>
> You mean, pay attention to the test of the same flags a few lines
> before?
The information gained about the contents of fd_info[fd] from that test
is discarded when the compiler finds a call to an external function
(DebPrint) a few lines below, since DebPrint (or one of the functions it
calls) might change the contents of the global fd_info array.
If the OP was not building with EMACSDEBUG defined, the warning would be
bogus indeed, since DebPrint is a no-op on that case. But please note
that the warning says "may be undefined", that is, the compiler is just
saying that it was unable to prove that `rc' is assigned before it is
used. It is not a bug, but a limitation, a QoI issue.
This piked my curiosity and wrote this sample:
#include <stdlib.h>
enum { FILE_PIPE, FILE_SERIAL, FILE_SOCKET, FILE_READ, FILE_CONNECT};
typedef struct
{
unsigned flags;
} filedesc;
extern filedesc fd_info [10];
extern void _DebPrint (const char *fmt, ...);
#define DebPrint(stuff) _DebPrint stuff
// #define DebPrint(stuff) ((void) 0)
int _sys_read_ahead (int fd) {
int rc;
if ((fd_info[fd].flags & (FILE_PIPE | FILE_SERIAL | FILE_SOCKET)) == 0
|| (fd_info[fd].flags & FILE_READ) == 0)
{
DebPrint (("_sys_read_ahead: internal error: fd %d is not a pipe, serial port, or socket!\n", fd));
return(0);
}
if ((fd_info[fd].flags & FILE_CONNECT) != 0)
DebPrint (("_sys_read_ahead: read requested from fd %d, which waits for async connect!\n", fd));
if (fd_info[fd].flags & FILE_PIPE) {
rc = 1;
}
else if (fd_info[fd].flags & FILE_SERIAL) {
rc = 2;
}
else if (fd_info[fd].flags & FILE_SOCKET) {
rc = 3;
}
return rc;
}
which compiled with `gcc -c -Wall -Wmaybe-uninitialized' (gcc 10.1)
shows no warnings, which indeed might indicate a bug. OTOH, `clang -c
-Wall' (clang 11) shows:
w32.c:35:12: warning: variable 'rc' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
else if (fd_info[fd].flags & FILE_SOCKET) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
w32.c:39:10: note: uninitialized use occurs here
return rc;
^~
w32.c:35:8: note: remove the 'if' if its condition is always true
else if (fd_info[fd].flags & FILE_SOCKET) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
w32.c:17:9: note: initialize the variable 'rc' to silence this warning
int rc;
^
= 0
1 warning generated.
which is quite illustrative. But if you change the definition of
DebPrint to the no-op version, it keeps showing the same warning, which
demontrates the limitations of the compiler.
Right now the point of this type of warnings is that *sometimes* they
are helpful. The compiler guys try to do their best, but the result
never will be perfect, it can't be.
next prev parent reply other threads:[~2020-08-16 16:45 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-14 22:37 Warnings in mingw64 builds on master Andy Moreton
2020-08-15 16:24 ` Eli Zaretskii
2020-08-15 18:48 ` Andy Moreton
2020-08-15 19:03 ` Eli Zaretskii
2020-08-15 19:39 ` Andy Moreton
2020-08-15 20:36 ` Óscar Fuentes
2020-08-16 2:31 ` Eli Zaretskii
2020-08-16 11:21 ` Andy Moreton
2020-08-16 14:44 ` Eli Zaretskii
2020-08-16 16:45 ` Óscar Fuentes [this message]
2020-08-16 17:08 ` Eli Zaretskii
2020-08-16 15:05 ` Óscar Fuentes
2020-08-15 22:34 ` Paul Eggert
2020-08-16 2:31 ` Eli Zaretskii
2020-08-16 15:25 ` Paul Eggert
2020-08-16 15:39 ` Eli Zaretskii
2020-08-17 4:21 ` Paul Eggert
2020-08-17 16:21 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87tux2sfo4.fsf@telefonica.net \
--to=ofv@wanadoo.es \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).