OSDN Git Service

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