public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/95001] New: std::terminate() and abort() do not have __builtin_unreachable() semantics
@ 2020-05-08  9:07 s_gccbugzilla at nedprod dot com
  2020-05-08  9:44 ` [Bug tree-optimization/95001] " pinskia at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: s_gccbugzilla at nedprod dot com @ 2020-05-08  9:07 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 95001
           Summary: std::terminate() and abort() do not have
                    __builtin_unreachable() semantics
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: s_gccbugzilla at nedprod dot com
  Target Milestone: ---

Consider the codegen from https://godbolt.org/z/xhmBrL:

```
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <exception>

void sum(uint32_t *__restrict a, const uint32_t *__restrict b, const uint32_t
*__restrict c, size_t count)
{
    auto invoke_terminate = []{
#ifdef USE_UNREACHABLE
        __builtin_unreachable();
#else
        std::terminate();
#endif
    };
    if((((uintptr_t)a) & 15)!=0) invoke_terminate();
    if((((uintptr_t)b) & 15)!=0) invoke_terminate();
    if((((uintptr_t)c) & 15)!=0) invoke_terminate();
    if((count & 15) != 0) invoke_terminate();
    while(count != 0)
    {
        *a++ = *b++ + *c++;
        count--;
    }
}
```

It would seem that functions marked with both [[noreturn]] and noexcept do not
have the same improvements on codegen as __builtin_unreachable() has. This is
despite that [[noreturn]] functions returning is explicitly required to be UB
in the standard, and if they are noexcept then they cannot throw an exception
either.

Can noexcept functions marked [[noreturn]] please gain the same effects on
codegen as __builtin_unreachable() has please?

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

* [Bug tree-optimization/95001] std::terminate() and abort() do not have __builtin_unreachable() semantics
  2020-05-08  9:07 [Bug c++/95001] New: std::terminate() and abort() do not have __builtin_unreachable() semantics s_gccbugzilla at nedprod dot com
@ 2020-05-08  9:44 ` pinskia at gcc dot gnu.org
  2020-05-08 11:26 ` rguenth at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2020-05-08  9:44 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization
          Component|c++                         |tree-optimization
           Severity|normal                      |enhancement

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

* [Bug tree-optimization/95001] std::terminate() and abort() do not have __builtin_unreachable() semantics
  2020-05-08  9:07 [Bug c++/95001] New: std::terminate() and abort() do not have __builtin_unreachable() semantics s_gccbugzilla at nedprod dot com
  2020-05-08  9:44 ` [Bug tree-optimization/95001] " pinskia at gcc dot gnu.org
@ 2020-05-08 11:26 ` rguenth at gcc dot gnu.org
  2020-05-08 11:43 ` jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-05-08 11:26 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Sorry, but noreturn functions can have side-effects that need to be preserved.

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

* [Bug tree-optimization/95001] std::terminate() and abort() do not have __builtin_unreachable() semantics
  2020-05-08  9:07 [Bug c++/95001] New: std::terminate() and abort() do not have __builtin_unreachable() semantics s_gccbugzilla at nedprod dot com
  2020-05-08  9:44 ` [Bug tree-optimization/95001] " pinskia at gcc dot gnu.org
  2020-05-08 11:26 ` rguenth at gcc dot gnu.org
@ 2020-05-08 11:43 ` jakub at gcc dot gnu.org
  2020-05-08 12:16 ` glisse at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-05-08 11:43 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
My understanding of the request is to handle other noreturn functions in
assert_unreachable_fallthru_edge_p (or in callers of that function next to that
predicate), probably with similar requirements that there is no code before the
noreturn call.  Though, I think that is something we can't do, for
__builtin_unreachable we can add the range info on the guarding SSA_NAME
because otherwise the program invokes UB.  That is not the case with abort or
std::terminate, the program doesn't invoke UB, just calls the noreturn
function.

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

