GNU bug report logs - #47080
28.0.50; Spurious variable left uninitialized compiler warning

Previous Next

Package: emacs;

Reported by: Michael Heerdegen <michael_heerdegen <at> web.de>

Date: Fri, 12 Mar 2021 00:05:01 UTC

Severity: minor

Found in version 28.0.50

Done: Stefan Monnier <monnier <at> iro.umontreal.ca>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 47080 in the body.
You can then email your comments to 47080 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#47080; Package emacs. (Fri, 12 Mar 2021 00:05:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Michael Heerdegen <michael_heerdegen <at> web.de>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Fri, 12 Mar 2021 00:05:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Michael Heerdegen <michael_heerdegen <at> web.de>
To: bug-gnu-emacs <at> gnu.org
Cc: Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: 28.0.50; Spurious variable left uninitialized compiler warning
Date: Fri, 12 Mar 2021 01:04:14 +0100
Hello,

here is the test case:

#+begin_src emacs-lisp
;; -*- lexical-binding: t -*-

(require 'pcase)
(require 'find-func) ;not involved AFAICT, just funs used in example

(defun my-find-function (function)
  (interactive (find-function-read))
  (pcase (find-function-library function)
    ((or 'nil
         (and `(,_ . ,file) (guard (or (not (stringp file)) (string-match-p "\\.c$" file))))
         (guard (not (find-definition-noselect function nil))))
     (describe-function function))))
#+end_src

Compiling gives me:

| compile-test.el:6:1: Warning: Variable `file' left uninitialized
| compile-test.el:6:1: Warning: Variable `file' left uninitialized

TIA,

Michael.


In GNU Emacs 28.0.50 (build 8, x86_64-pc-linux-gnu, GTK+ Version 3.24.24, cairo version 1.16.0)
 of 2021-03-12 built on drachen
Repository revision: 69b952bcac5366df4cd37a7681318b29bc23e3c8
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12010000
System Description: Debian GNU/Linux bullseye/sid

Configured features:
CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GSETTINGS HARFBUZZ JPEG JSON
LCMS2 LIBSELINUX LIBXML2 MODULES NOTIFY INOTIFY PDUMPER PNG RSVG SOUND
THREADS TIFF TOOLKIT_SCROLL_BARS X11 XDBE XIM XPM GTK3 ZLIB





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#47080; Package emacs. (Fri, 12 Mar 2021 00:24:01 GMT) Full text and rfc822 format available.

Message #8 received at 47080 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Michael Heerdegen <michael_heerdegen <at> web.de>
Cc: Stefan Monnier <monnier <at> iro.umontreal.ca>, 47080 <at> debbugs.gnu.org
Subject: Re: bug#47080: 28.0.50; Spurious variable left uninitialized
 compiler warning
Date: Fri, 12 Mar 2021 01:23:01 +0100
Michael Heerdegen <michael_heerdegen <at> web.de> writes:

> Compiling gives me:
>
> | compile-test.el:6:1: Warning: Variable `file' left uninitialized
> | compile-test.el:6:1: Warning: Variable `file' left uninitialized

This is perhaps the same problem that's causing this warning on the
current Emacs trunk?

In toplevel form:
progmodes/sh-script.el:1050:1: Warning: Variable `syntax' left uninitialized

I was just looking at this, and it looks like a spurious warning, if I
read the syntax-propertize-rules correctly.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#47080; Package emacs. (Fri, 12 Mar 2021 00:40:02 GMT) Full text and rfc822 format available.

Message #11 received at 47080 <at> debbugs.gnu.org (full text, mbox):

From: Michael Heerdegen <michael_heerdegen <at> web.de>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: Stefan Monnier <monnier <at> iro.umontreal.ca>, 47080 <at> debbugs.gnu.org
Subject: Re: bug#47080: 28.0.50; Spurious variable left uninitialized
 compiler warning
Date: Fri, 12 Mar 2021 01:39:31 +0100
Lars Ingebrigtsen <larsi <at> gnus.org> writes:

> This is perhaps the same problem that's causing this warning on the
> current Emacs trunk?
>
> In toplevel form:
> progmodes/sh-script.el:1050:1: Warning: Variable `syntax' left uninitialized

Looks indeed similar: the macro expansion (syntax-propertize-rules)
binds the variable warned about to `nil'.  The latest changes in the
byte compiler don't seem to handle this class of cases as we want.

> I was just looking at this, and it looks like a spurious warning, if I
> read the syntax-propertize-rules correctly.

I think we can wait for Stefan's reply.

Regards,

Michael.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#47080; Package emacs. (Fri, 12 Mar 2021 03:00:02 GMT) Full text and rfc822 format available.

Message #14 received at 47080 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: Michael Heerdegen <michael_heerdegen <at> web.de>, 47080 <at> debbugs.gnu.org
Subject: Re: bug#47080: 28.0.50; Spurious variable left uninitialized
 compiler warning
Date: Thu, 11 Mar 2021 21:58:51 -0500
Lars Ingebrigtsen [2021-03-12 01:23:01] wrote:
> Michael Heerdegen <michael_heerdegen <at> web.de> writes:
>> Compiling gives me:
>> | compile-test.el:6:1: Warning: Variable `file' left uninitialized
>> | compile-test.el:6:1: Warning: Variable `file' left uninitialized
>
> This is perhaps the same problem that's causing this warning on the
> current Emacs trunk?

Indeed.

> In toplevel form:
> progmodes/sh-script.el:1050:1: Warning: Variable `syntax' left uninitialized

I just fixed this one.

> I was just looking at this, and it looks like a spurious warning, if I
> read the syntax-propertize-rules correctly.

The warning complains when you initially bind a lexical var to nil
(either by not giving a value or by giving an explicit nil) and then
never set it to any other value.

Indeed, it's a useless binding: you could just use nil instead wherever
you use that var, so the warning is working as intended.  And indeed, it
found a few places where we bound a var to nil and then just
returned its value (and it's thanks to this warning that I discovered
that those var needed to be declared as dynamically scoped).

But the above `pcase` and `syntax-propertize-rules` show that it can be
quite inconvenient.  I can probably fix `pcase` to work around the
issue, but ... it's probably better to tone down the warning so it's
only issued if the nil binding is implicit rather than explicit.


        Stefan





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#47080; Package emacs. (Fri, 12 Mar 2021 03:09:01 GMT) Full text and rfc822 format available.

Message #17 received at 47080 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: Michael Heerdegen <michael_heerdegen <at> web.de>, 47080 <at> debbugs.gnu.org
Subject: Re: bug#47080: 28.0.50; Spurious variable left uninitialized
 compiler warning
Date: Fri, 12 Mar 2021 04:07:47 +0100
Stefan Monnier <monnier <at> iro.umontreal.ca> writes:

> Indeed, it's a useless binding: you could just use nil instead wherever
> you use that var, so the warning is working as intended.  And indeed, it
> found a few places where we bound a var to nil and then just
> returned its value (and it's thanks to this warning that I discovered
> that those var needed to be declared as dynamically scoped).

Oh, is that what the warning means.  :-)  It's not immediately
obvious -- could it be changed to something like...  er...  "Variable
bound to constant value and not changed"?

> But the above `pcase` and `syntax-propertize-rules` show that it can be
> quite inconvenient.  I can probably fix `pcase` to work around the
> issue, but ... it's probably better to tone down the warning so it's
> only issued if the nil binding is implicit rather than explicit.

Right.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Reply sent to Stefan Monnier <monnier <at> iro.umontreal.ca>:
You have taken responsibility. (Fri, 12 Mar 2021 03:30:02 GMT) Full text and rfc822 format available.

Notification sent to Michael Heerdegen <michael_heerdegen <at> web.de>:
bug acknowledged by developer. (Fri, 12 Mar 2021 03:30:02 GMT) Full text and rfc822 format available.

Message #22 received at 47080-done <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: Michael Heerdegen <michael_heerdegen <at> web.de>, 47080-done <at> debbugs.gnu.org
Subject: Re: bug#47080: 28.0.50; Spurious variable left uninitialized
 compiler warning
Date: Thu, 11 Mar 2021 22:29:08 -0500
Lars Ingebrigtsen [2021-03-12 04:07:47] wrote:
> Stefan Monnier <monnier <at> iro.umontreal.ca> writes:
>> Indeed, it's a useless binding: you could just use nil instead wherever
>> you use that var, so the warning is working as intended.  And indeed, it
>> found a few places where we bound a var to nil and then just
>> returned its value (and it's thanks to this warning that I discovered
>> that those var needed to be declared as dynamically scoped).
>
> Oh, is that what the warning means.  :-)  It's not immediately
> obvious -- could it be changed to something like...  er...  "Variable
> bound to constant value and not changed"?

Indeed, the warning could even be generalized to other trivial constant
values like `t`, but I think what we have already gives enough false
positives ;-)
[ Still, I'm quite happy with the warning in that it pointed me to a few
  actual problems in the code.  The average usefulness rating of each
  of the warnings that I fixed after adding this warning was not too bad.  ]

As for changing the wording, feel free: I'm not too happy with the
current one either (after all, the variables are initialized to nil in
any case, so there's no such thing as an uninitialized variable),
tho I'm not very fond of the one you suggest.

In any case I installed the patch below which should fix the immediate offenders.


        Stefan


diff --git a/lisp/emacs-lisp/cconv.el b/lisp/emacs-lisp/cconv.el
index ca641a2ef0..cfb0168a6e 100644
--- a/lisp/emacs-lisp/cconv.el
+++ b/lisp/emacs-lisp/cconv.el
@@ -602,7 +602,8 @@ cconv--analyze-use
      (byte-compile-warn
       "%s `%S' not left unused" varkind var))
     ((and (let (or 'let* 'let) (car form))
-          `(,(or `(,var) `(,var nil)) t nil ,_ ,_))
+          `(,`(,var) ;; (or `(,var nil) : Too many false positives: bug#47080
+            t nil ,_ ,_))
      ;; FIXME: Convert this warning to use `macroexp--warn-wrap'
      ;; so as to give better position information.
      (unless (not (intern-soft var))





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#47080; Package emacs. (Sat, 13 Mar 2021 00:15:02 GMT) Full text and rfc822 format available.

Message #25 received at 47080-done <at> debbugs.gnu.org (full text, mbox):

From: Michael Heerdegen <michael_heerdegen <at> web.de>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: Lars Ingebrigtsen <larsi <at> gnus.org>, 47080-done <at> debbugs.gnu.org
Subject: Re: bug#47080: 28.0.50; Spurious variable left uninitialized
 compiler warning
Date: Sat, 13 Mar 2021 01:13:49 +0100
Stefan Monnier <monnier <at> iro.umontreal.ca> writes:

> Indeed, the warning could even be generalized to other trivial constant
> values like `t`, but I think what we have already gives enough false
> positives ;-)

FWIW, I also got one or two true positives in my own stuff.

To avoid false positives, is it possible to limit the warning to "human
written" code or to code that is not the result of macro expansion?


Thanks,

Michael.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#47080; Package emacs. (Sat, 13 Mar 2021 00:38:01 GMT) Full text and rfc822 format available.

Message #28 received at 47080-done <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Michael Heerdegen <michael_heerdegen <at> web.de>
Cc: Lars Ingebrigtsen <larsi <at> gnus.org>, 47080-done <at> debbugs.gnu.org
Subject: Re: bug#47080: 28.0.50; Spurious variable left uninitialized
 compiler warning
Date: Fri, 12 Mar 2021 19:37:35 -0500
>> Indeed, the warning could even be generalized to other trivial constant
>> values like `t`, but I think what we have already gives enough false
>> positives ;-)
> FWIW, I also got one or two true positives in my own stuff.
> To avoid false positives, is it possible to limit the warning to "human
> written" code or to code that is not the result of macro expansion?

It's somewhere between difficult and impossible with the current setup.
Hygienic macro systems should be able to get that information, but
our macro system doesn't keep track of it.

It would require efforts similar to those needed to preserve
file+line+col information.


        Stefan





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#47080; Package emacs. (Sat, 13 Mar 2021 00:45:02 GMT) Full text and rfc822 format available.

Message #31 received at 47080-done <at> debbugs.gnu.org (full text, mbox):

From: Michael Heerdegen <michael_heerdegen <at> web.de>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: Lars Ingebrigtsen <larsi <at> gnus.org>, 47080-done <at> debbugs.gnu.org
Subject: Re: bug#47080: 28.0.50; Spurious variable left uninitialized
 compiler warning
Date: Sat, 13 Mar 2021 01:44:31 +0100
Stefan Monnier <monnier <at> iro.umontreal.ca> writes:

> It would require efforts similar to those needed to preserve
> file+line+col information.

I had hoped we could maybe benefit from that: if the variable has
line+col information, it must have been human written.  But it's
probably not reliable enough.

Michael.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#47080; Package emacs. (Sat, 13 Mar 2021 00:59:02 GMT) Full text and rfc822 format available.

Message #34 received at 47080-done <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Michael Heerdegen <michael_heerdegen <at> web.de>
Cc: Lars Ingebrigtsen <larsi <at> gnus.org>, 47080-done <at> debbugs.gnu.org
Subject: Re: bug#47080: 28.0.50; Spurious variable left uninitialized
 compiler warning
Date: Fri, 12 Mar 2021 19:58:42 -0500
>> It would require efforts similar to those needed to preserve
>> file+line+col information.
> I had hoped we could maybe benefit from that: if the variable has
> line+col information, it must have been human written.  But it's
> probably not reliable enough.

It's not just "not reliable enough": there's simply no variable that has
line+col info currently.


        Stefan





bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 10 Apr 2021 11:24:09 GMT) Full text and rfc822 format available.

This bug report was last modified 3 years and 30 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.