comparison gcc/c-pragma.c @ 55:77e2b8dfacca gcc-4.4.5

update it from 4.4.3 to 4.5.0
author ryoma <e075725@ie.u-ryukyu.ac.jp>
date Fri, 12 Feb 2010 23:39:51 +0900
parents 3bfb6c00c1e0
children b7f97abdc517
comparison
equal deleted inserted replaced
52:c156f1bd5cd9 55:77e2b8dfacca
35 #include "tm_p.h" 35 #include "tm_p.h"
36 #include "vec.h" 36 #include "vec.h"
37 #include "target.h" 37 #include "target.h"
38 #include "diagnostic.h" 38 #include "diagnostic.h"
39 #include "opts.h" 39 #include "opts.h"
40 #include "plugin.h"
40 41
41 #define GCC_BAD(gmsgid) \ 42 #define GCC_BAD(gmsgid) \
42 do { warning (OPT_Wpragmas, gmsgid); return; } while (0) 43 do { warning (OPT_Wpragmas, gmsgid); return; } while (0)
43 #define GCC_BAD2(gmsgid, arg) \ 44 #define GCC_BAD2(gmsgid, arg) \
44 do { warning (OPT_Wpragmas, gmsgid, arg); return; } while (0) 45 do { warning (OPT_Wpragmas, gmsgid, arg); return; } while (0)
45 46
46 typedef struct align_stack GTY(()) 47 typedef struct GTY(()) align_stack {
47 {
48 int alignment; 48 int alignment;
49 tree id; 49 tree id;
50 struct align_stack * prev; 50 struct align_stack * prev;
51 } align_stack; 51 } align_stack;
52 52
111 alignment_stack = entry; 111 alignment_stack = entry;
112 break; 112 break;
113 } 113 }
114 if (entry == NULL) 114 if (entry == NULL)
115 warning (OPT_Wpragmas, "\ 115 warning (OPT_Wpragmas, "\
116 #pragma pack(pop, %s) encountered without matching #pragma pack(push, %s)" 116 #pragma pack(pop, %E) encountered without matching #pragma pack(push, %E)"
117 , IDENTIFIER_POINTER (id), IDENTIFIER_POINTER (id)); 117 , id, id);
118 } 118 }
119 119
120 entry = alignment_stack->prev; 120 entry = alignment_stack->prev;
121 121
122 maximum_field_alignment = entry ? entry->alignment : default_alignment; 122 maximum_field_alignment = entry ? entry->alignment : default_alignment;
178 if (!strcmp (op, "push")) 178 if (!strcmp (op, "push"))
179 action = push; 179 action = push;
180 else if (!strcmp (op, "pop")) 180 else if (!strcmp (op, "pop"))
181 action = pop; 181 action = pop;
182 else 182 else
183 GCC_BAD2 ("unknown action %qs for %<#pragma pack%> - ignored", op); 183 GCC_BAD2 ("unknown action %qE for %<#pragma pack%> - ignored", x);
184 184
185 while ((token = pragma_lex (&x)) == CPP_COMMA) 185 while ((token = pragma_lex (&x)) == CPP_COMMA)
186 { 186 {
187 token = pragma_lex (&x); 187 token = pragma_lex (&x);
188 if (token == CPP_NAME && id == 0) 188 if (token == CPP_NAME && id == 0)
316 id = TREE_VALUE (t); 316 id = TREE_VALUE (t);
317 317
318 if (TREE_VALUE (t) == NULL) 318 if (TREE_VALUE (t) == NULL)
319 continue; 319 continue;
320 320
321 decl = build_decl (FUNCTION_DECL, alias_id, default_function_type); 321 decl = build_decl (UNKNOWN_LOCATION,
322 FUNCTION_DECL, alias_id, default_function_type);
322 323
323 DECL_ARTIFICIAL (decl) = 1; 324 DECL_ARTIFICIAL (decl) = 1;
324 TREE_PUBLIC (decl) = 1; 325 TREE_PUBLIC (decl) = 1;
325 DECL_EXTERNAL (decl) = 1; 326 DECL_EXTERNAL (decl) = 1;
326 DECL_WEAK (decl) = 1; 327 DECL_WEAK (decl) = 1;
420 if (pragma_lex (&newname) != CPP_NAME) 421 if (pragma_lex (&newname) != CPP_NAME)
421 GCC_BAD ("malformed #pragma redefine_extname, ignored"); 422 GCC_BAD ("malformed #pragma redefine_extname, ignored");
422 t = pragma_lex (&x); 423 t = pragma_lex (&x);
423 if (t != CPP_EOF) 424 if (t != CPP_EOF)
424 warning (OPT_Wpragmas, "junk at end of %<#pragma redefine_extname%>"); 425 warning (OPT_Wpragmas, "junk at end of %<#pragma redefine_extname%>");
425
426 if (!flag_mudflap && !targetm.handle_pragma_redefine_extname)
427 {
428 if (warn_unknown_pragmas > in_system_header)
429 warning (OPT_Wunknown_pragmas,
430 "#pragma redefine_extname not supported on this target");
431 return;
432 }
433 426
434 decl = identifier_global_value (oldname); 427 decl = identifier_global_value (oldname);
435 if (decl 428 if (decl
436 && (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl)) 429 && (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl))
437 && (TREE_CODE (decl) == FUNCTION_DECL 430 && (TREE_CODE (decl) == FUNCTION_DECL
591 584
592 585
593 #ifdef HANDLE_PRAGMA_VISIBILITY 586 #ifdef HANDLE_PRAGMA_VISIBILITY
594 static void handle_pragma_visibility (cpp_reader *); 587 static void handle_pragma_visibility (cpp_reader *);
595 588
596 typedef enum symbol_visibility visibility; 589 static VEC (int, heap) *visstack;
597 DEF_VEC_I (visibility);
598 DEF_VEC_ALLOC_I (visibility, heap);
599 static VEC (visibility, heap) *visstack;
600 590
601 /* Push the visibility indicated by STR onto the top of the #pragma 591 /* Push the visibility indicated by STR onto the top of the #pragma
602 visibility stack. */ 592 visibility stack. KIND is 0 for #pragma GCC visibility, 1 for
593 C++ namespace with visibility attribute and 2 for C++ builtin
594 ABI namespace. push_visibility/pop_visibility calls must have
595 matching KIND, it is not allowed to push visibility using one
596 KIND and pop using a different one. */
603 597
604 void 598 void
605 push_visibility (const char *str) 599 push_visibility (const char *str, int kind)
606 { 600 {
607 VEC_safe_push (visibility, heap, visstack, 601 VEC_safe_push (int, heap, visstack,
608 default_visibility); 602 ((int) default_visibility) | (kind << 8));
609 if (!strcmp (str, "default")) 603 if (!strcmp (str, "default"))
610 default_visibility = VISIBILITY_DEFAULT; 604 default_visibility = VISIBILITY_DEFAULT;
611 else if (!strcmp (str, "internal")) 605 else if (!strcmp (str, "internal"))
612 default_visibility = VISIBILITY_INTERNAL; 606 default_visibility = VISIBILITY_INTERNAL;
613 else if (!strcmp (str, "hidden")) 607 else if (!strcmp (str, "hidden"))
617 else 611 else
618 GCC_BAD ("#pragma GCC visibility push() must specify default, internal, hidden or protected"); 612 GCC_BAD ("#pragma GCC visibility push() must specify default, internal, hidden or protected");
619 visibility_options.inpragma = 1; 613 visibility_options.inpragma = 1;
620 } 614 }
621 615
622 /* Pop a level of the #pragma visibility stack. */ 616 /* Pop a level of the #pragma visibility stack. Return true if
623 617 successful. */
624 void 618
625 pop_visibility (void) 619 bool
626 { 620 pop_visibility (int kind)
627 default_visibility = VEC_pop (visibility, visstack); 621 {
622 if (!VEC_length (int, visstack))
623 return false;
624 if ((VEC_last (int, visstack) >> 8) != kind)
625 return false;
626 default_visibility
627 = (enum symbol_visibility) (VEC_pop (int, visstack) & 0xff);
628 visibility_options.inpragma 628 visibility_options.inpragma
629 = VEC_length (visibility, visstack) != 0; 629 = VEC_length (int, visstack) != 0;
630 return true;
630 } 631 }
631 632
632 /* Sets the default visibility for symbols to something other than that 633 /* Sets the default visibility for symbols to something other than that
633 specified on the command line. */ 634 specified on the command line. */
634 635
653 GCC_BAD ("#pragma GCC visibility must be followed by push or pop"); 654 GCC_BAD ("#pragma GCC visibility must be followed by push or pop");
654 else 655 else
655 { 656 {
656 if (pop == action) 657 if (pop == action)
657 { 658 {
658 if (!VEC_length (visibility, visstack)) 659 if (! pop_visibility (0))
659 GCC_BAD ("no matching push for %<#pragma GCC visibility pop%>"); 660 GCC_BAD ("no matching push for %<#pragma GCC visibility pop%>");
660 else
661 pop_visibility ();
662 } 661 }
663 else 662 else
664 { 663 {
665 if (pragma_lex (&x) != CPP_OPEN_PAREN) 664 if (pragma_lex (&x) != CPP_OPEN_PAREN)
666 GCC_BAD ("missing %<(%> after %<#pragma GCC visibility push%> - ignored"); 665 GCC_BAD ("missing %<(%> after %<#pragma GCC visibility push%> - ignored");
667 token = pragma_lex (&x); 666 token = pragma_lex (&x);
668 if (token != CPP_NAME) 667 if (token != CPP_NAME)
669 GCC_BAD ("malformed #pragma GCC visibility push"); 668 GCC_BAD ("malformed #pragma GCC visibility push");
670 else 669 else
671 push_visibility (IDENTIFIER_POINTER (x)); 670 push_visibility (IDENTIFIER_POINTER (x), 0);
672 if (pragma_lex (&x) != CPP_CLOSE_PAREN) 671 if (pragma_lex (&x) != CPP_CLOSE_PAREN)
673 GCC_BAD ("missing %<(%> after %<#pragma GCC visibility push%> - ignored"); 672 GCC_BAD ("missing %<(%> after %<#pragma GCC visibility push%> - ignored");
674 } 673 }
675 } 674 }
676 if (pragma_lex (&x) != CPP_EOF) 675 if (pragma_lex (&x) != CPP_EOF)
867 } 866 }
868 867
869 /* Stack of the #pragma GCC options created with #pragma GCC push_option. Save 868 /* Stack of the #pragma GCC options created with #pragma GCC push_option. Save
870 both the binary representation of the options and the TREE_LIST of 869 both the binary representation of the options and the TREE_LIST of
871 strings that will be added to the function's attribute list. */ 870 strings that will be added to the function's attribute list. */
872 typedef struct opt_stack GTY(()) 871 typedef struct GTY(()) opt_stack {
873 {
874 struct opt_stack *prev; 872 struct opt_stack *prev;
875 tree target_binary; 873 tree target_binary;
876 tree target_strings; 874 tree target_strings;
877 tree optimize_binary; 875 tree optimize_binary;
878 tree optimize_strings; 876 tree optimize_strings;
1022 if (pragma_lex (&x) != CPP_EOF) 1020 if (pragma_lex (&x) != CPP_EOF)
1023 warning (OPT_Wpragmas, "junk at end of %<#pragma message%>"); 1021 warning (OPT_Wpragmas, "junk at end of %<#pragma message%>");
1024 1022
1025 if (TREE_STRING_LENGTH (message) > 1) 1023 if (TREE_STRING_LENGTH (message) > 1)
1026 inform (input_location, "#pragma message: %s", TREE_STRING_POINTER (message)); 1024 inform (input_location, "#pragma message: %s", TREE_STRING_POINTER (message));
1025 }
1026
1027 /* Mark whether the current location is valid for a STDC pragma. */
1028
1029 static bool valid_location_for_stdc_pragma;
1030
1031 void
1032 mark_valid_location_for_stdc_pragma (bool flag)
1033 {
1034 valid_location_for_stdc_pragma = flag;
1035 }
1036
1037 /* Return true if the current location is valid for a STDC pragma. */
1038
1039 bool
1040 valid_location_for_stdc_pragma_p (void)
1041 {
1042 return valid_location_for_stdc_pragma;
1043 }
1044
1045 enum pragma_switch_t { PRAGMA_ON, PRAGMA_OFF, PRAGMA_DEFAULT, PRAGMA_BAD };
1046
1047 /* A STDC pragma must appear outside of external declarations or
1048 preceding all explicit declarations and statements inside a compound
1049 statement; its behavior is undefined if used in any other context.
1050 It takes a switch of ON, OFF, or DEFAULT. */
1051
1052 static enum pragma_switch_t
1053 handle_stdc_pragma (const char *pname)
1054 {
1055 const char *arg;
1056 tree t;
1057 enum pragma_switch_t ret;
1058
1059 if (!valid_location_for_stdc_pragma_p ())
1060 {
1061 warning (OPT_Wpragmas, "invalid location for %<pragma %s%>, ignored",
1062 pname);
1063 return PRAGMA_BAD;
1064 }
1065
1066 if (pragma_lex (&t) != CPP_NAME)
1067 {
1068 warning (OPT_Wpragmas, "malformed %<#pragma %s%>, ignored", pname);
1069 return PRAGMA_BAD;
1070 }
1071
1072 arg = IDENTIFIER_POINTER (t);
1073
1074 if (!strcmp (arg, "ON"))
1075 ret = PRAGMA_ON;
1076 else if (!strcmp (arg, "OFF"))
1077 ret = PRAGMA_OFF;
1078 else if (!strcmp (arg, "DEFAULT"))
1079 ret = PRAGMA_DEFAULT;
1080 else
1081 {
1082 warning (OPT_Wpragmas, "malformed %<#pragma %s%>, ignored", pname);
1083 return PRAGMA_BAD;
1084 }
1085
1086 if (pragma_lex (&t) != CPP_EOF)
1087 {
1088 warning (OPT_Wpragmas, "junk at end of %<#pragma %s%>", pname);
1089 return PRAGMA_BAD;
1090 }
1091
1092 return ret;
1093 }
1094
1095 /* #pragma STDC FLOAT_CONST_DECIMAL64 ON
1096 #pragma STDC FLOAT_CONST_DECIMAL64 OFF
1097 #pragma STDC FLOAT_CONST_DECIMAL64 DEFAULT */
1098
1099 static void
1100 handle_pragma_float_const_decimal64 (cpp_reader *ARG_UNUSED (dummy))
1101 {
1102 if (c_dialect_cxx ())
1103 {
1104 if (warn_unknown_pragmas > in_system_header)
1105 warning (OPT_Wunknown_pragmas,
1106 "%<#pragma STDC FLOAT_CONST_DECIMAL64%> is not supported"
1107 " for C++");
1108 return;
1109 }
1110
1111 if (!targetm.decimal_float_supported_p ())
1112 {
1113 if (warn_unknown_pragmas > in_system_header)
1114 warning (OPT_Wunknown_pragmas,
1115 "%<#pragma STDC FLOAT_CONST_DECIMAL64%> is not supported"
1116 " on this target");
1117 return;
1118 }
1119
1120 pedwarn (input_location, OPT_pedantic,
1121 "ISO C does not support %<#pragma STDC FLOAT_CONST_DECIMAL64%>");
1122
1123 switch (handle_stdc_pragma ("STDC FLOAT_CONST_DECIMAL64"))
1124 {
1125 case PRAGMA_ON:
1126 set_float_const_decimal64 ();
1127 break;
1128 case PRAGMA_OFF:
1129 case PRAGMA_DEFAULT:
1130 clear_float_const_decimal64 ();
1131 break;
1132 case PRAGMA_BAD:
1133 break;
1134 }
1027 } 1135 }
1028 1136
1029 /* A vector of registered pragma callbacks. */ 1137 /* A vector of registered pragma callbacks. */
1030 1138
1031 DEF_VEC_O (pragma_handler); 1139 DEF_VEC_O (pragma_handler);
1188 c_register_pragma ("GCC", "optimize", handle_pragma_optimize); 1296 c_register_pragma ("GCC", "optimize", handle_pragma_optimize);
1189 c_register_pragma ("GCC", "push_options", handle_pragma_push_options); 1297 c_register_pragma ("GCC", "push_options", handle_pragma_push_options);
1190 c_register_pragma ("GCC", "pop_options", handle_pragma_pop_options); 1298 c_register_pragma ("GCC", "pop_options", handle_pragma_pop_options);
1191 c_register_pragma ("GCC", "reset_options", handle_pragma_reset_options); 1299 c_register_pragma ("GCC", "reset_options", handle_pragma_reset_options);
1192 1300
1301 c_register_pragma ("STDC", "FLOAT_CONST_DECIMAL64",
1302 handle_pragma_float_const_decimal64);
1303
1193 c_register_pragma_with_expansion (0, "redefine_extname", handle_pragma_redefine_extname); 1304 c_register_pragma_with_expansion (0, "redefine_extname", handle_pragma_redefine_extname);
1194 c_register_pragma (0, "extern_prefix", handle_pragma_extern_prefix); 1305 c_register_pragma (0, "extern_prefix", handle_pragma_extern_prefix);
1195 1306
1196 c_register_pragma_with_expansion (0, "message", handle_pragma_message); 1307 c_register_pragma_with_expansion (0, "message", handle_pragma_message);
1197 1308
1198 #ifdef REGISTER_TARGET_PRAGMAS 1309 #ifdef REGISTER_TARGET_PRAGMAS
1199 REGISTER_TARGET_PRAGMAS (); 1310 REGISTER_TARGET_PRAGMAS ();
1200 #endif 1311 #endif
1312
1313 /* Allow plugins to register their own pragmas. */
1314 invoke_plugin_callbacks (PLUGIN_PRAGMAS, NULL);
1201 } 1315 }
1202 1316
1203 #include "gt-c-pragma.h" 1317 #include "gt-c-pragma.h"