View | Details | Raw Unified | Return to bug 250406
Collapse All | Expand All

(-)b/sys/sys/cdefs.h (-136 / +6 lines)
Lines 42-47 Link Here
42
#error "_KERNEL and _STANDALONE are mutually exclusive"
42
#error "_KERNEL and _STANDALONE are mutually exclusive"
43
#endif
43
#endif
44
44
45
#if !defined(__GNUC__)
46
#error "Requires a compiler that supports gcc defines"
47
#endif
48
45
/*
49
/*
46
 * Testing against Clang-specific extensions.
50
 * Testing against Clang-specific extensions.
47
 */
51
 */
Lines 75-127 Link Here
75
 * having a compiler-agnostic source tree.
79
 * having a compiler-agnostic source tree.
76
 */
80
 */
77
81
78
#if defined(__GNUC__) || defined(__INTEL_COMPILER)
79
80
#if __GNUC__ >= 3 || defined(__INTEL_COMPILER)
81
#define	__GNUCLIKE_ASM 3
82
#define	__GNUCLIKE_ASM 3
82
#define	__GNUCLIKE_MATH_BUILTIN_CONSTANTS
83
#define	__GNUCLIKE_MATH_BUILTIN_CONSTANTS
83
#else
84
#define	__GNUCLIKE_ASM 2
85
#endif
86
#define	__GNUCLIKE___TYPEOF 1
84
#define	__GNUCLIKE___TYPEOF 1
87
#define	__GNUCLIKE___OFFSETOF 1
85
#define	__GNUCLIKE___OFFSETOF 1
88
#define	__GNUCLIKE___SECTION 1
86
#define	__GNUCLIKE___SECTION 1
89
87
90
#ifndef __INTEL_COMPILER
91
#define	__GNUCLIKE_CTOR_SECTION_HANDLING 1
88
#define	__GNUCLIKE_CTOR_SECTION_HANDLING 1
92
#endif
93
89
94
#define	__GNUCLIKE_BUILTIN_CONSTANT_P 1
90
#define	__GNUCLIKE_BUILTIN_CONSTANT_P 1
95
#if defined(__INTEL_COMPILER) && defined(__cplusplus) && \
96
   __INTEL_COMPILER < 800
97
#undef __GNUCLIKE_BUILTIN_CONSTANT_P
98
#endif
99
91
100
#if (__GNUC_MINOR__ > 95 || __GNUC__ >= 3)
101
#define	__GNUCLIKE_BUILTIN_VARARGS 1
92
#define	__GNUCLIKE_BUILTIN_VARARGS 1
102
#define	__GNUCLIKE_BUILTIN_STDARG 1
93
#define	__GNUCLIKE_BUILTIN_STDARG 1
103
#define	__GNUCLIKE_BUILTIN_VAALIST 1
94
#define	__GNUCLIKE_BUILTIN_VAALIST 1
104
#endif
105
95
106
#if defined(__GNUC__)
107
#define	__GNUC_VA_LIST_COMPATIBILITY 1
96
#define	__GNUC_VA_LIST_COMPATIBILITY 1
108
#endif
109
97
110
/*
98
/*
111
 * Compiler memory barriers, specific to gcc and clang.
99
 * Compiler memory barriers, specific to gcc and clang.
112
 */
100
 */
113
#if defined(__GNUC__)
114
#define	__compiler_membar()	__asm __volatile(" " : : : "memory")
101
#define	__compiler_membar()	__asm __volatile(" " : : : "memory")
115
#endif
116
102
117
#ifndef __INTEL_COMPILER
118
#define	__GNUCLIKE_BUILTIN_NEXT_ARG 1
103
#define	__GNUCLIKE_BUILTIN_NEXT_ARG 1
119
#define	__GNUCLIKE_MATH_BUILTIN_RELOPS
104
#define	__GNUCLIKE_MATH_BUILTIN_RELOPS
120
#endif
121
105
122
#define	__GNUCLIKE_BUILTIN_MEMCPY 1
106
#define	__GNUCLIKE_BUILTIN_MEMCPY 1
123
107
124
/* XXX: if __GNUC__ >= 2: not tested everywhere originally, where replaced */
125
#define	__CC_SUPPORTS_INLINE 1
108
#define	__CC_SUPPORTS_INLINE 1
126
#define	__CC_SUPPORTS___INLINE 1
109
#define	__CC_SUPPORTS___INLINE 1
127
#define	__CC_SUPPORTS___INLINE__ 1
110
#define	__CC_SUPPORTS___INLINE__ 1
Lines 133-149 Link Here
133
116
134
#define	__CC_SUPPORTS_DYNAMIC_ARRAY_INIT 1
117
#define	__CC_SUPPORTS_DYNAMIC_ARRAY_INIT 1
135
118
136
#endif /* __GNUC__ || __INTEL_COMPILER */
137
138
/*
119
/*
139
 * Macro to test if we're using a specific version of gcc or later.
120
 * Macro to test if we're using a specific version of gcc or later.
140
 */
