Merge trunk version 208609 into gupc branch.
[official-gcc.git] / gcc / c-family / c-pragma.c
blobd241c96e68fb57929753d3309be8de5e85bedb1a
1 /* Handle #pragma, system V.4 style. Supports #pragma weak and #pragma pack.
2 Copyright (C) 1992-2014 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #include "config.h"
21 #include "system.h"
22 #include "coretypes.h"
23 #include "tm.h"
24 #include "tree.h"
25 #include "stringpool.h"
26 #include "attribs.h"
27 #include "varasm.h"
28 #include "gcc-symtab.h"
29 #include "function.h" /* For cfun. FIXME: Does the parser know
30 when it is inside a function, so that
31 we don't have to look at cfun? */
32 #include "cpplib.h"
33 #include "c-pragma.h"
34 #include "flags.h"
35 #include "langhooks.h"
36 #include "c-common.h"
37 #include "c-upc.h"
38 #include "tm_p.h" /* For REGISTER_TARGET_PRAGMAS (why is
39 this not a target hook?). */
40 #include "vec.h"
41 #include "target.h"
42 #include "diagnostic.h"
43 #include "opts.h"
44 #include "plugin.h"
45 #include "cgraph.h"
47 #define GCC_BAD(gmsgid) \
48 do { warning (OPT_Wpragmas, gmsgid); return; } while (0)
49 #define GCC_BAD2(gmsgid, arg) \
50 do { warning (OPT_Wpragmas, gmsgid, arg); return; } while (0)
52 typedef struct GTY(()) align_stack {
53 int alignment;
54 tree id;
55 struct align_stack * prev;
56 } align_stack;
58 static GTY(()) struct align_stack * alignment_stack;
60 static void handle_pragma_pack (cpp_reader *);
62 /* If we have a "global" #pragma pack(<n>) in effect when the first
63 #pragma pack(push,<n>) is encountered, this stores the value of
64 maximum_field_alignment in effect. When the final pop_alignment()
65 happens, we restore the value to this, not to a value of 0 for
66 maximum_field_alignment. Value is in bits. */
67 static int default_alignment;
68 #define SET_GLOBAL_ALIGNMENT(ALIGN) (maximum_field_alignment = *(alignment_stack == NULL \
69 ? &default_alignment \
70 : &alignment_stack->alignment) = (ALIGN))
72 static void push_alignment (int, tree);
73 static void pop_alignment (tree);
75 /* Push an alignment value onto the stack. */
76 static void
77 push_alignment (int alignment, tree id)
79 align_stack * entry;
81 entry = ggc_alloc_align_stack ();
83 entry->alignment = alignment;
84 entry->id = id;
85 entry->prev = alignment_stack;
87 /* The current value of maximum_field_alignment is not necessarily
88 0 since there may be a #pragma pack(<n>) in effect; remember it
89 so that we can restore it after the final #pragma pop(). */
90 if (alignment_stack == NULL)
91 default_alignment = maximum_field_alignment;
93 alignment_stack = entry;
95 maximum_field_alignment = alignment;
98 /* Undo a push of an alignment onto the stack. */
99 static void
100 pop_alignment (tree id)
102 align_stack * entry;
104 if (alignment_stack == NULL)
105 GCC_BAD ("#pragma pack (pop) encountered without matching #pragma pack (push)");
107 /* If we got an identifier, strip away everything above the target
108 entry so that the next step will restore the state just below it. */
109 if (id)
111 for (entry = alignment_stack; entry; entry = entry->prev)
112 if (entry->id == id)
114 alignment_stack = entry;
115 break;
117 if (entry == NULL)
118 warning (OPT_Wpragmas, "\
119 #pragma pack(pop, %E) encountered without matching #pragma pack(push, %E)"
120 , id, id);
123 entry = alignment_stack->prev;
125 maximum_field_alignment = entry ? entry->alignment : default_alignment;
127 alignment_stack = entry;
130 /* #pragma pack ()
131 #pragma pack (N)
133 #pragma pack (push)
134 #pragma pack (push, N)
135 #pragma pack (push, ID)
136 #pragma pack (push, ID, N)
137 #pragma pack (pop)
138 #pragma pack (pop, ID) */
139 static void
140 handle_pragma_pack (cpp_reader * ARG_UNUSED (dummy))
142 tree x, id = 0;
143 int align = -1;
144 enum cpp_ttype token;
145 enum { set, push, pop } action;
147 if (pragma_lex (&x) != CPP_OPEN_PAREN)
148 GCC_BAD ("missing %<(%> after %<#pragma pack%> - ignored");
150 token = pragma_lex (&x);
151 if (token == CPP_CLOSE_PAREN)
153 action = set;
154 align = initial_max_fld_align;
156 else if (token == CPP_NUMBER)
158 if (TREE_CODE (x) != INTEGER_CST)
159 GCC_BAD ("invalid constant in %<#pragma pack%> - ignored");
160 align = TREE_INT_CST_LOW (x);
161 action = set;
162 if (pragma_lex (&x) != CPP_CLOSE_PAREN)
163 GCC_BAD ("malformed %<#pragma pack%> - ignored");
165 else if (token == CPP_NAME)
167 #define GCC_BAD_ACTION do { if (action != pop) \
168 GCC_BAD ("malformed %<#pragma pack(push[, id][, <n>])%> - ignored"); \
169 else \
170 GCC_BAD ("malformed %<#pragma pack(pop[, id])%> - ignored"); \
171 } while (0)
173 const char *op = IDENTIFIER_POINTER (x);
174 if (!strcmp (op, "push"))
175 action = push;
176 else if (!strcmp (op, "pop"))
177 action = pop;
178 else
179 GCC_BAD2 ("unknown action %qE for %<#pragma pack%> - ignored", x);
181 while ((token = pragma_lex (&x)) == CPP_COMMA)
183 token = pragma_lex (&x);
184 if (token == CPP_NAME && id == 0)
186 id = x;
188 else if (token == CPP_NUMBER && action == push && align == -1)
190 if (TREE_CODE (x) != INTEGER_CST)
191 GCC_BAD ("invalid constant in %<#pragma pack%> - ignored");
192 align = TREE_INT_CST_LOW (x);
193 if (align == -1)
194 action = set;
196 else
197 GCC_BAD_ACTION;
200 if (token != CPP_CLOSE_PAREN)
201 GCC_BAD_ACTION;
202 #undef GCC_BAD_ACTION
204 else
205 GCC_BAD ("malformed %<#pragma pack%> - ignored");
207 if (pragma_lex (&x) != CPP_EOF)
208 warning (OPT_Wpragmas, "junk at end of %<#pragma pack%>");
210 if (flag_pack_struct)
211 GCC_BAD ("#pragma pack has no effect with -fpack-struct - ignored");
213 if (action != pop)
214 switch (align)
216 case 0:
217 case 1:
218 case 2:
219 case 4:
220 case 8:
221 case 16:
222 align *= BITS_PER_UNIT;
223 break;
224 case -1:
225 if (action == push)
227 align = maximum_field_alignment;
228 break;
230 default:
231 GCC_BAD2 ("alignment must be a small power of two, not %d", align);
234 switch (action)
236 case set: SET_GLOBAL_ALIGNMENT (align); break;
237 case push: push_alignment (align, id); break;
238 case pop: pop_alignment (id); break;
242 typedef struct GTY(()) pending_weak_d
244 tree name;
245 tree value;
246 } pending_weak;
249 static GTY(()) vec<pending_weak, va_gc> *pending_weaks;
251 static void apply_pragma_weak (tree, tree);
252 static void handle_pragma_weak (cpp_reader *);
254 static void
255 apply_pragma_weak (tree decl, tree value)
257 if (value)
259 value = build_string (IDENTIFIER_LENGTH (value),
260 IDENTIFIER_POINTER (value));
261 decl_attributes (&decl, build_tree_list (get_identifier ("alias"),
262 build_tree_list (NULL, value)),
266 if (SUPPORTS_WEAK && DECL_EXTERNAL (decl) && TREE_USED (decl)
267 && !DECL_WEAK (decl) /* Don't complain about a redundant #pragma. */
268 && DECL_ASSEMBLER_NAME_SET_P (decl)
269 && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
270 warning (OPT_Wpragmas, "applying #pragma weak %q+D after first use "
271 "results in unspecified behavior", decl);
273 declare_weak (decl);
276 void
277 maybe_apply_pragma_weak (tree decl)
279 tree id;
280 int i;
281 pending_weak *pe;
283 /* Avoid asking for DECL_ASSEMBLER_NAME when it's not needed. */
285 /* No weak symbols pending, take the short-cut. */
286 if (vec_safe_is_empty (pending_weaks))
287 return;
288 /* If it's not visible outside this file, it doesn't matter whether
289 it's weak. */
290 if (!DECL_EXTERNAL (decl) && !TREE_PUBLIC (decl))
291 return;
292 /* If it's not a function or a variable, it can't be weak.
293 FIXME: what kinds of things are visible outside this file but
294 aren't functions or variables? Should this be an assert instead? */
295 if (TREE_CODE (decl) != FUNCTION_DECL && TREE_CODE (decl) != VAR_DECL)
296 return;
298 if (DECL_ASSEMBLER_NAME_SET_P (decl))
299 id = DECL_ASSEMBLER_NAME (decl);
300 else
302 id = DECL_ASSEMBLER_NAME (decl);
303 SET_DECL_ASSEMBLER_NAME (decl, NULL_TREE);
306 FOR_EACH_VEC_ELT (*pending_weaks, i, pe)
307 if (id == pe->name)
309 apply_pragma_weak (decl, pe->value);
310 pending_weaks->unordered_remove (i);
311 break;
315 /* Process all "#pragma weak A = B" directives where we have not seen
316 a decl for A. */
317 void
318 maybe_apply_pending_pragma_weaks (void)
320 tree alias_id, id, decl;
321 int i;
322 pending_weak *pe;
323 symtab_node *target;
325 if (vec_safe_is_empty (pending_weaks))
326 return;
328 FOR_EACH_VEC_ELT (*pending_weaks, i, pe)
330 alias_id = pe->name;
331 id = pe->value;
333 if (id == NULL)
334 continue;
336 target = symtab_node_for_asm (id);
337 decl = build_decl (UNKNOWN_LOCATION,
338 target ? TREE_CODE (target->decl) : FUNCTION_DECL,
339 alias_id, default_function_type);
341 DECL_ARTIFICIAL (decl) = 1;
342 TREE_PUBLIC (decl) = 1;
343 DECL_WEAK (decl) = 1;
344 if (TREE_CODE (decl) == VAR_DECL)
345 TREE_STATIC (decl) = 1;
346 if (!target)
348 error ("%q+D aliased to undefined symbol %qE",
349 decl, id);
350 continue;
353 assemble_alias (decl, id);
357 /* #pragma weak name [= value] */
358 static void
359 handle_pragma_weak (cpp_reader * ARG_UNUSED (dummy))
361 tree name, value, x, decl;
362 enum cpp_ttype t;
364 value = 0;
366 if (pragma_lex (&name) != CPP_NAME)
367 GCC_BAD ("malformed #pragma weak, ignored");
368 t = pragma_lex (&x);
369 if (t == CPP_EQ)
371 if (pragma_lex (&value) != CPP_NAME)
372 GCC_BAD ("malformed #pragma weak, ignored");
373 t = pragma_lex (&x);
375 if (t != CPP_EOF)
376 warning (OPT_Wpragmas, "junk at end of %<#pragma weak%>");
378 decl = identifier_global_value (name);
379 if (decl && DECL_P (decl))
381 apply_pragma_weak (decl, value);
382 if (value)
384 DECL_EXTERNAL (decl) = 0;
385 if (TREE_CODE (decl) == VAR_DECL)
386 TREE_STATIC (decl) = 1;
387 assemble_alias (decl, value);
390 else
392 pending_weak pe = {name, value};
393 vec_safe_push (pending_weaks, pe);
397 /* GCC supports two #pragma directives for renaming the external
398 symbol associated with a declaration (DECL_ASSEMBLER_NAME), for
399 compatibility with the Solaris and VMS system headers. GCC also
400 has its own notation for this, __asm__("name") annotations.
402 Corner cases of these features and their interaction:
404 1) Both pragmas silently apply only to declarations with external
405 linkage (that is, TREE_PUBLIC || DECL_EXTERNAL). Asm labels
406 do not have this restriction.
408 2) In C++, both #pragmas silently apply only to extern "C" declarations.
409 Asm labels do not have this restriction.
411 3) If any of the three ways of changing DECL_ASSEMBLER_NAME is
412 applied to a decl whose DECL_ASSEMBLER_NAME is already set, and the
413 new name is different, a warning issues and the name does not change.
415 4) The "source name" for #pragma redefine_extname is the DECL_NAME,
416 *not* the DECL_ASSEMBLER_NAME.
418 5) If #pragma extern_prefix is in effect and a declaration occurs
419 with an __asm__ name, the #pragma extern_prefix is silently
420 ignored for that declaration.
422 6) If #pragma extern_prefix and #pragma redefine_extname apply to
423 the same declaration, whichever triggered first wins, and a warning
424 is issued. (We would like to have #pragma redefine_extname always
425 win, but it can appear either before or after the declaration, and
426 if it appears afterward, we have no way of knowing whether a modified
427 DECL_ASSEMBLER_NAME is due to #pragma extern_prefix.) */
429 typedef struct GTY(()) pending_redefinition_d {
430 tree oldname;
431 tree newname;
432 } pending_redefinition;
435 static GTY(()) vec<pending_redefinition, va_gc> *pending_redefine_extname;
437 static void handle_pragma_redefine_extname (cpp_reader *);
439 /* #pragma redefine_extname oldname newname */
440 static void
441 handle_pragma_redefine_extname (cpp_reader * ARG_UNUSED (dummy))
443 tree oldname, newname, decls, x;
444 enum cpp_ttype t;
445 bool found;
447 if (pragma_lex (&oldname) != CPP_NAME)
448 GCC_BAD ("malformed #pragma redefine_extname, ignored");
449 if (pragma_lex (&newname) != CPP_NAME)
450 GCC_BAD ("malformed #pragma redefine_extname, ignored");
451 t = pragma_lex (&x);
452 if (t != CPP_EOF)
453 warning (OPT_Wpragmas, "junk at end of %<#pragma redefine_extname%>");
455 found = false;
456 for (decls = c_linkage_bindings (oldname);
457 decls; )
459 tree decl;
460 if (TREE_CODE (decls) == TREE_LIST)
462 decl = TREE_VALUE (decls);
463 decls = TREE_CHAIN (decls);
465 else
467 decl = decls;
468 decls = NULL_TREE;
471 if ((TREE_PUBLIC (decl) || DECL_EXTERNAL (decl))
472 && (TREE_CODE (decl) == FUNCTION_DECL
473 || TREE_CODE (decl) == VAR_DECL))
475 found = true;
476 if (DECL_ASSEMBLER_NAME_SET_P (decl))
478 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
479 name = targetm.strip_name_encoding (name);
481 if (strcmp (name, IDENTIFIER_POINTER (newname)))
482 warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
483 "conflict with previous rename");
485 else
486 change_decl_assembler_name (decl, newname);
490 if (!found)
491 /* We have to add this to the rename list even if there's already
492 a global value that doesn't meet the above criteria, because in
493 C++ "struct foo {...};" puts "foo" in the current namespace but
494 does *not* conflict with a subsequent declaration of a function
495 or variable foo. See g++.dg/other/pragma-re-2.C. */
496 add_to_renaming_pragma_list (oldname, newname);
499 /* This is called from here and from ia64-c.c. */
500 void
501 add_to_renaming_pragma_list (tree oldname, tree newname)
503 unsigned ix;
504 pending_redefinition *p;
506 FOR_EACH_VEC_SAFE_ELT (pending_redefine_extname, ix, p)
507 if (oldname == p->oldname)
509 if (p->newname != newname)
510 warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
511 "conflict with previous #pragma redefine_extname");
512 return;
515 pending_redefinition e = {oldname, newname};
516 vec_safe_push (pending_redefine_extname, e);
519 /* The current prefix set by #pragma extern_prefix. */
520 GTY(()) tree pragma_extern_prefix;
522 /* variables used to implement #pragma upc semantics */
523 #ifndef UPC_CMODE_STACK_INCREMENT
524 #define UPC_CMODE_STACK_INCREMENT 32
525 #endif
526 static int pragma_upc_permitted;
527 static int upc_cmode;
528 static int *upc_cmode_stack;
529 static int upc_cmode_stack_in_use;
530 static int upc_cmode_stack_allocated;
532 static void init_pragma_upc (void);
533 static void handle_pragma_upc (cpp_reader * ARG_UNUSED (dummy));
535 /* Initialize the variables used to manage the current UPC consistency
536 mode (strict/relaxed) */
538 static void
539 init_pragma_upc (void)
541 pragma_upc_permitted = 0;
542 upc_cmode = 0;
543 upc_cmode_stack = (int *) xcalloc (UPC_CMODE_STACK_INCREMENT,
544 sizeof (int));
545 upc_cmode_stack_allocated = UPC_CMODE_STACK_INCREMENT;
546 upc_cmode_stack_in_use = 0;
550 * #pragma upc strict
551 * #pragma upc relaxed
552 * #pragma upc upc_code
553 * #pragma upc c_code
555 static void
556 handle_pragma_upc (cpp_reader * ARG_UNUSED (dummy))
558 tree x;
559 enum cpp_ttype t;
560 enum upc_pragma_op {p_strict, p_relaxed, p_upc_code,
561 p_c_code, p_detect_upc, p_unknown};
562 enum upc_pragma_op upc_pragma = p_unknown;
564 t = pragma_lex (&x);
565 if (t == CPP_NAME)
567 const char *op = IDENTIFIER_POINTER (x);
568 if (!strcmp (op, "strict"))
569 upc_pragma = p_strict;
570 else if (!strcmp (op, "relaxed"))
571 upc_pragma = p_relaxed;
572 else if (!strcmp (op, "upc_code"))
573 upc_pragma = p_upc_code;
574 else if (!strcmp (op, "c_code"))
575 upc_pragma = p_c_code;
576 else if (!strcmp (op, "detect_upc"))
578 const char *detect_op;
579 upc_pragma = p_detect_upc;
580 t = pragma_lex (&x);
581 if (t != CPP_NAME)
582 GCC_BAD ("missing [suspend_insertion|resume_insertion]"
583 " after %<#pragma UPC detect_upc%>");
584 detect_op = IDENTIFIER_POINTER (x);
585 if (strcmp (detect_op, "suspend_insertion") == 0)
586 /* no action */;
587 else if (strcmp (detect_op, "resume_insertion") == 0)
588 /* no action */;
589 else
590 GCC_BAD ("expected [suspend_insertion|resume_insertion]"
591 " after %<#pragma UPC detect_upc%>");
593 else
594 GCC_BAD2 ("unknown action '%s' for '#pragma upc' - ignored", op);
596 else
597 warning (OPT_Wpragmas, "missing parameter after #pragma upc");
599 t = pragma_lex (&x);
600 if (t != CPP_EOF)
601 warning (OPT_Wpragmas, "junk at end of #pragma upc");
603 if ((upc_pragma == p_strict) || (upc_pragma == p_relaxed))
605 if (pragma_upc_permitted_p ())
607 int consistency_mode = (upc_pragma == p_strict);
608 set_upc_consistency_mode (consistency_mode);
610 else
611 warning (OPT_Wpragmas, "#pragma upc not allowed in this context");
613 else if ((upc_pragma == p_upc_code) || (upc_pragma == p_c_code))
615 flag_upc = (upc_pragma == p_upc_code);
616 lang_hooks.upc.toggle_keywords (flag_upc);
618 else if (upc_pragma == p_detect_upc)
620 /* Skip: This is a Berkeley-specific pragma that requires no action. */
624 /* Set the current setting of the UPC consistency mode
625 that is in effect. */
627 void
628 set_upc_consistency_mode (int mode)
630 upc_cmode = mode;
633 /* Return the current setting of the UPC consistency mode. */
636 get_upc_consistency_mode (void)
638 return upc_cmode;
641 /* Called from the parser just after the bracket that opens a compound
642 statement has been parsed. Set the flag that allows the pragma
643 in this context. */
645 void
646 permit_pragma_upc (void)
648 pragma_upc_permitted = 1;
651 /* Called just before the body of a compound statement is parsed.
652 Clear the flag that allows the pragma. */
654 void
655 deny_pragma_upc (void)
657 pragma_upc_permitted = 0;
660 /* A #pragma upc is permitted either at the outermost scope,
661 or directly after the bracket that opens a compound statement. */
664 pragma_upc_permitted_p (void)
666 return !current_function_decl || pragma_upc_permitted;
669 /* Called at the beginning of every compound statement.
670 Pushes the old value of the current UPC consistency mode
671 onto the stack. */
673 void
674 push_upc_consistency_mode (void)
676 if (upc_cmode_stack_in_use == upc_cmode_stack_allocated)
678 upc_cmode_stack_allocated += UPC_CMODE_STACK_INCREMENT;
679 upc_cmode_stack = (int *) xrealloc (upc_cmode_stack,
680 upc_cmode_stack_allocated * sizeof (int));
682 upc_cmode_stack[upc_cmode_stack_in_use++] = upc_cmode;
685 /* Called at the end of every compound statement.
686 Sets the current consistency mode to the previously saved value. */
688 void
689 pop_upc_consistency_mode (void)
691 if (upc_cmode_stack_in_use <= 0)
692 abort ();
693 upc_cmode = upc_cmode_stack[--upc_cmode_stack_in_use];
696 static int pragma_pupc_on;
697 static void init_pragma_pupc (void);
698 static void handle_pragma_pupc (cpp_reader *);
700 /* Pragma pupc defaults to being on */
701 static void
702 init_pragma_pupc (void)
704 pragma_pupc_on = 1;
708 get_upc_pupc_mode (void)
710 return pragma_pupc_on;
714 disable_pupc_mode (void)
716 int old_pupc = pragma_pupc_on;
717 pragma_pupc_on = 0;
718 return old_pupc;
721 void
722 set_pupc_mode (int new_pupc)
724 pragma_pupc_on = new_pupc;
728 * #pragma pupc on
729 * #pragma pupc off
731 static void
732 handle_pragma_pupc (cpp_reader *dummy ATTRIBUTE_UNUSED)
734 tree x;
735 enum cpp_ttype t;
737 t = pragma_lex(&x);
738 if (t == CPP_NAME) {
739 const char *op = IDENTIFIER_POINTER (x);
740 if (!strcmp (op, "on"))
741 pragma_pupc_on = 1;
742 else if (!strcmp (op, "off"))
743 pragma_pupc_on = 0;
744 else
745 GCC_BAD2 ("unknown action '%s' for '#pragma pupc' - ignored", op);
748 t = pragma_lex (&x);
749 if (t != CPP_EOF)
750 warning (OPT_Wpragmas, "junk at end of #pragma pupc");
753 /* Hook from the front ends to apply the results of one of the preceding
754 pragmas that rename variables. */
756 tree
757 maybe_apply_renaming_pragma (tree decl, tree asmname)
759 unsigned ix;
760 pending_redefinition *p;
762 /* The renaming pragmas are only applied to declarations with
763 external linkage. */
764 if ((TREE_CODE (decl) != FUNCTION_DECL && TREE_CODE (decl) != VAR_DECL)
765 || (!TREE_PUBLIC (decl) && !DECL_EXTERNAL (decl))
766 || !has_c_linkage (decl))
767 return asmname;
769 /* If the DECL_ASSEMBLER_NAME is already set, it does not change,
770 but we may warn about a rename that conflicts. */
771 if (DECL_ASSEMBLER_NAME_SET_P (decl))
773 const char *oldname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
774 oldname = targetm.strip_name_encoding (oldname);
776 if (asmname && strcmp (TREE_STRING_POINTER (asmname), oldname))
777 warning (OPT_Wpragmas, "asm declaration ignored due to "
778 "conflict with previous rename");
780 /* Take any pending redefine_extname off the list. */
781 FOR_EACH_VEC_SAFE_ELT (pending_redefine_extname, ix, p)
782 if (DECL_NAME (decl) == p->oldname)
784 /* Only warn if there is a conflict. */
785 if (strcmp (IDENTIFIER_POINTER (p->newname), oldname))
786 warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
787 "conflict with previous rename");
789 pending_redefine_extname->unordered_remove (ix);
790 break;
792 return 0;
795 /* Find out if we have a pending #pragma redefine_extname. */
796 FOR_EACH_VEC_SAFE_ELT (pending_redefine_extname, ix, p)
797 if (DECL_NAME (decl) == p->oldname)
799 tree newname = p->newname;
800 pending_redefine_extname->unordered_remove (ix);
802 /* If we already have an asmname, #pragma redefine_extname is
803 ignored (with a warning if it conflicts). */
804 if (asmname)
806 if (strcmp (TREE_STRING_POINTER (asmname),
807 IDENTIFIER_POINTER (newname)) != 0)
808 warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
809 "conflict with __asm__ declaration");
810 return asmname;
813 /* Otherwise we use what we've got; #pragma extern_prefix is
814 silently ignored. */
815 return build_string (IDENTIFIER_LENGTH (newname),
816 IDENTIFIER_POINTER (newname));
819 /* If we've got an asmname, #pragma extern_prefix is silently ignored. */
820 if (asmname)
821 return asmname;
823 /* If #pragma extern_prefix is in effect, apply it. */
824 if (pragma_extern_prefix)
826 const char *prefix = TREE_STRING_POINTER (pragma_extern_prefix);
827 size_t plen = TREE_STRING_LENGTH (pragma_extern_prefix) - 1;
829 const char *id = IDENTIFIER_POINTER (DECL_NAME (decl));
830 size_t ilen = IDENTIFIER_LENGTH (DECL_NAME (decl));
832 char *newname = (char *) alloca (plen + ilen + 1);
834 memcpy (newname, prefix, plen);
835 memcpy (newname + plen, id, ilen + 1);
837 return build_string (plen + ilen, newname);
840 /* Nada. */
841 return 0;
845 static void handle_pragma_visibility (cpp_reader *);
847 static vec<int> visstack;
849 /* Push the visibility indicated by STR onto the top of the #pragma
850 visibility stack. KIND is 0 for #pragma GCC visibility, 1 for
851 C++ namespace with visibility attribute and 2 for C++ builtin
852 ABI namespace. push_visibility/pop_visibility calls must have
853 matching KIND, it is not allowed to push visibility using one
854 KIND and pop using a different one. */
856 void
857 push_visibility (const char *str, int kind)
859 visstack.safe_push (((int) default_visibility) | (kind << 8));
860 if (!strcmp (str, "default"))
861 default_visibility = VISIBILITY_DEFAULT;
862 else if (!strcmp (str, "internal"))
863 default_visibility = VISIBILITY_INTERNAL;
864 else if (!strcmp (str, "hidden"))
865 default_visibility = VISIBILITY_HIDDEN;
866 else if (!strcmp (str, "protected"))
867 default_visibility = VISIBILITY_PROTECTED;
868 else
869 GCC_BAD ("#pragma GCC visibility push() must specify default, internal, hidden or protected");
870 visibility_options.inpragma = 1;
873 /* Pop a level of the #pragma visibility stack. Return true if
874 successful. */
876 bool
877 pop_visibility (int kind)
879 if (!visstack.length ())
880 return false;
881 if ((visstack.last () >> 8) != kind)
882 return false;
883 default_visibility
884 = (enum symbol_visibility) (visstack.pop () & 0xff);
885 visibility_options.inpragma
886 = visstack.length () != 0;
887 return true;
890 /* Sets the default visibility for symbols to something other than that
891 specified on the command line. */
893 static void
894 handle_pragma_visibility (cpp_reader *dummy ATTRIBUTE_UNUSED)
896 /* Form is #pragma GCC visibility push(hidden)|pop */
897 tree x;
898 enum cpp_ttype token;
899 enum { bad, push, pop } action = bad;
901 token = pragma_lex (&x);
902 if (token == CPP_NAME)
904 const char *op = IDENTIFIER_POINTER (x);
905 if (!strcmp (op, "push"))
906 action = push;
907 else if (!strcmp (op, "pop"))
908 action = pop;
910 if (bad == action)
911 GCC_BAD ("#pragma GCC visibility must be followed by push or pop");
912 else
914 if (pop == action)
916 if (! pop_visibility (0))
917 GCC_BAD ("no matching push for %<#pragma GCC visibility pop%>");
919 else
921 if (pragma_lex (&x) != CPP_OPEN_PAREN)
922 GCC_BAD ("missing %<(%> after %<#pragma GCC visibility push%> - ignored");
923 token = pragma_lex (&x);
924 if (token != CPP_NAME)
925 GCC_BAD ("malformed #pragma GCC visibility push");
926 else
927 push_visibility (IDENTIFIER_POINTER (x), 0);
928 if (pragma_lex (&x) != CPP_CLOSE_PAREN)
929 GCC_BAD ("missing %<(%> after %<#pragma GCC visibility push%> - ignored");
932 if (pragma_lex (&x) != CPP_EOF)
933 warning (OPT_Wpragmas, "junk at end of %<#pragma GCC visibility%>");
936 static void
937 handle_pragma_diagnostic(cpp_reader *ARG_UNUSED(dummy))
939 const char *kind_string, *option_string;
940 unsigned int option_index;
941 enum cpp_ttype token;
942 diagnostic_t kind;
943 tree x;
944 struct cl_option_handlers handlers;
946 token = pragma_lex (&x);
947 if (token != CPP_NAME)
948 GCC_BAD ("missing [error|warning|ignored] after %<#pragma GCC diagnostic%>");
949 kind_string = IDENTIFIER_POINTER (x);
950 if (strcmp (kind_string, "error") == 0)
951 kind = DK_ERROR;
952 else if (strcmp (kind_string, "warning") == 0)
953 kind = DK_WARNING;
954 else if (strcmp (kind_string, "ignored") == 0)
955 kind = DK_IGNORED;
956 else if (strcmp (kind_string, "push") == 0)
958 diagnostic_push_diagnostics (global_dc, input_location);
959 return;
961 else if (strcmp (kind_string, "pop") == 0)
963 diagnostic_pop_diagnostics (global_dc, input_location);
964 return;
966 else
967 GCC_BAD ("expected [error|warning|ignored|push|pop] after %<#pragma GCC diagnostic%>");
969 token = pragma_lex (&x);
970 if (token != CPP_STRING)
971 GCC_BAD ("missing option after %<#pragma GCC diagnostic%> kind");
972 option_string = TREE_STRING_POINTER (x);
973 set_default_handlers (&handlers);
974 for (option_index = 0; option_index < cl_options_count; option_index++)
975 if (strcmp (cl_options[option_index].opt_text, option_string) == 0)
977 control_warning_option (option_index, (int) kind, kind != DK_IGNORED,
978 input_location, c_family_lang_mask, &handlers,
979 &global_options, &global_options_set,
980 global_dc);
981 return;
983 GCC_BAD ("unknown option after %<#pragma GCC diagnostic%> kind");
986 /* Parse #pragma GCC target (xxx) to set target specific options. */
987 static void
988 handle_pragma_target(cpp_reader *ARG_UNUSED(dummy))
990 enum cpp_ttype token;
991 tree x;
992 bool close_paren_needed_p = false;
994 if (cfun)
996 error ("#pragma GCC option is not allowed inside functions");
997 return;
1000 token = pragma_lex (&x);
1001 if (token == CPP_OPEN_PAREN)
1003 close_paren_needed_p = true;
1004 token = pragma_lex (&x);
1007 if (token != CPP_STRING)
1009 GCC_BAD ("%<#pragma GCC option%> is not a string");
1010 return;
1013 /* Strings are user options. */
1014 else
1016 tree args = NULL_TREE;
1020 /* Build up the strings now as a tree linked list. Skip empty
1021 strings. */
1022 if (TREE_STRING_LENGTH (x) > 0)
1023 args = tree_cons (NULL_TREE, x, args);
1025 token = pragma_lex (&x);
1026 while (token == CPP_COMMA)
1027 token = pragma_lex (&x);
1029 while (token == CPP_STRING);
1031 if (close_paren_needed_p)
1033 if (token == CPP_CLOSE_PAREN)
1034 token = pragma_lex (&x);
1035 else
1036 GCC_BAD ("%<#pragma GCC target (string [,string]...)%> does "
1037 "not have a final %<)%>");
1040 if (token != CPP_EOF)
1042 error ("#pragma GCC target string... is badly formed");
1043 return;
1046 /* put arguments in the order the user typed them. */
1047 args = nreverse (args);
1049 if (targetm.target_option.pragma_parse (args, NULL_TREE))
1050 current_target_pragma = args;
1054 /* Handle #pragma GCC optimize to set optimization options. */
1055 static void
1056 handle_pragma_optimize (cpp_reader *ARG_UNUSED(dummy))
1058 enum cpp_ttype token;
1059 tree x;
1060 bool close_paren_needed_p = false;
1061 tree optimization_previous_node = optimization_current_node;
1063 if (cfun)
1065 error ("#pragma GCC optimize is not allowed inside functions");
1066 return;
1069 token = pragma_lex (&x);
1070 if (token == CPP_OPEN_PAREN)
1072 close_paren_needed_p = true;
1073 token = pragma_lex (&x);
1076 if (token != CPP_STRING && token != CPP_NUMBER)
1078 GCC_BAD ("%<#pragma GCC optimize%> is not a string or number");
1079 return;
1082 /* Strings/numbers are user options. */
1083 else
1085 tree args = NULL_TREE;
1089 /* Build up the numbers/strings now as a list. */
1090 if (token != CPP_STRING || TREE_STRING_LENGTH (x) > 0)
1091 args = tree_cons (NULL_TREE, x, args);
1093 token = pragma_lex (&x);
1094 while (token == CPP_COMMA)
1095 token = pragma_lex (&x);
1097 while (token == CPP_STRING || token == CPP_NUMBER);
1099 if (close_paren_needed_p)
1101 if (token == CPP_CLOSE_PAREN)
1102 token = pragma_lex (&x);
1103 else
1104 GCC_BAD ("%<#pragma GCC optimize (string [,string]...)%> does "
1105 "not have a final %<)%>");
1108 if (token != CPP_EOF)
1110 error ("#pragma GCC optimize string... is badly formed");
1111 return;
1114 /* put arguments in the order the user typed them. */
1115 args = nreverse (args);
1117 parse_optimize_options (args, false);
1118 current_optimize_pragma = chainon (current_optimize_pragma, args);
1119 optimization_current_node = build_optimization_node (&global_options);
1120 c_cpp_builtins_optimize_pragma (parse_in,
1121 optimization_previous_node,
1122 optimization_current_node);
1126 /* Stack of the #pragma GCC options created with #pragma GCC push_option. Save
1127 both the binary representation of the options and the TREE_LIST of
1128 strings that will be added to the function's attribute list. */
1129 typedef struct GTY(()) opt_stack {
1130 struct opt_stack *prev;
1131 tree target_binary;
1132 tree target_strings;
1133 tree optimize_binary;
1134 tree optimize_strings;
1135 } opt_stack;
1137 static GTY(()) struct opt_stack * options_stack;
1139 /* Handle #pragma GCC push_options to save the current target and optimization
1140 options. */
1142 static void
1143 handle_pragma_push_options (cpp_reader *ARG_UNUSED(dummy))
1145 enum cpp_ttype token;
1146 tree x = 0;
1147 opt_stack *p;
1149 token = pragma_lex (&x);
1150 if (token != CPP_EOF)
1152 warning (OPT_Wpragmas, "junk at end of %<#pragma push_options%>");
1153 return;
1156 p = ggc_alloc_opt_stack ();
1157 p->prev = options_stack;
1158 options_stack = p;
1160 /* Save optimization and target flags in binary format. */
1161 p->optimize_binary = build_optimization_node (&global_options);
1162 p->target_binary = build_target_option_node (&global_options);
1164 /* Save optimization and target flags in string list format. */
1165 p->optimize_strings = copy_list (current_optimize_pragma);
1166 p->target_strings = copy_list (current_target_pragma);
1169 /* Handle #pragma GCC pop_options to restore the current target and
1170 optimization options from a previous push_options. */
1172 static void
1173 handle_pragma_pop_options (cpp_reader *ARG_UNUSED(dummy))
1175 enum cpp_ttype token;
1176 tree x = 0;
1177 opt_stack *p;
1179 token = pragma_lex (&x);
1180 if (token != CPP_EOF)
1182 warning (OPT_Wpragmas, "junk at end of %<#pragma pop_options%>");
1183 return;
1186 if (! options_stack)
1188 warning (OPT_Wpragmas,
1189 "%<#pragma GCC pop_options%> without a corresponding "
1190 "%<#pragma GCC push_options%>");
1191 return;
1194 p = options_stack;
1195 options_stack = p->prev;
1197 if (p->target_binary != target_option_current_node)
1199 (void) targetm.target_option.pragma_parse (NULL_TREE, p->target_binary);
1200 target_option_current_node = p->target_binary;
1203 if (p->optimize_binary != optimization_current_node)
1205 tree old_optimize = optimization_current_node;
1206 cl_optimization_restore (&global_options,
1207 TREE_OPTIMIZATION (p->optimize_binary));
1208 c_cpp_builtins_optimize_pragma (parse_in, old_optimize,
1209 p->optimize_binary);
1210 optimization_current_node = p->optimize_binary;
1213 current_target_pragma = p->target_strings;
1214 current_optimize_pragma = p->optimize_strings;
1217 /* Handle #pragma GCC reset_options to restore the current target and
1218 optimization options to the original options used on the command line. */
1220 static void
1221 handle_pragma_reset_options (cpp_reader *ARG_UNUSED(dummy))
1223 enum cpp_ttype token;
1224 tree x = 0;
1225 tree new_optimize = optimization_default_node;
1226 tree new_target = target_option_default_node;
1228 token = pragma_lex (&x);
1229 if (token != CPP_EOF)
1231 warning (OPT_Wpragmas, "junk at end of %<#pragma reset_options%>");
1232 return;
1235 if (new_target != target_option_current_node)
1237 (void) targetm.target_option.pragma_parse (NULL_TREE, new_target);
1238 target_option_current_node = new_target;
1241 if (new_optimize != optimization_current_node)
1243 tree old_optimize = optimization_current_node;
1244 cl_optimization_restore (&global_options,
1245 TREE_OPTIMIZATION (new_optimize));
1246 c_cpp_builtins_optimize_pragma (parse_in, old_optimize, new_optimize);
1247 optimization_current_node = new_optimize;
1250 current_target_pragma = NULL_TREE;
1251 current_optimize_pragma = NULL_TREE;
1254 /* Print a plain user-specified message. */
1256 static void
1257 handle_pragma_message (cpp_reader *ARG_UNUSED(dummy))
1259 enum cpp_ttype token;
1260 tree x, message = 0;
1262 token = pragma_lex (&x);
1263 if (token == CPP_OPEN_PAREN)
1265 token = pragma_lex (&x);
1266 if (token == CPP_STRING)
1267 message = x;
1268 else
1269 GCC_BAD ("expected a string after %<#pragma message%>");
1270 if (pragma_lex (&x) != CPP_CLOSE_PAREN)
1271 GCC_BAD ("malformed %<#pragma message%>, ignored");
1273 else if (token == CPP_STRING)
1274 message = x;
1275 else
1276 GCC_BAD ("expected a string after %<#pragma message%>");
1278 gcc_assert (message);
1280 if (pragma_lex (&x) != CPP_EOF)
1281 warning (OPT_Wpragmas, "junk at end of %<#pragma message%>");
1283 if (TREE_STRING_LENGTH (message) > 1)
1284 inform (input_location, "#pragma message: %s", TREE_STRING_POINTER (message));
1287 /* Mark whether the current location is valid for a STDC pragma. */
1289 static bool valid_location_for_stdc_pragma;
1291 void
1292 mark_valid_location_for_stdc_pragma (bool flag)
1294 valid_location_for_stdc_pragma = flag;
1297 /* Return true if the current location is valid for a STDC pragma. */
1299 bool
1300 valid_location_for_stdc_pragma_p (void)
1302 return valid_location_for_stdc_pragma;
1305 enum pragma_switch_t { PRAGMA_ON, PRAGMA_OFF, PRAGMA_DEFAULT, PRAGMA_BAD };
1307 /* A STDC pragma must appear outside of external declarations or
1308 preceding all explicit declarations and statements inside a compound
1309 statement; its behavior is undefined if used in any other context.
1310 It takes a switch of ON, OFF, or DEFAULT. */
1312 static enum pragma_switch_t
1313 handle_stdc_pragma (const char *pname)
1315 const char *arg;
1316 tree t;
1317 enum pragma_switch_t ret;
1319 if (!valid_location_for_stdc_pragma_p ())
1321 warning (OPT_Wpragmas, "invalid location for %<pragma %s%>, ignored",
1322 pname);
1323 return PRAGMA_BAD;
1326 if (pragma_lex (&t) != CPP_NAME)
1328 warning (OPT_Wpragmas, "malformed %<#pragma %s%>, ignored", pname);
1329 return PRAGMA_BAD;
1332 arg = IDENTIFIER_POINTER (t);
1334 if (!strcmp (arg, "ON"))
1335 ret = PRAGMA_ON;
1336 else if (!strcmp (arg, "OFF"))
1337 ret = PRAGMA_OFF;
1338 else if (!strcmp (arg, "DEFAULT"))
1339 ret = PRAGMA_DEFAULT;
1340 else
1342 warning (OPT_Wpragmas, "malformed %<#pragma %s%>, ignored", pname);
1343 return PRAGMA_BAD;
1346 if (pragma_lex (&t) != CPP_EOF)
1348 warning (OPT_Wpragmas, "junk at end of %<#pragma %s%>", pname);
1349 return PRAGMA_BAD;
1352 return ret;
1355 /* #pragma STDC FLOAT_CONST_DECIMAL64 ON
1356 #pragma STDC FLOAT_CONST_DECIMAL64 OFF
1357 #pragma STDC FLOAT_CONST_DECIMAL64 DEFAULT */
1359 static void
1360 handle_pragma_float_const_decimal64 (cpp_reader *ARG_UNUSED (dummy))
1362 if (c_dialect_cxx ())
1364 if (warn_unknown_pragmas > in_system_header_at (input_location))
1365 warning (OPT_Wunknown_pragmas,
1366 "%<#pragma STDC FLOAT_CONST_DECIMAL64%> is not supported"
1367 " for C++");
1368 return;
1371 if (!targetm.decimal_float_supported_p ())
1373 if (warn_unknown_pragmas > in_system_header_at (input_location))
1374 warning (OPT_Wunknown_pragmas,
1375 "%<#pragma STDC FLOAT_CONST_DECIMAL64%> is not supported"
1376 " on this target");
1377 return;
1380 pedwarn (input_location, OPT_Wpedantic,
1381 "ISO C does not support %<#pragma STDC FLOAT_CONST_DECIMAL64%>");
1383 switch (handle_stdc_pragma ("STDC FLOAT_CONST_DECIMAL64"))
1385 case PRAGMA_ON:
1386 set_float_const_decimal64 ();
1387 break;
1388 case PRAGMA_OFF:
1389 case PRAGMA_DEFAULT:
1390 clear_float_const_decimal64 ();
1391 break;
1392 case PRAGMA_BAD:
1393 break;
1397 /* A vector of registered pragma callbacks, which is never freed. */
1399 static vec<internal_pragma_handler> registered_pragmas;
1401 typedef struct
1403 const char *space;
1404 const char *name;
1405 } pragma_ns_name;
1408 static vec<pragma_ns_name> registered_pp_pragmas;
1410 struct omp_pragma_def { const char *name; unsigned int id; };
1411 static const struct omp_pragma_def omp_pragmas[] = {
1412 { "atomic", PRAGMA_OMP_ATOMIC },
1413 { "barrier", PRAGMA_OMP_BARRIER },
1414 { "cancel", PRAGMA_OMP_CANCEL },
1415 { "cancellation", PRAGMA_OMP_CANCELLATION_POINT },
1416 { "critical", PRAGMA_OMP_CRITICAL },
1417 { "end", PRAGMA_OMP_END_DECLARE_TARGET },
1418 { "flush", PRAGMA_OMP_FLUSH },
1419 { "master", PRAGMA_OMP_MASTER },
1420 { "ordered", PRAGMA_OMP_ORDERED },
1421 { "section", PRAGMA_OMP_SECTION },
1422 { "sections", PRAGMA_OMP_SECTIONS },
1423 { "single", PRAGMA_OMP_SINGLE },
1424 { "taskgroup", PRAGMA_OMP_TASKGROUP },
1425 { "taskwait", PRAGMA_OMP_TASKWAIT },
1426 { "taskyield", PRAGMA_OMP_TASKYIELD },
1427 { "threadprivate", PRAGMA_OMP_THREADPRIVATE }
1429 static const struct omp_pragma_def omp_pragmas_simd[] = {
1430 { "declare", PRAGMA_OMP_DECLARE_REDUCTION },
1431 { "distribute", PRAGMA_OMP_DISTRIBUTE },
1432 { "for", PRAGMA_OMP_FOR },
1433 { "parallel", PRAGMA_OMP_PARALLEL },
1434 { "simd", PRAGMA_OMP_SIMD },
1435 { "target", PRAGMA_OMP_TARGET },
1436 { "task", PRAGMA_OMP_TASK },
1437 { "teams", PRAGMA_OMP_TEAMS },
1440 void
1441 c_pp_lookup_pragma (unsigned int id, const char **space, const char **name)
1443 const int n_omp_pragmas = sizeof (omp_pragmas) / sizeof (*omp_pragmas);
1444 const int n_omp_pragmas_simd = sizeof (omp_pragmas_simd)
1445 / sizeof (*omp_pragmas);
1446 int i;
1448 for (i = 0; i < n_omp_pragmas; ++i)
1449 if (omp_pragmas[i].id == id)
1451 *space = "omp";
1452 *name = omp_pragmas[i].name;
1453 return;
1456 for (i = 0; i < n_omp_pragmas_simd; ++i)
1457 if (omp_pragmas_simd[i].id == id)
1459 *space = "omp";
1460 *name = omp_pragmas_simd[i].name;
1461 return;
1464 if (id == PRAGMA_CILK_SIMD)
1466 *space = NULL;
1467 *name = "simd";
1468 return;
1471 if (id >= PRAGMA_FIRST_EXTERNAL
1472 && (id < PRAGMA_FIRST_EXTERNAL + registered_pp_pragmas.length ()))
1474 *space = registered_pp_pragmas[id - PRAGMA_FIRST_EXTERNAL].space;
1475 *name = registered_pp_pragmas[id - PRAGMA_FIRST_EXTERNAL].name;
1476 return;
1479 gcc_unreachable ();
1482 /* Front-end wrappers for pragma registration to avoid dragging
1483 cpplib.h in almost everywhere. */
1485 static void
1486 c_register_pragma_1 (const char *space, const char *name,
1487 internal_pragma_handler ihandler, bool allow_expansion)
1489 unsigned id;
1491 if (flag_preprocess_only)
1493 pragma_ns_name ns_name;
1495 if (!allow_expansion)
1496 return;
1498 ns_name.space = space;
1499 ns_name.name = name;
1500 registered_pp_pragmas.safe_push (ns_name);
1501 id = registered_pp_pragmas.length ();
1502 id += PRAGMA_FIRST_EXTERNAL - 1;
1504 else
1506 registered_pragmas.safe_push (ihandler);
1507 id = registered_pragmas.length ();
1508 id += PRAGMA_FIRST_EXTERNAL - 1;
1510 /* The C++ front end allocates 6 bits in cp_token; the C front end
1511 allocates 7 bits in c_token. At present this is sufficient. */
1512 gcc_assert (id < 64);
1515 cpp_register_deferred_pragma (parse_in, space, name, id,
1516 allow_expansion, false);
1519 /* Register a C pragma handler, using a space and a name. It disallows pragma
1520 expansion (if you want it, use c_register_pragma_with_expansion instead). */
1521 void
1522 c_register_pragma (const char *space, const char *name,
1523 pragma_handler_1arg handler)
1525 internal_pragma_handler ihandler;
1527 ihandler.handler.handler_1arg = handler;
1528 ihandler.extra_data = false;
1529 ihandler.data = NULL;
1530 c_register_pragma_1 (space, name, ihandler, false);
1533 /* Register a C pragma handler, using a space and a name, it also carries an
1534 extra data field which can be used by the handler. It disallows pragma
1535 expansion (if you want it, use c_register_pragma_with_expansion_and_data
1536 instead). */
1537 void
1538 c_register_pragma_with_data (const char *space, const char *name,
1539 pragma_handler_2arg handler, void * data)
1541 internal_pragma_handler ihandler;
1543 ihandler.handler.handler_2arg = handler;
1544 ihandler.extra_data = true;
1545 ihandler.data = data;
1546 c_register_pragma_1 (space, name, ihandler, false);
1549 /* Register a C pragma handler, using a space and a name. It allows pragma
1550 expansion as in the following example:
1552 #define NUMBER 10
1553 #pragma count (NUMBER)
1555 Name expansion is still disallowed. */
1556 void
1557 c_register_pragma_with_expansion (const char *space, const char *name,
1558 pragma_handler_1arg handler)
1560 internal_pragma_handler ihandler;
1562 ihandler.handler.handler_1arg = handler;
1563 ihandler.extra_data = false;
1564 ihandler.data = NULL;
1565 c_register_pragma_1 (space, name, ihandler, true);
1568 /* Register a C pragma handler, using a space and a name, it also carries an
1569 extra data field which can be used by the handler. It allows pragma
1570 expansion as in the following example:
1572 #define NUMBER 10
1573 #pragma count (NUMBER)
1575 Name expansion is still disallowed. */
1576 void
1577 c_register_pragma_with_expansion_and_data (const char *space, const char *name,
1578 pragma_handler_2arg handler,
1579 void *data)
1581 internal_pragma_handler ihandler;
1583 ihandler.handler.handler_2arg = handler;
1584 ihandler.extra_data = true;
1585 ihandler.data = data;
1586 c_register_pragma_1 (space, name, ihandler, true);
1589 void
1590 c_invoke_pragma_handler (unsigned int id)
1592 internal_pragma_handler *ihandler;
1593 pragma_handler_1arg handler_1arg;
1594 pragma_handler_2arg handler_2arg;
1596 id -= PRAGMA_FIRST_EXTERNAL;
1597 ihandler = &registered_pragmas[id];
1598 if (ihandler->extra_data)
1600 handler_2arg = ihandler->handler.handler_2arg;
1601 handler_2arg (parse_in, ihandler->data);
1603 else
1605 handler_1arg = ihandler->handler.handler_1arg;
1606 handler_1arg (parse_in);
1610 /* Set up front-end pragmas. */
1611 void
1612 init_pragma (void)
1614 if (flag_openmp)
1616 const int n_omp_pragmas = sizeof (omp_pragmas) / sizeof (*omp_pragmas);
1617 int i;
1619 for (i = 0; i < n_omp_pragmas; ++i)
1620 cpp_register_deferred_pragma (parse_in, "omp", omp_pragmas[i].name,
1621 omp_pragmas[i].id, true, true);
1623 if (flag_openmp || flag_openmp_simd)
1625 const int n_omp_pragmas_simd = sizeof (omp_pragmas_simd)
1626 / sizeof (*omp_pragmas);
1627 int i;
1629 for (i = 0; i < n_omp_pragmas_simd; ++i)
1630 cpp_register_deferred_pragma (parse_in, "omp", omp_pragmas_simd[i].name,
1631 omp_pragmas_simd[i].id, true, true);
1634 if (flag_cilkplus)
1635 cpp_register_deferred_pragma (parse_in, NULL, "simd", PRAGMA_CILK_SIMD,
1636 true, false);
1638 if (!flag_preprocess_only)
1639 cpp_register_deferred_pragma (parse_in, "GCC", "pch_preprocess",
1640 PRAGMA_GCC_PCH_PREPROCESS, false, false);
1642 if (!flag_preprocess_only)
1643 cpp_register_deferred_pragma (parse_in, "GCC", "ivdep", PRAGMA_IVDEP, false,
1644 false);
1645 #ifdef HANDLE_PRAGMA_PACK_WITH_EXPANSION
1646 c_register_pragma_with_expansion (0, "pack", handle_pragma_pack);
1647 #else
1648 c_register_pragma (0, "pack", handle_pragma_pack);
1649 #endif
1650 c_register_pragma (0, "weak", handle_pragma_weak);
1651 c_register_pragma ("GCC", "visibility", handle_pragma_visibility);
1653 c_register_pragma ("GCC", "diagnostic", handle_pragma_diagnostic);
1654 c_register_pragma ("GCC", "target", handle_pragma_target);
1655 c_register_pragma ("GCC", "optimize", handle_pragma_optimize);
1656 c_register_pragma ("GCC", "push_options", handle_pragma_push_options);
1657 c_register_pragma ("GCC", "pop_options", handle_pragma_pop_options);
1658 c_register_pragma ("GCC", "reset_options", handle_pragma_reset_options);
1660 c_register_pragma ("STDC", "FLOAT_CONST_DECIMAL64",
1661 handle_pragma_float_const_decimal64);
1663 c_register_pragma_with_expansion (0, "redefine_extname",
1664 handle_pragma_redefine_extname);
1666 c_register_pragma_with_expansion (0, "message", handle_pragma_message);
1668 if (flag_upc)
1670 c_register_pragma (0, "upc", handle_pragma_upc);
1671 init_pragma_upc ();
1672 c_register_pragma (0, "pupc", handle_pragma_pupc);
1673 init_pragma_pupc ();
1676 #ifdef REGISTER_TARGET_PRAGMAS
1677 REGISTER_TARGET_PRAGMAS ();
1678 #endif
1680 /* Allow plugins to register their own pragmas. */
1681 invoke_plugin_callbacks (PLUGIN_PRAGMAS, NULL);
1684 #include "gt-c-family-c-pragma.h"