[ARM] Fix ICE in Armv8-M Security Extensions code
[official-gcc.git] / gcc / c-family / c-pragma.c
blobf7b59b3480726b038c7c323c31380d364480d52d
1 /* Handle #pragma, system V.4 style. Supports #pragma weak and #pragma pack.
2 Copyright (C) 1992-2017 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 "memmodel.h"
27 #include "tm_p.h" /* For REGISTER_TARGET_PRAGMAS. */
28 #include "stringpool.h"
29 #include "cgraph.h"
30 #include "diagnostic.h"
31 #include "attribs.h"
32 #include "varasm.h"
33 #include "c-pragma.h"
34 #include "opts.h"
35 #include "plugin.h"
37 #define GCC_BAD(gmsgid) \
38 do { warning (OPT_Wpragmas, gmsgid); return; } while (0)
39 #define GCC_BAD2(gmsgid, arg) \
40 do { warning (OPT_Wpragmas, gmsgid, arg); return; } while (0)
42 struct GTY(()) align_stack {
43 int alignment;
44 tree id;
45 struct align_stack * prev;
48 static GTY(()) struct align_stack * alignment_stack;
50 static void handle_pragma_pack (cpp_reader *);
52 /* If we have a "global" #pragma pack(<n>) in effect when the first
53 #pragma pack(push,<n>) is encountered, this stores the value of
54 maximum_field_alignment in effect. When the final pop_alignment()
55 happens, we restore the value to this, not to a value of 0 for
56 maximum_field_alignment. Value is in bits. */
57 static int default_alignment;
58 #define SET_GLOBAL_ALIGNMENT(ALIGN) (maximum_field_alignment = *(alignment_stack == NULL \
59 ? &default_alignment \
60 : &alignment_stack->alignment) = (ALIGN))
62 static void push_alignment (int, tree);
63 static void pop_alignment (tree);
65 /* Push an alignment value onto the stack. */
66 static void
67 push_alignment (int alignment, tree id)
69 align_stack * entry = ggc_alloc<align_stack> ();
71 entry->alignment = alignment;
72 entry->id = id;
73 entry->prev = alignment_stack;
75 /* The current value of maximum_field_alignment is not necessarily
76 0 since there may be a #pragma pack(<n>) in effect; remember it
77 so that we can restore it after the final #pragma pop(). */
78 if (alignment_stack == NULL)
79 default_alignment = maximum_field_alignment;
81 alignment_stack = entry;
83 maximum_field_alignment = alignment;
86 /* Undo a push of an alignment onto the stack. */
87 static void
88 pop_alignment (tree id)
90 align_stack * entry;
92 if (alignment_stack == NULL)
93 GCC_BAD ("#pragma pack (pop) encountered without matching #pragma pack (push)");
95 /* If we got an identifier, strip away everything above the target
96 entry so that the next step will restore the state just below it. */
97 if (id)
99 for (entry = alignment_stack; entry; entry = entry->prev)
100 if (entry->id == id)
102 alignment_stack = entry;
103 break;
105 if (entry == NULL)
106 warning (OPT_Wpragmas, "\
107 #pragma pack(pop, %E) encountered without matching #pragma pack(push, %E)"
108 , id, id);
111 entry = alignment_stack->prev;
113 maximum_field_alignment = entry ? entry->alignment : default_alignment;
115 alignment_stack = entry;
118 /* #pragma pack ()
119 #pragma pack (N)
121 #pragma pack (push)
122 #pragma pack (push, N)
123 #pragma pack (push, ID)
124 #pragma pack (push, ID, N)
125 #pragma pack (pop)
126 #pragma pack (pop, ID) */
127 static void
128 handle_pragma_pack (cpp_reader * ARG_UNUSED (dummy))
130 tree x, id = 0;
131 int align = -1;
132 enum cpp_ttype token;
133 enum { set, push, pop } action;
135 if (pragma_lex (&x) != CPP_OPEN_PAREN)
136 GCC_BAD ("missing %<(%> after %<#pragma pack%> - ignored");
138 token = pragma_lex (&x);
139 if (token == CPP_CLOSE_PAREN)
141 action = set;
142 align = initial_max_fld_align;
144 else if (token == CPP_NUMBER)
146 if (TREE_CODE (x) != INTEGER_CST)
147 GCC_BAD ("invalid constant in %<#pragma pack%> - ignored");
148 align = TREE_INT_CST_LOW (x);
149 action = set;
150 if (pragma_lex (&x) != CPP_CLOSE_PAREN)
151 GCC_BAD ("malformed %<#pragma pack%> - ignored");
153 else if (token == CPP_NAME)
155 #define GCC_BAD_ACTION do { if (action != pop) \
156 GCC_BAD ("malformed %<#pragma pack(push[, id][, <n>])%> - ignored"); \
157 else \
158 GCC_BAD ("malformed %<#pragma pack(pop[, id])%> - ignored"); \
159 } while (0)
161 const char *op = IDENTIFIER_POINTER (x);
162 if (!strcmp (op, "push"))
163 action = push;
164 else if (!strcmp (op, "pop"))
165 action = pop;
166 else
167 GCC_BAD2 ("unknown action %qE for %<#pragma pack%> - ignored", x);
169 while ((token = pragma_lex (&x)) == CPP_COMMA)
171 token = pragma_lex (&x);
172 if (token == CPP_NAME && id == 0)
174 id = x;
176 else if (token == CPP_NUMBER && action == push && align == -1)
178 if (TREE_CODE (x) != INTEGER_CST)
179 GCC_BAD ("invalid constant in %<#pragma pack%> - ignored");
180 align = TREE_INT_CST_LOW (x);
181 if (align == -1)
182 action = set;
184 else
185 GCC_BAD_ACTION;
188 if (token != CPP_CLOSE_PAREN)
189 GCC_BAD_ACTION;
190 #undef GCC_BAD_ACTION
192 else
193 GCC_BAD ("malformed %<#pragma pack%> - ignored");
195 if (pragma_lex (&x) != CPP_EOF)
196 warning (OPT_Wpragmas, "junk at end of %<#pragma pack%>");
198 if (flag_pack_struct)
199 GCC_BAD ("#pragma pack has no effect with -fpack-struct - ignored");
201 if (action != pop)
202 switch (align)
204 case 0:
205 case 1:
206 case 2:
207 case 4:
208 case 8:
209 case 16:
210 align *= BITS_PER_UNIT;
211 break;
212 case -1:
213 if (action == push)
215 align = maximum_field_alignment;
216 break;
218 /* FALLTHRU */
219 default:
220 GCC_BAD2 ("alignment must be a small power of two, not %d", align);
223 switch (action)
225 case set: SET_GLOBAL_ALIGNMENT (align); break;
226 case push: push_alignment (align, id); break;
227 case pop: pop_alignment (id); break;
231 struct GTY(()) pending_weak
233 tree name;
234 tree value;
238 static GTY(()) vec<pending_weak, va_gc> *pending_weaks;
240 static void apply_pragma_weak (tree, tree);
241 static void handle_pragma_weak (cpp_reader *);
243 static void
244 apply_pragma_weak (tree decl, tree value)
246 if (value)
248 value = build_string (IDENTIFIER_LENGTH (value),
249 IDENTIFIER_POINTER (value));
250 decl_attributes (&decl, build_tree_list (get_identifier ("alias"),
251 build_tree_list (NULL, value)),
255 if (SUPPORTS_WEAK && DECL_EXTERNAL (decl) && TREE_USED (decl)
256 && !DECL_WEAK (decl) /* Don't complain about a redundant #pragma. */
257 && DECL_ASSEMBLER_NAME_SET_P (decl)
258 && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
259 warning (OPT_Wpragmas, "applying #pragma weak %q+D after first use "
260 "results in unspecified behavior", decl);
262 declare_weak (decl);
265 void
266 maybe_apply_pragma_weak (tree decl)
268 tree id;
269 int i;
270 pending_weak *pe;
272 /* Avoid asking for DECL_ASSEMBLER_NAME when it's not needed. */
274 /* No weak symbols pending, take the short-cut. */
275 if (vec_safe_is_empty (pending_weaks))
276 return;
277 /* If it's not visible outside this file, it doesn't matter whether
278 it's weak. */
279 if (!DECL_EXTERNAL (decl) && !TREE_PUBLIC (decl))
280 return;
281 /* If it's not a function or a variable, it can't be weak.
282 FIXME: what kinds of things are visible outside this file but
283 aren't functions or variables? Should this be an assert instead? */
284 if (!VAR_OR_FUNCTION_DECL_P (decl))
285 return;
287 if (DECL_ASSEMBLER_NAME_SET_P (decl))
288 id = DECL_ASSEMBLER_NAME (decl);
289 else
291 id = DECL_ASSEMBLER_NAME (decl);
292 SET_DECL_ASSEMBLER_NAME (decl, NULL_TREE);
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 (vec_safe_is_empty (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::get_for_asmname (id);
326 decl = build_decl (UNKNOWN_LOCATION,
327 target ? TREE_CODE (target->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 (VAR_P (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 if (!VAR_OR_FUNCTION_DECL_P (decl))
371 GCC_BAD2 ("%<#pragma weak%> declaration of %q+D not allowed,"
372 " ignored", decl);
373 apply_pragma_weak (decl, value);
374 if (value)
376 DECL_EXTERNAL (decl) = 0;
377 if (VAR_P (decl))
378 TREE_STATIC (decl) = 1;
379 assemble_alias (decl, value);
382 else
384 pending_weak pe = {name, value};
385 vec_safe_push (pending_weaks, pe);
389 static enum scalar_storage_order_kind global_sso;
391 void
392 maybe_apply_pragma_scalar_storage_order (tree type)
394 if (global_sso == SSO_NATIVE)
395 return;
397 gcc_assert (RECORD_OR_UNION_TYPE_P (type));
399 if (lookup_attribute ("scalar_storage_order", TYPE_ATTRIBUTES (type)))
400 return;
402 if (global_sso == SSO_BIG_ENDIAN)
403 TYPE_REVERSE_STORAGE_ORDER (type) = !BYTES_BIG_ENDIAN;
404 else if (global_sso == SSO_LITTLE_ENDIAN)
405 TYPE_REVERSE_STORAGE_ORDER (type) = BYTES_BIG_ENDIAN;
406 else
407 gcc_unreachable ();
410 static void
411 handle_pragma_scalar_storage_order (cpp_reader *ARG_UNUSED(dummy))
413 const char *kind_string;
414 enum cpp_ttype token;
415 tree x;
417 if (BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN)
419 error ("scalar_storage_order is not supported because endianness "
420 "is not uniform");
421 return;
424 if (c_dialect_cxx ())
426 if (warn_unknown_pragmas > in_system_header_at (input_location))
427 warning (OPT_Wunknown_pragmas,
428 "%<#pragma scalar_storage_order%> is not supported for C++");
429 return;
432 token = pragma_lex (&x);
433 if (token != CPP_NAME)
434 GCC_BAD ("missing [big-endian|little-endian|default] after %<#pragma scalar_storage_order%>");
435 kind_string = IDENTIFIER_POINTER (x);
436 if (strcmp (kind_string, "default") == 0)
437 global_sso = default_sso;
438 else if (strcmp (kind_string, "big") == 0)
439 global_sso = SSO_BIG_ENDIAN;
440 else if (strcmp (kind_string, "little") == 0)
441 global_sso = SSO_LITTLE_ENDIAN;
442 else
443 GCC_BAD ("expected [big-endian|little-endian|default] after %<#pragma scalar_storage_order%>");
446 /* GCC supports two #pragma directives for renaming the external
447 symbol associated with a declaration (DECL_ASSEMBLER_NAME), for
448 compatibility with the Solaris and VMS system headers. GCC also
449 has its own notation for this, __asm__("name") annotations.
451 Corner cases of these features and their interaction:
453 1) Both pragmas silently apply only to declarations with external
454 linkage (that is, TREE_PUBLIC || DECL_EXTERNAL). Asm labels
455 do not have this restriction.
457 2) In C++, both #pragmas silently apply only to extern "C" declarations.
458 Asm labels do not have this restriction.
460 3) If any of the three ways of changing DECL_ASSEMBLER_NAME is
461 applied to a decl whose DECL_ASSEMBLER_NAME is already set, and the
462 new name is different, a warning issues and the name does not change.
464 4) The "source name" for #pragma redefine_extname is the DECL_NAME,
465 *not* the DECL_ASSEMBLER_NAME.
467 5) If #pragma extern_prefix is in effect and a declaration occurs
468 with an __asm__ name, the #pragma extern_prefix is silently
469 ignored for that declaration.
471 6) If #pragma extern_prefix and #pragma redefine_extname apply to
472 the same declaration, whichever triggered first wins, and a warning
473 is issued. (We would like to have #pragma redefine_extname always
474 win, but it can appear either before or after the declaration, and
475 if it appears afterward, we have no way of knowing whether a modified
476 DECL_ASSEMBLER_NAME is due to #pragma extern_prefix.) */
478 struct GTY(()) pending_redefinition {
479 tree oldname;
480 tree newname;
484 static GTY(()) vec<pending_redefinition, va_gc> *pending_redefine_extname;
486 static void handle_pragma_redefine_extname (cpp_reader *);
488 /* #pragma redefine_extname oldname newname */
489 static void
490 handle_pragma_redefine_extname (cpp_reader * ARG_UNUSED (dummy))
492 tree oldname, newname, decls, x;
493 enum cpp_ttype t;
494 bool found;
496 if (pragma_lex (&oldname) != CPP_NAME)
497 GCC_BAD ("malformed #pragma redefine_extname, ignored");
498 if (pragma_lex (&newname) != CPP_NAME)
499 GCC_BAD ("malformed #pragma redefine_extname, ignored");
500 t = pragma_lex (&x);
501 if (t != CPP_EOF)
502 warning (OPT_Wpragmas, "junk at end of %<#pragma redefine_extname%>");
504 found = false;
505 for (decls = c_linkage_bindings (oldname);
506 decls; )
508 tree decl;
509 if (TREE_CODE (decls) == TREE_LIST)
511 decl = TREE_VALUE (decls);
512 decls = TREE_CHAIN (decls);
514 else
516 decl = decls;
517 decls = NULL_TREE;
520 if ((TREE_PUBLIC (decl) || DECL_EXTERNAL (decl))
521 && VAR_OR_FUNCTION_DECL_P (decl))
523 found = true;
524 if (DECL_ASSEMBLER_NAME_SET_P (decl))
526 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
527 name = targetm.strip_name_encoding (name);
529 if (!id_equal (newname, name))
530 warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
531 "conflict with previous rename");
533 else
534 symtab->change_decl_assembler_name (decl, newname);
538 if (!found)
539 /* We have to add this to the rename list even if there's already
540 a global value that doesn't meet the above criteria, because in
541 C++ "struct foo {...};" puts "foo" in the current namespace but
542 does *not* conflict with a subsequent declaration of a function
543 or variable foo. See g++.dg/other/pragma-re-2.C. */
544 add_to_renaming_pragma_list (oldname, newname);
547 /* This is called from here and from ia64-c.c. */
548 void
549 add_to_renaming_pragma_list (tree oldname, tree newname)
551 unsigned ix;
552 pending_redefinition *p;
554 FOR_EACH_VEC_SAFE_ELT (pending_redefine_extname, ix, p)
555 if (oldname == p->oldname)
557 if (p->newname != newname)
558 warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
559 "conflict with previous #pragma redefine_extname");
560 return;
563 pending_redefinition e = {oldname, newname};
564 vec_safe_push (pending_redefine_extname, e);
567 /* The current prefix set by #pragma extern_prefix. */
568 GTY(()) tree pragma_extern_prefix;
570 /* Hook from the front ends to apply the results of one of the preceding
571 pragmas that rename variables. */
573 tree
574 maybe_apply_renaming_pragma (tree decl, tree asmname)
576 unsigned ix;
577 pending_redefinition *p;
579 /* The renaming pragmas are only applied to declarations with
580 external linkage. */
581 if (!VAR_OR_FUNCTION_DECL_P (decl)
582 || (!TREE_PUBLIC (decl) && !DECL_EXTERNAL (decl))
583 || !has_c_linkage (decl))
584 return asmname;
586 /* If the DECL_ASSEMBLER_NAME is already set, it does not change,
587 but we may warn about a rename that conflicts. */
588 if (DECL_ASSEMBLER_NAME_SET_P (decl))
590 const char *oldname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
591 oldname = targetm.strip_name_encoding (oldname);
593 if (asmname && strcmp (TREE_STRING_POINTER (asmname), oldname))
594 warning (OPT_Wpragmas, "asm declaration ignored due to "
595 "conflict with previous rename");
597 /* Take any pending redefine_extname off the list. */
598 FOR_EACH_VEC_SAFE_ELT (pending_redefine_extname, ix, p)
599 if (DECL_NAME (decl) == p->oldname)
601 /* Only warn if there is a conflict. */
602 if (!id_equal (p->newname, oldname))
603 warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
604 "conflict with previous rename");
606 pending_redefine_extname->unordered_remove (ix);
607 break;
609 return NULL_TREE;
612 /* Find out if we have a pending #pragma redefine_extname. */
613 FOR_EACH_VEC_SAFE_ELT (pending_redefine_extname, ix, p)
614 if (DECL_NAME (decl) == p->oldname)
616 tree newname = p->newname;
617 pending_redefine_extname->unordered_remove (ix);
619 /* If we already have an asmname, #pragma redefine_extname is
620 ignored (with a warning if it conflicts). */
621 if (asmname)
623 if (strcmp (TREE_STRING_POINTER (asmname),
624 IDENTIFIER_POINTER (newname)) != 0)
625 warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
626 "conflict with __asm__ declaration");
627 return asmname;
630 /* Otherwise we use what we've got; #pragma extern_prefix is
631 silently ignored. */
632 return build_string (IDENTIFIER_LENGTH (newname),
633 IDENTIFIER_POINTER (newname));
636 /* If we've got an asmname, #pragma extern_prefix is silently ignored. */
637 if (asmname)
638 return asmname;
640 /* If #pragma extern_prefix is in effect, apply it. */
641 if (pragma_extern_prefix)
643 const char *prefix = TREE_STRING_POINTER (pragma_extern_prefix);
644 size_t plen = TREE_STRING_LENGTH (pragma_extern_prefix) - 1;
646 const char *id = IDENTIFIER_POINTER (DECL_NAME (decl));
647 size_t ilen = IDENTIFIER_LENGTH (DECL_NAME (decl));
649 char *newname = (char *) alloca (plen + ilen + 1);
651 memcpy (newname, prefix, plen);
652 memcpy (newname + plen, id, ilen + 1);
654 return build_string (plen + ilen, newname);
657 /* Nada. */
658 return NULL_TREE;
662 static void handle_pragma_visibility (cpp_reader *);
664 static vec<int> visstack;
666 /* Push the visibility indicated by STR onto the top of the #pragma
667 visibility stack. KIND is 0 for #pragma GCC visibility, 1 for
668 C++ namespace with visibility attribute and 2 for C++ builtin
669 ABI namespace. push_visibility/pop_visibility calls must have
670 matching KIND, it is not allowed to push visibility using one
671 KIND and pop using a different one. */
673 void
674 push_visibility (const char *str, int kind)
676 visstack.safe_push (((int) default_visibility) | (kind << 8));
677 if (!strcmp (str, "default"))
678 default_visibility = VISIBILITY_DEFAULT;
679 else if (!strcmp (str, "internal"))
680 default_visibility = VISIBILITY_INTERNAL;
681 else if (!strcmp (str, "hidden"))
682 default_visibility = VISIBILITY_HIDDEN;
683 else if (!strcmp (str, "protected"))
684 default_visibility = VISIBILITY_PROTECTED;
685 else
686 GCC_BAD ("#pragma GCC visibility push() must specify default, internal, hidden or protected");
687 visibility_options.inpragma = 1;
690 /* Pop a level of the #pragma visibility stack. Return true if
691 successful. */
693 bool
694 pop_visibility (int kind)
696 if (!visstack.length ())
697 return false;
698 if ((visstack.last () >> 8) != kind)
699 return false;
700 default_visibility
701 = (enum symbol_visibility) (visstack.pop () & 0xff);
702 visibility_options.inpragma
703 = visstack.length () != 0;
704 return true;
707 /* Sets the default visibility for symbols to something other than that
708 specified on the command line. */
710 static void
711 handle_pragma_visibility (cpp_reader *dummy ATTRIBUTE_UNUSED)
713 /* Form is #pragma GCC visibility push(hidden)|pop */
714 tree x;
715 enum cpp_ttype token;
716 enum { bad, push, pop } action = bad;
718 token = pragma_lex (&x);
719 if (token == CPP_NAME)
721 const char *op = IDENTIFIER_POINTER (x);
722 if (!strcmp (op, "push"))
723 action = push;
724 else if (!strcmp (op, "pop"))
725 action = pop;
727 if (bad == action)
728 GCC_BAD ("#pragma GCC visibility must be followed by push or pop");
729 else
731 if (pop == action)
733 if (! pop_visibility (0))
734 GCC_BAD ("no matching push for %<#pragma GCC visibility pop%>");
736 else
738 if (pragma_lex (&x) != CPP_OPEN_PAREN)
739 GCC_BAD ("missing %<(%> after %<#pragma GCC visibility push%> - ignored");
740 token = pragma_lex (&x);
741 if (token != CPP_NAME)
742 GCC_BAD ("malformed #pragma GCC visibility push");
743 else
744 push_visibility (IDENTIFIER_POINTER (x), 0);
745 if (pragma_lex (&x) != CPP_CLOSE_PAREN)
746 GCC_BAD ("missing %<(%> after %<#pragma GCC visibility push%> - ignored");
749 if (pragma_lex (&x) != CPP_EOF)
750 warning (OPT_Wpragmas, "junk at end of %<#pragma GCC visibility%>");
753 static void
754 handle_pragma_diagnostic(cpp_reader *ARG_UNUSED(dummy))
756 tree x;
757 location_t loc;
758 enum cpp_ttype token = pragma_lex (&x, &loc);
759 if (token != CPP_NAME)
761 warning_at (loc, OPT_Wpragmas,
762 "missing [error|warning|ignored|push|pop]"
763 " after %<#pragma GCC diagnostic%>");
764 return;
767 diagnostic_t kind;
768 const char *kind_string = IDENTIFIER_POINTER (x);
769 if (strcmp (kind_string, "error") == 0)
770 kind = DK_ERROR;
771 else if (strcmp (kind_string, "warning") == 0)
772 kind = DK_WARNING;
773 else if (strcmp (kind_string, "ignored") == 0)
774 kind = DK_IGNORED;
775 else if (strcmp (kind_string, "push") == 0)
777 diagnostic_push_diagnostics (global_dc, input_location);
778 return;
780 else if (strcmp (kind_string, "pop") == 0)
782 diagnostic_pop_diagnostics (global_dc, input_location);
783 return;
785 else
787 warning_at (loc, OPT_Wpragmas,
788 "expected [error|warning|ignored|push|pop]"
789 " after %<#pragma GCC diagnostic%>");
790 return;
793 token = pragma_lex (&x, &loc);
794 if (token != CPP_STRING)
796 warning_at (loc, OPT_Wpragmas,
797 "missing option after %<#pragma GCC diagnostic%> kind");
798 return;
801 const char *option_string = TREE_STRING_POINTER (x);
802 unsigned int lang_mask = c_common_option_lang_mask () | CL_COMMON;
803 /* option_string + 1 to skip the initial '-' */
804 unsigned int option_index = find_opt (option_string + 1, lang_mask);
805 if (option_index == OPT_SPECIAL_unknown)
807 warning_at (loc, OPT_Wpragmas,
808 "unknown option after %<#pragma GCC diagnostic%> kind");
809 return;
811 else if (!(cl_options[option_index].flags & CL_WARNING))
813 warning_at (loc, OPT_Wpragmas,
814 "%qs is not an option that controls warnings", option_string);
815 return;
817 else if (!(cl_options[option_index].flags & lang_mask))
819 char *ok_langs = write_langs (cl_options[option_index].flags);
820 char *bad_lang = write_langs (c_common_option_lang_mask ());
821 warning_at (loc, OPT_Wpragmas,
822 "option %qs is valid for %s but not for %s",
823 option_string, ok_langs, bad_lang);
824 free (ok_langs);
825 free (bad_lang);
826 return;
829 struct cl_option_handlers handlers;
830 set_default_handlers (&handlers, NULL);
831 const char *arg = NULL;
832 if (cl_options[option_index].flags & CL_JOINED)
833 arg = option_string + 1 + cl_options[option_index].opt_len;
834 /* FIXME: input_location isn't the best location here, but it is
835 what we used to do here before and changing it breaks e.g.
836 PR69543 and PR69558. */
837 control_warning_option (option_index, (int) kind,
838 arg, kind != DK_IGNORED,
839 input_location, lang_mask, &handlers,
840 &global_options, &global_options_set,
841 global_dc);
844 /* Parse #pragma GCC target (xxx) to set target specific options. */
845 static void
846 handle_pragma_target(cpp_reader *ARG_UNUSED(dummy))
848 enum cpp_ttype token;
849 tree x;
850 bool close_paren_needed_p = false;
852 if (cfun)
854 error ("#pragma GCC option is not allowed inside functions");
855 return;
858 token = pragma_lex (&x);
859 if (token == CPP_OPEN_PAREN)
861 close_paren_needed_p = true;
862 token = pragma_lex (&x);
865 if (token != CPP_STRING)
867 GCC_BAD ("%<#pragma GCC option%> is not a string");
868 return;
871 /* Strings are user options. */
872 else
874 tree args = NULL_TREE;
878 /* Build up the strings now as a tree linked list. Skip empty
879 strings. */
880 if (TREE_STRING_LENGTH (x) > 0)
881 args = tree_cons (NULL_TREE, x, args);
883 token = pragma_lex (&x);
884 while (token == CPP_COMMA)
885 token = pragma_lex (&x);
887 while (token == CPP_STRING);
889 if (close_paren_needed_p)
891 if (token == CPP_CLOSE_PAREN)
892 token = pragma_lex (&x);
893 else
894 GCC_BAD ("%<#pragma GCC target (string [,string]...)%> does "
895 "not have a final %<)%>");
898 if (token != CPP_EOF)
900 error ("#pragma GCC target string... is badly formed");
901 return;
904 /* put arguments in the order the user typed them. */
905 args = nreverse (args);
907 if (targetm.target_option.pragma_parse (args, NULL_TREE))
908 current_target_pragma = chainon (current_target_pragma, args);
912 /* Handle #pragma GCC optimize to set optimization options. */
913 static void
914 handle_pragma_optimize (cpp_reader *ARG_UNUSED(dummy))
916 enum cpp_ttype token;
917 tree x;
918 bool close_paren_needed_p = false;
919 tree optimization_previous_node = optimization_current_node;
921 if (cfun)
923 error ("#pragma GCC optimize is not allowed inside functions");
924 return;
927 token = pragma_lex (&x);
928 if (token == CPP_OPEN_PAREN)
930 close_paren_needed_p = true;
931 token = pragma_lex (&x);
934 if (token != CPP_STRING && token != CPP_NUMBER)
936 GCC_BAD ("%<#pragma GCC optimize%> is not a string or number");
937 return;
940 /* Strings/numbers are user options. */
941 else
943 tree args = NULL_TREE;
947 /* Build up the numbers/strings now as a list. */
948 if (token != CPP_STRING || TREE_STRING_LENGTH (x) > 0)
949 args = tree_cons (NULL_TREE, x, args);
951 token = pragma_lex (&x);
952 while (token == CPP_COMMA)
953 token = pragma_lex (&x);
955 while (token == CPP_STRING || token == CPP_NUMBER);
957 if (close_paren_needed_p)
959 if (token == CPP_CLOSE_PAREN)
960 token = pragma_lex (&x);
961 else
962 GCC_BAD ("%<#pragma GCC optimize (string [,string]...)%> does "
963 "not have a final %<)%>");
966 if (token != CPP_EOF)
968 error ("#pragma GCC optimize string... is badly formed");
969 return;
972 /* put arguments in the order the user typed them. */
973 args = nreverse (args);
975 parse_optimize_options (args, false);
976 current_optimize_pragma = chainon (current_optimize_pragma, args);
977 optimization_current_node = build_optimization_node (&global_options);
978 c_cpp_builtins_optimize_pragma (parse_in,
979 optimization_previous_node,
980 optimization_current_node);
984 /* Stack of the #pragma GCC options created with #pragma GCC push_option. Save
985 both the binary representation of the options and the TREE_LIST of
986 strings that will be added to the function's attribute list. */
987 struct GTY(()) opt_stack {
988 struct opt_stack *prev;
989 tree target_binary;
990 tree target_strings;
991 tree optimize_binary;
992 tree optimize_strings;
995 static GTY(()) struct opt_stack * options_stack;
997 /* Handle #pragma GCC push_options to save the current target and optimization
998 options. */
1000 static void
1001 handle_pragma_push_options (cpp_reader *ARG_UNUSED(dummy))
1003 enum cpp_ttype token;
1004 tree x = 0;
1006 token = pragma_lex (&x);
1007 if (token != CPP_EOF)
1009 warning (OPT_Wpragmas, "junk at end of %<#pragma push_options%>");
1010 return;
1013 opt_stack *p = ggc_alloc<opt_stack> ();
1014 p->prev = options_stack;
1015 options_stack = p;
1017 /* Save optimization and target flags in binary format. */
1018 p->optimize_binary = build_optimization_node (&global_options);
1019 p->target_binary = build_target_option_node (&global_options);
1021 /* Save optimization and target flags in string list format. */
1022 p->optimize_strings = copy_list (current_optimize_pragma);
1023 p->target_strings = copy_list (current_target_pragma);
1026 /* Handle #pragma GCC pop_options to restore the current target and
1027 optimization options from a previous push_options. */
1029 static void
1030 handle_pragma_pop_options (cpp_reader *ARG_UNUSED(dummy))
1032 enum cpp_ttype token;
1033 tree x = 0;
1034 opt_stack *p;
1036 token = pragma_lex (&x);
1037 if (token != CPP_EOF)
1039 warning (OPT_Wpragmas, "junk at end of %<#pragma pop_options%>");
1040 return;
1043 if (! options_stack)
1045 warning (OPT_Wpragmas,
1046 "%<#pragma GCC pop_options%> without a corresponding "
1047 "%<#pragma GCC push_options%>");
1048 return;
1051 p = options_stack;
1052 options_stack = p->prev;
1054 if (p->target_binary != target_option_current_node)
1056 (void) targetm.target_option.pragma_parse (NULL_TREE, p->target_binary);
1057 target_option_current_node = p->target_binary;
1060 if (p->optimize_binary != optimization_current_node)
1062 tree old_optimize = optimization_current_node;
1063 cl_optimization_restore (&global_options,
1064 TREE_OPTIMIZATION (p->optimize_binary));
1065 c_cpp_builtins_optimize_pragma (parse_in, old_optimize,
1066 p->optimize_binary);
1067 optimization_current_node = p->optimize_binary;
1070 current_target_pragma = p->target_strings;
1071 current_optimize_pragma = p->optimize_strings;
1074 /* Handle #pragma GCC reset_options to restore the current target and
1075 optimization options to the original options used on the command line. */
1077 static void
1078 handle_pragma_reset_options (cpp_reader *ARG_UNUSED(dummy))
1080 enum cpp_ttype token;
1081 tree x = 0;
1082 tree new_optimize = optimization_default_node;
1083 tree new_target = target_option_default_node;
1085 token = pragma_lex (&x);
1086 if (token != CPP_EOF)
1088 warning (OPT_Wpragmas, "junk at end of %<#pragma reset_options%>");
1089 return;
1092 if (new_target != target_option_current_node)
1094 (void) targetm.target_option.pragma_parse (NULL_TREE, new_target);
1095 target_option_current_node = new_target;
1098 if (new_optimize != optimization_current_node)
1100 tree old_optimize = optimization_current_node;
1101 cl_optimization_restore (&global_options,
1102 TREE_OPTIMIZATION (new_optimize));
1103 c_cpp_builtins_optimize_pragma (parse_in, old_optimize, new_optimize);
1104 optimization_current_node = new_optimize;
1107 current_target_pragma = NULL_TREE;
1108 current_optimize_pragma = NULL_TREE;
1111 /* Print a plain user-specified message. */
1113 static void
1114 handle_pragma_message (cpp_reader *ARG_UNUSED(dummy))
1116 enum cpp_ttype token;
1117 tree x, message = 0;
1119 token = pragma_lex (&x);
1120 if (token == CPP_OPEN_PAREN)
1122 token = pragma_lex (&x);
1123 if (token == CPP_STRING)
1124 message = x;
1125 else
1126 GCC_BAD ("expected a string after %<#pragma message%>");
1127 if (pragma_lex (&x) != CPP_CLOSE_PAREN)
1128 GCC_BAD ("malformed %<#pragma message%>, ignored");
1130 else if (token == CPP_STRING)
1131 message = x;
1132 else
1133 GCC_BAD ("expected a string after %<#pragma message%>");
1135 gcc_assert (message);
1137 if (pragma_lex (&x) != CPP_EOF)
1138 warning (OPT_Wpragmas, "junk at end of %<#pragma message%>");
1140 if (TREE_STRING_LENGTH (message) > 1)
1141 inform (input_location, "#pragma message: %s", TREE_STRING_POINTER (message));
1144 /* Mark whether the current location is valid for a STDC pragma. */
1146 static bool valid_location_for_stdc_pragma;
1148 void
1149 mark_valid_location_for_stdc_pragma (bool flag)
1151 valid_location_for_stdc_pragma = flag;
1154 /* Return true if the current location is valid for a STDC pragma. */
1156 bool
1157 valid_location_for_stdc_pragma_p (void)
1159 return valid_location_for_stdc_pragma;
1162 enum pragma_switch_t { PRAGMA_ON, PRAGMA_OFF, PRAGMA_DEFAULT, PRAGMA_BAD };
1164 /* A STDC pragma must appear outside of external declarations or
1165 preceding all explicit declarations and statements inside a compound
1166 statement; its behavior is undefined if used in any other context.
1167 It takes a switch of ON, OFF, or DEFAULT. */
1169 static enum pragma_switch_t
1170 handle_stdc_pragma (const char *pname)
1172 const char *arg;
1173 tree t;
1174 enum pragma_switch_t ret;
1176 if (!valid_location_for_stdc_pragma_p ())
1178 warning (OPT_Wpragmas, "invalid location for %<pragma %s%>, ignored",
1179 pname);
1180 return PRAGMA_BAD;
1183 if (pragma_lex (&t) != CPP_NAME)
1185 warning (OPT_Wpragmas, "malformed %<#pragma %s%>, ignored", pname);
1186 return PRAGMA_BAD;
1189 arg = IDENTIFIER_POINTER (t);
1191 if (!strcmp (arg, "ON"))
1192 ret = PRAGMA_ON;
1193 else if (!strcmp (arg, "OFF"))
1194 ret = PRAGMA_OFF;
1195 else if (!strcmp (arg, "DEFAULT"))
1196 ret = PRAGMA_DEFAULT;
1197 else
1199 warning (OPT_Wpragmas, "malformed %<#pragma %s%>, ignored", pname);
1200 return PRAGMA_BAD;
1203 if (pragma_lex (&t) != CPP_EOF)
1205 warning (OPT_Wpragmas, "junk at end of %<#pragma %s%>", pname);
1206 return PRAGMA_BAD;
1209 return ret;
1212 /* #pragma STDC FLOAT_CONST_DECIMAL64 ON
1213 #pragma STDC FLOAT_CONST_DECIMAL64 OFF
1214 #pragma STDC FLOAT_CONST_DECIMAL64 DEFAULT */
1216 static void
1217 handle_pragma_float_const_decimal64 (cpp_reader *ARG_UNUSED (dummy))
1219 if (c_dialect_cxx ())
1221 if (warn_unknown_pragmas > in_system_header_at (input_location))
1222 warning (OPT_Wunknown_pragmas,
1223 "%<#pragma STDC FLOAT_CONST_DECIMAL64%> is not supported"
1224 " for C++");
1225 return;
1228 if (!targetm.decimal_float_supported_p ())
1230 if (warn_unknown_pragmas > in_system_header_at (input_location))
1231 warning (OPT_Wunknown_pragmas,
1232 "%<#pragma STDC FLOAT_CONST_DECIMAL64%> is not supported"
1233 " on this target");
1234 return;
1237 pedwarn (input_location, OPT_Wpedantic,
1238 "ISO C does not support %<#pragma STDC FLOAT_CONST_DECIMAL64%>");
1240 switch (handle_stdc_pragma ("STDC FLOAT_CONST_DECIMAL64"))
1242 case PRAGMA_ON:
1243 set_float_const_decimal64 ();
1244 break;
1245 case PRAGMA_OFF:
1246 case PRAGMA_DEFAULT:
1247 clear_float_const_decimal64 ();
1248 break;
1249 case PRAGMA_BAD:
1250 break;
1254 /* A vector of registered pragma callbacks, which is never freed. */
1256 static vec<internal_pragma_handler> registered_pragmas;
1258 struct pragma_ns_name
1260 const char *space;
1261 const char *name;
1265 static vec<pragma_ns_name> registered_pp_pragmas;
1267 struct omp_pragma_def { const char *name; unsigned int id; };
1268 static const struct omp_pragma_def oacc_pragmas[] = {
1269 { "atomic", PRAGMA_OACC_ATOMIC },
1270 { "cache", PRAGMA_OACC_CACHE },
1271 { "data", PRAGMA_OACC_DATA },
1272 { "declare", PRAGMA_OACC_DECLARE },
1273 { "enter", PRAGMA_OACC_ENTER_DATA },
1274 { "exit", PRAGMA_OACC_EXIT_DATA },
1275 { "host_data", PRAGMA_OACC_HOST_DATA },
1276 { "kernels", PRAGMA_OACC_KERNELS },
1277 { "loop", PRAGMA_OACC_LOOP },
1278 { "parallel", PRAGMA_OACC_PARALLEL },
1279 { "routine", PRAGMA_OACC_ROUTINE },
1280 { "update", PRAGMA_OACC_UPDATE },
1281 { "wait", PRAGMA_OACC_WAIT }
1283 static const struct omp_pragma_def omp_pragmas[] = {
1284 { "atomic", PRAGMA_OMP_ATOMIC },
1285 { "barrier", PRAGMA_OMP_BARRIER },
1286 { "cancel", PRAGMA_OMP_CANCEL },
1287 { "cancellation", PRAGMA_OMP_CANCELLATION_POINT },
1288 { "critical", PRAGMA_OMP_CRITICAL },
1289 { "end", PRAGMA_OMP_END_DECLARE_TARGET },
1290 { "flush", PRAGMA_OMP_FLUSH },
1291 { "master", PRAGMA_OMP_MASTER },
1292 { "section", PRAGMA_OMP_SECTION },
1293 { "sections", PRAGMA_OMP_SECTIONS },
1294 { "single", PRAGMA_OMP_SINGLE },
1295 { "task", PRAGMA_OMP_TASK },
1296 { "taskgroup", PRAGMA_OMP_TASKGROUP },
1297 { "taskwait", PRAGMA_OMP_TASKWAIT },
1298 { "taskyield", PRAGMA_OMP_TASKYIELD },
1299 { "threadprivate", PRAGMA_OMP_THREADPRIVATE }
1301 static const struct omp_pragma_def omp_pragmas_simd[] = {
1302 { "declare", PRAGMA_OMP_DECLARE },
1303 { "distribute", PRAGMA_OMP_DISTRIBUTE },
1304 { "for", PRAGMA_OMP_FOR },
1305 { "ordered", PRAGMA_OMP_ORDERED },
1306 { "parallel", PRAGMA_OMP_PARALLEL },
1307 { "simd", PRAGMA_OMP_SIMD },
1308 { "target", PRAGMA_OMP_TARGET },
1309 { "taskloop", PRAGMA_OMP_TASKLOOP },
1310 { "teams", PRAGMA_OMP_TEAMS },
1313 void
1314 c_pp_lookup_pragma (unsigned int id, const char **space, const char **name)
1316 const int n_oacc_pragmas = sizeof (oacc_pragmas) / sizeof (*oacc_pragmas);
1317 const int n_omp_pragmas = sizeof (omp_pragmas) / sizeof (*omp_pragmas);
1318 const int n_omp_pragmas_simd = sizeof (omp_pragmas_simd)
1319 / sizeof (*omp_pragmas);
1320 int i;
1322 for (i = 0; i < n_oacc_pragmas; ++i)
1323 if (oacc_pragmas[i].id == id)
1325 *space = "acc";
1326 *name = oacc_pragmas[i].name;
1327 return;
1330 for (i = 0; i < n_omp_pragmas; ++i)
1331 if (omp_pragmas[i].id == id)
1333 *space = "omp";
1334 *name = omp_pragmas[i].name;
1335 return;
1338 for (i = 0; i < n_omp_pragmas_simd; ++i)
1339 if (omp_pragmas_simd[i].id == id)
1341 *space = "omp";
1342 *name = omp_pragmas_simd[i].name;
1343 return;
1346 if (id == PRAGMA_CILK_SIMD)
1348 *space = NULL;
1349 *name = "simd";
1350 return;
1353 if (id == PRAGMA_CILK_GRAINSIZE)
1355 *space = "cilk";
1356 *name = "grainsize";
1357 return;
1360 if (id >= PRAGMA_FIRST_EXTERNAL
1361 && (id < PRAGMA_FIRST_EXTERNAL + registered_pp_pragmas.length ()))
1363 *space = registered_pp_pragmas[id - PRAGMA_FIRST_EXTERNAL].space;
1364 *name = registered_pp_pragmas[id - PRAGMA_FIRST_EXTERNAL].name;
1365 return;
1368 gcc_unreachable ();
1371 /* Front-end wrappers for pragma registration to avoid dragging
1372 cpplib.h in almost everywhere. */
1374 static void
1375 c_register_pragma_1 (const char *space, const char *name,
1376 internal_pragma_handler ihandler, bool allow_expansion)
1378 unsigned id;
1380 if (flag_preprocess_only)
1382 pragma_ns_name ns_name;
1384 if (!allow_expansion)
1385 return;
1387 ns_name.space = space;
1388 ns_name.name = name;
1389 registered_pp_pragmas.safe_push (ns_name);
1390 id = registered_pp_pragmas.length ();
1391 id += PRAGMA_FIRST_EXTERNAL - 1;
1393 else
1395 registered_pragmas.safe_push (ihandler);
1396 id = registered_pragmas.length ();
1397 id += PRAGMA_FIRST_EXTERNAL - 1;
1399 /* The C front end allocates 8 bits in c_token. The C++ front end
1400 keeps the pragma kind in the form of INTEGER_CST, so no small
1401 limit applies. At present this is sufficient. */
1402 gcc_assert (id < 256);
1405 cpp_register_deferred_pragma (parse_in, space, name, id,
1406 allow_expansion, false);
1409 /* Register a C pragma handler, using a space and a name. It disallows pragma
1410 expansion (if you want it, use c_register_pragma_with_expansion instead). */
1411 void
1412 c_register_pragma (const char *space, const char *name,
1413 pragma_handler_1arg handler)
1415 internal_pragma_handler ihandler;
1417 ihandler.handler.handler_1arg = handler;
1418 ihandler.extra_data = false;
1419 ihandler.data = NULL;
1420 c_register_pragma_1 (space, name, ihandler, false);
1423 /* Register a C pragma handler, using a space and a name, it also carries an
1424 extra data field which can be used by the handler. It disallows pragma
1425 expansion (if you want it, use c_register_pragma_with_expansion_and_data
1426 instead). */
1427 void
1428 c_register_pragma_with_data (const char *space, const char *name,
1429 pragma_handler_2arg handler, void * data)
1431 internal_pragma_handler ihandler;
1433 ihandler.handler.handler_2arg = handler;
1434 ihandler.extra_data = true;
1435 ihandler.data = data;
1436 c_register_pragma_1 (space, name, ihandler, false);
1439 /* Register a C pragma handler, using a space and a name. It allows pragma
1440 expansion as in the following example:
1442 #define NUMBER 10
1443 #pragma count (NUMBER)
1445 Name expansion is still disallowed. */
1446 void
1447 c_register_pragma_with_expansion (const char *space, const char *name,
1448 pragma_handler_1arg handler)
1450 internal_pragma_handler ihandler;
1452 ihandler.handler.handler_1arg = handler;
1453 ihandler.extra_data = false;
1454 ihandler.data = NULL;
1455 c_register_pragma_1 (space, name, ihandler, true);
1458 /* Register a C pragma handler, using a space and a name, it also carries an
1459 extra data field which can be used by the handler. It allows pragma
1460 expansion as in the following example:
1462 #define NUMBER 10
1463 #pragma count (NUMBER)
1465 Name expansion is still disallowed. */
1466 void
1467 c_register_pragma_with_expansion_and_data (const char *space, const char *name,
1468 pragma_handler_2arg handler,
1469 void *data)
1471 internal_pragma_handler ihandler;
1473 ihandler.handler.handler_2arg = handler;
1474 ihandler.extra_data = true;
1475 ihandler.data = data;
1476 c_register_pragma_1 (space, name, ihandler, true);
1479 void
1480 c_invoke_pragma_handler (unsigned int id)
1482 internal_pragma_handler *ihandler;
1483 pragma_handler_1arg handler_1arg;
1484 pragma_handler_2arg handler_2arg;
1486 id -= PRAGMA_FIRST_EXTERNAL;
1487 ihandler = &registered_pragmas[id];
1488 if (ihandler->extra_data)
1490 handler_2arg = ihandler->handler.handler_2arg;
1491 handler_2arg (parse_in, ihandler->data);
1493 else
1495 handler_1arg = ihandler->handler.handler_1arg;
1496 handler_1arg (parse_in);
1500 /* Set up front-end pragmas. */
1501 void
1502 init_pragma (void)
1504 if (flag_openacc)
1506 const int n_oacc_pragmas
1507 = sizeof (oacc_pragmas) / sizeof (*oacc_pragmas);
1508 int i;
1510 for (i = 0; i < n_oacc_pragmas; ++i)
1511 cpp_register_deferred_pragma (parse_in, "acc", oacc_pragmas[i].name,
1512 oacc_pragmas[i].id, true, true);
1515 if (flag_openmp)
1517 const int n_omp_pragmas = sizeof (omp_pragmas) / sizeof (*omp_pragmas);
1518 int i;
1520 for (i = 0; i < n_omp_pragmas; ++i)
1521 cpp_register_deferred_pragma (parse_in, "omp", omp_pragmas[i].name,
1522 omp_pragmas[i].id, true, true);
1524 if (flag_openmp || flag_openmp_simd)
1526 const int n_omp_pragmas_simd = sizeof (omp_pragmas_simd)
1527 / sizeof (*omp_pragmas);
1528 int i;
1530 for (i = 0; i < n_omp_pragmas_simd; ++i)
1531 cpp_register_deferred_pragma (parse_in, "omp", omp_pragmas_simd[i].name,
1532 omp_pragmas_simd[i].id, true, true);
1535 if (flag_cilkplus)
1536 cpp_register_deferred_pragma (parse_in, NULL, "simd", PRAGMA_CILK_SIMD,
1537 true, false);
1539 if (!flag_preprocess_only)
1540 cpp_register_deferred_pragma (parse_in, "GCC", "pch_preprocess",
1541 PRAGMA_GCC_PCH_PREPROCESS, false, false);
1543 if (!flag_preprocess_only)
1544 cpp_register_deferred_pragma (parse_in, "GCC", "ivdep", PRAGMA_IVDEP, false,
1545 false);
1547 if (flag_cilkplus)
1548 cpp_register_deferred_pragma (parse_in, "cilk", "grainsize",
1549 PRAGMA_CILK_GRAINSIZE, true, false);
1551 #ifdef HANDLE_PRAGMA_PACK_WITH_EXPANSION
1552 c_register_pragma_with_expansion (0, "pack", handle_pragma_pack);
1553 #else
1554 c_register_pragma (0, "pack", handle_pragma_pack);
1555 #endif
1556 c_register_pragma (0, "weak", handle_pragma_weak);
1558 c_register_pragma ("GCC", "visibility", handle_pragma_visibility);
1560 c_register_pragma ("GCC", "diagnostic", handle_pragma_diagnostic);
1561 c_register_pragma ("GCC", "target", handle_pragma_target);
1562 c_register_pragma ("GCC", "optimize", handle_pragma_optimize);
1563 c_register_pragma ("GCC", "push_options", handle_pragma_push_options);
1564 c_register_pragma ("GCC", "pop_options", handle_pragma_pop_options);
1565 c_register_pragma ("GCC", "reset_options", handle_pragma_reset_options);
1567 c_register_pragma ("STDC", "FLOAT_CONST_DECIMAL64",
1568 handle_pragma_float_const_decimal64);
1570 c_register_pragma_with_expansion (0, "redefine_extname",
1571 handle_pragma_redefine_extname);
1573 c_register_pragma_with_expansion (0, "message", handle_pragma_message);
1575 #ifdef REGISTER_TARGET_PRAGMAS
1576 REGISTER_TARGET_PRAGMAS ();
1577 #endif
1579 global_sso = default_sso;
1580 c_register_pragma (0, "scalar_storage_order",
1581 handle_pragma_scalar_storage_order);
1583 /* Allow plugins to register their own pragmas. */
1584 invoke_plugin_callbacks (PLUGIN_PRAGMAS, NULL);
1587 #include "gt-c-family-c-pragma.h"