xref: /titanic_50/usr/src/uts/common/sys/ccompile.h (revision 6a3e8e8695d5c7d1d18c6800d676990d7f61a2a4)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #ifndef	_SYS_CCOMPILE_H
287c478bd9Sstevel@tonic-gate #define	_SYS_CCOMPILE_H
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate /*
317c478bd9Sstevel@tonic-gate  * This file contains definitions designed to enable different compilers
327c478bd9Sstevel@tonic-gate  * to be used harmoniously on Solaris systems.
337c478bd9Sstevel@tonic-gate  */
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
367c478bd9Sstevel@tonic-gate extern "C" {
377c478bd9Sstevel@tonic-gate #endif
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate /*
407c478bd9Sstevel@tonic-gate  * Allow for version tests for compiler bugs and features.
417c478bd9Sstevel@tonic-gate  */
427c478bd9Sstevel@tonic-gate #if defined(__GNUC__)
437c478bd9Sstevel@tonic-gate #define	__GNUC_VERSION	\
447c478bd9Sstevel@tonic-gate 	(__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
457c478bd9Sstevel@tonic-gate #else
467c478bd9Sstevel@tonic-gate #define	__GNUC_VERSION	0
477c478bd9Sstevel@tonic-gate #endif
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate #if defined(__ATTRIBUTE_IMPLEMENTED) || defined(__GNUC__)
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate /*
527c478bd9Sstevel@tonic-gate  * analogous to lint's PRINTFLIKEn
537c478bd9Sstevel@tonic-gate  */
547c478bd9Sstevel@tonic-gate #define	__sun_attr___PRINTFLIKE__(__n)	\
557c478bd9Sstevel@tonic-gate 		__attribute__((__format__(printf, __n, (__n)+1)))
567c478bd9Sstevel@tonic-gate #define	__sun_attr___VPRINTFLIKE__(__n)	\
577c478bd9Sstevel@tonic-gate 		__attribute__((__format__(printf, __n, 0)))
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate /*
607c478bd9Sstevel@tonic-gate  * Handle the kernel printf routines that can take '%b' too
617c478bd9Sstevel@tonic-gate  */
627c478bd9Sstevel@tonic-gate #if __GNUC_VERSION < 30402
637c478bd9Sstevel@tonic-gate /*
647c478bd9Sstevel@tonic-gate  * XX64 at least this doesn't work correctly yet with 3.4.1 anyway!
657c478bd9Sstevel@tonic-gate  */
667c478bd9Sstevel@tonic-gate #define	__sun_attr___KPRINTFLIKE__	__sun_attr___PRINTFLIKE__
677c478bd9Sstevel@tonic-gate #define	__sun_attr___KVPRINTFLIKE__	__sun_attr___VPRINTFLIKE__
687c478bd9Sstevel@tonic-gate #else
697c478bd9Sstevel@tonic-gate #define	__sun_attr___KPRINTFLIKE__(__n)	\
707c478bd9Sstevel@tonic-gate 		__attribute__((__format__(cmn_err, __n, (__n)+1)))
717c478bd9Sstevel@tonic-gate #define	__sun_attr___KVPRINTFLIKE__(__n) \
727c478bd9Sstevel@tonic-gate 		__attribute__((__format__(cmn_err, __n, 0)))
737c478bd9Sstevel@tonic-gate #endif
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate /*
767c478bd9Sstevel@tonic-gate  * This one's pretty obvious -- the function never returns
777c478bd9Sstevel@tonic-gate  */
787c478bd9Sstevel@tonic-gate #define	__sun_attr___noreturn__ __attribute__((__noreturn__))
797c478bd9Sstevel@tonic-gate 
806b7143d7SRichard Lowe /*
816b7143d7SRichard Lowe  * The function is 'extern inline' and expects GNU C89 behaviour, not C99
826b7143d7SRichard Lowe  * behaviour.
836b7143d7SRichard Lowe  *
846b7143d7SRichard Lowe  * Should only be used on 'extern inline' definitions for GCC.
856b7143d7SRichard Lowe  */
86*6a3e8e86SRichard Lowe #if __GNUC_VERSION >= 40200
876b7143d7SRichard Lowe #define	__sun_attr___gnu_inline__	__attribute__((__gnu_inline__))
886b7143d7SRichard Lowe #else
896b7143d7SRichard Lowe #define	__sun_attr___gnu_inline__
906b7143d7SRichard Lowe #endif
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate /*
93*6a3e8e86SRichard Lowe  * The function has control flow such that it may return multiple times (in
94*6a3e8e86SRichard Lowe  * the manner of setjmp or vfork)
95*6a3e8e86SRichard Lowe  */
96*6a3e8e86SRichard Lowe #if __GNUC_VERSION >= 40100
97*6a3e8e86SRichard Lowe #define	__sun_attr___returns_twice__	__attribute__((__returns_twice__))
98*6a3e8e86SRichard Lowe #else
99*6a3e8e86SRichard Lowe #define	__sun_attr___returns_twice__
100*6a3e8e86SRichard Lowe #endif
101*6a3e8e86SRichard Lowe 
102*6a3e8e86SRichard Lowe /*
1037c478bd9Sstevel@tonic-gate  * This is an appropriate label for functions that do not
1047c478bd9Sstevel@tonic-gate  * modify their arguments, e.g. strlen()
1057c478bd9Sstevel@tonic-gate  */
1067c478bd9Sstevel@tonic-gate #define	__sun_attr___pure__	__attribute__((__pure__))
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate /*
1097c478bd9Sstevel@tonic-gate  * This is a stronger form of __pure__. Can be used for functions
1107c478bd9Sstevel@tonic-gate  * that do not modify their arguments and don't depend on global
1117c478bd9Sstevel@tonic-gate  * memory.
1127c478bd9Sstevel@tonic-gate  */
1137c478bd9Sstevel@tonic-gate #define	__sun_attr___const__	__attribute__((__const__))
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate /*
1167c478bd9Sstevel@tonic-gate  * structure packing like #pragma pack(1)
1177c478bd9Sstevel@tonic-gate  */
1187c478bd9Sstevel@tonic-gate #define	__sun_attr___packed__	__attribute__((__packed__))
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate #define	___sun_attr_inner(__a)	__sun_attr_##__a
1217c478bd9Sstevel@tonic-gate #define	__sun_attr__(__a)	___sun_attr_inner __a
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate #else	/* __ATTRIBUTE_IMPLEMENTED || __GNUC__ */
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate #define	__sun_attr__(__a)
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate #endif	/* __ATTRIBUTE_IMPLEMENTED || __GNUC__ */
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate /*
1307c478bd9Sstevel@tonic-gate  * Shorthand versions for readability
1317c478bd9Sstevel@tonic-gate  */
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate #define	__PRINTFLIKE(__n)	__sun_attr__((__PRINTFLIKE__(__n)))
1347c478bd9Sstevel@tonic-gate #define	__VPRINTFLIKE(__n)	__sun_attr__((__VPRINTFLIKE__(__n)))
1357c478bd9Sstevel@tonic-gate #define	__KPRINTFLIKE(__n)	__sun_attr__((__KPRINTFLIKE__(__n)))
1367c478bd9Sstevel@tonic-gate #define	__KVPRINTFLIKE(__n)	__sun_attr__((__KVPRINTFLIKE__(__n)))
1377c478bd9Sstevel@tonic-gate #define	__NORETURN		__sun_attr__((__noreturn__))
1386b7143d7SRichard Lowe #define	__GNU_INLINE		__inline__ __sun_attr__((__gnu_inline__))
139*6a3e8e86SRichard Lowe #define	__RETURNS_TWICE		__sun_attr__((__returns_twice__))
1407c478bd9Sstevel@tonic-gate #define	__CONST			__sun_attr__((__const__))
1417c478bd9Sstevel@tonic-gate #define	__PURE			__sun_attr__((__pure__))
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1447c478bd9Sstevel@tonic-gate }
1457c478bd9Sstevel@tonic-gate #endif
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate #endif	/* _SYS_CCOMPILE_H */
148