Mercurial > hg > CbC > CbC_gcc
comparison gcc/c-decl.c @ 67:f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
author | nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 22 Mar 2011 17:18:12 +0900 |
parents | b7f97abdc517 |
children | 1b10fe6932e1 |
comparison
equal
deleted
inserted
replaced
65:65488c3d617d | 67:f6334be47118 |
---|---|
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 "c-tree.h" | 40 #include "c-tree.h" |
42 #include "toplev.h" | 41 #include "toplev.h" |
44 #include "cpplib.h" | 43 #include "cpplib.h" |
45 #include "target.h" | 44 #include "target.h" |
46 #include "debug.h" | 45 #include "debug.h" |
47 #include "opts.h" | 46 #include "opts.h" |
48 #include "timevar.h" | 47 #include "timevar.h" |
49 #include "c-common.h" | 48 #include "c-family/c-common.h" |
50 #include "c-pragma.h" | 49 #include "c-family/c-objc.h" |
50 #include "c-family/c-pragma.h" | |
51 #include "c-lang.h" | 51 #include "c-lang.h" |
52 #include "langhooks.h" | 52 #include "langhooks.h" |
53 #include "tree-mudflap.h" | 53 #include "tree-mudflap.h" |
54 #include "tree-iterator.h" | 54 #include "tree-iterator.h" |
55 #include "diagnostic.h" | 55 #include "diagnostic-core.h" |
56 #include "tree-dump.h" | 56 #include "tree-dump.h" |
57 #include "cgraph.h" | 57 #include "cgraph.h" |
58 #include "hashtab.h" | 58 #include "hashtab.h" |
59 #include "langhooks-def.h" | 59 #include "langhooks-def.h" |
60 #include "pointer-set.h" | 60 #include "pointer-set.h" |
61 #include "plugin.h" | 61 #include "plugin.h" |
62 #include "c-family/c-ada-spec.h" | |
62 | 63 |
63 /* In grokdeclarator, distinguish syntactic contexts of declarators. */ | 64 /* In grokdeclarator, distinguish syntactic contexts of declarators. */ |
64 enum decl_context | 65 enum decl_context |
65 { NORMAL, /* Ordinary declaration */ | 66 { NORMAL, /* Ordinary declaration */ |
66 FUNCDEF, /* Function definition */ | 67 FUNCDEF, /* Function definition */ |
115 static GTY(()) struct stmt_tree_s c_stmt_tree; | 116 static GTY(()) struct stmt_tree_s c_stmt_tree; |
116 | 117 |
117 /* State saving variables. */ | 118 /* State saving variables. */ |
118 tree c_break_label; | 119 tree c_break_label; |
119 tree c_cont_label; | 120 tree c_cont_label; |
120 | |
121 /* Linked list of TRANSLATION_UNIT_DECLS for the translation units | |
122 included in this invocation. Note that the current translation | |
123 unit is not included in this list. */ | |
124 | |
125 static GTY(()) tree all_translation_units; | |
126 | 121 |
127 /* A list of decls to be made automatically visible in each file scope. */ | 122 /* A list of decls to be made automatically visible in each file scope. */ |
128 static GTY(()) tree visible_builtins; | 123 static GTY(()) tree visible_builtins; |
129 | 124 |
130 /* Set to 0 at beginning of a function definition, set to 1 if | 125 /* Set to 0 at beginning of a function definition, set to 1 if |
407 | 402 |
408 /* True if this scope has any label bindings. This is used to speed | 403 /* True if this scope has any label bindings. This is used to speed |
409 up searching for labels when popping scopes, particularly since | 404 up searching for labels when popping scopes, particularly since |
410 labels are normally only found at function scope. */ | 405 labels are normally only found at function scope. */ |
411 BOOL_BITFIELD has_label_bindings : 1; | 406 BOOL_BITFIELD has_label_bindings : 1; |
407 | |
408 /* True if we should issue a warning if a goto statement crosses any | |
409 of the bindings. We still need to check the list of bindings to | |
410 find the specific ones we need to warn about. This is true if | |
411 decl_jump_unsafe would return true for any of the bindings. This | |
412 is used to avoid looping over all the bindings unnecessarily. */ | |
413 BOOL_BITFIELD has_jump_unsafe_decl : 1; | |
412 }; | 414 }; |
413 | 415 |
414 /* The scope currently in effect. */ | 416 /* The scope currently in effect. */ |
415 | 417 |
416 static GTY(()) struct c_scope *current_scope; | 418 static GTY(()) struct c_scope *current_scope; |
557 append_to_statement_list_force (t, &cur_stmt_list); | 559 append_to_statement_list_force (t, &cur_stmt_list); |
558 | 560 |
559 return t; | 561 return t; |
560 } | 562 } |
561 | 563 |
564 /* Return true if we will want to say something if a goto statement | |
565 crosses DECL. */ | |
566 | |
567 static bool | |
568 decl_jump_unsafe (tree decl) | |
569 { | |
570 if (decl == error_mark_node || TREE_TYPE (decl) == error_mark_node) | |
571 return false; | |
572 | |
573 /* Always warn about crossing variably modified types. */ | |
574 if ((TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == TYPE_DECL) | |
575 && variably_modified_type_p (TREE_TYPE (decl), NULL_TREE)) | |
576 return true; | |
577 | |
578 /* Otherwise, only warn if -Wgoto-misses-init and this is an | |
579 initialized automatic decl. */ | |
580 if (warn_jump_misses_init | |
581 && TREE_CODE (decl) == VAR_DECL | |
582 && !TREE_STATIC (decl) | |
583 && DECL_INITIAL (decl) != NULL_TREE) | |
584 return true; | |
585 | |
586 return false; | |
587 } | |
588 | |
562 | 589 |
563 void | 590 void |
564 c_print_identifier (FILE *file, tree node, int indent) | 591 c_print_identifier (FILE *file, tree node, int indent) |
565 { | 592 { |
566 print_node (file, "symbol", I_SYMBOL_DECL (node), indent + 4); | 593 print_node (file, "symbol", I_SYMBOL_DECL (node), indent + 4); |
588 { | 615 { |
589 b = binding_freelist; | 616 b = binding_freelist; |
590 binding_freelist = b->prev; | 617 binding_freelist = b->prev; |
591 } | 618 } |
592 else | 619 else |
593 b = GGC_NEW (struct c_binding); | 620 b = ggc_alloc_c_binding (); |
594 | 621 |
595 b->shadowed = 0; | 622 b->shadowed = 0; |
596 b->decl = decl; | 623 b->decl = decl; |
597 b->id = name; | 624 b->id = name; |
598 b->depth = scope->depth; | 625 b->depth = scope->depth; |
604 | 631 |
605 b->u.type = NULL; | 632 b->u.type = NULL; |
606 | 633 |
607 b->prev = scope->bindings; | 634 b->prev = scope->bindings; |
608 scope->bindings = b; | 635 scope->bindings = b; |
636 | |
637 if (decl_jump_unsafe (decl)) | |
638 scope->has_jump_unsafe_decl = 1; | |
609 | 639 |
610 if (!name) | 640 if (!name) |
611 return; | 641 return; |
612 | 642 |
613 switch (TREE_CODE (decl)) | 643 switch (TREE_CODE (decl)) |
702 | 732 |
703 void | 733 void |
704 record_inline_static (location_t loc, tree func, tree decl, | 734 record_inline_static (location_t loc, tree func, tree decl, |
705 enum c_inline_static_type type) | 735 enum c_inline_static_type type) |
706 { | 736 { |
707 struct c_inline_static *csi = GGC_NEW (struct c_inline_static); | 737 struct c_inline_static *csi = ggc_alloc_c_inline_static (); |
708 csi->location = loc; | 738 csi->location = loc; |
709 csi->function = func; | 739 csi->function = func; |
710 csi->static_decl = decl; | 740 csi->static_decl = decl; |
711 csi->type = type; | 741 csi->type = type; |
712 csi->next = c_inline_statics; | 742 csi->next = c_inline_statics; |
761 } | 791 } |
762 p->stmt_exprs = 0; | 792 p->stmt_exprs = 0; |
763 p->left_stmt_expr = false; | 793 p->left_stmt_expr = false; |
764 } | 794 } |
765 | 795 |
766 /* Return true if we will want to say something if a goto statement | |
767 crosses DECL. */ | |
768 | |
769 static bool | |
770 decl_jump_unsafe (tree decl) | |
771 { | |
772 if (decl == error_mark_node || TREE_TYPE (decl) == error_mark_node) | |
773 return false; | |
774 | |
775 /* Always warn about crossing variably modified types. */ | |
776 if ((TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == TYPE_DECL) | |
777 && variably_modified_type_p (TREE_TYPE (decl), NULL_TREE)) | |
778 return true; | |
779 | |
780 /* Otherwise, only warn if -Wgoto-misses-init and this is an | |
781 initialized automatic decl. */ | |
782 if (warn_jump_misses_init | |
783 && TREE_CODE (decl) == VAR_DECL | |
784 && !TREE_STATIC (decl) | |
785 && DECL_INITIAL (decl) != NULL_TREE) | |
786 return true; | |
787 | |
788 return false; | |
789 } | |
790 | |
791 /* Update spot bindings P as we pop out of SCOPE. Return true if we | 796 /* Update spot bindings P as we pop out of SCOPE. Return true if we |
792 should push decls for a label. */ | 797 should push decls for a label. */ |
793 | 798 |
794 static bool | 799 static bool |
795 update_spot_bindings (struct c_scope *scope, struct c_spot_bindings *p) | 800 update_spot_bindings (struct c_scope *scope, struct c_spot_bindings *p) |
926 { | 931 { |
927 scope = scope_freelist; | 932 scope = scope_freelist; |
928 scope_freelist = scope->outer; | 933 scope_freelist = scope->outer; |
929 } | 934 } |
930 else | 935 else |
931 scope = GGC_CNEW (struct c_scope); | 936 scope = ggc_alloc_cleared_c_scope (); |
932 | 937 |
933 /* The FLOAT_CONST_DECIMAL64 pragma applies to nested scopes. */ | 938 /* The FLOAT_CONST_DECIMAL64 pragma applies to nested scopes. */ |
934 if (current_scope) | 939 if (current_scope) |
935 scope->float_const_decimal64 = current_scope->float_const_decimal64; | 940 scope->float_const_decimal64 = current_scope->float_const_decimal64; |
936 else | 941 else |
972 | 977 |
973 for (b = s->bindings; b != NULL; b = b->prev) | 978 for (b = s->bindings; b != NULL; b = b->prev) |
974 { | 979 { |
975 struct c_label_vars *label_vars; | 980 struct c_label_vars *label_vars; |
976 struct c_binding *b1; | 981 struct c_binding *b1; |
982 bool hjud; | |
977 unsigned int ix; | 983 unsigned int ix; |
978 struct c_goto_bindings *g; | 984 struct c_goto_bindings *g; |
979 | 985 |
980 if (TREE_CODE (b->decl) != LABEL_DECL) | 986 if (TREE_CODE (b->decl) != LABEL_DECL) |
981 continue; | 987 continue; |
982 label_vars = b->u.label; | 988 label_vars = b->u.label; |
983 | 989 |
984 b1 = label_vars->label_bindings.bindings_in_scope; | 990 b1 = label_vars->label_bindings.bindings_in_scope; |
991 if (label_vars->label_bindings.scope == NULL) | |
992 hjud = false; | |
993 else | |
994 hjud = label_vars->label_bindings.scope->has_jump_unsafe_decl; | |
985 if (update_spot_bindings (scope, &label_vars->label_bindings)) | 995 if (update_spot_bindings (scope, &label_vars->label_bindings)) |
986 { | 996 { |
987 /* This label is defined in this scope. */ | 997 /* This label is defined in this scope. */ |
988 for (; b1 != NULL; b1 = b1->prev) | 998 if (hjud) |
989 { | 999 { |
990 /* A goto from later in the function to this | 1000 for (; b1 != NULL; b1 = b1->prev) |
991 label will never see the initialization of | 1001 { |
992 B1, if any. Save it to issue a warning if | 1002 /* A goto from later in the function to this |
993 needed. */ | 1003 label will never see the initialization |
994 if (decl_jump_unsafe (b1->decl)) | 1004 of B1, if any. Save it to issue a |
995 VEC_safe_push (tree, gc, label_vars->decls_in_scope, | 1005 warning if needed. */ |
996 b1->decl); | 1006 if (decl_jump_unsafe (b1->decl)) |
1007 VEC_safe_push (tree, gc, | |
1008 label_vars->decls_in_scope, | |
1009 b1->decl); | |
1010 } | |
997 } | 1011 } |
998 } | 1012 } |
999 | 1013 |
1000 /* Update the bindings of any goto statements associated | 1014 /* Update the bindings of any goto statements associated |
1001 with this label. */ | 1015 with this label. */ |
1002 for (ix = 0; | 1016 FOR_EACH_VEC_ELT (c_goto_bindings_p, label_vars->gotos, ix, g) |
1003 VEC_iterate (c_goto_bindings_p, label_vars->gotos, ix, g); | |
1004 ++ix) | |
1005 update_spot_bindings (scope, &g->goto_bindings); | 1017 update_spot_bindings (scope, &g->goto_bindings); |
1006 } | 1018 } |
1007 } | 1019 } |
1008 | 1020 |
1009 /* Don't search beyond the current function. */ | 1021 /* Don't search beyond the current function. */ |
1072 "parameter list local" tagged types. */ | 1084 "parameter list local" tagged types. */ |
1073 if (scope->function_body) | 1085 if (scope->function_body) |
1074 context = current_function_decl; | 1086 context = current_function_decl; |
1075 else if (scope == file_scope) | 1087 else if (scope == file_scope) |
1076 { | 1088 { |
1077 tree file_decl = build_decl (UNKNOWN_LOCATION, | 1089 tree file_decl = build_translation_unit_decl (NULL_TREE); |
1078 TRANSLATION_UNIT_DECL, 0, 0); | |
1079 TREE_CHAIN (file_decl) = all_translation_units; | |
1080 all_translation_units = file_decl; | |
1081 context = file_decl; | 1090 context = file_decl; |
1082 } | 1091 } |
1083 else | 1092 else |
1084 context = block; | 1093 context = block; |
1085 | 1094 |
1098 } | 1107 } |
1099 else | 1108 else |
1100 warn_for_unused_label (p); | 1109 warn_for_unused_label (p); |
1101 | 1110 |
1102 /* Labels go in BLOCK_VARS. */ | 1111 /* Labels go in BLOCK_VARS. */ |
1103 TREE_CHAIN (p) = BLOCK_VARS (block); | 1112 DECL_CHAIN (p) = BLOCK_VARS (block); |
1104 BLOCK_VARS (block) = p; | 1113 BLOCK_VARS (block) = p; |
1105 gcc_assert (I_LABEL_BINDING (b->id) == b); | 1114 gcc_assert (I_LABEL_BINDING (b->id) == b); |
1106 I_LABEL_BINDING (b->id) = b->shadowed; | 1115 I_LABEL_BINDING (b->id) = b->shadowed; |
1107 | 1116 |
1108 /* Also pop back to the shadowed label_vars. */ | 1117 /* Also pop back to the shadowed label_vars. */ |
1186 common_symbol: | 1195 common_symbol: |
1187 /* All of these go in BLOCK_VARS, but only if this is the | 1196 /* All of these go in BLOCK_VARS, but only if this is the |
1188 binding in the home scope. */ | 1197 binding in the home scope. */ |
1189 if (!b->nested) | 1198 if (!b->nested) |
1190 { | 1199 { |
1191 TREE_CHAIN (p) = BLOCK_VARS (block); | 1200 DECL_CHAIN (p) = BLOCK_VARS (block); |
1192 BLOCK_VARS (block) = p; | 1201 BLOCK_VARS (block) = p; |
1193 } | 1202 } |
1194 else if (VAR_OR_FUNCTION_DECL_P (p)) | 1203 else if (VAR_OR_FUNCTION_DECL_P (p)) |
1195 { | 1204 { |
1196 /* For block local externs add a special | 1205 /* For block local externs add a special |
1209 DECL_SAVED_TREE (extp) = NULL_TREE; | 1218 DECL_SAVED_TREE (extp) = NULL_TREE; |
1210 DECL_STRUCT_FUNCTION (extp) = NULL; | 1219 DECL_STRUCT_FUNCTION (extp) = NULL; |
1211 } | 1220 } |
1212 if (b->locus != UNKNOWN_LOCATION) | 1221 if (b->locus != UNKNOWN_LOCATION) |
1213 DECL_SOURCE_LOCATION (extp) = b->locus; | 1222 DECL_SOURCE_LOCATION (extp) = b->locus; |
1214 TREE_CHAIN (extp) = BLOCK_VARS (block); | 1223 DECL_CHAIN (extp) = BLOCK_VARS (block); |
1215 BLOCK_VARS (block) = extp; | 1224 BLOCK_VARS (block) = extp; |
1216 } | 1225 } |
1217 /* If this is the file scope, and we are processing more | 1226 /* If this is the file scope set DECL_CONTEXT of each decl to |
1218 than one translation unit in this compilation, set | 1227 the TRANSLATION_UNIT_DECL. This makes same_translation_unit_p |
1219 DECL_CONTEXT of each decl to the TRANSLATION_UNIT_DECL. | 1228 work. */ |
1220 This makes same_translation_unit_p work, and causes | 1229 if (scope == file_scope) |
1221 static declarations to be given disambiguating suffixes. */ | |
1222 if (scope == file_scope && num_in_fnames > 1) | |
1223 { | 1230 { |
1224 DECL_CONTEXT (p) = context; | 1231 DECL_CONTEXT (p) = context; |
1225 if (TREE_CODE (p) == TYPE_DECL) | 1232 if (TREE_CODE (p) == TYPE_DECL |
1233 && TREE_TYPE (p) != error_mark_node) | |
1226 set_type_context (TREE_TYPE (p), context); | 1234 set_type_context (TREE_TYPE (p), context); |
1227 } | 1235 } |
1228 | 1236 |
1229 /* Fall through. */ | 1237 /* Fall through. */ |
1230 /* Parameters go in DECL_ARGUMENTS, not BLOCK_VARS, and have | 1238 /* Parameters go in DECL_ARGUMENTS, not BLOCK_VARS, and have |
1291 push_scope (); | 1299 push_scope (); |
1292 file_scope = current_scope; | 1300 file_scope = current_scope; |
1293 | 1301 |
1294 start_fname_decls (); | 1302 start_fname_decls (); |
1295 | 1303 |
1296 for (decl = visible_builtins; decl; decl = TREE_CHAIN (decl)) | 1304 for (decl = visible_builtins; decl; decl = DECL_CHAIN (decl)) |
1297 bind (DECL_NAME (decl), decl, file_scope, | 1305 bind (DECL_NAME (decl), decl, file_scope, |
1298 /*invisible=*/false, /*nested=*/true, DECL_SOURCE_LOCATION (decl)); | 1306 /*invisible=*/false, /*nested=*/true, DECL_SOURCE_LOCATION (decl)); |
1299 } | 1307 } |
1300 | 1308 |
1301 void | 1309 void |
1350 | 1358 |
1351 if (TREE_CODE (b->decl) != LABEL_DECL) | 1359 if (TREE_CODE (b->decl) != LABEL_DECL) |
1352 continue; | 1360 continue; |
1353 label_vars = b->u.label; | 1361 label_vars = b->u.label; |
1354 ++label_vars->label_bindings.stmt_exprs; | 1362 ++label_vars->label_bindings.stmt_exprs; |
1355 for (ix = 0; | 1363 FOR_EACH_VEC_ELT (c_goto_bindings_p, label_vars->gotos, ix, g) |
1356 VEC_iterate (c_goto_bindings_p, label_vars->gotos, ix, g); | |
1357 ++ix) | |
1358 ++g->goto_bindings.stmt_exprs; | 1364 ++g->goto_bindings.stmt_exprs; |
1359 } | 1365 } |
1360 } | 1366 } |
1361 | 1367 |
1362 if (switch_bindings != NULL) | 1368 if (switch_bindings != NULL) |
1390 if (label_vars->label_bindings.stmt_exprs < 0) | 1396 if (label_vars->label_bindings.stmt_exprs < 0) |
1391 { | 1397 { |
1392 label_vars->label_bindings.left_stmt_expr = true; | 1398 label_vars->label_bindings.left_stmt_expr = true; |
1393 label_vars->label_bindings.stmt_exprs = 0; | 1399 label_vars->label_bindings.stmt_exprs = 0; |
1394 } | 1400 } |
1395 for (ix = 0; | 1401 FOR_EACH_VEC_ELT (c_goto_bindings_p, label_vars->gotos, ix, g) |
1396 VEC_iterate (c_goto_bindings_p, label_vars->gotos, ix, g); | |
1397 ++ix) | |
1398 { | 1402 { |
1399 --g->goto_bindings.stmt_exprs; | 1403 --g->goto_bindings.stmt_exprs; |
1400 if (g->goto_bindings.stmt_exprs < 0) | 1404 if (g->goto_bindings.stmt_exprs < 0) |
1401 { | 1405 { |
1402 g->goto_bindings.left_stmt_expr = true; | 1406 g->goto_bindings.left_stmt_expr = true; |
1514 { | 1518 { |
1515 tree t; | 1519 tree t; |
1516 | 1520 |
1517 if (TREE_CODE (olddecl) != FUNCTION_DECL | 1521 if (TREE_CODE (olddecl) != FUNCTION_DECL |
1518 || !comptypes (TREE_TYPE (oldtype), TREE_TYPE (newtype)) | 1522 || !comptypes (TREE_TYPE (oldtype), TREE_TYPE (newtype)) |
1519 || !((TYPE_ARG_TYPES (oldtype) == 0 && DECL_INITIAL (olddecl) == 0) | 1523 || !((!prototype_p (oldtype) && DECL_INITIAL (olddecl) == 0) |
1520 || | 1524 || (!prototype_p (newtype) && DECL_INITIAL (newdecl) == 0))) |
1521 (TYPE_ARG_TYPES (newtype) == 0 && DECL_INITIAL (newdecl) == 0))) | |
1522 return; | 1525 return; |
1523 | 1526 |
1524 t = TYPE_ARG_TYPES (oldtype); | 1527 t = TYPE_ARG_TYPES (oldtype); |
1525 if (t == 0) | 1528 if (t == 0) |
1526 t = TYPE_ARG_TYPES (newtype); | 1529 t = TYPE_ARG_TYPES (newtype); |
1784 } | 1787 } |
1785 } | 1788 } |
1786 | 1789 |
1787 /* Redeclaration of a type is a constraint violation (6.7.2.3p1), | 1790 /* Redeclaration of a type is a constraint violation (6.7.2.3p1), |
1788 but silently ignore the redeclaration if either is in a system | 1791 but silently ignore the redeclaration if either is in a system |
1789 header. (Conflicting redeclarations were handled above.) */ | 1792 header. (Conflicting redeclarations were handled above.) This |
1793 is allowed for C1X if the types are the same, not just | |
1794 compatible. */ | |
1790 if (TREE_CODE (newdecl) == TYPE_DECL) | 1795 if (TREE_CODE (newdecl) == TYPE_DECL) |
1791 { | 1796 { |
1797 bool types_different = false; | |
1798 int comptypes_result; | |
1799 | |
1800 comptypes_result | |
1801 = comptypes_check_different_types (oldtype, newtype, &types_different); | |
1802 | |
1803 if (comptypes_result != 1 || types_different) | |
1804 { | |
1805 error ("redefinition of typedef %q+D with different type", newdecl); | |
1806 locate_old_decl (olddecl); | |
1807 return false; | |
1808 } | |
1809 | |
1792 if (DECL_IN_SYSTEM_HEADER (newdecl) | 1810 if (DECL_IN_SYSTEM_HEADER (newdecl) |
1793 || DECL_IN_SYSTEM_HEADER (olddecl) | 1811 || DECL_IN_SYSTEM_HEADER (olddecl) |
1794 || TREE_NO_WARNING (newdecl) | 1812 || TREE_NO_WARNING (newdecl) |
1795 || TREE_NO_WARNING (olddecl)) | 1813 || TREE_NO_WARNING (olddecl)) |
1796 return true; /* Allow OLDDECL to continue in use. */ | 1814 return true; /* Allow OLDDECL to continue in use. */ |
1797 | 1815 |
1798 error ("redefinition of typedef %q+D", newdecl); | 1816 if (pedantic && !flag_isoc1x) |
1799 locate_old_decl (olddecl); | 1817 { |
1800 return false; | 1818 pedwarn (input_location, OPT_pedantic, |
1819 "redefinition of typedef %q+D", newdecl); | |
1820 locate_old_decl (olddecl); | |
1821 } | |
1822 else if (variably_modified_type_p (newtype, NULL)) | |
1823 { | |
1824 /* Whether there is a constraint violation for the types not | |
1825 being the same cannot be determined at compile time; a | |
1826 warning that there may be one at runtime is considered | |
1827 appropriate (WG14 reflector message 11743, 8 May 2009). */ | |
1828 warning (0, "redefinition of typedef %q+D may be a constraint " | |
1829 "violation at runtime", newdecl); | |
1830 locate_old_decl (olddecl); | |
1831 } | |
1832 | |
1833 return true; | |
1801 } | 1834 } |
1802 | 1835 |
1803 /* Function declarations can either be 'static' or 'extern' (no | 1836 /* Function declarations can either be 'static' or 'extern' (no |
1804 qualifier is equivalent to 'extern' - C99 6.2.2p5) and therefore | 1837 qualifier is equivalent to 'extern' - C99 6.2.2p5) and therefore |
1805 can never conflict with each other on account of linkage | 1838 can never conflict with each other on account of linkage |
1816 overridden, but optionally warn this was a bad choice of name. */ | 1849 overridden, but optionally warn this was a bad choice of name. */ |
1817 if (DECL_BUILT_IN (olddecl) | 1850 if (DECL_BUILT_IN (olddecl) |
1818 && !C_DECL_DECLARED_BUILTIN (olddecl) | 1851 && !C_DECL_DECLARED_BUILTIN (olddecl) |
1819 && (!TREE_PUBLIC (newdecl) | 1852 && (!TREE_PUBLIC (newdecl) |
1820 || (DECL_INITIAL (newdecl) | 1853 || (DECL_INITIAL (newdecl) |
1821 && !TYPE_ARG_TYPES (TREE_TYPE (newdecl))))) | 1854 && !prototype_p (TREE_TYPE (newdecl))))) |
1822 { | 1855 { |
1823 warning (OPT_Wshadow, "declaration of %q+D shadows " | 1856 warning (OPT_Wshadow, "declaration of %q+D shadows " |
1824 "a built-in function", newdecl); | 1857 "a built-in function", newdecl); |
1825 /* Discard the old built-in function. */ | 1858 /* Discard the old built-in function. */ |
1826 return false; | 1859 return false; |
1853 } | 1886 } |
1854 } | 1887 } |
1855 /* If we have a prototype after an old-style function definition, | 1888 /* If we have a prototype after an old-style function definition, |
1856 the argument types must be checked specially. */ | 1889 the argument types must be checked specially. */ |
1857 else if (DECL_INITIAL (olddecl) | 1890 else if (DECL_INITIAL (olddecl) |
1858 && !TYPE_ARG_TYPES (oldtype) && TYPE_ARG_TYPES (newtype) | 1891 && !prototype_p (oldtype) && prototype_p (newtype) |
1859 && TYPE_ACTUAL_ARG_TYPES (oldtype) | 1892 && TYPE_ACTUAL_ARG_TYPES (oldtype) |
1860 && !validate_proto_after_old_defn (newdecl, newtype, oldtype)) | 1893 && !validate_proto_after_old_defn (newdecl, newtype, oldtype)) |
1861 { | 1894 { |
1862 locate_old_decl (olddecl); | 1895 locate_old_decl (olddecl); |
1863 return false; | 1896 return false; |
2122 merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype) | 2155 merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype) |
2123 { | 2156 { |
2124 bool new_is_definition = (TREE_CODE (newdecl) == FUNCTION_DECL | 2157 bool new_is_definition = (TREE_CODE (newdecl) == FUNCTION_DECL |
2125 && DECL_INITIAL (newdecl) != 0); | 2158 && DECL_INITIAL (newdecl) != 0); |
2126 bool new_is_prototype = (TREE_CODE (newdecl) == FUNCTION_DECL | 2159 bool new_is_prototype = (TREE_CODE (newdecl) == FUNCTION_DECL |
2127 && TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != 0); | 2160 && prototype_p (TREE_TYPE (newdecl))); |
2128 bool old_is_prototype = (TREE_CODE (olddecl) == FUNCTION_DECL | 2161 bool old_is_prototype = (TREE_CODE (olddecl) == FUNCTION_DECL |
2129 && TYPE_ARG_TYPES (TREE_TYPE (olddecl)) != 0); | 2162 && prototype_p (TREE_TYPE (olddecl))); |
2130 bool extern_changed = false; | 2163 bool extern_changed = false; |
2131 | 2164 |
2132 /* For real parm decl following a forward decl, rechain the old decl | 2165 /* For real parm decl following a forward decl, rechain the old decl |
2133 in its new location and clear TREE_ASM_WRITTEN (it's not a | 2166 in its new location and clear TREE_ASM_WRITTEN (it's not a |
2134 forward decl anymore). */ | 2167 forward decl anymore). */ |
2368 DECL_RESULT (newdecl) = DECL_RESULT (olddecl); | 2401 DECL_RESULT (newdecl) = DECL_RESULT (olddecl); |
2369 DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl); | 2402 DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl); |
2370 DECL_STRUCT_FUNCTION (newdecl) = DECL_STRUCT_FUNCTION (olddecl); | 2403 DECL_STRUCT_FUNCTION (newdecl) = DECL_STRUCT_FUNCTION (olddecl); |
2371 DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl); | 2404 DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl); |
2372 DECL_ARGUMENTS (newdecl) = copy_list (DECL_ARGUMENTS (olddecl)); | 2405 DECL_ARGUMENTS (newdecl) = copy_list (DECL_ARGUMENTS (olddecl)); |
2373 for (t = DECL_ARGUMENTS (newdecl); t ; t = TREE_CHAIN (t)) | 2406 for (t = DECL_ARGUMENTS (newdecl); t ; t = DECL_CHAIN (t)) |
2374 DECL_CONTEXT (t) = newdecl; | 2407 DECL_CONTEXT (t) = newdecl; |
2375 | 2408 |
2376 /* See if we've got a function to instantiate from. */ | 2409 /* See if we've got a function to instantiate from. */ |
2377 if (DECL_SAVED_TREE (olddecl)) | 2410 if (DECL_SAVED_TREE (olddecl)) |
2378 DECL_ABSTRACT_ORIGIN (newdecl) | 2411 DECL_ABSTRACT_ORIGIN (newdecl) |
2945 error_at (loc, "%qE undeclared here (not in a function)", id); | 2978 error_at (loc, "%qE undeclared here (not in a function)", id); |
2946 scope = current_scope; | 2979 scope = current_scope; |
2947 } | 2980 } |
2948 else | 2981 else |
2949 { | 2982 { |
2950 error_at (loc, "%qE undeclared (first use in this function)", id); | 2983 if (!objc_diagnose_private_ivar (id)) |
2984 error_at (loc, "%qE undeclared (first use in this function)", id); | |
2951 if (!already) | 2985 if (!already) |
2952 { | 2986 { |
2953 inform (loc, "each undeclared identifier is reported only" | 2987 inform (loc, "each undeclared identifier is reported only" |
2954 " once for each function it appears in"); | 2988 " once for each function it appears in"); |
2955 already = true; | 2989 already = true; |
2975 struct c_label_vars *label_vars; | 3009 struct c_label_vars *label_vars; |
2976 | 3010 |
2977 DECL_CONTEXT (label) = current_function_decl; | 3011 DECL_CONTEXT (label) = current_function_decl; |
2978 DECL_MODE (label) = VOIDmode; | 3012 DECL_MODE (label) = VOIDmode; |
2979 | 3013 |
2980 label_vars = GGC_NEW (struct c_label_vars); | 3014 label_vars = ggc_alloc_c_label_vars (); |
2981 label_vars->shadowed = NULL; | 3015 label_vars->shadowed = NULL; |
2982 set_spot_bindings (&label_vars->label_bindings, defining); | 3016 set_spot_bindings (&label_vars->label_bindings, defining); |
2983 label_vars->decls_in_scope = make_tree_vector (); | 3017 label_vars->decls_in_scope = make_tree_vector (); |
2984 label_vars->gotos = VEC_alloc (c_goto_bindings_p, gc, 0); | 3018 label_vars->gotos = VEC_alloc (c_goto_bindings_p, gc, 0); |
2985 *p_label_vars = label_vars; | 3019 *p_label_vars = label_vars; |
2996 lookup_label (tree name) | 3030 lookup_label (tree name) |
2997 { | 3031 { |
2998 tree label; | 3032 tree label; |
2999 struct c_label_vars *label_vars; | 3033 struct c_label_vars *label_vars; |
3000 | 3034 |
3001 if (current_function_decl == 0) | 3035 if (current_function_scope == 0) |
3002 { | 3036 { |
3003 error ("label %qE referenced outside of any function", name); | 3037 error ("label %qE referenced outside of any function", name); |
3004 return 0; | 3038 return 0; |
3005 } | 3039 } |
3006 | 3040 |
3073 list for possible later warnings. */ | 3107 list for possible later warnings. */ |
3074 if (label_vars->label_bindings.scope == NULL) | 3108 if (label_vars->label_bindings.scope == NULL) |
3075 { | 3109 { |
3076 struct c_goto_bindings *g; | 3110 struct c_goto_bindings *g; |
3077 | 3111 |
3078 g = GGC_NEW (struct c_goto_bindings); | 3112 g = ggc_alloc_c_goto_bindings (); |
3079 g->loc = loc; | 3113 g->loc = loc; |
3080 set_spot_bindings (&g->goto_bindings, true); | 3114 set_spot_bindings (&g->goto_bindings, true); |
3081 VEC_safe_push (c_goto_bindings_p, gc, label_vars->gotos, g); | 3115 VEC_safe_push (c_goto_bindings_p, gc, label_vars->gotos, g); |
3082 return label; | 3116 return label; |
3083 } | 3117 } |
3088 int i = 1; | 3122 int i = 1; |
3089 lab: | 3123 lab: |
3090 ... | 3124 ... |
3091 goto lab; | 3125 goto lab; |
3092 Issue a warning or error. */ | 3126 Issue a warning or error. */ |
3093 for (ix = 0; VEC_iterate (tree, label_vars->decls_in_scope, ix, decl); ++ix) | 3127 FOR_EACH_VEC_ELT (tree, label_vars->decls_in_scope, ix, decl) |
3094 warn_about_goto (loc, label, decl); | 3128 warn_about_goto (loc, label, decl); |
3095 | 3129 |
3096 if (label_vars->label_bindings.left_stmt_expr) | 3130 if (label_vars->label_bindings.left_stmt_expr) |
3097 { | 3131 { |
3098 error_at (loc, "jump into statement expression"); | 3132 error_at (loc, "jump into statement expression"); |
3140 check_earlier_gotos (tree label, struct c_label_vars* label_vars) | 3174 check_earlier_gotos (tree label, struct c_label_vars* label_vars) |
3141 { | 3175 { |
3142 unsigned int ix; | 3176 unsigned int ix; |
3143 struct c_goto_bindings *g; | 3177 struct c_goto_bindings *g; |
3144 | 3178 |
3145 for (ix = 0; | 3179 FOR_EACH_VEC_ELT (c_goto_bindings_p, label_vars->gotos, ix, g) |
3146 VEC_iterate (c_goto_bindings_p, label_vars->gotos, ix, g); | |
3147 ++ix) | |
3148 { | 3180 { |
3149 struct c_binding *b; | 3181 struct c_binding *b; |
3150 struct c_scope *scope; | 3182 struct c_scope *scope; |
3151 | 3183 |
3152 /* We have a goto to this label. The goto is going forward. In | 3184 /* We have a goto to this label. The goto is going forward. In |
3153 g->scope, the goto is going to skip any binding which was | 3185 g->scope, the goto is going to skip any binding which was |
3154 defined after g->bindings_in_scope. */ | 3186 defined after g->bindings_in_scope. */ |
3155 for (b = g->goto_bindings.scope->bindings; | 3187 if (g->goto_bindings.scope->has_jump_unsafe_decl) |
3156 b != g->goto_bindings.bindings_in_scope; | 3188 { |
3157 b = b->prev) | 3189 for (b = g->goto_bindings.scope->bindings; |
3158 { | 3190 b != g->goto_bindings.bindings_in_scope; |
3159 if (decl_jump_unsafe (b->decl)) | 3191 b = b->prev) |
3160 warn_about_goto (g->loc, label, b->decl); | 3192 { |
3193 if (decl_jump_unsafe (b->decl)) | |
3194 warn_about_goto (g->loc, label, b->decl); | |
3195 } | |
3161 } | 3196 } |
3162 | 3197 |
3163 /* We also need to warn about decls defined in any scopes | 3198 /* We also need to warn about decls defined in any scopes |
3164 between the scope of the label and the scope of the goto. */ | 3199 between the scope of the label and the scope of the goto. */ |
3165 for (scope = label_vars->label_bindings.scope; | 3200 for (scope = label_vars->label_bindings.scope; |
3166 scope != g->goto_bindings.scope; | 3201 scope != g->goto_bindings.scope; |
3167 scope = scope->outer) | 3202 scope = scope->outer) |
3168 { | 3203 { |
3169 gcc_assert (scope != NULL); | 3204 gcc_assert (scope != NULL); |
3170 if (scope == label_vars->label_bindings.scope) | 3205 if (scope->has_jump_unsafe_decl) |
3171 b = label_vars->label_bindings.bindings_in_scope; | |
3172 else | |
3173 b = scope->bindings; | |
3174 for (; b != NULL; b = b->prev) | |
3175 { | 3206 { |
3176 if (decl_jump_unsafe (b->decl)) | 3207 if (scope == label_vars->label_bindings.scope) |
3177 warn_about_goto (g->loc, label, b->decl); | 3208 b = label_vars->label_bindings.bindings_in_scope; |
3209 else | |
3210 b = scope->bindings; | |
3211 for (; b != NULL; b = b->prev) | |
3212 { | |
3213 if (decl_jump_unsafe (b->decl)) | |
3214 warn_about_goto (g->loc, label, b->decl); | |
3215 } | |
3178 } | 3216 } |
3179 } | 3217 } |
3180 | 3218 |
3181 if (g->goto_bindings.stmt_exprs > 0) | 3219 if (g->goto_bindings.stmt_exprs > 0) |
3182 { | 3220 { |
3288 scope = scope->outer) | 3326 scope = scope->outer) |
3289 { | 3327 { |
3290 struct c_binding *b; | 3328 struct c_binding *b; |
3291 | 3329 |
3292 gcc_assert (scope != NULL); | 3330 gcc_assert (scope != NULL); |
3331 | |
3332 if (!scope->has_jump_unsafe_decl) | |
3333 continue; | |
3334 | |
3293 for (b = scope->bindings; b != NULL; b = b->prev) | 3335 for (b = scope->bindings; b != NULL; b = b->prev) |
3294 { | 3336 { |
3295 if (decl_jump_unsafe (b->decl)) | 3337 if (decl_jump_unsafe (b->decl)) |
3296 { | 3338 { |
3297 if (variably_modified_type_p (TREE_TYPE (b->decl), NULL_TREE)) | 3339 if (variably_modified_type_p (TREE_TYPE (b->decl), NULL_TREE)) |
3504 const char* p = __FUNCTION__; | 3546 const char* p = __FUNCTION__; |
3505 | 3547 |
3506 the __FUNCTION__ is believed to appear in K&R style function | 3548 the __FUNCTION__ is believed to appear in K&R style function |
3507 parameter declarator. In that case we still don't have | 3549 parameter declarator. In that case we still don't have |
3508 function_scope. */ | 3550 function_scope. */ |
3509 && (!errorcount || current_function_scope)) | 3551 && (!seen_error () || current_function_scope)) |
3510 { | 3552 { |
3511 DECL_CONTEXT (decl) = current_function_decl; | 3553 DECL_CONTEXT (decl) = current_function_decl; |
3512 bind (id, decl, current_function_scope, | 3554 bind (id, decl, current_function_scope, |
3513 /*invisible=*/false, /*nested=*/false, UNKNOWN_LOCATION); | 3555 /*invisible=*/false, /*nested=*/false, UNKNOWN_LOCATION); |
3514 } | 3556 } |
3523 { | 3565 { |
3524 tree type = TREE_TYPE (decl); | 3566 tree type = TREE_TYPE (decl); |
3525 tree id = DECL_NAME (decl); | 3567 tree id = DECL_NAME (decl); |
3526 | 3568 |
3527 const char *name = IDENTIFIER_POINTER (id); | 3569 const char *name = IDENTIFIER_POINTER (id); |
3528 C_DECL_BUILTIN_PROTOTYPE (decl) = (TYPE_ARG_TYPES (type) != 0); | 3570 C_DECL_BUILTIN_PROTOTYPE (decl) = prototype_p (type); |
3529 | 3571 |
3530 /* Should never be called on a symbol with a preexisting meaning. */ | 3572 /* Should never be called on a symbol with a preexisting meaning. */ |
3531 gcc_assert (!I_SYMBOL_BINDING (id)); | 3573 gcc_assert (!I_SYMBOL_BINDING (id)); |
3532 | 3574 |
3533 bind (id, decl, external_scope, /*invisible=*/true, /*nested=*/false, | 3575 bind (id, decl, external_scope, /*invisible=*/true, /*nested=*/false, |
3535 | 3577 |
3536 /* Builtins in the implementation namespace are made visible without | 3578 /* Builtins in the implementation namespace are made visible without |
3537 needing to be explicitly declared. See push_file_scope. */ | 3579 needing to be explicitly declared. See push_file_scope. */ |
3538 if (name[0] == '_' && (name[1] == '_' || ISUPPER (name[1]))) | 3580 if (name[0] == '_' && (name[1] == '_' || ISUPPER (name[1]))) |
3539 { | 3581 { |
3540 TREE_CHAIN (decl) = visible_builtins; | 3582 DECL_CHAIN (decl) = visible_builtins; |
3541 visible_builtins = decl; | 3583 visible_builtins = decl; |
3542 } | 3584 } |
3543 | 3585 |
3544 return decl; | 3586 return decl; |
3545 } | 3587 } |
3549 { | 3591 { |
3550 tree type = TREE_TYPE (decl); | 3592 tree type = TREE_TYPE (decl); |
3551 tree id = DECL_NAME (decl); | 3593 tree id = DECL_NAME (decl); |
3552 | 3594 |
3553 const char *name = IDENTIFIER_POINTER (id); | 3595 const char *name = IDENTIFIER_POINTER (id); |
3554 C_DECL_BUILTIN_PROTOTYPE (decl) = (TYPE_ARG_TYPES (type) != 0); | 3596 C_DECL_BUILTIN_PROTOTYPE (decl) = prototype_p (type); |
3555 | 3597 |
3556 /* Should never be called on a symbol with a preexisting meaning. */ | 3598 /* Should never be called on a symbol with a preexisting meaning. */ |
3557 gcc_assert (!I_SYMBOL_BINDING (id)); | 3599 gcc_assert (!I_SYMBOL_BINDING (id)); |
3558 | 3600 |
3559 bind (id, decl, external_scope, /*invisible=*/false, /*nested=*/false, | 3601 bind (id, decl, external_scope, /*invisible=*/false, /*nested=*/false, |
3561 | 3603 |
3562 /* Builtins in the implementation namespace are made visible without | 3604 /* Builtins in the implementation namespace are made visible without |
3563 needing to be explicitly declared. See push_file_scope. */ | 3605 needing to be explicitly declared. See push_file_scope. */ |
3564 if (name[0] == '_' && (name[1] == '_' || ISUPPER (name[1]))) | 3606 if (name[0] == '_' && (name[1] == '_' || ISUPPER (name[1]))) |
3565 { | 3607 { |
3566 TREE_CHAIN (decl) = visible_builtins; | 3608 DECL_CHAIN (decl) = visible_builtins; |
3567 visible_builtins = decl; | 3609 visible_builtins = decl; |
3568 } | 3610 } |
3569 | 3611 |
3570 return decl; | 3612 return decl; |
3571 } | 3613 } |
3619 pedwarn (input_location, 0, | 3661 pedwarn (input_location, 0, |
3620 "unnamed struct/union that defines no instances"); | 3662 "unnamed struct/union that defines no instances"); |
3621 warned = 1; | 3663 warned = 1; |
3622 } | 3664 } |
3623 } | 3665 } |
3624 else if (!declspecs->tag_defined_p | 3666 else if (declspecs->typespec_kind != ctsk_tagdef |
3667 && declspecs->typespec_kind != ctsk_tagfirstref | |
3625 && declspecs->storage_class != csc_none) | 3668 && declspecs->storage_class != csc_none) |
3626 { | 3669 { |
3627 if (warned != 1) | 3670 if (warned != 1) |
3628 pedwarn (input_location, 0, | 3671 pedwarn (input_location, 0, |
3629 "empty declaration with storage class specifier " | 3672 "empty declaration with storage class specifier " |
3630 "does not redeclare tag"); | 3673 "does not redeclare tag"); |
3631 warned = 1; | 3674 warned = 1; |
3632 pending_xref_error (); | 3675 pending_xref_error (); |
3633 } | 3676 } |
3634 else if (!declspecs->tag_defined_p | 3677 else if (declspecs->typespec_kind != ctsk_tagdef |
3678 && declspecs->typespec_kind != ctsk_tagfirstref | |
3635 && (declspecs->const_p | 3679 && (declspecs->const_p |
3636 || declspecs->volatile_p | 3680 || declspecs->volatile_p |
3637 || declspecs->restrict_p | 3681 || declspecs->restrict_p |
3638 || declspecs->address_space)) | 3682 || declspecs->address_space)) |
3639 { | 3683 { |
3983 | 4027 |
3984 /* If this is a function declaration, write a record describing it to the | 4028 /* If this is a function declaration, write a record describing it to the |
3985 prototypes file (if requested). */ | 4029 prototypes file (if requested). */ |
3986 | 4030 |
3987 if (TREE_CODE (decl) == FUNCTION_DECL) | 4031 if (TREE_CODE (decl) == FUNCTION_DECL) |
3988 gen_aux_info_record (decl, 0, 0, TYPE_ARG_TYPES (TREE_TYPE (decl)) != 0); | 4032 gen_aux_info_record (decl, 0, 0, prototype_p (TREE_TYPE (decl))); |
3989 | 4033 |
3990 /* ANSI specifies that a tentative definition which is not merged with | 4034 /* ANSI specifies that a tentative definition which is not merged with |
3991 a non-tentative definition behaves exactly like a definition with an | 4035 a non-tentative definition behaves exactly like a definition with an |
3992 initializer equal to zero. (Section 3.7.2) | 4036 initializer equal to zero. (Section 3.7.2) |
3993 | 4037 |
4029 if (ce->kind == cdk_pointer) | 4073 if (ce->kind == cdk_pointer) |
4030 ce = declarator->declarator; | 4074 ce = declarator->declarator; |
4031 if (ce->kind == cdk_function) | 4075 if (ce->kind == cdk_function) |
4032 { | 4076 { |
4033 tree args = ce->u.arg_info->parms; | 4077 tree args = ce->u.arg_info->parms; |
4034 for (; args; args = TREE_CHAIN (args)) | 4078 for (; args; args = DECL_CHAIN (args)) |
4035 { | 4079 { |
4036 tree type = TREE_TYPE (args); | 4080 tree type = TREE_TYPE (args); |
4037 if (type && INTEGRAL_TYPE_P (type) | 4081 if (type && INTEGRAL_TYPE_P (type) |
4038 && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)) | 4082 && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)) |
4039 DECL_ARG_TYPE (args) = integer_type_node; | 4083 DECL_ARG_TYPE (args) = integer_type_node; |
4058 && DECL_DECLARED_INLINE_P (current_function_decl) | 4102 && DECL_DECLARED_INLINE_P (current_function_decl) |
4059 && DECL_EXTERNAL (current_function_decl)) | 4103 && DECL_EXTERNAL (current_function_decl)) |
4060 record_inline_static (input_location, current_function_decl, | 4104 record_inline_static (input_location, current_function_decl, |
4061 decl, csi_modifiable); | 4105 decl, csi_modifiable); |
4062 | 4106 |
4107 if (c_dialect_objc () | |
4108 && (TREE_CODE (decl) == VAR_DECL | |
4109 || TREE_CODE (decl) == FUNCTION_DECL)) | |
4110 objc_check_global_decl (decl); | |
4111 | |
4063 /* Add this decl to the current scope. | 4112 /* Add this decl to the current scope. |
4064 TEM may equal DECL or it may be a previous decl of the same name. */ | 4113 TEM may equal DECL or it may be a previous decl of the same name. */ |
4065 tem = pushdecl (decl); | 4114 tem = pushdecl (decl); |
4066 | 4115 |
4067 if (initialized && DECL_EXTERNAL (tem)) | 4116 if (initialized && DECL_EXTERNAL (tem)) |
4069 DECL_EXTERNAL (tem) = 0; | 4118 DECL_EXTERNAL (tem) = 0; |
4070 TREE_STATIC (tem) = 1; | 4119 TREE_STATIC (tem) = 1; |
4071 } | 4120 } |
4072 | 4121 |
4073 return tem; | 4122 return tem; |
4123 } | |
4124 | |
4125 /* Subroutine of finish_decl. TYPE is the type of an uninitialized object | |
4126 DECL or the non-array element type if DECL is an uninitialized array. | |
4127 If that type has a const member, diagnose this. */ | |
4128 | |
4129 static void | |
4130 diagnose_uninitialized_cst_member (tree decl, tree type) | |
4131 { | |
4132 tree field; | |
4133 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field)) | |
4134 { | |
4135 tree field_type; | |
4136 if (TREE_CODE (field) != FIELD_DECL) | |
4137 continue; | |
4138 field_type = strip_array_types (TREE_TYPE (field)); | |
4139 | |
4140 if (TYPE_QUALS (field_type) & TYPE_QUAL_CONST) | |
4141 { | |
4142 warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wc___compat, | |
4143 "uninitialized const member in %qT is invalid in C++", | |
4144 strip_array_types (TREE_TYPE (decl))); | |
4145 inform (DECL_SOURCE_LOCATION (field), "%qD should be initialized", field); | |
4146 } | |
4147 | |
4148 if (TREE_CODE (field_type) == RECORD_TYPE | |
4149 || TREE_CODE (field_type) == UNION_TYPE) | |
4150 diagnose_uninitialized_cst_member (decl, field_type); | |
4151 } | |
4074 } | 4152 } |
4075 | 4153 |
4076 /* Finish processing of a declaration; | 4154 /* Finish processing of a declaration; |
4077 install its initial value. | 4155 install its initial value. |
4078 If ORIGTYPE is not NULL_TREE, it is the original type of INIT. | 4156 If ORIGTYPE is not NULL_TREE, it is the original type of INIT. |
4388 } | 4466 } |
4389 } | 4467 } |
4390 | 4468 |
4391 if (warn_cxx_compat | 4469 if (warn_cxx_compat |
4392 && TREE_CODE (decl) == VAR_DECL | 4470 && TREE_CODE (decl) == VAR_DECL |
4393 && TREE_READONLY (decl) | |
4394 && !DECL_EXTERNAL (decl) | 4471 && !DECL_EXTERNAL (decl) |
4395 && DECL_INITIAL (decl) == NULL_TREE) | 4472 && DECL_INITIAL (decl) == NULL_TREE) |
4396 warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wc___compat, | 4473 { |
4397 "uninitialized const %qD is invalid in C++", decl); | 4474 type = strip_array_types (type); |
4475 if (TREE_READONLY (decl)) | |
4476 warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wc___compat, | |
4477 "uninitialized const %qD is invalid in C++", decl); | |
4478 else if ((TREE_CODE (type) == RECORD_TYPE | |
4479 || TREE_CODE (type) == UNION_TYPE) | |
4480 && C_TYPE_FIELDS_READONLY (type)) | |
4481 diagnose_uninitialized_cst_member (decl, type); | |
4482 } | |
4398 } | 4483 } |
4399 | 4484 |
4400 /* Given a parsed parameter declaration, decode it into a PARM_DECL. */ | 4485 /* Given a parsed parameter declaration, decode it into a PARM_DECL. */ |
4401 | 4486 |
4402 tree | 4487 tree |
4524 is valid for C++. */ | 4609 is valid for C++. */ |
4525 | 4610 |
4526 void | 4611 void |
4527 check_compound_literal_type (location_t loc, struct c_type_name *type_name) | 4612 check_compound_literal_type (location_t loc, struct c_type_name *type_name) |
4528 { | 4613 { |
4529 if (warn_cxx_compat && type_name->specs->tag_defined_p) | 4614 if (warn_cxx_compat |
4615 && (type_name->specs->typespec_kind == ctsk_tagdef | |
4616 || type_name->specs->typespec_kind == ctsk_tagfirstref)) | |
4530 warning_at (loc, OPT_Wc___compat, | 4617 warning_at (loc, OPT_Wc___compat, |
4531 "defining a type in a compound literal is invalid in C++"); | 4618 "defining a type in a compound literal is invalid in C++"); |
4532 } | 4619 } |
4533 | 4620 |
4534 /* Determine whether TYPE is a structure with a flexible array member, | 4621 /* Determine whether TYPE is a structure with a flexible array member, |
4542 { | 4629 { |
4543 case RECORD_TYPE: | 4630 case RECORD_TYPE: |
4544 x = TYPE_FIELDS (type); | 4631 x = TYPE_FIELDS (type); |
4545 if (x == NULL_TREE) | 4632 if (x == NULL_TREE) |
4546 return false; | 4633 return false; |
4547 while (TREE_CHAIN (x) != NULL_TREE) | 4634 while (DECL_CHAIN (x) != NULL_TREE) |
4548 x = TREE_CHAIN (x); | 4635 x = DECL_CHAIN (x); |
4549 if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE | 4636 if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE |
4550 && TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE | 4637 && TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE |
4551 && TYPE_DOMAIN (TREE_TYPE (x)) != NULL_TREE | 4638 && TYPE_DOMAIN (TREE_TYPE (x)) != NULL_TREE |
4552 && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (x))) == NULL_TREE) | 4639 && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (x))) == NULL_TREE) |
4553 return true; | 4640 return true; |
4554 return false; | 4641 return false; |
4555 case UNION_TYPE: | 4642 case UNION_TYPE: |
4556 for (x = TYPE_FIELDS (type); x != NULL_TREE; x = TREE_CHAIN (x)) | 4643 for (x = TYPE_FIELDS (type); x != NULL_TREE; x = DECL_CHAIN (x)) |
4557 { | 4644 { |
4558 if (flexible_array_type_p (TREE_TYPE (x))) | 4645 if (flexible_array_type_p (TREE_TYPE (x))) |
4559 return true; | 4646 return true; |
4560 } | 4647 } |
4561 return false; | 4648 return false; |
4804 location_t loc = UNKNOWN_LOCATION; | 4891 location_t loc = UNKNOWN_LOCATION; |
4805 const char *errmsg; | 4892 const char *errmsg; |
4806 tree expr_dummy; | 4893 tree expr_dummy; |
4807 bool expr_const_operands_dummy; | 4894 bool expr_const_operands_dummy; |
4808 | 4895 |
4896 if (TREE_CODE (type) == ERROR_MARK) | |
4897 return error_mark_node; | |
4809 if (expr == NULL) | 4898 if (expr == NULL) |
4810 expr = &expr_dummy; | 4899 expr = &expr_dummy; |
4811 if (expr_const_operands == NULL) | 4900 if (expr_const_operands == NULL) |
4812 expr_const_operands = &expr_const_operands_dummy; | 4901 expr_const_operands = &expr_const_operands_dummy; |
4813 | 4902 |
5398 ISO flexible array members in that sizeof yields | 5487 ISO flexible array members in that sizeof yields |
5399 zero. */ | 5488 zero. */ |
5400 if (size && integer_zerop (size)) | 5489 if (size && integer_zerop (size)) |
5401 { | 5490 { |
5402 gcc_assert (itype); | 5491 gcc_assert (itype); |
5492 type = build_distinct_type_copy (TYPE_MAIN_VARIANT (type)); | |
5403 TYPE_SIZE (type) = bitsize_zero_node; | 5493 TYPE_SIZE (type) = bitsize_zero_node; |
5404 TYPE_SIZE_UNIT (type) = size_zero_node; | 5494 TYPE_SIZE_UNIT (type) = size_zero_node; |
5405 SET_TYPE_STRUCTURAL_EQUALITY (type); | 5495 SET_TYPE_STRUCTURAL_EQUALITY (type); |
5406 } | 5496 } |
5407 if (array_parm_vla_unspec_p) | 5497 if (array_parm_vla_unspec_p) |
5408 { | 5498 { |
5409 gcc_assert (itype); | 5499 gcc_assert (itype); |
5410 /* The type is complete. C99 6.7.5.2p4 */ | 5500 /* The type is complete. C99 6.7.5.2p4 */ |
5501 type = build_distinct_type_copy (TYPE_MAIN_VARIANT (type)); | |
5411 TYPE_SIZE (type) = bitsize_zero_node; | 5502 TYPE_SIZE (type) = bitsize_zero_node; |
5412 TYPE_SIZE_UNIT (type) = size_zero_node; | 5503 TYPE_SIZE_UNIT (type) = size_zero_node; |
5413 SET_TYPE_STRUCTURAL_EQUALITY (type); | 5504 SET_TYPE_STRUCTURAL_EQUALITY (type); |
5414 } | 5505 } |
5415 } | 5506 } |
5509 | 5600 |
5510 /* Set the TYPE_CONTEXTs for each tagged type which is local to | 5601 /* Set the TYPE_CONTEXTs for each tagged type which is local to |
5511 the formal parameter list of this FUNCTION_TYPE to point to | 5602 the formal parameter list of this FUNCTION_TYPE to point to |
5512 the FUNCTION_TYPE node itself. */ | 5603 the FUNCTION_TYPE node itself. */ |
5513 { | 5604 { |
5514 tree link; | 5605 c_arg_tag *tag; |
5515 | 5606 unsigned ix; |
5516 for (link = arg_info->tags; | 5607 |
5517 link; | 5608 FOR_EACH_VEC_ELT_REVERSE (c_arg_tag, arg_info->tags, ix, tag) |
5518 link = TREE_CHAIN (link)) | 5609 TYPE_CONTEXT (tag->type) = type; |
5519 TYPE_CONTEXT (TREE_VALUE (link)) = type; | |
5520 } | 5610 } |
5521 break; | 5611 break; |
5522 } | 5612 } |
5523 case cdk_pointer: | 5613 case cdk_pointer: |
5524 { | 5614 { |
5869 | 5959 |
5870 if (pedantic && type_quals && !DECL_IN_SYSTEM_HEADER (decl)) | 5960 if (pedantic && type_quals && !DECL_IN_SYSTEM_HEADER (decl)) |
5871 pedwarn (loc, OPT_pedantic, | 5961 pedwarn (loc, OPT_pedantic, |
5872 "ISO C forbids qualified function types"); | 5962 "ISO C forbids qualified function types"); |
5873 | 5963 |
5874 /* GNU C interprets a volatile-qualified function type to indicate | |
5875 that the function does not return. */ | |
5876 if ((type_quals & TYPE_QUAL_VOLATILE) | |
5877 && !VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl)))) | |
5878 warning_at (loc, 0, "%<noreturn%> function returns non-void value"); | |
5879 | |
5880 /* Every function declaration is an external reference | 5964 /* Every function declaration is an external reference |
5881 (DECL_EXTERNAL) except for those which are not at file | 5965 (DECL_EXTERNAL) except for those which are not at file |
5882 scope and are explicitly declared "auto". This is | 5966 scope and are explicitly declared "auto". This is |
5883 forbidden by standard C (C99 6.7.1p5) and is interpreted by | 5967 forbidden by standard C (C99 6.7.1p5) and is interpreted by |
5884 GCC to signify a forward declaration of a nested function. */ | 5968 GCC to signify a forward declaration of a nested function. */ |
6076 return 0; /* don't set TYPE_ARG_TYPES in this case */ | 6160 return 0; /* don't set TYPE_ARG_TYPES in this case */ |
6077 | 6161 |
6078 else if (arg_types && TREE_CODE (TREE_VALUE (arg_types)) == IDENTIFIER_NODE) | 6162 else if (arg_types && TREE_CODE (TREE_VALUE (arg_types)) == IDENTIFIER_NODE) |
6079 { | 6163 { |
6080 if (!funcdef_flag) | 6164 if (!funcdef_flag) |
6081 pedwarn (input_location, 0, "parameter names (without types) in function declaration"); | 6165 { |
6082 | 6166 pedwarn (input_location, 0, "parameter names (without types) in function declaration"); |
6083 arg_info->parms = arg_info->types; | 6167 arg_info->parms = NULL_TREE; |
6168 } | |
6169 else | |
6170 arg_info->parms = arg_info->types; | |
6171 | |
6084 arg_info->types = 0; | 6172 arg_info->types = 0; |
6085 return 0; | 6173 return 0; |
6086 } | 6174 } |
6087 else | 6175 else |
6088 { | 6176 { |
6099 however the function cannot be defined or called, so | 6187 however the function cannot be defined or called, so |
6100 warn. */ | 6188 warn. */ |
6101 | 6189 |
6102 for (parm = arg_info->parms, typelt = arg_types, parmno = 1; | 6190 for (parm = arg_info->parms, typelt = arg_types, parmno = 1; |
6103 parm; | 6191 parm; |
6104 parm = TREE_CHAIN (parm), typelt = TREE_CHAIN (typelt), parmno++) | 6192 parm = DECL_CHAIN (parm), typelt = TREE_CHAIN (typelt), parmno++) |
6105 { | 6193 { |
6106 type = TREE_VALUE (typelt); | 6194 type = TREE_VALUE (typelt); |
6107 if (type == error_mark_node) | 6195 if (type == error_mark_node) |
6108 continue; | 6196 continue; |
6109 | 6197 |
6151 } | 6239 } |
6152 return arg_types; | 6240 return arg_types; |
6153 } | 6241 } |
6154 } | 6242 } |
6155 | 6243 |
6244 /* Allocate and initialize a c_arg_info structure from the parser's | |
6245 obstack. */ | |
6246 | |
6247 struct c_arg_info * | |
6248 build_arg_info (void) | |
6249 { | |
6250 struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info); | |
6251 ret->parms = NULL_TREE; | |
6252 ret->tags = NULL; | |
6253 ret->types = NULL_TREE; | |
6254 ret->others = NULL_TREE; | |
6255 ret->pending_sizes = NULL; | |
6256 ret->had_vla_unspec = 0; | |
6257 return ret; | |
6258 } | |
6259 | |
6156 /* Take apart the current scope and return a c_arg_info structure with | 6260 /* Take apart the current scope and return a c_arg_info structure with |
6157 info on a parameter list just parsed. | 6261 info on a parameter list just parsed. |
6158 | 6262 |
6159 This structure is later fed to 'grokparms' and 'store_parm_decls'. | 6263 This structure is later fed to 'grokparms' and 'store_parm_decls'. |
6160 | 6264 |
6163 | 6267 |
6164 struct c_arg_info * | 6268 struct c_arg_info * |
6165 get_parm_info (bool ellipsis) | 6269 get_parm_info (bool ellipsis) |
6166 { | 6270 { |
6167 struct c_binding *b = current_scope->bindings; | 6271 struct c_binding *b = current_scope->bindings; |
6168 struct c_arg_info *arg_info = XOBNEW (&parser_obstack, | 6272 struct c_arg_info *arg_info = build_arg_info (); |
6169 struct c_arg_info); | 6273 |
6170 tree parms = 0; | 6274 tree parms = 0; |
6171 tree tags = 0; | 6275 VEC(c_arg_tag,gc) *tags = NULL; |
6172 tree types = 0; | 6276 tree types = 0; |
6173 tree others = 0; | 6277 tree others = 0; |
6174 | 6278 |
6175 static bool explained_incomplete_types = false; | 6279 static bool explained_incomplete_types = false; |
6176 bool gave_void_only_once_err = false; | 6280 bool gave_void_only_once_err = false; |
6177 | 6281 |
6178 arg_info->parms = 0; | |
6179 arg_info->tags = 0; | |
6180 arg_info->types = 0; | |
6181 arg_info->others = 0; | |
6182 arg_info->pending_sizes = 0; | |
6183 arg_info->had_vla_unspec = current_scope->had_vla_unspec; | 6282 arg_info->had_vla_unspec = current_scope->had_vla_unspec; |
6184 | 6283 |
6185 /* The bindings in this scope must not get put into a block. | 6284 /* The bindings in this scope must not get put into a block. |
6186 We will take care of deleting the binding nodes. */ | 6285 We will take care of deleting the binding nodes. */ |
6187 current_scope->bindings = 0; | 6286 current_scope->bindings = 0; |
6220 apply sanity checks; purge the name-to-decl bindings. */ | 6319 apply sanity checks; purge the name-to-decl bindings. */ |
6221 while (b) | 6320 while (b) |
6222 { | 6321 { |
6223 tree decl = b->decl; | 6322 tree decl = b->decl; |
6224 tree type = TREE_TYPE (decl); | 6323 tree type = TREE_TYPE (decl); |
6324 c_arg_tag *tag; | |
6225 const char *keyword; | 6325 const char *keyword; |
6226 | 6326 |
6227 switch (TREE_CODE (decl)) | 6327 switch (TREE_CODE (decl)) |
6228 { | 6328 { |
6229 case PARM_DECL: | 6329 case PARM_DECL: |
6246 } | 6346 } |
6247 } | 6347 } |
6248 else | 6348 else |
6249 { | 6349 { |
6250 /* Valid parameter, add it to the list. */ | 6350 /* Valid parameter, add it to the list. */ |
6251 TREE_CHAIN (decl) = parms; | 6351 DECL_CHAIN (decl) = parms; |
6252 parms = decl; | 6352 parms = decl; |
6253 | 6353 |
6254 /* Since there is a prototype, args are passed in their | 6354 /* Since there is a prototype, args are passed in their |
6255 declared types. The back end may override this later. */ | 6355 declared types. The back end may override this later. */ |
6256 DECL_ARG_TYPE (decl) = type; | 6356 DECL_ARG_TYPE (decl) = type; |
6293 " which is probably not what you want"); | 6393 " which is probably not what you want"); |
6294 explained_incomplete_types = true; | 6394 explained_incomplete_types = true; |
6295 } | 6395 } |
6296 } | 6396 } |
6297 | 6397 |
6298 tags = tree_cons (b->id, decl, tags); | 6398 tag = VEC_safe_push (c_arg_tag, gc, tags, NULL); |
6399 tag->id = b->id; | |
6400 tag->type = decl; | |
6299 break; | 6401 break; |
6300 | 6402 |
6301 case CONST_DECL: | 6403 case CONST_DECL: |
6302 case TYPE_DECL: | 6404 case TYPE_DECL: |
6303 case FUNCTION_DECL: | 6405 case FUNCTION_DECL: |
6310 /* When we reinsert this decl in the function body, we need | 6412 /* When we reinsert this decl in the function body, we need |
6311 to reconstruct whether it was marked as nested. */ | 6413 to reconstruct whether it was marked as nested. */ |
6312 gcc_assert (TREE_CODE (decl) == FUNCTION_DECL | 6414 gcc_assert (TREE_CODE (decl) == FUNCTION_DECL |
6313 ? b->nested | 6415 ? b->nested |
6314 : !b->nested); | 6416 : !b->nested); |
6315 TREE_CHAIN (decl) = others; | 6417 DECL_CHAIN (decl) = others; |
6316 others = decl; | 6418 others = decl; |
6317 /* fall through */ | 6419 /* fall through */ |
6318 | 6420 |
6319 case ERROR_MARK: | 6421 case ERROR_MARK: |
6320 /* error_mark_node appears here when we have an undeclared | 6422 /* error_mark_node appears here when we have an undeclared |
6550 | 6652 |
6551 If we have something of the form "union { list } ;" then this | 6653 If we have something of the form "union { list } ;" then this |
6552 is the anonymous union extension. Similarly for struct. | 6654 is the anonymous union extension. Similarly for struct. |
6553 | 6655 |
6554 If this is something of the form "struct foo;", then | 6656 If this is something of the form "struct foo;", then |
6555 If MS extensions are enabled, this is handled as an | 6657 If MS or Plan 9 extensions are enabled, this is handled as |
6556 anonymous struct. | 6658 an anonymous struct. |
6557 Otherwise this is a forward declaration of a structure tag. | 6659 Otherwise this is a forward declaration of a structure tag. |
6558 | 6660 |
6559 If this is something of the form "foo;" and foo is a TYPE_DECL, then | 6661 If this is something of the form "foo;" and foo is a TYPE_DECL, then |
6560 If foo names a structure or union without a tag, then this | 6662 If foo names a structure or union without a tag, then this |
6561 is an anonymous struct (this is permitted by C1X). | 6663 is an anonymous struct (this is permitted by C1X). |
6562 If MS extensions are enabled and foo names a structure, then | 6664 If MS or Plan 9 extensions are enabled and foo names a |
6563 again this is an anonymous struct. | 6665 structure, then again this is an anonymous struct. |
6564 Otherwise this is an error. | 6666 Otherwise this is an error. |
6565 | 6667 |
6566 Oh what a horrid tangled web we weave. I wonder if MS consciously | 6668 Oh what a horrid tangled web we weave. I wonder if MS consciously |
6567 took this from Plan 9 or if it was an accident of implementation | 6669 took this from Plan 9 or if it was an accident of implementation |
6568 that took root before someone noticed the bug... */ | 6670 that took root before someone noticed the bug... */ |
6572 || TREE_CODE (type) == UNION_TYPE); | 6674 || TREE_CODE (type) == UNION_TYPE); |
6573 bool ok = false; | 6675 bool ok = false; |
6574 | 6676 |
6575 if (type_ok) | 6677 if (type_ok) |
6576 { | 6678 { |
6577 if (flag_ms_extensions) | 6679 if (flag_ms_extensions || flag_plan9_extensions) |
6578 ok = true; | 6680 ok = true; |
6579 else if (TYPE_NAME (TYPE_MAIN_VARIANT (type)) == NULL) | 6681 else if (TYPE_NAME (TYPE_MAIN_VARIANT (type)) == NULL) |
6580 ok = true; | 6682 ok = true; |
6581 else | 6683 else |
6582 ok = false; | 6684 ok = false; |
6624 } | 6726 } |
6625 | 6727 |
6626 return value; | 6728 return value; |
6627 } | 6729 } |
6628 | 6730 |
6731 /* Subroutine of detect_field_duplicates: return whether X and Y, | |
6732 which are both fields in the same struct, have duplicate field | |
6733 names. */ | |
6734 | |
6735 static bool | |
6736 is_duplicate_field (tree x, tree y) | |
6737 { | |
6738 if (DECL_NAME (x) != NULL_TREE && DECL_NAME (x) == DECL_NAME (y)) | |
6739 return true; | |
6740 | |
6741 /* When using -fplan9-extensions, an anonymous field whose name is a | |
6742 typedef can duplicate a field name. */ | |
6743 if (flag_plan9_extensions | |
6744 && (DECL_NAME (x) == NULL_TREE || DECL_NAME (y) == NULL_TREE)) | |
6745 { | |
6746 tree xt, xn, yt, yn; | |
6747 | |
6748 xt = TREE_TYPE (x); | |
6749 if (DECL_NAME (x) != NULL_TREE) | |
6750 xn = DECL_NAME (x); | |
6751 else if ((TREE_CODE (xt) == RECORD_TYPE || TREE_CODE (xt) == UNION_TYPE) | |
6752 && TYPE_NAME (xt) != NULL_TREE | |
6753 && TREE_CODE (TYPE_NAME (xt)) == TYPE_DECL) | |
6754 xn = DECL_NAME (TYPE_NAME (xt)); | |
6755 else | |
6756 xn = NULL_TREE; | |
6757 | |
6758 yt = TREE_TYPE (y); | |
6759 if (DECL_NAME (y) != NULL_TREE) | |
6760 yn = DECL_NAME (y); | |
6761 else if ((TREE_CODE (yt) == RECORD_TYPE || TREE_CODE (yt) == UNION_TYPE) | |
6762 && TYPE_NAME (yt) != NULL_TREE | |
6763 && TREE_CODE (TYPE_NAME (yt)) == TYPE_DECL) | |
6764 yn = DECL_NAME (TYPE_NAME (yt)); | |
6765 else | |
6766 yn = NULL_TREE; | |
6767 | |
6768 if (xn != NULL_TREE && xn == yn) | |
6769 return true; | |
6770 } | |
6771 | |
6772 return false; | |
6773 } | |
6774 | |
6629 /* Subroutine of detect_field_duplicates: add the fields of FIELDLIST | 6775 /* Subroutine of detect_field_duplicates: add the fields of FIELDLIST |
6630 to HTAB, giving errors for any duplicates. */ | 6776 to HTAB, giving errors for any duplicates. */ |
6631 | 6777 |
6632 static void | 6778 static void |
6633 detect_field_duplicates_hash (tree fieldlist, htab_t htab) | 6779 detect_field_duplicates_hash (tree fieldlist, htab_t htab) |
6634 { | 6780 { |
6635 tree x, y; | 6781 tree x, y; |
6636 void **slot; | 6782 void **slot; |
6637 | 6783 |
6638 for (x = fieldlist; x ; x = TREE_CHAIN (x)) | 6784 for (x = fieldlist; x ; x = DECL_CHAIN (x)) |
6639 if ((y = DECL_NAME (x)) != 0) | 6785 if ((y = DECL_NAME (x)) != 0) |
6640 { | 6786 { |
6641 slot = htab_find_slot (htab, y, INSERT); | 6787 slot = htab_find_slot (htab, y, INSERT); |
6642 if (*slot) | 6788 if (*slot) |
6643 { | 6789 { |
6646 } | 6792 } |
6647 *slot = y; | 6793 *slot = y; |
6648 } | 6794 } |
6649 else if (TREE_CODE (TREE_TYPE (x)) == RECORD_TYPE | 6795 else if (TREE_CODE (TREE_TYPE (x)) == RECORD_TYPE |
6650 || TREE_CODE (TREE_TYPE (x)) == UNION_TYPE) | 6796 || TREE_CODE (TREE_TYPE (x)) == UNION_TYPE) |
6651 detect_field_duplicates_hash (TYPE_FIELDS (TREE_TYPE (x)), htab); | 6797 { |
6798 detect_field_duplicates_hash (TYPE_FIELDS (TREE_TYPE (x)), htab); | |
6799 | |
6800 /* When using -fplan9-extensions, an anonymous field whose | |
6801 name is a typedef can duplicate a field name. */ | |
6802 if (flag_plan9_extensions | |
6803 && TYPE_NAME (TREE_TYPE (x)) != NULL_TREE | |
6804 && TREE_CODE (TYPE_NAME (TREE_TYPE (x))) == TYPE_DECL) | |
6805 { | |
6806 tree xn = DECL_NAME (TYPE_NAME (TREE_TYPE (x))); | |
6807 slot = htab_find_slot (htab, xn, INSERT); | |
6808 if (*slot) | |
6809 error ("duplicate member %q+D", TYPE_NAME (TREE_TYPE (x))); | |
6810 *slot = xn; | |
6811 } | |
6812 } | |
6652 } | 6813 } |
6653 | 6814 |
6654 /* Generate an error for any duplicate field names in FIELDLIST. Munge | 6815 /* Generate an error for any duplicate field names in FIELDLIST. Munge |
6655 the list such that this does not present a problem later. */ | 6816 the list such that this does not present a problem later. */ |
6656 | 6817 |
6658 detect_field_duplicates (tree fieldlist) | 6819 detect_field_duplicates (tree fieldlist) |
6659 { | 6820 { |
6660 tree x, y; | 6821 tree x, y; |
6661 int timeout = 10; | 6822 int timeout = 10; |
6662 | 6823 |
6824 /* If the struct is the list of instance variables of an Objective-C | |
6825 class, then we need to add all the instance variables of | |
6826 superclasses before checking for duplicates (since you can't have | |
6827 an instance variable in a subclass with the same name as an | |
6828 instance variable in a superclass). objc_get_interface_ivars() | |
6829 leaves fieldlist unchanged if we are not in this case, so in that | |
6830 case nothing changes compared to C. | |
6831 */ | |
6832 if (c_dialect_objc ()) | |
6833 fieldlist = objc_get_interface_ivars (fieldlist); | |
6834 | |
6663 /* First, see if there are more than "a few" fields. | 6835 /* First, see if there are more than "a few" fields. |
6664 This is trivially true if there are zero or one fields. */ | 6836 This is trivially true if there are zero or one fields. */ |
6665 if (!fieldlist) | 6837 if (!fieldlist || !DECL_CHAIN (fieldlist)) |
6666 return; | 6838 return; |
6667 x = TREE_CHAIN (fieldlist); | 6839 x = fieldlist; |
6668 if (!x) | |
6669 return; | |
6670 do { | 6840 do { |
6671 timeout--; | 6841 timeout--; |
6672 if (DECL_NAME (x) == NULL_TREE | 6842 if (DECL_NAME (x) == NULL_TREE |
6673 && (TREE_CODE (TREE_TYPE (x)) == RECORD_TYPE | 6843 && (TREE_CODE (TREE_TYPE (x)) == RECORD_TYPE |
6674 || TREE_CODE (TREE_TYPE (x)) == UNION_TYPE)) | 6844 || TREE_CODE (TREE_TYPE (x)) == UNION_TYPE)) |
6675 timeout = 0; | 6845 timeout = 0; |
6676 x = TREE_CHAIN (x); | 6846 x = DECL_CHAIN (x); |
6677 } while (timeout > 0 && x); | 6847 } while (timeout > 0 && x); |
6678 | 6848 |
6679 /* If there were "few" fields and no anonymous structures or unions, | 6849 /* If there were "few" fields and no anonymous structures or unions, |
6680 avoid the overhead of allocating a hash table. Instead just do | 6850 avoid the overhead of allocating a hash table. Instead just do |
6681 the nested traversal thing. */ | 6851 the nested traversal thing. */ |
6682 if (timeout > 0) | 6852 if (timeout > 0) |
6683 { | 6853 { |
6684 for (x = TREE_CHAIN (fieldlist); x ; x = TREE_CHAIN (x)) | 6854 for (x = DECL_CHAIN (fieldlist); x; x = DECL_CHAIN (x)) |
6685 if (DECL_NAME (x)) | 6855 /* When using -fplan9-extensions, we can have duplicates |
6856 between typedef names and fields. */ | |
6857 if (DECL_NAME (x) | |
6858 || (flag_plan9_extensions | |
6859 && DECL_NAME (x) == NULL_TREE | |
6860 && (TREE_CODE (TREE_TYPE (x)) == RECORD_TYPE | |
6861 || TREE_CODE (TREE_TYPE (x)) == UNION_TYPE) | |
6862 && TYPE_NAME (TREE_TYPE (x)) != NULL_TREE | |
6863 && TREE_CODE (TYPE_NAME (TREE_TYPE (x))) == TYPE_DECL)) | |
6686 { | 6864 { |
6687 for (y = fieldlist; y != x; y = TREE_CHAIN (y)) | 6865 for (y = fieldlist; y != x; y = TREE_CHAIN (y)) |
6688 if (DECL_NAME (y) == DECL_NAME (x)) | 6866 if (is_duplicate_field (y, x)) |
6689 { | 6867 { |
6690 error ("duplicate member %q+D", x); | 6868 error ("duplicate member %q+D", x); |
6691 DECL_NAME (x) = NULL_TREE; | 6869 DECL_NAME (x) = NULL_TREE; |
6692 } | 6870 } |
6693 } | 6871 } |
6713 /* Set the C_TYPE_DEFINED_IN_STRUCT flag for each type defined in | 6891 /* Set the C_TYPE_DEFINED_IN_STRUCT flag for each type defined in |
6714 the current struct. We do this now at the end of the struct | 6892 the current struct. We do this now at the end of the struct |
6715 because the flag is used to issue visibility warnings, and we | 6893 because the flag is used to issue visibility warnings, and we |
6716 only want to issue those warnings if the type is referenced | 6894 only want to issue those warnings if the type is referenced |
6717 outside of the struct declaration. */ | 6895 outside of the struct declaration. */ |
6718 for (ix = 0; VEC_iterate (tree, struct_parse_info->struct_types, ix, x); ++ix) | 6896 FOR_EACH_VEC_ELT (tree, struct_parse_info->struct_types, ix, x) |
6719 C_TYPE_DEFINED_IN_STRUCT (x) = 1; | 6897 C_TYPE_DEFINED_IN_STRUCT (x) = 1; |
6720 | 6898 |
6721 /* The TYPEDEFS_SEEN field of STRUCT_PARSE_INFO is a list of | 6899 /* The TYPEDEFS_SEEN field of STRUCT_PARSE_INFO is a list of |
6722 typedefs used when declaring fields in this struct. If the name | 6900 typedefs used when declaring fields in this struct. If the name |
6723 of any of the fields is also a typedef name then the struct would | 6901 of any of the fields is also a typedef name then the struct would |
6729 { | 6907 { |
6730 /* Use a pointer_set using the name of the typedef. We can use | 6908 /* Use a pointer_set using the name of the typedef. We can use |
6731 a pointer_set because identifiers are interned. */ | 6909 a pointer_set because identifiers are interned. */ |
6732 struct pointer_set_t *tset = pointer_set_create (); | 6910 struct pointer_set_t *tset = pointer_set_create (); |
6733 | 6911 |
6734 for (ix = 0; | 6912 FOR_EACH_VEC_ELT (tree, struct_parse_info->typedefs_seen, ix, x) |
6735 VEC_iterate (tree, struct_parse_info->typedefs_seen, ix, x); | |
6736 ++ix) | |
6737 pointer_set_insert (tset, DECL_NAME (x)); | 6913 pointer_set_insert (tset, DECL_NAME (x)); |
6738 | 6914 |
6739 for (x = fieldlist; x != NULL_TREE; x = TREE_CHAIN (x)) | 6915 for (x = fieldlist; x != NULL_TREE; x = DECL_CHAIN (x)) |
6740 { | 6916 { |
6741 if (pointer_set_contains (tset, DECL_NAME (x))) | 6917 if (DECL_NAME (x) != NULL_TREE |
6918 && pointer_set_contains (tset, DECL_NAME (x))) | |
6742 { | 6919 { |
6743 warning_at (DECL_SOURCE_LOCATION (x), OPT_Wc___compat, | 6920 warning_at (DECL_SOURCE_LOCATION (x), OPT_Wc___compat, |
6744 ("using %qD as both field and typedef name is " | 6921 ("using %qD as both field and typedef name is " |
6745 "invalid in C++"), | 6922 "invalid in C++"), |
6746 x); | 6923 x); |
6752 pointer_set_destroy (tset); | 6929 pointer_set_destroy (tset); |
6753 } | 6930 } |
6754 | 6931 |
6755 /* For each field which has a binding and which was not defined in | 6932 /* For each field which has a binding and which was not defined in |
6756 an enclosing struct, clear the in_struct field. */ | 6933 an enclosing struct, clear the in_struct field. */ |
6757 for (ix = 0; | 6934 FOR_EACH_VEC_ELT (c_binding_ptr, struct_parse_info->fields, ix, b) |
6758 VEC_iterate (c_binding_ptr, struct_parse_info->fields, ix, b); | |
6759 ++ix) | |
6760 b->in_struct = 0; | 6935 b->in_struct = 0; |
6761 } | 6936 } |
6762 | 6937 |
6763 /* Fill in the fields of a RECORD_TYPE or UNION_TYPE node, T. | 6938 /* Fill in the fields of a RECORD_TYPE or UNION_TYPE node, T. |
6764 LOC is the location of the RECORD_TYPE or UNION_TYPE's definition. | 6939 LOC is the location of the RECORD_TYPE or UNION_TYPE's definition. |
6783 | 6958 |
6784 decl_attributes (&t, attributes, (int) ATTR_FLAG_TYPE_IN_PLACE); | 6959 decl_attributes (&t, attributes, (int) ATTR_FLAG_TYPE_IN_PLACE); |
6785 | 6960 |
6786 if (pedantic) | 6961 if (pedantic) |
6787 { | 6962 { |
6788 for (x = fieldlist; x; x = TREE_CHAIN (x)) | 6963 for (x = fieldlist; x; x = DECL_CHAIN (x)) |
6789 { | 6964 { |
6790 if (DECL_NAME (x) != 0) | 6965 if (DECL_NAME (x) != 0) |
6791 break; | 6966 break; |
6792 if (flag_isoc1x | 6967 if (flag_isoc1x |
6793 && (TREE_CODE (TREE_TYPE (x)) == RECORD_TYPE | 6968 && (TREE_CODE (TREE_TYPE (x)) == RECORD_TYPE |
6820 to its width, rather than the precision of the specified standard | 6995 to its width, rather than the precision of the specified standard |
6821 type. (Correct layout requires the original type to have been preserved | 6996 type. (Correct layout requires the original type to have been preserved |
6822 until now.) */ | 6997 until now.) */ |
6823 | 6998 |
6824 saw_named_field = 0; | 6999 saw_named_field = 0; |
6825 for (x = fieldlist; x; x = TREE_CHAIN (x)) | 7000 for (x = fieldlist; x; x = DECL_CHAIN (x)) |
6826 { | 7001 { |
6827 if (TREE_TYPE (x) == error_mark_node) | 7002 if (TREE_TYPE (x) == error_mark_node) |
6828 continue; | 7003 continue; |
6829 | 7004 |
6830 DECL_CONTEXT (x) = t; | 7005 DECL_CONTEXT (x) = t; |
6833 if (TREE_READONLY (x)) | 7008 if (TREE_READONLY (x)) |
6834 C_TYPE_FIELDS_READONLY (t) = 1; | 7009 C_TYPE_FIELDS_READONLY (t) = 1; |
6835 else | 7010 else |
6836 { | 7011 { |
6837 /* A field that is pseudo-const makes the structure likewise. */ | 7012 /* A field that is pseudo-const makes the structure likewise. */ |
6838 tree t1 = TREE_TYPE (x); | 7013 tree t1 = strip_array_types (TREE_TYPE (x)); |
6839 while (TREE_CODE (t1) == ARRAY_TYPE) | |
6840 t1 = TREE_TYPE (t1); | |
6841 if ((TREE_CODE (t1) == RECORD_TYPE || TREE_CODE (t1) == UNION_TYPE) | 7014 if ((TREE_CODE (t1) == RECORD_TYPE || TREE_CODE (t1) == UNION_TYPE) |
6842 && C_TYPE_FIELDS_READONLY (t1)) | 7015 && C_TYPE_FIELDS_READONLY (t1)) |
6843 C_TYPE_FIELDS_READONLY (t) = 1; | 7016 C_TYPE_FIELDS_READONLY (t) = 1; |
6844 } | 7017 } |
6845 | 7018 |
6875 { | 7048 { |
6876 error_at (DECL_SOURCE_LOCATION (x), | 7049 error_at (DECL_SOURCE_LOCATION (x), |
6877 "flexible array member in union"); | 7050 "flexible array member in union"); |
6878 TREE_TYPE (x) = error_mark_node; | 7051 TREE_TYPE (x) = error_mark_node; |
6879 } | 7052 } |
6880 else if (TREE_CHAIN (x) != NULL_TREE) | 7053 else if (DECL_CHAIN (x) != NULL_TREE) |
6881 { | 7054 { |
6882 error_at (DECL_SOURCE_LOCATION (x), | 7055 error_at (DECL_SOURCE_LOCATION (x), |
6883 "flexible array member not at end of struct"); | 7056 "flexible array member not at end of struct"); |
6884 TREE_TYPE (x) = error_mark_node; | 7057 TREE_TYPE (x) = error_mark_node; |
6885 } | 7058 } |
6928 DECL_MODE (*fieldlistp) = TYPE_MODE (TREE_TYPE (*fieldlistp)); | 7101 DECL_MODE (*fieldlistp) = TYPE_MODE (TREE_TYPE (*fieldlistp)); |
6929 } | 7102 } |
6930 DECL_INITIAL (*fieldlistp) = 0; | 7103 DECL_INITIAL (*fieldlistp) = 0; |
6931 } | 7104 } |
6932 else | 7105 else |
6933 fieldlistp = &TREE_CHAIN (*fieldlistp); | 7106 fieldlistp = &DECL_CHAIN (*fieldlistp); |
6934 } | 7107 } |
6935 | 7108 |
6936 /* Now we have the truly final field list. | 7109 /* Now we have the truly final field list. |
6937 Store it in this type and in the variants. */ | 7110 Store it in this type and in the variants. */ |
6938 | 7111 |
6942 We arbitrarily consider 16 or more elts to be "a lot". */ | 7115 We arbitrarily consider 16 or more elts to be "a lot". */ |
6943 | 7116 |
6944 { | 7117 { |
6945 int len = 0; | 7118 int len = 0; |
6946 | 7119 |
6947 for (x = fieldlist; x; x = TREE_CHAIN (x)) | 7120 for (x = fieldlist; x; x = DECL_CHAIN (x)) |
6948 { | 7121 { |
6949 if (len > 15 || DECL_NAME (x) == NULL) | 7122 if (len > 15 || DECL_NAME (x) == NULL) |
6950 break; | 7123 break; |
6951 len += 1; | 7124 len += 1; |
6952 } | 7125 } |
6961 | 7134 |
6962 /* Use the same allocation policy here that make_node uses, to | 7135 /* Use the same allocation policy here that make_node uses, to |
6963 ensure that this lives as long as the rest of the struct decl. | 7136 ensure that this lives as long as the rest of the struct decl. |
6964 All decls in an inline function need to be saved. */ | 7137 All decls in an inline function need to be saved. */ |
6965 | 7138 |
6966 space = GGC_CNEW (struct lang_type); | 7139 space = ggc_alloc_cleared_lang_type (sizeof (struct lang_type)); |
6967 space2 = GGC_NEWVAR (struct sorted_fields_type, | 7140 space2 = ggc_alloc_sorted_fields_type |
6968 sizeof (struct sorted_fields_type) + len * sizeof (tree)); | 7141 (sizeof (struct sorted_fields_type) + len * sizeof (tree)); |
6969 | 7142 |
6970 len = 0; | 7143 len = 0; |
6971 space->s = space2; | 7144 space->s = space2; |
6972 field_array = &space2->elts[0]; | 7145 field_array = &space2->elts[0]; |
6973 for (x = fieldlist; x; x = TREE_CHAIN (x)) | 7146 for (x = fieldlist; x; x = DECL_CHAIN (x)) |
6974 { | 7147 { |
6975 field_array[len++] = x; | 7148 field_array[len++] = x; |
6976 | 7149 |
6977 /* If there is anonymous struct or union, break out of the loop. */ | 7150 /* If there is anonymous struct or union, break out of the loop. */ |
6978 if (DECL_NAME (x) == NULL) | 7151 if (DECL_NAME (x) == NULL) |
7244 TYPE_VALUES (enumtype) = values; | 7417 TYPE_VALUES (enumtype) = values; |
7245 } | 7418 } |
7246 | 7419 |
7247 /* Record the min/max values so that we can warn about bit-field | 7420 /* Record the min/max values so that we can warn about bit-field |
7248 enumerations that are too small for the values. */ | 7421 enumerations that are too small for the values. */ |
7249 lt = GGC_CNEW (struct lang_type); | 7422 lt = ggc_alloc_cleared_lang_type (sizeof (struct lang_type)); |
7250 lt->enum_min = minnode; | 7423 lt->enum_min = minnode; |
7251 lt->enum_max = maxnode; | 7424 lt->enum_max = maxnode; |
7252 TYPE_LANG_SPECIFIC (enumtype) = lt; | 7425 TYPE_LANG_SPECIFIC (enumtype) = lt; |
7253 | 7426 |
7254 /* Fix up all variant types of this enum type. */ | 7427 /* Fix up all variant types of this enum type. */ |
7282 return enumtype; | 7455 return enumtype; |
7283 } | 7456 } |
7284 | 7457 |
7285 /* Build and install a CONST_DECL for one value of the | 7458 /* Build and install a CONST_DECL for one value of the |
7286 current enumeration type (one that was begun with start_enum). | 7459 current enumeration type (one that was begun with start_enum). |
7287 LOC is the location of the enumerator. | 7460 DECL_LOC is the location of the enumerator. |
7461 LOC is the location of the '=' operator if any, DECL_LOC otherwise. | |
7288 Return a tree-list containing the CONST_DECL and its value. | 7462 Return a tree-list containing the CONST_DECL and its value. |
7289 Assignment of sequential values by default is handled here. */ | 7463 Assignment of sequential values by default is handled here. */ |
7290 | 7464 |
7291 tree | 7465 tree |
7292 build_enumerator (location_t loc, | 7466 build_enumerator (location_t decl_loc, location_t loc, |
7293 struct c_enum_contents *the_enum, tree name, tree value) | 7467 struct c_enum_contents *the_enum, tree name, tree value) |
7294 { | 7468 { |
7295 tree decl, type; | 7469 tree decl, type; |
7296 | 7470 |
7297 /* Validate and default VALUE. */ | 7471 /* Validate and default VALUE. */ |
7361 if (int_fits_type_p (value, integer_type_node)) | 7535 if (int_fits_type_p (value, integer_type_node)) |
7362 value = convert (integer_type_node, value); | 7536 value = convert (integer_type_node, value); |
7363 | 7537 |
7364 /* Set basis for default for next value. */ | 7538 /* Set basis for default for next value. */ |
7365 the_enum->enum_next_value | 7539 the_enum->enum_next_value |
7366 = build_binary_op | 7540 = build_binary_op (EXPR_LOC_OR_HERE (value), |
7367 (EXPR_HAS_LOCATION (value) ? EXPR_LOCATION (value) : input_location, | 7541 PLUS_EXPR, value, integer_one_node, 0); |
7368 PLUS_EXPR, value, integer_one_node, 0); | |
7369 the_enum->enum_overflow = tree_int_cst_lt (the_enum->enum_next_value, value); | 7542 the_enum->enum_overflow = tree_int_cst_lt (the_enum->enum_next_value, value); |
7370 | 7543 |
7371 /* Now create a declaration for the enum value name. */ | 7544 /* Now create a declaration for the enum value name. */ |
7372 | 7545 |
7373 type = TREE_TYPE (value); | 7546 type = TREE_TYPE (value); |
7375 TYPE_PRECISION (integer_type_node)), | 7548 TYPE_PRECISION (integer_type_node)), |
7376 (TYPE_PRECISION (type) | 7549 (TYPE_PRECISION (type) |
7377 >= TYPE_PRECISION (integer_type_node) | 7550 >= TYPE_PRECISION (integer_type_node) |
7378 && TYPE_UNSIGNED (type))); | 7551 && TYPE_UNSIGNED (type))); |
7379 | 7552 |
7380 decl = build_decl (loc, CONST_DECL, name, type); | 7553 decl = build_decl (decl_loc, CONST_DECL, name, type); |
7381 DECL_INITIAL (decl) = convert (type, value); | 7554 DECL_INITIAL (decl) = convert (type, value); |
7382 pushdecl (decl); | 7555 pushdecl (decl); |
7383 | 7556 |
7384 return tree_cons (decl, value, NULL_TREE); | 7557 return tree_cons (decl, value, NULL_TREE); |
7385 } | 7558 } |
7476 if (old_decl && TREE_CODE (old_decl) != FUNCTION_DECL) | 7649 if (old_decl && TREE_CODE (old_decl) != FUNCTION_DECL) |
7477 old_decl = 0; | 7650 old_decl = 0; |
7478 current_function_prototype_locus = UNKNOWN_LOCATION; | 7651 current_function_prototype_locus = UNKNOWN_LOCATION; |
7479 current_function_prototype_built_in = false; | 7652 current_function_prototype_built_in = false; |
7480 current_function_prototype_arg_types = NULL_TREE; | 7653 current_function_prototype_arg_types = NULL_TREE; |
7481 if (TYPE_ARG_TYPES (TREE_TYPE (decl1)) == 0) | 7654 if (!prototype_p (TREE_TYPE (decl1))) |
7482 { | 7655 { |
7483 if (old_decl != 0 && TREE_CODE (TREE_TYPE (old_decl)) == FUNCTION_TYPE | 7656 if (old_decl != 0 && TREE_CODE (TREE_TYPE (old_decl)) == FUNCTION_TYPE |
7484 && comptypes (TREE_TYPE (TREE_TYPE (decl1)), | 7657 && comptypes (TREE_TYPE (TREE_TYPE (decl1)), |
7485 TREE_TYPE (TREE_TYPE (old_decl)))) | 7658 TREE_TYPE (TREE_TYPE (old_decl)))) |
7486 { | 7659 { |
7525 } | 7698 } |
7526 | 7699 |
7527 /* Optionally warn of old-fashioned def with no previous prototype. */ | 7700 /* Optionally warn of old-fashioned def with no previous prototype. */ |
7528 if (warn_strict_prototypes | 7701 if (warn_strict_prototypes |
7529 && old_decl != error_mark_node | 7702 && old_decl != error_mark_node |
7530 && TYPE_ARG_TYPES (TREE_TYPE (decl1)) == 0 | 7703 && !prototype_p (TREE_TYPE (decl1)) |
7531 && C_DECL_ISNT_PROTOTYPE (old_decl)) | 7704 && C_DECL_ISNT_PROTOTYPE (old_decl)) |
7532 warning_at (loc, OPT_Wstrict_prototypes, | 7705 warning_at (loc, OPT_Wstrict_prototypes, |
7533 "function declaration isn%'t a prototype"); | 7706 "function declaration isn%'t a prototype"); |
7534 /* Optionally warn of any global def with no previous prototype. */ | 7707 /* Optionally warn of any global def with no previous prototype. */ |
7535 else if (warn_missing_prototypes | 7708 else if (warn_missing_prototypes |
7543 if the function has already been used. */ | 7716 if the function has already been used. */ |
7544 else if (warn_missing_prototypes | 7717 else if (warn_missing_prototypes |
7545 && old_decl != 0 | 7718 && old_decl != 0 |
7546 && old_decl != error_mark_node | 7719 && old_decl != error_mark_node |
7547 && TREE_USED (old_decl) | 7720 && TREE_USED (old_decl) |
7548 && TYPE_ARG_TYPES (TREE_TYPE (old_decl)) == 0) | 7721 && !prototype_p (TREE_TYPE (old_decl))) |
7549 warning_at (loc, OPT_Wmissing_prototypes, | 7722 warning_at (loc, OPT_Wmissing_prototypes, |
7550 "%qD was used with no prototype before its definition", decl1); | 7723 "%qD was used with no prototype before its definition", decl1); |
7551 /* Optionally warn of any global def with no previous declaration. */ | 7724 /* Optionally warn of any global def with no previous declaration. */ |
7552 else if (warn_missing_declarations | 7725 else if (warn_missing_declarations |
7553 && TREE_PUBLIC (decl1) | 7726 && TREE_PUBLIC (decl1) |
7618 old-style parm decls were written. */ | 7791 old-style parm decls were written. */ |
7619 static void | 7792 static void |
7620 store_parm_decls_newstyle (tree fndecl, const struct c_arg_info *arg_info) | 7793 store_parm_decls_newstyle (tree fndecl, const struct c_arg_info *arg_info) |
7621 { | 7794 { |
7622 tree decl; | 7795 tree decl; |
7796 c_arg_tag *tag; | |
7797 unsigned ix; | |
7623 | 7798 |
7624 if (current_scope->bindings) | 7799 if (current_scope->bindings) |
7625 { | 7800 { |
7626 error_at (DECL_SOURCE_LOCATION (fndecl), | 7801 error_at (DECL_SOURCE_LOCATION (fndecl), |
7627 "old-style parameter declarations in prototyped " | 7802 "old-style parameter declarations in prototyped " |
7640 warning_at (DECL_SOURCE_LOCATION (fndecl), OPT_Wtraditional, | 7815 warning_at (DECL_SOURCE_LOCATION (fndecl), OPT_Wtraditional, |
7641 "traditional C rejects ISO C style function definitions"); | 7816 "traditional C rejects ISO C style function definitions"); |
7642 | 7817 |
7643 /* Now make all the parameter declarations visible in the function body. | 7818 /* Now make all the parameter declarations visible in the function body. |
7644 We can bypass most of the grunt work of pushdecl. */ | 7819 We can bypass most of the grunt work of pushdecl. */ |
7645 for (decl = arg_info->parms; decl; decl = TREE_CHAIN (decl)) | 7820 for (decl = arg_info->parms; decl; decl = DECL_CHAIN (decl)) |
7646 { | 7821 { |
7647 DECL_CONTEXT (decl) = current_function_decl; | 7822 DECL_CONTEXT (decl) = current_function_decl; |
7648 if (DECL_NAME (decl)) | 7823 if (DECL_NAME (decl)) |
7649 { | 7824 { |
7650 bind (DECL_NAME (decl), decl, current_scope, | 7825 bind (DECL_NAME (decl), decl, current_scope, |
7659 | 7834 |
7660 /* Record the parameter list in the function declaration. */ | 7835 /* Record the parameter list in the function declaration. */ |
7661 DECL_ARGUMENTS (fndecl) = arg_info->parms; | 7836 DECL_ARGUMENTS (fndecl) = arg_info->parms; |
7662 | 7837 |
7663 /* Now make all the ancillary declarations visible, likewise. */ | 7838 /* Now make all the ancillary declarations visible, likewise. */ |
7664 for (decl = arg_info->others; decl; decl = TREE_CHAIN (decl)) | 7839 for (decl = arg_info->others; decl; decl = DECL_CHAIN (decl)) |
7665 { | 7840 { |
7666 DECL_CONTEXT (decl) = current_function_decl; | 7841 DECL_CONTEXT (decl) = current_function_decl; |
7667 if (DECL_NAME (decl)) | 7842 if (DECL_NAME (decl)) |
7668 bind (DECL_NAME (decl), decl, current_scope, | 7843 bind (DECL_NAME (decl), decl, current_scope, |
7669 /*invisible=*/false, | 7844 /*invisible=*/false, |
7670 /*nested=*/(TREE_CODE (decl) == FUNCTION_DECL), | 7845 /*nested=*/(TREE_CODE (decl) == FUNCTION_DECL), |
7671 UNKNOWN_LOCATION); | 7846 UNKNOWN_LOCATION); |
7672 } | 7847 } |
7673 | 7848 |
7674 /* And all the tag declarations. */ | 7849 /* And all the tag declarations. */ |
7675 for (decl = arg_info->tags; decl; decl = TREE_CHAIN (decl)) | 7850 FOR_EACH_VEC_ELT_REVERSE (c_arg_tag, arg_info->tags, ix, tag) |
7676 if (TREE_PURPOSE (decl)) | 7851 if (tag->id) |
7677 bind (TREE_PURPOSE (decl), TREE_VALUE (decl), current_scope, | 7852 bind (tag->id, tag->type, current_scope, |
7678 /*invisible=*/false, /*nested=*/false, UNKNOWN_LOCATION); | 7853 /*invisible=*/false, /*nested=*/false, UNKNOWN_LOCATION); |
7679 } | 7854 } |
7680 | 7855 |
7681 /* Subroutine of store_parm_decls which handles old-style function | 7856 /* Subroutine of store_parm_decls which handles old-style function |
7682 definitions (separate parameter list and declarations). */ | 7857 definitions (separate parameter list and declarations). */ |
7707 | 7882 |
7708 b = I_SYMBOL_BINDING (TREE_VALUE (parm)); | 7883 b = I_SYMBOL_BINDING (TREE_VALUE (parm)); |
7709 if (b && B_IN_CURRENT_SCOPE (b)) | 7884 if (b && B_IN_CURRENT_SCOPE (b)) |
7710 { | 7885 { |
7711 decl = b->decl; | 7886 decl = b->decl; |
7887 /* Skip erroneous parameters. */ | |
7888 if (decl == error_mark_node) | |
7889 continue; | |
7712 /* If we got something other than a PARM_DECL it is an error. */ | 7890 /* If we got something other than a PARM_DECL it is an error. */ |
7713 if (TREE_CODE (decl) != PARM_DECL) | 7891 if (TREE_CODE (decl) != PARM_DECL) |
7714 error_at (DECL_SOURCE_LOCATION (decl), | 7892 error_at (DECL_SOURCE_LOCATION (decl), |
7715 "%qD declared as a non-parameter", decl); | 7893 "%qD declared as a non-parameter", decl); |
7716 /* If the declaration is already marked, we have a duplicate | 7894 /* If the declaration is already marked, we have a duplicate |
7811 DECL_ARGUMENTS (fndecl) = last; | 7989 DECL_ARGUMENTS (fndecl) = last; |
7812 | 7990 |
7813 for (parm = TREE_CHAIN (parm); parm; parm = TREE_CHAIN (parm)) | 7991 for (parm = TREE_CHAIN (parm); parm; parm = TREE_CHAIN (parm)) |
7814 if (TREE_PURPOSE (parm)) | 7992 if (TREE_PURPOSE (parm)) |
7815 { | 7993 { |
7816 TREE_CHAIN (last) = TREE_PURPOSE (parm); | 7994 DECL_CHAIN (last) = TREE_PURPOSE (parm); |
7817 last = TREE_PURPOSE (parm); | 7995 last = TREE_PURPOSE (parm); |
7818 } | 7996 } |
7819 TREE_CHAIN (last) = 0; | 7997 DECL_CHAIN (last) = 0; |
7820 } | 7998 } |
7821 | 7999 |
7822 pointer_set_destroy (seen_args); | 8000 pointer_set_destroy (seen_args); |
7823 | 8001 |
7824 /* If there was a previous prototype, | 8002 /* If there was a previous prototype, |
7830 tree type; | 8008 tree type; |
7831 for (parm = DECL_ARGUMENTS (fndecl), | 8009 for (parm = DECL_ARGUMENTS (fndecl), |
7832 type = current_function_prototype_arg_types; | 8010 type = current_function_prototype_arg_types; |
7833 parm || (type && TREE_VALUE (type) != error_mark_node | 8011 parm || (type && TREE_VALUE (type) != error_mark_node |
7834 && (TYPE_MAIN_VARIANT (TREE_VALUE (type)) != void_type_node)); | 8012 && (TYPE_MAIN_VARIANT (TREE_VALUE (type)) != void_type_node)); |
7835 parm = TREE_CHAIN (parm), type = TREE_CHAIN (type)) | 8013 parm = DECL_CHAIN (parm), type = TREE_CHAIN (type)) |
7836 { | 8014 { |
7837 if (parm == 0 || type == 0 | 8015 if (parm == 0 || type == 0 |
7838 || TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node) | 8016 || TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node) |
7839 { | 8017 { |
7840 if (current_function_prototype_built_in) | 8018 if (current_function_prototype_built_in) |
7921 | 8099 |
7922 else | 8100 else |
7923 { | 8101 { |
7924 tree actual = 0, last = 0, type; | 8102 tree actual = 0, last = 0, type; |
7925 | 8103 |
7926 for (parm = DECL_ARGUMENTS (fndecl); parm; parm = TREE_CHAIN (parm)) | 8104 for (parm = DECL_ARGUMENTS (fndecl); parm; parm = DECL_CHAIN (parm)) |
7927 { | 8105 { |
7928 type = tree_cons (NULL_TREE, DECL_ARG_TYPE (parm), NULL_TREE); | 8106 type = tree_cons (NULL_TREE, DECL_ARG_TYPE (parm), NULL_TREE); |
7929 if (last) | 8107 if (last) |
7930 TREE_CHAIN (last) = type; | 8108 TREE_CHAIN (last) = type; |
7931 else | 8109 else |
8015 { | 8193 { |
8016 VEC(tree,gc) *pending_sizes = get_pending_sizes (); | 8194 VEC(tree,gc) *pending_sizes = get_pending_sizes (); |
8017 tree t; | 8195 tree t; |
8018 int i; | 8196 int i; |
8019 | 8197 |
8020 for (i = 0; VEC_iterate (tree, pending_sizes, i, t); i++) | 8198 FOR_EACH_VEC_ELT (tree, pending_sizes, i, t) |
8021 add_stmt (t); | 8199 add_stmt (t); |
8022 } | 8200 } |
8023 | 8201 |
8024 /* Even though we're inside a function body, we still don't want to | 8202 /* Even though we're inside a function body, we still don't want to |
8025 call expand_expr to calculate the size of a variable-sized array. | 8203 call expand_expr to calculate the size of a variable-sized array. |
8028 cfun->dont_save_pending_sizes_p = 1; | 8206 cfun->dont_save_pending_sizes_p = 1; |
8029 } | 8207 } |
8030 | 8208 |
8031 | 8209 |
8032 /* Finish up a function declaration and compile that function | 8210 /* Finish up a function declaration and compile that function |
8033 all the way to assembler language output. The free the storage | 8211 all the way to assembler language output. Then free the storage |
8034 for the function definition. | 8212 for the function definition. |
8035 | 8213 |
8036 This is called after parsing the body of the function definition. */ | 8214 This is called after parsing the body of the function definition. */ |
8037 | 8215 |
8038 void | 8216 void |
8039 finish_function (void) | 8217 finish_function (void) |
8040 { | 8218 { |
8041 tree fndecl = current_function_decl; | 8219 tree fndecl = current_function_decl; |
8220 | |
8221 if (c_dialect_objc ()) | |
8222 objc_finish_function (); | |
8042 | 8223 |
8043 if (TREE_CODE (fndecl) == FUNCTION_DECL | 8224 if (TREE_CODE (fndecl) == FUNCTION_DECL |
8044 && targetm.calls.promote_prototypes (TREE_TYPE (fndecl))) | 8225 && targetm.calls.promote_prototypes (TREE_TYPE (fndecl))) |
8045 { | 8226 { |
8046 tree args = DECL_ARGUMENTS (fndecl); | 8227 tree args = DECL_ARGUMENTS (fndecl); |
8047 for (; args; args = TREE_CHAIN (args)) | 8228 for (; args; args = DECL_CHAIN (args)) |
8048 { | 8229 { |
8049 tree type = TREE_TYPE (args); | 8230 tree type = TREE_TYPE (args); |
8050 if (INTEGRAL_TYPE_P (type) | 8231 if (INTEGRAL_TYPE_P (type) |
8051 && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)) | 8232 && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)) |
8052 DECL_ARG_TYPE (args) = integer_type_node; | 8233 DECL_ARG_TYPE (args) = integer_type_node; |
8105 { | 8286 { |
8106 tree decl; | 8287 tree decl; |
8107 | 8288 |
8108 for (decl = DECL_ARGUMENTS (fndecl); | 8289 for (decl = DECL_ARGUMENTS (fndecl); |
8109 decl; | 8290 decl; |
8110 decl = TREE_CHAIN (decl)) | 8291 decl = DECL_CHAIN (decl)) |
8111 if (TREE_USED (decl) | 8292 if (TREE_USED (decl) |
8112 && TREE_CODE (decl) == PARM_DECL | 8293 && TREE_CODE (decl) == PARM_DECL |
8113 && !DECL_READ_P (decl) | 8294 && !DECL_READ_P (decl) |
8114 && DECL_NAME (decl) | 8295 && DECL_NAME (decl) |
8115 && !DECL_ARTIFICIAL (decl) | 8296 && !DECL_ARTIFICIAL (decl) |
8171 current_function_decl = NULL; | 8352 current_function_decl = NULL; |
8172 } | 8353 } |
8173 | 8354 |
8174 /* Check the declarations given in a for-loop for satisfying the C99 | 8355 /* Check the declarations given in a for-loop for satisfying the C99 |
8175 constraints. If exactly one such decl is found, return it. LOC is | 8356 constraints. If exactly one such decl is found, return it. LOC is |
8176 the location of the opening parenthesis of the for loop. */ | 8357 the location of the opening parenthesis of the for loop. The last |
8358 parameter allows you to control the "for loop initial declarations | |
8359 are only allowed in C99 mode". Normally, you should pass | |
8360 flag_isoc99 as that parameter. But in some cases (Objective-C | |
8361 foreach loop, for example) we want to run the checks in this | |
8362 function even if not in C99 mode, so we allow the caller to turn | |
8363 off the error about not being in C99 mode. | |
8364 */ | |
8177 | 8365 |
8178 tree | 8366 tree |
8179 check_for_loop_decls (location_t loc) | 8367 check_for_loop_decls (location_t loc, bool turn_off_iso_c99_error) |
8180 { | 8368 { |
8181 struct c_binding *b; | 8369 struct c_binding *b; |
8182 tree one_decl = NULL_TREE; | 8370 tree one_decl = NULL_TREE; |
8183 int n_decls = 0; | 8371 int n_decls = 0; |
8184 | 8372 |
8185 if (!flag_isoc99) | 8373 if (!turn_off_iso_c99_error) |
8186 { | 8374 { |
8187 static bool hint = true; | 8375 static bool hint = true; |
8188 /* If we get here, declarations have been used in a for loop without | 8376 /* If we get here, declarations have been used in a for loop without |
8189 the C99 for loop scope. This doesn't make much sense, so don't | 8377 the C99 for loop scope. This doesn't make much sense, so don't |
8190 allow it. */ | 8378 allow it. */ |
8267 | 8455 |
8268 void | 8456 void |
8269 c_push_function_context (void) | 8457 c_push_function_context (void) |
8270 { | 8458 { |
8271 struct language_function *p; | 8459 struct language_function *p; |
8272 p = GGC_NEW (struct language_function); | 8460 p = ggc_alloc_language_function (); |
8273 cfun->language = p; | 8461 cfun->language = p; |
8274 | 8462 |
8275 p->base.x_stmt_tree = c_stmt_tree; | 8463 p->base.x_stmt_tree = c_stmt_tree; |
8276 p->x_break_label = c_break_label; | 8464 p->x_break_label = c_break_label; |
8277 p->x_cont_label = c_cont_label; | 8465 p->x_cont_label = c_cont_label; |
8466 ret->attrs = 0; | 8654 ret->attrs = 0; |
8467 ret->typespec_word = cts_none; | 8655 ret->typespec_word = cts_none; |
8468 ret->storage_class = csc_none; | 8656 ret->storage_class = csc_none; |
8469 ret->expr_const_operands = true; | 8657 ret->expr_const_operands = true; |
8470 ret->declspecs_seen_p = false; | 8658 ret->declspecs_seen_p = false; |
8471 ret->type_seen_p = false; | 8659 ret->typespec_kind = ctsk_none; |
8472 ret->non_sc_seen_p = false; | 8660 ret->non_sc_seen_p = false; |
8473 ret->typedef_p = false; | 8661 ret->typedef_p = false; |
8474 ret->tag_defined_p = false; | |
8475 ret->explicit_signed_p = false; | 8662 ret->explicit_signed_p = false; |
8476 ret->deprecated_p = false; | 8663 ret->deprecated_p = false; |
8477 ret->default_int_p = false; | 8664 ret->default_int_p = false; |
8478 ret->long_p = false; | 8665 ret->long_p = false; |
8479 ret->long_long_p = false; | 8666 ret->long_long_p = false; |
8553 struct c_typespec spec) | 8740 struct c_typespec spec) |
8554 { | 8741 { |
8555 tree type = spec.spec; | 8742 tree type = spec.spec; |
8556 specs->non_sc_seen_p = true; | 8743 specs->non_sc_seen_p = true; |
8557 specs->declspecs_seen_p = true; | 8744 specs->declspecs_seen_p = true; |
8558 specs->type_seen_p = true; | 8745 specs->typespec_kind = spec.kind; |
8559 if (TREE_DEPRECATED (type)) | 8746 if (TREE_DEPRECATED (type)) |
8560 specs->deprecated_p = true; | 8747 specs->deprecated_p = true; |
8561 | 8748 |
8562 /* Handle type specifier keywords. */ | 8749 /* Handle type specifier keywords. */ |
8563 if (TREE_CODE (type) == IDENTIFIER_NODE | 8750 if (TREE_CODE (type) == IDENTIFIER_NODE |
8602 "declaration specifiers")); | 8789 "declaration specifiers")); |
8603 else if (specs->typespec_word == cts_void) | 8790 else if (specs->typespec_word == cts_void) |
8604 error_at (loc, | 8791 error_at (loc, |
8605 ("both %<long%> and %<void%> in " | 8792 ("both %<long%> and %<void%> in " |
8606 "declaration specifiers")); | 8793 "declaration specifiers")); |
8794 else if (specs->typespec_word == cts_int128) | |
8795 error_at (loc, | |
8796 ("both %<long%> and %<__int128%> in " | |
8797 "declaration specifiers")); | |
8607 else if (specs->typespec_word == cts_bool) | 8798 else if (specs->typespec_word == cts_bool) |
8608 error_at (loc, | 8799 error_at (loc, |
8609 ("both %<long%> and %<_Bool%> in " | 8800 ("both %<long%> and %<_Bool%> in " |
8610 "declaration specifiers")); | 8801 "declaration specifiers")); |
8611 else if (specs->typespec_word == cts_char) | 8802 else if (specs->typespec_word == cts_char) |
8638 ("both %<long%> and %<short%> in " | 8829 ("both %<long%> and %<short%> in " |
8639 "declaration specifiers")); | 8830 "declaration specifiers")); |
8640 else if (specs->typespec_word == cts_void) | 8831 else if (specs->typespec_word == cts_void) |
8641 error_at (loc, | 8832 error_at (loc, |
8642 ("both %<short%> and %<void%> in " | 8833 ("both %<short%> and %<void%> in " |
8834 "declaration specifiers")); | |
8835 else if (specs->typespec_word == cts_int128) | |
8836 error_at (loc, | |
8837 ("both %<short%> and %<__int128%> in " | |
8643 "declaration specifiers")); | 8838 "declaration specifiers")); |
8644 else if (specs->typespec_word == cts_bool) | 8839 else if (specs->typespec_word == cts_bool) |
8645 error_at (loc, | 8840 error_at (loc, |
8646 ("both %<short%> and %<_Bool%> in " | 8841 ("both %<short%> and %<_Bool%> in " |
8647 "declaration specifiers")); | 8842 "declaration specifiers")); |
8788 break; | 8983 break; |
8789 case RID_SAT: | 8984 case RID_SAT: |
8790 dupe = specs->saturating_p; | 8985 dupe = specs->saturating_p; |
8791 pedwarn (loc, OPT_pedantic, | 8986 pedwarn (loc, OPT_pedantic, |
8792 "ISO C does not support saturating types"); | 8987 "ISO C does not support saturating types"); |
8793 if (specs->typespec_word == cts_void) | 8988 if (specs->typespec_word == cts_int128) |
8989 { | |
8990 error_at (loc, | |
8991 ("both %<_Sat%> and %<__int128%> in " | |
8992 "declaration specifiers")); | |
8993 } | |
8994 else if (specs->typespec_word == cts_void) | |
8794 error_at (loc, | 8995 error_at (loc, |
8795 ("both %<_Sat%> and %<void%> in " | 8996 ("both %<_Sat%> and %<void%> in " |
8796 "declaration specifiers")); | 8997 "declaration specifiers")); |
8797 else if (specs->typespec_word == cts_bool) | 8998 else if (specs->typespec_word == cts_bool) |
8798 error_at (loc, | 8999 error_at (loc, |
8843 return specs; | 9044 return specs; |
8844 } | 9045 } |
8845 else | 9046 else |
8846 { | 9047 { |
8847 /* "void", "_Bool", "char", "int", "float", "double", "_Decimal32", | 9048 /* "void", "_Bool", "char", "int", "float", "double", "_Decimal32", |
8848 "_Decimal64", "_Decimal128", "_Fract" or "_Accum". */ | 9049 "__int128", "_Decimal64", "_Decimal128", "_Fract" or "_Accum". */ |
8849 if (specs->typespec_word != cts_none) | 9050 if (specs->typespec_word != cts_none) |
8850 { | 9051 { |
8851 error_at (loc, | 9052 error_at (loc, |
8852 "two or more data types in declaration specifiers"); | 9053 "two or more data types in declaration specifiers"); |
8853 return specs; | 9054 return specs; |
8854 } | 9055 } |
8855 switch (i) | 9056 switch (i) |
8856 { | 9057 { |
9058 case RID_INT128: | |
9059 if (int128_integer_type_node == NULL_TREE) | |
9060 { | |
9061 error_at (loc, "%<__int128%> is not supported for this target"); | |
9062 return specs; | |
9063 } | |
9064 if (!in_system_header) | |
9065 pedwarn (loc, OPT_pedantic, | |
9066 "ISO C does not support %<__int128%> type"); | |
9067 | |
9068 if (specs->long_p) | |
9069 error_at (loc, | |
9070 ("both %<__int128%> and %<long%> in " | |
9071 "declaration specifiers")); | |
9072 else if (specs->saturating_p) | |
9073 error_at (loc, | |
9074 ("both %<_Sat%> and %<__int128%> in " | |
9075 "declaration specifiers")); | |
9076 else if (specs->short_p) | |
9077 error_at (loc, | |
9078 ("both %<__int128%> and %<short%> in " | |
9079 "declaration specifiers")); | |
9080 else | |
9081 specs->typespec_word = cts_int128; | |
9082 return specs; | |
8857 case RID_VOID: | 9083 case RID_VOID: |
8858 if (specs->long_p) | 9084 if (specs->long_p) |
8859 error_at (loc, | 9085 error_at (loc, |
8860 ("both %<long%> and %<void%> in " | 9086 ("both %<long%> and %<void%> in " |
8861 "declaration specifiers")); | 9087 "declaration specifiers")); |
9115 else if (TREE_TYPE (t) == error_mark_node) | 9341 else if (TREE_TYPE (t) == error_mark_node) |
9116 ; | 9342 ; |
9117 else | 9343 else |
9118 specs->type = TREE_TYPE (t); | 9344 specs->type = TREE_TYPE (t); |
9119 } | 9345 } |
9120 else if (TREE_CODE (type) != ERROR_MARK) | 9346 else |
9121 { | 9347 { |
9122 if (spec.kind == ctsk_tagdef || spec.kind == ctsk_tagfirstref) | 9348 if (TREE_CODE (type) != ERROR_MARK && spec.kind == ctsk_typeof) |
9123 specs->tag_defined_p = true; | |
9124 if (spec.kind == ctsk_typeof) | |
9125 { | 9349 { |
9126 specs->typedef_p = true; | 9350 specs->typedef_p = true; |
9127 if (spec.expr) | 9351 if (spec.expr) |
9128 { | 9352 { |
9129 if (specs->expr) | 9353 if (specs->expr) |
9249 if (specs->type != NULL_TREE) | 9473 if (specs->type != NULL_TREE) |
9250 { | 9474 { |
9251 gcc_assert (!specs->long_p && !specs->long_long_p && !specs->short_p | 9475 gcc_assert (!specs->long_p && !specs->long_long_p && !specs->short_p |
9252 && !specs->signed_p && !specs->unsigned_p | 9476 && !specs->signed_p && !specs->unsigned_p |
9253 && !specs->complex_p); | 9477 && !specs->complex_p); |
9478 | |
9479 /* Set a dummy type. */ | |
9480 if (TREE_CODE (specs->type) == ERROR_MARK) | |
9481 specs->type = integer_type_node; | |
9254 return specs; | 9482 return specs; |
9255 } | 9483 } |
9256 | 9484 |
9257 /* If none of "void", "_Bool", "char", "int", "float" or "double" | 9485 /* If none of "void", "_Bool", "char", "int", "float" or "double" |
9258 has been specified, treat it as "int" unless "_Complex" is | 9486 has been specified, treat it as "int" unless "_Complex" is |
9324 pedwarn (input_location, OPT_pedantic, | 9552 pedwarn (input_location, OPT_pedantic, |
9325 "ISO C does not support complex integer types"); | 9553 "ISO C does not support complex integer types"); |
9326 specs->type = build_complex_type (specs->type); | 9554 specs->type = build_complex_type (specs->type); |
9327 } | 9555 } |
9328 break; | 9556 break; |
9557 case cts_int128: | |
9558 gcc_assert (!specs->long_p && !specs->short_p && !specs->long_long_p); | |
9559 gcc_assert (!(specs->signed_p && specs->unsigned_p)); | |
9560 specs->type = (specs->unsigned_p | |
9561 ? int128_unsigned_type_node | |
9562 : int128_integer_type_node); | |
9563 if (specs->complex_p) | |
9564 { | |
9565 pedwarn (input_location, OPT_pedantic, | |
9566 "ISO C does not support complex integer types"); | |
9567 specs->type = build_complex_type (specs->type); | |
9568 } | |
9569 break; | |
9329 case cts_int: | 9570 case cts_int: |
9330 gcc_assert (!(specs->long_p && specs->short_p)); | 9571 gcc_assert (!(specs->long_p && specs->short_p)); |
9331 gcc_assert (!(specs->signed_p && specs->unsigned_p)); | 9572 gcc_assert (!(specs->signed_p && specs->unsigned_p)); |
9332 if (specs->long_long_p) | 9573 if (specs->long_long_p) |
9333 specs->type = (specs->unsigned_p | 9574 specs->type = (specs->unsigned_p |
9489 { | 9730 { |
9490 tree decl; | 9731 tree decl; |
9491 bool reconsider; | 9732 bool reconsider; |
9492 | 9733 |
9493 /* Process the decls in the order they were written. */ | 9734 /* Process the decls in the order they were written. */ |
9494 for (decl = globals; decl; decl = TREE_CHAIN (decl)) | 9735 for (decl = globals; decl; decl = DECL_CHAIN (decl)) |
9495 { | 9736 { |
9496 /* Check for used but undefined static functions using the C | 9737 /* Check for used but undefined static functions using the C |
9497 standard's definition of "used", and set TREE_NO_WARNING so | 9738 standard's definition of "used", and set TREE_NO_WARNING so |
9498 that check_global_declarations doesn't repeat the check. */ | 9739 that check_global_declarations doesn't repeat the check. */ |
9499 if (TREE_CODE (decl) == FUNCTION_DECL | 9740 if (TREE_CODE (decl) == FUNCTION_DECL |
9510 } | 9751 } |
9511 | 9752 |
9512 do | 9753 do |
9513 { | 9754 { |
9514 reconsider = false; | 9755 reconsider = false; |
9515 for (decl = globals; decl; decl = TREE_CHAIN (decl)) | 9756 for (decl = globals; decl; decl = DECL_CHAIN (decl)) |
9516 reconsider |= wrapup_global_declaration_2 (decl); | 9757 reconsider |= wrapup_global_declaration_2 (decl); |
9517 } | 9758 } |
9518 while (reconsider); | 9759 while (reconsider); |
9519 | 9760 |
9520 for (decl = globals; decl; decl = TREE_CHAIN (decl)) | 9761 for (decl = globals; decl; decl = DECL_CHAIN (decl)) |
9521 check_global_declaration_1 (decl); | 9762 check_global_declaration_1 (decl); |
9522 } | 9763 } |
9523 | 9764 |
9524 /* A subroutine of c_write_global_declarations Emit debug information for each | 9765 /* A subroutine of c_write_global_declarations Emit debug information for each |
9525 of the declarations in GLOBALS. */ | 9766 of the declarations in GLOBALS. */ |
9527 static void | 9768 static void |
9528 c_write_global_declarations_2 (tree globals) | 9769 c_write_global_declarations_2 (tree globals) |
9529 { | 9770 { |
9530 tree decl; | 9771 tree decl; |
9531 | 9772 |
9532 for (decl = globals; decl ; decl = TREE_CHAIN (decl)) | 9773 for (decl = globals; decl ; decl = DECL_CHAIN (decl)) |
9533 debug_hooks->global_decl (decl); | 9774 debug_hooks->global_decl (decl); |
9775 } | |
9776 | |
9777 /* Callback to collect a source_ref from a DECL. */ | |
9778 | |
9779 static void | |
9780 collect_source_ref_cb (tree decl) | |
9781 { | |
9782 if (!DECL_IS_BUILTIN (decl)) | |
9783 collect_source_ref (LOCATION_FILE (decl_sloc (decl, false))); | |
9784 } | |
9785 | |
9786 /* Collect all references relevant to SOURCE_FILE. */ | |
9787 | |
9788 static void | |
9789 collect_all_refs (const char *source_file) | |
9790 { | |
9791 tree t; | |
9792 unsigned i; | |
9793 | |
9794 FOR_EACH_VEC_ELT (tree, all_translation_units, i, t) | |
9795 collect_ada_nodes (BLOCK_VARS (DECL_INITIAL (t)), source_file); | |
9796 } | |
9797 | |
9798 /* Iterate over all global declarations and call CALLBACK. */ | |
9799 | |
9800 static void | |
9801 for_each_global_decl (void (*callback) (tree decl)) | |
9802 { | |
9803 tree t; | |
9804 tree decls; | |
9805 tree decl; | |
9806 unsigned i; | |
9807 | |
9808 FOR_EACH_VEC_ELT (tree, all_translation_units, i, t) | |
9809 { | |
9810 decls = DECL_INITIAL (t); | |
9811 for (decl = BLOCK_VARS (decls); decl; decl = TREE_CHAIN (decl)) | |
9812 callback (decl); | |
9813 } | |
9534 } | 9814 } |
9535 | 9815 |
9536 /* Preserve the external declarations scope across a garbage collect. */ | 9816 /* Preserve the external declarations scope across a garbage collect. */ |
9537 static GTY(()) tree ext_block; | 9817 static GTY(()) tree ext_block; |
9538 | 9818 |
9539 void | 9819 void |
9540 c_write_global_declarations (void) | 9820 c_write_global_declarations (void) |
9541 { | 9821 { |
9542 tree t; | 9822 tree t; |
9823 unsigned i; | |
9543 | 9824 |
9544 /* We don't want to do this if generating a PCH. */ | 9825 /* We don't want to do this if generating a PCH. */ |
9545 if (pch_file) | 9826 if (pch_file) |
9546 return; | 9827 return; |
9547 | 9828 |
9548 /* Don't waste time on further processing if -fsyntax-only. | 9829 /* Do the Objective-C stuff. This is where all the Objective-C |
9549 Continue for warning and errors issued during lowering though. */ | 9830 module stuff gets generated (symtab, class/protocol/selector |
9550 if (flag_syntax_only) | 9831 lists etc). */ |
9551 return; | 9832 if (c_dialect_objc ()) |
9833 objc_write_global_declarations (); | |
9552 | 9834 |
9553 /* Close the external scope. */ | 9835 /* Close the external scope. */ |
9554 ext_block = pop_scope (); | 9836 ext_block = pop_scope (); |
9555 external_scope = 0; | 9837 external_scope = 0; |
9556 gcc_assert (!current_scope); | 9838 gcc_assert (!current_scope); |
9557 | 9839 |
9840 /* Handle -fdump-ada-spec[-slim]. */ | |
9841 if (dump_enabled_p (TDI_ada)) | |
9842 { | |
9843 /* Build a table of files to generate specs for */ | |
9844 if (get_dump_file_info (TDI_ada)->flags & TDF_SLIM) | |
9845 collect_source_ref (main_input_filename); | |
9846 else | |
9847 for_each_global_decl (collect_source_ref_cb); | |
9848 | |
9849 dump_ada_specs (collect_all_refs, NULL); | |
9850 } | |
9851 | |
9558 if (ext_block) | 9852 if (ext_block) |
9559 { | 9853 { |
9560 tree tmp = BLOCK_VARS (ext_block); | 9854 tree tmp = BLOCK_VARS (ext_block); |
9561 int flags; | 9855 int flags; |
9562 FILE * stream = dump_begin (TDI_tu, &flags); | 9856 FILE * stream = dump_begin (TDI_tu, &flags); |
9567 } | 9861 } |
9568 } | 9862 } |
9569 | 9863 |
9570 /* Process all file scopes in this compilation, and the external_scope, | 9864 /* Process all file scopes in this compilation, and the external_scope, |
9571 through wrapup_global_declarations and check_global_declarations. */ | 9865 through wrapup_global_declarations and check_global_declarations. */ |
9572 for (t = all_translation_units; t; t = TREE_CHAIN (t)) | 9866 FOR_EACH_VEC_ELT (tree, all_translation_units, i, t) |
9573 c_write_global_declarations_1 (BLOCK_VARS (DECL_INITIAL (t))); | 9867 c_write_global_declarations_1 (BLOCK_VARS (DECL_INITIAL (t))); |
9574 c_write_global_declarations_1 (BLOCK_VARS (ext_block)); | 9868 c_write_global_declarations_1 (BLOCK_VARS (ext_block)); |
9575 | 9869 |
9576 /* We're done parsing; proceed to optimize and emit assembly. | 9870 /* We're done parsing; proceed to optimize and emit assembly. |
9577 FIXME: shouldn't be the front end's responsibility to call this. */ | 9871 FIXME: shouldn't be the front end's responsibility to call this. */ |
9578 cgraph_finalize_compilation_unit (); | 9872 cgraph_finalize_compilation_unit (); |
9579 | 9873 |
9580 /* After cgraph has had a chance to emit everything that's going to | 9874 /* After cgraph has had a chance to emit everything that's going to |
9581 be emitted, output debug information for globals. */ | 9875 be emitted, output debug information for globals. */ |
9582 if (errorcount == 0 && sorrycount == 0) | 9876 if (!seen_error ()) |
9583 { | 9877 { |
9584 timevar_push (TV_SYMOUT); | 9878 timevar_push (TV_SYMOUT); |
9585 for (t = all_translation_units; t; t = TREE_CHAIN (t)) | 9879 FOR_EACH_VEC_ELT (tree, all_translation_units, i, t) |
9586 c_write_global_declarations_2 (BLOCK_VARS (DECL_INITIAL (t))); | 9880 c_write_global_declarations_2 (BLOCK_VARS (DECL_INITIAL (t))); |
9587 c_write_global_declarations_2 (BLOCK_VARS (ext_block)); | 9881 c_write_global_declarations_2 (BLOCK_VARS (ext_block)); |
9588 timevar_pop (TV_SYMOUT); | 9882 timevar_pop (TV_SYMOUT); |
9589 } | 9883 } |
9590 | 9884 |
9591 ext_block = NULL; | 9885 ext_block = NULL; |
9592 } | 9886 } |
9593 | 9887 |
9888 /* Register reserved keyword WORD as qualifier for address space AS. */ | |
9889 | |
9890 void | |
9891 c_register_addr_space (const char *word, addr_space_t as) | |
9892 { | |
9893 int rid = RID_FIRST_ADDR_SPACE + as; | |
9894 tree id; | |
9895 | |
9896 /* Address space qualifiers are only supported | |
9897 in C with GNU extensions enabled. */ | |
9898 if (c_dialect_objc () || flag_no_asm) | |
9899 return; | |
9900 | |
9901 id = get_identifier (word); | |
9902 C_SET_RID_CODE (id, rid); | |
9903 C_IS_RESERVED_WORD (id) = 1; | |
9904 ridpointers [rid] = id; | |
9905 } | |
9906 | |
9594 #include "gt-c-decl.h" | 9907 #include "gt-c-decl.h" |