* [Bug tree-optimization/95001] std::terminate() and abort() do not have __builtin_unreachable() semantics
  2020-05-08  9:07 [Bug c++/95001] New: std::terminate() and abort() do not have __builtin_unreachable() semantics s_gccbugzilla at nedprod dot com
                   ` (2 preceding siblings ...)
  2020-05-08 11:43 ` jakub at gcc dot gnu.org
@ 2020-05-08 12:16 ` glisse at gcc dot gnu.org
  2020-05-08 12:24 ` jakub at gcc dot gnu.org
  2020-05-08 12:42 ` s_gccbugzilla at nedprod dot com
  5 siblings, 0 replies; 7+ messages in thread
From: glisse at gcc dot gnu.org @ 2020-05-08 12:16 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Marc Glisse <glisse at gcc dot gnu.org> ---
Simpler example:

[[noreturn]] void theend();

int f(int x){
  if(x&7)theend();
  return x&3;
}

(or replace "theend()" with "throw 42")

We shouldn't compute x&3, it is always 0 in the branch where it is computed.

But this simple example would probably be doable similarly to VRP, while the
original example requires that the information be available during another pass
(on-demand non-zero bits, like there is work on on-demand ranges?).

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

* [Bug tree-optimization/95001] std::terminate() and abort() do not have __builtin_unreachable() semantics
  2020-05-08  9:07 [Bug c++/95001] New: std::terminate() and abort() do not have __builtin_unreachable() semantics s_gccbugzilla at nedprod dot com
                   ` (3 preceding siblings ...)
  2020-05-08 12:16 ` glisse at gcc dot gnu.org
@ 2020-05-08 12:24 ` jakub at gcc dot gnu.org
  2020-05-08 12:42 ` s_gccbugzilla at nedprod dot com
  5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-05-08 12:24 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
The on-demand VRP (or if it can do non-zero bits too, even better), ought to
handle this kind of things, but it isn't something we can store in the
SSA_NAMEs unless we create the ASSERT_EXPRs (which means during VRP only).

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

* [Bug tree-optimization/95001] std::terminate() and abort() do not have __builtin_unreachable() semantics
  2020-05-08  9:07 [Bug c++/95001] New: std::terminate() and abort() do not have __builtin_unreachable() semantics s_gccbugzilla at nedprod dot com
                   ` (4 preceding siblings ...)
  2020-05-08 12:24 ` jakub at gcc dot gnu.org
@ 2020-05-08 12:42 ` s_gccbugzilla at nedprod dot com
  5 siblings, 0 replies; 7+ messages in thread
From: s_gccbugzilla at nedprod dot com @ 2020-05-08 12:42 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Niall Douglas <s_gccbugzilla at nedprod dot com> ---
Just to clarify what I'm asking for:

Calling a [[noreturn]] function ought to have the same effects on codegen as:

```
[[noreturn]] void theend();
...
if(a)
{
  theend();
  __builtin_unreachable();
}
```

Right now, the [[noreturn]] attribute causes the __builtin_unreachable() to be
ignored, which is not helpful.

I think there should be an implicit __builtin_unreachable() if a [[noreturn]]
function ever would return. To be specific here: I only care about codegen.

If that's not doable, can you please make a __builtin_unreachable() called
after a [[noreturn]] function not be ignored please?

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

end of thread, other threads:[~2020-05-08 12:42 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-08  9:07 [Bug c++/95001] New: std::terminate() and abort() do not have __builtin_unreachable() semantics s_gccbugzilla at nedprod dot com
2020-05-08  9:44 ` [Bug tree-optimization/95001] " pinskia at gcc dot gnu.org
2020-05-08 11:26 ` rguenth at gcc dot gnu.org
2020-05-08 11:43 ` jakub at gcc dot gnu.org
2020-05-08 12:16 ` glisse at gcc dot gnu.org
2020-05-08 12:24 ` jakub at gcc dot gnu.org
2020-05-08 12:42 ` s_gccbugzilla at nedprod 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).