Merge trunk version 190437 into gupc branch.
[official-gcc.git] / gcc / c-family / c-pragma.c
blobd23a4eb153c7535c723d262f1f0ad7f1685d2fb4
1 /* Handle #pragma, system V.4 style. Supports #pragma weak and #pragma pack.
2 Copyright (C) 1992, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3 2006, 2007, 2008, 2009, 2010, 2012 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tm.h"
25 #include "tree.h"
26 #include "function.h" /* For cfun. FIXME: Does the parser know
27 when it is inside a function, so that
28 we don't have to look at cfun? */
29 #include "cpplib.h"
30 #include "c-pragma.h"
31 #include "flags.h"
32 #include "c-common.h"
33 #include "c-upc.h"
34 #include "tm_p.h" /* For REGISTER_TARGET_PRAGMAS (why is
35 this not a target hook?). */
36 #include "vec.h"
37 #include "vecprim.h"
38 #include "target.h"
39 #include "diagnostic.h"
40 #include "opts.h"
41 #include "plugin.h"
42 #include "cgraph.h"
44 #define GCC_BAD(gmsgid) \
45 do { warning (OPT_Wpragmas, gmsgid); return; } while (0)
46 #define GCC_BAD2(gmsgid, arg) \
47 do { warning (OPT_Wpragmas, gmsgid, arg); return; } while (0)
49 typedef struct GTY(()) align_stack {
50 int alignment;
51 tree id;
52 struct align_stack * prev;
53 } align_stack;
55 static GTY(()) struct align_stack * alignment_stack;
57 static void handle_pragma_pack (cpp_reader *);
59 /* If we have a "global" #pragma pack(<n>) in effect when the first
60 #pragma pack(push,<n>) is encountered, this stores the value of
61 maximum_field_alignment in effect. When the final pop_alignment()
62 happens, we restore the value to this, not to a value of 0 for
63 maximum_field_alignment. Value is in bits. */
64 static int default_alignment;
65 #define SET_GLOBAL_ALIGNMENT(ALIGN) (maximum_field_alignment = *(alignment_stack == NULL \
66 ? &default_alignment \
67 : &alignment_stack->alignment) = (ALIGN))
69 static void push_alignment (int, tree);
70 static void pop_alignment (tree);
72 /* Push an alignment value onto the stack. */
73 static void
74 push_alignment (int alignment, tree id)
76 align_stack * entry;
78 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;
245 DEF_VEC_O(pending_weak);
246 DEF_VEC_ALLOC_O(pending_weak,gc);
248 static GTY(()) VEC(pending_weak,gc) *pending_weaks;
250 static void apply_pragma_weak (tree, tree);
251 static void handle_pragma_weak (cpp_reader *);
253 static void
254 apply_pragma_weak (tree decl, tree value)
256 if (value)
258 value = build_string (IDENTIFIER_LENGTH (value),
259 IDENTIFIER_POINTER (value));
260 decl_attributes (&decl, build_tree_list (get_identifier ("alias"),
261 build_tree_list (NULL, value)),
265 if (SUPPORTS_WEAK && DECL_EXTERNAL (decl) && TREE_USED (decl)
266 && !DECL_WEAK (decl) /* Don't complain about a redundant #pragma. */
267 && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
268 warning (OPT_Wpragmas, "applying #pragma weak %q+D after first use "
269 "results in unspecified behavior", decl);
271 declare_weak (decl);
274 void
275 maybe_apply_pragma_weak (tree decl)
277 tree id;
278 int i;
279 pending_weak *pe;
281 /* Avoid asking for DECL_ASSEMBLER_NAME when it's not needed. */
283 /* No weak symbols pending, take the short-cut. */
284 if (!pending_weaks)
285 return;
286 /* If it's not visible outside this file, it doesn't matter whether
287 it's weak. */
288 if (!DECL_EXTERNAL (decl) && !TREE_PUBLIC (decl))
289 return;
290 /* If it's not a function or a variable, it can't be weak.
291 FIXME: what kinds of things are visible outside this file but
292 aren't functions or variables? Should this be an assert instead? */
293 if (TREE_CODE (decl) != FUNCTION_DECL && TREE_CODE (decl) != VAR_DECL)
294 return;
296 id = DECL_ASSEMBLER_NAME (decl);
298 FOR_EACH_VEC_ELT (pending_weak, pending_weaks, i, pe)
299 if (id == pe->name)
301 apply_pragma_weak (decl, pe->value);
302 VEC_unordered_remove (pending_weak, pending_weaks, i);
303 break;
307 /* Process all "#pragma weak A = B" directives where we have not seen
308 a decl for A. */
309 void
310 maybe_apply_pending_pragma_weaks (void)
312 tree alias_id, id, decl;
313 int i;
314 pending_weak *pe;
315 symtab_node target;
317 FOR_EACH_VEC_ELT (pending_weak, pending_weaks, i, pe)
319 alias_id = pe->name;
320 id = pe->value;
322 if (id == NULL)
323 continue;
325 target = symtab_node_for_asm (id);
326 decl = build_decl (UNKNOWN_LOCATION,
327 target ? TREE_CODE (target->symbol.decl) : FUNCTION_DECL,
328 alias_id, default_function_type);
330 DECL_ARTIFICIAL (decl) = 1;
331 TREE_PUBLIC (decl) = 1;
332 DECL_WEAK (decl) = 1;
333 if (TREE_CODE (decl) == VAR_DECL)
334 TREE_STATIC (decl) = 1;
335 if (!target)
337 error ("%q+D aliased to undefined symbol %qE",
338 decl, id);
339 continue;
342 assemble_alias (decl, id);
346 /* #pragma weak name [= value] */
347 static void
348 handle_pragma_weak (cpp_reader * ARG_UNUSED (dummy))
350 tree name, value, x, decl;
351 enum cpp_ttype t;
353 value = 0;
355 if (pragma_lex (&name) != CPP_NAME)
356 GCC_BAD ("malformed #pragma weak, ignored");
357 t = pragma_lex (&x);
358 if (t == CPP_EQ)
360 if (pragma_lex (&value) != CPP_NAME)
361 GCC_BAD ("malformed #pragma weak, ignored");
362 t = pragma_lex (&x);
364 if (t != CPP_EOF)
365 warning (OPT_Wpragmas, "junk at end of %<#pragma weak%>");
367 decl = identifier_global_value (name);
368 if (decl && DECL_P (decl))
370 apply_pragma_weak (decl, value);
371 if (value)
372 assemble_alias (decl, value);
374 else
376 pending_weak *pe;
377 pe = VEC_safe_push (pending_weak, gc, pending_weaks, NULL);
378 pe->name = name;
379 pe->value = value;
383 /* GCC supports two #pragma directives for renaming the external
384 symbol associated with a declaration (DECL_ASSEMBLER_NAME), for
385 compatibility with the Solaris and VMS system headers. GCC also
386 has its own notation for this, __asm__("name") annotations.
388 Corner cases of these features and their interaction:
390 1) Both pragmas silently apply only to declarations with external
391 linkage (that is, TREE_PUBLIC || DECL_EXTERNAL). Asm labels
392 do not have this restriction.
394 2) In C++, both #pragmas silently apply only to extern "C" declarations.
395 Asm labels do not have this restriction.
397 3) If any of the three ways of changing DECL_ASSEMBLER_NAME is
398 applied to a decl whose DECL_ASSEMBLER_NAME is already set, and the
399 new name is different, a warning issues and the name does not change.
401 4) The "source name" for #pragma redefine_extname is the DECL_NAME,
402 *not* the DECL_ASSEMBLER_NAME.
404 5) If #pragma extern_prefix is in effect and a declaration occurs
405 with an __asm__ name, the #pragma extern_prefix is silently
406 ignored for that declaration.
408 6) If #pragma extern_prefix and #pragma redefine_extname apply to
409 the same declaration, whichever triggered first wins, and a warning
410 is issued. (We would like to have #pragma redefine_extname always
411 win, but it can appear either before or after the declaration, and
412 if it appears afterward, we have no way of knowing whether a modified
413 DECL_ASSEMBLER_NAME is due to #pragma extern_prefix.) */
415 typedef struct GTY(()) pending_redefinition_d {
416 tree oldname;
417 tree newname;
418 } pending_redefinition;
420 DEF_VEC_O(pending_redefinition);
421 DEF_VEC_ALLOC_O(pending_redefinition,gc);
423 static GTY(()) VEC(pending_redefinition,gc) *pending_redefine_extname;
425 static void handle_pragma_redefine_extname (cpp_reader *);
427 /* #pragma redefine_extname oldname newname */
428 static void
429 handle_pragma_redefine_extname (cpp_reader * ARG_UNUSED (dummy))
431 tree oldname, newname, decls, x;
432 enum cpp_ttype t;
433 bool found;
435 if (pragma_lex (&oldname) != CPP_NAME)
436 GCC_BAD ("malformed #pragma redefine_extname, ignored");
437 if (pragma_lex (&newname) != CPP_NAME)
438 GCC_BAD ("malformed #pragma redefine_extname, ignored");
439 t = pragma_lex (&x);
440 if (t != CPP_EOF)
441 warning (OPT_Wpragmas, "junk at end of %<#pragma redefine_extname%>");
443 found = false;
444 for (decls = c_linkage_bindings (oldname);
445 decls; )
447 tree decl;
448 if (TREE_CODE (decls) == TREE_LIST)
450 decl = TREE_VALUE (decls);
451 decls = TREE_CHAIN (decls);
453 else
455 decl = decls;
456 decls = NULL_TREE;
459 if ((TREE_PUBLIC (decl) || DECL_EXTERNAL (decl))
460 && (TREE_CODE (decl) == FUNCTION_DECL
461 || TREE_CODE (decl) == VAR_DECL))
463 found = true;
464 if (DECL_ASSEMBLER_NAME_SET_P (decl))
466 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
467 name = targetm.strip_name_encoding (name);
469 if (strcmp (name, IDENTIFIER_POINTER (newname)))
470 warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
471 "conflict with previous rename");
473 else
474 change_decl_assembler_name (decl, newname);
478 if (!found)
479 /* We have to add this to the rename list even if there's already
480 a global value that doesn't meet the above criteria, because in
481 C++ "struct foo {...};" puts "foo" in the current namespace but
482 does *not* conflict with a subsequent declaration of a function
483 or variable foo. See g++.dg/other/pragma-re-2.C. */
484 add_to_renaming_pragma_list (oldname, newname);
487 /* This is called from here and from ia64.c. */
488 void
489 add_to_renaming_pragma_list (tree oldname, tree newname)
491 unsigned ix;
492 pending_redefinition *p;
494 FOR_EACH_VEC_ELT (pending_redefinition, pending_redefine_extname, ix, p)
495 if (oldname == p->oldname)
497 if (p->newname != newname)
498 warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
499 "conflict with previous #pragma redefine_extname");
500 return;
503 p = VEC_safe_push (pending_redefinition, gc, pending_redefine_extname, NULL);
504 p->oldname = oldname;
505 p->newname = newname;
508 /* The current prefix set by #pragma extern_prefix. */
509 GTY(()) tree pragma_extern_prefix;
511 /* variables used to implement #pragma upc semantics */
512 #ifndef UPC_CMODE_STACK_INCREMENT
513 #define UPC_CMODE_STACK_INCREMENT 32
514 #endif
515 static int pragma_upc_permitted;
516 static int upc_cmode;
517 static int *upc_cmode_stack;
518 static int upc_cmode_stack_in_use;
519 static int upc_cmode_stack_allocated;
521 static void init_pragma_upc (void);
522 static void handle_pragma_upc (cpp_reader * ARG_UNUSED (dummy));
524 /* Initialize the variables used to manage the current UPC consistency
525 mode (strict/relaxed) */
527 static void
528 init_pragma_upc (void)
530 pragma_upc_permitted = 0;
531 upc_cmode = 0;
532 upc_cmode_stack = (int *) xcalloc (UPC_CMODE_STACK_INCREMENT,
533 sizeof (int));
534 upc_cmode_stack_allocated = UPC_CMODE_STACK_INCREMENT;
535 upc_cmode_stack_in_use = 0;
539 * #pragma upc strict
540 * #pragma upc relaxed
541 * #pragma upc upc_code
542 * #pragma upc c_code
544 static void
545 handle_pragma_upc (cpp_reader * ARG_UNUSED (dummy))
547 tree x;
548 enum cpp_ttype t;
549 enum upc_pragma_op {p_strict, p_relaxed, p_upc_code,
550 p_c_code, p_detect_upc, p_unknown};
551 enum upc_pragma_op upc_pragma = p_unknown;
553 if (!flag_upc)
555 warning (OPT_Wpragmas, "#pragma upc found in non-UPC source file");
556 return;
559 t = pragma_lex (&x);
560 if (t == CPP_NAME)
562 const char *op = IDENTIFIER_POINTER (x);
563 if (!strcmp (op, "strict"))
564 upc_pragma = p_strict;
565 else if (!strcmp (op, "relaxed"))
566 upc_pragma = p_relaxed;
567 else if (!strcmp (op, "upc_code"))
568 upc_pragma = p_upc_code;
569 else if (!strcmp (op, "c_code"))
570 upc_pragma = p_c_code;
571 else if (!strcmp (op, "detect_upc"))
573 const char *detect_op;
574 upc_pragma = p_detect_upc;
575 t = pragma_lex (&x);
576 if (t != CPP_NAME)
577 GCC_BAD ("missing [suspend_insertion|resume_insertion]"
578 " after %<#pragma UPC detect_upc%>");
579 detect_op = IDENTIFIER_POINTER (x);
580 if (strcmp (detect_op, "suspend_insertion") == 0)
581 /* no action */;
582 else if (strcmp (detect_op, "resume_insertion") == 0)
583 /* no action */;
584 else
585 GCC_BAD ("expected [suspend_insertion|resume_insertion]"
586 " after %<#pragma UPC detect_upc%>");
588 else
589 GCC_BAD2 ("unknown action '%s' for '#pragma upc' - ignored", op);
591 else
592 warning (OPT_Wpragmas, "missing parameter after #pragma upc");
594 t = pragma_lex (&x);
595 if (t != CPP_EOF)
596 warning (OPT_Wpragmas, "junk at end of #pragma upc");
598 if ((upc_pragma == p_strict) || (upc_pragma == p_relaxed))
600 if (pragma_upc_permitted_p ())
602 int consistency_mode = (upc_pragma == p_strict);
603 set_upc_consistency_mode (consistency_mode);
605 else
606 warning (OPT_Wpragmas, "#pragma upc not allowed in this context");
608 else if ((upc_pragma == p_upc_code) || (upc_pragma == p_c_code))
610 compiling_upc = (upc_pragma == p_upc_code);
612 else if (upc_pragma == p_detect_upc)
614 /* Skip: this is a Berkeley-specific pragma that requires no action. */
618 /* Set the current setting of the UPC consistency mode
619 that is in effect. */
621 void
622 set_upc_consistency_mode (int mode)
624 upc_cmode = mode;
627 /* Return the current setting of the UPC consistency mode. */
630 get_upc_consistency_mode (void)
632 return upc_cmode;
635 /* Called from the parser just after the bracket that opens a compound
636 statement has been parsed. Set the flag that allows the pragma
637 in this context. */
639 void
640 permit_pragma_upc (void)
642 pragma_upc_permitted = 1;
645 /* Called just before the body of a compound statement is parsed.
646 Clear the flag that allows the pragma. */
648 void
649 deny_pragma_upc (void)
651 pragma_upc_permitted = 0;
654 /* A #pragma upc is permitted either at the outermost scope,
655 or directly after the bracket that opens a compound statement. */
658 pragma_upc_permitted_p (void)
660 return !current_function_decl || pragma_upc_permitted;
663 /* Called at the beginning of every compound statement.
664 Pushes the old value of the current UPC consistency mode
665 onto the stack. */
667 void
668 push_upc_consistency_mode (void)
670 if (upc_cmode_stack_in_use == upc_cmode_stack_allocated)
672 upc_cmode_stack_allocated += UPC_CMODE_STACK_INCREMENT;
673 upc_cmode_stack = (int *) xrealloc (upc_cmode_stack,
674 upc_cmode_stack_allocated * sizeof (int));
676 upc_cmode_stack[upc_cmode_stack_in_use++] = upc_cmode;
679 /* Called at the end of every compound statement.
680 Sets the current consistency mode to the previously saved value. */
682 void
683 pop_upc_consistency_mode (void)
685 if (upc_cmode_stack_in_use <= 0)
686 abort ();
687 upc_cmode = upc_cmode_stack[--upc_cmode_stack_in_use];
690 static int pragma_pupc_on;
691 static void init_pragma_pupc (void);
692 static void handle_pragma_pupc (cpp_reader *);
694 /* Pragma pupc defaults to being on */
695 static void
696 init_pragma_pupc (void)
698 pragma_pupc_on = 1;
702 get_upc_pupc_mode (void)
704 return pragma_pupc_on;
708 disable_pupc_mode (void)
710 int old_pupc = pragma_pupc_on;
711 pragma_pupc_on = 0;
712 return old_pupc;
715 void
716 set_pupc_mode (int new_pupc)
718 pragma_pupc_on = new_pupc;
722 * #pragma pupc on
723 * #pragma pupc off
725 static void
726 handle_pragma_pupc (cpp_reader *dummy ATTRIBUTE_UNUSED)
728 tree x;
729 enum cpp_ttype t;
731 t = pragma_lex(&x);
732 if (t == CPP_NAME) {
733 const char *op = IDENTIFIER_POINTER (x);
734 if (!strcmp (op, "on"))
735 pragma_pupc_on = 1;
736 else if (!strcmp (op, "off"))
737 pragma_pupc_on = 0;
738 else
739 GCC_BAD2 ("unknown action '%s' for '#pragma pupc' - ignored", op);
742 t = pragma_lex (&x);
743 if (t != CPP_EOF)
744 warning (OPT_Wpragmas, "junk at end of #pragma pupc");
747 /* Hook from the front ends to apply the results of one of the preceding
748 pragmas that rename variables. */
750 tree
751 maybe_apply_renaming_pragma (tree decl, tree asmname)
753 unsigned ix;
754 pending_redefinition *p;
756 /* The renaming pragmas are only applied to declarations with
757 external linkage. */
758 if ((TREE_CODE (decl) != FUNCTION_DECL && TREE_CODE (decl) != VAR_DECL)
759 || (!TREE_PUBLIC (decl) && !DECL_EXTERNAL (decl))
760 || !has_c_linkage (decl))
761 return asmname;
763 /* If the DECL_ASSEMBLER_NAME is already set, it does not change,
764 but we may warn about a rename that conflicts. */
765 if (DECL_ASSEMBLER_NAME_SET_P (decl))
767 const char *oldname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
768 oldname = targetm.strip_name_encoding (oldname);
770 if (asmname && strcmp (TREE_STRING_POINTER (asmname), oldname))
771 warning (OPT_Wpragmas, "asm declaration ignored due to "
772 "conflict with previous rename");
774 /* Take any pending redefine_extname off the list. */
775 FOR_EACH_VEC_ELT (pending_redefinition, pending_redefine_extname, ix, p)
776 if (DECL_NAME (decl) == p->oldname)
778 /* Only warn if there is a conflict. */
779 if (strcmp (IDENTIFIER_POINTER (p->newname), oldname))
780 warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
781 "conflict with previous rename");
783 VEC_unordered_remove (pending_redefinition,
784 pending_redefine_extname, ix);
785 break;
787 return 0;
790 /* Find out if we have a pending #pragma redefine_extname. */
791 FOR_EACH_VEC_ELT (pending_redefinition, pending_redefine_extname, ix, p)
792 if (DECL_NAME (decl) == p->oldname)
794 tree newname = p->newname;
795 VEC_unordered_remove (pending_redefinition,
796 pending_redefine_extname, ix);
798 /* If we already have an asmname, #pragma redefine_extname is
799 ignored (with a warning if it conflicts). */
800 if (asmname)
802 if (strcmp (TREE_STRING_POINTER (asmname),
803 IDENTIFIER_POINTER (newname)) != 0)
804 warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
805 "conflict with __asm__ declaration");
806 return asmname;
809 /* Otherwise we use what we've got; #pragma extern_prefix is
810 silently ignored. */
811 return build_string (IDENTIFIER_LENGTH (newname),
812 IDENTIFIER_POINTER (newname));
815 /* If we've got an asmname, #pragma extern_prefix is silently ignored. */
816 if (asmname)
817 return asmname;
819 /* If #pragma extern_prefix is in effect, apply it. */
820 if (pragma_extern_prefix)
822 const char *prefix = TREE_STRING_POINTER (pragma_extern_prefix);
823 size_t plen = TREE_STRING_LENGTH (pragma_extern_prefix) - 1;
825 const char *id = IDENTIFIER_POINTER (DECL_NAME (decl));
826 size_t ilen = IDENTIFIER_LENGTH (DECL_NAME (decl));
828 char *newname = (char *) alloca (plen + ilen + 1);
830 memcpy (newname, prefix, plen);
831 memcpy (newname + plen, id, ilen + 1);
833 return build_string (plen + ilen, newname);
836 /* Nada. */
837 return 0;
841 static void handle_pragma_visibility (cpp_reader *);
843 static VEC (int, heap) *visstack;
845 /* Push the visibility indicated by STR onto the top of the #pragma
846 visibility stack. KIND is 0 for #pragma GCC visibility, 1 for
847 C++ namespace with visibility attribute and 2 for C++ builtin
848 ABI namespace. push_visibility/pop_visibility calls must have
849 matching KIND, it is not allowed to push visibility using one
850 KIND and pop using a different one. */
852 void
853 push_visibility (const char *str, int kind)
855 VEC_safe_push (int, heap, visstack,
856 ((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 (!VEC_length (int, visstack))
877 return false;
878 if ((VEC_last (int, visstack) >> 8) != kind)
879 return false;
880 default_visibility
881 = (enum symbol_visibility) (VEC_pop (int, visstack) & 0xff);
882 visibility_options.inpragma
883 = VEC_length (int, visstack) != 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 ();
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;
1144 opt_stack *p;
1146 token = pragma_lex (&x);
1147 if (token != CPP_EOF)
1149 warning (OPT_Wpragmas, "junk at end of %<#pragma push_options%>");
1150 return;
1153 p = ggc_alloc_opt_stack ();
1154 p->prev = options_stack;
1155 options_stack = p;
1157 /* Save optimization and target flags in binary format. */
1158 p->optimize_binary = build_optimization_node ();
1159 p->target_binary = build_target_option_node ();
1161 /* Save optimization and target flags in string list format. */
1162 p->optimize_strings = copy_list (current_optimize_pragma);
1163 p->target_strings = copy_list (current_target_pragma);
1166 /* Handle #pragma GCC pop_options to restore the current target and
1167 optimization options from a previous push_options. */
1169 static void
1170 handle_pragma_pop_options (cpp_reader *ARG_UNUSED(dummy))
1172 enum cpp_ttype token;
1173 tree x = 0;
1174 opt_stack *p;
1176 token = pragma_lex (&x);
1177 if (token != CPP_EOF)
1179 warning (OPT_Wpragmas, "junk at end of %<#pragma pop_options%>");
1180 return;
1183 if (! options_stack)
1185 warning (OPT_Wpragmas,
1186 "%<#pragma GCC pop_options%> without a corresponding "
1187 "%<#pragma GCC push_options%>");
1188 return;
1191 p = options_stack;
1192 options_stack = p->prev;
1194 if (p->target_binary != target_option_current_node)
1196 (void) targetm.target_option.pragma_parse (NULL_TREE, p->target_binary);
1197 target_option_current_node = p->target_binary;
1200 if (p->optimize_binary != optimization_current_node)
1202 tree old_optimize = optimization_current_node;
1203 cl_optimization_restore (&global_options,
1204 TREE_OPTIMIZATION (p->optimize_binary));
1205 c_cpp_builtins_optimize_pragma (parse_in, old_optimize,
1206 p->optimize_binary);
1207 optimization_current_node = p->optimize_binary;
1210 current_target_pragma = p->target_strings;
1211 current_optimize_pragma = p->optimize_strings;
1214 /* Handle #pragma GCC reset_options to restore the current target and
1215 optimization options to the original options used on the command line. */
1217 static void
1218 handle_pragma_reset_options (cpp_reader *ARG_UNUSED(dummy))
1220 enum cpp_ttype token;
1221 tree x = 0;
1222 tree new_optimize = optimization_default_node;
1223 tree new_target = target_option_default_node;
1225 token = pragma_lex (&x);
1226 if (token != CPP_EOF)
1228 warning (OPT_Wpragmas, "junk at end of %<#pragma reset_options%>");
1229 return;
1232 if (new_target != target_option_current_node)
1234 (void) targetm.target_option.pragma_parse (NULL_TREE, new_target);
1235 target_option_current_node = new_target;
1238 if (new_optimize != optimization_current_node)
1240 tree old_optimize = optimization_current_node;
1241 cl_optimization_restore (&global_options,
1242 TREE_OPTIMIZATION (new_optimize));
1243 c_cpp_builtins_optimize_pragma (parse_in, old_optimize, new_optimize);
1244 optimization_current_node = new_optimize;
1247 current_target_pragma = NULL_TREE;
1248 current_optimize_pragma = NULL_TREE;
1251 /* Print a plain user-specified message. */
1253 static void
1254 handle_pragma_message (cpp_reader *ARG_UNUSED(dummy))
1256 enum cpp_ttype token;
1257 tree x, message = 0;
1259 token = pragma_lex (&x);
1260 if (token == CPP_OPEN_PAREN)
1262 token = pragma_lex (&x);
1263 if (token == CPP_STRING)
1264 message = x;
1265 else
1266 GCC_BAD ("expected a string after %<#pragma message%>");
1267 if (pragma_lex (&x) != CPP_CLOSE_PAREN)
1268 GCC_BAD ("malformed %<#pragma message%>, ignored");
1270 else if (token == CPP_STRING)
1271 message = x;
1272 else
1273 GCC_BAD ("expected a string after %<#pragma message%>");
1275 gcc_assert (message);
1277 if (pragma_lex (&x) != CPP_EOF)
1278 warning (OPT_Wpragmas, "junk at end of %<#pragma message%>");
1280 if (TREE_STRING_LENGTH (message) > 1)
1281 inform (input_location, "#pragma message: %s", TREE_STRING_POINTER (message));
1284 /* Mark whether the current location is valid for a STDC pragma. */
1286 static bool valid_location_for_stdc_pragma;
1288 void
1289 mark_valid_location_for_stdc_pragma (bool flag)
1291 valid_location_for_stdc_pragma = flag;
1294 /* Return true if the current location is valid for a STDC pragma. */
1296 bool
1297 valid_location_for_stdc_pragma_p (void)
1299 return valid_location_for_stdc_pragma;
1302 enum pragma_switch_t { PRAGMA_ON, PRAGMA_OFF, PRAGMA_DEFAULT, PRAGMA_BAD };
1304 /* A STDC pragma must appear outside of external declarations or
1305 preceding all explicit declarations and statements inside a compound
1306 statement; its behavior is undefined if used in any other context.
1307 It takes a switch of ON, OFF, or DEFAULT. */
1309 static enum pragma_switch_t
1310 handle_stdc_pragma (const char *pname)
1312 const char *arg;
1313 tree t;
1314 enum pragma_switch_t ret;
1316 if (!valid_location_for_stdc_pragma_p ())
1318 warning (OPT_Wpragmas, "invalid location for %<pragma %s%>, ignored",
1319 pname);
1320 return PRAGMA_BAD;
1323 if (pragma_lex (&t) != CPP_NAME)
1325 warning (OPT_Wpragmas, "malformed %<#pragma %s%>, ignored", pname);
1326 return PRAGMA_BAD;
1329 arg = IDENTIFIER_POINTER (t);
1331 if (!strcmp (arg, "ON"))
1332 ret = PRAGMA_ON;
1333 else if (!strcmp (arg, "OFF"))
1334 ret = PRAGMA_OFF;
1335 else if (!strcmp (arg, "DEFAULT"))
1336 ret = PRAGMA_DEFAULT;
1337 else
1339 warning (OPT_Wpragmas, "malformed %<#pragma %s%>, ignored", pname);
1340 return PRAGMA_BAD;
1343 if (pragma_lex (&t) != CPP_EOF)
1345 warning (OPT_Wpragmas, "junk at end of %<#pragma %s%>", pname);
1346 return PRAGMA_BAD;
1349 return ret;
1352 /* #pragma STDC FLOAT_CONST_DECIMAL64 ON
1353 #pragma STDC FLOAT_CONST_DECIMAL64 OFF
1354 #pragma STDC FLOAT_CONST_DECIMAL64 DEFAULT */
1356 static void
1357 handle_pragma_float_const_decimal64 (cpp_reader *ARG_UNUSED (dummy))
1359 if (c_dialect_cxx ())
1361 if (warn_unknown_pragmas > in_system_header)
1362 warning (OPT_Wunknown_pragmas,
1363 "%<#pragma STDC FLOAT_CONST_DECIMAL64%> is not supported"
1364 " for C++");
1365 return;
1368 if (!targetm.decimal_float_supported_p ())
1370 if (warn_unknown_pragmas > in_system_header)
1371 warning (OPT_Wunknown_pragmas,
1372 "%<#pragma STDC FLOAT_CONST_DECIMAL64%> is not supported"
1373 " on this target");
1374 return;
1377 pedwarn (input_location, OPT_Wpedantic,
1378 "ISO C does not support %<#pragma STDC FLOAT_CONST_DECIMAL64%>");
1380 switch (handle_stdc_pragma ("STDC FLOAT_CONST_DECIMAL64"))
1382 case PRAGMA_ON:
1383 set_float_const_decimal64 ();
1384 break;
1385 case PRAGMA_OFF:
1386 case PRAGMA_DEFAULT:
1387 clear_float_const_decimal64 ();
1388 break;
1389 case PRAGMA_BAD:
1390 break;
1394 /* A vector of registered pragma callbacks, which is never freed. */
1395 DEF_VEC_O (internal_pragma_handler);
1396 DEF_VEC_ALLOC_O (internal_pragma_handler, heap);
1398 static VEC(internal_pragma_handler, heap) *registered_pragmas;
1400 typedef struct
1402 const char *space;
1403 const char *name;
1404 } pragma_ns_name;
1406 DEF_VEC_O (pragma_ns_name);
1407 DEF_VEC_ALLOC_O (pragma_ns_name, heap);
1409 static VEC(pragma_ns_name, heap) *registered_pp_pragmas;
1411 struct omp_pragma_def { const char *name; unsigned int id; };
1412 static const struct omp_pragma_def omp_pragmas[] = {
1413 { "atomic", PRAGMA_OMP_ATOMIC },
1414 { "barrier", PRAGMA_OMP_BARRIER },
1415 { "critical", PRAGMA_OMP_CRITICAL },
1416 { "flush", PRAGMA_OMP_FLUSH },
1417 { "for", PRAGMA_OMP_FOR },
1418 { "master", PRAGMA_OMP_MASTER },
1419 { "ordered", PRAGMA_OMP_ORDERED },
1420 { "parallel", PRAGMA_OMP_PARALLEL },
1421 { "section", PRAGMA_OMP_SECTION },
1422 { "sections", PRAGMA_OMP_SECTIONS },
1423 { "single", PRAGMA_OMP_SINGLE },
1424 { "task", PRAGMA_OMP_TASK },
1425 { "taskwait", PRAGMA_OMP_TASKWAIT },
1426 { "taskyield", PRAGMA_OMP_TASKYIELD },
1427 { "threadprivate", PRAGMA_OMP_THREADPRIVATE }
1430 void
1431 c_pp_lookup_pragma (unsigned int id, const char **space, const char **name)
1433 const int n_omp_pragmas = sizeof (omp_pragmas) / sizeof (*omp_pragmas);
1434 int i;
1436 for (i = 0; i < n_omp_pragmas; ++i)
1437 if (omp_pragmas[i].id == id)
1439 *space = "omp";
1440 *name = omp_pragmas[i].name;
1441 return;
1444 if (id >= PRAGMA_FIRST_EXTERNAL
1445 && (id < PRAGMA_FIRST_EXTERNAL
1446 + VEC_length (pragma_ns_name, registered_pp_pragmas)))
1448 *space = VEC_index (pragma_ns_name, registered_pp_pragmas,
1449 id - PRAGMA_FIRST_EXTERNAL).space;
1450 *name = VEC_index (pragma_ns_name, registered_pp_pragmas,
1451 id - PRAGMA_FIRST_EXTERNAL).name;
1452 return;
1455 gcc_unreachable ();
1458 /* Front-end wrappers for pragma registration to avoid dragging
1459 cpplib.h in almost everywhere. */
1461 static void
1462 c_register_pragma_1 (const char *space, const char *name,
1463 internal_pragma_handler ihandler, bool allow_expansion)
1465 unsigned id;
1467 if (flag_preprocess_only)
1469 pragma_ns_name ns_name;
1471 if (!allow_expansion)
1472 return;
1474 ns_name.space = space;
1475 ns_name.name = name;
1476 VEC_safe_push (pragma_ns_name, heap, registered_pp_pragmas, &ns_name);
1477 id = VEC_length (pragma_ns_name, registered_pp_pragmas);
1478 id += PRAGMA_FIRST_EXTERNAL - 1;
1480 else
1482 VEC_safe_push (internal_pragma_handler, heap, registered_pragmas,
1483 &ihandler);
1484 id = VEC_length (internal_pragma_handler, registered_pragmas);
1485 id += PRAGMA_FIRST_EXTERNAL - 1;
1487 /* The C++ front end allocates 6 bits in cp_token; the C front end
1488 allocates 7 bits in c_token. At present this is sufficient. */
1489 gcc_assert (id < 64);
1492 cpp_register_deferred_pragma (parse_in, space, name, id,
1493 allow_expansion, false);
1496 /* Register a C pragma handler, using a space and a name. It disallows pragma
1497 expansion (if you want it, use c_register_pragma_with_expansion instead). */
1498 void
1499 c_register_pragma (const char *space, const char *name,
1500 pragma_handler_1arg handler)
1502 internal_pragma_handler ihandler;
1504 ihandler.handler.handler_1arg = handler;
1505 ihandler.extra_data = false;
1506 ihandler.data = NULL;
1507 c_register_pragma_1 (space, name, ihandler, false);
1510 /* Register a C pragma handler, using a space and a name, it also carries an
1511 extra data field which can be used by the handler. It disallows pragma
1512 expansion (if you want it, use c_register_pragma_with_expansion_and_data
1513 instead). */
1514 void
1515 c_register_pragma_with_data (const char *space, const char *name,
1516 pragma_handler_2arg handler, void * data)
1518 internal_pragma_handler ihandler;
1520 ihandler.handler.handler_2arg = handler;
1521 ihandler.extra_data = true;
1522 ihandler.data = data;
1523 c_register_pragma_1 (space, name, ihandler, false);
1526 /* Register a C pragma handler, using a space and a name. It allows pragma
1527 expansion as in the following example:
1529 #define NUMBER 10
1530 #pragma count (NUMBER)
1532 Name expansion is still disallowed. */
1533 void
1534 c_register_pragma_with_expansion (const char *space, const char *name,
1535 pragma_handler_1arg handler)
1537 internal_pragma_handler ihandler;
1539 ihandler.handler.handler_1arg = handler;
1540 ihandler.extra_data = false;
1541 ihandler.data = NULL;
1542 c_register_pragma_1 (space, name, ihandler, true);
1545 /* Register a C pragma handler, using a space and a name, it also carries an
1546 extra data field which can be used by the handler. It allows pragma
1547 expansion as in the following example:
1549 #define NUMBER 10
1550 #pragma count (NUMBER)
1552 Name expansion is still disallowed. */
1553 void
1554 c_register_pragma_with_expansion_and_data (const char *space, const char *name,
1555 pragma_handler_2arg handler,
1556 void *data)
1558 internal_pragma_handler ihandler;
1560 ihandler.handler.handler_2arg = handler;
1561 ihandler.extra_data = true;
1562 ihandler.data = data;
1563 c_register_pragma_1 (space, name, ihandler, true);
1566 void
1567 c_invoke_pragma_handler (unsigned int id)
1569 internal_pragma_handler *ihandler;
1570 pragma_handler_1arg handler_1arg;
1571 pragma_handler_2arg handler_2arg;
1573 id -= PRAGMA_FIRST_EXTERNAL;
1574 ihandler = &VEC_index (internal_pragma_handler, registered_pragmas, id);
1575 if (ihandler->extra_data)
1577 handler_2arg = ihandler->handler.handler_2arg;
1578 handler_2arg (parse_in, ihandler->data);
1580 else
1582 handler_1arg = ihandler->handler.handler_1arg;
1583 handler_1arg (parse_in);
1587 /* Set up front-end pragmas. */
1588 void
1589 init_pragma (void)
1591 if (flag_openmp)
1593 const int n_omp_pragmas = sizeof (omp_pragmas) / sizeof (*omp_pragmas);
1594 int i;
1596 for (i = 0; i < n_omp_pragmas; ++i)
1597 cpp_register_deferred_pragma (parse_in, "omp", omp_pragmas[i].name,
1598 omp_pragmas[i].id, true, true);
1601 if (!flag_preprocess_only)
1602 cpp_register_deferred_pragma (parse_in, "GCC", "pch_preprocess",
1603 PRAGMA_GCC_PCH_PREPROCESS, false, false);
1605 #ifdef HANDLE_PRAGMA_PACK_WITH_EXPANSION
1606 c_register_pragma_with_expansion (0, "pack", handle_pragma_pack);
1607 #else
1608 c_register_pragma (0, "pack", handle_pragma_pack);
1609 #endif
1610 c_register_pragma (0, "weak", handle_pragma_weak);
1611 c_register_pragma ("GCC", "visibility", handle_pragma_visibility);
1613 c_register_pragma ("GCC", "diagnostic", handle_pragma_diagnostic);
1614 c_register_pragma ("GCC", "target", handle_pragma_target);
1615 c_register_pragma ("GCC", "optimize", handle_pragma_optimize);
1616 c_register_pragma ("GCC", "push_options", handle_pragma_push_options);
1617 c_register_pragma ("GCC", "pop_options", handle_pragma_pop_options);
1618 c_register_pragma ("GCC", "reset_options", handle_pragma_reset_options);
1620 c_register_pragma ("STDC", "FLOAT_CONST_DECIMAL64",
1621 handle_pragma_float_const_decimal64);
1623 c_register_pragma_with_expansion (0, "redefine_extname",
1624 handle_pragma_redefine_extname);
1626 c_register_pragma_with_expansion (0, "message", handle_pragma_message);
1628 if (compiling_upc)
1630 c_register_pragma (0, "upc", handle_pragma_upc);
1631 init_pragma_upc ();
1632 c_register_pragma (0, "pupc", handle_pragma_pupc);
1633 init_pragma_pupc ();
1636 #ifdef REGISTER_TARGET_PRAGMAS
1637 REGISTER_TARGET_PRAGMAS ();
1638 #endif
1640 /* Allow plugins to register their own pragmas. */
1641 invoke_plugin_callbacks (PLUGIN_PRAGMAS, NULL);
1644 #include "gt-c-family-c-pragma.h"