public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "eggert at cs dot ucla.edu" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/114965] New: wrong code generated for Emacs/Gnulib strftime (regression from 13.2)
Date: Mon, 06 May 2024 22:17:55 +0000	[thread overview]
Message-ID: <bug-114965-4@http.gcc.gnu.org/bugzilla/> (raw)

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

             reply	other threads:[~2024-05-06 22:17 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-06 22:17 eggert at cs dot ucla.edu [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-114965-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).