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

            Bug ID: 106267
           Summary: #pragma GCC diagnostic ignored not preserved for a
                    -Wattribute-alias warning
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: preprocessor
          Assignee: unassigned at gcc dot gnu.org
          Reporter: marxin at gcc dot gnu.org
  Target Milestone: ---

For the following code snippet isolated from Linux kernel the ignored
-Wattribute-alias is not preserved:

$ cat posix-stubs.c
#define __diag_GCC(version, severity, s)                                      
\
  __diag_GCC_##version(__diag_GCC_##severity s)
#define __diag_GCC_ignore ignored
#define __diag_str1(s) #s
#define __diag_str(s) __diag_str1(s)
#define __diag(s) _Pragma(__diag_str(GCC diagnostic s))
#define __diag_GCC_8(s) __diag(s)
#define __diag_pop() __diag(pop)
#define __diag_push()   __diag(push)
#define __diag_ignore(compiler, version, option, comment)                     
\
  __diag_##compiler(version, ignore, option)

#define SYSCALL_ALIAS_PROTO(a) \
        __diag_push(); \
        __diag_ignore(GCC, 8, "-Wattribute-alias", \
                        "Alias to nonimplemented syscall"); \
        typeof(a) a __attribute__((alias("sys_ni_posix_timers"))); \
        __diag_pop()

int sys_timer_create(int);
void sys_ni_posix_timers(void) {}

#define SYS_NI(name) SYSCALL_ALIAS_PROTO(sys_##name)
SYS_NI(timer_create)

$ gcc posix-stubs.c -c -Werror
posix-stubs.c:23:42: error: ‘sys_timer_create’ alias between functions of
incompatible types ‘int(int)’ and ‘void(void)’ [-Werror=attribute-alias=]
   23 | #define SYS_NI(name) SYSCALL_ALIAS_PROTO(sys_##name)
      |                                          ^~~~
posix-stubs.c:17:19: note: in definition of macro ‘SYSCALL_ALIAS_PROTO’
   17 |         typeof(a) a __attribute__((alias("sys_ni_posix_timers"))); \
      |                   ^
posix-stubs.c:24:1: note: in expansion of macro ‘SYS_NI’
   24 | SYS_NI(timer_create)
      | ^~~~~~
posix-stubs.c:21:6: note: aliased declaration here
   21 | void sys_ni_posix_timers(void) {}
      |      ^~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors

While using pre-processed input works correctly:

$ gcc posix-stubs.c -c -Werror -E > posix-stubs.i && gcc posix-stubs.i -c
-Werror

Reply via email to