xref: /titanic_52/usr/src/uts/common/sys/ccompile.h (revision bdfc6d18da790deeec2e0eb09c625902defe2498)
1 /*
2  * CDDL HEADER START
3  *
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
7  * with the License.
8  *
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.
13  *
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]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_CCOMPILE_H
28 #define	_SYS_CCOMPILE_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 /*
33  * This file contains definitions designed to enable different compilers
34  * to be used harmoniously on Solaris systems.
35  */
36 
37 #ifdef	__cplusplus
38 extern "C" {
39 #endif
40 
41 /*
42  * Allow for version tests for compiler bugs and features.
43  */
44 #if defined(__GNUC__)
45 #define	__GNUC_VERSION	\
46 	(__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
47 #else
48 #define	__GNUC_VERSION	0
49 #endif
50 
51 #if defined(__ATTRIBUTE_IMPLEMENTED) || defined(__GNUC__)
52 
53 /*
54  * analogous to lint's PRINTFLIKEn
55  */
56 #define	__sun_attr___PRINTFLIKE__(__n)	\
57 		__attribute__((__format__(printf, __n, (__n)+1)))
58 #define	__sun_attr___VPRINTFLIKE__(__n)	\
59 		__attribute__((__format__(printf, __n, 0)))
60 
61 /*
62  * Handle the kernel printf routines that can take '%b' too
63  */
64 #if __GNUC_VERSION < 30402
65 /*
66  * XX64 at least this doesn't work correctly yet with 3.4.1 anyway!
67  */
68 #define	__sun_attr___KPRINTFLIKE__	__sun_attr___PRINTFLIKE__
69 #define	__sun_attr___KVPRINTFLIKE__	__sun_attr___VPRINTFLIKE__
70 #else
71 #define	__sun_attr___KPRINTFLIKE__(__n)	\
72 		__attribute__((__format__(cmn_err, __n, (__n)+1)))
73 #define	__sun_attr___KVPRINTFLIKE__(__n) \
74 		__attribute__((__format__(cmn_err, __n, 0)))
75 #endif
76 
77 /*
78  * This one's pretty obvious -- the function never returns
79  */
80 #define	__sun_attr___noreturn__ __attribute__((__noreturn__))
81 
82 
83 /*
84  * This is an appropriate label for functions that do not
85  * modify their arguments, e.g. strlen()
86  */
87 #define	__sun_attr___pure__	__attribute__((__pure__))
88 
89 /*
90  * This is a stronger form of __pure__. Can be used for functions
91  * that do not modify their arguments and don't depend on global
92  * memory.
93  */
94 #define	__sun_attr___const__	__attribute__((__const__))
95 
96 /*
97  * structure packing like #pragma pack(1)
98  */
99 #define	__sun_attr___packed__	__attribute__((__packed__))
100 
101 #define	___sun_attr_inner(__a)	__sun_attr_##__a
102 #define	__sun_attr__(__a)	___sun_attr_inner __a
103 
104 #else	/* __ATTRIBUTE_IMPLEMENTED || __GNUC__ */
105 
106 #define	__sun_attr__(__a)
107 
108 #endif	/* __ATTRIBUTE_IMPLEMENTED || __GNUC__ */
109 
110 /*
111  * Shorthand versions for readability
112  */
113 
114 #define	__PRINTFLIKE(__n)	__sun_attr__((__PRINTFLIKE__(__n)))
115 #define	__VPRINTFLIKE(__n)	__sun_attr__((__VPRINTFLIKE__(__n)))
116 #define	__KPRINTFLIKE(__n)	__sun_attr__((__KPRINTFLIKE__(__n)))
117 #define	__KVPRINTFLIKE(__n)	__sun_attr__((__KVPRINTFLIKE__(__n)))
118 #define	__NORETURN		__sun_attr__((__noreturn__))
119 #define	__CONST			__sun_attr__((__const__))
120 #define	__PURE			__sun_attr__((__pure__))
121 
122 
123 #ifdef	__cplusplus
124 }
125 #endif
126 
127 #endif	/* _SYS_CCOMPILE_H */
128