Line data Source code
1 : /* Handle #pragma, system V.4 style. Supports #pragma weak and #pragma pack.
2 : Copyright (C) 1992-2026 Free Software Foundation, Inc.
3 :
4 : This file is part of GCC.
5 :
6 : GCC is free software; you can redistribute it and/or modify it under
7 : the terms of the GNU General Public License as published by the Free
8 : Software Foundation; either version 3, or (at your option) any later
9 : version.
10 :
11 : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 : WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 : for more details.
15 :
16 : You should have received a copy of the GNU General Public License
17 : along with GCC; see the file COPYING3. If not see
18 : <http://www.gnu.org/licenses/>. */
19 :
20 : #include "config.h"
21 : #include "system.h"
22 : #include "coretypes.h"
23 : #include "target.h"
24 : #include "function.h" /* For cfun. */
25 : #include "c-common.h"
26 : #include "memmodel.h"
27 : #include "tm_p.h" /* For REGISTER_TARGET_PRAGMAS. */
28 : #include "stringpool.h"
29 : #include "cgraph.h"
30 : #include "diagnostic.h"
31 : #include "attribs.h"
32 : #include "varasm.h"
33 : #include "c-pragma.h"
34 : #include "opts.h"
35 : #include "plugin.h"
36 : #include "opt-suggestions.h"
37 :
38 : #define GCC_BAD(gmsgid) \
39 : do { warning (OPT_Wpragmas, gmsgid); return; } while (0)
40 : #define GCC_BAD2(gmsgid, arg) \
41 : do { warning (OPT_Wpragmas, gmsgid, arg); return; } while (0)
42 : #define GCC_BAD_AT(loc, gmsgid) \
43 : do { warning_at (loc, OPT_Wpragmas, gmsgid); return; } while (0)
44 : #define GCC_BAD2_AT(loc, gmsgid, arg) \
45 : do { warning_at (loc, OPT_Wpragmas, gmsgid, arg); return; } while (0)
46 :
47 : struct GTY(()) align_stack {
48 : int alignment;
49 : tree id;
50 : struct align_stack * prev;
51 : };
52 :
53 : static GTY(()) struct align_stack * alignment_stack;
54 :
55 : static void handle_pragma_pack (cpp_reader *);
56 :
57 : /* If we have a "global" #pragma pack(<n>) in effect when the first
58 : #pragma pack(push,<n>) is encountered, this stores the value of
59 : maximum_field_alignment in effect. When the final pop_alignment()
60 : happens, we restore the value to this, not to a value of 0 for
61 : maximum_field_alignment. Value is in bits. */
62 : static int default_alignment;
63 : #define SET_GLOBAL_ALIGNMENT(ALIGN) (maximum_field_alignment = *(alignment_stack == NULL \
64 : ? &default_alignment \
65 : : &alignment_stack->alignment) = (ALIGN))
66 :
67 : static void push_alignment (int, tree);
68 : static void pop_alignment (tree);
69 :
70 : /* Push an alignment value onto the stack. */
71 : static void
72 22 : push_alignment (int alignment, tree id)
73 : {
74 22 : align_stack * entry = ggc_alloc<align_stack> ();
75 :
76 22 : entry->alignment = alignment;
77 22 : entry->id = id;
78 22 : entry->prev = alignment_stack;
79 :
80 : /* The current value of maximum_field_alignment is not necessarily
81 : 0 since there may be a #pragma pack(<n>) in effect; remember it
82 : so that we can restore it after the final #pragma pop(). */
83 22 : if (alignment_stack == NULL)
84 19 : default_alignment = maximum_field_alignment;
85 :
86 22 : alignment_stack = entry;
87 :
88 22 : maximum_field_alignment = alignment;
89 22 : }
90 :
91 : /* Undo a push of an alignment onto the stack. */
92 : static void
93 24 : pop_alignment (tree id)
94 : {
95 24 : align_stack * entry;
96 :
97 24 : if (alignment_stack == NULL)
98 2 : GCC_BAD ("%<#pragma pack (pop)%> encountered without matching "
99 : "%<#pragma pack (push)%>");
100 :
101 : /* If we got an identifier, strip away everything above the target
102 : entry so that the next step will restore the state just below it. */
103 22 : if (id)
104 : {
105 9 : for (entry = alignment_stack; entry; entry = entry->prev)
106 6 : if (entry->id == id)
107 : {
108 2 : alignment_stack = entry;
109 2 : break;
110 : }
111 5 : if (entry == NULL)
112 3 : warning (OPT_Wpragmas,
113 : "%<#pragma pack(pop, %E)%> encountered without matching "
114 : "%<#pragma pack(push, %E)%>"
115 : , id, id);
116 : }
117 :
118 22 : entry = alignment_stack->prev;
119 :
120 22 : maximum_field_alignment = entry ? entry->alignment : default_alignment;
121 :
122 22 : alignment_stack = entry;
123 : }
124 :
125 : /* #pragma pack ()
126 : #pragma pack (N)
127 :
128 : #pragma pack (push)
129 : #pragma pack (push, N)
130 : #pragma pack (push, ID)
131 : #pragma pack (push, ID, N)
132 : #pragma pack (pop)
133 : #pragma pack (pop, ID) */
134 : static void
135 187 : handle_pragma_pack (cpp_reader *)
136 : {
137 187 : location_t loc;
138 187 : tree x, id = 0;
139 187 : int align = -1;
140 187 : enum cpp_ttype token;
141 187 : enum { set, push, pop } action;
142 :
143 187 : if (pragma_lex (&x) != CPP_OPEN_PAREN)
144 13 : GCC_BAD ("missing %<(%> after %<#pragma pack%> - ignored");
145 :
146 186 : token = pragma_lex (&x, &loc);
147 186 : if (token == CPP_CLOSE_PAREN)
148 : {
149 15 : action = set;
150 15 : align = initial_max_fld_align;
151 : }
152 171 : else if (token == CPP_NUMBER)
153 : {
154 116 : if (TREE_CODE (x) != INTEGER_CST)
155 2 : GCC_BAD_AT (loc, "invalid constant in %<#pragma pack%> - ignored");
156 114 : align = TREE_INT_CST_LOW (x);
157 114 : action = set;
158 114 : if (pragma_lex (&x) != CPP_CLOSE_PAREN)
159 1 : GCC_BAD ("malformed %<#pragma pack%> - ignored");
160 : }
161 55 : else if (token == CPP_NAME)
162 : {
163 : #define GCC_BAD_ACTION do { if (action != pop) \
164 : GCC_BAD ("malformed %<#pragma pack(push[, id][, <n>])%> - ignored"); \
165 : else \
166 : GCC_BAD ("malformed %<#pragma pack(pop[, id])%> - ignored"); \
167 : } while (0)
168 :
169 54 : const char *op = IDENTIFIER_POINTER (x);
170 54 : if (!strcmp (op, "push"))
171 51 : action = push;
172 28 : else if (!strcmp (op, "pop"))
173 : action = pop;
174 : else
175 3 : GCC_BAD2_AT (loc, "unknown action %qE for %<#pragma pack%> - ignored",
176 : x);
177 :
178 75 : while ((token = pragma_lex (&x)) == CPP_COMMA)
179 : {
180 28 : token = pragma_lex (&x, &loc);
181 28 : if (token == CPP_NAME && id == 0)
182 : {
183 16 : id = x;
184 : }
185 12 : else if (token == CPP_NUMBER && action == push && align == -1)
186 : {
187 11 : if (TREE_CODE (x) != INTEGER_CST)
188 3 : GCC_BAD_AT (loc,
189 : "invalid constant in %<#pragma pack%> - ignored");
190 8 : align = TREE_INT_CST_LOW (x);
191 8 : if (align == -1)
192 0 : action = set;
193 : }
194 : else
195 76 : GCC_BAD_ACTION;
196 : }
197 :
198 47 : if (token != CPP_CLOSE_PAREN)
199 0 : GCC_BAD_ACTION;
200 : #undef GCC_BAD_ACTION
201 : }
202 : else
203 1 : GCC_BAD ("malformed %<#pragma pack%> - ignored");
204 :
205 175 : if (pragma_lex (&x, &loc) != CPP_EOF)
206 1 : warning_at (loc, OPT_Wpragmas, "junk at end of %<#pragma pack%>");
207 :
208 175 : if (flag_pack_struct)
209 0 : GCC_BAD ("%<#pragma pack%> has no effect with %<-fpack-struct%> - ignored");
210 :
211 175 : if (action != pop)
212 151 : switch (align)
213 : {
214 135 : case 0:
215 135 : case 1:
216 135 : case 2:
217 135 : case 4:
218 135 : case 8:
219 135 : case 16:
220 135 : align *= BITS_PER_UNIT;
221 135 : break;
222 15 : case -1:
223 15 : if (action == push)
224 : {
225 15 : align = maximum_field_alignment;
226 15 : break;
227 : }
228 : /* FALLTHRU */
229 1 : default:
230 1 : GCC_BAD2 ("alignment must be a small power of two, not %d", align);
231 : }
232 :
233 150 : switch (action)
234 : {
235 128 : case set: SET_GLOBAL_ALIGNMENT (align); break;
236 22 : case push: push_alignment (align, id); break;
237 24 : case pop: pop_alignment (id); break;
238 : }
239 : }
240 :
241 : struct GTY(()) pending_weak
242 : {
243 : tree name;
244 : tree value;
245 : };
246 :
247 :
248 : static GTY(()) vec<pending_weak, va_gc> *pending_weaks;
249 :
250 : static void apply_pragma_weak (tree, tree);
251 : static void handle_pragma_weak (cpp_reader *);
252 :
253 : static void
254 135 : apply_pragma_weak (tree decl, tree value)
255 : {
256 135 : if (value)
257 : {
258 9 : value = build_string (IDENTIFIER_LENGTH (value),
259 9 : IDENTIFIER_POINTER (value));
260 9 : decl_attributes (&decl, build_tree_list (get_identifier ("alias"),
261 : build_tree_list (NULL, value)),
262 : 0);
263 : }
264 :
265 252 : if (SUPPORTS_WEAK && DECL_EXTERNAL (decl) && TREE_USED (decl)
266 17 : && !DECL_WEAK (decl) /* Don't complain about a redundant #pragma. */
267 3 : && DECL_ASSEMBLER_NAME_SET_P (decl)
268 135 : && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
269 0 : warning (OPT_Wpragmas, "applying %<#pragma weak %+D%> after first use "
270 : "results in unspecified behavior", decl);
271 :
272 135 : declare_weak (decl);
273 :
274 : /* With VALUE, DECL is now an alias defined in this translation unit,
275 : which binds no less locally than the declaration its TLS model was
276 : chosen for, but decl_default_tls_model cannot see that yet. */
277 135 : if (!value)
278 126 : weak_decl_tls_model (decl);
279 135 : }
280 :
281 : void
282 249836568 : maybe_apply_pragma_weak (tree decl)
283 : {
284 249836568 : tree id;
285 249836568 : int i;
286 249836568 : pending_weak *pe;
287 :
288 : /* Avoid asking for DECL_ASSEMBLER_NAME when it's not needed. */
289 :
290 : /* No weak symbols pending, take the short-cut. */
291 249836568 : if (vec_safe_is_empty (pending_weaks))
292 : return;
293 : /* If it's not visible outside this file, it doesn't matter whether
294 : it's weak. */
295 699 : if (!DECL_EXTERNAL (decl) && !TREE_PUBLIC (decl))
296 : return;
297 : /* If it's not a function or a variable, it can't be weak.
298 : FIXME: what kinds of things are visible outside this file but
299 : aren't functions or variables? Should this be an assert instead? */
300 130 : if (!VAR_OR_FUNCTION_DECL_P (decl))
301 : return;
302 :
303 130 : if (DECL_ASSEMBLER_NAME_SET_P (decl))
304 7 : id = DECL_ASSEMBLER_NAME (decl);
305 : else
306 : {
307 123 : id = DECL_ASSEMBLER_NAME (decl);
308 123 : SET_DECL_ASSEMBLER_NAME (decl, NULL_TREE);
309 : }
310 :
311 219 : FOR_EACH_VEC_ELT (*pending_weaks, i, pe)
312 130 : if (id == pe->name)
313 : {
314 41 : apply_pragma_weak (decl, pe->value);
315 41 : pending_weaks->unordered_remove (i);
316 41 : break;
317 : }
318 : }
319 :
320 : /* Process all "#pragma weak A = B" directives where we have not seen
321 : a decl for A. */
322 : void
323 207440 : maybe_apply_pending_pragma_weaks (void)
324 : {
325 207440 : tree alias_id, id, decl;
326 207440 : int i;
327 207440 : pending_weak *pe;
328 207440 : symtab_node *target;
329 :
330 207440 : if (vec_safe_is_empty (pending_weaks))
331 207440 : return;
332 :
333 42 : FOR_EACH_VEC_ELT (*pending_weaks, i, pe)
334 : {
335 21 : alias_id = pe->name;
336 21 : id = pe->value;
337 :
338 21 : if (id == NULL)
339 16 : continue;
340 :
341 5 : target = symtab_node::get_for_asmname (id);
342 10 : decl = build_decl (UNKNOWN_LOCATION,
343 5 : target ? TREE_CODE (target->decl) : FUNCTION_DECL,
344 : alias_id, default_function_type);
345 :
346 5 : DECL_ARTIFICIAL (decl) = 1;
347 5 : TREE_PUBLIC (decl) = 1;
348 5 : DECL_WEAK (decl) = 1;
349 5 : if (VAR_P (decl))
350 1 : TREE_STATIC (decl) = 1;
351 5 : if (!target)
352 : {
353 0 : error ("%q+D aliased to undefined symbol %qE",
354 : decl, id);
355 0 : continue;
356 : }
357 :
358 5 : assemble_alias (decl, id);
359 : }
360 : }
361 :
362 : /* #pragma weak name [= value] */
363 : static void
364 160 : handle_pragma_weak (cpp_reader *)
365 : {
366 160 : tree name, value, x, decl;
367 160 : enum cpp_ttype t;
368 :
369 160 : value = 0;
370 :
371 160 : if (pragma_lex (&name) != CPP_NAME)
372 4 : GCC_BAD ("malformed %<#pragma weak%>, ignored");
373 160 : t = pragma_lex (&x);
374 160 : if (t == CPP_EQ)
375 : {
376 18 : if (pragma_lex (&value) != CPP_NAME)
377 3 : GCC_BAD ("malformed %<#pragma weak%>, ignored");
378 15 : t = pragma_lex (&x);
379 : }
380 157 : if (t != CPP_EOF)
381 0 : warning (OPT_Wpragmas, "junk at end of %<#pragma weak%>");
382 :
383 157 : decl = identifier_global_value (name);
384 157 : if (decl && DECL_P (decl))
385 : {
386 95 : if (!VAR_OR_FUNCTION_DECL_P (decl))
387 1 : GCC_BAD2 ("%<#pragma weak%> declaration of %q+D not allowed,"
388 : " ignored", decl);
389 94 : apply_pragma_weak (decl, value);
390 94 : if (value)
391 : {
392 5 : DECL_EXTERNAL (decl) = 0;
393 5 : if (VAR_P (decl))
394 4 : TREE_STATIC (decl) = 1;
395 5 : assemble_alias (decl, value);
396 : }
397 : }
398 : else
399 : {
400 62 : pending_weak pe = {name, value};
401 62 : vec_safe_push (pending_weaks, pe);
402 : }
403 : }
404 :
405 : static enum scalar_storage_order_kind global_sso;
406 :
407 : void
408 1193529 : maybe_apply_pragma_scalar_storage_order (tree type)
409 : {
410 1193529 : if (global_sso == SSO_NATIVE)
411 : return;
412 :
413 30 : gcc_assert (RECORD_OR_UNION_TYPE_P (type));
414 :
415 30 : if (lookup_attribute ("scalar_storage_order", TYPE_ATTRIBUTES (type)))
416 : return;
417 :
418 28 : if (global_sso == SSO_BIG_ENDIAN)
419 24 : TYPE_REVERSE_STORAGE_ORDER (type) = !BYTES_BIG_ENDIAN;
420 4 : else if (global_sso == SSO_LITTLE_ENDIAN)
421 4 : TYPE_REVERSE_STORAGE_ORDER (type) = BYTES_BIG_ENDIAN;
422 : else
423 0 : gcc_unreachable ();
424 : }
425 :
426 : static void
427 49 : handle_pragma_scalar_storage_order (cpp_reader *)
428 : {
429 49 : const char *kind_string;
430 49 : enum cpp_ttype token;
431 49 : tree x;
432 :
433 49 : if (BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN)
434 : {
435 : error ("%<scalar_storage_order%> is not supported because endianness "
436 : "is not uniform");
437 5 : return;
438 : }
439 :
440 49 : if (c_dialect_cxx ())
441 : {
442 3 : if (warn_unknown_pragmas > in_system_header_at (input_location))
443 3 : warning (OPT_Wunknown_pragmas,
444 : "%<#pragma scalar_storage_order%> is not supported for C++");
445 : return;
446 : }
447 :
448 46 : token = pragma_lex (&x);
449 46 : if (token != CPP_NAME)
450 1 : GCC_BAD ("missing %<big-endian%>, %<little-endian%>, or %<default%> after "
451 : "%<#pragma scalar_storage_order%>");
452 45 : kind_string = IDENTIFIER_POINTER (x);
453 45 : if (strcmp (kind_string, "default") == 0)
454 21 : global_sso = default_sso;
455 24 : else if (strcmp (kind_string, "big") == 0)
456 21 : global_sso = SSO_BIG_ENDIAN;
457 3 : else if (strcmp (kind_string, "little") == 0)
458 2 : global_sso = SSO_LITTLE_ENDIAN;
459 : else
460 45 : GCC_BAD ("expected %<big-endian%>, %<little-endian%>, or %<default%> after "
461 : "%<#pragma scalar_storage_order%>");
462 : }
463 :
464 : /* GCC supports two #pragma directives for renaming the external
465 : symbol associated with a declaration (DECL_ASSEMBLER_NAME), for
466 : compatibility with the Solaris and VMS system headers. GCC also
467 : has its own notation for this, __asm__("name") annotations.
468 :
469 : Corner cases of these features and their interaction:
470 :
471 : 1) Both pragmas silently apply only to declarations with external
472 : linkage (that is, TREE_PUBLIC || DECL_EXTERNAL). Asm labels
473 : do not have this restriction.
474 :
475 : 2) In C++, both #pragmas silently apply only to extern "C" declarations.
476 : Asm labels do not have this restriction.
477 :
478 : 3) If any of the three ways of changing DECL_ASSEMBLER_NAME is
479 : applied to a decl whose DECL_ASSEMBLER_NAME is already set, and the
480 : new name is different, a warning issues and the name does not change.
481 :
482 : 4) The "source name" for #pragma redefine_extname is the DECL_NAME,
483 : *not* the DECL_ASSEMBLER_NAME.
484 :
485 : 5) If #pragma extern_prefix is in effect and a declaration occurs
486 : with an __asm__ name, the #pragma extern_prefix is silently
487 : ignored for that declaration.
488 :
489 : 6) If #pragma extern_prefix and #pragma redefine_extname apply to
490 : the same declaration, whichever triggered first wins, and a warning
491 : is issued. (We would like to have #pragma redefine_extname always
492 : win, but it can appear either before or after the declaration, and
493 : if it appears afterward, we have no way of knowing whether a modified
494 : DECL_ASSEMBLER_NAME is due to #pragma extern_prefix.) */
495 :
496 : struct GTY(()) pending_redefinition {
497 : tree oldname;
498 : tree newname;
499 : };
500 :
501 :
502 : static GTY(()) vec<pending_redefinition, va_gc> *pending_redefine_extname;
503 :
504 : static void handle_pragma_redefine_extname (cpp_reader *);
505 :
506 : /* #pragma redefine_extname oldname newname */
507 : static void
508 30 : handle_pragma_redefine_extname (cpp_reader *)
509 : {
510 30 : tree oldname, newname, decls, x;
511 30 : enum cpp_ttype t;
512 30 : bool found;
513 :
514 30 : if (pragma_lex (&oldname) != CPP_NAME)
515 7 : GCC_BAD ("malformed %<#pragma redefine_extname%>, ignored");
516 25 : if (pragma_lex (&newname) != CPP_NAME)
517 2 : GCC_BAD ("malformed %<#pragma redefine_extname%>, ignored");
518 23 : t = pragma_lex (&x);
519 23 : if (t != CPP_EOF)
520 1 : warning (OPT_Wpragmas, "junk at end of %<#pragma redefine_extname%>");
521 :
522 23 : found = false;
523 23 : for (decls = c_linkage_bindings (oldname);
524 33 : decls; )
525 : {
526 10 : tree decl;
527 10 : if (TREE_CODE (decls) == TREE_LIST)
528 : {
529 3 : decl = TREE_VALUE (decls);
530 3 : decls = TREE_CHAIN (decls);
531 : }
532 : else
533 : {
534 : decl = decls;
535 : decls = NULL_TREE;
536 : }
537 :
538 0 : if ((TREE_PUBLIC (decl) || DECL_EXTERNAL (decl))
539 10 : && VAR_OR_FUNCTION_DECL_P (decl))
540 : {
541 10 : found = true;
542 10 : if (DECL_ASSEMBLER_NAME_SET_P (decl))
543 : {
544 0 : const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
545 0 : name = targetm.strip_name_encoding (name);
546 :
547 0 : if (!id_equal (newname, name))
548 0 : warning (OPT_Wpragmas, "%<#pragma redefine_extname%> "
549 : "ignored due to conflict with previous rename");
550 : }
551 : else
552 10 : symtab->change_decl_assembler_name (decl, newname);
553 : }
554 : }
555 :
556 23 : if (!found)
557 : /* We have to add this to the rename list even if there's already
558 : a global value that doesn't meet the above criteria, because in
559 : C++ "struct foo {...};" puts "foo" in the current namespace but
560 : does *not* conflict with a subsequent declaration of a function
561 : or variable foo. See g++.dg/other/pragma-re-2.C. */
562 16 : add_to_renaming_pragma_list (oldname, newname);
563 : }
564 :
565 : /* This is called from here and from ia64-c.cc. */
566 : void
567 16 : add_to_renaming_pragma_list (tree oldname, tree newname)
568 : {
569 16 : unsigned ix;
570 16 : pending_redefinition *p;
571 :
572 20 : FOR_EACH_VEC_SAFE_ELT (pending_redefine_extname, ix, p)
573 4 : if (oldname == p->oldname)
574 : {
575 0 : if (p->newname != newname)
576 0 : warning (OPT_Wpragmas, "%<#pragma redefine_extname%> ignored due to "
577 : "conflict with previous %<#pragma redefine_extname%>");
578 0 : return;
579 : }
580 :
581 16 : pending_redefinition e = {oldname, newname};
582 16 : vec_safe_push (pending_redefine_extname, e);
583 : }
584 :
585 : /* The current prefix set by #pragma extern_prefix. */
586 : GTY(()) tree pragma_extern_prefix;
587 :
588 : /* Hook from the front ends to apply the results of one of the preceding
589 : pragmas that rename variables. */
590 :
591 : tree
592 89011270 : maybe_apply_renaming_pragma (tree decl, tree asmname)
593 : {
594 89011270 : unsigned ix;
595 89011270 : pending_redefinition *p;
596 :
597 : /* The renaming pragmas are only applied to declarations with
598 : external linkage. */
599 63859511 : if (!VAR_OR_FUNCTION_DECL_P (decl)
600 79101186 : || (!TREE_PUBLIC (decl) && !DECL_EXTERNAL (decl))
601 167992260 : || !has_c_linkage (decl))
602 : return asmname;
603 :
604 : /* If the DECL_ASSEMBLER_NAME is already set, it does not change,
605 : but we may warn about a rename that conflicts. */
606 45798468 : if (DECL_ASSEMBLER_NAME_SET_P (decl))
607 : {
608 4619 : const char *oldname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
609 4619 : oldname = targetm.strip_name_encoding (oldname);
610 :
611 5218 : if (asmname && strcmp (TREE_STRING_POINTER (asmname), oldname))
612 7 : warning (OPT_Wpragmas, "%<asm%> declaration ignored due to "
613 : "conflict with previous rename");
614 :
615 : /* Take any pending redefine_extname off the list. */
616 4622 : FOR_EACH_VEC_SAFE_ELT (pending_redefine_extname, ix, p)
617 3 : if (DECL_NAME (decl) == p->oldname)
618 : {
619 : /* Only warn if there is a conflict. */
620 0 : if (!id_equal (p->newname, oldname))
621 0 : warning (OPT_Wpragmas, "%<#pragma redefine_extname%> ignored "
622 : "due to conflict with previous rename");
623 :
624 0 : pending_redefine_extname->unordered_remove (ix);
625 0 : break;
626 : }
627 : return NULL_TREE;
628 : }
629 :
630 : /* Find out if we have a pending #pragma redefine_extname. */
631 45793862 : FOR_EACH_VEC_SAFE_ELT (pending_redefine_extname, ix, p)
632 25 : if (DECL_NAME (decl) == p->oldname)
633 : {
634 12 : tree newname = p->newname;
635 12 : pending_redefine_extname->unordered_remove (ix);
636 :
637 : /* If we already have an asmname, #pragma redefine_extname is
638 : ignored (with a warning if it conflicts). */
639 12 : if (asmname)
640 : {
641 0 : if (strcmp (TREE_STRING_POINTER (asmname),
642 0 : IDENTIFIER_POINTER (newname)) != 0)
643 0 : warning (OPT_Wpragmas, "%<#pragma redefine_extname%> ignored "
644 : "due to conflict with %<asm%> declaration");
645 : return asmname;
646 : }
647 :
648 : /* Otherwise we use what we've got; #pragma extern_prefix is
649 : silently ignored. */
650 12 : return build_string (IDENTIFIER_LENGTH (newname),
651 12 : IDENTIFIER_POINTER (newname));
652 : }
653 :
654 : /* If we've got an asmname, #pragma extern_prefix is silently ignored. */
655 45793837 : if (asmname)
656 : return asmname;
657 :
658 : /* If #pragma extern_prefix is in effect, apply it. */
659 44342176 : if (pragma_extern_prefix)
660 : {
661 0 : const char *prefix = TREE_STRING_POINTER (pragma_extern_prefix);
662 0 : size_t plen = TREE_STRING_LENGTH (pragma_extern_prefix) - 1;
663 :
664 0 : const char *id = IDENTIFIER_POINTER (DECL_NAME (decl));
665 0 : size_t ilen = IDENTIFIER_LENGTH (DECL_NAME (decl));
666 :
667 0 : char *newname = (char *) alloca (plen + ilen + 1);
668 :
669 0 : memcpy (newname, prefix, plen);
670 0 : memcpy (newname + plen, id, ilen + 1);
671 :
672 0 : return build_string (plen + ilen, newname);
673 : }
674 :
675 : /* Nada. */
676 : return NULL_TREE;
677 : }
678 :
679 :
680 : static void handle_pragma_visibility (cpp_reader *);
681 :
682 : static vec<int> visstack;
683 :
684 : /* Push the visibility indicated by STR onto the top of the #pragma
685 : visibility stack. KIND is 0 for #pragma GCC visibility, 1 for
686 : C++ namespace with visibility attribute and 2 for C++ builtin
687 : ABI namespace. push_visibility/pop_visibility calls must have
688 : matching KIND, it is not allowed to push visibility using one
689 : KIND and pop using a different one. */
690 :
691 : void
692 3290381 : push_visibility (const char *str, int kind)
693 : {
694 3290381 : visstack.safe_push (((int) default_visibility) | (kind << 8));
695 3290381 : if (!strcmp (str, "default"))
696 3288782 : default_visibility = VISIBILITY_DEFAULT;
697 1599 : else if (!strcmp (str, "internal"))
698 0 : default_visibility = VISIBILITY_INTERNAL;
699 1599 : else if (!strcmp (str, "hidden"))
700 1599 : default_visibility = VISIBILITY_HIDDEN;
701 0 : else if (!strcmp (str, "protected"))
702 0 : default_visibility = VISIBILITY_PROTECTED;
703 : else
704 0 : GCC_BAD ("%<#pragma GCC visibility push()%> must specify %<default%>, "
705 : "%<internal%>, %<hidden%> or %<protected%>");
706 3290381 : visibility_options.inpragma = 1;
707 : }
708 :
709 : /* Pop a level of the #pragma visibility stack. Return true if
710 : successful. */
711 :
712 : bool
713 3290365 : pop_visibility (int kind)
714 : {
715 3290365 : if (!visstack.length ())
716 : return false;
717 3290365 : if ((visstack.last () >> 8) != kind)
718 : return false;
719 3290362 : default_visibility
720 3290362 : = (enum symbol_visibility) (visstack.pop () & 0xff);
721 3290362 : visibility_options.inpragma
722 3290362 : = visstack.length () != 0;
723 3290362 : return true;
724 : }
725 :
726 : /* Sets the default visibility for symbols to something other than that
727 : specified on the command line. */
728 :
729 : static void
730 249658 : handle_pragma_visibility (cpp_reader *)
731 : {
732 : /* Form is #pragma GCC visibility push(hidden)|pop */
733 249658 : tree x;
734 249658 : enum cpp_ttype token;
735 249658 : enum { bad, push, pop } action = bad;
736 :
737 249658 : token = pragma_lex (&x);
738 249658 : if (token == CPP_NAME)
739 : {
740 249658 : const char *op = IDENTIFIER_POINTER (x);
741 249658 : if (!strcmp (op, "push"))
742 : action = push;
743 124821 : else if (!strcmp (op, "pop"))
744 : action = pop;
745 : }
746 : if (bad == action)
747 3 : GCC_BAD ("%<#pragma GCC visibility%> must be followed by %<push%> "
748 : "or %<pop%>");
749 : else
750 : {
751 249658 : if (pop == action)
752 : {
753 124821 : if (! pop_visibility (0))
754 3 : GCC_BAD ("no matching push for %<#pragma GCC visibility pop%>");
755 : }
756 : else
757 : {
758 124837 : if (pragma_lex (&x) != CPP_OPEN_PAREN)
759 0 : GCC_BAD ("missing %<(%> after %<#pragma GCC visibility push%> - ignored");
760 124837 : token = pragma_lex (&x);
761 124837 : if (token != CPP_NAME)
762 0 : GCC_BAD ("malformed %<#pragma GCC visibility push%>");
763 : else
764 124837 : push_visibility (IDENTIFIER_POINTER (x), 0);
765 124837 : if (pragma_lex (&x) != CPP_CLOSE_PAREN)
766 0 : GCC_BAD ("missing %<(%> after %<#pragma GCC visibility push%> - ignored");
767 : }
768 : }
769 249655 : if (pragma_lex (&x) != CPP_EOF)
770 0 : warning (OPT_Wpragmas, "junk at end of %<#pragma GCC visibility%>");
771 : }
772 :
773 : /* Helper routines for parsing #pragma GCC diagnostic. */
774 : class pragma_diagnostic_data
775 : {
776 : pragma_diagnostic_data (const pragma_diagnostic_data &) = delete;
777 : pragma_diagnostic_data& operator= (const pragma_diagnostic_data &) = delete;
778 :
779 : public:
780 : bool valid;
781 : location_t loc_kind, loc_option;
782 : enum pd_kind_t
783 : {
784 : PK_INVALID,
785 : PK_PUSH,
786 : PK_POP,
787 : PK_IGNORED_ATTRIBUTES,
788 : PK_DIAGNOSTIC,
789 : } pd_kind;
790 : enum diagnostics::kind diagnostic_kind;
791 : const char *kind_str;
792 : const char *option_str;
793 : bool own_option_str;
794 :
795 15324701 : pragma_diagnostic_data () { clear (); }
796 30649402 : void clear ()
797 : {
798 30649402 : valid = false;
799 30649402 : loc_kind = loc_option = UNKNOWN_LOCATION;
800 30649402 : pd_kind = PK_INVALID;
801 30649402 : diagnostic_kind = diagnostics::kind::unspecified;
802 30649402 : kind_str = option_str = nullptr;
803 30649402 : own_option_str = false;
804 : }
805 :
806 15324701 : ~pragma_diagnostic_data ()
807 : {
808 15324701 : if (own_option_str && option_str)
809 0 : XDELETEVEC (const_cast<char *> (option_str));
810 15324701 : }
811 :
812 15324691 : void set_kind (const char *kind_string)
813 : {
814 15324691 : kind_str = kind_string;
815 :
816 15324691 : pd_kind = PK_INVALID;
817 15324691 : diagnostic_kind = diagnostics::kind::unspecified;
818 15324691 : if (strcmp (kind_str, "push") == 0)
819 4900624 : pd_kind = PK_PUSH;
820 10424067 : else if (strcmp (kind_str, "pop") == 0)
821 4900045 : pd_kind = PK_POP;
822 5524022 : else if (strcmp (kind_str, "ignored_attributes") == 0)
823 77 : pd_kind = PK_IGNORED_ATTRIBUTES;
824 5523945 : else if (strcmp (kind_str, "error") == 0)
825 : {
826 63 : pd_kind = PK_DIAGNOSTIC;
827 63 : diagnostic_kind = diagnostics::kind::error;
828 : }
829 5523882 : else if (strcmp (kind_str, "warning") == 0)
830 : {
831 63 : pd_kind = PK_DIAGNOSTIC;
832 63 : diagnostic_kind = diagnostics::kind::warning;
833 : }
834 5523819 : else if (strcmp (kind_str, "ignored") == 0)
835 : {
836 5523811 : pd_kind = PK_DIAGNOSTIC;
837 5523811 : diagnostic_kind = diagnostics::kind::ignored;
838 : }
839 15324691 : }
840 :
841 15324683 : bool needs_option () const
842 : {
843 15324683 : return pd_kind == PK_IGNORED_ATTRIBUTES
844 15324683 : || pd_kind == PK_DIAGNOSTIC;
845 : }
846 :
847 : };
848 :
849 : /* This will call into either the C or C++ frontends as appropriate to get
850 : tokens from libcpp for the pragma. */
851 :
852 : static void
853 15324701 : pragma_diagnostic_lex (pragma_diagnostic_data *result)
854 : {
855 15324701 : result->clear ();
856 15324701 : tree x;
857 15324701 : auto ttype = pragma_lex (&x, &result->loc_kind);
858 15324701 : if (ttype != CPP_NAME)
859 18 : return;
860 15324691 : result->set_kind (IDENTIFIER_POINTER (x));
861 15324691 : if (result->pd_kind == pragma_diagnostic_data::PK_INVALID)
862 : return;
863 :
864 15324683 : if (result->needs_option ())
865 : {
866 5524014 : ttype = pragma_lex (&x, &result->loc_option);
867 5524014 : if (ttype != CPP_STRING)
868 : return;
869 5524014 : result->option_str = TREE_STRING_POINTER (x);
870 : }
871 :
872 15324683 : result->valid = true;
873 : }
874 :
875 : /* Handle #pragma GCC diagnostic. Early mode is used by frontends (such as C++)
876 : that do not process the deferred pragma while they are consuming tokens; they
877 : can use early mode to make sure diagnostics affecting the preprocessor itself
878 : are correctly modified by the #pragma. */
879 : template<bool early, bool is_pp> static void
880 15324701 : handle_pragma_diagnostic_impl ()
881 : {
882 : static const bool want_diagnostics = (is_pp || !early);
883 :
884 15324701 : pragma_diagnostic_data data;
885 15324701 : pragma_diagnostic_lex (&data);
886 :
887 15324701 : if (!data.kind_str)
888 : {
889 : if (want_diagnostics)
890 7 : warning_at (data.loc_kind, OPT_Wpragmas,
891 : "missing %<error%>, %<warning%>, %<ignored%>, %<push%>, "
892 : "%<pop%>, or %<ignored_attributes%> after "
893 : "%<#pragma GCC diagnostic%>");
894 7 : return;
895 : }
896 :
897 15324691 : switch (data.pd_kind)
898 : {
899 :
900 4900624 : case pragma_diagnostic_data::PK_PUSH:
901 4900624 : diagnostic_push_diagnostics (global_dc, input_location);
902 4900624 : return;
903 :
904 4900045 : case pragma_diagnostic_data::PK_POP:
905 4900045 : diagnostic_pop_diagnostics (global_dc, input_location);
906 4900045 : return;
907 :
908 : case pragma_diagnostic_data::PK_IGNORED_ATTRIBUTES:
909 : {
910 : if (early)
911 : return;
912 44 : if (!data.option_str)
913 : {
914 0 : warning_at (data.loc_option, OPT_Wpragmas,
915 : "missing attribute name after %<#pragma GCC diagnostic "
916 : "ignored_attributes%>");
917 0 : return;
918 : }
919 44 : char *args = xstrdup (data.option_str);
920 44 : const size_t l = strlen (args);
921 44 : if (l == 0)
922 : {
923 0 : warning_at (data.loc_option, OPT_Wpragmas,
924 : "missing argument to %<#pragma GCC "
925 : "diagnostic ignored_attributes%>");
926 0 : free (args);
927 0 : return;
928 : }
929 44 : else if (args[l - 1] == ',')
930 : {
931 0 : warning_at (data.loc_option, OPT_Wpragmas,
932 : "trailing %<,%> in arguments for "
933 : "%<#pragma GCC diagnostic ignored_attributes%>");
934 0 : free (args);
935 0 : return;
936 : }
937 44 : auto_vec<char *> v;
938 108 : for (char *p = strtok (args, ","); p; p = strtok (NULL, ","))
939 64 : v.safe_push (p);
940 44 : handle_ignored_attributes_option (&v);
941 44 : free (args);
942 : return;
943 44 : }
944 :
945 5523937 : case pragma_diagnostic_data::PK_DIAGNOSTIC:
946 5523937 : if (!data.option_str)
947 : {
948 : if (want_diagnostics)
949 0 : warning_at (data.loc_option, OPT_Wpragmas,
950 : "missing option after %<#pragma GCC diagnostic%> kind");
951 0 : return;
952 : }
953 : break;
954 :
955 5 : default:
956 : if (want_diagnostics)
957 5 : warning_at (data.loc_kind, OPT_Wpragmas,
958 : "expected %<error%>, %<warning%>, %<ignored%>, %<push%>, "
959 : "%<pop%>, %<ignored_attributes%> after "
960 : "%<#pragma GCC diagnostic%>");
961 5 : return;
962 :
963 : }
964 :
965 : gcc_assert (data.pd_kind == pragma_diagnostic_data::PK_DIAGNOSTIC);
966 5523937 : gcc_assert (data.valid);
967 :
968 5523937 : unsigned int lang_mask = c_common_option_lang_mask () | CL_COMMON;
969 : /* option_string + 1 to skip the initial '-' */
970 5523937 : unsigned int option_index = find_opt (data.option_str + 1, lang_mask);
971 :
972 2710158 : if (early && !(c_option_is_from_cpp_diagnostics (option_index)
973 2710158 : || option_index == OPT_Wunknown_pragmas))
974 : return;
975 :
976 4496506 : if (option_index == OPT_SPECIAL_unknown)
977 : {
978 : if (want_diagnostics)
979 : {
980 11 : auto_diagnostic_group d;
981 11 : if (warning_at (data.loc_option, OPT_Wpragmas,
982 : "unknown option after %<#pragma GCC diagnostic%> kind"))
983 : {
984 11 : option_proposer op;
985 11 : const char *hint = op.suggest_option (data.option_str + 1);
986 11 : if (hint)
987 4 : inform (data.loc_option, "did you mean %<-%s%>?", hint);
988 11 : }
989 11 : }
990 11 : return;
991 : }
992 4496495 : else if (!(cl_options[option_index].flags & CL_WARNING))
993 : {
994 : if (want_diagnostics)
995 11 : warning_at (data.loc_option, OPT_Wpragmas,
996 : "%qs is not an option that controls warnings",
997 : data.option_str);
998 11 : return;
999 : }
1000 4496484 : else if (!(cl_options[option_index].flags & lang_mask))
1001 : {
1002 : if (want_diagnostics)
1003 : {
1004 1 : char *ok_langs = write_langs (cl_options[option_index].flags);
1005 1 : char *bad_lang = write_langs (c_common_option_lang_mask ());
1006 1 : warning_at (data.loc_option, OPT_Wpragmas,
1007 : "option %qs is valid for %s but not for %s",
1008 : data.option_str, ok_langs, bad_lang);
1009 1 : free (ok_langs);
1010 1 : free (bad_lang);
1011 : }
1012 1 : return;
1013 : }
1014 :
1015 4496483 : const char *arg = NULL;
1016 4496483 : if (cl_options[option_index].flags & CL_JOINED)
1017 18 : arg = data.option_str + 1 + cl_options[option_index].opt_len;
1018 :
1019 : struct cl_option_handlers handlers;
1020 4496483 : set_default_handlers (&handlers, NULL);
1021 : /* FIXME: input_location isn't the best location here, but it is
1022 : what we used to do here before and changing it breaks e.g.
1023 : PR69543 and PR69558. */
1024 4496483 : control_warning_option (option_index, (int) data.diagnostic_kind,
1025 : arg,
1026 4496483 : data.diagnostic_kind != diagnostics::kind::ignored,
1027 : input_location, lang_mask, &handlers,
1028 : &global_options, &global_options_set,
1029 : global_dc);
1030 15324701 : }
1031 :
1032 : static void
1033 7819681 : handle_pragma_diagnostic (cpp_reader *)
1034 : {
1035 7819681 : handle_pragma_diagnostic_impl<false, false> ();
1036 7819681 : }
1037 :
1038 : static void
1039 7471375 : handle_pragma_diagnostic_early (cpp_reader *)
1040 : {
1041 7471375 : handle_pragma_diagnostic_impl<true, false> ();
1042 7471375 : }
1043 :
1044 : static void
1045 33645 : handle_pragma_diagnostic_early_pp (cpp_reader *)
1046 : {
1047 33645 : handle_pragma_diagnostic_impl<true, true> ();
1048 33645 : }
1049 :
1050 : /* Parse #pragma GCC suppress_coverage begin|end to stop lines from contributing
1051 : towards (missing) coverage. */
1052 : static void
1053 717 : handle_pragma_suppress_coverage (cpp_reader*)
1054 : {
1055 717 : tree x;
1056 717 : location_t loc;
1057 717 : auto token = pragma_lex (&x);
1058 717 : enum { bad, begin, end } action = bad;
1059 :
1060 717 : if (token == CPP_NAME)
1061 : {
1062 716 : const char *op = IDENTIFIER_POINTER (x);
1063 716 : if (!strcmp (op, "begin"))
1064 : action = begin;
1065 359 : else if (!strcmp (op, "end"))
1066 : action = end;
1067 : }
1068 :
1069 : if (bad == action)
1070 4 : GCC_BAD ("%<#pragma GCC suppress_coverage%> must be followed by %<begin%> "
1071 : "or %<end%>");
1072 716 : else if (end == action)
1073 : {
1074 359 : if (!suppress_coverage_end (input_location))
1075 2 : GCC_BAD ("no matching begin for %<#pragma GCC suppress_coverage end%>");
1076 : }
1077 : else
1078 357 : suppress_coverage_begin (input_location);
1079 :
1080 714 : if (pragma_lex (&x, &loc) != CPP_EOF)
1081 714 : GCC_BAD_AT (loc, "junk at end of %<#pragma GCC suppress_coverage%>");
1082 : }
1083 :
1084 : /* Parse #pragma GCC target (xxx) to set target specific options. */
1085 : static void
1086 575166 : handle_pragma_target(cpp_reader *)
1087 : {
1088 575166 : location_t loc;
1089 575166 : enum cpp_ttype token;
1090 575166 : tree x;
1091 575166 : bool close_paren_needed_p = false;
1092 :
1093 575166 : if (cfun)
1094 : {
1095 0 : error ("%<#pragma GCC option%> is not allowed inside functions");
1096 2 : return;
1097 : }
1098 :
1099 575166 : token = pragma_lex (&x, &loc);
1100 575166 : if (token == CPP_OPEN_PAREN)
1101 : {
1102 575110 : close_paren_needed_p = true;
1103 575110 : token = pragma_lex (&x, &loc);
1104 : }
1105 :
1106 575166 : if (token != CPP_STRING)
1107 2 : GCC_BAD_AT (loc, "%<#pragma GCC option%> is not a string");
1108 :
1109 : /* Strings are user options. */
1110 : else
1111 : {
1112 : tree args = NULL_TREE;
1113 :
1114 575182 : do
1115 : {
1116 : /* Build up the strings now as a tree linked list. Skip empty
1117 : strings. */
1118 575182 : if (TREE_STRING_LENGTH (x) > 0)
1119 575182 : args = tree_cons (NULL_TREE, x, args);
1120 :
1121 575182 : token = pragma_lex (&x);
1122 1150382 : while (token == CPP_COMMA)
1123 18 : token = pragma_lex (&x);
1124 : }
1125 575182 : while (token == CPP_STRING);
1126 :
1127 575164 : if (close_paren_needed_p)
1128 : {
1129 575109 : if (token == CPP_CLOSE_PAREN)
1130 575109 : token = pragma_lex (&x);
1131 : else
1132 575109 : GCC_BAD ("%<#pragma GCC target (string [,string]...)%> does "
1133 : "not have a final %<)%>");
1134 : }
1135 :
1136 575164 : if (token != CPP_EOF)
1137 : {
1138 0 : error ("%<#pragma GCC target%> string is badly formed");
1139 0 : return;
1140 : }
1141 :
1142 : /* put arguments in the order the user typed them. */
1143 575164 : args = nreverse (args);
1144 :
1145 575164 : if (targetm.target_option.pragma_parse (args, NULL_TREE))
1146 574895 : current_target_pragma = chainon (current_target_pragma, args);
1147 :
1148 : /* A target pragma can also influence optimization options. */
1149 575164 : tree current_optimize
1150 575164 : = build_optimization_node (&global_options, &global_options_set);
1151 575164 : if (current_optimize != optimization_current_node)
1152 80 : optimization_current_node = current_optimize;
1153 : }
1154 : }
1155 :
1156 : /* Handle #pragma GCC optimize to set optimization options. */
1157 : static void
1158 537 : handle_pragma_optimize (cpp_reader *)
1159 : {
1160 537 : enum cpp_ttype token;
1161 537 : tree x;
1162 537 : bool close_paren_needed_p = false;
1163 537 : tree optimization_previous_node = optimization_current_node;
1164 :
1165 537 : if (cfun)
1166 : {
1167 0 : error ("%<#pragma GCC optimize%> is not allowed inside functions");
1168 0 : return;
1169 : }
1170 :
1171 537 : token = pragma_lex (&x);
1172 537 : if (token == CPP_OPEN_PAREN)
1173 : {
1174 126 : close_paren_needed_p = true;
1175 126 : token = pragma_lex (&x);
1176 : }
1177 :
1178 537 : if (token != CPP_STRING && token != CPP_NUMBER)
1179 0 : GCC_BAD ("%<#pragma GCC optimize%> is not a string or number");
1180 :
1181 : /* Strings/numbers are user options. */
1182 : else
1183 : {
1184 : tree args = NULL_TREE;
1185 :
1186 553 : do
1187 : {
1188 : /* Build up the numbers/strings now as a list. */
1189 553 : if (token != CPP_STRING || TREE_STRING_LENGTH (x) > 0)
1190 553 : args = tree_cons (NULL_TREE, x, args);
1191 :
1192 553 : token = pragma_lex (&x);
1193 1122 : while (token == CPP_COMMA)
1194 16 : token = pragma_lex (&x);
1195 : }
1196 553 : while (token == CPP_STRING || token == CPP_NUMBER);
1197 :
1198 537 : if (close_paren_needed_p)
1199 : {
1200 126 : if (token == CPP_CLOSE_PAREN)
1201 126 : token = pragma_lex (&x);
1202 : else
1203 126 : GCC_BAD ("%<#pragma GCC optimize (string [,string]...)%> does "
1204 : "not have a final %<)%>");
1205 : }
1206 :
1207 537 : if (token != CPP_EOF)
1208 : {
1209 0 : error ("%<#pragma GCC optimize%> string is badly formed");
1210 0 : return;
1211 : }
1212 :
1213 : /* put arguments in the order the user typed them. */
1214 537 : args = nreverse (args);
1215 :
1216 537 : parse_optimize_options (args, false);
1217 537 : current_optimize_pragma = chainon (current_optimize_pragma, args);
1218 537 : optimization_current_node
1219 537 : = build_optimization_node (&global_options, &global_options_set);
1220 537 : c_cpp_builtins_optimize_pragma (parse_in,
1221 : optimization_previous_node,
1222 : optimization_current_node);
1223 : }
1224 : }
1225 :
1226 : /* Stack of the #pragma GCC options created with #pragma GCC push_option. Save
1227 : both the binary representation of the options and the TREE_LIST of
1228 : strings that will be added to the function's attribute list. */
1229 : struct GTY(()) opt_stack {
1230 : struct opt_stack *prev;
1231 : tree target_binary;
1232 : tree target_strings;
1233 : tree optimize_binary;
1234 : tree optimize_strings;
1235 : gcc_options * GTY ((skip)) saved_global_options;
1236 : };
1237 :
1238 : static GTY(()) struct opt_stack * options_stack;
1239 :
1240 : /* Handle #pragma GCC push_options to save the current target and optimization
1241 : options. */
1242 :
1243 : static void
1244 575376 : handle_pragma_push_options (cpp_reader *)
1245 : {
1246 575376 : enum cpp_ttype token;
1247 575376 : tree x = 0;
1248 :
1249 575376 : token = pragma_lex (&x);
1250 575376 : if (token != CPP_EOF)
1251 : {
1252 0 : warning (OPT_Wpragmas, "junk at end of %<#pragma GCC push_options%>");
1253 0 : return;
1254 : }
1255 :
1256 575376 : opt_stack *p = ggc_alloc<opt_stack> ();
1257 575376 : p->prev = options_stack;
1258 575376 : options_stack = p;
1259 :
1260 : /* Save optimization and target flags in binary format. */
1261 575376 : if (flag_checking)
1262 : {
1263 575376 : p->saved_global_options = XNEW (gcc_options);
1264 575376 : *p->saved_global_options = global_options;
1265 : }
1266 575376 : p->optimize_binary = build_optimization_node (&global_options,
1267 : &global_options_set);
1268 575376 : p->target_binary = build_target_option_node (&global_options,
1269 : &global_options_set);
1270 :
1271 : /* Save optimization and target flags in string list format. */
1272 575376 : p->optimize_strings = copy_list (current_optimize_pragma);
1273 575376 : p->target_strings = copy_list (current_target_pragma);
1274 : }
1275 :
1276 : /* Handle #pragma GCC pop_options to restore the current target and
1277 : optimization options from a previous push_options. */
1278 :
1279 : static void
1280 575375 : handle_pragma_pop_options (cpp_reader *)
1281 : {
1282 575375 : enum cpp_ttype token;
1283 575375 : tree x = 0;
1284 575375 : opt_stack *p;
1285 :
1286 575375 : token = pragma_lex (&x);
1287 575375 : if (token != CPP_EOF)
1288 : {
1289 0 : warning (OPT_Wpragmas, "junk at end of %<#pragma GCC pop_options%>");
1290 0 : return;
1291 : }
1292 :
1293 575375 : if (! options_stack)
1294 : {
1295 0 : warning (OPT_Wpragmas,
1296 : "%<#pragma GCC pop_options%> without a corresponding "
1297 : "%<#pragma GCC push_options%>");
1298 0 : return;
1299 : }
1300 :
1301 575375 : p = options_stack;
1302 575375 : options_stack = p->prev;
1303 :
1304 575375 : if (p->target_binary != target_option_current_node)
1305 : {
1306 570142 : (void) targetm.target_option.pragma_parse (NULL_TREE, p->target_binary);
1307 570142 : target_option_current_node = p->target_binary;
1308 : }
1309 :
1310 : /* Always restore optimization options as optimization_current_node is
1311 : * overwritten by invoke_set_current_function_hook. */
1312 1150750 : cl_optimization_restore (&global_options, &global_options_set,
1313 575375 : TREE_OPTIMIZATION (p->optimize_binary));
1314 1150750 : cl_target_option_restore (&global_options, &global_options_set,
1315 575375 : TREE_TARGET_OPTION (p->target_binary));
1316 :
1317 575375 : if (p->optimize_binary != optimization_current_node)
1318 : {
1319 52 : c_cpp_builtins_optimize_pragma (parse_in, optimization_current_node,
1320 : p->optimize_binary);
1321 52 : optimization_current_node = p->optimize_binary;
1322 : }
1323 575375 : if (flag_checking && !seen_error ())
1324 : {
1325 575371 : cl_optimization_compare (p->saved_global_options, &global_options);
1326 575371 : free (p->saved_global_options);
1327 : }
1328 :
1329 575375 : current_target_pragma = p->target_strings;
1330 575375 : current_optimize_pragma = p->optimize_strings;
1331 : }
1332 :
1333 : /* This is mostly a helper for handle_pragma_reset_options () to do the actual
1334 : work, but the C++ frontend, for example, needs an external interface to
1335 : perform this operation, since it processes target pragmas twice. (Once for
1336 : preprocessing purposes, and then again during compilation.) */
1337 :
1338 : void
1339 99522 : c_reset_target_pragmas ()
1340 : {
1341 99522 : tree new_optimize = optimization_default_node;
1342 99522 : tree new_target = target_option_default_node;
1343 99522 : if (new_target != target_option_current_node)
1344 : {
1345 41 : (void) targetm.target_option.pragma_parse (NULL_TREE, new_target);
1346 41 : target_option_current_node = new_target;
1347 : }
1348 :
1349 99522 : if (new_optimize != optimization_current_node)
1350 : {
1351 49 : tree old_optimize = optimization_current_node;
1352 49 : cl_optimization_restore (&global_options, &global_options_set,
1353 49 : TREE_OPTIMIZATION (new_optimize));
1354 49 : c_cpp_builtins_optimize_pragma (parse_in, old_optimize, new_optimize);
1355 49 : optimization_current_node = new_optimize;
1356 : }
1357 :
1358 99522 : current_target_pragma = NULL_TREE;
1359 99522 : current_optimize_pragma = NULL_TREE;
1360 99522 : }
1361 :
1362 : /* Handle #pragma GCC reset_options to restore the current target and
1363 : optimization options to the original options used on the command line. */
1364 :
1365 : static void
1366 4 : handle_pragma_reset_options (cpp_reader *)
1367 : {
1368 4 : tree x;
1369 4 : if (pragma_lex (&x) != CPP_EOF)
1370 0 : warning (OPT_Wpragmas, "junk at end of %<#pragma reset_options%>");
1371 : else
1372 4 : c_reset_target_pragmas ();
1373 4 : }
1374 :
1375 : /* Print a plain user-specified message. */
1376 :
1377 : static void
1378 56 : handle_pragma_message (cpp_reader *)
1379 : {
1380 56 : location_t loc;
1381 56 : enum cpp_ttype token;
1382 56 : tree x, message = 0;
1383 :
1384 56 : token = pragma_lex (&x);
1385 56 : if (token == CPP_OPEN_PAREN)
1386 : {
1387 21 : token = pragma_lex (&x);
1388 21 : if (token == CPP_STRING)
1389 14 : message = x;
1390 : else
1391 20 : GCC_BAD ("expected a string after %<#pragma message%>");
1392 14 : if (pragma_lex (&x) != CPP_CLOSE_PAREN)
1393 1 : GCC_BAD ("malformed %<#pragma message%>, ignored");
1394 : }
1395 35 : else if (token == CPP_STRING)
1396 23 : message = x;
1397 12 : else if (token == CPP_STRING_USERDEF)
1398 3 : GCC_BAD ("string literal with user-defined suffix is invalid in this "
1399 : "context");
1400 : else
1401 9 : GCC_BAD ("expected a string after %<#pragma message%>");
1402 :
1403 36 : gcc_assert (message);
1404 :
1405 36 : if (pragma_lex (&x, &loc) != CPP_EOF)
1406 3 : warning_at (loc, OPT_Wpragmas, "junk at end of %<#pragma message%>");
1407 :
1408 36 : if (TREE_STRING_LENGTH (message) > 1)
1409 32 : inform (input_location, "%<#pragma message: %s%>",
1410 32 : TREE_STRING_POINTER (message));
1411 : }
1412 :
1413 : /* Ignore a no-op pragma that GCC recognizes, but which has no effect. */
1414 : static void
1415 16 : handle_pragma_ignore (cpp_reader *)
1416 : {
1417 16 : }
1418 :
1419 : /* Mark whether the current location is valid for a STDC pragma. */
1420 :
1421 : static bool valid_location_for_stdc_pragma;
1422 :
1423 : void
1424 132426492 : mark_valid_location_for_stdc_pragma (bool flag)
1425 : {
1426 132426492 : valid_location_for_stdc_pragma = flag;
1427 132426492 : }
1428 :
1429 : /* Return true if the current location is valid for a STDC pragma. */
1430 :
1431 : bool
1432 38626525 : valid_location_for_stdc_pragma_p (void)
1433 : {
1434 38626525 : return valid_location_for_stdc_pragma;
1435 : }
1436 :
1437 : enum pragma_switch_t { PRAGMA_ON, PRAGMA_OFF, PRAGMA_DEFAULT, PRAGMA_BAD };
1438 :
1439 : /* A STDC pragma must appear outside of external declarations or
1440 : preceding all explicit declarations and statements inside a compound
1441 : statement; its behavior is undefined if used in any other context.
1442 : It takes a switch of ON, OFF, or DEFAULT. */
1443 :
1444 : static enum pragma_switch_t
1445 66 : handle_stdc_pragma (const char *pname)
1446 : {
1447 66 : const char *arg;
1448 66 : tree t;
1449 66 : enum pragma_switch_t ret;
1450 :
1451 66 : if (!valid_location_for_stdc_pragma_p ())
1452 : {
1453 12 : warning (OPT_Wpragmas, "invalid location for %<pragma %s%>, ignored",
1454 : pname);
1455 12 : return PRAGMA_BAD;
1456 : }
1457 :
1458 54 : if (pragma_lex (&t) != CPP_NAME)
1459 : {
1460 2 : warning (OPT_Wpragmas, "malformed %<#pragma %s%>, ignored", pname);
1461 2 : return PRAGMA_BAD;
1462 : }
1463 :
1464 52 : arg = IDENTIFIER_POINTER (t);
1465 :
1466 52 : if (!strcmp (arg, "ON"))
1467 : ret = PRAGMA_ON;
1468 30 : else if (!strcmp (arg, "OFF"))
1469 : ret = PRAGMA_OFF;
1470 11 : else if (!strcmp (arg, "DEFAULT"))
1471 : ret = PRAGMA_DEFAULT;
1472 : else
1473 : {
1474 2 : warning (OPT_Wpragmas, "malformed %<#pragma %s%>, ignored", pname);
1475 2 : return PRAGMA_BAD;
1476 : }
1477 :
1478 50 : if (pragma_lex (&t) != CPP_EOF)
1479 : {
1480 2 : warning (OPT_Wpragmas, "junk at end of %<#pragma %s%>", pname);
1481 2 : return PRAGMA_BAD;
1482 : }
1483 :
1484 : return ret;
1485 : }
1486 :
1487 : /* #pragma STDC FLOAT_CONST_DECIMAL64 ON
1488 : #pragma STDC FLOAT_CONST_DECIMAL64 OFF
1489 : #pragma STDC FLOAT_CONST_DECIMAL64 DEFAULT */
1490 :
1491 : static void
1492 69 : handle_pragma_float_const_decimal64 (cpp_reader *)
1493 : {
1494 69 : if (c_dialect_cxx ())
1495 : {
1496 3 : if (warn_unknown_pragmas > in_system_header_at (input_location))
1497 3 : warning (OPT_Wunknown_pragmas,
1498 : "%<#pragma STDC FLOAT_CONST_DECIMAL64%> is not supported"
1499 : " for C++");
1500 : return;
1501 : }
1502 :
1503 66 : if (!targetm.decimal_float_supported_p ())
1504 : {
1505 0 : if (warn_unknown_pragmas > in_system_header_at (input_location))
1506 0 : warning (OPT_Wunknown_pragmas,
1507 : "%<#pragma STDC FLOAT_CONST_DECIMAL64%> is not supported"
1508 : " on this target");
1509 : return;
1510 : }
1511 :
1512 66 : pedwarn (input_location, OPT_Wpedantic,
1513 : "ISO C does not support %<#pragma STDC FLOAT_CONST_DECIMAL64%>");
1514 :
1515 66 : switch (handle_stdc_pragma ("STDC FLOAT_CONST_DECIMAL64"))
1516 : {
1517 20 : case PRAGMA_ON:
1518 20 : set_float_const_decimal64 ();
1519 20 : break;
1520 28 : case PRAGMA_OFF:
1521 28 : case PRAGMA_DEFAULT:
1522 28 : clear_float_const_decimal64 ();
1523 28 : break;
1524 : case PRAGMA_BAD:
1525 : break;
1526 : }
1527 : }
1528 :
1529 : /* A vector of registered pragma callbacks, which is never freed. */
1530 :
1531 :
1532 : struct pragma_data
1533 : {
1534 : const char *space;
1535 : const char *name;
1536 : struct internal_pragma_handler ihandler;
1537 : };
1538 :
1539 : static vec<pragma_data> registered_pragmas;
1540 :
1541 : struct omp_pragma_def { const char *name; unsigned int id; };
1542 : static const struct omp_pragma_def oacc_pragmas[] = {
1543 : { "atomic", PRAGMA_OACC_ATOMIC },
1544 : { "cache", PRAGMA_OACC_CACHE },
1545 : { "data", PRAGMA_OACC_DATA },
1546 : { "declare", PRAGMA_OACC_DECLARE },
1547 : { "enter", PRAGMA_OACC_ENTER_DATA },
1548 : { "exit", PRAGMA_OACC_EXIT_DATA },
1549 : { "host_data", PRAGMA_OACC_HOST_DATA },
1550 : { "kernels", PRAGMA_OACC_KERNELS },
1551 : { "loop", PRAGMA_OACC_LOOP },
1552 : { "parallel", PRAGMA_OACC_PARALLEL },
1553 : { "routine", PRAGMA_OACC_ROUTINE },
1554 : { "serial", PRAGMA_OACC_SERIAL },
1555 : { "update", PRAGMA_OACC_UPDATE },
1556 : { "wait", PRAGMA_OACC_WAIT }
1557 : };
1558 : static const struct omp_pragma_def omp_pragmas[] = {
1559 : { "allocate", PRAGMA_OMP_ALLOCATE },
1560 : { "assumes", PRAGMA_OMP_ASSUMES },
1561 : { "atomic", PRAGMA_OMP_ATOMIC },
1562 : { "barrier", PRAGMA_OMP_BARRIER },
1563 : { "begin", PRAGMA_OMP_BEGIN },
1564 : { "cancel", PRAGMA_OMP_CANCEL },
1565 : { "cancellation", PRAGMA_OMP_CANCELLATION_POINT },
1566 : { "critical", PRAGMA_OMP_CRITICAL },
1567 : { "depobj", PRAGMA_OMP_DEPOBJ },
1568 : { "dispatch", PRAGMA_OMP_DISPATCH },
1569 : { "error", PRAGMA_OMP_ERROR },
1570 : { "end", PRAGMA_OMP_END },
1571 : { "flush", PRAGMA_OMP_FLUSH },
1572 : { "groupprivate", PRAGMA_OMP_GROUPPRIVATE },
1573 : { "interop", PRAGMA_OMP_INTEROP },
1574 : { "metadirective", PRAGMA_OMP_METADIRECTIVE },
1575 : { "nothing", PRAGMA_OMP_NOTHING },
1576 : { "requires", PRAGMA_OMP_REQUIRES },
1577 : { "scope", PRAGMA_OMP_SCOPE },
1578 : { "section", PRAGMA_OMP_SECTION },
1579 : { "sections", PRAGMA_OMP_SECTIONS },
1580 : { "single", PRAGMA_OMP_SINGLE },
1581 : { "task", PRAGMA_OMP_TASK },
1582 : { "taskgroup", PRAGMA_OMP_TASKGROUP },
1583 : { "taskwait", PRAGMA_OMP_TASKWAIT },
1584 : { "taskyield", PRAGMA_OMP_TASKYIELD },
1585 : { "threadprivate", PRAGMA_OMP_THREADPRIVATE }
1586 : };
1587 : static const struct omp_pragma_def omp_pragmas_simd[] = {
1588 : { "assume", PRAGMA_OMP_ASSUME },
1589 : { "declare", PRAGMA_OMP_DECLARE },
1590 : { "distribute", PRAGMA_OMP_DISTRIBUTE },
1591 : { "for", PRAGMA_OMP_FOR },
1592 : { "loop", PRAGMA_OMP_LOOP },
1593 : { "masked", PRAGMA_OMP_MASKED },
1594 : { "master", PRAGMA_OMP_MASTER },
1595 : { "ordered", PRAGMA_OMP_ORDERED },
1596 : { "parallel", PRAGMA_OMP_PARALLEL },
1597 : { "scan", PRAGMA_OMP_SCAN },
1598 : { "simd", PRAGMA_OMP_SIMD },
1599 : { "target", PRAGMA_OMP_TARGET },
1600 : { "taskloop", PRAGMA_OMP_TASKLOOP },
1601 : { "teams", PRAGMA_OMP_TEAMS },
1602 : { "tile", PRAGMA_OMP_TILE },
1603 : { "unroll", PRAGMA_OMP_UNROLL },
1604 : };
1605 :
1606 : void
1607 41650 : c_pp_lookup_pragma (unsigned int id, const char **space, const char **name)
1608 : {
1609 41650 : const int n_oacc_pragmas = ARRAY_SIZE (oacc_pragmas);
1610 41650 : const int n_omp_pragmas = ARRAY_SIZE (omp_pragmas);
1611 41650 : const int n_omp_pragmas_simd = ARRAY_SIZE (omp_pragmas_simd);
1612 41650 : int i;
1613 :
1614 624750 : for (i = 0; i < n_oacc_pragmas; ++i)
1615 583100 : if (oacc_pragmas[i].id == id)
1616 : {
1617 0 : *space = "acc";
1618 0 : *name = oacc_pragmas[i].name;
1619 0 : return;
1620 : }
1621 :
1622 1165978 : for (i = 0; i < n_omp_pragmas; ++i)
1623 1124356 : if (omp_pragmas[i].id == id)
1624 : {
1625 28 : *space = "omp";
1626 28 : *name = omp_pragmas[i].name;
1627 28 : return;
1628 : }
1629 :
1630 707004 : for (i = 0; i < n_omp_pragmas_simd; ++i)
1631 665448 : if (omp_pragmas_simd[i].id == id)
1632 : {
1633 66 : *space = "omp";
1634 66 : *name = omp_pragmas_simd[i].name;
1635 66 : return;
1636 : }
1637 :
1638 41556 : if (id >= PRAGMA_FIRST_EXTERNAL
1639 83112 : && (id < PRAGMA_FIRST_EXTERNAL + registered_pragmas.length ()))
1640 : {
1641 41556 : *space = registered_pragmas[id - PRAGMA_FIRST_EXTERNAL].space;
1642 41556 : *name = registered_pragmas[id - PRAGMA_FIRST_EXTERNAL].name;
1643 41556 : return;
1644 : }
1645 :
1646 0 : gcc_unreachable ();
1647 : }
1648 :
1649 : /* Front-end wrappers for pragma registration to avoid dragging
1650 : cpplib.h in almost everywhere. */
1651 :
1652 : static void
1653 4043753 : c_register_pragma_1 (const char *space, const char *name,
1654 : internal_pragma_handler ihandler, bool allow_expansion)
1655 : {
1656 4043753 : unsigned id;
1657 :
1658 4043753 : pragma_data data;
1659 4043753 : data.space = space;
1660 4043753 : data.name = name;
1661 :
1662 4043753 : if (flag_preprocess_only
1663 115584 : && (cpp_get_options (parse_in)->directives_only
1664 114016 : || !(allow_expansion || ihandler.early_handler.handler_1arg)))
1665 58576 : return;
1666 :
1667 3985177 : data.ihandler = ihandler;
1668 3985177 : registered_pragmas.safe_push (data);
1669 3985177 : id = registered_pragmas.length ();
1670 7970354 : id += PRAGMA_FIRST_EXTERNAL - 1;
1671 :
1672 : /* The C front end allocates 8 bits in c_token. The C++ front end
1673 : keeps the pragma kind in the form of INTEGER_CST, so no small
1674 : limit applies. At present this is sufficient. */
1675 3985177 : gcc_assert (id < 256);
1676 :
1677 3985177 : cpp_register_deferred_pragma (parse_in, space, name, id,
1678 : allow_expansion, false);
1679 : }
1680 :
1681 : /* Register a C pragma handler, using a space and a name. It disallows pragma
1682 : expansion (if you want it, use c_register_pragma_with_expansion instead). */
1683 : void
1684 2320545 : c_register_pragma (const char *space, const char *name,
1685 : pragma_handler_1arg handler)
1686 : {
1687 2320545 : c_register_pragma_with_early_handler (space, name, handler, nullptr);
1688 2320545 : }
1689 3612951 : void c_register_pragma_with_early_handler (const char *space, const char *name,
1690 : pragma_handler_1arg handler,
1691 : pragma_handler_1arg early_handler)
1692 : {
1693 3612951 : internal_pragma_handler ihandler;
1694 :
1695 3612951 : ihandler.handler.handler_1arg = handler;
1696 3612951 : ihandler.early_handler.handler_1arg = early_handler;
1697 3612951 : ihandler.extra_data = false;
1698 3612951 : ihandler.data = NULL;
1699 3612951 : c_register_pragma_1 (space, name, ihandler, false);
1700 3612951 : }
1701 :
1702 : /* Register a C pragma handler, using a space and a name, it also carries an
1703 : extra data field which can be used by the handler. It disallows pragma
1704 : expansion (if you want it, use c_register_pragma_with_expansion_and_data
1705 : instead). */
1706 : void
1707 0 : c_register_pragma_with_data (const char *space, const char *name,
1708 : pragma_handler_2arg handler, void * data)
1709 : {
1710 0 : internal_pragma_handler ihandler;
1711 :
1712 0 : ihandler.handler.handler_2arg = handler;
1713 0 : ihandler.early_handler.handler_2arg = nullptr;
1714 0 : ihandler.extra_data = true;
1715 0 : ihandler.data = data;
1716 0 : c_register_pragma_1 (space, name, ihandler, false);
1717 0 : }
1718 :
1719 : /* Register a C pragma handler, using a space and a name. It allows pragma
1720 : expansion as in the following example:
1721 :
1722 : #define NUMBER 10
1723 : #pragma count (NUMBER)
1724 :
1725 : Name expansion is still disallowed. */
1726 : void
1727 430802 : c_register_pragma_with_expansion (const char *space, const char *name,
1728 : pragma_handler_1arg handler)
1729 : {
1730 430802 : internal_pragma_handler ihandler;
1731 :
1732 430802 : ihandler.handler.handler_1arg = handler;
1733 430802 : ihandler.early_handler.handler_1arg = nullptr;
1734 430802 : ihandler.extra_data = false;
1735 430802 : ihandler.data = NULL;
1736 430802 : c_register_pragma_1 (space, name, ihandler, true);
1737 430802 : }
1738 :
1739 : /* Register a C pragma handler, using a space and a name, it also carries an
1740 : extra data field which can be used by the handler. It allows pragma
1741 : expansion as in the following example:
1742 :
1743 : #define NUMBER 10
1744 : #pragma count (NUMBER)
1745 :
1746 : Name expansion is still disallowed. */
1747 : void
1748 0 : c_register_pragma_with_expansion_and_data (const char *space, const char *name,
1749 : pragma_handler_2arg handler,
1750 : void *data)
1751 : {
1752 0 : internal_pragma_handler ihandler;
1753 :
1754 0 : ihandler.handler.handler_2arg = handler;
1755 0 : ihandler.early_handler.handler_2arg = nullptr;
1756 0 : ihandler.extra_data = true;
1757 0 : ihandler.data = data;
1758 0 : c_register_pragma_1 (space, name, ihandler, true);
1759 0 : }
1760 :
1761 : void
1762 9726963 : c_invoke_pragma_handler (unsigned int id)
1763 : {
1764 9726963 : internal_pragma_handler *ihandler;
1765 9726963 : pragma_handler_1arg handler_1arg;
1766 9726963 : pragma_handler_2arg handler_2arg;
1767 :
1768 9726963 : id -= PRAGMA_FIRST_EXTERNAL;
1769 9726963 : ihandler = ®istered_pragmas[id].ihandler;
1770 9726963 : if (ihandler->extra_data)
1771 : {
1772 0 : handler_2arg = ihandler->handler.handler_2arg;
1773 0 : handler_2arg (parse_in, ihandler->data);
1774 : }
1775 : else
1776 : {
1777 9726963 : handler_1arg = ihandler->handler.handler_1arg;
1778 9726963 : handler_1arg (parse_in);
1779 : }
1780 9726963 : }
1781 :
1782 : /* In contrast to the normal handler, the early handler is optional. */
1783 : void
1784 7782384 : c_invoke_early_pragma_handler (unsigned int id)
1785 : {
1786 7782384 : internal_pragma_handler *ihandler;
1787 7782384 : pragma_handler_1arg handler_1arg;
1788 7782384 : pragma_handler_2arg handler_2arg;
1789 :
1790 7782384 : id -= PRAGMA_FIRST_EXTERNAL;
1791 7782384 : ihandler = ®istered_pragmas[id].ihandler;
1792 7782384 : if (ihandler->extra_data)
1793 : {
1794 0 : handler_2arg = ihandler->early_handler.handler_2arg;
1795 0 : if (handler_2arg)
1796 0 : handler_2arg (parse_in, ihandler->data);
1797 : }
1798 : else
1799 : {
1800 7782384 : handler_1arg = ihandler->early_handler.handler_1arg;
1801 7782384 : if (handler_1arg)
1802 7533724 : handler_1arg (parse_in);
1803 : }
1804 7782384 : }
1805 :
1806 : void
1807 41556 : c_pp_invoke_early_pragma_handler (unsigned int id)
1808 : {
1809 41556 : const auto data = ®istered_pragmas[id - PRAGMA_FIRST_EXTERNAL];
1810 41556 : pragma_handler_1arg handler = data->ihandler.early_handler.handler_1arg;
1811 41556 : if (handler)
1812 : {
1813 41538 : handler (parse_in);
1814 41538 : pragma_lex_discard_to_eol ();
1815 : }
1816 41556 : }
1817 :
1818 : /* Set up front-end pragmas. */
1819 : void
1820 215401 : init_pragma (void)
1821 : {
1822 :
1823 215401 : if (!cpp_get_options (parse_in)->directives_only)
1824 : {
1825 215270 : if (flag_openacc)
1826 : {
1827 : const int n_oacc_pragmas = ARRAY_SIZE (oacc_pragmas);
1828 : int i;
1829 :
1830 25125 : for (i = 0; i < n_oacc_pragmas; ++i)
1831 23450 : cpp_register_deferred_pragma (parse_in, "acc", oacc_pragmas[i].name,
1832 23450 : oacc_pragmas[i].id, true, true);
1833 : }
1834 :
1835 215270 : if (flag_openmp)
1836 : {
1837 : const int n_omp_pragmas = ARRAY_SIZE (omp_pragmas);
1838 : int i;
1839 :
1840 188020 : for (i = 0; i < n_omp_pragmas; ++i)
1841 181305 : cpp_register_deferred_pragma (parse_in, "omp", omp_pragmas[i].name,
1842 181305 : omp_pragmas[i].id, true, true);
1843 : }
1844 215270 : if (flag_openmp || flag_openmp_simd)
1845 : {
1846 : const int n_omp_pragmas_simd = ARRAY_SIZE (omp_pragmas_simd);
1847 : int i;
1848 :
1849 121720 : for (i = 0; i < n_omp_pragmas_simd; ++i)
1850 114560 : cpp_register_deferred_pragma (parse_in, "omp",
1851 114560 : omp_pragmas_simd[i].name,
1852 114560 : omp_pragmas_simd[i].id, true, true);
1853 : }
1854 : }
1855 :
1856 215401 : if (!flag_preprocess_only)
1857 208177 : cpp_register_deferred_pragma (parse_in, "GCC", "pch_preprocess",
1858 : PRAGMA_GCC_PCH_PREPROCESS, false, false);
1859 :
1860 215401 : if (!flag_preprocess_only)
1861 208177 : cpp_register_deferred_pragma (parse_in, "GCC", "ivdep", PRAGMA_IVDEP, false,
1862 : false);
1863 :
1864 215401 : if (!flag_preprocess_only)
1865 208177 : cpp_register_deferred_pragma (parse_in, "GCC", "unroll", PRAGMA_UNROLL,
1866 : false, false);
1867 :
1868 215401 : if (!flag_preprocess_only)
1869 208177 : cpp_register_deferred_pragma (parse_in, "GCC", "novector", PRAGMA_NOVECTOR,
1870 : false, false);
1871 :
1872 : #ifdef HANDLE_PRAGMA_PACK_WITH_EXPANSION
1873 : c_register_pragma_with_expansion (0, "pack", handle_pragma_pack);
1874 : #else
1875 215401 : c_register_pragma (0, "pack", handle_pragma_pack);
1876 : #endif
1877 215401 : c_register_pragma (0, "weak", handle_pragma_weak);
1878 :
1879 215401 : c_register_pragma ("GCC", "visibility", handle_pragma_visibility);
1880 215401 : c_register_pragma ("GCC", "suppress_coverage",
1881 : handle_pragma_suppress_coverage);
1882 :
1883 215401 : if (flag_preprocess_only)
1884 7224 : c_register_pragma_with_early_handler ("GCC", "diagnostic",
1885 : nullptr,
1886 : handle_pragma_diagnostic_early_pp);
1887 : else
1888 208177 : c_register_pragma_with_early_handler ("GCC", "diagnostic",
1889 : handle_pragma_diagnostic,
1890 : handle_pragma_diagnostic_early);
1891 215401 : c_register_pragma_with_early_handler ("GCC", "target",
1892 : handle_pragma_target,
1893 : handle_pragma_target);
1894 215401 : c_register_pragma_with_early_handler ("GCC", "optimize",
1895 : handle_pragma_optimize,
1896 : handle_pragma_optimize);
1897 215401 : c_register_pragma_with_early_handler ("GCC", "push_options",
1898 : handle_pragma_push_options,
1899 : handle_pragma_push_options);
1900 215401 : c_register_pragma_with_early_handler ("GCC", "pop_options",
1901 : handle_pragma_pop_options,
1902 : handle_pragma_pop_options);
1903 215401 : c_register_pragma_with_early_handler ("GCC", "reset_options",
1904 : handle_pragma_reset_options,
1905 : handle_pragma_reset_options);
1906 :
1907 215401 : c_register_pragma (0, "region", handle_pragma_ignore);
1908 215401 : c_register_pragma (0, "endregion", handle_pragma_ignore);
1909 :
1910 215401 : c_register_pragma ("STDC", "FLOAT_CONST_DECIMAL64",
1911 : handle_pragma_float_const_decimal64);
1912 :
1913 215401 : c_register_pragma_with_expansion (0, "redefine_extname",
1914 : handle_pragma_redefine_extname);
1915 :
1916 215401 : c_register_pragma_with_expansion (0, "message", handle_pragma_message);
1917 :
1918 : #ifdef REGISTER_TARGET_PRAGMAS
1919 215401 : REGISTER_TARGET_PRAGMAS ();
1920 : #endif
1921 :
1922 215401 : global_sso = default_sso;
1923 215401 : c_register_pragma (0, "scalar_storage_order",
1924 : handle_pragma_scalar_storage_order);
1925 :
1926 : /* Allow plugins to register their own pragmas. */
1927 215401 : invoke_plugin_callbacks (PLUGIN_PRAGMAS, NULL);
1928 215401 : }
1929 :
1930 : #include "gt-c-family-c-pragma.h"
|