tcc 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (283) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +35 -0
  3. data/README.md +196 -0
  4. data/ext/tcc/extconf.rb +25 -0
  5. data/ext/tcc/tcc-0.9.26.patch +30 -0
  6. data/ext/tcc/tcc-0.9.26/COPYING +504 -0
  7. data/ext/tcc/tcc-0.9.26/Changelog +396 -0
  8. data/ext/tcc/tcc-0.9.26/Makefile +349 -0
  9. data/ext/tcc/tcc-0.9.26/README +101 -0
  10. data/ext/tcc/tcc-0.9.26/TODO +93 -0
  11. data/ext/tcc/tcc-0.9.26/VERSION +1 -0
  12. data/ext/tcc/tcc-0.9.26/arm-gen.c +2005 -0
  13. data/ext/tcc/tcc-0.9.26/c67-gen.c +2560 -0
  14. data/ext/tcc/tcc-0.9.26/coff.h +446 -0
  15. data/ext/tcc/tcc-0.9.26/config.h +8 -0
  16. data/ext/tcc/tcc-0.9.26/config.mak +28 -0
  17. data/ext/tcc/tcc-0.9.26/config.texi +1 -0
  18. data/ext/tcc/tcc-0.9.26/configure +540 -0
  19. data/ext/tcc/tcc-0.9.26/conftest.c +71 -0
  20. data/ext/tcc/tcc-0.9.26/elf.h +1731 -0
  21. data/ext/tcc/tcc-0.9.26/examples/ex1.c +8 -0
  22. data/ext/tcc/tcc-0.9.26/examples/ex2.c +98 -0
  23. data/ext/tcc/tcc-0.9.26/examples/ex3.c +24 -0
  24. data/ext/tcc/tcc-0.9.26/examples/ex4.c +26 -0
  25. data/ext/tcc/tcc-0.9.26/examples/ex5.c +8 -0
  26. data/ext/tcc/tcc-0.9.26/i386-asm.c +1498 -0
  27. data/ext/tcc/tcc-0.9.26/i386-asm.h +473 -0
  28. data/ext/tcc/tcc-0.9.26/i386-gen.c +1096 -0
  29. data/ext/tcc/tcc-0.9.26/i386-tok.h +243 -0
  30. data/ext/tcc/tcc-0.9.26/il-gen.c +667 -0
  31. data/ext/tcc/tcc-0.9.26/il-opcodes.h +251 -0
  32. data/ext/tcc/tcc-0.9.26/include/float.h +57 -0
  33. data/ext/tcc/tcc-0.9.26/include/stdarg.h +41 -0
  34. data/ext/tcc/tcc-0.9.26/include/stdbool.h +10 -0
  35. data/ext/tcc/tcc-0.9.26/include/stddef.h +28 -0
  36. data/ext/tcc/tcc-0.9.26/include/tcclib.h +78 -0
  37. data/ext/tcc/tcc-0.9.26/include/varargs.h +12 -0
  38. data/ext/tcc/tcc-0.9.26/lib/Makefile +102 -0
  39. data/ext/tcc/tcc-0.9.26/lib/alloca86-bt.S +47 -0
  40. data/ext/tcc/tcc-0.9.26/lib/alloca86.S +35 -0
  41. data/ext/tcc/tcc-0.9.26/lib/alloca86_64.S +42 -0
  42. data/ext/tcc/tcc-0.9.26/lib/bcheck.c +875 -0
  43. data/ext/tcc/tcc-0.9.26/lib/libtcc1.c +691 -0
  44. data/ext/tcc/tcc-0.9.26/libtcc.c +1941 -0
  45. data/ext/tcc/tcc-0.9.26/libtcc.h +103 -0
  46. data/ext/tcc/tcc-0.9.26/stab.def +234 -0
  47. data/ext/tcc/tcc-0.9.26/stab.h +17 -0
  48. data/ext/tcc/tcc-0.9.26/tcc-doc.html +2332 -0
  49. data/ext/tcc/tcc-0.9.26/tcc-doc.info +1151 -0
  50. data/ext/tcc/tcc-0.9.26/tcc-doc.texi +1268 -0
  51. data/ext/tcc/tcc-0.9.26/tcc.1 +415 -0
  52. data/ext/tcc/tcc-0.9.26/tcc.c +352 -0
  53. data/ext/tcc/tcc-0.9.26/tcc.h +1379 -0
  54. data/ext/tcc/tcc-0.9.26/tccasm.c +1118 -0
  55. data/ext/tcc/tcc-0.9.26/tcccoff.c +948 -0
  56. data/ext/tcc/tcc-0.9.26/tccelf.c +3129 -0
  57. data/ext/tcc/tcc-0.9.26/tccgen.c +5841 -0
  58. data/ext/tcc/tcc-0.9.26/tccpe.c +1887 -0
  59. data/ext/tcc/tcc-0.9.26/tccpp.c +3128 -0
  60. data/ext/tcc/tcc-0.9.26/tccrun.c +737 -0
  61. data/ext/tcc/tcc-0.9.26/tcctok.h +278 -0
  62. data/ext/tcc/tcc-0.9.26/tests/Makefile +199 -0
  63. data/ext/tcc/tcc-0.9.26/tests/asmtest.S +609 -0
  64. data/ext/tcc/tcc-0.9.26/tests/boundtest.c +233 -0
  65. data/ext/tcc/tcc-0.9.26/tests/gcctestsuite.sh +33 -0
  66. data/ext/tcc/tcc-0.9.26/tests/libtcc_test.c +76 -0
  67. data/ext/tcc/tcc-0.9.26/tests/tcctest.c +2713 -0
  68. data/ext/tcc/tcc-0.9.26/tests/tests2/00_assignment.c +18 -0
  69. data/ext/tcc/tcc-0.9.26/tests/tests2/00_assignment.expect +3 -0
  70. data/ext/tcc/tcc-0.9.26/tests/tests2/01_comment.c +14 -0
  71. data/ext/tcc/tcc-0.9.26/tests/tests2/01_comment.expect +5 -0
  72. data/ext/tcc/tcc-0.9.26/tests/tests2/02_printf.c +18 -0
  73. data/ext/tcc/tcc-0.9.26/tests/tests2/02_printf.expect +15 -0
  74. data/ext/tcc/tcc-0.9.26/tests/tests2/03_struct.c +31 -0
  75. data/ext/tcc/tcc-0.9.26/tests/tests2/03_struct.expect +6 -0
  76. data/ext/tcc/tcc-0.9.26/tests/tests2/04_for.c +15 -0
  77. data/ext/tcc/tcc-0.9.26/tests/tests2/04_for.expect +10 -0
  78. data/ext/tcc/tcc-0.9.26/tests/tests2/05_array.c +21 -0
  79. data/ext/tcc/tcc-0.9.26/tests/tests2/05_array.expect +10 -0
  80. data/ext/tcc/tcc-0.9.26/tests/tests2/06_case.c +29 -0
  81. data/ext/tcc/tcc-0.9.26/tests/tests2/06_case.expect +8 -0
  82. data/ext/tcc/tcc-0.9.26/tests/tests2/07_function.c +30 -0
  83. data/ext/tcc/tcc-0.9.26/tests/tests2/07_function.expect +4 -0
  84. data/ext/tcc/tcc-0.9.26/tests/tests2/08_while.c +24 -0
  85. data/ext/tcc/tcc-0.9.26/tests/tests2/08_while.expect +11 -0
  86. data/ext/tcc/tcc-0.9.26/tests/tests2/09_do_while.c +24 -0
  87. data/ext/tcc/tcc-0.9.26/tests/tests2/09_do_while.expect +11 -0
  88. data/ext/tcc/tcc-0.9.26/tests/tests2/10_pointer.c +40 -0
  89. data/ext/tcc/tcc-0.9.26/tests/tests2/10_pointer.expect +8 -0
  90. data/ext/tcc/tcc-0.9.26/tests/tests2/11_precedence.c +40 -0
  91. data/ext/tcc/tcc-0.9.26/tests/tests2/11_precedence.expect +15 -0
  92. data/ext/tcc/tcc-0.9.26/tests/tests2/12_hashdefine.c +14 -0
  93. data/ext/tcc/tcc-0.9.26/tests/tests2/12_hashdefine.expect +2 -0
  94. data/ext/tcc/tcc-0.9.26/tests/tests2/13_integer_literals.c +20 -0
  95. data/ext/tcc/tcc-0.9.26/tests/tests2/13_integer_literals.expect +5 -0
  96. data/ext/tcc/tcc-0.9.26/tests/tests2/14_if.c +21 -0
  97. data/ext/tcc/tcc-0.9.26/tests/tests2/14_if.expect +2 -0
  98. data/ext/tcc/tcc-0.9.26/tests/tests2/15_recursion.c +21 -0
  99. data/ext/tcc/tcc-0.9.26/tests/tests2/15_recursion.expect +10 -0
  100. data/ext/tcc/tcc-0.9.26/tests/tests2/16_nesting.c +21 -0
  101. data/ext/tcc/tcc-0.9.26/tests/tests2/16_nesting.expect +18 -0
  102. data/ext/tcc/tcc-0.9.26/tests/tests2/17_enum.c +29 -0
  103. data/ext/tcc/tcc-0.9.26/tests/tests2/17_enum.expect +3 -0
  104. data/ext/tcc/tcc-0.9.26/tests/tests2/18_include.c +12 -0
  105. data/ext/tcc/tcc-0.9.26/tests/tests2/18_include.expect +3 -0
  106. data/ext/tcc/tcc-0.9.26/tests/tests2/18_include.h +1 -0
  107. data/ext/tcc/tcc-0.9.26/tests/tests2/19_pointer_arithmetic.c +28 -0
  108. data/ext/tcc/tcc-0.9.26/tests/tests2/19_pointer_arithmetic.expect +3 -0
  109. data/ext/tcc/tcc-0.9.26/tests/tests2/20_pointer_comparison.c +24 -0
  110. data/ext/tcc/tcc-0.9.26/tests/tests2/20_pointer_comparison.expect +6 -0
  111. data/ext/tcc/tcc-0.9.26/tests/tests2/21_char_array.c +33 -0
  112. data/ext/tcc/tcc-0.9.26/tests/tests2/21_char_array.expect +7 -0
  113. data/ext/tcc/tcc-0.9.26/tests/tests2/22_floating_point.c +50 -0
  114. data/ext/tcc/tcc-0.9.26/tests/tests2/22_floating_point.expect +16 -0
  115. data/ext/tcc/tcc-0.9.26/tests/tests2/23_type_coercion.c +54 -0
  116. data/ext/tcc/tcc-0.9.26/tests/tests2/23_type_coercion.expect +12 -0
  117. data/ext/tcc/tcc-0.9.26/tests/tests2/24_math_library.c +28 -0
  118. data/ext/tcc/tcc-0.9.26/tests/tests2/24_math_library.expect +18 -0
  119. data/ext/tcc/tcc-0.9.26/tests/tests2/25_quicksort.c +83 -0
  120. data/ext/tcc/tcc-0.9.26/tests/tests2/25_quicksort.expect +2 -0
  121. data/ext/tcc/tcc-0.9.26/tests/tests2/26_character_constants.c +17 -0
  122. data/ext/tcc/tcc-0.9.26/tests/tests2/26_character_constants.expect +8 -0
  123. data/ext/tcc/tcc-0.9.26/tests/tests2/27_sizeof.c +16 -0
  124. data/ext/tcc/tcc-0.9.26/tests/tests2/27_sizeof.expect +3 -0
  125. data/ext/tcc/tcc-0.9.26/tests/tests2/28_strings.c +46 -0
  126. data/ext/tcc/tcc-0.9.26/tests/tests2/28_strings.expect +19 -0
  127. data/ext/tcc/tcc-0.9.26/tests/tests2/29_array_address.c +13 -0
  128. data/ext/tcc/tcc-0.9.26/tests/tests2/29_array_address.expect +1 -0
  129. data/ext/tcc/tcc-0.9.26/tests/tests2/30_hanoi.c +122 -0
  130. data/ext/tcc/tcc-0.9.26/tests/tests2/30_hanoi.expect +71 -0
  131. data/ext/tcc/tcc-0.9.26/tests/tests2/31_args.c +14 -0
  132. data/ext/tcc/tcc-0.9.26/tests/tests2/31_args.expect +7 -0
  133. data/ext/tcc/tcc-0.9.26/tests/tests2/32_led.c +266 -0
  134. data/ext/tcc/tcc-0.9.26/tests/tests2/32_led.expect +4 -0
  135. data/ext/tcc/tcc-0.9.26/tests/tests2/33_ternary_op.c +15 -0
  136. data/ext/tcc/tcc-0.9.26/tests/tests2/33_ternary_op.expect +10 -0
  137. data/ext/tcc/tcc-0.9.26/tests/tests2/34_array_assignment.c +23 -0
  138. data/ext/tcc/tcc-0.9.26/tests/tests2/34_array_assignment.expect +2 -0
  139. data/ext/tcc/tcc-0.9.26/tests/tests2/35_sizeof.c +14 -0
  140. data/ext/tcc/tcc-0.9.26/tests/tests2/35_sizeof.expect +2 -0
  141. data/ext/tcc/tcc-0.9.26/tests/tests2/36_array_initialisers.c +21 -0
  142. data/ext/tcc/tcc-0.9.26/tests/tests2/36_array_initialisers.expect +20 -0
  143. data/ext/tcc/tcc-0.9.26/tests/tests2/37_sprintf.c +17 -0
  144. data/ext/tcc/tcc-0.9.26/tests/tests2/37_sprintf.expect +20 -0
  145. data/ext/tcc/tcc-0.9.26/tests/tests2/38_multiple_array_index.c +32 -0
  146. data/ext/tcc/tcc-0.9.26/tests/tests2/38_multiple_array_index.expect +4 -0
  147. data/ext/tcc/tcc-0.9.26/tests/tests2/39_typedef.c +31 -0
  148. data/ext/tcc/tcc-0.9.26/tests/tests2/39_typedef.expect +3 -0
  149. data/ext/tcc/tcc-0.9.26/tests/tests2/40_stdio.c +52 -0
  150. data/ext/tcc/tcc-0.9.26/tests/tests2/40_stdio.expect +27 -0
  151. data/ext/tcc/tcc-0.9.26/tests/tests2/41_hashif.c +85 -0
  152. data/ext/tcc/tcc-0.9.26/tests/tests2/41_hashif.expect +6 -0
  153. data/ext/tcc/tcc-0.9.26/tests/tests2/42_function_pointer.c +18 -0
  154. data/ext/tcc/tcc-0.9.26/tests/tests2/42_function_pointer.expect +2 -0
  155. data/ext/tcc/tcc-0.9.26/tests/tests2/43_void_param.c +15 -0
  156. data/ext/tcc/tcc-0.9.26/tests/tests2/43_void_param.expect +1 -0
  157. data/ext/tcc/tcc-0.9.26/tests/tests2/44_scoped_declarations.c +17 -0
  158. data/ext/tcc/tcc-0.9.26/tests/tests2/44_scoped_declarations.expect +1 -0
  159. data/ext/tcc/tcc-0.9.26/tests/tests2/45_empty_for.c +18 -0
  160. data/ext/tcc/tcc-0.9.26/tests/tests2/45_empty_for.expect +10 -0
  161. data/ext/tcc/tcc-0.9.26/tests/tests2/46_grep.c +564 -0
  162. data/ext/tcc/tcc-0.9.26/tests/tests2/47_switch_return.c +24 -0
  163. data/ext/tcc/tcc-0.9.26/tests/tests2/47_switch_return.expect +4 -0
  164. data/ext/tcc/tcc-0.9.26/tests/tests2/48_nested_break.c +26 -0
  165. data/ext/tcc/tcc-0.9.26/tests/tests2/48_nested_break.expect +1 -0
  166. data/ext/tcc/tcc-0.9.26/tests/tests2/49_bracket_evaluation.c +23 -0
  167. data/ext/tcc/tcc-0.9.26/tests/tests2/49_bracket_evaluation.expect +1 -0
  168. data/ext/tcc/tcc-0.9.26/tests/tests2/50_logical_second_arg.c +29 -0
  169. data/ext/tcc/tcc-0.9.26/tests/tests2/50_logical_second_arg.expect +20 -0
  170. data/ext/tcc/tcc-0.9.26/tests/tests2/51_static.c +30 -0
  171. data/ext/tcc/tcc-0.9.26/tests/tests2/51_static.expect +8 -0
  172. data/ext/tcc/tcc-0.9.26/tests/tests2/52_unnamed_enum.c +27 -0
  173. data/ext/tcc/tcc-0.9.26/tests/tests2/52_unnamed_enum.expect +9 -0
  174. data/ext/tcc/tcc-0.9.26/tests/tests2/54_goto.c +56 -0
  175. data/ext/tcc/tcc-0.9.26/tests/tests2/54_goto.expect +8 -0
  176. data/ext/tcc/tcc-0.9.26/tests/tests2/55_lshift_type.c +52 -0
  177. data/ext/tcc/tcc-0.9.26/tests/tests2/55_lshift_type.expect +1 -0
  178. data/ext/tcc/tcc-0.9.26/tests/tests2/LICENSE +37 -0
  179. data/ext/tcc/tcc-0.9.26/tests/tests2/Makefile +98 -0
  180. data/ext/tcc/tcc-0.9.26/texi2pod.pl +427 -0
  181. data/ext/tcc/tcc-0.9.26/win32/build-tcc.bat +60 -0
  182. data/ext/tcc/tcc-0.9.26/win32/examples/dll.c +12 -0
  183. data/ext/tcc/tcc-0.9.26/win32/examples/fib.c +23 -0
  184. data/ext/tcc/tcc-0.9.26/win32/examples/hello_dll.c +19 -0
  185. data/ext/tcc/tcc-0.9.26/win32/examples/hello_win.c +163 -0
  186. data/ext/tcc/tcc-0.9.26/win32/include/_mingw.h +139 -0
  187. data/ext/tcc/tcc-0.9.26/win32/include/assert.h +54 -0
  188. data/ext/tcc/tcc-0.9.26/win32/include/conio.h +409 -0
  189. data/ext/tcc/tcc-0.9.26/win32/include/ctype.h +281 -0
  190. data/ext/tcc/tcc-0.9.26/win32/include/dir.h +31 -0
  191. data/ext/tcc/tcc-0.9.26/win32/include/direct.h +68 -0
  192. data/ext/tcc/tcc-0.9.26/win32/include/dirent.h +135 -0
  193. data/ext/tcc/tcc-0.9.26/win32/include/dos.h +55 -0
  194. data/ext/tcc/tcc-0.9.26/win32/include/errno.h +75 -0
  195. data/ext/tcc/tcc-0.9.26/win32/include/excpt.h +123 -0
  196. data/ext/tcc/tcc-0.9.26/win32/include/fcntl.h +52 -0
  197. data/ext/tcc/tcc-0.9.26/win32/include/fenv.h +108 -0
  198. data/ext/tcc/tcc-0.9.26/win32/include/inttypes.h +297 -0
  199. data/ext/tcc/tcc-0.9.26/win32/include/io.h +418 -0
  200. data/ext/tcc/tcc-0.9.26/win32/include/limits.h +111 -0
  201. data/ext/tcc/tcc-0.9.26/win32/include/locale.h +91 -0
  202. data/ext/tcc/tcc-0.9.26/win32/include/malloc.h +175 -0
  203. data/ext/tcc/tcc-0.9.26/win32/include/math.h +777 -0
  204. data/ext/tcc/tcc-0.9.26/win32/include/mem.h +13 -0
  205. data/ext/tcc/tcc-0.9.26/win32/include/memory.h +40 -0
  206. data/ext/tcc/tcc-0.9.26/win32/include/process.h +176 -0
  207. data/ext/tcc/tcc-0.9.26/win32/include/sec_api/conio_s.h +42 -0
  208. data/ext/tcc/tcc-0.9.26/win32/include/sec_api/crtdbg_s.h +19 -0
  209. data/ext/tcc/tcc-0.9.26/win32/include/sec_api/io_s.h +33 -0
  210. data/ext/tcc/tcc-0.9.26/win32/include/sec_api/mbstring_s.h +52 -0
  211. data/ext/tcc/tcc-0.9.26/win32/include/sec_api/search_s.h +25 -0
  212. data/ext/tcc/tcc-0.9.26/win32/include/sec_api/stdio_s.h +145 -0
  213. data/ext/tcc/tcc-0.9.26/win32/include/sec_api/stdlib_s.h +67 -0
  214. data/ext/tcc/tcc-0.9.26/win32/include/sec_api/stralign_s.h +30 -0
  215. data/ext/tcc/tcc-0.9.26/win32/include/sec_api/string_s.h +41 -0
  216. data/ext/tcc/tcc-0.9.26/win32/include/sec_api/sys/timeb_s.h +34 -0
  217. data/ext/tcc/tcc-0.9.26/win32/include/sec_api/tchar_s.h +266 -0
  218. data/ext/tcc/tcc-0.9.26/win32/include/sec_api/time_s.h +61 -0
  219. data/ext/tcc/tcc-0.9.26/win32/include/sec_api/wchar_s.h +128 -0
  220. data/ext/tcc/tcc-0.9.26/win32/include/setjmp.h +160 -0
  221. data/ext/tcc/tcc-0.9.26/win32/include/share.h +28 -0
  222. data/ext/tcc/tcc-0.9.26/win32/include/signal.h +63 -0
  223. data/ext/tcc/tcc-0.9.26/win32/include/stdint.h +209 -0
  224. data/ext/tcc/tcc-0.9.26/win32/include/stdio.h +429 -0
  225. data/ext/tcc/tcc-0.9.26/win32/include/stdlib.h +580 -0
  226. data/ext/tcc/tcc-0.9.26/win32/include/string.h +164 -0
  227. data/ext/tcc/tcc-0.9.26/win32/include/sys/fcntl.h +13 -0
  228. data/ext/tcc/tcc-0.9.26/win32/include/sys/file.h +14 -0
  229. data/ext/tcc/tcc-0.9.26/win32/include/sys/locking.h +30 -0
  230. data/ext/tcc/tcc-0.9.26/win32/include/sys/stat.h +290 -0
  231. data/ext/tcc/tcc-0.9.26/win32/include/sys/time.h +69 -0
  232. data/ext/tcc/tcc-0.9.26/win32/include/sys/timeb.h +133 -0
  233. data/ext/tcc/tcc-0.9.26/win32/include/sys/types.h +118 -0
  234. data/ext/tcc/tcc-0.9.26/win32/include/sys/unistd.h +14 -0
  235. data/ext/tcc/tcc-0.9.26/win32/include/sys/utime.h +146 -0
  236. data/ext/tcc/tcc-0.9.26/win32/include/tchar.h +1102 -0
  237. data/ext/tcc/tcc-0.9.26/win32/include/time.h +287 -0
  238. data/ext/tcc/tcc-0.9.26/win32/include/vadefs.h +11 -0
  239. data/ext/tcc/tcc-0.9.26/win32/include/values.h +4 -0
  240. data/ext/tcc/tcc-0.9.26/win32/include/wchar.h +871 -0
  241. data/ext/tcc/tcc-0.9.26/win32/include/wctype.h +172 -0
  242. data/ext/tcc/tcc-0.9.26/win32/include/winapi/basetsd.h +149 -0
  243. data/ext/tcc/tcc-0.9.26/win32/include/winapi/basetyps.h +85 -0
  244. data/ext/tcc/tcc-0.9.26/win32/include/winapi/guiddef.h +151 -0
  245. data/ext/tcc/tcc-0.9.26/win32/include/winapi/intrin.h +11 -0
  246. data/ext/tcc/tcc-0.9.26/win32/include/winapi/poppack.h +8 -0
  247. data/ext/tcc/tcc-0.9.26/win32/include/winapi/pshpack1.h +8 -0
  248. data/ext/tcc/tcc-0.9.26/win32/include/winapi/pshpack2.h +8 -0
  249. data/ext/tcc/tcc-0.9.26/win32/include/winapi/pshpack4.h +8 -0
  250. data/ext/tcc/tcc-0.9.26/win32/include/winapi/pshpack8.h +8 -0
  251. data/ext/tcc/tcc-0.9.26/win32/include/winapi/reason.h +80 -0
  252. data/ext/tcc/tcc-0.9.26/win32/include/winapi/specstrings.h +7 -0
  253. data/ext/tcc/tcc-0.9.26/win32/include/winapi/stralign.h +154 -0
  254. data/ext/tcc/tcc-0.9.26/win32/include/winapi/tvout.h +79 -0
  255. data/ext/tcc/tcc-0.9.26/win32/include/winapi/winbase.h +2951 -0
  256. data/ext/tcc/tcc-0.9.26/win32/include/winapi/wincon.h +301 -0
  257. data/ext/tcc/tcc-0.9.26/win32/include/winapi/windef.h +293 -0
  258. data/ext/tcc/tcc-0.9.26/win32/include/winapi/windows.h +123 -0
  259. data/ext/tcc/tcc-0.9.26/win32/include/winapi/winerror.h +3166 -0
  260. data/ext/tcc/tcc-0.9.26/win32/include/winapi/wingdi.h +4080 -0
  261. data/ext/tcc/tcc-0.9.26/win32/include/winapi/winnetwk.h +476 -0
  262. data/ext/tcc/tcc-0.9.26/win32/include/winapi/winnls.h +765 -0
  263. data/ext/tcc/tcc-0.9.26/win32/include/winapi/winnt.h +5770 -0
  264. data/ext/tcc/tcc-0.9.26/win32/include/winapi/winreg.h +272 -0
  265. data/ext/tcc/tcc-0.9.26/win32/include/winapi/winuser.h +5651 -0
  266. data/ext/tcc/tcc-0.9.26/win32/include/winapi/winver.h +160 -0
  267. data/ext/tcc/tcc-0.9.26/win32/lib/chkstk.S +191 -0
  268. data/ext/tcc/tcc-0.9.26/win32/lib/crt1.c +34 -0
  269. data/ext/tcc/tcc-0.9.26/win32/lib/dllcrt1.c +13 -0
  270. data/ext/tcc/tcc-0.9.26/win32/lib/dllmain.c +9 -0
  271. data/ext/tcc/tcc-0.9.26/win32/lib/gdi32.def +337 -0
  272. data/ext/tcc/tcc-0.9.26/win32/lib/kernel32.def +765 -0
  273. data/ext/tcc/tcc-0.9.26/win32/lib/msvcrt.def +1399 -0
  274. data/ext/tcc/tcc-0.9.26/win32/lib/user32.def +654 -0
  275. data/ext/tcc/tcc-0.9.26/win32/lib/wincrt1.c +64 -0
  276. data/ext/tcc/tcc-0.9.26/win32/tcc-win32.txt +156 -0
  277. data/ext/tcc/tcc-0.9.26/win32/tools/tiny_impdef.c +243 -0
  278. data/ext/tcc/tcc-0.9.26/win32/tools/tiny_libmaker.c +258 -0
  279. data/ext/tcc/tcc-0.9.26/x86_64-asm.h +448 -0
  280. data/ext/tcc/tcc-0.9.26/x86_64-gen.c +1701 -0
  281. data/lib/tcc.rb +291 -0
  282. data/tcc.gemspec +15 -0
  283. metadata +343 -0
