comparison gcc/c-decl.c @ 69:1b10fe6932e1

merge 69
author Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
date Sun, 21 Aug 2011 07:53:12 +0900
parents 326d9e06c2e3 f6334be47118
children b81903832de2
comparison
equal deleted inserted replaced
66:b362627d71ba 69:1b10fe6932e1
1 /* Process declarations and variables for C compiler. 1 /* Process declarations and variables for C compiler.
2 Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2 Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 3 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc. 4 Free Software Foundation, Inc.
5 5
6 This file is part of GCC. 6 This file is part of GCC.
7 7
8 GCC is free software; you can redistribute it and/or modify it under 8 GCC is free software; you can redistribute it and/or modify it under
32 #include "input.h" 32 #include "input.h"
33 #include "tm.h" 33 #include "tm.h"
34 #include "intl.h" 34 #include "intl.h"
35 #include "tree.h" 35 #include "tree.h"
36 #include "tree-inline.h" 36 #include "tree-inline.h"
37 #include "rtl.h"
38 #include "flags.h" 37 #include "flags.h"
39 #include "function.h" 38 #include "function.h"
40 #include "output.h" 39 #include "output.h"
41 #include "expr.h"
42 #include "c-tree.h" 40 #include "c-tree.h"
43 #include "toplev.h" 41 #include "toplev.h"
44 #include "ggc.h"
45 #include "tm_p.h" 42 #include "tm_p.h"
46 #include "cpplib.h" 43 #include "cpplib.h"
47 #include "target.h" 44 #include "target.h"
48 #include "debug.h" 45 #include "debug.h"
49 #include "opts.h" 46 #include "opts.h"
50 #include "timevar.h" 47 #include "timevar.h"
51 #include "c-common.h" 48 #include "c-family/c-common.h"
52 #include "c-pragma.h" 49 #include "c-family/c-objc.h"
50 #include "c-family/c-pragma.h"
53 #include "c-lang.h" 51 #include "c-lang.h"
54 #include "langhooks.h" 52 #include "langhooks.h"
55 #include "tree-mudflap.h" 53 #include "tree-mudflap.h"
56 #include "gimple.h"
57 #include "tree-iterator.h" 54 #include "tree-iterator.h"
58 #include "diagnostic.h" 55 #include "diagnostic-core.h"
59 #include "tree-dump.h" 56 #include "tree-dump.h"
60 #include "cgraph.h" 57 #include "cgraph.h"
61 #include "hashtab.h" 58 #include "hashtab.h"
62 #include "libfuncs.h"
63 #include "except.h"
64 #include "langhooks-def.h" 59 #include "langhooks-def.h"
65 #include "pointer-set.h" 60 #include "pointer-set.h"
66 #include "gimple.h" 61 #include "gimple.h"
67 #ifndef noCbC 62 #ifndef noCbC
68 #include "cbc-tree.h" 63 #include "cbc-tree.h"
69 tree cbc_env; 64 tree cbc_env;
70 tree cbc_return_f; 65 tree cbc_return_f;
71 location_t cbc_return; 66 location_t cbc_return;
72 #endif 67 #endif
73
74 #include "plugin.h" 68 #include "plugin.h"
69 #include "c-family/c-ada-spec.h"
75 70
76 /* In grokdeclarator, distinguish syntactic contexts of declarators. */ 71 /* In grokdeclarator, distinguish syntactic contexts of declarators. */
77 enum decl_context 72 enum decl_context
78 { NORMAL, /* Ordinary declaration */ 73 { NORMAL, /* Ordinary declaration */
79 FUNCDEF, /* Function definition */ 74 FUNCDEF, /* Function definition */
128 static GTY(()) struct stmt_tree_s c_stmt_tree; 123 static GTY(()) struct stmt_tree_s c_stmt_tree;
129 124
130 /* State saving variables. */ 125 /* State saving variables. */
131 tree c_break_label; 126 tree c_break_label;
132 tree c_cont_label; 127 tree c_cont_label;
133
134 /* Linked list of TRANSLATION_UNIT_DECLS for the translation units
135 included in this invocation. Note that the current translation
136 unit is not included in this list. */
137
138 static GTY(()) tree all_translation_units;
139 128
140 /* A list of decls to be made automatically visible in each file scope. */ 129 /* A list of decls to be made automatically visible in each file scope. */
141 static GTY(()) tree visible_builtins; 130 static GTY(()) tree visible_builtins;
142 131
143 /* Set to 0 at beginning of a function definition, set to 1 if 132 /* Set to 0 at beginning of a function definition, set to 1 if
420 409
421 /* True if this scope has any label bindings. This is used to speed 410 /* True if this scope has any label bindings. This is used to speed
422 up searching for labels when popping scopes, particularly since 411 up searching for labels when popping scopes, particularly since
423 labels are normally only found at function scope. */ 412 labels are normally only found at function scope. */
424 BOOL_BITFIELD has_label_bindings : 1; 413 BOOL_BITFIELD has_label_bindings : 1;
414
415 /* True if we should issue a warning if a goto statement crosses any
416 of the bindings. We still need to check the list of bindings to
417 find the specific ones we need to warn about. This is true if
418 decl_jump_unsafe would return true for any of the bindings. This
419 is used to avoid looping over all the bindings unnecessarily. */
420 BOOL_BITFIELD has_jump_unsafe_decl : 1;
425 }; 421 };
426 422
427 /* The scope currently in effect. */ 423 /* The scope currently in effect. */
428 424
429 static GTY(()) struct c_scope *current_scope; 425 static GTY(()) struct c_scope *current_scope;
570 append_to_statement_list_force (t, &cur_stmt_list); 566 append_to_statement_list_force (t, &cur_stmt_list);
571 567
572 return t; 568 return t;
573 } 569 }
574 570
571 /* Return true if we will want to say something if a goto statement
572 crosses DECL. */
573
574 static bool
575 decl_jump_unsafe (tree decl)
576 {
577 if (decl == error_mark_node || TREE_TYPE (decl) == error_mark_node)
578 return false;
579
580 /* Always warn about crossing variably modified types. */
581 if ((TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == TYPE_DECL)
582 && variably_modified_type_p (TREE_TYPE (decl), NULL_TREE))
583 return true;
584
585 /* Otherwise, only warn if -Wgoto-misses-init and this is an
586 initialized automatic decl. */
587 if (warn_jump_misses_init
588 && TREE_CODE (decl) == VAR_DECL
589 && !TREE_STATIC (decl)
590 && DECL_INITIAL (decl) != NULL_TREE)
591 return true;
592
593 return false;
594 }
595
575 596
576 void 597 void
577 c_print_identifier (FILE *file, tree node, int indent) 598 c_print_identifier (FILE *file, tree node, int indent)
578 { 599 {
579 print_node (file, "symbol", I_SYMBOL_DECL (node), indent + 4); 600 print_node (file, "symbol", I_SYMBOL_DECL (node), indent + 4);
601 { 622 {
602 b = binding_freelist; 623 b = binding_freelist;
603 binding_freelist = b->prev; 624 binding_freelist = b->prev;
604 } 625 }
605 else 626 else
606 b = GGC_NEW (struct c_binding); 627 b = ggc_alloc_c_binding ();
607 628
608 b->shadowed = 0; 629 b->shadowed = 0;
609 b->decl = decl; 630 b->decl = decl;
610 b->id = name; 631 b->id = name;
611 b->depth = scope->depth; 632 b->depth = scope->depth;
617 638
618 b->u.type = NULL; 639 b->u.type = NULL;
619 640
620 b->prev = scope->bindings; 641 b->prev = scope->bindings;
621 scope->bindings = b; 642 scope->bindings = b;
643
644 if (decl_jump_unsafe (decl))
645 scope->has_jump_unsafe_decl = 1;
622 646
623 if (!name) 647 if (!name)
624 return; 648 return;
625 649
626 switch (TREE_CODE (decl)) 650 switch (TREE_CODE (decl))
715 739
716 void 740 void
717 record_inline_static (location_t loc, tree func, tree decl, 741 record_inline_static (location_t loc, tree func, tree decl,
718 enum c_inline_static_type type) 742 enum c_inline_static_type type)
719 { 743 {
720 struct c_inline_static *csi = GGC_NEW (struct c_inline_static); 744 struct c_inline_static *csi = ggc_alloc_c_inline_static ();
721 csi->location = loc; 745 csi->location = loc;
722 csi->function = func; 746 csi->function = func;
723 csi->static_decl = decl; 747 csi->static_decl = decl;
724 csi->type = type; 748 csi->type = type;
725 csi->next = c_inline_statics; 749 csi->next = c_inline_statics;
774 } 798 }
775 p->stmt_exprs = 0; 799 p->stmt_exprs = 0;
776 p->left_stmt_expr = false; 800 p->left_stmt_expr = false;
777 } 801 }
778 802
779 /* Return true if we will want to say something if a goto statement
780 crosses DECL. */
781
782 static bool
783 decl_jump_unsafe (tree decl)
784 {
785 if (decl == error_mark_node || TREE_TYPE (decl) == error_mark_node)
786 return false;
787
788 /* Always warn about crossing variably modified types. */
789 if ((TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == TYPE_DECL)
790 && variably_modified_type_p (TREE_TYPE (decl), NULL_TREE))
791 return true;
792
793 /* Otherwise, only warn if -Wgoto-misses-init and this is an
794 initialized automatic decl. */
795 if (warn_jump_misses_init
796 && TREE_CODE (decl) == VAR_DECL
797 && !TREE_STATIC (decl)
798 && DECL_INITIAL (decl) != NULL_TREE)
799 return true;
800
801 return false;
802 }
803
804 /* Update spot bindings P as we pop out of SCOPE. Return true if we 803 /* Update spot bindings P as we pop out of SCOPE. Return true if we
805 should push decls for a label. */ 804 should push decls for a label. */
806 805
807 static bool 806 static bool
808 update_spot_bindings (struct c_scope *scope, struct c_spot_bindings *p) 807 update_spot_bindings (struct c_scope *scope, struct c_spot_bindings *p)
939 { 938 {
940 scope = scope_freelist; 939 scope = scope_freelist;
941 scope_freelist = scope->outer; 940 scope_freelist = scope->outer;
942 } 941 }
943 else 942 else
944 scope = GGC_CNEW (struct c_scope); 943 scope = ggc_alloc_cleared_c_scope ();
945 944
946 /* The FLOAT_CONST_DECIMAL64 pragma applies to nested scopes. */ 945 /* The FLOAT_CONST_DECIMAL64 pragma applies to nested scopes. */
947 if (current_scope) 946 if (current_scope)
948 scope->float_const_decimal64 = current_scope->float_const_decimal64; 947 scope->float_const_decimal64 = current_scope->float_const_decimal64;
949 else 948 else
978 977
979 s = scope; 978 s = scope;
980 while (s != NULL) 979 while (s != NULL)
981 { 980 {
982 if (s->has_label_bindings) 981 if (s->has_label_bindings)
983 { 982 {
984 struct c_binding *b; 983 struct c_binding *b;
985 984
986 for (b = s->bindings; b != NULL; b = b->prev) 985 for (b = s->bindings; b != NULL; b = b->prev)
987 { 986 {
988 struct c_label_vars *label_vars; 987 struct c_label_vars *label_vars;
989 struct c_binding *b1; 988 struct c_binding *b1;
990 unsigned int ix; 989 bool hjud;
991 struct c_goto_bindings *g; 990 unsigned int ix;
992 991 struct c_goto_bindings *g;
993 if (TREE_CODE (b->decl) != LABEL_DECL) 992
994 continue; 993 if (TREE_CODE (b->decl) != LABEL_DECL)
995 label_vars = b->u.label; 994 continue;
996 995 label_vars = b->u.label;
997 b1 = label_vars->label_bindings.bindings_in_scope; 996
998 if (update_spot_bindings (scope, &label_vars->label_bindings)) 997 b1 = label_vars->label_bindings.bindings_in_scope;
999 { 998 if (label_vars->label_bindings.scope == NULL)
1000 /* This label is defined in this scope. */ 999 hjud = false;
1001 for (; b1 != NULL; b1 = b1->prev) 1000 else
1002 { 1001 hjud = label_vars->label_bindings.scope->has_jump_unsafe_decl;
1003 /* A goto from later in the function to this 1002 if (update_spot_bindings (scope, &label_vars->label_bindings))
1004 label will never see the initialization of 1003 {
1005 B1, if any. Save it to issue a warning if 1004 /* This label is defined in this scope. */
1006 needed. */ 1005 if (hjud)
1007 if (decl_jump_unsafe (b1->decl)) 1006 {
1008 VEC_safe_push (tree, gc, label_vars->decls_in_scope, 1007 for (; b1 != NULL; b1 = b1->prev)
1009 b1->decl); 1008 {
1010 } 1009 /* A goto from later in the function to this
1011 } 1010 label will never see the initialization
1012 1011 of B1, if any. Save it to issue a
1013 /* Update the bindings of any goto statements associated 1012 warning if needed. */
1014 with this label. */ 1013 if (decl_jump_unsafe (b1->decl))
1015 for (ix = 0; 1014 VEC_safe_push (tree, gc,
1016 VEC_iterate (c_goto_bindings_p, label_vars->gotos, ix, g); 1015 label_vars->decls_in_scope,
1017 ++ix) 1016 b1->decl);
1018 update_spot_bindings (scope, &g->goto_bindings); 1017 }
1019 } 1018 }
1020 } 1019 }
1020
1021 /* Update the bindings of any goto statements associated
1022 with this label. */
1023 FOR_EACH_VEC_ELT (c_goto_bindings_p, label_vars->gotos, ix, g)
1024 update_spot_bindings (scope, &g->goto_bindings);
1025 }
1026 }
1021 1027
1022 /* Don't search beyond the current function. */ 1028 /* Don't search beyond the current function. */
1023 if (s == current_function_scope) 1029 if (s == current_function_scope)
1024 break; 1030 break;
1025 1031
1085 "parameter list local" tagged types. */ 1091 "parameter list local" tagged types. */
1086 if (scope->function_body) 1092 if (scope->function_body)
1087 context = current_function_decl; 1093 context = current_function_decl;
1088 else if (scope == file_scope) 1094 else if (scope == file_scope)
1089 { 1095 {
1090 tree file_decl = build_decl (UNKNOWN_LOCATION, 1096 tree file_decl = build_translation_unit_decl (NULL_TREE);
1091 TRANSLATION_UNIT_DECL, 0, 0);
1092 TREE_CHAIN (file_decl) = all_translation_units;
1093 all_translation_units = file_decl;
1094 context = file_decl; 1097 context = file_decl;
1095 } 1098 }
1096 else 1099 else
1097 context = block; 1100 context = block;
1098 1101
1099 /* Clear all bindings in this scope. */ 1102 /* Clear all bindings in this scope. */
1100 for (b = scope->bindings; b; b = free_binding_and_advance (b)) 1103 for (b = scope->bindings; b; b = free_binding_and_advance (b))
1101 { 1104 {
1102 p = b->decl; 1105 p = b->decl;
1103 switch (TREE_CODE (p)) 1106 switch (TREE_CODE (p))
1104 { 1107 {
1105 case LABEL_DECL: 1108 case LABEL_DECL:
1106 /* Warnings for unused labels, errors for undefined labels. */ 1109 /* Warnings for unused labels, errors for undefined labels. */
1107 if (TREE_USED (p) && !DECL_INITIAL (p)) 1110 if (TREE_USED (p) && !DECL_INITIAL (p))
1108 { 1111 {
1109 error ("label %q+D used but not defined", p); 1112 error ("label %q+D used but not defined", p);
1110 DECL_INITIAL (p) = error_mark_node; 1113 DECL_INITIAL (p) = error_mark_node;
1111 } 1114 }
1112 else 1115 else
1113 warn_for_unused_label (p); 1116 warn_for_unused_label (p);
1114 1117 /* Labels go in BLOCK_VARS. */
1115 /* Labels go in BLOCK_VARS. */ 1118 DECL_CHAIN (p) = BLOCK_VARS (block);
1116 TREE_CHAIN (p) = BLOCK_VARS (block); 1119 BLOCK_VARS (block) = p;
1117 BLOCK_VARS (block) = p; 1120 gcc_assert (I_LABEL_BINDING (b->id) == b);
1118 gcc_assert (I_LABEL_BINDING (b->id) == b); 1121 I_LABEL_BINDING (b->id) = b->shadowed;
1119 I_LABEL_BINDING (b->id) = b->shadowed; 1122
1120 1123 /* Also pop back to the shadowed label_vars. */
1121 /* Also pop back to the shadowed label_vars. */ 1124 release_tree_vector (b->u.label->decls_in_scope);
1122 release_tree_vector (b->u.label->decls_in_scope); 1125 b->u.label = b->u.label->shadowed;
1123 b->u.label = b->u.label->shadowed; 1126 break;
1124 break; 1127
1125 1128 case ENUMERAL_TYPE:
1126 case ENUMERAL_TYPE: 1129 case UNION_TYPE:
1127 case UNION_TYPE: 1130 case RECORD_TYPE:
1128 case RECORD_TYPE: 1131 set_type_context (p, context);
1129 set_type_context (p, context); 1132
1130 1133 /* Types may not have tag-names, in which case the type
1131 /* Types may not have tag-names, in which case the type 1134 appears in the bindings list with b->id NULL. */
1132 appears in the bindings list with b->id NULL. */ 1135 if (b->id)
1133 if (b->id) 1136 {
1134 { 1137 gcc_assert (I_TAG_BINDING (b->id) == b);
1135 gcc_assert (I_TAG_BINDING (b->id) == b); 1138 I_TAG_BINDING (b->id) = b->shadowed;
1136 I_TAG_BINDING (b->id) = b->shadowed; 1139 }
1137 } 1140 break;
1138 break; 1141
1139 1142 case FUNCTION_DECL:
1140 case FUNCTION_DECL: 1143 /* Propagate TREE_ADDRESSABLE from nested functions to their
1141 /* Propagate TREE_ADDRESSABLE from nested functions to their 1144 containing functions. */
1142 containing functions. */ 1145 if (!TREE_ASM_WRITTEN (p)
1143 if (!TREE_ASM_WRITTEN (p) 1146 && DECL_INITIAL (p) != 0
1144 && DECL_INITIAL (p) != 0 1147 && TREE_ADDRESSABLE (p)
1145 && TREE_ADDRESSABLE (p) 1148 && DECL_ABSTRACT_ORIGIN (p) != 0
1146 && DECL_ABSTRACT_ORIGIN (p) != 0 1149 && DECL_ABSTRACT_ORIGIN (p) != p)
1147 && DECL_ABSTRACT_ORIGIN (p) != p) 1150 TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (p)) = 1;
1148 TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (p)) = 1; 1151 if (!DECL_EXTERNAL (p)
1149 if (!DECL_EXTERNAL (p) 1152 && !DECL_INITIAL (p)
1150 && !DECL_INITIAL (p) 1153 && scope != file_scope
1151 && scope != file_scope 1154 && scope != external_scope)
1152 && scope != external_scope) 1155 {
1153 { 1156 error ("nested function %q+D declared but never defined", p);
1154 error ("nested function %q+D declared but never defined", p); 1157 undef_nested_function = true;
1155 undef_nested_function = true; 1158 }
1156 } 1159 else if (DECL_DECLARED_INLINE_P (p)
1157 else if (DECL_DECLARED_INLINE_P (p) 1160 && TREE_PUBLIC (p)
1158 && TREE_PUBLIC (p) 1161 && !DECL_INITIAL (p))
1159 && !DECL_INITIAL (p)) 1162 {
1160 { 1163 /* C99 6.7.4p6: "a function with external linkage... declared
1161 /* C99 6.7.4p6: "a function with external linkage... declared 1164 with an inline function specifier ... shall also be defined
1162 with an inline function specifier ... shall also be defined 1165 in the same translation unit." */
1163 in the same translation unit." */ 1166 if (!flag_gnu89_inline)
1164 if (!flag_gnu89_inline) 1167 pedwarn (input_location, 0,
1165 pedwarn (input_location, 0, 1168 "inline function %q+D declared but never defined", p);
1166 "inline function %q+D declared but never defined", p); 1169 DECL_EXTERNAL (p) = 1;
1167 DECL_EXTERNAL (p) = 1; 1170 }
1168 } 1171
1169 1172 goto common_symbol;
1170 goto common_symbol; 1173
1171 1174 case VAR_DECL:
1172 case VAR_DECL: 1175 /* Warnings for unused variables. */
1173 /* Warnings for unused variables. */ 1176 if ((!TREE_USED (p) || !DECL_READ_P (p))
1174 if (!TREE_USED (p) 1177 && !TREE_NO_WARNING (p)
1175 && !TREE_NO_WARNING (p) 1178 && !DECL_IN_SYSTEM_HEADER (p)
1176 && !DECL_IN_SYSTEM_HEADER (p) 1179 && DECL_NAME (p)
1177 && DECL_NAME (p) 1180 && !DECL_ARTIFICIAL (p)
1178 && !DECL_ARTIFICIAL (p) 1181 && scope != file_scope
1179 && scope != file_scope 1182 && scope != external_scope)
1180 && scope != external_scope) 1183 {
1181 warning (OPT_Wunused_variable, "unused variable %q+D", p); 1184 if (!TREE_USED (p))
1182 1185 warning (OPT_Wunused_variable, "unused variable %q+D", p);
1183 if (b->inner_comp) 1186 else if (DECL_CONTEXT (p) == current_function_decl)
1184 { 1187 warning_at (DECL_SOURCE_LOCATION (p),
1185 error ("type of array %q+D completed incompatibly with" 1188 OPT_Wunused_but_set_variable,
1186 " implicit initialization", p); 1189 "variable %qD set but not used", p);
1187 } 1190 }
1188 1191
1189 /* Fall through. */ 1192 if (b->inner_comp)
1190 case TYPE_DECL: 1193 {
1191 case CONST_DECL: 1194 error ("type of array %q+D completed incompatibly with"
1192 common_symbol: 1195 " implicit initialization", p);
1193 /* All of these go in BLOCK_VARS, but only if this is the 1196 }
1194 binding in the home scope. */ 1197
1195 if (!b->nested) 1198 /* Fall through. */
1196 { 1199 case TYPE_DECL:
1197 TREE_CHAIN (p) = BLOCK_VARS (block); 1200 case CONST_DECL:
1198 BLOCK_VARS (block) = p; 1201 common_symbol:
1199 } 1202 /* All of these go in BLOCK_VARS, but only if this is the
1200 else if (VAR_OR_FUNCTION_DECL_P (p)) 1203 binding in the home scope. */
1201 { 1204 if (!b->nested)
1202 /* For block local externs add a special 1205 {
1203 DECL_EXTERNAL decl for debug info generation. */ 1206 DECL_CHAIN (p) = BLOCK_VARS (block);
1204 tree extp = copy_node (p); 1207 BLOCK_VARS (block) = p;
1205 1208 }
1206 DECL_EXTERNAL (extp) = 1; 1209 else if (VAR_OR_FUNCTION_DECL_P (p))
1207 TREE_STATIC (extp) = 0; 1210 {
1208 TREE_PUBLIC (extp) = 1; 1211 /* For block local externs add a special
1209 DECL_INITIAL (extp) = NULL_TREE; 1212 DECL_EXTERNAL decl for debug info generation. */
1210 DECL_LANG_SPECIFIC (extp) = NULL; 1213 tree extp = copy_node (p);
1211 DECL_CONTEXT (extp) = current_function_decl; 1214
1212 if (TREE_CODE (p) == FUNCTION_DECL) 1215
1213 { 1216 DECL_EXTERNAL (extp) = 1;
1214 DECL_RESULT (extp) = NULL_TREE; 1217 TREE_STATIC (extp) = 0;
1215 DECL_SAVED_TREE (extp) = NULL_TREE; 1218 TREE_PUBLIC (extp) = 1;
1216 DECL_STRUCT_FUNCTION (extp) = NULL; 1219 DECL_INITIAL (extp) = NULL_TREE;
1217 } 1220 DECL_LANG_SPECIFIC (extp) = NULL;
1218 if (b->locus != UNKNOWN_LOCATION) 1221 DECL_CONTEXT (extp) = current_function_decl;
1219 DECL_SOURCE_LOCATION (extp) = b->locus; 1222 if (TREE_CODE (p) == FUNCTION_DECL)
1220 TREE_CHAIN (extp) = BLOCK_VARS (block); 1223 {
1221 BLOCK_VARS (block) = extp; 1224 DECL_RESULT (extp) = NULL_TREE;
1222 } 1225 DECL_SAVED_TREE (extp) = NULL_TREE;
1223 /* If this is the file scope, and we are processing more 1226 DECL_STRUCT_FUNCTION (extp) = NULL;
1224 than one translation unit in this compilation, set 1227 }
1225 DECL_CONTEXT of each decl to the TRANSLATION_UNIT_DECL. 1228 if (b->locus != UNKNOWN_LOCATION)
1226 This makes same_translation_unit_p work, and causes 1229 DECL_SOURCE_LOCATION (extp) = b->locus;
1227 static declarations to be given disambiguating suffixes. */ 1230 DECL_CHAIN (extp) = BLOCK_VARS (block);
1228 if (scope == file_scope && num_in_fnames > 1) 1231 BLOCK_VARS (block) = extp;
1229 { 1232 }
1230 DECL_CONTEXT (p) = context; 1233 /* If this is the file scope set DECL_CONTEXT of each decl to
1231 if (TREE_CODE (p) == TYPE_DECL) 1234 the TRANSLATION_UNIT_DECL. This makes same_translation_unit_p
1232 set_type_context (TREE_TYPE (p), context); 1235 work. */
1233 } 1236 if (scope == file_scope)
1234 1237 {
1235 /* Fall through. */ 1238 DECL_CONTEXT (p) = context;
1236 /* Parameters go in DECL_ARGUMENTS, not BLOCK_VARS, and have 1239 if (TREE_CODE (p) == TYPE_DECL
1237 already been put there by store_parm_decls. Unused- 1240 && TREE_TYPE (p) != error_mark_node)
1238 parameter warnings are handled by function.c. 1241 set_type_context (TREE_TYPE (p), context);
1239 error_mark_node obviously does not go in BLOCK_VARS and 1242 }
1240 does not get unused-variable warnings. */ 1243
1241 case PARM_DECL: 1244
1242 case ERROR_MARK: 1245 /* Fall through. */
1243 /* It is possible for a decl not to have a name. We get 1246 /* Parameters go in DECL_ARGUMENTS, not BLOCK_VARS, and have
1244 here with b->id NULL in this case. */ 1247 already been put there by store_parm_decls. Unused-
1245 if (b->id) 1248 parameter warnings are handled by function.c.
1246 { 1249 error_mark_node obviously does not go in BLOCK_VARS and
1247 gcc_assert (I_SYMBOL_BINDING (b->id) == b); 1250 does not get unused-variable warnings. */
1248 I_SYMBOL_BINDING (b->id) = b->shadowed; 1251 case PARM_DECL:
1249 if (b->shadowed && b->shadowed->u.type) 1252 case ERROR_MARK:
1250 TREE_TYPE (b->shadowed->decl) = b->shadowed->u.type; 1253 /* It is possible for a decl not to have a name. We get
1251 } 1254 here with b->id NULL in this case. */
1252 break; 1255 if (b->id)
1253 1256 {
1254 default: 1257 gcc_assert (I_SYMBOL_BINDING (b->id) == b);
1255 gcc_unreachable (); 1258 I_SYMBOL_BINDING (b->id) = b->shadowed;
1256 } 1259 if (b->shadowed && b->shadowed->u.type)
1260 TREE_TYPE (b->shadowed->decl) = b->shadowed->u.type;
1261 }
1262 break;
1263
1264 default:
1265 gcc_unreachable ();
1266 }
1257 } 1267 }
1258 1268
1259 1269
1260 /* Dispose of the block that we just made inside some higher level. */ 1270 /* Dispose of the block that we just made inside some higher level. */
1261 if ((scope->function_body || scope == file_scope) && context) 1271 if ((scope->function_body || scope == file_scope) && context)
1297 push_scope (); 1307 push_scope ();
1298 file_scope = current_scope; 1308 file_scope = current_scope;
1299 1309
1300 start_fname_decls (); 1310 start_fname_decls ();
1301 1311
1302 for (decl = visible_builtins; decl; decl = TREE_CHAIN (decl)) 1312 for (decl = visible_builtins; decl; decl = DECL_CHAIN (decl))
1303 bind (DECL_NAME (decl), decl, file_scope, 1313 bind (DECL_NAME (decl), decl, file_scope,
1304 /*invisible=*/false, /*nested=*/true, DECL_SOURCE_LOCATION (decl)); 1314 /*invisible=*/false, /*nested=*/true, DECL_SOURCE_LOCATION (decl));
1305 } 1315 }
1306 1316
1307 void 1317 void
1347 1357
1348 if (!scope->has_label_bindings) 1358 if (!scope->has_label_bindings)
1349 continue; 1359 continue;
1350 1360
1351 for (b = scope->bindings; b != NULL; b = b->prev) 1361 for (b = scope->bindings; b != NULL; b = b->prev)
1352 { 1362 {
1353 struct c_label_vars *label_vars; 1363 struct c_label_vars *label_vars;
1354 unsigned int ix; 1364 unsigned int ix;
1355 struct c_goto_bindings *g; 1365 struct c_goto_bindings *g;
1356 1366
1357 if (TREE_CODE (b->decl) != LABEL_DECL) 1367 if (TREE_CODE (b->decl) != LABEL_DECL)
1358 continue; 1368 continue;
1359 label_vars = b->u.label; 1369 label_vars = b->u.label;
1360 ++label_vars->label_bindings.stmt_exprs; 1370 ++label_vars->label_bindings.stmt_exprs;
1361 for (ix = 0; 1371 FOR_EACH_VEC_ELT (c_goto_bindings_p, label_vars->gotos, ix, g)
1362 VEC_iterate (c_goto_bindings_p, label_vars->gotos, ix, g); 1372 ++g->goto_bindings.stmt_exprs;
1363 ++ix) 1373 }
1364 ++g->goto_bindings.stmt_exprs;
1365 }
1366 } 1374 }
1367 1375
1368 if (switch_bindings != NULL) 1376 if (switch_bindings != NULL)
1369 ++switch_bindings->stmt_exprs; 1377 ++switch_bindings->stmt_exprs;
1370 } 1378 }
1382 1390
1383 if (!scope->has_label_bindings) 1391 if (!scope->has_label_bindings)
1384 continue; 1392 continue;
1385 1393
1386 for (b = scope->bindings; b != NULL; b = b->prev) 1394 for (b = scope->bindings; b != NULL; b = b->prev)
1387 { 1395 {
1388 struct c_label_vars *label_vars; 1396 struct c_label_vars *label_vars;
1389 unsigned int ix; 1397 unsigned int ix;
1390 struct c_goto_bindings *g; 1398 struct c_goto_bindings *g;
1391 1399
1392 if (TREE_CODE (b->decl) != LABEL_DECL) 1400 if (TREE_CODE (b->decl) != LABEL_DECL)
1393 continue; 1401 continue;
1394 label_vars = b->u.label; 1402 label_vars = b->u.label;
1395 --label_vars->label_bindings.stmt_exprs; 1403 --label_vars->label_bindings.stmt_exprs;
1396 if (label_vars->label_bindings.stmt_exprs < 0) 1404 if (label_vars->label_bindings.stmt_exprs < 0)
1397 { 1405 {
1398 label_vars->label_bindings.left_stmt_expr = true; 1406 label_vars->label_bindings.left_stmt_expr = true;
1399 label_vars->label_bindings.stmt_exprs = 0; 1407 label_vars->label_bindings.stmt_exprs = 0;
1400 } 1408 }
1401 for (ix = 0; 1409 FOR_EACH_VEC_ELT (c_goto_bindings_p, label_vars->gotos, ix, g)
1402 VEC_iterate (c_goto_bindings_p, label_vars->gotos, ix, g); 1410 {
1403 ++ix) 1411 --g->goto_bindings.stmt_exprs;
1404 { 1412 if (g->goto_bindings.stmt_exprs < 0)
1405 --g->goto_bindings.stmt_exprs; 1413 {
1406 if (g->goto_bindings.stmt_exprs < 0) 1414 g->goto_bindings.left_stmt_expr = true;
1407 { 1415 g->goto_bindings.stmt_exprs = 0;
1408 g->goto_bindings.left_stmt_expr = true; 1416 }
1409 g->goto_bindings.stmt_exprs = 0; 1417 }
1410 } 1418 }
1411 }
1412 }
1413 } 1419 }
1414 1420
1415 if (switch_bindings != NULL) 1421 if (switch_bindings != NULL)
1416 { 1422 {
1417 --switch_bindings->stmt_exprs; 1423 --switch_bindings->stmt_exprs;
1520 { 1526 {
1521 tree t; 1527 tree t;
1522 1528
1523 if (TREE_CODE (olddecl) != FUNCTION_DECL 1529 if (TREE_CODE (olddecl) != FUNCTION_DECL
1524 || !comptypes (TREE_TYPE (oldtype), TREE_TYPE (newtype)) 1530 || !comptypes (TREE_TYPE (oldtype), TREE_TYPE (newtype))
1525 || !((TYPE_ARG_TYPES (oldtype) == 0 && DECL_INITIAL (olddecl) == 0) 1531 || !((!prototype_p (oldtype) && DECL_INITIAL (olddecl) == 0)
1526 || 1532 || (!prototype_p (newtype) && DECL_INITIAL (newdecl) == 0)))
1527 (TYPE_ARG_TYPES (newtype) == 0 && DECL_INITIAL (newdecl) == 0)))
1528 return; 1533 return;
1529 1534
1530 t = TYPE_ARG_TYPES (oldtype); 1535 t = TYPE_ARG_TYPES (oldtype);
1531 if (t == 0) 1536 if (t == 0)
1532 t = TYPE_ARG_TYPES (newtype); 1537 t = TYPE_ARG_TYPES (newtype);
1790 } 1795 }
1791 } 1796 }
1792 1797
1793 /* Redeclaration of a type is a constraint violation (6.7.2.3p1), 1798 /* Redeclaration of a type is a constraint violation (6.7.2.3p1),
1794 but silently ignore the redeclaration if either is in a system 1799 but silently ignore the redeclaration if either is in a system
1795 header. (Conflicting redeclarations were handled above.) */ 1800 header. (Conflicting redeclarations were handled above.) This
1801 is allowed for C1X if the types are the same, not just
1802 compatible. */
1796 if (TREE_CODE (newdecl) == TYPE_DECL) 1803 if (TREE_CODE (newdecl) == TYPE_DECL)
1797 { 1804 {
1805 bool types_different = false;
1806 int comptypes_result;
1807
1808 comptypes_result
1809 = comptypes_check_different_types (oldtype, newtype, &types_different);
1810
1811 if (comptypes_result != 1 || types_different)
1812 {
1813 error ("redefinition of typedef %q+D with different type", newdecl);
1814 locate_old_decl (olddecl);
1815 return false;
1816 }
1817
1798 if (DECL_IN_SYSTEM_HEADER (newdecl) 1818 if (DECL_IN_SYSTEM_HEADER (newdecl)
1799 || DECL_IN_SYSTEM_HEADER (olddecl) 1819 || DECL_IN_SYSTEM_HEADER (olddecl)
1800 || TREE_NO_WARNING (newdecl) 1820 || TREE_NO_WARNING (newdecl)
1801 || TREE_NO_WARNING (olddecl)) 1821 || TREE_NO_WARNING (olddecl))
1802 return true; /* Allow OLDDECL to continue in use. */ 1822 return true; /* Allow OLDDECL to continue in use. */
1803 1823
1804 error ("redefinition of typedef %q+D", newdecl); 1824 if (pedantic && !flag_isoc1x)
1805 locate_old_decl (olddecl); 1825 {
1806 return false; 1826 pedwarn (input_location, OPT_pedantic,
1827 "redefinition of typedef %q+D", newdecl);
1828 locate_old_decl (olddecl);
1829 }
1830 else if (variably_modified_type_p (newtype, NULL))
1831 {
1832 /* Whether there is a constraint violation for the types not
1833 being the same cannot be determined at compile time; a
1834 warning that there may be one at runtime is considered
1835 appropriate (WG14 reflector message 11743, 8 May 2009). */
1836 warning (0, "redefinition of typedef %q+D may be a constraint "
1837 "violation at runtime", newdecl);
1838 locate_old_decl (olddecl);
1839 }
1840
1841 return true;
1807 } 1842 }
1808 1843
1809 /* Function declarations can either be 'static' or 'extern' (no 1844 /* Function declarations can either be 'static' or 'extern' (no
1810 qualifier is equivalent to 'extern' - C99 6.2.2p5) and therefore 1845 qualifier is equivalent to 'extern' - C99 6.2.2p5) and therefore
1811 can never conflict with each other on account of linkage 1846 can never conflict with each other on account of linkage
1819 /* If you declare a built-in function name as static, or 1854 /* If you declare a built-in function name as static, or
1820 define the built-in with an old-style definition (so we 1855 define the built-in with an old-style definition (so we
1821 can't validate the argument list) the built-in definition is 1856 can't validate the argument list) the built-in definition is
1822 overridden, but optionally warn this was a bad choice of name. */ 1857 overridden, but optionally warn this was a bad choice of name. */
1823 if (DECL_BUILT_IN (olddecl) 1858 if (DECL_BUILT_IN (olddecl)
1824 && !C_DECL_DECLARED_BUILTIN (olddecl) 1859 && !C_DECL_DECLARED_BUILTIN (olddecl)
1825 && (!TREE_PUBLIC (newdecl) 1860 && (!TREE_PUBLIC (newdecl)
1826 || (DECL_INITIAL (newdecl) 1861 || (DECL_INITIAL (newdecl)
1827 && !TYPE_ARG_TYPES (TREE_TYPE (newdecl))))) 1862 && !prototype_p (TREE_TYPE (newdecl)))))
1828 { 1863 {
1829 warning (OPT_Wshadow, "declaration of %q+D shadows " 1864 warning (OPT_Wshadow, "declaration of %q+D shadows "
1830 "a built-in function", newdecl); 1865 "a built-in function", newdecl);
1831 /* Discard the old built-in function. */ 1866 /* Discard the old built-in function. */
1832 return false; 1867 return false;
1833 } 1868 }
1834 1869
1835 if (DECL_INITIAL (newdecl)) 1870 if (DECL_INITIAL (newdecl))
1836 { 1871 {
1837 if (DECL_INITIAL (olddecl)) 1872 if (DECL_INITIAL (olddecl))
1838 { 1873 {
1859 } 1894 }
1860 } 1895 }
1861 /* If we have a prototype after an old-style function definition, 1896 /* If we have a prototype after an old-style function definition,
1862 the argument types must be checked specially. */ 1897 the argument types must be checked specially. */
1863 else if (DECL_INITIAL (olddecl) 1898 else if (DECL_INITIAL (olddecl)
1864 && !TYPE_ARG_TYPES (oldtype) && TYPE_ARG_TYPES (newtype) 1899 && !prototype_p (oldtype) && prototype_p (newtype)
1865 && TYPE_ACTUAL_ARG_TYPES (oldtype) 1900 && TYPE_ACTUAL_ARG_TYPES (oldtype)
1866 && !validate_proto_after_old_defn (newdecl, newtype, oldtype)) 1901 && !validate_proto_after_old_defn (newdecl, newtype, oldtype))
1867 { 1902 {
1868 locate_old_decl (olddecl); 1903 locate_old_decl (olddecl);
1869 return false; 1904 return false;
1870 } 1905 }
1871 /* A non-static declaration (even an "extern") followed by a 1906 /* A non-static declaration (even an "extern") followed by a
1872 static declaration is undefined behavior per C99 6.2.2p3-5,7. 1907 static declaration is undefined behavior per C99 6.2.2p3-5,7.
1873 The same is true for a static forward declaration at block 1908 The same is true for a static forward declaration at block
1874 scope followed by a non-static declaration/definition at file 1909 scope followed by a non-static declaration/definition at file
1875 scope. Static followed by non-static at the same scope is 1910 scope. Static followed by non-static at the same scope is
2128 merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype) 2163 merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype)
2129 { 2164 {
2130 bool new_is_definition = (TREE_CODE (newdecl) == FUNCTION_DECL 2165 bool new_is_definition = (TREE_CODE (newdecl) == FUNCTION_DECL
2131 && DECL_INITIAL (newdecl) != 0); 2166 && DECL_INITIAL (newdecl) != 0);
2132 bool new_is_prototype = (TREE_CODE (newdecl) == FUNCTION_DECL 2167 bool new_is_prototype = (TREE_CODE (newdecl) == FUNCTION_DECL
2133 && TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != 0); 2168 && prototype_p (TREE_TYPE (newdecl)));
2134 bool old_is_prototype = (TREE_CODE (olddecl) == FUNCTION_DECL 2169 bool old_is_prototype = (TREE_CODE (olddecl) == FUNCTION_DECL
2135 && TYPE_ARG_TYPES (TREE_TYPE (olddecl)) != 0); 2170 && prototype_p (TREE_TYPE (olddecl)));
2136 bool extern_changed = false; 2171 bool extern_changed = false;
2137 2172
2138 /* For real parm decl following a forward decl, rechain the old decl 2173 /* For real parm decl following a forward decl, rechain the old decl
2139 in its new location and clear TREE_ASM_WRITTEN (it's not a 2174 in its new location and clear TREE_ASM_WRITTEN (it's not a
2140 forward decl anymore). */ 2175 forward decl anymore). */
2367 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl) 2402 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl)
2368 = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl); 2403 = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl);
2369 2404
2370 /* Also preserve various other info from the definition. */ 2405 /* Also preserve various other info from the definition. */
2371 if (!new_is_definition) 2406 if (!new_is_definition)
2372 { 2407 {
2373 tree t; 2408 tree t;
2374 DECL_RESULT (newdecl) = DECL_RESULT (olddecl); 2409 DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
2375 DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl); 2410 DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
2376 DECL_STRUCT_FUNCTION (newdecl) = DECL_STRUCT_FUNCTION (olddecl); 2411 DECL_STRUCT_FUNCTION (newdecl) = DECL_STRUCT_FUNCTION (olddecl);
2377 DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl); 2412 DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl);
2378 gimple_set_body (newdecl, gimple_body (olddecl)); 2413 DECL_ARGUMENTS (newdecl) = copy_list (DECL_ARGUMENTS (olddecl));
2379 DECL_ARGUMENTS (newdecl) = copy_list (DECL_ARGUMENTS (olddecl)); 2414 for (t = DECL_ARGUMENTS (newdecl); t ; t = DECL_CHAIN (t))
2380 for (t = DECL_ARGUMENTS (newdecl); t ; t = TREE_CHAIN (t)) 2415 DECL_CONTEXT (t) = newdecl;
2381 DECL_CONTEXT (t) = newdecl; 2416
2382 2417 /* See if we've got a function to instantiate from. */
2383 /* See if we've got a function to instantiate from. */ 2418 if (DECL_SAVED_TREE (olddecl))
2384 if (DECL_SAVED_TREE (olddecl)) 2419 DECL_ABSTRACT_ORIGIN (newdecl)
2385 DECL_ABSTRACT_ORIGIN (newdecl) 2420 = DECL_ABSTRACT_ORIGIN (olddecl);
2386 = DECL_ABSTRACT_ORIGIN (olddecl); 2421 }
2387 }
2388 } 2422 }
2389 2423
2390 extern_changed = DECL_EXTERNAL (olddecl) && !DECL_EXTERNAL (newdecl); 2424 extern_changed = DECL_EXTERNAL (olddecl) && !DECL_EXTERNAL (newdecl);
2391 2425
2392 /* Merge the USED information. */ 2426 /* Merge the USED information. */
2393 if (TREE_USED (olddecl)) 2427 if (TREE_USED (olddecl))
2394 TREE_USED (newdecl) = 1; 2428 TREE_USED (newdecl) = 1;
2395 else if (TREE_USED (newdecl)) 2429 else if (TREE_USED (newdecl))
2396 TREE_USED (olddecl) = 1; 2430 TREE_USED (olddecl) = 1;
2431 if (TREE_CODE (olddecl) == VAR_DECL || TREE_CODE (olddecl) == PARM_DECL)
2432 DECL_READ_P (newdecl) |= DECL_READ_P (olddecl);
2433 if (DECL_PRESERVE_P (olddecl))
2434 DECL_PRESERVE_P (newdecl) = 1;
2435 else if (DECL_PRESERVE_P (newdecl))
2436 DECL_PRESERVE_P (olddecl) = 1;
2397 2437
2398 /* Copy most of the decl-specific fields of NEWDECL into OLDDECL. 2438 /* Copy most of the decl-specific fields of NEWDECL into OLDDECL.
2399 But preserve OLDDECL's DECL_UID, DECL_CONTEXT and 2439 But preserve OLDDECL's DECL_UID, DECL_CONTEXT and
2400 DECL_ARGUMENTS (if appropriate). */ 2440 DECL_ARGUMENTS (if appropriate). */
2401 { 2441 {
2409 (char *) newdecl + sizeof (struct tree_common), 2449 (char *) newdecl + sizeof (struct tree_common),
2410 sizeof (struct tree_decl_common) - sizeof (struct tree_common)); 2450 sizeof (struct tree_decl_common) - sizeof (struct tree_common));
2411 switch (TREE_CODE (olddecl)) 2451 switch (TREE_CODE (olddecl))
2412 { 2452 {
2413 case FUNCTION_DECL: 2453 case FUNCTION_DECL:
2414 gimple_set_body (olddecl, gimple_body (newdecl));
2415 /* fall through */
2416
2417 case FIELD_DECL: 2454 case FIELD_DECL:
2418 case VAR_DECL: 2455 case VAR_DECL:
2419 case PARM_DECL: 2456 case PARM_DECL:
2420 case LABEL_DECL: 2457 case LABEL_DECL:
2421 case RESULT_DECL: 2458 case RESULT_DECL:
2959 error_at (loc, "%qE undeclared here (not in a function)", id); 2996 error_at (loc, "%qE undeclared here (not in a function)", id);
2960 scope = current_scope; 2997 scope = current_scope;
2961 } 2998 }
2962 else 2999 else
2963 { 3000 {
2964 error_at (loc, "%qE undeclared (first use in this function)", id); 3001 if (!objc_diagnose_private_ivar (id))
2965 3002 error_at (loc, "%qE undeclared (first use in this function)", id);
2966 if (!already) 3003 if (!already)
2967 { 3004 {
2968 error_at (loc, "(Each undeclared identifier is reported only once"); 3005 inform (loc, "each undeclared identifier is reported only"
2969 error_at (loc, "for each function it appears in.)"); 3006 " once for each function it appears in");
2970 already = true; 3007 already = true;
2971 } 3008 }
2972 3009
2973 /* If we are parsing old-style parameter decls, current_function_decl 3010 /* If we are parsing old-style parameter decls, current_function_decl
2974 will be nonnull but current_function_scope will be null. */ 3011 will be nonnull but current_function_scope will be null. */
2975 scope = current_function_scope ? current_function_scope : current_scope; 3012 scope = current_function_scope ? current_function_scope : current_scope;
2976 } 3013 }
2990 struct c_label_vars *label_vars; 3027 struct c_label_vars *label_vars;
2991 3028
2992 DECL_CONTEXT (label) = current_function_decl; 3029 DECL_CONTEXT (label) = current_function_decl;
2993 DECL_MODE (label) = VOIDmode; 3030 DECL_MODE (label) = VOIDmode;
2994 3031
2995 label_vars = GGC_NEW (struct c_label_vars); 3032 label_vars = ggc_alloc_c_label_vars ();
2996 label_vars->shadowed = NULL; 3033 label_vars->shadowed = NULL;
2997 set_spot_bindings (&label_vars->label_bindings, defining); 3034 set_spot_bindings (&label_vars->label_bindings, defining);
2998 label_vars->decls_in_scope = make_tree_vector (); 3035 label_vars->decls_in_scope = make_tree_vector ();
2999 label_vars->gotos = VEC_alloc (c_goto_bindings_p, gc, 0); 3036 label_vars->gotos = VEC_alloc (c_goto_bindings_p, gc, 0);
3000 *p_label_vars = label_vars; 3037 *p_label_vars = label_vars;
3011 lookup_label (tree name) 3048 lookup_label (tree name)
3012 { 3049 {
3013 tree label; 3050 tree label;
3014 struct c_label_vars *label_vars; 3051 struct c_label_vars *label_vars;
3015 3052
3016 if (current_function_decl == 0) 3053 if (current_function_scope == 0)
3017 { 3054 {
3018 error ("label %qE referenced outside of any function", name); 3055 error ("label %qE referenced outside of any function", name);
3019 return 0; 3056 return 0;
3020 } 3057 }
3021 3058
3088 list for possible later warnings. */ 3125 list for possible later warnings. */
3089 if (label_vars->label_bindings.scope == NULL) 3126 if (label_vars->label_bindings.scope == NULL)
3090 { 3127 {
3091 struct c_goto_bindings *g; 3128 struct c_goto_bindings *g;
3092 3129
3093 g = GGC_NEW (struct c_goto_bindings); 3130 g = ggc_alloc_c_goto_bindings ();
3094 g->loc = loc; 3131 g->loc = loc;
3095 set_spot_bindings (&g->goto_bindings, true); 3132 set_spot_bindings (&g->goto_bindings, true);
3096 VEC_safe_push (c_goto_bindings_p, gc, label_vars->gotos, g); 3133 VEC_safe_push (c_goto_bindings_p, gc, label_vars->gotos, g);
3097 return label; 3134 return label;
3098 } 3135 }
3103 int i = 1; 3140 int i = 1;
3104 lab: 3141 lab:
3105 ... 3142 ...
3106 goto lab; 3143 goto lab;
3107 Issue a warning or error. */ 3144 Issue a warning or error. */
3108 for (ix = 0; VEC_iterate (tree, label_vars->decls_in_scope, ix, decl); ++ix) 3145 FOR_EACH_VEC_ELT (tree, label_vars->decls_in_scope, ix, decl)
3109 warn_about_goto (loc, label, decl); 3146 warn_about_goto (loc, label, decl);
3110 3147
3111 if (label_vars->label_bindings.left_stmt_expr) 3148 if (label_vars->label_bindings.left_stmt_expr)
3112 { 3149 {
3113 error_at (loc, "jump into statement expression"); 3150 error_at (loc, "jump into statement expression");
3155 check_earlier_gotos (tree label, struct c_label_vars* label_vars) 3192 check_earlier_gotos (tree label, struct c_label_vars* label_vars)
3156 { 3193 {
3157 unsigned int ix; 3194 unsigned int ix;
3158 struct c_goto_bindings *g; 3195 struct c_goto_bindings *g;
3159 3196
3160 for (ix = 0; 3197 FOR_EACH_VEC_ELT (c_goto_bindings_p, label_vars->gotos, ix, g)
3161 VEC_iterate (c_goto_bindings_p, label_vars->gotos, ix, g);
3162 ++ix)
3163 { 3198 {
3164 struct c_binding *b; 3199 struct c_binding *b;
3165 struct c_scope *scope; 3200 struct c_scope *scope;
3166 3201
3167 /* We have a goto to this label. The goto is going forward. In 3202 /* We have a goto to this label. The goto is going forward. In
3168 g->scope, the goto is going to skip any binding which was 3203 g->scope, the goto is going to skip any binding which was
3169 defined after g->bindings_in_scope. */ 3204 defined after g->bindings_in_scope. */
3170 for (b = g->goto_bindings.scope->bindings; 3205 if (g->goto_bindings.scope->has_jump_unsafe_decl)
3171 b != g->goto_bindings.bindings_in_scope; 3206 {
3172 b = b->prev) 3207 for (b = g->goto_bindings.scope->bindings;
3173 { 3208 b != g->goto_bindings.bindings_in_scope;
3174 if (decl_jump_unsafe (b->decl)) 3209 b = b->prev)
3175 warn_about_goto (g->loc, label, b->decl); 3210 {
3176 } 3211 if (decl_jump_unsafe (b->decl))
3212 warn_about_goto (g->loc, label, b->decl);
3213 }
3214 }
3177 3215
3178 /* We also need to warn about decls defined in any scopes 3216 /* We also need to warn about decls defined in any scopes
3179 between the scope of the label and the scope of the goto. */ 3217 between the scope of the label and the scope of the goto. */
3180 for (scope = label_vars->label_bindings.scope; 3218 for (scope = label_vars->label_bindings.scope;
3181 scope != g->goto_bindings.scope; 3219 scope != g->goto_bindings.scope;
3182 scope = scope->outer) 3220 scope = scope->outer)
3183 { 3221 {
3184 gcc_assert (scope != NULL); 3222 gcc_assert (scope != NULL);
3185 if (scope == label_vars->label_bindings.scope) 3223 if (scope->has_jump_unsafe_decl)
3186 b = label_vars->label_bindings.bindings_in_scope; 3224 {
3187 else 3225 if (scope == label_vars->label_bindings.scope)
3188 b = scope->bindings; 3226 b = label_vars->label_bindings.bindings_in_scope;
3189 for (; b != NULL; b = b->prev) 3227 else
3190 { 3228 b = scope->bindings;
3191 if (decl_jump_unsafe (b->decl)) 3229 for (; b != NULL; b = b->prev)
3192 warn_about_goto (g->loc, label, b->decl); 3230 {
3193 } 3231 if (decl_jump_unsafe (b->decl))
3194 } 3232 warn_about_goto (g->loc, label, b->decl);
3233 }
3234 }
3235 }
3195 3236
3196 if (g->goto_bindings.stmt_exprs > 0) 3237 if (g->goto_bindings.stmt_exprs > 0)
3197 { 3238 {
3198 error_at (g->loc, "jump into statement expression"); 3239 error_at (g->loc, "jump into statement expression");
3199 inform (DECL_SOURCE_LOCATION (label), "label %qD defined here", 3240 inform (DECL_SOURCE_LOCATION (label), "label %qD defined here",
3303 scope = scope->outer) 3344 scope = scope->outer)
3304 { 3345 {
3305 struct c_binding *b; 3346 struct c_binding *b;
3306 3347
3307 gcc_assert (scope != NULL); 3348 gcc_assert (scope != NULL);
3349
3350 if (!scope->has_jump_unsafe_decl)
3351 continue;
3352
3308 for (b = scope->bindings; b != NULL; b = b->prev) 3353 for (b = scope->bindings; b != NULL; b = b->prev)
3309 { 3354 {
3310 if (decl_jump_unsafe (b->decl)) 3355 if (decl_jump_unsafe (b->decl))
3311 { 3356 {
3312 if (variably_modified_type_p (TREE_TYPE (b->decl), NULL_TREE)) 3357 if (variably_modified_type_p (TREE_TYPE (b->decl), NULL_TREE))
3457 /* Declarations from c_common_nodes_and_builtins must not be associated 3502 /* Declarations from c_common_nodes_and_builtins must not be associated
3458 with this input file, lest we get differences between using and not 3503 with this input file, lest we get differences between using and not
3459 using preprocessed headers. */ 3504 using preprocessed headers. */
3460 input_location = BUILTINS_LOCATION; 3505 input_location = BUILTINS_LOCATION;
3461 3506
3462 build_common_tree_nodes (flag_signed_char, false); 3507 build_common_tree_nodes (flag_signed_char);
3463 3508
3464 c_common_nodes_and_builtins (); 3509 c_common_nodes_and_builtins ();
3465 3510
3466 /* In C, comparisons and TRUTH_* expressions have type int. */ 3511 /* In C, comparisons and TRUTH_* expressions have type int. */
3467 truthvalue_type_node = integer_type_node; 3512 truthvalue_type_node = integer_type_node;
3516 /* For invalid programs like this: 3561 /* For invalid programs like this:
3517 3562
3518 void foo() 3563 void foo()
3519 const char* p = __FUNCTION__; 3564 const char* p = __FUNCTION__;
3520 3565
3521 the __FUNCTION__ is believed to appear in K&R style function 3566 the __FUNCTION__ is believed to appear in K&R style function
3522 parameter declarator. In that case we still don't have 3567 parameter declarator. In that case we still don't have
3523 function_scope. */ 3568 function_scope. */
3524 && (!errorcount || current_function_scope)) 3569 && (!seen_error () || current_function_scope))
3525 { 3570 {
3526 DECL_CONTEXT (decl) = current_function_decl; 3571 DECL_CONTEXT (decl) = current_function_decl;
3527 bind (id, decl, current_function_scope, 3572 bind (id, decl, current_function_scope,
3528 /*invisible=*/false, /*nested=*/false, UNKNOWN_LOCATION); 3573 /*invisible=*/false, /*nested=*/false, UNKNOWN_LOCATION);
3529 } 3574 }
3538 { 3583 {
3539 tree type = TREE_TYPE (decl); 3584 tree type = TREE_TYPE (decl);
3540 tree id = DECL_NAME (decl); 3585 tree id = DECL_NAME (decl);
3541 3586
3542 const char *name = IDENTIFIER_POINTER (id); 3587 const char *name = IDENTIFIER_POINTER (id);
3543 C_DECL_BUILTIN_PROTOTYPE (decl) = (TYPE_ARG_TYPES (type) != 0); 3588 C_DECL_BUILTIN_PROTOTYPE (decl) = prototype_p (type);
3544 3589
3545 /* Should never be called on a symbol with a preexisting meaning. */ 3590 /* Should never be called on a symbol with a preexisting meaning. */
3546 gcc_assert (!I_SYMBOL_BINDING (id)); 3591 gcc_assert (!I_SYMBOL_BINDING (id));
3547 3592
3548 bind (id, decl, external_scope, /*invisible=*/true, /*nested=*/false, 3593 bind (id, decl, external_scope, /*invisible=*/true, /*nested=*/false,
3550 3595
3551 /* Builtins in the implementation namespace are made visible without 3596 /* Builtins in the implementation namespace are made visible without
3552 needing to be explicitly declared. See push_file_scope. */ 3597 needing to be explicitly declared. See push_file_scope. */
3553 if (name[0] == '_' && (name[1] == '_' || ISUPPER (name[1]))) 3598 if (name[0] == '_' && (name[1] == '_' || ISUPPER (name[1])))
3554 { 3599 {
3555 TREE_CHAIN (decl) = visible_builtins; 3600 DECL_CHAIN (decl) = visible_builtins;
3556 visible_builtins = decl; 3601 visible_builtins = decl;
3557 } 3602 }
3558 3603
3559 return decl; 3604 return decl;
3560 } 3605 }
3564 { 3609 {
3565 tree type = TREE_TYPE (decl); 3610 tree type = TREE_TYPE (decl);
3566 tree id = DECL_NAME (decl); 3611 tree id = DECL_NAME (decl);
3567 3612
3568 const char *name = IDENTIFIER_POINTER (id); 3613 const char *name = IDENTIFIER_POINTER (id);
3569 C_DECL_BUILTIN_PROTOTYPE (decl) = (TYPE_ARG_TYPES (type) != 0); 3614 C_DECL_BUILTIN_PROTOTYPE (decl) = prototype_p (type);
3570 3615
3571 /* Should never be called on a symbol with a preexisting meaning. */ 3616 /* Should never be called on a symbol with a preexisting meaning. */
3572 gcc_assert (!I_SYMBOL_BINDING (id)); 3617 gcc_assert (!I_SYMBOL_BINDING (id));
3573 3618
3574 bind (id, decl, external_scope, /*invisible=*/false, /*nested=*/false, 3619 bind (id, decl, external_scope, /*invisible=*/false, /*nested=*/false,
3576 3621
3577 /* Builtins in the implementation namespace are made visible without 3622 /* Builtins in the implementation namespace are made visible without
3578 needing to be explicitly declared. See push_file_scope. */ 3623 needing to be explicitly declared. See push_file_scope. */
3579 if (name[0] == '_' && (name[1] == '_' || ISUPPER (name[1]))) 3624 if (name[0] == '_' && (name[1] == '_' || ISUPPER (name[1])))
3580 { 3625 {
3581 TREE_CHAIN (decl) = visible_builtins; 3626 DECL_CHAIN (decl) = visible_builtins;
3582 visible_builtins = decl; 3627 visible_builtins = decl;
3583 } 3628 }
3584 3629
3585 return decl; 3630 return decl;
3586 } 3631 }
3610 { 3655 {
3611 tree value = declspecs->type; 3656 tree value = declspecs->type;
3612 enum tree_code code = TREE_CODE (value); 3657 enum tree_code code = TREE_CODE (value);
3613 3658
3614 if (code == RECORD_TYPE || code == UNION_TYPE || code == ENUMERAL_TYPE) 3659 if (code == RECORD_TYPE || code == UNION_TYPE || code == ENUMERAL_TYPE)
3615 /* Used to test also that TYPE_SIZE (value) != 0. 3660 /* Used to test also that TYPE_SIZE (value) != 0.
3616 That caused warning for `struct foo;' at top level in the file. */ 3661 That caused warning for `struct foo;' at top level in the file. */
3617 { 3662 {
3618 tree name = TYPE_NAME (value); 3663 tree name = TYPE_NAME (value);
3619 tree t; 3664 tree t;
3620 3665
3621 found_tag = true; 3666 found_tag = true;
3622 3667
3623 if (declspecs->restrict_p) 3668 if (declspecs->restrict_p)
3624 { 3669 {
3625 error ("invalid use of %<restrict%>"); 3670 error ("invalid use of %<restrict%>");
3626 warned = 1; 3671 warned = 1;
3627 } 3672 }
3628 3673
3629 if (name == 0) 3674 if (name == 0)
3630 { 3675 {
3631 if (warned != 1 && code != ENUMERAL_TYPE) 3676 if (warned != 1 && code != ENUMERAL_TYPE)
3632 /* Empty unnamed enum OK */ 3677 /* Empty unnamed enum OK */
3633 { 3678 {
3634 pedwarn (input_location, 0, 3679 pedwarn (input_location, 0,
3635 "unnamed struct/union that defines no instances"); 3680 "unnamed struct/union that defines no instances");
3636 warned = 1; 3681 warned = 1;
3637 } 3682 }
3638 } 3683 }
3639 else if (!declspecs->tag_defined_p 3684 else if (declspecs->typespec_kind != ctsk_tagdef
3640 && declspecs->storage_class != csc_none) 3685 && declspecs->typespec_kind != ctsk_tagfirstref
3641 { 3686 && declspecs->storage_class != csc_none)
3642 if (warned != 1) 3687 {
3643 pedwarn (input_location, 0, 3688 if (warned != 1)
3644 "empty declaration with storage class specifier " 3689 pedwarn (input_location, 0,
3645 "does not redeclare tag"); 3690 "empty declaration with storage class specifier "
3646 warned = 1; 3691 "does not redeclare tag");
3647 pending_xref_error (); 3692 warned = 1;
3648 } 3693 pending_xref_error ();
3649 else if (!declspecs->tag_defined_p 3694 }
3650 && (declspecs->const_p 3695 else if (declspecs->typespec_kind != ctsk_tagdef
3651 || declspecs->volatile_p 3696 && declspecs->typespec_kind != ctsk_tagfirstref
3652 || declspecs->restrict_p 3697 && (declspecs->const_p
3653 || declspecs->address_space)) 3698 || declspecs->volatile_p
3654 { 3699 || declspecs->restrict_p
3655 if (warned != 1) 3700 || declspecs->address_space))
3656 pedwarn (input_location, 0, 3701 {
3657 "empty declaration with type qualifier " 3702 if (warned != 1)
3658 "does not redeclare tag"); 3703 pedwarn (input_location, 0,
3659 warned = 1; 3704 "empty declaration with type qualifier "
3660 pending_xref_error (); 3705 "does not redeclare tag");
3661 } 3706 warned = 1;
3707 pending_xref_error ();
3708 }
3709 else
3710 {
3711 pending_invalid_xref = 0;
3712 t = lookup_tag (code, name, 1, NULL);
3713
3714 if (t == 0)
3715 {
3716 t = make_node (code);
3717 pushtag (input_location, name, t);
3718 }
3719 }
3720 }
3662 else 3721 else
3663 { 3722 {
3664 pending_invalid_xref = 0; 3723 pending_invalid_xref = 0;
3665 t = lookup_tag (code, name, 1, NULL); 3724 t = lookup_tag (code, name, 1, NULL);
3666 3725
3998 4057
3999 /* If this is a function declaration, write a record describing it to the 4058 /* If this is a function declaration, write a record describing it to the
4000 prototypes file (if requested). */ 4059 prototypes file (if requested). */
4001 4060
4002 if (TREE_CODE (decl) == FUNCTION_DECL) 4061 if (TREE_CODE (decl) == FUNCTION_DECL)
4003 gen_aux_info_record (decl, 0, 0, TYPE_ARG_TYPES (TREE_TYPE (decl)) != 0); 4062 gen_aux_info_record (decl, 0, 0, prototype_p (TREE_TYPE (decl)));
4004 4063
4005 /* ANSI specifies that a tentative definition which is not merged with 4064 /* ANSI specifies that a tentative definition which is not merged with
4006 a non-tentative definition behaves exactly like a definition with an 4065 a non-tentative definition behaves exactly like a definition with an
4007 initializer equal to zero. (Section 3.7.2) 4066 initializer equal to zero. (Section 3.7.2)
4008 4067
4042 struct c_declarator *ce = declarator; 4101 struct c_declarator *ce = declarator;
4043 4102
4044 if (ce->kind == cdk_pointer) 4103 if (ce->kind == cdk_pointer)
4045 ce = declarator->declarator; 4104 ce = declarator->declarator;
4046 if (ce->kind == cdk_function) 4105 if (ce->kind == cdk_function)
4047 { 4106 {
4048 tree args = ce->u.arg_info->parms; 4107 tree args = ce->u.arg_info->parms;
4049 for (; args; args = TREE_CHAIN (args)) 4108 for (; args; args = DECL_CHAIN (args))
4050 { 4109 {
4051 tree type = TREE_TYPE (args); 4110 tree type = TREE_TYPE (args);
4052 if (type && INTEGRAL_TYPE_P (type) 4111 if (type && INTEGRAL_TYPE_P (type)
4053 && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)) 4112 && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
4054 DECL_ARG_TYPE (args) = integer_type_node; 4113 DECL_ARG_TYPE (args) = integer_type_node;
4055 } 4114 }
4056 } 4115 }
4057 } 4116 }
4058 4117
4059 if (TREE_CODE (decl) == FUNCTION_DECL 4118 if (TREE_CODE (decl) == FUNCTION_DECL
4060 && DECL_DECLARED_INLINE_P (decl) 4119 && DECL_DECLARED_INLINE_P (decl)
4061 && DECL_UNINLINABLE (decl) 4120 && DECL_UNINLINABLE (decl)
4073 && DECL_DECLARED_INLINE_P (current_function_decl) 4132 && DECL_DECLARED_INLINE_P (current_function_decl)
4074 && DECL_EXTERNAL (current_function_decl)) 4133 && DECL_EXTERNAL (current_function_decl))
4075 record_inline_static (input_location, current_function_decl, 4134 record_inline_static (input_location, current_function_decl,
4076 decl, csi_modifiable); 4135 decl, csi_modifiable);
4077 4136
4137 if (c_dialect_objc ()
4138 && (TREE_CODE (decl) == VAR_DECL
4139 || TREE_CODE (decl) == FUNCTION_DECL))
4140 objc_check_global_decl (decl);
4141
4078 /* Add this decl to the current scope. 4142 /* Add this decl to the current scope.
4079 TEM may equal DECL or it may be a previous decl of the same name. */ 4143 TEM may equal DECL or it may be a previous decl of the same name. */
4080 tem = pushdecl (decl); 4144 tem = pushdecl (decl);
4081 4145
4082 if (initialized && DECL_EXTERNAL (tem)) 4146 if (initialized && DECL_EXTERNAL (tem))
4084 DECL_EXTERNAL (tem) = 0; 4148 DECL_EXTERNAL (tem) = 0;
4085 TREE_STATIC (tem) = 1; 4149 TREE_STATIC (tem) = 1;
4086 } 4150 }
4087 4151
4088 return tem; 4152 return tem;
4153 }
4154
4155 /* Subroutine of finish_decl. TYPE is the type of an uninitialized object
4156 DECL or the non-array element type if DECL is an uninitialized array.
4157 If that type has a const member, diagnose this. */
4158
4159 static void
4160 diagnose_uninitialized_cst_member (tree decl, tree type)
4161 {
4162 tree field;
4163 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
4164 {
4165 tree field_type;
4166 if (TREE_CODE (field) != FIELD_DECL)
4167 continue;
4168 field_type = strip_array_types (TREE_TYPE (field));
4169
4170 if (TYPE_QUALS (field_type) & TYPE_QUAL_CONST)
4171 {
4172 warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wc___compat,
4173 "uninitialized const member in %qT is invalid in C++",
4174 strip_array_types (TREE_TYPE (decl)));
4175 inform (DECL_SOURCE_LOCATION (field), "%qD should be initialized", field);
4176 }
4177
4178 if (TREE_CODE (field_type) == RECORD_TYPE
4179 || TREE_CODE (field_type) == UNION_TYPE)
4180 diagnose_uninitialized_cst_member (decl, field_type);
4181 }
4089 } 4182 }
4090 4183
4091 /* Finish processing of a declaration; 4184 /* Finish processing of a declaration;
4092 install its initial value. 4185 install its initial value.
4093 If ORIGTYPE is not NULL_TREE, it is the original type of INIT. 4186 If ORIGTYPE is not NULL_TREE, it is the original type of INIT.
4244 TREE_TYPE (decl) = error_mark_node; 4337 TREE_TYPE (decl) = error_mark_node;
4245 } 4338 }
4246 } 4339 }
4247 4340
4248 if (TREE_USED (type)) 4341 if (TREE_USED (type))
4249 TREE_USED (decl) = 1; 4342 {
4343 TREE_USED (decl) = 1;
4344 DECL_READ_P (decl) = 1;
4345 }
4250 } 4346 }
4251 4347
4252 /* If this is a function and an assembler name is specified, reset DECL_RTL 4348 /* If this is a function and an assembler name is specified, reset DECL_RTL
4253 so we can give it its new name. Also, update built_in_decls if it 4349 so we can give it its new name. Also, update built_in_decls if it
4254 was a normal built-in. */ 4350 was a normal built-in. */
4375 /* Install a cleanup (aka destructor) if one was given. */ 4471 /* Install a cleanup (aka destructor) if one was given. */
4376 if (TREE_CODE (decl) == VAR_DECL && !TREE_STATIC (decl)) 4472 if (TREE_CODE (decl) == VAR_DECL && !TREE_STATIC (decl))
4377 { 4473 {
4378 tree attr = lookup_attribute ("cleanup", DECL_ATTRIBUTES (decl)); 4474 tree attr = lookup_attribute ("cleanup", DECL_ATTRIBUTES (decl));
4379 if (attr) 4475 if (attr)
4380 { 4476 {
4381 tree cleanup_id = TREE_VALUE (TREE_VALUE (attr)); 4477 tree cleanup_id = TREE_VALUE (TREE_VALUE (attr));
4382 tree cleanup_decl = lookup_name (cleanup_id); 4478 tree cleanup_decl = lookup_name (cleanup_id);
4383 tree cleanup; 4479 tree cleanup;
4384 VEC(tree,gc) *vec; 4480 VEC(tree,gc) *vec;
4385 4481
4386 /* Build "cleanup(&decl)" for the destructor. */ 4482 /* Build "cleanup(&decl)" for the destructor. */
4387 cleanup = build_unary_op (input_location, ADDR_EXPR, decl, 0); 4483 cleanup = build_unary_op (input_location, ADDR_EXPR, decl, 0);
4388 vec = VEC_alloc (tree, gc, 1); 4484 vec = VEC_alloc (tree, gc, 1);
4389 VEC_quick_push (tree, vec, cleanup); 4485 VEC_quick_push (tree, vec, cleanup);
4390 cleanup = build_function_call_vec (DECL_SOURCE_LOCATION (decl), 4486 cleanup = build_function_call_vec (DECL_SOURCE_LOCATION (decl),
4391 cleanup_decl, vec, NULL); 4487 cleanup_decl, vec, NULL);
4392 VEC_free (tree, gc, vec); 4488 VEC_free (tree, gc, vec);
4393 4489
4394 /* Don't warn about decl unused; the cleanup uses it. */ 4490 /* Don't warn about decl unused; the cleanup uses it. */
4395 TREE_USED (decl) = 1; 4491 TREE_USED (decl) = 1;
4396 TREE_USED (cleanup_decl) = 1; 4492 TREE_USED (cleanup_decl) = 1;
4397 4493 DECL_READ_P (decl) = 1;
4398 push_cleanup (decl, cleanup, false); 4494
4399 } 4495 push_cleanup (decl, cleanup, false);
4496 }
4400 } 4497 }
4401 4498
4402 if (warn_cxx_compat 4499 if (warn_cxx_compat
4403 && TREE_CODE (decl) == VAR_DECL 4500 && TREE_CODE (decl) == VAR_DECL
4404 && TREE_READONLY (decl)
4405 && !DECL_EXTERNAL (decl) 4501 && !DECL_EXTERNAL (decl)
4406 && DECL_INITIAL (decl) == NULL_TREE) 4502 && DECL_INITIAL (decl) == NULL_TREE)
4407 warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wc___compat, 4503 {
4408 "uninitialized const %qD is invalid in C++", decl); 4504 type = strip_array_types (type);
4505 if (TREE_READONLY (decl))
4506 warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wc___compat,
4507 "uninitialized const %qD is invalid in C++", decl);
4508 else if ((TREE_CODE (type) == RECORD_TYPE
4509 || TREE_CODE (type) == UNION_TYPE)
4510 && C_TYPE_FIELDS_READONLY (type))
4511 diagnose_uninitialized_cst_member (decl, type);
4512 }
4409 } 4513 }
4410 4514
4411 /* Given a parsed parameter declaration, decode it into a PARM_DECL. */ 4515 /* Given a parsed parameter declaration, decode it into a PARM_DECL. */
4412 4516
4413 tree 4517 tree
4474 the COMPOUND_LITERAL_EXPR rather than added elsewhere as a DECL_EXPR. */ 4578 the COMPOUND_LITERAL_EXPR rather than added elsewhere as a DECL_EXPR. */
4475 tree decl; 4579 tree decl;
4476 tree complit; 4580 tree complit;
4477 tree stmt; 4581 tree stmt;
4478 4582
4479 if (type == error_mark_node) 4583 if (type == error_mark_node
4584 || init == error_mark_node)
4480 return error_mark_node; 4585 return error_mark_node;
4481 4586
4482 decl = build_decl (loc, VAR_DECL, NULL_TREE, type); 4587 decl = build_decl (loc, VAR_DECL, NULL_TREE, type);
4483 DECL_EXTERNAL (decl) = 0; 4588 DECL_EXTERNAL (decl) = 0;
4484 TREE_PUBLIC (decl) = 0; 4589 TREE_PUBLIC (decl) = 0;
4485 TREE_STATIC (decl) = (current_scope == file_scope); 4590 TREE_STATIC (decl) = (current_scope == file_scope);
4486 DECL_CONTEXT (decl) = current_function_decl; 4591 DECL_CONTEXT (decl) = current_function_decl;
4487 TREE_USED (decl) = 1; 4592 TREE_USED (decl) = 1;
4593 DECL_READ_P (decl) = 1;
4488 TREE_TYPE (decl) = type; 4594 TREE_TYPE (decl) = type;
4489 TREE_READONLY (decl) = TYPE_READONLY (type); 4595 TREE_READONLY (decl) = TYPE_READONLY (type);
4490 store_init_value (loc, decl, init, NULL_TREE); 4596 store_init_value (loc, decl, init, NULL_TREE);
4491 4597
4492 if (TREE_CODE (type) == ARRAY_TYPE && !COMPLETE_TYPE_P (type)) 4598 if (TREE_CODE (type) == ARRAY_TYPE && !COMPLETE_TYPE_P (type))
4533 is valid for C++. */ 4639 is valid for C++. */
4534 4640
4535 void 4641 void
4536 check_compound_literal_type (location_t loc, struct c_type_name *type_name) 4642 check_compound_literal_type (location_t loc, struct c_type_name *type_name)
4537 { 4643 {
4538 if (warn_cxx_compat && type_name->specs->tag_defined_p) 4644 if (warn_cxx_compat
4645 && (type_name->specs->typespec_kind == ctsk_tagdef
4646 || type_name->specs->typespec_kind == ctsk_tagfirstref))
4539 warning_at (loc, OPT_Wc___compat, 4647 warning_at (loc, OPT_Wc___compat,
4540 "defining a type in a compound literal is invalid in C++"); 4648 "defining a type in a compound literal is invalid in C++");
4541 } 4649 }
4542 4650
4543 /* Determine whether TYPE is a structure with a flexible array member, 4651 /* Determine whether TYPE is a structure with a flexible array member,
4550 switch (TREE_CODE (type)) 4658 switch (TREE_CODE (type))
4551 { 4659 {
4552 case RECORD_TYPE: 4660 case RECORD_TYPE:
4553 x = TYPE_FIELDS (type); 4661 x = TYPE_FIELDS (type);
4554 if (x == NULL_TREE) 4662 if (x == NULL_TREE)
4555 return false; 4663 return false;
4556 while (TREE_CHAIN (x) != NULL_TREE) 4664 while (DECL_CHAIN (x) != NULL_TREE)
4557 x = TREE_CHAIN (x); 4665 x = DECL_CHAIN (x);
4558 if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE 4666 if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE
4559 && TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE 4667 && TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE
4560 && TYPE_DOMAIN (TREE_TYPE (x)) != NULL_TREE 4668 && TYPE_DOMAIN (TREE_TYPE (x)) != NULL_TREE
4561 && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (x))) == NULL_TREE) 4669 && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (x))) == NULL_TREE)
4562 return true; 4670 return true;
4563 return false; 4671 return false;
4564 case UNION_TYPE: 4672 case UNION_TYPE:
4565 for (x = TYPE_FIELDS (type); x != NULL_TREE; x = TREE_CHAIN (x)) 4673 for (x = TYPE_FIELDS (type); x != NULL_TREE; x = DECL_CHAIN (x))
4566 { 4674 {
4567 if (flexible_array_type_p (TREE_TYPE (x))) 4675 if (flexible_array_type_p (TREE_TYPE (x)))
4568 return true; 4676 return true;
4569 } 4677 }
4570 return false; 4678 return false;
4571 default: 4679 default:
4572 return false; 4680 return false;
4573 } 4681 }
4574 } 4682 }
4813 location_t loc = UNKNOWN_LOCATION; 4921 location_t loc = UNKNOWN_LOCATION;
4814 const char *errmsg; 4922 const char *errmsg;
4815 tree expr_dummy; 4923 tree expr_dummy;
4816 bool expr_const_operands_dummy; 4924 bool expr_const_operands_dummy;
4817 4925
4926 if (TREE_CODE (type) == ERROR_MARK)
4927 return error_mark_node;
4818 if (expr == NULL) 4928 if (expr == NULL)
4819 expr = &expr_dummy; 4929 expr = &expr_dummy;
4820 if (expr_const_operands == NULL) 4930 if (expr_const_operands == NULL)
4821 expr_const_operands = &expr_const_operands_dummy; 4931 expr_const_operands = &expr_const_operands_dummy;
4822 4932
5103 array_ptr_attrs = NULL_TREE; 5213 array_ptr_attrs = NULL_TREE;
5104 array_parm_static = 0; 5214 array_parm_static = 0;
5105 } 5215 }
5106 5216
5107 switch (declarator->kind) 5217 switch (declarator->kind)
5108 { 5218 {
5109 case cdk_attrs: 5219 case cdk_attrs:
5110 { 5220 {
5111 /* A declarator with embedded attributes. */ 5221 /* A declarator with embedded attributes. */
5112 tree attrs = declarator->u.attrs; 5222 tree attrs = declarator->u.attrs;
5113 const struct c_declarator *inner_decl; 5223 const struct c_declarator *inner_decl;
5114 int attr_flags = 0; 5224 int attr_flags = 0;
5115 declarator = declarator->declarator; 5225 declarator = declarator->declarator;
5116 inner_decl = declarator; 5226 inner_decl = declarator;
5117 while (inner_decl->kind == cdk_attrs) 5227 while (inner_decl->kind == cdk_attrs)
5118 inner_decl = inner_decl->declarator; 5228 inner_decl = inner_decl->declarator;
5119 if (inner_decl->kind == cdk_id) 5229 if (inner_decl->kind == cdk_id)
5120 attr_flags |= (int) ATTR_FLAG_DECL_NEXT; 5230 attr_flags |= (int) ATTR_FLAG_DECL_NEXT;
5121 else if (inner_decl->kind == cdk_function) 5231 else if (inner_decl->kind == cdk_function)
5122 attr_flags |= (int) ATTR_FLAG_FUNCTION_NEXT; 5232 attr_flags |= (int) ATTR_FLAG_FUNCTION_NEXT;
5123 else if (inner_decl->kind == cdk_array) 5233 else if (inner_decl->kind == cdk_array)
5124 attr_flags |= (int) ATTR_FLAG_ARRAY_NEXT; 5234 attr_flags |= (int) ATTR_FLAG_ARRAY_NEXT;
5125 returned_attrs = decl_attributes (&type, 5235 returned_attrs = decl_attributes (&type,
5126 chainon (returned_attrs, attrs), 5236 chainon (returned_attrs, attrs),
5127 attr_flags); 5237 attr_flags);
5128 break; 5238 break;
5129 } 5239 }
5130 case cdk_array: 5240 case cdk_array:
5131 { 5241 {
5132 tree itype = NULL_TREE; 5242 tree itype = NULL_TREE;
5133 tree size = declarator->u.array.dimen; 5243 tree size = declarator->u.array.dimen;
5134 /* The index is a signed object `sizetype' bits wide. */ 5244 /* The index is a signed object `sizetype' bits wide. */
5135 tree index_type = c_common_signed_type (sizetype); 5245 tree index_type = c_common_signed_type (sizetype);
5136 5246
5137 array_ptr_quals = declarator->u.array.quals; 5247 array_ptr_quals = declarator->u.array.quals;
5138 array_ptr_attrs = declarator->u.array.attrs; 5248 array_ptr_attrs = declarator->u.array.attrs;
5139 array_parm_static = declarator->u.array.static_p; 5249 array_parm_static = declarator->u.array.static_p;
5140 array_parm_vla_unspec_p = declarator->u.array.vla_unspec_p; 5250 array_parm_vla_unspec_p = declarator->u.array.vla_unspec_p;
5141 5251
5142 declarator = declarator->declarator; 5252 declarator = declarator->declarator;
5143 5253
5144 /* Check for some types that there cannot be arrays of. */ 5254 /* Check for some types that there cannot be arrays of. */
5145 5255
5146 if (VOID_TYPE_P (type)) 5256 if (VOID_TYPE_P (type))
5147 { 5257 {
5148 if (name) 5258 if (name)
5149 error_at (loc, "declaration of %qE as array of voids", name); 5259 error_at (loc, "declaration of %qE as array of voids", name);
5150 else 5260 else
5151 error_at (loc, "declaration of type name as array of voids"); 5261 error_at (loc, "declaration of type name as array of voids");
5152 type = error_mark_node; 5262 type = error_mark_node;
5153 } 5263 }
5154 5264
5155 if (TREE_CODE (type) == FUNCTION_TYPE) 5265 if (TREE_CODE (type) == FUNCTION_TYPE)
5156 { 5266 {
5157 if (name) 5267 if (name)
5158 error_at (loc, "declaration of %qE as array of functions", 5268 error_at (loc, "declaration of %qE as array of functions",
5159 name); 5269 name);
5160 else 5270 else
5161 error_at (loc, "declaration of type name as array of " 5271 error_at (loc, "declaration of type name as array of "
5162 "functions"); 5272 "functions");
5163 type = error_mark_node; 5273 type = error_mark_node;
5164 } 5274 }
5165 5275 if (pedantic && !in_system_header && flexible_array_type_p (type))
5166 if (pedantic && !in_system_header && flexible_array_type_p (type)) 5276 pedwarn (loc, OPT_pedantic,
5167 pedwarn (loc, OPT_pedantic, 5277 "invalid use of structure with flexible array member");
5168 "invalid use of structure with flexible array member"); 5278
5169 5279 if (size == error_mark_node)
5170 if (size == error_mark_node) 5280 type = error_mark_node;
5171 type = error_mark_node; 5281
5172 5282 if (type == error_mark_node)
5173 if (type == error_mark_node) 5283 continue;
5174 continue; 5284
5175 5285 /* If size was specified, set ITYPE to a range-type for
5176 /* If size was specified, set ITYPE to a range-type for 5286 that size. Otherwise, ITYPE remains null. finish_decl
5177 that size. Otherwise, ITYPE remains null. finish_decl 5287 may figure it out from an initial value. */
5178 may figure it out from an initial value. */ 5288
5179 5289 if (size)
5180 if (size) 5290 {
5181 { 5291 bool size_maybe_const = true;
5182 bool size_maybe_const = true; 5292 bool size_int_const = (TREE_CODE (size) == INTEGER_CST
5183 bool size_int_const = (TREE_CODE (size) == INTEGER_CST 5293 && !TREE_OVERFLOW (size));
5184 && !TREE_OVERFLOW (size)); 5294 bool this_size_varies = false;
5185 bool this_size_varies = false; 5295
5186 5296 /* Strip NON_LVALUE_EXPRs since we aren't using as an
5187 /* Strip NON_LVALUE_EXPRs since we aren't using as an 5297 lvalue. */
5188 lvalue. */ 5298 STRIP_TYPE_NOPS (size);
5189 STRIP_TYPE_NOPS (size); 5299
5190 5300 if (!INTEGRAL_TYPE_P (TREE_TYPE (size)))
5191 if (!INTEGRAL_TYPE_P (TREE_TYPE (size))) 5301 {
5192 { 5302 if (name)
5193 if (name) 5303 error_at (loc, "size of array %qE has non-integer type",
5194 error_at (loc, "size of array %qE has non-integer type", 5304 name);
5195 name); 5305 else
5196 else 5306 error_at (loc,
5197 error_at (loc, 5307 "size of unnamed array has non-integer type");
5198 "size of unnamed array has non-integer type"); 5308 size = integer_one_node;
5199 size = integer_one_node; 5309 }
5200 } 5310
5201 5311 size = c_fully_fold (size, false, &size_maybe_const);
5202 size = c_fully_fold (size, false, &size_maybe_const); 5312
5203 5313 if (pedantic && size_maybe_const && integer_zerop (size))
5204 if (pedantic && size_maybe_const && integer_zerop (size)) 5314 {
5205 { 5315 if (name)
5206 if (name) 5316 pedwarn (loc, OPT_pedantic,
5207 pedwarn (loc, OPT_pedantic, 5317 "ISO C forbids zero-size array %qE", name);
5208 "ISO C forbids zero-size array %qE", name); 5318 else
5209 else 5319 pedwarn (loc, OPT_pedantic,
5210 pedwarn (loc, OPT_pedantic, 5320 "ISO C forbids zero-size array");
5211 "ISO C forbids zero-size array"); 5321 }
5212 } 5322
5213 5323 if (TREE_CODE (size) == INTEGER_CST && size_maybe_const)
5214 if (TREE_CODE (size) == INTEGER_CST && size_maybe_const) 5324 {
5215 { 5325 constant_expression_warning (size);
5216 constant_expression_warning (size); 5326 if (tree_int_cst_sgn (size) < 0)
5217 if (tree_int_cst_sgn (size) < 0) 5327 {
5218 { 5328 if (name)
5219 if (name) 5329 error_at (loc, "size of array %qE is negative", name);
5220 error_at (loc, "size of array %qE is negative", name); 5330 else
5221 else 5331 error_at (loc, "size of unnamed array is negative");
5222 error_at (loc, "size of unnamed array is negative"); 5332 size = integer_one_node;
5223 size = integer_one_node; 5333 }
5224 } 5334 /* Handle a size folded to an integer constant but
5225 /* Handle a size folded to an integer constant but 5335 not an integer constant expression. */
5226 not an integer constant expression. */ 5336 if (!size_int_const)
5227 if (!size_int_const) 5337 {
5228 { 5338 /* If this is a file scope declaration of an
5229 /* If this is a file scope declaration of an 5339 ordinary identifier, this is invalid code;
5230 ordinary identifier, this is invalid code; 5340 diagnosing it here and not subsequently
5231 diagnosing it here and not subsequently 5341 treating the type as variable-length avoids
5232 treating the type as variable-length avoids 5342 more confusing diagnostics later. */
5233 more confusing diagnostics later. */ 5343 if ((decl_context == NORMAL || decl_context == FIELD)
5234 if ((decl_context == NORMAL || decl_context == FIELD) 5344 && current_scope == file_scope)
5235 && current_scope == file_scope) 5345 pedwarn (input_location, 0,
5236 pedwarn (input_location, 0, 5346 "variably modified %qE at file scope",
5237 "variably modified %qE at file scope", 5347 name);
5238 name); 5348 else
5239 else 5349 this_size_varies = size_varies = true;
5240 this_size_varies = size_varies = true; 5350 warn_variable_length_array (name, size);
5241 warn_variable_length_array (name, size); 5351 }
5242 } 5352 }
5243 } 5353 else if ((decl_context == NORMAL || decl_context == FIELD)
5244 else if ((decl_context == NORMAL || decl_context == FIELD) 5354 && current_scope == file_scope)
5245 && current_scope == file_scope) 5355 {
5246 { 5356 error_at (loc, "variably modified %qE at file scope", name);
5247 error_at (loc, "variably modified %qE at file scope", name); 5357 size = integer_one_node;
5248 size = integer_one_node; 5358 }
5249 } 5359 else
5250 else 5360 {
5251 { 5361 /* Make sure the array size remains visibly
5252 /* Make sure the array size remains visibly 5362 nonconstant even if it is (eg) a const variable
5253 nonconstant even if it is (eg) a const variable 5363 with known value. */
5254 with known value. */ 5364 this_size_varies = size_varies = true;
5255 this_size_varies = size_varies = true; 5365 warn_variable_length_array (name, size);
5256 warn_variable_length_array (name, size); 5366 }
5257 } 5367
5258 5368 if (integer_zerop (size) && !this_size_varies)
5259 if (integer_zerop (size) && !this_size_varies) 5369 {
5260 { 5370 /* A zero-length array cannot be represented with
5261 /* A zero-length array cannot be represented with 5371 an unsigned index type, which is what we'll
5262 an unsigned index type, which is what we'll 5372 get with build_index_type. Create an
5263 get with build_index_type. Create an 5373 open-ended range instead. */
5264 open-ended range instead. */ 5374 itype = build_range_type (sizetype, size, NULL_TREE);
5265 itype = build_range_type (sizetype, size, NULL_TREE); 5375 }
5266 } 5376 else
5267 else 5377 {
5268 { 5378 /* Arrange for the SAVE_EXPR on the inside of the
5269 /* Arrange for the SAVE_EXPR on the inside of the 5379 MINUS_EXPR, which allows the -1 to get folded
5270 MINUS_EXPR, which allows the -1 to get folded 5380 with the +1 that happens when building TYPE_SIZE. */
5271 with the +1 that happens when building TYPE_SIZE. */ 5381 if (size_varies)
5272 if (size_varies) 5382 size = c_variable_size (size);
5273 size = c_variable_size (size); 5383 if (this_size_varies && TREE_CODE (size) == INTEGER_CST)
5274 if (this_size_varies && TREE_CODE (size) == INTEGER_CST) 5384 size = build2 (COMPOUND_EXPR, TREE_TYPE (size),
5275 size = build2 (COMPOUND_EXPR, TREE_TYPE (size), 5385 integer_zero_node, size);
5276 integer_zero_node, size); 5386
5277 5387 /* Compute the maximum valid index, that is, size
5278 /* Compute the maximum valid index, that is, size 5388 - 1. Do the calculation in index_type, so that
5279 - 1. Do the calculation in index_type, so that 5389 if it is a variable the computations will be
5280 if it is a variable the computations will be 5390 done in the proper mode. */
5281 done in the proper mode. */ 5391 itype = fold_build2_loc (loc, MINUS_EXPR, index_type,
5282 itype = fold_build2_loc (loc, MINUS_EXPR, index_type, 5392 convert (index_type, size),
5283 convert (index_type, size), 5393 convert (index_type,
5284 convert (index_type, 5394 size_one_node));
5285 size_one_node)); 5395
5286 5396 /* If that overflowed, the array is too big. ???
5287 /* If that overflowed, the array is too big. ??? 5397 While a size of INT_MAX+1 technically shouldn't
5288 While a size of INT_MAX+1 technically shouldn't 5398 cause an overflow (because we subtract 1), the
5289 cause an overflow (because we subtract 1), the 5399 overflow is recorded during the conversion to
5290 overflow is recorded during the conversion to 5400 index_type, before the subtraction. Handling
5291 index_type, before the subtraction. Handling 5401 this case seems like an unnecessary
5292 this case seems like an unnecessary 5402 complication. */
5293 complication. */ 5403 if (TREE_CODE (itype) == INTEGER_CST
5294 if (TREE_CODE (itype) == INTEGER_CST 5404 && TREE_OVERFLOW (itype))
5295 && TREE_OVERFLOW (itype)) 5405 {
5296 { 5406 if (name)
5297 if (name) 5407 error_at (loc, "size of array %qE is too large",
5298 error_at (loc, "size of array %qE is too large", 5408 name);
5299 name); 5409 else
5300 else 5410 error_at (loc, "size of unnamed array is too large");
5301 error_at (loc, "size of unnamed array is too large"); 5411 type = error_mark_node;
5302 type = error_mark_node; 5412 continue;
5303 continue; 5413 }
5304 } 5414
5305 5415 itype = build_index_type (itype);
5306 itype = build_index_type (itype); 5416 }
5307 } 5417 if (this_size_varies)
5308 if (this_size_varies) 5418 {
5309 { 5419 if (*expr)
5310 if (*expr) 5420 *expr = build2 (COMPOUND_EXPR, TREE_TYPE (size),
5311 *expr = build2 (COMPOUND_EXPR, TREE_TYPE (size), 5421 *expr, size);
5312 *expr, size); 5422 else
5313 else 5423 *expr = size;
5314 *expr = size; 5424 *expr_const_operands &= size_maybe_const;
5315 *expr_const_operands &= size_maybe_const; 5425 }
5316 } 5426 }
5317 } 5427 else if (decl_context == FIELD)
5318 else if (decl_context == FIELD) 5428 {
5319 { 5429 bool flexible_array_member = false;
5320 bool flexible_array_member = false; 5430 if (array_parm_vla_unspec_p)
5321 if (array_parm_vla_unspec_p) 5431 /* Field names can in fact have function prototype
5322 /* Field names can in fact have function prototype 5432 scope so [*] is disallowed here through making
5323 scope so [*] is disallowed here through making 5433 the field variably modified, not through being
5324 the field variably modified, not through being 5434 something other than a declaration with function
5325 something other than a declaration with function 5435 prototype scope. */
5326 prototype scope. */ 5436 size_varies = true;
5327 size_varies = true; 5437 else
5328 else 5438 {
5329 { 5439 const struct c_declarator *t = declarator;
5330 const struct c_declarator *t = declarator; 5440 while (t->kind == cdk_attrs)
5331 while (t->kind == cdk_attrs) 5441 t = t->declarator;
5332 t = t->declarator; 5442 flexible_array_member = (t->kind == cdk_id);
5333 flexible_array_member = (t->kind == cdk_id); 5443 }
5334 } 5444 if (flexible_array_member
5335 if (flexible_array_member 5445 && pedantic && !flag_isoc99 && !in_system_header)
5336 && pedantic && !flag_isoc99 && !in_system_header) 5446 pedwarn (loc, OPT_pedantic,
5337 pedwarn (loc, OPT_pedantic, 5447 "ISO C90 does not support flexible array members");
5338 "ISO C90 does not support flexible array members"); 5448
5339 5449 /* ISO C99 Flexible array members are effectively
5340 /* ISO C99 Flexible array members are effectively 5450 identical to GCC's zero-length array extension. */
5341 identical to GCC's zero-length array extension. */ 5451 if (flexible_array_member || array_parm_vla_unspec_p)
5342 if (flexible_array_member || array_parm_vla_unspec_p) 5452 itype = build_range_type (sizetype, size_zero_node,
5343 itype = build_range_type (sizetype, size_zero_node, 5453 NULL_TREE);
5344 NULL_TREE); 5454 }
5345 } 5455 else if (decl_context == PARM)
5346 else if (decl_context == PARM) 5456 {
5347 { 5457 if (array_parm_vla_unspec_p)
5348 if (array_parm_vla_unspec_p) 5458 {
5349 { 5459 itype = build_range_type (sizetype, size_zero_node, NULL_TREE);
5350 itype = build_range_type (sizetype, size_zero_node, NULL_TREE); 5460 size_varies = true;
5351 size_varies = true; 5461 }
5352 } 5462 }
5353 } 5463 else if (decl_context == TYPENAME)
5354 else if (decl_context == TYPENAME) 5464 {
5355 { 5465 if (array_parm_vla_unspec_p)
5356 if (array_parm_vla_unspec_p) 5466 {
5357 { 5467 /* C99 6.7.5.2p4 */
5358 /* C99 6.7.5.2p4 */ 5468 warning (0, "%<[*]%> not in a declaration");
5359 warning (0, "%<[*]%> not in a declaration"); 5469 /* We use this to avoid messing up with incomplete
5360 /* We use this to avoid messing up with incomplete 5470 array types of the same type, that would
5361 array types of the same type, that would 5471 otherwise be modified below. */
5362 otherwise be modified below. */ 5472 itype = build_range_type (sizetype, size_zero_node,
5363 itype = build_range_type (sizetype, size_zero_node, 5473 NULL_TREE);
5364 NULL_TREE); 5474 size_varies = true;
5365 size_varies = true; 5475 }
5366 } 5476 }
5367 } 5477
5368 5478 /* Complain about arrays of incomplete types. */
5369 /* Complain about arrays of incomplete types. */ 5479 if (!COMPLETE_TYPE_P (type))
5370 if (!COMPLETE_TYPE_P (type)) 5480 {
5371 { 5481 error_at (loc, "array type has incomplete element type");
5372 error_at (loc, "array type has incomplete element type"); 5482 type = error_mark_node;
5373 type = error_mark_node; 5483 }
5374 } 5484 else
5375 else 5485 /* When itype is NULL, a shared incomplete array type is
5376 /* When itype is NULL, a shared incomplete array type is 5486 returned for all array of a given type. Elsewhere we
5377 returned for all array of a given type. Elsewhere we 5487 make sure we don't complete that type before copying
5378 make sure we don't complete that type before copying 5488 it, but here we want to make sure we don't ever
5379 it, but here we want to make sure we don't ever 5489 modify the shared type, so we gcc_assert (itype)
5380 modify the shared type, so we gcc_assert (itype) 5490 below. */
5381 below. */ 5491 {
5382 { 5492 addr_space_t as = DECODE_QUAL_ADDR_SPACE (type_quals);
5383 addr_space_t as = DECODE_QUAL_ADDR_SPACE (type_quals); 5493 if (!ADDR_SPACE_GENERIC_P (as) && as != TYPE_ADDR_SPACE (type))
5384 if (!ADDR_SPACE_GENERIC_P (as) && as != TYPE_ADDR_SPACE (type)) 5494 type = build_qualified_type (type,
5385 type = build_qualified_type (type, 5495 ENCODE_QUAL_ADDR_SPACE (as));
5386 ENCODE_QUAL_ADDR_SPACE (as)); 5496
5387 5497 type = build_array_type (type, itype);
5388 type = build_array_type (type, itype); 5498 }
5389 } 5499
5390 5500 if (type != error_mark_node)
5391 if (type != error_mark_node) 5501 {
5392 { 5502 if (size_varies)
5393 if (size_varies) 5503 {
5394 { 5504 /* It is ok to modify type here even if itype is
5395 /* It is ok to modify type here even if itype is 5505 NULL: if size_varies, we're in a
5396 NULL: if size_varies, we're in a 5506 multi-dimensional array and the inner type has
5397 multi-dimensional array and the inner type has 5507 variable size, so the enclosing shared array type
5398 variable size, so the enclosing shared array type 5508 must too. */
5399 must too. */ 5509 if (size && TREE_CODE (size) == INTEGER_CST)
5400 if (size && TREE_CODE (size) == INTEGER_CST) 5510 type
5401 type 5511 = build_distinct_type_copy (TYPE_MAIN_VARIANT (type));
5402 = build_distinct_type_copy (TYPE_MAIN_VARIANT (type)); 5512 C_TYPE_VARIABLE_SIZE (type) = 1;
5403 C_TYPE_VARIABLE_SIZE (type) = 1; 5513 }
5404 } 5514
5405 5515 /* The GCC extension for zero-length arrays differs from
5406 /* The GCC extension for zero-length arrays differs from 5516 ISO flexible array members in that sizeof yields
5407 ISO flexible array members in that sizeof yields 5517 zero. */
5408 zero. */ 5518 if (size && integer_zerop (size))
5409 if (size && integer_zerop (size)) 5519 {
5410 { 5520 gcc_assert (itype);
5411 gcc_assert (itype); 5521 type = build_distinct_type_copy (TYPE_MAIN_VARIANT (type));
5412 TYPE_SIZE (type) = bitsize_zero_node; 5522 TYPE_SIZE (type) = bitsize_zero_node;
5413 TYPE_SIZE_UNIT (type) = size_zero_node; 5523 TYPE_SIZE_UNIT (type) = size_zero_node;
5414 } 5524 SET_TYPE_STRUCTURAL_EQUALITY (type);
5415 if (array_parm_vla_unspec_p) 5525 }
5416 { 5526 if (array_parm_vla_unspec_p)
5417 gcc_assert (itype); 5527 {
5418 /* The type is complete. C99 6.7.5.2p4 */ 5528 gcc_assert (itype);
5419 TYPE_SIZE (type) = bitsize_zero_node; 5529 /* The type is complete. C99 6.7.5.2p4 */
5420 TYPE_SIZE_UNIT (type) = size_zero_node; 5530 type = build_distinct_type_copy (TYPE_MAIN_VARIANT (type));
5421 } 5531 TYPE_SIZE (type) = bitsize_zero_node;
5422 } 5532 TYPE_SIZE_UNIT (type) = size_zero_node;
5423 5533 SET_TYPE_STRUCTURAL_EQUALITY (type);
5424 if (decl_context != PARM 5534 }
5425 && (array_ptr_quals != TYPE_UNQUALIFIED 5535 }
5426 || array_ptr_attrs != NULL_TREE 5536
5427 || array_parm_static)) 5537 if (decl_context != PARM
5428 { 5538 && (array_ptr_quals != TYPE_UNQUALIFIED
5429 error_at (loc, "static or type qualifiers in non-parameter array declarator"); 5539 || array_ptr_attrs != NULL_TREE
5430 array_ptr_quals = TYPE_UNQUALIFIED; 5540 || array_parm_static))
5431 array_ptr_attrs = NULL_TREE; 5541 {
5432 array_parm_static = 0; 5542 error_at (loc, "static or type qualifiers in non-parameter array declarator");
5433 } 5543 array_ptr_quals = TYPE_UNQUALIFIED;
5434 break; 5544 array_ptr_attrs = NULL_TREE;
5435 } 5545 array_parm_static = 0;
5436 case cdk_function: 5546 }
5437 { 5547 break;
5438 /* Say it's a definition only for the declarator closest 5548 }
5439 to the identifier, apart possibly from some 5549 case cdk_function:
5440 attributes. */ 5550 {
5441 bool really_funcdef = false; 5551 /* Say it's a definition only for the declarator closest
5442 tree arg_types; 5552 to the identifier, apart possibly from some
5443 if (funcdef_flag) 5553 attributes. */
5444 { 5554 bool really_funcdef = false;
5445 const struct c_declarator *t = declarator->declarator; 5555 tree arg_types;
5446 while (t->kind == cdk_attrs) 5556 if (funcdef_flag)
5447 t = t->declarator; 5557 {
5448 really_funcdef = (t->kind == cdk_id); 5558 const struct c_declarator *t = declarator->declarator;
5449 } 5559 while (t->kind == cdk_attrs)
5450 5560 t = t->declarator;
5451 /* Declaring a function type. Make sure we have a valid 5561 really_funcdef = (t->kind == cdk_id);
5452 type for the function to return. */ 5562 }
5453 if (type == error_mark_node) 5563
5454 continue; 5564
5455 5565 /* Declaring a function type. Make sure we have a valid
5456 size_varies = false; 5566 type for the function to return. */
5457 5567 if (type == error_mark_node)
5458 /* Warn about some types functions can't return. */ 5568 continue;
5459 if (TREE_CODE (type) == FUNCTION_TYPE) 5569
5460 { 5570 size_varies = false;
5461 if (name) 5571
5462 error_at (loc, "%qE declared as function returning a " 5572 /* Warn about some types functions can't return. */
5463 "function", name); 5573 if (TREE_CODE (type) == FUNCTION_TYPE)
5464 else 5574 {
5465 error_at (loc, "type name declared as function " 5575 if (name)
5466 "returning a function"); 5576 error_at (loc, "%qE declared as function returning a "
5467 type = integer_type_node; 5577 "function", name);
5468 } 5578 else
5469 if (TREE_CODE (type) == ARRAY_TYPE) 5579 error_at (loc, "type name declared as function "
5470 { 5580 "returning a function");
5471 if (name) 5581 type = integer_type_node;
5472 error_at (loc, "%qE declared as function returning an array", 5582 }
5473 name); 5583 if (TREE_CODE (type) == ARRAY_TYPE)
5474 else 5584 {
5475 error_at (loc, "type name declared as function returning " 5585 if (name)
5476 "an array"); 5586 error_at (loc, "%qE declared as function returning an array",
5477 type = integer_type_node; 5587 name);
5478 } 5588 else
5479 errmsg = targetm.invalid_return_type (type); 5589 error_at (loc, "type name declared as function returning "
5480 if (errmsg) 5590 "an array");
5481 { 5591 type = integer_type_node;
5482 error (errmsg); 5592 }
5483 type = integer_type_node; 5593 errmsg = targetm.invalid_return_type (type);
5484 } 5594 if (errmsg)
5485 5595 {
5486 /* Construct the function type and go to the next 5596 error (errmsg);
5487 inner layer of declarator. */ 5597 type = integer_type_node;
5488 arg_info = declarator->u.arg_info; 5598 }
5489 arg_types = grokparms (arg_info, really_funcdef); 5599
5490 if (really_funcdef) 5600 /* Construct the function type and go to the next
5491 put_pending_sizes (arg_info->pending_sizes); 5601 inner layer of declarator. */
5492 5602 arg_info = declarator->u.arg_info;
5493 /* Type qualifiers before the return type of the function 5603 arg_types = grokparms (arg_info, really_funcdef);
5494 qualify the return type, not the function type. */ 5604 if (really_funcdef)
5495 if (type_quals) 5605 put_pending_sizes (arg_info->pending_sizes);
5496 { 5606
5497 /* Type qualifiers on a function return type are 5607 /* Type qualifiers before the return type of the function
5498 normally permitted by the standard but have no 5608 qualify the return type, not the function type. */
5499 effect, so give a warning at -Wreturn-type. 5609 if (type_quals)
5500 Qualifiers on a void return type are banned on 5610 {
5501 function definitions in ISO C; GCC used to used 5611 /* Type qualifiers on a function return type are
5502 them for noreturn functions. */ 5612 normally permitted by the standard but have no
5503 if (VOID_TYPE_P (type) && really_funcdef) 5613 effect, so give a warning at -Wreturn-type.
5504 pedwarn (loc, 0, 5614 Qualifiers on a void return type are banned on
5505 "function definition has qualified void return type"); 5615 function definitions in ISO C; GCC used to used
5506 else 5616 them for noreturn functions. */
5507 warning_at (loc, OPT_Wignored_qualifiers, 5617 if (VOID_TYPE_P (type) && really_funcdef)
5508 "type qualifiers ignored on function return type"); 5618 pedwarn (loc, 0,
5509 5619 "function definition has qualified void return type");
5510 type = c_build_qualified_type (type, type_quals); 5620 else
5511 } 5621 warning_at (loc, OPT_Wignored_qualifiers,
5512 type_quals = TYPE_UNQUALIFIED; 5622 "type qualifiers ignored on function return type");
5623
5624 type = c_build_qualified_type (type, type_quals);
5625 }
5626 type_quals = TYPE_UNQUALIFIED;
5513 5627
5514 #ifndef noCbC 5628 #ifndef noCbC
5515 if ( declspecs->typespec_word == cts_CbC_code ) 5629 if ( declspecs->typespec_word == cts_CbC_code )
5516 { 5630 {
5517 type = build_code_segment_type (type, arg_types); 5631 type = build_code_segment_type (type, arg_types);
5519 else 5633 else
5520 #endif 5634 #endif
5521 { 5635 {
5522 type = build_function_type (type, arg_types); 5636 type = build_function_type (type, arg_types);
5523 } 5637 }
5524 5638 declarator = declarator->declarator;
5525 declarator = declarator->declarator; 5639
5526 5640 /* Set the TYPE_CONTEXTs for each tagged type which is local to
5527 /* Set the TYPE_CONTEXTs for each tagged type which is local to 5641 the formal parameter list of this FUNCTION_TYPE to point to
5528 the formal parameter list of this FUNCTION_TYPE to point to 5642 the FUNCTION_TYPE node itself. */
5529 the FUNCTION_TYPE node itself. */ 5643 {
5530 { 5644 c_arg_tag *tag;
5531 tree link; 5645 unsigned ix;
5532 5646
5533 for (link = arg_info->tags; 5647 FOR_EACH_VEC_ELT_REVERSE (c_arg_tag, arg_info->tags, ix, tag)
5534 link; 5648 TYPE_CONTEXT (tag->type) = type;
5535 link = TREE_CHAIN (link)) 5649 }
5536 TYPE_CONTEXT (TREE_VALUE (link)) = type; 5650 break;
5537 } 5651 }
5538 break; 5652 case cdk_pointer:
5539 } 5653 {
5540 case cdk_pointer: 5654 /* Merge any constancy or volatility into the target type
5541 { 5655 for the pointer. */
5542 /* Merge any constancy or volatility into the target type 5656 if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
5543 for the pointer. */ 5657 && type_quals)
5544 5658 pedwarn (loc, OPT_pedantic,
5545 if (pedantic && TREE_CODE (type) == FUNCTION_TYPE 5659 "ISO C forbids qualified function types");
5546 && type_quals) 5660 if (type_quals)
5547 pedwarn (loc, OPT_pedantic, 5661 type = c_build_qualified_type (type, type_quals);
5548 "ISO C forbids qualified function types"); 5662 size_varies = false;
5549 if (type_quals) 5663
5550 type = c_build_qualified_type (type, type_quals); 5664 /* When the pointed-to type involves components of variable size,
5551 size_varies = false; 5665 care must be taken to ensure that the size evaluation code is
5552 5666 emitted early enough to dominate all the possible later uses
5553 /* When the pointed-to type involves components of variable size, 5667 and late enough for the variables on which it depends to have
5554 care must be taken to ensure that the size evaluation code is 5668 been assigned.
5555 emitted early enough to dominate all the possible later uses 5669 This is expected to happen automatically when the pointed-to
5556 and late enough for the variables on which it depends to have 5670 type has a name/declaration of it's own, but special attention
5557 been assigned. 5671 is required if the type is anonymous.
5558 5672 We handle the NORMAL and FIELD contexts here by attaching an
5559 This is expected to happen automatically when the pointed-to 5673 artificial TYPE_DECL to such pointed-to type. This forces the
5560 type has a name/declaration of it's own, but special attention 5674 sizes evaluation at a safe point and ensures it is not deferred
5561 is required if the type is anonymous. 5675 until e.g. within a deeper conditional context.
5562 5676 We expect nothing to be needed here for PARM or TYPENAME.
5563 We handle the NORMAL and FIELD contexts here by attaching an 5677 Pushing a TYPE_DECL at this point for TYPENAME would actually
5564 artificial TYPE_DECL to such pointed-to type. This forces the 5678 be incorrect, as we might be in the middle of an expression
5565 sizes evaluation at a safe point and ensures it is not deferred 5679 with side effects on the pointed-to type size "arguments" prior
5566 until e.g. within a deeper conditional context. 5680 to the pointer declaration point and the fake TYPE_DECL in the
5567 5681 enclosing context would force the size evaluation prior to the
5568 We expect nothing to be needed here for PARM or TYPENAME. 5682 side effects. */
5569 Pushing a TYPE_DECL at this point for TYPENAME would actually 5683
5570 be incorrect, as we might be in the middle of an expression 5684 if (!TYPE_NAME (type)
5571 with side effects on the pointed-to type size "arguments" prior 5685 && (decl_context == NORMAL || decl_context == FIELD)
5572 to the pointer declaration point and the fake TYPE_DECL in the 5686 && variably_modified_type_p (type, NULL_TREE))
5573 enclosing context would force the size evaluation prior to the 5687 {
5574 side effects. */ 5688 tree decl = build_decl (loc, TYPE_DECL, NULL_TREE, type);
5575 5689 DECL_ARTIFICIAL (decl) = 1;
5576 if (!TYPE_NAME (type) 5690 pushdecl (decl);
5577 && (decl_context == NORMAL || decl_context == FIELD) 5691 finish_decl (decl, loc, NULL_TREE, NULL_TREE, NULL_TREE);
5578 && variably_modified_type_p (type, NULL_TREE)) 5692 TYPE_NAME (type) = decl;
5579 { 5693 }
5580 tree decl = build_decl (loc, TYPE_DECL, NULL_TREE, type); 5694
5581 DECL_ARTIFICIAL (decl) = 1; 5695 type = build_pointer_type (type);
5582 pushdecl (decl); 5696
5583 finish_decl (decl, loc, NULL_TREE, NULL_TREE, NULL_TREE); 5697 /* Process type qualifiers (such as const or volatile)
5584 TYPE_NAME (type) = decl; 5698 that were given inside the `*'. */
5585 } 5699 type_quals = declarator->u.pointer_quals;
5586 5700
5587 type = build_pointer_type (type); 5701
5588 5702 declarator = declarator->declarator;
5589 /* Process type qualifiers (such as const or volatile) 5703 break;
5590 that were given inside the `*'. */ 5704 }
5591 type_quals = declarator->u.pointer_quals; 5705 default:
5592 5706 gcc_unreachable ();
5593 declarator = declarator->declarator; 5707 }
5594 break;
5595 }
5596 default:
5597 gcc_unreachable ();
5598 }
5599 } 5708 }
5600 *decl_attrs = chainon (returned_attrs, *decl_attrs); 5709 *decl_attrs = chainon (returned_attrs, *decl_attrs);
5601 5710
5602 /* Now TYPE has the actual type, apart from any qualifiers in 5711 /* Now TYPE has the actual type, apart from any qualifiers in
5603 TYPE_QUALS. */ 5712 TYPE_QUALS. */
5854 if (size_varies) 5963 if (size_varies)
5855 C_DECL_VARIABLE_SIZE (decl) = 1; 5964 C_DECL_VARIABLE_SIZE (decl) = 1;
5856 } 5965 }
5857 else if (TREE_CODE (type) == FUNCTION_TYPE) 5966 else if (TREE_CODE (type) == FUNCTION_TYPE)
5858 { 5967 {
5859 if (storage_class == csc_register || threadp) 5968 if (storage_class == csc_register || threadp)
5860 { 5969 {
5861 error_at (loc, "invalid storage class for function %qE", name); 5970 error_at (loc, "invalid storage class for function %qE", name);
5862 } 5971 }
5863 else if (current_scope != file_scope) 5972 else if (current_scope != file_scope)
5864 { 5973 {
5865 /* Function declaration not at file scope. Storage 5974 /* Function declaration not at file scope. Storage
5866 classes other than `extern' are not allowed, C99 5975 classes other than `extern' are not allowed, C99
5867 6.7.1p5, and `extern' makes no difference. However, 5976 6.7.1p5, and `extern' makes no difference. However,
5868 GCC allows 'auto', perhaps with 'inline', to support 5977 GCC allows 'auto', perhaps with 'inline', to support
5869 nested functions. */ 5978 nested functions. */
5870 if (storage_class == csc_auto) 5979 if (storage_class == csc_auto)
5871 pedwarn (loc, OPT_pedantic, 5980 pedwarn (loc, OPT_pedantic,
5872 "invalid storage class for function %qE", name); 5981 "invalid storage class for function %qE", name);
5873 else if (storage_class == csc_static) 5982 else if (storage_class == csc_static)
5874 { 5983 {
5875 error_at (loc, "invalid storage class for function %qE", name); 5984 error_at (loc, "invalid storage class for function %qE", name);
5876 if (funcdef_flag) 5985 if (funcdef_flag)
5877 storage_class = declspecs->storage_class = csc_none; 5986 storage_class = declspecs->storage_class = csc_none;
5878 else 5987 else
5879 return 0; 5988 return 0;
5880 } 5989 }
5881 } 5990 }
5882 5991
5883 decl = build_decl (declarator->id_loc, 5992
5884 FUNCTION_DECL, declarator->u.id, type); 5993 decl = build_decl (declarator->id_loc,
5885 decl = build_decl_attribute_variant (decl, decl_attr); 5994 FUNCTION_DECL, declarator->u.id, type);
5886 5995 decl = build_decl_attribute_variant (decl, decl_attr);
5887 if (pedantic && type_quals && !DECL_IN_SYSTEM_HEADER (decl)) 5996
5888 pedwarn (loc, OPT_pedantic, 5997 if (pedantic && type_quals && !DECL_IN_SYSTEM_HEADER (decl))
5889 "ISO C forbids qualified function types"); 5998 pedwarn (loc, OPT_pedantic,
5890 5999 "ISO C forbids qualified function types");
5891 /* GNU C interprets a volatile-qualified function type to indicate 6000
5892 that the function does not return. */ 6001 /* Every function declaration is an external reference
5893 if ((type_quals & TYPE_QUAL_VOLATILE) 6002 (DECL_EXTERNAL) except for those which are not at file
5894 && !VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl)))) 6003 scope and are explicitly declared "auto". This is
5895 warning_at (loc, 0, "%<noreturn%> function returns non-void value"); 6004 forbidden by standard C (C99 6.7.1p5) and is interpreted by
5896 6005 GCC to signify a forward declaration of a nested function. */
5897 /* Every function declaration is an external reference 6006 if (storage_class == csc_auto && current_scope != file_scope)
5898 (DECL_EXTERNAL) except for those which are not at file 6007 DECL_EXTERNAL (decl) = 0;
5899 scope and are explicitly declared "auto". This is 6008 /* In C99, a function which is declared 'inline' with 'extern'
5900 forbidden by standard C (C99 6.7.1p5) and is interpreted by 6009 is not an external reference (which is confusing). It
5901 GCC to signify a forward declaration of a nested function. */ 6010 means that the later definition of the function must be output
5902 if (storage_class == csc_auto && current_scope != file_scope) 6011 in this file, C99 6.7.4p6. In GNU C89, a function declared
5903 DECL_EXTERNAL (decl) = 0; 6012 'extern inline' is an external reference. */
5904 /* In C99, a function which is declared 'inline' with 'extern' 6013 else if (declspecs->inline_p && storage_class != csc_static)
5905 is not an external reference (which is confusing). It 6014 DECL_EXTERNAL (decl) = ((storage_class == csc_extern)
5906 means that the later definition of the function must be output 6015 == flag_gnu89_inline);
5907 in this file, C99 6.7.4p6. In GNU C89, a function declared 6016 else
5908 'extern inline' is an external reference. */ 6017 DECL_EXTERNAL (decl) = !initialized;
5909 else if (declspecs->inline_p && storage_class != csc_static) 6018
5910 DECL_EXTERNAL (decl) = ((storage_class == csc_extern) 6019 /* Record absence of global scope for `static' or `auto'. */
5911 == flag_gnu89_inline); 6020 TREE_PUBLIC (decl)
5912 else 6021 = !(storage_class == csc_static || storage_class == csc_auto);
5913 DECL_EXTERNAL (decl) = !initialized; 6022
5914 6023 /* For a function definition, record the argument information
5915 /* Record absence of global scope for `static' or `auto'. */ 6024 block where store_parm_decls will look for it. */
5916 TREE_PUBLIC (decl) 6025 if (funcdef_flag)
5917 = !(storage_class == csc_static || storage_class == csc_auto); 6026 current_function_arg_info = arg_info;
5918 6027
5919 /* For a function definition, record the argument information 6028 if (declspecs->default_int_p)
5920 block where store_parm_decls will look for it. */ 6029 C_FUNCTION_IMPLICIT_INT (decl) = 1;
5921 if (funcdef_flag) 6030
5922 current_function_arg_info = arg_info; 6031 /* Record presence of `inline', if it is reasonable. */
5923 6032 if (flag_hosted && MAIN_NAME_P (declarator->u.id))
5924 if (declspecs->default_int_p) 6033 {
5925 C_FUNCTION_IMPLICIT_INT (decl) = 1; 6034 if (declspecs->inline_p)
5926 6035 pedwarn (loc, 0, "cannot inline function %<main%>");
5927 /* Record presence of `inline', if it is reasonable. */ 6036 }
5928 if (flag_hosted && MAIN_NAME_P (declarator->u.id)) 6037 else if (declspecs->inline_p)
5929 { 6038 /* Record that the function is declared `inline'. */
5930 if (declspecs->inline_p) 6039 DECL_DECLARED_INLINE_P (decl) = 1;
5931 pedwarn (loc, 0, "cannot inline function %<main%>");
5932 }
5933 else if (declspecs->inline_p)
5934 /* Record that the function is declared `inline'. */
5935 DECL_DECLARED_INLINE_P (decl) = 1;
5936 } 6040 }
5937 else 6041 else
5938 { 6042 {
5939 /* It's a variable. */ 6043 /* It's a variable. */
5940 /* An uninitialized decl with `extern' is a reference. */ 6044 /* An uninitialized decl with `extern' is a reference. */
6093 return 0; /* don't set TYPE_ARG_TYPES in this case */ 6197 return 0; /* don't set TYPE_ARG_TYPES in this case */
6094 6198
6095 else if (arg_types && TREE_CODE (TREE_VALUE (arg_types)) == IDENTIFIER_NODE) 6199 else if (arg_types && TREE_CODE (TREE_VALUE (arg_types)) == IDENTIFIER_NODE)
6096 { 6200 {
6097 if (!funcdef_flag) 6201 if (!funcdef_flag)
6098 pedwarn (input_location, 0, "parameter names (without types) in function declaration"); 6202 {
6099 6203 pedwarn (input_location, 0, "parameter names (without types) in function declaration");
6100 arg_info->parms = arg_info->types; 6204 arg_info->parms = NULL_TREE;
6205 }
6206 else
6207 arg_info->parms = arg_info->types;
6101 arg_info->types = 0; 6208 arg_info->types = 0;
6102 return 0; 6209 return 0;
6103 } 6210 }
6104 else 6211 else
6105 { 6212 {
6115 already been given. If a parameter has void type, then 6222 already been given. If a parameter has void type, then
6116 however the function cannot be defined or called, so 6223 however the function cannot be defined or called, so
6117 warn. */ 6224 warn. */
6118 6225
6119 for (parm = arg_info->parms, typelt = arg_types, parmno = 1; 6226 for (parm = arg_info->parms, typelt = arg_types, parmno = 1;
6120 parm; 6227 parm;
6121 parm = TREE_CHAIN (parm), typelt = TREE_CHAIN (typelt), parmno++) 6228 parm = DECL_CHAIN (parm), typelt = TREE_CHAIN (typelt), parmno++)
6122 { 6229 {
6123 type = TREE_VALUE (typelt); 6230 type = TREE_VALUE (typelt);
6124 if (type == error_mark_node) 6231 if (type == error_mark_node)
6125 continue; 6232 continue;
6126 6233
6127 if (!COMPLETE_TYPE_P (type)) 6234 if (!COMPLETE_TYPE_P (type))
6128 { 6235 {
6129 if (funcdef_flag) 6236 if (funcdef_flag)
6130 { 6237 {
6131 if (DECL_NAME (parm)) 6238 if (DECL_NAME (parm))
6132 error_at (input_location, 6239 error_at (input_location,
6133 "parameter %u (%q+D) has incomplete type", 6240 "parameter %u (%q+D) has incomplete type",
6134 parmno, parm); 6241 parmno, parm);
6135 else 6242 else
6136 error_at (DECL_SOURCE_LOCATION (parm), 6243 error_at (DECL_SOURCE_LOCATION (parm),
6137 "parameter %u has incomplete type", 6244 "parameter %u has incomplete type",
6138 parmno); 6245 parmno);
6139 6246
6140 TREE_VALUE (typelt) = error_mark_node; 6247 TREE_VALUE (typelt) = error_mark_node;
6141 TREE_TYPE (parm) = error_mark_node; 6248 TREE_TYPE (parm) = error_mark_node;
6142 } 6249 arg_types = NULL_TREE;
6143 else if (VOID_TYPE_P (type)) 6250 }
6144 { 6251 else if (VOID_TYPE_P (type))
6145 if (DECL_NAME (parm)) 6252 {
6146 warning_at (input_location, 0, 6253 if (DECL_NAME (parm))
6147 "parameter %u (%q+D) has void type", 6254 warning_at (input_location, 0,
6148 parmno, parm); 6255 "parameter %u (%q+D) has void type",
6149 else 6256 parmno, parm);
6150 warning_at (DECL_SOURCE_LOCATION (parm), 0, 6257 else
6151 "parameter %u has void type", 6258 warning_at (DECL_SOURCE_LOCATION (parm), 0,
6152 parmno); 6259 "parameter %u has void type",
6153 } 6260 parmno);
6154 } 6261 }
6155 6262 }
6156 errmsg = targetm.invalid_parameter_type (type); 6263
6157 if (errmsg) 6264 errmsg = targetm.invalid_parameter_type (type);
6158 { 6265 if (errmsg)
6159 error (errmsg); 6266 {
6160 TREE_VALUE (typelt) = error_mark_node; 6267 error (errmsg);
6161 TREE_TYPE (parm) = error_mark_node; 6268 TREE_VALUE (typelt) = error_mark_node;
6162 } 6269 TREE_TYPE (parm) = error_mark_node;
6163 6270 arg_types = NULL_TREE;
6164 if (DECL_NAME (parm) && TREE_USED (parm)) 6271 }
6165 warn_if_shadowing (parm); 6272
6166 } 6273 if (DECL_NAME (parm) && TREE_USED (parm))
6274 warn_if_shadowing (parm);
6275 }
6167 return arg_types; 6276 return arg_types;
6168 } 6277 }
6278 }
6279
6280 /* Allocate and initialize a c_arg_info structure from the parser's
6281 obstack. */
6282
6283 struct c_arg_info *
6284 build_arg_info (void)
6285 {
6286 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info);
6287 ret->parms = NULL_TREE;
6288 ret->tags = NULL;
6289 ret->types = NULL_TREE;
6290 ret->others = NULL_TREE;
6291 ret->pending_sizes = NULL;
6292 ret->had_vla_unspec = 0;
6293 return ret;
6169 } 6294 }
6170 6295
6171 /* Take apart the current scope and return a c_arg_info structure with 6296 /* Take apart the current scope and return a c_arg_info structure with
6172 info on a parameter list just parsed. 6297 info on a parameter list just parsed.
6173 6298
6178 6303
6179 struct c_arg_info * 6304 struct c_arg_info *
6180 get_parm_info (bool ellipsis) 6305 get_parm_info (bool ellipsis)
6181 { 6306 {
6182 struct c_binding *b = current_scope->bindings; 6307 struct c_binding *b = current_scope->bindings;
6183 struct c_arg_info *arg_info = XOBNEW (&parser_obstack, 6308 struct c_arg_info *arg_info = build_arg_info ();
6184 struct c_arg_info); 6309
6185 tree parms = 0; 6310 tree parms = 0;
6186 tree tags = 0; 6311 VEC(c_arg_tag,gc) *tags = NULL;
6187 tree types = 0; 6312 tree types = 0;
6188 tree others = 0; 6313 tree others = 0;
6189 6314
6190 static bool explained_incomplete_types = false; 6315 static bool explained_incomplete_types = false;
6191 bool gave_void_only_once_err = false; 6316 bool gave_void_only_once_err = false;
6192 6317
6193 arg_info->parms = 0;
6194 arg_info->tags = 0;
6195 arg_info->types = 0;
6196 arg_info->others = 0;
6197 arg_info->pending_sizes = 0;
6198 arg_info->had_vla_unspec = current_scope->had_vla_unspec; 6318 arg_info->had_vla_unspec = current_scope->had_vla_unspec;
6199 6319
6200 /* The bindings in this scope must not get put into a block. 6320 /* The bindings in this scope must not get put into a block.
6201 We will take care of deleting the binding nodes. */ 6321 We will take care of deleting the binding nodes. */
6202 current_scope->bindings = 0; 6322 current_scope->bindings = 0;
6235 apply sanity checks; purge the name-to-decl bindings. */ 6355 apply sanity checks; purge the name-to-decl bindings. */
6236 while (b) 6356 while (b)
6237 { 6357 {
6238 tree decl = b->decl; 6358 tree decl = b->decl;
6239 tree type = TREE_TYPE (decl); 6359 tree type = TREE_TYPE (decl);
6360 c_arg_tag *tag;
6240 const char *keyword; 6361 const char *keyword;
6241 6362
6242 switch (TREE_CODE (decl)) 6363 switch (TREE_CODE (decl))
6243 { 6364 {
6244 case PARM_DECL: 6365 case PARM_DECL:
6245 if (b->id) 6366 if (b->id)
6246 { 6367 {
6247 gcc_assert (I_SYMBOL_BINDING (b->id) == b); 6368 gcc_assert (I_SYMBOL_BINDING (b->id) == b);
6248 I_SYMBOL_BINDING (b->id) = b->shadowed; 6369 I_SYMBOL_BINDING (b->id) = b->shadowed;
6249 } 6370 }
6250 6371
6251 /* Check for forward decls that never got their actual decl. */ 6372 /* Check for forward decls that never got their actual decl. */
6252 if (TREE_ASM_WRITTEN (decl)) 6373 if (TREE_ASM_WRITTEN (decl))
6253 error ("parameter %q+D has just a forward declaration", decl); 6374 error ("parameter %q+D has just a forward declaration", decl);
6254 /* Check for (..., void, ...) and issue an error. */ 6375 /* Check for (..., void, ...) and issue an error. */
6255 else if (VOID_TYPE_P (type) && !DECL_NAME (decl)) 6376 else if (VOID_TYPE_P (type) && !DECL_NAME (decl))
6256 { 6377 {
6257 if (!gave_void_only_once_err) 6378 if (!gave_void_only_once_err)
6258 { 6379 {
6259 error ("%<void%> must be the only parameter"); 6380 error ("%<void%> must be the only parameter");
6260 gave_void_only_once_err = true; 6381 gave_void_only_once_err = true;
6261 } 6382 }
6262 } 6383 }
6263 else 6384 else
6264 { 6385 {
6265 /* Valid parameter, add it to the list. */ 6386 /* Valid parameter, add it to the list. */
6266 TREE_CHAIN (decl) = parms; 6387 DECL_CHAIN (decl) = parms;
6267 parms = decl; 6388 parms = decl;
6268 6389
6269 /* Since there is a prototype, args are passed in their 6390 /* Since there is a prototype, args are passed in their
6270 declared types. The back end may override this later. */ 6391 declared types. The back end may override this later. */
6271 DECL_ARG_TYPE (decl) = type; 6392 DECL_ARG_TYPE (decl) = type;
6272 types = tree_cons (0, type, types); 6393 types = tree_cons (0, type, types);
6273 } 6394 }
6274 break; 6395 break;
6275 6396
6276 case ENUMERAL_TYPE: keyword = "enum"; goto tag; 6397 case ENUMERAL_TYPE: keyword = "enum"; goto tag;
6277 case UNION_TYPE: keyword = "union"; goto tag; 6398 case UNION_TYPE: keyword = "union"; goto tag;
6278 case RECORD_TYPE: keyword = "struct"; goto tag; 6399 case RECORD_TYPE: keyword = "struct"; goto tag;
6279 tag: 6400 tag:
6280 /* Types may not have tag-names, in which case the type 6401 /* Types may not have tag-names, in which case the type
6281 appears in the bindings list with b->id NULL. */ 6402 appears in the bindings list with b->id NULL. */
6282 if (b->id) 6403 if (b->id)
6283 { 6404 {
6284 gcc_assert (I_TAG_BINDING (b->id) == b); 6405 gcc_assert (I_TAG_BINDING (b->id) == b);
6285 I_TAG_BINDING (b->id) = b->shadowed; 6406 I_TAG_BINDING (b->id) = b->shadowed;
6286 } 6407 }
6287 6408
6288 /* Warn about any struct, union or enum tags defined in a 6409 /* Warn about any struct, union or enum tags defined in a
6289 parameter list. The scope of such types is limited to 6410 parameter list. The scope of such types is limited to
6290 the parameter list, which is rarely if ever desirable 6411 the parameter list, which is rarely if ever desirable
6291 (it's impossible to call such a function with type- 6412 (it's impossible to call such a function with type-
6292 correct arguments). An anonymous union parm type is 6413 correct arguments). An anonymous union parm type is
6293 meaningful as a GNU extension, so don't warn for that. */ 6414 meaningful as a GNU extension, so don't warn for that. */
6294 if (TREE_CODE (decl) != UNION_TYPE || b->id != 0) 6415 if (TREE_CODE (decl) != UNION_TYPE || b->id != 0)
6295 { 6416 {
6296 if (b->id) 6417 if (b->id)
6297 /* The %s will be one of 'struct', 'union', or 'enum'. */ 6418 /* The %s will be one of 'struct', 'union', or 'enum'. */
6298 warning (0, "%<%s %E%> declared inside parameter list", 6419 warning (0, "%<%s %E%> declared inside parameter list",
6299 keyword, b->id); 6420 keyword, b->id);
6300 else 6421 else
6301 /* The %s will be one of 'struct', 'union', or 'enum'. */ 6422 /* The %s will be one of 'struct', 'union', or 'enum'. */
6302 warning (0, "anonymous %s declared inside parameter list", 6423 warning (0, "anonymous %s declared inside parameter list",
6303 keyword); 6424 keyword);
6304 6425
6305 if (!explained_incomplete_types) 6426 if (!explained_incomplete_types)
6306 { 6427 {
6307 warning (0, "its scope is only this definition or declaration," 6428 warning (0, "its scope is only this definition or declaration,"
6308 " which is probably not what you want"); 6429 " which is probably not what you want");
6309 explained_incomplete_types = true; 6430 explained_incomplete_types = true;
6310 } 6431 }
6311 } 6432 }
6312 6433
6313 tags = tree_cons (b->id, decl, tags); 6434 tag = VEC_safe_push (c_arg_tag, gc, tags, NULL);
6314 break; 6435 tag->id = b->id;
6315 6436 tag->type = decl;
6316 case CONST_DECL: 6437 break;
6317 case TYPE_DECL: 6438
6318 case FUNCTION_DECL: 6439 case CONST_DECL:
6319 /* CONST_DECLs appear here when we have an embedded enum, 6440 case TYPE_DECL:
6320 and TYPE_DECLs appear here when we have an embedded struct 6441 case FUNCTION_DECL:
6321 or union. No warnings for this - we already warned about the 6442 /* CONST_DECLs appear here when we have an embedded enum,
6322 type itself. FUNCTION_DECLs appear when there is an implicit 6443 and TYPE_DECLs appear here when we have an embedded struct
6323 function declaration in the parameter list. */ 6444 or union. No warnings for this - we already warned about the
6324 6445 type itself. FUNCTION_DECLs appear when there is an implicit
6325 TREE_CHAIN (decl) = others; 6446 function declaration in the parameter list. */
6326 others = decl; 6447
6327 /* fall through */ 6448 /* When we reinsert this decl in the function body, we need
6328 6449 to reconstruct whether it was marked as nested. */
6329 case ERROR_MARK: 6450 gcc_assert (TREE_CODE (decl) == FUNCTION_DECL
6330 /* error_mark_node appears here when we have an undeclared 6451 ? b->nested
6331 variable. Just throw it away. */ 6452 : !b->nested);
6332 if (b->id) 6453 DECL_CHAIN (decl) = others;
6333 { 6454 others = decl;
6334 gcc_assert (I_SYMBOL_BINDING (b->id) == b); 6455 /* fall through */
6335 I_SYMBOL_BINDING (b->id) = b->shadowed; 6456
6336 } 6457 case ERROR_MARK:
6337 break; 6458 /* error_mark_node appears here when we have an undeclared
6338 6459 variable. Just throw it away. */
6339 /* Other things that might be encountered. */ 6460 if (b->id)
6340 case LABEL_DECL: 6461 {
6341 case VAR_DECL: 6462 gcc_assert (I_SYMBOL_BINDING (b->id) == b);
6342 default: 6463 I_SYMBOL_BINDING (b->id) = b->shadowed;
6343 gcc_unreachable (); 6464 }
6344 } 6465 break;
6466
6467 /* Other things that might be encountered. */
6468 case LABEL_DECL:
6469 case VAR_DECL:
6470 default:
6471 gcc_unreachable ();
6472 }
6345 6473
6346 b = free_binding_and_advance (b); 6474 b = free_binding_and_advance (b);
6347 } 6475 }
6348 6476
6349 arg_info->parms = parms; 6477 arg_info->parms = parms;
6556 if (declarator->kind == cdk_id && declarator->u.id == NULL_TREE 6684 if (declarator->kind == cdk_id && declarator->u.id == NULL_TREE
6557 && width == NULL_TREE) 6685 && width == NULL_TREE)
6558 { 6686 {
6559 /* This is an unnamed decl. 6687 /* This is an unnamed decl.
6560 6688
6561 If we have something of the form "union { list } ;" then this 6689 If we have something of the form "union { list } ;" then this
6562 is the anonymous union extension. Similarly for struct. 6690 is the anonymous union extension. Similarly for struct.
6563 6691
6564 If this is something of the form "struct foo;", then 6692 If this is something of the form "struct foo;", then
6565 If MS extensions are enabled, this is handled as an 6693 If MS or Plan 9 extensions are enabled, this is handled as
6566 anonymous struct. 6694 an anonymous struct.
6567 Otherwise this is a forward declaration of a structure tag. 6695 Otherwise this is a forward declaration of a structure tag.
6568 6696
6569 If this is something of the form "foo;" and foo is a TYPE_DECL, then 6697 If this is something of the form "foo;" and foo is a TYPE_DECL, then
6570 If MS extensions are enabled and foo names a structure, then 6698 If foo names a structure or union without a tag, then this
6571 again this is an anonymous struct. 6699 is an anonymous struct (this is permitted by C1X).
6572 Otherwise this is an error. 6700 If MS or Plan 9 extensions are enabled and foo names a
6573 6701 structure, then again this is an anonymous struct.
6574 Oh what a horrid tangled web we weave. I wonder if MS consciously 6702 Otherwise this is an error.
6575 took this from Plan 9 or if it was an accident of implementation 6703
6576 that took root before someone noticed the bug... */ 6704 Oh what a horrid tangled web we weave. I wonder if MS consciously
6705 took this from Plan 9 or if it was an accident of implementation
6706 that took root before someone noticed the bug... */
6577 6707
6578 tree type = declspecs->type; 6708 tree type = declspecs->type;
6579 bool type_ok = (TREE_CODE (type) == RECORD_TYPE 6709 bool type_ok = (TREE_CODE (type) == RECORD_TYPE
6580 || TREE_CODE (type) == UNION_TYPE); 6710 || TREE_CODE (type) == UNION_TYPE);
6581 bool ok = false; 6711 bool ok = false;
6582 6712
6583 if (type_ok 6713 if (type_ok)
6584 && (flag_ms_extensions || !declspecs->typedef_p)) 6714 {
6585 { 6715 if (flag_ms_extensions || flag_plan9_extensions)
6586 if (flag_ms_extensions) 6716 ok = true;
6587 ok = true; 6717 else if (TYPE_NAME (TYPE_MAIN_VARIANT (type)) == NULL)
6588 else if (flag_iso) 6718 ok = true;
6589 ok = false; 6719 else
6590 else if (TYPE_NAME (type) == NULL) 6720 ok = false;
6591 ok = true; 6721 }
6592 else 6722
6593 ok = false; 6723
6594 }
6595 if (!ok) 6724 if (!ok)
6596 { 6725 {
6597 pedwarn (loc, 0, "declaration does not declare anything"); 6726 pedwarn (loc, 0, "declaration does not declare anything");
6598 return NULL_TREE; 6727 return NULL_TREE;
6599 } 6728 }
6600 pedwarn (loc, OPT_pedantic, "ISO C doesn%'t support unnamed structs/unions"); 6729 if (!flag_isoc1x)
6730 {
6731 if (flag_isoc99)
6732 pedwarn (loc, OPT_pedantic,
6733 "ISO C99 doesn%'t support unnamed structs/unions");
6734 else
6735 pedwarn (loc, OPT_pedantic,
6736 "ISO C90 doesn%'t support unnamed structs/unions");
6737 }
6601 } 6738 }
6602 6739
6603 value = grokdeclarator (declarator, declspecs, FIELD, false, 6740 value = grokdeclarator (declarator, declspecs, FIELD, false,
6604 width ? &width : NULL, decl_attrs, NULL, NULL, 6741 width ? &width : NULL, decl_attrs, NULL, NULL,
6605 DEPRECATED_NORMAL); 6742 DEPRECATED_NORMAL);
6627 } 6764 }
6628 6765
6629 return value; 6766 return value;
6630 } 6767 }
6631 6768
6769 /* Subroutine of detect_field_duplicates: return whether X and Y,
6770 which are both fields in the same struct, have duplicate field
6771 names. */
6772
6773 static bool
6774 is_duplicate_field (tree x, tree y)
6775 {
6776 if (DECL_NAME (x) != NULL_TREE && DECL_NAME (x) == DECL_NAME (y))
6777 return true;
6778
6779 /* When using -fplan9-extensions, an anonymous field whose name is a
6780 typedef can duplicate a field name. */
6781 if (flag_plan9_extensions
6782 && (DECL_NAME (x) == NULL_TREE || DECL_NAME (y) == NULL_TREE))
6783 {
6784 tree xt, xn, yt, yn;
6785
6786 xt = TREE_TYPE (x);
6787 if (DECL_NAME (x) != NULL_TREE)
6788 xn = DECL_NAME (x);
6789 else if ((TREE_CODE (xt) == RECORD_TYPE || TREE_CODE (xt) == UNION_TYPE)
6790 && TYPE_NAME (xt) != NULL_TREE
6791 && TREE_CODE (TYPE_NAME (xt)) == TYPE_DECL)
6792 xn = DECL_NAME (TYPE_NAME (xt));
6793 else
6794 xn = NULL_TREE;
6795
6796 yt = TREE_TYPE (y);
6797 if (DECL_NAME (y) != NULL_TREE)
6798 yn = DECL_NAME (y);
6799 else if ((TREE_CODE (yt) == RECORD_TYPE || TREE_CODE (yt) == UNION_TYPE)
6800 && TYPE_NAME (yt) != NULL_TREE
6801 && TREE_CODE (TYPE_NAME (yt)) == TYPE_DECL)
6802 yn = DECL_NAME (TYPE_NAME (yt));
6803 else
6804 yn = NULL_TREE;
6805
6806 if (xn != NULL_TREE && xn == yn)
6807 return true;
6808 }
6809
6810 return false;
6811 }
6812
6813 /* Subroutine of detect_field_duplicates: add the fields of FIELDLIST
6814 to HTAB, giving errors for any duplicates. */
6815
6816 static void
6817 detect_field_duplicates_hash (tree fieldlist, htab_t htab)
6818 {
6819 tree x, y;
6820 void **slot;
6821
6822 for (x = fieldlist; x ; x = DECL_CHAIN (x))
6823 if ((y = DECL_NAME (x)) != 0)
6824 {
6825 slot = htab_find_slot (htab, y, INSERT);
6826 if (*slot)
6827 {
6828 error ("duplicate member %q+D", x);
6829 DECL_NAME (x) = NULL_TREE;
6830 }
6831 *slot = y;
6832 }
6833 else if (TREE_CODE (TREE_TYPE (x)) == RECORD_TYPE
6834 || TREE_CODE (TREE_TYPE (x)) == UNION_TYPE)
6835 {
6836 detect_field_duplicates_hash (TYPE_FIELDS (TREE_TYPE (x)), htab);
6837
6838 /* When using -fplan9-extensions, an anonymous field whose
6839 name is a typedef can duplicate a field name. */
6840 if (flag_plan9_extensions
6841 && TYPE_NAME (TREE_TYPE (x)) != NULL_TREE
6842 && TREE_CODE (TYPE_NAME (TREE_TYPE (x))) == TYPE_DECL)
6843 {
6844 tree xn = DECL_NAME (TYPE_NAME (TREE_TYPE (x)));
6845 slot = htab_find_slot (htab, xn, INSERT);
6846 if (*slot)
6847 error ("duplicate member %q+D", TYPE_NAME (TREE_TYPE (x)));
6848 *slot = xn;
6849 }
6850 }
6851 }
6852
6632 /* Generate an error for any duplicate field names in FIELDLIST. Munge 6853 /* Generate an error for any duplicate field names in FIELDLIST. Munge
6633 the list such that this does not present a problem later. */ 6854 the list such that this does not present a problem later. */
6634 6855
6635 static void 6856 static void
6636 detect_field_duplicates (tree fieldlist) 6857 detect_field_duplicates (tree fieldlist)
6637 { 6858 {
6638 tree x, y; 6859 tree x, y;
6639 int timeout = 10; 6860 int timeout = 10;
6640 6861
6862 /* If the struct is the list of instance variables of an Objective-C
6863 class, then we need to add all the instance variables of
6864 superclasses before checking for duplicates (since you can't have
6865 an instance variable in a subclass with the same name as an
6866 instance variable in a superclass). objc_get_interface_ivars()
6867 leaves fieldlist unchanged if we are not in this case, so in that
6868 case nothing changes compared to C.
6869 */
6870 if (c_dialect_objc ())
6871 fieldlist = objc_get_interface_ivars (fieldlist);
6872
6641 /* First, see if there are more than "a few" fields. 6873 /* First, see if there are more than "a few" fields.
6642 This is trivially true if there are zero or one fields. */ 6874 This is trivially true if there are zero or one fields. */
6643 if (!fieldlist) 6875 if (!fieldlist || !DECL_CHAIN (fieldlist))
6644 return; 6876 return;
6645 x = TREE_CHAIN (fieldlist); 6877 x = fieldlist;
6646 if (!x)
6647 return;
6648 do { 6878 do {
6649 timeout--; 6879 timeout--;
6650 x = TREE_CHAIN (x); 6880 if (DECL_NAME (x) == NULL_TREE
6881 && (TREE_CODE (TREE_TYPE (x)) == RECORD_TYPE
6882 || TREE_CODE (TREE_TYPE (x)) == UNION_TYPE))
6883 timeout = 0;
6884 x = DECL_CHAIN (x);
6651 } while (timeout > 0 && x); 6885 } while (timeout > 0 && x);
6652 6886
6653 /* If there were "few" fields, avoid the overhead of allocating 6887 /* If there were "few" fields and no anonymous structures or unions,
6654 a hash table. Instead just do the nested traversal thing. */ 6888 avoid the overhead of allocating a hash table. Instead just do
6889 the nested traversal thing. */
6655 if (timeout > 0) 6890 if (timeout > 0)
6656 { 6891 {
6657 for (x = TREE_CHAIN (fieldlist); x ; x = TREE_CHAIN (x)) 6892 for (x = DECL_CHAIN (fieldlist); x; x = DECL_CHAIN (x))
6658 if (DECL_NAME (x)) 6893 /* When using -fplan9-extensions, we can have duplicates
6659 { 6894 between typedef names and fields. */
6660 for (y = fieldlist; y != x; y = TREE_CHAIN (y)) 6895 if (DECL_NAME (x)
6661 if (DECL_NAME (y) == DECL_NAME (x)) 6896 || (flag_plan9_extensions
6662 { 6897 && DECL_NAME (x) == NULL_TREE
6663 error ("duplicate member %q+D", x); 6898 && (TREE_CODE (TREE_TYPE (x)) == RECORD_TYPE
6664 DECL_NAME (x) = NULL_TREE; 6899 || TREE_CODE (TREE_TYPE (x)) == UNION_TYPE)
6665 } 6900 && TYPE_NAME (TREE_TYPE (x)) != NULL_TREE
6666 } 6901 && TREE_CODE (TYPE_NAME (TREE_TYPE (x))) == TYPE_DECL))
6902 {
6903 for (y = fieldlist; y != x; y = TREE_CHAIN (y))
6904 if (is_duplicate_field (y, x))
6905 {
6906 error ("duplicate member %q+D", x);
6907 DECL_NAME (x) = NULL_TREE;
6908 }
6909 }
6667 } 6910 }
6668 else 6911 else
6669 { 6912 {
6670 htab_t htab = htab_create (37, htab_hash_pointer, htab_eq_pointer, NULL); 6913 htab_t htab = htab_create (37, htab_hash_pointer, htab_eq_pointer, NULL);
6671 void **slot; 6914
6672 6915 detect_field_duplicates_hash (fieldlist, htab);
6673 for (x = fieldlist; x ; x = TREE_CHAIN (x))
6674 if ((y = DECL_NAME (x)) != 0)
6675 {
6676 slot = htab_find_slot (htab, y, INSERT);
6677 if (*slot)
6678 {
6679 error ("duplicate member %q+D", x);
6680 DECL_NAME (x) = NULL_TREE;
6681 }
6682 *slot = y;
6683 }
6684
6685 htab_delete (htab); 6916 htab_delete (htab);
6686 } 6917 }
6687 } 6918 }
6688 6919
6689 /* Finish up struct info used by -Wc++-compat. */ 6920 /* Finish up struct info used by -Wc++-compat. */
6698 /* Set the C_TYPE_DEFINED_IN_STRUCT flag for each type defined in 6929 /* Set the C_TYPE_DEFINED_IN_STRUCT flag for each type defined in
6699 the current struct. We do this now at the end of the struct 6930 the current struct. We do this now at the end of the struct
6700 because the flag is used to issue visibility warnings, and we 6931 because the flag is used to issue visibility warnings, and we
6701 only want to issue those warnings if the type is referenced 6932 only want to issue those warnings if the type is referenced
6702 outside of the struct declaration. */ 6933 outside of the struct declaration. */
6703 for (ix = 0; VEC_iterate (tree, struct_parse_info->struct_types, ix, x); ++ix) 6934 FOR_EACH_VEC_ELT (tree, struct_parse_info->struct_types, ix, x)
6704 C_TYPE_DEFINED_IN_STRUCT (x) = 1; 6935 C_TYPE_DEFINED_IN_STRUCT (x) = 1;
6705 6936
6706 /* The TYPEDEFS_SEEN field of STRUCT_PARSE_INFO is a list of 6937 /* The TYPEDEFS_SEEN field of STRUCT_PARSE_INFO is a list of
6707 typedefs used when declaring fields in this struct. If the name 6938 typedefs used when declaring fields in this struct. If the name
6708 of any of the fields is also a typedef name then the struct would 6939 of any of the fields is also a typedef name then the struct would
6714 { 6945 {
6715 /* Use a pointer_set using the name of the typedef. We can use 6946 /* Use a pointer_set using the name of the typedef. We can use
6716 a pointer_set because identifiers are interned. */ 6947 a pointer_set because identifiers are interned. */
6717 struct pointer_set_t *tset = pointer_set_create (); 6948 struct pointer_set_t *tset = pointer_set_create ();
6718 6949
6719 for (ix = 0; 6950 FOR_EACH_VEC_ELT (tree, struct_parse_info->typedefs_seen, ix, x)
6720 VEC_iterate (tree, struct_parse_info->typedefs_seen, ix, x); 6951 pointer_set_insert (tset, DECL_NAME (x));
6721 ++ix) 6952
6722 pointer_set_insert (tset, DECL_NAME (x)); 6953 for (x = fieldlist; x != NULL_TREE; x = DECL_CHAIN (x))
6723 6954 {
6724 for (x = fieldlist; x != NULL_TREE; x = TREE_CHAIN (x)) 6955 if (DECL_NAME (x) != NULL_TREE
6725 { 6956 && pointer_set_contains (tset, DECL_NAME (x)))
6726 if (pointer_set_contains (tset, DECL_NAME (x))) 6957 {
6727 { 6958 warning_at (DECL_SOURCE_LOCATION (x), OPT_Wc___compat,
6728 warning_at (DECL_SOURCE_LOCATION (x), OPT_Wc___compat, 6959 ("using %qD as both field and typedef name is "
6729 ("using %qD as both field and typedef name is " 6960 "invalid in C++"),
6730 "invalid in C++"), 6961 x);
6731 x); 6962 /* FIXME: It would be nice to report the location where
6732 /* FIXME: It would be nice to report the location where 6963 the typedef name is used. */
6733 the typedef name is used. */ 6964 }
6734 } 6965 }
6735 }
6736
6737 pointer_set_destroy (tset); 6966 pointer_set_destroy (tset);
6738 } 6967 }
6739 6968
6740 /* For each field which has a binding and which was not defined in 6969 /* For each field which has a binding and which was not defined in
6741 an enclosing struct, clear the in_struct field. */ 6970 an enclosing struct, clear the in_struct field. */
6742 for (ix = 0; 6971 FOR_EACH_VEC_ELT (c_binding_ptr, struct_parse_info->fields, ix, b)
6743 VEC_iterate (c_binding_ptr, struct_parse_info->fields, ix, b);
6744 ++ix)
6745 b->in_struct = 0; 6972 b->in_struct = 0;
6746 } 6973 }
6747 6974
6748 /* Fill in the fields of a RECORD_TYPE or UNION_TYPE node, T. 6975 /* Fill in the fields of a RECORD_TYPE or UNION_TYPE node, T.
6749 LOC is the location of the RECORD_TYPE or UNION_TYPE's definition. 6976 LOC is the location of the RECORD_TYPE or UNION_TYPE's definition.
6768 6995
6769 decl_attributes (&t, attributes, (int) ATTR_FLAG_TYPE_IN_PLACE); 6996 decl_attributes (&t, attributes, (int) ATTR_FLAG_TYPE_IN_PLACE);
6770 6997
6771 if (pedantic) 6998 if (pedantic)
6772 { 6999 {
6773 for (x = fieldlist; x; x = TREE_CHAIN (x)) 7000 for (x = fieldlist; x; x = DECL_CHAIN (x))
6774 if (DECL_NAME (x) != 0) 7001 {
6775 break; 7002 if (DECL_NAME (x) != 0)
7003 break;
7004 if (flag_isoc1x
7005 && (TREE_CODE (TREE_TYPE (x)) == RECORD_TYPE
7006 || TREE_CODE (TREE_TYPE (x)) == UNION_TYPE))
7007 break;
7008 }
6776 7009
6777 if (x == 0) 7010 if (x == 0)
6778 { 7011 {
6779 if (TREE_CODE (t) == UNION_TYPE) 7012 if (TREE_CODE (t) == UNION_TYPE)
6780 { 7013 {
6799 to its width, rather than the precision of the specified standard 7032 to its width, rather than the precision of the specified standard
6800 type. (Correct layout requires the original type to have been preserved 7033 type. (Correct layout requires the original type to have been preserved
6801 until now.) */ 7034 until now.) */
6802 7035
6803 saw_named_field = 0; 7036 saw_named_field = 0;
6804 for (x = fieldlist; x; x = TREE_CHAIN (x)) 7037 for (x = fieldlist; x; x = DECL_CHAIN (x))
6805 { 7038 {
6806 if (TREE_TYPE (x) == error_mark_node) 7039 if (TREE_TYPE (x) == error_mark_node)
6807 continue; 7040 continue;
6808 7041
6809 DECL_CONTEXT (x) = t; 7042 DECL_CONTEXT (x) = t;
6810 7043
6811 /* If any field is const, the structure type is pseudo-const. */ 7044 /* If any field is const, the structure type is pseudo-const. */
6812 if (TREE_READONLY (x)) 7045 if (TREE_READONLY (x))
6813 C_TYPE_FIELDS_READONLY (t) = 1; 7046 C_TYPE_FIELDS_READONLY (t) = 1;
6814 else 7047 else
6815 { 7048 {
6816 /* A field that is pseudo-const makes the structure likewise. */ 7049 /* A field that is pseudo-const makes the structure likewise. */
6817 tree t1 = TREE_TYPE (x); 7050 tree t1 = strip_array_types (TREE_TYPE (x));
6818 while (TREE_CODE (t1) == ARRAY_TYPE) 7051 if ((TREE_CODE (t1) == RECORD_TYPE || TREE_CODE (t1) == UNION_TYPE)
6819 t1 = TREE_TYPE (t1); 7052 && C_TYPE_FIELDS_READONLY (t1))
6820 if ((TREE_CODE (t1) == RECORD_TYPE || TREE_CODE (t1) == UNION_TYPE) 7053 C_TYPE_FIELDS_READONLY (t) = 1;
6821 && C_TYPE_FIELDS_READONLY (t1)) 7054 }
6822 C_TYPE_FIELDS_READONLY (t) = 1;
6823 }
6824 7055
6825 /* Any field that is volatile means variables of this type must be 7056 /* Any field that is volatile means variables of this type must be
6826 treated in some ways as volatile. */ 7057 treated in some ways as volatile. */
6827 if (TREE_THIS_VOLATILE (x)) 7058 if (TREE_THIS_VOLATILE (x))
6828 C_TYPE_FIELDS_VOLATILE (t) = 1; 7059 C_TYPE_FIELDS_VOLATILE (t) = 1;
6844 || TYPE_ALIGN (TREE_TYPE (x)) > BITS_PER_UNIT)) 7075 || TYPE_ALIGN (TREE_TYPE (x)) > BITS_PER_UNIT))
6845 DECL_PACKED (x) = 1; 7076 DECL_PACKED (x) = 1;
6846 7077
6847 /* Detect flexible array member in an invalid context. */ 7078 /* Detect flexible array member in an invalid context. */
6848 if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE 7079 if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE
6849 && TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE 7080 && TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE
6850 && TYPE_DOMAIN (TREE_TYPE (x)) != NULL_TREE 7081 && TYPE_DOMAIN (TREE_TYPE (x)) != NULL_TREE
6851 && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (x))) == NULL_TREE) 7082 && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (x))) == NULL_TREE)
6852 { 7083 {
6853 if (TREE_CODE (t) == UNION_TYPE) 7084 if (TREE_CODE (t) == UNION_TYPE)
6854 { 7085 {
6855 error_at (DECL_SOURCE_LOCATION (x), 7086 error_at (DECL_SOURCE_LOCATION (x),
6856 "flexible array member in union"); 7087 "flexible array member in union");
6857 TREE_TYPE (x) = error_mark_node; 7088 TREE_TYPE (x) = error_mark_node;
6858 } 7089 }
6859 else if (TREE_CHAIN (x) != NULL_TREE) 7090 else if (DECL_CHAIN (x) != NULL_TREE)
6860 { 7091 {
6861 error_at (DECL_SOURCE_LOCATION (x), 7092 error_at (DECL_SOURCE_LOCATION (x),
6862 "flexible array member not at end of struct"); 7093 "flexible array member not at end of struct");
6863 TREE_TYPE (x) = error_mark_node; 7094 TREE_TYPE (x) = error_mark_node;
6864 } 7095 }
6865 else if (!saw_named_field) 7096 else if (!saw_named_field)
6866 { 7097 {
6867 error_at (DECL_SOURCE_LOCATION (x), 7098 error_at (DECL_SOURCE_LOCATION (x),
6868 "flexible array member in otherwise empty struct"); 7099 "flexible array member in otherwise empty struct");
6869 TREE_TYPE (x) = error_mark_node; 7100 TREE_TYPE (x) = error_mark_node;
6870 } 7101 }
6871 } 7102 }
6872 7103
6873 if (pedantic && TREE_CODE (t) == RECORD_TYPE 7104 if (pedantic && TREE_CODE (t) == RECORD_TYPE
6874 && flexible_array_type_p (TREE_TYPE (x))) 7105 && flexible_array_type_p (TREE_TYPE (x)))
6875 pedwarn (DECL_SOURCE_LOCATION (x), OPT_pedantic, 7106 pedwarn (DECL_SOURCE_LOCATION (x), OPT_pedantic,
6876 "invalid use of structure with flexible array member"); 7107 "invalid use of structure with flexible array member");
6877 7108
6878 if (DECL_NAME (x)) 7109 if (DECL_NAME (x)
6879 saw_named_field = 1; 7110 || TREE_CODE (TREE_TYPE (x)) == RECORD_TYPE
7111 || TREE_CODE (TREE_TYPE (x)) == UNION_TYPE)
7112 saw_named_field = 1;
6880 } 7113 }
6881 7114
6882 detect_field_duplicates (fieldlist); 7115 detect_field_duplicates (fieldlist);
6883 7116
6884 /* Now we have the nearly final fieldlist. Record it, 7117 /* Now we have the nearly final fieldlist. Record it,
6905 DECL_MODE (*fieldlistp) = TYPE_MODE (TREE_TYPE (*fieldlistp)); 7138 DECL_MODE (*fieldlistp) = TYPE_MODE (TREE_TYPE (*fieldlistp));
6906 } 7139 }
6907 DECL_INITIAL (*fieldlistp) = 0; 7140 DECL_INITIAL (*fieldlistp) = 0;
6908 } 7141 }
6909 else 7142 else
6910 fieldlistp = &TREE_CHAIN (*fieldlistp); 7143 fieldlistp = &DECL_CHAIN (*fieldlistp);
6911 } 7144 }
6912 7145
6913 /* Now we have the truly final field list. 7146 /* Now we have the truly final field list.
6914 Store it in this type and in the variants. */ 7147 Store it in this type and in the variants. */
6915 7148
6919 We arbitrarily consider 16 or more elts to be "a lot". */ 7152 We arbitrarily consider 16 or more elts to be "a lot". */
6920 7153
6921 { 7154 {
6922 int len = 0; 7155 int len = 0;
6923 7156
6924 for (x = fieldlist; x; x = TREE_CHAIN (x)) 7157 for (x = fieldlist; x; x = DECL_CHAIN (x))
6925 { 7158 {
6926 if (len > 15 || DECL_NAME (x) == NULL) 7159 if (len > 15 || DECL_NAME (x) == NULL)
6927 break; 7160 break;
6928 len += 1; 7161 len += 1;
6929 } 7162 }
6930 7163
6931 if (len > 15) 7164 if (len > 15)
6932 { 7165 {
6933 tree *field_array; 7166 tree *field_array;
6934 struct lang_type *space; 7167 struct lang_type *space;
6935 struct sorted_fields_type *space2; 7168 struct sorted_fields_type *space2;
6936 7169
6937 len += list_length (x); 7170 len += list_length (x);
6938 7171
6939 /* Use the same allocation policy here that make_node uses, to 7172 /* Use the same allocation policy here that make_node uses, to
6940 ensure that this lives as long as the rest of the struct decl. 7173 ensure that this lives as long as the rest of the struct decl.
6941 All decls in an inline function need to be saved. */ 7174 All decls in an inline function need to be saved. */
6942 7175
6943 space = GGC_CNEW (struct lang_type); 7176 space = ggc_alloc_cleared_lang_type (sizeof (struct lang_type));
6944 space2 = GGC_NEWVAR (struct sorted_fields_type, 7177 space2 = ggc_alloc_sorted_fields_type
6945 sizeof (struct sorted_fields_type) + len * sizeof (tree)); 7178 (sizeof (struct sorted_fields_type) + len * sizeof (tree));
6946 7179
6947 len = 0; 7180 len = 0;
6948 space->s = space2; 7181 space->s = space2;
6949 field_array = &space2->elts[0]; 7182 field_array = &space2->elts[0];
6950 for (x = fieldlist; x; x = TREE_CHAIN (x)) 7183 for (x = fieldlist; x; x = DECL_CHAIN (x))
6951 { 7184 {
6952 field_array[len++] = x; 7185 field_array[len++] = x;
6953 7186
6954 /* If there is anonymous struct or union, break out of the loop. */ 7187 /* If there is anonymous struct or union, break out of the loop. */
6955 if (DECL_NAME (x) == NULL) 7188 if (DECL_NAME (x) == NULL)
6956 break; 7189 break;
6957 } 7190 }
6958 /* Found no anonymous struct/union. Add the TYPE_LANG_SPECIFIC. */ 7191 /* Found no anonymous struct/union. Add the TYPE_LANG_SPECIFIC. */
6959 if (x == NULL) 7192 if (x == NULL)
6960 { 7193 {
6961 TYPE_LANG_SPECIFIC (t) = space; 7194 TYPE_LANG_SPECIFIC (t) = space;
6962 TYPE_LANG_SPECIFIC (t)->s->len = len; 7195 TYPE_LANG_SPECIFIC (t)->s->len = len;
6963 field_array = TYPE_LANG_SPECIFIC (t)->s->elts; 7196 field_array = TYPE_LANG_SPECIFIC (t)->s->elts;
6964 qsort (field_array, len, sizeof (tree), field_decl_cmp); 7197 qsort (field_array, len, sizeof (tree), field_decl_cmp);
6965 } 7198 }
6966 } 7199 }
6967 } 7200 }
6968 7201
6969 for (x = TYPE_MAIN_VARIANT (t); x; x = TYPE_NEXT_VARIANT (x)) 7202 for (x = TYPE_MAIN_VARIANT (t); x; x = TYPE_NEXT_VARIANT (x))
6970 { 7203 {
6976 } 7209 }
6977 7210
6978 /* If this was supposed to be a transparent union, but we can't 7211 /* If this was supposed to be a transparent union, but we can't
6979 make it one, warn and turn off the flag. */ 7212 make it one, warn and turn off the flag. */
6980 if (TREE_CODE (t) == UNION_TYPE 7213 if (TREE_CODE (t) == UNION_TYPE
6981 && TYPE_TRANSPARENT_UNION (t) 7214 && TYPE_TRANSPARENT_AGGR (t)
6982 && (!TYPE_FIELDS (t) || TYPE_MODE (t) != DECL_MODE (TYPE_FIELDS (t)))) 7215 && (!TYPE_FIELDS (t) || TYPE_MODE (t) != DECL_MODE (TYPE_FIELDS (t))))
6983 { 7216 {
6984 TYPE_TRANSPARENT_UNION (t) = 0; 7217 TYPE_TRANSPARENT_AGGR (t) = 0;
6985 warning_at (loc, 0, "union cannot be made transparent"); 7218 warning_at (loc, 0, "union cannot be made transparent");
6986 } 7219 }
6987 7220
6988 /* If this structure or union completes the type of any previous 7221 /* If this structure or union completes the type of any previous
6989 variable declaration, lay it out and output its rtl. */ 7222 variable declaration, lay it out and output its rtl. */
7221 TYPE_VALUES (enumtype) = values; 7454 TYPE_VALUES (enumtype) = values;
7222 } 7455 }
7223 7456
7224 /* Record the min/max values so that we can warn about bit-field 7457 /* Record the min/max values so that we can warn about bit-field
7225 enumerations that are too small for the values. */ 7458 enumerations that are too small for the values. */
7226 lt = GGC_CNEW (struct lang_type); 7459 lt = ggc_alloc_cleared_lang_type (sizeof (struct lang_type));
7227 lt->enum_min = minnode; 7460 lt->enum_min = minnode;
7228 lt->enum_max = maxnode; 7461 lt->enum_max = maxnode;
7229 TYPE_LANG_SPECIFIC (enumtype) = lt; 7462 TYPE_LANG_SPECIFIC (enumtype) = lt;
7230 7463
7231 /* Fix up all variant types of this enum type. */ 7464 /* Fix up all variant types of this enum type. */
7259 return enumtype; 7492 return enumtype;
7260 } 7493 }
7261 7494
7262 /* Build and install a CONST_DECL for one value of the 7495 /* Build and install a CONST_DECL for one value of the
7263 current enumeration type (one that was begun with start_enum). 7496 current enumeration type (one that was begun with start_enum).
7264 LOC is the location of the enumerator. 7497 DECL_LOC is the location of the enumerator.
7498 LOC is the location of the '=' operator if any, DECL_LOC otherwise.
7265 Return a tree-list containing the CONST_DECL and its value. 7499 Return a tree-list containing the CONST_DECL and its value.
7266 Assignment of sequential values by default is handled here. */ 7500 Assignment of sequential values by default is handled here. */
7267 7501
7268 tree 7502 tree
7269 build_enumerator (location_t loc, 7503 build_enumerator (location_t decl_loc, location_t loc,
7270 struct c_enum_contents *the_enum, tree name, tree value) 7504 struct c_enum_contents *the_enum, tree name, tree value)
7271 { 7505 {
7272 tree decl, type; 7506 tree decl, type;
7273 7507
7274 /* Validate and default VALUE. */ 7508 /* Validate and default VALUE. */
7275 7509
7338 if (int_fits_type_p (value, integer_type_node)) 7572 if (int_fits_type_p (value, integer_type_node))
7339 value = convert (integer_type_node, value); 7573 value = convert (integer_type_node, value);
7340 7574
7341 /* Set basis for default for next value. */ 7575 /* Set basis for default for next value. */
7342 the_enum->enum_next_value 7576 the_enum->enum_next_value
7343 = build_binary_op 7577 = build_binary_op (EXPR_LOC_OR_HERE (value),
7344 (EXPR_HAS_LOCATION (value) ? EXPR_LOCATION (value) : input_location, 7578 PLUS_EXPR, value, integer_one_node, 0);
7345 PLUS_EXPR, value, integer_one_node, 0);
7346 the_enum->enum_overflow = tree_int_cst_lt (the_enum->enum_next_value, value); 7579 the_enum->enum_overflow = tree_int_cst_lt (the_enum->enum_next_value, value);
7347 7580
7348 /* Now create a declaration for the enum value name. */ 7581 /* Now create a declaration for the enum value name. */
7349 7582
7350 type = TREE_TYPE (value); 7583 type = TREE_TYPE (value);
7352 TYPE_PRECISION (integer_type_node)), 7585 TYPE_PRECISION (integer_type_node)),
7353 (TYPE_PRECISION (type) 7586 (TYPE_PRECISION (type)
7354 >= TYPE_PRECISION (integer_type_node) 7587 >= TYPE_PRECISION (integer_type_node)
7355 && TYPE_UNSIGNED (type))); 7588 && TYPE_UNSIGNED (type)));
7356 7589
7357 decl = build_decl (loc, CONST_DECL, name, type); 7590 decl = build_decl (decl_loc, CONST_DECL, name, type);
7358 DECL_INITIAL (decl) = convert (type, value); 7591 DECL_INITIAL (decl) = convert (type, value);
7359 pushdecl (decl); 7592 pushdecl (decl);
7360 7593
7361 return tree_cons (decl, value, NULL_TREE); 7594 return tree_cons (decl, value, NULL_TREE);
7362 } 7595 }
7513 7746
7514 /* Make the init_value nonzero so pushdecl knows this is not tentative. 7747 /* Make the init_value nonzero so pushdecl knows this is not tentative.
7515 error_mark_node is replaced below (in pop_scope) with the BLOCK. */ 7748 error_mark_node is replaced below (in pop_scope) with the BLOCK. */
7516 DECL_INITIAL (decl1) = error_mark_node; 7749 DECL_INITIAL (decl1) = error_mark_node;
7517 7750
7751 /* A nested function is not global. */
7752 if (current_function_decl != 0)
7753 TREE_PUBLIC (decl1) = 0;
7754
7518 /* If this definition isn't a prototype and we had a prototype declaration 7755 /* If this definition isn't a prototype and we had a prototype declaration
7519 before, copy the arg type info from that prototype. */ 7756 before, copy the arg type info from that prototype. */
7520 old_decl = lookup_name_in_scope (DECL_NAME (decl1), current_scope); 7757 old_decl = lookup_name_in_scope (DECL_NAME (decl1), current_scope);
7521 if (old_decl && TREE_CODE (old_decl) != FUNCTION_DECL) 7758 if (old_decl && TREE_CODE (old_decl) != FUNCTION_DECL)
7522 old_decl = 0; 7759 old_decl = 0;
7523 current_function_prototype_locus = UNKNOWN_LOCATION; 7760 current_function_prototype_locus = UNKNOWN_LOCATION;
7524 current_function_prototype_built_in = false; 7761 current_function_prototype_built_in = false;
7525 current_function_prototype_arg_types = NULL_TREE; 7762 current_function_prototype_arg_types = NULL_TREE;
7526 if (TYPE_ARG_TYPES (TREE_TYPE (decl1)) == 0) 7763 if (!prototype_p (TREE_TYPE (decl1)))
7527 { 7764 {
7528 if (old_decl != 0 && TREE_CODE (TREE_TYPE (old_decl)) == FUNCTION_TYPE 7765 if (old_decl != 0 && TREE_CODE (TREE_TYPE (old_decl)) == FUNCTION_TYPE
7529 && comptypes (TREE_TYPE (TREE_TYPE (decl1)), 7766 && comptypes (TREE_TYPE (TREE_TYPE (decl1)),
7530 TREE_TYPE (TREE_TYPE (old_decl)))) 7767 TREE_TYPE (TREE_TYPE (old_decl))))
7531 { 7768 {
7570 } 7807 }
7571 7808
7572 /* Optionally warn of old-fashioned def with no previous prototype. */ 7809 /* Optionally warn of old-fashioned def with no previous prototype. */
7573 if (warn_strict_prototypes 7810 if (warn_strict_prototypes
7574 && old_decl != error_mark_node 7811 && old_decl != error_mark_node
7575 && TYPE_ARG_TYPES (TREE_TYPE (decl1)) == 0 7812 && !prototype_p (TREE_TYPE (decl1))
7576 && C_DECL_ISNT_PROTOTYPE (old_decl)) 7813 && C_DECL_ISNT_PROTOTYPE (old_decl))
7577 warning_at (loc, OPT_Wstrict_prototypes, 7814 warning_at (loc, OPT_Wstrict_prototypes,
7578 "function declaration isn%'t a prototype"); 7815 "function declaration isn%'t a prototype");
7579 /* Optionally warn of any global def with no previous prototype. */ 7816 /* Optionally warn of any global def with no previous prototype. */
7580 else if (warn_missing_prototypes 7817 else if (warn_missing_prototypes
7585 warning_at (loc, OPT_Wmissing_prototypes, 7822 warning_at (loc, OPT_Wmissing_prototypes,
7586 "no previous prototype for %qD", decl1); 7823 "no previous prototype for %qD", decl1);
7587 /* Optionally warn of any def with no previous prototype 7824 /* Optionally warn of any def with no previous prototype
7588 if the function has already been used. */ 7825 if the function has already been used. */
7589 else if (warn_missing_prototypes 7826 else if (warn_missing_prototypes
7590 && old_decl != 0 7827 && old_decl != 0
7591 && old_decl != error_mark_node 7828 && old_decl != error_mark_node
7592 && TREE_USED (old_decl) 7829 && TREE_USED (old_decl)
7593 && TYPE_ARG_TYPES (TREE_TYPE (old_decl)) == 0) 7830 && !prototype_p (TREE_TYPE (old_decl)))
7594 warning_at (loc, OPT_Wmissing_prototypes, 7831 warning_at (loc, OPT_Wmissing_prototypes,
7595 "%qD was used with no prototype before its definition", decl1); 7832 "%qD was used with no prototype before its definition", decl1);
7596 /* Optionally warn of any global def with no previous declaration. */ 7833 /* Optionally warn of any global def with no previous declaration. */
7597 else if (warn_missing_declarations 7834 else if (warn_missing_declarations
7598 && TREE_PUBLIC (decl1) 7835 && TREE_PUBLIC (decl1)
7613 7850
7614 /* This function exists in static storage. 7851 /* This function exists in static storage.
7615 (This does not mean `static' in the C sense!) */ 7852 (This does not mean `static' in the C sense!) */
7616 TREE_STATIC (decl1) = 1; 7853 TREE_STATIC (decl1) = 1;
7617 7854
7618 /* A nested function is not global. */
7619 if (current_function_decl != 0)
7620 TREE_PUBLIC (decl1) = 0;
7621
7622 /* This is the earliest point at which we might know the assembler 7855 /* This is the earliest point at which we might know the assembler
7623 name of the function. Thus, if it's set before this, die horribly. */ 7856 name of the function. Thus, if it's set before this, die horribly. */
7624 gcc_assert (!DECL_ASSEMBLER_NAME_SET_P (decl1)); 7857 gcc_assert (!DECL_ASSEMBLER_NAME_SET_P (decl1));
7625 7858
7626 /* If #pragma weak was used, mark the decl weak now. */ 7859 /* If #pragma weak was used, mark the decl weak now. */
7667 old-style parm decls were written. */ 7900 old-style parm decls were written. */
7668 static void 7901 static void
7669 store_parm_decls_newstyle (tree fndecl, const struct c_arg_info *arg_info) 7902 store_parm_decls_newstyle (tree fndecl, const struct c_arg_info *arg_info)
7670 { 7903 {
7671 tree decl; 7904 tree decl;
7905 c_arg_tag *tag;
7906 unsigned ix;
7672 7907
7673 if (current_scope->bindings) 7908 if (current_scope->bindings)
7674 { 7909 {
7675 error_at (DECL_SOURCE_LOCATION (fndecl), 7910 error_at (DECL_SOURCE_LOCATION (fndecl),
7676 "old-style parameter declarations in prototyped " 7911 "old-style parameter declarations in prototyped "
7689 warning_at (DECL_SOURCE_LOCATION (fndecl), OPT_Wtraditional, 7924 warning_at (DECL_SOURCE_LOCATION (fndecl), OPT_Wtraditional,
7690 "traditional C rejects ISO C style function definitions"); 7925 "traditional C rejects ISO C style function definitions");
7691 7926
7692 /* Now make all the parameter declarations visible in the function body. 7927 /* Now make all the parameter declarations visible in the function body.
7693 We can bypass most of the grunt work of pushdecl. */ 7928 We can bypass most of the grunt work of pushdecl. */
7694 for (decl = arg_info->parms; decl; decl = TREE_CHAIN (decl)) 7929 for (decl = arg_info->parms; decl; decl = DECL_CHAIN (decl))
7695 { 7930 {
7696 DECL_CONTEXT (decl) = current_function_decl; 7931 DECL_CONTEXT (decl) = current_function_decl;
7697 if (DECL_NAME (decl)) 7932 if (DECL_NAME (decl))
7698 { 7933 {
7699 bind (DECL_NAME (decl), decl, current_scope, 7934 bind (DECL_NAME (decl), decl, current_scope,
7708 7943
7709 /* Record the parameter list in the function declaration. */ 7944 /* Record the parameter list in the function declaration. */
7710 DECL_ARGUMENTS (fndecl) = arg_info->parms; 7945 DECL_ARGUMENTS (fndecl) = arg_info->parms;
7711 7946
7712 /* Now make all the ancillary declarations visible, likewise. */ 7947 /* Now make all the ancillary declarations visible, likewise. */
7713 for (decl = arg_info->others; decl; decl = TREE_CHAIN (decl)) 7948 for (decl = arg_info->others; decl; decl = DECL_CHAIN (decl))
7714 { 7949 {
7715 DECL_CONTEXT (decl) = current_function_decl; 7950 DECL_CONTEXT (decl) = current_function_decl;
7716 if (DECL_NAME (decl)) 7951 if (DECL_NAME (decl))
7717 bind (DECL_NAME (decl), decl, current_scope, 7952 bind (DECL_NAME (decl), decl, current_scope,
7718 /*invisible=*/false, /*nested=*/false, UNKNOWN_LOCATION); 7953 /*invisible=*/false,
7954 /*nested=*/(TREE_CODE (decl) == FUNCTION_DECL),
7955 UNKNOWN_LOCATION);
7719 } 7956 }
7720 7957
7721 /* And all the tag declarations. */ 7958 /* And all the tag declarations. */
7722 for (decl = arg_info->tags; decl; decl = TREE_CHAIN (decl)) 7959 FOR_EACH_VEC_ELT_REVERSE (c_arg_tag, arg_info->tags, ix, tag)
7723 if (TREE_PURPOSE (decl)) 7960 if (tag->id)
7724 bind (TREE_PURPOSE (decl), TREE_VALUE (decl), current_scope, 7961 bind (tag->id, tag->type, current_scope,
7725 /*invisible=*/false, /*nested=*/false, UNKNOWN_LOCATION); 7962 /*invisible=*/false, /*nested=*/false, UNKNOWN_LOCATION);
7726 } 7963 }
7727 7964
7728 /* Subroutine of store_parm_decls which handles old-style function 7965 /* Subroutine of store_parm_decls which handles old-style function
7729 definitions (separate parameter list and declarations). */ 7966 definitions (separate parameter list and declarations). */
7730 7967
7752 continue; 7989 continue;
7753 } 7990 }
7754 7991
7755 b = I_SYMBOL_BINDING (TREE_VALUE (parm)); 7992 b = I_SYMBOL_BINDING (TREE_VALUE (parm));
7756 if (b && B_IN_CURRENT_SCOPE (b)) 7993 if (b && B_IN_CURRENT_SCOPE (b))
7757 { 7994 {
7758 decl = b->decl; 7995 decl = b->decl;
7759 /* If we got something other than a PARM_DECL it is an error. */ 7996 /* Skip erroneous parameters. */
7760 if (TREE_CODE (decl) != PARM_DECL) 7997 if (decl == error_mark_node)
7761 error_at (DECL_SOURCE_LOCATION (decl), 7998 continue;
7762 "%qD declared as a non-parameter", decl); 7999 /* If we got something other than a PARM_DECL it is an error. */
7763 /* If the declaration is already marked, we have a duplicate 8000 if (TREE_CODE (decl) != PARM_DECL)
7764 name. Complain and ignore the duplicate. */ 8001 error_at (DECL_SOURCE_LOCATION (decl),
7765 else if (pointer_set_contains (seen_args, decl)) 8002 "%qD declared as a non-parameter", decl);
7766 { 8003 /* If the declaration is already marked, we have a duplicate
7767 error_at (DECL_SOURCE_LOCATION (decl), 8004 name. Complain and ignore the duplicate. */
7768 "multiple parameters named %qD", decl); 8005 else if (pointer_set_contains (seen_args, decl))
7769 TREE_PURPOSE (parm) = 0; 8006 {
7770 continue; 8007 error_at (DECL_SOURCE_LOCATION (decl),
7771 } 8008 "multiple parameters named %qD", decl);
7772 /* If the declaration says "void", complain and turn it into 8009 TREE_PURPOSE (parm) = 0;
7773 an int. */ 8010 continue;
7774 else if (VOID_TYPE_P (TREE_TYPE (decl))) 8011 }
7775 { 8012 /* If the declaration says "void", complain and turn it into
7776 error_at (DECL_SOURCE_LOCATION (decl), 8013 an int. */
7777 "parameter %qD declared with void type", decl); 8014 else if (VOID_TYPE_P (TREE_TYPE (decl)))
7778 TREE_TYPE (decl) = integer_type_node; 8015 {
7779 DECL_ARG_TYPE (decl) = integer_type_node; 8016 error_at (DECL_SOURCE_LOCATION (decl),
7780 layout_decl (decl, 0); 8017 "parameter %qD declared with void type", decl);
7781 } 8018 TREE_TYPE (decl) = integer_type_node;
7782 warn_if_shadowing (decl); 8019 DECL_ARG_TYPE (decl) = integer_type_node;
7783 } 8020 layout_decl (decl, 0);
8021 }
8022 warn_if_shadowing (decl);
8023 }
7784 /* If no declaration found, default to int. */ 8024 /* If no declaration found, default to int. */
7785 else 8025 else
7786 { 8026 {
7787 /* FIXME diagnostics: This should be the location of the argument, 8027 /* FIXME diagnostics: This should be the location of the argument,
7788 not the FNDECL. E.g., for an old-style declaration 8028 not the FNDECL. E.g., for an old-style declaration
7856 { 8096 {
7857 last = TREE_PURPOSE (parm); 8097 last = TREE_PURPOSE (parm);
7858 DECL_ARGUMENTS (fndecl) = last; 8098 DECL_ARGUMENTS (fndecl) = last;
7859 8099
7860 for (parm = TREE_CHAIN (parm); parm; parm = TREE_CHAIN (parm)) 8100 for (parm = TREE_CHAIN (parm); parm; parm = TREE_CHAIN (parm))
7861 if (TREE_PURPOSE (parm)) 8101 if (TREE_PURPOSE (parm))
7862 { 8102 {
7863 TREE_CHAIN (last) = TREE_PURPOSE (parm); 8103 DECL_CHAIN (last) = TREE_PURPOSE (parm);
7864 last = TREE_PURPOSE (parm); 8104 last = TREE_PURPOSE (parm);
7865 } 8105 }
7866 TREE_CHAIN (last) = 0; 8106 DECL_CHAIN (last) = 0;
7867 } 8107 }
7868 8108
7869 pointer_set_destroy (seen_args); 8109 pointer_set_destroy (seen_args);
7870 8110
7871 /* If there was a previous prototype, 8111 /* If there was a previous prototype,
7877 tree type; 8117 tree type;
7878 for (parm = DECL_ARGUMENTS (fndecl), 8118 for (parm = DECL_ARGUMENTS (fndecl),
7879 type = current_function_prototype_arg_types; 8119 type = current_function_prototype_arg_types;
7880 parm || (type && TREE_VALUE (type) != error_mark_node 8120 parm || (type && TREE_VALUE (type) != error_mark_node
7881 && (TYPE_MAIN_VARIANT (TREE_VALUE (type)) != void_type_node)); 8121 && (TYPE_MAIN_VARIANT (TREE_VALUE (type)) != void_type_node));
7882 parm = TREE_CHAIN (parm), type = TREE_CHAIN (type)) 8122 parm = DECL_CHAIN (parm), type = TREE_CHAIN (type))
7883 { 8123 {
7884 if (parm == 0 || type == 0 8124 if (parm == 0 || type == 0
7885 || TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node) 8125 || TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node)
7886 { 8126 {
7887 if (current_function_prototype_built_in) 8127 if (current_function_prototype_built_in)
7888 warning_at (DECL_SOURCE_LOCATION (fndecl), 8128 warning_at (DECL_SOURCE_LOCATION (fndecl),
7889 0, "number of arguments doesn%'t match " 8129 0, "number of arguments doesn%'t match "
7890 "built-in prototype"); 8130 "built-in prototype");
7891 else 8131 else
7892 { 8132 {
7893 /* FIXME diagnostics: This should be the location of 8133 /* FIXME diagnostics: This should be the location of
7894 FNDECL, but there is bug when a prototype is 8134 FNDECL, but there is bug when a prototype is
7895 declared inside function context, but defined 8135 declared inside function context, but defined
7896 outside of it (e.g., gcc.dg/pr15698-2.c). In 8136 outside of it (e.g., gcc.dg/pr15698-2.c). In
7897 which case FNDECL gets the location of the 8137 which case FNDECL gets the location of the
7898 prototype, not the definition. */ 8138 prototype, not the definition. */
7899 error_at (input_location, 8139 error_at (input_location,
7900 "number of arguments doesn%'t match prototype"); 8140 "number of arguments doesn%'t match prototype");
7901 8141
7902 error_at (current_function_prototype_locus, 8142 error_at (current_function_prototype_locus,
7903 "prototype declaration"); 8143 "prototype declaration");
7904 } 8144 }
7905 break; 8145 break;
7906 } 8146 }
7907 /* Type for passing arg must be consistent with that 8147 /* Type for passing arg must be consistent with that
7908 declared for the arg. ISO C says we take the unqualified 8148 declared for the arg. ISO C says we take the unqualified
7909 type for parameters declared with qualified type. */ 8149 type for parameters declared with qualified type. */
7910 if (TREE_TYPE (parm) != error_mark_node 8150 if (TREE_TYPE (parm) != error_mark_node
7911 && TREE_TYPE (type) != error_mark_node 8151 && TREE_TYPE (type) != error_mark_node
7912 && !comptypes (TYPE_MAIN_VARIANT (DECL_ARG_TYPE (parm)), 8152 && !comptypes (TYPE_MAIN_VARIANT (DECL_ARG_TYPE (parm)),
7913 TYPE_MAIN_VARIANT (TREE_VALUE (type)))) 8153 TYPE_MAIN_VARIANT (TREE_VALUE (type))))
7914 { 8154 {
7915 if (TYPE_MAIN_VARIANT (TREE_TYPE (parm)) 8155 if (TYPE_MAIN_VARIANT (TREE_TYPE (parm))
7916 == TYPE_MAIN_VARIANT (TREE_VALUE (type))) 8156 == TYPE_MAIN_VARIANT (TREE_VALUE (type)))
7917 { 8157 {
7918 /* Adjust argument to match prototype. E.g. a previous 8158 /* Adjust argument to match prototype. E.g. a previous
7919 `int foo(float);' prototype causes 8159 `int foo(float);' prototype causes
7920 `int foo(x) float x; {...}' to be treated like 8160 `int foo(x) float x; {...}' to be treated like
7921 `int foo(float x) {...}'. This is particularly 8161 `int foo(float x) {...}'. This is particularly
7922 useful for argument types like uid_t. */ 8162 useful for argument types like uid_t. */
7923 DECL_ARG_TYPE (parm) = TREE_TYPE (parm); 8163 DECL_ARG_TYPE (parm) = TREE_TYPE (parm);
7924 8164
7925 if (targetm.calls.promote_prototypes (TREE_TYPE (current_function_decl)) 8165 if (targetm.calls.promote_prototypes (TREE_TYPE (current_function_decl))
7926 && INTEGRAL_TYPE_P (TREE_TYPE (parm)) 8166 && INTEGRAL_TYPE_P (TREE_TYPE (parm))
7927 && TYPE_PRECISION (TREE_TYPE (parm)) 8167 && TYPE_PRECISION (TREE_TYPE (parm))
7928 < TYPE_PRECISION (integer_type_node)) 8168 < TYPE_PRECISION (integer_type_node))
7929 DECL_ARG_TYPE (parm) = integer_type_node; 8169 DECL_ARG_TYPE (parm) = integer_type_node;
7930 8170
7931 /* ??? Is it possible to get here with a 8171 /* ??? Is it possible to get here with a
7932 built-in prototype or will it always have 8172 built-in prototype or will it always have
7933 been diagnosed as conflicting with an 8173 been diagnosed as conflicting with an
7934 old-style definition and discarded? */ 8174 old-style definition and discarded? */
7935 if (current_function_prototype_built_in) 8175 if (current_function_prototype_built_in)
7936 warning_at (DECL_SOURCE_LOCATION (parm), 8176 warning_at (DECL_SOURCE_LOCATION (parm),
7937 OPT_pedantic, "promoted argument %qD " 8177 OPT_pedantic, "promoted argument %qD "
7938 "doesn%'t match built-in prototype", parm); 8178 "doesn%'t match built-in prototype", parm);
7939 else 8179 else
7940 { 8180 {
7941 pedwarn (DECL_SOURCE_LOCATION (parm), 8181 pedwarn (DECL_SOURCE_LOCATION (parm),
7942 OPT_pedantic, "promoted argument %qD " 8182 OPT_pedantic, "promoted argument %qD "
7943 "doesn%'t match prototype", parm); 8183 "doesn%'t match prototype", parm);
7944 pedwarn (current_function_prototype_locus, OPT_pedantic, 8184 pedwarn (current_function_prototype_locus, OPT_pedantic,
7945 "prototype declaration"); 8185 "prototype declaration");
7946 } 8186 }
7947 } 8187 }
7948 else 8188 else
7949 { 8189 {
7950 if (current_function_prototype_built_in) 8190 if (current_function_prototype_built_in)
7951 warning_at (DECL_SOURCE_LOCATION (parm), 8191 warning_at (DECL_SOURCE_LOCATION (parm),
7952 0, "argument %qD doesn%'t match " 8192 0, "argument %qD doesn%'t match "
7953 "built-in prototype", parm); 8193 "built-in prototype", parm);
7954 else 8194 else
7955 { 8195 {
7956 error_at (DECL_SOURCE_LOCATION (parm), 8196 error_at (DECL_SOURCE_LOCATION (parm),
7957 "argument %qD doesn%'t match prototype", parm); 8197 "argument %qD doesn%'t match prototype", parm);
7958 error_at (current_function_prototype_locus, 8198 error_at (current_function_prototype_locus,
7959 "prototype declaration"); 8199 "prototype declaration");
7960 } 8200 }
7961 } 8201 }
7962 } 8202 }
7963 } 8203 }
7964 TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = 0; 8204 TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = 0;
7965 } 8205 }
7966 8206
7967 /* Otherwise, create a prototype that would match. */ 8207 /* Otherwise, create a prototype that would match. */
7968 8208
7969 else 8209 else
7970 { 8210 {
7971 tree actual = 0, last = 0, type; 8211 tree actual = 0, last = 0, type;
7972 8212
7973 for (parm = DECL_ARGUMENTS (fndecl); parm; parm = TREE_CHAIN (parm)) 8213 for (parm = DECL_ARGUMENTS (fndecl); parm; parm = DECL_CHAIN (parm))
7974 { 8214 {
7975 type = tree_cons (NULL_TREE, DECL_ARG_TYPE (parm), NULL_TREE); 8215 type = tree_cons (NULL_TREE, DECL_ARG_TYPE (parm), NULL_TREE);
7976 if (last) 8216 if (last)
7977 TREE_CHAIN (last) = type; 8217 TREE_CHAIN (last) = type;
7978 else 8218 else
7979 actual = type; 8219 actual = type;
7980 last = type; 8220 last = type;
7981 } 8221 }
7982 type = tree_cons (NULL_TREE, void_type_node, NULL_TREE); 8222 type = tree_cons (NULL_TREE, void_type_node, NULL_TREE);
7983 if (last) 8223 if (last)
7984 TREE_CHAIN (last) = type; 8224 TREE_CHAIN (last) = type;
7985 else 8225 else
7986 actual = type; 8226 actual = type;
8058 void foo(int n, int array[n++]) 8298 void foo(int n, int array[n++])
8059 because we throw away the array type in favor of a pointer type, and 8299 because we throw away the array type in favor of a pointer type, and
8060 thus won't naturally see the SAVE_EXPR containing the increment. All 8300 thus won't naturally see the SAVE_EXPR containing the increment. All
8061 other pending sizes would be handled by gimplify_parameters. */ 8301 other pending sizes would be handled by gimplify_parameters. */
8062 { 8302 {
8303 VEC(tree,gc) *pending_sizes = get_pending_sizes ();
8063 tree t; 8304 tree t;
8064 for (t = nreverse (get_pending_sizes ()); t ; t = TREE_CHAIN (t)) 8305 int i;
8065 add_stmt (TREE_VALUE (t)); 8306
8307 FOR_EACH_VEC_ELT (tree, pending_sizes, i, t)
8308 add_stmt (t);
8066 } 8309 }
8067 8310
8068 /* Even though we're inside a function body, we still don't want to 8311 /* Even though we're inside a function body, we still don't want to
8069 call expand_expr to calculate the size of a variable-sized array. 8312 call expand_expr to calculate the size of a variable-sized array.
8070 We haven't necessarily assigned RTL to all variables yet, so it's 8313 We haven't necessarily assigned RTL to all variables yet, so it's
8072 cfun->dont_save_pending_sizes_p = 1; 8315 cfun->dont_save_pending_sizes_p = 1;
8073 } 8316 }
8074 8317
8075 8318
8076 /* Finish up a function declaration and compile that function 8319 /* Finish up a function declaration and compile that function
8077 all the way to assembler language output. The free the storage 8320 all the way to assembler language output. Then free the storage
8078 for the function definition. 8321 for the function definition.
8079 8322
8080 This is called after parsing the body of the function definition. */ 8323 This is called after parsing the body of the function definition. */
8081 8324
8082 void 8325 void
8083 finish_function (void) 8326 finish_function (void)
8084 { 8327 {
8085 tree fndecl = current_function_decl; 8328 tree fndecl = current_function_decl;
8329
8330 if (c_dialect_objc ())
8331 objc_finish_function ();
8086 8332
8087 if (TREE_CODE (fndecl) == FUNCTION_DECL 8333 if (TREE_CODE (fndecl) == FUNCTION_DECL
8088 && targetm.calls.promote_prototypes (TREE_TYPE (fndecl))) 8334 && targetm.calls.promote_prototypes (TREE_TYPE (fndecl)))
8089 { 8335 {
8090 tree args = DECL_ARGUMENTS (fndecl); 8336 tree args = DECL_ARGUMENTS (fndecl);
8091 for (; args; args = TREE_CHAIN (args)) 8337 for (; args; args = DECL_CHAIN (args))
8092 { 8338 {
8093 tree type = TREE_TYPE (args); 8339 tree type = TREE_TYPE (args);
8094 if (INTEGRAL_TYPE_P (type) 8340 if (INTEGRAL_TYPE_P (type)
8095 && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)) 8341 && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
8096 DECL_ARG_TYPE (args) = integer_type_node; 8342 DECL_ARG_TYPE (args) = integer_type_node;
8097 } 8343 }
8098 } 8344 }
8099 8345
8100 if (DECL_INITIAL (fndecl) && DECL_INITIAL (fndecl) != error_mark_node) 8346 if (DECL_INITIAL (fndecl) && DECL_INITIAL (fndecl) != error_mark_node)
8101 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl; 8347 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
8102 8348
8127 if (warn_return_type 8373 if (warn_return_type
8128 && TREE_CODE (TREE_TYPE (TREE_TYPE (fndecl))) != VOID_TYPE 8374 && TREE_CODE (TREE_TYPE (TREE_TYPE (fndecl))) != VOID_TYPE
8129 && !current_function_returns_value && !current_function_returns_null 8375 && !current_function_returns_value && !current_function_returns_null
8130 /* Don't complain if we are no-return. */ 8376 /* Don't complain if we are no-return. */
8131 && !current_function_returns_abnormally 8377 && !current_function_returns_abnormally
8378 /* Don't complain if we are declared noreturn. */
8379 && !TREE_THIS_VOLATILE (fndecl)
8132 /* Don't warn for main(). */ 8380 /* Don't warn for main(). */
8133 && !MAIN_NAME_P (DECL_NAME (fndecl)) 8381 && !MAIN_NAME_P (DECL_NAME (fndecl))
8134 /* Or if they didn't actually specify a return type. */ 8382 /* Or if they didn't actually specify a return type. */
8135 && !C_FUNCTION_IMPLICIT_INT (fndecl) 8383 && !C_FUNCTION_IMPLICIT_INT (fndecl)
8136 /* Normally, with -Wreturn-type, flow will complain, but we might 8384 /* Normally, with -Wreturn-type, flow will complain, but we might
8138 && !TREE_PUBLIC (fndecl)) 8386 && !TREE_PUBLIC (fndecl))
8139 { 8387 {
8140 warning (OPT_Wreturn_type, 8388 warning (OPT_Wreturn_type,
8141 "no return statement in function returning non-void"); 8389 "no return statement in function returning non-void");
8142 TREE_NO_WARNING (fndecl) = 1; 8390 TREE_NO_WARNING (fndecl) = 1;
8391 }
8392
8393 /* Complain about parameters that are only set, but never otherwise used. */
8394 if (warn_unused_but_set_parameter)
8395 {
8396 tree decl;
8397
8398 for (decl = DECL_ARGUMENTS (fndecl);
8399 decl;
8400 decl = DECL_CHAIN (decl))
8401 if (TREE_USED (decl)
8402 && TREE_CODE (decl) == PARM_DECL
8403 && !DECL_READ_P (decl)
8404 && DECL_NAME (decl)
8405 && !DECL_ARTIFICIAL (decl)
8406 && !TREE_NO_WARNING (decl))
8407 warning_at (DECL_SOURCE_LOCATION (decl),
8408 OPT_Wunused_but_set_parameter,
8409 "parameter %qD set but not used", decl);
8143 } 8410 }
8144 8411
8145 /* Store the end of the function, so that we get good line number 8412 /* Store the end of the function, so that we get good line number
8146 info for the epilogue. */ 8413 info for the epilogue. */
8147 cfun->function_end_locus = input_location; 8414 cfun->function_end_locus = input_location;
8194 current_function_decl = NULL; 8461 current_function_decl = NULL;
8195 } 8462 }
8196 8463
8197 /* Check the declarations given in a for-loop for satisfying the C99 8464 /* Check the declarations given in a for-loop for satisfying the C99
8198 constraints. If exactly one such decl is found, return it. LOC is 8465 constraints. If exactly one such decl is found, return it. LOC is
8199 the location of the opening parenthesis of the for loop. */ 8466 the location of the opening parenthesis of the for loop. The last
8467 parameter allows you to control the "for loop initial declarations
8468 are only allowed in C99 mode". Normally, you should pass
8469 flag_isoc99 as that parameter. But in some cases (Objective-C
8470 foreach loop, for example) we want to run the checks in this
8471 function even if not in C99 mode, so we allow the caller to turn
8472 off the error about not being in C99 mode.
8473 */
8200 8474
8201 tree 8475 tree
8202 check_for_loop_decls (location_t loc) 8476 check_for_loop_decls (location_t loc, bool turn_off_iso_c99_error)
8203 { 8477 {
8204 struct c_binding *b; 8478 struct c_binding *b;
8205 tree one_decl = NULL_TREE; 8479 tree one_decl = NULL_TREE;
8206 int n_decls = 0; 8480 int n_decls = 0;
8207 8481
8208 if (!flag_isoc99) 8482 if (!turn_off_iso_c99_error)
8209 { 8483 {
8210 static bool hint = true; 8484 static bool hint = true;
8211 /* If we get here, declarations have been used in a for loop without 8485 /* If we get here, declarations have been used in a for loop without
8212 the C99 for loop scope. This doesn't make much sense, so don't 8486 the C99 for loop scope. This doesn't make much sense, so don't
8213 allow it. */ 8487 allow it. */
8290 8564
8291 void 8565 void
8292 c_push_function_context (void) 8566 c_push_function_context (void)
8293 { 8567 {
8294 struct language_function *p; 8568 struct language_function *p;
8295 p = GGC_NEW (struct language_function); 8569 p = ggc_alloc_language_function ();
8296 cfun->language = p; 8570 cfun->language = p;
8297 8571
8298 p->base.x_stmt_tree = c_stmt_tree; 8572 p->base.x_stmt_tree = c_stmt_tree;
8299 p->x_break_label = c_break_label; 8573 p->x_break_label = c_break_label;
8300 p->x_cont_label = c_cont_label; 8574 p->x_cont_label = c_cont_label;
8489 ret->attrs = 0; 8763 ret->attrs = 0;
8490 ret->typespec_word = cts_none; 8764 ret->typespec_word = cts_none;
8491 ret->storage_class = csc_none; 8765 ret->storage_class = csc_none;
8492 ret->expr_const_operands = true; 8766 ret->expr_const_operands = true;
8493 ret->declspecs_seen_p = false; 8767 ret->declspecs_seen_p = false;
8494 ret->type_seen_p = false; 8768 ret->typespec_kind = ctsk_none;
8495 ret->non_sc_seen_p = false; 8769 ret->non_sc_seen_p = false;
8496 ret->typedef_p = false; 8770 ret->typedef_p = false;
8497 ret->tag_defined_p = false;
8498 ret->explicit_signed_p = false; 8771 ret->explicit_signed_p = false;
8499 ret->deprecated_p = false; 8772 ret->deprecated_p = false;
8500 ret->default_int_p = false; 8773 ret->default_int_p = false;
8501 ret->long_p = false; 8774 ret->long_p = false;
8502 ret->long_long_p = false; 8775 ret->long_long_p = false;
8576 struct c_typespec spec) 8849 struct c_typespec spec)
8577 { 8850 {
8578 tree type = spec.spec; 8851 tree type = spec.spec;
8579 specs->non_sc_seen_p = true; 8852 specs->non_sc_seen_p = true;
8580 specs->declspecs_seen_p = true; 8853 specs->declspecs_seen_p = true;
8581 specs->type_seen_p = true; 8854 specs->typespec_kind = spec.kind;
8582 if (TREE_DEPRECATED (type)) 8855 if (TREE_DEPRECATED (type))
8583 specs->deprecated_p = true; 8856 specs->deprecated_p = true;
8584 8857
8585 /* Handle type specifier keywords. */ 8858 /* Handle type specifier keywords. */
8586 if (TREE_CODE (type) == IDENTIFIER_NODE 8859 if (TREE_CODE (type) == IDENTIFIER_NODE
8592 { 8865 {
8593 error_at (loc, "two or more data types in declaration specifiers"); 8866 error_at (loc, "two or more data types in declaration specifiers");
8594 return specs; 8867 return specs;
8595 } 8868 }
8596 if ((int) i <= (int) RID_LAST_MODIFIER) 8869 if ((int) i <= (int) RID_LAST_MODIFIER)
8597 { 8870 {
8598 /* "long", "short", "signed", "unsigned", "_Complex" or "_Sat". */ 8871 /* "long", "short", "signed", "unsigned", "_Complex" or "_Sat". */
8599 bool dupe = false; 8872 bool dupe = false;
8600 switch (i) 8873 switch (i)
8601 { 8874 {
8602 case RID_LONG: 8875 case RID_LONG:
8603 if (specs->long_long_p) 8876 if (specs->long_long_p)
8604 { 8877 {
8605 error_at (loc, "%<long long long%> is too long for GCC"); 8878 error_at (loc, "%<long long long%> is too long for GCC");
8606 break; 8879 break;
8607 } 8880 }
8608 if (specs->long_p) 8881 if (specs->long_p)
8609 { 8882 {
8610 if (specs->typespec_word == cts_double) 8883 if (specs->typespec_word == cts_double)
8611 { 8884 {
8612 error_at (loc, 8885 error_at (loc,
8613 ("both %<long long%> and %<double%> in " 8886 ("both %<long long%> and %<double%> in "
8614 "declaration specifiers")); 8887 "declaration specifiers"));
8615 break; 8888 break;
8616 } 8889 }
8617 pedwarn_c90 (loc, OPT_Wlong_long, 8890 pedwarn_c90 (loc, OPT_Wlong_long,
8618 "ISO C90 does not support %<long long%>"); 8891 "ISO C90 does not support %<long long%>");
8619 specs->long_long_p = 1; 8892 specs->long_long_p = 1;
8620 break; 8893 break;
8621 } 8894 }
8622 if (specs->short_p) 8895 if (specs->short_p)
8623 error_at (loc, 8896 error_at (loc,
8624 ("both %<long%> and %<short%> in " 8897 ("both %<long%> and %<short%> in "
8625 "declaration specifiers")); 8898 "declaration specifiers"));
8626 else if (specs->typespec_word == cts_void) 8899 else if (specs->typespec_word == cts_void)
8627 error_at (loc, 8900 error_at (loc,
8628 ("both %<long%> and %<void%> in " 8901 ("both %<long%> and %<void%> in "
8629 "declaration specifiers")); 8902 "declaration specifiers"));
8630 #ifndef noCbC 8903 #ifndef noCbC
8631 else if (specs->typespec_word == cts_CbC_code) 8904 else if (specs->typespec_word == cts_CbC_code)
8632 error_at (loc, 8905 error_at (loc,
8633 ("both %<long%> and %<void%> in " 8906 ("both %<long%> and %<void%> in "
8634 "declaration specifiers")); 8907 "declaration specifiers"));
8635 #endif 8908 #endif
8636 else if (specs->typespec_word == cts_bool) 8909 else if (specs->typespec_word == cts_int128)
8637 error_at (loc, 8910 error_at (loc,
8638 ("both %<long%> and %<_Bool%> in " 8911 ("both %<long%> and %<__int128%> in "
8639 "declaration specifiers")); 8912 "declaration specifiers"));
8640 else if (specs->typespec_word == cts_char) 8913 else if (specs->typespec_word == cts_bool)
8641 error_at (loc, 8914 error_at (loc,
8642 ("both %<long%> and %<char%> in " 8915 ("both %<long%> and %<_Bool%> in "
8643 "declaration specifiers")); 8916 "declaration specifiers"));
8644 else if (specs->typespec_word == cts_float) 8917 else if (specs->typespec_word == cts_char)
8645 error_at (loc, 8918 error_at (loc,
8646 ("both %<long%> and %<float%> in " 8919 ("both %<long%> and %<char%> in "
8647 "declaration specifiers")); 8920 "declaration specifiers"));
8648 else if (specs->typespec_word == cts_dfloat32) 8921 else if (specs->typespec_word == cts_float)
8649 error_at (loc, 8922 error_at (loc,
8650 ("both %<long%> and %<_Decimal32%> in " 8923 ("both %<long%> and %<float%> in "
8651 "declaration specifiers")); 8924 "declaration specifiers"));
8652 else if (specs->typespec_word == cts_dfloat64) 8925 else if (specs->typespec_word == cts_dfloat32)
8653 error_at (loc, 8926 error_at (loc,
8654 ("both %<long%> and %<_Decimal64%> in " 8927 ("both %<long%> and %<_Decimal32%> in "
8655 "declaration specifiers")); 8928 "declaration specifiers"));
8656 else if (specs->typespec_word == cts_dfloat128) 8929 else if (specs->typespec_word == cts_dfloat64)
8657 error_at (loc, 8930 error_at (loc,
8658 ("both %<long%> and %<_Decimal128%> in " 8931 ("both %<long%> and %<_Decimal64%> in "
8659 "declaration specifiers")); 8932 "declaration specifiers"));
8660 else 8933 else if (specs->typespec_word == cts_dfloat128)
8661 specs->long_p = true; 8934 error_at (loc,
8662 break; 8935 ("both %<long%> and %<_Decimal128%> in "
8663 case RID_SHORT: 8936 "declaration specifiers"));
8664 dupe = specs->short_p; 8937 else
8665 if (specs->long_p) 8938 specs->long_p = true;
8666 error_at (loc, 8939 break;
8667 ("both %<long%> and %<short%> in " 8940 case RID_SHORT:
8668 "declaration specifiers")); 8941 dupe = specs->short_p;
8669 else if (specs->typespec_word == cts_void) 8942 if (specs->long_p)
8670 error_at (loc, 8943 error_at (loc,
8671 ("both %<short%> and %<void%> in " 8944 ("both %<long%> and %<short%> in "
8672 "declaration specifiers")); 8945 "declaration specifiers"));
8946 else if (specs->typespec_word == cts_void)
8947 error_at (loc,
8948 ("both %<short%> and %<void%> in "
8949 "declaration specifiers"));
8673 #ifndef noCbC 8950 #ifndef noCbC
8674 else if (specs->typespec_word == cts_CbC_code) 8951 else if (specs->typespec_word == cts_CbC_code)
8675 error_at (loc, 8952 error_at (loc,
8676 ("both %<short%> and %<void%> in " 8953 ("both %<short%> and %<void%> in "
8677 "declaration specifiers")); 8954 "declaration specifiers"));
8678 #endif 8955 #endif
8679 else if (specs->typespec_word == cts_bool) 8956 else if (specs->typespec_word == cts_int128)
8680 error_at (loc, 8957 error_at (loc,
8681 ("both %<short%> and %<_Bool%> in " 8958 ("both %<short%> and %<__int128%> in "
8682 "declaration specifiers")); 8959 "declaration specifiers"));
8683 else if (specs->typespec_word == cts_char) 8960 else if (specs->typespec_word == cts_bool)
8684 error_at (loc, 8961 error_at (loc,
8685 ("both %<short%> and %<char%> in " 8962 ("both %<short%> and %<_Bool%> in "
8686 "declaration specifiers")); 8963 "declaration specifiers"));
8687 else if (specs->typespec_word == cts_float) 8964 else if (specs->typespec_word == cts_char)
8688 error_at (loc, 8965 error_at (loc,
8689 ("both %<short%> and %<float%> in " 8966 ("both %<short%> and %<char%> in "
8690 "declaration specifiers")); 8967 "declaration specifiers"));
8691 else if (specs->typespec_word == cts_double) 8968 else if (specs->typespec_word == cts_float)
8692 error_at (loc, 8969 error_at (loc,
8693 ("both %<short%> and %<double%> in " 8970 ("both %<short%> and %<float%> in "
8694 "declaration specifiers")); 8971 "declaration specifiers"));
8695 else if (specs->typespec_word == cts_dfloat32) 8972 else if (specs->typespec_word == cts_double)
8973 error_at (loc,
8974 ("both %<short%> and %<double%> in "
8975 "declaration specifiers"));
8976 else if (specs->typespec_word == cts_dfloat32)
8977 >>>>>>> other
8696 error_at (loc, 8978 error_at (loc,
8697 ("both %<short%> and %<_Decimal32%> in " 8979 ("both %<short%> and %<_Decimal32%> in "
8698 "declaration specifiers")); 8980 "declaration specifiers"));
8699 else if (specs->typespec_word == cts_dfloat64) 8981 else if (specs->typespec_word == cts_dfloat64)
8700 error_at (loc, 8982 error_at (loc,
8811 else if (specs->typespec_word == cts_bool) 9093 else if (specs->typespec_word == cts_bool)
8812 error_at (loc, 9094 error_at (loc,
8813 ("both %<complex%> and %<_Bool%> in " 9095 ("both %<complex%> and %<_Bool%> in "
8814 "declaration specifiers")); 9096 "declaration specifiers"));
8815 else if (specs->typespec_word == cts_dfloat32) 9097 else if (specs->typespec_word == cts_dfloat32)
8816 error_at (loc, 9098 error_at (loc,
8817 ("both %<complex%> and %<_Decimal32%> in " 9099 ("both %<complex%> and %<_Decimal32%> in "
8818 "declaration specifiers")); 9100 "declaration specifiers"));
8819 else if (specs->typespec_word == cts_dfloat64) 9101 else if (specs->typespec_word == cts_dfloat64)
8820 error_at (loc, 9102 error_at (loc,
8821 ("both %<complex%> and %<_Decimal64%> in " 9103 ("both %<complex%> and %<_Decimal64%> in "
8822 "declaration specifiers")); 9104 "declaration specifiers"));
8823 else if (specs->typespec_word == cts_dfloat128) 9105 else if (specs->typespec_word == cts_dfloat128)
8824 error_at (loc, 9106 error_at (loc,
8825 ("both %<complex%> and %<_Decimal128%> in " 9107 ("both %<complex%> and %<_Decimal128%> in "
8826 "declaration specifiers")); 9108 "declaration specifiers"));
8827 else if (specs->typespec_word == cts_fract) 9109 else if (specs->typespec_word == cts_fract)
8828 error_at (loc, 9110 error_at (loc,
8829 ("both %<complex%> and %<_Fract%> in " 9111 ("both %<complex%> and %<_Fract%> in "
8830 "declaration specifiers")); 9112 "declaration specifiers"));
8831 else if (specs->typespec_word == cts_accum) 9113 else if (specs->typespec_word == cts_accum)
8832 error_at (loc, 9114 error_at (loc,
8833 ("both %<complex%> and %<_Accum%> in " 9115 ("both %<complex%> and %<_Accum%> in "
8834 "declaration specifiers")); 9116 "declaration specifiers"));
8835 else if (specs->saturating_p) 9117 else if (specs->saturating_p)
8836 error_at (loc, 9118 error_at (loc,
8837 ("both %<complex%> and %<_Sat%> in " 9119 ("both %<complex%> and %<_Sat%> in "
8838 "declaration specifiers")); 9120 "declaration specifiers"));
8839 else 9121 else
8840 specs->complex_p = true; 9122 specs->complex_p = true;
8841 break; 9123 break;
8842 case RID_SAT: 9124 case RID_SAT:
8843 dupe = specs->saturating_p; 9125 dupe = specs->saturating_p;
8844 pedwarn (loc, OPT_pedantic, 9126 pedwarn (loc, OPT_pedantic,
8845 "ISO C does not support saturating types"); 9127 "ISO C does not support saturating types");
8846 if (specs->typespec_word == cts_void) 9128 if (specs->typespec_word == cts_int128)
8847 error_at (loc, 9129 {
8848 ("both %<_Sat%> and %<void%> in " 9130 error_at (loc,
8849 "declaration specifiers")); 9131 ("both %<_Sat%> and %<__int128%> in "
8850 else if (specs->typespec_word == cts_bool) 9132 "declaration specifiers"));
8851 error_at (loc, 9133 }
8852 ("both %<_Sat%> and %<_Bool%> in " 9134 else if (specs->typespec_word == cts_void)
8853 "declaration specifiers")); 9135 error_at (loc,
8854 else if (specs->typespec_word == cts_char) 9136 ("both %<_Sat%> and %<void%> in "
8855 error_at (loc, 9137 "declaration specifiers"));
8856 ("both %<_Sat%> and %<char%> in " 9138 else if (specs->typespec_word == cts_bool)
8857 "declaration specifiers")); 9139 error_at (loc,
8858 else if (specs->typespec_word == cts_int) 9140 ("both %<_Sat%> and %<_Bool%> in "
8859 error_at (loc, 9141 "declaration specifiers"));
8860 ("both %<_Sat%> and %<int%> in " 9142 else if (specs->typespec_word == cts_char)
8861 "declaration specifiers")); 9143 error_at (loc,
8862 else if (specs->typespec_word == cts_float) 9144 ("both %<_Sat%> and %<char%> in "
8863 error_at (loc, 9145 "declaration specifiers"));
8864 ("both %<_Sat%> and %<float%> in " 9146 else if (specs->typespec_word == cts_int)
8865 "declaration specifiers")); 9147 error_at (loc,
8866 else if (specs->typespec_word == cts_double) 9148 ("both %<_Sat%> and %<int%> in "
8867 error_at (loc, 9149 "declaration specifiers"));
8868 ("both %<_Sat%> and %<double%> in " 9150 else if (specs->typespec_word == cts_float)
8869 "declaration specifiers")); 9151 error_at (loc,
9152 ("both %<_Sat%> and %<float%> in "
9153 "declaration specifiers"));
9154 else if (specs->typespec_word == cts_double)
9155 error_at (loc,
9156 ("both %<_Sat%> and %<double%> in "
9157 "declaration specifiers"));
8870 else if (specs->typespec_word == cts_dfloat32) 9158 else if (specs->typespec_word == cts_dfloat32)
8871 error_at (loc, 9159 error_at (loc,
8872 ("both %<_Sat%> and %<_Decimal32%> in " 9160 ("both %<_Sat%> and %<_Decimal32%> in "
8873 "declaration specifiers")); 9161 "declaration specifiers"));
8874 else if (specs->typespec_word == cts_dfloat64) 9162 else if (specs->typespec_word == cts_dfloat64)
8894 error_at (loc, "duplicate %qE", type); 9182 error_at (loc, "duplicate %qE", type);
8895 9183
8896 return specs; 9184 return specs;
8897 } 9185 }
8898 else 9186 else
8899 { 9187 {
8900 /* "void", "_Bool", "char", "int", "float", "double", "_Decimal32", 9188 /* "void", "_Bool", "char", "int", "float", "double", "_Decimal32",
8901 "_Decimal64", "_Decimal128", "_Fract" or "_Accum". */ 9189 "__int128", "_Decimal64", "_Decimal128", "_Fract" or "_Accum". */
8902 if (specs->typespec_word != cts_none) 9190 if (specs->typespec_word != cts_none)
8903 { 9191 {
8904 error_at (loc, 9192 error_at (loc,
8905 "two or more data types in declaration specifiers"); 9193 "two or more data types in declaration specifiers");
8906 return specs; 9194 return specs;
8907 } 9195 }
8908 switch (i) 9196 switch (i)
8909 { 9197 {
8910 case RID_VOID: 9198 case RID_INT128:
8911 if (specs->long_p) 9199 if (int128_integer_type_node == NULL_TREE)
8912 error_at (loc, 9200 {
8913 ("both %<long%> and %<void%> in " 9201 error_at (loc, "%<__int128%> is not supported for this target");
8914 "declaration specifiers")); 9202 return specs;
8915 else if (specs->short_p) 9203 }
8916 error_at (loc, 9204 if (!in_system_header)
8917 ("both %<short%> and %<void%> in " 9205 pedwarn (loc, OPT_pedantic,
8918 "declaration specifiers")); 9206 "ISO C does not support %<__int128%> type");
8919 else if (specs->signed_p) 9207
8920 error_at (loc, 9208 if (specs->long_p)
8921 ("both %<signed%> and %<void%> in " 9209 error_at (loc,
8922 "declaration specifiers")); 9210 ("both %<__int128%> and %<long%> in "
8923 else if (specs->unsigned_p) 9211 "declaration specifiers"));
8924 error_at (loc, 9212 else if (specs->saturating_p)
8925 ("both %<unsigned%> and %<void%> in " 9213 error_at (loc,
8926 "declaration specifiers")); 9214 ("both %<_Sat%> and %<__int128%> in "
8927 else if (specs->complex_p) 9215 "declaration specifiers"));
8928 error_at (loc, 9216 else if (specs->short_p)
8929 ("both %<complex%> and %<void%> in " 9217 error_at (loc,
8930 "declaration specifiers")); 9218 ("both %<__int128%> and %<short%> in "
8931 else if (specs->saturating_p) 9219 "declaration specifiers"));
8932 error_at (loc, 9220 else
8933 ("both %<_Sat%> and %<void%> in " 9221 specs->typespec_word = cts_int128;
8934 "declaration specifiers")); 9222 return specs;
8935 else 9223 case RID_VOID:
8936 specs->typespec_word = cts_void; 9224 if (specs->long_p)
8937 return specs; 9225 error_at (loc,
9226 ("both %<long%> and %<void%> in "
9227 "declaration specifiers"));
9228 else if (specs->short_p)
9229 error_at (loc,
9230 ("both %<short%> and %<void%> in "
9231 "declaration specifiers"));
9232 else if (specs->signed_p)
9233 error_at (loc,
9234 ("both %<signed%> and %<void%> in "
9235 "declaration specifiers"));
9236 else if (specs->unsigned_p)
9237 error_at (loc,
9238 ("both %<unsigned%> and %<void%> in "
9239 "declaration specifiers"));
9240 else if (specs->complex_p)
9241 error_at (loc,
9242 ("both %<complex%> and %<void%> in "
9243 "declaration specifiers"));
9244 else if (specs->saturating_p)
9245 error_at (loc,
9246 ("both %<_Sat%> and %<void%> in "
9247 "declaration specifiers"));
9248 else
9249 specs->typespec_word = cts_void;
9250 return specs;
8938 #ifndef noCbC 9251 #ifndef noCbC
8939 case RID_CbC_CODE: 9252 case RID_CbC_CODE:
8940 if (specs->long_p) 9253 if (specs->long_p)
8941 error ("both %<long%> and %<void%> in " 9254 error ("both %<long%> and %<void%> in "
8942 "declaration specifiers"); 9255 "declaration specifiers");
8943 else if (specs->short_p) 9256 else if (specs->short_p)
8944 error ("both %<short%> and %<void%> in " 9257 error ("both %<short%> and %<void%> in "
8945 "declaration specifiers"); 9258 "declaration specifiers");
8946 else if (specs->signed_p) 9259 else if (specs->signed_p)
8947 error ("both %<signed%> and %<void%> in " 9260 error ("both %<signed%> and %<void%> in "
8948 "declaration specifiers"); 9261 "declaration specifiers");
8949 else if (specs->unsigned_p) 9262 else if (specs->unsigned_p)
8950 error ("both %<unsigned%> and %<void%> in " 9263 error ("both %<unsigned%> and %<void%> in "
8951 "declaration specifiers"); 9264 "declaration specifiers");
8952 else if (specs->complex_p) 9265 else if (specs->complex_p)
8953 error ("both %<complex%> and %<void%> in " 9266 error ("both %<complex%> and %<void%> in "
8954 "declaration specifiers"); 9267 "declaration specifiers");
8955 else 9268 else
8956 specs->typespec_word = cts_CbC_code; 9269 specs->typespec_word = cts_CbC_code;
8957 return specs; 9270 return specs;
8958 #endif 9271 #endif
8959 case RID_BOOL: 9272 case RID_BOOL:
8960 if (specs->long_p) 9273 if (specs->long_p)
8961 error_at (loc, 9274 error_at (loc,
8962 ("both %<long%> and %<_Bool%> in " 9275 ("both %<long%> and %<_Bool%> in "
8963 "declaration specifiers")); 9276 "declaration specifiers"));
8964 else if (specs->short_p) 9277 else if (specs->short_p)
8965 error_at (loc, 9278 error_at (loc,
8966 ("both %<short%> and %<_Bool%> in " 9279 ("both %<short%> and %<_Bool%> in "
8967 "declaration specifiers")); 9280 "declaration specifiers"));
8968 else if (specs->signed_p) 9281 else if (specs->signed_p)
8969 error_at (loc, 9282 error_at (loc,
8970 ("both %<signed%> and %<_Bool%> in " 9283 ("both %<signed%> and %<_Bool%> in "
8971 "declaration specifiers")); 9284 "declaration specifiers"));
8972 else if (specs->unsigned_p) 9285 else if (specs->unsigned_p)
8973 error_at (loc, 9286 error_at (loc,
8974 ("both %<unsigned%> and %<_Bool%> in " 9287 ("both %<unsigned%> and %<_Bool%> in "
8975 "declaration specifiers")); 9288 "declaration specifiers"));
8976 else if (specs->complex_p) 9289 else if (specs->complex_p)
8977 error_at (loc, 9290 error_at (loc,
8978 ("both %<complex%> and %<_Bool%> in " 9291 ("both %<complex%> and %<_Bool%> in "
8979 "declaration specifiers")); 9292 "declaration specifiers"));
8980 else if (specs->saturating_p) 9293 else if (specs->saturating_p)
8981 error_at (loc, 9294 error_at (loc,
8982 ("both %<_Sat%> and %<_Bool%> in " 9295 ("both %<_Sat%> and %<_Bool%> in "
8983 "declaration specifiers")); 9296 "declaration specifiers"));
8984 else 9297 else
8985 specs->typespec_word = cts_bool; 9298 specs->typespec_word = cts_bool;
8986 return specs; 9299 return specs;
8987 case RID_CHAR: 9300 case RID_CHAR:
8988 if (specs->long_p) 9301 if (specs->long_p)
8989 error_at (loc, 9302 error_at (loc,
8990 ("both %<long%> and %<char%> in " 9303 ("both %<long%> and %<char%> in "
8991 "declaration specifiers")); 9304 "declaration specifiers"));
8992 else if (specs->short_p) 9305 else if (specs->short_p)
8993 error_at (loc, 9306 error_at (loc,
8994 ("both %<short%> and %<char%> in " 9307 ("both %<short%> and %<char%> in "
8995 "declaration specifiers")); 9308 "declaration specifiers"));
8996 else if (specs->saturating_p) 9309 else if (specs->saturating_p)
8997 error_at (loc, 9310 error_at (loc,
8998 ("both %<_Sat%> and %<char%> in " 9311 ("both %<_Sat%> and %<char%> in "
8999 "declaration specifiers")); 9312 "declaration specifiers"));
9000 else 9313 else
9001 specs->typespec_word = cts_char; 9314 specs->typespec_word = cts_char;
9002 return specs; 9315 return specs;
9003 case RID_INT: 9316 case RID_INT:
9004 if (specs->saturating_p) 9317 if (specs->saturating_p)
9005 error_at (loc, 9318 error_at (loc,
9006 ("both %<_Sat%> and %<int%> in " 9319 ("both %<_Sat%> and %<int%> in "
9007 "declaration specifiers")); 9320 "declaration specifiers"));
9008 else 9321 else
9009 specs->typespec_word = cts_int; 9322 specs->typespec_word = cts_int;
9010 return specs; 9323 return specs;
9011 case RID_FLOAT: 9324 case RID_FLOAT:
9012 if (specs->long_p) 9325 if (specs->long_p)
9013 error_at (loc, 9326 error_at (loc,
9014 ("both %<long%> and %<float%> in " 9327 ("both %<long%> and %<float%> in "
9015 "declaration specifiers")); 9328 "declaration specifiers"));
9016 else if (specs->short_p) 9329 else if (specs->short_p)
9017 error_at (loc, 9330 error_at (loc,
9018 ("both %<short%> and %<float%> in " 9331 ("both %<short%> and %<float%> in "
9019 "declaration specifiers")); 9332 "declaration specifiers"));
9020 else if (specs->signed_p) 9333 else if (specs->signed_p)
9021 error_at (loc, 9334 error_at (loc,
9022 ("both %<signed%> and %<float%> in " 9335 ("both %<signed%> and %<float%> in "
9023 "declaration specifiers")); 9336 "declaration specifiers"));
9024 else if (specs->unsigned_p) 9337 else if (specs->unsigned_p)
9025 error_at (loc, 9338 error_at (loc,
9026 ("both %<unsigned%> and %<float%> in " 9339 ("both %<unsigned%> and %<float%> in "
9027 "declaration specifiers")); 9340 "declaration specifiers"));
9028 else if (specs->saturating_p) 9341 else if (specs->saturating_p)
9029 error_at (loc, 9342 error_at (loc,
9030 ("both %<_Sat%> and %<float%> in " 9343 ("both %<_Sat%> and %<float%> in "
9031 "declaration specifiers")); 9344 "declaration specifiers"));
9032 else 9345 else
9033 specs->typespec_word = cts_float; 9346 specs->typespec_word = cts_float;
9034 return specs; 9347 return specs;
9035 case RID_DOUBLE: 9348 case RID_DOUBLE:
9036 if (specs->long_long_p) 9349 if (specs->long_long_p)
9037 error_at (loc, 9350 error_at (loc,
9038 ("both %<long long%> and %<double%> in " 9351 ("both %<long long%> and %<double%> in "
9039 "declaration specifiers")); 9352 "declaration specifiers"));
9040 else if (specs->short_p) 9353 else if (specs->short_p)
9041 error_at (loc, 9354 error_at (loc,
9042 ("both %<short%> and %<double%> in " 9355 ("both %<short%> and %<double%> in "
9043 "declaration specifiers")); 9356 "declaration specifiers"));
9044 else if (specs->signed_p) 9357 else if (specs->signed_p)
9045 error_at (loc, 9358 error_at (loc,
9046 ("both %<signed%> and %<double%> in " 9359 ("both %<signed%> and %<double%> in "
9047 "declaration specifiers")); 9360 "declaration specifiers"));
9048 else if (specs->unsigned_p) 9361 else if (specs->unsigned_p)
9049 error_at (loc, 9362 error_at (loc,
9050 ("both %<unsigned%> and %<double%> in " 9363 ("both %<unsigned%> and %<double%> in "
9051 "declaration specifiers")); 9364 "declaration specifiers"));
9052 else if (specs->saturating_p) 9365 else if (specs->saturating_p)
9053 error_at (loc, 9366 error_at (loc,
9054 ("both %<_Sat%> and %<double%> in " 9367 ("both %<_Sat%> and %<double%> in "
9055 "declaration specifiers")); 9368 "declaration specifiers"));
9056 else 9369 else
9057 specs->typespec_word = cts_double; 9370 specs->typespec_word = cts_double;
9058 return specs; 9371 return specs;
9059 case RID_DFLOAT32: 9372 case RID_DFLOAT32:
9060 case RID_DFLOAT64: 9373 case RID_DFLOAT64:
9061 case RID_DFLOAT128: 9374 case RID_DFLOAT128:
9062 { 9375 {
9063 const char *str; 9376 const char *str;
9064 if (i == RID_DFLOAT32) 9377 if (i == RID_DFLOAT32)
9065 str = "_Decimal32"; 9378 str = "_Decimal32";
9066 else if (i == RID_DFLOAT64) 9379 else if (i == RID_DFLOAT64)
9067 str = "_Decimal64"; 9380 str = "_Decimal64";
9068 else 9381 else
9069 str = "_Decimal128"; 9382 str = "_Decimal128";
9070 if (specs->long_long_p) 9383 if (specs->long_long_p)
9071 error_at (loc, 9384 error_at (loc,
9072 ("both %<long long%> and %<%s%> in " 9385 ("both %<long long%> and %<%s%> in "
9073 "declaration specifiers"), 9386 "declaration specifiers"),
9074 str); 9387 str);
9075 if (specs->long_p) 9388 if (specs->long_p)
9076 error_at (loc, 9389 error_at (loc,
9077 ("both %<long%> and %<%s%> in " 9390 ("both %<long%> and %<%s%> in "
9078 "declaration specifiers"), 9391 "declaration specifiers"),
9079 str); 9392 str);
9080 else if (specs->short_p) 9393 else if (specs->short_p)
9081 error_at (loc, 9394 error_at (loc,
9082 ("both %<short%> and %<%s%> in " 9395 ("both %<short%> and %<%s%> in "
9083 "declaration specifiers"), 9396 "declaration specifiers"),
9084 str); 9397 str);
9085 else if (specs->signed_p) 9398 else if (specs->signed_p)
9086 error_at (loc, 9399 error_at (loc,
9087 ("both %<signed%> and %<%s%> in " 9400 ("both %<signed%> and %<%s%> in "
9088 "declaration specifiers"), 9401 "declaration specifiers"),
9089 str); 9402 str);
9090 else if (specs->unsigned_p) 9403 else if (specs->unsigned_p)
9091 error_at (loc, 9404 error_at (loc,
9092 ("both %<unsigned%> and %<%s%> in " 9405 ("both %<unsigned%> and %<%s%> in "
9093 "declaration specifiers"), 9406 "declaration specifiers"),
9094 str); 9407 str);
9095 else if (specs->complex_p) 9408 else if (specs->complex_p)
9096 error_at (loc, 9409 error_at (loc,
9097 ("both %<complex%> and %<%s%> in " 9410 ("both %<complex%> and %<%s%> in "
9098 "declaration specifiers"), 9411 "declaration specifiers"),
9099 str); 9412 str);
9189 else if (TREE_TYPE (t) == error_mark_node) 9502 else if (TREE_TYPE (t) == error_mark_node)
9190 ; 9503 ;
9191 else 9504 else
9192 specs->type = TREE_TYPE (t); 9505 specs->type = TREE_TYPE (t);
9193 } 9506 }
9194 else if (TREE_CODE (type) != ERROR_MARK) 9507 else
9195 { 9508 {
9196 if (spec.kind == ctsk_tagdef || spec.kind == ctsk_tagfirstref) 9509 if (TREE_CODE (type) != ERROR_MARK && spec.kind == ctsk_typeof)
9197 specs->tag_defined_p = true; 9510 {
9198 if (spec.kind == ctsk_typeof) 9511 specs->typedef_p = true;
9199 { 9512 if (spec.expr)
9200 specs->typedef_p = true; 9513 {
9201 if (spec.expr) 9514 if (specs->expr)
9202 { 9515 specs->expr = build2 (COMPOUND_EXPR, TREE_TYPE (spec.expr),
9203 if (specs->expr) 9516 specs->expr, spec.expr);
9204 specs->expr = build2 (COMPOUND_EXPR, TREE_TYPE (spec.expr), 9517 else
9205 specs->expr, spec.expr); 9518 specs->expr = spec.expr;
9206 else 9519 specs->expr_const_operands &= spec.expr_const_operands;
9207 specs->expr = spec.expr; 9520 }
9208 specs->expr_const_operands &= spec.expr_const_operands; 9521 }
9209 }
9210 }
9211 specs->type = type; 9522 specs->type = type;
9212 } 9523 }
9213 9524
9214 return specs; 9525 return specs;
9215 } 9526 }
9321 /* If a type was specified as a whole, we have no modifiers and are 9632 /* If a type was specified as a whole, we have no modifiers and are
9322 done. */ 9633 done. */
9323 if (specs->type != NULL_TREE) 9634 if (specs->type != NULL_TREE)
9324 { 9635 {
9325 gcc_assert (!specs->long_p && !specs->long_long_p && !specs->short_p 9636 gcc_assert (!specs->long_p && !specs->long_long_p && !specs->short_p
9326 && !specs->signed_p && !specs->unsigned_p 9637 && !specs->signed_p && !specs->unsigned_p
9327 && !specs->complex_p); 9638 && !specs->complex_p);
9639
9640 /* Set a dummy type. */
9641 if (TREE_CODE (specs->type) == ERROR_MARK)
9642 specs->type = integer_type_node;
9328 return specs; 9643 return specs;
9329 } 9644 }
9330 9645
9331 /* If none of "void", "_Bool", "char", "int", "float" or "double" 9646 /* If none of "void", "_Bool", "char", "int", "float" or "double"
9332 has been specified, treat it as "int" unless "_Complex" is 9647 has been specified, treat it as "int" unless "_Complex" is
9401 pedwarn (input_location, OPT_pedantic, 9716 pedwarn (input_location, OPT_pedantic,
9402 "ISO C does not support complex integer types"); 9717 "ISO C does not support complex integer types");
9403 specs->type = build_complex_type (specs->type); 9718 specs->type = build_complex_type (specs->type);
9404 } 9719 }
9405 break; 9720 break;
9721 case cts_int128:
9722 gcc_assert (!specs->long_p && !specs->short_p && !specs->long_long_p);
9723 gcc_assert (!(specs->signed_p && specs->unsigned_p));
9724 specs->type = (specs->unsigned_p
9725 ? int128_unsigned_type_node
9726 : int128_integer_type_node);
9727 if (specs->complex_p)
9728 {
9729 pedwarn (input_location, OPT_pedantic,
9730 "ISO C does not support complex integer types");
9731 specs->type = build_complex_type (specs->type);
9732 }
9733 break;
9406 case cts_int: 9734 case cts_int:
9407 gcc_assert (!(specs->long_p && specs->short_p)); 9735 gcc_assert (!(specs->long_p && specs->short_p));
9408 gcc_assert (!(specs->signed_p && specs->unsigned_p)); 9736 gcc_assert (!(specs->signed_p && specs->unsigned_p));
9409 if (specs->long_long_p) 9737 if (specs->long_long_p)
9410 specs->type = (specs->unsigned_p 9738 specs->type = (specs->unsigned_p
9566 { 9894 {
9567 tree decl; 9895 tree decl;
9568 bool reconsider; 9896 bool reconsider;
9569 9897
9570 /* Process the decls in the order they were written. */ 9898 /* Process the decls in the order they were written. */
9571 for (decl = globals; decl; decl = TREE_CHAIN (decl)) 9899 for (decl = globals; decl; decl = DECL_CHAIN (decl))
9572 { 9900 {
9573 /* Check for used but undefined static functions using the C 9901 /* Check for used but undefined static functions using the C
9574 standard's definition of "used", and set TREE_NO_WARNING so 9902 standard's definition of "used", and set TREE_NO_WARNING so
9575 that check_global_declarations doesn't repeat the check. */ 9903 that check_global_declarations doesn't repeat the check. */
9576 if (TREE_CODE (decl) == FUNCTION_DECL 9904 if (TREE_CODE (decl) == FUNCTION_DECL
9587 } 9915 }
9588 9916
9589 do 9917 do
9590 { 9918 {
9591 reconsider = false; 9919 reconsider = false;
9592 for (decl = globals; decl; decl = TREE_CHAIN (decl)) 9920 for (decl = globals; decl; decl = DECL_CHAIN (decl))
9593 reconsider |= wrapup_global_declaration_2 (decl); 9921 reconsider |= wrapup_global_declaration_2 (decl);
9594 } 9922 }
9595 while (reconsider); 9923 while (reconsider);
9596 9924
9597 for (decl = globals; decl; decl = TREE_CHAIN (decl)) 9925 for (decl = globals; decl; decl = DECL_CHAIN (decl))
9598 check_global_declaration_1 (decl); 9926 check_global_declaration_1 (decl);
9599 } 9927 }
9600 9928
9601 /* A subroutine of c_write_global_declarations Emit debug information for each 9929 /* A subroutine of c_write_global_declarations Emit debug information for each
9602 of the declarations in GLOBALS. */ 9930 of the declarations in GLOBALS. */
9604 static void 9932 static void
9605 c_write_global_declarations_2 (tree globals) 9933 c_write_global_declarations_2 (tree globals)
9606 { 9934 {
9607 tree decl; 9935 tree decl;
9608 9936
9609 for (decl = globals; decl ; decl = TREE_CHAIN (decl)) 9937 for (decl = globals; decl ; decl = DECL_CHAIN (decl))
9610 debug_hooks->global_decl (decl); 9938 debug_hooks->global_decl (decl);
9939 }
9940
9941 /* Callback to collect a source_ref from a DECL. */
9942
9943 static void
9944 collect_source_ref_cb (tree decl)
9945 {
9946 if (!DECL_IS_BUILTIN (decl))
9947 collect_source_ref (LOCATION_FILE (decl_sloc (decl, false)));
9948 }
9949
9950 /* Collect all references relevant to SOURCE_FILE. */
9951
9952 static void
9953 collect_all_refs (const char *source_file)
9954 {
9955 tree t;
9956 unsigned i;
9957
9958 FOR_EACH_VEC_ELT (tree, all_translation_units, i, t)
9959 collect_ada_nodes (BLOCK_VARS (DECL_INITIAL (t)), source_file);
9960 }
9961
9962 /* Iterate over all global declarations and call CALLBACK. */
9963
9964 static void
9965 for_each_global_decl (void (*callback) (tree decl))
9966 {
9967 tree t;
9968 tree decls;
9969 tree decl;
9970 unsigned i;
9971
9972 FOR_EACH_VEC_ELT (tree, all_translation_units, i, t)
9973 {
9974 decls = DECL_INITIAL (t);
9975 for (decl = BLOCK_VARS (decls); decl; decl = TREE_CHAIN (decl))
9976 callback (decl);
9977 }
9611 } 9978 }
9612 9979
9613 /* Preserve the external declarations scope across a garbage collect. */ 9980 /* Preserve the external declarations scope across a garbage collect. */
9614 static GTY(()) tree ext_block; 9981 static GTY(()) tree ext_block;
9615 9982
9616 void 9983 void
9617 c_write_global_declarations (void) 9984 c_write_global_declarations (void)
9618 { 9985 {
9619 tree t; 9986 tree t;
9987 unsigned i;
9620 9988
9621 /* We don't want to do this if generating a PCH. */ 9989 /* We don't want to do this if generating a PCH. */
9622 if (pch_file) 9990 if (pch_file)
9623 return; 9991 return;
9624 9992
9625 /* Don't waste time on further processing if -fsyntax-only. 9993 /* Do the Objective-C stuff. This is where all the Objective-C
9626 Continue for warning and errors issued during lowering though. */ 9994 module stuff gets generated (symtab, class/protocol/selector
9627 if (flag_syntax_only) 9995 lists etc). */
9628 return; 9996 if (c_dialect_objc ())
9997 objc_write_global_declarations ();
9629 9998
9630 /* Close the external scope. */ 9999 /* Close the external scope. */
9631 ext_block = pop_scope (); 10000 ext_block = pop_scope ();
9632 external_scope = 0; 10001 external_scope = 0;
9633 gcc_assert (!current_scope); 10002 gcc_assert (!current_scope);
9634 10003
10004 /* Handle -fdump-ada-spec[-slim]. */
10005 if (dump_enabled_p (TDI_ada))
10006 {
10007 /* Build a table of files to generate specs for */
10008 if (get_dump_file_info (TDI_ada)->flags & TDF_SLIM)
10009 collect_source_ref (main_input_filename);
10010 else
10011 for_each_global_decl (collect_source_ref_cb);
10012
10013 dump_ada_specs (collect_all_refs, NULL);
10014 }
10015
9635 if (ext_block) 10016 if (ext_block)
9636 { 10017 {
9637 tree tmp = BLOCK_VARS (ext_block); 10018 tree tmp = BLOCK_VARS (ext_block);
9638 int flags; 10019 int flags;
9639 FILE * stream = dump_begin (TDI_tu, &flags); 10020 FILE * stream = dump_begin (TDI_tu, &flags);
9644 } 10025 }
9645 } 10026 }
9646 10027
9647 /* Process all file scopes in this compilation, and the external_scope, 10028 /* Process all file scopes in this compilation, and the external_scope,
9648 through wrapup_global_declarations and check_global_declarations. */ 10029 through wrapup_global_declarations and check_global_declarations. */
9649 for (t = all_translation_units; t; t = TREE_CHAIN (t)) 10030 FOR_EACH_VEC_ELT (tree, all_translation_units, i, t)
9650 c_write_global_declarations_1 (BLOCK_VARS (DECL_INITIAL (t))); 10031 c_write_global_declarations_1 (BLOCK_VARS (DECL_INITIAL (t)));
9651 c_write_global_declarations_1 (BLOCK_VARS (ext_block)); 10032 c_write_global_declarations_1 (BLOCK_VARS (ext_block));
9652 10033
9653 /* We're done parsing; proceed to optimize and emit assembly. 10034 /* We're done parsing; proceed to optimize and emit assembly.
9654 FIXME: shouldn't be the front end's responsibility to call this. */ 10035 FIXME: shouldn't be the front end's responsibility to call this. */
9655 cgraph_finalize_compilation_unit (); 10036 cgraph_finalize_compilation_unit ();
9656 10037
9657 /* After cgraph has had a chance to emit everything that's going to 10038 /* After cgraph has had a chance to emit everything that's going to
9658 be emitted, output debug information for globals. */ 10039 be emitted, output debug information for globals. */
9659 if (errorcount == 0 && sorrycount == 0) 10040 if (!seen_error ())
9660 { 10041 {
9661 timevar_push (TV_SYMOUT); 10042 timevar_push (TV_SYMOUT);
9662 for (t = all_translation_units; t; t = TREE_CHAIN (t)) 10043 FOR_EACH_VEC_ELT (tree, all_translation_units, i, t)
9663 c_write_global_declarations_2 (BLOCK_VARS (DECL_INITIAL (t))); 10044 c_write_global_declarations_2 (BLOCK_VARS (DECL_INITIAL (t)));
9664 c_write_global_declarations_2 (BLOCK_VARS (ext_block)); 10045 c_write_global_declarations_2 (BLOCK_VARS (ext_block));
9665 timevar_pop (TV_SYMOUT); 10046 timevar_pop (TV_SYMOUT);
9666 } 10047 }
9667 10048
9668 ext_block = NULL; 10049 ext_block = NULL;
9669 } 10050 }
9670 10051
10052 /* Register reserved keyword WORD as qualifier for address space AS. */
10053
10054 void
10055 c_register_addr_space (const char *word, addr_space_t as)
10056 {
10057 int rid = RID_FIRST_ADDR_SPACE + as;
10058 tree id;
10059
10060 /* Address space qualifiers are only supported
10061 in C with GNU extensions enabled. */
10062 if (c_dialect_objc () || flag_no_asm)
10063 return;
10064
10065 id = get_identifier (word);
10066 C_SET_RID_CODE (id, rid);
10067 C_IS_RESERVED_WORD (id) = 1;
10068 ridpointers [rid] = id;
10069 }
10070
9671 #include "gt-c-decl.h" 10071 #include "gt-c-decl.h"