public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/110938] New: miscompile if implicit special member is deleted in a subtle way
@ 2023-08-07 21:21 richard-gccbugzilla at metafoo dot co.uk
  2023-08-07 21:32 ` [Bug c++/110938] miscompile if implicit special member is deleted and mutable pinskia at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: richard-gccbugzilla at metafoo dot co.uk @ 2023-08-07 21:21 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110938
           Summary: miscompile if implicit special member is deleted in a
                    subtle way
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: richard-gccbugzilla at metafoo dot co.uk
  Target Milestone: ---

Testcase: https://godbolt.org/z/rKG8c166f

```
template<typename T> struct Error {
  //static_assert(false);
  using type = T;
};

template<typename T> using ArbitraryComputation = typename Error<T>::type;

struct X {
  template<typename T = X> X(ArbitraryComputation<T> &) = delete;
  X(const X&) = default;
  X(X&&) = delete;
};

struct Y {
#if 0
  Y(const Y&) = default;
  Y(Y&&) = default;
#endif
  mutable X x;
  int n;
};

void print(int);

Y f();

void g() {
  print(f().n);
}
```

Uncommenting the `static_assert`, we can see that GCC never instantiates
`Error<X>` in this example. But it must! If `ArbitraryComputation<X>` evaluates
to `T`, then the non-trivial, templated constructor in `X` is used to copy the
member `Y::x`, so `Y` is not trivially-copyable.

This issue affects both type traits (GCC incorrectly evaluates
`__is_trivially_copyable(Y)` to true) and code generation (GCC emits `f()` as
returning in registers, which is both non-compliant with the ABI and doesn't
follow the C++ language rules because `Y` has no trivial copy or move
constructor).

If the `#if 0` is changed to `#if 1`, the problem disappears.

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

* [Bug c++/110938] miscompile if implicit special member is deleted and mutable
  2023-08-07 21:21 [Bug c++/110938] New: miscompile if implicit special member is deleted in a subtle way richard-gccbugzilla at metafoo dot co.uk
@ 2023-08-07 21:32 ` pinskia at gcc dot gnu.org
  2023-08-07 21:35 ` [Bug c++/110938] [11/12/13/14 Regression] " pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-07 21:32 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|miscompile if implicit      |miscompile if implicit
                   |special member is deleted   |special member is deleted
                   |in a subtle way             |and mutable

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Reduced:
```
struct X {
  X(X &) = delete;
  X(X&&) = delete;
  X(const X&) = default;
};

struct Y {
#if 1
  mutable
#endif
   X x;
  int n;
};

void print(int);

Y f();

void g() {
  print(f().n);
}
```

If we change `#if 1` to `#if 0` then GCC does the correct thing.

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

* [Bug c++/110938] [11/12/13/14 Regression] miscompile if implicit special member is deleted and mutable
  2023-08-07 21:21 [Bug c++/110938] New: miscompile if implicit special member is deleted in a subtle way richard-gccbugzilla at metafoo dot co.uk
  2023-08-07 21:32 ` [Bug c++/110938] miscompile if implicit special member is deleted and mutable pinskia at gcc dot gnu.org
@ 2023-08-07 21:35 ` pinskia at gcc dot gnu.org
  2023-08-07 21:40 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-07 21:35 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |11.5
            Summary|miscompile if implicit      |[11/12/13/14 Regression]
                   |special member is deleted   |miscompile if implicit
                   |and mutable                 |special member is deleted
                   |                            |and mutable
      Known to work|                            |4.7.1, 4.8.1
      Known to fail|                            |4.9.0, 5.1.0, 7.1.0

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

* [Bug c++/110938] [11/12/13/14 Regression] miscompile if implicit special member is deleted and mutable
  2023-08-07 21:21 [Bug c++/110938] New: miscompile if implicit special member is deleted in a subtle way richard-gccbugzilla at metafoo dot co.uk
  2023-08-07 21:32 ` [Bug c++/110938] miscompile if implicit special member is deleted and mutable pinskia at gcc dot gnu.org
  2023-08-07 21:35 ` [Bug c++/110938] [11/12/13/14 Regression] " pinskia at gcc dot gnu.org
@ 2023-08-07 21:40 ` pinskia at gcc dot gnu.org
  2023-08-08 10:31 ` redi at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-07 21:40 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note 4.8.5 (and before), seems to have the wrong ABI for non-mutable case too.

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

* [Bug c++/110938] [11/12/13/14 Regression] miscompile if implicit special member is deleted and mutable
  2023-08-07 21:21 [Bug c++/110938] New: miscompile if implicit special member is deleted in a subtle way richard-gccbugzilla at metafoo dot co.uk
                   ` (2 preceding siblings ...)
  2023-08-07 21:40 ` pinskia at gcc dot gnu.org
@ 2023-08-08 10:31 ` redi at gcc dot gnu.org
  2023-08-08 19:18 ` richard-gccbugzilla at metafoo dot co.uk
  2023-11-16  0:43 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2023-08-08 10:31 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
The 4.9.0 regression to return Y in a register seems to have happened with:

commit 3b6d16993b9d6812f6212bce4f35547fd9e40457 [r0-126146-g3b6d16993b9d68]
Author: Vladimir Makarov
Date:   Wed Oct 30 14:27:25 2013

    regmove.c: Remove.

But I don't think that will have affected the __is_trivially_copyable(Y)
result.

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

* [Bug c++/110938] [11/12/13/14 Regression] miscompile if implicit special member is deleted and mutable
  2023-08-07 21:21 [Bug c++/110938] New: miscompile if implicit special member is deleted in a subtle way richard-gccbugzilla at metafoo dot co.uk
                   ` (3 preceding siblings ...)
  2023-08-08 10:31 ` redi at gcc dot gnu.org
@ 2023-08-08 19:18 ` richard-gccbugzilla at metafoo dot co.uk
  2023-11-16  0:43 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: richard-gccbugzilla at metafoo dot co.uk @ 2023-08-08 19:18 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Richard Smith <richard-gccbugzilla at metafoo dot co.uk> ---
Looks like the trait difference only happens if the templated constructor is
not deleted, but the ABI mismatch happens regardless. Possibly there are two
separate issues here?

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

* [Bug c++/110938] [11/12/13/14 Regression] miscompile if implicit special member is deleted and mutable
  2023-08-07 21:21 [Bug c++/110938] New: miscompile if implicit special member is deleted in a subtle way richard-gccbugzilla at metafoo dot co.uk
                   ` (4 preceding siblings ...)
  2023-08-08 19:18 ` richard-gccbugzilla at metafoo dot co.uk
@ 2023-11-16  0:43 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-11-16  0:43 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #3)
> But I don't think that will have affected the __is_trivially_copyable(Y)
> result.

Maybe the __is_trivially_copyable is due to the same reason why PR 112544 shows
up; ::operator= is not synthesized to be deleted yet.

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

end of thread, other threads:[~2023-11-16  0:43 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-07 21:21 [Bug c++/110938] New: miscompile if implicit special member is deleted in a subtle way richard-gccbugzilla at metafoo dot co.uk
2023-08-07 21:32 ` [Bug c++/110938] miscompile if implicit special member is deleted and mutable pinskia at gcc dot gnu.org
2023-08-07 21:35 ` [Bug c++/110938] [11/12/13/14 Regression] " pinskia at gcc dot gnu.org
2023-08-07 21:40 ` pinskia at gcc dot gnu.org
2023-08-08 10:31 ` redi at gcc dot gnu.org
2023-08-08 19:18 ` richard-gccbugzilla at metafoo dot co.uk
2023-11-16  0:43 ` pinskia 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).