]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/c-family/c-pragma.c
Update copyright years.
[thirdparty/gcc.git] / gcc / c-family / c-pragma.c
1 /* Handle #pragma, system V.4 style. Supports #pragma weak and #pragma pack.
2 Copyright (C) 1992-2017 Free Software Foundation, Inc.
3
4 This file is part of GCC.
5
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.
10
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.
15
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/>. */
19
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
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)
41
42 struct GTY(()) align_stack {
43 int alignment;
44 tree id;
45 struct align_stack * prev;
46 };
47
48 static GTY(()) struct align_stack * alignment_stack;
49
50 static void handle_pragma_pack (cpp_reader *);
51
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))
61
62 static void push_alignment (int, tree);
63 static void pop_alignment (tree);
64
65 /* Push an alignment value onto the stack. */
66 static void
67 push_alignment (int alignment, tree id)
68 {
69 align_stack * entry = ggc_alloc<align_stack> ();
70
71 entry->alignment = alignment;
72 entry->id = id;
73 entry->prev = alignment_stack;
74
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;
80
81 alignment_stack = entry;
82
83 maximum_field_alignment = alignment;
84 }
85
86 /* Undo a push of an alignment onto the stack. */
87 static void
88 pop_alignment (tree id)
89 {
90 align_stack * entry;
91
92 if (alignment_stack == NULL)
93 GCC_BAD ("#pragma pack (pop) encountered without matching #pragma pack (push)");
94
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)
98 {
99 for (entry = alignment_stack; entry; entry = entry->prev)
100 if (entry->id == id)
101 {
102 alignment_stack = entry;
103 break;
104 }
105 if (entry == NULL)
106 warning (OPT_Wpragmas, "\
107 #pragma pack(pop, %E) encountered without matching #pragma pack(push, %E)"
108 , id, id);
109 }
110
111 entry = alignment_stack->prev;
112
113 maximum_field_alignment = entry ? entry->alignment : default_alignment;
114
115 alignment_stack = entry;
116 }
117
118 /* #pragma pack ()
119 #pragma pack (N)
120
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))
129 {
130 tree x, id = 0;
131 int align = -1;
132 enum cpp_ttype token;
133 enum { set, push, pop } action;
134
135 if (pragma_lex (&x) != CPP_OPEN_PAREN)
136 GCC_BAD ("missing %<(%> after %<#pragma pack%> - ignored");
137
138 token = pragma_lex (&x);
139 if (token == CPP_CLOSE_PAREN)
140 {
141 action = set;
142 align = initial_max_fld_align;
143 }
144 else if (token == CPP_NUMBER)
145 {
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");
152 }
153 else if (token == CPP_NAME)
154 {
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)
160
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);
168
169 while ((token = pragma_lex (&x)) == CPP_COMMA)
170 {
171 token = pragma_lex (&x);
172 if (token == CPP_NAME && id == 0)
173 {
174 id = x;
175 }
176 else if (token == CPP_NUMBER && action == push && align == -1)
177 {
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;
183 }
184 else
185 GCC_BAD_ACTION;
186 }
187
188 if (token != CPP_CLOSE_PAREN)
189 GCC_BAD_ACTION;
190 #undef GCC_BAD_ACTION
191 }
192 else
193 GCC_BAD ("malformed %<#pragma pack%> - ignored");
194
195 if (pragma_lex (&x) != CPP_EOF)
196 warning (OPT_Wpragmas, "junk at end of %<#pragma pack%>");
197
198 if (flag_pack_struct)
199 GCC_BAD ("#pragma pack has no effect with -fpack-struct - ignored");
200
201 if (action != pop)
202 switch (align)
203 {
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)
214 {
215 align = maximum_field_alignment;
216 break;
217 }
218 /* FALLTHRU */
219 default:
220 GCC_BAD2 ("alignment must be a small power of two, not %d", align);
221 }
222
223 switch (action)
224 {
225 case set: SET_GLOBAL_ALIGNMENT (align); break;
226 case push: push_alignment (align, id); break;
227 case pop: pop_alignment (id); break;
228 }
229 }
230
231 struct GTY(()) pending_weak
232 {
233 tree name;
234 tree value;
235 };
236
237
238 static GTY(()) vec<pending_weak, va_gc> *pending_weaks;
239
240 static void apply_pragma_weak (tree, tree);
241 static void handle_pragma_weak (cpp_reader *);
242
243 static void
244 apply_pragma_weak (tree decl, tree value)
245 {
246 if (value)
247 {
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)),
252 0);
253 }
254
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);
261
262 declare_weak (decl);
263 }
264
265 void
266 maybe_apply_pragma_weak (tree decl)
267 {
268 tree id;
269 int i;
270 pending_weak *pe;
271
272 /* Avoid asking for DECL_ASSEMBLER_NAME when it's not needed. */
273
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;
286
287 if (DECL_ASSEMBLER_NAME_SET_P (decl))
288 id = DECL_ASSEMBLER_NAME (decl);
289 else
290 {
291 id = DECL_ASSEMBLER_NAME (decl);
292 SET_DECL_ASSEMBLER_NAME (decl, NULL_TREE);
293 }
294
295 FOR_EACH_VEC_ELT (*pending_weaks, i, pe)
296 if (id == pe->name)
297 {
298 apply_pragma_weak (decl, pe->value);
299 pending_weaks->unordered_remove (i);
300 break;
301 }
302 }
303
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)
308 {
309 tree alias_id, id, decl;
310 int i;
311 pending_weak *pe;
312 symtab_node *target;
313
314 if (vec_safe_is_empty (pending_weaks))
315 return;
316
317 FOR_EACH_VEC_ELT (*pending_weaks, i, pe)
318 {
319 alias_id = pe->name;
320 id = pe->value;
321
322 if (id == NULL)
323 continue;
324
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);
329
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)
336 {
337 error ("%q+D aliased to undefined symbol %qE",
338 decl, id);
339 continue;
340 }
341
342 assemble_alias (decl, id);
343 }
344 }
345
346 /* #pragma weak name [= value] */
347 static void
348 handle_pragma_weak (cpp_reader * ARG_UNUSED (dummy))
349 {
350 tree name, value, x, decl;
351 enum cpp_ttype t;
352
353 value = 0;
354
355 if (pragma_lex (&name) != CPP_NAME)
356 GCC_BAD ("malformed #pragma weak, ignored");
357 t = pragma_lex (&x);
358 if (t == CPP_EQ)
359 {
360 if (pragma_lex (&value) != CPP_NAME)
361 GCC_BAD ("malformed #pragma weak, ignored");
362 t = pragma_lex (&x);
363 }
364 if (t != CPP_EOF)
365 warning (OPT_Wpragmas, "junk at end of %<#pragma weak%>");
366
367 decl = identifier_global_value (name);
368 if (decl && DECL_P (decl))
369 {
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)
375 {
376 DECL_EXTERNAL (decl) = 0;
377 if (VAR_P (decl))
378 TREE_STATIC (decl) = 1;
379 assemble_alias (decl, value);
380 }
381 }
382 else
383 {
384 pending_weak pe = {name, value};
385 vec_safe_push (pending_weaks, pe);
386 }
387 }
388
389 static enum scalar_storage_order_kind global_sso;
390
391 void
392 maybe_apply_pragma_scalar_storage_order (tree type)
393 {
394 if (global_sso == SSO_NATIVE)
395 return;
396
397 gcc_assert (RECORD_OR_UNION_TYPE_P (type));
398
399 if (lookup_attribute ("scalar_storage_order", TYPE_ATTRIBUTES (type)))
400 return;
401
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 ();
408 }
409
410 static void
411 handle_pragma_scalar_storage_order (cpp_reader *ARG_UNUSED(dummy))
412 {
413 const char *kind_string;
414 enum cpp_ttype token;
415 tree x;
416
417 if (BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN)
418 error ("scalar_storage_order is not supported");
419
420 token = pragma_lex (&x);
421 if (token != CPP_NAME)
422 GCC_BAD ("missing [big-endian|little-endian|default] after %<#pragma scalar_storage_order%>");
423 kind_string = IDENTIFIER_POINTER (x);
424 if (strcmp (kind_string, "default") == 0)
425 global_sso = default_sso;
426 else if (strcmp (kind_string, "big") == 0)
427 global_sso = SSO_BIG_ENDIAN;
428 else if (strcmp (kind_string, "little") == 0)
429 global_sso = SSO_LITTLE_ENDIAN;
430 else
431 GCC_BAD ("expected [big-endian|little-endian|default] after %<#pragma scalar_storage_order%>");
432 }
433
434 /* GCC supports two #pragma directives for renaming the external
435 symbol associated with a declaration (DECL_ASSEMBLER_NAME), for
436 compatibility with the Solaris and VMS system headers. GCC also
437 has its own notation for this, __asm__("name") annotations.
438
439 Corner cases of these features and their interaction:
440
441 1) Both pragmas silently apply only to declarations with external
442 linkage (that is, TREE_PUBLIC || DECL_EXTERNAL). Asm labels
443 do not have this restriction.
444
445 2) In C++, both #pragmas silently apply only to extern "C" declarations.
446 Asm labels do not have this restriction.
447
448 3) If any of the three ways of changing DECL_ASSEMBLER_NAME is
449 applied to a decl whose DECL_ASSEMBLER_NAME is already set, and the
450 new name is different, a warning issues and the name does not change.
451
452 4) The "source name" for #pragma redefine_extname is the DECL_NAME,
453 *not* the DECL_ASSEMBLER_NAME.
454
455 5) If #pragma extern_prefix is in effect and a declaration occurs
456 with an __asm__ name, the #pragma extern_prefix is silently
457 ignored for that declaration.
458
459 6) If #pragma extern_prefix and #pragma redefine_extname apply to
460 the same declaration, whichever triggered first wins, and a warning
461 is issued. (We would like to have #pragma redefine_extname always
462 win, but it can appear either before or after the declaration, and
463 if it appears afterward, we have no way of knowing whether a modified
464 DECL_ASSEMBLER_NAME is due to #pragma extern_prefix.) */
465
466 struct GTY(()) pending_redefinition {
467 tree oldname;
468 tree newname;
469 };
470
471
472 static GTY(()) vec<pending_redefinition, va_gc> *pending_redefine_extname;
473
474 static void handle_pragma_redefine_extname (cpp_reader *);
475
476 /* #pragma redefine_extname oldname newname */
477 static void
478 handle_pragma_redefine_extname (cpp_reader * ARG_UNUSED (dummy))
479 {
480 tree oldname, newname, decls, x;
481 enum cpp_ttype t;
482 bool found;
483
484 if (pragma_lex (&oldname) != CPP_NAME)
485 GCC_BAD ("malformed #pragma redefine_extname, ignored");
486 if (pragma_lex (&newname) != CPP_NAME)
487 GCC_BAD ("malformed #pragma redefine_extname, ignored");
488 t = pragma_lex (&x);
489 if (t != CPP_EOF)
490 warning (OPT_Wpragmas, "junk at end of %<#pragma redefine_extname%>");
491
492 found = false;
493 for (decls = c_linkage_bindings (oldname);
494 decls; )
495 {
496 tree decl;
497 if (TREE_CODE (decls) == TREE_LIST)
498 {
499 decl = TREE_VALUE (decls);
500 decls = TREE_CHAIN (decls);
501 }
502 else
503 {
504 decl = decls;
505 decls = NULL_TREE;
506 }
507
508 if ((TREE_PUBLIC (decl) || DECL_EXTERNAL (decl))
509 && VAR_OR_FUNCTION_DECL_P (decl))
510 {
511 found = true;
512 if (DECL_ASSEMBLER_NAME_SET_P (decl))
513 {
514 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
515 name = targetm.strip_name_encoding (name);
516
517 if (strcmp (name, IDENTIFIER_POINTER (newname)))
518 warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
519 "conflict with previous rename");
520 }
521 else
522 symtab->change_decl_assembler_name (decl, newname);
523 }
524 }
525
526 if (!found)
527 /* We have to add this to the rename list even if there's already
528 a global value that doesn't meet the above criteria, because in
529 C++ "struct foo {...};" puts "foo" in the current namespace but
530 does *not* conflict with a subsequent declaration of a function
531 or variable foo. See g++.dg/other/pragma-re-2.C. */
532 add_to_renaming_pragma_list (oldname, newname);
533 }
534
535 /* This is called from here and from ia64-c.c. */
536 void
537 add_to_renaming_pragma_list (tree oldname, tree newname)
538 {
539 unsigned ix;
540 pending_redefinition *p;
541
542 FOR_EACH_VEC_SAFE_ELT (pending_redefine_extname, ix, p)
543 if (oldname == p->oldname)
544 {
545 if (p->newname != newname)
546 warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
547 "conflict with previous #pragma redefine_extname");
548 return;
549 }
550
551 pending_redefinition e = {oldname, newname};
552 vec_safe_push (pending_redefine_extname, e);
553 }
554
555 /* The current prefix set by #pragma extern_prefix. */
556 GTY(()) tree pragma_extern_prefix;
557
558 /* Hook from the front ends to apply the results of one of the preceding
559 pragmas that rename variables. */
560
561 tree
562 maybe_apply_renaming_pragma (tree decl, tree asmname)
563 {
564 unsigned ix;
565 pending_redefinition *p;
566
567 /* The renaming pragmas are only applied to declarations with
568 external linkage. */
569 if (!VAR_OR_FUNCTION_DECL_P (decl)
570 || (!TREE_PUBLIC (decl) && !DECL_EXTERNAL (decl))
571 || !has_c_linkage (decl))
572 return asmname;
573
574 /* If the DECL_ASSEMBLER_NAME is already set, it does not change,
575 but we may warn about a rename that conflicts. */
576 if (DECL_ASSEMBLER_NAME_SET_P (decl))
577 {
578 const char *oldname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
579 oldname = targetm.strip_name_encoding (oldname);
580
581 if (asmname && strcmp (TREE_STRING_POINTER (asmname), oldname))
582 warning (OPT_Wpragmas, "asm declaration ignored due to "
583 "conflict with previous rename");
584
585 /* Take any pending redefine_extname off the list. */
586 FOR_EACH_VEC_SAFE_ELT (pending_redefine_extname, ix, p)
587 if (DECL_NAME (decl) == p->oldname)
588 {
589 /* Only warn if there is a conflict. */
590 if (strcmp (IDENTIFIER_POINTER (p->newname), oldname))
591 warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
592 "conflict with previous rename");
593
594 pending_redefine_extname->unordered_remove (ix);
595 break;
596 }
597 return 0;
598 }
599
600 /* Find out if we have a pending #pragma redefine_extname. */
601 FOR_EACH_VEC_SAFE_ELT (pending_redefine_extname, ix, p)
602 if (DECL_NAME (decl) == p->oldname)
603 {
604 tree newname = p->newname;
605 pending_redefine_extname->unordered_remove (ix);
606
607 /* If we already have an asmname, #pragma redefine_extname is
608 ignored (with a warning if it conflicts). */
609 if (asmname)
610 {
611 if (strcmp (TREE_STRING_POINTER (asmname),
612 IDENTIFIER_POINTER (newname)) != 0)
613 warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
614 "conflict with __asm__ declaration");
615 return asmname;
616 }
617
618 /* Otherwise we use what we've got; #pragma extern_prefix is
619 silently ignored. */
620 return build_string (IDENTIFIER_LENGTH (newname),
621 IDENTIFIER_POINTER (newname));
622 }
623
624 /* If we've got an asmname, #pragma extern_prefix is silently ignored. */
625 if (asmname)
626 return asmname;
627
628 /* If #pragma extern_prefix is in effect, apply it. */
629 if (pragma_extern_prefix)
630 {
631 const char *prefix = TREE_STRING_POINTER (pragma_extern_prefix);
632 size_t plen = TREE_STRING_LENGTH (pragma_extern_prefix) - 1;
633
634 const char *id = IDENTIFIER_POINTER (DECL_NAME (decl));
635 size_t ilen = IDENTIFIER_LENGTH (DECL_NAME (decl));
636
637 char *newname = (char *) alloca (plen + ilen + 1);
638
639 memcpy (newname, prefix, plen);
640 memcpy (newname + plen, id, ilen + 1);
641
642 return build_string (plen + ilen, newname);
643 }
644
645 /* Nada. */
646 return 0;
647 }
648
649
650 static void handle_pragma_visibility (cpp_reader *);
651
652 static vec<int> visstack;
653
654 /* Push the visibility indicated by STR onto the top of the #pragma
655 visibility stack. KIND is 0 for #pragma GCC visibility, 1 for
656 C++ namespace with visibility attribute and 2 for C++ builtin
657 ABI namespace. push_visibility/pop_visibility calls must have
658 matching KIND, it is not allowed to push visibility using one
659 KIND and pop using a different one. */
660
661 void
662 push_visibility (const char *str, int kind)
663 {
664 visstack.safe_push (((int) default_visibility) | (kind << 8));
665 if (!strcmp (str, "default"))
666 default_visibility = VISIBILITY_DEFAULT;
667 else if (!strcmp (str, "internal"))
668 default_visibility = VISIBILITY_INTERNAL;
669 else if (!strcmp (str, "hidden"))
670 default_visibility = VISIBILITY_HIDDEN;
671 else if (!strcmp (str, "protected"))
672 default_visibility = VISIBILITY_PROTECTED;
673 else
674 GCC_BAD ("#pragma GCC visibility push() must specify default, internal, hidden or protected");
675 visibility_options.inpragma = 1;
676 }
677
678 /* Pop a level of the #pragma visibility stack. Return true if
679 successful. */
680
681 bool
682 pop_visibility (int kind)
683 {
684 if (!visstack.length ())
685 return false;
686 if ((visstack.last () >> 8) != kind)
687 return false;
688 default_visibility
689 = (enum symbol_visibility) (visstack.pop () & 0xff);
690 visibility_options.inpragma
691 = visstack.length () != 0;
692 return true;
693 }
694
695 /* Sets the default visibility for symbols to something other than that
696 specified on the command line. */
697
698 static void
699 handle_pragma_visibility (cpp_reader *dummy ATTRIBUTE_UNUSED)
700 {
701 /* Form is #pragma GCC visibility push(hidden)|pop */
702 tree x;
703 enum cpp_ttype token;
704 enum { bad, push, pop } action = bad;
705
706 token = pragma_lex (&x);
707 if (token == CPP_NAME)
708 {
709 const char *op = IDENTIFIER_POINTER (x);
710 if (!strcmp (op, "push"))
711 action = push;
712 else if (!strcmp (op, "pop"))
713 action = pop;
714 }
715 if (bad == action)
716 GCC_BAD ("#pragma GCC visibility must be followed by push or pop");
717 else
718 {
719 if (pop == action)
720 {
721 if (! pop_visibility (0))
722 GCC_BAD ("no matching push for %<#pragma GCC visibility pop%>");
723 }
724 else
725 {
726 if (pragma_lex (&x) != CPP_OPEN_PAREN)
727 GCC_BAD ("missing %<(%> after %<#pragma GCC visibility push%> - ignored");
728 token = pragma_lex (&x);
729 if (token != CPP_NAME)
730 GCC_BAD ("malformed #pragma GCC visibility push");
731 else
732 push_visibility (IDENTIFIER_POINTER (x), 0);
733 if (pragma_lex (&x) != CPP_CLOSE_PAREN)
734 GCC_BAD ("missing %<(%> after %<#pragma GCC visibility push%> - ignored");
735 }
736 }
737 if (pragma_lex (&x) != CPP_EOF)
738 warning (OPT_Wpragmas, "junk at end of %<#pragma GCC visibility%>");
739 }
740
741 static void
742 handle_pragma_diagnostic(cpp_reader *ARG_UNUSED(dummy))
743 {
744 tree x;
745 location_t loc;
746 enum cpp_ttype token = pragma_lex (&x, &loc);
747 if (token != CPP_NAME)
748 {
749 warning_at (loc, OPT_Wpragmas,
750 "missing [error|warning|ignored|push|pop]"
751 " after %<#pragma GCC diagnostic%>");
752 return;
753 }
754
755 diagnostic_t kind;
756 const char *kind_string = IDENTIFIER_POINTER (x);
757 if (strcmp (kind_string, "error") == 0)
758 kind = DK_ERROR;
759 else if (strcmp (kind_string, "warning") == 0)
760 kind = DK_WARNING;
761 else if (strcmp (kind_string, "ignored") == 0)
762 kind = DK_IGNORED;
763 else if (strcmp (kind_string, "push") == 0)
764 {
765 diagnostic_push_diagnostics (global_dc, input_location);
766 return;
767 }
768 else if (strcmp (kind_string, "pop") == 0)
769 {
770 diagnostic_pop_diagnostics (global_dc, input_location);
771 return;
772 }
773 else
774 {
775 warning_at (loc, OPT_Wpragmas,
776 "expected [error|warning|ignored|push|pop]"
777 " after %<#pragma GCC diagnostic%>");
778 return;
779 }
780
781 token = pragma_lex (&x, &loc);
782 if (token != CPP_STRING)
783 {
784 warning_at (loc, OPT_Wpragmas,
785 "missing option after %<#pragma GCC diagnostic%> kind");
786 return;
787 }
788
789 const char *option_string = TREE_STRING_POINTER (x);
790 unsigned int lang_mask = c_common_option_lang_mask () | CL_COMMON;
791 /* option_string + 1 to skip the initial '-' */
792 unsigned int option_index = find_opt (option_string + 1, lang_mask);
793 if (option_index == OPT_SPECIAL_unknown)
794 {
795 warning_at (loc, OPT_Wpragmas,
796 "unknown option after %<#pragma GCC diagnostic%> kind");
797 return;
798 }
799 else if (!(cl_options[option_index].flags & CL_WARNING))
800 {
801 warning_at (loc, OPT_Wpragmas,
802 "%qs is not an option that controls warnings", option_string);
803 return;
804 }
805 else if (!(cl_options[option_index].flags & lang_mask))
806 {
807 char *ok_langs = write_langs (cl_options[option_index].flags);
808 char *bad_lang = write_langs (c_common_option_lang_mask ());
809 warning_at (loc, OPT_Wpragmas,
810 "option %qs is valid for %s but not for %s",
811 option_string, ok_langs, bad_lang);
812 free (ok_langs);
813 free (bad_lang);
814 return;
815 }
816
817 struct cl_option_handlers handlers;
818 set_default_handlers (&handlers);
819 const char *arg = NULL;
820 if (cl_options[option_index].flags & CL_JOINED)
821 arg = option_string + 1 + cl_options[option_index].opt_len;
822 /* FIXME: input_location isn't the best location here, but it is
823 what we used to do here before and changing it breaks e.g.
824 PR69543 and PR69558. */
825 control_warning_option (option_index, (int) kind,
826 arg, kind != DK_IGNORED,
827 input_location, lang_mask, &handlers,
828 &global_options, &global_options_set,
829 global_dc);
830 }
831
832 /* Parse #pragma GCC target (xxx) to set target specific options. */
833 static void
834 handle_pragma_target(cpp_reader *ARG_UNUSED(dummy))
835 {
836 enum cpp_ttype token;
837 tree x;
838 bool close_paren_needed_p = false;
839
840 if (cfun)
841 {
842 error ("#pragma GCC option is not allowed inside functions");
843 return;
844 }
845
846 token = pragma_lex (&x);
847 if (token == CPP_OPEN_PAREN)
848 {
849 close_paren_needed_p = true;
850 token = pragma_lex (&x);
851 }
852
853 if (token != CPP_STRING)
854 {
855 GCC_BAD ("%<#pragma GCC option%> is not a string");
856 return;
857 }
858
859 /* Strings are user options. */
860 else
861 {
862 tree args = NULL_TREE;
863
864 do
865 {
866 /* Build up the strings now as a tree linked list. Skip empty
867 strings. */
868 if (TREE_STRING_LENGTH (x) > 0)
869 args = tree_cons (NULL_TREE, x, args);
870
871 token = pragma_lex (&x);
872 while (token == CPP_COMMA)
873 token = pragma_lex (&x);
874 }
875 while (token == CPP_STRING);
876
877 if (close_paren_needed_p)
878 {
879 if (token == CPP_CLOSE_PAREN)
880 token = pragma_lex (&x);
881 else
882 GCC_BAD ("%<#pragma GCC target (string [,string]...)%> does "
883 "not have a final %<)%>");
884 }
885
886 if (token != CPP_EOF)
887 {
888 error ("#pragma GCC target string... is badly formed");
889 return;
890 }
891
892 /* put arguments in the order the user typed them. */
893 args = nreverse (args);
894
895 if (targetm.target_option.pragma_parse (args, NULL_TREE))
896 current_target_pragma = chainon (current_target_pragma, args);
897 }
898 }
899
900 /* Handle #pragma GCC optimize to set optimization options. */
901 static void
902 handle_pragma_optimize (cpp_reader *ARG_UNUSED(dummy))
903 {
904 enum cpp_ttype token;
905 tree x;
906 bool close_paren_needed_p = false;
907 tree optimization_previous_node = optimization_current_node;
908
909 if (cfun)
910 {
911 error ("#pragma GCC optimize is not allowed inside functions");
912 return;
913 }
914
915 token = pragma_lex (&x);
916 if (token == CPP_OPEN_PAREN)
917 {
918 close_paren_needed_p = true;
919 token = pragma_lex (&x);
920 }
921
922 if (token != CPP_STRING && token != CPP_NUMBER)
923 {
924 GCC_BAD ("%<#pragma GCC optimize%> is not a string or number");
925 return;
926 }
927
928 /* Strings/numbers are user options. */
929 else
930 {
931 tree args = NULL_TREE;
932
933 do
934 {
935 /* Build up the numbers/strings now as a list. */
936 if (token != CPP_STRING || TREE_STRING_LENGTH (x) > 0)
937 args = tree_cons (NULL_TREE, x, args);
938
939 token = pragma_lex (&x);
940 while (token == CPP_COMMA)
941 token = pragma_lex (&x);
942 }
943 while (token == CPP_STRING || token == CPP_NUMBER);
944
945 if (close_paren_needed_p)
946 {
947 if (token == CPP_CLOSE_PAREN)
948 token = pragma_lex (&x);
949 else
950 GCC_BAD ("%<#pragma GCC optimize (string [,string]...)%> does "
951 "not have a final %<)%>");
952 }
953
954 if (token != CPP_EOF)
955 {
956 error ("#pragma GCC optimize string... is badly formed");
957 return;
958 }
959
960 /* put arguments in the order the user typed them. */
961 args = nreverse (args);
962
963 parse_optimize_options (args, false);
964 current_optimize_pragma = chainon (current_optimize_pragma, args);
965 optimization_current_node = build_optimization_node (&global_options);
966 c_cpp_builtins_optimize_pragma (parse_in,
967 optimization_previous_node,
968 optimization_current_node);
969 }
970 }
971
972 /* Stack of the #pragma GCC options created with #pragma GCC push_option. Save
973 both the binary representation of the options and the TREE_LIST of
974 strings that will be added to the function's attribute list. */
975 struct GTY(()) opt_stack {
976 struct opt_stack *prev;
977 tree target_binary;
978 tree target_strings;
979 tree optimize_binary;
980 tree optimize_strings;
981 };
982
983 static GTY(()) struct opt_stack * options_stack;
984
985 /* Handle #pragma GCC push_options to save the current target and optimization
986 options. */
987
988 static void
989 handle_pragma_push_options (cpp_reader *ARG_UNUSED(dummy))
990 {
991 enum cpp_ttype token;
992 tree x = 0;
993
994 token = pragma_lex (&x);
995 if (token != CPP_EOF)
996 {
997 warning (OPT_Wpragmas, "junk at end of %<#pragma push_options%>");
998 return;
999 }
1000
1001 opt_stack *p = ggc_alloc<opt_stack> ();
1002 p->prev = options_stack;
1003 options_stack = p;
1004
1005 /* Save optimization and target flags in binary format. */
1006 p->optimize_binary = build_optimization_node (&global_options);
1007 p->target_binary = build_target_option_node (&global_options);
1008
1009 /* Save optimization and target flags in string list format. */
1010 p->optimize_strings = copy_list (current_optimize_pragma);
1011 p->target_strings = copy_list (current_target_pragma);
1012 }
1013
1014 /* Handle #pragma GCC pop_options to restore the current target and
1015 optimization options from a previous push_options. */
1016
1017 static void
1018 handle_pragma_pop_options (cpp_reader *ARG_UNUSED(dummy))
1019 {
1020 enum cpp_ttype token;
1021 tree x = 0;
1022 opt_stack *p;
1023
1024 token = pragma_lex (&x);
1025 if (token != CPP_EOF)
1026 {
1027 warning (OPT_Wpragmas, "junk at end of %<#pragma pop_options%>");
1028 return;
1029 }
1030
1031 if (! options_stack)
1032 {
1033 warning (OPT_Wpragmas,
1034 "%<#pragma GCC pop_options%> without a corresponding "
1035 "%<#pragma GCC push_options%>");
1036 return;
1037 }
1038
1039 p = options_stack;
1040 options_stack = p->prev;
1041
1042 if (p->target_binary != target_option_current_node)
1043 {
1044 (void) targetm.target_option.pragma_parse (NULL_TREE, p->target_binary);
1045 target_option_current_node = p->target_binary;
1046 }
1047
1048 if (p->optimize_binary != optimization_current_node)
1049 {
1050 tree old_optimize = optimization_current_node;
1051 cl_optimization_restore (&global_options,
1052 TREE_OPTIMIZATION (p->optimize_binary));
1053 c_cpp_builtins_optimize_pragma (parse_in, old_optimize,
1054 p->optimize_binary);
1055 optimization_current_node = p->optimize_binary;
1056 }
1057
1058 current_target_pragma = p->target_strings;
1059 current_optimize_pragma = p->optimize_strings;
1060 }
1061
1062 /* Handle #pragma GCC reset_options to restore the current target and
1063 optimization options to the original options used on the command line. */
1064
1065 static void
1066 handle_pragma_reset_options (cpp_reader *ARG_UNUSED(dummy))
1067 {
1068 enum cpp_ttype token;
1069 tree x = 0;
1070 tree new_optimize = optimization_default_node;
1071 tree new_target = target_option_default_node;
1072
1073 token = pragma_lex (&x);
1074 if (token != CPP_EOF)
1075 {
1076 warning (OPT_Wpragmas, "junk at end of %<#pragma reset_options%>");
1077 return;
1078 }
1079
1080 if (new_target != target_option_current_node)
1081 {
1082 (void) targetm.target_option.pragma_parse (NULL_TREE, new_target);
1083 target_option_current_node = new_target;
1084 }
1085
1086 if (new_optimize != optimization_current_node)
1087 {
1088 tree old_optimize = optimization_current_node;
1089 cl_optimization_restore (&global_options,
1090 TREE_OPTIMIZATION (new_optimize));
1091 c_cpp_builtins_optimize_pragma (parse_in, old_optimize, new_optimize);
1092 optimization_current_node = new_optimize;
1093 }
1094
1095 current_target_pragma = NULL_TREE;
1096 current_optimize_pragma = NULL_TREE;
1097 }
1098
1099 /* Print a plain user-specified message. */
1100
1101 static void
1102 handle_pragma_message (cpp_reader *ARG_UNUSED(dummy))
1103 {
1104 enum cpp_ttype token;
1105 tree x, message = 0;
1106
1107 token = pragma_lex (&x);
1108 if (token == CPP_OPEN_PAREN)
1109 {
1110 token = pragma_lex (&x);
1111 if (token == CPP_STRING)
1112 message = x;
1113 else
1114 GCC_BAD ("expected a string after %<#pragma message%>");
1115 if (pragma_lex (&x) != CPP_CLOSE_PAREN)
1116 GCC_BAD ("malformed %<#pragma message%>, ignored");
1117 }
1118 else if (token == CPP_STRING)
1119 message = x;
1120 else
1121 GCC_BAD ("expected a string after %<#pragma message%>");
1122
1123 gcc_assert (message);
1124
1125 if (pragma_lex (&x) != CPP_EOF)
1126 warning (OPT_Wpragmas, "junk at end of %<#pragma message%>");
1127
1128 if (TREE_STRING_LENGTH (message) > 1)
1129 inform (input_location, "#pragma message: %s", TREE_STRING_POINTER (message));
1130 }
1131
1132 /* Mark whether the current location is valid for a STDC pragma. */
1133
1134 static bool valid_location_for_stdc_pragma;
1135
1136 void
1137 mark_valid_location_for_stdc_pragma (bool flag)
1138 {
1139 valid_location_for_stdc_pragma = flag;
1140 }
1141
1142 /* Return true if the current location is valid for a STDC pragma. */
1143
1144 bool
1145 valid_location_for_stdc_pragma_p (void)
1146 {
1147 return valid_location_for_stdc_pragma;
1148 }
1149
1150 enum pragma_switch_t { PRAGMA_ON, PRAGMA_OFF, PRAGMA_DEFAULT, PRAGMA_BAD };
1151
1152 /* A STDC pragma must appear outside of external declarations or
1153 preceding all explicit declarations and statements inside a compound
1154 statement; its behavior is undefined if used in any other context.
1155 It takes a switch of ON, OFF, or DEFAULT. */
1156
1157 static enum pragma_switch_t
1158 handle_stdc_pragma (const char *pname)
1159 {
1160 const char *arg;
1161 tree t;
1162 enum pragma_switch_t ret;
1163
1164 if (!valid_location_for_stdc_pragma_p ())
1165 {
1166 warning (OPT_Wpragmas, "invalid location for %<pragma %s%>, ignored",
1167 pname);
1168 return PRAGMA_BAD;
1169 }
1170
1171 if (pragma_lex (&t) != CPP_NAME)
1172 {
1173 warning (OPT_Wpragmas, "malformed %<#pragma %s%>, ignored", pname);
1174 return PRAGMA_BAD;
1175 }
1176
1177 arg = IDENTIFIER_POINTER (t);
1178
1179 if (!strcmp (arg, "ON"))
1180 ret = PRAGMA_ON;
1181 else if (!strcmp (arg, "OFF"))
1182 ret = PRAGMA_OFF;
1183 else if (!strcmp (arg, "DEFAULT"))
1184 ret = PRAGMA_DEFAULT;
1185 else
1186 {
1187 warning (OPT_Wpragmas, "malformed %<#pragma %s%>, ignored", pname);
1188 return PRAGMA_BAD;
1189 }
1190
1191 if (pragma_lex (&t) != CPP_EOF)
1192 {
1193 warning (OPT_Wpragmas, "junk at end of %<#pragma %s%>", pname);
1194 return PRAGMA_BAD;
1195 }
1196
1197 return ret;
1198 }
1199
1200 /* #pragma STDC FLOAT_CONST_DECIMAL64 ON
1201 #pragma STDC FLOAT_CONST_DECIMAL64 OFF
1202 #pragma STDC FLOAT_CONST_DECIMAL64 DEFAULT */
1203
1204 static void
1205 handle_pragma_float_const_decimal64 (cpp_reader *ARG_UNUSED (dummy))
1206 {
1207 if (c_dialect_cxx ())
1208 {
1209 if (warn_unknown_pragmas > in_system_header_at (input_location))
1210 warning (OPT_Wunknown_pragmas,
1211 "%<#pragma STDC FLOAT_CONST_DECIMAL64%> is not supported"
1212 " for C++");
1213 return;
1214 }
1215
1216 if (!targetm.decimal_float_supported_p ())
1217 {
1218 if (warn_unknown_pragmas > in_system_header_at (input_location))
1219 warning (OPT_Wunknown_pragmas,
1220 "%<#pragma STDC FLOAT_CONST_DECIMAL64%> is not supported"
1221 " on this target");
1222 return;
1223 }
1224
1225 pedwarn (input_location, OPT_Wpedantic,
1226 "ISO C does not support %<#pragma STDC FLOAT_CONST_DECIMAL64%>");
1227
1228 switch (handle_stdc_pragma ("STDC FLOAT_CONST_DECIMAL64"))
1229 {
1230 case PRAGMA_ON:
1231 set_float_const_decimal64 ();
1232 break;
1233 case PRAGMA_OFF:
1234 case PRAGMA_DEFAULT:
1235 clear_float_const_decimal64 ();
1236 break;
1237 case PRAGMA_BAD:
1238 break;
1239 }
1240 }
1241
1242 /* A vector of registered pragma callbacks, which is never freed. */
1243
1244 static vec<internal_pragma_handler> registered_pragmas;
1245
1246 struct pragma_ns_name
1247 {
1248 const char *space;
1249 const char *name;
1250 };
1251
1252
1253 static vec<pragma_ns_name> registered_pp_pragmas;
1254
1255 struct omp_pragma_def { const char *name; unsigned int id; };
1256 static const struct omp_pragma_def oacc_pragmas[] = {
1257 { "atomic", PRAGMA_OACC_ATOMIC },
1258 { "cache", PRAGMA_OACC_CACHE },
1259 { "data", PRAGMA_OACC_DATA },
1260 { "declare", PRAGMA_OACC_DECLARE },
1261 { "enter", PRAGMA_OACC_ENTER_DATA },
1262 { "exit", PRAGMA_OACC_EXIT_DATA },
1263 { "host_data", PRAGMA_OACC_HOST_DATA },
1264 { "kernels", PRAGMA_OACC_KERNELS },
1265 { "loop", PRAGMA_OACC_LOOP },
1266 { "parallel", PRAGMA_OACC_PARALLEL },
1267 { "routine", PRAGMA_OACC_ROUTINE },
1268 { "update", PRAGMA_OACC_UPDATE },
1269 { "wait", PRAGMA_OACC_WAIT }
1270 };
1271 static const struct omp_pragma_def omp_pragmas[] = {
1272 { "atomic", PRAGMA_OMP_ATOMIC },
1273 { "barrier", PRAGMA_OMP_BARRIER },
1274 { "cancel", PRAGMA_OMP_CANCEL },
1275 { "cancellation", PRAGMA_OMP_CANCELLATION_POINT },
1276 { "critical", PRAGMA_OMP_CRITICAL },
1277 { "end", PRAGMA_OMP_END_DECLARE_TARGET },
1278 { "flush", PRAGMA_OMP_FLUSH },
1279 { "master", PRAGMA_OMP_MASTER },
1280 { "ordered", PRAGMA_OMP_ORDERED },
1281 { "section", PRAGMA_OMP_SECTION },
1282 { "sections", PRAGMA_OMP_SECTIONS },
1283 { "single", PRAGMA_OMP_SINGLE },
1284 { "task", PRAGMA_OMP_TASK },
1285 { "taskgroup", PRAGMA_OMP_TASKGROUP },
1286 { "taskwait", PRAGMA_OMP_TASKWAIT },
1287 { "taskyield", PRAGMA_OMP_TASKYIELD },
1288 { "threadprivate", PRAGMA_OMP_THREADPRIVATE }
1289 };
1290 static const struct omp_pragma_def omp_pragmas_simd[] = {
1291 { "declare", PRAGMA_OMP_DECLARE },
1292 { "distribute", PRAGMA_OMP_DISTRIBUTE },
1293 { "for", PRAGMA_OMP_FOR },
1294 { "parallel", PRAGMA_OMP_PARALLEL },
1295 { "simd", PRAGMA_OMP_SIMD },
1296 { "target", PRAGMA_OMP_TARGET },
1297 { "taskloop", PRAGMA_OMP_TASKLOOP },
1298 { "teams", PRAGMA_OMP_TEAMS },
1299 };
1300
1301 void
1302 c_pp_lookup_pragma (unsigned int id, const char **space, const char **name)
1303 {
1304 const int n_oacc_pragmas = sizeof (oacc_pragmas) / sizeof (*oacc_pragmas);
1305 const int n_omp_pragmas = sizeof (omp_pragmas) / sizeof (*omp_pragmas);
1306 const int n_omp_pragmas_simd = sizeof (omp_pragmas_simd)
1307 / sizeof (*omp_pragmas);
1308 int i;
1309
1310 for (i = 0; i < n_oacc_pragmas; ++i)
1311 if (oacc_pragmas[i].id == id)
1312 {
1313 *space = "acc";
1314 *name = oacc_pragmas[i].name;
1315 return;
1316 }
1317
1318 for (i = 0; i < n_omp_pragmas; ++i)
1319 if (omp_pragmas[i].id == id)
1320 {
1321 *space = "omp";
1322 *name = omp_pragmas[i].name;
1323 return;
1324 }
1325
1326 for (i = 0; i < n_omp_pragmas_simd; ++i)
1327 if (omp_pragmas_simd[i].id == id)
1328 {
1329 *space = "omp";
1330 *name = omp_pragmas_simd[i].name;
1331 return;
1332 }
1333
1334 if (id == PRAGMA_CILK_SIMD)
1335 {
1336 *space = NULL;
1337 *name = "simd";
1338 return;
1339 }
1340
1341 if (id == PRAGMA_CILK_GRAINSIZE)
1342 {
1343 *space = "cilk";
1344 *name = "grainsize";
1345 return;
1346 }
1347
1348 if (id >= PRAGMA_FIRST_EXTERNAL
1349 && (id < PRAGMA_FIRST_EXTERNAL + registered_pp_pragmas.length ()))
1350 {
1351 *space = registered_pp_pragmas[id - PRAGMA_FIRST_EXTERNAL].space;
1352 *name = registered_pp_pragmas[id - PRAGMA_FIRST_EXTERNAL].name;
1353 return;
1354 }
1355
1356 gcc_unreachable ();
1357 }
1358
1359 /* Front-end wrappers for pragma registration to avoid dragging
1360 cpplib.h in almost everywhere. */
1361
1362 static void
1363 c_register_pragma_1 (const char *space, const char *name,
1364 internal_pragma_handler ihandler, bool allow_expansion)
1365 {
1366 unsigned id;
1367
1368 if (flag_preprocess_only)
1369 {
1370 pragma_ns_name ns_name;
1371
1372 if (!allow_expansion)
1373 return;
1374
1375 ns_name.space = space;
1376 ns_name.name = name;
1377 registered_pp_pragmas.safe_push (ns_name);
1378 id = registered_pp_pragmas.length ();
1379 id += PRAGMA_FIRST_EXTERNAL - 1;
1380 }
1381 else
1382 {
1383 registered_pragmas.safe_push (ihandler);
1384 id = registered_pragmas.length ();
1385 id += PRAGMA_FIRST_EXTERNAL - 1;
1386
1387 /* The C front end allocates 8 bits in c_token. The C++ front end
1388 keeps the pragma kind in the form of INTEGER_CST, so no small
1389 limit applies. At present this is sufficient. */
1390 gcc_assert (id < 256);
1391 }
1392
1393 cpp_register_deferred_pragma (parse_in, space, name, id,
1394 allow_expansion, false);
1395 }
1396
1397 /* Register a C pragma handler, using a space and a name. It disallows pragma
1398 expansion (if you want it, use c_register_pragma_with_expansion instead). */
1399 void
1400 c_register_pragma (const char *space, const char *name,
1401 pragma_handler_1arg handler)
1402 {
1403 internal_pragma_handler ihandler;
1404
1405 ihandler.handler.handler_1arg = handler;
1406 ihandler.extra_data = false;
1407 ihandler.data = NULL;
1408 c_register_pragma_1 (space, name, ihandler, false);
1409 }
1410
1411 /* Register a C pragma handler, using a space and a name, it also carries an
1412 extra data field which can be used by the handler. It disallows pragma
1413 expansion (if you want it, use c_register_pragma_with_expansion_and_data
1414 instead). */
1415 void
1416 c_register_pragma_with_data (const char *space, const char *name,
1417 pragma_handler_2arg handler, void * data)
1418 {
1419 internal_pragma_handler ihandler;
1420
1421 ihandler.handler.handler_2arg = handler;
1422 ihandler.extra_data = true;
1423 ihandler.data = data;
1424 c_register_pragma_1 (space, name, ihandler, false);
1425 }
1426
1427 /* Register a C pragma handler, using a space and a name. It allows pragma
1428 expansion as in the following example:
1429
1430 #define NUMBER 10
1431 #pragma count (NUMBER)
1432
1433 Name expansion is still disallowed. */
1434 void
1435 c_register_pragma_with_expansion (const char *space, const char *name,
1436 pragma_handler_1arg handler)
1437 {
1438 internal_pragma_handler ihandler;
1439
1440 ihandler.handler.handler_1arg = handler;
1441 ihandler.extra_data = false;
1442 ihandler.data = NULL;
1443 c_register_pragma_1 (space, name, ihandler, true);
1444 }
1445
1446 /* Register a C pragma handler, using a space and a name, it also carries an
1447 extra data field which can be used by the handler. It allows pragma
1448 expansion as in the following example:
1449
1450 #define NUMBER 10
1451 #pragma count (NUMBER)
1452
1453 Name expansion is still disallowed. */
1454 void
1455 c_register_pragma_with_expansion_and_data (const char *space, const char *name,
1456 pragma_handler_2arg handler,
1457 void *data)
1458 {
1459 internal_pragma_handler ihandler;
1460
1461 ihandler.handler.handler_2arg = handler;
1462 ihandler.extra_data = true;
1463 ihandler.data = data;
1464 c_register_pragma_1 (space, name, ihandler, true);
1465 }
1466
1467 void
1468 c_invoke_pragma_handler (unsigned int id)
1469 {
1470 internal_pragma_handler *ihandler;
1471 pragma_handler_1arg handler_1arg;
1472 pragma_handler_2arg handler_2arg;
1473
1474 id -= PRAGMA_FIRST_EXTERNAL;
1475 ihandler = &registered_pragmas[id];
1476 if (ihandler->extra_data)
1477 {
1478 handler_2arg = ihandler->handler.handler_2arg;
1479 handler_2arg (parse_in, ihandler->data);
1480 }
1481 else
1482 {
1483 handler_1arg = ihandler->handler.handler_1arg;
1484 handler_1arg (parse_in);
1485 }
1486 }
1487
1488 /* Set up front-end pragmas. */
1489 void
1490 init_pragma (void)
1491 {
1492 if (flag_openacc)
1493 {
1494 const int n_oacc_pragmas
1495 = sizeof (oacc_pragmas) / sizeof (*oacc_pragmas);
1496 int i;
1497
1498 for (i = 0; i < n_oacc_pragmas; ++i)
1499 cpp_register_deferred_pragma (parse_in, "acc", oacc_pragmas[i].name,
1500 oacc_pragmas[i].id, true, true);
1501 }
1502
1503 if (flag_openmp)
1504 {
1505 const int n_omp_pragmas = sizeof (omp_pragmas) / sizeof (*omp_pragmas);
1506 int i;
1507
1508 for (i = 0; i < n_omp_pragmas; ++i)
1509 cpp_register_deferred_pragma (parse_in, "omp", omp_pragmas[i].name,
1510 omp_pragmas[i].id, true, true);
1511 }
1512 if (flag_openmp || flag_openmp_simd)
1513 {
1514 const int n_omp_pragmas_simd = sizeof (omp_pragmas_simd)
1515 / sizeof (*omp_pragmas);
1516 int i;
1517
1518 for (i = 0; i < n_omp_pragmas_simd; ++i)
1519 cpp_register_deferred_pragma (parse_in, "omp", omp_pragmas_simd[i].name,
1520 omp_pragmas_simd[i].id, true, true);
1521 }
1522
1523 if (flag_cilkplus)
1524 cpp_register_deferred_pragma (parse_in, NULL, "simd", PRAGMA_CILK_SIMD,
1525 true, false);
1526
1527 if (!flag_preprocess_only)
1528 cpp_register_deferred_pragma (parse_in, "GCC", "pch_preprocess",
1529 PRAGMA_GCC_PCH_PREPROCESS, false, false);
1530
1531 if (!flag_preprocess_only)
1532 cpp_register_deferred_pragma (parse_in, "GCC", "ivdep", PRAGMA_IVDEP, false,
1533 false);
1534
1535 if (flag_cilkplus)
1536 cpp_register_deferred_pragma (parse_in, "cilk", "grainsize",
1537 PRAGMA_CILK_GRAINSIZE, true, false);
1538
1539 #ifdef HANDLE_PRAGMA_PACK_WITH_EXPANSION
1540 c_register_pragma_with_expansion (0, "pack", handle_pragma_pack);
1541 #else
1542 c_register_pragma (0, "pack", handle_pragma_pack);
1543 #endif
1544 c_register_pragma (0, "weak", handle_pragma_weak);
1545
1546 c_register_pragma ("GCC", "visibility", handle_pragma_visibility);
1547
1548 c_register_pragma ("GCC", "diagnostic", handle_pragma_diagnostic);
1549 c_register_pragma ("GCC", "target", handle_pragma_target);
1550 c_register_pragma ("GCC", "optimize", handle_pragma_optimize);
1551 c_register_pragma ("GCC", "push_options", handle_pragma_push_options);
1552 c_register_pragma ("GCC", "pop_options", handle_pragma_pop_options);
1553 c_register_pragma ("GCC", "reset_options", handle_pragma_reset_options);
1554
1555 c_register_pragma ("STDC", "FLOAT_CONST_DECIMAL64",
1556 handle_pragma_float_const_decimal64);
1557
1558 c_register_pragma_with_expansion (0, "redefine_extname",
1559 handle_pragma_redefine_extname);
1560
1561 c_register_pragma_with_expansion (0, "message", handle_pragma_message);
1562
1563 #ifdef REGISTER_TARGET_PRAGMAS
1564 REGISTER_TARGET_PRAGMAS ();
1565 #endif
1566
1567 global_sso = default_sso;
1568 c_register_pragma (0, "scalar_storage_order",
1569 handle_pragma_scalar_storage_order);
1570
1571 /* Allow plugins to register their own pragmas. */
1572 invoke_plugin_callbacks (PLUGIN_PRAGMAS, NULL);
1573 }
1574
1575 #include "gt-c-family-c-pragma.h"