Subject: Re: bug#76559: 31.0.50; [-O3 + PGTK] Crash when 'copying as kill'/'killing word'

From: Po Lu <[email-masked]>
Date: Thu, 27 Feb 2025 18:15:42 +0800

Po Lu <[email-masked]> writes:

> Po Lu <[email-masked]> writes:
>
>> What I suspect is that there is some CU in which `struct
>> selection_input_event' is incomplete or fails to appear in `union
>> buffered_input_event' and that that misleads the compiler during
>> link-time recompilation.  But I could be far off the mark, since I am
>> very much out of touch with contemporary GCC.
>
> After devoting another 30 minutes to this problem, I've reduced it to a
> trivial test case that reveals the same miscompilation under GCC 14.2.1:
>
>
>
>
>
> Simply execute:
>
>   $ gcc -fdump-tree-all -fdump-rtl-all -save-temps -O3 -flto -g3 \
>     reduction1.c reduction.c -o reduction && ./reduction
>   ffffffff
>
> and observe that the high 32 bits of the dpyinfo pointer in the saved
> event are truncated, as would be expected from these expressions:
>
>   ev_12 = MEM <unsigned int> [(union buffered_input_event *)&main_inev];
>
> [...]
>
>   MEM <unsigned int> [(union buffered_input_event *)&kbd_buffer] = ev_12;
>   MEM <unsigned int> [(union buffered_input_event *)&kbd_buffer + 4B] = ev$ie$code_16;
>   MEM <unsigned int> [(union buffered_input_event *)&kbd_buffer + 8B] = ev$ie$modifiers_1;
>   MEM <long int> [(union buffered_input_event *)&kbd_buffer + 16B] = ev$ie$device_6;
>
> With aggregate access expansion disabled, all is normal:
>
>   $ gcc -fdump-tree-all -fdump-rtl-all -fno-tree-sra -save-temps \
>     -O3 -flto -g3 reduction1.c reduction.c -o reduction && ./reduction
>   ffffffffffffffff
>
> In a word, tampering with optimizer options is tantamount to playing
> with fire.  Don't do it, if your object is a functioning Emacs.

Which, if it wasn't apparent, belies my earlier theory respecting what
would be reported in C++ mode as ODR violations.  It's a genuine GCC
bug.