]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/cppbuiltin.c
re PR c++/67845 (ICE on invalid use of const qualifier on x86_64-linux-gnu in merge_t...
[thirdparty/gcc.git] / gcc / cppbuiltin.c
CommitLineData
82a1c2fe 1/* Define builtin-in macros for all front ends that perform preprocessing
5624e564 2 Copyright (C) 2010-2015 Free Software Foundation, Inc.
82a1c2fe
FXC
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
8Software Foundation; either version 3, or (at your option) any later
9version.
10
11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14for more details.
15
16You should have received a copy of the GNU General Public License
17along with GCC; see the file COPYING3. If not see
18<http://www.gnu.org/licenses/>. */
19
20#include "config.h"
21#include "system.h"
22#include "coretypes.h"
23#include "tm.h"
40e23961 24#include "alias.h"
82a1c2fe
FXC
25#include "tree.h"
26#include "version.h"
27#include "flags.h"
82a1c2fe
FXC
28#include "cpp-id-data.h"
29#include "cppbuiltin.h"
f87c158e 30#include "target.h"
82a1c2fe
FXC
31
32
33/* Parse a BASEVER version string of the format "major.minor.patchlevel"
34 or "major.minor" to extract its components. */
35void
36parse_basever (int *major, int *minor, int *patchlevel)
37{
38 static int s_major = -1, s_minor, s_patchlevel;
39
40 if (s_major == -1)
41 if (sscanf (BASEVER, "%d.%d.%d", &s_major, &s_minor, &s_patchlevel) != 3)
42 {
43 sscanf (BASEVER, "%d.%d", &s_major, &s_minor);
44 s_patchlevel = 0;
45 }
46
47 if (major)
48 *major = s_major;
49
50 if (minor)
51 *minor = s_minor;
52
53 if (patchlevel)
54 *patchlevel = s_patchlevel;
55}
56
57
58/* Define __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__ and __VERSION__. */
59static void
60define__GNUC__ (cpp_reader *pfile)
61{
62 int major, minor, patchlevel;
63
64 parse_basever (&major, &minor, &patchlevel);
65 cpp_define_formatted (pfile, "__GNUC__=%d", major);
66 cpp_define_formatted (pfile, "__GNUC_MINOR__=%d", minor);
67 cpp_define_formatted (pfile, "__GNUC_PATCHLEVEL__=%d", patchlevel);
68 cpp_define_formatted (pfile, "__VERSION__=\"%s\"", version_string);
86951993
AM
69 cpp_define_formatted (pfile, "__ATOMIC_RELAXED=%d", MEMMODEL_RELAXED);
70 cpp_define_formatted (pfile, "__ATOMIC_SEQ_CST=%d", MEMMODEL_SEQ_CST);
71 cpp_define_formatted (pfile, "__ATOMIC_ACQUIRE=%d", MEMMODEL_ACQUIRE);
72 cpp_define_formatted (pfile, "__ATOMIC_RELEASE=%d", MEMMODEL_RELEASE);
73 cpp_define_formatted (pfile, "__ATOMIC_ACQ_REL=%d", MEMMODEL_ACQ_REL);
74 cpp_define_formatted (pfile, "__ATOMIC_CONSUME=%d", MEMMODEL_CONSUME);
82a1c2fe
FXC
75}
76
77
78/* Define various built-in CPP macros that depend on language-independent
79 compilation flags. */
80static void
81define_builtin_macros_for_compilation_flags (cpp_reader *pfile)
82{
83 if (flag_pic)
84 {
85 cpp_define_formatted (pfile, "__pic__=%d", flag_pic);
86 cpp_define_formatted (pfile, "__PIC__=%d", flag_pic);
87 }
88 if (flag_pie)
89 {
90 cpp_define_formatted (pfile, "__pie__=%d", flag_pie);
91 cpp_define_formatted (pfile, "__PIE__=%d", flag_pie);
92 }
93
de5a5fa1 94 if (flag_sanitize & SANITIZE_ADDRESS)
70e0bf7b
L
95 cpp_define (pfile, "__SANITIZE_ADDRESS__");
96
82a1c2fe
FXC
97 if (optimize_size)
98 cpp_define (pfile, "__OPTIMIZE_SIZE__");
99 if (optimize)
100 cpp_define (pfile, "__OPTIMIZE__");
101
0576d21f 102 if (fast_math_flags_set_p (&global_options))
82a1c2fe
FXC
103 cpp_define (pfile, "__FAST_MATH__");
104 if (flag_signaling_nans)
105 cpp_define (pfile, "__SUPPORT_SNAN__");
2079956a
JM
106 if (!flag_errno_math)
107 cpp_define (pfile, "__NO_MATH_ERRNO__");
82a1c2fe
FXC
108
109 cpp_define_formatted (pfile, "__FINITE_MATH_ONLY__=%d",
110 flag_finite_math_only);
b72271b9 111 if (flag_cilkplus)
939b37da 112 cpp_define (pfile, "__cilk=200");
d5e254e1
IE
113
114 if (flag_check_pointer_bounds)
115 cpp_define (pfile, "__CHKP__");
82a1c2fe
FXC
116}
117
118
119/* Define built-in macros for LP64 targets. */
120static void
121define_builtin_macros_for_lp64 (cpp_reader *pfile)
122{
123 if (TYPE_PRECISION (long_integer_type_node) == 64
124 && POINTER_SIZE == 64
125 && TYPE_PRECISION (integer_type_node) == 32)
126 {
127 cpp_define (pfile, "_LP64");
128 cpp_define (pfile, "__LP64__");
129 }
130}
131
132
133/* Define macros for size of basic C types. */
134static void
135define_builtin_macros_for_type_sizes (cpp_reader *pfile)
136{
137#define define_type_sizeof(NAME, TYPE) \
16998094 138 cpp_define_formatted (pfile, NAME"=" HOST_WIDE_INT_PRINT_DEC, \
ae7e9ddd 139 tree_to_uhwi (TYPE_SIZE_UNIT (TYPE)))
82a1c2fe
FXC
140
141 define_type_sizeof ("__SIZEOF_INT__", integer_type_node);
142 define_type_sizeof ("__SIZEOF_LONG__", long_integer_type_node);
143 define_type_sizeof ("__SIZEOF_LONG_LONG__", long_long_integer_type_node);
144 define_type_sizeof ("__SIZEOF_SHORT__", short_integer_type_node);
145 define_type_sizeof ("__SIZEOF_FLOAT__", float_type_node);
146 define_type_sizeof ("__SIZEOF_DOUBLE__", double_type_node);
147 define_type_sizeof ("__SIZEOF_LONG_DOUBLE__", long_double_type_node);
148 define_type_sizeof ("__SIZEOF_SIZE_T__", size_type_node);
149
150#undef define_type_sizeof
151
152 cpp_define_formatted (pfile, "__CHAR_BIT__=%u",
153 TYPE_PRECISION (char_type_node));
154 cpp_define_formatted (pfile, "__BIGGEST_ALIGNMENT__=%d",
155 BIGGEST_ALIGNMENT / BITS_PER_UNIT);
156
18ed6ee4
NF
157 /* Define constants useful for implementing endian.h. */
158 cpp_define (pfile, "__ORDER_LITTLE_ENDIAN__=1234");
159 cpp_define (pfile, "__ORDER_BIG_ENDIAN__=4321");
160 cpp_define (pfile, "__ORDER_PDP_ENDIAN__=3412");
161
162 if (WORDS_BIG_ENDIAN == BYTES_BIG_ENDIAN)
163 cpp_define_formatted (pfile, "__BYTE_ORDER__=%s",
164 (WORDS_BIG_ENDIAN
165 ? "__ORDER_BIG_ENDIAN__"
166 : "__ORDER_LITTLE_ENDIAN__"));
167 else
168 {
169 /* Assert that we're only dealing with the PDP11 case. */
17f84643
JR
170 gcc_assert (!BYTES_BIG_ENDIAN);
171 gcc_assert (WORDS_BIG_ENDIAN);
18ed6ee4
NF
172
173 cpp_define (pfile, "__BYTE_ORDER__=__ORDER_PDP_ENDIAN__");
174 }
175
a3abe41c 176 cpp_define_formatted (pfile, "__FLOAT_WORD_ORDER__=%s",
f87c158e 177 (targetm.float_words_big_endian ()
a3abe41c
NF
178 ? "__ORDER_BIG_ENDIAN__"
179 : "__ORDER_LITTLE_ENDIAN__"));
180
82a1c2fe
FXC
181 /* ptr_type_node can't be used here since ptr_mode is only set when
182 toplev calls backend_init which is not done with -E switch. */
183 cpp_define_formatted (pfile, "__SIZEOF_POINTER__=%d",
50b6ee8b 184 1 << ceil_log2 ((POINTER_SIZE + BITS_PER_UNIT - 1) / BITS_PER_UNIT));
82a1c2fe
FXC
185}
186
187
188/* Define macros builtins common to all language performing CPP
189 preprocessing. */
190void
191define_language_independent_builtin_macros (cpp_reader *pfile)
192{
193 define__GNUC__ (pfile);
194 define_builtin_macros_for_compilation_flags (pfile);
195 define_builtin_macros_for_lp64 (pfile);
196 define_builtin_macros_for_type_sizes (pfile);
197}