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

            Bug ID: 118612
           Summary: return value loaded despite noreturn attribute
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: drepper.fsp+rhbz at gmail dot com
  Target Milestone: ---

The following code is, as can be seen, stand-alone with the definition of error
from glibc inlined.  The generated code for -O2 (gcc 15, 14, haven't tested
others):

0000000000000000 <f>:
   0:   85 ff                   test   %edi,%edi
   2:   75 03                   jne    7 <f+0x7>
   4:   31 c0                   xor    %eax,%eax
   6:   c3                      ret
   7:   ba 00 00 00 00          mov    $0x0,%edx
   c:   50                      push   %rax
   d:   31 f6                   xor    %esi,%esi
   f:   bf 01 00 00 00          mov    $0x1,%edi
  14:   31 c0                   xor    %eax,%eax
  16:   e8 00 00 00 00          call   1b <f+0x1b>

The problem is at address 0x14.  This is the return value of 'f' but, as the
compiler correctly determines, 'error' will not return and therefore this load
is unnecessary.


extern void __error_alias(int __status, int __errnum, const char *__format,
...) __asm__("error")
  __attribute__ ((__format__ (__printf__, 3, 4)));
extern void __error_noreturn(int __status, int __errnum, const char *__format,
...) __asm__("error")
  __attribute__ ((__noreturn__, __format__ (__printf__, 3, 4)));


extern inline __attribute__ ((__gnu_inline__)) void
error (int __status, int __errnum, const char *__format, ...)
{
  if (__builtin_constant_p (__status) && __status != 0)
    __error_noreturn (__status, __errnum, __format, __builtin_va_arg_pack ());
  else
    __error_alias (__status, __errnum, __format, __builtin_va_arg_pack ());
}


int f(int a)
{
  if (a)
    error(1, 0, "string");
  return 0;
}

Reply via email to