Subversion Repositories Kolibri OS

Rev

Rev 4921 | Rev 6109 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4921 Rev 6099
Line 67... Line 67...
67
#endif
67
#endif
Line 68... Line 68...
68
 
68
 
69
/*
69
/*
70
 * Testing against Clang-specific extensions.
70
 * Testing against Clang-specific extensions.
-
 
71
 */
-
 
72
#ifndef	__has_attribute
71
 */
73
#define	__has_attribute(x)	0
72
 
74
#endif
73
#ifndef	__has_extension
75
#ifndef	__has_extension
74
#define	__has_extension		__has_feature
76
#define	__has_extension		__has_feature
75
#endif
77
#endif
76
#ifndef	__has_feature
78
#ifndef	__has_feature
Line 112... Line 114...
112
#ifndef __INTEL_COMPILER
114
#ifndef __INTEL_COMPILER
113
# define __GNUCLIKE_CTOR_SECTION_HANDLING 1
115
#define	__GNUCLIKE_CTOR_SECTION_HANDLING 1
114
#endif
116
#endif
Line 115... Line 117...
115
 
117
 
116
#define __GNUCLIKE_BUILTIN_CONSTANT_P 1
118
#define	__GNUCLIKE_BUILTIN_CONSTANT_P 1
117
# if defined(__INTEL_COMPILER) && defined(__cplusplus) \
119
#if defined(__INTEL_COMPILER) && defined(__cplusplus) && \
118
    && __INTEL_COMPILER < 800
120
   __INTEL_COMPILER < 800
119
#  undef __GNUCLIKE_BUILTIN_CONSTANT_P
121
#undef __GNUCLIKE_BUILTIN_CONSTANT_P
Line 120... Line 122...
120
# endif
122
#endif
121
 
123
 
122
#if (__GNUC_MINOR__ > 95 || __GNUC__ >= 3) && !defined(__INTEL_COMPILER)
124
#if (__GNUC_MINOR__ > 95 || __GNUC__ >= 3)
123
# define __GNUCLIKE_BUILTIN_VARARGS 1
125
#define	__GNUCLIKE_BUILTIN_VARARGS 1
124
# define __GNUCLIKE_BUILTIN_STDARG 1
126
#define	__GNUCLIKE_BUILTIN_STDARG 1
Line 227... Line 229...
227
#define	__dead2
229
#define	__dead2
228
#define	__pure2
230
#define	__pure2
229
#define	__unused
231
#define	__unused
230
#define	__packed
232
#define	__packed
231
#define	__aligned(x)
233
#define	__aligned(x)
-
 
234
#define	__alloc_align(x)
-
 
235
#define	__alloc_size(x)
232
#define	__section(x)
236
#define	__section(x)
-
 
237
#define	__weak_symbol
233
#else
238
#else
-
 
239
#define	__weak_symbol	__attribute__((__weak__))
234
#if !__GNUC_PREREQ__(2, 5) && !defined(__INTEL_COMPILER)
240
#if !__GNUC_PREREQ__(2, 5) && !defined(__INTEL_COMPILER)
235
#define	__dead2
241
#define	__dead2
236
#define	__pure2
242
#define	__pure2
237
#define	__unused
243
#define	__unused
238
#endif
244
#endif
Line 240... Line 246...
240
#define	__dead2		__attribute__((__noreturn__))
246
#define	__dead2		__attribute__((__noreturn__))
241
#define	__pure2		__attribute__((__const__))
247
#define	__pure2		__attribute__((__const__))
242
#define	__unused
248
#define	__unused
243
/* XXX Find out what to do for __packed, __aligned and __section */
249
/* XXX Find out what to do for __packed, __aligned and __section */
244
#endif
250
#endif
245
#if __GNUC_PREREQ__(2, 7)
251
#if __GNUC_PREREQ__(2, 7) || defined(__INTEL_COMPILER)
246
#define	__dead2		__attribute__((__noreturn__))
252
#define	__dead2		__attribute__((__noreturn__))
247
#define	__pure2		__attribute__((__const__))
253
#define	__pure2		__attribute__((__const__))
248
#define	__unused	__attribute__((__unused__))
254
#define	__unused	__attribute__((__unused__))
249
#define	__used		__attribute__((__used__))
255
#define	__used		__attribute__((__used__))
250
#define	__packed	__attribute__((__packed__))
256
#define	__packed	__attribute__((__packed__))
251
#define	__aligned(x)	__attribute__((__aligned__(x)))
257
#define	__aligned(x)	__attribute__((__aligned__(x)))
252
#define	__section(x)	__attribute__((__section__(x)))
258
#define	__section(x)	__attribute__((__section__(x)))
253
#endif
259
#endif
254
#if defined(__INTEL_COMPILER)
-
 
