Hackfix and re-enable strtoull and wcstoull, see bug #3798.
[sdcc.git] / sdcc / support / cpp / gcc / c-family / c-pragma.cc
blobfc9a91323eb2db2240981370751cd027cbd41093
1 /* Handle #pragma, system V.4 style. Supports #pragma weak and #pragma pack.
2 Copyright (C) 1992-2022 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"
36 #include "opt-suggestions.h"
38 #define GCC_BAD(gmsgid) \
39 do { warning (OPT_Wpragmas, gmsgid); return; } while (0)
40 #define GCC_BAD2(gmsgid, arg) \
41 do { warning (OPT_Wpragmas, gmsgid, arg); return; } while (0)
42 #define GCC_BAD_AT(loc, gmsgid) \
43 do { warning_at (loc, OPT_Wpragmas, gmsgid); return; } while (0)
44 #define GCC_BAD2_AT(loc, gmsgid, arg) \
45 do { warning_at (loc, OPT_Wpragmas, gmsgid, arg); return; } while (0)
47 struct GTY(()) align_stack {
48 int alignment;
49 tree id;
50 struct align_stack * prev;
53 // sdcpp static GTY(()) struct align_stack * alignment_stack;
55 static void handle_pragma_pack (cpp_reader *);
57 /* If we have a "global" #pragma pack(<n>) in effect when the first
58 #pragma pack(push,<n>) is encountered, this stores the value of
59 maximum_field_alignment in effect. When the final pop_alignment()
60 happens, we restore the value to this, not to a value of 0 for
61 maximum_field_alignment. Value is in bits. */
62 #if 0 // sdcpp
63 static int default_alignment;
64 #define SET_GLOBAL_ALIGNMENT(ALIGN) (maximum_field_alignment = *(alignment_stack == NULL \
65 ? &default_alignment \
66 : &alignment_stack->alignment) = (ALIGN))
68 static void push_alignment (int, tree);
69 static void pop_alignment (tree);
71 /* Push an alignment value onto the stack. */
72 static void
73 push_alignment (int alignment, tree id)
75 align_stack * entry = ggc_alloc<align_stack> ();
77 entry->alignment = alignment;
78 entry->id = id;
79 entry->prev = alignment_stack;
81 /* The current value of maximum_field_alignment is not necessarily
82 0 since there may be a #pragma pack(<n>) in effect; remember it
83 so that we can restore it after the final #pragma pop(). */
84 if (alignment_stack == NULL)
85 default_alignment = maximum_field_alignment;
87 alignment_stack = entry;
89 maximum_field_alignment = alignment;
92 /* Undo a push of an alignment onto the stack. */
93 static void
94 pop_alignment (tree id)
96 align_stack * entry;
98 if (alignment_stack == NULL)
99 GCC_BAD ("%<#pragma pack (pop)%> encountered without matching "
100 "%<#pragma pack (push)%>");
102 /* If we got an identifier, strip away everything above the target
103 entry so that the next step will restore the state just below it. */
104 if (id)
106 for (entry = alignment_stack; entry; entry = entry->prev)
107 if (entry->id == id)
109 alignment_stack = entry;
110 break;
112 if (entry == NULL)
113 warning (OPT_Wpragmas,
114 "%<#pragma pack(pop, %E)%> encountered without matching "
115 "%<#pragma pack(push, %E)%>"
116 , id, id);
119 entry = alignment_stack->prev;
121 maximum_field_alignment = entry ? entry->alignment : default_alignment;
123 alignment_stack = entry;
125 #endif // sdcpp
127 /* #pragma pack ()
128 #pragma pack (N)
130 #pragma pack (push)
131 #pragma pack (push, N)
132 #pragma pack (push, ID)
133 #pragma pack (push, ID, N)
134 #pragma pack (pop)
135 #pragma pack (pop, ID) */
136 static void
137 handle_pragma_pack (cpp_reader *)
139 #if 0 // sdcpp
140 location_t loc;
141 tree x, id = 0;
142 int align = -1;
143 enum cpp_ttype token;
144 enum { set, push, pop } action;
146 if (pragma_lex (&x) != CPP_OPEN_PAREN)
147 GCC_BAD ("missing %<(%> after %<#pragma pack%> - ignored");
149 token = pragma_lex (&x, &loc);
150 if (token == CPP_CLOSE_PAREN)
152 action = set;
153 align = initial_max_fld_align;
155 else if (token == CPP_NUMBER)
157 if (TREE_CODE (x) != INTEGER_CST)
158 GCC_BAD_AT (loc, "invalid constant in %<#pragma pack%> - ignored");
159 align = TREE_INT_CST_LOW (x);
160 action = set;
161 if (pragma_lex (&x) != CPP_CLOSE_PAREN)
162 GCC_BAD ("malformed %<#pragma pack%> - ignored");
164 else if (token == CPP_NAME)
166 #define GCC_BAD_ACTION do { if (action != pop) \
167 GCC_BAD ("malformed %<#pragma pack(push[, id][, <n>])%> - ignored"); \
168 else \
169 GCC_BAD ("malformed %<#pragma pack(pop[, id])%> - ignored"); \
170 } while (0)
172 const char *op = IDENTIFIER_POINTER (x);
173 if (!strcmp (op, "push"))
174 action = push;
175 else if (!strcmp (op, "pop"))
176 action = pop;
177 else
178 GCC_BAD2_AT (loc, "unknown action %qE for %<#pragma pack%> - ignored",
181 while ((token = pragma_lex (&x)) == CPP_COMMA)
183 token = pragma_lex (&x, &loc);
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_AT (loc,
192 "invalid constant in %<#pragma pack%> - ignored");
193 align = TREE_INT_CST_LOW (x);
194 if (align == -1)
195 action = set;
197 else
198 GCC_BAD_ACTION;
201 if (token != CPP_CLOSE_PAREN)
202 GCC_BAD_ACTION;
203 #undef GCC_BAD_ACTION
205 else
206 GCC_BAD ("malformed %<#pragma pack%> - ignored");
208 if (pragma_lex (&x, &loc) != CPP_EOF)
209 warning_at (loc, OPT_Wpragmas, "junk at end of %<#pragma pack%>");
211 if (flag_pack_struct)
212 GCC_BAD ("%<#pragma pack%> has no effect with %<-fpack-struct%> - ignored");
214 if (action != pop)
215 switch (align)
217 case 0:
218 case 1:
219 case 2:
220 case 4:
221 case 8:
222 case 16:
223 align *= BITS_PER_UNIT;
224 break;
225 case -1:
226 if (action == push)
228 align = maximum_field_alignment;
229 break;
231 /* FALLTHRU */
232 default:
233 GCC_BAD2 ("alignment must be a small power of two, not %d", align);
236 switch (action)
238 case set: SET_GLOBAL_ALIGNMENT (align); break;
239 case push: push_alignment (align, id); break;
240 case pop: pop_alignment (id); break;
242 #endif // sdcpp
245 struct GTY(()) pending_weak
247 tree name;
248 tree value;
252 #if 0 // sdcpp
253 static GTY(()) vec<pending_weak, va_gc> *pending_weaks;
255 static void apply_pragma_weak (tree, tree);
256 static void handle_pragma_weak (cpp_reader *);
258 static void
259 apply_pragma_weak (tree decl, tree value)
261 if (value)
263 value = build_string (IDENTIFIER_LENGTH (value),
264 IDENTIFIER_POINTER (value));
265 fprintf(stderr, "apply_pragma_weak, incomplete\n");
266 // sdcpp decl_attributes (&decl, build_tree_list (get_identifier ("alias"),
267 // sdcpp build_tree_list (NULL, value)),
268 // sdcpp 0);
271 fprintf(stderr, "apply_pragma_weak2, incomplete\n");
272 // sdcpp if (SUPPORTS_WEAK && DECL_EXTERNAL (decl) && TREE_USED (decl)
273 // sdcpp && !DECL_WEAK (decl) /* Don't complain about a redundant #pragma. */
274 // sdcpp && DECL_ASSEMBLER_NAME_SET_P (decl)
275 // sdcpp && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
276 // sdcpp warning (OPT_Wpragmas, "applying %<#pragma weak %+D%> after first use "
277 // sdcpp "results in unspecified behavior", decl);
279 declare_weak (decl);
281 #endif // sdcpp
283 #if 0 // sdcpp
284 void
285 maybe_apply_pragma_weak (tree decl)
287 tree id;
288 int i;
289 pending_weak *pe;
291 /* Avoid asking for DECL_ASSEMBLER_NAME when it's not needed. */
293 /* No weak symbols pending, take the short-cut. */
294 if (vec_safe_is_empty (pending_weaks))
295 return;
296 /* If it's not visible outside this file, it doesn't matter whether
297 it's weak. */
298 if (!DECL_EXTERNAL (decl) && !TREE_PUBLIC (decl))
299 return;
300 /* If it's not a function or a variable, it can't be weak.
301 FIXME: what kinds of things are visible outside this file but
302 aren't functions or variables? Should this be an assert instead? */
303 if (!VAR_OR_FUNCTION_DECL_P (decl))
304 return;
306 if (DECL_ASSEMBLER_NAME_SET_P (decl))
307 id = DECL_ASSEMBLER_NAME (decl);
308 else
310 id = DECL_ASSEMBLER_NAME (decl);
311 SET_DECL_ASSEMBLER_NAME (decl, NULL_TREE);
314 FOR_EACH_VEC_ELT (*pending_weaks, i, pe)
315 if (id == pe->name)
317 apply_pragma_weak (decl, pe->value);
318 pending_weaks->unordered_remove (i);
319 break;
323 /* Process all "#pragma weak A = B" directives where we have not seen
324 a decl for A. */
325 void
326 maybe_apply_pending_pragma_weaks (void)
328 tree alias_id, id, decl;
329 (void) alias_id;
330 (void) decl;
331 int i;
332 pending_weak *pe;
333 symtab_node *target;
334 (void) target;
336 if (vec_safe_is_empty (pending_weaks))
337 return;
339 FOR_EACH_VEC_ELT (*pending_weaks, i, pe)
341 alias_id = pe->name;
342 id = pe->value;
344 if (id == NULL)
345 continue;
347 fprintf(stderr, "%s, incomplete\n", __func__);
348 #if 0 // sdcpp
349 target = symtab_node::get_for_asmname (id);
350 decl = build_decl (UNKNOWN_LOCATION,
351 target ? TREE_CODE (target->decl) : FUNCTION_DECL,
352 alias_id, default_function_type);
354 DECL_ARTIFICIAL (decl) = 1;
355 TREE_PUBLIC (decl) = 1;
356 DECL_WEAK (decl) = 1;
357 if (VAR_P (decl))
358 TREE_STATIC (decl) = 1;
359 if (!target)
361 error ("%q+D aliased to undefined symbol %qE",
362 decl, id);
363 continue;
366 assemble_alias (decl, id);
367 #endif // sdcpp
370 #endif // sdcpp
372 /* #pragma weak name [= value] */
373 static void
374 handle_pragma_weak (cpp_reader *)
376 #if 0 // sdcpp
377 tree name, value, x, decl;
378 enum cpp_ttype t;
380 value = 0;
382 if (pragma_lex (&name) != CPP_NAME)
383 GCC_BAD ("malformed %<#pragma weak%>, ignored");
384 t = pragma_lex (&x);
385 if (t == CPP_EQ)
387 if (pragma_lex (&value) != CPP_NAME)
388 GCC_BAD ("malformed %<#pragma weak%>, ignored");
389 t = pragma_lex (&x);
391 if (t != CPP_EOF)
392 warning (OPT_Wpragmas, "junk at end of %<#pragma weak%>");
394 decl = identifier_global_value (name);
395 if (decl && DECL_P (decl))
397 if (!VAR_OR_FUNCTION_DECL_P (decl))
398 GCC_BAD2 ("%<#pragma weak%> declaration of %q+D not allowed,"
399 " ignored", decl);
400 apply_pragma_weak (decl, value);
401 if (value)
403 DECL_EXTERNAL (decl) = 0;
404 if (VAR_P (decl))
405 TREE_STATIC (decl) = 1;
406 assemble_alias (decl, value);
409 else
411 pending_weak pe = {name, value};
412 vec_safe_push (pending_weaks, pe);
414 #endif // sdcpp
417 #if 0 // sdcpp
418 static enum scalar_storage_order_kind global_sso;
420 void
421 maybe_apply_pragma_scalar_storage_order (tree type)
423 if (global_sso == SSO_NATIVE)
424 return;
426 gcc_assert (RECORD_OR_UNION_TYPE_P (type));
428 if (lookup_attribute ("scalar_storage_order", TYPE_ATTRIBUTES (type)))
429 return;
431 if (global_sso == SSO_BIG_ENDIAN)
432 TYPE_REVERSE_STORAGE_ORDER (type) = !BYTES_BIG_ENDIAN;
433 else if (global_sso == SSO_LITTLE_ENDIAN)
434 TYPE_REVERSE_STORAGE_ORDER (type) = BYTES_BIG_ENDIAN;
435 else
436 gcc_unreachable ();
439 static void
440 handle_pragma_scalar_storage_order (cpp_reader *)
442 const char *kind_string;
443 enum cpp_ttype token;
444 tree x;
446 if (BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN)
448 error ("%<scalar_storage_order%> is not supported because endianness "
449 "is not uniform");
450 return;
453 if (c_dialect_cxx ())
455 if (warn_unknown_pragmas > in_system_header_at (input_location))
456 warning (OPT_Wunknown_pragmas,
457 "%<#pragma scalar_storage_order%> is not supported for C++");
458 return;
461 token = pragma_lex (&x);
462 if (token != CPP_NAME)
463 GCC_BAD ("missing %<big-endian%>, %<little-endian%>, or %<default%> after "
464 "%<#pragma scalar_storage_order%>");
465 kind_string = IDENTIFIER_POINTER (x);
466 if (strcmp (kind_string, "default") == 0)
467 global_sso = default_sso;
468 else if (strcmp (kind_string, "big") == 0)
469 global_sso = SSO_BIG_ENDIAN;
470 else if (strcmp (kind_string, "little") == 0)
471 global_sso = SSO_LITTLE_ENDIAN;
472 else
473 GCC_BAD ("expected %<big-endian%>, %<little-endian%>, or %<default%> after "
474 "%<#pragma scalar_storage_order%>");
476 #endif // sdcpp
478 /* GCC supports two #pragma directives for renaming the external
479 symbol associated with a declaration (DECL_ASSEMBLER_NAME), for
480 compatibility with the Solaris and VMS system headers. GCC also
481 has its own notation for this, __asm__("name") annotations.
483 Corner cases of these features and their interaction:
485 1) Both pragmas silently apply only to declarations with external
486 linkage (that is, TREE_PUBLIC || DECL_EXTERNAL). Asm labels
487 do not have this restriction.
489 2) In C++, both #pragmas silently apply only to extern "C" declarations.
490 Asm labels do not have this restriction.
492 3) If any of the three ways of changing DECL_ASSEMBLER_NAME is
493 applied to a decl whose DECL_ASSEMBLER_NAME is already set, and the
494 new name is different, a warning issues and the name does not change.
496 4) The "source name" for #pragma redefine_extname is the DECL_NAME,
497 *not* the DECL_ASSEMBLER_NAME.
499 5) If #pragma extern_prefix is in effect and a declaration occurs
500 with an __asm__ name, the #pragma extern_prefix is silently
501 ignored for that declaration.
503 6) If #pragma extern_prefix and #pragma redefine_extname apply to
504 the same declaration, whichever triggered first wins, and a warning
505 is issued. (We would like to have #pragma redefine_extname always
506 win, but it can appear either before or after the declaration, and
507 if it appears afterward, we have no way of knowing whether a modified
508 DECL_ASSEMBLER_NAME is due to #pragma extern_prefix.) */
510 struct GTY(()) pending_redefinition {
511 tree oldname;
512 tree newname;
516 #if 0 // sdcpp
517 static GTY(()) vec<pending_redefinition, va_gc> *pending_redefine_extname;
519 static void handle_pragma_redefine_extname (cpp_reader *);
521 /* #pragma redefine_extname oldname newname */
522 static void
523 handle_pragma_redefine_extname (cpp_reader *)
525 tree oldname, newname, decls, x;
526 enum cpp_ttype t;
527 bool found;
529 if (pragma_lex (&oldname) != CPP_NAME)
530 GCC_BAD ("malformed %<#pragma redefine_extname%>, ignored");
531 if (pragma_lex (&newname) != CPP_NAME)
532 GCC_BAD ("malformed %<#pragma redefine_extname%>, ignored");
533 t = pragma_lex (&x);
534 if (t != CPP_EOF)
535 warning (OPT_Wpragmas, "junk at end of %<#pragma redefine_extname%>");
537 found = false;
538 for (decls = c_linkage_bindings (oldname);
539 decls; )
541 tree decl;
542 if (TREE_CODE (decls) == TREE_LIST)
544 decl = TREE_VALUE (decls);
545 decls = TREE_CHAIN (decls);
547 else
549 decl = decls;
550 decls = NULL_TREE;
553 if ((TREE_PUBLIC (decl) || DECL_EXTERNAL (decl))
554 && VAR_OR_FUNCTION_DECL_P (decl))
556 found = true;
557 fprintf(stderr, "%s, incomplete\n", __func__);
558 #if 0 // sdcpp
559 if (DECL_ASSEMBLER_NAME_SET_P (decl))
561 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
562 name = targetm.strip_name_encoding (name);
564 if (!id_equal (newname, name))
565 warning (OPT_Wpragmas, "%<#pragma redefine_extname%> "
566 "ignored due to conflict with previous rename");
568 else
569 symtab->change_decl_assembler_name (decl, newname);
570 #endif
574 if (!found)
575 /* We have to add this to the rename list even if there's already
576 a global value that doesn't meet the above criteria, because in
577 C++ "struct foo {...};" puts "foo" in the current namespace but
578 does *not* conflict with a subsequent declaration of a function
579 or variable foo. See g++.dg/other/pragma-re-2.C. */
580 add_to_renaming_pragma_list (oldname, newname);
583 /* This is called from here and from ia64-c.cc. */
584 void
585 add_to_renaming_pragma_list (tree oldname, tree newname)
587 unsigned ix;
588 pending_redefinition *p;
590 FOR_EACH_VEC_SAFE_ELT (pending_redefine_extname, ix, p)
591 if (oldname == p->oldname)
593 if (p->newname != newname)
594 warning (OPT_Wpragmas, "%<#pragma redefine_extname%> ignored due to "
595 "conflict with previous %<#pragma redefine_extname%>");
596 return;
599 pending_redefinition e = {oldname, newname};
600 vec_safe_push (pending_redefine_extname, e);
602 #endif // sdcpp
604 /* The current prefix set by #pragma extern_prefix. */
605 GTY(()) tree pragma_extern_prefix;
607 /* Hook from the front ends to apply the results of one of the preceding
608 pragmas that rename variables. */
610 #if 0 // sdcpp
611 tree
612 maybe_apply_renaming_pragma (tree decl, tree asmname)
614 unsigned ix;
615 pending_redefinition *p;
617 /* The renaming pragmas are only applied to declarations with
618 external linkage. */
619 if (!VAR_OR_FUNCTION_DECL_P (decl)
620 || (!TREE_PUBLIC (decl) && !DECL_EXTERNAL (decl))
621 || !has_c_linkage (decl))
622 return asmname;
624 /* If the DECL_ASSEMBLER_NAME is already set, it does not change,
625 but we may warn about a rename that conflicts. */
626 if (DECL_ASSEMBLER_NAME_SET_P (decl))
628 const char *oldname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
629 oldname = targetm.strip_name_encoding (oldname);
631 if (asmname && strcmp (TREE_STRING_POINTER (asmname), oldname))
632 warning (OPT_Wpragmas, "%<asm%> declaration ignored due to "
633 "conflict with previous rename");
635 /* Take any pending redefine_extname off the list. */
636 FOR_EACH_VEC_SAFE_ELT (pending_redefine_extname, ix, p)
637 if (DECL_NAME (decl) == p->oldname)
639 /* Only warn if there is a conflict. */
640 if (!id_equal (p->newname, oldname))
641 warning (OPT_Wpragmas, "%<#pragma redefine_extname%> ignored "
642 "due to conflict with previous rename");
644 pending_redefine_extname->unordered_remove (ix);
645 break;
647 return NULL_TREE;
650 /* Find out if we have a pending #pragma redefine_extname. */
651 FOR_EACH_VEC_SAFE_ELT (pending_redefine_extname, ix, p)
652 if (DECL_NAME (decl) == p->oldname)
654 tree newname = p->newname;
655 pending_redefine_extname->unordered_remove (ix);
657 /* If we already have an asmname, #pragma redefine_extname is
658 ignored (with a warning if it conflicts). */
659 if (asmname)
661 if (strcmp (TREE_STRING_POINTER (asmname),
662 IDENTIFIER_POINTER (newname)) != 0)
663 warning (OPT_Wpragmas, "%<#pragma redefine_extname%> ignored "
664 "due to conflict with %<asm%> declaration");
665 return asmname;
668 /* Otherwise we use what we've got; #pragma extern_prefix is
669 silently ignored. */
670 return build_string (IDENTIFIER_LENGTH (newname),
671 IDENTIFIER_POINTER (newname));
674 /* If we've got an asmname, #pragma extern_prefix is silently ignored. */
675 if (asmname)
676 return asmname;
678 /* If #pragma extern_prefix is in effect, apply it. */
679 if (pragma_extern_prefix)
681 const char *prefix = TREE_STRING_POINTER (pragma_extern_prefix);
682 size_t plen = TREE_STRING_LENGTH (pragma_extern_prefix) - 1;
684 const char *id = IDENTIFIER_POINTER (DECL_NAME (decl));
685 size_t ilen = IDENTIFIER_LENGTH (DECL_NAME (decl));
687 char *newname = (char *) alloca (plen + ilen + 1);
689 memcpy (newname, prefix, plen);
690 memcpy (newname + plen, id, ilen + 1);
692 return build_string (plen + ilen, newname);
695 /* Nada. */
696 return NULL_TREE;
698 #endif
701 static void handle_pragma_visibility (cpp_reader *);
703 static vec<int> visstack;
705 /* Push the visibility indicated by STR onto the top of the #pragma
706 visibility stack. KIND is 0 for #pragma GCC visibility, 1 for
707 C++ namespace with visibility attribute and 2 for C++ builtin
708 ABI namespace. push_visibility/pop_visibility calls must have
709 matching KIND, it is not allowed to push visibility using one
710 KIND and pop using a different one. */
712 void
713 push_visibility (const char *str, int kind)
715 visstack.safe_push (((int) default_visibility) | (kind << 8));
716 if (!strcmp (str, "default"))
717 default_visibility = VISIBILITY_DEFAULT;
718 else if (!strcmp (str, "internal"))
719 default_visibility = VISIBILITY_INTERNAL;
720 else if (!strcmp (str, "hidden"))
721 default_visibility = VISIBILITY_HIDDEN;
722 else if (!strcmp (str, "protected"))
723 default_visibility = VISIBILITY_PROTECTED;
724 else
725 GCC_BAD ("%<#pragma GCC visibility push()%> must specify %<default%>, "
726 "%<internal%>, %<hidden%> or %<protected%>");
727 visibility_options.inpragma = 1;
730 /* Pop a level of the #pragma visibility stack. Return true if
731 successful. */
733 bool
734 pop_visibility (int kind)
736 if (!visstack.length ())
737 return false;
738 if ((visstack.last () >> 8) != kind)
739 return false;
740 default_visibility
741 = (enum symbol_visibility) (visstack.pop () & 0xff);
742 visibility_options.inpragma
743 = visstack.length () != 0;
744 return true;
747 /* Sets the default visibility for symbols to something other than that
748 specified on the command line. */
750 static void
751 handle_pragma_visibility (cpp_reader *)
753 #if 0 // sdcpp
754 /* Form is #pragma GCC visibility push(hidden)|pop */
755 tree x;
756 enum cpp_ttype token;
757 enum { bad, push, pop } action = bad;
759 token = pragma_lex (&x);
760 if (token == CPP_NAME)
762 const char *op = IDENTIFIER_POINTER (x);
763 if (!strcmp (op, "push"))
764 action = push;
765 else if (!strcmp (op, "pop"))
766 action = pop;
768 if (bad == action)
769 GCC_BAD ("%<#pragma GCC visibility%> must be followed by %<push%> "
770 "or %<pop%>");
771 else
773 if (pop == action)
775 if (! pop_visibility (0))
776 GCC_BAD ("no matching push for %<#pragma GCC visibility pop%>");
778 else
780 if (pragma_lex (&x) != CPP_OPEN_PAREN)
781 GCC_BAD ("missing %<(%> after %<#pragma GCC visibility push%> - ignored");
782 token = pragma_lex (&x);
783 if (token != CPP_NAME)
784 GCC_BAD ("malformed %<#pragma GCC visibility push%>");
785 else
786 push_visibility (IDENTIFIER_POINTER (x), 0);
787 if (pragma_lex (&x) != CPP_CLOSE_PAREN)
788 GCC_BAD ("missing %<(%> after %<#pragma GCC visibility push%> - ignored");
791 if (pragma_lex (&x) != CPP_EOF)
792 warning (OPT_Wpragmas, "junk at end of %<#pragma GCC visibility%>");
793 #endif // sdcpp
796 #if 0 // sdcpp
797 static void
798 handle_pragma_diagnostic(cpp_reader *)
800 tree x;
801 location_t loc;
802 enum cpp_ttype token = pragma_lex (&x, &loc);
803 if (token != CPP_NAME)
805 warning_at (loc, OPT_Wpragmas,
806 "missing %<error%>, %<warning%>, %<ignored%>, %<push%>, "
807 "%<pop%>, or %<ignored_attributes%> after "
808 "%<#pragma GCC diagnostic%>");
809 return;
812 diagnostic_t kind;
813 const char *kind_string = IDENTIFIER_POINTER (x);
814 if (strcmp (kind_string, "error") == 0)
815 kind = DK_ERROR;
816 else if (strcmp (kind_string, "warning") == 0)
817 kind = DK_WARNING;
818 else if (strcmp (kind_string, "ignored") == 0)
819 kind = DK_IGNORED;
820 else if (strcmp (kind_string, "push") == 0)
822 diagnostic_push_diagnostics (global_dc, input_location);
823 return;
825 else if (strcmp (kind_string, "pop") == 0)
827 diagnostic_pop_diagnostics (global_dc, input_location);
828 return;
830 else if (strcmp (kind_string, "ignored_attributes") == 0)
832 token = pragma_lex (&x, &loc);
833 if (token != CPP_STRING)
835 warning_at (loc, OPT_Wpragmas,
836 "missing attribute name after %<#pragma GCC diagnostic "
837 "ignored_attributes%>");
838 return;
840 char *args = xstrdup (TREE_STRING_POINTER (x));
841 const size_t l = strlen (args);
842 if (l == 0)
844 warning_at (loc, OPT_Wpragmas, "missing argument to %<#pragma GCC "
845 "diagnostic ignored_attributes%>");
846 free (args);
847 return;
849 else if (args[l - 1] == ',')
851 warning_at (loc, OPT_Wpragmas, "trailing %<,%> in arguments for "
852 "%<#pragma GCC diagnostic ignored_attributes%>");
853 free (args);
854 return;
856 auto_vec<char *> v;
857 for (char *p = strtok (args, ","); p; p = strtok (NULL, ","))
858 v.safe_push (p);
859 handle_ignored_attributes_option (&v);
860 free (args);
861 return;
863 else
865 warning_at (loc, OPT_Wpragmas,
866 "expected %<error%>, %<warning%>, %<ignored%>, %<push%>, "
867 "%<pop%>, %<ignored_attributes%> after "
868 "%<#pragma GCC diagnostic%>");
869 return;
872 token = pragma_lex (&x, &loc);
873 if (token != CPP_STRING)
875 warning_at (loc, OPT_Wpragmas,
876 "missing option after %<#pragma GCC diagnostic%> kind");
877 return;
880 const char *option_string = TREE_STRING_POINTER (x);
881 unsigned int lang_mask = c_common_option_lang_mask () | CL_COMMON;
882 /* option_string + 1 to skip the initial '-' */
883 unsigned int option_index = find_opt (option_string + 1, lang_mask);
884 if (option_index == OPT_SPECIAL_unknown)
886 auto_diagnostic_group d;
887 if (warning_at (loc, OPT_Wpragmas,
888 "unknown option after %<#pragma GCC diagnostic%> kind"))
890 option_proposer op;
891 const char *hint = op.suggest_option (option_string + 1);
892 if (hint)
893 inform (loc, "did you mean %<-%s%>?", hint);
895 return;
897 else if (!(cl_options[option_index].flags & CL_WARNING))
899 warning_at (loc, OPT_Wpragmas,
900 "%qs is not an option that controls warnings", option_string);
901 return;
903 else if (!(cl_options[option_index].flags & lang_mask))
905 char *ok_langs = write_langs (cl_options[option_index].flags);
906 char *bad_lang = write_langs (c_common_option_lang_mask ());
907 warning_at (loc, OPT_Wpragmas,
908 "option %qs is valid for %s but not for %s",
909 option_string, ok_langs, bad_lang);
910 free (ok_langs);
911 free (bad_lang);
912 return;
915 struct cl_option_handlers handlers;
916 set_default_handlers (&handlers, NULL);
917 const char *arg = NULL;
918 if (cl_options[option_index].flags & CL_JOINED)
919 arg = option_string + 1 + cl_options[option_index].opt_len;
920 /* FIXME: input_location isn't the best location here, but it is
921 what we used to do here before and changing it breaks e.g.
922 PR69543 and PR69558. */
923 control_warning_option (option_index, (int) kind,
924 arg, kind != DK_IGNORED,
925 input_location, lang_mask, &handlers,
926 &global_options, &global_options_set,
927 global_dc);
929 #endif // sdcpp
931 /* Parse #pragma GCC target (xxx) to set target specific options. */
932 #if 0 // sdcpp
933 static void
934 handle_pragma_target(cpp_reader *)
936 location_t loc;
937 enum cpp_ttype token;
938 tree x;
939 bool close_paren_needed_p = false;
941 if (cfun)
943 error ("%<#pragma GCC option%> is not allowed inside functions");
944 return;
947 token = pragma_lex (&x, &loc);
948 if (token == CPP_OPEN_PAREN)
950 close_paren_needed_p = true;
951 token = pragma_lex (&x, &loc);
954 if (token != CPP_STRING)
955 GCC_BAD_AT (loc, "%<#pragma GCC option%> is not a string");
957 /* Strings are user options. */
958 else
960 tree args = NULL_TREE;
964 /* Build up the strings now as a tree linked list. Skip empty
965 strings. */
966 if (TREE_STRING_LENGTH (x) > 0)
967 args = tree_cons (NULL_TREE, x, args);
969 token = pragma_lex (&x);
970 while (token == CPP_COMMA)
971 token = pragma_lex (&x);
973 while (token == CPP_STRING);
975 if (close_paren_needed_p)
977 if (token == CPP_CLOSE_PAREN)
978 token = pragma_lex (&x);
979 else
980 GCC_BAD ("%<#pragma GCC target (string [,string]...)%> does "
981 "not have a final %<)%>");
984 if (token != CPP_EOF)
986 error ("%<#pragma GCC target%> string is badly formed");
987 return;
990 /* put arguments in the order the user typed them. */
991 args = nreverse (args);
993 fprintf(stderr, "%s, incomplete\n", __func__);
994 // sdcpp if (targetm.target_option.pragma_parse (args, NULL_TREE))
995 // sdcpp current_target_pragma = chainon (current_target_pragma, args);
997 /* A target pragma can also influence optimization options. */
998 tree current_optimize
999 = build_optimization_node (&global_options, &global_options_set);
1000 if (current_optimize != optimization_current_node)
1001 optimization_current_node = current_optimize;
1005 /* Handle #pragma GCC optimize to set optimization options. */
1006 static void
1007 handle_pragma_optimize (cpp_reader *)
1009 enum cpp_ttype token;
1010 tree x;
1011 bool close_paren_needed_p = false;
1012 tree optimization_previous_node = optimization_current_node;
1014 if (cfun)
1016 error ("%<#pragma GCC optimize%> is not allowed inside functions");
1017 return;
1020 token = pragma_lex (&x);
1021 if (token == CPP_OPEN_PAREN)
1023 close_paren_needed_p = true;
1024 token = pragma_lex (&x);
1027 if (token != CPP_STRING && token != CPP_NUMBER)
1028 GCC_BAD ("%<#pragma GCC optimize%> is not a string or number");
1030 /* Strings/numbers are user options. */
1031 else
1033 tree args = NULL_TREE;
1037 /* Build up the numbers/strings now as a list. */
1038 if (token != CPP_STRING || TREE_STRING_LENGTH (x) > 0)
1039 args = tree_cons (NULL_TREE, x, args);
1041 token = pragma_lex (&x);
1042 while (token == CPP_COMMA)
1043 token = pragma_lex (&x);
1045 while (token == CPP_STRING || token == CPP_NUMBER);
1047 if (close_paren_needed_p)
1049 if (token == CPP_CLOSE_PAREN)
1050 token = pragma_lex (&x);
1051 else
1052 GCC_BAD ("%<#pragma GCC optimize (string [,string]...)%> does "
1053 "not have a final %<)%>");
1056 if (token != CPP_EOF)
1058 error ("%<#pragma GCC optimize%> string is badly formed");
1059 return;
1062 /* put arguments in the order the user typed them. */
1063 args = nreverse (args);
1065 parse_optimize_options (args, false);
1066 current_optimize_pragma = chainon (current_optimize_pragma, args);
1067 optimization_current_node
1068 = build_optimization_node (&global_options, &global_options_set);
1069 c_cpp_builtins_optimize_pragma (parse_in,
1070 optimization_previous_node,
1071 optimization_current_node);
1075 /* Stack of the #pragma GCC options created with #pragma GCC push_option. Save
1076 both the binary representation of the options and the TREE_LIST of
1077 strings that will be added to the function's attribute list. */
1078 struct GTY(()) opt_stack {
1079 struct opt_stack *prev;
1080 tree target_binary;
1081 tree target_strings;
1082 tree optimize_binary;
1083 tree optimize_strings;
1084 gcc_options * GTY ((skip)) saved_global_options;
1087 static GTY(()) struct opt_stack * options_stack;
1088 #endif // sdcpp
1090 /* Handle #pragma GCC push_options to save the current target and optimization
1091 options. */
1093 #if 0 // sdcpp
1094 static void
1095 handle_pragma_push_options (cpp_reader *)
1097 enum cpp_ttype token;
1098 tree x = 0;
1100 token = pragma_lex (&x);
1101 if (token != CPP_EOF)
1103 warning (OPT_Wpragmas, "junk at end of %<#pragma push_options%>");
1104 return;
1107 opt_stack *p = ggc_alloc<opt_stack> ();
1108 p->prev = options_stack;
1109 options_stack = p;
1111 /* Save optimization and target flags in binary format. */
1112 if (flag_checking)
1114 p->saved_global_options = XNEW (gcc_options);
1115 *p->saved_global_options = global_options;
1117 p->optimize_binary = build_optimization_node (&global_options,
1118 &global_options_set);
1119 p->target_binary = build_target_option_node (&global_options,
1120 &global_options_set);
1122 /* Save optimization and target flags in string list format. */
1123 p->optimize_strings = copy_list (current_optimize_pragma);
1124 p->target_strings = copy_list (current_target_pragma);
1127 /* Handle #pragma GCC pop_options to restore the current target and
1128 optimization options from a previous push_options. */
1130 static void
1131 handle_pragma_pop_options (cpp_reader *)
1133 enum cpp_ttype token;
1134 tree x = 0;
1135 opt_stack *p;
1137 token = pragma_lex (&x);
1138 if (token != CPP_EOF)
1140 warning (OPT_Wpragmas, "junk at end of %<#pragma pop_options%>");
1141 return;
1144 if (! options_stack)
1146 warning (OPT_Wpragmas,
1147 "%<#pragma GCC pop_options%> without a corresponding "
1148 "%<#pragma GCC push_options%>");
1149 return;
1152 p = options_stack;
1153 options_stack = p->prev;
1155 if (p->target_binary != target_option_current_node)
1157 fprintf(stderr, "%s, incomplete\n", __func__);
1158 // sdcpp (void) targetm.target_option.pragma_parse (NULL_TREE, p->target_binary);
1159 target_option_current_node = p->target_binary;
1162 /* Always restore optimization options as optimization_current_node is
1163 * overwritten by invoke_set_current_function_hook. */
1164 cl_optimization_restore (&global_options, &global_options_set,
1165 TREE_OPTIMIZATION (p->optimize_binary));
1166 cl_target_option_restore (&global_options, &global_options_set,
1167 TREE_TARGET_OPTION (p->target_binary));
1169 if (p->optimize_binary != optimization_current_node)
1171 c_cpp_builtins_optimize_pragma (parse_in, optimization_current_node,
1172 p->optimize_binary);
1173 optimization_current_node = p->optimize_binary;
1175 if (flag_checking && !seen_error ())
1177 cl_optimization_compare (p->saved_global_options, &global_options);
1178 free (p->saved_global_options);
1181 current_target_pragma = p->target_strings;
1182 current_optimize_pragma = p->optimize_strings;
1185 /* Handle #pragma GCC reset_options to restore the current target and
1186 optimization options to the original options used on the command line. */
1188 static void
1189 handle_pragma_reset_options (cpp_reader *)
1191 enum cpp_ttype token;
1192 tree x = 0;
1193 tree new_optimize = optimization_default_node;
1194 tree new_target = target_option_default_node;
1196 token = pragma_lex (&x);
1197 if (token != CPP_EOF)
1199 warning (OPT_Wpragmas, "junk at end of %<#pragma reset_options%>");
1200 return;
1203 if (new_target != target_option_current_node)
1205 fprintf(stderr, "%s, incomplete\n", __func__);
1206 // sdcpp (void) targetm.target_option.pragma_parse (NULL_TREE, new_target);
1207 target_option_current_node = new_target;
1210 if (new_optimize != optimization_current_node)
1212 tree old_optimize = optimization_current_node;
1213 cl_optimization_restore (&global_options, &global_options_set,
1214 TREE_OPTIMIZATION (new_optimize));
1215 c_cpp_builtins_optimize_pragma (parse_in, old_optimize, new_optimize);
1216 optimization_current_node = new_optimize;
1219 current_target_pragma = NULL_TREE;
1220 current_optimize_pragma = NULL_TREE;
1223 /* Print a plain user-specified message. */
1225 static void
1226 handle_pragma_message (cpp_reader *)
1228 location_t loc;
1229 enum cpp_ttype token;
1230 tree x, message = 0;
1232 token = pragma_lex (&x);
1233 if (token == CPP_OPEN_PAREN)
1235 token = pragma_lex (&x);
1236 if (token == CPP_STRING)
1237 message = x;
1238 else
1239 GCC_BAD ("expected a string after %<#pragma message%>");
1240 if (pragma_lex (&x) != CPP_CLOSE_PAREN)
1241 GCC_BAD ("malformed %<#pragma message%>, ignored");
1243 else if (token == CPP_STRING)
1244 message = x;
1245 else
1246 GCC_BAD ("expected a string after %<#pragma message%>");
1248 gcc_assert (message);
1250 if (pragma_lex (&x, &loc) != CPP_EOF)
1251 warning_at (loc, OPT_Wpragmas, "junk at end of %<#pragma message%>");
1253 if (TREE_STRING_LENGTH (message) > 1)
1254 inform (input_location, "%<#pragma message: %s%>",
1255 TREE_STRING_POINTER (message));
1258 /* Mark whether the current location is valid for a STDC pragma. */
1260 static bool valid_location_for_stdc_pragma;
1262 void
1263 mark_valid_location_for_stdc_pragma (bool flag)
1265 valid_location_for_stdc_pragma = flag;
1268 /* Return true if the current location is valid for a STDC pragma. */
1270 bool
1271 valid_location_for_stdc_pragma_p (void)
1273 return valid_location_for_stdc_pragma;
1276 enum pragma_switch_t { PRAGMA_ON, PRAGMA_OFF, PRAGMA_DEFAULT, PRAGMA_BAD };
1277 #endif // sdcpp
1279 /* A STDC pragma must appear outside of external declarations or
1280 preceding all explicit declarations and statements inside a compound
1281 statement; its behavior is undefined if used in any other context.
1282 It takes a switch of ON, OFF, or DEFAULT. */
1284 #if 0 // sdcpp
1285 static enum pragma_switch_t
1286 handle_stdc_pragma (const char *pname)
1288 const char *arg;
1289 tree t;
1290 enum pragma_switch_t ret;
1292 if (!valid_location_for_stdc_pragma_p ())
1294 warning (OPT_Wpragmas, "invalid location for %<pragma %s%>, ignored",
1295 pname);
1296 return PRAGMA_BAD;
1299 if (pragma_lex (&t) != CPP_NAME)
1301 warning (OPT_Wpragmas, "malformed %<#pragma %s%>, ignored", pname);
1302 return PRAGMA_BAD;
1305 arg = IDENTIFIER_POINTER (t);
1307 if (!strcmp (arg, "ON"))
1308 ret = PRAGMA_ON;
1309 else if (!strcmp (arg, "OFF"))
1310 ret = PRAGMA_OFF;
1311 else if (!strcmp (arg, "DEFAULT"))
1312 ret = PRAGMA_DEFAULT;
1313 else
1315 warning (OPT_Wpragmas, "malformed %<#pragma %s%>, ignored", pname);
1316 return PRAGMA_BAD;
1319 if (pragma_lex (&t) != CPP_EOF)
1321 warning (OPT_Wpragmas, "junk at end of %<#pragma %s%>", pname);
1322 return PRAGMA_BAD;
1325 return ret;
1327 #endif // sdcpp
1329 /* #pragma STDC FLOAT_CONST_DECIMAL64 ON
1330 #pragma STDC FLOAT_CONST_DECIMAL64 OFF
1331 #pragma STDC FLOAT_CONST_DECIMAL64 DEFAULT */
1333 #if 0 //sdcpp
1334 static void
1335 handle_pragma_float_const_decimal64 (cpp_reader *)
1337 if (c_dialect_cxx ())
1339 if (warn_unknown_pragmas > in_system_header_at (input_location))
1340 warning (OPT_Wunknown_pragmas,
1341 "%<#pragma STDC FLOAT_CONST_DECIMAL64%> is not supported"
1342 " for C++");
1343 return;
1346 if (!targetm.decimal_float_supported_p ())
1348 if (warn_unknown_pragmas > in_system_header_at (input_location))
1349 warning (OPT_Wunknown_pragmas,
1350 "%<#pragma STDC FLOAT_CONST_DECIMAL64%> is not supported"
1351 " on this target");
1352 return;
1355 pedwarn (input_location, OPT_Wpedantic,
1356 "ISO C does not support %<#pragma STDC FLOAT_CONST_DECIMAL64%>");
1358 switch (handle_stdc_pragma ("STDC FLOAT_CONST_DECIMAL64"))
1360 case PRAGMA_ON:
1361 set_float_const_decimal64 ();
1362 break;
1363 case PRAGMA_OFF:
1364 case PRAGMA_DEFAULT:
1365 clear_float_const_decimal64 ();
1366 break;
1367 case PRAGMA_BAD:
1368 break;
1371 #endif //sdcpp
1373 /* A vector of registered pragma callbacks, which is never freed. */
1375 static vec<internal_pragma_handler> registered_pragmas;
1377 struct pragma_ns_name
1379 const char *space;
1380 const char *name;
1384 static vec<pragma_ns_name> registered_pp_pragmas;
1386 struct omp_pragma_def { const char *name; unsigned int id; };
1387 static const struct omp_pragma_def oacc_pragmas[] = {
1388 { "atomic", PRAGMA_OACC_ATOMIC },
1389 { "cache", PRAGMA_OACC_CACHE },
1390 { "data", PRAGMA_OACC_DATA },
1391 { "declare", PRAGMA_OACC_DECLARE },
1392 { "enter", PRAGMA_OACC_ENTER_DATA },
1393 { "exit", PRAGMA_OACC_EXIT_DATA },
1394 { "host_data", PRAGMA_OACC_HOST_DATA },
1395 { "kernels", PRAGMA_OACC_KERNELS },
1396 { "loop", PRAGMA_OACC_LOOP },
1397 { "parallel", PRAGMA_OACC_PARALLEL },
1398 { "routine", PRAGMA_OACC_ROUTINE },
1399 { "serial", PRAGMA_OACC_SERIAL },
1400 { "update", PRAGMA_OACC_UPDATE },
1401 { "wait", PRAGMA_OACC_WAIT }
1403 static const struct omp_pragma_def omp_pragmas[] = {
1404 { "allocate", PRAGMA_OMP_ALLOCATE },
1405 { "atomic", PRAGMA_OMP_ATOMIC },
1406 { "barrier", PRAGMA_OMP_BARRIER },
1407 { "cancel", PRAGMA_OMP_CANCEL },
1408 { "cancellation", PRAGMA_OMP_CANCELLATION_POINT },
1409 { "critical", PRAGMA_OMP_CRITICAL },
1410 { "depobj", PRAGMA_OMP_DEPOBJ },
1411 { "error", PRAGMA_OMP_ERROR },
1412 { "end", PRAGMA_OMP_END_DECLARE_TARGET },
1413 { "flush", PRAGMA_OMP_FLUSH },
1414 { "nothing", PRAGMA_OMP_NOTHING },
1415 { "requires", PRAGMA_OMP_REQUIRES },
1416 { "scope", PRAGMA_OMP_SCOPE },
1417 { "section", PRAGMA_OMP_SECTION },
1418 { "sections", PRAGMA_OMP_SECTIONS },
1419 { "single", PRAGMA_OMP_SINGLE },
1420 { "task", PRAGMA_OMP_TASK },
1421 { "taskgroup", PRAGMA_OMP_TASKGROUP },
1422 { "taskwait", PRAGMA_OMP_TASKWAIT },
1423 { "taskyield", PRAGMA_OMP_TASKYIELD },
1424 { "threadprivate", PRAGMA_OMP_THREADPRIVATE }
1426 static const struct omp_pragma_def omp_pragmas_simd[] = {
1427 { "declare", PRAGMA_OMP_DECLARE },
1428 { "distribute", PRAGMA_OMP_DISTRIBUTE },
1429 { "for", PRAGMA_OMP_FOR },
1430 { "loop", PRAGMA_OMP_LOOP },
1431 { "masked", PRAGMA_OMP_MASKED },
1432 { "master", PRAGMA_OMP_MASTER },
1433 { "ordered", PRAGMA_OMP_ORDERED },
1434 { "parallel", PRAGMA_OMP_PARALLEL },
1435 { "scan", PRAGMA_OMP_SCAN },
1436 { "simd", PRAGMA_OMP_SIMD },
1437 { "target", PRAGMA_OMP_TARGET },
1438 { "taskloop", PRAGMA_OMP_TASKLOOP },
1439 { "teams", PRAGMA_OMP_TEAMS },
1442 void
1443 c_pp_lookup_pragma (unsigned int id, const char **space, const char **name)
1445 const int n_oacc_pragmas = sizeof (oacc_pragmas) / sizeof (*oacc_pragmas);
1446 const int n_omp_pragmas = sizeof (omp_pragmas) / sizeof (*omp_pragmas);
1447 const int n_omp_pragmas_simd = sizeof (omp_pragmas_simd)
1448 / sizeof (*omp_pragmas);
1449 int i;
1451 for (i = 0; i < n_oacc_pragmas; ++i)
1452 if (oacc_pragmas[i].id == id)
1454 *space = "acc";
1455 *name = oacc_pragmas[i].name;
1456 return;
1459 for (i = 0; i < n_omp_pragmas; ++i)
1460 if (omp_pragmas[i].id == id)
1462 *space = "omp";
1463 *name = omp_pragmas[i].name;
1464 return;
1467 for (i = 0; i < n_omp_pragmas_simd; ++i)
1468 if (omp_pragmas_simd[i].id == id)
1470 *space = "omp";
1471 *name = omp_pragmas_simd[i].name;
1472 return;
1475 if (id >= PRAGMA_FIRST_EXTERNAL
1476 && (id < PRAGMA_FIRST_EXTERNAL + registered_pp_pragmas.length ()))
1478 *space = registered_pp_pragmas[id - PRAGMA_FIRST_EXTERNAL].space;
1479 *name = registered_pp_pragmas[id - PRAGMA_FIRST_EXTERNAL].name;
1480 return;
1483 gcc_unreachable ();
1486 /* Front-end wrappers for pragma registration to avoid dragging
1487 cpplib.h in almost everywhere. */
1489 static void
1490 c_register_pragma_1 (const char *space, const char *name,
1491 internal_pragma_handler ihandler, bool allow_expansion)
1493 unsigned id;
1495 if (flag_preprocess_only)
1497 pragma_ns_name ns_name;
1499 if (!allow_expansion)
1500 return;
1502 ns_name.space = space;
1503 ns_name.name = name;
1504 registered_pp_pragmas.safe_push (ns_name);
1505 id = registered_pp_pragmas.length ();
1506 id += PRAGMA_FIRST_EXTERNAL - 1;
1508 else
1510 registered_pragmas.safe_push (ihandler);
1511 id = registered_pragmas.length ();
1512 id += PRAGMA_FIRST_EXTERNAL - 1;
1514 /* The C front end allocates 8 bits in c_token. The C++ front end
1515 keeps the pragma kind in the form of INTEGER_CST, so no small
1516 limit applies. At present this is sufficient. */
1517 gcc_assert (id < 256);
1520 cpp_register_deferred_pragma (parse_in, space, name, id,
1521 allow_expansion, false);
1524 /* Register a C pragma handler, using a space and a name. It disallows pragma
1525 expansion (if you want it, use c_register_pragma_with_expansion instead). */
1526 void
1527 c_register_pragma (const char *space, const char *name,
1528 pragma_handler_1arg handler)
1530 internal_pragma_handler ihandler;
1532 ihandler.handler.handler_1arg = handler;
1533 ihandler.extra_data = false;
1534 ihandler.data = NULL;
1535 c_register_pragma_1 (space, name, ihandler, false);
1538 /* Register a C pragma handler, using a space and a name, it also carries an
1539 extra data field which can be used by the handler. It disallows pragma
1540 expansion (if you want it, use c_register_pragma_with_expansion_and_data
1541 instead). */
1542 void
1543 c_register_pragma_with_data (const char *space, const char *name,
1544 pragma_handler_2arg handler, void * data)
1546 internal_pragma_handler ihandler;
1548 ihandler.handler.handler_2arg = handler;
1549 ihandler.extra_data = true;
1550 ihandler.data = data;
1551 c_register_pragma_1 (space, name, ihandler, false);
1554 /* Register a C pragma handler, using a space and a name. It allows pragma
1555 expansion as in the following example:
1557 #define NUMBER 10
1558 #pragma count (NUMBER)
1560 Name expansion is still disallowed. */
1561 void
1562 c_register_pragma_with_expansion (const char *space, const char *name,
1563 pragma_handler_1arg handler)
1565 internal_pragma_handler ihandler;
1567 ihandler.handler.handler_1arg = handler;
1568 ihandler.extra_data = false;
1569 ihandler.data = NULL;
1570 c_register_pragma_1 (space, name, ihandler, true);
1573 /* Register a C pragma handler, using a space and a name, it also carries an
1574 extra data field which can be used by the handler. It allows pragma
1575 expansion as in the following example:
1577 #define NUMBER 10
1578 #pragma count (NUMBER)
1580 Name expansion is still disallowed. */
1581 void
1582 c_register_pragma_with_expansion_and_data (const char *space, const char *name,
1583 pragma_handler_2arg handler,
1584 void *data)
1586 internal_pragma_handler ihandler;
1588 ihandler.handler.handler_2arg = handler;
1589 ihandler.extra_data = true;
1590 ihandler.data = data;
1591 c_register_pragma_1 (space, name, ihandler, true);
1594 void
1595 c_invoke_pragma_handler (unsigned int id)
1597 internal_pragma_handler *ihandler;
1598 pragma_handler_1arg handler_1arg;
1599 pragma_handler_2arg handler_2arg;
1601 id -= PRAGMA_FIRST_EXTERNAL;
1602 ihandler = &registered_pragmas[id];
1603 if (ihandler->extra_data)
1605 handler_2arg = ihandler->handler.handler_2arg;
1606 handler_2arg (parse_in, ihandler->data);
1608 else
1610 handler_1arg = ihandler->handler.handler_1arg;
1611 handler_1arg (parse_in);
1615 /* Set up front-end pragmas. */
1616 void
1617 init_pragma (void)
1619 if (flag_openacc)
1621 const int n_oacc_pragmas
1622 = sizeof (oacc_pragmas) / sizeof (*oacc_pragmas);
1623 int i;
1625 for (i = 0; i < n_oacc_pragmas; ++i)
1626 cpp_register_deferred_pragma (parse_in, "acc", oacc_pragmas[i].name,
1627 oacc_pragmas[i].id, true, true);
1630 if (flag_openmp)
1632 const int n_omp_pragmas = sizeof (omp_pragmas) / sizeof (*omp_pragmas);
1633 int i;
1635 for (i = 0; i < n_omp_pragmas; ++i)
1636 cpp_register_deferred_pragma (parse_in, "omp", omp_pragmas[i].name,
1637 omp_pragmas[i].id, true, true);
1639 if (flag_openmp || flag_openmp_simd)
1641 const int n_omp_pragmas_simd = sizeof (omp_pragmas_simd)
1642 / sizeof (*omp_pragmas);
1643 int i;
1645 for (i = 0; i < n_omp_pragmas_simd; ++i)
1646 cpp_register_deferred_pragma (parse_in, "omp", omp_pragmas_simd[i].name,
1647 omp_pragmas_simd[i].id, true, true);
1650 if (!flag_preprocess_only)
1651 cpp_register_deferred_pragma (parse_in, "GCC", "pch_preprocess",
1652 PRAGMA_GCC_PCH_PREPROCESS, false, false);
1654 if (!flag_preprocess_only)
1655 cpp_register_deferred_pragma (parse_in, "GCC", "ivdep", PRAGMA_IVDEP, false,
1656 false);
1658 if (!flag_preprocess_only)
1659 cpp_register_deferred_pragma (parse_in, "GCC", "unroll", PRAGMA_UNROLL,
1660 false, false);
1662 #ifdef HANDLE_PRAGMA_PACK_WITH_EXPANSION
1663 c_register_pragma_with_expansion (0, "pack", handle_pragma_pack);
1664 #else
1665 c_register_pragma (0, "pack", handle_pragma_pack);
1666 #endif
1667 c_register_pragma (0, "weak", handle_pragma_weak);
1669 c_register_pragma ("GCC", "visibility", handle_pragma_visibility);
1671 #if 0 // sdcpp
1672 c_register_pragma ("GCC", "diagnostic", handle_pragma_diagnostic);
1673 c_register_pragma ("GCC", "target", handle_pragma_target);
1674 c_register_pragma ("GCC", "optimize", handle_pragma_optimize);
1675 c_register_pragma ("GCC", "push_options", handle_pragma_push_options);
1676 c_register_pragma ("GCC", "pop_options", handle_pragma_pop_options);
1677 c_register_pragma ("GCC", "reset_options", handle_pragma_reset_options);
1679 c_register_pragma ("STDC", "FLOAT_CONST_DECIMAL64",
1680 handle_pragma_float_const_decimal64);
1682 c_register_pragma_with_expansion (0, "redefine_extname",
1683 handle_pragma_redefine_extname);
1685 c_register_pragma_with_expansion (0, "message", handle_pragma_message);
1687 #ifdef REGISTER_TARGET_PRAGMAS
1688 // fprintf(stderr, "no REGISTER_TARGET_PRAGMAS\n");
1689 // REGISTER_TARGET_PRAGMAS ();
1690 #endif
1692 global_sso = default_sso;
1693 c_register_pragma (0, "scalar_storage_order",
1694 handle_pragma_scalar_storage_order);
1696 /* Allow plugins to register their own pragmas. */
1697 invoke_plugin_callbacks (PLUGIN_PRAGMAS, NULL);
1698 #endif // sdcpp
1701 // sdcpp #include "gt-c-family-c-pragma.h"