121
 */
141
#if defined(__GNUC__) && !defined(__INTEL_COMPILER)
142
#define	__GNUC_PREREQ__(ma, mi)	\
122
#define	__GNUC_PREREQ__(ma, mi)	\
143
	(__GNUC__ > (ma) || __GNUC__ == (ma) && __GNUC_MINOR__ >= (mi))
123
	(__GNUC__ > (ma) || __GNUC__ == (ma) && __GNUC_MINOR__ >= (mi))
144
#else
145
#define	__GNUC_PREREQ__(ma, mi)	0
146
#endif
147
124
148
/*
125
/*
149
 * The __CONCAT macro is used to concatenate parts of symbol names, e.g.
126
 * The __CONCAT macro is used to concatenate parts of symbol names, e.g.
Lines 212-229 Link Here
212
 * a feature that we cannot live without.
189
 * a feature that we cannot live without.
213
 */
190
 */
214
#define	__weak_symbol	__attribute__((__weak__))
191
#define	__weak_symbol	__attribute__((__weak__))
215
#if !__GNUC_PREREQ__(2, 5) && !defined(__INTEL_COMPILER)
216
#define	__dead2
217
#define	__pure2
218
#define	__unused
219
#endif
220
#if __GNUC__ == 2 && __GNUC_MINOR__ >= 5 && __GNUC_MINOR__ < 7 && !defined(__INTEL_COMPILER)
221
#define	__dead2		__attribute__((__noreturn__))
222
#define	__pure2		__attribute__((__const__))
223
#define	__unused
224
/* XXX Find out what to do for __packed, __aligned and __section */
225
#endif
226
#if __GNUC_PREREQ__(2, 7) || defined(__INTEL_COMPILER)
227
#define	__dead2		__attribute__((__noreturn__))
192
#define	__dead2		__attribute__((__noreturn__))
228
#define	__pure2		__attribute__((__const__))
193
#define	__pure2		__attribute__((__const__))
229
#define	__unused	__attribute__((__unused__))
194
#define	__unused	__attribute__((__unused__))
Lines 231-237 Link Here
231
#define	__packed	__attribute__((__packed__))
196
#define	__packed	__attribute__((__packed__))
232
#define	__aligned(x)	__attribute__((__aligned__(x)))
197
#define	__aligned(x)	__attribute__((__aligned__(x)))
233
#define	__section(x)	__attribute__((__section__(x)))
198
#define	__section(x)	__attribute__((__section__(x)))
234
#endif
235
#if __GNUC_PREREQ__(4, 3) || __has_attribute(__alloc_size__)
199
#if __GNUC_PREREQ__(4, 3) || __has_attribute(__alloc_size__)
236
#define	__alloc_size(x)	__attribute__((__alloc_size__(x)))
200
#define	__alloc_size(x)	__attribute__((__alloc_size__(x)))
237
#define	__alloc_size2(n, x)	__attribute__((__alloc_size__(n, x)))
201
#define	__alloc_size2(n, x)	__attribute__((__alloc_size__(n, x)))
Lines 245-254 Link Here
245
#define	__alloc_align(x)
209
#define	__alloc_align(x)
246
#endif
210
#endif
247
211
248
#if !__GNUC_PREREQ__(2, 95)
249
#define	__alignof(x)	__offsetof(struct { char __a; x __b; }, __b)
250
#endif
251
252
/*
212
/*
253
 * Keywords added in C11.
213
 * Keywords added in C11.
254
 */
214
 */
Lines 331-337 Link Here
331
    __has_extension(c_generic_selections)
