From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?utf-8?Q?=C3=93scar_Fuentes?= Newsgroups: gmane.emacs.devel Subject: Re: Warnings in mingw64 builds on master Date: Sun, 16 Aug 2020 18:45:31 +0200 Message-ID: <87tux2sfo4.fsf@telefonica.net> References: <864kp47t20.fsf@gmail.com> <83a6yvkhby.fsf@gnu.org> <86v9hj7njb.fsf@gmail.com> <83tux3ive9.fsf@gnu.org> <875z9jtznn.fsf@telefonica.net> <83sgcniaol.fsf@gnu.org> <86tux2lttk.fsf@gmail.com> <83eeo6irap.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="21869"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.91 (gnu/linux) To: emacs-devel@gnu.org Cancel-Lock: sha1:crtRkk7UY2KNNlDkdzyuOPYh4cs= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Aug 16 18:46:35 2020 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k7Lnn-0005as-Pl for ged-emacs-devel@m.gmane-mx.org; Sun, 16 Aug 2020 18:46:35 +0200 Original-Received: from localhost ([::1]:36864 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k7Lnm-0001j0-Sf for ged-emacs-devel@m.gmane-mx.org; Sun, 16 Aug 2020 12:46:34 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:39134) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k7Lmz-0001GK-R9 for emacs-devel@gnu.org; Sun, 16 Aug 2020 12:45:45 -0400 Original-Received: from static.214.254.202.116.clients.your-server.de ([116.202.254.214]:44336 helo=ciao.gmane.io) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k7Lmx-0003sK-Vq for emacs-devel@gnu.org; Sun, 16 Aug 2020 12:45:45 -0400 Original-Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1k7Lmq-0004ds-PO for emacs-devel@gnu.org; Sun, 16 Aug 2020 18:45:36 +0200 X-Injected-Via-Gmane: http://gmane.org/ Received-SPF: pass client-ip=116.202.254.214; envelope-from=ged-emacs-devel@m.gmane-mx.org; helo=ciao.gmane.io X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/16 06:30:15 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -8 X-Spam_score: -0.9 X-Spam_bar: / X-Spam_report: (-0.9 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:253855 Archived-At: Eli Zaretskii 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 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.