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