255
#define __dead2		__attribute__((__noreturn__))
-
 
256
#define __pure2		__attribute__((__const__))
260
#if __GNUC_PREREQ__(4, 3) || __has_attribute(__alloc_size__)
257
#define __unused	__attribute__((__unused__))
261
#define	__alloc_size(x)	__attribute__((__alloc_size__(x)))
258
#define __used		__attribute__((__used__))
262
#else
259
#define __packed	__attribute__((__packed__))
263
#define	__alloc_size(x)
260
#define __aligned(x)	__attribute__((__aligned__(x)))
-
 
261
#define __section(x)	__attribute__((__section__(x)))
-
 
262
#endif
264
#endif
-
 
265
#if __GNUC_PREREQ__(4, 9) || __has_attribute(__alloc_align__)
-
 
266
#define	__alloc_align(x)	__attribute__((__alloc_align__(x)))
-
 
267
#else
-
 
268
#define	__alloc_align(x)
263
#endif
269
#endif
-
 
270
#endif /* lint */
Line 264... Line 271...
264
 
271
 
265
#if !__GNUC_PREREQ__(2, 95)
272
#if !__GNUC_PREREQ__(2, 95)
266
#define	__alignof(x)	__offsetof(struct { char __a; x __b; }, __b)
273
#define	__alignof(x)	__offsetof(struct { char __a; x __b; }, __b)
Line 267... Line 274...
267
#endif
274
#endif
268
 
275
 
269
/*
276
/*
Line 270... Line 277...
270
 * Keywords added in C11.
277
 * Keywords added in C11.
Line 271... Line 278...
271
 */
278
 */
272
 
279
 
273
#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L
280
#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L || defined(lint)
274
 
281
 
Line 300... Line 307...
300
#define	_Noreturn		[[noreturn]]
307
#define	_Noreturn		[[noreturn]]
301
#else
308
#else
302
#define	_Noreturn		__dead2
309
#define	_Noreturn		__dead2
303
#endif
310
#endif
Line 304... Line -...
304
 
-
 
305
#if __GNUC_PREREQ__(4, 6) && !defined(__cplusplus)
-
 
306
/*  Do nothing: _Static_assert() works as per C11 */
311
 
307
#elif !__has_extension(c_static_assert)
312
#if !__has_extension(c_static_assert)
308
#if (defined(__cplusplus) && __cplusplus >= 201103L) || \
313
#if (defined(__cplusplus) && __cplusplus >= 201103L) || \
309
    __has_extension(cxx_static_assert)
314
    __has_extension(cxx_static_assert)
-
 
315
#define	_Static_assert(x, y)	static_assert(x, y)
-
 
316
#elif __GNUC_PREREQ__(4,6)
310
#define	_Static_assert(x, y)	static_assert(x, y)
317
/* Nothing, gcc 4.6 and higher has _Static_assert built-in */
311
#elif defined(__COUNTER__)
318
#elif defined(__COUNTER__)
312
#define	_Static_assert(x, y)	__Static_assert(x, __COUNTER__)
319
#define	_Static_assert(x, y)	__Static_assert(x, __COUNTER__)
313
#define	__Static_assert(x, y)	___Static_assert(x, y)
320
#define	__Static_assert(x, y)	___Static_assert(x, y)
-
 