291
    __has_extension(c_generic_selections)
332
#define	__generic(expr, t, yes, no)					\
292
#define	__generic(expr, t, yes, no)					\
333
	_Generic(expr, t: yes, default: no)
293
	_Generic(expr, t: yes, default: no)
334
#elif __GNUC_PREREQ__(3, 1) && !defined(__cplusplus)
294
#elif !defined(__cplusplus)
335
#define	__generic(expr, t, yes, no)					\
295
#define	__generic(expr, t, yes, no)					\
336
	__builtin_choose_expr(						\
296
	__builtin_choose_expr(						\
337
	    __builtin_types_compatible_p(__typeof(expr), t), yes, no)
297
	    __builtin_types_compatible_p(__typeof(expr), t), yes, no)
Lines 352-390 Link Here
352
#define __min_size(x)	(x)
312
#define __min_size(x)	(x)
353
#endif
313
#endif
354
314
355
#if __GNUC_PREREQ__(2, 96)
356
#define	__malloc_like	__attribute__((__malloc__))
315
#define	__malloc_like	__attribute__((__malloc__))
357
#define	__pure		__attribute__((__pure__))
316
#define	__pure		__attribute__((__pure__))
358
#else
359
#define	__malloc_like
360
#define	__pure
361
#endif
362
317
363
#if __GNUC_PREREQ__(3, 1) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 800)
364
#define	__always_inline	__attribute__((__always_inline__))
318
#define	__always_inline	__attribute__((__always_inline__))
365
#else
366
#define	__always_inline
367
#endif
368
319
369
#if __GNUC_PREREQ__(3, 1)
370
#define	__noinline	__attribute__ ((__noinline__))
320
#define	__noinline	__attribute__ ((__noinline__))
371
#else
372
#define	__noinline
373
#endif
374
321
375
#if __GNUC_PREREQ__(3, 4)
376
#define	__fastcall	__attribute__((__fastcall__))
322
#define	__fastcall	__attribute__((__fastcall__))
377
#define	__result_use_check	__attribute__((__warn_unused_result__))
323
#define	__result_use_check	__attribute__((__warn_unused_result__))
378
#else
379
#define	__fastcall
380
#define	__result_use_check
381
#endif
382
324
383
#if __GNUC_PREREQ__(4, 1)
384
#define	__returns_twice	__attribute__((__returns_twice__))
325
#define	__returns_twice	__attribute__((__returns_twice__))
385
#else
386
#define	__returns_twice
387
#endif
388
326
389
#if __GNUC_PREREQ__(4, 6) || __has_builtin(__builtin_unreachable)
327
#if __GNUC_PREREQ__(4, 6) || __has_builtin(__builtin_unreachable)
390
#define	__unreachable()	__builtin_unreachable()
328
#define	__unreachable()	__builtin_unreachable()
Lines 392-403 Link Here
392
#define	__unreachable()	((void)0)
330
#define	__unreachable()	((void)0)
393
#endif
331
#endif
394
332
395
/* XXX: should use `#if __STDC_VERSION__ < 199901'. */
333
#if !defined(__STRICT_ANSI__) || __STDC_VERSION__ >= 199901
396
#if !__GNUC_PREREQ__(2, 7) && !defined(__INTEL_COMPILER)
397
#define	__func__	NULL
398
#endif
399
400
#if (defined(__INTEL_COMPILER) || (defined(__GNUC__) && __GNUC__ >= 2)) && !defined(__STRICT_ANSI__) || __STDC_VERSION__ >= 199901
401
#define	__LONG_LONG_SUPPORTED
334
#define	__LONG_LONG_SUPPORTED
402
#endif
335
#endif
403
336
Lines 412-430 Link Here
412
#endif
345
#endif
413
#endif
346
#endif
414
347
415
/*
416
 * GCC 2.95 provides `__restrict' as an extension to C90 to support the
417
 * C99-specific `restrict' type qualifier.  We happen to use `__restrict' as
418
 * a way to define the `restrict' type qualifier without disturbing older
419
 * software that is unaware of C99 keywords.
420
 */
