Merge trunk version 214779 into gupc branch.
[official-gcc.git] / gcc / c-family / c-pragma.c
blob688fa3727baf98979063323f22e63373449bf399
1 /* Handle #pragma, system V.4 style. Supports #pragma weak and #pragma pack.
2 Copyright (C) 1992-2014 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #include "config.h"
21 #include "system.h"
22 #include "coretypes.h"
23 #include "tm.h"
24 #include "tree.h"
25 #include "stringpool.h"
26 #include "attribs.h"
27 #include "varasm.h"
28 #include "function.h" /* For cfun. FIXME: Does the parser know
29 when it is inside a function, so that
30 we don't have to look at cfun? */
31 #include "cpplib.h"
32 #include "c-pragma.h"
33 #include "flags.h"
34 #include "langhooks.h"
35 #include "c-common.h"
36 #include "c-upc.h"
37 #include "tm_p.h" /* For REGISTER_TARGET_PRAGMAS (why is
38 this not a target hook?). */
39 #include "vec.h"
40 #include "target.h"
41 #include "diagnostic.h"
42 #include "opts.h"
43 #include "plugin.h"
44 #include "cgraph.h"
46 #define GCC_BAD(gmsgid) \
47 do { warning (OPT_Wpragmas, gmsgid); return; } while (0)
48 #define GCC_BAD2(gmsgid, arg) \
49 do { warning (OPT_Wpragmas, gmsgid, arg); return; } while (0)
51 typedef struct GTY(()) align_stack {
52 int alignment;
53 tree id;
54 struct align_stack * prev;
55 } align_stack;
57 static GTY(()) struct align_stack * alignment_stack;
59 static void handle_pragma_pack (cpp_reader *);
61 /* If we have a "global" #pragma pack(<n>) in effect when the first
62 #pragma pack(push,<n>) is encountered, this stores the value of
63 maximum_field_alignment in effect. When the final pop_alignment()
64 happens, we restore the value to this, not to a value of 0 for
65 maximum_field_alignment. Value is in bits. */
66 static int default_alignment;
67 #define SET_GLOBAL_ALIGNMENT(ALIGN) (maximum_field_alignment = *(alignment_stack == NULL \
68 ? &default_alignment \
69 : &alignment_stack->alignment) = (ALIGN))
71 static void push_alignment (int, tree);
72 static void pop_alignment (tree);
74 /* Push an alignment value onto the stack. */
75 static void
76 push_alignment (int alignment, tree id)
78 align_stack * entry = ggc_alloc<align_stack> ();
80 entry->alignment = alignment;
81 entry->id = id;
82 entry->prev = alignment_stack;
84 /* The current value of maximum_field_alignment is not necessarily
85 0 since there may be a #pragma pack(<n>) in effect; remember it
86 so that we can restore it after the final #pragma pop(). */
87 if (alignment_stack == NULL)
88 default_alignment = maximum_field_alignment;
90 alignment_stack = entry;
92 maximum_field_alignment = alignment;
95 /* Undo a push of an alignment onto the stack. */
96 static void
97 pop_alignment (tree id)
99 align_stack * entry;
101 if (alignment_stack == NULL)
102 GCC_BAD ("#pragma pack (pop) encountered without matching #pragma pack (push)");
104 /* If we got an identifier, strip away everything above the target
105 entry so that the next step will restore the state just below it. */
106 if (id)
108 for (entry = alignment_stack; entry; entry = entry->prev)
109 if (entry->id == id)
111 alignment_stack = entry;
112 break;
114 if (entry == NULL)
115 warning (OPT_Wpragmas, "\
116 #pragma pack(pop, %E) encountered without matching #pragma pack(push, %E)"
117 , id, id);
120 entry = alignment_stack->prev;
122 maximum_field_alignment = entry ? entry->alignment : default_alignment;
124 alignment_stack = entry;
127 /* #pragma pack ()
128 #pragma pack (N)
130 #pragma pack (push)
131 #pragma pack (push, N)
132 #pragma pack (push, ID)
133 #pragma pack (push, ID, N)
134 #pragma pack (pop)
135 #pragma pack (pop, ID) */
136 static void
137 handle_pragma_pack (cpp_reader * ARG_UNUSED (dummy))
139 tree x, id = 0;
140 int align = -1;
141 enum cpp_ttype token;
142 enum { set, push, pop } action;
144 if (pragma_lex (&x) != CPP_OPEN_PAREN)
145 GCC_BAD ("missing %<(%> after %<#pragma pack%> - ignored");
147 token = pragma_lex (&x);
148 if (token == CPP_CLOSE_PAREN)
150 action = set;
151 align = initial_max_fld_align;
153 else if (token == CPP_NUMBER)
155 if (TREE_CODE (x) != INTEGER_CST)
156 GCC_BAD ("invalid constant in %<#pragma pack%> - ignored");
157 align = TREE_INT_CST_LOW (x);
158 action = set;
159 if (pragma_lex (&x) != CPP_CLOSE_PAREN)
160 GCC_BAD ("malformed %<#pragma pack%> - ignored");
162 else if (token == CPP_NAME)
164 #define GCC_BAD_ACTION do { if (action != pop) \
165 GCC_BAD ("malformed %<#pragma pack(push[, id][, <n>])%> - ignored"); \
166 else \
167 GCC_BAD ("malformed %<#pragma pack(pop[, id])%> - ignored"); \
168 } while (0)
170 const char *op = IDENTIFIER_POINTER (x);
171 if (!strcmp (op, "push"))
172 action = push;
173 else if (!strcmp (op, "pop"))
174 action = pop;
175 else
176 GCC_BAD2 ("unknown action %qE for %<#pragma pack%> - ignored", x);
178 while ((token = pragma_lex (&x)) == CPP_COMMA)
180 token = pragma_lex (&x);
181 if (token == CPP_NAME && id == 0)
183 id = x;
185 else if (token == CPP_NUMBER && action == push && align == -1)
187 if (TREE_CODE (x) != INTEGER_CST)
188 GCC_BAD ("invalid constant in %<#pragma pack%> - ignored");
189 align = TREE_INT_CST_LOW (x);
190 if (align == -1)
191 action = set;
193 else
194 GCC_BAD_ACTION;
197 if (token != CPP_CLOSE_PAREN)
198 GCC_BAD_ACTION;
199 #undef GCC_BAD_ACTION
201 else
202 GCC_BAD ("malformed %<#pragma pack%> - ignored");
204 if (pragma_lex (&x) != CPP_EOF)
205 warning (OPT_Wpragmas, "junk at end of %<#pragma pack%>");
207 if (flag_pack_struct)
208 GCC_BAD ("#pragma pack has no effect with -fpack-struct - ignored");
210 if (action != pop)
211 switch (align)
213 case 0:
214 case 1:
215 case 2:
216 case 4:
217 case 8:
218 case 16:
219 align *= BITS_PER_UNIT;
220 break;
221 case -1:
222 if (action == push)
224 align = maximum_field_alignment;
225 break;
227 default:
228 GCC_BAD2 ("alignment must be a small power of two, not %d", align);
231 switch (action)
233 case set: SET_GLOBAL_ALIGNMENT (align); break;
234 case push: push_alignment (align, id); break;
235 case pop: pop_alignment (id); break;
239 typedef struct GTY(()) pending_weak_d
241 tree name;
242 tree value;
243 } pending_weak;
246 static GTY(()) vec<pending_weak, va_gc> *pending_weaks;
248 static void apply_pragma_weak (tree, tree);
249 static void handle_pragma_weak (cpp_reader *);
251 static void
252 apply_pragma_weak (tree decl, tree value)
254 if (value)
256 value = build_string (IDENTIFIER_LENGTH (value),
257 IDENTIFIER_POINTER (value));
258 decl_attributes (&decl, build_tree_list (get_identifier ("alias"),
259 build_tree_list (NULL, value)),
263 if (SUPPORTS_WEAK && DECL_EXTERNAL (decl) && TREE_USED (decl)
264 && !DECL_WEAK (decl) /* Don't complain about a redundant #pragma. */
265 && DECL_ASSEMBLER_NAME_SET_P (decl)
266 && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
267 warning (OPT_Wpragmas, "applying #pragma weak %q+D after first use "
268 "results in unspecified behavior", decl);
270 declare_weak (decl);
273 void
274 maybe_apply_pragma_weak (tree decl)
276 tree id;
277 int i;
278 pending_weak *pe;
280 /* Avoid asking for DECL_ASSEMBLER_NAME when it's not needed. */
282 /* No weak symbols pending, take the short-cut. */
283 if (vec_safe_is_empty (pending_weaks))
284 return;
285 /* If it's not visible outside this file, it doesn't matter whether
286 it's weak. */
287 if (!DECL_EXTERNAL (decl) && !TREE_PUBLIC (decl))
288 return;
289 /* If it's not a function or a variable, it can't be weak.
290 FIXME: what kinds of things are visible outside this file but
291 aren't functions or variables? Should this be an assert instead? */
292 if (TREE_CODE (decl) != FUNCTION_DECL && TREE_CODE (decl) != VAR_DECL)
293 return;
295 if (DECL_ASSEMBLER_NAME_SET_P (decl))
296 id = DECL_ASSEMBLER_NAME (decl);
297 else
299 id = DECL_ASSEMBLER_NAME (decl);
300 SET_DECL_ASSEMBLER_NAME (decl, NULL_TREE);
303 FOR_EACH_VEC_ELT (*pending_weaks, i, pe)
304 if (id == pe->name)
306 apply_pragma_weak (decl, pe->value);
307 pending_weaks->unordered_remove (i);
308 break;
312 /* Process all "#pragma weak A = B" directives where we have not seen
313 a decl for A. */
314 void
315 maybe_apply_pending_pragma_weaks (void)
317 tree alias_id, id, decl;
318 int i;
319 pending_weak *pe;
320 symtab_node *target;
322 if (vec_safe_is_empty (pending_weaks))
323 return;
325 FOR_EACH_VEC_ELT (*pending_weaks, i, pe)
327 alias_id = pe->name;
328 id = pe->value;
330 if (id == NULL)
331 continue;
333 target = symtab_node::get_for_asmname (id);
334 decl = build_decl (UNKNOWN_LOCATION,
335 target ? TREE_CODE (target->decl) : FUNCTION_DECL,
336 alias_id, default_function_type);
338 DECL_ARTIFICIAL (decl) = 1;
339 TREE_PUBLIC (decl) = 1;
340 DECL_WEAK (decl) = 1;
341 if (TREE_CODE (decl) == VAR_DECL)
342 TREE_STATIC (decl) = 1;
343 if (!target)
345 error ("%q+D aliased to undefined symbol %qE",
346 decl, id);
347 continue;
350 assemble_alias (decl, id);
354 /* #pragma weak name [= value] */
355 static void
356 handle_pragma_weak (cpp_reader * ARG_UNUSED (dummy))
358 tree name, value, x, decl;
359 enum cpp_ttype t;
361 value = 0;
363 if (pragma_lex (&name) != CPP_NAME)
364 GCC_BAD ("malformed #pragma weak, ignored");
365 t = pragma_lex (&x);
366 if (t == CPP_EQ)
368 if (pragma_lex (&value) != CPP_NAME)
369 GCC_BAD ("malformed #pragma weak, ignored");
370 t = pragma_lex (&x);
372 if (t != CPP_EOF)
373 warning (OPT_Wpragmas, "junk at end of %<#pragma weak%>");
375 decl = identifier_global_value (name);
376 if (decl && DECL_P (decl))
378 apply_pragma_weak (decl, value);
379 if (value)
381 DECL_EXTERNAL (decl) = 0;
382 if (TREE_CODE (decl) == VAR_DECL)
383 TREE_STATIC (decl) = 1;
384 assemble_alias (decl, value);
387 else
389 pending_weak pe = {name, value};
390 vec_safe_push (pending_weaks, pe);
394 /* GCC supports two #pragma directives for renaming the external
395 symbol associated with a declaration (DECL_ASSEMBLER_NAME), for
396 compatibility with the Solaris and VMS system headers. GCC also
397 has its own notation for this, __asm__("name") annotations.
399 Corner cases of these features and their interaction:
401 1) Both pragmas silently apply only to declarations with external
402 linkage (that is, TREE_PUBLIC || DECL_EXTERNAL). Asm labels
403 do not have this restriction.
405 2) In C++, both #pragmas silently apply only to extern "C" declarations.
406 Asm labels do not have this restriction.
408 3) If any of the three ways of changing DECL_ASSEMBLER_NAME is
409 applied to a decl whose DECL_ASSEMBLER_NAME is already set, and the
410 new name is different, a warning issues and the name does not change.
412 4) The "source name" for #pragma redefine_extname is the DECL_NAME,
413 *not* the DECL_ASSEMBLER_NAME.
415 5) If #pragma extern_prefix is in effect and a declaration occurs
416 with an __asm__ name, the #pragma extern_prefix is silently
417 ignored for that declaration.
419 6) If #pragma extern_prefix and #pragma redefine_extname apply to
420 the same declaration, whichever triggered first wins, and a warning
421 is issued. (We would like to have #pragma redefine_extname always
422 win, but it can appear either before or after the declaration, and
423 if it appears afterward, we have no way of knowing whether a modified
424 DECL_ASSEMBLER_NAME is due to #pragma extern_prefix.) */
426 typedef struct GTY(()) pending_redefinition_d {
427 tree oldname;
428 tree newname;
429 } pending_redefinition;
432 static GTY(()) vec<pending_redefinition, va_gc> *pending_redefine_extname;
434 static void handle_pragma_redefine_extname (cpp_reader *);
436 /* #pragma redefine_extname oldname newname */
437 static void
438 handle_pragma_redefine_extname (cpp_reader * ARG_UNUSED (dummy))
440 tree oldname, newname, decls, x;
441 enum cpp_ttype t;
442 bool found;
444 if (pragma_lex (&oldname) != CPP_NAME)
445 GCC_BAD ("malformed #pragma redefine_extname, ignored");
446 if (pragma_lex (&newname) != CPP_NAME)
447 GCC_BAD ("malformed #pragma redefine_extname, ignored");
448 t = pragma_lex (&x);
449 if (t != CPP_EOF)
450 warning (OPT_Wpragmas, "junk at end of %<#pragma redefine_extname%>");
452 found = false;
453 for (decls = c_linkage_bindings (oldname);
454 decls; )
456 tree decl;
457 if (TREE_CODE (decls) == TREE_LIST)
459 decl = TREE_VALUE (decls);
460 decls = TREE_CHAIN (decls);
462 else
464 decl = decls;
465 decls = NULL_TREE;
468 if ((TREE_PUBLIC (decl) || DECL_EXTERNAL (decl))
469 && (TREE_CODE (decl) == FUNCTION_DECL
470 || TREE_CODE (decl) == VAR_DECL))
472 found = true;
473 if (DECL_ASSEMBLER_NAME_SET_P (decl))
475 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
476 name = targetm.strip_name_encoding (name);
478 if (strcmp (name, IDENTIFIER_POINTER (newname)))
479 warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
480 "conflict with previous rename");
482 else
483 symtab->change_decl_assembler_name (decl, newname);
487 if (!found)
488 /* We have to add this to the rename list even if there's already
489 a global value that doesn't meet the above criteria, because in
490 C++ "struct foo {...};" puts "foo" in the current namespace but
491 does *not* conflict with a subsequent declaration of a function
492 or variable foo. See g++.dg/other/pragma-re-2.C. */
493 add_to_renaming_pragma_list (oldname, newname);
496 /* This is called from here and from ia64-c.c. */
497 void
498 add_to_renaming_pragma_list (tree oldname, tree newname)
500 unsigned ix;
501 pending_redefinition *p;
503 FOR_EACH_VEC_SAFE_ELT (pending_redefine_extname, ix, p)
504 if (oldname == p->oldname)
506 if (p->newname != newname)
507 warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
508 "conflict with previous #pragma redefine_extname");
509 return;
512 pending_redefinition e = {oldname, newname};
513 vec_safe_push (pending_redefine_extname, e);
516 /* The current prefix set by #pragma extern_prefix. */
517 GTY(()) tree pragma_extern_prefix;
519 /* variables used to implement #pragma upc semantics */
520 #ifndef UPC_CMODE_STACK_INCREMENT
521 #define UPC_CMODE_STACK_INCREMENT 32
522 #endif
523 static int pragma_upc_permitted;
524 static int upc_cmode;
525 static int *upc_cmode_stack;
526 static int upc_cmode_stack_in_use;
527 static int upc_cmode_stack_allocated;
529 static void init_pragma_upc (void);
530 static void handle_pragma_upc (cpp_reader * ARG_UNUSED (dummy));
532 /* Initialize the variables used to manage the current UPC consistency
533 mode (strict/relaxed) */
535 static void
536 init_pragma_upc (void)
538 pragma_upc_permitted = 0;
539 upc_cmode = 0;
540 upc_cmode_stack = (int *) xcalloc (UPC_CMODE_STACK_INCREMENT,
541 sizeof (int));
542 upc_cmode_stack_allocated = UPC_CMODE_STACK_INCREMENT;
543 upc_cmode_stack_in_use = 0;
547 * #pragma upc strict
548 * #pragma upc relaxed
549 * #pragma upc upc_code
550 * #pragma upc c_code
552 static void
553 handle_pragma_upc (cpp_reader * ARG_UNUSED (dummy))
555 tree x;
556 enum cpp_ttype t;
557 enum upc_pragma_op {p_strict, p_relaxed, p_upc_code,
558 p_c_code, p_detect_upc, p_unknown};
559 enum upc_pragma_op upc_pragma = p_unknown;
561 t = pragma_lex (&x);
562 if (t == CPP_NAME)
564 const char *op = IDENTIFIER_POINTER (x);
565 if (!strcmp (op, "strict"))
566 upc_pragma = p_strict;
567 else if (!strcmp (op, "relaxed"))
568 upc_pragma = p_relaxed;
569 else if (!strcmp (op, "upc_code"))
570 upc_pragma = p_upc_code;
571 else if (!strcmp (op, "c_code"))
572 upc_pragma = p_c_code;
573 else if (!strcmp (op, "detect_upc"))
575 const char *detect_op;
576 upc_pragma = p_detect_upc;
577 t = pragma_lex (&x);
578 if (t != CPP_NAME)
579 GCC_BAD ("missing [suspend_insertion|resume_insertion]"
580 " after %<#pragma UPC detect_upc%>");
581 detect_op = IDENTIFIER_POINTER (x);
582 if (strcmp (detect_op, "suspend_insertion") == 0)
583 /* no action */;
584 else if (strcmp (detect_op, "resume_insertion") == 0)
585 /* no action */;
586 else
587 GCC_BAD ("expected [suspend_insertion|resume_insertion]"
588 " after %<#pragma UPC detect_upc%>");
590 else
591 GCC_BAD2 ("unknown action '%s' for '#pragma upc' - ignored", op);
593 else
594 warning (OPT_Wpragmas, "missing parameter after #pragma upc");
596 t = pragma_lex (&x);
597 if (t != CPP_EOF)
598 warning (OPT_Wpragmas, "junk at end of #pragma upc");
600 if ((upc_pragma == p_strict) || (upc_pragma == p_relaxed))
602 if (pragma_upc_permitted_p ())
604 int consistency_mode = (upc_pragma == p_strict);
605 set_upc_consistency_mode (consistency_mode);
607 else
608 warning (OPT_Wpragmas, "#pragma upc not allowed in this context");
610 else if ((upc_pragma == p_upc_code) || (upc_pragma == p_c_code))
612 flag_upc = (upc_pragma == p_upc_code);
613 lang_hooks.upc.toggle_keywords (flag_upc);
615 else if (upc_pragma == p_detect_upc)
617 /* Skip: This is a Berkeley-specific pragma that requires no action. */
621 /* Set the current setting of the UPC consistency mode
622 that is in effect. */
624 void
625 set_upc_consistency_mode (int mode)
627 upc_cmode = mode;
630 /* Return the current setting of the UPC consistency mode. */
633 get_upc_consistency_mode (void)
635 return upc_cmode;
638 /* Called from the parser just after the bracket that opens a compound
639 statement has been parsed. Set the flag that allows the pragma
640 in this context. */
642 void
643 permit_pragma_upc (void)
645 pragma_upc_permitted = 1;
648 /* Called just before the body of a compound statement is parsed.
649 Clear the flag that allows the pragma. */
651 void
652 deny_pragma_upc (void)
654 pragma_upc_permitted = 0;
657 /* A #pragma upc is permitted either at the outermost scope,
658 or directly after the bracket that opens a compound statement. */
661 pragma_upc_permitted_p (void)
663 return !current_function_decl || pragma_upc_permitted;
666 /* Called at the beginning of every compound statement.
667 Pushes the old value of the current UPC consistency mode
668 onto the stack. */
670 void
671 push_upc_consistency_mode (void)
673 if (upc_cmode_stack_in_use == upc_cmode_stack_allocated)
675 upc_cmode_stack_allocated += UPC_CMODE_STACK_INCREMENT;
676 upc_cmode_stack = (int *) xrealloc (upc_cmode_stack,
677 upc_cmode_stack_allocated * sizeof (int));
679 upc_cmode_stack[upc_cmode_stack_in_use++] = upc_cmode;
682 /* Called at the end of every compound statement.
683 Sets the current consistency mode to the previously saved value. */
685 void
686 pop_upc_consistency_mode (void)
688 if (upc_cmode_stack_in_use <= 0)
689 abort ();
690 upc_cmode = upc_cmode_stack[--upc_cmode_stack_in_use];
693 static int pragma_pupc_on;
694 static void init_pragma_pupc (void);
695 static void handle_pragma_pupc (cpp_reader *);
697 /* Pragma pupc defaults to being on */
698 static void
699 init_pragma_pupc (void)
701 pragma_pupc_on = 1;
705 get_upc_pupc_mode (void)
707 return pragma_pupc_on;
711 disable_pupc_mode (void)
713 int old_pupc = pragma_pupc_on;
714 pragma_pupc_on = 0;
715 return old_pupc;
718 void
719 set_pupc_mode (int new_pupc)
721 pragma_pupc_on = new_pupc;
725 * #pragma pupc on
726 * #pragma pupc off
728 static void
729 handle_pragma_pupc (cpp_reader *dummy ATTRIBUTE_UNUSED)
731 tree x;
732 enum cpp_ttype t;
734 t = pragma_lex(&x);
735 if (t == CPP_NAME) {
736 const char *op = IDENTIFIER_POINTER (x);
737 if (!strcmp (op, "on"))
738 pragma_pupc_on = 1;
739 else if (!strcmp (op, "off"))
740 pragma_pupc_on = 0;
741 else
742 GCC_BAD2 ("unknown action '%s' for '#pragma pupc' - ignored", op);
745 t = pragma_lex (&x);
746 if (t != CPP_EOF)
747 warning (OPT_Wpragmas, "junk at end of #pragma pupc");
750 /* Hook from the front ends to apply the results of one of the preceding
751 pragmas that rename variables. */
753 tree
754 maybe_apply_renaming_pragma (tree decl, tree asmname)
756 unsigned ix;
757 pending_redefinition *p;
759 /* The renaming pragmas are only applied to declarations with
760 external linkage. */
761 if ((TREE_CODE (decl) != FUNCTION_DECL && TREE_CODE (decl) != VAR_DECL)
762 || (!TREE_PUBLIC (decl) && !DECL_EXTERNAL (decl))
763 || !has_c_linkage (decl))
764 return asmname;
766 /* If the DECL_ASSEMBLER_NAME is already set, it does not change,
767 but we may warn about a rename that conflicts. */
768 if (DECL_ASSEMBLER_NAME_SET_P (decl))
770 const char *oldname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
771 oldname = targetm.strip_name_encoding (oldname);
773 if (asmname && strcmp (TREE_STRING_POINTER (asmname), oldname))
774 warning (OPT_Wpragmas, "asm declaration ignored due to "
775 "conflict with previous rename");
777 /* Take any pending redefine_extname off the list. */
778 FOR_EACH_VEC_SAFE_ELT (pending_redefine_extname, ix, p)
779 if (DECL_NAME (decl) == p->oldname)
781 /* Only warn if there is a conflict. */
782 if (strcmp (IDENTIFIER_POINTER (p->newname), oldname))
783 warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
784 "conflict with previous rename");
786 pending_redefine_extname->unordered_remove (ix);
787 break;
789 return 0;
792 /* Find out if we have a pending #pragma redefine_extname. */
793 FOR_EACH_VEC_SAFE_ELT (pending_redefine_extname, ix, p)
794 if (DECL_NAME (decl) == p->oldname)
796 tree newname = p->newname;
797 pending_redefine_extname->unordered_remove (ix);
799 /* If we already have an asmname, #pragma redefine_extname is
800 ignored (with a warning if it conflicts). */
801 if (asmname)
803 if (strcmp (TREE_STRING_POINTER (asmname),
804 IDENTIFIER_POINTER (newname)) != 0)
805 warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
806 "conflict with __asm__ declaration");
807 return asmname;
810 /* Otherwise we use what we've got; #pragma extern_prefix is
811 silently ignored. */
812 return build_string (IDENTIFIER_LENGTH (newname),
813 IDENTIFIER_POINTER (newname));
816 /* If we've got an asmname, #pragma extern_prefix is silently ignored. */
817 if (asmname)
818 return asmname;
820 /* If #pragma extern_prefix is in effect, apply it. */
821 if (pragma_extern_prefix)
823 const char *prefix = TREE_STRING_POINTER (pragma_extern_prefix);
824 size_t plen = TREE_STRING_LENGTH (pragma_extern_prefix) - 1;
826 const char *id = IDENTIFIER_POINTER (DECL_NAME (decl));
827 size_t ilen = IDENTIFIER_LENGTH (DECL_NAME (decl));
829 char *newname = (char *) alloca (plen + ilen + 1);
831 memcpy (newname, prefix, plen);
832 memcpy (newname + plen, id, ilen + 1);
834 return build_string (plen + ilen, newname);
837 /* Nada. */
838 return 0;
842 static void handle_pragma_visibility (cpp_reader *);
844 static vec<int> visstack;
846 /* Push the visibility indicated by STR onto the top of the #pragma
847 visibility stack. KIND is 0 for #pragma GCC visibility, 1 for
848 C++ namespace with visibility attribute and 2 for C++ builtin
849 ABI namespace. push_visibility/pop_visibility calls must have
850 matching KIND, it is not allowed to push visibility using one
851 KIND and pop using a different one. */
853 void
854 push_visibility (const char *str, int kind)
856 visstack.safe_push (((int) default_visibility) | (kind << 8));
857 if (!strcmp (str, "default"))
858 default_visibility = VISIBILITY_DEFAULT;
859 else if (!strcmp (str, "internal"))
860 default_visibility = VISIBILITY_INTERNAL;
861 else if (!strcmp (str, "hidden"))
862 default_visibility = VISIBILITY_HIDDEN;
863 else if (!strcmp (str, "protected"))
864 default_visibility = VISIBILITY_PROTECTED;
865 else
866 GCC_BAD ("#pragma GCC visibility push() must specify default, internal, hidden or protected");
867 visibility_options.inpragma = 1;
870 /* Pop a level of the #pragma visibility stack. Return true if
871 successful. */
873 bool
874 pop_visibility (int kind)
876 if (!visstack.length ())
877 return false;
878 if ((visstack.last () >> 8) != kind)
879 return false;
880 default_visibility
881 = (enum symbol_visibility) (visstack.pop () & 0xff);
882 visibility_options.inpragma
883 = visstack.length () != 0;
884 return true;
887 /* Sets the default visibility for symbols to something other than that
888 specified on the command line. */
890 static void
891 handle_pragma_visibility (cpp_reader *dummy ATTRIBUTE_UNUSED)
893 /* Form is #pragma GCC visibility push(hidden)|pop */
894 tree x;
895 enum cpp_ttype token;
896 enum { bad, push, pop } action = bad;
898 token = pragma_lex (&x);
899 if (token == CPP_NAME)
901 const char *op = IDENTIFIER_POINTER (x);
902 if (!strcmp (op, "push"))
903 action = push;
904 else if (!strcmp (op, "pop"))
905 action = pop;
907 if (bad == action)
908 GCC_BAD ("#pragma GCC visibility must be followed by push or pop");
909 else
911 if (pop == action)
913 if (! pop_visibility (0))
914 GCC_BAD ("no matching push for %<#pragma GCC visibility pop%>");
916 else
918 if (pragma_lex (&x) != CPP_OPEN_PAREN)
919 GCC_BAD ("missing %<(%> after %<#pragma GCC visibility push%> - ignored");
920 token = pragma_lex (&x);
921 if (token != CPP_NAME)
922 GCC_BAD ("malformed #pragma GCC visibility push");
923 else
924 push_visibility (IDENTIFIER_POINTER (x), 0);
925 if (pragma_lex (&x) != CPP_CLOSE_PAREN)
926 GCC_BAD ("missing %<(%> after %<#pragma GCC visibility push%> - ignored");
929 if (pragma_lex (&x) != CPP_EOF)
930 warning (OPT_Wpragmas, "junk at end of %<#pragma GCC visibility%>");
933 static void
934 handle_pragma_diagnostic(cpp_reader *ARG_UNUSED(dummy))
936 const char *kind_string, *option_string;
937 unsigned int option_index;
938 enum cpp_ttype token;
939 diagnostic_t kind;
940 tree x;
941 struct cl_option_handlers handlers;
943 token = pragma_lex (&x);
944 if (token != CPP_NAME)
945 GCC_BAD ("missing [error|warning|ignored] after %<#pragma GCC diagnostic%>");
946 kind_string = IDENTIFIER_POINTER (x);
947 if (strcmp (kind_string, "error") == 0)
948 kind = DK_ERROR;
949 else if (strcmp (kind_string, "warning") == 0)
950 kind = DK_WARNING;
951 else if (strcmp (kind_string, "ignored") == 0)
952 kind = DK_IGNORED;
953 else if (strcmp (kind_string, "push") == 0)
955 diagnostic_push_diagnostics (global_dc, input_location);
956 return;
958 else if (strcmp (kind_string, "pop") == 0)
960 diagnostic_pop_diagnostics (global_dc, input_location);
961 return;
963 else
964 GCC_BAD ("expected [error|warning|ignored|push|pop] after %<#pragma GCC diagnostic%>");
966 token = pragma_lex (&x);
967 if (token != CPP_STRING)
968 GCC_BAD ("missing option after %<#pragma GCC diagnostic%> kind");
969 option_string = TREE_STRING_POINTER (x);
970 set_default_handlers (&handlers);
971 for (option_index = 0; option_index < cl_options_count; option_index++)
972 if (strcmp (cl_options[option_index].opt_text, option_string) == 0)
974 control_warning_option (option_index, (int) kind, kind != DK_IGNORED,
975 input_location, c_family_lang_mask, &handlers,
976 &global_options, &global_options_set,
977 global_dc);
978 return;
980 GCC_BAD ("unknown option after %<#pragma GCC diagnostic%> kind");
983 /* Parse #pragma GCC target (xxx) to set target specific options. */
984 static void
985 handle_pragma_target(cpp_reader *ARG_UNUSED(dummy))
987 enum cpp_ttype token;
988 tree x;
989 bool close_paren_needed_p = false;
991 if (cfun)
993 error ("#pragma GCC option is not allowed inside functions");
994 return;
997 token = pragma_lex (&x);
998 if (token == CPP_OPEN_PAREN)
1000 close_paren_needed_p = true;
1001 token = pragma_lex (&x);
1004 if (token != CPP_STRING)
1006 GCC_BAD ("%<#pragma GCC option%> is not a string");
1007 return;
1010 /* Strings are user options. */
1011 else
1013 tree args = NULL_TREE;
1017 /* Build up the strings now as a tree linked list. Skip empty
1018 strings. */
1019 if (TREE_STRING_LENGTH (x) > 0)
1020 args = tree_cons (NULL_TREE, x, args);
1022 token = pragma_lex (&x);
1023 while (token == CPP_COMMA)
1024 token = pragma_lex (&x);
1026 while (token == CPP_STRING);
1028 if (close_paren_needed_p)
1030 if (token == CPP_CLOSE_PAREN)
1031 token = pragma_lex (&x);
1032 else
1033 GCC_BAD ("%<#pragma GCC target (string [,string]...)%> does "
1034 "not have a final %<)%>");
1037 if (token != CPP_EOF)
1039 error ("#pragma GCC target string... is badly formed");
1040 return;
1043 /* put arguments in the order the user typed them. */
1044 args = nreverse (args);
1046 if (targetm.target_option.pragma_parse (args, NULL_TREE))
1047 current_target_pragma = args;
1051 /* Handle #pragma GCC optimize to set optimization options. */
1052 static void
1053 handle_pragma_optimize (cpp_reader *ARG_UNUSED(dummy))
1055 enum cpp_ttype token;
1056 tree x;
1057 bool close_paren_needed_p = false;
1058 tree optimization_previous_node = optimization_current_node;
1060 if (cfun)
1062 error ("#pragma GCC optimize is not allowed inside functions");
1063 return;
1066 token = pragma_lex (&x);
1067 if (token == CPP_OPEN_PAREN)
1069 close_paren_needed_p = true;
1070 token = pragma_lex (&x);
1073 if (token != CPP_STRING && token != CPP_NUMBER)
1075 GCC_BAD ("%<#pragma GCC optimize%> is not a string or number");
1076 return;
1079 /* Strings/numbers are user options. */
1080 else
1082 tree args = NULL_TREE;
1086 /* Build up the numbers/strings now as a list. */
1087 if (token != CPP_STRING || TREE_STRING_LENGTH (x) > 0)
1088 args = tree_cons (NULL_TREE, x, args);
1090 token = pragma_lex (&x);
1091 while (token == CPP_COMMA)
1092 token = pragma_lex (&x);
1094 while (token == CPP_STRING || token == CPP_NUMBER);
1096 if (close_paren_needed_p)
1098 if (token == CPP_CLOSE_PAREN)
1099 token = pragma_lex (&x);
1100 else
1101 GCC_BAD ("%<#pragma GCC optimize (string [,string]...)%> does "
1102 "not have a final %<)%>");
1105 if (token != CPP_EOF)
1107 error ("#pragma GCC optimize string... is badly formed");
1108 return;
1111 /* put arguments in the order the user typed them. */
1112 args = nreverse (args);
1114 parse_optimize_options (args, false);
1115 current_optimize_pragma = chainon (current_optimize_pragma, args);
1116 optimization_current_node = build_optimization_node (&global_options);
1117 c_cpp_builtins_optimize_pragma (parse_in,
1118 optimization_previous_node,
1119 optimization_current_node);
1123 /* Stack of the #pragma GCC options created with #pragma GCC push_option. Save
1124 both the binary representation of the options and the TREE_LIST of
1125 strings that will be added to the function's attribute list. */
1126 typedef struct GTY(()) opt_stack {
1127 struct opt_stack *prev;
1128 tree target_binary;
1129 tree target_strings;
1130 tree optimize_binary;
1131 tree optimize_strings;
1132 } opt_stack;
1134 static GTY(()) struct opt_stack * options_stack;
1136 /* Handle #pragma GCC push_options to save the current target and optimization
1137 options. */
1139 static void
1140 handle_pragma_push_options (cpp_reader *ARG_UNUSED(dummy))
1142 enum cpp_ttype token;
1143 tree x = 0;
1145 token = pragma_lex (&x);
1146 if (token != CPP_EOF)
1148 warning (OPT_Wpragmas, "junk at end of %<#pragma push_options%>");
1149 return;
1152 opt_stack *p = ggc_alloc<opt_stack> ();
1153 p->prev = options_stack;
1154 options_stack = p;
1156 /* Save optimization and target flags in binary format. */
1157 p->optimize_binary = build_optimization_node (&global_options);
1158 p->target_binary = build_target_option_node (&global_options);
1160 /* Save optimization and target flags in string list format. */
1161 p->optimize_strings = copy_list (current_optimize_pragma);
1162 p->target_strings = copy_list (current_target_pragma);
1165 /* Handle #pragma GCC pop_options to restore the current target and
1166 optimization options from a previous push_options. */
1168 static void
1169 handle_pragma_pop_options (cpp_reader *ARG_UNUSED(dummy))
1171 enum cpp_ttype token;
1172 tree x = 0;
1173 opt_stack *p;
1175 token = pragma_lex (&x);
1176 if (token != CPP_EOF)
1178 warning (OPT_Wpragmas, "junk at end of %<#pragma pop_options%>");
1179 return;
1182 if (! options_stack)
1184 warning (OPT_Wpragmas,
1185 "%<#pragma GCC pop_options%> without a corresponding "
1186 "%<#pragma GCC push_options%>");
1187 return;
1190 p = options_stack;
1191 options_stack = p->prev;
1193 if (p->target_binary != target_option_current_node)
1195 (void) targetm.target_option.pragma_parse (NULL_TREE, p->target_binary);
1196 target_option_current_node = p->target_binary;
1199 if (p->optimize_binary != optimization_current_node)
1201 tree old_optimize = optimization_current_node;
1202 cl_optimization_restore (&global_options,
1203 TREE_OPTIMIZATION (p->optimize_binary));
1204 c_cpp_builtins_optimize_pragma (parse_in, old_optimize,
1205 p->optimize_binary);
1206 optimization_current_node = p->optimize_binary;
1209 current_target_pragma = p->target_strings;
1210 current_optimize_pragma = p->optimize_strings;
1213 /* Handle #pragma GCC reset_options to restore the current target and
1214 optimization options to the original options used on the command line. */
1216 static void
1217 handle_pragma_reset_options (cpp_reader *ARG_UNUSED(dummy))
1219 enum cpp_ttype token;
1220 tree x = 0;
1221 tree new_optimize = optimization_default_node;
1222 tree new_target = target_option_default_node;
1224 token = pragma_lex (&x);
1225 if (token != CPP_EOF)
1227 warning (OPT_Wpragmas, "junk at end of %<#pragma reset_options%>");
1228 return;
1231 if (new_target != target_option_current_node)
1233 (void) targetm.target_option.pragma_parse (NULL_TREE, new_target);
1234 target_option_current_node = new_target;
1237 if (new_optimize != optimization_current_node)
1239 tree old_optimize = optimization_current_node;
1240 cl_optimization_restore (&global_options,
1241 TREE_OPTIMIZATION (new_optimize));
1242 c_cpp_builtins_optimize_pragma (parse_in, old_optimize, new_optimize);
1243 optimization_current_node = new_optimize;
1246 current_target_pragma = NULL_TREE;
1247 current_optimize_pragma = NULL_TREE;
1250 /* Print a plain user-specified message. */
1252 static void
1253 handle_pragma_message (cpp_reader *ARG_UNUSED(dummy))
1255 enum cpp_ttype token;
1256 tree x, message = 0;
1258 token = pragma_lex (&x);
1259 if (token == CPP_OPEN_PAREN)
1261 token = pragma_lex (&x);
1262 if (token == CPP_STRING)
1263 message = x;
1264 else
1265 GCC_BAD ("expected a string after %<#pragma message%>");
1266 if (pragma_lex (&x) != CPP_CLOSE_PAREN)
1267 GCC_BAD ("malformed %<#pragma message%>, ignored");
1269 else if (token == CPP_STRING)
1270 message = x;
1271 else
1272 GCC_BAD ("expected a string after %<#pragma message%>");
1274 gcc_assert (message);
1276 if (pragma_lex (&x) != CPP_EOF)
1277 warning (OPT_Wpragmas, "junk at end of %<#pragma message%>");
1279 if (TREE_STRING_LENGTH (message) > 1)
1280 inform (input_location, "#pragma message: %s", TREE_STRING_POINTER (message));
1283 /* Mark whether the current location is valid for a STDC pragma. */
1285 static bool valid_location_for_stdc_pragma;
1287 void
1288 mark_valid_location_for_stdc_pragma (bool flag)
1290 valid_location_for_stdc_pragma = flag;
1293 /* Return true if the current location is valid for a STDC pragma. */
1295 bool
1296 valid_location_for_stdc_pragma_p (void)
1298 return valid_location_for_stdc_pragma;
1301 enum pragma_switch_t { PRAGMA_ON, PRAGMA_OFF, PRAGMA_DEFAULT, PRAGMA_BAD };
1303 /* A STDC pragma must appear outside of external declarations or
1304 preceding all explicit declarations and statements inside a compound
1305 statement; its behavior is undefined if used in any other context.
1306 It takes a switch of ON, OFF, or DEFAULT. */
1308 static enum pragma_switch_t
1309 handle_stdc_pragma (const char *pname)
1311 const char *arg;
1312 tree t;
1313 enum pragma_switch_t ret;
1315 if (!valid_location_for_stdc_pragma_p ())
1317 warning (OPT_Wpragmas, "invalid location for %<pragma %s%>, ignored",
1318 pname);
1319 return PRAGMA_BAD;
1322 if (pragma_lex (&t) != CPP_NAME)
1324 warning (OPT_Wpragmas, "malformed %<#pragma %s%>, ignored", pname);
1325 return PRAGMA_BAD;
1328 arg = IDENTIFIER_POINTER (t);
1330 if (!strcmp (arg, "ON"))
1331 ret = PRAGMA_ON;
1332 else if (!strcmp (arg, "OFF"))
1333 ret = PRAGMA_OFF;
1334 else if (!strcmp (arg, "DEFAULT"))
1335 ret = PRAGMA_DEFAULT;
1336 else
1338 warning (OPT_Wpragmas, "malformed %<#pragma %s%>, ignored", pname);
1339 return PRAGMA_BAD;
1342 if (pragma_lex (&t) != CPP_EOF)
1344 warning (OPT_Wpragmas, "junk at end of %<#pragma %s%>", pname);
1345 return PRAGMA_BAD;
1348 return ret;
1351 /* #pragma STDC FLOAT_CONST_DECIMAL64 ON
1352 #pragma STDC FLOAT_CONST_DECIMAL64 OFF
1353 #pragma STDC FLOAT_CONST_DECIMAL64 DEFAULT */
1355 static void
1356 handle_pragma_float_const_decimal64 (cpp_reader *ARG_UNUSED (dummy))
1358 if (c_dialect_cxx ())
1360 if (warn_unknown_pragmas > in_system_header_at (input_location))
1361 warning (OPT_Wunknown_pragmas,
1362 "%<#pragma STDC FLOAT_CONST_DECIMAL64%> is not supported"
1363 " for C++");
1364 return;
1367 if (!targetm.decimal_float_supported_p ())
1369 if (warn_unknown_pragmas > in_system_header_at (input_location))
1370 warning (OPT_Wunknown_pragmas,
1371 "%<#pragma STDC FLOAT_CONST_DECIMAL64%> is not supported"
1372 " on this target");
1373 return;
1376 pedwarn (input_location, OPT_Wpedantic,
1377 "ISO C does not support %<#pragma STDC FLOAT_CONST_DECIMAL64%>");
1379 switch (handle_stdc_pragma ("STDC FLOAT_CONST_DECIMAL64"))
1381 case PRAGMA_ON:
1382 set_float_const_decimal64 ();
1383 break;
1384 case PRAGMA_OFF:
1385 case PRAGMA_DEFAULT:
1386 clear_float_const_decimal64 ();
1387 break;
1388 case PRAGMA_BAD:
1389 break;
1393 /* A vector of registered pragma callbacks, which is never freed. */
1395 static vec<internal_pragma_handler> registered_pragmas;
1397 typedef struct
1399 const char *space;
1400 const char *name;
1401 } pragma_ns_name;
1404 static vec<pragma_ns_name> registered_pp_pragmas;
1406 struct omp_pragma_def { const char *name; unsigned int id; };
1407 static const struct omp_pragma_def omp_pragmas[] = {
1408 { "atomic", PRAGMA_OMP_ATOMIC },
1409 { "barrier", PRAGMA_OMP_BARRIER },
1410 { "cancel", PRAGMA_OMP_CANCEL },
1411 { "cancellation", PRAGMA_OMP_CANCELLATION_POINT },
1412 { "critical", PRAGMA_OMP_CRITICAL },
1413 { "end", PRAGMA_OMP_END_DECLARE_TARGET },
1414 { "flush", PRAGMA_OMP_FLUSH },
1415 { "master", PRAGMA_OMP_MASTER },
1416 { "ordered", PRAGMA_OMP_ORDERED },
1417 { "section", PRAGMA_OMP_SECTION },
1418 { "sections", PRAGMA_OMP_SECTIONS },
1419 { "single", PRAGMA_OMP_SINGLE },
1420 { "task", PRAGMA_OMP_TASK },
1421 { "taskgroup", PRAGMA_OMP_TASKGROUP },
1422 { "taskwait", PRAGMA_OMP_TASKWAIT },
1423 { "taskyield", PRAGMA_OMP_TASKYIELD },
1424 { "threadprivate", PRAGMA_OMP_THREADPRIVATE }
1426 static const struct omp_pragma_def omp_pragmas_simd[] = {
1427 { "declare", PRAGMA_OMP_DECLARE_REDUCTION },
1428 { "distribute", PRAGMA_OMP_DISTRIBUTE },
1429 { "for", PRAGMA_OMP_FOR },
1430 { "parallel", PRAGMA_OMP_PARALLEL },
1431 { "simd", PRAGMA_OMP_SIMD },
1432 { "target", PRAGMA_OMP_TARGET },
1433 { "teams", PRAGMA_OMP_TEAMS },
1436 void
1437 c_pp_lookup_pragma (unsigned int id, const char **space, const char **name)
1439 const int n_omp_pragmas = sizeof (omp_pragmas) / sizeof (*omp_pragmas);
1440 const int n_omp_pragmas_simd = sizeof (omp_pragmas_simd)
1441 / sizeof (*omp_pragmas);
1442 int i;
1444 for (i = 0; i < n_omp_pragmas; ++i)
1445 if (omp_pragmas[i].id == id)
1447 *space = "omp";
1448 *name = omp_pragmas[i].name;
1449 return;
1452 for (i = 0; i < n_omp_pragmas_simd; ++i)
1453 if (omp_pragmas_simd[i].id == id)
1455 *space = "omp";
1456 *name = omp_pragmas_simd[i].name;
1457 return;
1460 if (id == PRAGMA_CILK_SIMD)
1462 *space = NULL;
1463 *name = "simd";
1464 return;
1467 if (id >= PRAGMA_FIRST_EXTERNAL
1468 && (id < PRAGMA_FIRST_EXTERNAL + registered_pp_pragmas.length ()))
1470 *space = registered_pp_pragmas[id - PRAGMA_FIRST_EXTERNAL].space;
1471 *name = registered_pp_pragmas[id - PRAGMA_FIRST_EXTERNAL].name;
1472 return;
1475 gcc_unreachable ();
1478 /* Front-end wrappers for pragma registration to avoid dragging
1479 cpplib.h in almost everywhere. */
1481 static void
1482 c_register_pragma_1 (const char *space, const char *name,
1483 internal_pragma_handler ihandler, bool allow_expansion)
1485 unsigned id;
1487 if (flag_preprocess_only)
1489 pragma_ns_name ns_name;
1491 if (!allow_expansion)
1492 return;
1494 ns_name.space = space;
1495 ns_name.name = name;
1496 registered_pp_pragmas.safe_push (ns_name);
1497 id = registered_pp_pragmas.length ();
1498 id += PRAGMA_FIRST_EXTERNAL - 1;
1500 else
1502 registered_pragmas.safe_push (ihandler);
1503 id = registered_pragmas.length ();
1504 id += PRAGMA_FIRST_EXTERNAL - 1;
1506 /* The C++ front end allocates 6 bits in cp_token; the C front end
1507 allocates 7 bits in c_token. At present this is sufficient. */
1508 gcc_assert (id < 64);
1511 cpp_register_deferred_pragma (parse_in, space, name, id,
1512 allow_expansion, false);
1515 /* Register a C pragma handler, using a space and a name. It disallows pragma
1516 expansion (if you want it, use c_register_pragma_with_expansion instead). */
1517 void
1518 c_register_pragma (const char *space, const char *name,
1519 pragma_handler_1arg handler)
1521 internal_pragma_handler ihandler;
1523 ihandler.handler.handler_1arg = handler;
1524 ihandler.extra_data = false;
1525 ihandler.data = NULL;
1526 c_register_pragma_1 (space, name, ihandler, false);
1529 /* Register a C pragma handler, using a space and a name, it also carries an
1530 extra data field which can be used by the handler. It disallows pragma
1531 expansion (if you want it, use c_register_pragma_with_expansion_and_data
1532 instead). */
1533 void
1534 c_register_pragma_with_data (const char *space, const char *name,
1535 pragma_handler_2arg handler, void * data)
1537 internal_pragma_handler ihandler;
1539 ihandler.handler.handler_2arg = handler;
1540 ihandler.extra_data = true;
1541 ihandler.data = data;
1542 c_register_pragma_1 (space, name, ihandler, false);
1545 /* Register a C pragma handler, using a space and a name. It allows pragma
1546 expansion as in the following example:
1548 #define NUMBER 10
1549 #pragma count (NUMBER)
1551 Name expansion is still disallowed. */
1552 void
1553 c_register_pragma_with_expansion (const char *space, const char *name,
1554 pragma_handler_1arg handler)
1556 internal_pragma_handler ihandler;
1558 ihandler.handler.handler_1arg = handler;
1559 ihandler.extra_data = false;
1560 ihandler.data = NULL;
1561 c_register_pragma_1 (space, name, ihandler, true);
1564 /* Register a C pragma handler, using a space and a name, it also carries an
1565 extra data field which can be used by the handler. It allows pragma
1566 expansion as in the following example:
1568 #define NUMBER 10
1569 #pragma count (NUMBER)
1571 Name expansion is still disallowed. */
1572 void
1573 c_register_pragma_with_expansion_and_data (const char *space, const char *name,
1574 pragma_handler_2arg handler,
1575 void *data)
1577 internal_pragma_handler ihandler;
1579 ihandler.handler.handler_2arg = handler;
1580 ihandler.extra_data = true;
1581 ihandler.data = data;
1582 c_register_pragma_1 (space, name, ihandler, true);
1585 void
1586 c_invoke_pragma_handler (unsigned int id)
1588 internal_pragma_handler *ihandler;
1589 pragma_handler_1arg handler_1arg;
1590 pragma_handler_2arg handler_2arg;
1592 id -= PRAGMA_FIRST_EXTERNAL;
1593 ihandler = &registered_pragmas[id];
1594 if (ihandler->extra_data)
1596 handler_2arg = ihandler->handler.handler_2arg;
1597 handler_2arg (parse_in, ihandler->data);
1599 else
1601 handler_1arg = ihandler->handler.handler_1arg;
1602 handler_1arg (parse_in);
1606 /* Set up front-end pragmas. */
1607 void
1608 init_pragma (void)
1610 if (flag_openmp)
1612 const int n_omp_pragmas = sizeof (omp_pragmas) / sizeof (*omp_pragmas);
1613 int i;
1615 for (i = 0; i < n_omp_pragmas; ++i)
1616 cpp_register_deferred_pragma (parse_in, "omp", omp_pragmas[i].name,
1617 omp_pragmas[i].id, true, true);
1619 if (flag_openmp || flag_openmp_simd)
1621 const int n_omp_pragmas_simd = sizeof (omp_pragmas_simd)
1622 / sizeof (*omp_pragmas);
1623 int i;
1625 for (i = 0; i < n_omp_pragmas_simd; ++i)
1626 cpp_register_deferred_pragma (parse_in, "omp", omp_pragmas_simd[i].name,
1627 omp_pragmas_simd[i].id, true, true);
1630 if (flag_cilkplus)
1631 cpp_register_deferred_pragma (parse_in, NULL, "simd", PRAGMA_CILK_SIMD,
1632 true, false);
1634 if (!flag_preprocess_only)
1635 cpp_register_deferred_pragma (parse_in, "GCC", "pch_preprocess",
1636 PRAGMA_GCC_PCH_PREPROCESS, false, false);
1638 if (!flag_preprocess_only)
1639 cpp_register_deferred_pragma (parse_in, "GCC", "ivdep", PRAGMA_IVDEP, false,
1640 false);
1641 #ifdef HANDLE_PRAGMA_PACK_WITH_EXPANSION
1642 c_register_pragma_with_expansion (0, "pack", handle_pragma_pack);
1643 #else
1644 c_register_pragma (0, "pack", handle_pragma_pack);
1645 #endif
1646 c_register_pragma (0, "weak", handle_pragma_weak);
1647 c_register_pragma ("GCC", "visibility", handle_pragma_visibility);
1649 c_register_pragma ("GCC", "diagnostic", handle_pragma_diagnostic);
1650 c_register_pragma ("GCC", "target", handle_pragma_target);
1651 c_register_pragma ("GCC", "optimize", handle_pragma_optimize);
1652 c_register_pragma ("GCC", "push_options", handle_pragma_push_options);
1653 c_register_pragma ("GCC", "pop_options", handle_pragma_pop_options);
1654 c_register_pragma ("GCC", "reset_options", handle_pragma_reset_options);
1656 c_register_pragma ("STDC", "FLOAT_CONST_DECIMAL64",
1657 handle_pragma_float_const_decimal64);
1659 c_register_pragma_with_expansion (0, "redefine_extname",
1660 handle_pragma_redefine_extname);
1662 c_register_pragma_with_expansion (0, "message", handle_pragma_message);
1664 if (flag_upc)
1666 c_register_pragma (0, "upc", handle_pragma_upc);
1667 init_pragma_upc ();
1668 c_register_pragma (0, "pupc", handle_pragma_pupc);
1669 init_pragma_pupc ();
1672 #ifdef REGISTER_TARGET_PRAGMAS
1673 REGISTER_TARGET_PRAGMAS ();
1674 #endif
1676 /* Allow plugins to register their own pragmas. */
1677 invoke_plugin_callbacks (PLUGIN_PRAGMAS, NULL);
1680 #include "gt-c-family-c-pragma.h"