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    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 2, 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 COPYING.  If not, write to the Free
19 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
20 02110-1301, USA.  */
21 
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "rtl.h"
27 #include "tree.h"
28 #include "function.h"
29 #include "cpplib.h"
30 #include "c-pragma.h"
31 #include "flags.h"
32 #include "toplev.h"
33 #include "ggc.h"
34 #include "c-common.h"
35 #include "output.h"
36 #include "tm_p.h"
37 #include "vec.h"
38 #include "target.h"
39 
40 #define GCC_BAD(gmsgid) \
41   do { warning (OPT_Wpragmas, gmsgid); return; } while (0)
42 #define GCC_BAD2(gmsgid, arg) \
43   do { warning (OPT_Wpragmas, gmsgid, arg); return; } while (0)
44 
45 typedef struct align_stack GTY(())
46 {
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
push_alignment(int alignment,tree id)73 push_alignment (int alignment, tree id)
74 {
75   align_stack * entry;
76 
77   entry = ggc_alloc (sizeof (* entry));
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
pop_alignment(tree id)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, %s) encountered without matching #pragma pack(push, %s)"
116 		 , IDENTIFIER_POINTER (id), IDENTIFIER_POINTER (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
handle_pragma_pack(cpp_reader * ARG_UNUSED (dummy))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 (c_lex (&x) != CPP_OPEN_PAREN)
151     GCC_BAD ("missing %<(%> after %<#pragma pack%> - ignored");
152 
153   token = c_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 (c_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 %qs for %<#pragma pack%> - ignored", op);
183 
184       while ((token = c_lex (&x)) == CPP_COMMA)
185 	{
186 	  token = c_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 (c_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 static GTY(()) tree pending_weaks;
247 
248 #ifdef HANDLE_PRAGMA_WEAK
249 static void apply_pragma_weak (tree, tree);
250 static void handle_pragma_weak (cpp_reader *);
251 
252 static void
apply_pragma_weak(tree decl,tree value)253 apply_pragma_weak (tree decl, tree value)
254 {
255   if (value)
256     {
257       value = build_string (IDENTIFIER_LENGTH (value),
258 			    IDENTIFIER_POINTER (value));
259       decl_attributes (&decl, build_tree_list (get_identifier ("alias"),
260 					       build_tree_list (NULL, value)),
261 		       0);
262     }
263 
264   if (SUPPORTS_WEAK && DECL_EXTERNAL (decl) && TREE_USED (decl)
265       && !DECL_WEAK (decl) /* Don't complain about a redundant #pragma.  */
266       && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
267     warning (OPT_Wpragmas, "applying #pragma weak %q+D after first use "
268              "results in unspecified behavior", decl);
269 
270   declare_weak (decl);
271 }
272 
273 void
maybe_apply_pragma_weak(tree decl)274 maybe_apply_pragma_weak (tree decl)
275 {
276   tree *p, t, id;
277 
278   /* Avoid asking for DECL_ASSEMBLER_NAME when it's not needed.  */
279 
280   /* No weak symbols pending, take the short-cut.  */
281   if (!pending_weaks)
282     return;
283   /* If it's not visible outside this file, it doesn't matter whether
284      it's weak.  */
285   if (!DECL_EXTERNAL (decl) && !TREE_PUBLIC (decl))
286     return;
287   /* If it's not a function or a variable, it can't be weak.
288      FIXME: what kinds of things are visible outside this file but
289      aren't functions or variables?   Should this be an assert instead?  */
290   if (TREE_CODE (decl) != FUNCTION_DECL && TREE_CODE (decl) != VAR_DECL)
291     return;
292 
293   id = DECL_ASSEMBLER_NAME (decl);
294 
295   for (p = &pending_weaks; (t = *p) ; p = &TREE_CHAIN (t))
296     if (id == TREE_PURPOSE (t))
297       {
298 	apply_pragma_weak (decl, TREE_VALUE (t));
299 	*p = TREE_CHAIN (t);
300 	break;
301       }
302 }
303 
304 /* Process all "#pragma weak A = B" directives where we have not seen
305    a decl for A.  */
306 void
maybe_apply_pending_pragma_weaks(void)307 maybe_apply_pending_pragma_weaks (void)
308 {
309   tree *p, t, alias_id, id, decl, *next;
310 
311   for (p = &pending_weaks; (t = *p) ; p = next)
312     {
313       next = &TREE_CHAIN (t);
314       alias_id = TREE_PURPOSE (t);
315       id = TREE_VALUE (t);
316 
317       if (TREE_VALUE (t) == NULL)
318 	continue;
319 
320       decl = build_decl (FUNCTION_DECL, alias_id, default_function_type);
321 
322       DECL_ARTIFICIAL (decl) = 1;
323       TREE_PUBLIC (decl) = 1;
324       DECL_EXTERNAL (decl) = 1;
325       DECL_WEAK (decl) = 1;
326 
327       assemble_alias (decl, id);
328     }
329 }
330 
331 /* #pragma weak name [= value] */
332 static void
handle_pragma_weak(cpp_reader * ARG_UNUSED (dummy))333 handle_pragma_weak (cpp_reader * ARG_UNUSED (dummy))
334 {
335   tree name, value, x, decl;
336   enum cpp_ttype t;
337 
338   value = 0;
339 
340   if (c_lex (&name) != CPP_NAME)
341     GCC_BAD ("malformed #pragma weak, ignored");
342   t = c_lex (&x);
343   if (t == CPP_EQ)
344     {
345       if (c_lex (&value) != CPP_NAME)
346 	GCC_BAD ("malformed #pragma weak, ignored");
347       t = c_lex (&x);
348     }
349   if (t != CPP_EOF)
350     warning (OPT_Wpragmas, "junk at end of #pragma weak");
351 
352   decl = identifier_global_value (name);
353   if (decl && DECL_P (decl))
354     {
355       apply_pragma_weak (decl, value);
356       if (value)
357 	assemble_alias (decl, value);
358     }
359   else
360     pending_weaks = tree_cons (name, value, pending_weaks);
361 }
362 #else
363 void
maybe_apply_pragma_weak(tree ARG_UNUSED (decl))364 maybe_apply_pragma_weak (tree ARG_UNUSED (decl))
365 {
366 }
367 
368 void
maybe_apply_pending_pragma_weaks(void)369 maybe_apply_pending_pragma_weaks (void)
370 {
371 }
372 #endif /* HANDLE_PRAGMA_WEAK */
373 
374 /* GCC supports two #pragma directives for renaming the external
375    symbol associated with a declaration (DECL_ASSEMBLER_NAME), for
376    compatibility with the Solaris and Tru64 system headers.  GCC also
377    has its own notation for this, __asm__("name") annotations.
378 
379    Corner cases of these features and their interaction:
380 
381    1) Both pragmas silently apply only to declarations with external
382       linkage (that is, TREE_PUBLIC || DECL_EXTERNAL).  Asm labels
383       do not have this restriction.
384 
385    2) In C++, both #pragmas silently apply only to extern "C" declarations.
386       Asm labels do not have this restriction.
387 
388    3) If any of the three ways of changing DECL_ASSEMBLER_NAME is
389       applied to a decl whose DECL_ASSEMBLER_NAME is already set, and the
390       new name is different, a warning issues and the name does not change.
391 
392    4) The "source name" for #pragma redefine_extname is the DECL_NAME,
393       *not* the DECL_ASSEMBLER_NAME.
394 
395    5) If #pragma extern_prefix is in effect and a declaration occurs
396       with an __asm__ name, the #pragma extern_prefix is silently
397       ignored for that declaration.
398 
399    6) If #pragma extern_prefix and #pragma redefine_extname apply to
400       the same declaration, whichever triggered first wins, and a warning
401       is issued.  (We would like to have #pragma redefine_extname always
402       win, but it can appear either before or after the declaration, and
403       if it appears afterward, we have no way of knowing whether a modified
404       DECL_ASSEMBLER_NAME is due to #pragma extern_prefix.)  */
405 
406 static GTY(()) tree pending_redefine_extname;
407 
408 static void handle_pragma_redefine_extname (cpp_reader *);
409 
410 /* #pragma redefine_extname oldname newname */
411 static void
handle_pragma_redefine_extname(cpp_reader * ARG_UNUSED (dummy))412 handle_pragma_redefine_extname (cpp_reader * ARG_UNUSED (dummy))
413 {
414   tree oldname, newname, decl, x;
415   enum cpp_ttype t;
416 
417   if (c_lex (&oldname) != CPP_NAME)
418     GCC_BAD ("malformed #pragma redefine_extname, ignored");
419   if (c_lex (&newname) != CPP_NAME)
420     GCC_BAD ("malformed #pragma redefine_extname, ignored");
421   t = c_lex (&x);
422   if (t != CPP_EOF)
423     warning (OPT_Wpragmas, "junk at end of #pragma redefine_extname");
424 
425   if (!flag_mudflap && !targetm.handle_pragma_redefine_extname)
426     {
427       if (warn_unknown_pragmas > in_system_header)
428 	warning (OPT_Wunknown_pragmas,
429 		 "#pragma redefine_extname not supported on this target");
430       return;
431     }
432 
433   decl = identifier_global_value (oldname);
434   if (decl
435       && (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl))
436       && (TREE_CODE (decl) == FUNCTION_DECL
437 	  || TREE_CODE (decl) == VAR_DECL)
438       && has_c_linkage (decl))
439     {
440       if (DECL_ASSEMBLER_NAME_SET_P (decl))
441 	{
442 	  const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
443 	  name = targetm.strip_name_encoding (name);
444 
445 	  if (strcmp (name, IDENTIFIER_POINTER (newname)))
446 	    warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
447 		     "conflict with previous rename");
448 	}
449       else
450 	change_decl_assembler_name (decl, newname);
451     }
452   else
453     /* We have to add this to the rename list even if there's already
454        a global value that doesn't meet the above criteria, because in
455        C++ "struct foo {...};" puts "foo" in the current namespace but
456        does *not* conflict with a subsequent declaration of a function
457        or variable foo.  See g++.dg/other/pragma-re-2.C.  */
458     add_to_renaming_pragma_list (oldname, newname);
459 }
460 
461 /* This is called from here and from ia64.c.  */
462 void
add_to_renaming_pragma_list(tree oldname,tree newname)463 add_to_renaming_pragma_list (tree oldname, tree newname)
464 {
465   tree previous = purpose_member (oldname, pending_redefine_extname);
466   if (previous)
467     {
468       if (TREE_VALUE (previous) != newname)
469 	warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
470 		 "conflict with previous #pragma redefine_extname");
471       return;
472     }
473 
474   pending_redefine_extname
475     = tree_cons (oldname, newname, pending_redefine_extname);
476 }
477 
478 static GTY(()) tree pragma_extern_prefix;
479 
480 /* #pragma extern_prefix "prefix" */
481 static void
handle_pragma_extern_prefix(cpp_reader * ARG_UNUSED (dummy))482 handle_pragma_extern_prefix (cpp_reader * ARG_UNUSED (dummy))
483 {
484   tree prefix, x;
485   enum cpp_ttype t;
486 
487   if (c_lex (&prefix) != CPP_STRING)
488     GCC_BAD ("malformed #pragma extern_prefix, ignored");
489   t = c_lex (&x);
490   if (t != CPP_EOF)
491     warning (OPT_Wpragmas, "junk at end of #pragma extern_prefix");
492 
493   if (targetm.handle_pragma_extern_prefix)
494     /* Note that the length includes the null terminator.  */
495     pragma_extern_prefix = (TREE_STRING_LENGTH (prefix) > 1 ? prefix : NULL);
496   else if (warn_unknown_pragmas > in_system_header)
497     warning (OPT_Wunknown_pragmas,
498 	     "#pragma extern_prefix not supported on this target");
499 }
500 
501 /* Hook from the front ends to apply the results of one of the preceding
502    pragmas that rename variables.  */
503 
504 tree
maybe_apply_renaming_pragma(tree decl,tree asmname)505 maybe_apply_renaming_pragma (tree decl, tree asmname)
506 {
507   tree *p, t;
508 
509   /* The renaming pragmas are only applied to declarations with
510      external linkage.  */
511   if ((TREE_CODE (decl) != FUNCTION_DECL && TREE_CODE (decl) != VAR_DECL)
512       || (!TREE_PUBLIC (decl) && !DECL_EXTERNAL (decl))
513       || !has_c_linkage (decl))
514     return asmname;
515 
516   /* If the DECL_ASSEMBLER_NAME is already set, it does not change,
517      but we may warn about a rename that conflicts.  */
518   if (DECL_ASSEMBLER_NAME_SET_P (decl))
519     {
520       const char *oldname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
521       oldname = targetm.strip_name_encoding (oldname);
522 
523       if (asmname && strcmp (TREE_STRING_POINTER (asmname), oldname))
524 	  warning (OPT_Wpragmas, "asm declaration ignored due to "
525 		   "conflict with previous rename");
526 
527       /* Take any pending redefine_extname off the list.  */
528       for (p = &pending_redefine_extname; (t = *p); p = &TREE_CHAIN (t))
529 	if (DECL_NAME (decl) == TREE_PURPOSE (t))
530 	  {
531 	    /* Only warn if there is a conflict.  */
532 	    if (strcmp (IDENTIFIER_POINTER (TREE_VALUE (t)), oldname))
533 	      warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
534 		       "conflict with previous rename");
535 
536 	    *p = TREE_CHAIN (t);
537 	    break;
538 	  }
539       return 0;
540     }
541 
542   /* Find out if we have a pending #pragma redefine_extname.  */
543   for (p = &pending_redefine_extname; (t = *p); p = &TREE_CHAIN (t))
544     if (DECL_NAME (decl) == TREE_PURPOSE (t))
545       {
546 	tree newname = TREE_VALUE (t);
547 	*p = TREE_CHAIN (t);
548 
549 	/* If we already have an asmname, #pragma redefine_extname is
550  	   ignored (with a warning if it conflicts).  */
551 	if (asmname)
552 	  {
553 	    if (strcmp (TREE_STRING_POINTER (asmname),
554 			IDENTIFIER_POINTER (newname)) != 0)
555 	      warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
556 		       "conflict with __asm__ declaration");
557 	    return asmname;
558 	  }
559 
560 	/* Otherwise we use what we've got; #pragma extern_prefix is
561 	   silently ignored.  */
562 	return build_string (IDENTIFIER_LENGTH (newname),
563 			     IDENTIFIER_POINTER (newname));
564       }
565 
566   /* If we've got an asmname, #pragma extern_prefix is silently ignored.  */
567   if (asmname)
568     return asmname;
569 
570   /* If #pragma extern_prefix is in effect, apply it.  */
571   if (pragma_extern_prefix)
572     {
573       const char *prefix = TREE_STRING_POINTER (pragma_extern_prefix);
574       size_t plen = TREE_STRING_LENGTH (pragma_extern_prefix) - 1;
575 
576       const char *id = IDENTIFIER_POINTER (DECL_NAME (decl));
577       size_t ilen = IDENTIFIER_LENGTH (DECL_NAME (decl));
578 
579       char *newname = (char *) alloca (plen + ilen + 1);
580 
581       memcpy (newname,        prefix, plen);
582       memcpy (newname + plen, id, ilen + 1);
583 
584       return build_string (plen + ilen, newname);
585     }
586 
587   /* Nada.  */
588   return 0;
589 }
590 
591 
592 #ifdef HANDLE_PRAGMA_VISIBILITY
593 static void handle_pragma_visibility (cpp_reader *);
594 
595 typedef enum symbol_visibility visibility;
596 DEF_VEC_I (visibility);
597 DEF_VEC_ALLOC_I (visibility, heap);
598 
599 /* Sets the default visibility for symbols to something other than that
600    specified on the command line.  */
601 static void
handle_pragma_visibility(cpp_reader * dummy ATTRIBUTE_UNUSED)602 handle_pragma_visibility (cpp_reader *dummy ATTRIBUTE_UNUSED)
603 {
604   /* Form is #pragma GCC visibility push(hidden)|pop */
605   tree x;
606   enum cpp_ttype token;
607   enum { bad, push, pop } action = bad;
608   static VEC (visibility, heap) *visstack;
609 
610   token = c_lex (&x);
611   if (token == CPP_NAME)
612     {
613       const char *op = IDENTIFIER_POINTER (x);
614       if (!strcmp (op, "push"))
615         action = push;
616       else if (!strcmp (op, "pop"))
617         action = pop;
618     }
619   if (bad == action)
620     GCC_BAD ("#pragma GCC visibility must be followed by push or pop");
621   else
622     {
623       if (pop == action)
624         {
625           if (!VEC_length (visibility, visstack))
626             {
627               GCC_BAD ("no matching push for %<#pragma GCC visibility pop%>");
628             }
629           else
630             {
631 	      default_visibility = VEC_pop (visibility, visstack);
632 	      visibility_options.inpragma
633 		= VEC_length (visibility, visstack) != 0;
634             }
635         }
636       else
637         {
638           if (c_lex (&x) != CPP_OPEN_PAREN)
639             GCC_BAD ("missing %<(%> after %<#pragma GCC visibility push%> - ignored");
640           token = c_lex (&x);
641           if (token != CPP_NAME)
642             {
643               GCC_BAD ("malformed #pragma GCC visibility push");
644             }
645           else
646             {
647               const char *str = IDENTIFIER_POINTER (x);
648 	      VEC_safe_push (visibility, heap, visstack,
649 			     default_visibility);
650               if (!strcmp (str, "default"))
651                 default_visibility = VISIBILITY_DEFAULT;
652               else if (!strcmp (str, "internal"))
653                 default_visibility = VISIBILITY_INTERNAL;
654               else if (!strcmp (str, "hidden"))
655                 default_visibility = VISIBILITY_HIDDEN;
656               else if (!strcmp (str, "protected"))
657                 default_visibility = VISIBILITY_PROTECTED;
658               else
659                 {
660                   GCC_BAD ("#pragma GCC visibility push() must specify default, internal, hidden or protected");
661                 }
662               visibility_options.inpragma = 1;
663             }
664           if (c_lex (&x) != CPP_CLOSE_PAREN)
665             GCC_BAD ("missing %<(%> after %<#pragma GCC visibility push%> - ignored");
666         }
667     }
668   if (c_lex (&x) != CPP_EOF)
669     warning (OPT_Wpragmas, "junk at end of %<#pragma GCC visibility%>");
670 }
671 
672 #endif
673 
674 /* Front-end wrappers for pragma registration to avoid dragging
675    cpplib.h in almost everywhere.  */
676 void
c_register_pragma(const char * space,const char * name,void (* handler)(struct cpp_reader *))677 c_register_pragma (const char *space, const char *name,
678 		   void (*handler) (struct cpp_reader *))
679 {
680   cpp_register_pragma (parse_in, space, name, handler, 0);
681 }
682 
683 void
c_register_pragma_with_expansion(const char * space,const char * name,void (* handler)(struct cpp_reader *))684 c_register_pragma_with_expansion (const char *space, const char *name,
685 				  void (*handler) (struct cpp_reader *))
686 {
687   cpp_register_pragma (parse_in, space, name, handler, 1);
688 }
689 
690 /* Set up front-end pragmas.  */
691 void
init_pragma(void)692 init_pragma (void)
693 {
694 #ifdef HANDLE_PRAGMA_PACK
695 #ifdef HANDLE_PRAGMA_PACK_WITH_EXPANSION
696   c_register_pragma_with_expansion (0, "pack", handle_pragma_pack);
697 #else
698   c_register_pragma (0, "pack", handle_pragma_pack);
699 #endif
700 #endif
701 #ifdef HANDLE_PRAGMA_WEAK
702   c_register_pragma (0, "weak", handle_pragma_weak);
703 #endif
704 #ifdef HANDLE_PRAGMA_VISIBILITY
705   c_register_pragma ("GCC", "visibility", handle_pragma_visibility);
706 #endif
707 
708   c_register_pragma (0, "redefine_extname", handle_pragma_redefine_extname);
709   c_register_pragma (0, "extern_prefix", handle_pragma_extern_prefix);
710 
711   c_register_pragma ("GCC", "pch_preprocess", c_common_pch_pragma);
712 
713 #ifdef REGISTER_TARGET_PRAGMAS
714   REGISTER_TARGET_PRAGMAS ();
715 #endif
716 }
717 
718 #include "gt-c-pragma.h"
719