diff options
author | pfg <pfg@FreeBSD.org> | 2015-03-26 16:00:35 +0000 |
---|---|---|
committer | pfg <pfg@FreeBSD.org> | 2015-03-26 16:00:35 +0000 |
commit | d37730a0c44e508531c8685077265253867263f9 (patch) | |
tree | 1a5ac7b6dc0e1d07a4bc01ac4b1d7a5577306787 /sys/sys/cdefs.h | |
parent | c504b60c4e6b6cb26d1387d7afc1356c1d9d4c37 (diff) | |
download | FreeBSD-src-d37730a0c44e508531c8685077265253867263f9.zip FreeBSD-src-d37730a0c44e508531c8685077265253867263f9.tar.gz |
Introduce some allocation function attributes.
Bring support for two gcc function attributes that are likely to be used
in our system headers:
__alloc_size
The alloc_size attribute is used to tell the compiler that the function
return value points to memory, where the size is given by one or two of
the functions parameters.
__result_use_check
Causes a warning to be emitted if a caller of the function with this
attribute does not use its return value. This is known in gcc as
"warn_unused_result" but we considered the original naming unsuitable
for an attribute.
The __alloc_size attribute required some workarounds for lint(1).
Both attributes are supported by clang.
Also see: D2107
MFC after: 3 days
Diffstat (limited to 'sys/sys/cdefs.h')
-rw-r--r-- | sys/sys/cdefs.h | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/sys/sys/cdefs.h b/sys/sys/cdefs.h index 3fd5175..b963345 100644 --- a/sys/sys/cdefs.h +++ b/sys/sys/cdefs.h @@ -40,6 +40,9 @@ * Testing against Clang-specific extensions. */ +#ifndef __has_attribute +#define __has_attribute(x) 0 +#endif #ifndef __has_extension #define __has_extension __has_feature #endif @@ -209,6 +212,7 @@ #define __unused #define __packed #define __aligned(x) +#define __alloc_size(...) #define __section(x) #define __weak #else @@ -233,6 +237,11 @@ #define __aligned(x) __attribute__((__aligned__(x))) #define __section(x) __attribute__((__section__(x))) #endif +#if __has_attribute(alloc_size) || __GNUC_PREREQ__(4, 3) +#define __alloc_size(...) __attribute__((alloc_size(__VA_ARGS__))) +#else +#define __alloc_size(...) +#endif #if defined(__INTEL_COMPILER) #define __dead2 __attribute__((__noreturn__)) #define __pure2 __attribute__((__const__)) @@ -242,7 +251,7 @@ #define __aligned(x) __attribute__((__aligned__(x))) #define __section(x) __attribute__((__section__(x))) #endif -#endif +#endif /* lint */ #if !__GNUC_PREREQ__(2, 95) #define __alignof(x) __offsetof(struct { char __a; x __b; }, __b) @@ -363,8 +372,10 @@ #if __GNUC_PREREQ__(3, 4) #define __fastcall __attribute__((__fastcall__)) +#define __result_use_check __attribute__((__warn_unused_result__)) #else #define __fastcall +#define __result_use_check #endif #if __GNUC_PREREQ__(4, 1) |