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?