GNU bug report logs - #76559
31.0.50; [-O3 + PGTK] Crash when 'copying as kill'/'killing word'

Previous Next

Package: emacs;

Reported by: Iurie Marian <marian.iurie <at> gmail.com>

Date: Tue, 25 Feb 2025 17:34:01 UTC

Severity: normal

Merged with 76729

Found in version 31.0.50

Full log


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

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Pip Cet <pipcet <at> protonmail.com>
Cc: Po Lu <luangruo <at> yahoo.com>, iura.mail <at> gmail.com, marian.iurie <at> gmail.com,
 michael.albinus <at> gmx.de, Eli Zaretskii <eliz <at> gnu.org>, 76559 <at> debbugs.gnu.org,
 Stefan Kangas <stefankangas <at> gmail.com>
Subject: Re: bug#76559: 31.0.50; [-O3 + PGTK] Crash when 'copying as
 kill'/'killing word'
Date: Thu, 27 Feb 2025 10:50:18 -0800
On 2025-02-27 04:22, Pip Cet wrote:
> (I'm not convinced there's a GCC bug there, but it doesn't matter:
> aggressive GCC optimizations currently result in broken Emacs builds).

I don't see a GCC bug there. If a program casts a pointer to a different 
pointer type and dereferences the result, behavior is undefined (with 
exceptions for void * and char * that don't apply here). And even if we 
blacklist gcc -O3 -flto, who's to say some other compiler won't do the 
optimization?

The violation of C rules occurs in keyboard.h, here:

  INLINE void
  kbd_buffer_store_event_hold (struct input_event *event,
			       struct input_event *hold_quit)
  {
    kbd_buffer_store_buffered_event ((union buffered_input_event *) event,
				     hold_quit);
  }

That cast is invalid and the resulting code need not work as one might 
expect with a circa 1978 C compiler.

One possible fix to the bug would be to change the API of 
kbd_buffer_store_event_hold to accept a pointer to the union rather than 
a pointer to the struct, and change its callers accordingly. There are 
other possible fixes. I'm dubious whether Po Lu's latest proposal 
<https://bugs.gnu.org/76559#71> suffices, though, as it doesn't fix the 
invalid pointer cast.


>> I believe we should recommend against using -O3.  Too many bad bugs
> 
> If we do that, can we include link time optimization in that?

I've found real bugs with -flto, an option that is not supposed to 
introduce bugs though it may trigger latent bugs. Although I'm not a fan 
of -flto for typical use (for one thing, it's too expensive) I don't 
think we should discourage it at least when debugging.

Similarly for -O3.




This bug report was last modified 108 days ago.

Previous Next


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