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

            Bug ID: 88574
           Summary: -Wmissing-attributes vs -Wattribute-alias=2 wrong for
                    noreturn
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

The definition of the alias fa() below is diagnosed with -Wall but the
definition  of ga() is not, despite the fact that the former is safe (and just
leads to suboptimal code) while the latter is unsafe (GCC emits code based on
the function not returning when it in fact does).

$ cat t.c && gcc -S -Wall t.c
__attribute__ ((noreturn)) void f (void) { __builtin_abort (); }

__attribute__ ((alias ("f"))) void fa (void);


void g (void) { }

__attribute__ ((alias ("g"), noreturn)) void ga (void);

t.c:3:36: warning: ‘fa’ specifies less restrictive attribute than its target
‘f’: ‘noreturn’ [-Wmissing-attributes]
    3 | __attribute__ ((alias ("f"))) void fa (void);
      |                                    ^~
t.c:1:33: note: ‘fa’ target declared here
    1 | __attribute__ ((noreturn)) void f (void) { __builtin_abort (); }
      |                                 ^


$ gcc -S -Wall -Wattribute-alias=2 t.c
t.c:3:36: warning: ‘fa’ specifies less restrictive attribute than its target
‘f’: ‘noreturn’ [-Wmissing-attributes]
    3 | __attribute__ ((alias ("f"))) void fa (void);
      |                                    ^~
t.c:1:33: note: ‘fa’ target declared here
    1 | __attribute__ ((noreturn)) void f (void) { __builtin_abort (); }
      |                                 ^
t.c:8:46: warning: ‘ga’ specifies more restrictive attribute than its target
‘g’: ‘noreturn’ [-Wattribute-alias=]
    8 | __attribute__ ((alias ("g"), noreturn)) void ga (void);
      |                                              ^~
t.c:6:6: note: ‘ga’ target declared here
    6 | void g (void) { }
      |      ^

Reply via email to