c99_compat.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /**************************************************************************
  2. *
  3. * Copyright 2007-2013 VMware, Inc.
  4. * All Rights Reserved.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the
  8. * "Software"), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sub license, and/or sell copies of the Software, and to
  11. * permit persons to whom the Software is furnished to do so, subject to
  12. * the following conditions:
  13. *
  14. * The above copyright notice and this permission notice (including the
  15. * next paragraph) shall be included in all copies or substantial portions
  16. * of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  19. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
  21. * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
  22. * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  23. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  24. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25. *
  26. **************************************************************************/
  27. #ifndef _C99_COMPAT_H_
  28. #define _C99_COMPAT_H_
  29. /*
  30. * MSVC hacks.
  31. */
  32. #if defined(_MSC_VER)
  33. // BK - STFU!
  34. # pragma warning(disable:4244) // warning C4244: 'function' : conversion from 'intmax_t' to 'int', possible loss of data
  35. # pragma warning(disable:4267) // warning C4267: '=' : conversion from 'size_t' to 'unsigned int', possible loss of data
  36. # pragma warning(disable:4351) // warning C4351: new behavior: elements of array '`anonymous-namespace'::per_vertex_accumulator::fields' will be default initialized
  37. # pragma warning(disable:4345) // warning C4345: behavior change: an object of POD type constructed with an initializer of the form () will be default-initialized
  38. # pragma warning(disable:4715) // warning C4715: 'write_mask_to_swizzle' : not all control paths return a value
  39. # pragma warning(disable:4800) // warning C4800: 'unsigned int' : forcing value to bool 'true' or 'false' (performance warning)
  40. # pragma warning(disable:4456) // warning C4456: declaration of 'deref_var' hides previous local declaration
  41. # pragma warning(disable:4457) // warning C4457: declaration of 'idx' hides function parameter
  42. # pragma warning(disable:4458) // warning C4458: declaration of 'type' hides class member
  43. # pragma warning(disable:4018) // warning C4018: '<': signed / unsigned mismatch
  44. # pragma warning(disable:4805) // warning C4805: '|=': unsafe mix of type 'GLboolean' and type 'bool' in operation
  45. /*
  46. * Visual Studio 2012 will complain if we define the `inline` keyword, but
  47. * actually it only supports the keyword on C++.
  48. *
  49. * To avoid this the _ALLOW_KEYWORD_MACROS must be set.
  50. */
  51. # if (_MSC_VER >= 1700) && !defined(_ALLOW_KEYWORD_MACROS)
  52. # define _ALLOW_KEYWORD_MACROS
  53. # endif
  54. /*
  55. * XXX: MSVC has a `__restrict` keyword, but it also has a
  56. * `__declspec(restrict)` modifier, so it is impossible to define a
  57. * `restrict` macro without interfering with the latter. Furthermore the
  58. * MSVC standard library uses __declspec(restrict) under the _CRTRESTRICT
  59. * macro. For now resolve this issue by redefining _CRTRESTRICT, but going
  60. * forward we should probably should stop using restrict, especially
  61. * considering that our code does not obbey strict aliasing rules any way.
  62. */
  63. # include <crtdefs.h>
  64. # undef _CRTRESTRICT
  65. # define _CRTRESTRICT
  66. #else
  67. // BK - STFU!
  68. # pragma GCC diagnostic ignored "-Wunknown-pragmas" // for clang to disable GCC pragmas
  69. # pragma GCC diagnostic ignored "-Wpragmas" // for GCC to disable clang pragmas
  70. # pragma GCC diagnostic ignored "-Wformat-extra-args"
  71. # pragma GCC diagnostic ignored "-Wignored-qualifiers"
  72. # pragma GCC diagnostic ignored "-Wmissing-field-initializers"
  73. # pragma GCC diagnostic ignored "-Wreorder"
  74. # pragma GCC diagnostic ignored "-Woverloaded-virtual"
  75. # pragma GCC diagnostic ignored "-Wsign-compare"
  76. # pragma GCC diagnostic ignored "-Wunneeded-internal-declaration"
  77. # pragma GCC diagnostic ignored "-Wunused-parameter"
  78. # pragma GCC diagnostic ignored "-Wunused-private-field"
  79. # pragma GCC diagnostic ignored "-Wunused-variable"
  80. # pragma GCC diagnostic ignored "-Wdelete-non-virtual-dtor"
  81. # if !defined(__clang__)
  82. # pragma GCC diagnostic ignored "-Wformat="
  83. # pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
  84. # endif
  85. #endif
  86. /*
  87. * C99 inline keyword
  88. */
  89. #ifndef inline
  90. # ifdef __cplusplus
  91. /* C++ supports inline keyword */
  92. # elif defined(__GNUC__)
  93. # define inline __inline__
  94. # elif defined(_MSC_VER)
  95. # define inline __inline
  96. # elif defined(__ICL)
  97. # define inline __inline
  98. # elif defined(__INTEL_COMPILER)
  99. /* Intel compiler supports inline keyword */
  100. # elif defined(__WATCOMC__) && (__WATCOMC__ >= 1100)
  101. # define inline __inline
  102. # elif defined(__SUNPRO_C) && defined(__C99FEATURES__)
  103. /* C99 supports inline keyword */
  104. # elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
  105. /* C99 supports inline keyword */
  106. # else
  107. # define inline
  108. # endif
  109. #endif
  110. /*
  111. * C99 restrict keyword
  112. *
  113. * See also:
  114. * - http://cellperformance.beyond3d.com/articles/2006/05/demystifying-the-restrict-keyword.html
  115. */
  116. #ifndef restrict
  117. # if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
  118. /* C99 */
  119. # elif defined(__SUNPRO_C) && defined(__C99FEATURES__)
  120. /* C99 */
  121. # elif defined(__GNUC__)
  122. # define restrict __restrict__
  123. # elif defined(_MSC_VER)
  124. # define restrict __restrict
  125. # else
  126. # define restrict /* */
  127. # endif
  128. #endif
  129. /*
  130. * C99 __func__ macro
  131. */
  132. #ifndef __func__
  133. # if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && !defined(_MSC_VER)
  134. /* C99 */
  135. # elif defined(__SUNPRO_C) && defined(__C99FEATURES__)
  136. /* C99 */
  137. # elif defined(__GNUC__)
  138. # if __GNUC__ >= 2
  139. # define __func__ __FUNCTION__
  140. # else
  141. # define __func__ "<unknown>"
  142. # endif
  143. # elif defined(_MSC_VER)
  144. # if _MSC_VER >= 1300
  145. # define __func__ __FUNCTION__
  146. # else
  147. # define __func__ "<unknown>"
  148. # endif
  149. # else
  150. # define __func__ "<unknown>"
  151. # endif
  152. #endif
  153. /* Simple test case for debugging */
  154. #if 0
  155. static inline const char *
  156. test_c99_compat_h(const void * restrict a,
  157. const void * restrict b)
  158. {
  159. return __func__;
  160. }
  161. #endif
  162. #endif /* _C99_COMPAT_H_ */