* c-family/c-pragma.c (handle_pragma_upc):
[official-gcc.git] / gcc / c-family / c-pragma.c
blobb27105f3a6d0190cd1812583858e38058d34e3d3
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 "output.h"
35 #include "tm_p.h" /* For REGISTER_TARGET_PRAGMAS (why is
36 this not a target hook?). */
37 #include "vec.h"
38 #include "vecprim.h"
39 #include "target.h"
40 #include "diagnostic.h"
41 #include "opts.h"
42 #include "plugin.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;
316 FOR_EACH_VEC_ELT (pending_weak, pending_weaks, i, pe)
318 alias_id = pe->name;
319 id = pe->value;
321 if (id == NULL)
322 continue;
324 decl = build_decl (UNKNOWN_LOCATION,
325 FUNCTION_DECL, alias_id, default_function_type);
327 DECL_ARTIFICIAL (decl) = 1;
328 TREE_PUBLIC (decl) = 1;
329 DECL_EXTERNAL (decl) = 1;
330 DECL_WEAK (decl) = 1;
332 assemble_alias (decl, id);
336 /* #pragma weak name [= value] */
337 static void
338 handle_pragma_weak (cpp_reader * ARG_UNUSED (dummy))
340 tree name, value, x, decl;
341 enum cpp_ttype t;
343 value = 0;
345 if (pragma_lex (&name) != CPP_NAME)
346 GCC_BAD ("malformed #pragma weak, ignored");
347 t = pragma_lex (&x);
348 if (t == CPP_EQ)
350 if (pragma_lex (&value) != CPP_NAME)
351 GCC_BAD ("malformed #pragma weak, ignored");
352 t = pragma_lex (&x);
354 if (t != CPP_EOF)
355 warning (OPT_Wpragmas, "junk at end of %<#pragma weak%>");
357 decl = identifier_global_value (name);
358 if (decl && DECL_P (decl))
360 apply_pragma_weak (decl, value);
361 if (value)
362 assemble_alias (decl, value);
364 else
366 pending_weak *pe;
367 pe = VEC_safe_push (pending_weak, gc, pending_weaks, NULL);
368 pe->name = name;
369 pe->value = value;
373 /* GCC supports two #pragma directives for renaming the external
374 symbol associated with a declaration (DECL_ASSEMBLER_NAME), for
375 compatibility with the Solaris and VMS system headers. GCC also
376 has its own notation for this, __asm__("name") annotations.
378 Corner cases of these features and their interaction:
380 1) Both pragmas silently apply only to declarations with external
381 linkage (that is, TREE_PUBLIC || DECL_EXTERNAL). Asm labels
382 do not have this restriction.
384 2) In C++, both #pragmas silently apply only to extern "C" declarations.
385 Asm labels do not have this restriction.
387 3) If any of the three ways of changing DECL_ASSEMBLER_NAME is
388 applied to a decl whose DECL_ASSEMBLER_NAME is already set, and the
389 new name is different, a warning issues and the name does not change.
391 4) The "source name" for #pragma redefine_extname is the DECL_NAME,
392 *not* the DECL_ASSEMBLER_NAME.
394 5) If #pragma extern_prefix is in effect and a declaration occurs
395 with an __asm__ name, the #pragma extern_prefix is silently
396 ignored for that declaration.
398 6) If #pragma extern_prefix and #pragma redefine_extname apply to
399 the same declaration, whichever triggered first wins, and a warning
400 is issued. (We would like to have #pragma redefine_extname always
401 win, but it can appear either before or after the declaration, and
402 if it appears afterward, we have no way of knowing whether a modified
403 DECL_ASSEMBLER_NAME is due to #pragma extern_prefix.) */
405 typedef struct GTY(()) pending_redefinition_d {
406 tree oldname;
407 tree newname;
408 } pending_redefinition;
410 DEF_VEC_O(pending_redefinition);
411 DEF_VEC_ALLOC_O(pending_redefinition,gc);
413 static GTY(()) VEC(pending_redefinition,gc) *pending_redefine_extname;
415 static void handle_pragma_redefine_extname (cpp_reader *);
417 /* #pragma redefine_extname oldname newname */
418 static void
419 handle_pragma_redefine_extname (cpp_reader * ARG_UNUSED (dummy))
421 tree oldname, newname, decls, x;
422 enum cpp_ttype t;
423 bool found;
425 if (pragma_lex (&oldname) != CPP_NAME)
426 GCC_BAD ("malformed #pragma redefine_extname, ignored");
427 if (pragma_lex (&newname) != CPP_NAME)
428 GCC_BAD ("malformed #pragma redefine_extname, ignored");
429 t = pragma_lex (&x);
430 if (t != CPP_EOF)
431 warning (OPT_Wpragmas, "junk at end of %<#pragma redefine_extname%>");
433 found = false;
434 for (decls = c_linkage_bindings (oldname);
435 decls; )
437 tree decl;
438 if (TREE_CODE (decls) == TREE_LIST)
440 decl = TREE_VALUE (decls);
441 decls = TREE_CHAIN (decls);
443 else
445 decl = decls;
446 decls = NULL_TREE;
449 if ((TREE_PUBLIC (decl) || DECL_EXTERNAL (decl))
450 && (TREE_CODE (decl) == FUNCTION_DECL
451 || TREE_CODE (decl) == VAR_DECL))
453 found = true;
454 if (DECL_ASSEMBLER_NAME_SET_P (decl))
456 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
457 name = targetm.strip_name_encoding (name);
459 if (strcmp (name, IDENTIFIER_POINTER (newname)))
460 warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
461 "conflict with previous rename");
463 else
464 change_decl_assembler_name (decl, newname);
468 if (!found)
469 /* We have to add this to the rename list even if there's already
470 a global value that doesn't meet the above criteria, because in
471 C++ "struct foo {...};" puts "foo" in the current namespace but
472 does *not* conflict with a subsequent declaration of a function
473 or variable foo. See g++.dg/other/pragma-re-2.C. */
474 add_to_renaming_pragma_list (oldname, newname);
477 /* This is called from here and from ia64.c. */
478 void
479 add_to_renaming_pragma_list (tree oldname, tree newname)
481 unsigned ix;
482 pending_redefinition *p;
484 FOR_EACH_VEC_ELT (pending_redefinition, pending_redefine_extname, ix, p)
485 if (oldname == p->oldname)
487 if (p->newname != newname)
488 warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
489 "conflict with previous #pragma redefine_extname");
490 return;
493 p = VEC_safe_push (pending_redefinition, gc, pending_redefine_extname, NULL);
494 p->oldname = oldname;
495 p->newname = newname;
498 /* The current prefix set by #pragma extern_prefix. */
499 GTY(()) tree pragma_extern_prefix;
501 /* variables used to implement #pragma upc semantics */
502 #ifndef UPC_CMODE_STACK_INCREMENT
503 #define UPC_CMODE_STACK_INCREMENT 32
504 #endif
505 static int pragma_upc_permitted;
506 static int upc_cmode;
507 static int *upc_cmode_stack;
508 static int upc_cmode_stack_in_use;
509 static int upc_cmode_stack_allocated;
511 static void init_pragma_upc (void);
512 static void handle_pragma_upc (cpp_reader * ARG_UNUSED (dummy));
514 /* Initialize the variables used to manage the current UPC consistency
515 mode (strict/relaxed) */
517 static void
518 init_pragma_upc (void)
520 pragma_upc_permitted = 0;
521 upc_cmode = 0;
522 upc_cmode_stack = (int *) xcalloc (UPC_CMODE_STACK_INCREMENT,
523 sizeof (int));
524 upc_cmode_stack_allocated = UPC_CMODE_STACK_INCREMENT;
525 upc_cmode_stack_in_use = 0;
529 * #pragma upc strict
530 * #pragma upc relaxed
531 * #pragma upc upc_code
532 * #pragma upc c_code
534 static void
535 handle_pragma_upc (cpp_reader * ARG_UNUSED (dummy))
537 tree x;
538 enum cpp_ttype t;
539 enum upc_pragma_op {p_strict, p_relaxed, p_upc_code,
540 p_c_code, p_detect_upc, p_unknown};
541 enum upc_pragma_op upc_pragma = p_unknown;
543 if (!flag_upc)
545 warning (OPT_Wpragmas, "#pragma upc found in non-UPC source file");
546 return;
549 t = pragma_lex (&x);
550 if (t == CPP_NAME)
552 const char *op = IDENTIFIER_POINTER (x);
553 if (!strcmp (op, "strict"))
554 upc_pragma = p_strict;
555 else if (!strcmp (op, "relaxed"))
556 upc_pragma = p_relaxed;
557 else if (!strcmp (op, "upc_code"))
558 upc_pragma = p_upc_code;
559 else if (!strcmp (op, "c_code"))
560 upc_pragma = p_c_code;
561 else if (!strcmp (op, "detect_upc"))
563 const char *detect_op;
564 upc_pragma = p_detect_upc;
565 t = pragma_lex (&x);
566 if (t != CPP_NAME)
567 GCC_BAD ("missing [suspend_insertion|resume_insertion]"
568 " after %<#pragma UPC detect_upc%>");
569 detect_op = IDENTIFIER_POINTER (x);
570 if (strcmp (detect_op, "suspend_insertion") == 0)
571 /* no action */;
572 else if (strcmp (detect_op, "resume_insertion") == 0)
573 /* no action */;
574 else
575 GCC_BAD ("expected [suspend_insertion|resume_insertion]"
576 " after %<#pragma UPC detect_upc%>");
578 else
579 GCC_BAD2 ("unknown action '%s' for '#pragma upc' - ignored", op);
581 else
582 warning (OPT_Wpragmas, "missing parameter after #pragma upc");
584 t = pragma_lex (&x);
585 if (t != CPP_EOF)
586 warning (OPT_Wpragmas, "junk at end of #pragma upc");
588 if ((upc_pragma == p_strict) || (upc_pragma == p_relaxed))
590 if (pragma_upc_permitted_p ())
592 int consistency_mode = (upc_pragma == p_strict);
593 set_upc_consistency_mode (consistency_mode);
595 else
596 warning (OPT_Wpragmas, "#pragma upc not allowed in this context");
598 else if ((upc_pragma == p_upc_code) || (upc_pragma == p_c_code))
600 compiling_upc = (upc_pragma == p_upc_code);
602 else if (upc_pragma == p_detect_upc)
604 /* Skip: this is a Berkeley-specific pragma that requires no action. */
608 /* Set the current setting of the UPC consistency mode
609 that is in effect. */
611 void
612 set_upc_consistency_mode (int mode)
614 upc_cmode = mode;
617 /* Return the current setting of the UPC consistency mode. */
620 get_upc_consistency_mode (void)
622 return upc_cmode;
625 /* Called from the parser just after the bracket that opens a compound
626 statement has been parsed. Set the flag that allows the pragma
627 in this context. */
629 void
630 permit_pragma_upc (void)
632 pragma_upc_permitted = 1;
635 /* Called just before the body of a compound statement is parsed.
636 Clear the flag that allows the pragma. */
638 void
639 deny_pragma_upc (void)
641 pragma_upc_permitted = 0;
644 /* A #pragma upc is permitted either at the outermost scope,
645 or directly after the bracket that opens a compound statement. */
648 pragma_upc_permitted_p (void)
650 return !current_function_decl || pragma_upc_permitted;
653 /* Called at the beginning of every compound statement.
654 Pushes the old value of the current UPC consistency mode
655 onto the stack. */
657 void
658 push_upc_consistency_mode (void)
660 if (upc_cmode_stack_in_use == upc_cmode_stack_allocated)
662 upc_cmode_stack_allocated += UPC_CMODE_STACK_INCREMENT;
663 upc_cmode_stack = (int *) xrealloc (upc_cmode_stack,
664 upc_cmode_stack_allocated * sizeof (int));
666 upc_cmode_stack[upc_cmode_stack_in_use++] = upc_cmode;
669 /* Called at the end of every compound statement.
670 Sets the current consistency mode to the previously saved value. */
672 void
673 pop_upc_consistency_mode (void)
675 if (upc_cmode_stack_in_use <= 0)
676 abort ();
677 upc_cmode = upc_cmode_stack[--upc_cmode_stack_in_use];
680 static int pragma_pupc_on;
681 static void init_pragma_pupc (void);
682 static void handle_pragma_pupc (cpp_reader *);
684 /* Pragma pupc defaults to being on */
685 static void
686 init_pragma_pupc (void)
688 pragma_pupc_on = 1;
692 get_upc_pupc_mode (void)
694 return pragma_pupc_on;
698 disable_pupc_mode (void)
700 int old_pupc = pragma_pupc_on;
701 pragma_pupc_on = 0;
702 return old_pupc;
705 void
706 set_pupc_mode (int new_pupc)
708 pragma_pupc_on = new_pupc;
712 * #pragma pupc on
713 * #pragma pupc off
715 static void
716 handle_pragma_pupc (cpp_reader *dummy ATTRIBUTE_UNUSED)
718 tree x;
719 enum cpp_ttype t;
721 t = pragma_lex(&x);
722 if (t == CPP_NAME) {
723 const char *op = IDENTIFIER_POINTER (x);
724 if (!strcmp (op, "on"))
725 pragma_pupc_on = 1;
726 else if (!strcmp (op, "off"))
727 pragma_pupc_on = 0;
728 else
729 GCC_BAD2 ("unknown action '%s' for '#pragma pupc' - ignored", op);
732 t = pragma_lex (&x);
733 if (t != CPP_EOF)
734 warning (OPT_Wpragmas, "junk at end of #pragma pupc");
737 /* Hook from the front ends to apply the results of one of the preceding
738 pragmas that rename variables. */
740 tree
741 maybe_apply_renaming_pragma (tree decl, tree asmname)
743 unsigned ix;
744 pending_redefinition *p;
746 /* The renaming pragmas are only applied to declarations with
747 external linkage. */
748 if ((TREE_CODE (decl) != FUNCTION_DECL && TREE_CODE (decl) != VAR_DECL)
749 || (!TREE_PUBLIC (decl) && !DECL_EXTERNAL (decl))
750 || !has_c_linkage (decl))
751 return asmname;
753 /* If the DECL_ASSEMBLER_NAME is already set, it does not change,
754 but we may warn about a rename that conflicts. */
755 if (DECL_ASSEMBLER_NAME_SET_P (decl))
757 const char *oldname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
758 oldname = targetm.strip_name_encoding (oldname);
760 if (asmname && strcmp (TREE_STRING_POINTER (asmname), oldname))
761 warning (OPT_Wpragmas, "asm declaration ignored due to "
762 "conflict with previous rename");
764 /* Take any pending redefine_extname off the list. */
765 FOR_EACH_VEC_ELT (pending_redefinition, pending_redefine_extname, ix, p)
766 if (DECL_NAME (decl) == p->oldname)
768 /* Only warn if there is a conflict. */
769 if (strcmp (IDENTIFIER_POINTER (p->newname), oldname))
770 warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
771 "conflict with previous rename");
773 VEC_unordered_remove (pending_redefinition,
774 pending_redefine_extname, ix);
775 break;
777 return 0;
780 /* Find out if we have a pending #pragma redefine_extname. */
781 FOR_EACH_VEC_ELT (pending_redefinition, pending_redefine_extname, ix, p)
782 if (DECL_NAME (decl) == p->oldname)
784 tree newname = p->newname;
785 VEC_unordered_remove (pending_redefinition,
786 pending_redefine_extname, ix);
788 /* If we already have an asmname, #pragma redefine_extname is
789 ignored (with a warning if it conflicts). */
790 if (asmname)
792 if (strcmp (TREE_STRING_POINTER (asmname),
793 IDENTIFIER_POINTER (newname)) != 0)
794 warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
795 "conflict with __asm__ declaration");
796 return asmname;
799 /* Otherwise we use what we've got; #pragma extern_prefix is
800 silently ignored. */
801 return build_string (IDENTIFIER_LENGTH (newname),
802 IDENTIFIER_POINTER (newname));
805 /* If we've got an asmname, #pragma extern_prefix is silently ignored. */
806 if (asmname)
807 return asmname;
809 /* If #pragma extern_prefix is in effect, apply it. */
810 if (pragma_extern_prefix)
812 const char *prefix = TREE_STRING_POINTER (pragma_extern_prefix);
813 size_t plen = TREE_STRING_LENGTH (pragma_extern_prefix) - 1;
815 const char *id = IDENTIFIER_POINTER (DECL_NAME (decl));
816 size_t ilen = IDENTIFIER_LENGTH (DECL_NAME (decl));
818 char *newname = (char *) alloca (plen + ilen + 1);
820 memcpy (newname, prefix, plen);
821 memcpy (newname + plen, id, ilen + 1);
823 return build_string (plen + ilen, newname);
826 /* Nada. */
827 return 0;
831 static void handle_pragma_visibility (cpp_reader *);
833 static VEC (int, heap) *visstack;
835 /* Push the visibility indicated by STR onto the top of the #pragma
836 visibility stack. KIND is 0 for #pragma GCC visibility, 1 for
837 C++ namespace with visibility attribute and 2 for C++ builtin
838 ABI namespace. push_visibility/pop_visibility calls must have
839 matching KIND, it is not allowed to push visibility using one
840 KIND and pop using a different one. */
842 void
843 push_visibility (const char *str, int kind)
845 VEC_safe_push (int, heap, visstack,
846 ((int) default_visibility) | (kind << 8));
847 if (!strcmp (str, "default"))
848 default_visibility = VISIBILITY_DEFAULT;
849 else if (!strcmp (str, "internal"))
850 default_visibility = VISIBILITY_INTERNAL;
851 else if (!strcmp (str, "hidden"))
852 default_visibility = VISIBILITY_HIDDEN;
853 else if (!strcmp (str, "protected"))
854 default_visibility = VISIBILITY_PROTECTED;
855 else
856 GCC_BAD ("#pragma GCC visibility push() must specify default, internal, hidden or protected");
857 visibility_options.inpragma = 1;
860 /* Pop a level of the #pragma visibility stack. Return true if
861 successful. */
863 bool
864 pop_visibility (int kind)
866 if (!VEC_length (int, visstack))
867 return false;
868 if ((VEC_last (int, visstack) >> 8) != kind)
869 return false;
870 default_visibility
871 = (enum symbol_visibility) (VEC_pop (int, visstack) & 0xff);
872 visibility_options.inpragma
873 = VEC_length (int, visstack) != 0;
874 return true;
877 /* Sets the default visibility for symbols to something other than that
878 specified on the command line. */
880 static void
881 handle_pragma_visibility (cpp_reader *dummy ATTRIBUTE_UNUSED)
883 /* Form is #pragma GCC visibility push(hidden)|pop */
884 tree x;
885 enum cpp_ttype token;
886 enum { bad, push, pop } action = bad;
888 token = pragma_lex (&x);
889 if (token == CPP_NAME)
891 const char *op = IDENTIFIER_POINTER (x);
892 if (!strcmp (op, "push"))
893 action = push;
894 else if (!strcmp (op, "pop"))
895 action = pop;
897 if (bad == action)
898 GCC_BAD ("#pragma GCC visibility must be followed by push or pop");
899 else
901 if (pop == action)
903 if (! pop_visibility (0))
904 GCC_BAD ("no matching push for %<#pragma GCC visibility pop%>");
906 else
908 if (pragma_lex (&x) != CPP_OPEN_PAREN)
909 GCC_BAD ("missing %<(%> after %<#pragma GCC visibility push%> - ignored");
910 token = pragma_lex (&x);
911 if (token != CPP_NAME)
912 GCC_BAD ("malformed #pragma GCC visibility push");
913 else
914 push_visibility (IDENTIFIER_POINTER (x), 0);
915 if (pragma_lex (&x) != CPP_CLOSE_PAREN)
916 GCC_BAD ("missing %<(%> after %<#pragma GCC visibility push%> - ignored");
919 if (pragma_lex (&x) != CPP_EOF)
920 warning (OPT_Wpragmas, "junk at end of %<#pragma GCC visibility%>");
923 static void
924 handle_pragma_diagnostic(cpp_reader *ARG_UNUSED(dummy))
926 const char *kind_string, *option_string;
927 unsigned int option_index;
928 enum cpp_ttype token;
929 diagnostic_t kind;
930 tree x;
931 struct cl_option_handlers handlers;
933 token = pragma_lex (&x);
934 if (token != CPP_NAME)
935 GCC_BAD ("missing [error|warning|ignored] after %<#pragma GCC diagnostic%>");
936 kind_string = IDENTIFIER_POINTER (x);
937 if (strcmp (kind_string, "error") == 0)
938 kind = DK_ERROR;
939 else if (strcmp (kind_string, "warning") == 0)
940 kind = DK_WARNING;
941 else if (strcmp (kind_string, "ignored") == 0)
942 kind = DK_IGNORED;
943 else if (strcmp (kind_string, "push") == 0)
945 diagnostic_push_diagnostics (global_dc, input_location);
946 return;
948 else if (strcmp (kind_string, "pop") == 0)
950 diagnostic_pop_diagnostics (global_dc, input_location);
951 return;
953 else
954 GCC_BAD ("expected [error|warning|ignored|push|pop] after %<#pragma GCC diagnostic%>");
956 token = pragma_lex (&x);
957 if (token != CPP_STRING)
958 GCC_BAD ("missing option after %<#pragma GCC diagnostic%> kind");
959 option_string = TREE_STRING_POINTER (x);
960 set_default_handlers (&handlers);
961 for (option_index = 0; option_index < cl_options_count; option_index++)
962 if (strcmp (cl_options[option_index].opt_text, option_string) == 0)
964 control_warning_option (option_index, (int) kind, kind != DK_IGNORED,
965 input_location, c_family_lang_mask, &handlers,
966 &global_options, &global_options_set,
967 global_dc);
968 return;
970 GCC_BAD ("unknown option after %<#pragma GCC diagnostic%> kind");
973 /* Parse #pragma GCC target (xxx) to set target specific options. */
974 static void
975 handle_pragma_target(cpp_reader *ARG_UNUSED(dummy))
977 enum cpp_ttype token;
978 tree x;
979 bool close_paren_needed_p = false;
981 if (cfun)
983 error ("#pragma GCC option is not allowed inside functions");
984 return;
987 token = pragma_lex (&x);
988 if (token == CPP_OPEN_PAREN)
990 close_paren_needed_p = true;
991 token = pragma_lex (&x);
994 if (token != CPP_STRING)
996 GCC_BAD ("%<#pragma GCC option%> is not a string");
997 return;
1000 /* Strings are user options. */
1001 else
1003 tree args = NULL_TREE;
1007 /* Build up the strings now as a tree linked list. Skip empty
1008 strings. */
1009 if (TREE_STRING_LENGTH (x) > 0)
1010 args = tree_cons (NULL_TREE, x, args);
1012 token = pragma_lex (&x);
1013 while (token == CPP_COMMA)
1014 token = pragma_lex (&x);
1016 while (token == CPP_STRING);
1018 if (close_paren_needed_p)
1020 if (token == CPP_CLOSE_PAREN)
1021 token = pragma_lex (&x);
1022 else
1023 GCC_BAD ("%<#pragma GCC target (string [,string]...)%> does "
1024 "not have a final %<)%>");
1027 if (token != CPP_EOF)
1029 error ("#pragma GCC target string... is badly formed");
1030 return;
1033 /* put arguments in the order the user typed them. */
1034 args = nreverse (args);
1036 if (targetm.target_option.pragma_parse (args, NULL_TREE))
1037 current_target_pragma = args;
1041 /* Handle #pragma GCC optimize to set optimization options. */
1042 static void
1043 handle_pragma_optimize (cpp_reader *ARG_UNUSED(dummy))
1045 enum cpp_ttype token;
1046 tree x;
1047 bool close_paren_needed_p = false;
1048 tree optimization_previous_node = optimization_current_node;
1050 if (cfun)
1052 error ("#pragma GCC optimize is not allowed inside functions");
1053 return;
1056 token = pragma_lex (&x);
1057 if (token == CPP_OPEN_PAREN)
1059 close_paren_needed_p = true;
1060 token = pragma_lex (&x);
1063 if (token != CPP_STRING && token != CPP_NUMBER)
1065 GCC_BAD ("%<#pragma GCC optimize%> is not a string or number");
1066 return;
1069 /* Strings/numbers are user options. */
1070 else
1072 tree args = NULL_TREE;
1076 /* Build up the numbers/strings now as a list. */
1077 if (token != CPP_STRING || TREE_STRING_LENGTH (x) > 0)
1078 args = tree_cons (NULL_TREE, x, args);
1080 token = pragma_lex (&x);
1081 while (token == CPP_COMMA)
1082 token = pragma_lex (&x);
1084 while (token == CPP_STRING || token == CPP_NUMBER);
1086 if (close_paren_needed_p)
1088 if (token == CPP_CLOSE_PAREN)
1089 token = pragma_lex (&x);
1090 else
1091 GCC_BAD ("%<#pragma GCC optimize (string [,string]...)%> does "
1092 "not have a final %<)%>");
1095 if (token != CPP_EOF)
1097 error ("#pragma GCC optimize string... is badly formed");
1098 return;
1101 /* put arguments in the order the user typed them. */
1102 args = nreverse (args);
1104 parse_optimize_options (args, false);
1105 current_optimize_pragma = chainon (current_optimize_pragma, args);
1106 optimization_current_node = build_optimization_node ();
1107 c_cpp_builtins_optimize_pragma (parse_in,
1108 optimization_previous_node,
1109 optimization_current_node);
1113 /* Stack of the #pragma GCC options created with #pragma GCC push_option. Save
1114 both the binary representation of the options and the TREE_LIST of
1115 strings that will be added to the function's attribute list. */
1116 typedef struct GTY(()) opt_stack {
1117 struct opt_stack *prev;
1118 tree target_binary;
1119 tree target_strings;
1120 tree optimize_binary;
1121 tree optimize_strings;
1122 } opt_stack;
1124 static GTY(()) struct opt_stack * options_stack;
1126 /* Handle #pragma GCC push_options to save the current target and optimization
1127 options. */
1129 static void
1130 handle_pragma_push_options (cpp_reader *ARG_UNUSED(dummy))
1132 enum cpp_ttype token;
1133 tree x = 0;
1134 opt_stack *p;
1136 token = pragma_lex (&x);
1137 if (token != CPP_EOF)
1139 warning (OPT_Wpragmas, "junk at end of %<#pragma push_options%>");
1140 return;
1143 p = ggc_alloc_opt_stack ();
1144 p->prev = options_stack;
1145 options_stack = p;
1147 /* Save optimization and target flags in binary format. */
1148 p->optimize_binary = build_optimization_node ();
1149 p->target_binary = build_target_option_node ();
1151 /* Save optimization and target flags in string list format. */
1152 p->optimize_strings = copy_list (current_optimize_pragma);
1153 p->target_strings = copy_list (current_target_pragma);
1156 /* Handle #pragma GCC pop_options to restore the current target and
1157 optimization options from a previous push_options. */
1159 static void
1160 handle_pragma_pop_options (cpp_reader *ARG_UNUSED(dummy))
1162 enum cpp_ttype token;
1163 tree x = 0;
1164 opt_stack *p;
1166 token = pragma_lex (&x);
1167 if (token != CPP_EOF)
1169 warning (OPT_Wpragmas, "junk at end of %<#pragma pop_options%>");
1170 return;
1173 if (! options_stack)
1175 warning (OPT_Wpragmas,
1176 "%<#pragma GCC pop_options%> without a corresponding "
1177 "%<#pragma GCC push_options%>");
1178 return;
1181 p = options_stack;
1182 options_stack = p->prev;
1184 if (p->target_binary != target_option_current_node)
1186 (void) targetm.target_option.pragma_parse (NULL_TREE, p->target_binary);
1187 target_option_current_node = p->target_binary;
1190 if (p->optimize_binary != optimization_current_node)
1192 tree old_optimize = optimization_current_node;
1193 cl_optimization_restore (&global_options,
1194 TREE_OPTIMIZATION (p->optimize_binary));
1195 c_cpp_builtins_optimize_pragma (parse_in, old_optimize,
1196 p->optimize_binary);
1197 optimization_current_node = p->optimize_binary;
1200 current_target_pragma = p->target_strings;
1201 current_optimize_pragma = p->optimize_strings;
1204 /* Handle #pragma GCC reset_options to restore the current target and
1205 optimization options to the original options used on the command line. */
1207 static void
1208 handle_pragma_reset_options (cpp_reader *ARG_UNUSED(dummy))
1210 enum cpp_ttype token;
1211 tree x = 0;
1212 tree new_optimize = optimization_default_node;
1213 tree new_target = target_option_default_node;
1215 token = pragma_lex (&x);
1216 if (token != CPP_EOF)
1218 warning (OPT_Wpragmas, "junk at end of %<#pragma reset_options%>");
1219 return;
1222 if (new_target != target_option_current_node)
1224 (void) targetm.target_option.pragma_parse (NULL_TREE, new_target);
1225 target_option_current_node = new_target;
1228 if (new_optimize != optimization_current_node)
1230 tree old_optimize = optimization_current_node;
1231 cl_optimization_restore (&global_options,
1232 TREE_OPTIMIZATION (new_optimize));
1233 c_cpp_builtins_optimize_pragma (parse_in, old_optimize, new_optimize);
1234 optimization_current_node = new_optimize;
1237 current_target_pragma = NULL_TREE;
1238 current_optimize_pragma = NULL_TREE;
1241 /* Print a plain user-specified message. */
1243 static void
1244 handle_pragma_message (cpp_reader *ARG_UNUSED(dummy))
1246 enum cpp_ttype token;
1247 tree x, message = 0;
1249 token = pragma_lex (&x);
1250 if (token == CPP_OPEN_PAREN)
1252 token = pragma_lex (&x);
1253 if (token == CPP_STRING)
1254 message = x;
1255 else
1256 GCC_BAD ("expected a string after %<#pragma message%>");
1257 if (pragma_lex (&x) != CPP_CLOSE_PAREN)
1258 GCC_BAD ("malformed %<#pragma message%>, ignored");
1260 else if (token == CPP_STRING)
1261 message = x;
1262 else
1263 GCC_BAD ("expected a string after %<#pragma message%>");
1265 gcc_assert (message);
1267 if (pragma_lex (&x) != CPP_EOF)
1268 warning (OPT_Wpragmas, "junk at end of %<#pragma message%>");
1270 if (TREE_STRING_LENGTH (message) > 1)
1271 inform (input_location, "#pragma message: %s", TREE_STRING_POINTER (message));
1274 /* Mark whether the current location is valid for a STDC pragma. */
1276 static bool valid_location_for_stdc_pragma;
1278 void
1279 mark_valid_location_for_stdc_pragma (bool flag)
1281 valid_location_for_stdc_pragma = flag;
1284 /* Return true if the current location is valid for a STDC pragma. */
1286 bool
1287 valid_location_for_stdc_pragma_p (void)
1289 return valid_location_for_stdc_pragma;
1292 enum pragma_switch_t { PRAGMA_ON, PRAGMA_OFF, PRAGMA_DEFAULT, PRAGMA_BAD };
1294 /* A STDC pragma must appear outside of external declarations or
1295 preceding all explicit declarations and statements inside a compound
1296 statement; its behavior is undefined if used in any other context.
1297 It takes a switch of ON, OFF, or DEFAULT. */
1299 static enum pragma_switch_t
1300 handle_stdc_pragma (const char *pname)
1302 const char *arg;
1303 tree t;
1304 enum pragma_switch_t ret;
1306 if (!valid_location_for_stdc_pragma_p ())
1308 warning (OPT_Wpragmas, "invalid location for %<pragma %s%>, ignored",
1309 pname);
1310 return PRAGMA_BAD;
1313 if (pragma_lex (&t) != CPP_NAME)
1315 warning (OPT_Wpragmas, "malformed %<#pragma %s%>, ignored", pname);
1316 return PRAGMA_BAD;
1319 arg = IDENTIFIER_POINTER (t);
1321 if (!strcmp (arg, "ON"))
1322 ret = PRAGMA_ON;
1323 else if (!strcmp (arg, "OFF"))
1324 ret = PRAGMA_OFF;
1325 else if (!strcmp (arg, "DEFAULT"))
1326 ret = PRAGMA_DEFAULT;
1327 else
1329 warning (OPT_Wpragmas, "malformed %<#pragma %s%>, ignored", pname);
1330 return PRAGMA_BAD;
1333 if (pragma_lex (&t) != CPP_EOF)
1335 warning (OPT_Wpragmas, "junk at end of %<#pragma %s%>", pname);
1336 return PRAGMA_BAD;
1339 return ret;
1342 /* #pragma STDC FLOAT_CONST_DECIMAL64 ON
1343 #pragma STDC FLOAT_CONST_DECIMAL64 OFF
1344 #pragma STDC FLOAT_CONST_DECIMAL64 DEFAULT */
1346 static void
1347 handle_pragma_float_const_decimal64 (cpp_reader *ARG_UNUSED (dummy))
1349 if (c_dialect_cxx ())
1351 if (warn_unknown_pragmas > in_system_header)
1352 warning (OPT_Wunknown_pragmas,
1353 "%<#pragma STDC FLOAT_CONST_DECIMAL64%> is not supported"
1354 " for C++");
1355 return;
1358 if (!targetm.decimal_float_supported_p ())
1360 if (warn_unknown_pragmas > in_system_header)
1361 warning (OPT_Wunknown_pragmas,
1362 "%<#pragma STDC FLOAT_CONST_DECIMAL64%> is not supported"
1363 " on this target");
1364 return;
1367 pedwarn (input_location, OPT_pedantic,
1368 "ISO C does not support %<#pragma STDC FLOAT_CONST_DECIMAL64%>");
1370 switch (handle_stdc_pragma ("STDC FLOAT_CONST_DECIMAL64"))
1372 case PRAGMA_ON:
1373 set_float_const_decimal64 ();
1374 break;
1375 case PRAGMA_OFF:
1376 case PRAGMA_DEFAULT:
1377 clear_float_const_decimal64 ();
1378 break;
1379 case PRAGMA_BAD:
1380 break;
1384 /* A vector of registered pragma callbacks, which is never freed. */
1385 DEF_VEC_O (internal_pragma_handler);
1386 DEF_VEC_ALLOC_O (internal_pragma_handler, heap);
1388 static VEC(internal_pragma_handler, heap) *registered_pragmas;
1390 typedef struct
1392 const char *space;
1393 const char *name;
1394 } pragma_ns_name;
1396 DEF_VEC_O (pragma_ns_name);
1397 DEF_VEC_ALLOC_O (pragma_ns_name, heap);
1399 static VEC(pragma_ns_name, heap) *registered_pp_pragmas;
1401 struct omp_pragma_def { const char *name; unsigned int id; };
1402 static const struct omp_pragma_def omp_pragmas[] = {
1403 { "atomic", PRAGMA_OMP_ATOMIC },
1404 { "barrier", PRAGMA_OMP_BARRIER },
1405 { "critical", PRAGMA_OMP_CRITICAL },
1406 { "flush", PRAGMA_OMP_FLUSH },
1407 { "for", PRAGMA_OMP_FOR },
1408 { "master", PRAGMA_OMP_MASTER },
1409 { "ordered", PRAGMA_OMP_ORDERED },
1410 { "parallel", PRAGMA_OMP_PARALLEL },
1411 { "section", PRAGMA_OMP_SECTION },
1412 { "sections", PRAGMA_OMP_SECTIONS },
1413 { "single", PRAGMA_OMP_SINGLE },
1414 { "task", PRAGMA_OMP_TASK },
1415 { "taskwait", PRAGMA_OMP_TASKWAIT },
1416 { "taskyield", PRAGMA_OMP_TASKYIELD },
1417 { "threadprivate", PRAGMA_OMP_THREADPRIVATE }
1420 void
1421 c_pp_lookup_pragma (unsigned int id, const char **space, const char **name)
1423 const int n_omp_pragmas = sizeof (omp_pragmas) / sizeof (*omp_pragmas);
1424 int i;
1426 for (i = 0; i < n_omp_pragmas; ++i)
1427 if (omp_pragmas[i].id == id)
1429 *space = "omp";
1430 *name = omp_pragmas[i].name;
1431 return;
1434 if (id >= PRAGMA_FIRST_EXTERNAL
1435 && (id < PRAGMA_FIRST_EXTERNAL
1436 + VEC_length (pragma_ns_name, registered_pp_pragmas)))
1438 *space = VEC_index (pragma_ns_name, registered_pp_pragmas,
1439 id - PRAGMA_FIRST_EXTERNAL)->space;
1440 *name = VEC_index (pragma_ns_name, registered_pp_pragmas,
1441 id - PRAGMA_FIRST_EXTERNAL)->name;
1442 return;
1445 gcc_unreachable ();
1448 /* Front-end wrappers for pragma registration to avoid dragging
1449 cpplib.h in almost everywhere. */
1451 static void
1452 c_register_pragma_1 (const char *space, const char *name,
1453 internal_pragma_handler ihandler, bool allow_expansion)
1455 unsigned id;
1457 if (flag_preprocess_only)
1459 pragma_ns_name ns_name;
1461 if (!allow_expansion)
1462 return;
1464 ns_name.space = space;
1465 ns_name.name = name;
1466 VEC_safe_push (pragma_ns_name, heap, registered_pp_pragmas, &ns_name);
1467 id = VEC_length (pragma_ns_name, registered_pp_pragmas);
1468 id += PRAGMA_FIRST_EXTERNAL - 1;
1470 else
1472 VEC_safe_push (internal_pragma_handler, heap, registered_pragmas,
1473 &ihandler);
1474 id = VEC_length (internal_pragma_handler, registered_pragmas);
1475 id += PRAGMA_FIRST_EXTERNAL - 1;
1477 /* The C++ front end allocates 6 bits in cp_token; the C front end
1478 allocates 7 bits in c_token. At present this is sufficient. */
1479 gcc_assert (id < 64);
1482 cpp_register_deferred_pragma (parse_in, space, name, id,
1483 allow_expansion, false);
1486 /* Register a C pragma handler, using a space and a name. It disallows pragma
1487 expansion (if you want it, use c_register_pragma_with_expansion instead). */
1488 void
1489 c_register_pragma (const char *space, const char *name,
1490 pragma_handler_1arg handler)
1492 internal_pragma_handler ihandler;
1494 ihandler.handler.handler_1arg = handler;
1495 ihandler.extra_data = false;
1496 ihandler.data = NULL;
1497 c_register_pragma_1 (space, name, ihandler, false);
1500 /* Register a C pragma handler, using a space and a name, it also carries an
1501 extra data field which can be used by the handler. It disallows pragma
1502 expansion (if you want it, use c_register_pragma_with_expansion_and_data
1503 instead). */
1504 void
1505 c_register_pragma_with_data (const char *space, const char *name,
1506 pragma_handler_2arg handler, void * data)
1508 internal_pragma_handler ihandler;
1510 ihandler.handler.handler_2arg = handler;
1511 ihandler.extra_data = true;
1512 ihandler.data = data;
1513 c_register_pragma_1 (space, name, ihandler, false);
1516 /* Register a C pragma handler, using a space and a name. It allows pragma
1517 expansion as in the following example:
1519 #define NUMBER 10
1520 #pragma count (NUMBER)
1522 Name expansion is still disallowed. */
1523 void
1524 c_register_pragma_with_expansion (const char *space, const char *name,
1525 pragma_handler_1arg handler)
1527 internal_pragma_handler ihandler;
1529 ihandler.handler.handler_1arg = handler;
1530 ihandler.extra_data = false;
1531 ihandler.data = NULL;
1532 c_register_pragma_1 (space, name, ihandler, true);
1535 /* Register a C pragma handler, using a space and a name, it also carries an
1536 extra data field which can be used by the handler. It allows pragma
1537 expansion as in the following example:
1539 #define NUMBER 10
1540 #pragma count (NUMBER)
1542 Name expansion is still disallowed. */
1543 void
1544 c_register_pragma_with_expansion_and_data (const char *space, const char *name,
1545 pragma_handler_2arg handler,
1546 void *data)
1548 internal_pragma_handler ihandler;
1550 ihandler.handler.handler_2arg = handler;
1551 ihandler.extra_data = true;
1552 ihandler.data = data;
1553 c_register_pragma_1 (space, name, ihandler, true);
1556 void
1557 c_invoke_pragma_handler (unsigned int id)
1559 internal_pragma_handler *ihandler;
1560 pragma_handler_1arg handler_1arg;
1561 pragma_handler_2arg handler_2arg;
1563 id -= PRAGMA_FIRST_EXTERNAL;
1564 ihandler = VEC_index (internal_pragma_handler, registered_pragmas, id);
1565 if (ihandler->extra_data)
1567 handler_2arg = ihandler->handler.handler_2arg;
1568 handler_2arg (parse_in, ihandler->data);
1570 else
1572 handler_1arg = ihandler->handler.handler_1arg;
1573 handler_1arg (parse_in);
1577 /* Set up front-end pragmas. */
1578 void
1579 init_pragma (void)
1581 if (flag_openmp)
1583 const int n_omp_pragmas = sizeof (omp_pragmas) / sizeof (*omp_pragmas);
1584 int i;
1586 for (i = 0; i < n_omp_pragmas; ++i)
1587 cpp_register_deferred_pragma (parse_in, "omp", omp_pragmas[i].name,
1588 omp_pragmas[i].id, true, true);
1591 if (!flag_preprocess_only)
1592 cpp_register_deferred_pragma (parse_in, "GCC", "pch_preprocess",
1593 PRAGMA_GCC_PCH_PREPROCESS, false, false);
1595 #ifdef HANDLE_PRAGMA_PACK_WITH_EXPANSION
1596 c_register_pragma_with_expansion (0, "pack", handle_pragma_pack);
1597 #else
1598 c_register_pragma (0, "pack", handle_pragma_pack);
1599 #endif
1600 c_register_pragma (0, "weak", handle_pragma_weak);
1601 c_register_pragma ("GCC", "visibility", handle_pragma_visibility);
1603 c_register_pragma ("GCC", "diagnostic", handle_pragma_diagnostic);
1604 c_register_pragma ("GCC", "target", handle_pragma_target);
1605 c_register_pragma ("GCC", "optimize", handle_pragma_optimize);
1606 c_register_pragma ("GCC", "push_options", handle_pragma_push_options);
1607 c_register_pragma ("GCC", "pop_options", handle_pragma_pop_options);
1608 c_register_pragma ("GCC", "reset_options", handle_pragma_reset_options);
1610 c_register_pragma ("STDC", "FLOAT_CONST_DECIMAL64",
1611 handle_pragma_float_const_decimal64);
1613 c_register_pragma_with_expansion (0, "redefine_extname",
1614 handle_pragma_redefine_extname);
1616 c_register_pragma_with_expansion (0, "message", handle_pragma_message);
1618 if (compiling_upc)
1620 c_register_pragma (0, "upc", handle_pragma_upc);
1621 init_pragma_upc ();
1622 c_register_pragma (0, "pupc", handle_pragma_pupc);
1623 init_pragma_pupc ();
1626 #ifdef REGISTER_TARGET_PRAGMAS
1627 REGISTER_TARGET_PRAGMAS ();
1628 #endif
1630 /* Allow plugins to register their own pragmas. */
1631 invoke_plugin_callbacks (PLUGIN_PRAGMAS, NULL);
1634 #include "gt-c-family-c-pragma.h"