public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/94383] New: [8/9/10 Regression] class with empty base passed incorrectly with -std=c++17
@ 2020-03-28 15:54 redi at gcc dot gnu.org
  2020-03-28 15:55 ` [Bug target/94383] " redi at gcc dot gnu.org
                   ` (20 more replies)
  0 siblings, 21 replies; 22+ messages in thread
From: redi at gcc dot gnu.org @ 2020-03-28 15:54 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 94383
           Summary: [8/9/10 Regression] class with empty base passed
                    incorrectly with -std=c++17
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Keywords: ABI
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
  Target Milestone: ---
            Target: aarch64-*-linux

This code is miscompiled on aarch64 with -std=c++17, apparently due to the
empty base class:

struct base { };
struct pair : base
{
  float first;
  float second;
  pair(float f, float s) : first(f), second(s) { }
};

void f(pair);

int main()
{
  f({3.14, 666});
}

It is wrong with any optimization level, but with -std=gnu++14 -O1 we get:

main:
        stp     x29, x30, [sp, -16]!
        mov     x29, sp
        mov     x0, 0
        mov     x1, 62915
        movk    x1, 0x4048, lsl 16
        bfi     x0, x1, 0, 32
        mov     x1, 32768
        movk    x1, 0x4426, lsl 16
        bfi     x0, x1, 32, 32
        lsr     w1, w0, 0
        fmov    d0, x0
        ushr    d1, d0, 32
        fmov    s0, w1
        bl      f(pair)
        mov     w0, 0
        ldp     x29, x30, [sp], 16
        ret

With -std=gnu++17 -O1 we get:

main:
        stp     x29, x30, [sp, -16]!
        mov     x29, sp
        mov     x0, 0
        mov     x1, 62915
        movk    x1, 0x4048, lsl 16
        bfi     x0, x1, 0, 32
        mov     x1, 32768
        movk    x1, 0x4426, lsl 16
        bfi     x0, x1, 32, 32
        bl      f(pair)
        mov     w0, 0
        ldp     x29, x30, [sp], 16
        ret

If the translation unit containing the called function is:

struct base { };
struct pair : base
{
  float first;
  float second;
  pair(float f, float s) : first(f), second(s) { }
};

void f(pair lr)
{
  __builtin_printf("%f %f\n", lr.first, lr.second);
}

and the caller is compiled with -std=gnu++14 and the callee is compiled with
-std=gnu++17 then the callee prints garabage:

-13874.335938 0.000000

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

end of thread, other threads:[~2021-11-05 23:18 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-28 15:54 [Bug target/94383] New: [8/9/10 Regression] class with empty base passed incorrectly with -std=c++17 redi at gcc dot gnu.org
2020-03-28 15:55 ` [Bug target/94383] " redi at gcc dot gnu.org
2020-03-28 16:01 ` redi at gcc dot gnu.org
2020-03-28 17:37 ` [Bug target/94383] [8/9/10 Regression] class with empty base passed incorrectly with -std=c++17 on aarch64 redi at gcc dot gnu.org
2020-03-28 17:39 ` redi at gcc dot gnu.org
2020-03-28 18:00 ` mpolacek at gcc dot gnu.org
2020-03-28 19:26 ` pinskia at gcc dot gnu.org
2020-03-30  8:13 ` rguenth at gcc dot gnu.org
2020-03-30 14:04 ` jakub at gcc dot gnu.org
2020-03-30 14:38 ` jakub at gcc dot gnu.org
2020-04-15 15:38 ` jakub at gcc dot gnu.org
2020-04-16 14:08 ` matmal01 at gcc dot gnu.org
2020-04-16 14:14 ` jakub at gcc dot gnu.org
2020-04-20 18:21 ` jakub at gcc dot gnu.org
2020-04-21 15:10 ` cvs-commit at gcc dot gnu.org
2020-04-22 12:10 ` jakub at gcc dot gnu.org
2020-04-22 14:47 ` cvs-commit at gcc dot gnu.org
2020-04-23 14:34 ` cvs-commit at gcc dot gnu.org
2020-04-23 14:38 ` jakub at gcc dot gnu.org
2020-04-23 16:54 ` redi at gcc dot gnu.org
2020-04-24 17:15 ` cvs-commit at gcc dot gnu.org
2021-11-05 23:18 ` timturnerc at yahoo dot com

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