public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/114965] New: wrong code generated for Emacs/Gnulib strftime (regression from 13.2)
@ 2024-05-06 22:17 eggert at cs dot ucla.edu
  2024-05-06 23:05 ` [Bug middle-end/114965] " pinskia at gcc dot gnu.org
                   ` (17 more replies)
  0 siblings, 18 replies; 19+ messages in thread
From: eggert at cs dot ucla.edu @ 2024-05-06 22:17 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114965

            Bug ID: 114965
           Summary: wrong code generated for Emacs/Gnulib strftime
                    (regression from 13.2)
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: eggert at cs dot ucla.edu
  Target Milestone: ---

Created attachment 58111
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58111&action=edit
Test with "gcc -O2 u5.i; ./a.out". The output should be a "123   " line.

I ran into this problem when building newish GNU Emacs with gcc (GCC) 14.0.1
20240411 (Red Hat 14.0.1-0) on x86-64.

GCC generates incorrect code for emacs/lib/nstrftime.c, which is taken from
Gnulib. The incorrect code causes some of Emacs's own test cases ("make check")
to fail. Possibly you'll see a similar problem with glibc strftime, though I
haven't tested this.

A stripped-down version of the problem is attached. Compile and run it with:

  gcc -O2 u5.i
  ./a.out

The output is "123000", but it should be "123   " - that is, three spaces
should follow the "123" instead of three zeros.

Looking at the generated code, it appears that GCC gets confused by the
complicated logic involving the 'pad' local variable, switch statements, etc.
The code generated for line 62 behaves as if (pad == '0' || pad == '+') is
true, even though it is false because pad == '_'.

Compiling without -O2 makes the problem go away. The problem does not occur
with GCC 13.2.0, which I built myself. Nor does it occur with gcc (GCC) 8.5.0
20210514 (Red Hat 8.5.0-4).

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2024-05-09  8:19 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-06 22:17 [Bug c/114965] New: wrong code generated for Emacs/Gnulib strftime (regression from 13.2) eggert at cs dot ucla.edu
2024-05-06 23:05 ` [Bug middle-end/114965] " pinskia at gcc dot gnu.org
2024-05-06 23:07 ` [Bug tree-optimization/114965] [14/15 Regression] " pinskia at gcc dot gnu.org
2024-05-06 23:08 ` pinskia at gcc dot gnu.org
2024-05-06 23:10 ` [Bug tree-optimization/114965] [13/14/15 " pinskia at gcc dot gnu.org
2024-05-06 23:35 ` pinskia at gcc dot gnu.org
2024-05-06 23:45 ` pinskia at gcc dot gnu.org
2024-05-07  4:45 ` sjames at gcc dot gnu.org
2024-05-07  8:51 ` rguenth at gcc dot gnu.org
2024-05-07  9:49 ` sjames at gcc dot gnu.org
2024-05-07 11:25 ` jakub at gcc dot gnu.org
2024-05-07 11:49 ` jakub at gcc dot gnu.org
2024-05-07 16:24 ` jakub at gcc dot gnu.org
2024-05-07 16:38 ` eggert at cs dot ucla.edu
2024-05-08  8:18 ` cvs-commit at gcc dot gnu.org
2024-05-08  8:19 ` cvs-commit at gcc dot gnu.org
2024-05-08  8:20 ` [Bug tree-optimization/114965] [13 " jakub at gcc dot gnu.org
2024-05-09  4:27 ` cvs-commit at gcc dot gnu.org
2024-05-09  8:19 ` jakub at gcc dot gnu.org

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).