321
#define	___Static_assert(x, y)	typedef char __assert_ ## y[(x) ? 1 : -1] \
314
#define	___Static_assert(x, y)	typedef char __assert_ ## y[(x) ? 1 : -1]
322
				__unused
315
#else
323
#else
316
#define	_Static_assert(x, y)	struct __hack
324
#define	_Static_assert(x, y)	struct __hack
317
#endif
325
#endif
Line 318... Line 326...
318
#endif
326
#endif
-
 
327
 
-
 
328
#if !__has_extension(c_thread_local)
-
 
329
/*
319
 
330
 * XXX: Some compilers (Clang 3.3, GCC 4.7) falsely announce C++11 mode
-
 
331
 * without actually supporting the thread_local keyword. Don't check for
320
#if !__has_extension(c_thread_local)
332
 * the presence of C++11 when defining _Thread_local.
321
/* XXX: Change this to test against C++11 when clang in base supports it. */
333
 */
322
#if /* (defined(__cplusplus) && __cplusplus >= 201103L) || */ \
334
#if /* (defined(__cplusplus) && __cplusplus >= 201103L) || */ \
323
    __has_extension(cxx_thread_local)
335
    __has_extension(cxx_thread_local)
324
#define	_Thread_local		thread_local
336
#define	_Thread_local		thread_local
Line 336... Line 348...
336
 * __generic().  Unlike _Generic(), this macro can only distinguish
348
 * __generic().  Unlike _Generic(), this macro can only distinguish
337
 * between a single type, so it requires nested invocations to
349
 * between a single type, so it requires nested invocations to
338
 * distinguish multiple cases.
350
 * distinguish multiple cases.
339
 */
351
 */
Line 340... Line 352...
340
 
352
 
-
 
353
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || \
341
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
354
    __has_extension(c_generic_selections)
342
#define	__generic(expr, t, yes, no)					\
355
#define	__generic(expr, t, yes, no)					\
343
	_Generic(expr, t: yes, default: no)
356
	_Generic(expr, t: yes, default: no)
344
#elif __GNUC_PREREQ__(3, 1) && !defined(__cplusplus)
357
#elif __GNUC_PREREQ__(3, 1) && !defined(__cplusplus)
345
#define	__generic(expr, t, yes, no)					\
358
#define	__generic(expr, t, yes, no)					\
Line 367... Line 380...
367
#define	__noinline
380
#define	__noinline
368
#endif
381
#endif
Line 369... Line 382...
369
 
382
 
370
#if __GNUC_PREREQ__(3, 3)
383
#if __GNUC_PREREQ__(3, 3)
-
 
384
#define	__nonnull(x)	__attribute__((__nonnull__(x)))
371
#define __nonnull(x)	__attribute__((__nonnull__(x)))
385
#define	__nonnull_all	__attribute__((__nonnull__))
372
#else
386
#else
-
 
387
#define	__nonnull(x)
373
#define __nonnull(x)
388
#define	__nonnull_all
Line 374... Line 389...
374
#endif
389
#endif
375
 
390
 
-
 
391
#if __GNUC_PREREQ__(3, 4)
376
#if __GNUC_PREREQ__(3, 4)
392
#define	__fastcall	__attribute__((__fastcall__))
377
#define	__fastcall	__attribute__((__fastcall__))
393
#define	__result_use_check	__attribute__((__warn_unused_result__))
-
 
394
#else
378
#else
395
#define	__fastcall
Line 379... Line 396...
379
#define	__fastcall
396
#define	__result_use_check
380
#endif
397
#endif
381
 
398
 
382
#if __GNUC_PREREQ__(4, 1)
399
#if __GNUC_PREREQ__(4, 1)
383
#define	__returns_twice	__attribute__((__returns_twice__))
400
#define	__returns_twice	__attribute__((__returns_twice__))
Line -... Line 401...
-
 
401
#else
-
 
402
#define	__returns_twice
-
 
403
#endif
-
 
404
 
-
 
