Daily bump.
[official-gcc.git] / gcc / c-family / c-pragma.c
blobc73aa8221049b85949b0b62e88f58120e43aa39d
1 /* Handle #pragma, system V.4 style. Supports #pragma weak and #pragma pack.
2 Copyright (C) 1992-2016 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 "target.h"
24 #include "function.h" /* For cfun. */
25 #include "c-common.h"
26 #include "tm_p.h" /* For REGISTER_TARGET_PRAGMAS. */
27 #include "stringpool.h"
28 #include "cgraph.h"
29 #include "diagnostic.h"
30 #include "attribs.h"
31 #include "varasm.h"
32 #include "c-pragma.h"
33 #include "opts.h"
34 #include "plugin.h"
36 #define GCC_BAD(gmsgid) \
37 do { warning (OPT_Wpragmas, gmsgid); return; } while (0)
38 #define GCC_BAD2(gmsgid, arg) \
39 do { warning (OPT_Wpragmas, gmsgid, arg); return; } while (0)
41 struct GTY(()) align_stack {
42 int alignment;
43 tree id;
44 struct align_stack * prev;
47 static GTY(()) struct align_stack * alignment_stack;
49 static void handle_pragma_pack (cpp_reader *);
51 /* If we have a "global" #pragma pack(<n>) in effect when the first
52 #pragma pack(push,<n>) is encountered, this stores the value of
53 maximum_field_alignment in effect. When the final pop_alignment()
54 happens, we restore the value to this, not to a value of 0 for
55 maximum_field_alignment. Value is in bits. */
56 static int default_alignment;
57 #define SET_GLOBAL_ALIGNMENT(ALIGN) (maximum_field_alignment = *(alignment_stack == NULL \
58 ? &default_alignment \
59 : &alignment_stack->alignment) = (ALIGN))
61 static void push_alignment (int, tree);
62 static void pop_alignment (tree);
64 /* Push an alignment value onto the stack. */
65 static void
66 push_alignment (int alignment, tree id)
68 align_stack * entry = ggc_alloc<align_stack> ();
70 entry->alignment = alignment;
71 entry->id = id;
72 entry->prev = alignment_stack;
74 /* The current value of maximum_field_alignment is not necessarily
75 0 since there may be a #pragma pack(<n>) in effect; remember it
76 so that we can restore it after the final #pragma pop(). */
77 if (alignment_stack == NULL)
78 default_alignment = maximum_field_alignment;
80 alignment_stack = entry;
82 maximum_field_alignment = alignment;
85 /* Undo a push of an alignment onto the stack. */
86 static void
87 pop_alignment (tree id)
89 align_stack * entry;
91 if (alignment_stack == NULL)
92 GCC_BAD ("#pragma pack (pop) encountered without matching #pragma pack (push)");
94 /* If we got an identifier, strip away everything above the target
95 entry so that the next step will restore the state just below it. */
96 if (id)
98 for (entry = alignment_stack; entry; entry = entry->prev)
99 if (entry->id == id)
101 alignment_stack = entry;
102 break;
104 if (entry == NULL)
105 warning (OPT_Wpragmas, "\
106 #pragma pack(pop, %E) encountered without matching #pragma pack(push, %E)"
107 , id, id);
110 entry = alignment_stack->prev;
112 maximum_field_alignment = entry ? entry->alignment : default_alignment;
114 alignment_stack = entry;
117 /* #pragma pack ()
118 #pragma pack (N)
120 #pragma pack (push)
121 #pragma pack (push, N)
122 #pragma pack (push, ID)
123 #pragma pack (push, ID, N)
124 #pragma pack (pop)
125 #pragma pack (pop, ID) */
126 static void
127 handle_pragma_pack (cpp_reader * ARG_UNUSED (dummy))
129 tree x, id = 0;
130 int align = -1;
131 enum cpp_ttype token;
132 enum { set, push, pop } action;
134 if (pragma_lex (&x) != CPP_OPEN_PAREN)
135 GCC_BAD ("missing %<(%> after %<#pragma pack%> - ignored");
137 token = pragma_lex (&x);
138 if (token == CPP_CLOSE_PAREN)
140 action = set;
141 align = initial_max_fld_align;
143 else if (token == CPP_NUMBER)
145 if (TREE_CODE (x) != INTEGER_CST)
146 GCC_BAD ("invalid constant in %<#pragma pack%> - ignored");
147 align = TREE_INT_CST_LOW (x);
148 action = set;
149 if (pragma_lex (&x) != CPP_CLOSE_PAREN)
150 GCC_BAD ("malformed %<#pragma pack%> - ignored");
152 else if (token == CPP_NAME)
154 #define GCC_BAD_ACTION do { if (action != pop) \
155 GCC_BAD ("malformed %<#pragma pack(push[, id][, <n>])%> - ignored"); \
156 else \
157 GCC_BAD ("malformed %<#pragma pack(pop[, id])%> - ignored"); \
158 } while (0)
160 const char *op = IDENTIFIER_POINTER (x);
161 if (!strcmp (op, "push"))
162 action = push;
163 else if (!strcmp (op, "pop"))
164 action = pop;
165 else
166 GCC_BAD2 ("unknown action %qE for %<#pragma pack%> - ignored", x);
168 while ((token = pragma_lex (&x)) == CPP_COMMA)
170 token = pragma_lex (&x);
171 if (token == CPP_NAME && id == 0)
173 id = x;
175 else if (token == CPP_NUMBER && action == push && align == -1)
177 if (TREE_CODE (x) != INTEGER_CST)
178 GCC_BAD ("invalid constant in %<#pragma pack%> - ignored");
179 align = TREE_INT_CST_LOW (x);
180 if (align == -1)
181 action = set;
183 else
184 GCC_BAD_ACTION;
187 if (token != CPP_CLOSE_PAREN)
188 GCC_BAD_ACTION;
189 #undef GCC_BAD_ACTION
191 else
192 GCC_BAD ("malformed %<#pragma pack%> - ignored");
194 if (pragma_lex (&x) != CPP_EOF)
195 warning (OPT_Wpragmas, "junk at end of %<#pragma pack%>");
197 if (flag_pack_struct)
198 GCC_BAD ("#pragma pack has no effect with -fpack-struct - ignored");
200 if (action != pop)
201 switch (align)
203 case 0:
204 case 1:
205 case 2:
206 case 4:
207 case 8:
208 case 16:
209 align *= BITS_PER_UNIT;
210 break;
211 case -1:
212 if (action == push)
214 align = maximum_field_alignment;
215 break;
217 default:
218 GCC_BAD2 ("alignment must be a small power of two, not %d", align);
221 switch (action)
223 case set: SET_GLOBAL_ALIGNMENT (align); break;
224 case push: push_alignment (align, id); break;
225 case pop: pop_alignment (id); break;
229 struct GTY(()) pending_weak
231 tree name;
232 tree value;
236 static GTY(()) vec<pending_weak, va_gc> *pending_weaks;
238 static void apply_pragma_weak (tree, tree);
239 static void handle_pragma_weak (cpp_reader *);
241 static void
242 apply_pragma_weak (tree decl, tree value)
244 if (value)
246 value = build_string (IDENTIFIER_LENGTH (value),
247 IDENTIFIER_POINTER (value));
248 decl_attributes (&decl, build_tree_list (get_identifier ("alias"),
249 build_tree_list (NULL, value)),
253 if (SUPPORTS_WEAK && DECL_EXTERNAL (decl) && TREE_USED (decl)
254 && !DECL_WEAK (decl) /* Don't complain about a redundant #pragma. */
255 && DECL_ASSEMBLER_NAME_SET_P (decl)
256 && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
257 warning (OPT_Wpragmas, "applying #pragma weak %q+D after first use "
258 "results in unspecified behavior", decl);
260 declare_weak (decl);
263 void
264 maybe_apply_pragma_weak (tree decl)
266 tree id;
267 int i;
268 pending_weak *pe;
270 /* Avoid asking for DECL_ASSEMBLER_NAME when it's not needed. */
272 /* No weak symbols pending, take the short-cut. */
273 if (vec_safe_is_empty (pending_weaks))
274 return;
275 /* If it's not visible outside this file, it doesn't matter whether
276 it's weak. */
277 if (!DECL_EXTERNAL (decl) && !TREE_PUBLIC (decl))
278 return;
279 /* If it's not a function or a variable, it can't be weak.
280 FIXME: what kinds of things are visible outside this file but
281 aren't functions or variables? Should this be an assert instead? */
282 if (!VAR_OR_FUNCTION_DECL_P (decl))
283 return;
285 if (DECL_ASSEMBLER_NAME_SET_P (decl))
286 id = DECL_ASSEMBLER_NAME (decl);
287 else
289 id = DECL_ASSEMBLER_NAME (decl);
290 SET_DECL_ASSEMBLER_NAME (decl, NULL_TREE);
293 FOR_EACH_VEC_ELT (*pending_weaks, i, pe)
294 if (id == pe->name)
296 apply_pragma_weak (decl, pe->value);
297 pending_weaks->unordered_remove (i);
298 break;
302 /* Process all "#pragma weak A = B" directives where we have not seen
303 a decl for A. */
304 void
305 maybe_apply_pending_pragma_weaks (void)
307 tree alias_id, id, decl;
308 int i;
309 pending_weak *pe;
310 symtab_node *target;
312 if (vec_safe_is_empty (pending_weaks))
313 return;
315 FOR_EACH_VEC_ELT (*pending_weaks, i, pe)
317 alias_id = pe->name;
318 id = pe->value;
320 if (id == NULL)
321 continue;
323 target = symtab_node::get_for_asmname (id);
324 decl = build_decl (UNKNOWN_LOCATION,
325 target ? TREE_CODE (target->decl) : FUNCTION_DECL,
326 alias_id, default_function_type);
328 DECL_ARTIFICIAL (decl) = 1;
329 TREE_PUBLIC (decl) = 1;
330 DECL_WEAK (decl) = 1;
331 if (VAR_P (decl))
332 TREE_STATIC (decl) = 1;
333 if (!target)
335 error ("%q+D aliased to undefined symbol %qE",
336 decl, id);
337 continue;
340 assemble_alias (decl, id);
344 /* #pragma weak name [= value] */
345 static void
346 handle_pragma_weak (cpp_reader * ARG_UNUSED (dummy))
348 tree name, value, x, decl;
349 enum cpp_ttype t;
351 value = 0;
353 if (pragma_lex (&name) != CPP_NAME)
354 GCC_BAD ("malformed #pragma weak, ignored");
355 t = pragma_lex (&x);
356 if (t == CPP_EQ)
358 if (pragma_lex (&value) != CPP_NAME)
359 GCC_BAD ("malformed #pragma weak, ignored");
360 t = pragma_lex (&x);
362 if (t != CPP_EOF)
363 warning (OPT_Wpragmas, "junk at end of %<#pragma weak%>");
365 decl = identifier_global_value (name);
366 if (decl && DECL_P (decl))
368 if (!VAR_OR_FUNCTION_DECL_P (decl))
369 GCC_BAD2 ("%<#pragma weak%> declaration of %q+D not allowed,"
370 " ignored", decl);
371 apply_pragma_weak (decl, value);
372 if (value)
374 DECL_EXTERNAL (decl) = 0;
375 if (VAR_P (decl))
376 TREE_STATIC (decl) = 1;
377 assemble_alias (decl, value);
380 else
382 pending_weak pe = {name, value};
383 vec_safe_push (pending_weaks, pe);
387 static enum scalar_storage_order_kind global_sso;
389 void
390 maybe_apply_pragma_scalar_storage_order (tree type)
392 if (global_sso == SSO_NATIVE)
393 return;
395 gcc_assert (RECORD_OR_UNION_TYPE_P (type));
397 if (lookup_attribute ("scalar_storage_order", TYPE_ATTRIBUTES (type)))
398 return;
400 if (global_sso == SSO_BIG_ENDIAN)
401 TYPE_REVERSE_STORAGE_ORDER (type) = !BYTES_BIG_ENDIAN;
402 else if (global_sso == SSO_LITTLE_ENDIAN)
403 TYPE_REVERSE_STORAGE_ORDER (type) = BYTES_BIG_ENDIAN;
404 else
405 gcc_unreachable ();
408 static void
409 handle_pragma_scalar_storage_order (cpp_reader *ARG_UNUSED(dummy))
411 const char *kind_string;
412 enum cpp_ttype token;
413 tree x;
415 if (BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN)
416 error ("scalar_storage_order is not supported");
418 token = pragma_lex (&x);
419 if (token != CPP_NAME)
420 GCC_BAD ("missing [big-endian|little-endian|default] after %<#pragma scalar_storage_order%>");
421 kind_string = IDENTIFIER_POINTER (x);
422 if (strcmp (kind_string, "default") == 0)
423 global_sso = default_sso;
424 else if (strcmp (kind_string, "big") == 0)
425 global_sso = SSO_BIG_ENDIAN;
426 else if (strcmp (kind_string, "little") == 0)
427 global_sso = SSO_LITTLE_ENDIAN;
428 else
429 GCC_BAD ("expected [big-endian|little-endian|default] after %<#pragma scalar_storage_order%>");
432 /* GCC supports two #pragma directives for renaming the external
433 symbol associated with a declaration (DECL_ASSEMBLER_NAME), for
434 compatibility with the Solaris and VMS system headers. GCC also
435 has its own notation for this, __asm__("name") annotations.
437 Corner cases of these features and their interaction:
439 1) Both pragmas silently apply only to declarations with external
440 linkage (that is, TREE_PUBLIC || DECL_EXTERNAL). Asm labels
441 do not have this restriction.
443 2) In C++, both #pragmas silently apply only to extern "C" declarations.
444 Asm labels do not have this restriction.
446 3) If any of the three ways of changing DECL_ASSEMBLER_NAME is
447 applied to a decl whose DECL_ASSEMBLER_NAME is already set, and the
448 new name is different, a warning issues and the name does not change.
450 4) The "source name" for #pragma redefine_extname is the DECL_NAME,
451 *not* the DECL_ASSEMBLER_NAME.
453 5) If #pragma extern_prefix is in effect and a declaration occurs
454 with an __asm__ name, the #pragma extern_prefix is silently
455 ignored for that declaration.
457 6) If #pragma extern_prefix and #pragma redefine_extname apply to
458 the same declaration, whichever triggered first wins, and a warning
459 is issued. (We would like to have #pragma redefine_extname always
460 win, but it can appear either before or after the declaration, and
461 if it appears afterward, we have no way of knowing whether a modified
462 DECL_ASSEMBLER_NAME is due to #pragma extern_prefix.) */
464 struct GTY(()) pending_redefinition {
465 tree oldname;
466 tree newname;
470 static GTY(()) vec<pending_redefinition, va_gc> *pending_redefine_extname;
472 static void handle_pragma_redefine_extname (cpp_reader *);
474 /* #pragma redefine_extname oldname newname */
475 static void
476 handle_pragma_redefine_extname (cpp_reader * ARG_UNUSED (dummy))
478 tree oldname, newname, decls, x;
479 enum cpp_ttype t;
480 bool found;
482 if (pragma_lex (&oldname) != CPP_NAME)
483 GCC_BAD ("malformed #pragma redefine_extname, ignored");
484 if (pragma_lex (&newname) != CPP_NAME)
485 GCC_BAD ("malformed #pragma redefine_extname, ignored");
486 t = pragma_lex (&x);
487 if (t != CPP_EOF)
488 warning (OPT_Wpragmas, "junk at end of %<#pragma redefine_extname%>");
490 found = false;
491 for (decls = c_linkage_bindings (oldname);
492 decls; )
494 tree decl;
495 if (TREE_CODE (decls) == TREE_LIST)
497 decl = TREE_VALUE (decls);
498 decls = TREE_CHAIN (decls);
500 else
502 decl = decls;
503 decls = NULL_TREE;
506 if ((TREE_PUBLIC (decl) || DECL_EXTERNAL (decl))
507 && VAR_OR_FUNCTION_DECL_P (decl))
509 found = true;
510 if (DECL_ASSEMBLER_NAME_SET_P (decl))
512 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
513 name = targetm.strip_name_encoding (name);
515 if (strcmp (name, IDENTIFIER_POINTER (newname)))
516 warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
517 "conflict with previous rename");
519 else
520 symtab->change_decl_assembler_name (decl, newname);
524 if (!found)
525 /* We have to add this to the rename list even if there's already
526 a global value that doesn't meet the above criteria, because in
527 C++ "struct foo {...};" puts "foo" in the current namespace but
528 does *not* conflict with a subsequent declaration of a function
529 or variable foo. See g++.dg/other/pragma-re-2.C. */
530 add_to_renaming_pragma_list (oldname, newname);
533 /* This is called from here and from ia64-c.c. */
534 void
535 add_to_renaming_pragma_list (tree oldname, tree newname)
537 unsigned ix;
538 pending_redefinition *p;
540 FOR_EACH_VEC_SAFE_ELT (pending_redefine_extname, ix, p)
541 if (oldname == p->oldname)
543 if (p->newname != newname)
544 warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
545 "conflict with previous #pragma redefine_extname");
546 return;
549 pending_redefinition e = {oldname, newname};
550 vec_safe_push (pending_redefine_extname, e);
553 /* The current prefix set by #pragma extern_prefix. */
554 GTY(()) tree pragma_extern_prefix;
556 /* Hook from the front ends to apply the results of one of the preceding
557 pragmas that rename variables. */
559 tree
560 maybe_apply_renaming_pragma (tree decl, tree asmname)
562 unsigned ix;
563 pending_redefinition *p;
565 /* The renaming pragmas are only applied to declarations with
566 external linkage. */
567 if (!VAR_OR_FUNCTION_DECL_P (decl)
568 || (!TREE_PUBLIC (decl) && !DECL_EXTERNAL (decl))
569 || !has_c_linkage (decl))
570 return asmname;
572 /* If the DECL_ASSEMBLER_NAME is already set, it does not change,
573 but we may warn about a rename that conflicts. */
574 if (DECL_ASSEMBLER_NAME_SET_P (decl))
576 const char *oldname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
577 oldname = targetm.strip_name_encoding (oldname);
579 if (asmname && strcmp (TREE_STRING_POINTER (asmname), oldname))
580 warning (OPT_Wpragmas, "asm declaration ignored due to "
581 "conflict with previous rename");
583 /* Take any pending redefine_extname off the list. */
584 FOR_EACH_VEC_SAFE_ELT (pending_redefine_extname, ix, p)
585 if (DECL_NAME (decl) == p->oldname)
587 /* Only warn if there is a conflict. */
588 if (strcmp (IDENTIFIER_POINTER (p->newname), oldname))
589 warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
590 "conflict with previous rename");
592 pending_redefine_extname->unordered_remove (ix);
593 break;
595 return 0;
598 /* Find out if we have a pending #pragma redefine_extname. */
599 FOR_EACH_VEC_SAFE_ELT (pending_redefine_extname, ix, p)
600 if (DECL_NAME (decl) == p->oldname)
602 tree newname = p->newname;
603 pending_redefine_extname->unordered_remove (ix);
605 /* If we already have an asmname, #pragma redefine_extname is
606 ignored (with a warning if it conflicts). */
607 if (asmname)
609 if (strcmp (TREE_STRING_POINTER (asmname),
610 IDENTIFIER_POINTER (newname)) != 0)
611 warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
612 "conflict with __asm__ declaration");
613 return asmname;
616 /* Otherwise we use what we've got; #pragma extern_prefix is
617 silently ignored. */
618 return build_string (IDENTIFIER_LENGTH (newname),
619 IDENTIFIER_POINTER (newname));
622 /* If we've got an asmname, #pragma extern_prefix is silently ignored. */
623 if (asmname)
624 return asmname;
626 /* If #pragma extern_prefix is in effect, apply it. */
627 if (pragma_extern_prefix)
629 const char *prefix = TREE_STRING_POINTER (pragma_extern_prefix);
630 size_t plen = TREE_STRING_LENGTH (pragma_extern_prefix) - 1;
632 const char *id = IDENTIFIER_POINTER (DECL_NAME (decl));
633 size_t ilen = IDENTIFIER_LENGTH (DECL_NAME (decl));
635 char *newname = (char *) alloca (plen + ilen + 1);
637 memcpy (newname, prefix, plen);
638 memcpy (newname + plen, id, ilen + 1);
640 return build_string (plen + ilen, newname);
643 /* Nada. */
644 return 0;
648 static void handle_pragma_visibility (cpp_reader *);
650 static vec<int> visstack;
652 /* Push the visibility indicated by STR onto the top of the #pragma
653 visibility stack. KIND is 0 for #pragma GCC visibility, 1 for
654 C++ namespace with visibility attribute and 2 for C++ builtin
655 ABI namespace. push_visibility/pop_visibility calls must have
656 matching KIND, it is not allowed to push visibility using one
657 KIND and pop using a different one. */
659 void
660 push_visibility (const char *str, int kind)
662 visstack.safe_push (((int) default_visibility) | (kind << 8));
663 if (!strcmp (str, "default"))
664 default_visibility = VISIBILITY_DEFAULT;
665 else if (!strcmp (str, "internal"))
666 default_visibility = VISIBILITY_INTERNAL;
667 else if (!strcmp (str, "hidden"))
668 default_visibility = VISIBILITY_HIDDEN;
669 else if (!strcmp (str, "protected"))
670 default_visibility = VISIBILITY_PROTECTED;
671 else
672 GCC_BAD ("#pragma GCC visibility push() must specify default, internal, hidden or protected");
673 visibility_options.inpragma = 1;
676 /* Pop a level of the #pragma visibility stack. Return true if
677 successful. */
679 bool
680 pop_visibility (int kind)
682 if (!visstack.length ())
683 return false;
684 if ((visstack.last () >> 8) != kind)
685 return false;
686 default_visibility
687 = (enum symbol_visibility) (visstack.pop () & 0xff);
688 visibility_options.inpragma
689 = visstack.length () != 0;
690 return true;
693 /* Sets the default visibility for symbols to something other than that
694 specified on the command line. */
696 static void
697 handle_pragma_visibility (cpp_reader *dummy ATTRIBUTE_UNUSED)
699 /* Form is #pragma GCC visibility push(hidden)|pop */
700 tree x;
701 enum cpp_ttype token;
702 enum { bad, push, pop } action = bad;
704 token = pragma_lex (&x);
705 if (token == CPP_NAME)
707 const char *op = IDENTIFIER_POINTER (x);
708 if (!strcmp (op, "push"))
709 action = push;
710 else if (!strcmp (op, "pop"))
711 action = pop;
713 if (bad == action)
714 GCC_BAD ("#pragma GCC visibility must be followed by push or pop");
715 else
717 if (pop == action)
719 if (! pop_visibility (0))
720 GCC_BAD ("no matching push for %<#pragma GCC visibility pop%>");
722 else
724 if (pragma_lex (&x) != CPP_OPEN_PAREN)
725 GCC_BAD ("missing %<(%> after %<#pragma GCC visibility push%> - ignored");
726 token = pragma_lex (&x);
727 if (token != CPP_NAME)
728 GCC_BAD ("malformed #pragma GCC visibility push");
729 else
730 push_visibility (IDENTIFIER_POINTER (x), 0);
731 if (pragma_lex (&x) != CPP_CLOSE_PAREN)
732 GCC_BAD ("missing %<(%> after %<#pragma GCC visibility push%> - ignored");
735 if (pragma_lex (&x) != CPP_EOF)
736 warning (OPT_Wpragmas, "junk at end of %<#pragma GCC visibility%>");
739 static void
740 handle_pragma_diagnostic(cpp_reader *ARG_UNUSED(dummy))
742 tree x;
743 location_t loc;
744 enum cpp_ttype token = pragma_lex (&x, &loc);
745 if (token != CPP_NAME)
747 warning_at (loc, OPT_Wpragmas,
748 "missing [error|warning|ignored|push|pop]"
749 " after %<#pragma GCC diagnostic%>");
750 return;
753 diagnostic_t kind;
754 const char *kind_string = IDENTIFIER_POINTER (x);
755 if (strcmp (kind_string, "error") == 0)
756 kind = DK_ERROR;
757 else if (strcmp (kind_string, "warning") == 0)
758 kind = DK_WARNING;
759 else if (strcmp (kind_string, "ignored") == 0)
760 kind = DK_IGNORED;
761 else if (strcmp (kind_string, "push") == 0)
763 diagnostic_push_diagnostics (global_dc, input_location);
764 return;
766 else if (strcmp (kind_string, "pop") == 0)
768 diagnostic_pop_diagnostics (global_dc, input_location);
769 return;
771 else
773 warning_at (loc, OPT_Wpragmas,
774 "expected [error|warning|ignored|push|pop]"
775 " after %<#pragma GCC diagnostic%>");
776 return;
779 token = pragma_lex (&x, &loc);
780 if (token != CPP_STRING)
782 warning_at (loc, OPT_Wpragmas,
783 "missing option after %<#pragma GCC diagnostic%> kind");
784 return;
787 const char *option_string = TREE_STRING_POINTER (x);
788 unsigned int lang_mask = c_common_option_lang_mask () | CL_COMMON;
789 /* option_string + 1 to skip the initial '-' */
790 unsigned int option_index = find_opt (option_string + 1, lang_mask);
791 if (option_index == OPT_SPECIAL_unknown)
793 warning_at (loc, OPT_Wpragmas,
794 "unknown option after %<#pragma GCC diagnostic%> kind");
795 return;
797 else if (!(cl_options[option_index].flags & CL_WARNING))
799 warning_at (loc, OPT_Wpragmas,
800 "%qs is not an option that controls warnings", option_string);
801 return;
803 else if (!(cl_options[option_index].flags & lang_mask))
805 char *ok_langs = write_langs (cl_options[option_index].flags);
806 char *bad_lang = write_langs (c_common_option_lang_mask ());
807 warning_at (loc, OPT_Wpragmas,
808 "option %qs is valid for %s but not for %s",
809 option_string, ok_langs, bad_lang);
810 free (ok_langs);
811 free (bad_lang);
812 return;
815 struct cl_option_handlers handlers;
816 set_default_handlers (&handlers);
817 const char *arg = NULL;
818 if (cl_options[option_index].flags & CL_JOINED)
819 arg = option_string + 1 + cl_options[option_index].opt_len;
820 /* FIXME: input_location isn't the best location here, but it is
821 what we used to do here before and changing it breaks e.g.
822 PR69543 and PR69558. */
823 control_warning_option (option_index, (int) kind,
824 arg, kind != DK_IGNORED,
825 input_location, lang_mask, &handlers,
826 &global_options, &global_options_set,
827 global_dc);
830 /* Parse #pragma GCC target (xxx) to set target specific options. */
831 static void
832 handle_pragma_target(cpp_reader *ARG_UNUSED(dummy))
834 enum cpp_ttype token;
835 tree x;
836 bool close_paren_needed_p = false;
838 if (cfun)
840 error ("#pragma GCC option is not allowed inside functions");
841 return;
844 token = pragma_lex (&x);
845 if (token == CPP_OPEN_PAREN)
847 close_paren_needed_p = true;
848 token = pragma_lex (&x);
851 if (token != CPP_STRING)
853 GCC_BAD ("%<#pragma GCC option%> is not a string");
854 return;
857 /* Strings are user options. */
858 else
860 tree args = NULL_TREE;
864 /* Build up the strings now as a tree linked list. Skip empty
865 strings. */
866 if (TREE_STRING_LENGTH (x) > 0)
867 args = tree_cons (NULL_TREE, x, args);
869 token = pragma_lex (&x);
870 while (token == CPP_COMMA)
871 token = pragma_lex (&x);
873 while (token == CPP_STRING);
875 if (close_paren_needed_p)
877 if (token == CPP_CLOSE_PAREN)
878 token = pragma_lex (&x);
879 else
880 GCC_BAD ("%<#pragma GCC target (string [,string]...)%> does "
881 "not have a final %<)%>");
884 if (token != CPP_EOF)
886 error ("#pragma GCC target string... is badly formed");
887 return;
890 /* put arguments in the order the user typed them. */
891 args = nreverse (args);
893 if (targetm.target_option.pragma_parse (args, NULL_TREE))
894 current_target_pragma = args;
898 /* Handle #pragma GCC optimize to set optimization options. */
899 static void
900 handle_pragma_optimize (cpp_reader *ARG_UNUSED(dummy))
902 enum cpp_ttype token;
903 tree x;
904 bool close_paren_needed_p = false;
905 tree optimization_previous_node = optimization_current_node;
907 if (cfun)
909 error ("#pragma GCC optimize is not allowed inside functions");
910 return;
913 token = pragma_lex (&x);
914 if (token == CPP_OPEN_PAREN)
916 close_paren_needed_p = true;
917 token = pragma_lex (&x);
920 if (token != CPP_STRING && token != CPP_NUMBER)
922 GCC_BAD ("%<#pragma GCC optimize%> is not a string or number");
923 return;
926 /* Strings/numbers are user options. */
927 else
929 tree args = NULL_TREE;
933 /* Build up the numbers/strings now as a list. */
934 if (token != CPP_STRING || TREE_STRING_LENGTH (x) > 0)
935 args = tree_cons (NULL_TREE, x, args);
937 token = pragma_lex (&x);
938 while (token == CPP_COMMA)
939 token = pragma_lex (&x);
941 while (token == CPP_STRING || token == CPP_NUMBER);
943 if (close_paren_needed_p)
945 if (token == CPP_CLOSE_PAREN)
946 token = pragma_lex (&x);
947 else
948 GCC_BAD ("%<#pragma GCC optimize (string [,string]...)%> does "
949 "not have a final %<)%>");
952 if (token != CPP_EOF)
954 error ("#pragma GCC optimize string... is badly formed");
955 return;
958 /* put arguments in the order the user typed them. */
959 args = nreverse (args);
961 parse_optimize_options (args, false);
962 current_optimize_pragma = chainon (current_optimize_pragma, args);
963 optimization_current_node = build_optimization_node (&global_options);
964 c_cpp_builtins_optimize_pragma (parse_in,
965 optimization_previous_node,
966 optimization_current_node);
970 /* Stack of the #pragma GCC options created with #pragma GCC push_option. Save
971 both the binary representation of the options and the TREE_LIST of
972 strings that will be added to the function's attribute list. */
973 struct GTY(()) opt_stack {
974 struct opt_stack *prev;
975 tree target_binary;
976 tree target_strings;
977 tree optimize_binary;
978 tree optimize_strings;
981 static GTY(()) struct opt_stack * options_stack;
983 /* Handle #pragma GCC push_options to save the current target and optimization
984 options. */
986 static void
987 handle_pragma_push_options (cpp_reader *ARG_UNUSED(dummy))
989 enum cpp_ttype token;
990 tree x = 0;
992 token = pragma_lex (&x);
993 if (token != CPP_EOF)
995 warning (OPT_Wpragmas, "junk at end of %<#pragma push_options%>");
996 return;
999 opt_stack *p = ggc_alloc<opt_stack> ();
1000 p->prev = options_stack;
1001 options_stack = p;
1003 /* Save optimization and target flags in binary format. */
1004 p->optimize_binary = build_optimization_node (&global_options);
1005 p->target_binary = build_target_option_node (&global_options);
1007 /* Save optimization and target flags in string list format. */
1008 p->optimize_strings = copy_list (current_optimize_pragma);
1009 p->target_strings = copy_list (current_target_pragma);
1012 /* Handle #pragma GCC pop_options to restore the current target and
1013 optimization options from a previous push_options. */
1015 static void
1016 handle_pragma_pop_options (cpp_reader *ARG_UNUSED(dummy))
1018 enum cpp_ttype token;
1019 tree x = 0;
1020 opt_stack *p;
1022 token = pragma_lex (&x);
1023 if (token != CPP_EOF)
1025 warning (OPT_Wpragmas, "junk at end of %<#pragma pop_options%>");
1026 return;
1029 if (! options_stack)
1031 warning (OPT_Wpragmas,
1032 "%<#pragma GCC pop_options%> without a corresponding "
1033 "%<#pragma GCC push_options%>");
1034 return;
1037 p = options_stack;
1038 options_stack = p->prev;
1040 if (p->target_binary != target_option_current_node)
1042 (void) targetm.target_option.pragma_parse (NULL_TREE, p->target_binary);
1043 target_option_current_node = p->target_binary;
1046 if (p->optimize_binary != optimization_current_node)
1048 tree old_optimize = optimization_current_node;
1049 cl_optimization_restore (&global_options,
1050 TREE_OPTIMIZATION (p->optimize_binary));
1051 c_cpp_builtins_optimize_pragma (parse_in, old_optimize,
1052 p->optimize_binary);
1053 optimization_current_node = p->optimize_binary;
1056 current_target_pragma = p->target_strings;
1057 current_optimize_pragma = p->optimize_strings;
1060 /* Handle #pragma GCC reset_options to restore the current target and
1061 optimization options to the original options used on the command line. */
1063 static void
1064 handle_pragma_reset_options (cpp_reader *ARG_UNUSED(dummy))
1066 enum cpp_ttype token;
1067 tree x = 0;
1068 tree new_optimize = optimization_default_node;
1069 tree new_target = target_option_default_node;
1071 token = pragma_lex (&x);
1072 if (token != CPP_EOF)
1074 warning (OPT_Wpragmas, "junk at end of %<#pragma reset_options%>");
1075 return;
1078 if (new_target != target_option_current_node)
1080 (void) targetm.target_option.pragma_parse (NULL_TREE, new_target);
1081 target_option_current_node = new_target;
1084 if (new_optimize != optimization_current_node)
1086 tree old_optimize = optimization_current_node;
1087 cl_optimization_restore (&global_options,
1088 TREE_OPTIMIZATION (new_optimize));
1089 c_cpp_builtins_optimize_pragma (parse_in, old_optimize, new_optimize);
1090 optimization_current_node = new_optimize;
1093 current_target_pragma = NULL_TREE;
1094 current_optimize_pragma = NULL_TREE;
1097 /* Print a plain user-specified message. */
1099 static void
1100 handle_pragma_message (cpp_reader *ARG_UNUSED(dummy))
1102 enum cpp_ttype token;
1103 tree x, message = 0;
1105 token = pragma_lex (&x);
1106 if (token == CPP_OPEN_PAREN)
1108 token = pragma_lex (&x);
1109 if (token == CPP_STRING)
1110 message = x;
1111 else
1112 GCC_BAD ("expected a string after %<#pragma message%>");
1113 if (pragma_lex (&x) != CPP_CLOSE_PAREN)
1114 GCC_BAD ("malformed %<#pragma message%>, ignored");
1116 else if (token == CPP_STRING)
1117 message = x;
1118 else
1119 GCC_BAD ("expected a string after %<#pragma message%>");
1121 gcc_assert (message);
1123 if (pragma_lex (&x) != CPP_EOF)
1124 warning (OPT_Wpragmas, "junk at end of %<#pragma message%>");
1126 if (TREE_STRING_LENGTH (message) > 1)
1127 inform (input_location, "#pragma message: %s", TREE_STRING_POINTER (message));
1130 /* Mark whether the current location is valid for a STDC pragma. */
1132 static bool valid_location_for_stdc_pragma;
1134 void
1135 mark_valid_location_for_stdc_pragma (bool flag)
1137 valid_location_for_stdc_pragma = flag;
1140 /* Return true if the current location is valid for a STDC pragma. */
1142 bool
1143 valid_location_for_stdc_pragma_p (void)
1145 return valid_location_for_stdc_pragma;
1148 enum pragma_switch_t { PRAGMA_ON, PRAGMA_OFF, PRAGMA_DEFAULT, PRAGMA_BAD };
1150 /* A STDC pragma must appear outside of external declarations or
1151 preceding all explicit declarations and statements inside a compound
1152 statement; its behavior is undefined if used in any other context.
1153 It takes a switch of ON, OFF, or DEFAULT. */
1155 static enum pragma_switch_t
1156 handle_stdc_pragma (const char *pname)
1158 const char *arg;
1159 tree t;
1160 enum pragma_switch_t ret;
1162 if (!valid_location_for_stdc_pragma_p ())
1164 warning (OPT_Wpragmas, "invalid location for %<pragma %s%>, ignored",
1165 pname);
1166 return PRAGMA_BAD;
1169 if (pragma_lex (&t) != CPP_NAME)
1171 warning (OPT_Wpragmas, "malformed %<#pragma %s%>, ignored", pname);
1172 return PRAGMA_BAD;
1175 arg = IDENTIFIER_POINTER (t);
1177 if (!strcmp (arg, "ON"))
1178 ret = PRAGMA_ON;
1179 else if (!strcmp (arg, "OFF"))
1180 ret = PRAGMA_OFF;
1181 else if (!strcmp (arg, "DEFAULT"))
1182 ret = PRAGMA_DEFAULT;
1183 else
1185 warning (OPT_Wpragmas, "malformed %<#pragma %s%>, ignored", pname);
1186 return PRAGMA_BAD;
1189 if (pragma_lex (&t) != CPP_EOF)
1191 warning (OPT_Wpragmas, "junk at end of %<#pragma %s%>", pname);
1192 return PRAGMA_BAD;
1195 return ret;
1198 /* #pragma STDC FLOAT_CONST_DECIMAL64 ON
1199 #pragma STDC FLOAT_CONST_DECIMAL64 OFF
1200 #pragma STDC FLOAT_CONST_DECIMAL64 DEFAULT */
1202 static void
1203 handle_pragma_float_const_decimal64 (cpp_reader *ARG_UNUSED (dummy))
1205 if (c_dialect_cxx ())
1207 if (warn_unknown_pragmas > in_system_header_at (input_location))
1208 warning (OPT_Wunknown_pragmas,
1209 "%<#pragma STDC FLOAT_CONST_DECIMAL64%> is not supported"
1210 " for C++");
1211 return;
1214 if (!targetm.decimal_float_supported_p ())
1216 if (warn_unknown_pragmas > in_system_header_at (input_location))
1217 warning (OPT_Wunknown_pragmas,
1218 "%<#pragma STDC FLOAT_CONST_DECIMAL64%> is not supported"
1219 " on this target");
1220 return;
1223 pedwarn (input_location, OPT_Wpedantic,
1224 "ISO C does not support %<#pragma STDC FLOAT_CONST_DECIMAL64%>");
1226 switch (handle_stdc_pragma ("STDC FLOAT_CONST_DECIMAL64"))
1228 case PRAGMA_ON:
1229 set_float_const_decimal64 ();
1230 break;
1231 case PRAGMA_OFF:
1232 case PRAGMA_DEFAULT:
1233 clear_float_const_decimal64 ();
1234 break;
1235 case PRAGMA_BAD:
1236 break;
1240 /* A vector of registered pragma callbacks, which is never freed. */
1242 static vec<internal_pragma_handler> registered_pragmas;
1244 struct pragma_ns_name
1246 const char *space;
1247 const char *name;
1251 static vec<pragma_ns_name> registered_pp_pragmas;
1253 struct omp_pragma_def { const char *name; unsigned int id; };
1254 static const struct omp_pragma_def oacc_pragmas[] = {
1255 { "atomic", PRAGMA_OACC_ATOMIC },
1256 { "cache", PRAGMA_OACC_CACHE },
1257 { "data", PRAGMA_OACC_DATA },
1258 { "declare", PRAGMA_OACC_DECLARE },
1259 { "enter", PRAGMA_OACC_ENTER_DATA },
1260 { "exit", PRAGMA_OACC_EXIT_DATA },
1261 { "host_data", PRAGMA_OACC_HOST_DATA },
1262 { "kernels", PRAGMA_OACC_KERNELS },
1263 { "loop", PRAGMA_OACC_LOOP },
1264 { "parallel", PRAGMA_OACC_PARALLEL },
1265 { "routine", PRAGMA_OACC_ROUTINE },
1266 { "update", PRAGMA_OACC_UPDATE },
1267 { "wait", PRAGMA_OACC_WAIT }
1269 static const struct omp_pragma_def omp_pragmas[] = {
1270 { "atomic", PRAGMA_OMP_ATOMIC },
1271 { "barrier", PRAGMA_OMP_BARRIER },
1272 { "cancel", PRAGMA_OMP_CANCEL },
1273 { "cancellation", PRAGMA_OMP_CANCELLATION_POINT },
1274 { "critical", PRAGMA_OMP_CRITICAL },
1275 { "end", PRAGMA_OMP_END_DECLARE_TARGET },
1276 { "flush", PRAGMA_OMP_FLUSH },
1277 { "master", PRAGMA_OMP_MASTER },
1278 { "ordered", PRAGMA_OMP_ORDERED },
1279 { "section", PRAGMA_OMP_SECTION },
1280 { "sections", PRAGMA_OMP_SECTIONS },
1281 { "single", PRAGMA_OMP_SINGLE },
1282 { "task", PRAGMA_OMP_TASK },
1283 { "taskgroup", PRAGMA_OMP_TASKGROUP },
1284 { "taskwait", PRAGMA_OMP_TASKWAIT },
1285 { "taskyield", PRAGMA_OMP_TASKYIELD },
1286 { "threadprivate", PRAGMA_OMP_THREADPRIVATE }
1288 static const struct omp_pragma_def omp_pragmas_simd[] = {
1289 { "declare", PRAGMA_OMP_DECLARE_REDUCTION },
1290 { "distribute", PRAGMA_OMP_DISTRIBUTE },
1291 { "for", PRAGMA_OMP_FOR },
1292 { "parallel", PRAGMA_OMP_PARALLEL },
1293 { "simd", PRAGMA_OMP_SIMD },
1294 { "target", PRAGMA_OMP_TARGET },
1295 { "taskloop", PRAGMA_OMP_TASKLOOP },
1296 { "teams", PRAGMA_OMP_TEAMS },
1299 void
1300 c_pp_lookup_pragma (unsigned int id, const char **space, const char **name)
1302 const int n_oacc_pragmas = sizeof (oacc_pragmas) / sizeof (*oacc_pragmas);
1303 const int n_omp_pragmas = sizeof (omp_pragmas) / sizeof (*omp_pragmas);
1304 const int n_omp_pragmas_simd = sizeof (omp_pragmas_simd)
1305 / sizeof (*omp_pragmas);
1306 int i;
1308 for (i = 0; i < n_oacc_pragmas; ++i)
1309 if (oacc_pragmas[i].id == id)
1311 *space = "acc";
1312 *name = oacc_pragmas[i].name;
1313 return;
1316 for (i = 0; i < n_omp_pragmas; ++i)
1317 if (omp_pragmas[i].id == id)
1319 *space = "omp";
1320 *name = omp_pragmas[i].name;
1321 return;
1324 for (i = 0; i < n_omp_pragmas_simd; ++i)
1325 if (omp_pragmas_simd[i].id == id)
1327 *space = "omp";
1328 *name = omp_pragmas_simd[i].name;
1329 return;
1332 if (id == PRAGMA_CILK_SIMD)
1334 *space = NULL;
1335 *name = "simd";
1336 return;
1339 if (id == PRAGMA_CILK_GRAINSIZE)
1341 *space = "cilk";
1342 *name = "grainsize";
1343 return;
1346 if (id >= PRAGMA_FIRST_EXTERNAL
1347 && (id < PRAGMA_FIRST_EXTERNAL + registered_pp_pragmas.length ()))
1349 *space = registered_pp_pragmas[id - PRAGMA_FIRST_EXTERNAL].space;
1350 *name = registered_pp_pragmas[id - PRAGMA_FIRST_EXTERNAL].name;
1351 return;
1354 gcc_unreachable ();
1357 /* Front-end wrappers for pragma registration to avoid dragging
1358 cpplib.h in almost everywhere. */
1360 static void
1361 c_register_pragma_1 (const char *space, const char *name,
1362 internal_pragma_handler ihandler, bool allow_expansion)
1364 unsigned id;
1366 if (flag_preprocess_only)
1368 pragma_ns_name ns_name;
1370 if (!allow_expansion)
1371 return;
1373 ns_name.space = space;
1374 ns_name.name = name;
1375 registered_pp_pragmas.safe_push (ns_name);
1376 id = registered_pp_pragmas.length ();
1377 id += PRAGMA_FIRST_EXTERNAL - 1;
1379 else
1381 registered_pragmas.safe_push (ihandler);
1382 id = registered_pragmas.length ();
1383 id += PRAGMA_FIRST_EXTERNAL - 1;
1385 /* The C front end allocates 8 bits in c_token. The C++ front end
1386 keeps the pragma kind in the form of INTEGER_CST, so no small
1387 limit applies. At present this is sufficient. */
1388 gcc_assert (id < 256);
1391 cpp_register_deferred_pragma (parse_in, space, name, id,
1392 allow_expansion, false);
1395 /* Register a C pragma handler, using a space and a name. It disallows pragma
1396 expansion (if you want it, use c_register_pragma_with_expansion instead). */
1397 void
1398 c_register_pragma (const char *space, const char *name,
1399 pragma_handler_1arg handler)
1401 internal_pragma_handler ihandler;
1403 ihandler.handler.handler_1arg = handler;
1404 ihandler.extra_data = false;
1405 ihandler.data = NULL;
1406 c_register_pragma_1 (space, name, ihandler, false);
1409 /* Register a C pragma handler, using a space and a name, it also carries an
1410 extra data field which can be used by the handler. It disallows pragma
1411 expansion (if you want it, use c_register_pragma_with_expansion_and_data
1412 instead). */
1413 void
1414 c_register_pragma_with_data (const char *space, const char *name,
1415 pragma_handler_2arg handler, void * data)
1417 internal_pragma_handler ihandler;
1419 ihandler.handler.handler_2arg = handler;
1420 ihandler.extra_data = true;
1421 ihandler.data = data;
1422 c_register_pragma_1 (space, name, ihandler, false);
1425 /* Register a C pragma handler, using a space and a name. It allows pragma
1426 expansion as in the following example:
1428 #define NUMBER 10
1429 #pragma count (NUMBER)
1431 Name expansion is still disallowed. */
1432 void
1433 c_register_pragma_with_expansion (const char *space, const char *name,
1434 pragma_handler_1arg handler)
1436 internal_pragma_handler ihandler;
1438 ihandler.handler.handler_1arg = handler;
1439 ihandler.extra_data = false;
1440 ihandler.data = NULL;
1441 c_register_pragma_1 (space, name, ihandler, true);
1444 /* Register a C pragma handler, using a space and a name, it also carries an
1445 extra data field which can be used by the handler. It allows pragma
1446 expansion as in the following example:
1448 #define NUMBER 10
1449 #pragma count (NUMBER)
1451 Name expansion is still disallowed. */
1452 void
1453 c_register_pragma_with_expansion_and_data (const char *space, const char *name,
1454 pragma_handler_2arg handler,
1455 void *data)
1457 internal_pragma_handler ihandler;
1459 ihandler.handler.handler_2arg = handler;
1460 ihandler.extra_data = true;
1461 ihandler.data = data;
1462 c_register_pragma_1 (space, name, ihandler, true);
1465 void
1466 c_invoke_pragma_handler (unsigned int id)
1468 internal_pragma_handler *ihandler;
1469 pragma_handler_1arg handler_1arg;
1470 pragma_handler_2arg handler_2arg;
1472 id -= PRAGMA_FIRST_EXTERNAL;
1473 ihandler = &registered_pragmas[id];
1474 if (ihandler->extra_data)
1476 handler_2arg = ihandler->handler.handler_2arg;
1477 handler_2arg (parse_in, ihandler->data);
1479 else
1481 handler_1arg = ihandler->handler.handler_1arg;
1482 handler_1arg (parse_in);
1486 /* Set up front-end pragmas. */
1487 void
1488 init_pragma (void)
1490 if (flag_openacc)
1492 const int n_oacc_pragmas
1493 = sizeof (oacc_pragmas) / sizeof (*oacc_pragmas);
1494 int i;
1496 for (i = 0; i < n_oacc_pragmas; ++i)
1497 cpp_register_deferred_pragma (parse_in, "acc", oacc_pragmas[i].name,
1498 oacc_pragmas[i].id, true, true);
1501 if (flag_openmp)
1503 const int n_omp_pragmas = sizeof (omp_pragmas) / sizeof (*omp_pragmas);
1504 int i;
1506 for (i = 0; i < n_omp_pragmas; ++i)
1507 cpp_register_deferred_pragma (parse_in, "omp", omp_pragmas[i].name,
1508 omp_pragmas[i].id, true, true);
1510 if (flag_openmp || flag_openmp_simd)
1512 const int n_omp_pragmas_simd = sizeof (omp_pragmas_simd)
1513 / sizeof (*omp_pragmas);
1514 int i;
1516 for (i = 0; i < n_omp_pragmas_simd; ++i)
1517 cpp_register_deferred_pragma (parse_in, "omp", omp_pragmas_simd[i].name,
1518 omp_pragmas_simd[i].id, true, true);
1521 if (flag_cilkplus)
1522 cpp_register_deferred_pragma (parse_in, NULL, "simd", PRAGMA_CILK_SIMD,
1523 true, false);
1525 if (!flag_preprocess_only)
1526 cpp_register_deferred_pragma (parse_in, "GCC", "pch_preprocess",
1527 PRAGMA_GCC_PCH_PREPROCESS, false, false);
1529 if (!flag_preprocess_only)
1530 cpp_register_deferred_pragma (parse_in, "GCC", "ivdep", PRAGMA_IVDEP, false,
1531 false);
1533 if (flag_cilkplus)
1534 cpp_register_deferred_pragma (parse_in, "cilk", "grainsize",
1535 PRAGMA_CILK_GRAINSIZE, true, false);
1537 #ifdef HANDLE_PRAGMA_PACK_WITH_EXPANSION
1538 c_register_pragma_with_expansion (0, "pack", handle_pragma_pack);
1539 #else
1540 c_register_pragma (0, "pack", handle_pragma_pack);
1541 #endif
1542 c_register_pragma (0, "weak", handle_pragma_weak);
1544 c_register_pragma ("GCC", "visibility", handle_pragma_visibility);
1546 c_register_pragma ("GCC", "diagnostic", handle_pragma_diagnostic);
1547 c_register_pragma ("GCC", "target", handle_pragma_target);
1548 c_register_pragma ("GCC", "optimize", handle_pragma_optimize);
1549 c_register_pragma ("GCC", "push_options", handle_pragma_push_options);
1550 c_register_pragma ("GCC", "pop_options", handle_pragma_pop_options);
1551 c_register_pragma ("GCC", "reset_options", handle_pragma_reset_options);
1553 c_register_pragma ("STDC", "FLOAT_CONST_DECIMAL64",
1554 handle_pragma_float_const_decimal64);
1556 c_register_pragma_with_expansion (0, "redefine_extname",
1557 handle_pragma_redefine_extname);
1559 c_register_pragma_with_expansion (0, "message", handle_pragma_message);
1561 #ifdef REGISTER_TARGET_PRAGMAS
1562 REGISTER_TARGET_PRAGMAS ();
1563 #endif
1565 global_sso = default_sso;
1566 c_register_pragma (0, "scalar_storage_order",
1567 handle_pragma_scalar_storage_order);
1569 /* Allow plugins to register their own pragmas. */
1570 invoke_plugin_callbacks (PLUGIN_PRAGMAS, NULL);
1573 #include "gt-c-family-c-pragma.h"