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