comparison gcc/c-family/c-pragma.c @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
comparison
equal deleted inserted replaced
131:84e7813d76e9 145:1830386684a0
1 /* Handle #pragma, system V.4 style. Supports #pragma weak and #pragma pack. 1 /* Handle #pragma, system V.4 style. Supports #pragma weak and #pragma pack.
2 Copyright (C) 1992-2018 Free Software Foundation, Inc. 2 Copyright (C) 1992-2020 Free Software Foundation, Inc.
3 3
4 This file is part of GCC. 4 This file is part of GCC.
5 5
6 GCC is free software; you can redistribute it and/or modify it under 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 7 the terms of the GNU General Public License as published by the Free
31 #include "attribs.h" 31 #include "attribs.h"
32 #include "varasm.h" 32 #include "varasm.h"
33 #include "c-pragma.h" 33 #include "c-pragma.h"
34 #include "opts.h" 34 #include "opts.h"
35 #include "plugin.h" 35 #include "plugin.h"
36 #include "opt-suggestions.h"
36 37
37 #define GCC_BAD(gmsgid) \ 38 #define GCC_BAD(gmsgid) \
38 do { warning (OPT_Wpragmas, gmsgid); return; } while (0) 39 do { warning (OPT_Wpragmas, gmsgid); return; } while (0)
39 #define GCC_BAD2(gmsgid, arg) \ 40 #define GCC_BAD2(gmsgid, arg) \
40 do { warning (OPT_Wpragmas, gmsgid, arg); return; } while (0) 41 do { warning (OPT_Wpragmas, gmsgid, arg); return; } while (0)
88 pop_alignment (tree id) 89 pop_alignment (tree id)
89 { 90 {
90 align_stack * entry; 91 align_stack * entry;
91 92
92 if (alignment_stack == NULL) 93 if (alignment_stack == NULL)
93 GCC_BAD ("#pragma pack (pop) encountered without matching #pragma pack (push)"); 94 GCC_BAD ("%<#pragma pack (pop)%> encountered without matching "
95 "%<#pragma pack (push)%>");
94 96
95 /* If we got an identifier, strip away everything above the target 97 /* If we got an identifier, strip away everything above the target
96 entry so that the next step will restore the state just below it. */ 98 entry so that the next step will restore the state just below it. */
97 if (id) 99 if (id)
98 { 100 {
101 { 103 {
102 alignment_stack = entry; 104 alignment_stack = entry;
103 break; 105 break;
104 } 106 }
105 if (entry == NULL) 107 if (entry == NULL)
106 warning (OPT_Wpragmas, "\ 108 warning (OPT_Wpragmas,
107 #pragma pack(pop, %E) encountered without matching #pragma pack(push, %E)" 109 "%<#pragma pack(pop, %E)%> encountered without matching "
110 "%<#pragma pack(push, %E)%>"
108 , id, id); 111 , id, id);
109 } 112 }
110 113
111 entry = alignment_stack->prev; 114 entry = alignment_stack->prev;
112 115
194 197
195 if (pragma_lex (&x) != CPP_EOF) 198 if (pragma_lex (&x) != CPP_EOF)
196 warning (OPT_Wpragmas, "junk at end of %<#pragma pack%>"); 199 warning (OPT_Wpragmas, "junk at end of %<#pragma pack%>");
197 200
198 if (flag_pack_struct) 201 if (flag_pack_struct)
199 GCC_BAD ("#pragma pack has no effect with -fpack-struct - ignored"); 202 GCC_BAD ("%<#pragma pack%> has no effect with %<-fpack-struct%> - ignored");
200 203
201 if (action != pop) 204 if (action != pop)
202 switch (align) 205 switch (align)
203 { 206 {
204 case 0: 207 case 0:
254 257
255 if (SUPPORTS_WEAK && DECL_EXTERNAL (decl) && TREE_USED (decl) 258 if (SUPPORTS_WEAK && DECL_EXTERNAL (decl) && TREE_USED (decl)
256 && !DECL_WEAK (decl) /* Don't complain about a redundant #pragma. */ 259 && !DECL_WEAK (decl) /* Don't complain about a redundant #pragma. */
257 && DECL_ASSEMBLER_NAME_SET_P (decl) 260 && DECL_ASSEMBLER_NAME_SET_P (decl)
258 && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))) 261 && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
259 warning (OPT_Wpragmas, "applying #pragma weak %q+D after first use " 262 warning (OPT_Wpragmas, "applying %<#pragma weak %+D%> after first use "
260 "results in unspecified behavior", decl); 263 "results in unspecified behavior", decl);
261 264
262 declare_weak (decl); 265 declare_weak (decl);
263 } 266 }
264 267
351 enum cpp_ttype t; 354 enum cpp_ttype t;
352 355
353 value = 0; 356 value = 0;
354 357
355 if (pragma_lex (&name) != CPP_NAME) 358 if (pragma_lex (&name) != CPP_NAME)
356 GCC_BAD ("malformed #pragma weak, ignored"); 359 GCC_BAD ("malformed %<#pragma weak%>, ignored");
357 t = pragma_lex (&x); 360 t = pragma_lex (&x);
358 if (t == CPP_EQ) 361 if (t == CPP_EQ)
359 { 362 {
360 if (pragma_lex (&value) != CPP_NAME) 363 if (pragma_lex (&value) != CPP_NAME)
361 GCC_BAD ("malformed #pragma weak, ignored"); 364 GCC_BAD ("malformed %<#pragma weak%>, ignored");
362 t = pragma_lex (&x); 365 t = pragma_lex (&x);
363 } 366 }
364 if (t != CPP_EOF) 367 if (t != CPP_EOF)
365 warning (OPT_Wpragmas, "junk at end of %<#pragma weak%>"); 368 warning (OPT_Wpragmas, "junk at end of %<#pragma weak%>");
366 369
414 enum cpp_ttype token; 417 enum cpp_ttype token;
415 tree x; 418 tree x;
416 419
417 if (BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN) 420 if (BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN)
418 { 421 {
419 error ("scalar_storage_order is not supported because endianness " 422 error ("%<scalar_storage_order%> is not supported because endianness "
420 "is not uniform"); 423 "is not uniform");
421 return; 424 return;
422 } 425 }
423 426
424 if (c_dialect_cxx ()) 427 if (c_dialect_cxx ())
492 tree oldname, newname, decls, x; 495 tree oldname, newname, decls, x;
493 enum cpp_ttype t; 496 enum cpp_ttype t;
494 bool found; 497 bool found;
495 498
496 if (pragma_lex (&oldname) != CPP_NAME) 499 if (pragma_lex (&oldname) != CPP_NAME)
497 GCC_BAD ("malformed #pragma redefine_extname, ignored"); 500 GCC_BAD ("malformed %<#pragma redefine_extname%>, ignored");
498 if (pragma_lex (&newname) != CPP_NAME) 501 if (pragma_lex (&newname) != CPP_NAME)
499 GCC_BAD ("malformed #pragma redefine_extname, ignored"); 502 GCC_BAD ("malformed %<#pragma redefine_extname%>, ignored");
500 t = pragma_lex (&x); 503 t = pragma_lex (&x);
501 if (t != CPP_EOF) 504 if (t != CPP_EOF)
502 warning (OPT_Wpragmas, "junk at end of %<#pragma redefine_extname%>"); 505 warning (OPT_Wpragmas, "junk at end of %<#pragma redefine_extname%>");
503 506
504 found = false; 507 found = false;
525 { 528 {
526 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); 529 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
527 name = targetm.strip_name_encoding (name); 530 name = targetm.strip_name_encoding (name);
528 531
529 if (!id_equal (newname, name)) 532 if (!id_equal (newname, name))
530 warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to " 533 warning (OPT_Wpragmas, "%<#pragma redefine_extname%> "
531 "conflict with previous rename"); 534 "ignored due to conflict with previous rename");
532 } 535 }
533 else 536 else
534 symtab->change_decl_assembler_name (decl, newname); 537 symtab->change_decl_assembler_name (decl, newname);
535 } 538 }
536 } 539 }
553 556
554 FOR_EACH_VEC_SAFE_ELT (pending_redefine_extname, ix, p) 557 FOR_EACH_VEC_SAFE_ELT (pending_redefine_extname, ix, p)
555 if (oldname == p->oldname) 558 if (oldname == p->oldname)
556 { 559 {
557 if (p->newname != newname) 560 if (p->newname != newname)
558 warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to " 561 warning (OPT_Wpragmas, "%<#pragma redefine_extname%> ignored due to "
559 "conflict with previous #pragma redefine_extname"); 562 "conflict with previous %<#pragma redefine_extname%>");
560 return; 563 return;
561 } 564 }
562 565
563 pending_redefinition e = {oldname, newname}; 566 pending_redefinition e = {oldname, newname};
564 vec_safe_push (pending_redefine_extname, e); 567 vec_safe_push (pending_redefine_extname, e);
589 { 592 {
590 const char *oldname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); 593 const char *oldname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
591 oldname = targetm.strip_name_encoding (oldname); 594 oldname = targetm.strip_name_encoding (oldname);
592 595
593 if (asmname && strcmp (TREE_STRING_POINTER (asmname), oldname)) 596 if (asmname && strcmp (TREE_STRING_POINTER (asmname), oldname))
594 warning (OPT_Wpragmas, "asm declaration ignored due to " 597 warning (OPT_Wpragmas, "%<asm%> declaration ignored due to "
595 "conflict with previous rename"); 598 "conflict with previous rename");
596 599
597 /* Take any pending redefine_extname off the list. */ 600 /* Take any pending redefine_extname off the list. */
598 FOR_EACH_VEC_SAFE_ELT (pending_redefine_extname, ix, p) 601 FOR_EACH_VEC_SAFE_ELT (pending_redefine_extname, ix, p)
599 if (DECL_NAME (decl) == p->oldname) 602 if (DECL_NAME (decl) == p->oldname)
600 { 603 {
601 /* Only warn if there is a conflict. */ 604 /* Only warn if there is a conflict. */
602 if (!id_equal (p->newname, oldname)) 605 if (!id_equal (p->newname, oldname))
603 warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to " 606 warning (OPT_Wpragmas, "%<#pragma redefine_extname%> ignored "
604 "conflict with previous rename"); 607 "due to conflict with previous rename");
605 608
606 pending_redefine_extname->unordered_remove (ix); 609 pending_redefine_extname->unordered_remove (ix);
607 break; 610 break;
608 } 611 }
609 return NULL_TREE; 612 return NULL_TREE;
620 ignored (with a warning if it conflicts). */ 623 ignored (with a warning if it conflicts). */
621 if (asmname) 624 if (asmname)
622 { 625 {
623 if (strcmp (TREE_STRING_POINTER (asmname), 626 if (strcmp (TREE_STRING_POINTER (asmname),
624 IDENTIFIER_POINTER (newname)) != 0) 627 IDENTIFIER_POINTER (newname)) != 0)
625 warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to " 628 warning (OPT_Wpragmas, "%<#pragma redefine_extname%> ignored "
626 "conflict with __asm__ declaration"); 629 "due to conflict with %<asm%> declaration");
627 return asmname; 630 return asmname;
628 } 631 }
629 632
630 /* Otherwise we use what we've got; #pragma extern_prefix is 633 /* Otherwise we use what we've got; #pragma extern_prefix is
631 silently ignored. */ 634 silently ignored. */
681 else if (!strcmp (str, "hidden")) 684 else if (!strcmp (str, "hidden"))
682 default_visibility = VISIBILITY_HIDDEN; 685 default_visibility = VISIBILITY_HIDDEN;
683 else if (!strcmp (str, "protected")) 686 else if (!strcmp (str, "protected"))
684 default_visibility = VISIBILITY_PROTECTED; 687 default_visibility = VISIBILITY_PROTECTED;
685 else 688 else
686 GCC_BAD ("#pragma GCC visibility push() must specify default, internal, hidden or protected"); 689 GCC_BAD ("%<#pragma GCC visibility push()%> must specify %<default%>, "
690 "%<internal%>, %<hidden%> or %<protected%>");
687 visibility_options.inpragma = 1; 691 visibility_options.inpragma = 1;
688 } 692 }
689 693
690 /* Pop a level of the #pragma visibility stack. Return true if 694 /* Pop a level of the #pragma visibility stack. Return true if
691 successful. */ 695 successful. */
723 action = push; 727 action = push;
724 else if (!strcmp (op, "pop")) 728 else if (!strcmp (op, "pop"))
725 action = pop; 729 action = pop;
726 } 730 }
727 if (bad == action) 731 if (bad == action)
728 GCC_BAD ("#pragma GCC visibility must be followed by push or pop"); 732 GCC_BAD ("%<#pragma GCC visibility%> must be followed by %<push%> "
733 "or %<pop%>");
729 else 734 else
730 { 735 {
731 if (pop == action) 736 if (pop == action)
732 { 737 {
733 if (! pop_visibility (0)) 738 if (! pop_visibility (0))
737 { 742 {
738 if (pragma_lex (&x) != CPP_OPEN_PAREN) 743 if (pragma_lex (&x) != CPP_OPEN_PAREN)
739 GCC_BAD ("missing %<(%> after %<#pragma GCC visibility push%> - ignored"); 744 GCC_BAD ("missing %<(%> after %<#pragma GCC visibility push%> - ignored");
740 token = pragma_lex (&x); 745 token = pragma_lex (&x);
741 if (token != CPP_NAME) 746 if (token != CPP_NAME)
742 GCC_BAD ("malformed #pragma GCC visibility push"); 747 GCC_BAD ("malformed %<#pragma GCC visibility push%>");
743 else 748 else
744 push_visibility (IDENTIFIER_POINTER (x), 0); 749 push_visibility (IDENTIFIER_POINTER (x), 0);
745 if (pragma_lex (&x) != CPP_CLOSE_PAREN) 750 if (pragma_lex (&x) != CPP_CLOSE_PAREN)
746 GCC_BAD ("missing %<(%> after %<#pragma GCC visibility push%> - ignored"); 751 GCC_BAD ("missing %<(%> after %<#pragma GCC visibility push%> - ignored");
747 } 752 }
802 unsigned int lang_mask = c_common_option_lang_mask () | CL_COMMON; 807 unsigned int lang_mask = c_common_option_lang_mask () | CL_COMMON;
803 /* option_string + 1 to skip the initial '-' */ 808 /* option_string + 1 to skip the initial '-' */
804 unsigned int option_index = find_opt (option_string + 1, lang_mask); 809 unsigned int option_index = find_opt (option_string + 1, lang_mask);
805 if (option_index == OPT_SPECIAL_unknown) 810 if (option_index == OPT_SPECIAL_unknown)
806 { 811 {
807 warning_at (loc, OPT_Wpragmas, 812 option_proposer op;
808 "unknown option after %<#pragma GCC diagnostic%> kind"); 813 const char *hint = op.suggest_option (option_string + 1);
814 if (hint)
815 warning_at (loc, OPT_Wpragmas,
816 "unknown option after %<#pragma GCC diagnostic%> kind;"
817 " did you mean %<-%s%>", hint);
818 else
819 warning_at (loc, OPT_Wpragmas,
820 "unknown option after %<#pragma GCC diagnostic%> kind");
821
809 return; 822 return;
810 } 823 }
811 else if (!(cl_options[option_index].flags & CL_WARNING)) 824 else if (!(cl_options[option_index].flags & CL_WARNING))
812 { 825 {
813 warning_at (loc, OPT_Wpragmas, 826 warning_at (loc, OPT_Wpragmas,
849 tree x; 862 tree x;
850 bool close_paren_needed_p = false; 863 bool close_paren_needed_p = false;
851 864
852 if (cfun) 865 if (cfun)
853 { 866 {
854 error ("#pragma GCC option is not allowed inside functions"); 867 error ("%<#pragma GCC option%> is not allowed inside functions");
855 return; 868 return;
856 } 869 }
857 870
858 token = pragma_lex (&x); 871 token = pragma_lex (&x);
859 if (token == CPP_OPEN_PAREN) 872 if (token == CPP_OPEN_PAREN)
895 "not have a final %<)%>"); 908 "not have a final %<)%>");
896 } 909 }
897 910
898 if (token != CPP_EOF) 911 if (token != CPP_EOF)
899 { 912 {
900 error ("#pragma GCC target string... is badly formed"); 913 error ("%<#pragma GCC target%> string is badly formed");
901 return; 914 return;
902 } 915 }
903 916
904 /* put arguments in the order the user typed them. */ 917 /* put arguments in the order the user typed them. */
905 args = nreverse (args); 918 args = nreverse (args);
918 bool close_paren_needed_p = false; 931 bool close_paren_needed_p = false;
919 tree optimization_previous_node = optimization_current_node; 932 tree optimization_previous_node = optimization_current_node;
920 933
921 if (cfun) 934 if (cfun)
922 { 935 {
923 error ("#pragma GCC optimize is not allowed inside functions"); 936 error ("%<#pragma GCC optimize%> is not allowed inside functions");
924 return; 937 return;
925 } 938 }
926 939
927 token = pragma_lex (&x); 940 token = pragma_lex (&x);
928 if (token == CPP_OPEN_PAREN) 941 if (token == CPP_OPEN_PAREN)
963 "not have a final %<)%>"); 976 "not have a final %<)%>");
964 } 977 }
965 978
966 if (token != CPP_EOF) 979 if (token != CPP_EOF)
967 { 980 {
968 error ("#pragma GCC optimize string... is badly formed"); 981 error ("%<#pragma GCC optimize%> string is badly formed");
969 return; 982 return;
970 } 983 }
971 984
972 /* put arguments in the order the user typed them. */ 985 /* put arguments in the order the user typed them. */
973 args = nreverse (args); 986 args = nreverse (args);
1136 1149
1137 if (pragma_lex (&x) != CPP_EOF) 1150 if (pragma_lex (&x) != CPP_EOF)
1138 warning (OPT_Wpragmas, "junk at end of %<#pragma message%>"); 1151 warning (OPT_Wpragmas, "junk at end of %<#pragma message%>");
1139 1152
1140 if (TREE_STRING_LENGTH (message) > 1) 1153 if (TREE_STRING_LENGTH (message) > 1)
1141 inform (input_location, "#pragma message: %s", TREE_STRING_POINTER (message)); 1154 inform (input_location, "%<#pragma message: %s%>",
1155 TREE_STRING_POINTER (message));
1142 } 1156 }
1143 1157
1144 /* Mark whether the current location is valid for a STDC pragma. */ 1158 /* Mark whether the current location is valid for a STDC pragma. */
1145 1159
1146 static bool valid_location_for_stdc_pragma; 1160 static bool valid_location_for_stdc_pragma;
1275 { "host_data", PRAGMA_OACC_HOST_DATA }, 1289 { "host_data", PRAGMA_OACC_HOST_DATA },
1276 { "kernels", PRAGMA_OACC_KERNELS }, 1290 { "kernels", PRAGMA_OACC_KERNELS },
1277 { "loop", PRAGMA_OACC_LOOP }, 1291 { "loop", PRAGMA_OACC_LOOP },
1278 { "parallel", PRAGMA_OACC_PARALLEL }, 1292 { "parallel", PRAGMA_OACC_PARALLEL },
1279 { "routine", PRAGMA_OACC_ROUTINE }, 1293 { "routine", PRAGMA_OACC_ROUTINE },
1294 { "serial", PRAGMA_OACC_SERIAL },
1280 { "update", PRAGMA_OACC_UPDATE }, 1295 { "update", PRAGMA_OACC_UPDATE },
1281 { "wait", PRAGMA_OACC_WAIT } 1296 { "wait", PRAGMA_OACC_WAIT }
1282 }; 1297 };
1283 static const struct omp_pragma_def omp_pragmas[] = { 1298 static const struct omp_pragma_def omp_pragmas[] = {
1284 { "atomic", PRAGMA_OMP_ATOMIC }, 1299 { "atomic", PRAGMA_OMP_ATOMIC },
1285 { "barrier", PRAGMA_OMP_BARRIER }, 1300 { "barrier", PRAGMA_OMP_BARRIER },
1286 { "cancel", PRAGMA_OMP_CANCEL }, 1301 { "cancel", PRAGMA_OMP_CANCEL },
1287 { "cancellation", PRAGMA_OMP_CANCELLATION_POINT }, 1302 { "cancellation", PRAGMA_OMP_CANCELLATION_POINT },
1288 { "critical", PRAGMA_OMP_CRITICAL }, 1303 { "critical", PRAGMA_OMP_CRITICAL },
1304 { "depobj", PRAGMA_OMP_DEPOBJ },
1289 { "end", PRAGMA_OMP_END_DECLARE_TARGET }, 1305 { "end", PRAGMA_OMP_END_DECLARE_TARGET },
1290 { "flush", PRAGMA_OMP_FLUSH }, 1306 { "flush", PRAGMA_OMP_FLUSH },
1291 { "master", PRAGMA_OMP_MASTER }, 1307 { "master", PRAGMA_OMP_MASTER },
1308 { "requires", PRAGMA_OMP_REQUIRES },
1292 { "section", PRAGMA_OMP_SECTION }, 1309 { "section", PRAGMA_OMP_SECTION },
1293 { "sections", PRAGMA_OMP_SECTIONS }, 1310 { "sections", PRAGMA_OMP_SECTIONS },
1294 { "single", PRAGMA_OMP_SINGLE }, 1311 { "single", PRAGMA_OMP_SINGLE },
1295 { "task", PRAGMA_OMP_TASK }, 1312 { "task", PRAGMA_OMP_TASK },
1296 { "taskgroup", PRAGMA_OMP_TASKGROUP }, 1313 { "taskgroup", PRAGMA_OMP_TASKGROUP },
1300 }; 1317 };
1301 static const struct omp_pragma_def omp_pragmas_simd[] = { 1318 static const struct omp_pragma_def omp_pragmas_simd[] = {
1302 { "declare", PRAGMA_OMP_DECLARE }, 1319 { "declare", PRAGMA_OMP_DECLARE },
1303 { "distribute", PRAGMA_OMP_DISTRIBUTE }, 1320 { "distribute", PRAGMA_OMP_DISTRIBUTE },
1304 { "for", PRAGMA_OMP_FOR }, 1321 { "for", PRAGMA_OMP_FOR },
1322 { "loop", PRAGMA_OMP_LOOP },
1305 { "ordered", PRAGMA_OMP_ORDERED }, 1323 { "ordered", PRAGMA_OMP_ORDERED },
1306 { "parallel", PRAGMA_OMP_PARALLEL }, 1324 { "parallel", PRAGMA_OMP_PARALLEL },
1325 { "scan", PRAGMA_OMP_SCAN },
1307 { "simd", PRAGMA_OMP_SIMD }, 1326 { "simd", PRAGMA_OMP_SIMD },
1308 { "target", PRAGMA_OMP_TARGET }, 1327 { "target", PRAGMA_OMP_TARGET },
1309 { "taskloop", PRAGMA_OMP_TASKLOOP }, 1328 { "taskloop", PRAGMA_OMP_TASKLOOP },
1310 { "teams", PRAGMA_OMP_TEAMS }, 1329 { "teams", PRAGMA_OMP_TEAMS },
1311 }; 1330 };