]> gcc.gnu.org Git - gcc.git/blame - gcc/c-family/c-pragma.c
cgraph.h: Flatten.
[gcc.git] / gcc / c-family / c-pragma.c
CommitLineData
a187ac95 1/* Handle #pragma, system V.4 style. Supports #pragma weak and #pragma pack.
23a5b65a 2 Copyright (C) 1992-2014 Free Software Foundation, Inc.
a187ac95 3
1322177d 4This file is part of GCC.
a187ac95 5
1322177d
LB
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
9dcd6f09 8Software Foundation; either version 3, or (at your option) any later
1322177d 9version.
a187ac95 10
1322177d
LB
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.
a187ac95
RS
15
16You should have received a copy of the GNU General Public License
9dcd6f09
NC
17along with GCC; see the file COPYING3. If not see
18<http://www.gnu.org/licenses/>. */
a187ac95 19
4b578ebf 20#include "config.h"
670ee920 21#include "system.h"
4977bab6
ZW
22#include "coretypes.h"
23#include "tm.h"
4b578ebf 24#include "tree.h"
d8a2d370
DN
25#include "stringpool.h"
26#include "attribs.h"
27#include "varasm.h"
83685514
AM
28#include "hashtab.h"
29#include "hash-set.h"
30#include "vec.h"
31#include "machmode.h"
32#include "hard-reg-set.h"
33#include "input.h"
f4ce02c5
SB
34#include "function.h" /* For cfun. FIXME: Does the parser know
35 when it is inside a function, so that
36 we don't have to look at cfun? */
8b97c5f8 37#include "cpplib.h"
3d6f7931 38#include "c-pragma.h"
750caf0d 39#include "flags.h"
ecb0eece 40#include "c-common.h"
f4ce02c5
SB
41#include "tm_p.h" /* For REGISTER_TARGET_PRAGMAS (why is
42 this not a target hook?). */
84b8b0e0 43#include "target.h"
79cf5994
DD
44#include "diagnostic.h"
45#include "opts.h"
7ac8318c 46#include "plugin.h"
c582198b
AM
47#include "hash-map.h"
48#include "is-a.h"
49#include "plugin-api.h"
50#include "ipa-ref.h"
65d630d4 51#include "cgraph.h"
bc4071dd 52
b9b8dde3
DD
53#define GCC_BAD(gmsgid) \
54 do { warning (OPT_Wpragmas, gmsgid); return; } while (0)
4b794eaf 55#define GCC_BAD2(gmsgid, arg) \
b9b8dde3 56 do { warning (OPT_Wpragmas, gmsgid, arg); return; } while (0)
0e5921e8 57
d1b38208 58typedef struct GTY(()) align_stack {
c22cacf3
MS
59 int alignment;
60 tree id;
e2af664c
NC
61 struct align_stack * prev;
62} align_stack;
63
e2500fed
GK
64static GTY(()) struct align_stack * alignment_stack;
65
35b1a6fa 66static void handle_pragma_pack (cpp_reader *);
e2af664c 67
63eb1269 68/* If we have a "global" #pragma pack(<n>) in effect when the first
c22cacf3
MS
69 #pragma pack(push,<n>) is encountered, this stores the value of
70 maximum_field_alignment in effect. When the final pop_alignment()
61e8b354 71 happens, we restore the value to this, not to a value of 0 for
ec5c56db 72 maximum_field_alignment. Value is in bits. */
ecb0eece 73static int default_alignment;
467cecf3
JB
74#define SET_GLOBAL_ALIGNMENT(ALIGN) (maximum_field_alignment = *(alignment_stack == NULL \
75 ? &default_alignment \
76 : &alignment_stack->alignment) = (ALIGN))
61e8b354 77
35b1a6fa
AJ
78static void push_alignment (int, tree);
79static void pop_alignment (tree);
e2af664c
NC
80
81/* Push an alignment value onto the stack. */
0e5921e8 82static void
35b1a6fa 83push_alignment (int alignment, tree id)
e2af664c 84{
766090c2 85 align_stack * entry = ggc_alloc<align_stack> ();
e2af664c 86
467cecf3 87 entry->alignment = alignment;
c22cacf3
MS
88 entry->id = id;
89 entry->prev = alignment_stack;
90
91 /* The current value of maximum_field_alignment is not necessarily
92 0 since there may be a #pragma pack(<n>) in effect; remember it
467cecf3
JB
93 so that we can restore it after the final #pragma pop(). */
94 if (alignment_stack == NULL)
95 default_alignment = maximum_field_alignment;
c22cacf3 96
467cecf3 97 alignment_stack = entry;
e2af664c 98
467cecf3 99 maximum_field_alignment = alignment;
e2af664c
NC
100}
101
102/* Undo a push of an alignment onto the stack. */
0e5921e8 103static void
35b1a6fa 104pop_alignment (tree id)
e2af664c 105{
0f92adae 106 align_stack * entry;
c22cacf3 107
e2af664c 108 if (alignment_stack == NULL)
3f75a254 109 GCC_BAD ("#pragma pack (pop) encountered without matching #pragma pack (push)");
e2af664c 110
0f92adae
JM
111 /* If we got an identifier, strip away everything above the target
112 entry so that the next step will restore the state just below it. */
113 if (id)
114 {
115 for (entry = alignment_stack; entry; entry = entry->prev)
116 if (entry->id == id)
117 {
0f92adae
JM
118 alignment_stack = entry;
119 break;
120 }
121 if (entry == NULL)
b9b8dde3 122 warning (OPT_Wpragmas, "\
88388a52
JM
123#pragma pack(pop, %E) encountered without matching #pragma pack(push, %E)"
124 , id, id);
0f92adae
JM
125 }
126
467cecf3 127 entry = alignment_stack->prev;
e2af664c 128
467cecf3 129 maximum_field_alignment = entry ? entry->alignment : default_alignment;
e2af664c 130
467cecf3 131 alignment_stack = entry;
e2af664c 132}
a187ac95 133
0e5921e8
ZW
134/* #pragma pack ()
135 #pragma pack (N)
c22cacf3 136
467cecf3 137 #pragma pack (push)
0e5921e8 138 #pragma pack (push, N)
467cecf3 139 #pragma pack (push, ID)
0e5921e8
ZW
140 #pragma pack (push, ID, N)
141 #pragma pack (pop)
142 #pragma pack (pop, ID) */
143static void
e18476eb 144handle_pragma_pack (cpp_reader * ARG_UNUSED (dummy))
0e5921e8
ZW
145{
146 tree x, id = 0;
63eb1269 147 int align = -1;
0e5921e8 148 enum cpp_ttype token;
4337bc93 149 enum { set, push, pop } action;
0e5921e8 150
75ce3d48 151 if (pragma_lex (&x) != CPP_OPEN_PAREN)
bda67431 152 GCC_BAD ("missing %<(%> after %<#pragma pack%> - ignored");
0e5921e8 153
75ce3d48 154 token = pragma_lex (&x);
0e5921e8 155 if (token == CPP_CLOSE_PAREN)
4337bc93
ZW
156 {
157 action = set;
467cecf3 158 align = initial_max_fld_align;
4337bc93 159 }
0e5921e8
ZW
160 else if (token == CPP_NUMBER)
161 {
12050e44
VR
162 if (TREE_CODE (x) != INTEGER_CST)
163 GCC_BAD ("invalid constant in %<#pragma pack%> - ignored");
0e5921e8
ZW
164 align = TREE_INT_CST_LOW (x);
165 action = set;
75ce3d48 166 if (pragma_lex (&x) != CPP_CLOSE_PAREN)
bda67431 167 GCC_BAD ("malformed %<#pragma pack%> - ignored");
0e5921e8
ZW
168 }
169 else if (token == CPP_NAME)
170 {
467cecf3 171#define GCC_BAD_ACTION do { if (action != pop) \
bda67431 172 GCC_BAD ("malformed %<#pragma pack(push[, id][, <n>])%> - ignored"); \
63eb1269 173 else \
bda67431 174 GCC_BAD ("malformed %<#pragma pack(pop[, id])%> - ignored"); \
63eb1269
MC
175 } while (0)
176
4337bc93
ZW
177 const char *op = IDENTIFIER_POINTER (x);
178 if (!strcmp (op, "push"))
0e5921e8 179 action = push;
4337bc93 180 else if (!strcmp (op, "pop"))
0e5921e8
ZW
181 action = pop;
182 else
88388a52 183 GCC_BAD2 ("unknown action %qE for %<#pragma pack%> - ignored", x);
a187ac95 184
75ce3d48 185 while ((token = pragma_lex (&x)) == CPP_COMMA)
e2af664c 186 {
75ce3d48 187 token = pragma_lex (&x);
467cecf3 188 if (token == CPP_NAME && id == 0)
63eb1269
MC
189 {
190 id = x;
63eb1269 191 }
467cecf3 192 else if (token == CPP_NUMBER && action == push && align == -1)
63eb1269 193 {
12050e44
VR
194 if (TREE_CODE (x) != INTEGER_CST)
195 GCC_BAD ("invalid constant in %<#pragma pack%> - ignored");
467cecf3
JB
196 align = TREE_INT_CST_LOW (x);
197 if (align == -1)
198 action = set;
63eb1269 199 }
467cecf3
JB
200 else
201 GCC_BAD_ACTION;
e2af664c 202 }
4337bc93 203
63eb1269 204 if (token != CPP_CLOSE_PAREN)
da4083c7
CR
205 GCC_BAD_ACTION;
206#undef GCC_BAD_ACTION
e2af664c 207 }
4337bc93 208 else
bda67431 209 GCC_BAD ("malformed %<#pragma pack%> - ignored");
4337bc93 210
75ce3d48 211 if (pragma_lex (&x) != CPP_EOF)
b9b8dde3 212 warning (OPT_Wpragmas, "junk at end of %<#pragma pack%>");
0e5921e8 213
467cecf3
JB
214 if (flag_pack_struct)
215 GCC_BAD ("#pragma pack has no effect with -fpack-struct - ignored");
216
63eb1269
MC
217 if (action != pop)
218 switch (align)
219 {
220 case 0:
221 case 1:
222 case 2:
223 case 4:
224 case 8:
225 case 16:
226 align *= BITS_PER_UNIT;
227 break;
467cecf3
JB
228 case -1:
229 if (action == push)
230 {
231 align = maximum_field_alignment;
232 break;
233 }
63eb1269 234 default:
da4083c7 235 GCC_BAD2 ("alignment must be a small power of two, not %d", align);
63eb1269 236 }
fc009f96 237
0e5921e8
ZW
238 switch (action)
239 {
240 case set: SET_GLOBAL_ALIGNMENT (align); break;
0e5921e8 241 case push: push_alignment (align, id); break;
c22cacf3 242 case pop: pop_alignment (id); break;
0e5921e8
ZW
243 }
244}
a187ac95 245
18bc5398
SB
246typedef struct GTY(()) pending_weak_d
247{
248 tree name;
249 tree value;
250} pending_weak;
251
18bc5398 252
9771b263 253static GTY(()) vec<pending_weak, va_gc> *pending_weaks;
e2500fed 254
35b1a6fa
AJ
255static void apply_pragma_weak (tree, tree);
256static void handle_pragma_weak (cpp_reader *);
a187ac95 257
ecb0eece 258static void
35b1a6fa 259apply_pragma_weak (tree decl, tree value)
ecb0eece
RH
260{
261 if (value)
b53bb376
RH
262 {
263 value = build_string (IDENTIFIER_LENGTH (value),
264 IDENTIFIER_POINTER (value));
265 decl_attributes (&decl, build_tree_list (get_identifier ("alias"),
266 build_tree_list (NULL, value)),
267 0);
268 }
269
45806a3f 270 if (SUPPORTS_WEAK && DECL_EXTERNAL (decl) && TREE_USED (decl)
e0a21ab9 271 && !DECL_WEAK (decl) /* Don't complain about a redundant #pragma. */
39a1ebb3 272 && DECL_ASSEMBLER_NAME_SET_P (decl)
45806a3f 273 && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
b9b8dde3 274 warning (OPT_Wpragmas, "applying #pragma weak %q+D after first use "
c22cacf3 275 "results in unspecified behavior", decl);
45806a3f 276
ecb0eece
RH
277 declare_weak (decl);
278}
279
280void
35b1a6fa 281maybe_apply_pragma_weak (tree decl)
ecb0eece 282{
18bc5398
SB
283 tree id;
284 int i;
285 pending_weak *pe;
ecb0eece 286
49a64b24
GK
287 /* Avoid asking for DECL_ASSEMBLER_NAME when it's not needed. */
288
289 /* No weak symbols pending, take the short-cut. */
39a1ebb3 290 if (vec_safe_is_empty (pending_weaks))
49a64b24
GK
291 return;
292 /* If it's not visible outside this file, it doesn't matter whether
293 it's weak. */
294 if (!DECL_EXTERNAL (decl) && !TREE_PUBLIC (decl))
ecb0eece 295 return;
49a64b24
GK
296 /* If it's not a function or a variable, it can't be weak.
297 FIXME: what kinds of things are visible outside this file but
366de0ce 298 aren't functions or variables? Should this be an assert instead? */
49a64b24
GK
299 if (TREE_CODE (decl) != FUNCTION_DECL && TREE_CODE (decl) != VAR_DECL)
300 return;
301
39a1ebb3
JJ
302 if (DECL_ASSEMBLER_NAME_SET_P (decl))
303 id = DECL_ASSEMBLER_NAME (decl);
304 else
305 {
306 id = DECL_ASSEMBLER_NAME (decl);
307 SET_DECL_ASSEMBLER_NAME (decl, NULL_TREE);
308 }
ecb0eece 309
9771b263 310 FOR_EACH_VEC_ELT (*pending_weaks, i, pe)
18bc5398 311 if (id == pe->name)
ecb0eece 312 {
18bc5398 313 apply_pragma_weak (decl, pe->value);
9771b263 314 pending_weaks->unordered_remove (i);
ecb0eece
RH
315 break;
316 }
317}
318
86f029aa
JM
319/* Process all "#pragma weak A = B" directives where we have not seen
320 a decl for A. */
321void
322maybe_apply_pending_pragma_weaks (void)
323{
18bc5398
SB
324 tree alias_id, id, decl;
325 int i;
326 pending_weak *pe;
5e20cdc9 327 symtab_node *target;
86f029aa 328
39a1ebb3 329 if (vec_safe_is_empty (pending_weaks))
9771b263
DN
330 return;
331
332 FOR_EACH_VEC_ELT (*pending_weaks, i, pe)
86f029aa 333 {
18bc5398
SB
334 alias_id = pe->name;
335 id = pe->value;
86f029aa 336
18bc5398 337 if (id == NULL)
86f029aa
JM
338 continue;
339
3dafb85c 340 target = symtab_node::get_for_asmname (id);
c2255bc4 341 decl = build_decl (UNKNOWN_LOCATION,
67348ccc 342 target ? TREE_CODE (target->decl) : FUNCTION_DECL,
65d630d4 343 alias_id, default_function_type);
86f029aa
JM
344
345 DECL_ARTIFICIAL (decl) = 1;
346 TREE_PUBLIC (decl) = 1;
86f029aa 347 DECL_WEAK (decl) = 1;
65d630d4
JH
348 if (TREE_CODE (decl) == VAR_DECL)
349 TREE_STATIC (decl) = 1;
350 if (!target)
351 {
352 error ("%q+D aliased to undefined symbol %qE",
353 decl, id);
354 continue;
355 }
86f029aa
JM
356
357 assemble_alias (decl, id);
358 }
359}
360
0e5921e8
ZW
361/* #pragma weak name [= value] */
362static void
e18476eb 363handle_pragma_weak (cpp_reader * ARG_UNUSED (dummy))
0e5921e8 364{
ecb0eece 365 tree name, value, x, decl;
0e5921e8 366 enum cpp_ttype t;
a187ac95 367
0e5921e8 368 value = 0;
7169a029 369
75ce3d48 370 if (pragma_lex (&name) != CPP_NAME)
da4083c7 371 GCC_BAD ("malformed #pragma weak, ignored");
75ce3d48 372 t = pragma_lex (&x);
0e5921e8
ZW
373 if (t == CPP_EQ)
374 {
75ce3d48 375 if (pragma_lex (&value) != CPP_NAME)
da4083c7 376 GCC_BAD ("malformed #pragma weak, ignored");
75ce3d48 377 t = pragma_lex (&x);
0e5921e8
ZW
378 }
379 if (t != CPP_EOF)
bc4071dd 380 warning (OPT_Wpragmas, "junk at end of %<#pragma weak%>");
0f92adae 381
ecb0eece 382 decl = identifier_global_value (name);
6615c446 383 if (decl && DECL_P (decl))
b53bb376
RH
384 {
385 apply_pragma_weak (decl, value);
386 if (value)
08346abd
JH
387 {
388 DECL_EXTERNAL (decl) = 0;
389 if (TREE_CODE (decl) == VAR_DECL)
390 TREE_STATIC (decl) = 1;
391 assemble_alias (decl, value);
392 }
b53bb376 393 }
ecb0eece 394 else
18bc5398 395 {
f32682ca 396 pending_weak pe = {name, value};
9771b263 397 vec_safe_push (pending_weaks, pe);
18bc5398 398 }
0e5921e8 399}
0f92adae 400
84b8b0e0
ZW
401/* GCC supports two #pragma directives for renaming the external
402 symbol associated with a declaration (DECL_ASSEMBLER_NAME), for
5c30094f 403 compatibility with the Solaris and VMS system headers. GCC also
84b8b0e0
ZW
404 has its own notation for this, __asm__("name") annotations.
405
406 Corner cases of these features and their interaction:
407
408 1) Both pragmas silently apply only to declarations with external
409 linkage (that is, TREE_PUBLIC || DECL_EXTERNAL). Asm labels
410 do not have this restriction.
411
412 2) In C++, both #pragmas silently apply only to extern "C" declarations.
413 Asm labels do not have this restriction.
414
415 3) If any of the three ways of changing DECL_ASSEMBLER_NAME is
416 applied to a decl whose DECL_ASSEMBLER_NAME is already set, and the
417 new name is different, a warning issues and the name does not change.
418
419 4) The "source name" for #pragma redefine_extname is the DECL_NAME,
420 *not* the DECL_ASSEMBLER_NAME.
421
422 5) If #pragma extern_prefix is in effect and a declaration occurs
423 with an __asm__ name, the #pragma extern_prefix is silently
424 ignored for that declaration.
425
426 6) If #pragma extern_prefix and #pragma redefine_extname apply to
427 the same declaration, whichever triggered first wins, and a warning
428 is issued. (We would like to have #pragma redefine_extname always
429 win, but it can appear either before or after the declaration, and
430 if it appears afterward, we have no way of knowing whether a modified
431 DECL_ASSEMBLER_NAME is due to #pragma extern_prefix.) */
432
4f8c876d
NF
433typedef struct GTY(()) pending_redefinition_d {
434 tree oldname;
435 tree newname;
436} pending_redefinition;
437
4f8c876d 438
9771b263 439static GTY(()) vec<pending_redefinition, va_gc> *pending_redefine_extname;
e2500fed 440
35b1a6fa 441static void handle_pragma_redefine_extname (cpp_reader *);
41c64394 442
84b8b0e0 443/* #pragma redefine_extname oldname newname */
41c64394 444static void
e18476eb 445handle_pragma_redefine_extname (cpp_reader * ARG_UNUSED (dummy))
41c64394 446{
3a636414 447 tree oldname, newname, decls, x;
41c64394 448 enum cpp_ttype t;
3a636414 449 bool found;
41c64394 450
75ce3d48 451 if (pragma_lex (&oldname) != CPP_NAME)
84b8b0e0 452 GCC_BAD ("malformed #pragma redefine_extname, ignored");
75ce3d48 453 if (pragma_lex (&newname) != CPP_NAME)
84b8b0e0 454 GCC_BAD ("malformed #pragma redefine_extname, ignored");
75ce3d48 455 t = pragma_lex (&x);
41c64394 456 if (t != CPP_EOF)
bc4071dd 457 warning (OPT_Wpragmas, "junk at end of %<#pragma redefine_extname%>");
41c64394 458
3a636414
JM
459 found = false;
460 for (decls = c_linkage_bindings (oldname);
461 decls; )
41c64394 462 {
3a636414
JM
463 tree decl;
464 if (TREE_CODE (decls) == TREE_LIST)
84b8b0e0 465 {
3a636414
JM
466 decl = TREE_VALUE (decls);
467 decls = TREE_CHAIN (decls);
84b8b0e0
ZW
468 }
469 else
3a636414
JM
470 {
471 decl = decls;
472 decls = NULL_TREE;
473 }
474
475 if ((TREE_PUBLIC (decl) || DECL_EXTERNAL (decl))
476 && (TREE_CODE (decl) == FUNCTION_DECL
477 || TREE_CODE (decl) == VAR_DECL))
478 {
479 found = true;
480 if (DECL_ASSEMBLER_NAME_SET_P (decl))
481 {
482 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
483 name = targetm.strip_name_encoding (name);
484
485 if (strcmp (name, IDENTIFIER_POINTER (newname)))
486 warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
487 "conflict with previous rename");
488 }
489 else
3dafb85c 490 symtab->change_decl_assembler_name (decl, newname);
3a636414 491 }
41c64394 492 }
3a636414
JM
493
494 if (!found)
84b8b0e0
ZW
495 /* We have to add this to the rename list even if there's already
496 a global value that doesn't meet the above criteria, because in
497 C++ "struct foo {...};" puts "foo" in the current namespace but
498 does *not* conflict with a subsequent declaration of a function
499 or variable foo. See g++.dg/other/pragma-re-2.C. */
500 add_to_renaming_pragma_list (oldname, newname);
41c64394 501}
41c64394 502
fb037b5d 503/* This is called from here and from ia64-c.c. */
0c3a2ea0 504void
35b1a6fa 505add_to_renaming_pragma_list (tree oldname, tree newname)
0c3a2ea0 506{
4f8c876d
NF
507 unsigned ix;
508 pending_redefinition *p;
509
9771b263 510 FOR_EACH_VEC_SAFE_ELT (pending_redefine_extname, ix, p)
4f8c876d
NF
511 if (oldname == p->oldname)
512 {
513 if (p->newname != newname)
514 warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
515 "conflict with previous #pragma redefine_extname");
516 return;
517 }
c22cacf3 518
f32682ca 519 pending_redefinition e = {oldname, newname};
9771b263 520 vec_safe_push (pending_redefine_extname, e);
0c3a2ea0
SE
521}
522
e50e723e
TG
523/* The current prefix set by #pragma extern_prefix. */
524GTY(()) tree pragma_extern_prefix;
e2500fed 525
95bd1dd7 526/* Hook from the front ends to apply the results of one of the preceding
41c64394
RH
527 pragmas that rename variables. */
528
529tree
35b1a6fa 530maybe_apply_renaming_pragma (tree decl, tree asmname)
41c64394 531{
4f8c876d
NF
532 unsigned ix;
533 pending_redefinition *p;
84b8b0e0
ZW
534
535 /* The renaming pragmas are only applied to declarations with
536 external linkage. */
537 if ((TREE_CODE (decl) != FUNCTION_DECL && TREE_CODE (decl) != VAR_DECL)
538 || (!TREE_PUBLIC (decl) && !DECL_EXTERNAL (decl))
539 || !has_c_linkage (decl))
41c64394
RH
540 return asmname;
541
84b8b0e0
ZW
542 /* If the DECL_ASSEMBLER_NAME is already set, it does not change,
543 but we may warn about a rename that conflicts. */
544 if (DECL_ASSEMBLER_NAME_SET_P (decl))
41c64394 545 {
84b8b0e0
ZW
546 const char *oldname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
547 oldname = targetm.strip_name_encoding (oldname);
548
549 if (asmname && strcmp (TREE_STRING_POINTER (asmname), oldname))
b9b8dde3 550 warning (OPT_Wpragmas, "asm declaration ignored due to "
84b8b0e0
ZW
551 "conflict with previous rename");
552
553 /* Take any pending redefine_extname off the list. */
9771b263 554 FOR_EACH_VEC_SAFE_ELT (pending_redefine_extname, ix, p)
4f8c876d 555 if (DECL_NAME (decl) == p->oldname)
84b8b0e0
ZW
556 {
557 /* Only warn if there is a conflict. */
4f8c876d 558 if (strcmp (IDENTIFIER_POINTER (p->newname), oldname))
b9b8dde3 559 warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
84b8b0e0
ZW
560 "conflict with previous rename");
561
9771b263 562 pending_redefine_extname->unordered_remove (ix);
84b8b0e0
ZW
563 break;
564 }
565 return 0;
41c64394
RH
566 }
567
84b8b0e0 568 /* Find out if we have a pending #pragma redefine_extname. */
9771b263 569 FOR_EACH_VEC_SAFE_ELT (pending_redefine_extname, ix, p)
4f8c876d 570 if (DECL_NAME (decl) == p->oldname)
84b8b0e0 571 {
4f8c876d 572 tree newname = p->newname;
9771b263 573 pending_redefine_extname->unordered_remove (ix);
41c64394 574
84b8b0e0 575 /* If we already have an asmname, #pragma redefine_extname is
c22cacf3 576 ignored (with a warning if it conflicts). */
84b8b0e0
ZW
577 if (asmname)
578 {
579 if (strcmp (TREE_STRING_POINTER (asmname),
580 IDENTIFIER_POINTER (newname)) != 0)
b9b8dde3 581 warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
84b8b0e0
ZW
582 "conflict with __asm__ declaration");
583 return asmname;
584 }
41c64394 585
84b8b0e0
ZW
586 /* Otherwise we use what we've got; #pragma extern_prefix is
587 silently ignored. */
588 return build_string (IDENTIFIER_LENGTH (newname),
589 IDENTIFIER_POINTER (newname));
590 }
41c64394 591
84b8b0e0
ZW
592 /* If we've got an asmname, #pragma extern_prefix is silently ignored. */
593 if (asmname)
594 return asmname;
41c64394 595
84b8b0e0
ZW
596 /* If #pragma extern_prefix is in effect, apply it. */
597 if (pragma_extern_prefix)
41c64394 598 {
84b8b0e0
ZW
599 const char *prefix = TREE_STRING_POINTER (pragma_extern_prefix);
600 size_t plen = TREE_STRING_LENGTH (pragma_extern_prefix) - 1;
601
602 const char *id = IDENTIFIER_POINTER (DECL_NAME (decl));
603 size_t ilen = IDENTIFIER_LENGTH (DECL_NAME (decl));
c22cacf3 604
28dab132 605 char *newname = (char *) alloca (plen + ilen + 1);
84b8b0e0
ZW
606
607 memcpy (newname, prefix, plen);
608 memcpy (newname + plen, id, ilen + 1);
609
610 return build_string (plen + ilen, newname);
41c64394 611 }
41c64394 612
84b8b0e0
ZW
613 /* Nada. */
614 return 0;
41c64394
RH
615}
616
d7afec4b 617
d7afec4b
ND
618static void handle_pragma_visibility (cpp_reader *);
619
9771b263 620static vec<int> visstack;
0ed5edac
JM
621
622/* Push the visibility indicated by STR onto the top of the #pragma
9789ba46
JJ
623 visibility stack. KIND is 0 for #pragma GCC visibility, 1 for
624 C++ namespace with visibility attribute and 2 for C++ builtin
625 ABI namespace. push_visibility/pop_visibility calls must have
626 matching KIND, it is not allowed to push visibility using one
627 KIND and pop using a different one. */
0ed5edac
JM
628
629void
9789ba46 630push_visibility (const char *str, int kind)
0ed5edac 631{
9771b263 632 visstack.safe_push (((int) default_visibility) | (kind << 8));
0ed5edac
JM
633 if (!strcmp (str, "default"))
634 default_visibility = VISIBILITY_DEFAULT;
635 else if (!strcmp (str, "internal"))
636 default_visibility = VISIBILITY_INTERNAL;
637 else if (!strcmp (str, "hidden"))
c22cacf3 638 default_visibility = VISIBILITY_HIDDEN;
0ed5edac
JM
639 else if (!strcmp (str, "protected"))
640 default_visibility = VISIBILITY_PROTECTED;
641 else
642 GCC_BAD ("#pragma GCC visibility push() must specify default, internal, hidden or protected");
643 visibility_options.inpragma = 1;
644}
645
9789ba46
JJ
646/* Pop a level of the #pragma visibility stack. Return true if
647 successful. */
0ed5edac 648
9789ba46
JJ
649bool
650pop_visibility (int kind)
0ed5edac 651{
9771b263 652 if (!visstack.length ())
9789ba46 653 return false;
9771b263 654 if ((visstack.last () >> 8) != kind)
9789ba46
JJ
655 return false;
656 default_visibility
9771b263 657 = (enum symbol_visibility) (visstack.pop () & 0xff);
0ed5edac 658 visibility_options.inpragma
9771b263 659 = visstack.length () != 0;
9789ba46 660 return true;
c22cacf3 661}
be1b1c9b 662
d7afec4b
ND
663/* Sets the default visibility for symbols to something other than that
664 specified on the command line. */
0ed5edac 665
d7afec4b
ND
666static void
667handle_pragma_visibility (cpp_reader *dummy ATTRIBUTE_UNUSED)
be1b1c9b
L
668{
669 /* Form is #pragma GCC visibility push(hidden)|pop */
d7afec4b
ND
670 tree x;
671 enum cpp_ttype token;
672 enum { bad, push, pop } action = bad;
c22cacf3 673
75ce3d48 674 token = pragma_lex (&x);
d7afec4b
ND
675 if (token == CPP_NAME)
676 {
677 const char *op = IDENTIFIER_POINTER (x);
678 if (!strcmp (op, "push"))
c22cacf3 679 action = push;
d7afec4b 680 else if (!strcmp (op, "pop"))
c22cacf3 681 action = pop;
d7afec4b
ND
682 }
683 if (bad == action)
684 GCC_BAD ("#pragma GCC visibility must be followed by push or pop");
685 else
686 {
687 if (pop == action)
c22cacf3 688 {
9789ba46 689 if (! pop_visibility (0))
0ed5edac 690 GCC_BAD ("no matching push for %<#pragma GCC visibility pop%>");
c22cacf3 691 }
d7afec4b 692 else
c22cacf3
MS
693 {
694 if (pragma_lex (&x) != CPP_OPEN_PAREN)
695 GCC_BAD ("missing %<(%> after %<#pragma GCC visibility push%> - ignored");
696 token = pragma_lex (&x);
697 if (token != CPP_NAME)
0ed5edac 698 GCC_BAD ("malformed #pragma GCC visibility push");
c22cacf3 699 else
9789ba46 700 push_visibility (IDENTIFIER_POINTER (x), 0);
c22cacf3
MS
701 if (pragma_lex (&x) != CPP_CLOSE_PAREN)
702 GCC_BAD ("missing %<(%> after %<#pragma GCC visibility push%> - ignored");
703 }
d7afec4b 704 }
75ce3d48 705 if (pragma_lex (&x) != CPP_EOF)
b9b8dde3 706 warning (OPT_Wpragmas, "junk at end of %<#pragma GCC visibility%>");
d7afec4b
ND
707}
708
79cf5994
DD
709static void
710handle_pragma_diagnostic(cpp_reader *ARG_UNUSED(dummy))
711{
712 const char *kind_string, *option_string;
713 unsigned int option_index;
714 enum cpp_ttype token;
715 diagnostic_t kind;
716 tree x;
c5fa0890 717 struct cl_option_handlers handlers;
79cf5994 718
79cf5994
DD
719 token = pragma_lex (&x);
720 if (token != CPP_NAME)
721 GCC_BAD ("missing [error|warning|ignored] after %<#pragma GCC diagnostic%>");
722 kind_string = IDENTIFIER_POINTER (x);
723 if (strcmp (kind_string, "error") == 0)
724 kind = DK_ERROR;
725 else if (strcmp (kind_string, "warning") == 0)
726 kind = DK_WARNING;
727 else if (strcmp (kind_string, "ignored") == 0)
728 kind = DK_IGNORED;
cd7fe53b
DD
729 else if (strcmp (kind_string, "push") == 0)
730 {
731 diagnostic_push_diagnostics (global_dc, input_location);
732 return;
733 }
734 else if (strcmp (kind_string, "pop") == 0)
735 {
736 diagnostic_pop_diagnostics (global_dc, input_location);
737 return;
738 }
79cf5994 739 else
cd7fe53b 740 GCC_BAD ("expected [error|warning|ignored|push|pop] after %<#pragma GCC diagnostic%>");
79cf5994
DD
741
742 token = pragma_lex (&x);
743 if (token != CPP_STRING)
744 GCC_BAD ("missing option after %<#pragma GCC diagnostic%> kind");
745 option_string = TREE_STRING_POINTER (x);
c5fa0890 746 set_default_handlers (&handlers);
79cf5994
DD
747 for (option_index = 0; option_index < cl_options_count; option_index++)
748 if (strcmp (cl_options[option_index].opt_text, option_string) == 0)
749 {
c5fa0890
JM
750 control_warning_option (option_index, (int) kind, kind != DK_IGNORED,
751 input_location, c_family_lang_mask, &handlers,
752 &global_options, &global_options_set,
753 global_dc);
79cf5994
DD
754 return;
755 }
756 GCC_BAD ("unknown option after %<#pragma GCC diagnostic%> kind");
757}
758
5779e713 759/* Parse #pragma GCC target (xxx) to set target specific options. */
ab442df7 760static void
5779e713 761handle_pragma_target(cpp_reader *ARG_UNUSED(dummy))
ab442df7
MM
762{
763 enum cpp_ttype token;
ab442df7
MM
764 tree x;
765 bool close_paren_needed_p = false;
766
767 if (cfun)
768 {
769 error ("#pragma GCC option is not allowed inside functions");
770 return;
771 }
772
ab442df7
MM
773 token = pragma_lex (&x);
774 if (token == CPP_OPEN_PAREN)
775 {
776 close_paren_needed_p = true;
777 token = pragma_lex (&x);
778 }
779
5779e713 780 if (token != CPP_STRING)
ab442df7 781 {
5779e713 782 GCC_BAD ("%<#pragma GCC option%> is not a string");
ab442df7
MM
783 return;
784 }
785
786 /* Strings are user options. */
787 else
788 {
789 tree args = NULL_TREE;
790
791 do
792 {
793 /* Build up the strings now as a tree linked list. Skip empty
794 strings. */
795 if (TREE_STRING_LENGTH (x) > 0)
796 args = tree_cons (NULL_TREE, x, args);
797
798 token = pragma_lex (&x);
799 while (token == CPP_COMMA)
800 token = pragma_lex (&x);
801 }
802 while (token == CPP_STRING);
803
804 if (close_paren_needed_p)
805 {
806 if (token == CPP_CLOSE_PAREN)
807 token = pragma_lex (&x);
808 else
5779e713 809 GCC_BAD ("%<#pragma GCC target (string [,string]...)%> does "
d8a07487 810 "not have a final %<)%>");
ab442df7
MM
811 }
812
813 if (token != CPP_EOF)
814 {
5779e713 815 error ("#pragma GCC target string... is badly formed");
ab442df7
MM
816 return;
817 }
818
819 /* put arguments in the order the user typed them. */
820 args = nreverse (args);
821
5779e713
MM
822 if (targetm.target_option.pragma_parse (args, NULL_TREE))
823 current_target_pragma = args;
ab442df7
MM
824 }
825}
826
ab442df7
MM
827/* Handle #pragma GCC optimize to set optimization options. */
828static void
5779e713 829handle_pragma_optimize (cpp_reader *ARG_UNUSED(dummy))
ab442df7
MM
830{
831 enum cpp_ttype token;
ab442df7
MM
832 tree x;
833 bool close_paren_needed_p = false;
834 tree optimization_previous_node = optimization_current_node;
835
836 if (cfun)
837 {
838 error ("#pragma GCC optimize is not allowed inside functions");
839 return;
840 }
841
842 token = pragma_lex (&x);
843 if (token == CPP_OPEN_PAREN)
844 {
845 close_paren_needed_p = true;
846 token = pragma_lex (&x);
847 }
848
5779e713 849 if (token != CPP_STRING && token != CPP_NUMBER)
ab442df7 850 {
5779e713 851 GCC_BAD ("%<#pragma GCC optimize%> is not a string or number");
ab442df7
MM
852 return;
853 }
854
855 /* Strings/numbers are user options. */
856 else
857 {
858 tree args = NULL_TREE;
859
860 do
861 {
862 /* Build up the numbers/strings now as a list. */
863 if (token != CPP_STRING || TREE_STRING_LENGTH (x) > 0)
864 args = tree_cons (NULL_TREE, x, args);
865
866 token = pragma_lex (&x);
867 while (token == CPP_COMMA)
868 token = pragma_lex (&x);
869 }
870 while (token == CPP_STRING || token == CPP_NUMBER);
871
872 if (close_paren_needed_p)
873 {
874 if (token == CPP_CLOSE_PAREN)
875 token = pragma_lex (&x);
876 else
877 GCC_BAD ("%<#pragma GCC optimize (string [,string]...)%> does "
d8a07487 878 "not have a final %<)%>");
ab442df7
MM
879 }
880
881 if (token != CPP_EOF)
882 {
883 error ("#pragma GCC optimize string... is badly formed");
884 return;
885 }
886
887 /* put arguments in the order the user typed them. */
888 args = nreverse (args);
889
890 parse_optimize_options (args, false);
5779e713 891 current_optimize_pragma = chainon (current_optimize_pragma, args);
bf7b5747 892 optimization_current_node = build_optimization_node (&global_options);
ab442df7
MM
893 c_cpp_builtins_optimize_pragma (parse_in,
894 optimization_previous_node,
895 optimization_current_node);
896 }
897}
898
5779e713
MM
899/* Stack of the #pragma GCC options created with #pragma GCC push_option. Save
900 both the binary representation of the options and the TREE_LIST of
901 strings that will be added to the function's attribute list. */
d1b38208 902typedef struct GTY(()) opt_stack {
5779e713
MM
903 struct opt_stack *prev;
904 tree target_binary;
905 tree target_strings;
906 tree optimize_binary;
907 tree optimize_strings;
908} opt_stack;
909
910static GTY(()) struct opt_stack * options_stack;
911
912/* Handle #pragma GCC push_options to save the current target and optimization
913 options. */
914
915static void
916handle_pragma_push_options (cpp_reader *ARG_UNUSED(dummy))
917{
918 enum cpp_ttype token;
919 tree x = 0;
5779e713
MM
920
921 token = pragma_lex (&x);
922 if (token != CPP_EOF)
923 {
924 warning (OPT_Wpragmas, "junk at end of %<#pragma push_options%>");
925 return;
926 }
927
766090c2 928 opt_stack *p = ggc_alloc<opt_stack> ();
5779e713
MM
929 p->prev = options_stack;
930 options_stack = p;
931
932 /* Save optimization and target flags in binary format. */
bf7b5747
ST
933 p->optimize_binary = build_optimization_node (&global_options);
934 p->target_binary = build_target_option_node (&global_options);
5779e713
MM
935
936 /* Save optimization and target flags in string list format. */
937 p->optimize_strings = copy_list (current_optimize_pragma);
938 p->target_strings = copy_list (current_target_pragma);
939}
940
941/* Handle #pragma GCC pop_options to restore the current target and
942 optimization options from a previous push_options. */
943
944static void
945handle_pragma_pop_options (cpp_reader *ARG_UNUSED(dummy))
946{
947 enum cpp_ttype token;
948 tree x = 0;
949 opt_stack *p;
950
951 token = pragma_lex (&x);
952 if (token != CPP_EOF)
953 {
954 warning (OPT_Wpragmas, "junk at end of %<#pragma pop_options%>");
955 return;
956 }
957
958 if (! options_stack)
959 {
960 warning (OPT_Wpragmas,
961 "%<#pragma GCC pop_options%> without a corresponding "
962 "%<#pragma GCC push_options%>");
963 return;
964 }
965
966 p = options_stack;
967 options_stack = p->prev;
968
969 if (p->target_binary != target_option_current_node)
970 {
971 (void) targetm.target_option.pragma_parse (NULL_TREE, p->target_binary);
972 target_option_current_node = p->target_binary;
973 }
974
975 if (p->optimize_binary != optimization_current_node)
976 {
977 tree old_optimize = optimization_current_node;
46625112
JM
978 cl_optimization_restore (&global_options,
979 TREE_OPTIMIZATION (p->optimize_binary));
5779e713
MM
980 c_cpp_builtins_optimize_pragma (parse_in, old_optimize,
981 p->optimize_binary);
982 optimization_current_node = p->optimize_binary;
983 }
984
985 current_target_pragma = p->target_strings;
986 current_optimize_pragma = p->optimize_strings;
987}
988
989/* Handle #pragma GCC reset_options to restore the current target and
990 optimization options to the original options used on the command line. */
991
992static void
993handle_pragma_reset_options (cpp_reader *ARG_UNUSED(dummy))
994{
995 enum cpp_ttype token;
996 tree x = 0;
997 tree new_optimize = optimization_default_node;
998 tree new_target = target_option_default_node;
999
1000 token = pragma_lex (&x);
1001 if (token != CPP_EOF)
1002 {
1003 warning (OPT_Wpragmas, "junk at end of %<#pragma reset_options%>");
1004 return;
1005 }
1006
1007 if (new_target != target_option_current_node)
1008 {
1009 (void) targetm.target_option.pragma_parse (NULL_TREE, new_target);
1010 target_option_current_node = new_target;
1011 }
1012
1013 if (new_optimize != optimization_current_node)
1014 {
1015 tree old_optimize = optimization_current_node;
46625112
JM
1016 cl_optimization_restore (&global_options,
1017 TREE_OPTIMIZATION (new_optimize));
5779e713
MM
1018 c_cpp_builtins_optimize_pragma (parse_in, old_optimize, new_optimize);
1019 optimization_current_node = new_optimize;
1020 }
1021
1022 current_target_pragma = NULL_TREE;
1023 current_optimize_pragma = NULL_TREE;
1024}
1025
0d48657d
SB
1026/* Print a plain user-specified message. */
1027
1028static void
1029handle_pragma_message (cpp_reader *ARG_UNUSED(dummy))
1030{
1031 enum cpp_ttype token;
1032 tree x, message = 0;
1033
1034 token = pragma_lex (&x);
1035 if (token == CPP_OPEN_PAREN)
1036 {
1037 token = pragma_lex (&x);
1038 if (token == CPP_STRING)
1039 message = x;
1040 else
1041 GCC_BAD ("expected a string after %<#pragma message%>");
1042 if (pragma_lex (&x) != CPP_CLOSE_PAREN)
1043 GCC_BAD ("malformed %<#pragma message%>, ignored");
1044 }
1045 else if (token == CPP_STRING)
1046 message = x;
1047 else
1048 GCC_BAD ("expected a string after %<#pragma message%>");
1049
1050 gcc_assert (message);
1051
1052 if (pragma_lex (&x) != CPP_EOF)
1053 warning (OPT_Wpragmas, "junk at end of %<#pragma message%>");
1054
1055 if (TREE_STRING_LENGTH (message) > 1)
1f5b3869 1056 inform (input_location, "#pragma message: %s", TREE_STRING_POINTER (message));
0d48657d
SB
1057}
1058
6ec637a4
JJ
1059/* Mark whether the current location is valid for a STDC pragma. */
1060
1061static bool valid_location_for_stdc_pragma;
1062
1063void
1064mark_valid_location_for_stdc_pragma (bool flag)
1065{
1066 valid_location_for_stdc_pragma = flag;
1067}
1068
1069/* Return true if the current location is valid for a STDC pragma. */
1070
1071bool
1072valid_location_for_stdc_pragma_p (void)
1073{
1074 return valid_location_for_stdc_pragma;
1075}
1076
7de1d221 1077enum pragma_switch_t { PRAGMA_ON, PRAGMA_OFF, PRAGMA_DEFAULT, PRAGMA_BAD };
6ec637a4
JJ
1078
1079/* A STDC pragma must appear outside of external declarations or
1080 preceding all explicit declarations and statements inside a compound
1081 statement; its behavior is undefined if used in any other context.
1082 It takes a switch of ON, OFF, or DEFAULT. */
1083
1084static enum pragma_switch_t
1085handle_stdc_pragma (const char *pname)
1086{
1087 const char *arg;
1088 tree t;
1089 enum pragma_switch_t ret;
1090
1091 if (!valid_location_for_stdc_pragma_p ())
1092 {
1093 warning (OPT_Wpragmas, "invalid location for %<pragma %s%>, ignored",
1094 pname);
7de1d221 1095 return PRAGMA_BAD;
6ec637a4
JJ
1096 }
1097
1098 if (pragma_lex (&t) != CPP_NAME)
1099 {
1100 warning (OPT_Wpragmas, "malformed %<#pragma %s%>, ignored", pname);
7de1d221 1101 return PRAGMA_BAD;
6ec637a4
JJ
1102 }
1103
1104 arg = IDENTIFIER_POINTER (t);
1105
1106 if (!strcmp (arg, "ON"))
7de1d221 1107 ret = PRAGMA_ON;
6ec637a4 1108 else if (!strcmp (arg, "OFF"))
7de1d221 1109 ret = PRAGMA_OFF;
6ec637a4 1110 else if (!strcmp (arg, "DEFAULT"))
7de1d221 1111 ret = PRAGMA_DEFAULT;
6ec637a4
JJ
1112 else
1113 {
1114 warning (OPT_Wpragmas, "malformed %<#pragma %s%>, ignored", pname);
7de1d221 1115 return PRAGMA_BAD;
6ec637a4
JJ
1116 }
1117
1118 if (pragma_lex (&t) != CPP_EOF)
1119 {
1120 warning (OPT_Wpragmas, "junk at end of %<#pragma %s%>", pname);
7de1d221 1121 return PRAGMA_BAD;
6ec637a4
JJ
1122 }
1123
1124 return ret;
1125}
1126
1127/* #pragma STDC FLOAT_CONST_DECIMAL64 ON
1128 #pragma STDC FLOAT_CONST_DECIMAL64 OFF
1129 #pragma STDC FLOAT_CONST_DECIMAL64 DEFAULT */
1130
1131static void
1132handle_pragma_float_const_decimal64 (cpp_reader *ARG_UNUSED (dummy))
1133{
1134 if (c_dialect_cxx ())
1135 {
8400e75e 1136 if (warn_unknown_pragmas > in_system_header_at (input_location))
6ec637a4
JJ
1137 warning (OPT_Wunknown_pragmas,
1138 "%<#pragma STDC FLOAT_CONST_DECIMAL64%> is not supported"
1139 " for C++");
1140 return;
1141 }
1142
1143 if (!targetm.decimal_float_supported_p ())
1144 {
8400e75e 1145 if (warn_unknown_pragmas > in_system_header_at (input_location))
6ec637a4
JJ
1146 warning (OPT_Wunknown_pragmas,
1147 "%<#pragma STDC FLOAT_CONST_DECIMAL64%> is not supported"
1148 " on this target");
1149 return;
1150 }
1151
c1771a20 1152 pedwarn (input_location, OPT_Wpedantic,
6ec637a4
JJ
1153 "ISO C does not support %<#pragma STDC FLOAT_CONST_DECIMAL64%>");
1154
1155 switch (handle_stdc_pragma ("STDC FLOAT_CONST_DECIMAL64"))
1156 {
7de1d221 1157 case PRAGMA_ON:
6ec637a4
JJ
1158 set_float_const_decimal64 ();
1159 break;
7de1d221
JJ
1160 case PRAGMA_OFF:
1161 case PRAGMA_DEFAULT:
6ec637a4
JJ
1162 clear_float_const_decimal64 ();
1163 break;
7de1d221 1164 case PRAGMA_BAD:
6ec637a4
JJ
1165 break;
1166 }
1167}
1168
dfb43cd5 1169/* A vector of registered pragma callbacks, which is never freed. */
bc4071dd 1170
9771b263 1171static vec<internal_pragma_handler> registered_pragmas;
bc4071dd 1172
a25a8f3b
JJ
1173typedef struct
1174{
1175 const char *space;
1176 const char *name;
1177} pragma_ns_name;
1178
a25a8f3b 1179
9771b263 1180static vec<pragma_ns_name> registered_pp_pragmas;
a25a8f3b
JJ
1181
1182struct omp_pragma_def { const char *name; unsigned int id; };
1183static const struct omp_pragma_def omp_pragmas[] = {
1184 { "atomic", PRAGMA_OMP_ATOMIC },
1185 { "barrier", PRAGMA_OMP_BARRIER },
acf0174b
JJ
1186 { "cancel", PRAGMA_OMP_CANCEL },
1187 { "cancellation", PRAGMA_OMP_CANCELLATION_POINT },
a25a8f3b 1188 { "critical", PRAGMA_OMP_CRITICAL },
acf0174b 1189 { "end", PRAGMA_OMP_END_DECLARE_TARGET },
a25a8f3b 1190 { "flush", PRAGMA_OMP_FLUSH },
a25a8f3b
JJ
1191 { "master", PRAGMA_OMP_MASTER },
1192 { "ordered", PRAGMA_OMP_ORDERED },
a25a8f3b
JJ
1193 { "section", PRAGMA_OMP_SECTION },
1194 { "sections", PRAGMA_OMP_SECTIONS },
1195 { "single", PRAGMA_OMP_SINGLE },
92d28cbb 1196 { "task", PRAGMA_OMP_TASK },
acf0174b 1197 { "taskgroup", PRAGMA_OMP_TASKGROUP },
a68ab351 1198 { "taskwait", PRAGMA_OMP_TASKWAIT },
20906c66 1199 { "taskyield", PRAGMA_OMP_TASKYIELD },
a25a8f3b
JJ
1200 { "threadprivate", PRAGMA_OMP_THREADPRIVATE }
1201};
6d7f7e0a
TB
1202static const struct omp_pragma_def omp_pragmas_simd[] = {
1203 { "declare", PRAGMA_OMP_DECLARE_REDUCTION },
1204 { "distribute", PRAGMA_OMP_DISTRIBUTE },
1205 { "for", PRAGMA_OMP_FOR },
1206 { "parallel", PRAGMA_OMP_PARALLEL },
1207 { "simd", PRAGMA_OMP_SIMD },
1208 { "target", PRAGMA_OMP_TARGET },
6d7f7e0a
TB
1209 { "teams", PRAGMA_OMP_TEAMS },
1210};
a25a8f3b
JJ
1211
1212void
1213c_pp_lookup_pragma (unsigned int id, const char **space, const char **name)
1214{
1215 const int n_omp_pragmas = sizeof (omp_pragmas) / sizeof (*omp_pragmas);
6d7f7e0a
TB
1216 const int n_omp_pragmas_simd = sizeof (omp_pragmas_simd)
1217 / sizeof (*omp_pragmas);
a25a8f3b
JJ
1218 int i;
1219
1220 for (i = 0; i < n_omp_pragmas; ++i)
1221 if (omp_pragmas[i].id == id)
1222 {
1223 *space = "omp";
1224 *name = omp_pragmas[i].name;
1225 return;
1226 }
1227
6d7f7e0a
TB
1228 for (i = 0; i < n_omp_pragmas_simd; ++i)
1229 if (omp_pragmas_simd[i].id == id)
1230 {
1231 *space = "omp";
1232 *name = omp_pragmas_simd[i].name;
1233 return;
1234 }
1235
b3bdf019
JJ
1236 if (id == PRAGMA_CILK_SIMD)
1237 {
1238 *space = NULL;
1239 *name = "simd";
1240 return;
1241 }
1242
a25a8f3b 1243 if (id >= PRAGMA_FIRST_EXTERNAL
9771b263 1244 && (id < PRAGMA_FIRST_EXTERNAL + registered_pp_pragmas.length ()))
a25a8f3b 1245 {
9771b263
DN
1246 *space = registered_pp_pragmas[id - PRAGMA_FIRST_EXTERNAL].space;
1247 *name = registered_pp_pragmas[id - PRAGMA_FIRST_EXTERNAL].name;
a25a8f3b
JJ
1248 return;
1249 }
1250
1251 gcc_unreachable ();
1252}
1253
b5b3e36a 1254/* Front-end wrappers for pragma registration to avoid dragging
c58b209a 1255 cpplib.h in almost everywhere. */
bc4071dd
RH
1256
1257static void
1258c_register_pragma_1 (const char *space, const char *name,
dfb43cd5 1259 internal_pragma_handler ihandler, bool allow_expansion)
bc4071dd
RH
1260{
1261 unsigned id;
1262
a25a8f3b
JJ
1263 if (flag_preprocess_only)
1264 {
1265 pragma_ns_name ns_name;
bc4071dd 1266
a25a8f3b
JJ
1267 if (!allow_expansion)
1268 return;
1269
1270 ns_name.space = space;
1271 ns_name.name = name;
9771b263
DN
1272 registered_pp_pragmas.safe_push (ns_name);
1273 id = registered_pp_pragmas.length ();
a25a8f3b
JJ
1274 id += PRAGMA_FIRST_EXTERNAL - 1;
1275 }
1276 else
1277 {
9771b263
DN
1278 registered_pragmas.safe_push (ihandler);
1279 id = registered_pragmas.length ();
a25a8f3b
JJ
1280 id += PRAGMA_FIRST_EXTERNAL - 1;
1281
1282 /* The C++ front end allocates 6 bits in cp_token; the C front end
1283 allocates 7 bits in c_token. At present this is sufficient. */
1284 gcc_assert (id < 64);
1285 }
bc4071dd
RH
1286
1287 cpp_register_deferred_pragma (parse_in, space, name, id,
1288 allow_expansion, false);
1289}
1290
dfb43cd5
PV
1291/* Register a C pragma handler, using a space and a name. It disallows pragma
1292 expansion (if you want it, use c_register_pragma_with_expansion instead). */
1293void
1294c_register_pragma (const char *space, const char *name,
1295 pragma_handler_1arg handler)
1296{
1297 internal_pragma_handler ihandler;
1298
1299 ihandler.handler.handler_1arg = handler;
1300 ihandler.extra_data = false;
1301 ihandler.data = NULL;
1302 c_register_pragma_1 (space, name, ihandler, false);
1303}
1304
1305/* Register a C pragma handler, using a space and a name, it also carries an
1306 extra data field which can be used by the handler. It disallows pragma
1307 expansion (if you want it, use c_register_pragma_with_expansion_and_data
1308 instead). */
c58b209a 1309void
dfb43cd5
PV
1310c_register_pragma_with_data (const char *space, const char *name,
1311 pragma_handler_2arg handler, void * data)
c58b209a 1312{
dfb43cd5
PV
1313 internal_pragma_handler ihandler;
1314
1315 ihandler.handler.handler_2arg = handler;
1316 ihandler.extra_data = true;
1317 ihandler.data = data;
1318 c_register_pragma_1 (space, name, ihandler, false);
b5b3e36a
DJ
1319}
1320
dfb43cd5
PV
1321/* Register a C pragma handler, using a space and a name. It allows pragma
1322 expansion as in the following example:
1323
1324 #define NUMBER 10
1325 #pragma count (NUMBER)
1326
1327 Name expansion is still disallowed. */
b5b3e36a
DJ
1328void
1329c_register_pragma_with_expansion (const char *space, const char *name,
dfb43cd5 1330 pragma_handler_1arg handler)
bc4071dd 1331{
dfb43cd5
PV
1332 internal_pragma_handler ihandler;
1333
1334 ihandler.handler.handler_1arg = handler;
1335 ihandler.extra_data = false;
1336 ihandler.data = NULL;
1337 c_register_pragma_1 (space, name, ihandler, true);
1338}
1339
1340/* Register a C pragma handler, using a space and a name, it also carries an
1341 extra data field which can be used by the handler. It allows pragma
1342 expansion as in the following example:
1343
1344 #define NUMBER 10
1345 #pragma count (NUMBER)
1346
1347 Name expansion is still disallowed. */
1348void
1349c_register_pragma_with_expansion_and_data (const char *space, const char *name,
1350 pragma_handler_2arg handler,
1351 void *data)
1352{
1353 internal_pragma_handler ihandler;
1354
1355 ihandler.handler.handler_2arg = handler;
1356 ihandler.extra_data = true;
1357 ihandler.data = data;
1358 c_register_pragma_1 (space, name, ihandler, true);
bc4071dd
RH
1359}
1360
1361void
1362c_invoke_pragma_handler (unsigned int id)
b5b3e36a 1363{
dfb43cd5
PV
1364 internal_pragma_handler *ihandler;
1365 pragma_handler_1arg handler_1arg;
1366 pragma_handler_2arg handler_2arg;
bc4071dd
RH
1367
1368 id -= PRAGMA_FIRST_EXTERNAL;
9771b263 1369 ihandler = &registered_pragmas[id];
dfb43cd5
PV
1370 if (ihandler->extra_data)
1371 {
1372 handler_2arg = ihandler->handler.handler_2arg;
1373 handler_2arg (parse_in, ihandler->data);
1374 }
1375 else
1376 {
1377 handler_1arg = ihandler->handler.handler_1arg;
1378 handler_1arg (parse_in);
1379 }
c58b209a
NB
1380}
1381
1382/* Set up front-end pragmas. */
568767a6 1383void
35b1a6fa 1384init_pragma (void)
568767a6 1385{
a25a8f3b 1386 if (flag_openmp)
953ff289 1387 {
953ff289
DN
1388 const int n_omp_pragmas = sizeof (omp_pragmas) / sizeof (*omp_pragmas);
1389 int i;
1390
1391 for (i = 0; i < n_omp_pragmas; ++i)
1392 cpp_register_deferred_pragma (parse_in, "omp", omp_pragmas[i].name,
1393 omp_pragmas[i].id, true, true);
1394 }
6d7f7e0a
TB
1395 if (flag_openmp || flag_openmp_simd)
1396 {
1397 const int n_omp_pragmas_simd = sizeof (omp_pragmas_simd)
1398 / sizeof (*omp_pragmas);
1399 int i;
1400
1401 for (i = 0; i < n_omp_pragmas_simd; ++i)
1402 cpp_register_deferred_pragma (parse_in, "omp", omp_pragmas_simd[i].name,
1403 omp_pragmas_simd[i].id, true, true);
1404 }
953ff289 1405
b3bdf019 1406 if (flag_cilkplus)
c02065fc
AH
1407 cpp_register_deferred_pragma (parse_in, NULL, "simd", PRAGMA_CILK_SIMD,
1408 true, false);
1409
a25a8f3b
JJ
1410 if (!flag_preprocess_only)
1411 cpp_register_deferred_pragma (parse_in, "GCC", "pch_preprocess",
1412 PRAGMA_GCC_PCH_PREPROCESS, false, false);
bc4071dd 1413
28e41874
JJ
1414 if (!flag_preprocess_only)
1415 cpp_register_deferred_pragma (parse_in, "GCC", "ivdep", PRAGMA_IVDEP, false,
1416 false);
9a771876
JJ
1417
1418 if (flag_cilkplus && !flag_preprocess_only)
1419 cpp_register_deferred_pragma (parse_in, "cilk", "grainsize",
1420 PRAGMA_CILK_GRAINSIZE, true, false);
1421
b5b3e36a
DJ
1422#ifdef HANDLE_PRAGMA_PACK_WITH_EXPANSION
1423 c_register_pragma_with_expansion (0, "pack", handle_pragma_pack);
1424#else
c58b209a 1425 c_register_pragma (0, "pack", handle_pragma_pack);
0e5921e8 1426#endif
c58b209a 1427 c_register_pragma (0, "weak", handle_pragma_weak);
d7afec4b 1428 c_register_pragma ("GCC", "visibility", handle_pragma_visibility);
84b8b0e0 1429
79cf5994 1430 c_register_pragma ("GCC", "diagnostic", handle_pragma_diagnostic);
5779e713 1431 c_register_pragma ("GCC", "target", handle_pragma_target);
ab442df7 1432 c_register_pragma ("GCC", "optimize", handle_pragma_optimize);
5779e713
MM
1433 c_register_pragma ("GCC", "push_options", handle_pragma_push_options);
1434 c_register_pragma ("GCC", "pop_options", handle_pragma_pop_options);
1435 c_register_pragma ("GCC", "reset_options", handle_pragma_reset_options);
79cf5994 1436
6ec637a4
JJ
1437 c_register_pragma ("STDC", "FLOAT_CONST_DECIMAL64",
1438 handle_pragma_float_const_decimal64);
1439
dfb43cd5
PV
1440 c_register_pragma_with_expansion (0, "redefine_extname",
1441 handle_pragma_redefine_extname);
41c64394 1442
0d48657d
SB
1443 c_register_pragma_with_expansion (0, "message", handle_pragma_message);
1444
8b97c5f8 1445#ifdef REGISTER_TARGET_PRAGMAS
c58b209a 1446 REGISTER_TARGET_PRAGMAS ();
8b97c5f8 1447#endif
7ac8318c
BS
1448
1449 /* Allow plugins to register their own pragmas. */
1450 invoke_plugin_callbacks (PLUGIN_PRAGMAS, NULL);
568767a6 1451}
e2500fed 1452
39dabefd 1453#include "gt-c-family-c-pragma.h"
This page took 3.576158 seconds and 5 git commands to generate.