405
#if __GNUC_PREREQ__(4, 6) || __has_builtin(__builtin_unreachable)
-
 
406
#define	__unreachable()	__builtin_unreachable()
384
#else
407
#else
385
#define	__returns_twice
408
#define	__unreachable()	((void)0)
386
#endif
409
#endif
387
 
410
 
Line 438... Line 461...
438
#else
461
#else
439
#define __predict_true(exp)     (exp)
462
#define	__predict_true(exp)     (exp)
440
#define __predict_false(exp)    (exp)
463
#define	__predict_false(exp)    (exp)
441
#endif
464
#endif
Line 442... Line 465...
442
 
465
 
443
#if __GNUC_PREREQ__(4, 2)
466
#if __GNUC_PREREQ__(4, 0)
444
#define	__hidden	__attribute__((__visibility__("hidden")))
467
#define	__sentinel	__attribute__((__sentinel__))
-
 
468
#define	__exported	__attribute__((__visibility__("default")))
445
#define	__exported	__attribute__((__visibility__("default")))
469
#define	__hidden	__attribute__((__visibility__("hidden")))
446
#else
470
#else
447
#define	__hidden
471
#define	__sentinel
-
 
472
#define	__exported
448
#define	__exported
473
#define	__hidden
Line 449... Line 474...
449
#endif
474
#endif
450
 
475
 
451
#define __offsetof(type, field)	offsetof(type, field)
476
#define __offsetof(type, field)	offsetof(type, field)
Line 458... Line 483...
458
 * assign pointer x to a local variable, to check that its type is
483
 * assign pointer x to a local variable, to check that its type is
459
 * compatible with member m.
484
 * compatible with member m.
460
 */
485
 */
461
#if __GNUC_PREREQ__(3, 1)
486
#if __GNUC_PREREQ__(3, 1)
462
#define	__containerof(x, s, m) ({					\
487
#define	__containerof(x, s, m) ({					\
463
	const volatile __typeof__(((s *)0)->m) *__x = (x);		\
488
	const volatile __typeof(((s *)0)->m) *__x = (x);		\
464
	__DEQUALIFY(s *, (const volatile char *)__x - __offsetof(s, m));\
489
	__DEQUALIFY(s *, (const volatile char *)__x - __offsetof(s, m));\
465
})
490
})
466
#else
491
#else
467
#define	__containerof(x, s, m)						\
492
#define	__containerof(x, s, m)						\
468
	__DEQUALIFY(s *, (const volatile char *)(x) - __offsetof(s, m))
493
	__DEQUALIFY(s *, (const volatile char *)(x) - __offsetof(s, m))
Line 490... Line 515...
490
	    __attribute__((__format__ (__strfmon__, fmtarg, firstvararg)))
515
	    __attribute__((__format__ (__strfmon__, fmtarg, firstvararg)))
491
#define	__strftimelike(fmtarg, firstvararg) \
516
#define	__strftimelike(fmtarg, firstvararg) \
492
	    __attribute__((__format__ (__strftime__, fmtarg, firstvararg)))
517
	    __attribute__((__format__ (__strftime__, fmtarg, firstvararg)))
493
#endif
518
#endif
Line -... Line 519...
-
 
519
 
-
 
520
/*
-
 
521
 * FORTIFY_SOURCE, and perhaps other compiler-specific features, require
-
 
522
 * the use of non-standard inlining.  In general we should try to avoid
-
 
523
 * using these but GCC-compatible compilers tend to support the extensions
-
 
524
 * well enough to use them in limited cases.
-
 
525
 */ 
-
 
526
#if defined(__GNUC_GNU_INLINE__) || defined(__GNUC_STDC_INLINE__)
-
 
527
#if __GNUC_PREREQ__(4, 3) || __has_attribute(__artificial__)
-
 
528
#define	__gnu_inline	__attribute__((__gnu_inline__, __artificial__))
-
 
529
#else
-
 
530
#define	__gnu_inline	__attribute__((__gnu_inline__))
-
 
531
#endif /* artificial */
-
 
532
#else
-
 