@@ -0,0 +1,233 @@
1
+ #include <stdlib.h>
2
+ #include <stdio.h>
3
+
4
+ #define NB_ITS 1000000
5
+ //#define NB_ITS 1
6
+ #define TAB_SIZE 100
7
+
8
+ int tab[TAB_SIZE];
9
+ int ret_sum;
10
+ char tab3[256];
11
+
12
+ int test1(void)
13
+ {
14
+ int i, sum = 0;
15
+ for(i=0;i<TAB_SIZE;i++) {
16
+ sum += tab[i];
17
+ }
18
+ return sum;
19
+ }
20
+
21
+ /* error */
22
+ int test2(void)
23
+ {
24
+ int i, sum = 0;
25
+ for(i=0;i<TAB_SIZE + 1;i++) {
26
+ sum += tab[i];
27
+ }
28
+ return sum;
29
+ }
30
+
31
+ /* actually, profiling test */
32
+ int test3(void)
33
+ {
34
+ int sum;
35
+ int i, it;
36
+
37
+ sum = 0;
38
+ for(it=0;it<NB_ITS;it++) {
39
+ for(i=0;i<TAB_SIZE;i++) {
40
+ sum += tab[i];
41
+ }
42
+ }
43
+ return sum;
44
+ }
45
+
46
+ /* ok */
47
+ int test4(void)
48
+ {
49
+ int i, sum = 0;
50
+ int *tab4;
51
+
52
+ tab4 = malloc(20 * sizeof(int));
53
+ for(i=0;i<20;i++) {
54
+ sum += tab4[i];
55
+ }
56
+ free(tab4);
57
+
58
+ return sum;
59
+ }
60
+
61
+ /* error */
62
+ int test5(void)
63
+ {
64
+ int i, sum = 0;
65
+ int *tab4;
66
+
67
+ tab4 = malloc(20 * sizeof(int));
68
+ for(i=0;i<21;i++) {
69
+ sum += tab4[i];
70
+ }
71
+ free(tab4);
72
+
73
+ return sum;
74
+ }
75
+
76
+ /* error */
77
+ /* XXX: currently: bug */
78
+ int test6(void)
79
+ {
80
+ int i, sum = 0;
81
+ int *tab4;
82
+
83
+ tab4 = malloc(20 * sizeof(int));
84
+ free(tab4);
85
+ for(i=0;i<21;i++) {
86
+ sum += tab4[i];
87
+ }
88
+
89
+ return sum;
90
+ }
91
+
92
+ /* error */
93
+ int test7(void)
94
+ {
95
+ int i, sum = 0;
96
+ int *p;
97
+
98
+ for(i=0;i<TAB_SIZE + 1;i++) {
99
+ p = &tab[i];
100
+ if (i == TAB_SIZE)
101
+ printf("i=%d %x\n", i, p);
102
+ sum += *p;
103
+ }
104
+ return sum;
105
+ }
106
+
107
+ /* ok */
108
+ int test8(void)
109
+ {
110
+ int i, sum = 0;
111
+ int tab[10];
112
+
113
+ for(i=0;i<10;i++) {
114
+ sum += tab[i];
115
+ }
116
+ return sum;
117
+ }
118
+
119
+ /* error */
120
+ int test9(void)
121
+ {
122
+ int i, sum = 0;
123
+ char tab[10];
124
+
125
+ for(i=0;i<11;i++) {
126
+ sum += tab[i];
127
+ }
128
+ return sum;
129
+ }
130
+
131
+ /* ok */
132
+ int test10(void)
133
+ {
134
+ char tab[10];
135
+ char tab1[10];
136
+
137
+ memset(tab, 0, 10);
138
+ memcpy(tab, tab1, 10);
139
+ memmove(tab, tab1, 10);
140
+ return 0;
141
+ }
142
+
143
+ /* error */
144
+ int test11(void)
145
+ {
146
+ char tab[10];
147
+
148
+ memset(tab, 0, 11);
149
+ return 0;
150
+ }
151
+
152
+ /* error */
153
+ int test12(void)
154
+ {
155
+ void *ptr;
156
+ ptr = malloc(10);
157
+ free(ptr);
158
+ free(ptr);
159
+ return 0;
160
+ }
161
+
162
+ /* error */
163
+ int test13(void)
164
+ {
165
+ char pad1 = 0;
166
+ char tab[10];
167
+ char pad2 = 0;
168
+ memset(tab, 'a', sizeof(tab));
169
+ return strlen(tab);
170
+ }
171
+
172
+ int test14(void)
173
+ {
174
+ char *p = alloca(TAB_SIZE);
175
+ memset(p, 'a', TAB_SIZE);
176
+ p[TAB_SIZE-1] = 0;
177
+ return strlen(p);
178
+ }
179
+
180
+ /* error */
181
+ int test15(void)
182
+ {
183
+ char *p = alloca(TAB_SIZE-1);
184
+ memset(p, 'a', TAB_SIZE);
185
+ p[TAB_SIZE-1] = 0;
186
+ return strlen(p);
187
+ }
188
+
189
+ int (*table_test[])(void) = {
190
+ test1,
191
+ test1,
192
+ test2,
193
+ test3,
194
+ test4,
195
+ test5,
196
+ test6,
197
+ test7,
198
+ test8,
199
+ test9,
200
+ test10,
201
+ test11,
202
+ test12,
203
+ test13,
204
+ test14,
205
+ test15,
206
+ };
207
+
208
+ int main(int argc, char **argv)
209
+ {
210
+ int index;
211
+ int (*ftest)(void);
212
+
213
+ if (argc < 2) {
214
+ printf("usage: boundtest n\n"
215
+ "test TCC bound checking system\n"
216
+ );
217
+ exit(1);
218
+ }
219
+
220
+ index = 0;
221
+ if (argc >= 2)
222
+ index = atoi(argv[1]);
223
+ /* well, we also use bounds on this ! */
224
+ ftest = table_test[index];
225
+ ftest();
226
+
227
+ return 0;
228
+ }
229
+
230
+ /*
231
+ * without bound 0.77 s
232
+ * with bounds 4.73
233
+ */
@@ -0,0 +1,33 @@
1
+ #!/bin/sh
2
+
3
+ TESTSUITE_PATH=$HOME/gcc/gcc-3.2/gcc/testsuite/gcc.c-torture
4
+ TCC="./tcc -B. -I. -DNO_TRAMPOLINES"
5
+ rm -f tcc.sum tcc.log
6
+ nb_failed="0"
7
+
8
+ for src in $TESTSUITE_PATH/compile/*.c ; do
9
+ echo $TCC -o /tmp/test.o -c $src
10
+ $TCC -o /tmp/test.o -c $src >> tcc.log 2>&1
11
+ if [ "$?" = "0" ] ; then
12
+ result="PASS"
13
+ else
14
+ result="FAIL"
15
+ nb_failed=$(( $nb_failed + 1 ))
16
+ fi
17
+ echo "$result: $src" >> tcc.sum
18
+ done
19
+
20
+ for src in $TESTSUITE_PATH/execute/*.c ; do
21
+ echo $TCC $src
22
+ $TCC $src >> tcc.log 2>&1
23
+ if [ "$?" = "0" ] ; then
24
+ result="PASS"
25
+ else
26
+ result="FAIL"
27
+ nb_failed=$(( $nb_failed + 1 ))
28
+ fi
29
+ echo "$result: $src" >> tcc.sum
30
+ done
31
+
32
+ echo "$nb_failed test(s) failed." >> tcc.sum
33
+ echo "$nb_failed test(s) failed."
@@ -0,0 +1,76 @@
1
+ /*
2
+ * Simple Test program for libtcc
3
+ *
4
+ * libtcc can be useful to use tcc as a "backend" for a code generator.
5
+ */
6
+ #include <stdlib.h>
7
+ #include <stdio.h>
8
+ #include <string.h>
9
+
10
+ #include "libtcc.h"
11
+
12
+ /* this function is called by the generated code */
13
+ int add(int a, int b)
14
+ {
15
+ return a + b;
16
+ }
17
+
18
+ char my_program[] =
19
+ "int fib(int n)\n"
20
+ "{\n"
21
+ " if (n <= 2)\n"
22
+ " return 1;\n"
23
+ " else\n"
24
+ " return fib(n-1) + fib(n-2);\n"
25
+ "}\n"
26
+ "\n"
27
+ "int foo(int n)\n"
28
+ "{\n"
29
+ " printf(\"Hello World!\\n\");\n"
30
+ " printf(\"fib(%d) = %d\\n\", n, fib(n));\n"
31
+ " printf(\"add(%d, %d) = %d\\n\", n, 2 * n, add(n, 2 * n));\n"
32
+ " return 0;\n"
33
+ "}\n";
34
+
35
+ int main(int argc, char **argv)
36
+ {
37
+ TCCState *s;
38
+ int (*func)(int);
39
+
40
+ s = tcc_new();
41
+ if (!s) {
42
+ fprintf(stderr, "Could not create tcc state\n");
43
+ exit(1);
44
+ }
45
+
46
+ /* if tcclib.h and libtcc1.a are not installed, where can we find them */
47
+ if (argc == 2 && !memcmp(argv[1], "lib_path=",9))
48
+ tcc_set_lib_path(s, argv[1]+9);
49
+
50
+ /* MUST BE CALLED before any compilation */
51
+ tcc_set_output_type(s, TCC_OUTPUT_MEMORY);
52
+
53
+ if (tcc_compile_string(s, my_program) == -1)
54
+ return 1;
55
+
56
+ /* as a test, we add a symbol that the compiled program can use.
57
+ You may also open a dll with tcc_add_dll() and use symbols from that */
58
+ tcc_add_symbol(s, "add", add);
59
+
60
+ /* relocate the code */
61
+ if (tcc_relocate(s, TCC_RELOCATE_AUTO) < 0)
62
+ return 1;
63
+
64
+ /* get entry symbol */
65
+ func = tcc_get_symbol(s, "foo");
66
+ if (!func)
67
+ return 1;
68
+
69
+ /* run the code */
70
+ func(32);
71
+
72
+ /* delete the state */
73
+ tcc_delete(s);
74
+
75
+ return 0;
76
+ }
@@ -0,0 +1,2713 @@
1
+ /*
2
+ * TCC auto test program
3
+ */
4
+ #include "../config.h"
5
+
6
+ #if GCC_MAJOR >= 3
7
+
8
+ /* Unfortunately, gcc version < 3 does not handle that! */
9
+ #define ALL_ISOC99
10
+
11
+ /* only gcc 3 handles _Bool correctly */
12
+ #define BOOL_ISOC99
13
+
14
+ /* gcc 2.95.3 does not handle correctly CR in strings or after strays */
15
+ #define CORRECT_CR_HANDLING
16
+
17
+ #endif
18
+
19
+ /* deprecated and no longer supported in gcc 3.3 */
20
+ //#define ACCEPT_CR_IN_STRINGS
21
+
22
+ /* __VA_ARGS__ and __func__ support */
23
+ #define C99_MACROS
24
+
25
+ /* test various include syntaxes */
26
+
27
+ #define TCCLIB_INC <tcclib.h>
28
+ #define TCCLIB_INC1 <tcclib
29
+ #define TCCLIB_INC2 h>
30
+ #define TCCLIB_INC3 "tcclib"
31
+
32
+ #include TCCLIB_INC
33
+
34
+ #include TCCLIB_INC1.TCCLIB_INC2
35
+
36
+ #include TCCLIB_INC1.h>
37
+
38
+ /* gcc 3.2 does not accept that (bug ?) */
39
+ //#include TCCLIB_INC3 ".h"
40
+
41
+ #include <tcclib.h>
42
+
43
+ #include "tcclib.h"
44
+
45
+ void string_test();
46
+ void expr_test();
47
+ void macro_test();
48
+ void recursive_macro_test();
49
+ void scope_test();
50
+ void forward_test();
51
+ void funcptr_test();
52
+ void loop_test();
53
+ void switch_test();
54
+ void goto_test();
55
+ void enum_test();
56
+ void typedef_test();
57
+ void struct_test();
58
+ void array_test();
59
+ void expr_ptr_test();
60
+ void bool_test();
61
+ void expr2_test();
62
+ void constant_expr_test();
63
+ void expr_cmp_test();
64
+ void char_short_test();
65
+ void init_test(void);
66
+ void compound_literal_test(void);
67
+ int kr_test();
68
+ void struct_assign_test(void);
69
+ void cast_test(void);
70
+ void bitfield_test(void);
71
+ void c99_bool_test(void);
72
+ void float_test(void);
73
+ void longlong_test(void);
74
+ void manyarg_test(void);
75
+ void stdarg_test(void);
76
+ void whitespace_test(void);
77
+ void relocation_test(void);
78
+ void old_style_function(void);
79
+ void alloca_test(void);
80
+ void c99_vla_test(int size1, int size2);
81
+ void sizeof_test(void);
82
+ void typeof_test(void);
83
+ void local_label_test(void);
84
+ void statement_expr_test(void);
85
+ void asm_test(void);
86
+ void builtin_test(void);
87
+ void weak_test(void);
88
+ void global_data_test(void);
89
+ void cmp_comparison_test(void);
90
+ void math_cmp_test(void);
91
+ void callsave_test(void);
92
+ void builtin_frame_address_test(void);
93
+
94
+ int fib(int n);
95
+ void num(int n);
96
+ void forward_ref(void);
97
+ int isid(int c);
98
+
99
+ #define A 2
100
+ #define N 1234 + A
101
+ #define pf printf
102
+ #define M1(a, b) (a) + (b)
103
+
104
+ #define str\
105
+ (s) # s
106
+ #define glue(a, b) a ## b
107
+ #define xglue(a, b) glue(a, b)
108
+ #define HIGHLOW "hello"
109
+ #define LOW LOW ", world"
110
+
111
+ static int onetwothree = 123;
112
+ #define onetwothree4 onetwothree
113
+ #define onetwothree xglue(onetwothree,4)
114
+
115
+ #define min(a, b) ((a) < (b) ? (a) : (b))
116
+
117
+ #ifdef C99_MACROS
118
+ #define dprintf(level,...) printf(__VA_ARGS__)
119
+ #endif
120
+
121
+ /* gcc vararg macros */
122
+ #define dprintf1(level, fmt, args...) printf(fmt, ## args)
123
+
124
+ #define MACRO_NOARGS()
125
+
126
+ #define AAA 3
127
+ #undef AAA
128
+ #define AAA 4
129
+
130
+ #if 1
131
+ #define B3 1
132
+ #elif 1
133
+ #define B3 2
134
+ #elif 0
135
+ #define B3 3
136
+ #else
137
+ #define B3 4
138
+ #endif
139
+
140
+ #define __INT64_C(c) c ## LL
141
+ #define INT64_MIN (-__INT64_C(9223372036854775807)-1)
142
+
143
+ int qq(int x)
144
+ {
145
+ return x + 40;
146
+ }
147
+ #define qq(x) x
148
+
149
+ #define spin_lock(lock) do { } while (0)
150
+ #define wq_spin_lock spin_lock
151
+ #define TEST2() wq_spin_lock(a)
152
+
153
+ void macro_test(void)
154
+ {
155
+ printf("macro:\n");
156
+ pf("N=%d\n", N);
157
+ printf("aaa=%d\n", AAA);
158
+
159
+ printf("min=%d\n", min(1, min(2, -1)));
160
+
161
+ printf("s1=%s\n", glue(HIGH, LOW));
162
+ printf("s2=%s\n", xglue(HIGH, LOW));
163
+ printf("s3=%s\n", str("c"));
164
+ printf("s4=%s\n", str(a1));
165
+ printf("B3=%d\n", B3);
166
+
167
+ printf("onetwothree=%d\n", onetwothree);
168
+
169
+ #ifdef A
170
+ printf("A defined\n");
171
+ #endif
172
+ #ifdef B
173
+ printf("B defined\n");
174
+ #endif
175
+ #ifdef A
176
+ printf("A defined\n");
177
+ #else
178
+ printf("A not defined\n");
179
+ #endif
180
+ #ifdef B
181
+ printf("B defined\n");
182
+ #else
183
+ printf("B not defined\n");
184
+ #endif
185
+
186
+ #ifdef A
187
+ printf("A defined\n");
188
+ #ifdef B
189
+ printf("B1 defined\n");
190
+ #else
191
+ printf("B1 not defined\n");
192
+ #endif
193
+ #else
194
+ printf("A not defined\n");
195
+ #ifdef B
196
+ printf("B2 defined\n");
197
+ #else
198
+ printf("B2 not defined\n");
199
+ #endif
200
+ #endif
201
+
202
+ #if 1+1
203
+ printf("test true1\n");
204
+ #endif
205
+ #if 0
206
+ printf("test true2\n");
207
+ #endif
208
+ #if 1-1
209
+ printf("test true3\n");
210
+ #endif
211
+ #if defined(A)
212
+ printf("test trueA\n");
213
+ #endif
214
+ #if defined(B)
215
+ printf("test trueB\n");
216
+ #endif
217
+
218
+ #if 0
219
+ printf("test 0\n");
220
+ #elif 0
221
+ printf("test 1\n");
222
+ #elif 2
223
+ printf("test 2\n");
224
+ #else
225
+ printf("test 3\n");
226
+ #endif
227
+
228
+ MACRO_NOARGS();
229
+
230
+ #ifdef __LINE__
231
+ printf("__LINE__ defined\n");
232
+ #endif
233
+
234
+ printf("__LINE__=%d __FILE__=%s\n",
235
+ __LINE__, __FILE__);
236
+ #line 200
237
+ printf("__LINE__=%d __FILE__=%s\n",
238
+ __LINE__, __FILE__);
239
+ #line 203 "test"
240
+ printf("__LINE__=%d __FILE__=%s\n",
241
+ __LINE__, __FILE__);
242
+ #line 227 "tcctest.c"
243
+
244
+ /* not strictly preprocessor, but we test it there */
245
+ #ifdef C99_MACROS
246
+ printf("__func__ = %s\n", __func__);
247
+ dprintf(1, "vaarg=%d\n", 1);
248
+ #endif
249
+ dprintf1(1, "vaarg1\n");
250
+ dprintf1(1, "vaarg1=%d\n", 2);
251
+ dprintf1(1, "vaarg1=%d %d\n", 1, 2);
252
+
253
+ /* gcc extension */
254
+ printf("func='%s'\n", __FUNCTION__);
255
+
256
+ /* complicated macros in glibc */
257
+ printf("INT64_MIN=%Ld\n", INT64_MIN);
258
+ {
259
+ int a;
260
+ a = 1;
261
+ glue(a+, +);
262
+ printf("a=%d\n", a);
263
+ glue(a <, <= 2);
264
+ printf("a=%d\n", a);
265
+ }
266
+
267
+ /* macro function with argument outside the macro string */
268
+ #define MF_s MF_hello
269
+ #define MF_hello(msg) printf("%s\n",msg)
270
+
271
+ #define MF_t printf("tralala\n"); MF_hello
272
+
273
+ MF_s("hi");
274
+ MF_t("hi");
275
+
276
+ /* test macro substituion inside args (should not eat stream) */
277
+ printf("qq=%d\n", qq(qq)(2));
278
+
279
+ /* test zero argument case. NOTE: gcc 2.95.x does not accept a
280
+ null argument without a space. gcc 3.2 fixes that. */
281
+
282
+ #define qq1(x) 1
283
+ printf("qq1=%d\n", qq1( ));
284
+
285
+ /* comment with stray handling *\
286
+ /
287
+ /* this is a valid *\/ comment */
288
+ /* this is a valid comment *\*/
289
+ // this is a valid\
290
+ comment
291
+
292
+ /* test function macro substitution when the function name is
293
+ substituted */
294
+ TEST2();
295
+
296
+ /* And again when the name and parenthes are separated by a
297
+ comment. */
298
+ TEST2 /* the comment */ ();
299
+ }
300
+
301
+
302
+ static void print_num(char *fn, int line, int num) {
303
+ printf("fn %s, line %d, num %d\n", fn, line, num);
304
+ }
305
+
306
+ void recursive_macro_test(void)
307
+ {
308
+
309
+ #define ELF32_ST_TYPE(val) ((val) & 0xf)
310
+ #define ELF32_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf))
311
+ #define STB_WEAK 2 /* Weak symbol */
312
+ #define ELFW(type) ELF##32##_##type
313
+ printf("%d\n", ELFW(ST_INFO)(STB_WEAK, ELFW(ST_TYPE)(123)));
314
+
315
+ #define WRAP(x) x
316
+
317
+ #define print_num(x) print_num(__FILE__,__LINE__,x)
318
+ print_num(123);
319
+ WRAP(print_num(123));
320
+ WRAP(WRAP(print_num(123)));
321
+
322
+ static struct recursive_macro { int rm_field; } G;
323
+ #define rm_field (G.rm_field)
324
+ printf("rm_field = %d\n", rm_field);
325
+ printf("rm_field = %d\n", WRAP(rm_field));
326
+ WRAP((printf("rm_field = %d %d\n", rm_field, WRAP(rm_field))));
327
+ }
328
+
329
+ int op(a,b)
330
+ {
331
+ return a / b;
332
+ }
333
+
334
+ int ret(a)
335
+ {
336
+ if (a == 2)
337
+ return 1;
338
+ if (a == 3)
339
+ return 2;
340
+ return 0;
341
+ }
342
+
343
+ void ps(const char *s)
344
+ {
345
+ int c;
346
+ while (1) {
347
+ c = *s;
348
+ if (c == 0)
349
+ break;
350
+ printf("%c", c);
351
+ s++;
352
+ }
353
+ }
354
+
355
+ const char foo1_string[] = "\
356
+ bar\n\
357
+ test\14\
358
+ 1";
359
+
360
+ void string_test()
361
+ {
362
+ unsigned int b;
363
+ printf("string:\n");
364
+ printf("\141\1423\143\n");/* dezdez test */
365
+ printf("\x41\x42\x43\x3a\n");
366
+ printf("c=%c\n", 'r');
367
+ printf("wc=%C 0x%lx %C\n", L'a', L'\x1234', L'c');
368
+ printf("foo1_string='%s'\n", foo1_string);
369
+ #if 0
370
+ printf("wstring=%S\n", L"abc");
371
+ printf("wstring=%S\n", L"abc" L"def" "ghi");
372
+ printf("'\\377'=%d '\\xff'=%d\n", '\377', '\xff');
373
+ printf("L'\\377'=%d L'\\xff'=%d\n", L'\377', L'\xff');
374
+ #endif
375
+ ps("test\n");
376
+ b = 32;
377
+ while ((b = b + 1) < 96) {
378
+ printf("%c", b);
379
+ }
380
+ printf("\n");
381
+ printf("fib=%d\n", fib(33));
382
+ b = 262144;
383
+ while (b != 0x80000000) {
384
+ num(b);
385
+ b = b * 2;
386
+ }
387
+ }
388
+
389
+ void loop_test()
390
+ {
391
+ int i;
392
+ i = 0;
393
+ while (i < 10)
394
+ printf("%d", i++);
395
+ printf("\n");
396
+ for(i = 0; i < 10;i++)
397
+ printf("%d", i);
398
+ printf("\n");
399
+ i = 0;
400
+ do {
401
+ printf("%d", i++);
402
+ } while (i < 10);
403
+ printf("\n");
404
+
405
+ char count = 123;
406
+ /* c99 for loop init test */
407
+ for (size_t count = 1; count < 3; count++)
408
+ printf("count=%d\n", count);
409
+ printf("count = %d\n", count);
410
+
411
+ /* break/continue tests */
412
+ i = 0;
413
+ while (1) {
414
+ if (i == 6)
415
+ break;
416
+ i++;
417
+ if (i == 3)
418
+ continue;
419
+ printf("%d", i);
420
+ }
421
+ printf("\n");
422
+
423
+ /* break/continue tests */
424
+ i = 0;
425
+ do {
426
+ if (i == 6)
427
+ break;
428
+ i++;
429
+ if (i == 3)
430
+ continue;
431
+ printf("%d", i);
432
+ } while(1);
433
+ printf("\n");
434
+
435
+ for(i = 0;i < 10;i++) {
436
+ if (i == 3)
437
+ continue;
438
+ printf("%d", i);
439
+ }
440
+ printf("\n");
441
+ }
442
+
443
+ typedef int typedef_and_label;
444
+
445
+ void goto_test()
446
+ {
447
+ int i;
448
+ static void *label_table[3] = { &&label1, &&label2, &&label3 };
449
+
450
+ printf("goto:\n");
451
+ i = 0;
452
+ /* This needs to parse as label, not as start of decl. */
453
+ typedef_and_label:
454
+ s_loop:
455
+ if (i >= 10)
456
+ goto s_end;
457
+ printf("%d", i);
458
+ i++;
459
+ goto s_loop;
460
+ s_end:
461
+ printf("\n");
462
+
463
+ /* we also test computed gotos (GCC extension) */
464
+ for(i=0;i<3;i++) {
465
+ goto *label_table[i];
466
+ label1:
467
+ printf("label1\n");
468
+ goto next;
469
+ label2:
470
+ printf("label2\n");
471
+ goto next;
472
+ label3:
473
+ printf("label3\n");
474
+ next: ;
475
+ }
476
+ }
477
+
478
+ enum {
479
+ E0,
480
+ E1 = 2,
481
+ E2 = 4,
482
+ E3,
483
+ E4,
484
+ };
485
+
486
+ enum test {
487
+ E5 = 1000,
488
+ };
489
+
490
+ void enum_test()
491
+ {
492
+ enum test b1;
493
+ printf("enum:\n%d %d %d %d %d %d\n",
494
+ E0, E1, E2, E3, E4, E5);
495
+ b1 = 1;
496
+ printf("b1=%d\n", b1);
497
+ }
498
+
499
+ typedef int *my_ptr;
500
+
501
+ typedef int mytype1;
502
+ typedef int mytype2;
503
+
504
+ void typedef_test()
505
+ {
506
+ my_ptr a;
507
+ mytype1 mytype2;
508
+ int b;
509
+
510
+ a = &b;
511
+ *a = 1234;
512
+ printf("typedef:\n");
513
+ printf("a=%d\n", *a);
514
+ mytype2 = 2;
515
+ printf("mytype2=%d\n", mytype2);
516
+ }
517
+
518
+ void forward_test()
519
+ {
520
+ printf("forward:\n");
521
+ forward_ref();
522
+ forward_ref();
523
+ }
524
+
525
+
526
+ void forward_ref(void)
527
+ {
528
+ printf("forward ok\n");
529
+ }
530
+
531
+ typedef struct struct1 {
532
+ int f1;
533
+ int f2, f3;
534
+ union union1 {
535
+ int v1;
536
+ int v2;
537
+ } u;
538
+ char str[3];
539
+ } struct1;
540
+
541
+ struct struct2 {
542
+ int a;
543
+ char b;
544
+ };
545
+
546
+ union union2 {
547
+ int w1;
548
+ int w2;
549
+ };
550
+
551
+ struct struct1 st1, st2;
552
+
553
+ int main(int argc, char **argv)
554
+ {
555
+ string_test();
556
+ expr_test();
557
+ macro_test();
558
+ recursive_macro_test();
559
+ scope_test();
560
+ forward_test();
561
+ funcptr_test();
562
+ loop_test();
563
+ switch_test();
564
+ goto_test();
565
+ enum_test();
566
+ typedef_test();
567
+ struct_test();
568
+ array_test();
569
+ expr_ptr_test();
570
+ bool_test();
571
+ expr2_test();
572
+ constant_expr_test();
573
+ expr_cmp_test();
574
+ char_short_test();
575
+ init_test();
576
+ compound_literal_test();
577
+ kr_test();
578
+ struct_assign_test();
579
+ cast_test();
580
+ bitfield_test();
581
+ c99_bool_test();
582
+ float_test();
583
+ longlong_test();
584
+ manyarg_test();
585
+ stdarg_test();
586
+ whitespace_test();
587
+ relocation_test();
588
+ old_style_function();
589
+ alloca_test();
590
+ c99_vla_test(5, 2);
591
+ sizeof_test();
592
+ typeof_test();
593
+ statement_expr_test();
594
+ local_label_test();
595
+ asm_test();
596
+ builtin_test();
597
+ #ifndef _WIN32
598
+ weak_test();
599
+ #endif
600
+ global_data_test();
601
+ cmp_comparison_test();
602
+ math_cmp_test();
603
+ callsave_test();
604
+ builtin_frame_address_test();
605
+ return 0;
606
+ }
607
+
608
+ int tab[3];
609
+ int tab2[3][2];
610
+
611
+ int g;
612
+
613
+ void f1(g)
614
+ {
615
+ printf("g1=%d\n", g);
616
+ }
617
+
618
+ void scope_test()
619
+ {
620
+ printf("scope:\n");
621
+ g = 2;
622
+ f1(1);
623
+ printf("g2=%d\n", g);
624
+ {
625
+ int g;
626
+ g = 3;
627
+ printf("g3=%d\n", g);
628
+ {
629
+ int g;
630
+ g = 4;
631
+ printf("g4=%d\n", g);
632
+ }
633
+ }
634
+ printf("g5=%d\n", g);
635
+ }
636
+
637
+ void array_test()
638
+ {
639
+ int i, j, a[4];
640
+
641
+ printf("array:\n");
642
+ printf("sizeof(a) = %d\n", sizeof(a));
643
+ printf("sizeof(\"a\") = %d\n", sizeof("a"));
644
+ #ifdef C99_MACROS
645
+ printf("sizeof(__func__) = %d\n", sizeof(__func__));
646
+ #endif
647
+ printf("sizeof tab %d\n", sizeof(tab));
648
+ printf("sizeof tab2 %d\n", sizeof tab2);
649
+ tab[0] = 1;
650
+ tab[1] = 2;
651
+ tab[2] = 3;
652
+ printf("%d %d %d\n", tab[0], tab[1], tab[2]);
653
+ for(i=0;i<3;i++)
654
+ for(j=0;j<2;j++)
655
+ tab2[i][j] = 10 * i + j;
656
+ for(i=0;i<3*2;i++) {
657
+ printf(" %3d", ((int *)tab2)[i]);
658
+ }
659
+ printf("\n");
660
+ printf("sizeof(size_t)=%d\n", sizeof(size_t));
661
+ printf("sizeof(ptrdiff_t)=%d\n", sizeof(ptrdiff_t));
662
+ }
663
+
664
+ void expr_test()
665
+ {
666
+ int a, b;
667
+ a = 0;
668
+ printf("%d\n", a += 1);
669
+ printf("%d\n", a -= 2);
670
+ printf("%d\n", a *= 31232132);
671
+ printf("%d\n", a /= 4);
672
+ printf("%d\n", a %= 20);
673
+ printf("%d\n", a &= 6);
674
+ printf("%d\n", a ^= 7);
675
+ printf("%d\n", a |= 8);
676
+ printf("%d\n", a >>= 3);
677
+ printf("%d\n", a <<= 4);
678
+
679
+ a = 22321;
680
+ b = -22321;
681
+ printf("%d\n", a + 1);
682
+ printf("%d\n", a - 2);
683
+ printf("%d\n", a * 312);
684
+ printf("%d\n", a / 4);
685
+ printf("%d\n", b / 4);
686
+ printf("%d\n", (unsigned)b / 4);
687
+ printf("%d\n", a % 20);
688
+ printf("%d\n", b % 20);
689
+ printf("%d\n", (unsigned)b % 20);
690
+ printf("%d\n", a & 6);
691
+ printf("%d\n", a ^ 7);
692
+ printf("%d\n", a | 8);
693
+ printf("%d\n", a >> 3);
694
+ printf("%d\n", b >> 3);
695
+ printf("%d\n", (unsigned)b >> 3);
696
+ printf("%d\n", a << 4);
697
+ printf("%d\n", ~a);
698
+ printf("%d\n", -a);
699
+ printf("%d\n", +a);
700
+
701
+ printf("%d\n", 12 + 1);
702
+ printf("%d\n", 12 - 2);
703
+ printf("%d\n", 12 * 312);
704
+ printf("%d\n", 12 / 4);
705
+ printf("%d\n", 12 % 20);
706
+ printf("%d\n", 12 & 6);
707
+ printf("%d\n", 12 ^ 7);
708
+ printf("%d\n", 12 | 8);
709
+ printf("%d\n", 12 >> 2);
710
+ printf("%d\n", 12 << 4);
711
+ printf("%d\n", ~12);
712
+ printf("%d\n", -12);
713
+ printf("%d\n", +12);
714
+ printf("%d %d %d %d\n",
715
+ isid('a'),
716
+ isid('g'),
717
+ isid('T'),
718
+ isid('('));
719
+ }
720
+
721
+ int isid(int c)
722
+ {
723
+ return (c >= 'a' & c <= 'z') | (c >= 'A' & c <= 'Z') | c == '_';
724
+ }
725
+
726
+ /**********************/
727
+
728
+ int vstack[10], *vstack_ptr;
729
+
730
+ void vpush(int vt, int vc)
731
+ {
732
+ *vstack_ptr++ = vt;
733
+ *vstack_ptr++ = vc;
734
+ }
735
+
736
+ void vpop(int *ft, int *fc)
737
+ {
738
+ *fc = *--vstack_ptr;
739
+ *ft = *--vstack_ptr;
740
+ }
741
+
742
+ void expr2_test()
743
+ {
744
+ int a, b;
745
+
746
+ printf("expr2:\n");
747
+ vstack_ptr = vstack;
748
+ vpush(1432432, 2);
749
+ vstack_ptr[-2] &= ~0xffffff80;
750
+ vpop(&a, &b);
751
+ printf("res= %d %d\n", a, b);
752
+ }
753
+
754
+ void constant_expr_test()
755
+ {
756
+ int a;
757
+ printf("constant_expr:\n");
758
+ a = 3;
759
+ printf("%d\n", a * 16);
760
+ printf("%d\n", a * 1);
761
+ printf("%d\n", a + 0);
762
+ }
763
+
764
+ int tab4[10];
765
+
766
+ void expr_ptr_test()
767
+ {
768
+ int *p, *q;
769
+ int i = -1;
770
+
771
+ printf("expr_ptr:\n");
772
+ p = tab4;
773
+ q = tab4 + 10;
774
+ printf("diff=%d\n", q - p);
775
+ p++;
776
+ printf("inc=%d\n", p - tab4);
777
+ p--;
778
+ printf("dec=%d\n", p - tab4);
779
+ ++p;
780
+ printf("inc=%d\n", p - tab4);
781
+ --p;
782
+ printf("dec=%d\n", p - tab4);
783
+ printf("add=%d\n", p + 3 - tab4);
784
+ printf("add=%d\n", 3 + p - tab4);
785
+
786
+ /* check if 64bit support is ok */
787
+ q = p = 0;
788
+ q += i;
789
+ printf("%p %p %ld\n", q, p, p-q);
790
+ printf("%d %d %d %d %d %d\n",
791
+ p == q, p != q, p < q, p <= q, p >= q, p > q);
792
+ i = 0xf0000000;
793
+ p += i;
794
+ printf("%p %p %ld\n", q, p, p-q);
795
+ printf("%d %d %d %d %d %d\n",
796
+ p == q, p != q, p < q, p <= q, p >= q, p > q);
797
+ p = (int *)((char *)p + 0xf0000000);
798
+ printf("%p %p %ld\n", q, p, p-q);
799
+ printf("%d %d %d %d %d %d\n",
800
+ p == q, p != q, p < q, p <= q, p >= q, p > q);
801
+ p += 0xf0000000;
802
+ printf("%p %p %ld\n", q, p, p-q);
803
+ printf("%d %d %d %d %d %d\n",
804
+ p == q, p != q, p < q, p <= q, p >= q, p > q);
805
+ {
806
+ struct size12 {
807
+ int i, j, k;
808
+ };
809
+ struct size12 s[2], *sp = s;
810
+ int i, j;
811
+ sp->i = 42;
812
+ sp++;
813
+ j = -1;
814
+ printf("%d\n", sp[j].i);
815
+ }
816
+ }
817
+
818
+ void expr_cmp_test()
819
+ {
820
+ int a, b;
821
+ printf("constant_expr:\n");
822
+ a = -1;
823
+ b = 1;
824
+ printf("%d\n", a == a);
825
+ printf("%d\n", a != a);
826
+
827
+ printf("%d\n", a < b);
828
+ printf("%d\n", a <= b);
829
+ printf("%d\n", a <= a);
830
+ printf("%d\n", b >= a);
831
+ printf("%d\n", a >= a);
832
+ printf("%d\n", b > a);
833
+
834
+ printf("%d\n", (unsigned)a < b);
835
+ printf("%d\n", (unsigned)a <= b);
836
+ printf("%d\n", (unsigned)a <= a);
837
+ printf("%d\n", (unsigned)b >= a);
838
+ printf("%d\n", (unsigned)a >= a);
839
+ printf("%d\n", (unsigned)b > a);
840
+ }
841
+
842
+ struct empty {
843
+ };
844
+
845
+ struct aligntest1 {
846
+ char a[10];
847
+ };
848
+
849
+ struct aligntest2 {
850
+ int a;
851
+ char b[10];
852
+ };
853
+
854
+ struct aligntest3 {
855
+ double a, b;
856
+ };
857
+
858
+ struct aligntest4 {
859
+ double a[0];
860
+ };
861
+
862
+ void struct_test()
863
+ {
864
+ struct1 *s;
865
+ union union2 u;
866
+
867
+ printf("struct:\n");
868
+ printf("sizes: %d %d %d %d\n",
869
+ sizeof(struct struct1),
870
+ sizeof(struct struct2),
871
+ sizeof(union union1),
872
+ sizeof(union union2));
873
+ st1.f1 = 1;
874
+ st1.f2 = 2;
875
+ st1.f3 = 3;
876
+ printf("st1: %d %d %d\n",
877
+ st1.f1, st1.f2, st1.f3);
878
+ st1.u.v1 = 1;
879
+ st1.u.v2 = 2;
880
+ printf("union1: %d\n", st1.u.v1);
881
+ u.w1 = 1;
882
+ u.w2 = 2;
883
+ printf("union2: %d\n", u.w1);
884
+ s = &st2;
885
+ s->f1 = 3;
886
+ s->f2 = 2;
887
+ s->f3 = 1;
888
+ printf("st2: %d %d %d\n",
889
+ s->f1, s->f2, s->f3);
890
+ printf("str_addr=%x\n", (int)st1.str - (int)&st1.f1);
891
+
892
+ /* align / size tests */
893
+ printf("aligntest1 sizeof=%d alignof=%d\n",
894
+ sizeof(struct aligntest1), __alignof__(struct aligntest1));
895
+ printf("aligntest2 sizeof=%d alignof=%d\n",
896
+ sizeof(struct aligntest2), __alignof__(struct aligntest2));
897
+ printf("aligntest3 sizeof=%d alignof=%d\n",
898
+ sizeof(struct aligntest3), __alignof__(struct aligntest3));
899
+ printf("aligntest4 sizeof=%d alignof=%d\n",
900
+ sizeof(struct aligntest4), __alignof__(struct aligntest4));
901
+
902
+ /* empty structures (GCC extension) */
903
+ printf("sizeof(struct empty) = %d\n", sizeof(struct empty));
904
+ printf("alignof(struct empty) = %d\n", __alignof__(struct empty));
905
+ }
906
+
907
+ /* XXX: depend on endianness */
908
+ void char_short_test()
909
+ {
910
+ int var1, var2;
911
+
912
+ printf("char_short:\n");
913
+
914
+ var1 = 0x01020304;
915
+ var2 = 0xfffefdfc;
916
+ printf("s8=%d %d\n",
917
+ *(char *)&var1, *(char *)&var2);
918
+ printf("u8=%d %d\n",
919
+ *(unsigned char *)&var1, *(unsigned char *)&var2);
920
+ printf("s16=%d %d\n",
921
+ *(short *)&var1, *(short *)&var2);
922
+ printf("u16=%d %d\n",
923
+ *(unsigned short *)&var1, *(unsigned short *)&var2);
924
+ printf("s32=%d %d\n",
925
+ *(int *)&var1, *(int *)&var2);
926
+ printf("u32=%d %d\n",
927
+ *(unsigned int *)&var1, *(unsigned int *)&var2);
928
+ *(char *)&var1 = 0x08;
929
+ printf("var1=%x\n", var1);
930
+ *(short *)&var1 = 0x0809;
931
+ printf("var1=%x\n", var1);
932
+ *(int *)&var1 = 0x08090a0b;
933
+ printf("var1=%x\n", var1);
934
+ }
935
+
936
+ /******************/
937
+
938
+ typedef struct Sym {
939
+ int v;
940
+ int t;
941
+ int c;
942
+ struct Sym *next;
943
+ struct Sym *prev;
944
+ } Sym;
945
+
946
+ #define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
947
+ #define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
948
+
949
+ static int toupper1(int a)
950
+ {
951
+ return TOUPPER(a);
952
+ }
953
+
954
+ void bool_test()
955
+ {
956
+ int *s, a, b, t, f, i;
957
+
958
+ a = 0;
959
+ s = (void*)0;
960
+ printf("!s=%d\n", !s);
961
+
962
+ if (!s || !s[0])
963
+ a = 1;
964
+ printf("a=%d\n", a);
965
+
966
+ printf("a=%d %d %d\n", 0 || 0, 0 || 1, 1 || 1);
967
+ printf("a=%d %d %d\n", 0 && 0, 0 && 1, 1 && 1);
968
+ printf("a=%d %d\n", 1 ? 1 : 0, 0 ? 1 : 0);
969
+ #if 1 && 1
970
+ printf("a1\n");
971
+ #endif
972
+ #if 1 || 0
973
+ printf("a2\n");
974
+ #endif
975
+ #if 1 ? 0 : 1
976
+ printf("a3\n");
977
+ #endif
978
+ #if 0 ? 0 : 1
979
+ printf("a4\n");
980
+ #endif
981
+
982
+ a = 4;
983
+ printf("b=%d\n", a + (0 ? 1 : a / 2));
984
+
985
+ /* test register spilling */
986
+ a = 10;
987
+ b = 10;
988
+ a = (a + b) * ((a < b) ?
989
+ ((b - a) * (a - b)): a + b);
990
+ printf("a=%d\n", a);
991
+
992
+ /* test complex || or && expressions */
993
+ t = 1;
994
+ f = 0;
995
+ a = 32;
996
+ printf("exp=%d\n", f == (32 <= a && a <= 3));
997
+ printf("r=%d\n", (t || f) + (t && f));
998
+
999
+ /* test ? : cast */
1000
+ {
1001
+ int aspect_on;
1002
+ int aspect_native = 65536;
1003
+ double bfu_aspect = 1.0;
1004
+ int aspect;
1005
+ for(aspect_on = 0; aspect_on < 2; aspect_on++) {
1006
+ aspect=aspect_on?(aspect_native*bfu_aspect+0.5):65535UL;
1007
+ printf("aspect=%d\n", aspect);
1008
+ }
1009
+ }
1010
+
1011
+ /* test ? : GCC extension */
1012
+ {
1013
+ static int v1 = 34 ? : -1; /* constant case */
1014
+ static int v2 = 0 ? : -1; /* constant case */
1015
+ int a = 30;
1016
+
1017
+ printf("%d %d\n", v1, v2);
1018
+ printf("%d %d\n", a - 30 ? : a * 2, a + 1 ? : a * 2);
1019
+ }
1020
+
1021
+ /* again complex expression */
1022
+ for(i=0;i<256;i++) {
1023
+ if (toupper1 (i) != TOUPPER (i))
1024
+ printf("error %d\n", i);
1025
+ }
1026
+ }
1027
+
1028
+ /* GCC accepts that */
1029
+ static int tab_reinit[];
1030
+ static int tab_reinit[10];
1031
+
1032
+ //int cinit1; /* a global variable can be defined several times without error ! */
1033
+ int cinit1;
1034
+ int cinit1;
1035
+ int cinit1 = 0;
1036
+ int *cinit2 = (int []){3, 2, 1};
1037
+
1038
+ void compound_literal_test(void)
1039
+ {
1040
+ int *p, i;
1041
+ char *q, *q3;
1042
+
1043
+ printf("compound_test:\n");
1044
+
1045
+ p = (int []){1, 2, 3};
1046
+ for(i=0;i<3;i++)
1047
+ printf(" %d", p[i]);
1048
+ printf("\n");
1049
+
1050
+ for(i=0;i<3;i++)
1051
+ printf("%d", cinit2[i]);
1052
+ printf("\n");
1053
+
1054
+ q = "tralala1";
1055
+ printf("q1=%s\n", q);
1056
+
1057
+ q = (char *){ "tralala2" };
1058
+ printf("q2=%s\n", q);
1059
+
1060
+ q3 = (char *){ q };
1061
+ printf("q3=%s\n", q3);
1062
+
1063
+ q = (char []){ "tralala3" };
1064
+ printf("q4=%s\n", q);
1065
+
1066
+ #ifdef ALL_ISOC99
1067
+ p = (int []){1, 2, cinit1 + 3};
1068
+ for(i=0;i<3;i++)
1069
+ printf(" %d", p[i]);
1070
+ printf("\n");
1071
+
1072
+ for(i=0;i<3;i++) {
1073
+ p = (int []){1, 2, 4 + i};
1074
+ printf("%d %d %d\n",
1075
+ p[0],
1076
+ p[1],
1077
+ p[2]);
1078
+ }
1079
+ #endif
1080
+ }
1081
+
1082
+ /* K & R protos */
1083
+
1084
+ kr_func1(a, b)
1085
+ {
1086
+ return a + b;
1087
+ }
1088
+
1089
+ int kr_func2(a, b)
1090
+ {
1091
+ return a + b;
1092
+ }
1093
+
1094
+ kr_test()
1095
+ {
1096
+ printf("kr_test:\n");
1097
+ printf("func1=%d\n", kr_func1(3, 4));
1098
+ printf("func2=%d\n", kr_func2(3, 4));
1099
+ return 0;
1100
+ }
1101
+
1102
+ void num(int n)
1103
+ {
1104
+ char *tab, *p;
1105
+ tab = (char*)malloc(20);
1106
+ p = tab;
1107
+ while (1) {
1108
+ *p = 48 + (n % 10);
1109
+ p++;
1110
+ n = n / 10;
1111
+ if (n == 0)
1112
+ break;
1113
+ }
1114
+ while (p != tab) {
1115
+ p--;
1116
+ printf("%c", *p);
1117
+ }
1118
+ printf("\n");
1119
+ free(tab);
1120
+ }
1121
+
1122
+ /* structure assignment tests */
1123
+ struct structa1 {
1124
+ int f1;
1125
+ char f2;
1126
+ };
1127
+
1128
+ struct structa1 ssta1;
1129
+
1130
+ void struct_assign_test1(struct structa1 s1, int t, float f)
1131
+ {
1132
+ printf("%d %d %d %f\n", s1.f1, s1.f2, t, f);
1133
+ }
1134
+
1135
+ struct structa1 struct_assign_test2(struct structa1 s1, int t)
1136
+ {
1137
+ s1.f1 += t;
1138
+ s1.f2 -= t;
1139
+ return s1;
1140
+ }
1141
+
1142
+ void struct_assign_test(void)
1143
+ {
1144
+ struct S {
1145
+ struct structa1 lsta1, lsta2;
1146
+ int i;
1147
+ } s, *ps;
1148
+
1149
+ ps = &s;
1150
+ ps->i = 4;
1151
+ #if 0
1152
+ printf("struct_assign_test:\n");
1153
+
1154
+ s.lsta1.f1 = 1;
1155
+ s.lsta1.f2 = 2;
1156
+ printf("%d %d\n", s.lsta1.f1, s.lsta1.f2);
1157
+ s.lsta2 = s.lsta1;
1158
+ printf("%d %d\n", s.lsta2.f1, s.lsta2.f2);
1159
+ #else
1160
+ s.lsta2.f1 = 1;
1161
+ s.lsta2.f2 = 2;
1162
+ #endif
1163
+ struct_assign_test1(ps->lsta2, 3, 4.5);
1164
+
1165
+ printf("before call: %d %d\n", s.lsta2.f1, s.lsta2.f2);
1166
+ ps->lsta2 = struct_assign_test2(ps->lsta2, ps->i);
1167
+ printf("after call: %d %d\n", ps->lsta2.f1, ps->lsta2.f2);
1168
+
1169
+ static struct {
1170
+ void (*elem)();
1171
+ } t[] = {
1172
+ /* XXX: we should allow this even without braces */
1173
+ { struct_assign_test }
1174
+ };
1175
+ printf("%d\n", struct_assign_test == t[0].elem);
1176
+ }
1177
+
1178
+ /* casts to short/char */
1179
+
1180
+ void cast1(char a, short b, unsigned char c, unsigned short d)
1181
+ {
1182
+ printf("%d %d %d %d\n", a, b, c, d);
1183
+ }
1184
+
1185
+ char bcast;
1186
+ short scast;
1187
+
1188
+ void cast_test()
1189
+ {
1190
+ int a;
1191
+ char c;
1192
+ char tab[10];
1193
+ unsigned b,d;
1194
+ short s;
1195
+ char *p = NULL;
1196
+ p -= 0x700000000042;
1197
+
1198
+ printf("cast_test:\n");
1199
+ a = 0xfffff;
1200
+ cast1(a, a, a, a);
1201
+ a = 0xffffe;
1202
+ printf("%d %d %d %d\n",
1203
+ (char)(a + 1),
1204
+ (short)(a + 1),
1205
+ (unsigned char)(a + 1),
1206
+ (unsigned short)(a + 1));
1207
+ printf("%d %d %d %d\n",
1208
+ (char)0xfffff,
1209
+ (short)0xfffff,
1210
+ (unsigned char)0xfffff,
1211
+ (unsigned short)0xfffff);
1212
+
1213
+ a = (bcast = 128) + 1;
1214
+ printf("%d\n", a);
1215
+ a = (scast = 65536) + 1;
1216
+ printf("%d\n", a);
1217
+
1218
+ printf("sizeof(c) = %d, sizeof((int)c) = %d\n", sizeof(c), sizeof((int)c));
1219
+
1220
+ /* test cast from unsigned to signed short to int */
1221
+ b = 0xf000;
1222
+ d = (short)b;
1223
+ printf("((unsigned)(short)0x%08x) = 0x%08x\n", b, d);
1224
+ b = 0xf0f0;
1225
+ d = (char)b;
1226
+ printf("((unsigned)(char)0x%08x) = 0x%08x\n", b, d);
1227
+
1228
+ /* test implicit int casting for array accesses */
1229
+ c = 0;
1230
+ tab[1] = 2;
1231
+ tab[c] = 1;
1232
+ printf("%d %d\n", tab[0], tab[1]);
1233
+
1234
+ /* test implicit casting on some operators */
1235
+ printf("sizeof(+(char)'a') = %d\n", sizeof(+(char)'a'));
1236
+ printf("sizeof(-(char)'a') = %d\n", sizeof(-(char)'a'));
1237
+ printf("sizeof(~(char)'a') = %d\n", sizeof(-(char)'a'));
1238
+
1239
+ /* from pointer to integer types */
1240
+ printf("%d %d %ld %ld %lld %lld\n",
1241
+ (int)p, (unsigned int)p,
1242
+ (long)p, (unsigned long)p,
1243
+ (long long)p, (unsigned long long)p);
1244
+
1245
+ /* from integers to pointers */
1246
+ printf("%p %p %p %p\n",
1247
+ (void *)a, (void *)b, (void *)c, (void *)d);
1248
+ }
1249
+
1250
+ /* initializers tests */
1251
+ struct structinit1 {
1252
+ int f1;
1253
+ char f2;
1254
+ short f3;
1255
+ int farray[3];
1256
+ };
1257
+
1258
+ int sinit1 = 2;
1259
+ int sinit2 = { 3 };
1260
+ int sinit3[3] = { 1, 2, {{3}}, };
1261
+ int sinit4[3][2] = { {1, 2}, {3, 4}, {5, 6} };
1262
+ int sinit5[3][2] = { 1, 2, 3, 4, 5, 6 };
1263
+ int sinit6[] = { 1, 2, 3 };
1264
+ int sinit7[] = { [2] = 3, [0] = 1, 2 };
1265
+ char sinit8[] = "hello" "trala";
1266
+
1267
+ struct structinit1 sinit9 = { 1, 2, 3 };
1268
+ struct structinit1 sinit10 = { .f2 = 2, 3, .f1 = 1 };
1269
+ struct structinit1 sinit11 = { .f2 = 2, 3, .f1 = 1,
1270
+ #ifdef ALL_ISOC99
1271
+ .farray[0] = 10,
1272
+ .farray[1] = 11,
1273
+ .farray[2] = 12,
1274
+ #endif
1275
+ };
1276
+
1277
+ char *sinit12 = "hello world";
1278
+ char *sinit13[] = {
1279
+ "test1",
1280
+ "test2",
1281
+ "test3",
1282
+ };
1283
+ char sinit14[10] = { "abc" };
1284
+ int sinit15[3] = { sizeof(sinit15), 1, 2 };
1285
+
1286
+ struct { int a[3], b; } sinit16[] = { { 1 }, 2 };
1287
+
1288
+ struct bar {
1289
+ char *s;
1290
+ int len;
1291
+ } sinit17[] = {
1292
+ "a1", 4,
1293
+ "a2", 1
1294
+ };
1295
+
1296
+ int sinit18[10] = {
1297
+ [2 ... 5] = 20,
1298
+ 2,
1299
+ [8] = 10,
1300
+ };
1301
+
1302
+ struct complexinit0 {
1303
+ int a;
1304
+ int b;
1305
+ };
1306
+
1307
+ struct complexinit {
1308
+ int a;
1309
+ const struct complexinit0 *b;
1310
+ };
1311
+
1312
+ const static struct complexinit cix[] = {
1313
+ [0] = {
1314
+ .a = 2000,
1315
+ .b = (const struct complexinit0[]) {
1316
+ { 2001, 2002 },
1317
+ { 2003, 2003 },
1318
+ {}
1319
+ }
1320
+ }
1321
+ };
1322
+
1323
+ struct complexinit2 {
1324
+ int a;
1325
+ int b[];
1326
+ };
1327
+
1328
+ struct complexinit2 cix20;
1329
+
1330
+ struct complexinit2 cix21 = {
1331
+ .a = 3000,
1332
+ .b = { 3001, 3002, 3003 }
1333
+ };
1334
+
1335
+ struct complexinit2 cix22 = {
1336
+ .a = 4000,
1337
+ .b = { 4001, 4002, 4003, 4004, 4005, 4006 }
1338
+ };
1339
+
1340
+ void init_test(void)
1341
+ {
1342
+ int linit1 = 2;
1343
+ int linit2 = { 3 };
1344
+ int linit4[3][2] = { {1, 2}, {3, 4}, {5, 6} };
1345
+ int linit6[] = { 1, 2, 3 };
1346
+ int i, j;
1347
+ char linit8[] = "hello" "trala";
1348
+ int linit12[10] = { 1, 2 };
1349
+ int linit13[10] = { 1, 2, [7] = 3, [3] = 4, };
1350
+ char linit14[10] = "abc";
1351
+ int linit15[10] = { linit1, linit1 + 1, [6] = linit1 + 2, };
1352
+ struct linit16 { int a1, a2, a3, a4; } linit16 = { 1, .a3 = 2 };
1353
+ int linit17 = sizeof(linit17);
1354
+
1355
+ printf("init_test:\n");
1356
+
1357
+ printf("sinit1=%d\n", sinit1);
1358
+ printf("sinit2=%d\n", sinit2);
1359
+ printf("sinit3=%d %d %d %d\n",
1360
+ sizeof(sinit3),
1361
+ sinit3[0],
1362
+ sinit3[1],
1363
+ sinit3[2]
1364
+ );
1365
+ printf("sinit6=%d\n", sizeof(sinit6));
1366
+ printf("sinit7=%d %d %d %d\n",
1367
+ sizeof(sinit7),
1368
+ sinit7[0],
1369
+ sinit7[1],
1370
+ sinit7[2]
1371
+ );
1372
+ printf("sinit8=%s\n", sinit8);
1373
+ printf("sinit9=%d %d %d\n",
1374
+ sinit9.f1,
1375
+ sinit9.f2,
1376
+ sinit9.f3
1377
+ );
1378
+ printf("sinit10=%d %d %d\n",
1379
+ sinit10.f1,
1380
+ sinit10.f2,
1381
+ sinit10.f3
1382
+ );
1383
+ printf("sinit11=%d %d %d %d %d %d\n",
1384
+ sinit11.f1,
1385
+ sinit11.f2,
1386
+ sinit11.f3,
1387
+ sinit11.farray[0],
1388
+ sinit11.farray[1],
1389
+ sinit11.farray[2]
1390
+ );
1391
+
1392
+ for(i=0;i<3;i++)
1393
+ for(j=0;j<2;j++)
1394
+ printf("[%d][%d] = %d %d %d\n",
1395
+ i, j, sinit4[i][j], sinit5[i][j], linit4[i][j]);
1396
+ printf("linit1=%d\n", linit1);
1397
+ printf("linit2=%d\n", linit2);
1398
+ printf("linit6=%d\n", sizeof(linit6));
1399
+ printf("linit8=%d %s\n", sizeof(linit8), linit8);
1400
+
1401
+ printf("sinit12=%s\n", sinit12);
1402
+ printf("sinit13=%d %s %s %s\n",
1403
+ sizeof(sinit13),
1404
+ sinit13[0],
1405
+ sinit13[1],
1406
+ sinit13[2]);
1407
+ printf("sinit14=%s\n", sinit14);
1408
+
1409
+ for(i=0;i<10;i++) printf(" %d", linit12[i]);
1410
+ printf("\n");
1411
+ for(i=0;i<10;i++) printf(" %d", linit13[i]);
1412
+ printf("\n");
1413
+ for(i=0;i<10;i++) printf(" %d", linit14[i]);
1414
+ printf("\n");
1415
+ for(i=0;i<10;i++) printf(" %d", linit15[i]);
1416
+ printf("\n");
1417
+ printf("%d %d %d %d\n",
1418
+ linit16.a1,
1419
+ linit16.a2,
1420
+ linit16.a3,
1421
+ linit16.a4);
1422
+ /* test that initialisation is done after variable declare */
1423
+ printf("linit17=%d\n", linit17);
1424
+ printf("sinit15=%d\n", sinit15[0]);
1425
+ printf("sinit16=%d %d\n", sinit16[0].a[0], sinit16[1].a[0]);
1426
+ printf("sinit17=%s %d %s %d\n",
1427
+ sinit17[0].s, sinit17[0].len,
1428
+ sinit17[1].s, sinit17[1].len);
1429
+ for(i=0;i<10;i++)
1430
+ printf("%x ", sinit18[i]);
1431
+ printf("\n");
1432
+ /* complex init check */
1433
+ printf("cix: %d %d %d %d %d %d %d\n",
1434
+ cix[0].a,
1435
+ cix[0].b[0].a, cix[0].b[0].b,
1436
+ cix[0].b[1].a, cix[0].b[1].b,
1437
+ cix[0].b[2].a, cix[0].b[2].b);
1438
+ printf("cix2: %d %d\n", cix21.b[2], cix22.b[5]);
1439
+ printf("sizeof cix20 %d, cix21 %d, sizeof cix22 %d\n", sizeof cix20, sizeof cix21, sizeof cix22);
1440
+ }
1441
+
1442
+
1443
+ void switch_test()
1444
+ {
1445
+ int i;
1446
+
1447
+ for(i=0;i<15;i++) {
1448
+ switch(i) {
1449
+ case 0:
1450
+ case 1:
1451
+ printf("a");
1452
+ break;
1453
+ default:
1454
+ printf("%d", i);
1455
+ break;
1456
+ case 8 ... 12:
1457
+ printf("c");
1458
+ break;
1459
+ case 3:
1460
+ printf("b");
1461
+ break;
1462
+ }
1463
+ }
1464
+ printf("\n");
1465
+ }
1466
+
1467
+ /* ISOC99 _Bool type */
1468
+ void c99_bool_test(void)
1469
+ {
1470
+ #ifdef BOOL_ISOC99
1471
+ int a;
1472
+ _Bool b;
1473
+
1474
+ printf("bool_test:\n");
1475
+ printf("sizeof(_Bool) = %d\n", sizeof(_Bool));
1476
+ a = 3;
1477
+ printf("cast: %d %d %d\n", (_Bool)10, (_Bool)0, (_Bool)a);
1478
+ b = 3;
1479
+ printf("b = %d\n", b);
1480
+ b++;
1481
+ printf("b = %d\n", b);
1482
+ #endif
1483
+ }
1484
+
1485
+ void bitfield_test(void)
1486
+ {
1487
+ int a;
1488
+ short sa;
1489
+ unsigned char ca;
1490
+ struct sbf1 {
1491
+ int f1 : 3;
1492
+ int : 2;
1493
+ int f2 : 1;
1494
+ int : 0;
1495
+ int f3 : 5;
1496
+ int f4 : 7;
1497
+ unsigned int f5 : 7;
1498
+ } st1;
1499
+ printf("bitfield_test:");
1500
+ printf("sizeof(st1) = %d\n", sizeof(st1));
1501
+
1502
+ st1.f1 = 3;
1503
+ st1.f2 = 1;
1504
+ st1.f3 = 15;
1505
+ a = 120;
1506
+ st1.f4 = a;
1507
+ st1.f5 = a;
1508
+ st1.f5++;
1509
+ printf("%d %d %d %d %d\n",
1510
+ st1.f1, st1.f2, st1.f3, st1.f4, st1.f5);
1511
+ sa = st1.f5;
1512
+ ca = st1.f5;
1513
+ printf("%d %d\n", sa, ca);
1514
+
1515
+ st1.f1 = 7;
1516
+ if (st1.f1 == -1)
1517
+ printf("st1.f1 == -1\n");
1518
+ else
1519
+ printf("st1.f1 != -1\n");
1520
+ if (st1.f2 == -1)
1521
+ printf("st1.f2 == -1\n");
1522
+ else
1523
+ printf("st1.f2 != -1\n");
1524
+
1525
+ /* bit sizes below must be bigger than 32 since GCC doesn't allow
1526
+ long-long bitfields whose size is not bigger than int */
1527
+ struct sbf2 {
1528
+ long long f1 : 45;
1529
+ long long : 2;
1530
+ long long f2 : 35;
1531
+ unsigned long long f3 : 38;
1532
+ } st2;
1533
+ st2.f1 = 0x123456789ULL;
1534
+ a = 120;
1535
+ st2.f2 = (long long)a << 25;
1536
+ st2.f3 = a;
1537
+ st2.f2++;
1538
+ printf("%lld %lld %lld\n", st2.f1, st2.f2, st2.f3);
1539
+ }
1540
+
1541
+ #ifdef __x86_64__
1542
+ #define FLOAT_FMT "%f\n"
1543
+ #else
1544
+ /* x86's float isn't compatible with GCC */
1545
+ #define FLOAT_FMT "%.5f\n"
1546
+ #endif
1547
+
1548
+ /* declare strto* functions as they are C99 */
1549
+ double strtod(const char *nptr, char **endptr);
1550
+ float strtof(const char *nptr, char **endptr);
1551
+ long double strtold(const char *nptr, char **endptr);
1552
+
1553
+ #define FTEST(prefix, type, fmt)\
1554
+ void prefix ## cmp(type a, type b)\
1555
+ {\
1556
+ printf("%d %d %d %d %d %d\n",\
1557
+ a == b,\
1558
+ a != b,\
1559
+ a < b,\
1560
+ a > b,\
1561
+ a >= b,\
1562
+ a <= b);\
1563
+ printf(fmt " " fmt " " fmt " " fmt " " fmt " " fmt " " fmt "\n",\
1564
+ a,\
1565
+ b,\
1566
+ a + b,\
1567
+ a - b,\
1568
+ a * b,\
1569
+ a / b,\
1570
+ -a);\
1571
+ printf(fmt "\n", ++a);\
1572
+ printf(fmt "\n", a++);\
1573
+ printf(fmt "\n", a);\
1574
+ b = 0;\
1575
+ printf("%d %d\n", !a, !b);\
1576
+ }\
1577
+ void prefix ## fcast(type a)\
1578
+ {\
1579
+ float fa;\
1580
+ double da;\
1581
+ long double la;\
1582
+ int ia;\
1583
+ unsigned int ua;\
1584
+ type b;\
1585
+ fa = a;\
1586
+ da = a;\
1587
+ la = a;\
1588
+ printf("ftof: %f %f %Lf\n", fa, da, la);\
1589
+ ia = (int)a;\
1590
+ ua = (unsigned int)a;\
1591
+ printf("ftoi: %d %u\n", ia, ua);\
1592
+ ia = -1234;\
1593
+ ua = 0x81234500;\
1594
+ b = ia;\
1595
+ printf("itof: " fmt "\n", b);\
1596
+ b = ua;\
1597
+ printf("utof: " fmt "\n", b);\
1598
+ }\
1599
+ \
1600
+ float prefix ## retf(type a) { return a; }\
1601
+ double prefix ## retd(type a) { return a; }\
1602
+ long double prefix ## retld(type a) { return a; }\
1603
+ \
1604
+ void prefix ## call(void)\
1605
+ {\
1606
+ printf("float: " FLOAT_FMT, prefix ## retf(42.123456789));\
1607
+ printf("double: %f\n", prefix ## retd(42.123456789));\
1608
+ printf("long double: %Lf\n", prefix ## retld(42.123456789));\
1609
+ printf("strto%s: %f\n", #prefix, (double)strto ## prefix("1.2", NULL));\
1610
+ }\
1611
+ \
1612
+ void prefix ## test(void)\
1613
+ {\
1614
+ printf("testing '%s'\n", #type);\
1615
+ prefix ## cmp(1, 2.5);\
1616
+ prefix ## cmp(2, 1.5);\
1617
+ prefix ## cmp(1, 1);\
1618
+ prefix ## fcast(234.6);\
1619
+ prefix ## fcast(-2334.6);\
1620
+ prefix ## call();\
1621
+ }
1622
+
1623
+ FTEST(f, float, "%f")
1624
+ FTEST(d, double, "%f")
1625
+ FTEST(ld, long double, "%Lf")
1626
+
1627
+ double ftab1[3] = { 1.2, 3.4, -5.6 };
1628
+
1629
+
1630
+ void float_test(void)
1631
+ {
1632
+ float fa, fb;
1633
+ double da, db;
1634
+ int a;
1635
+ unsigned int b;
1636
+
1637
+ printf("float_test:\n");
1638
+ printf("sizeof(float) = %d\n", sizeof(float));
1639
+ printf("sizeof(double) = %d\n", sizeof(double));
1640
+ printf("sizeof(long double) = %d\n", sizeof(long double));
1641
+ ftest();
1642
+ dtest();
1643
+ ldtest();
1644
+ printf("%f %f %f\n", ftab1[0], ftab1[1], ftab1[2]);
1645
+ printf("%f %f %f\n", 2.12, .5, 2.3e10);
1646
+ // printf("%f %f %f\n", 0x1234p12, 0x1e23.23p10, 0x12dp-10);
1647
+ da = 123;
1648
+ printf("da=%f\n", da);
1649
+ fa = 123;
1650
+ printf("fa=%f\n", fa);
1651
+ a = 4000000000;
1652
+ da = a;
1653
+ printf("da = %f\n", da);
1654
+ b = 4000000000;
1655
+ db = b;
1656
+ printf("db = %f\n", db);
1657
+ }
1658
+
1659
+ int fib(int n)
1660
+ {
1661
+ if (n <= 2)
1662
+ return 1;
1663
+ else
1664
+ return fib(n-1) + fib(n-2);
1665
+ }
1666
+
1667
+ void funcptr_test()
1668
+ {
1669
+ void (*func)(int);
1670
+ int a;
1671
+ struct {
1672
+ int dummy;
1673
+ void (*func)(int);
1674
+ } st1;
1675
+
1676
+ printf("funcptr:\n");
1677
+ func = &num;
1678
+ (*func)(12345);
1679
+ func = num;
1680
+ a = 1;
1681
+ a = 1;
1682
+ func(12345);
1683
+ /* more complicated pointer computation */
1684
+ st1.func = num;
1685
+ st1.func(12346);
1686
+ printf("sizeof1 = %d\n", sizeof(funcptr_test));
1687
+ printf("sizeof2 = %d\n", sizeof funcptr_test);
1688
+ printf("sizeof3 = %d\n", sizeof(&funcptr_test));
1689
+ printf("sizeof4 = %d\n", sizeof &funcptr_test);
1690
+ }
1691
+
1692
+ void lloptest(long long a, long long b)
1693
+ {
1694
+ unsigned long long ua, ub;
1695
+
1696
+ ua = a;
1697
+ ub = b;
1698
+ /* arith */
1699
+ printf("arith: %Ld %Ld %Ld\n",
1700
+ a + b,
1701
+ a - b,
1702
+ a * b);
1703
+
1704
+ if (b != 0) {
1705
+ printf("arith1: %Ld %Ld\n",
1706
+ a / b,
1707
+ a % b);
1708
+ }
1709
+
1710
+ /* binary */
1711
+ printf("bin: %Ld %Ld %Ld\n",
1712
+ a & b,
1713
+ a | b,
1714
+ a ^ b);
1715
+
1716
+ /* tests */
1717
+ printf("test: %d %d %d %d %d %d\n",
1718
+ a == b,
1719
+ a != b,
1720
+ a < b,
1721
+ a > b,
1722
+ a >= b,
1723
+ a <= b);
1724
+
1725
+ printf("utest: %d %d %d %d %d %d\n",
1726
+ ua == ub,
1727
+ ua != ub,
1728
+ ua < ub,
1729
+ ua > ub,
1730
+ ua >= ub,
1731
+ ua <= ub);
1732
+
1733
+ /* arith2 */
1734
+ a++;
1735
+ b++;
1736
+ printf("arith2: %Ld %Ld\n", a, b);
1737
+ printf("arith2: %Ld %Ld\n", a++, b++);
1738
+ printf("arith2: %Ld %Ld\n", --a, --b);
1739
+ printf("arith2: %Ld %Ld\n", a, b);
1740
+ b = ub = 0;
1741
+ printf("not: %d %d %d %d\n", !a, !ua, !b, !ub);
1742
+ }
1743
+
1744
+ void llshift(long long a, int b)
1745
+ {
1746
+ printf("shift: %Ld %Ld %Ld\n",
1747
+ (unsigned long long)a >> b,
1748
+ a >> b,
1749
+ a << b);
1750
+ printf("shiftc: %Ld %Ld %Ld\n",
1751
+ (unsigned long long)a >> 3,
1752
+ a >> 3,
1753
+ a << 3);
1754
+ printf("shiftc: %Ld %Ld %Ld\n",
1755
+ (unsigned long long)a >> 35,
1756
+ a >> 35,
1757
+ a << 35);
1758
+ }
1759
+
1760
+ void llfloat(void)
1761
+ {
1762
+ float fa;
1763
+ double da;
1764
+ long double lda;
1765
+ long long la, lb, lc;
1766
+ unsigned long long ula, ulb, ulc;
1767
+ la = 0x12345678;
1768
+ ula = 0x72345678;
1769
+ la = (la << 20) | 0x12345;
1770
+ ula = ula << 33;
1771
+ printf("la=%Ld ula=%Lu\n", la, ula);
1772
+
1773
+ fa = la;
1774
+ da = la;
1775
+ lda = la;
1776
+ printf("lltof: %f %f %Lf\n", fa, da, lda);
1777
+
1778
+ la = fa;
1779
+ lb = da;
1780
+ lc = lda;
1781
+ printf("ftoll: %Ld %Ld %Ld\n", la, lb, lc);
1782
+
1783
+ fa = ula;
1784
+ da = ula;
1785
+ lda = ula;
1786
+ printf("ulltof: %f %f %Lf\n", fa, da, lda);
1787
+
1788
+ ula = fa;
1789
+ ulb = da;
1790
+ ulc = lda;
1791
+ printf("ftoull: %Lu %Lu %Lu\n", ula, ulb, ulc);
1792
+ }
1793
+
1794
+ long long llfunc1(int a)
1795
+ {
1796
+ return a * 2;
1797
+ }
1798
+
1799
+ struct S {
1800
+ int id;
1801
+ char item;
1802
+ };
1803
+
1804
+ long long int value(struct S *v)
1805
+ {
1806
+ return ((long long int)v->item);
1807
+ }
1808
+
1809
+ void longlong_test(void)
1810
+ {
1811
+ long long a, b, c;
1812
+ int ia;
1813
+ unsigned int ua;
1814
+ printf("longlong_test:\n");
1815
+ printf("sizeof(long long) = %d\n", sizeof(long long));
1816
+ ia = -1;
1817
+ ua = -2;
1818
+ a = ia;
1819
+ b = ua;
1820
+ printf("%Ld %Ld\n", a, b);
1821
+ printf("%Ld %Ld %Ld %Lx\n",
1822
+ (long long)1,
1823
+ (long long)-2,
1824
+ 1LL,
1825
+ 0x1234567812345679);
1826
+ a = llfunc1(-3);
1827
+ printf("%Ld\n", a);
1828
+
1829
+ lloptest(1000, 23);
1830
+ lloptest(0xff, 0x1234);
1831
+ b = 0x72345678 << 10;
1832
+ lloptest(-3, b);
1833
+ llshift(0x123, 5);
1834
+ llshift(-23, 5);
1835
+ b = 0x72345678LL << 10;
1836
+ llshift(b, 47);
1837
+
1838
+ llfloat();
1839
+ #if 1
1840
+ b = 0x12345678;
1841
+ a = -1;
1842
+ c = a + b;
1843
+ printf("%Lx\n", c);
1844
+ #endif
1845
+
1846
+ /* long long reg spill test */
1847
+ {
1848
+ struct S a;
1849
+
1850
+ a.item = 3;
1851
+ printf("%lld\n", value(&a));
1852
+ }
1853
+ lloptest(0x80000000, 0);
1854
+
1855
+ /* another long long spill test */
1856
+ {
1857
+ long long *p, v;
1858
+ v = 1;
1859
+ p = &v;
1860
+ p[0]++;
1861
+ printf("%lld\n", *p);
1862
+ }
1863
+
1864
+ a = 68719476720LL;
1865
+ b = 4294967295LL;
1866
+ printf("%d %d %d %d\n", a > b, a < b, a >= b, a <= b);
1867
+
1868
+ printf("%Ld\n", 0x123456789LLU);
1869
+ }
1870
+
1871
+ void manyarg_test(void)
1872
+ {
1873
+ long double ld = 1234567891234LL;
1874
+ printf("manyarg_test:\n");
1875
+ printf("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f\n",
1876
+ 1, 2, 3, 4, 5, 6, 7, 8,
1877
+ 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0);
1878
+ printf("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f "
1879
+ "%Ld %Ld %f %f\n",
1880
+ 1, 2, 3, 4, 5, 6, 7, 8,
1881
+ 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0,
1882
+ 1234567891234LL, 987654321986LL,
1883
+ 42.0, 43.0);
1884
+ printf("%Lf %d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f "
1885
+ "%Ld %Ld %f %f\n",
1886
+ ld, 1, 2, 3, 4, 5, 6, 7, 8,
1887
+ 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0,
1888
+ 1234567891234LL, 987654321986LL,
1889
+ 42.0, 43.0);
1890
+ /* XXX: known bug of x86-64 */
1891
+ #ifndef __x86_64__
1892
+ printf("%d %d %d %d %d %d %d %d %Lf\n",
1893
+ 1, 2, 3, 4, 5, 6, 7, 8, ld);
1894
+ printf("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f "
1895
+ "%Ld %Ld %f %f %Lf\n",
1896
+ 1, 2, 3, 4, 5, 6, 7, 8,
1897
+ 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0,
1898
+ 1234567891234LL, 987654321986LL,
1899
+ 42.0, 43.0, ld);
1900
+ printf("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f "
1901
+ "%Lf %Ld %Ld %f %f %Lf\n",
1902
+ 1, 2, 3, 4, 5, 6, 7, 8,
1903
+ 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0,
1904
+ ld, 1234567891234LL, 987654321986LL,
1905
+ 42.0, 43.0, ld);
1906
+ #endif
1907
+ }
1908
+
1909
+ void vprintf1(const char *fmt, ...)
1910
+ {
1911
+ va_list ap, aq;
1912
+ const char *p;
1913
+ int c, i;
1914
+ double d;
1915
+ long long ll;
1916
+ long double ld;
1917
+
1918
+ va_start(aq, fmt);
1919
+ va_copy(ap, aq);
1920
+
1921
+ p = fmt;
1922
+ for(;;) {
1923
+ c = *p;
1924
+ if (c == '\0')
1925
+ break;
1926
+ p++;
1927
+ if (c == '%') {
1928
+ c = *p;
1929
+ switch(c) {
1930
+ case '\0':
1931
+ goto the_end;
1932
+ case 'd':
1933
+ i = va_arg(ap, int);
1934
+ printf("%d", i);
1935
+ break;
1936
+ case 'f':
1937
+ d = va_arg(ap, double);
1938
+ printf("%f", d);
1939
+ break;
1940
+ case 'l':
1941
+ ll = va_arg(ap, long long);
1942
+ printf("%Ld", ll);
1943
+ break;
1944
+ case 'F':
1945
+ ld = va_arg(ap, long double);
1946
+ printf("%Lf", ld);
1947
+ break;
1948
+ }
1949
+ p++;
1950
+ } else {
1951
+ putchar(c);
1952
+ }
1953
+ }
1954
+ the_end:
1955
+ va_end(aq);
1956
+ va_end(ap);
1957
+ }
1958
+
1959
+ struct myspace {
1960
+ short int profile;
1961
+ };
1962
+
1963
+ void stdarg_for_struct(struct myspace bob, ...)
1964
+ {
1965
+ struct myspace george, bill;
1966
+ va_list ap;
1967
+ short int validate;
1968
+
1969
+ va_start(ap, bob);
1970
+ bill = va_arg(ap, struct myspace);
1971
+ george = va_arg(ap, struct myspace);
1972
+ validate = va_arg(ap, int);
1973
+ printf("stdarg_for_struct: %d %d %d %d\n",
1974
+ bob.profile, bill.profile, george.profile, validate);
1975
+ va_end(ap);
1976
+ }
1977
+
1978
+ void stdarg_test(void)
1979
+ {
1980
+ long double ld = 1234567891234LL;
1981
+ struct myspace bob;
1982
+
1983
+ vprintf1("%d %d %d\n", 1, 2, 3);
1984
+ vprintf1("%f %d %f\n", 1.0, 2, 3.0);
1985
+ vprintf1("%l %l %d %f\n", 1234567891234LL, 987654321986LL, 3, 1234.0);
1986
+ vprintf1("%F %F %F\n", 1.2L, 2.3L, 3.4L);
1987
+ #ifdef __x86_64__
1988
+ /* a bug of x86's TCC */
1989
+ vprintf1("%d %f %l %F %d %f %l %F\n",
1990
+ 1, 1.2, 3L, 4.5L, 6, 7.8, 9L, 0.1L);
1991
+ #endif
1992
+ vprintf1("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f\n",
1993
+ 1, 2, 3, 4, 5, 6, 7, 8,
1994
+ 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8);
1995
+ vprintf1("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f\n",
1996
+ 1, 2, 3, 4, 5, 6, 7, 8,
1997
+ 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0);
1998
+ vprintf1("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f "
1999
+ "%l %l %f %f\n",
2000
+ 1, 2, 3, 4, 5, 6, 7, 8,
2001
+ 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0,
2002
+ 1234567891234LL, 987654321986LL,
2003
+ 42.0, 43.0);
2004
+ vprintf1("%F %d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f "
2005
+ "%l %l %f %f\n",
2006
+ ld, 1, 2, 3, 4, 5, 6, 7, 8,
2007
+ 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0,
2008
+ 1234567891234LL, 987654321986LL,
2009
+ 42.0, 43.0);
2010
+ vprintf1("%d %d %d %d %d %d %d %d %F\n",
2011
+ 1, 2, 3, 4, 5, 6, 7, 8, ld);
2012
+ vprintf1("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f "
2013
+ "%l %l %f %f %F\n",
2014
+ 1, 2, 3, 4, 5, 6, 7, 8,
2015
+ 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0,
2016
+ 1234567891234LL, 987654321986LL,
2017
+ 42.0, 43.0, ld);
2018
+ vprintf1("%d %d %d %d %d %d %d %d %f %f %f %f %f %f %f %f %f %f "
2019
+ "%F %l %l %f %f %F\n",
2020
+ 1, 2, 3, 4, 5, 6, 7, 8,
2021
+ 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0,
2022
+ ld, 1234567891234LL, 987654321986LL,
2023
+ 42.0, 43.0, ld);
2024
+
2025
+ bob.profile = 42;
2026
+ stdarg_for_struct(bob, bob, bob, bob.profile);
2027
+ }
2028
+
2029
+ void whitespace_test(void)
2030
+ {
2031
+ char *str;
2032
+
2033
+
2034
+ pri\
2035
+ ntf("whitspace:\n");
2036
+ #endif
2037
+ pf("N=%d\n", 2);
2038
+
2039
+ #ifdef CORRECT_CR_HANDLING
2040
+ pri\
2041
+ ntf("aaa=%d\n", 3);
2042
+ #endif
2043
+
2044
+ pri\
2045
+ \
2046
+ ntf("min=%d\n", 4);
2047
+
2048
+ #ifdef ACCEPT_CR_IN_STRINGS
2049
+ printf("len1=%d\n", strlen("
2050
+ "));
2051
+ #ifdef CORRECT_CR_HANDLING
2052
+ str = "
2053
+ ";
2054
+ printf("len1=%d str[0]=%d\n", strlen(str), str[0]);
2055
+ #endif
2056
+ printf("len1=%d\n", strlen("
2057
+ "));
2058
+ #endif /* ACCEPT_CR_IN_STRINGS */
2059
+ }
2060
+
2061
+ int reltab[3] = { 1, 2, 3 };
2062
+
2063
+ int *rel1 = &reltab[1];
2064
+ int *rel2 = &reltab[2];
2065
+
2066
+ void relocation_test(void)
2067
+ {
2068
+ printf("*rel1=%d\n", *rel1);
2069
+ printf("*rel2=%d\n", *rel2);
2070
+ }
2071
+
2072
+ void old_style_f(a,b,c)
2073
+ int a, b;
2074
+ double c;
2075
+ {
2076
+ printf("a=%d b=%d b=%f\n", a, b, c);
2077
+ }
2078
+
2079
+ void decl_func1(int cmpfn())
2080
+ {
2081
+ printf("cmpfn=%lx\n", (long)cmpfn);
2082
+ }
2083
+
2084
+ void decl_func2(cmpfn)
2085
+ int cmpfn();
2086
+ {
2087
+ printf("cmpfn=%lx\n", (long)cmpfn);
2088
+ }
2089
+
2090
+ void old_style_function(void)
2091
+ {
2092
+ old_style_f((void *)1, 2, 3.0);
2093
+ decl_func1(NULL);
2094
+ decl_func2(NULL);
2095
+ }
2096
+
2097
+ void alloca_test()
2098
+ {
2099
+ #if defined __i386__ || defined __x86_64__
2100
+ char *p = alloca(16);
2101
+ strcpy(p,"123456789012345");
2102
+ printf("alloca: p is %s\n", p);
2103
+ char *demo = "This is only a test.\n";
2104
+ /* Test alloca embedded in a larger expression */
2105
+ printf("alloca: %s\n", strcpy(alloca(strlen(demo)+1),demo) );
2106
+ #endif
2107
+ }
2108
+
2109
+ void *bounds_checking_is_enabled()
2110
+ {
2111
+ char ca[10], *cp = ca-1;
2112
+ return (ca != cp + 1) ? cp : NULL;
2113
+ }
2114
+
2115
+ typedef int constant_negative_array_size_as_compile_time_assertion_idiom[(1 ? 2 : 0) - 1];
2116
+
2117
+ void c99_vla_test(int size1, int size2)
2118
+ {
2119
+ #if defined __i386__ || defined __x86_64__
2120
+ int size = size1 * size2;
2121
+ int tab1[size][2], tab2[10][2];
2122
+ void *tab1_ptr, *tab2_ptr, *bad_ptr;
2123
+
2124
+ /* "size" should have been 'captured' at tab1 declaration,
2125
+ so modifying it should have no effect on VLA behaviour. */
2126
+ size = size-1;
2127
+
2128
+ printf("Test C99 VLA 1 (sizeof): ");
2129
+ printf("%s\n", (sizeof tab1 == size1 * size2 * 2 * sizeof(int)) ? "PASSED" : "FAILED");
2130
+ tab1_ptr = tab1;
2131
+ tab2_ptr = tab2;
2132
+ printf("Test C99 VLA 2 (ptrs substract): ");
2133
+ printf("%s\n", (tab2 - tab1 == (tab2_ptr - tab1_ptr) / (sizeof(int) * 2)) ? "PASSED" : "FAILED");
2134
+ printf("Test C99 VLA 3 (ptr add): ");
2135
+ printf("%s\n", &tab1[5][1] == (tab1_ptr + (5 * 2 + 1) * sizeof(int)) ? "PASSED" : "FAILED");
2136
+ printf("Test C99 VLA 4 (ptr access): ");
2137
+ tab1[size1][1] = 42;
2138
+ printf("%s\n", (*((int *) (tab1_ptr + (size1 * 2 + 1) * sizeof(int))) == 42) ? "PASSED" : "FAILED");
2139
+
2140
+ printf("Test C99 VLA 5 (bounds checking (might be disabled)): ");
2141
+ if (bad_ptr = bounds_checking_is_enabled()) {
2142
+ int *t1 = &tab1[size1 * size2 - 1][3];
2143
+ int *t2 = &tab2[9][3];
2144
+ printf("%s ", bad_ptr == t1 ? "PASSED" : "FAILED");
2145
+ printf("%s ", bad_ptr == t2 ? "PASSED" : "FAILED");
2146
+
2147
+ char*c1 = 1 + sizeof(tab1) + (char*)tab1;
2148
+ char*c2 = 1 + sizeof(tab2) + (char*)tab2;
2149
+ printf("%s ", bad_ptr == c1 ? "PASSED" : "FAILED");
2150
+ printf("%s ", bad_ptr == c2 ? "PASSED" : "FAILED");
2151
+
2152
+ int *i1 = tab1[-1];
2153
+ int *i2 = tab2[-1];
2154
+ printf("%s ", bad_ptr == i1 ? "PASSED" : "FAILED");
2155
+ printf("%s ", bad_ptr == i2 ? "PASSED" : "FAILED");
2156
+
2157
+ int *x1 = tab1[size1 * size2 + 1];
2158
+ int *x2 = tab2[10 + 1];
2159
+ printf("%s ", bad_ptr == x1 ? "PASSED" : "FAILED");
2160
+ printf("%s ", bad_ptr == x2 ? "PASSED" : "FAILED");
2161
+ } else {
2162
+ printf("PASSED PASSED PASSED PASSED PASSED PASSED PASSED PASSED ");
2163
+ }
2164
+ printf("\n");
2165
+ #endif
2166
+ }
2167
+
2168
+ typedef __SIZE_TYPE__ uintptr_t;
2169
+
2170
+ void sizeof_test(void)
2171
+ {
2172
+ int a;
2173
+ int **ptr;
2174
+
2175
+ printf("sizeof(int) = %d\n", sizeof(int));
2176
+ printf("sizeof(unsigned int) = %d\n", sizeof(unsigned int));
2177
+ printf("sizeof(long) = %d\n", sizeof(long));
2178
+ printf("sizeof(unsigned long) = %d\n", sizeof(unsigned long));
2179
+ printf("sizeof(short) = %d\n", sizeof(short));
2180
+ printf("sizeof(unsigned short) = %d\n", sizeof(unsigned short));
2181
+ printf("sizeof(char) = %d\n", sizeof(char));
2182
+ printf("sizeof(unsigned char) = %d\n", sizeof(unsigned char));
2183
+ printf("sizeof(func) = %d\n", sizeof sizeof_test());
2184
+ a = 1;
2185
+ printf("sizeof(a++) = %d\n", sizeof a++);
2186
+ printf("a=%d\n", a);
2187
+ ptr = NULL;
2188
+ printf("sizeof(**ptr) = %d\n", sizeof (**ptr));
2189
+
2190
+ /* The type of sizeof should be as large as a pointer, actually
2191
+ it should be size_t. */
2192
+ printf("sizeof(sizeof(int) = %d\n", sizeof(sizeof(int)));
2193
+ uintptr_t t = 1;
2194
+ uintptr_t t2;
2195
+ /* Effectively <<32, but defined also on 32bit machines. */
2196
+ t <<= 16;
2197
+ t <<= 16;
2198
+ t++;
2199
+ /* This checks that sizeof really can be used to manipulate
2200
+ uintptr_t objects, without truncation. */
2201
+ t2 = t & -sizeof(uintptr_t);
2202
+ printf ("%lu %lu\n", t, t2);
2203
+
2204
+ /* some alignof tests */
2205
+ printf("__alignof__(int) = %d\n", __alignof__(int));
2206
+ printf("__alignof__(unsigned int) = %d\n", __alignof__(unsigned int));
2207
+ printf("__alignof__(short) = %d\n", __alignof__(short));
2208
+ printf("__alignof__(unsigned short) = %d\n", __alignof__(unsigned short));
2209
+ printf("__alignof__(char) = %d\n", __alignof__(char));
2210
+ printf("__alignof__(unsigned char) = %d\n", __alignof__(unsigned char));
2211
+ printf("__alignof__(func) = %d\n", __alignof__ sizeof_test());
2212
+ }
2213
+
2214
+ void typeof_test(void)
2215
+ {
2216
+ double a;
2217
+ typeof(a) b;
2218
+ typeof(float) c;
2219
+
2220
+ a = 1.5;
2221
+ b = 2.5;
2222
+ c = 3.5;
2223
+ printf("a=%f b=%f c=%f\n", a, b, c);
2224
+ }
2225
+
2226
+ void statement_expr_test(void)
2227
+ {
2228
+ int a, i;
2229
+
2230
+ a = 0;
2231
+ for(i=0;i<10;i++) {
2232
+ a += 1 +
2233
+ ( { int b, j;
2234
+ b = 0;
2235
+ for(j=0;j<5;j++)
2236
+ b += j; b;
2237
+ } );
2238
+ }
2239
+ printf("a=%d\n", a);
2240
+
2241
+ }
2242
+
2243
+ void local_label_test(void)
2244
+ {
2245
+ int a;
2246
+ goto l1;
2247
+ l2:
2248
+ a = 1 + ({
2249
+ __label__ l1, l2, l3, l4;
2250
+ goto l1;
2251
+ l4:
2252
+ printf("aa1\n");
2253
+ goto l3;
2254
+ l2:
2255
+ printf("aa3\n");
2256
+ goto l4;
2257
+ l1:
2258
+ printf("aa2\n");
2259
+ goto l2;
2260
+ l3:;
2261
+ 1;
2262
+ });
2263
+ printf("a=%d\n", a);
2264
+ return;
2265
+ l4:
2266
+ printf("bb1\n");
2267
+ goto l2;
2268
+ l1:
2269
+ printf("bb2\n");
2270
+ goto l4;
2271
+ }
2272
+
2273
+ /* inline assembler test */
2274
+ #ifdef __i386__
2275
+
2276
+ /* from linux kernel */
2277
+ static char * strncat1(char * dest,const char * src,size_t count)
2278
+ {
2279
+ int d0, d1, d2, d3;
2280
+ __asm__ __volatile__(
2281
+ "repne\n\t"
2282
+ "scasb\n\t"
2283
+ "decl %1\n\t"
2284
+ "movl %8,%3\n"
2285
+ "1:\tdecl %3\n\t"
2286
+ "js 2f\n\t"
2287
+ "lodsb\n\t"
2288
+ "stosb\n\t"
2289
+ "testb %%al,%%al\n\t"
2290
+ "jne 1b\n"
2291
+ "2:\txorl %2,%2\n\t"
2292
+ "stosb"
2293
+ : "=&S" (d0), "=&D" (d1), "=&a" (d2), "=&c" (d3)
2294
+ : "0" (src),"1" (dest),"2" (0),"3" (0xffffffff), "g" (count)
2295
+ : "memory");
2296
+ return dest;
2297
+ }
2298
+
2299
+ static char * strncat2(char * dest,const char * src,size_t count)
2300
+ {
2301
+ int d0, d1, d2, d3;
2302
+ __asm__ __volatile__(
2303
+ "repne scasb\n\t" /* one-line repne prefix + string op */
2304
+ "decl %1\n\t"
2305
+ "movl %8,%3\n"
2306
+ "1:\tdecl %3\n\t"
2307
+ "js 2f\n\t"
2308
+ "lodsb\n\t"
2309
+ "stosb\n\t"
2310
+ "testb %%al,%%al\n\t"
2311
+ "jne 1b\n"
2312
+ "2:\txorl %2,%2\n\t"
2313
+ "stosb"
2314
+ : "=&S" (d0), "=&D" (d1), "=&a" (d2), "=&c" (d3)
2315
+ : "0" (src),"1" (dest),"2" (0),"3" (0xffffffff), "g" (count)
2316
+ : "memory");
2317
+ return dest;
2318
+ }
2319
+
2320
+ static inline void * memcpy1(void * to, const void * from, size_t n)
2321
+ {
2322
+ int d0, d1, d2;
2323
+ __asm__ __volatile__(
2324
+ "rep ; movsl\n\t"
2325
+ "testb $2,%b4\n\t"
2326
+ "je 1f\n\t"
2327
+ "movsw\n"
2328
+ "1:\ttestb $1,%b4\n\t"
2329
+ "je 2f\n\t"
2330
+ "movsb\n"
2331
+ "2:"
2332
+ : "=&c" (d0), "=&D" (d1), "=&S" (d2)
2333
+ :"0" (n/4), "q" (n),"1" ((long) to),"2" ((long) from)
2334
+ : "memory");
2335
+ return (to);
2336
+ }
2337
+
2338
+ static inline void * memcpy2(void * to, const void * from, size_t n)
2339
+ {
2340
+ int d0, d1, d2;
2341
+ __asm__ __volatile__(
2342
+ "rep movsl\n\t" /* one-line rep prefix + string op */
2343
+ "testb $2,%b4\n\t"
2344
+ "je 1f\n\t"
2345
+ "movsw\n"
2346
+ "1:\ttestb $1,%b4\n\t"
2347
+ "je 2f\n\t"
2348
+ "movsb\n"
2349
+ "2:"
2350
+ : "=&c" (d0), "=&D" (d1), "=&S" (d2)
2351
+ :"0" (n/4), "q" (n),"1" ((long) to),"2" ((long) from)
2352
+ : "memory");
2353
+ return (to);
2354
+ }
2355
+
2356
+ static __inline__ void sigaddset1(unsigned int *set, int _sig)
2357
+ {
2358
+ __asm__("btsl %1,%0" : "=m"(*set) : "Ir"(_sig - 1) : "cc");
2359
+ }
2360
+
2361
+ static __inline__ void sigdelset1(unsigned int *set, int _sig)
2362
+ {
2363
+ asm("btrl %1,%0" : "=m"(*set) : "Ir"(_sig - 1) : "cc");
2364
+ }
2365
+
2366
+ static __inline__ __const__ unsigned int swab32(unsigned int x)
2367
+ {
2368
+ __asm__("xchgb %b0,%h0\n\t" /* swap lower bytes */
2369
+ "rorl $16,%0\n\t" /* swap words */
2370
+ "xchgb %b0,%h0" /* swap higher bytes */
2371
+ :"=q" (x)
2372
+ : "0" (x));
2373
+ return x;
2374
+ }
2375
+
2376
+ static __inline__ unsigned long long mul64(unsigned int a, unsigned int b)
2377
+ {
2378
+ unsigned long long res;
2379
+ __asm__("mull %2" : "=A" (res) : "a" (a), "r" (b));
2380
+ return res;
2381
+ }
2382
+
2383
+ static __inline__ unsigned long long inc64(unsigned long long a)
2384
+ {
2385
+ unsigned long long res;
2386
+ __asm__("addl $1, %%eax ; adcl $0, %%edx" : "=A" (res) : "A" (a));
2387
+ return res;
2388
+ }
2389
+
2390
+ unsigned int set;
2391
+
2392
+ void asm_test(void)
2393
+ {
2394
+ char buf[128];
2395
+ unsigned int val;
2396
+
2397
+ printf("inline asm:\n");
2398
+ /* test the no operand case */
2399
+ asm volatile ("xorl %eax, %eax");
2400
+
2401
+ memcpy1(buf, "hello", 6);
2402
+ strncat1(buf, " worldXXXXX", 3);
2403
+ printf("%s\n", buf);
2404
+
2405
+ memcpy2(buf, "hello", 6);
2406
+ strncat2(buf, " worldXXXXX", 3);
2407
+ printf("%s\n", buf);
2408
+
2409
+ /* 'A' constraint test */
2410
+ printf("mul64=0x%Lx\n", mul64(0x12345678, 0xabcd1234));
2411
+ printf("inc64=0x%Lx\n", inc64(0x12345678ffffffff));
2412
+
2413
+ set = 0xff;
2414
+ sigdelset1(&set, 2);
2415
+ sigaddset1(&set, 16);
2416
+ /* NOTE: we test here if C labels are correctly restored after the
2417
+ asm statement */
2418
+ goto label1;
2419
+ label2:
2420
+ __asm__("btsl %1,%0" : "=m"(set) : "Ir"(20) : "cc");
2421
+ #ifdef __GNUC__ // works strange with GCC 4.3
2422
+ set=0x1080fd;
2423
+ #endif
2424
+ printf("set=0x%x\n", set);
2425
+ val = 0x01020304;
2426
+ printf("swab32(0x%08x) = 0x%0x\n", val, swab32(val));
2427
+ return;
2428
+ label1:
2429
+ goto label2;
2430
+ }
2431
+
2432
+ #else
2433
+
2434
+ void asm_test(void)
2435
+ {
2436
+ }
2437
+
2438
+ #endif
2439
+
2440
+ #define COMPAT_TYPE(type1, type2) \
2441
+ {\
2442
+ printf("__builtin_types_compatible_p(%s, %s) = %d\n", #type1, #type2, \
2443
+ __builtin_types_compatible_p (type1, type2));\
2444
+ }
2445
+
2446
+ int constant_p_var;
2447
+
2448
+ void builtin_test(void)
2449
+ {
2450
+ #if GCC_MAJOR >= 3
2451
+ COMPAT_TYPE(int, int);
2452
+ COMPAT_TYPE(int, unsigned int);
2453
+ COMPAT_TYPE(int, char);
2454
+ COMPAT_TYPE(int, const int);
2455
+ COMPAT_TYPE(int, volatile int);
2456
+ COMPAT_TYPE(int *, int *);
2457
+ COMPAT_TYPE(int *, void *);
2458
+ COMPAT_TYPE(int *, const int *);
2459
+ COMPAT_TYPE(char *, unsigned char *);
2460
+ /* space is needed because tcc preprocessor introduces a space between each token */
2461
+ COMPAT_TYPE(char * *, void *);
2462
+ #endif
2463
+ printf("res = %d\n", __builtin_constant_p(1));
2464
+ printf("res = %d\n", __builtin_constant_p(1 + 2));
2465
+ printf("res = %d\n", __builtin_constant_p(&constant_p_var));
2466
+ printf("res = %d\n", __builtin_constant_p(constant_p_var));
2467
+ }
2468
+
2469
+ #ifndef _WIN32
2470
+ extern int __attribute__((weak)) weak_f1(void);
2471
+ extern int __attribute__((weak)) weak_f2(void);
2472
+ extern int weak_f3(void);
2473
+ extern int __attribute__((weak)) weak_v1;
2474
+ extern int __attribute__((weak)) weak_v2;
2475
+ extern int weak_v3;
2476
+
2477
+ extern int (*weak_fpa)() __attribute__((weak));
2478
+ extern int __attribute__((weak)) (*weak_fpb)();
2479
+ extern __attribute__((weak)) int (*weak_fpc)();
2480
+
2481
+ extern int weak_asm_f1(void) asm("weak_asm_f1x") __attribute((weak));
2482
+ extern int __attribute((weak)) weak_asm_f2(void) asm("weak_asm_f2x") ;
2483
+ extern int __attribute((weak)) weak_asm_f3(void) asm("weak_asm_f3x") __attribute((weak));
2484
+ extern int weak_asm_v1 asm("weak_asm_v1x") __attribute((weak));
2485
+ extern int __attribute((weak)) weak_asm_v2 asm("weak_asm_v2x") ;
2486
+ extern int __attribute((weak)) weak_asm_v3(void) asm("weak_asm_v3x") __attribute((weak));
2487
+
2488
+ static const size_t dummy = 0;
2489
+ extern __typeof(dummy) weak_dummy1 __attribute__((weak, alias("dummy")));
2490
+ extern __typeof(dummy) __attribute__((weak, alias("dummy"))) weak_dummy2;
2491
+ extern __attribute__((weak, alias("dummy"))) __typeof(dummy) weak_dummy3;
2492
+
2493
+ int some_lib_func(void);
2494
+ int dummy_impl_of_slf(void) { return 444; }
2495
+ int some_lib_func(void) __attribute__((weak, alias("dummy_impl_of_slf")));
2496
+
2497
+ int weak_toolate() __attribute__((weak));
2498
+ int weak_toolate() { return 0; }
2499
+
2500
+ void __attribute__((weak)) weak_test(void)
2501
+ {
2502
+ printf("weak_f1=%d\n", weak_f1 ? weak_f1() : 123);
2503
+ printf("weak_f2=%d\n", weak_f2 ? weak_f2() : 123);
2504
+ printf("weak_f3=%d\n", weak_f3 ? weak_f3() : 123);
2505
+ printf("weak_v1=%d\n",&weak_v1 ? weak_v1 : 123);
2506
+ printf("weak_v2=%d\n",&weak_v2 ? weak_v2 : 123);
2507
+ printf("weak_v3=%d\n",&weak_v3 ? weak_v3 : 123);
2508
+
2509
+ printf("weak_fpa=%d\n",&weak_fpa ? weak_fpa() : 123);
2510
+ printf("weak_fpb=%d\n",&weak_fpb ? weak_fpb() : 123);
2511
+ printf("weak_fpc=%d\n",&weak_fpc ? weak_fpc() : 123);
2512
+
2513
+ printf("weak_asm_f1=%d\n", weak_asm_f1 != NULL);
2514
+ printf("weak_asm_f2=%d\n", weak_asm_f2 != NULL);
2515
+ printf("weak_asm_f3=%d\n", weak_asm_f3 != NULL);
2516
+ printf("weak_asm_v1=%d\n",&weak_asm_v1 != NULL);
2517
+ printf("weak_asm_v2=%d\n",&weak_asm_v2 != NULL);
2518
+ printf("weak_asm_v3=%d\n",&weak_asm_v3 != NULL);
2519
+ }
2520
+
2521
+ int __attribute__((weak)) weak_f2() { return 222; }
2522
+ int __attribute__((weak)) weak_f3() { return 333; }
2523
+ int __attribute__((weak)) weak_v2 = 222;
2524
+ int __attribute__((weak)) weak_v3 = 333;
2525
+ #endif
2526
+
2527
+ void const_func(const int a)
2528
+ {
2529
+ }
2530
+
2531
+ void const_warn_test(void)
2532
+ {
2533
+ const_func(1);
2534
+ }
2535
+
2536
+ struct condstruct {
2537
+ int i;
2538
+ };
2539
+
2540
+ int getme (struct condstruct *s, int i)
2541
+ {
2542
+ int i1 = (i == 0 ? 0 : s)->i;
2543
+ int i2 = (i == 0 ? s : 0)->i;
2544
+ int i3 = (i == 0 ? (void*)0 : s)->i;
2545
+ int i4 = (i == 0 ? s : (void*)0)->i;
2546
+ return i1 + i2 + i3 + i4;
2547
+ }
2548
+
2549
+ struct global_data
2550
+ {
2551
+ int a[40];
2552
+ int *b[40];
2553
+ };
2554
+
2555
+ struct global_data global_data;
2556
+
2557
+ int global_data_getstuff (int *, int);
2558
+
2559
+ void global_data_callit (int i)
2560
+ {
2561
+ *global_data.b[i] = global_data_getstuff (global_data.b[i], 1);
2562
+ }
2563
+
2564
+ int global_data_getstuff (int *p, int i)
2565
+ {
2566
+ return *p + i;
2567
+ }
2568
+
2569
+ void global_data_test (void)
2570
+ {
2571
+ global_data.a[0] = 42;
2572
+ global_data.b[0] = &global_data.a[0];
2573
+ global_data_callit (0);
2574
+ printf ("%d\n", global_data.a[0]);
2575
+ }
2576
+
2577
+ struct cmpcmpS
2578
+ {
2579
+ unsigned char fill : 3;
2580
+ unsigned char b1 : 1;
2581
+ unsigned char b2 : 1;
2582
+ unsigned char fill2 : 3;
2583
+ };
2584
+
2585
+ int glob1, glob2, glob3;
2586
+
2587
+ void compare_comparisons (struct cmpcmpS *s)
2588
+ {
2589
+ if (s->b1 != (glob1 == glob2)
2590
+ || (s->b2 != (glob1 == glob3)))
2591
+ printf ("comparing comparisons broken\n");
2592
+ }
2593
+
2594
+ void cmp_comparison_test(void)
2595
+ {
2596
+ struct cmpcmpS s;
2597
+ s.b1 = 1;
2598
+ glob1 = 42; glob2 = 42;
2599
+ s.b2 = 0;
2600
+ glob3 = 43;
2601
+ compare_comparisons (&s);
2602
+ }
2603
+
2604
+ int fcompare (double a, double b, int code)
2605
+ {
2606
+ switch (code) {
2607
+ case 0: return a == b;
2608
+ case 1: return a != b;
2609
+ case 2: return a < b;
2610
+ case 3: return a >= b;
2611
+ case 4: return a > b;
2612
+ case 5: return a <= b;
2613
+ }
2614
+ }
2615
+
2616
+ void math_cmp_test(void)
2617
+ {
2618
+ double nan = 0.0/0.0;
2619
+ double one = 1.0;
2620
+ double two = 2.0;
2621
+ int comp = 0;
2622
+ #define bug(a,b,op,iop,part) printf("Test broken: %s %s %s %s %d\n", #a, #b, #op, #iop, part)
2623
+
2624
+ /* This asserts that "a op b" is _not_ true, but "a iop b" is true.
2625
+ And it does this in various ways so that all code generation paths
2626
+ are checked (generating inverted tests, or non-inverted tests, or
2627
+ producing a 0/1 value without jumps (that's done in the fcompare
2628
+ function). */
2629
+ #define FCMP(a,b,op,iop,code) \
2630
+ if (fcompare (a,b,code)) \
2631
+ bug (a,b,op,iop,1); \
2632
+ if (a op b) \
2633
+ bug (a,b,op,iop,2); \
2634
+ if (a iop b) \
2635
+ ; \
2636
+ else \
2637
+ bug (a,b,op,iop,3); \
2638
+ if ((a op b) || comp) \
2639
+ bug (a,b,op,iop,4); \
2640
+ if ((a iop b) || comp) \
2641
+ ; \
2642
+ else \
2643
+ bug (a,b,op,iop,5);
2644
+
2645
+ /* Equality tests. */
2646
+ FCMP(nan, nan, ==, !=, 0);
2647
+ FCMP(one, two, ==, !=, 0);
2648
+ FCMP(one, one, !=, ==, 1);
2649
+ /* Non-equality is a bit special. */
2650
+ if (!fcompare (nan, nan, 1))
2651
+ bug (nan, nan, !=, ==, 6);
2652
+
2653
+ /* Relational tests on numbers. */
2654
+ FCMP(two, one, <, >=, 2);
2655
+ FCMP(one, two, >=, <, 3);
2656
+ FCMP(one, two, >, <=, 4);
2657
+ FCMP(two, one, <=, >, 5);
2658
+
2659
+ /* Relational tests on NaNs. Note that the inverse op here is
2660
+ always !=, there's no operator in C that is equivalent to !(a < b),
2661
+ when NaNs are involved, same for the other relational ops. */
2662
+ FCMP(nan, nan, <, !=, 2);
2663
+ FCMP(nan, nan, >=, !=, 3);
2664
+ FCMP(nan, nan, >, !=, 4);
2665
+ FCMP(nan, nan, <=, !=, 5);
2666
+ }
2667
+
2668
+ double get100 () { return 100.0; }
2669
+
2670
+ void callsave_test(void)
2671
+ {
2672
+ #if defined __i386__ || defined __x86_64__
2673
+ int i, s; double *d; double t;
2674
+ s = sizeof (double);
2675
+ printf ("callsavetest: %d\n", s);
2676
+ d = alloca (sizeof(double));
2677
+ d[0] = 10.0;
2678
+ /* x86-64 had a bug were the next call to get100 would evict
2679
+ the lvalue &d[0] as VT_LLOCAL, and the reload would be done
2680
+ in int type, not pointer type. When alloca returns a pointer
2681
+ with the high 32 bit set (which is likely on x86-64) the access
2682
+ generates a segfault. */
2683
+ i = d[0] > get100 ();
2684
+ printf ("%d\n", i);
2685
+ #endif
2686
+ }
2687
+
2688
+
2689
+ void bfa3(ptrdiff_t str_offset)
2690
+ {
2691
+ printf("bfa3: %s\n", (char *)__builtin_frame_address(3) + str_offset);
2692
+ }
2693
+ void bfa2(ptrdiff_t str_offset)
2694
+ {
2695
+ printf("bfa2: %s\n", (char *)__builtin_frame_address(2) + str_offset);
2696
+ bfa3(str_offset);
2697
+ }
2698
+ void bfa1(ptrdiff_t str_offset)
2699
+ {
2700
+ printf("bfa1: %s\n", (char *)__builtin_frame_address(1) + str_offset);
2701
+ #if defined(__arm__) && !defined(__GNUC__)
2702
+ bfa2(str_offset);
2703
+ #endif
2704
+ }
2705
+
2706
+ void builtin_frame_address_test(void)
2707
+ {
2708
+ char str[] = "__builtin_frame_address";
2709
+ char *fp0 = __builtin_frame_address(0);
2710
+
2711
+ printf("str: %s\n", str);
2712
+ bfa1(str-fp0);
2713
+ }