public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "chfast at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/110020] New: [13/14 Regression] SHA2 misscompilation at -O3
Date: Mon, 29 May 2023 11:34:43 +0000	[thread overview]
Message-ID: <bug-110020-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 110020
           Summary: [13/14 Regression] SHA2 misscompilation at -O3
           Product: gcc
           Version: 13.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: chfast at gmail dot com
  Target Milestone: ---

This is a test case reduced from a C implementation of SHA256.

void test(unsigned h[8]) {
    for (unsigned i = 0; i < 2; i++) {

        unsigned w[16];
        for (unsigned j = 0; j < 16; j++) {
            if (i == 0)
                w[j] = 0;

            h[7] = h[6];
            h[6] = h[5];
            h[5] = h[4];
            h[4] = h[3];
            h[3] = h[2];
            h[2] = h[1];
            h[1] = h[0];
            h[0] += w[j];
        }
    }
}

It looks that at -O3 compiler looses track of w[j] = 0 and uses uninitialized
stack storage.

test:
        movl    -36(%rsp), %ecx
        movl    -68(%rsp), %eax
        movq    %rdi, %rdx
        movl    -32(%rsp), %esi
        addl    -72(%rsp), %eax
        addl    -64(%rsp), %eax
        addl    -60(%rsp), %eax
        addl    -56(%rsp), %eax
        addl    -52(%rsp), %eax
        addl    -48(%rsp), %eax
        addl    -44(%rsp), %eax
        addl    -40(%rsp), %eax
        addl    (%rdi), %eax
        addl    %eax, %ecx
        movl    -28(%rsp), %edi
        movl    -24(%rsp), %r8d
        movl    %eax, 28(%rdx)
        addl    %ecx, %esi
        movl    -20(%rsp), %r9d
        movl    -16(%rsp), %r10d
        movl    %ecx, 24(%rdx)
        addl    %esi, %edi
        movl    -12(%rsp), %r11d
        movl    %esi, 20(%rdx)
        addl    %edi, %r8d
        movl    %edi, 16(%rdx)
        addl    %r8d, %r9d
        movl    %r8d, 12(%rdx)
        addl    %r9d, %r10d
        movl    %r9d, 8(%rdx)
        addl    %r10d, %r11d
        movl    %r10d, 4(%rdx)
        movl    %r11d, (%rdx)
        ret 


https://godbolt.org/z/ff7E9sd94

             reply	other threads:[~2023-05-29 11:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-29 11:34 chfast at gmail dot com [this message]
2023-05-29 12:01 ` [Bug tree-optimization/110020] " jakub at gcc dot gnu.org
2023-05-29 12:16 ` chfast at gmail dot com

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