533
#define	__gnu_inline
-
 
534
#endif
494
 
535
 
495
/* Compiler-dependent macros that rely on FreeBSD-specific extensions. */
536
/* Compiler-dependent macros that rely on FreeBSD-specific extensions. */
496
#if defined(__FreeBSD_cc_version) && __FreeBSD_cc_version >= 300001 && \
537
#if defined(__FreeBSD_cc_version) && __FreeBSD_cc_version >= 300001 && \
497
    defined(__GNUC__) && !defined(__INTEL_COMPILER)
538
    defined(__GNUC__) && !defined(__INTEL_COMPILER)
498
#define	__printf0like(fmtarg, firstvararg) \
539
#define	__printf0like(fmtarg, firstvararg) \
Line 604... Line 645...
604
 * that specification, and which subsumes _POSIX_C_SOURCE.
645
 * that specification, and which subsumes _POSIX_C_SOURCE.
605
 *
646
 *
606
 * Our macros begin with two underscores to avoid namespace screwage.
647
 * Our macros begin with two underscores to avoid namespace screwage.
607
 */
648
 */
Line -... Line 649...
-
 
649
 
-
 
650
/* Deal with _GNU_SOURCE, which implies everything and the kitchen sink */
-
 
651
#ifdef _GNU_SOURCE
-
 
652
#undef _XOPEN_SOURCE
-
 
653
#define	_XOPEN_SOURCE		700
-
 
654
#define	__BSD_VISIBLE		1
-
 
655
#define	__GNU_VISIBLE		1
-
 
656
#endif
608
 
657
 
609
/* Deal with IEEE Std. 1003.1-1990, in which _POSIX_C_SOURCE == 1. */
658
/* Deal with IEEE Std. 1003.1-1990, in which _POSIX_C_SOURCE == 1. */
610
#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 1
659
#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 1
611
#undef _POSIX_C_SOURCE		/* Probably illegal, but beyond caring now. */
660
#undef _POSIX_C_SOURCE		/* Probably illegal, but beyond caring now. */
612
#define	_POSIX_C_SOURCE		199009
661
#define	_POSIX_C_SOURCE		199009
Line 691... Line 740...
691
#elif defined(_C11_SOURCE)	/* Localism to specify strict C11 env. */
740
#elif defined(_C11_SOURCE)	/* Localism to specify strict C11 env. */
692
#define	__POSIX_VISIBLE		0
741
#define	__POSIX_VISIBLE		0
693
#define	__XSI_VISIBLE		0
742
#define	__XSI_VISIBLE		0
694
#define	__BSD_VISIBLE		0
743
#define	__BSD_VISIBLE		0
695
#define	__ISO_C_VISIBLE		2011
744
#define	__ISO_C_VISIBLE		2011
696
#elif defined(_GNU_SOURCE)	/* Everything and the kitchen sink. */
-
 
697
#define	__POSIX_VISIBLE		200809
-
 
698
#define	__XSI_VISIBLE		700
-
 
699
#define	__BSD_VISIBLE		1
-
 
700
#define	__ISO_C_VISIBLE		2011
-
 
701
#define	__GNU_VISIBLE		1
-
 
702
#else				/* Default: everything except __GNU_VISIBLE. */
745
#else				/* Default: everything except __GNU_VISIBLE. */
703
#define	__POSIX_VISIBLE		200809
746
#define	__POSIX_VISIBLE		200809
704
#define	__XSI_VISIBLE		700
747
#define	__XSI_VISIBLE		700
705
#define	__BSD_VISIBLE		1
748
#define	__BSD_VISIBLE		1
706
#define	__ISO_C_VISIBLE		2011
749
#define	__ISO_C_VISIBLE		2011
707
#endif
750
#endif
708
#endif
751
#endif
Line -... Line 752...
-
 
752
 
-
 
753
/*
-
 
754
 * Type Safety Checking
-
 
755
 *
-
 
756
 * Clang provides additional attributes to enable checking type safety
-
 
757
 * properties that cannot be enforced by the C type system. 
-
 
758
 */
