4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 * Copyright 2015 EveryCity Ltd. All rights reserved.
30 #ifndef _SYS_CCOMPILE_H
31 #define _SYS_CCOMPILE_H
34 * This file contains definitions designed to enable different compilers
35 * to be used harmoniously on Solaris systems.
43 * Allow for version tests for compiler bugs and features.
46 #define __GNUC_VERSION \
47 (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
49 #define __GNUC_VERSION 0
52 #if defined(__ATTRIBUTE_IMPLEMENTED) || defined(__GNUC__)
55 * analogous to lint's PRINTFLIKEn
57 #define __sun_attr___PRINTFLIKE__(__n) \
58 __attribute__((__format__(printf, __n, (__n)+1)))
59 #define __sun_attr___VPRINTFLIKE__(__n) \
60 __attribute__((__format__(printf, __n, 0)))
63 * Handle the kernel printf routines that can take '%b' too
65 #if __GNUC_VERSION < 30402
67 * XX64 at least this doesn't work correctly yet with 3.4.1 anyway!
69 #define __sun_attr___KPRINTFLIKE__ __sun_attr___PRINTFLIKE__
70 #define __sun_attr___KVPRINTFLIKE__ __sun_attr___VPRINTFLIKE__
72 #define __sun_attr___KPRINTFLIKE__(__n) \
73 __attribute__((__format__(cmn_err, __n, (__n)+1)))
74 #define __sun_attr___KVPRINTFLIKE__(__n) \
75 __attribute__((__format__(cmn_err, __n, 0)))
79 * This one's pretty obvious -- the function never returns
81 #define __sun_attr___noreturn__ __attribute__((__noreturn__))
84 * The function is 'extern inline' and expects GNU C89 behaviour, not C99
87 * Should only be used on 'extern inline' definitions for GCC.
89 #if __GNUC_VERSION >= 40200
90 #define __sun_attr___gnu_inline__ __attribute__((__gnu_inline__))
92 #define __sun_attr___gnu_inline__
96 * The function has control flow such that it may return multiple times (in
97 * the manner of setjmp or vfork)
99 #if __GNUC_VERSION >= 40100
100 #define __sun_attr___returns_twice__ __attribute__((__returns_twice__))
102 #define __sun_attr___returns_twice__
106 * This is an appropriate label for functions that do not
107 * modify their arguments, e.g. strlen()
109 #define __sun_attr___pure__ __attribute__((__pure__))
112 * This is a stronger form of __pure__. Can be used for functions
113 * that do not modify their arguments and don't depend on global
116 #define __sun_attr___const__ __attribute__((__const__))
118 #if __GNUC_VERSION >= 20700
119 #define __aligned(x) __attribute__((__aligned__(x)))
121 * This attribute, attached to a variable, means that the variable is meant to
122 * be possibly unused. GCC will not produce a warning for this variable.
124 #define __sun_attr___unused__ __attribute__((__unused__))
127 #define ___sun_attr_inner(__a) __sun_attr_##__a
128 #define __sun_attr__(__a) ___sun_attr_inner __a
130 #else /* __ATTRIBUTE_IMPLEMENTED || __GNUC__ */
133 #define __sun_attr__(__a)
134 #define __sun_attr___unused__
136 #endif /* __ATTRIBUTE_IMPLEMENTED || __GNUC__ */
139 * Shorthand versions for readability
142 #define __PRINTFLIKE(__n) __sun_attr__((__PRINTFLIKE__(__n)))
143 #define __VPRINTFLIKE(__n) __sun_attr__((__VPRINTFLIKE__(__n)))
144 #define __KPRINTFLIKE(__n) __sun_attr__((__KPRINTFLIKE__(__n)))
145 #define __KVPRINTFLIKE(__n) __sun_attr__((__KVPRINTFLIKE__(__n)))
146 #define __NORETURN __sun_attr__((__noreturn__))
147 #define __GNU_INLINE __inline__ __sun_attr__((__gnu_inline__))
148 #define __RETURNS_TWICE __sun_attr__((__returns_twice__))
149 #define __CONST __sun_attr__((__const__))
150 #define __PURE __sun_attr__((__pure__))
151 #define __packed __attribute__((__packed__))
152 #define __unused __sun_attr__((__unused__))
158 #endif /* _SYS_CCOMPILE_H */