[llvm-bugs] [Bug 45839] New: std::terminate() and abort() do not have __builtin_unreachable() semantics

via llvm-bugs llvm-bugs at lists.llvm.org
Fri May 8 02:11:08 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=45839

            Bug ID: 45839
           Summary: std::terminate() and abort() do not have
                    __builtin_unreachable() semantics
           Product: clang
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: s_bugzilla at nedprod.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

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

```
#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?

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200508/4c1278c0/attachment.html>


More information about the llvm-bugs mailing list