-
 
759
 
-
 
760
#if __has_attribute(__argument_with_type_tag__) && \
-
 
761
    __has_attribute(__type_tag_for_datatype__) && !defined(lint)
-
 
762
#define	__arg_type_tag(arg_kind, arg_idx, type_tag_idx) \
-
 
763
	    __attribute__((__argument_with_type_tag__(arg_kind, arg_idx, type_tag_idx)))
-
 
764
#define	__datatype_type_tag(kind, type) \
-
 
765
	    __attribute__((__type_tag_for_datatype__(kind, type)))
-
 
766
#else
-
 
767
#define	__arg_type_tag(arg_kind, arg_idx, type_tag_idx)
-
 
768
#define	__datatype_type_tag(kind, type)
-
 
769
#endif
-
 
770
 
-
 
771
/*
-
 
772
 * Lock annotations.
-
 
773
 *
-
 
774
 * Clang provides support for doing basic thread-safety tests at
-
 
775
 * compile-time, by marking which locks will/should be held when
-
 
776
 * entering/leaving a functions.
-
 
777
 *
-
 
778
 * Furthermore, it is also possible to annotate variables and structure
-
 
779
 * members to enforce that they are only accessed when certain locks are
-
 
780
 * held.
-
 
781
 */
-
 
782
 
-
 
783
#if __has_extension(c_thread_safety_attributes)
-
 
784
#define	__lock_annotate(x)	__attribute__((x))
-
 
785
#else
-
 
786
#define	__lock_annotate(x)
-
 
787
#endif
-
 
788
 
-
 
789
/* Structure implements a lock. */
-
 
790
#define	__lockable		__lock_annotate(lockable)
-
 
791
 
-
 
792
/* Function acquires an exclusive or shared lock. */
-
 
793
#define	__locks_exclusive(...) \
-
 
794
	__lock_annotate(exclusive_lock_function(__VA_ARGS__))
-
 
795
#define	__locks_shared(...) \
-
 
796
	__lock_annotate(shared_lock_function(__VA_ARGS__))
-
 
797
 
-
 
798
/* Function attempts to acquire an exclusive or shared lock. */
-
 
799
#define	__trylocks_exclusive(...) \
-
 
800
	__lock_annotate(exclusive_trylock_function(__VA_ARGS__))
-
 
801
#define	__trylocks_shared(...) \
-
 
802
	__lock_annotate(shared_trylock_function(__VA_ARGS__))
-
 
803
 
-
 
804
/* Function releases a lock. */
-
 
805
#define	__unlocks(...)		__lock_annotate(unlock_function(__VA_ARGS__))
-
 
806
 
-
 
807
/* Function asserts that an exclusive or shared lock is held. */
-
 
808
#define	__asserts_exclusive(...) \
-
 
809
	__lock_annotate(assert_exclusive_lock(__VA_ARGS__))
-
 
810
#define	__asserts_shared(...) \
-
 
811
	__lock_annotate(assert_shared_lock(__VA_ARGS__))
-
 
812
 
-
 
813
/* Function requires that an exclusive or shared lock is or is not held. */
-
 
814
#define	__requires_exclusive(...) \
-
 
815
	__lock_annotate(exclusive_locks_required(__VA_ARGS__))
-
 
816
#define	__requires_shared(...) \
-
 
817
	__lock_annotate(shared_locks_required(__VA_ARGS__))
-
 
818
#define	__requires_unlocked(...) \
-
 
819
	__lock_annotate(locks_excluded(__VA_ARGS__))
-
 
820
 
-
 
821
/* Function should not be analyzed. */
-
 
822
#define	__no_lock_analysis	__lock_annotate(no_thread_safety_analysis)
-
 
823
 
-
 
824
/* Guard variables and structure members by lock. */
-
 
825
#define	__guarded_by(x)		__lock_annotate(guarded_by(x))
-
 
826
#define	__pt_guarded_by(x)	__lock_annotate(pt_guarded_by(x))
709
 
827