OSDN Git Service

Compiler Attributes: use feature checks instead of version checks
authorMiguel Ojeda <miguel.ojeda.sandonis@gmail.com>
Thu, 30 Aug 2018 18:36:59 +0000 (20:36 +0200)
committerMiguel Ojeda <miguel.ojeda.sandonis@gmail.com>
Sun, 30 Sep 2018 18:14:03 +0000 (20:14 +0200)
commita3f8a30f3f0079c7edfc72e329eee8594fb3e3cb
tree8855bb09c0335640b625080fe266e668d9225c16
parent66dbeef915f275dad6c8656b31667ef9640f5639
Compiler Attributes: use feature checks instead of version checks

Instead of using version checks per-compiler to define (or not)
each attribute, use __has_attribute to test for them, following
the cleanup started with commit 815f0ddb346c
("include/linux/compiler*.h: make compiler-*.h mutually exclusive"),
which is supported on gcc >= 5, clang >= 2.9 and icc >= 17.
In the meantime, to support 4.6 <= gcc < 5, we implement
__has_attribute by hand.

All the attributes that can be unconditionally defined and directly
map to compiler attribute(s) (even if optional) have been moved
to a new file include/linux/compiler_attributes.h

In an effort to make the file as regular as possible, comments
stating the purpose of attributes have been removed. Instead,
links to the compiler docs have been added (i.e. to gcc and,
if available, to clang as well). In addition, they have been sorted.

Finally, if an attribute is optional (i.e. if it is guarded
by __has_attribute), the reason has been stated for future reference.

Tested-by: Sedat Dilek <sedat.dilek@gmail.com> # on top of v4.19-rc5, clang 7
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Reviewed-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Signed-off-by: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
include/linux/compiler-clang.h
include/linux/compiler-gcc.h
include/linux/compiler-intel.h
include/linux/compiler_attributes.h [new file with mode: 0644]
include/linux/compiler_types.h