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