421
#if !(__GNUC__ == 2 && __GNUC_MINOR__ == 95)
422
#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901
348
#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901
423
#define	__restrict
349
#define	__restrict
424
#else
350
#else
425
#define	__restrict	restrict
351
#define	__restrict	restrict
426
#endif
352
#endif
427
#endif
428
353
429
/*
354
/*
430
 * GNU C version 2.96 adds explicit branch prediction so that
355
 * GNU C version 2.96 adds explicit branch prediction so that
Lines 454-494 Link Here
454
 *	  basic block reordering that this affects can often generate
379
 *	  basic block reordering that this affects can often generate
455
 *	  larger code.
380
 *	  larger code.
456
 */
381
 */
457
#if __GNUC_PREREQ__(2, 96)
458
#define	__predict_true(exp)     __builtin_expect((exp), 1)
382
#define	__predict_true(exp)     __builtin_expect((exp), 1)
459
#define	__predict_false(exp)    __builtin_expect((exp), 0)
383
#define	__predict_false(exp)    __builtin_expect((exp), 0)
460
#else
461
#define	__predict_true(exp)     (exp)
462
#define	__predict_false(exp)    (exp)
463
#endif
464
384
465
#if __GNUC_PREREQ__(4, 0)
466
#define	__null_sentinel	__attribute__((__sentinel__))
385
#define	__null_sentinel	__attribute__((__sentinel__))
467
#define	__exported	__attribute__((__visibility__("default")))
386
#define	__exported	__attribute__((__visibility__("default")))
468
#define	__hidden	__attribute__((__visibility__("hidden")))
387
#define	__hidden	__attribute__((__visibility__("hidden")))
469
#else
470
#define	__null_sentinel
471
#define	__exported
472
#define	__hidden
473
#endif
474
388
475
/*
389
/*
476
 * We define this here since <stddef.h>, <sys/queue.h>, and <sys/types.h>
390
 * We define this here since <stddef.h>, <sys/queue.h>, and <sys/types.h>
477
 * require it.
391
 * require it.
478
 */
392
 */
479
#if __GNUC_PREREQ__(4, 1)
480
#define	__offsetof(type, field)	 __builtin_offsetof(type, field)
393
#define	__offsetof(type, field)	 __builtin_offsetof(type, field)
481
#else
482
#ifndef __cplusplus
483
#define	__offsetof(type, field) \
484
	((__size_t)(__uintptr_t)((const volatile void *)&((type *)0)->field))
485
#else
486
#define	__offsetof(type, field)					\
487
  (__offsetof__ (reinterpret_cast <__size_t>			\
488
                 (&reinterpret_cast <const volatile char &>	\
489
                  (static_cast<type *> (0)->field))))
490
#endif
491
#endif
492
#define	__rangeof(type, start, end) \
394
#define	__rangeof(type, start, end) \
493
	(__offsetof(type, end) - __offsetof(type, start))
395
	(__offsetof(type, end) - __offsetof(type, start))
494
396
Lines 498-512 Link Here
498
 * assign pointer x to a local variable, to check that its type is
400
 * assign pointer x to a local variable, to check that its type is
499
 * compatible with member m.
401
 * compatible with member m.
500
 */
402
 */
501
#if __GNUC_PREREQ__(3, 1)
502
#define	__containerof(x, s, m) ({					\
403
#define	__containerof(x, s, m) ({					\
503
	const volatile __typeof(((s *)0)->m) *__x = (x);		\
404
	const volatile __typeof(((s *)0)->m) *__x = (x);		\
504
	__DEQUALIFY(s *, (const volatile char *)__x - __offsetof(s, m));\
405
	__DEQUALIFY(s *, (const volatile char *)__x - __offsetof(s, m));\
505
})
406
})
506
#else
507
#define	__containerof(x, s, m)						\
508
	__DEQUALIFY(s *, (const volatile char *)(x) - __offsetof(s, m))
509
#endif
510
407
511
/*
408
/*
512
 * Compiler-dependent macros to declare that functions take printf-like
409
 * Compiler-dependent macros to declare that functions take printf-like
Lines 514-526 Link Here
514
 * that are known to support the features properly (old versions of gcc-2
411
 * that are known to support the features properly (old versions of gcc-2
515
 * didn't permit keeping the keywords out of the application namespace).
412
 * didn't permit keeping the keywords out of the application namespace).
516
 */
413
 */
