Merge trunk version 193617 into gupc branch.
[official-gcc.git] / gcc / c-family / c-pragma.c
blob2463ddc3bcd32aaa5a6d7f10657d52051dd8673e
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 "target.h"
38 #include "diagnostic.h"
39 #include "opts.h"
40 #include "plugin.h"
41 #include "cgraph.h"
43 #define GCC_BAD(gmsgid) \
44 do { warning (OPT_Wpragmas, gmsgid); return; } while (0)
45 #define GCC_BAD2(gmsgid, arg) \
46 do { warning (OPT_Wpragmas, gmsgid, arg); return; } while (0)
48 typedef struct GTY(()) align_stack {
49 int alignment;
50 tree id;
51 struct align_stack * prev;
52 } align_stack;
54 static GTY(()) struct align_stack * alignment_stack;
56 static void handle_pragma_pack (cpp_reader *);
58 /* If we have a "global" #pragma pack(<n>) in effect when the first
59 #pragma pack(push,<n>) is encountered, this stores the value of
60 maximum_field_alignment in effect. When the final pop_alignment()
61 happens, we restore the value to this, not to a value of 0 for
62 maximum_field_alignment. Value is in bits. */
63 static int default_alignment;
64 #define SET_GLOBAL_ALIGNMENT(ALIGN) (maximum_field_alignment = *(alignment_stack == NULL \
65 ? &default_alignment \
66 : &alignment_stack->alignment) = (ALIGN))
68 static void push_alignment (int, tree);
69 static void pop_alignment (tree);
71 /* Push an alignment value onto the stack. */
72 static void
73 push_alignment (int alignment, tree id)
75 align_stack * entry;
77 entry = ggc_alloc_align_stack ();
79 entry->alignment = alignment;
80 entry->id = id;
81 entry->prev = alignment_stack;
83 /* The current value of maximum_field_alignment is not necessarily
84 0 since there may be a #pragma pack(<n>) in effect; remember it
85 so that we can restore it after the final #pragma pop(). */
86 if (alignment_stack == NULL)
87 default_alignment = maximum_field_alignment;
89 alignment_stack = entry;
91 maximum_field_alignment = alignment;
94 /* Undo a push of an alignment onto the stack. */
95 static void
96 pop_alignment (tree id)
98 align_stack * entry;
100 if (alignment_stack == NULL)
101 GCC_BAD ("#pragma pack (pop) encountered without matching #pragma pack (push)");
103 /* If we got an identifier, strip away everything above the target
104 entry so that the next step will restore the state just below it. */
105 if (id)
107 for (entry = alignment_stack; entry; entry = entry->prev)
108 if (entry->id == id)
110 alignment_stack = entry;
111 break;
113 if (entry == NULL)
114 warning (OPT_Wpragmas, "\
115 #pragma pack(pop, %E) encountered without matching #pragma pack(push, %E)"
116 , id, id);
119 entry = alignment_stack->prev;
121 maximum_field_alignment = entry ? entry->alignment : default_alignment;
123 alignment_stack = entry;
126 /* #pragma pack ()
127 #pragma pack (N)
129 #pragma pack (push)
130 #pragma pack (push, N)
131 #pragma pack (push, ID)
132 #pragma pack (push, ID, N)
133 #pragma pack (pop)
134 #pragma pack (pop, ID) */
135 static void
136 handle_pragma_pack (cpp_reader * ARG_UNUSED (dummy))
138 tree x, id = 0;
139 int align = -1;
140 enum cpp_ttype token;
141 enum { set, push, pop } action;
143 if (pragma_lex (&x) != CPP_OPEN_PAREN)
144 GCC_BAD ("missing %<(%> after %<#pragma pack%> - ignored");
146 token = pragma_lex (&x);
147 if (token == CPP_CLOSE_PAREN)
149 action = set;
150 align = initial_max_fld_align;
152 else if (token == CPP_NUMBER)
154 if (TREE_CODE (x) != INTEGER_CST)
155 GCC_BAD ("invalid constant in %<#pragma pack%> - ignored");
156 align = TREE_INT_CST_LOW (x);
157 action = set;
158 if (pragma_lex (&x) != CPP_CLOSE_PAREN)
159 GCC_BAD ("malformed %<#pragma pack%> - ignored");
161 else if (token == CPP_NAME)
163 #define GCC_BAD_ACTION do { if (action != pop) \
164 GCC_BAD ("malformed %<#pragma pack(push[, id][, <n>])%> - ignored"); \
165 else \
166 GCC_BAD ("malformed %<#pragma pack(pop[, id])%> - ignored"); \
167 } while (0)
169 const char *op = IDENTIFIER_POINTER (x);
170 if (!strcmp (op, "push"))
171 action = push;
172 else if (!strcmp (op, "pop"))
173 action = pop;
174 else
175 GCC_BAD2 ("unknown action %qE for %<#pragma pack%> - ignored", x);
177 while ((token = pragma_lex (&x)) == CPP_COMMA)
179 token = pragma_lex (&x);
180 if (token == CPP_NAME && id == 0)
182 id = x;
184 else if (token == CPP_NUMBER && action == push && align == -1)
186 if (TREE_CODE (x) != INTEGER_CST)
187 GCC_BAD ("invalid constant in %<#pragma pack%> - ignored");
188 align = TREE_INT_CST_LOW (x);
189 if (align == -1)
190 action = set;
192 else
193 GCC_BAD_ACTION;
196 if (token != CPP_CLOSE_PAREN)
197 GCC_BAD_ACTION;
198 #undef GCC_BAD_ACTION
200 else
201 GCC_BAD ("malformed %<#pragma pack%> - ignored");
203 if (pragma_lex (&x) != CPP_EOF)
204 warning (OPT_Wpragmas, "junk at end of %<#pragma pack%>");
206 if (flag_pack_struct)
207 GCC_BAD ("#pragma pack has no effect with -fpack-struct - ignored");
209 if (action != pop)
210 switch (align)
212 case 0:
213 case 1:
214 case 2:
215 case 4:
216 case 8:
217 case 16:
218 align *= BITS_PER_UNIT;
219 break;
220 case -1:
221 if (action == push)
223 align = maximum_field_alignment;
224 break;
226 default:
227 GCC_BAD2 ("alignment must be a small power of two, not %d", align);
230 switch (action)
232 case set: SET_GLOBAL_ALIGNMENT (align); break;
233 case push: push_alignment (align, id); break;
234 case pop: pop_alignment (id); break;
238 typedef struct GTY(()) pending_weak_d
240 tree name;
241 tree value;
242 } pending_weak;
245 static GTY(()) vec<pending_weak, va_gc> *pending_weaks;
247 static void apply_pragma_weak (tree, tree);
248 static void handle_pragma_weak (cpp_reader *);
250 static void
251 apply_pragma_weak (tree decl, tree value)
253 if (value)
255 value = build_string (IDENTIFIER_LENGTH (value),
256 IDENTIFIER_POINTER (value));
257 decl_attributes (&decl, build_tree_list (get_identifier ("alias"),
258 build_tree_list (NULL, value)),
262 if (SUPPORTS_WEAK && DECL_EXTERNAL (decl) && TREE_USED (decl)
263 && !DECL_WEAK (decl) /* Don't complain about a redundant #pragma. */
264 && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
265 warning (OPT_Wpragmas, "applying #pragma weak %q+D after first use "
266 "results in unspecified behavior", decl);
268 declare_weak (decl);
271 void
272 maybe_apply_pragma_weak (tree decl)
274 tree id;
275 int i;
276 pending_weak *pe;
278 /* Avoid asking for DECL_ASSEMBLER_NAME when it's not needed. */
280 /* No weak symbols pending, take the short-cut. */
281 if (!pending_weaks)
282 return;
283 /* If it's not visible outside this file, it doesn't matter whether
284 it's weak. */
285 if (!DECL_EXTERNAL (decl) && !TREE_PUBLIC (decl))
286 return;
287 /* If it's not a function or a variable, it can't be weak.
288 FIXME: what kinds of things are visible outside this file but
289 aren't functions or variables? Should this be an assert instead? */
290 if (TREE_CODE (decl) != FUNCTION_DECL && TREE_CODE (decl) != VAR_DECL)
291 return;
293 id = DECL_ASSEMBLER_NAME (decl);
295 FOR_EACH_VEC_ELT (*pending_weaks, i, pe)
296 if (id == pe->name)
298 apply_pragma_weak (decl, pe->value);
299 pending_weaks->unordered_remove (i);
300 break;
304 /* Process all "#pragma weak A = B" directives where we have not seen
305 a decl for A. */
306 void
307 maybe_apply_pending_pragma_weaks (void)
309 tree alias_id, id, decl;
310 int i;
311 pending_weak *pe;
312 symtab_node target;
314 if (!pending_weaks)
315 return;
317 FOR_EACH_VEC_ELT (*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 = {name, value};
377 vec_safe_push (pending_weaks, pe);
381 /* GCC supports two #pragma directives for renaming the external
382 symbol associated with a declaration (DECL_ASSEMBLER_NAME), for
383 compatibility with the Solaris and VMS system headers. GCC also
384 has its own notation for this, __asm__("name") annotations.
386 Corner cases of these features and their interaction:
388 1) Both pragmas silently apply only to declarations with external
389 linkage (that is, TREE_PUBLIC || DECL_EXTERNAL). Asm labels
390 do not have this restriction.
392 2) In C++, both #pragmas silently apply only to extern "C" declarations.
393 Asm labels do not have this restriction.
395 3) If any of the three ways of changing DECL_ASSEMBLER_NAME is
396 applied to a decl whose DECL_ASSEMBLER_NAME is already set, and the
397 new name is different, a warning issues and the name does not change.
399 4) The "source name" for #pragma redefine_extname is the DECL_NAME,
400 *not* the DECL_ASSEMBLER_NAME.
402 5) If #pragma extern_prefix is in effect and a declaration occurs
403 with an __asm__ name, the #pragma extern_prefix is silently
404 ignored for that declaration.
406 6) If #pragma extern_prefix and #pragma redefine_extname apply to
407 the same declaration, whichever triggered first wins, and a warning
408 is issued. (We would like to have #pragma redefine_extname always
409 win, but it can appear either before or after the declaration, and
410 if it appears afterward, we have no way of knowing whether a modified
411 DECL_ASSEMBLER_NAME is due to #pragma extern_prefix.) */
413 typedef struct GTY(()) pending_redefinition_d {
414 tree oldname;
415 tree newname;
416 } pending_redefinition;
419 static GTY(()) vec<pending_redefinition, va_gc> *pending_redefine_extname;
421 static void handle_pragma_redefine_extname (cpp_reader *);
423 /* #pragma redefine_extname oldname newname */
424 static void
425 handle_pragma_redefine_extname (cpp_reader * ARG_UNUSED (dummy))
427 tree oldname, newname, decls, x;
428 enum cpp_ttype t;
429 bool found;
431 if (pragma_lex (&oldname) != CPP_NAME)
432 GCC_BAD ("malformed #pragma redefine_extname, ignored");
433 if (pragma_lex (&newname) != CPP_NAME)
434 GCC_BAD ("malformed #pragma redefine_extname, ignored");
435 t = pragma_lex (&x);
436 if (t != CPP_EOF)
437 warning (OPT_Wpragmas, "junk at end of %<#pragma redefine_extname%>");
439 found = false;
440 for (decls = c_linkage_bindings (oldname);
441 decls; )
443 tree decl;
444 if (TREE_CODE (decls) == TREE_LIST)
446 decl = TREE_VALUE (decls);
447 decls = TREE_CHAIN (decls);
449 else
451 decl = decls;
452 decls = NULL_TREE;
455 if ((TREE_PUBLIC (decl) || DECL_EXTERNAL (decl))
456 && (TREE_CODE (decl) == FUNCTION_DECL
457 || TREE_CODE (decl) == VAR_DECL))
459 found = true;
460 if (DECL_ASSEMBLER_NAME_SET_P (decl))
462 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
463 name = targetm.strip_name_encoding (name);
465 if (strcmp (name, IDENTIFIER_POINTER (newname)))
466 warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
467 "conflict with previous rename");
469 else
470 change_decl_assembler_name (decl, newname);
474 if (!found)
475 /* We have to add this to the rename list even if there's already
476 a global value that doesn't meet the above criteria, because in
477 C++ "struct foo {...};" puts "foo" in the current namespace but
478 does *not* conflict with a subsequent declaration of a function
479 or variable foo. See g++.dg/other/pragma-re-2.C. */
480 add_to_renaming_pragma_list (oldname, newname);
483 /* This is called from here and from ia64.c. */
484 void
485 add_to_renaming_pragma_list (tree oldname, tree newname)
487 unsigned ix;
488 pending_redefinition *p;
490 FOR_EACH_VEC_SAFE_ELT (pending_redefine_extname, ix, p)
491 if (oldname == p->oldname)
493 if (p->newname != newname)
494 warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
495 "conflict with previous #pragma redefine_extname");
496 return;
499 pending_redefinition e = {oldname, newname};
500 vec_safe_push (pending_redefine_extname, e);
503 /* The current prefix set by #pragma extern_prefix. */
504 GTY(()) tree pragma_extern_prefix;
506 /* variables used to implement #pragma upc semantics */
507 #ifndef UPC_CMODE_STACK_INCREMENT
508 #define UPC_CMODE_STACK_INCREMENT 32
509 #endif
510 static int pragma_upc_permitted;
511 static int upc_cmode;
512 static int *upc_cmode_stack;
513 static int upc_cmode_stack_in_use;
514 static int upc_cmode_stack_allocated;
516 static void init_pragma_upc (void);
517 static void handle_pragma_upc (cpp_reader * ARG_UNUSED (dummy));
519 /* Initialize the variables used to manage the current UPC consistency
520 mode (strict/relaxed) */
522 static void
523 init_pragma_upc (void)
525 pragma_upc_permitted = 0;
526 upc_cmode = 0;
527 upc_cmode_stack = (int *) xcalloc (UPC_CMODE_STACK_INCREMENT,
528 sizeof (int));
529 upc_cmode_stack_allocated = UPC_CMODE_STACK_INCREMENT;
530 upc_cmode_stack_in_use = 0;
534 * #pragma upc strict
535 * #pragma upc relaxed
536 * #pragma upc upc_code
537 * #pragma upc c_code
539 static void
540 handle_pragma_upc (cpp_reader * ARG_UNUSED (dummy))
542 tree x;
543 enum cpp_ttype t;
544 enum upc_pragma_op {p_strict, p_relaxed, p_upc_code,
545 p_c_code, p_detect_upc, p_unknown};
546 enum upc_pragma_op upc_pragma = p_unknown;
548 if (!flag_upc)
550 warning (OPT_Wpragmas, "#pragma upc found in non-UPC source file");
551 return;
554 t = pragma_lex (&x);
555 if (t == CPP_NAME)
557 const char *op = IDENTIFIER_POINTER (x);
558 if (!strcmp (op, "strict"))
559 upc_pragma = p_strict;
560 else if (!strcmp (op, "relaxed"))
561 upc_pragma = p_relaxed;
562 else if (!strcmp (op, "upc_code"))
563 upc_pragma = p_upc_code;
564 else if (!strcmp (op, "c_code"))
565 upc_pragma = p_c_code;
566 else if (!strcmp (op, "detect_upc"))
568 const char *detect_op;
569 upc_pragma = p_detect_upc;
570 t = pragma_lex (&x);
571 if (t != CPP_NAME)
572 GCC_BAD ("missing [suspend_insertion|resume_insertion]"
573 " after %<#pragma UPC detect_upc%>");
574 detect_op = IDENTIFIER_POINTER (x);
575 if (strcmp (detect_op, "suspend_insertion") == 0)
576 /* no action */;
577 else if (strcmp (detect_op, "resume_insertion") == 0)
578 /* no action */;
579 else
580 GCC_BAD ("expected [suspend_insertion|resume_insertion]"
581 " after %<#pragma UPC detect_upc%>");
583 else
584 GCC_BAD2 ("unknown action '%s' for '#pragma upc' - ignored", op);
586 else
587 warning (OPT_Wpragmas, "missing parameter after #pragma upc");
589 t = pragma_lex (&x);
590 if (t != CPP_EOF)
591 warning (OPT_Wpragmas, "junk at end of #pragma upc");
593 if ((upc_pragma == p_strict) || (upc_pragma == p_relaxed))
595 if (pragma_upc_permitted_p ())
597 int consistency_mode = (upc_pragma == p_strict);
598 set_upc_consistency_mode (consistency_mode);
600 else
601 warning (OPT_Wpragmas, "#pragma upc not allowed in this context");
603 else if ((upc_pragma == p_upc_code) || (upc_pragma == p_c_code))
605 compiling_upc = (upc_pragma == p_upc_code);
607 else if (upc_pragma == p_detect_upc)
609 /* Skip: this is a Berkeley-specific pragma that requires no action. */
613 /* Set the current setting of the UPC consistency mode
614 that is in effect. */
616 void
617 set_upc_consistency_mode (int mode)
619 upc_cmode = mode;
622 /* Return the current setting of the UPC consistency mode. */
625 get_upc_consistency_mode (void)
627 return upc_cmode;
630 /* Called from the parser just after the bracket that opens a compound
631 statement has been parsed. Set the flag that allows the pragma
632 in this context. */
634 void
635 permit_pragma_upc (void)
637 pragma_upc_permitted = 1;
640 /* Called just before the body of a compound statement is parsed.
641 Clear the flag that allows the pragma. */
643 void
644 deny_pragma_upc (void)
646 pragma_upc_permitted = 0;
649 /* A #pragma upc is permitted either at the outermost scope,
650 or directly after the bracket that opens a compound statement. */
653 pragma_upc_permitted_p (void)
655 return !current_function_decl || pragma_upc_permitted;
658 /* Called at the beginning of every compound statement.
659 Pushes the old value of the current UPC consistency mode
660 onto the stack. */
662 void
663 push_upc_consistency_mode (void)
665 if (upc_cmode_stack_in_use == upc_cmode_stack_allocated)
667 upc_cmode_stack_allocated += UPC_CMODE_STACK_INCREMENT;
668 upc_cmode_stack = (int *) xrealloc (upc_cmode_stack,
669 upc_cmode_stack_allocated * sizeof (int));
671 upc_cmode_stack[upc_cmode_stack_in_use++] = upc_cmode;
674 /* Called at the end of every compound statement.
675 Sets the current consistency mode to the previously saved value. */
677 void
678 pop_upc_consistency_mode (void)
680 if (upc_cmode_stack_in_use <= 0)
681 abort ();
682 upc_cmode = upc_cmode_stack[--upc_cmode_stack_in_use];
685 static int pragma_pupc_on;
686 static void init_pragma_pupc (void);
687 static void handle_pragma_pupc (cpp_reader *);
689 /* Pragma pupc defaults to being on */
690 static void
691 init_pragma_pupc (void)
693 pragma_pupc_on = 1;
697 get_upc_pupc_mode (void)
699 return pragma_pupc_on;
703 disable_pupc_mode (void)
705 int old_pupc = pragma_pupc_on;
706 pragma_pupc_on = 0;
707 return old_pupc;
710 void
711 set_pupc_mode (int new_pupc)
713 pragma_pupc_on = new_pupc;
717 * #pragma pupc on
718 * #pragma pupc off
720 static void
721 handle_pragma_pupc (cpp_reader *dummy ATTRIBUTE_UNUSED)
723 tree x;
724 enum cpp_ttype t;
726 t = pragma_lex(&x);
727 if (t == CPP_NAME) {
728 const char *op = IDENTIFIER_POINTER (x);
729 if (!strcmp (op, "on"))
730 pragma_pupc_on = 1;
731 else if (!strcmp (op, "off"))
732 pragma_pupc_on = 0;
733 else
734 GCC_BAD2 ("unknown action '%s' for '#pragma pupc' - ignored", op);
737 t = pragma_lex (&x);
738 if (t != CPP_EOF)
739 warning (OPT_Wpragmas, "junk at end of #pragma pupc");
742 /* Hook from the front ends to apply the results of one of the preceding
743 pragmas that rename variables. */
745 tree
746 maybe_apply_renaming_pragma (tree decl, tree asmname)
748 unsigned ix;
749 pending_redefinition *p;
751 /* The renaming pragmas are only applied to declarations with
752 external linkage. */
753 if ((TREE_CODE (decl) != FUNCTION_DECL && TREE_CODE (decl) != VAR_DECL)
754 || (!TREE_PUBLIC (decl) && !DECL_EXTERNAL (decl))
755 || !has_c_linkage (decl))
756 return asmname;
758 /* If the DECL_ASSEMBLER_NAME is already set, it does not change,
759 but we may warn about a rename that conflicts. */
760 if (DECL_ASSEMBLER_NAME_SET_P (decl))
762 const char *oldname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
763 oldname = targetm.strip_name_encoding (oldname);
765 if (asmname && strcmp (TREE_STRING_POINTER (asmname), oldname))
766 warning (OPT_Wpragmas, "asm declaration ignored due to "
767 "conflict with previous rename");
769 /* Take any pending redefine_extname off the list. */
770 FOR_EACH_VEC_SAFE_ELT (pending_redefine_extname, ix, p)
771 if (DECL_NAME (decl) == p->oldname)
773 /* Only warn if there is a conflict. */
774 if (strcmp (IDENTIFIER_POINTER (p->newname), oldname))
775 warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
776 "conflict with previous rename");
778 pending_redefine_extname->unordered_remove (ix);
779 break;
781 return 0;
784 /* Find out if we have a pending #pragma redefine_extname. */
785 FOR_EACH_VEC_SAFE_ELT (pending_redefine_extname, ix, p)
786 if (DECL_NAME (decl) == p->oldname)
788 tree newname = p->newname;
789 pending_redefine_extname->unordered_remove (ix);
791 /* If we already have an asmname, #pragma redefine_extname is
792 ignored (with a warning if it conflicts). */
793 if (asmname)
795 if (strcmp (TREE_STRING_POINTER (asmname),
796 IDENTIFIER_POINTER (newname)) != 0)
797 warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
798 "conflict with __asm__ declaration");
799 return asmname;
802 /* Otherwise we use what we've got; #pragma extern_prefix is
803 silently ignored. */
804 return build_string (IDENTIFIER_LENGTH (newname),
805 IDENTIFIER_POINTER (newname));
808 /* If we've got an asmname, #pragma extern_prefix is silently ignored. */
809 if (asmname)
810 return asmname;
812 /* If #pragma extern_prefix is in effect, apply it. */
813 if (pragma_extern_prefix)
815 const char *prefix = TREE_STRING_POINTER (pragma_extern_prefix);
816 size_t plen = TREE_STRING_LENGTH (pragma_extern_prefix) - 1;
818 const char *id = IDENTIFIER_POINTER (DECL_NAME (decl));
819 size_t ilen = IDENTIFIER_LENGTH (DECL_NAME (decl));
821 char *newname = (char *) alloca (plen + ilen + 1);
823 memcpy (newname, prefix, plen);
824 memcpy (newname + plen, id, ilen + 1);
826 return build_string (plen + ilen, newname);
829 /* Nada. */
830 return 0;
834 static void handle_pragma_visibility (cpp_reader *);
836 static vec<int> visstack;
838 /* Push the visibility indicated by STR onto the top of the #pragma
839 visibility stack. KIND is 0 for #pragma GCC visibility, 1 for
840 C++ namespace with visibility attribute and 2 for C++ builtin
841 ABI namespace. push_visibility/pop_visibility calls must have
842 matching KIND, it is not allowed to push visibility using one
843 KIND and pop using a different one. */
845 void
846 push_visibility (const char *str, int kind)
848 visstack.safe_push (((int) default_visibility) | (kind << 8));
849 if (!strcmp (str, "default"))
850 default_visibility = VISIBILITY_DEFAULT;
851 else if (!strcmp (str, "internal"))
852 default_visibility = VISIBILITY_INTERNAL;
853 else if (!strcmp (str, "hidden"))
854 default_visibility = VISIBILITY_HIDDEN;
855 else if (!strcmp (str, "protected"))
856 default_visibility = VISIBILITY_PROTECTED;
857 else
858 GCC_BAD ("#pragma GCC visibility push() must specify default, internal, hidden or protected");
859 visibility_options.inpragma = 1;
862 /* Pop a level of the #pragma visibility stack. Return true if
863 successful. */
865 bool
866 pop_visibility (int kind)
868 if (!visstack.length ())
869 return false;
870 if ((visstack.last () >> 8) != kind)
871 return false;
872 default_visibility
873 = (enum symbol_visibility) (visstack.pop () & 0xff);
874 visibility_options.inpragma
875 = visstack.length () != 0;
876 return true;
879 /* Sets the default visibility for symbols to something other than that
880 specified on the command line. */
882 static void
883 handle_pragma_visibility (cpp_reader *dummy ATTRIBUTE_UNUSED)
885 /* Form is #pragma GCC visibility push(hidden)|pop */
886 tree x;
887 enum cpp_ttype token;
888 enum { bad, push, pop } action = bad;
890 token = pragma_lex (&x);
891 if (token == CPP_NAME)
893 const char *op = IDENTIFIER_POINTER (x);
894 if (!strcmp (op, "push"))
895 action = push;
896 else if (!strcmp (op, "pop"))
897 action = pop;
899 if (bad == action)
900 GCC_BAD ("#pragma GCC visibility must be followed by push or pop");
901 else
903 if (pop == action)
905 if (! pop_visibility (0))
906 GCC_BAD ("no matching push for %<#pragma GCC visibility pop%>");
908 else
910 if (pragma_lex (&x) != CPP_OPEN_PAREN)
911 GCC_BAD ("missing %<(%> after %<#pragma GCC visibility push%> - ignored");
912 token = pragma_lex (&x);
913 if (token != CPP_NAME)
914 GCC_BAD ("malformed #pragma GCC visibility push");
915 else
916 push_visibility (IDENTIFIER_POINTER (x), 0);
917 if (pragma_lex (&x) != CPP_CLOSE_PAREN)
918 GCC_BAD ("missing %<(%> after %<#pragma GCC visibility push%> - ignored");
921 if (pragma_lex (&x) != CPP_EOF)
922 warning (OPT_Wpragmas, "junk at end of %<#pragma GCC visibility%>");
925 static void
926 handle_pragma_diagnostic(cpp_reader *ARG_UNUSED(dummy))
928 const char *kind_string, *option_string;
929 unsigned int option_index;
930 enum cpp_ttype token;
931 diagnostic_t kind;
932 tree x;
933 struct cl_option_handlers handlers;
935 token = pragma_lex (&x);
936 if (token != CPP_NAME)
937 GCC_BAD ("missing [error|warning|ignored] after %<#pragma GCC diagnostic%>");
938 kind_string = IDENTIFIER_POINTER (x);
939 if (strcmp (kind_string, "error") == 0)
940 kind = DK_ERROR;
941 else if (strcmp (kind_string, "warning") == 0)
942 kind = DK_WARNING;
943 else if (strcmp (kind_string, "ignored") == 0)
944 kind = DK_IGNORED;
945 else if (strcmp (kind_string, "push") == 0)
947 diagnostic_push_diagnostics (global_dc, input_location);
948 return;
950 else if (strcmp (kind_string, "pop") == 0)
952 diagnostic_pop_diagnostics (global_dc, input_location);
953 return;
955 else
956 GCC_BAD ("expected [error|warning|ignored|push|pop] after %<#pragma GCC diagnostic%>");
958 token = pragma_lex (&x);
959 if (token != CPP_STRING)
960 GCC_BAD ("missing option after %<#pragma GCC diagnostic%> kind");
961 option_string = TREE_STRING_POINTER (x);
962 set_default_handlers (&handlers);
963 for (option_index = 0; option_index < cl_options_count; option_index++)
964 if (strcmp (cl_options[option_index].opt_text, option_string) == 0)
966 control_warning_option (option_index, (int) kind, kind != DK_IGNORED,
967 input_location, c_family_lang_mask, &handlers,
968 &global_options, &global_options_set,
969 global_dc);
970 return;
972 GCC_BAD ("unknown option after %<#pragma GCC diagnostic%> kind");
975 /* Parse #pragma GCC target (xxx) to set target specific options. */
976 static void
977 handle_pragma_target(cpp_reader *ARG_UNUSED(dummy))
979 enum cpp_ttype token;
980 tree x;
981 bool close_paren_needed_p = false;
983 if (cfun)
985 error ("#pragma GCC option is not allowed inside functions");
986 return;
989 token = pragma_lex (&x);
990 if (token == CPP_OPEN_PAREN)
992 close_paren_needed_p = true;
993 token = pragma_lex (&x);
996 if (token != CPP_STRING)
998 GCC_BAD ("%<#pragma GCC option%> is not a string");
999 return;
1002 /* Strings are user options. */
1003 else
1005 tree args = NULL_TREE;
1009 /* Build up the strings now as a tree linked list. Skip empty
1010 strings. */
1011 if (TREE_STRING_LENGTH (x) > 0)
1012 args = tree_cons (NULL_TREE, x, args);
1014 token = pragma_lex (&x);
1015 while (token == CPP_COMMA)
1016 token = pragma_lex (&x);
1018 while (token == CPP_STRING);
1020 if (close_paren_needed_p)
1022 if (token == CPP_CLOSE_PAREN)
1023 token = pragma_lex (&x);
1024 else
1025 GCC_BAD ("%<#pragma GCC target (string [,string]...)%> does "
1026 "not have a final %<)%>");
1029 if (token != CPP_EOF)
1031 error ("#pragma GCC target string... is badly formed");
1032 return;
1035 /* put arguments in the order the user typed them. */
1036 args = nreverse (args);
1038 if (targetm.target_option.pragma_parse (args, NULL_TREE))
1039 current_target_pragma = args;
1043 /* Handle #pragma GCC optimize to set optimization options. */
1044 static void
1045 handle_pragma_optimize (cpp_reader *ARG_UNUSED(dummy))
1047 enum cpp_ttype token;
1048 tree x;
1049 bool close_paren_needed_p = false;
1050 tree optimization_previous_node = optimization_current_node;
1052 if (cfun)
1054 error ("#pragma GCC optimize is not allowed inside functions");
1055 return;
1058 token = pragma_lex (&x);
1059 if (token == CPP_OPEN_PAREN)
1061 close_paren_needed_p = true;
1062 token = pragma_lex (&x);
1065 if (token != CPP_STRING && token != CPP_NUMBER)
1067 GCC_BAD ("%<#pragma GCC optimize%> is not a string or number");
1068 return;
1071 /* Strings/numbers are user options. */
1072 else
1074 tree args = NULL_TREE;
1078 /* Build up the numbers/strings now as a list. */
1079 if (token != CPP_STRING || TREE_STRING_LENGTH (x) > 0)
1080 args = tree_cons (NULL_TREE, x, args);
1082 token = pragma_lex (&x);
1083 while (token == CPP_COMMA)
1084 token = pragma_lex (&x);
1086 while (token == CPP_STRING || token == CPP_NUMBER);
1088 if (close_paren_needed_p)
1090 if (token == CPP_CLOSE_PAREN)
1091 token = pragma_lex (&x);
1092 else
1093 GCC_BAD ("%<#pragma GCC optimize (string [,string]...)%> does "
1094 "not have a final %<)%>");
1097 if (token != CPP_EOF)
1099 error ("#pragma GCC optimize string... is badly formed");
1100 return;
1103 /* put arguments in the order the user typed them. */
1104 args = nreverse (args);
1106 parse_optimize_options (args, false);
1107 current_optimize_pragma = chainon (current_optimize_pragma, args);
1108 optimization_current_node = build_optimization_node ();
1109 c_cpp_builtins_optimize_pragma (parse_in,
1110 optimization_previous_node,
1111 optimization_current_node);
1115 /* Stack of the #pragma GCC options created with #pragma GCC push_option. Save
1116 both the binary representation of the options and the TREE_LIST of
1117 strings that will be added to the function's attribute list. */
1118 typedef struct GTY(()) opt_stack {
1119 struct opt_stack *prev;
1120 tree target_binary;
1121 tree target_strings;
1122 tree optimize_binary;
1123 tree optimize_strings;
1124 } opt_stack;
1126 static GTY(()) struct opt_stack * options_stack;
1128 /* Handle #pragma GCC push_options to save the current target and optimization
1129 options. */
1131 static void
1132 handle_pragma_push_options (cpp_reader *ARG_UNUSED(dummy))
1134 enum cpp_ttype token;
1135 tree x = 0;
1136 opt_stack *p;
1138 token = pragma_lex (&x);
1139 if (token != CPP_EOF)
1141 warning (OPT_Wpragmas, "junk at end of %<#pragma push_options%>");
1142 return;
1145 p = ggc_alloc_opt_stack ();
1146 p->prev = options_stack;
1147 options_stack = p;
1149 /* Save optimization and target flags in binary format. */
1150 p->optimize_binary = build_optimization_node ();
1151 p->target_binary = build_target_option_node ();
1153 /* Save optimization and target flags in string list format. */
1154 p->optimize_strings = copy_list (current_optimize_pragma);
1155 p->target_strings = copy_list (current_target_pragma);
1158 /* Handle #pragma GCC pop_options to restore the current target and
1159 optimization options from a previous push_options. */
1161 static void
1162 handle_pragma_pop_options (cpp_reader *ARG_UNUSED(dummy))
1164 enum cpp_ttype token;
1165 tree x = 0;
1166 opt_stack *p;
1168 token = pragma_lex (&x);
1169 if (token != CPP_EOF)
1171 warning (OPT_Wpragmas, "junk at end of %<#pragma pop_options%>");
1172 return;
1175 if (! options_stack)
1177 warning (OPT_Wpragmas,
1178 "%<#pragma GCC pop_options%> without a corresponding "
1179 "%<#pragma GCC push_options%>");
1180 return;
1183 p = options_stack;
1184 options_stack = p->prev;
1186 if (p->target_binary != target_option_current_node)
1188 (void) targetm.target_option.pragma_parse (NULL_TREE, p->target_binary);
1189 target_option_current_node = p->target_binary;
1192 if (p->optimize_binary != optimization_current_node)
1194 tree old_optimize = optimization_current_node;
1195 cl_optimization_restore (&global_options,
1196 TREE_OPTIMIZATION (p->optimize_binary));
1197 c_cpp_builtins_optimize_pragma (parse_in, old_optimize,
1198 p->optimize_binary);
1199 optimization_current_node = p->optimize_binary;
1202 current_target_pragma = p->target_strings;
1203 current_optimize_pragma = p->optimize_strings;
1206 /* Handle #pragma GCC reset_options to restore the current target and
1207 optimization options to the original options used on the command line. */
1209 static void
1210 handle_pragma_reset_options (cpp_reader *ARG_UNUSED(dummy))
1212 enum cpp_ttype token;
1213 tree x = 0;
1214 tree new_optimize = optimization_default_node;
1215 tree new_target = target_option_default_node;
1217 token = pragma_lex (&x);
1218 if (token != CPP_EOF)
1220 warning (OPT_Wpragmas, "junk at end of %<#pragma reset_options%>");
1221 return;
1224 if (new_target != target_option_current_node)
1226 (void) targetm.target_option.pragma_parse (NULL_TREE, new_target);
1227 target_option_current_node = new_target;
1230 if (new_optimize != optimization_current_node)
1232 tree old_optimize = optimization_current_node;
1233 cl_optimization_restore (&global_options,
1234 TREE_OPTIMIZATION (new_optimize));
1235 c_cpp_builtins_optimize_pragma (parse_in, old_optimize, new_optimize);
1236 optimization_current_node = new_optimize;
1239 current_target_pragma = NULL_TREE;
1240 current_optimize_pragma = NULL_TREE;
1243 /* Print a plain user-specified message. */
1245 static void
1246 handle_pragma_message (cpp_reader *ARG_UNUSED(dummy))
1248 enum cpp_ttype token;
1249 tree x, message = 0;
1251 token = pragma_lex (&x);
1252 if (token == CPP_OPEN_PAREN)
1254 token = pragma_lex (&x);
1255 if (token == CPP_STRING)
1256 message = x;
1257 else
1258 GCC_BAD ("expected a string after %<#pragma message%>");
1259 if (pragma_lex (&x) != CPP_CLOSE_PAREN)
1260 GCC_BAD ("malformed %<#pragma message%>, ignored");
1262 else if (token == CPP_STRING)
1263 message = x;
1264 else
1265 GCC_BAD ("expected a string after %<#pragma message%>");
1267 gcc_assert (message);
1269 if (pragma_lex (&x) != CPP_EOF)
1270 warning (OPT_Wpragmas, "junk at end of %<#pragma message%>");
1272 if (TREE_STRING_LENGTH (message) > 1)
1273 inform (input_location, "#pragma message: %s", TREE_STRING_POINTER (message));
1276 /* Mark whether the current location is valid for a STDC pragma. */
1278 static bool valid_location_for_stdc_pragma;
1280 void
1281 mark_valid_location_for_stdc_pragma (bool flag)
1283 valid_location_for_stdc_pragma = flag;
1286 /* Return true if the current location is valid for a STDC pragma. */
1288 bool
1289 valid_location_for_stdc_pragma_p (void)
1291 return valid_location_for_stdc_pragma;
1294 enum pragma_switch_t { PRAGMA_ON, PRAGMA_OFF, PRAGMA_DEFAULT, PRAGMA_BAD };
1296 /* A STDC pragma must appear outside of external declarations or
1297 preceding all explicit declarations and statements inside a compound
1298 statement; its behavior is undefined if used in any other context.
1299 It takes a switch of ON, OFF, or DEFAULT. */
1301 static enum pragma_switch_t
1302 handle_stdc_pragma (const char *pname)
1304 const char *arg;
1305 tree t;
1306 enum pragma_switch_t ret;
1308 if (!valid_location_for_stdc_pragma_p ())
1310 warning (OPT_Wpragmas, "invalid location for %<pragma %s%>, ignored",
1311 pname);
1312 return PRAGMA_BAD;
1315 if (pragma_lex (&t) != CPP_NAME)
1317 warning (OPT_Wpragmas, "malformed %<#pragma %s%>, ignored", pname);
1318 return PRAGMA_BAD;
1321 arg = IDENTIFIER_POINTER (t);
1323 if (!strcmp (arg, "ON"))
1324 ret = PRAGMA_ON;
1325 else if (!strcmp (arg, "OFF"))
1326 ret = PRAGMA_OFF;
1327 else if (!strcmp (arg, "DEFAULT"))
1328 ret = PRAGMA_DEFAULT;
1329 else
1331 warning (OPT_Wpragmas, "malformed %<#pragma %s%>, ignored", pname);
1332 return PRAGMA_BAD;
1335 if (pragma_lex (&t) != CPP_EOF)
1337 warning (OPT_Wpragmas, "junk at end of %<#pragma %s%>", pname);
1338 return PRAGMA_BAD;
1341 return ret;
1344 /* #pragma STDC FLOAT_CONST_DECIMAL64 ON
1345 #pragma STDC FLOAT_CONST_DECIMAL64 OFF
1346 #pragma STDC FLOAT_CONST_DECIMAL64 DEFAULT */
1348 static void
1349 handle_pragma_float_const_decimal64 (cpp_reader *ARG_UNUSED (dummy))
1351 if (c_dialect_cxx ())
1353 if (warn_unknown_pragmas > in_system_header)
1354 warning (OPT_Wunknown_pragmas,
1355 "%<#pragma STDC FLOAT_CONST_DECIMAL64%> is not supported"
1356 " for C++");
1357 return;
1360 if (!targetm.decimal_float_supported_p ())
1362 if (warn_unknown_pragmas > in_system_header)
1363 warning (OPT_Wunknown_pragmas,
1364 "%<#pragma STDC FLOAT_CONST_DECIMAL64%> is not supported"
1365 " on this target");
1366 return;
1369 pedwarn (input_location, OPT_Wpedantic,
1370 "ISO C does not support %<#pragma STDC FLOAT_CONST_DECIMAL64%>");
1372 switch (handle_stdc_pragma ("STDC FLOAT_CONST_DECIMAL64"))
1374 case PRAGMA_ON:
1375 set_float_const_decimal64 ();
1376 break;
1377 case PRAGMA_OFF:
1378 case PRAGMA_DEFAULT:
1379 clear_float_const_decimal64 ();
1380 break;
1381 case PRAGMA_BAD:
1382 break;
1386 /* A vector of registered pragma callbacks, which is never freed. */
1388 static vec<internal_pragma_handler> registered_pragmas;
1390 typedef struct
1392 const char *space;
1393 const char *name;
1394 } pragma_ns_name;
1397 static vec<pragma_ns_name> registered_pp_pragmas;
1399 struct omp_pragma_def { const char *name; unsigned int id; };
1400 static const struct omp_pragma_def omp_pragmas[] = {
1401 { "atomic", PRAGMA_OMP_ATOMIC },
1402 { "barrier", PRAGMA_OMP_BARRIER },
1403 { "critical", PRAGMA_OMP_CRITICAL },
1404 { "flush", PRAGMA_OMP_FLUSH },
1405 { "for", PRAGMA_OMP_FOR },
1406 { "master", PRAGMA_OMP_MASTER },
1407 { "ordered", PRAGMA_OMP_ORDERED },
1408 { "parallel", PRAGMA_OMP_PARALLEL },
1409 { "section", PRAGMA_OMP_SECTION },
1410 { "sections", PRAGMA_OMP_SECTIONS },
1411 { "single", PRAGMA_OMP_SINGLE },
1412 { "task", PRAGMA_OMP_TASK },
1413 { "taskwait", PRAGMA_OMP_TASKWAIT },
1414 { "taskyield", PRAGMA_OMP_TASKYIELD },
1415 { "threadprivate", PRAGMA_OMP_THREADPRIVATE }
1418 void
1419 c_pp_lookup_pragma (unsigned int id, const char **space, const char **name)
1421 const int n_omp_pragmas = sizeof (omp_pragmas) / sizeof (*omp_pragmas);
1422 int i;
1424 for (i = 0; i < n_omp_pragmas; ++i)
1425 if (omp_pragmas[i].id == id)
1427 *space = "omp";
1428 *name = omp_pragmas[i].name;
1429 return;
1432 if (id >= PRAGMA_FIRST_EXTERNAL
1433 && (id < PRAGMA_FIRST_EXTERNAL + registered_pp_pragmas.length ()))
1435 *space = registered_pp_pragmas[id - PRAGMA_FIRST_EXTERNAL].space;
1436 *name = registered_pp_pragmas[id - PRAGMA_FIRST_EXTERNAL].name;
1437 return;
1440 gcc_unreachable ();
1443 /* Front-end wrappers for pragma registration to avoid dragging
1444 cpplib.h in almost everywhere. */
1446 static void
1447 c_register_pragma_1 (const char *space, const char *name,
1448 internal_pragma_handler ihandler, bool allow_expansion)
1450 unsigned id;
1452 if (flag_preprocess_only)
1454 pragma_ns_name ns_name;
1456 if (!allow_expansion)
1457 return;
1459 ns_name.space = space;
1460 ns_name.name = name;
1461 registered_pp_pragmas.safe_push (ns_name);
1462 id = registered_pp_pragmas.length ();
1463 id += PRAGMA_FIRST_EXTERNAL - 1;
1465 else
1467 registered_pragmas.safe_push (ihandler);
1468 id = registered_pragmas.length ();
1469 id += PRAGMA_FIRST_EXTERNAL - 1;
1471 /* The C++ front end allocates 6 bits in cp_token; the C front end
1472 allocates 7 bits in c_token. At present this is sufficient. */
1473 gcc_assert (id < 64);
1476 cpp_register_deferred_pragma (parse_in, space, name, id,
1477 allow_expansion, false);
1480 /* Register a C pragma handler, using a space and a name. It disallows pragma
1481 expansion (if you want it, use c_register_pragma_with_expansion instead). */
1482 void
1483 c_register_pragma (const char *space, const char *name,
1484 pragma_handler_1arg handler)
1486 internal_pragma_handler ihandler;
1488 ihandler.handler.handler_1arg = handler;
1489 ihandler.extra_data = false;
1490 ihandler.data = NULL;
1491 c_register_pragma_1 (space, name, ihandler, false);
1494 /* Register a C pragma handler, using a space and a name, it also carries an
1495 extra data field which can be used by the handler. It disallows pragma
1496 expansion (if you want it, use c_register_pragma_with_expansion_and_data
1497 instead). */
1498 void
1499 c_register_pragma_with_data (const char *space, const char *name,
1500 pragma_handler_2arg handler, void * data)
1502 internal_pragma_handler ihandler;
1504 ihandler.handler.handler_2arg = handler;
1505 ihandler.extra_data = true;
1506 ihandler.data = data;
1507 c_register_pragma_1 (space, name, ihandler, false);
1510 /* Register a C pragma handler, using a space and a name. It allows pragma
1511 expansion as in the following example:
1513 #define NUMBER 10
1514 #pragma count (NUMBER)
1516 Name expansion is still disallowed. */
1517 void
1518 c_register_pragma_with_expansion (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, true);
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 allows pragma
1531 expansion as in the following example:
1533 #define NUMBER 10
1534 #pragma count (NUMBER)
1536 Name expansion is still disallowed. */
1537 void
1538 c_register_pragma_with_expansion_and_data (const char *space, const char *name,
1539 pragma_handler_2arg handler,
1540 void *data)
1542 internal_pragma_handler ihandler;
1544 ihandler.handler.handler_2arg = handler;
1545 ihandler.extra_data = true;
1546 ihandler.data = data;
1547 c_register_pragma_1 (space, name, ihandler, true);
1550 void
1551 c_invoke_pragma_handler (unsigned int id)
1553 internal_pragma_handler *ihandler;
1554 pragma_handler_1arg handler_1arg;
1555 pragma_handler_2arg handler_2arg;
1557 id -= PRAGMA_FIRST_EXTERNAL;
1558 ihandler = &registered_pragmas[id];
1559 if (ihandler->extra_data)
1561 handler_2arg = ihandler->handler.handler_2arg;
1562 handler_2arg (parse_in, ihandler->data);
1564 else
1566 handler_1arg = ihandler->handler.handler_1arg;
1567 handler_1arg (parse_in);
1571 /* Set up front-end pragmas. */
1572 void
1573 init_pragma (void)
1575 if (flag_openmp)
1577 const int n_omp_pragmas = sizeof (omp_pragmas) / sizeof (*omp_pragmas);
1578 int i;
1580 for (i = 0; i < n_omp_pragmas; ++i)
1581 cpp_register_deferred_pragma (parse_in, "omp", omp_pragmas[i].name,
1582 omp_pragmas[i].id, true, true);
1585 if (!flag_preprocess_only)
1586 cpp_register_deferred_pragma (parse_in, "GCC", "pch_preprocess",
1587 PRAGMA_GCC_PCH_PREPROCESS, false, false);
1589 #ifdef HANDLE_PRAGMA_PACK_WITH_EXPANSION
1590 c_register_pragma_with_expansion (0, "pack", handle_pragma_pack);
1591 #else
1592 c_register_pragma (0, "pack", handle_pragma_pack);
1593 #endif
1594 c_register_pragma (0, "weak", handle_pragma_weak);
1595 c_register_pragma ("GCC", "visibility", handle_pragma_visibility);
1597 c_register_pragma ("GCC", "diagnostic", handle_pragma_diagnostic);
1598 c_register_pragma ("GCC", "target", handle_pragma_target);
1599 c_register_pragma ("GCC", "optimize", handle_pragma_optimize);
1600 c_register_pragma ("GCC", "push_options", handle_pragma_push_options);
1601 c_register_pragma ("GCC", "pop_options", handle_pragma_pop_options);
1602 c_register_pragma ("GCC", "reset_options", handle_pragma_reset_options);
1604 c_register_pragma ("STDC", "FLOAT_CONST_DECIMAL64",
1605 handle_pragma_float_const_decimal64);
1607 c_register_pragma_with_expansion (0, "redefine_extname",
1608 handle_pragma_redefine_extname);
1610 c_register_pragma_with_expansion (0, "message", handle_pragma_message);
1612 if (compiling_upc)
1614 c_register_pragma (0, "upc", handle_pragma_upc);
1615 init_pragma_upc ();
1616 c_register_pragma (0, "pupc", handle_pragma_pupc);
1617 init_pragma_pupc ();
1620 #ifdef REGISTER_TARGET_PRAGMAS
1621 REGISTER_TARGET_PRAGMAS ();
1622 #endif
1624 /* Allow plugins to register their own pragmas. */
1625 invoke_plugin_callbacks (PLUGIN_PRAGMAS, NULL);
1628 #include "gt-c-family-c-pragma.h"