c-cppbuiltin.c 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654
  1. /* Define builtin-in macros for the C family front ends.
  2. Copyright (C) 2002-2015 Free Software Foundation, Inc.
  3. This file is part of GCC.
  4. GCC is free software; you can redistribute it and/or modify it under
  5. the terms of the GNU General Public License as published by the Free
  6. Software Foundation; either version 3, or (at your option) any later
  7. version.
  8. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  9. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  11. for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GCC; see the file COPYING3. If not see
  14. <http://www.gnu.org/licenses/>. */
  15. #include "config.h"
  16. #include "system.h"
  17. #include "coretypes.h"
  18. #include "tm.h"
  19. #include "hash-set.h"
  20. #include "machmode.h"
  21. #include "vec.h"
  22. #include "double-int.h"
  23. #include "input.h"
  24. #include "alias.h"
  25. #include "symtab.h"
  26. #include "wide-int.h"
  27. #include "inchash.h"
  28. #include "tree.h"
  29. #include "stor-layout.h"
  30. #include "stringpool.h"
  31. #include "version.h"
  32. #include "flags.h"
  33. #include "c-common.h"
  34. #include "c-pragma.h"
  35. #include "output.h" /* For user_label_prefix. */
  36. #include "debug.h" /* For dwarf2out_do_cfi_asm. */
  37. #include "tm_p.h" /* For TARGET_CPU_CPP_BUILTINS & friends. */
  38. #include "target.h"
  39. #include "common/common-target.h"
  40. #include "cpp-id-data.h"
  41. #include "cppbuiltin.h"
  42. #ifndef TARGET_OS_CPP_BUILTINS
  43. # define TARGET_OS_CPP_BUILTINS()
  44. #endif
  45. #ifndef TARGET_OBJFMT_CPP_BUILTINS
  46. # define TARGET_OBJFMT_CPP_BUILTINS()
  47. #endif
  48. #ifndef REGISTER_PREFIX
  49. #define REGISTER_PREFIX ""
  50. #endif
  51. /* Non-static as some targets don't use it. */
  52. void builtin_define_std (const char *) ATTRIBUTE_UNUSED;
  53. static void builtin_define_with_int_value (const char *, HOST_WIDE_INT);
  54. static void builtin_define_with_hex_fp_value (const char *, tree,
  55. int, const char *,
  56. const char *,
  57. const char *);
  58. static void builtin_define_stdint_macros (void);
  59. static void builtin_define_constants (const char *, tree);
  60. static void builtin_define_type_max (const char *, tree);
  61. static void builtin_define_type_minmax (const char *, const char *, tree);
  62. static void builtin_define_type_sizeof (const char *, tree);
  63. static void builtin_define_float_constants (const char *,
  64. const char *,
  65. const char *,
  66. const char *,
  67. tree);
  68. /* Return true if MODE provides a fast multiply/add (FMA) builtin function.
  69. Originally this function used the fma optab, but that doesn't work with
  70. -save-temps, so just rely on the HAVE_fma macros for the standard floating
  71. point types. */
  72. static bool
  73. mode_has_fma (machine_mode mode)
  74. {
  75. switch (mode)
  76. {
  77. #ifdef HAVE_fmasf4
  78. case SFmode:
  79. return !!HAVE_fmasf4;
  80. #endif
  81. #ifdef HAVE_fmadf4
  82. case DFmode:
  83. return !!HAVE_fmadf4;
  84. #endif
  85. #ifdef HAVE_fmaxf4
  86. case XFmode:
  87. return !!HAVE_fmaxf4;
  88. #endif
  89. #ifdef HAVE_fmatf4
  90. case TFmode:
  91. return !!HAVE_fmatf4;
  92. #endif
  93. default:
  94. break;
  95. }
  96. return false;
  97. }
  98. /* Define NAME with value TYPE size_unit. */
  99. static void
  100. builtin_define_type_sizeof (const char *name, tree type)
  101. {
  102. builtin_define_with_int_value (name,
  103. tree_to_uhwi (TYPE_SIZE_UNIT (type)));
  104. }
  105. /* Define the float.h constants for TYPE using NAME_PREFIX, FP_SUFFIX,
  106. and FP_CAST. */
  107. static void
  108. builtin_define_float_constants (const char *name_prefix,
  109. const char *fp_suffix,
  110. const char *fp_cast,
  111. const char *fma_suffix,
  112. tree type)
  113. {
  114. /* Used to convert radix-based values to base 10 values in several cases.
  115. In the max_exp -> max_10_exp conversion for 128-bit IEEE, we need at
  116. least 6 significant digits for correct results. Using the fraction
  117. formed by (log(2)*1e6)/(log(10)*1e6) overflows a 32-bit integer as an
  118. intermediate; perhaps someone can find a better approximation, in the
  119. mean time, I suspect using doubles won't harm the bootstrap here. */
  120. const double log10_2 = .30102999566398119521;
  121. double log10_b;
  122. const struct real_format *fmt;
  123. const struct real_format *ldfmt;
  124. char name[64], buf[128];
  125. int dig, min_10_exp, max_10_exp;
  126. int decimal_dig;
  127. int type_decimal_dig;
  128. fmt = REAL_MODE_FORMAT (TYPE_MODE (type));
  129. gcc_assert (fmt->b != 10);
  130. ldfmt = REAL_MODE_FORMAT (TYPE_MODE (long_double_type_node));
  131. gcc_assert (ldfmt->b != 10);
  132. /* The radix of the exponent representation. */
  133. if (type == float_type_node)
  134. builtin_define_with_int_value ("__FLT_RADIX__", fmt->b);
  135. log10_b = log10_2;
  136. /* The number of radix digits, p, in the floating-point significand. */
  137. sprintf (name, "__%s_MANT_DIG__", name_prefix);
  138. builtin_define_with_int_value (name, fmt->p);
  139. /* The number of decimal digits, q, such that any floating-point number
  140. with q decimal digits can be rounded into a floating-point number with
  141. p radix b digits and back again without change to the q decimal digits,
  142. p log10 b if b is a power of 10
  143. floor((p - 1) log10 b) otherwise
  144. */
  145. dig = (fmt->p - 1) * log10_b;
  146. sprintf (name, "__%s_DIG__", name_prefix);
  147. builtin_define_with_int_value (name, dig);
  148. /* The minimum negative int x such that b**(x-1) is a normalized float. */
  149. sprintf (name, "__%s_MIN_EXP__", name_prefix);
  150. sprintf (buf, "(%d)", fmt->emin);
  151. builtin_define_with_value (name, buf, 0);
  152. /* The minimum negative int x such that 10**x is a normalized float,
  153. ceil (log10 (b ** (emin - 1)))
  154. = ceil (log10 (b) * (emin - 1))
  155. Recall that emin is negative, so the integer truncation calculates
  156. the ceiling, not the floor, in this case. */
  157. min_10_exp = (fmt->emin - 1) * log10_b;
  158. sprintf (name, "__%s_MIN_10_EXP__", name_prefix);
  159. sprintf (buf, "(%d)", min_10_exp);
  160. builtin_define_with_value (name, buf, 0);
  161. /* The maximum int x such that b**(x-1) is a representable float. */
  162. sprintf (name, "__%s_MAX_EXP__", name_prefix);
  163. builtin_define_with_int_value (name, fmt->emax);
  164. /* The maximum int x such that 10**x is in the range of representable
  165. finite floating-point numbers,
  166. floor (log10((1 - b**-p) * b**emax))
  167. = floor (log10(1 - b**-p) + log10(b**emax))
  168. = floor (log10(1 - b**-p) + log10(b)*emax)
  169. The safest thing to do here is to just compute this number. But since
  170. we don't link cc1 with libm, we cannot. We could implement log10 here
  171. a series expansion, but that seems too much effort because:
  172. Note that the first term, for all extant p, is a number exceedingly close
  173. to zero, but slightly negative. Note that the second term is an integer
  174. scaling an irrational number, and that because of the floor we are only
  175. interested in its integral portion.
  176. In order for the first term to have any effect on the integral portion
  177. of the second term, the second term has to be exceedingly close to an
  178. integer itself (e.g. 123.000000000001 or something). Getting a result
  179. that close to an integer requires that the irrational multiplicand have
  180. a long series of zeros in its expansion, which doesn't occur in the
  181. first 20 digits or so of log10(b).
  182. Hand-waving aside, crunching all of the sets of constants above by hand
  183. does not yield a case for which the first term is significant, which
  184. in the end is all that matters. */
  185. max_10_exp = fmt->emax * log10_b;
  186. sprintf (name, "__%s_MAX_10_EXP__", name_prefix);
  187. builtin_define_with_int_value (name, max_10_exp);
  188. /* The number of decimal digits, n, such that any floating-point number
  189. can be rounded to n decimal digits and back again without change to
  190. the value.
  191. p * log10(b) if b is a power of 10
  192. ceil(1 + p * log10(b)) otherwise
  193. The only macro we care about is this number for the widest supported
  194. floating type, but we want this value for rendering constants below. */
  195. {
  196. double d_decimal_dig
  197. = 1 + (fmt->p < ldfmt->p ? ldfmt->p : fmt->p) * log10_b;
  198. decimal_dig = d_decimal_dig;
  199. if (decimal_dig < d_decimal_dig)
  200. decimal_dig++;
  201. }
  202. /* Similar, for this type rather than long double. */
  203. {
  204. double type_d_decimal_dig = 1 + fmt->p * log10_b;
  205. type_decimal_dig = type_d_decimal_dig;
  206. if (type_decimal_dig < type_d_decimal_dig)
  207. type_decimal_dig++;
  208. }
  209. if (type == long_double_type_node)
  210. builtin_define_with_int_value ("__DECIMAL_DIG__", decimal_dig);
  211. else
  212. {
  213. sprintf (name, "__%s_DECIMAL_DIG__", name_prefix);
  214. builtin_define_with_int_value (name, type_decimal_dig);
  215. }
  216. /* Since, for the supported formats, B is always a power of 2, we
  217. construct the following numbers directly as a hexadecimal
  218. constants. */
  219. get_max_float (fmt, buf, sizeof (buf));
  220. sprintf (name, "__%s_MAX__", name_prefix);
  221. builtin_define_with_hex_fp_value (name, type, decimal_dig, buf, fp_suffix, fp_cast);
  222. /* The minimum normalized positive floating-point number,
  223. b**(emin-1). */
  224. sprintf (name, "__%s_MIN__", name_prefix);
  225. sprintf (buf, "0x1p%d", fmt->emin - 1);
  226. builtin_define_with_hex_fp_value (name, type, decimal_dig, buf, fp_suffix, fp_cast);
  227. /* The difference between 1 and the least value greater than 1 that is
  228. representable in the given floating point type, b**(1-p). */
  229. sprintf (name, "__%s_EPSILON__", name_prefix);
  230. if (fmt->pnan < fmt->p)
  231. /* This is an IBM extended double format, so 1.0 + any double is
  232. representable precisely. */
  233. sprintf (buf, "0x1p%d", fmt->emin - fmt->p);
  234. else
  235. sprintf (buf, "0x1p%d", 1 - fmt->p);
  236. builtin_define_with_hex_fp_value (name, type, decimal_dig, buf, fp_suffix, fp_cast);
  237. /* For C++ std::numeric_limits<T>::denorm_min and C11 *_TRUE_MIN.
  238. The minimum denormalized positive floating-point number, b**(emin-p).
  239. The minimum normalized positive floating-point number for formats
  240. that don't support denormals. */
  241. sprintf (name, "__%s_DENORM_MIN__", name_prefix);
  242. sprintf (buf, "0x1p%d", fmt->emin - (fmt->has_denorm ? fmt->p : 1));
  243. builtin_define_with_hex_fp_value (name, type, decimal_dig,
  244. buf, fp_suffix, fp_cast);
  245. sprintf (name, "__%s_HAS_DENORM__", name_prefix);
  246. builtin_define_with_value (name, fmt->has_denorm ? "1" : "0", 0);
  247. /* For C++ std::numeric_limits<T>::has_infinity. */
  248. sprintf (name, "__%s_HAS_INFINITY__", name_prefix);
  249. builtin_define_with_int_value (name,
  250. MODE_HAS_INFINITIES (TYPE_MODE (type)));
  251. /* For C++ std::numeric_limits<T>::has_quiet_NaN. We do not have a
  252. predicate to distinguish a target that has both quiet and
  253. signalling NaNs from a target that has only quiet NaNs or only
  254. signalling NaNs, so we assume that a target that has any kind of
  255. NaN has quiet NaNs. */
  256. sprintf (name, "__%s_HAS_QUIET_NAN__", name_prefix);
  257. builtin_define_with_int_value (name, MODE_HAS_NANS (TYPE_MODE (type)));
  258. /* Note whether we have fast FMA. */
  259. if (mode_has_fma (TYPE_MODE (type)))
  260. {
  261. sprintf (name, "__FP_FAST_FMA%s", fma_suffix);
  262. builtin_define_with_int_value (name, 1);
  263. }
  264. }
  265. /* Define __DECx__ constants for TYPE using NAME_PREFIX and SUFFIX. */
  266. static void
  267. builtin_define_decimal_float_constants (const char *name_prefix,
  268. const char *suffix,
  269. tree type)
  270. {
  271. const struct real_format *fmt;
  272. char name[64], buf[128], *p;
  273. int digits;
  274. fmt = REAL_MODE_FORMAT (TYPE_MODE (type));
  275. /* The number of radix digits, p, in the significand. */
  276. sprintf (name, "__%s_MANT_DIG__", name_prefix);
  277. builtin_define_with_int_value (name, fmt->p);
  278. /* The minimum negative int x such that b**(x-1) is a normalized float. */
  279. sprintf (name, "__%s_MIN_EXP__", name_prefix);
  280. sprintf (buf, "(%d)", fmt->emin);
  281. builtin_define_with_value (name, buf, 0);
  282. /* The maximum int x such that b**(x-1) is a representable float. */
  283. sprintf (name, "__%s_MAX_EXP__", name_prefix);
  284. builtin_define_with_int_value (name, fmt->emax);
  285. /* Compute the minimum representable value. */
  286. sprintf (name, "__%s_MIN__", name_prefix);
  287. sprintf (buf, "1E%d%s", fmt->emin - 1, suffix);
  288. builtin_define_with_value (name, buf, 0);
  289. /* Compute the maximum representable value. */
  290. sprintf (name, "__%s_MAX__", name_prefix);
  291. p = buf;
  292. for (digits = fmt->p; digits; digits--)
  293. {
  294. *p++ = '9';
  295. if (digits == fmt->p)
  296. *p++ = '.';
  297. }
  298. *p = 0;
  299. /* fmt->p plus 1, to account for the decimal point and fmt->emax
  300. minus 1 because the digits are nines, not 1.0. */
  301. sprintf (&buf[fmt->p + 1], "E%d%s", fmt->emax - 1, suffix);
  302. builtin_define_with_value (name, buf, 0);
  303. /* Compute epsilon (the difference between 1 and least value greater
  304. than 1 representable). */
  305. sprintf (name, "__%s_EPSILON__", name_prefix);
  306. sprintf (buf, "1E-%d%s", fmt->p - 1, suffix);
  307. builtin_define_with_value (name, buf, 0);
  308. /* Minimum subnormal positive decimal value. */
  309. sprintf (name, "__%s_SUBNORMAL_MIN__", name_prefix);
  310. p = buf;
  311. for (digits = fmt->p; digits > 1; digits--)
  312. {
  313. *p++ = '0';
  314. if (digits == fmt->p)
  315. *p++ = '.';
  316. }
  317. *p = 0;
  318. sprintf (&buf[fmt->p], "1E%d%s", fmt->emin - 1, suffix);
  319. builtin_define_with_value (name, buf, 0);
  320. }
  321. /* Define fixed-point constants for TYPE using NAME_PREFIX and SUFFIX. */
  322. static void
  323. builtin_define_fixed_point_constants (const char *name_prefix,
  324. const char *suffix,
  325. tree type)
  326. {
  327. char name[64], buf[256], *new_buf;
  328. int i, mod;
  329. sprintf (name, "__%s_FBIT__", name_prefix);
  330. builtin_define_with_int_value (name, TYPE_FBIT (type));
  331. sprintf (name, "__%s_IBIT__", name_prefix);
  332. builtin_define_with_int_value (name, TYPE_IBIT (type));
  333. /* If there is no suffix, defines are for fixed-point modes.
  334. We just return. */
  335. if (strcmp (suffix, "") == 0)
  336. return;
  337. if (TYPE_UNSIGNED (type))
  338. {
  339. sprintf (name, "__%s_MIN__", name_prefix);
  340. sprintf (buf, "0.0%s", suffix);
  341. builtin_define_with_value (name, buf, 0);
  342. }
  343. else
  344. {
  345. sprintf (name, "__%s_MIN__", name_prefix);
  346. if (ALL_ACCUM_MODE_P (TYPE_MODE (type)))
  347. sprintf (buf, "(-0X1P%d%s-0X1P%d%s)", TYPE_IBIT (type) - 1, suffix,
  348. TYPE_IBIT (type) - 1, suffix);
  349. else
  350. sprintf (buf, "(-0.5%s-0.5%s)", suffix, suffix);
  351. builtin_define_with_value (name, buf, 0);
  352. }
  353. sprintf (name, "__%s_MAX__", name_prefix);
  354. sprintf (buf, "0X");
  355. new_buf = buf + 2;
  356. mod = (TYPE_FBIT (type) + TYPE_IBIT (type)) % 4;
  357. if (mod)
  358. sprintf (new_buf++, "%x", (1 << mod) - 1);
  359. for (i = 0; i < (TYPE_FBIT (type) + TYPE_IBIT (type)) / 4; i++)
  360. sprintf (new_buf++, "F");
  361. sprintf (new_buf, "P-%d%s", TYPE_FBIT (type), suffix);
  362. builtin_define_with_value (name, buf, 0);
  363. sprintf (name, "__%s_EPSILON__", name_prefix);
  364. sprintf (buf, "0x1P-%d%s", TYPE_FBIT (type), suffix);
  365. builtin_define_with_value (name, buf, 0);
  366. }
  367. /* Define macros used by <stdint.h>. */
  368. static void
  369. builtin_define_stdint_macros (void)
  370. {
  371. builtin_define_type_max ("__INTMAX_MAX__", intmax_type_node);
  372. builtin_define_constants ("__INTMAX_C", intmax_type_node);
  373. builtin_define_type_max ("__UINTMAX_MAX__", uintmax_type_node);
  374. builtin_define_constants ("__UINTMAX_C", uintmax_type_node);
  375. if (sig_atomic_type_node)
  376. builtin_define_type_minmax ("__SIG_ATOMIC_MIN__", "__SIG_ATOMIC_MAX__",
  377. sig_atomic_type_node);
  378. if (int8_type_node)
  379. builtin_define_type_max ("__INT8_MAX__", int8_type_node);
  380. if (int16_type_node)
  381. builtin_define_type_max ("__INT16_MAX__", int16_type_node);
  382. if (int32_type_node)
  383. builtin_define_type_max ("__INT32_MAX__", int32_type_node);
  384. if (int64_type_node)
  385. builtin_define_type_max ("__INT64_MAX__", int64_type_node);
  386. if (uint8_type_node)
  387. builtin_define_type_max ("__UINT8_MAX__", uint8_type_node);
  388. if (c_uint16_type_node)
  389. builtin_define_type_max ("__UINT16_MAX__", c_uint16_type_node);
  390. if (c_uint32_type_node)
  391. builtin_define_type_max ("__UINT32_MAX__", c_uint32_type_node);
  392. if (c_uint64_type_node)
  393. builtin_define_type_max ("__UINT64_MAX__", c_uint64_type_node);
  394. if (int_least8_type_node)
  395. {
  396. builtin_define_type_max ("__INT_LEAST8_MAX__", int_least8_type_node);
  397. builtin_define_constants ("__INT8_C", int_least8_type_node);
  398. }
  399. if (int_least16_type_node)
  400. {
  401. builtin_define_type_max ("__INT_LEAST16_MAX__", int_least16_type_node);
  402. builtin_define_constants ("__INT16_C", int_least16_type_node);
  403. }
  404. if (int_least32_type_node)
  405. {
  406. builtin_define_type_max ("__INT_LEAST32_MAX__", int_least32_type_node);
  407. builtin_define_constants ("__INT32_C", int_least32_type_node);
  408. }
  409. if (int_least64_type_node)
  410. {
  411. builtin_define_type_max ("__INT_LEAST64_MAX__", int_least64_type_node);
  412. builtin_define_constants ("__INT64_C", int_least64_type_node);
  413. }
  414. if (uint_least8_type_node)
  415. {
  416. builtin_define_type_max ("__UINT_LEAST8_MAX__", uint_least8_type_node);
  417. builtin_define_constants ("__UINT8_C", uint_least8_type_node);
  418. }
  419. if (uint_least16_type_node)
  420. {
  421. builtin_define_type_max ("__UINT_LEAST16_MAX__", uint_least16_type_node);
  422. builtin_define_constants ("__UINT16_C", uint_least16_type_node);
  423. }
  424. if (uint_least32_type_node)
  425. {
  426. builtin_define_type_max ("__UINT_LEAST32_MAX__", uint_least32_type_node);
  427. builtin_define_constants ("__UINT32_C", uint_least32_type_node);
  428. }
  429. if (uint_least64_type_node)
  430. {
  431. builtin_define_type_max ("__UINT_LEAST64_MAX__", uint_least64_type_node);
  432. builtin_define_constants ("__UINT64_C", uint_least64_type_node);
  433. }
  434. if (int_fast8_type_node)
  435. builtin_define_type_max ("__INT_FAST8_MAX__", int_fast8_type_node);
  436. if (int_fast16_type_node)
  437. builtin_define_type_max ("__INT_FAST16_MAX__", int_fast16_type_node);
  438. if (int_fast32_type_node)
  439. builtin_define_type_max ("__INT_FAST32_MAX__", int_fast32_type_node);
  440. if (int_fast64_type_node)
  441. builtin_define_type_max ("__INT_FAST64_MAX__", int_fast64_type_node);
  442. if (uint_fast8_type_node)
  443. builtin_define_type_max ("__UINT_FAST8_MAX__", uint_fast8_type_node);
  444. if (uint_fast16_type_node)
  445. builtin_define_type_max ("__UINT_FAST16_MAX__", uint_fast16_type_node);
  446. if (uint_fast32_type_node)
  447. builtin_define_type_max ("__UINT_FAST32_MAX__", uint_fast32_type_node);
  448. if (uint_fast64_type_node)
  449. builtin_define_type_max ("__UINT_FAST64_MAX__", uint_fast64_type_node);
  450. if (intptr_type_node)
  451. builtin_define_type_max ("__INTPTR_MAX__", intptr_type_node);
  452. if (uintptr_type_node)
  453. builtin_define_type_max ("__UINTPTR_MAX__", uintptr_type_node);
  454. }
  455. /* Adjust the optimization macros when a #pragma GCC optimization is done to
  456. reflect the current level. */
  457. void
  458. c_cpp_builtins_optimize_pragma (cpp_reader *pfile, tree prev_tree,
  459. tree cur_tree)
  460. {
  461. struct cl_optimization *prev = TREE_OPTIMIZATION (prev_tree);
  462. struct cl_optimization *cur = TREE_OPTIMIZATION (cur_tree);
  463. bool prev_fast_math;
  464. bool cur_fast_math;
  465. /* -undef turns off target-specific built-ins. */
  466. if (flag_undef)
  467. return;
  468. /* Other target-independent built-ins determined by command-line
  469. options. */
  470. if (!prev->x_optimize_size && cur->x_optimize_size)
  471. cpp_define (pfile, "__OPTIMIZE_SIZE__");
  472. else if (prev->x_optimize_size && !cur->x_optimize_size)
  473. cpp_undef (pfile, "__OPTIMIZE_SIZE__");
  474. if (!prev->x_optimize && cur->x_optimize)
  475. cpp_define (pfile, "__OPTIMIZE__");
  476. else if (prev->x_optimize && !cur->x_optimize)
  477. cpp_undef (pfile, "__OPTIMIZE__");
  478. prev_fast_math = fast_math_flags_struct_set_p (prev);
  479. cur_fast_math = fast_math_flags_struct_set_p (cur);
  480. if (!prev_fast_math && cur_fast_math)
  481. cpp_define (pfile, "__FAST_MATH__");
  482. else if (prev_fast_math && !cur_fast_math)
  483. cpp_undef (pfile, "__FAST_MATH__");
  484. if (!prev->x_flag_signaling_nans && cur->x_flag_signaling_nans)
  485. cpp_define (pfile, "__SUPPORT_SNAN__");
  486. else if (prev->x_flag_signaling_nans && !cur->x_flag_signaling_nans)
  487. cpp_undef (pfile, "__SUPPORT_SNAN__");
  488. if (!prev->x_flag_errno_math && cur->x_flag_errno_math)
  489. cpp_undef (pfile, "__NO_MATH_ERRNO__");
  490. else if (prev->x_flag_errno_math && !cur->x_flag_errno_math)
  491. cpp_define (pfile, "__NO_MATH_ERRNO__");
  492. if (!prev->x_flag_finite_math_only && cur->x_flag_finite_math_only)
  493. {
  494. cpp_undef (pfile, "__FINITE_MATH_ONLY__");
  495. cpp_define (pfile, "__FINITE_MATH_ONLY__=1");
  496. }
  497. else if (prev->x_flag_finite_math_only && !cur->x_flag_finite_math_only)
  498. {
  499. cpp_undef (pfile, "__FINITE_MATH_ONLY__");
  500. cpp_define (pfile, "__FINITE_MATH_ONLY__=0");
  501. }
  502. }
  503. /* This function will emit cpp macros to indicate the presence of various lock
  504. free atomic operations. */
  505. static void
  506. cpp_atomic_builtins (cpp_reader *pfile)
  507. {
  508. /* Set a flag for each size of object that compare and swap exists for up to
  509. a 16 byte object. */
  510. #define SWAP_LIMIT 17
  511. bool have_swap[SWAP_LIMIT];
  512. unsigned int psize;
  513. /* Clear the map of sizes compare_and swap exists for. */
  514. memset (have_swap, 0, sizeof (have_swap));
  515. /* Tell source code if the compiler makes sync_compare_and_swap
  516. builtins available. */
  517. #ifndef HAVE_sync_compare_and_swapqi
  518. #define HAVE_sync_compare_and_swapqi 0
  519. #endif
  520. #ifndef HAVE_atomic_compare_and_swapqi
  521. #define HAVE_atomic_compare_and_swapqi 0
  522. #endif
  523. if (HAVE_sync_compare_and_swapqi || HAVE_atomic_compare_and_swapqi)
  524. {
  525. cpp_define (pfile, "__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
  526. have_swap[1] = true;
  527. }
  528. #ifndef HAVE_sync_compare_and_swaphi
  529. #define HAVE_sync_compare_and_swaphi 0
  530. #endif
  531. #ifndef HAVE_atomic_compare_and_swaphi
  532. #define HAVE_atomic_compare_and_swaphi 0
  533. #endif
  534. if (HAVE_sync_compare_and_swaphi || HAVE_atomic_compare_and_swaphi)
  535. {
  536. cpp_define (pfile, "__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
  537. have_swap[2] = true;
  538. }
  539. #ifndef HAVE_sync_compare_and_swapsi
  540. #define HAVE_sync_compare_and_swapsi 0
  541. #endif
  542. #ifndef HAVE_atomic_compare_and_swapsi
  543. #define HAVE_atomic_compare_and_swapsi 0
  544. #endif
  545. if (HAVE_sync_compare_and_swapsi || HAVE_atomic_compare_and_swapsi)
  546. {
  547. cpp_define (pfile, "__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
  548. have_swap[4] = true;
  549. }
  550. #ifndef HAVE_sync_compare_and_swapdi
  551. #define HAVE_sync_compare_and_swapdi 0
  552. #endif
  553. #ifndef HAVE_atomic_compare_and_swapdi
  554. #define HAVE_atomic_compare_and_swapdi 0
  555. #endif
  556. if (HAVE_sync_compare_and_swapdi || HAVE_atomic_compare_and_swapdi)
  557. {
  558. cpp_define (pfile, "__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
  559. have_swap[8] = true;
  560. }
  561. #ifndef HAVE_sync_compare_and_swapti
  562. #define HAVE_sync_compare_and_swapti 0
  563. #endif
  564. #ifndef HAVE_atomic_compare_and_swapti
  565. #define HAVE_atomic_compare_and_swapti 0
  566. #endif
  567. if (HAVE_sync_compare_and_swapti || HAVE_atomic_compare_and_swapti)
  568. {
  569. cpp_define (pfile, "__GCC_HAVE_SYNC_COMPARE_AND_SWAP_16");
  570. have_swap[16] = true;
  571. }
  572. /* Tell the source code about various types. These map to the C++11 and C11
  573. macros where 2 indicates lock-free always, and 1 indicates sometimes
  574. lock free. */
  575. #define SIZEOF_NODE(T) (tree_to_uhwi (TYPE_SIZE_UNIT (T)))
  576. #define SWAP_INDEX(T) ((SIZEOF_NODE (T) < SWAP_LIMIT) ? SIZEOF_NODE (T) : 0)
  577. builtin_define_with_int_value ("__GCC_ATOMIC_BOOL_LOCK_FREE",
  578. (have_swap[SWAP_INDEX (boolean_type_node)]? 2 : 1));
  579. builtin_define_with_int_value ("__GCC_ATOMIC_CHAR_LOCK_FREE",
  580. (have_swap[SWAP_INDEX (signed_char_type_node)]? 2 : 1));
  581. builtin_define_with_int_value ("__GCC_ATOMIC_CHAR16_T_LOCK_FREE",
  582. (have_swap[SWAP_INDEX (char16_type_node)]? 2 : 1));
  583. builtin_define_with_int_value ("__GCC_ATOMIC_CHAR32_T_LOCK_FREE",
  584. (have_swap[SWAP_INDEX (char32_type_node)]? 2 : 1));
  585. builtin_define_with_int_value ("__GCC_ATOMIC_WCHAR_T_LOCK_FREE",
  586. (have_swap[SWAP_INDEX (wchar_type_node)]? 2 : 1));
  587. builtin_define_with_int_value ("__GCC_ATOMIC_SHORT_LOCK_FREE",
  588. (have_swap[SWAP_INDEX (short_integer_type_node)]? 2 : 1));
  589. builtin_define_with_int_value ("__GCC_ATOMIC_INT_LOCK_FREE",
  590. (have_swap[SWAP_INDEX (integer_type_node)]? 2 : 1));
  591. builtin_define_with_int_value ("__GCC_ATOMIC_LONG_LOCK_FREE",
  592. (have_swap[SWAP_INDEX (long_integer_type_node)]? 2 : 1));
  593. builtin_define_with_int_value ("__GCC_ATOMIC_LLONG_LOCK_FREE",
  594. (have_swap[SWAP_INDEX (long_long_integer_type_node)]? 2 : 1));
  595. /* If we're dealing with a "set" value that doesn't exactly correspond
  596. to a boolean truth value, let the library work around that. */
  597. builtin_define_with_int_value ("__GCC_ATOMIC_TEST_AND_SET_TRUEVAL",
  598. targetm.atomic_test_and_set_trueval);
  599. /* ptr_type_node can't be used here since ptr_mode is only set when
  600. toplev calls backend_init which is not done with -E or pch. */
  601. psize = POINTER_SIZE_UNITS;
  602. if (psize >= SWAP_LIMIT)
  603. psize = 0;
  604. builtin_define_with_int_value ("__GCC_ATOMIC_POINTER_LOCK_FREE",
  605. (have_swap[psize]? 2 : 1));
  606. }
  607. /* Return the value for __GCC_IEC_559. */
  608. static int
  609. cpp_iec_559_value (void)
  610. {
  611. /* The default is support for IEEE 754-2008. */
  612. int ret = 2;
  613. /* float and double must be binary32 and binary64. If they are but
  614. with reversed NaN convention, at most IEEE 754-1985 is
  615. supported. */
  616. const struct real_format *ffmt
  617. = REAL_MODE_FORMAT (TYPE_MODE (float_type_node));
  618. const struct real_format *dfmt
  619. = REAL_MODE_FORMAT (TYPE_MODE (double_type_node));
  620. if (!ffmt->qnan_msb_set || !dfmt->qnan_msb_set)
  621. ret = 1;
  622. if (ffmt->b != 2
  623. || ffmt->p != 24
  624. || ffmt->pnan != 24
  625. || ffmt->emin != -125
  626. || ffmt->emax != 128
  627. || ffmt->signbit_rw != 31
  628. || ffmt->round_towards_zero
  629. || !ffmt->has_sign_dependent_rounding
  630. || !ffmt->has_nans
  631. || !ffmt->has_inf
  632. || !ffmt->has_denorm
  633. || !ffmt->has_signed_zero
  634. || dfmt->b != 2
  635. || dfmt->p != 53
  636. || dfmt->pnan != 53
  637. || dfmt->emin != -1021
  638. || dfmt->emax != 1024
  639. || dfmt->signbit_rw != 63
  640. || dfmt->round_towards_zero
  641. || !dfmt->has_sign_dependent_rounding
  642. || !dfmt->has_nans
  643. || !dfmt->has_inf
  644. || !dfmt->has_denorm
  645. || !dfmt->has_signed_zero)
  646. ret = 0;
  647. /* In strict C standards conformance mode, consider unpredictable
  648. excess precision to mean lack of IEEE 754 support. The same
  649. applies to unpredictable contraction. For C++, and outside
  650. strict conformance mode, do not consider these options to mean
  651. lack of IEEE 754 support. */
  652. if (flag_iso
  653. && !c_dialect_cxx ()
  654. && TARGET_FLT_EVAL_METHOD != 0
  655. && flag_excess_precision_cmdline != EXCESS_PRECISION_STANDARD)
  656. ret = 0;
  657. if (flag_iso
  658. && !c_dialect_cxx ()
  659. && flag_fp_contract_mode == FP_CONTRACT_FAST)
  660. ret = 0;
  661. /* Various options are contrary to IEEE 754 semantics. */
  662. if (flag_unsafe_math_optimizations
  663. || flag_associative_math
  664. || flag_reciprocal_math
  665. || flag_finite_math_only
  666. || !flag_signed_zeros
  667. || flag_single_precision_constant)
  668. ret = 0;
  669. /* If the target does not support IEEE 754 exceptions and rounding
  670. modes, consider IEEE 754 support to be absent. */
  671. if (!targetm.float_exceptions_rounding_supported_p ())
  672. ret = 0;
  673. return ret;
  674. }
  675. /* Return the value for __GCC_IEC_559_COMPLEX. */
  676. static int
  677. cpp_iec_559_complex_value (void)
  678. {
  679. /* The value is no bigger than that of __GCC_IEC_559. */
  680. int ret = cpp_iec_559_value ();
  681. /* Some options are contrary to the required default state of the
  682. CX_LIMITED_RANGE pragma. */
  683. if (flag_complex_method != 2)
  684. ret = 0;
  685. return ret;
  686. }
  687. /* Hook that registers front end and target-specific built-ins. */
  688. void
  689. c_cpp_builtins (cpp_reader *pfile)
  690. {
  691. int i;
  692. /* -undef turns off target-specific built-ins. */
  693. if (flag_undef)
  694. return;
  695. define_language_independent_builtin_macros (pfile);
  696. if (c_dialect_cxx ())
  697. {
  698. int major;
  699. parse_basever (&major, NULL, NULL);
  700. cpp_define_formatted (pfile, "__GNUG__=%d", major);
  701. }
  702. /* For stddef.h. They require macros defined in c-common.c. */
  703. c_stddef_cpp_builtins ();
  704. /* Set include test macros for all C/C++ (not for just C++11 etc.)
  705. The builtins __has_include__ and __has_include_next__ are defined
  706. in libcpp. */
  707. cpp_define (pfile, "__has_include(STR)=__has_include__(STR)");
  708. cpp_define (pfile, "__has_include_next(STR)=__has_include_next__(STR)");
  709. if (c_dialect_cxx ())
  710. {
  711. if (flag_weak && SUPPORTS_ONE_ONLY)
  712. cpp_define (pfile, "__GXX_WEAK__=1");
  713. else
  714. cpp_define (pfile, "__GXX_WEAK__=0");
  715. if (warn_deprecated)
  716. cpp_define (pfile, "__DEPRECATED");
  717. if (flag_rtti)
  718. {
  719. cpp_define (pfile, "__GXX_RTTI");
  720. cpp_define (pfile, "__cpp_rtti=199711");
  721. }
  722. if (cxx_dialect >= cxx11)
  723. cpp_define (pfile, "__GXX_EXPERIMENTAL_CXX0X__");
  724. /* Binary literals have been allowed in g++ before C++11
  725. and were standardized for C++14. */
  726. if (!pedantic || cxx_dialect > cxx11)
  727. cpp_define (pfile, "__cpp_binary_literals=201304");
  728. /* Arrays of runtime bound were removed from C++14, but we still
  729. support GNU VLAs. Let's define this macro to a low number
  730. (corresponding to the initial test release of GNU C++) if we won't
  731. complain about use of VLAs. */
  732. if (c_dialect_cxx ()
  733. && (pedantic ? warn_vla == 0 : warn_vla <= 0))
  734. cpp_define (pfile, "__cpp_runtime_arrays=198712");
  735. if (cxx_dialect >= cxx11)
  736. {
  737. /* Set feature test macros for C++11 */
  738. cpp_define (pfile, "__cpp_unicode_characters=200704");
  739. cpp_define (pfile, "__cpp_raw_strings=200710");
  740. cpp_define (pfile, "__cpp_unicode_literals=200710");
  741. cpp_define (pfile, "__cpp_user_defined_literals=200809");
  742. cpp_define (pfile, "__cpp_lambdas=200907");
  743. if (cxx_dialect == cxx11)
  744. cpp_define (pfile, "__cpp_constexpr=200704");
  745. cpp_define (pfile, "__cpp_range_based_for=200907");
  746. cpp_define (pfile, "__cpp_static_assert=200410");
  747. cpp_define (pfile, "__cpp_decltype=200707");
  748. cpp_define (pfile, "__cpp_attributes=200809");
  749. cpp_define (pfile, "__cpp_rvalue_reference=200610");
  750. cpp_define (pfile, "__cpp_variadic_templates=200704");
  751. cpp_define (pfile, "__cpp_initializer_lists=200806");
  752. cpp_define (pfile, "__cpp_delegating_constructors=200604");
  753. cpp_define (pfile, "__cpp_nsdmi=200809");
  754. cpp_define (pfile, "__cpp_inheriting_constructors=200802");
  755. cpp_define (pfile, "__cpp_ref_qualifiers=200710");
  756. cpp_define (pfile, "__cpp_alias_templates=200704");
  757. }
  758. if (cxx_dialect > cxx11)
  759. {
  760. /* Set feature test macros for C++14 */
  761. cpp_define (pfile, "__cpp_return_type_deduction=201304");
  762. cpp_define (pfile, "__cpp_init_captures=201304");
  763. cpp_define (pfile, "__cpp_generic_lambdas=201304");
  764. cpp_define (pfile, "__cpp_constexpr=201304");
  765. cpp_define (pfile, "__cpp_decltype_auto=201304");
  766. cpp_define (pfile, "__cpp_aggregate_nsdmi=201304");
  767. cpp_define (pfile, "__cpp_variable_templates=201304");
  768. cpp_define (pfile, "__cpp_digit_separators=201309");
  769. }
  770. if (flag_sized_deallocation)
  771. cpp_define (pfile, "__cpp_sized_deallocation=201309");
  772. }
  773. /* Note that we define this for C as well, so that we know if
  774. __attribute__((cleanup)) will interface with EH. */
  775. if (flag_exceptions)
  776. {
  777. cpp_define (pfile, "__EXCEPTIONS");
  778. if (c_dialect_cxx ())
  779. cpp_define (pfile, "__cpp_exceptions=199711");
  780. }
  781. /* Represents the C++ ABI version, always defined so it can be used while
  782. preprocessing C and assembler. */
  783. if (flag_abi_version == 0)
  784. /* We should have set this to something real in c_common_post_options. */
  785. gcc_unreachable ();
  786. else if (flag_abi_version == 1)
  787. /* Due to a historical accident, this version had the value
  788. "102". */
  789. builtin_define_with_int_value ("__GXX_ABI_VERSION", 102);
  790. else
  791. /* Newer versions have values 1002, 1003, .... */
  792. builtin_define_with_int_value ("__GXX_ABI_VERSION",
  793. 1000 + flag_abi_version);
  794. /* libgcc needs to know this. */
  795. if (targetm_common.except_unwind_info (&global_options) == UI_SJLJ)
  796. cpp_define (pfile, "__USING_SJLJ_EXCEPTIONS__");
  797. /* limits.h and stdint.h need to know these. */
  798. builtin_define_type_max ("__SCHAR_MAX__", signed_char_type_node);
  799. builtin_define_type_max ("__SHRT_MAX__", short_integer_type_node);
  800. builtin_define_type_max ("__INT_MAX__", integer_type_node);
  801. builtin_define_type_max ("__LONG_MAX__", long_integer_type_node);
  802. builtin_define_type_max ("__LONG_LONG_MAX__", long_long_integer_type_node);
  803. builtin_define_type_minmax ("__WCHAR_MIN__", "__WCHAR_MAX__",
  804. underlying_wchar_type_node);
  805. builtin_define_type_minmax ("__WINT_MIN__", "__WINT_MAX__", wint_type_node);
  806. builtin_define_type_max ("__PTRDIFF_MAX__", ptrdiff_type_node);
  807. builtin_define_type_max ("__SIZE_MAX__", size_type_node);
  808. if (c_dialect_cxx ())
  809. for (i = 0; i < NUM_INT_N_ENTS; i ++)
  810. if (int_n_enabled_p[i])
  811. {
  812. char buf[35+20+20];
  813. /* These are used to configure the C++ library. */
  814. if (!flag_iso || int_n_data[i].bitsize == POINTER_SIZE)
  815. {
  816. sprintf (buf, "__GLIBCXX_TYPE_INT_N_%d=__int%d", i, int_n_data[i].bitsize);
  817. cpp_define (parse_in, buf);
  818. sprintf (buf, "__GLIBCXX_BITSIZE_INT_N_%d=%d", i, int_n_data[i].bitsize);
  819. cpp_define (parse_in, buf);
  820. }
  821. }
  822. /* stdint.h and the testsuite need to know these. */
  823. builtin_define_stdint_macros ();
  824. /* Provide information for library headers to determine whether to
  825. define macros such as __STDC_IEC_559__ and
  826. __STDC_IEC_559_COMPLEX__. */
  827. builtin_define_with_int_value ("__GCC_IEC_559", cpp_iec_559_value ());
  828. builtin_define_with_int_value ("__GCC_IEC_559_COMPLEX",
  829. cpp_iec_559_complex_value ());
  830. /* float.h needs to know this. */
  831. builtin_define_with_int_value ("__FLT_EVAL_METHOD__",
  832. TARGET_FLT_EVAL_METHOD);
  833. /* And decfloat.h needs this. */
  834. builtin_define_with_int_value ("__DEC_EVAL_METHOD__",
  835. TARGET_DEC_EVAL_METHOD);
  836. builtin_define_float_constants ("FLT", "F", "%s", "F", float_type_node);
  837. /* Cast the double precision constants. This is needed when single
  838. precision constants are specified or when pragma FLOAT_CONST_DECIMAL64
  839. is used. The correct result is computed by the compiler when using
  840. macros that include a cast. We use a different cast for C++ to avoid
  841. problems with -Wold-style-cast. */
  842. builtin_define_float_constants ("DBL", "L",
  843. (c_dialect_cxx ()
  844. ? "double(%s)"
  845. : "((double)%s)"),
  846. "", double_type_node);
  847. builtin_define_float_constants ("LDBL", "L", "%s", "L",
  848. long_double_type_node);
  849. /* For decfloat.h. */
  850. builtin_define_decimal_float_constants ("DEC32", "DF", dfloat32_type_node);
  851. builtin_define_decimal_float_constants ("DEC64", "DD", dfloat64_type_node);
  852. builtin_define_decimal_float_constants ("DEC128", "DL", dfloat128_type_node);
  853. /* For fixed-point fibt, ibit, max, min, and epsilon. */
  854. if (targetm.fixed_point_supported_p ())
  855. {
  856. builtin_define_fixed_point_constants ("SFRACT", "HR",
  857. short_fract_type_node);
  858. builtin_define_fixed_point_constants ("USFRACT", "UHR",
  859. unsigned_short_fract_type_node);
  860. builtin_define_fixed_point_constants ("FRACT", "R",
  861. fract_type_node);
  862. builtin_define_fixed_point_constants ("UFRACT", "UR",
  863. unsigned_fract_type_node);
  864. builtin_define_fixed_point_constants ("LFRACT", "LR",
  865. long_fract_type_node);
  866. builtin_define_fixed_point_constants ("ULFRACT", "ULR",
  867. unsigned_long_fract_type_node);
  868. builtin_define_fixed_point_constants ("LLFRACT", "LLR",
  869. long_long_fract_type_node);
  870. builtin_define_fixed_point_constants ("ULLFRACT", "ULLR",
  871. unsigned_long_long_fract_type_node);
  872. builtin_define_fixed_point_constants ("SACCUM", "HK",
  873. short_accum_type_node);
  874. builtin_define_fixed_point_constants ("USACCUM", "UHK",
  875. unsigned_short_accum_type_node);
  876. builtin_define_fixed_point_constants ("ACCUM", "K",
  877. accum_type_node);
  878. builtin_define_fixed_point_constants ("UACCUM", "UK",
  879. unsigned_accum_type_node);
  880. builtin_define_fixed_point_constants ("LACCUM", "LK",
  881. long_accum_type_node);
  882. builtin_define_fixed_point_constants ("ULACCUM", "ULK",
  883. unsigned_long_accum_type_node);
  884. builtin_define_fixed_point_constants ("LLACCUM", "LLK",
  885. long_long_accum_type_node);
  886. builtin_define_fixed_point_constants ("ULLACCUM", "ULLK",
  887. unsigned_long_long_accum_type_node);
  888. builtin_define_fixed_point_constants ("QQ", "", qq_type_node);
  889. builtin_define_fixed_point_constants ("HQ", "", hq_type_node);
  890. builtin_define_fixed_point_constants ("SQ", "", sq_type_node);
  891. builtin_define_fixed_point_constants ("DQ", "", dq_type_node);
  892. builtin_define_fixed_point_constants ("TQ", "", tq_type_node);
  893. builtin_define_fixed_point_constants ("UQQ", "", uqq_type_node);
  894. builtin_define_fixed_point_constants ("UHQ", "", uhq_type_node);
  895. builtin_define_fixed_point_constants ("USQ", "", usq_type_node);
  896. builtin_define_fixed_point_constants ("UDQ", "", udq_type_node);
  897. builtin_define_fixed_point_constants ("UTQ", "", utq_type_node);
  898. builtin_define_fixed_point_constants ("HA", "", ha_type_node);
  899. builtin_define_fixed_point_constants ("SA", "", sa_type_node);
  900. builtin_define_fixed_point_constants ("DA", "", da_type_node);
  901. builtin_define_fixed_point_constants ("TA", "", ta_type_node);
  902. builtin_define_fixed_point_constants ("UHA", "", uha_type_node);
  903. builtin_define_fixed_point_constants ("USA", "", usa_type_node);
  904. builtin_define_fixed_point_constants ("UDA", "", uda_type_node);
  905. builtin_define_fixed_point_constants ("UTA", "", uta_type_node);
  906. }
  907. /* For libgcc-internal use only. */
  908. if (flag_building_libgcc)
  909. {
  910. /* Properties of floating-point modes for libgcc2.c. */
  911. for (machine_mode mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT);
  912. mode != VOIDmode;
  913. mode = GET_MODE_WIDER_MODE (mode))
  914. {
  915. const char *name = GET_MODE_NAME (mode);
  916. char *macro_name
  917. = (char *) alloca (strlen (name)
  918. + sizeof ("__LIBGCC__MANT_DIG__"));
  919. sprintf (macro_name, "__LIBGCC_%s_MANT_DIG__", name);
  920. builtin_define_with_int_value (macro_name,
  921. REAL_MODE_FORMAT (mode)->p);
  922. if (!targetm.scalar_mode_supported_p (mode)
  923. || !targetm.libgcc_floating_mode_supported_p (mode))
  924. continue;
  925. macro_name = (char *) alloca (strlen (name)
  926. + sizeof ("__LIBGCC_HAS__MODE__"));
  927. sprintf (macro_name, "__LIBGCC_HAS_%s_MODE__", name);
  928. cpp_define (pfile, macro_name);
  929. macro_name = (char *) alloca (strlen (name)
  930. + sizeof ("__LIBGCC__FUNC_EXT__"));
  931. sprintf (macro_name, "__LIBGCC_%s_FUNC_EXT__", name);
  932. const char *suffix;
  933. if (mode == TYPE_MODE (double_type_node))
  934. suffix = "";
  935. else if (mode == TYPE_MODE (float_type_node))
  936. suffix = "f";
  937. else if (mode == TYPE_MODE (long_double_type_node))
  938. suffix = "l";
  939. /* ??? The following assumes the built-in functions (defined
  940. in target-specific code) match the suffixes used for
  941. constants. Because in fact such functions are not
  942. defined for the 'w' suffix, 'l' is used there
  943. instead. */
  944. else if (mode == targetm.c.mode_for_suffix ('q'))
  945. suffix = "q";
  946. else if (mode == targetm.c.mode_for_suffix ('w'))
  947. suffix = "l";
  948. else
  949. gcc_unreachable ();
  950. builtin_define_with_value (macro_name, suffix, 0);
  951. bool excess_precision = false;
  952. if (TARGET_FLT_EVAL_METHOD != 0
  953. && mode != TYPE_MODE (long_double_type_node)
  954. && (mode == TYPE_MODE (float_type_node)
  955. || mode == TYPE_MODE (double_type_node)))
  956. switch (TARGET_FLT_EVAL_METHOD)
  957. {
  958. case -1:
  959. case 2:
  960. excess_precision = true;
  961. break;
  962. case 1:
  963. excess_precision = mode == TYPE_MODE (float_type_node);
  964. break;
  965. default:
  966. gcc_unreachable ();
  967. }
  968. macro_name = (char *) alloca (strlen (name)
  969. + sizeof ("__LIBGCC__EXCESS_"
  970. "PRECISION__"));
  971. sprintf (macro_name, "__LIBGCC_%s_EXCESS_PRECISION__", name);
  972. builtin_define_with_int_value (macro_name, excess_precision);
  973. }
  974. /* For libgcc crtstuff.c and libgcc2.c. */
  975. builtin_define_with_int_value ("__LIBGCC_EH_TABLES_CAN_BE_READ_ONLY__",
  976. EH_TABLES_CAN_BE_READ_ONLY);
  977. #ifdef EH_FRAME_SECTION_NAME
  978. builtin_define_with_value ("__LIBGCC_EH_FRAME_SECTION_NAME__",
  979. EH_FRAME_SECTION_NAME, 1);
  980. #endif
  981. #ifdef JCR_SECTION_NAME
  982. builtin_define_with_value ("__LIBGCC_JCR_SECTION_NAME__",
  983. JCR_SECTION_NAME, 1);
  984. #endif
  985. #ifdef CTORS_SECTION_ASM_OP
  986. builtin_define_with_value ("__LIBGCC_CTORS_SECTION_ASM_OP__",
  987. CTORS_SECTION_ASM_OP, 1);
  988. #endif
  989. #ifdef DTORS_SECTION_ASM_OP
  990. builtin_define_with_value ("__LIBGCC_DTORS_SECTION_ASM_OP__",
  991. DTORS_SECTION_ASM_OP, 1);
  992. #endif
  993. #ifdef TEXT_SECTION_ASM_OP
  994. builtin_define_with_value ("__LIBGCC_TEXT_SECTION_ASM_OP__",
  995. TEXT_SECTION_ASM_OP, 1);
  996. #endif
  997. #ifdef INIT_SECTION_ASM_OP
  998. builtin_define_with_value ("__LIBGCC_INIT_SECTION_ASM_OP__",
  999. INIT_SECTION_ASM_OP, 1);
  1000. #endif
  1001. #ifdef INIT_ARRAY_SECTION_ASM_OP
  1002. /* Despite the name of this target macro, the expansion is not
  1003. actually used, and may be empty rather than a string
  1004. constant. */
  1005. cpp_define (pfile, "__LIBGCC_INIT_ARRAY_SECTION_ASM_OP__");
  1006. #endif
  1007. /* For libgcc enable-execute-stack.c. */
  1008. builtin_define_with_int_value ("__LIBGCC_TRAMPOLINE_SIZE__",
  1009. TRAMPOLINE_SIZE);
  1010. /* For libgcc generic-morestack.c and unwinder code. */
  1011. #ifdef STACK_GROWS_DOWNWARD
  1012. cpp_define (pfile, "__LIBGCC_STACK_GROWS_DOWNWARD__");
  1013. #endif
  1014. /* For libgcc unwinder code. */
  1015. #ifdef DONT_USE_BUILTIN_SETJMP
  1016. cpp_define (pfile, "__LIBGCC_DONT_USE_BUILTIN_SETJMP__");
  1017. #endif
  1018. #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
  1019. builtin_define_with_int_value ("__LIBGCC_DWARF_ALT_FRAME_RETURN_COLUMN__",
  1020. DWARF_ALT_FRAME_RETURN_COLUMN);
  1021. #endif
  1022. builtin_define_with_int_value ("__LIBGCC_DWARF_FRAME_REGISTERS__",
  1023. DWARF_FRAME_REGISTERS);
  1024. #ifdef EH_RETURN_STACKADJ_RTX
  1025. cpp_define (pfile, "__LIBGCC_EH_RETURN_STACKADJ_RTX__");
  1026. #endif
  1027. #ifdef JMP_BUF_SIZE
  1028. builtin_define_with_int_value ("__LIBGCC_JMP_BUF_SIZE__",
  1029. JMP_BUF_SIZE);
  1030. #endif
  1031. builtin_define_with_int_value ("__LIBGCC_STACK_POINTER_REGNUM__",
  1032. STACK_POINTER_REGNUM);
  1033. /* For libgcov. */
  1034. builtin_define_with_int_value ("__LIBGCC_VTABLE_USES_DESCRIPTORS__",
  1035. TARGET_VTABLE_USES_DESCRIPTORS);
  1036. }
  1037. /* For use in assembly language. */
  1038. builtin_define_with_value ("__REGISTER_PREFIX__", REGISTER_PREFIX, 0);
  1039. builtin_define_with_value ("__USER_LABEL_PREFIX__", user_label_prefix, 0);
  1040. /* Misc. */
  1041. if (flag_gnu89_inline)
  1042. cpp_define (pfile, "__GNUC_GNU_INLINE__");
  1043. else
  1044. cpp_define (pfile, "__GNUC_STDC_INLINE__");
  1045. if (flag_no_inline)
  1046. cpp_define (pfile, "__NO_INLINE__");
  1047. if (flag_iso)
  1048. cpp_define (pfile, "__STRICT_ANSI__");
  1049. if (!flag_signed_char)
  1050. cpp_define (pfile, "__CHAR_UNSIGNED__");
  1051. if (c_dialect_cxx () && TYPE_UNSIGNED (wchar_type_node))
  1052. cpp_define (pfile, "__WCHAR_UNSIGNED__");
  1053. cpp_atomic_builtins (pfile);
  1054. #ifdef DWARF2_UNWIND_INFO
  1055. if (dwarf2out_do_cfi_asm ())
  1056. cpp_define (pfile, "__GCC_HAVE_DWARF2_CFI_ASM");
  1057. #endif
  1058. /* Make the choice of ObjC runtime visible to source code. */
  1059. if (c_dialect_objc () && flag_next_runtime)
  1060. cpp_define (pfile, "__NEXT_RUNTIME__");
  1061. /* Show the availability of some target pragmas. */
  1062. cpp_define (pfile, "__PRAGMA_REDEFINE_EXTNAME");
  1063. /* Make the choice of the stack protector runtime visible to source code.
  1064. The macro names and values here were chosen for compatibility with an
  1065. earlier implementation, i.e. ProPolice. */
  1066. if (flag_stack_protect == 4)
  1067. cpp_define (pfile, "__SSP_EXPLICIT__=4");
  1068. if (flag_stack_protect == 3)
  1069. cpp_define (pfile, "__SSP_STRONG__=3");
  1070. if (flag_stack_protect == 2)
  1071. cpp_define (pfile, "__SSP_ALL__=2");
  1072. else if (flag_stack_protect == 1)
  1073. cpp_define (pfile, "__SSP__=1");
  1074. if (flag_openacc)
  1075. cpp_define (pfile, "_OPENACC=201306");
  1076. if (flag_openmp)
  1077. cpp_define (pfile, "_OPENMP=201307");
  1078. for (i = 0; i < NUM_INT_N_ENTS; i ++)
  1079. if (int_n_enabled_p[i])
  1080. {
  1081. char buf[15+20];
  1082. sprintf(buf, "__SIZEOF_INT%d__", int_n_data[i].bitsize);
  1083. builtin_define_type_sizeof (buf,
  1084. int_n_trees[i].signed_type);
  1085. }
  1086. builtin_define_type_sizeof ("__SIZEOF_WCHAR_T__", wchar_type_node);
  1087. builtin_define_type_sizeof ("__SIZEOF_WINT_T__", wint_type_node);
  1088. builtin_define_type_sizeof ("__SIZEOF_PTRDIFF_T__",
  1089. unsigned_ptrdiff_type_node);
  1090. /* A straightforward target hook doesn't work, because of problems
  1091. linking that hook's body when part of non-C front ends. */
  1092. # define preprocessing_asm_p() (cpp_get_options (pfile)->lang == CLK_ASM)
  1093. # define preprocessing_trad_p() (cpp_get_options (pfile)->traditional)
  1094. # define builtin_define(TXT) cpp_define (pfile, TXT)
  1095. # define builtin_assert(TXT) cpp_assert (pfile, TXT)
  1096. TARGET_CPU_CPP_BUILTINS ();
  1097. TARGET_OS_CPP_BUILTINS ();
  1098. TARGET_OBJFMT_CPP_BUILTINS ();
  1099. /* Support the __declspec keyword by turning them into attributes.
  1100. Note that the current way we do this may result in a collision
  1101. with predefined attributes later on. This can be solved by using
  1102. one attribute, say __declspec__, and passing args to it. The
  1103. problem with that approach is that args are not accumulated: each
  1104. new appearance would clobber any existing args. */
  1105. if (TARGET_DECLSPEC)
  1106. builtin_define ("__declspec(x)=__attribute__((x))");
  1107. /* If decimal floating point is supported, tell the user if the
  1108. alternate format (BID) is used instead of the standard (DPD)
  1109. format. */
  1110. if (ENABLE_DECIMAL_FLOAT && ENABLE_DECIMAL_BID_FORMAT)
  1111. cpp_define (pfile, "__DECIMAL_BID_FORMAT__");
  1112. }
  1113. /* Pass an object-like macro. If it doesn't lie in the user's
  1114. namespace, defines it unconditionally. Otherwise define a version
  1115. with two leading underscores, and another version with two leading
  1116. and trailing underscores, and define the original only if an ISO
  1117. standard was not nominated.
  1118. e.g. passing "unix" defines "__unix", "__unix__" and possibly
  1119. "unix". Passing "_mips" defines "__mips", "__mips__" and possibly
  1120. "_mips". */
  1121. void
  1122. builtin_define_std (const char *macro)
  1123. {
  1124. size_t len = strlen (macro);
  1125. char *buff = (char *) alloca (len + 5);
  1126. char *p = buff + 2;
  1127. char *q = p + len;
  1128. /* prepend __ (or maybe just _) if in user's namespace. */
  1129. memcpy (p, macro, len + 1);
  1130. if (!( *p == '_' && (p[1] == '_' || ISUPPER (p[1]))))
  1131. {
  1132. if (*p != '_')
  1133. *--p = '_';
  1134. if (p[1] != '_')
  1135. *--p = '_';
  1136. }
  1137. cpp_define (parse_in, p);
  1138. /* If it was in user's namespace... */
  1139. if (p != buff + 2)
  1140. {
  1141. /* Define the macro with leading and following __. */
  1142. if (q[-1] != '_')
  1143. *q++ = '_';
  1144. if (q[-2] != '_')
  1145. *q++ = '_';
  1146. *q = '\0';
  1147. cpp_define (parse_in, p);
  1148. /* Finally, define the original macro if permitted. */
  1149. if (!flag_iso)
  1150. cpp_define (parse_in, macro);
  1151. }
  1152. }
  1153. /* Pass an object-like macro and a value to define it to. The third
  1154. parameter says whether or not to turn the value into a string
  1155. constant. */
  1156. void
  1157. builtin_define_with_value (const char *macro, const char *expansion, int is_str)
  1158. {
  1159. char *buf;
  1160. size_t mlen = strlen (macro);
  1161. size_t elen = strlen (expansion);
  1162. size_t extra = 2; /* space for an = and a NUL */
  1163. if (is_str)
  1164. {
  1165. char *quoted_expansion = (char *) alloca (elen * 4 + 1);
  1166. const char *p;
  1167. char *q;
  1168. extra += 2; /* space for two quote marks */
  1169. for (p = expansion, q = quoted_expansion; *p; p++)
  1170. {
  1171. switch (*p)
  1172. {
  1173. case '\n':
  1174. *q++ = '\\';
  1175. *q++ = 'n';
  1176. break;
  1177. case '\t':
  1178. *q++ = '\\';
  1179. *q++ = 't';
  1180. break;
  1181. case '\\':
  1182. *q++ = '\\';
  1183. *q++ = '\\';
  1184. break;
  1185. case '"':
  1186. *q++ = '\\';
  1187. *q++ = '"';
  1188. break;
  1189. default:
  1190. if (ISPRINT ((unsigned char) *p))
  1191. *q++ = *p;
  1192. else
  1193. {
  1194. sprintf (q, "\\%03o", (unsigned char) *p);
  1195. q += 4;
  1196. }
  1197. }
  1198. }
  1199. *q = '\0';
  1200. expansion = quoted_expansion;
  1201. elen = q - expansion;
  1202. }
  1203. buf = (char *) alloca (mlen + elen + extra);
  1204. if (is_str)
  1205. sprintf (buf, "%s=\"%s\"", macro, expansion);
  1206. else
  1207. sprintf (buf, "%s=%s", macro, expansion);
  1208. cpp_define (parse_in, buf);
  1209. }
  1210. /* Pass an object-like macro and an integer value to define it to. */
  1211. static void
  1212. builtin_define_with_int_value (const char *macro, HOST_WIDE_INT value)
  1213. {
  1214. char *buf;
  1215. size_t mlen = strlen (macro);
  1216. size_t vlen = 18;
  1217. size_t extra = 2; /* space for = and NUL. */
  1218. buf = (char *) alloca (mlen + vlen + extra);
  1219. memcpy (buf, macro, mlen);
  1220. buf[mlen] = '=';
  1221. sprintf (buf + mlen + 1, HOST_WIDE_INT_PRINT_DEC, value);
  1222. cpp_define (parse_in, buf);
  1223. }
  1224. /* builtin_define_with_hex_fp_value is very expensive, so the following
  1225. array and function allows it to be done lazily when __DBL_MAX__
  1226. etc. is first used. */
  1227. struct GTY(()) lazy_hex_fp_value_struct
  1228. {
  1229. const char *hex_str;
  1230. cpp_macro *macro;
  1231. machine_mode mode;
  1232. int digits;
  1233. const char *fp_suffix;
  1234. };
  1235. static GTY(()) struct lazy_hex_fp_value_struct lazy_hex_fp_values[12];
  1236. static GTY(()) int lazy_hex_fp_value_count;
  1237. static bool
  1238. lazy_hex_fp_value (cpp_reader *pfile ATTRIBUTE_UNUSED,
  1239. cpp_hashnode *node)
  1240. {
  1241. REAL_VALUE_TYPE real;
  1242. char dec_str[64], buf1[256];
  1243. unsigned int idx;
  1244. if (node->value.builtin < BT_FIRST_USER
  1245. || (int) node->value.builtin >= BT_FIRST_USER + lazy_hex_fp_value_count)
  1246. return false;
  1247. idx = node->value.builtin - BT_FIRST_USER;
  1248. real_from_string (&real, lazy_hex_fp_values[idx].hex_str);
  1249. real_to_decimal_for_mode (dec_str, &real, sizeof (dec_str),
  1250. lazy_hex_fp_values[idx].digits, 0,
  1251. lazy_hex_fp_values[idx].mode);
  1252. sprintf (buf1, "%s%s", dec_str, lazy_hex_fp_values[idx].fp_suffix);
  1253. node->flags &= ~(NODE_BUILTIN | NODE_USED);
  1254. node->value.macro = lazy_hex_fp_values[idx].macro;
  1255. for (idx = 0; idx < node->value.macro->count; idx++)
  1256. if (node->value.macro->exp.tokens[idx].type == CPP_NUMBER)
  1257. break;
  1258. gcc_assert (idx < node->value.macro->count);
  1259. node->value.macro->exp.tokens[idx].val.str.len = strlen (buf1);
  1260. node->value.macro->exp.tokens[idx].val.str.text
  1261. = (const unsigned char *) ggc_strdup (buf1);
  1262. return true;
  1263. }
  1264. /* Pass an object-like macro a hexadecimal floating-point value. */
  1265. static void
  1266. builtin_define_with_hex_fp_value (const char *macro,
  1267. tree type, int digits,
  1268. const char *hex_str,
  1269. const char *fp_suffix,
  1270. const char *fp_cast)
  1271. {
  1272. REAL_VALUE_TYPE real;
  1273. char dec_str[64], buf1[256], buf2[256];
  1274. /* This is very expensive, so if possible expand them lazily. */
  1275. if (lazy_hex_fp_value_count < 12
  1276. && flag_dump_macros == 0
  1277. && !cpp_get_options (parse_in)->traditional)
  1278. {
  1279. struct cpp_hashnode *node;
  1280. if (lazy_hex_fp_value_count == 0)
  1281. cpp_get_callbacks (parse_in)->user_builtin_macro = lazy_hex_fp_value;
  1282. sprintf (buf2, fp_cast, "1.1");
  1283. sprintf (buf1, "%s=%s", macro, buf2);
  1284. cpp_define (parse_in, buf1);
  1285. node = C_CPP_HASHNODE (get_identifier (macro));
  1286. lazy_hex_fp_values[lazy_hex_fp_value_count].hex_str
  1287. = ggc_strdup (hex_str);
  1288. lazy_hex_fp_values[lazy_hex_fp_value_count].mode = TYPE_MODE (type);
  1289. lazy_hex_fp_values[lazy_hex_fp_value_count].digits = digits;
  1290. lazy_hex_fp_values[lazy_hex_fp_value_count].fp_suffix = fp_suffix;
  1291. lazy_hex_fp_values[lazy_hex_fp_value_count].macro = node->value.macro;
  1292. node->flags |= NODE_BUILTIN;
  1293. node->value.builtin
  1294. = (enum cpp_builtin_type) (BT_FIRST_USER + lazy_hex_fp_value_count);
  1295. lazy_hex_fp_value_count++;
  1296. return;
  1297. }
  1298. /* Hex values are really cool and convenient, except that they're
  1299. not supported in strict ISO C90 mode. First, the "p-" sequence
  1300. is not valid as part of a preprocessor number. Second, we get a
  1301. pedwarn from the preprocessor, which has no context, so we can't
  1302. suppress the warning with __extension__.
  1303. So instead what we do is construct the number in hex (because
  1304. it's easy to get the exact correct value), parse it as a real,
  1305. then print it back out as decimal. */
  1306. real_from_string (&real, hex_str);
  1307. real_to_decimal_for_mode (dec_str, &real, sizeof (dec_str), digits, 0,
  1308. TYPE_MODE (type));
  1309. /* Assemble the macro in the following fashion
  1310. macro = fp_cast [dec_str fp_suffix] */
  1311. sprintf (buf1, "%s%s", dec_str, fp_suffix);
  1312. sprintf (buf2, fp_cast, buf1);
  1313. sprintf (buf1, "%s=%s", macro, buf2);
  1314. cpp_define (parse_in, buf1);
  1315. }
  1316. /* Return a string constant for the suffix for a value of type TYPE
  1317. promoted according to the integer promotions. The type must be one
  1318. of the standard integer type nodes. */
  1319. static const char *
  1320. type_suffix (tree type)
  1321. {
  1322. static const char *const suffixes[] = { "", "U", "L", "UL", "LL", "ULL" };
  1323. int unsigned_suffix;
  1324. int is_long;
  1325. int tp = TYPE_PRECISION (type);
  1326. if (type == long_long_integer_type_node
  1327. || type == long_long_unsigned_type_node
  1328. || tp > TYPE_PRECISION (long_integer_type_node))
  1329. is_long = 2;
  1330. else if (type == long_integer_type_node
  1331. || type == long_unsigned_type_node
  1332. || tp > TYPE_PRECISION (integer_type_node))
  1333. is_long = 1;
  1334. else if (type == integer_type_node
  1335. || type == unsigned_type_node
  1336. || type == short_integer_type_node
  1337. || type == short_unsigned_type_node
  1338. || type == signed_char_type_node
  1339. || type == unsigned_char_type_node
  1340. /* ??? "char" is not a signed or unsigned integer type and
  1341. so is not permitted for the standard typedefs, but some
  1342. systems use it anyway. */
  1343. || type == char_type_node)
  1344. is_long = 0;
  1345. else
  1346. gcc_unreachable ();
  1347. unsigned_suffix = TYPE_UNSIGNED (type);
  1348. if (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
  1349. unsigned_suffix = 0;
  1350. return suffixes[is_long * 2 + unsigned_suffix];
  1351. }
  1352. /* Define MACRO as a <stdint.h> constant-suffix macro for TYPE. */
  1353. static void
  1354. builtin_define_constants (const char *macro, tree type)
  1355. {
  1356. const char *suffix;
  1357. char *buf;
  1358. suffix = type_suffix (type);
  1359. if (suffix[0] == 0)
  1360. {
  1361. buf = (char *) alloca (strlen (macro) + 6);
  1362. sprintf (buf, "%s(c)=c", macro);
  1363. }
  1364. else
  1365. {
  1366. buf = (char *) alloca (strlen (macro) + 9 + strlen (suffix) + 1);
  1367. sprintf (buf, "%s(c)=c ## %s", macro, suffix);
  1368. }
  1369. cpp_define (parse_in, buf);
  1370. }
  1371. /* Define MAX for TYPE based on the precision of the type. */
  1372. static void
  1373. builtin_define_type_max (const char *macro, tree type)
  1374. {
  1375. builtin_define_type_minmax (NULL, macro, type);
  1376. }
  1377. /* Given a value with COUNT LSBs set, fill BUF with a hexidecimal
  1378. representation of that value. For example, a COUNT of 10 would
  1379. return "0x3ff". */
  1380. static void
  1381. print_bits_of_hex (char *buf, int bufsz, int count)
  1382. {
  1383. gcc_assert (bufsz > 3);
  1384. *buf++ = '0';
  1385. *buf++ = 'x';
  1386. bufsz -= 2;
  1387. gcc_assert (count > 0);
  1388. switch (count % 4) {
  1389. case 0:
  1390. break;
  1391. case 1:
  1392. *buf++ = '1';
  1393. bufsz --;
  1394. count -= 1;
  1395. break;
  1396. case 2:
  1397. *buf++ = '3';
  1398. bufsz --;
  1399. count -= 2;
  1400. break;
  1401. case 3:
  1402. *buf++ = '7';
  1403. bufsz --;
  1404. count -= 3;
  1405. break;
  1406. }
  1407. while (count >= 4)
  1408. {
  1409. gcc_assert (bufsz > 1);
  1410. *buf++ = 'f';
  1411. bufsz --;
  1412. count -= 4;
  1413. }
  1414. gcc_assert (bufsz > 0);
  1415. *buf++ = 0;
  1416. }
  1417. /* Define MIN_MACRO (if not NULL) and MAX_MACRO for TYPE based on the
  1418. precision of the type. */
  1419. static void
  1420. builtin_define_type_minmax (const char *min_macro, const char *max_macro,
  1421. tree type)
  1422. {
  1423. #define PBOH_SZ (MAX_BITSIZE_MODE_ANY_INT/4+4)
  1424. char value[PBOH_SZ];
  1425. const char *suffix;
  1426. char *buf;
  1427. int bits;
  1428. bits = TYPE_PRECISION (type) + (TYPE_UNSIGNED (type) ? 0 : -1);
  1429. print_bits_of_hex (value, PBOH_SZ, bits);
  1430. suffix = type_suffix (type);
  1431. buf = (char *) alloca (strlen (max_macro) + 1 + strlen (value)
  1432. + strlen (suffix) + 1);
  1433. sprintf (buf, "%s=%s%s", max_macro, value, suffix);
  1434. cpp_define (parse_in, buf);
  1435. if (min_macro)
  1436. {
  1437. if (TYPE_UNSIGNED (type))
  1438. {
  1439. buf = (char *) alloca (strlen (min_macro) + 2 + strlen (suffix) + 1);
  1440. sprintf (buf, "%s=0%s", min_macro, suffix);
  1441. }
  1442. else
  1443. {
  1444. buf = (char *) alloca (strlen (min_macro) + 3
  1445. + strlen (max_macro) + 6);
  1446. sprintf (buf, "%s=(-%s - 1)", min_macro, max_macro);
  1447. }
  1448. cpp_define (parse_in, buf);
  1449. }
  1450. }
  1451. #include "gt-c-family-c-cppbuiltin.h"