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
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
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/>. */
22 #include "coretypes.h"
24 #include "function.h" /* For cfun. */
27 // #include "tm_p.h" /* For REGISTER_TARGET_PRAGMAS. */
28 #include "stringpool.h"
30 #include "diagnostic.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
{
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. */
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. */
73 push_alignment (int alignment
, tree id
)
75 align_stack
* entry
= ggc_alloc
<align_stack
> ();
77 entry
->alignment
= alignment
;
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. */
94 pop_alignment (tree id
)
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. */
106 for (entry
= alignment_stack
; entry
; entry
= entry
->prev
)
109 alignment_stack
= entry
;
113 warning (OPT_Wpragmas
,
114 "%<#pragma pack(pop, %E)%> encountered without matching "
115 "%<#pragma pack(push, %E)%>"
119 entry
= alignment_stack
->prev
;
121 maximum_field_alignment
= entry
? entry
->alignment
: default_alignment
;
123 alignment_stack
= entry
;
131 #pragma pack (push, N)
132 #pragma pack (push, ID)
133 #pragma pack (push, ID, N)
135 #pragma pack (pop, ID) */
137 handle_pragma_pack (cpp_reader
*)
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
)
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
);
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"); \
169 GCC_BAD ("malformed %<#pragma pack(pop[, id])%> - ignored"); \
172 const char *op
= IDENTIFIER_POINTER (x
);
173 if (!strcmp (op
, "push"))
175 else if (!strcmp (op
, "pop"))
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)
188 else if (token
== CPP_NUMBER
&& action
== push
&& align
== -1)
190 if (TREE_CODE (x
) != INTEGER_CST
)
192 "invalid constant in %<#pragma pack%> - ignored");
193 align
= TREE_INT_CST_LOW (x
);
201 if (token
!= CPP_CLOSE_PAREN
)
203 #undef GCC_BAD_ACTION
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");
223 align
*= BITS_PER_UNIT
;
228 align
= maximum_field_alignment
;
233 GCC_BAD2 ("alignment must be a small power of two, not %d", align
);
238 case set
: SET_GLOBAL_ALIGNMENT (align
); break;
239 case push
: push_alignment (align
, id
); break;
240 case pop
: pop_alignment (id
); break;
245 struct GTY(()) pending_weak
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
*);
259 apply_pragma_weak (tree decl
, tree 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)),
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);
285 maybe_apply_pragma_weak (tree decl
)
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
))
296 /* If it's not visible outside this file, it doesn't matter whether
298 if (!DECL_EXTERNAL (decl
) && !TREE_PUBLIC (decl
))
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
))
306 if (DECL_ASSEMBLER_NAME_SET_P (decl
))
307 id
= DECL_ASSEMBLER_NAME (decl
);
310 id
= DECL_ASSEMBLER_NAME (decl
);
311 SET_DECL_ASSEMBLER_NAME (decl
, NULL_TREE
);
314 FOR_EACH_VEC_ELT (*pending_weaks
, i
, pe
)
317 apply_pragma_weak (decl
, pe
->value
);
318 pending_weaks
->unordered_remove (i
);
323 /* Process all "#pragma weak A = B" directives where we have not seen
326 maybe_apply_pending_pragma_weaks (void)
328 tree alias_id
, id
, decl
;
336 if (vec_safe_is_empty (pending_weaks
))
339 FOR_EACH_VEC_ELT (*pending_weaks
, i
, pe
)
347 fprintf(stderr
, "%s, incomplete\n", __func__
);
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;
358 TREE_STATIC (decl
) = 1;
361 error ("%q+D aliased to undefined symbol %qE",
366 assemble_alias (decl
, id
);
372 /* #pragma weak name [= value] */
374 handle_pragma_weak (cpp_reader
*)
377 tree name
, value
, x
, decl
;
382 if (pragma_lex (&name
) != CPP_NAME
)
383 GCC_BAD ("malformed %<#pragma weak%>, ignored");
387 if (pragma_lex (&value
) != CPP_NAME
)
388 GCC_BAD ("malformed %<#pragma weak%>, ignored");
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,"
400 apply_pragma_weak (decl
, value
);
403 DECL_EXTERNAL (decl
) = 0;
405 TREE_STATIC (decl
) = 1;
406 assemble_alias (decl
, value
);
411 pending_weak pe
= {name
, value
};
412 vec_safe_push (pending_weaks
, pe
);
418 static enum scalar_storage_order_kind global_sso
;
421 maybe_apply_pragma_scalar_storage_order (tree type
)
423 if (global_sso
== SSO_NATIVE
)
426 gcc_assert (RECORD_OR_UNION_TYPE_P (type
));
428 if (lookup_attribute ("scalar_storage_order", TYPE_ATTRIBUTES (type
)))
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
;
440 handle_pragma_scalar_storage_order (cpp_reader
*)
442 const char *kind_string
;
443 enum cpp_ttype token
;
446 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
)
448 error ("%<scalar_storage_order%> is not supported because endianness "
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++");
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
;
473 GCC_BAD ("expected %<big-endian%>, %<little-endian%>, or %<default%> after "
474 "%<#pragma scalar_storage_order%>");
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
{
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 */
523 handle_pragma_redefine_extname (cpp_reader
*)
525 tree oldname
, newname
, decls
, x
;
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");
535 warning (OPT_Wpragmas
, "junk at end of %<#pragma redefine_extname%>");
538 for (decls
= c_linkage_bindings (oldname
);
542 if (TREE_CODE (decls
) == TREE_LIST
)
544 decl
= TREE_VALUE (decls
);
545 decls
= TREE_CHAIN (decls
);
553 if ((TREE_PUBLIC (decl
) || DECL_EXTERNAL (decl
))
554 && VAR_OR_FUNCTION_DECL_P (decl
))
557 fprintf(stderr
, "%s, incomplete\n", __func__
);
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");
569 symtab
->change_decl_assembler_name (decl
, newname
);
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. */
585 add_to_renaming_pragma_list (tree oldname
, tree newname
)
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%>");
599 pending_redefinition e
= {oldname
, newname
};
600 vec_safe_push (pending_redefine_extname
, e
);
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. */
612 maybe_apply_renaming_pragma (tree decl
, tree asmname
)
615 pending_redefinition
*p
;
617 /* The renaming pragmas are only applied to declarations with
619 if (!VAR_OR_FUNCTION_DECL_P (decl
)
620 || (!TREE_PUBLIC (decl
) && !DECL_EXTERNAL (decl
))
621 || !has_c_linkage (decl
))
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
);
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). */
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");
668 /* Otherwise we use what we've got; #pragma extern_prefix is
670 return build_string (IDENTIFIER_LENGTH (newname
),
671 IDENTIFIER_POINTER (newname
));
674 /* If we've got an asmname, #pragma extern_prefix is silently ignored. */
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
);
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. */
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
;
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
734 pop_visibility (int kind
)
736 if (!visstack
.length ())
738 if ((visstack
.last () >> 8) != kind
)
741 = (enum symbol_visibility
) (visstack
.pop () & 0xff);
742 visibility_options
.inpragma
743 = visstack
.length () != 0;
747 /* Sets the default visibility for symbols to something other than that
748 specified on the command line. */
751 handle_pragma_visibility (cpp_reader
*)
754 /* Form is #pragma GCC visibility push(hidden)|pop */
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"))
765 else if (!strcmp (op
, "pop"))
769 GCC_BAD ("%<#pragma GCC visibility%> must be followed by %<push%> "
775 if (! pop_visibility (0))
776 GCC_BAD ("no matching push for %<#pragma GCC visibility pop%>");
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%>");
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%>");
798 handle_pragma_diagnostic(cpp_reader
*)
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%>");
813 const char *kind_string
= IDENTIFIER_POINTER (x
);
814 if (strcmp (kind_string
, "error") == 0)
816 else if (strcmp (kind_string
, "warning") == 0)
818 else if (strcmp (kind_string
, "ignored") == 0)
820 else if (strcmp (kind_string
, "push") == 0)
822 diagnostic_push_diagnostics (global_dc
, input_location
);
825 else if (strcmp (kind_string
, "pop") == 0)
827 diagnostic_pop_diagnostics (global_dc
, input_location
);
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%>");
840 char *args
= xstrdup (TREE_STRING_POINTER (x
));
841 const size_t l
= strlen (args
);
844 warning_at (loc
, OPT_Wpragmas
, "missing argument to %<#pragma GCC "
845 "diagnostic ignored_attributes%>");
849 else if (args
[l
- 1] == ',')
851 warning_at (loc
, OPT_Wpragmas
, "trailing %<,%> in arguments for "
852 "%<#pragma GCC diagnostic ignored_attributes%>");
857 for (char *p
= strtok (args
, ","); p
; p
= strtok (NULL
, ","))
859 handle_ignored_attributes_option (&v
);
865 warning_at (loc
, OPT_Wpragmas
,
866 "expected %<error%>, %<warning%>, %<ignored%>, %<push%>, "
867 "%<pop%>, %<ignored_attributes%> after "
868 "%<#pragma GCC diagnostic%>");
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");
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"))
891 const char *hint
= op
.suggest_option (option_string
+ 1);
893 inform (loc
, "did you mean %<-%s%>?", hint
);
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
);
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
);
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
,
931 /* Parse #pragma GCC target (xxx) to set target specific options. */
934 handle_pragma_target(cpp_reader
*)
937 enum cpp_ttype token
;
939 bool close_paren_needed_p
= false;
943 error ("%<#pragma GCC option%> is not allowed inside functions");
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. */
960 tree args
= NULL_TREE
;
964 /* Build up the strings now as a tree linked list. Skip empty
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
);
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");
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. */
1007 handle_pragma_optimize (cpp_reader
*)
1009 enum cpp_ttype token
;
1011 bool close_paren_needed_p
= false;
1012 tree optimization_previous_node
= optimization_current_node
;
1016 error ("%<#pragma GCC optimize%> is not allowed inside functions");
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. */
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
);
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");
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
;
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
;
1090 /* Handle #pragma GCC push_options to save the current target and optimization
1095 handle_pragma_push_options (cpp_reader
*)
1097 enum cpp_ttype token
;
1100 token
= pragma_lex (&x
);
1101 if (token
!= CPP_EOF
)
1103 warning (OPT_Wpragmas
, "junk at end of %<#pragma push_options%>");
1107 opt_stack
*p
= ggc_alloc
<opt_stack
> ();
1108 p
->prev
= options_stack
;
1111 /* Save optimization and target flags in binary format. */
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. */
1131 handle_pragma_pop_options (cpp_reader
*)
1133 enum cpp_ttype token
;
1137 token
= pragma_lex (&x
);
1138 if (token
!= CPP_EOF
)
1140 warning (OPT_Wpragmas
, "junk at end of %<#pragma pop_options%>");
1144 if (! options_stack
)
1146 warning (OPT_Wpragmas
,
1147 "%<#pragma GCC pop_options%> without a corresponding "
1148 "%<#pragma GCC push_options%>");
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. */
1189 handle_pragma_reset_options (cpp_reader
*)
1191 enum cpp_ttype token
;
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%>");
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. */
1226 handle_pragma_message (cpp_reader
*)
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
)
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
)
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
;
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. */
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
};
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. */
1285 static enum pragma_switch_t
1286 handle_stdc_pragma (const char *pname
)
1290 enum pragma_switch_t ret
;
1292 if (!valid_location_for_stdc_pragma_p ())
1294 warning (OPT_Wpragmas
, "invalid location for %<pragma %s%>, ignored",
1299 if (pragma_lex (&t
) != CPP_NAME
)
1301 warning (OPT_Wpragmas
, "malformed %<#pragma %s%>, ignored", pname
);
1305 arg
= IDENTIFIER_POINTER (t
);
1307 if (!strcmp (arg
, "ON"))
1309 else if (!strcmp (arg
, "OFF"))
1311 else if (!strcmp (arg
, "DEFAULT"))
1312 ret
= PRAGMA_DEFAULT
;
1315 warning (OPT_Wpragmas
, "malformed %<#pragma %s%>, ignored", pname
);
1319 if (pragma_lex (&t
) != CPP_EOF
)
1321 warning (OPT_Wpragmas
, "junk at end of %<#pragma %s%>", pname
);
1329 /* #pragma STDC FLOAT_CONST_DECIMAL64 ON
1330 #pragma STDC FLOAT_CONST_DECIMAL64 OFF
1331 #pragma STDC FLOAT_CONST_DECIMAL64 DEFAULT */
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"
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"
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"))
1361 set_float_const_decimal64 ();
1364 case PRAGMA_DEFAULT
:
1365 clear_float_const_decimal64 ();
1373 /* A vector of registered pragma callbacks, which is never freed. */
1375 static vec
<internal_pragma_handler
> registered_pragmas
;
1377 struct pragma_ns_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
},
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
);
1451 for (i
= 0; i
< n_oacc_pragmas
; ++i
)
1452 if (oacc_pragmas
[i
].id
== id
)
1455 *name
= oacc_pragmas
[i
].name
;
1459 for (i
= 0; i
< n_omp_pragmas
; ++i
)
1460 if (omp_pragmas
[i
].id
== id
)
1463 *name
= omp_pragmas
[i
].name
;
1467 for (i
= 0; i
< n_omp_pragmas_simd
; ++i
)
1468 if (omp_pragmas_simd
[i
].id
== id
)
1471 *name
= omp_pragmas_simd
[i
].name
;
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
;
1486 /* Front-end wrappers for pragma registration to avoid dragging
1487 cpplib.h in almost everywhere. */
1490 c_register_pragma_1 (const char *space
, const char *name
,
1491 internal_pragma_handler ihandler
, bool allow_expansion
)
1495 if (flag_preprocess_only
)
1497 pragma_ns_name ns_name
;
1499 if (!allow_expansion
)
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;
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). */
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
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:
1558 #pragma count (NUMBER)
1560 Name expansion is still disallowed. */
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:
1578 #pragma count (NUMBER)
1580 Name expansion is still disallowed. */
1582 c_register_pragma_with_expansion_and_data (const char *space
, const char *name
,
1583 pragma_handler_2arg handler
,
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);
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
= ®istered_pragmas
[id
];
1603 if (ihandler
->extra_data
)
1605 handler_2arg
= ihandler
->handler
.handler_2arg
;
1606 handler_2arg (parse_in
, ihandler
->data
);
1610 handler_1arg
= ihandler
->handler
.handler_1arg
;
1611 handler_1arg (parse_in
);
1615 /* Set up front-end pragmas. */
1621 const int n_oacc_pragmas
1622 = sizeof (oacc_pragmas
) / sizeof (*oacc_pragmas
);
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);
1632 const int n_omp_pragmas
= sizeof (omp_pragmas
) / sizeof (*omp_pragmas
);
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
);
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,
1658 if (!flag_preprocess_only
)
1659 cpp_register_deferred_pragma (parse_in
, "GCC", "unroll", PRAGMA_UNROLL
,
1662 #ifdef HANDLE_PRAGMA_PACK_WITH_EXPANSION
1663 c_register_pragma_with_expansion (0, "pack", handle_pragma_pack
);
1665 c_register_pragma (0, "pack", handle_pragma_pack
);
1667 c_register_pragma (0, "weak", handle_pragma_weak
);
1669 c_register_pragma ("GCC", "visibility", handle_pragma_visibility
);
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 ();
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
);
1701 // sdcpp #include "gt-c-family-c-pragma.h"