517
#if !__GNUC_PREREQ__(2, 7) && !defined(__INTEL_COMPILER)
518
#define	__printflike(fmtarg, firstvararg)
519
#define	__scanflike(fmtarg, firstvararg)
520
#define	__format_arg(fmtarg)
521
#define	__strfmonlike(fmtarg, firstvararg)
522
#define	__strftimelike(fmtarg, firstvararg)
523
#else
524
#define	__printflike(fmtarg, firstvararg) \
414
#define	__printflike(fmtarg, firstvararg) \
525
	    __attribute__((__format__ (__printf__, fmtarg, firstvararg)))
415
	    __attribute__((__format__ (__printf__, fmtarg, firstvararg)))
526
#define	__scanflike(fmtarg, firstvararg) \
416
#define	__scanflike(fmtarg, firstvararg) \
Lines 530-551 Link Here
530
	    __attribute__((__format__ (__strfmon__, fmtarg, firstvararg)))
420
	    __attribute__((__format__ (__strfmon__, fmtarg, firstvararg)))
531
#define	__strftimelike(fmtarg, firstvararg) \
421
#define	__strftimelike(fmtarg, firstvararg) \
532
	    __attribute__((__format__ (__strftime__, fmtarg, firstvararg)))
422
	    __attribute__((__format__ (__strftime__, fmtarg, firstvararg)))
533
#endif
534
423
535
/* Compiler-dependent macros that rely on FreeBSD-specific extensions. */
424
/* Compiler-dependent macros that rely on FreeBSD-specific extensions. */
536
#if defined(__FreeBSD_cc_version) && __FreeBSD_cc_version >= 300001 && \
537
    defined(__GNUC__) && !defined(__INTEL_COMPILER)
538
#define	__printf0like(fmtarg, firstvararg) \
425
#define	__printf0like(fmtarg, firstvararg) \
539
	    __attribute__((__format__ (__printf0__, fmtarg, firstvararg)))
426
	    __attribute__((__format__ (__printf0__, fmtarg, firstvararg)))
540
#else
541
#define	__printf0like(fmtarg, firstvararg)
542
#endif
543
427
544
#if defined(__GNUC__) || defined(__INTEL_COMPILER)
545
#ifndef __INTEL_COMPILER
546
#define	__strong_reference(sym,aliassym)	\
428
#define	__strong_reference(sym,aliassym)	\
547
	extern __typeof (sym) aliassym __attribute__ ((__alias__ (#sym)))
429
	extern __typeof (sym) aliassym __attribute__ ((__alias__ (#sym)))
548
#endif
549
#ifdef __STDC__
430
#ifdef __STDC__
550
#define	__weak_reference(sym,alias)	\
431
#define	__weak_reference(sym,alias)	\
551
	__asm__(".weak " #alias);	\
432
	__asm__(".weak " #alias);	\
Lines 571-592 Link Here
571
#define	__sym_default(impl,sym,verid)	\
452
#define	__sym_default(impl,sym,verid)	\
572
	__asm__(".symver impl, sym@@@verid")
453
	__asm__(".symver impl, sym@@@verid")
573
#endif	/* __STDC__ */
454
#endif	/* __STDC__ */
574
#endif	/* __GNUC__ || __INTEL_COMPILER */
575
455
576
#define	__GLOBL1(sym)	__asm__(".globl " #sym)
456
#define	__GLOBL1(sym)	__asm__(".globl " #sym)
577
#define	__GLOBL(sym)	__GLOBL1(sym)
457
#define	__GLOBL(sym)	__GLOBL1(sym)
578
458
579
#if defined(__GNUC__) || defined(__INTEL_COMPILER)
580
#define	__IDSTRING(name,string)	__asm__(".ident\t\"" string "\"")
459
#define	__IDSTRING(name,string)	__asm__(".ident\t\"" string "\"")
581
#else
582
/*
583
 * The following definition might not work well if used in header files,
584
 * but it should be better than nothing.  If you want a "do nothing"
585
 * version, then it should generate some harmless declaration, such as:
586
 *    #define	__IDSTRING(name,string)	struct __hack
587
 */
588
#define	__IDSTRING(name,string)	static const char name[] __unused = string
589
#endif
590
460
591
/*
461
/*
592
 * Embed the rcs id of a source file in the resulting library.  Note that in
462
 * Embed the rcs id of a source file in the resulting library.  Note that in

Return to bug 250406