comparison gcc/c-decl.c @ 57:326d9e06c2e3

modify c-parser.c
author ryoma <e075725@ie.u-ryukyu.ac.jp>
date Mon, 15 Feb 2010 00:54:17 +0900
parents 9907f3135723 77e2b8dfacca
children 1b10fe6932e1
comparison
equal deleted inserted replaced
54:f62c169bbc24 57:326d9e06c2e3
48 #include "debug.h" 48 #include "debug.h"
49 #include "opts.h" 49 #include "opts.h"
50 #include "timevar.h" 50 #include "timevar.h"
51 #include "c-common.h" 51 #include "c-common.h"
52 #include "c-pragma.h" 52 #include "c-pragma.h"
53 #include "c-lang.h"
53 #include "langhooks.h" 54 #include "langhooks.h"
54 #include "tree-mudflap.h" 55 #include "tree-mudflap.h"
55 #include "gimple.h" 56 #include "gimple.h"
56 #include "tree-iterator.h" 57 #include "tree-iterator.h"
57 #include "diagnostic.h" 58 #include "diagnostic.h"
68 tree cbc_env; 69 tree cbc_env;
69 tree cbc_return_f; 70 tree cbc_return_f;
70 location_t cbc_return; 71 location_t cbc_return;
71 #endif 72 #endif
72 73
74 #include "plugin.h"
73 75
74 /* In grokdeclarator, distinguish syntactic contexts of declarators. */ 76 /* In grokdeclarator, distinguish syntactic contexts of declarators. */
75 enum decl_context 77 enum decl_context
76 { NORMAL, /* Ordinary declaration */ 78 { NORMAL, /* Ordinary declaration */
77 FUNCDEF, /* Function definition */ 79 FUNCDEF, /* Function definition */
78 PARM, /* Declaration of parm before function body */ 80 PARM, /* Declaration of parm before function body */
79 FIELD, /* Declaration inside struct or union */ 81 FIELD, /* Declaration inside struct or union */
80 TYPENAME}; /* Typename (inside cast or sizeof) */ 82 TYPENAME}; /* Typename (inside cast or sizeof) */
81 83
82 /* States indicating how grokdeclarator() should handle declspecs marked 84 /* States indicating how grokdeclarator() should handle declspecs marked
83 with __attribute__((deprecated)). An object declared as 85 with __attribute__((deprecated)). An object declared as
84 __attribute__((deprecated)) suppresses warnings of uses of other 86 __attribute__((deprecated)) suppresses warnings of uses of other
85 deprecated items. */ 87 deprecated items. */
94 to a struct, union, or enum, but not yet printed the message. */ 96 to a struct, union, or enum, but not yet printed the message. */
95 tree pending_invalid_xref; 97 tree pending_invalid_xref;
96 98
97 /* File and line to appear in the eventual error message. */ 99 /* File and line to appear in the eventual error message. */
98 location_t pending_invalid_xref_location; 100 location_t pending_invalid_xref_location;
99
100 /* True means we've initialized exception handling. */
101 bool c_eh_initialized_p;
102 101
103 /* The file and line that the prototype came from if this is an 102 /* The file and line that the prototype came from if this is an
104 old-style definition; used for diagnostics in 103 old-style definition; used for diagnostics in
105 store_parm_decls_oldstyle. */ 104 store_parm_decls_oldstyle. */
106 105
183 RECORD_TYPE, UNION_TYPE, or ENUMERAL_TYPE node. If an undeclared 182 RECORD_TYPE, UNION_TYPE, or ENUMERAL_TYPE node. If an undeclared
184 identifier is encountered, it is bound to error_mark_node to 183 identifier is encountered, it is bound to error_mark_node to
185 suppress further errors about that identifier in the current 184 suppress further errors about that identifier in the current
186 function. 185 function.
187 186
188 The ->type field stores the type of the declaration in this scope; 187 The ->u.type field stores the type of the declaration in this scope;
189 if NULL, the type is the type of the ->decl field. This is only of 188 if NULL, the type is the type of the ->decl field. This is only of
190 relevance for objects with external or internal linkage which may 189 relevance for objects with external or internal linkage which may
191 be redeclared in inner scopes, forming composite types that only 190 be redeclared in inner scopes, forming composite types that only
192 persist for the duration of those scopes. In the external scope, 191 persist for the duration of those scopes. In the external scope,
193 this stores the composite of all the types declared for this 192 this stores the composite of all the types declared for this
194 object, visible or not. The ->inner_comp field (used only at file 193 object, visible or not. The ->inner_comp field (used only at file
195 scope) stores whether an incomplete array type at file scope was 194 scope) stores whether an incomplete array type at file scope was
196 completed at an inner scope to an array size other than 1. 195 completed at an inner scope to an array size other than 1.
197 196
197 The ->u.label field is used for labels. It points to a structure
198 which stores additional information used for warnings.
199
198 The depth field is copied from the scope structure that holds this 200 The depth field is copied from the scope structure that holds this
199 decl. It is used to preserve the proper ordering of the ->shadowed 201 decl. It is used to preserve the proper ordering of the ->shadowed
200 field (see bind()) and also for a handful of special-case checks. 202 field (see bind()) and also for a handful of special-case checks.
201 Finally, the invisible bit is true for a decl which should be 203 Finally, the invisible bit is true for a decl which should be
202 ignored for purposes of normal name lookup, and the nested bit is 204 ignored for purposes of normal name lookup, and the nested bit is
203 true for a decl that's been bound a second time in an inner scope; 205 true for a decl that's been bound a second time in an inner scope;
204 in all such cases, the binding in the outer scope will have its 206 in all such cases, the binding in the outer scope will have its
205 invisible bit true. */ 207 invisible bit true. */
206 208
207 struct c_binding GTY((chain_next ("%h.prev"))) 209 struct GTY((chain_next ("%h.prev"))) c_binding {
208 { 210 union GTY(()) { /* first so GTY desc can use decl */
209 tree decl; /* the decl bound */ 211 tree GTY((tag ("0"))) type; /* the type in this scope */
210 tree type; /* the type in this scope */ 212 struct c_label_vars * GTY((tag ("1"))) label; /* for warnings */
211 tree id; /* the identifier it's bound to */ 213 } GTY((desc ("TREE_CODE (%0.decl) == LABEL_DECL"))) u;
212 struct c_binding *prev; /* the previous decl in this scope */ 214 tree decl; /* the decl bound */
213 struct c_binding *shadowed; /* the innermost decl shadowed by this one */ 215 tree id; /* the identifier it's bound to */
216 struct c_binding *prev; /* the previous decl in this scope */
217 struct c_binding *shadowed; /* the innermost decl shadowed by this one */
214 unsigned int depth : 28; /* depth of this scope */ 218 unsigned int depth : 28; /* depth of this scope */
215 BOOL_BITFIELD invisible : 1; /* normal lookup should ignore this binding */ 219 BOOL_BITFIELD invisible : 1; /* normal lookup should ignore this binding */
216 BOOL_BITFIELD nested : 1; /* do not set DECL_CONTEXT when popping */ 220 BOOL_BITFIELD nested : 1; /* do not set DECL_CONTEXT when popping */
217 BOOL_BITFIELD inner_comp : 1; /* incomplete array completed in inner scope */ 221 BOOL_BITFIELD inner_comp : 1; /* incomplete array completed in inner scope */
218 /* one free bit */ 222 BOOL_BITFIELD in_struct : 1; /* currently defined as struct field */
223 location_t locus; /* location for nested bindings */
219 }; 224 };
220 #define B_IN_SCOPE(b1, b2) ((b1)->depth == (b2)->depth) 225 #define B_IN_SCOPE(b1, b2) ((b1)->depth == (b2)->depth)
221 #define B_IN_CURRENT_SCOPE(b) ((b)->depth == current_scope->depth) 226 #define B_IN_CURRENT_SCOPE(b) ((b)->depth == current_scope->depth)
222 #define B_IN_FILE_SCOPE(b) ((b)->depth == 1 /*file_scope->depth*/) 227 #define B_IN_FILE_SCOPE(b) ((b)->depth == 1 /*file_scope->depth*/)
223 #define B_IN_EXTERNAL_SCOPE(b) ((b)->depth == 0 /*external_scope->depth*/) 228 #define B_IN_EXTERNAL_SCOPE(b) ((b)->depth == 0 /*external_scope->depth*/)
239 244
240 /* Each C symbol points to three linked lists of c_binding structures. 245 /* Each C symbol points to three linked lists of c_binding structures.
241 These describe the values of the identifier in the three different 246 These describe the values of the identifier in the three different
242 namespaces defined by the language. */ 247 namespaces defined by the language. */
243 248
244 struct lang_identifier GTY(()) 249 struct GTY(()) lang_identifier {
245 {
246 struct c_common_identifier common_id; 250 struct c_common_identifier common_id;
247 struct c_binding *symbol_binding; /* vars, funcs, constants, typedefs */ 251 struct c_binding *symbol_binding; /* vars, funcs, constants, typedefs */
248 struct c_binding *tag_binding; /* struct/union/enum tags */ 252 struct c_binding *tag_binding; /* struct/union/enum tags */
249 struct c_binding *label_binding; /* labels */ 253 struct c_binding *label_binding; /* labels */
250 }; 254 };
253 extern char C_SIZEOF_STRUCT_LANG_IDENTIFIER_isnt_accurate 257 extern char C_SIZEOF_STRUCT_LANG_IDENTIFIER_isnt_accurate
254 [(sizeof(struct lang_identifier) == C_SIZEOF_STRUCT_LANG_IDENTIFIER) ? 1 : -1]; 258 [(sizeof(struct lang_identifier) == C_SIZEOF_STRUCT_LANG_IDENTIFIER) ? 1 : -1];
255 259
256 /* The resulting tree type. */ 260 /* The resulting tree type. */
257 261
258 union lang_tree_node 262 union GTY((desc ("TREE_CODE (&%h.generic) == IDENTIFIER_NODE"),
259 GTY((desc ("TREE_CODE (&%h.generic) == IDENTIFIER_NODE"), 263 chain_next ("TREE_CODE (&%h.generic) == INTEGER_TYPE ? (union lang_tree_node *) TYPE_NEXT_VARIANT (&%h.generic) : ((union lang_tree_node *) TREE_CHAIN (&%h.generic))"))) lang_tree_node
260 chain_next ("TREE_CODE (&%h.generic) == INTEGER_TYPE ? (union lang_tree_node *) TYPE_NEXT_VARIANT (&%h.generic) : ((union lang_tree_node *) TREE_CHAIN (&%h.generic))"))) 264 {
261 {
262 union tree_node GTY ((tag ("0"), 265 union tree_node GTY ((tag ("0"),
263 desc ("tree_node_structure (&%h)"))) 266 desc ("tree_node_structure (&%h)")))
264 generic; 267 generic;
265 struct lang_identifier GTY ((tag ("1"))) identifier; 268 struct lang_identifier GTY ((tag ("1"))) identifier;
269 };
270
271 /* Track bindings and other things that matter for goto warnings. For
272 efficiency, we do not gather all the decls at the point of
273 definition. Instead, we point into the bindings structure. As
274 scopes are popped, we update these structures and gather the decls
275 that matter at that time. */
276
277 struct GTY(()) c_spot_bindings {
278 /* The currently open scope which holds bindings defined when the
279 label was defined or the goto statement was found. */
280 struct c_scope *scope;
281 /* The bindings in the scope field which were defined at the point
282 of the label or goto. This lets us look at older or newer
283 bindings in the scope, as appropriate. */
284 struct c_binding *bindings_in_scope;
285 /* The number of statement expressions that have started since this
286 label or goto statement was defined. This is zero if we are at
287 the same statement expression level. It is positive if we are in
288 a statement expression started since this spot. It is negative
289 if this spot was in a statement expression and we have left
290 it. */
291 int stmt_exprs;
292 /* Whether we started in a statement expression but are no longer in
293 it. This is set to true if stmt_exprs ever goes negative. */
294 bool left_stmt_expr;
295 };
296
297 /* This structure is used to keep track of bindings seen when a goto
298 statement is defined. This is only used if we see the goto
299 statement before we see the label. */
300
301 struct GTY(()) c_goto_bindings {
302 /* The location of the goto statement. */
303 location_t loc;
304 /* The bindings of the goto statement. */
305 struct c_spot_bindings goto_bindings;
306 };
307
308 typedef struct c_goto_bindings *c_goto_bindings_p;
309 DEF_VEC_P(c_goto_bindings_p);
310 DEF_VEC_ALLOC_P(c_goto_bindings_p,gc);
311
312 /* The additional information we keep track of for a label binding.
313 These fields are updated as scopes are popped. */
314
315 struct GTY(()) c_label_vars {
316 /* The shadowed c_label_vars, when one label shadows another (which
317 can only happen using a __label__ declaration). */
318 struct c_label_vars *shadowed;
319 /* The bindings when the label was defined. */
320 struct c_spot_bindings label_bindings;
321 /* A list of decls that we care about: decls about which we should
322 warn if a goto branches to this label from later in the function.
323 Decls are added to this list as scopes are popped. We only add
324 the decls that matter. */
325 VEC(tree,gc) *decls_in_scope;
326 /* A list of goto statements to this label. This is only used for
327 goto statements seen before the label was defined, so that we can
328 issue appropriate warnings for them. */
329 VEC(c_goto_bindings_p,gc) *gotos;
266 }; 330 };
267 331
268 /* Each c_scope structure describes the complete contents of one 332 /* Each c_scope structure describes the complete contents of one
269 scope. Four scopes are distinguished specially: the innermost or 333 scope. Four scopes are distinguished specially: the innermost or
270 current scope, the innermost function scope, the file scope (always 334 current scope, the innermost function scope, the file scope (always
308 372
309 The bindings list is strictly in reverse order of declarations; 373 The bindings list is strictly in reverse order of declarations;
310 pop_scope relies on this. */ 374 pop_scope relies on this. */
311 375
312 376
313 struct c_scope GTY((chain_next ("%h.outer"))) 377 struct GTY((chain_next ("%h.outer"))) c_scope {
314 {
315 /* The scope containing this one. */ 378 /* The scope containing this one. */
316 struct c_scope *outer; 379 struct c_scope *outer;
317 380
318 /* The next outermost function scope. */ 381 /* The next outermost function scope. */
319 struct c_scope *outer_function; 382 struct c_scope *outer_function;
349 nested functions, or declared at block scope with __label__). */ 412 nested functions, or declared at block scope with __label__). */
350 BOOL_BITFIELD function_body : 1; 413 BOOL_BITFIELD function_body : 1;
351 414
352 /* True means make a BLOCK for this scope no matter what. */ 415 /* True means make a BLOCK for this scope no matter what. */
353 BOOL_BITFIELD keep : 1; 416 BOOL_BITFIELD keep : 1;
417
418 /* True means that an unsuffixed float constant is _Decimal64. */
419 BOOL_BITFIELD float_const_decimal64 : 1;
420
421 /* True if this scope has any label bindings. This is used to speed
422 up searching for labels when popping scopes, particularly since
423 labels are normally only found at function scope. */
424 BOOL_BITFIELD has_label_bindings : 1;
354 }; 425 };
355 426
356 /* The scope currently in effect. */ 427 /* The scope currently in effect. */
357 428
358 static GTY(()) struct c_scope *current_scope; 429 static GTY(()) struct c_scope *current_scope;
379 /* A chain of c_binding structures awaiting reuse. */ 450 /* A chain of c_binding structures awaiting reuse. */
380 451
381 static GTY((deletable)) struct c_binding *binding_freelist; 452 static GTY((deletable)) struct c_binding *binding_freelist;
382 453
383 /* Append VAR to LIST in scope SCOPE. */ 454 /* Append VAR to LIST in scope SCOPE. */
384 #define SCOPE_LIST_APPEND(scope, list, decl) do { \ 455 #define SCOPE_LIST_APPEND(scope, list, decl) do { \
385 struct c_scope *s_ = (scope); \ 456 struct c_scope *s_ = (scope); \
386 tree d_ = (decl); \ 457 tree d_ = (decl); \
387 if (s_->list##_last) \ 458 if (s_->list##_last) \
388 BLOCK_CHAIN (s_->list##_last) = d_; \ 459 BLOCK_CHAIN (s_->list##_last) = d_; \
389 else \ 460 else \
390 s_->list = d_; \ 461 s_->list = d_; \
391 s_->list##_last = d_; \ 462 s_->list##_last = d_; \
392 } while (0) 463 } while (0)
393 464
394 /* Concatenate FROM in scope FSCOPE onto TO in scope TSCOPE. */ 465 /* Concatenate FROM in scope FSCOPE onto TO in scope TSCOPE. */
395 #define SCOPE_LIST_CONCAT(tscope, to, fscope, from) do { \ 466 #define SCOPE_LIST_CONCAT(tscope, to, fscope, from) do { \
396 struct c_scope *t_ = (tscope); \ 467 struct c_scope *t_ = (tscope); \
397 struct c_scope *f_ = (fscope); \ 468 struct c_scope *f_ = (fscope); \
398 if (t_->to##_last) \ 469 if (t_->to##_last) \
399 BLOCK_CHAIN (t_->to##_last) = f_->from; \ 470 BLOCK_CHAIN (t_->to##_last) = f_->from; \
400 else \ 471 else \
401 t_->to = f_->from; \ 472 t_->to = f_->from; \
402 t_->to##_last = f_->from##_last; \ 473 t_->to##_last = f_->from##_last; \
403 } while (0) 474 } while (0)
475
476 /* A c_inline_static structure stores details of a static identifier
477 referenced in a definition of a function that may be an inline
478 definition if no subsequent declaration of that function uses
479 "extern" or does not use "inline". */
480
481 struct GTY((chain_next ("%h.next"))) c_inline_static {
482 /* The location for a diagnostic. */
483 location_t location;
484
485 /* The function that may be an inline definition. */
486 tree function;
487
488 /* The object or function referenced. */
489 tree static_decl;
490
491 /* What sort of reference this is. */
492 enum c_inline_static_type type;
493
494 /* The next such structure or NULL. */
495 struct c_inline_static *next;
496 };
497
498 /* List of static identifiers used or referenced in functions that may
499 be inline definitions. */
500 static GTY(()) struct c_inline_static *c_inline_statics;
404 501
405 /* True means unconditionally make a BLOCK for the next scope pushed. */ 502 /* True means unconditionally make a BLOCK for the next scope pushed. */
406 503
407 static bool keep_next_level_flag; 504 static bool keep_next_level_flag;
408 505
410 of a function body, so do not push a new scope, merely cease 507 of a function body, so do not push a new scope, merely cease
411 expecting parameter decls. */ 508 expecting parameter decls. */
412 509
413 static bool next_is_function_body; 510 static bool next_is_function_body;
414 511
512 /* A VEC of pointers to c_binding structures. */
513
514 typedef struct c_binding *c_binding_ptr;
515 DEF_VEC_P(c_binding_ptr);
516 DEF_VEC_ALLOC_P(c_binding_ptr,heap);
517
518 /* Information that we keep for a struct or union while it is being
519 parsed. */
520
521 struct c_struct_parse_info
522 {
523 /* If warn_cxx_compat, a list of types defined within this
524 struct. */
525 VEC(tree,heap) *struct_types;
526 /* If warn_cxx_compat, a list of field names which have bindings,
527 and which are defined in this struct, but which are not defined
528 in any enclosing struct. This is used to clear the in_struct
529 field of the c_bindings structure. */
530 VEC(c_binding_ptr,heap) *fields;
531 /* If warn_cxx_compat, a list of typedef names used when defining
532 fields in this struct. */
533 VEC(tree,heap) *typedefs_seen;
534 };
535
536 /* Information for the struct or union currently being parsed, or
537 NULL if not parsing a struct or union. */
538 static struct c_struct_parse_info *struct_parse_info;
539
415 /* Forward declarations. */ 540 /* Forward declarations. */
416 static tree lookup_name_in_scope (tree, struct c_scope *); 541 static tree lookup_name_in_scope (tree, struct c_scope *);
417 static tree c_make_fname_decl (tree, int); 542 static tree c_make_fname_decl (location_t, tree, int);
418 static tree grokdeclarator (const struct c_declarator *, 543 static tree grokdeclarator (const struct c_declarator *,
419 struct c_declspecs *, 544 struct c_declspecs *,
420 enum decl_context, bool, tree *, tree *, 545 enum decl_context, bool, tree *, tree *, tree *,
421 enum deprecated_states); 546 bool *, enum deprecated_states);
422 static tree grokparms (struct c_arg_info *, bool); 547 static tree grokparms (struct c_arg_info *, bool);
423 static void layout_array_type (tree); 548 static void layout_array_type (tree);
424 549
425 /* T is a statement. Add it to the statement-tree. This is the 550 /* T is a statement. Add it to the statement-tree. This is the
426 C/ObjC version--C++ has a slightly different version of this 551 C/ObjC version--C++ has a slightly different version of this
432 enum tree_code code = TREE_CODE (t); 557 enum tree_code code = TREE_CODE (t);
433 558
434 if (CAN_HAVE_LOCATION_P (t) && code != LABEL_EXPR) 559 if (CAN_HAVE_LOCATION_P (t) && code != LABEL_EXPR)
435 { 560 {
436 if (!EXPR_HAS_LOCATION (t)) 561 if (!EXPR_HAS_LOCATION (t))
437 SET_EXPR_LOCATION (t, input_location); 562 SET_EXPR_LOCATION (t, input_location);
438 } 563 }
439 564
440 if (code == LABEL_EXPR || code == CASE_LABEL_EXPR) 565 if (code == LABEL_EXPR || code == CASE_LABEL_EXPR)
441 STATEMENT_LIST_HAS_LABEL (cur_stmt_list) = 1; 566 STATEMENT_LIST_HAS_LABEL (cur_stmt_list) = 1;
442 567
456 print_node (file, "label", I_LABEL_DECL (node), indent + 4); 581 print_node (file, "label", I_LABEL_DECL (node), indent + 4);
457 if (C_IS_RESERVED_WORD (node) && C_RID_CODE (node) != RID_CXX_COMPAT_WARN) 582 if (C_IS_RESERVED_WORD (node) && C_RID_CODE (node) != RID_CXX_COMPAT_WARN)
458 { 583 {
459 tree rid = ridpointers[C_RID_CODE (node)]; 584 tree rid = ridpointers[C_RID_CODE (node)];
460 indent_to (file, indent + 4); 585 indent_to (file, indent + 4);
461 fprintf (file, "rid %p \"%s\"", 586 fprintf (file, "rid " HOST_PTR_PRINTF " \"%s\"",
462 (void *) rid, IDENTIFIER_POINTER (rid)); 587 (void *) rid, IDENTIFIER_POINTER (rid));
463 } 588 }
464 } 589 }
465 590
466 /* Establish a binding between NAME, an IDENTIFIER_NODE, and DECL, 591 /* Establish a binding between NAME, an IDENTIFIER_NODE, and DECL,
467 which may be any of several kinds of DECL or TYPE or error_mark_node, 592 which may be any of several kinds of DECL or TYPE or error_mark_node,
468 in the scope SCOPE. */ 593 in the scope SCOPE. */
469 static void 594 static void
470 bind (tree name, tree decl, struct c_scope *scope, bool invisible, bool nested) 595 bind (tree name, tree decl, struct c_scope *scope, bool invisible,
596 bool nested, location_t locus)
471 { 597 {
472 struct c_binding *b, **here; 598 struct c_binding *b, **here;
473 599
474 if (binding_freelist) 600 if (binding_freelist)
475 { 601 {
484 b->id = name; 610 b->id = name;
485 b->depth = scope->depth; 611 b->depth = scope->depth;
486 b->invisible = invisible; 612 b->invisible = invisible;
487 b->nested = nested; 613 b->nested = nested;
488 b->inner_comp = 0; 614 b->inner_comp = 0;
489 615 b->in_struct = 0;
490 b->type = 0; 616 b->locus = locus;
617
618 b->u.type = NULL;
491 619
492 b->prev = scope->bindings; 620 b->prev = scope->bindings;
493 scope->bindings = b; 621 scope->bindings = b;
494 622
495 if (!name) 623 if (!name)
536 binding_freelist = b; 664 binding_freelist = b;
537 665
538 return prev; 666 return prev;
539 } 667 }
540 668
669 /* Bind a label. Like bind, but skip fields which aren't used for
670 labels, and add the LABEL_VARS value. */
671 static void
672 bind_label (tree name, tree label, struct c_scope *scope,
673 struct c_label_vars *label_vars)
674 {
675 struct c_binding *b;
676
677 bind (name, label, scope, /*invisible=*/false, /*nested=*/false,
678 UNKNOWN_LOCATION);
679
680 scope->has_label_bindings = true;
681
682 b = scope->bindings;
683 gcc_assert (b->decl == label);
684 label_vars->shadowed = b->u.label;
685 b->u.label = label_vars;
686 }
541 687
542 /* Hook called at end of compilation to assume 1 elt 688 /* Hook called at end of compilation to assume 1 elt
543 for a file-scope tentative array defn that wasn't complete before. */ 689 for a file-scope tentative array defn that wasn't complete before. */
544 690
545 void 691 void
547 { 693 {
548 if (TREE_CODE (decl) == VAR_DECL) 694 if (TREE_CODE (decl) == VAR_DECL)
549 { 695 {
550 tree type = TREE_TYPE (decl); 696 tree type = TREE_TYPE (decl);
551 if (type != error_mark_node 697 if (type != error_mark_node
552 && TREE_CODE (type) == ARRAY_TYPE 698 && TREE_CODE (type) == ARRAY_TYPE
553 && !DECL_EXTERNAL (decl) 699 && !DECL_EXTERNAL (decl)
554 && TYPE_DOMAIN (type) == 0) 700 && TYPE_DOMAIN (type) == 0)
555 { 701 {
556 warning (0, "array %q+D assumed to have one element", decl); 702 warning_at (DECL_SOURCE_LOCATION (decl),
557 703 0, "array %q+D assumed to have one element", decl);
558 complete_array_type (&TREE_TYPE (decl), NULL_TREE, true); 704
559 705 complete_array_type (&TREE_TYPE (decl), NULL_TREE, true);
560 layout_decl (decl, 0); 706
561 } 707 layout_decl (decl, 0);
562 } 708 }
709 }
710 }
711
712 /* Record that inline function FUNC contains a reference (location
713 LOC) to static DECL (file-scope or function-local according to
714 TYPE). */
715
716 void
717 record_inline_static (location_t loc, tree func, tree decl,
718 enum c_inline_static_type type)
719 {
720 struct c_inline_static *csi = GGC_NEW (struct c_inline_static);
721 csi->location = loc;
722 csi->function = func;
723 csi->static_decl = decl;
724 csi->type = type;
725 csi->next = c_inline_statics;
726 c_inline_statics = csi;
727 }
728
729 /* Check for references to static declarations in inline functions at
730 the end of the translation unit and diagnose them if the functions
731 are still inline definitions. */
732
733 static void
734 check_inline_statics (void)
735 {
736 struct c_inline_static *csi;
737 for (csi = c_inline_statics; csi; csi = csi->next)
738 {
739 if (DECL_EXTERNAL (csi->function))
740 switch (csi->type)
741 {
742 case csi_internal:
743 pedwarn (csi->location, 0,
744 "%qD is static but used in inline function %qD "
745 "which is not static", csi->static_decl, csi->function);
746 break;
747 case csi_modifiable:
748 pedwarn (csi->location, 0,
749 "%q+D is static but declared in inline function %qD "
750 "which is not static", csi->static_decl, csi->function);
751 break;
752 default:
753 gcc_unreachable ();
754 }
755 }
756 c_inline_statics = NULL;
757 }
758
759 /* Fill in a c_spot_bindings structure. If DEFINING is true, set it
760 for the current state, otherwise set it to uninitialized. */
761
762 static void
763 set_spot_bindings (struct c_spot_bindings *p, bool defining)
764 {
765 if (defining)
766 {
767 p->scope = current_scope;
768 p->bindings_in_scope = current_scope->bindings;
769 }
770 else
771 {
772 p->scope = NULL;
773 p->bindings_in_scope = NULL;
774 }
775 p->stmt_exprs = 0;
776 p->left_stmt_expr = false;
777 }
778
779 /* Return true if we will want to say something if a goto statement
780 crosses DECL. */
781
782 static bool
783 decl_jump_unsafe (tree decl)
784 {
785 if (decl == error_mark_node || TREE_TYPE (decl) == error_mark_node)
786 return false;
787
788 /* Always warn about crossing variably modified types. */
789 if ((TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == TYPE_DECL)
790 && variably_modified_type_p (TREE_TYPE (decl), NULL_TREE))
791 return true;
792
793 /* Otherwise, only warn if -Wgoto-misses-init and this is an
794 initialized automatic decl. */
795 if (warn_jump_misses_init
796 && TREE_CODE (decl) == VAR_DECL
797 && !TREE_STATIC (decl)
798 && DECL_INITIAL (decl) != NULL_TREE)
799 return true;
800
801 return false;
802 }
803
804 /* Update spot bindings P as we pop out of SCOPE. Return true if we
805 should push decls for a label. */
806
807 static bool
808 update_spot_bindings (struct c_scope *scope, struct c_spot_bindings *p)
809 {
810 if (p->scope != scope)
811 {
812 /* This label or goto is defined in some other scope, or it is a
813 label which is not yet defined. There is nothing to
814 update. */
815 return false;
816 }
817
818 /* Adjust the spot bindings to refer to the bindings already defined
819 in the enclosing scope. */
820 p->scope = scope->outer;
821 p->bindings_in_scope = p->scope->bindings;
822
823 return true;
563 } 824 }
564 825
565 /* The Objective-C front-end often needs to determine the current scope. */ 826 /* The Objective-C front-end often needs to determine the current scope. */
566 827
567 void * 828 void *
582 for (scope = current_scope; 843 for (scope = current_scope;
583 scope && scope != enclosing_blk; 844 scope && scope != enclosing_blk;
584 scope = scope->outer) 845 scope = scope->outer)
585 { 846 {
586 for (b = scope->bindings; b; b = b->prev) 847 for (b = scope->bindings; b; b = b->prev)
587 objc_volatilize_decl (b->decl); 848 objc_volatilize_decl (b->decl);
588 849
589 /* Do not climb up past the current function. */ 850 /* Do not climb up past the current function. */
590 if (scope->function_body) 851 if (scope->function_body)
591 break; 852 break;
592 } 853 }
593 } 854 }
594 855
595 /* Nonzero if we are currently in file scope. */ 856 /* Nonzero if we are currently in file scope. */
596 857
597 int 858 int
598 global_bindings_p (void) 859 global_bindings_p (void)
599 { 860 {
600 return current_scope == file_scope && !c_override_global_bindings_to_false; 861 return (current_scope == file_scope && !c_override_global_bindings_to_false
862 ? -1
863 : 0);
601 } 864 }
602 865
603 void 866 void
604 keep_next_level (void) 867 keep_next_level (void)
605 { 868 {
606 keep_next_level_flag = true; 869 keep_next_level_flag = true;
607 } 870 }
608 871
872 /* Set the flag for the FLOAT_CONST_DECIMAL64 pragma being ON. */
873
874 void
875 set_float_const_decimal64 (void)
876 {
877 current_scope->float_const_decimal64 = true;
878 }
879
880 /* Clear the flag for the FLOAT_CONST_DECIMAL64 pragma. */
881
882 void
883 clear_float_const_decimal64 (void)
884 {
885 current_scope->float_const_decimal64 = false;
886 }
887
888 /* Return nonzero if an unsuffixed float constant is _Decimal64. */
889
890 bool
891 float_const_decimal64_p (void)
892 {
893 return current_scope->float_const_decimal64;
894 }
895
609 /* Identify this scope as currently being filled with parameters. */ 896 /* Identify this scope as currently being filled with parameters. */
610 897
611 void 898 void
612 declare_parm_level (void) 899 declare_parm_level (void)
613 { 900 {
618 push_scope (void) 905 push_scope (void)
619 { 906 {
620 if (next_is_function_body) 907 if (next_is_function_body)
621 { 908 {
622 /* This is the transition from the parameters to the top level 909 /* This is the transition from the parameters to the top level
623 of the function body. These are the same scope 910 of the function body. These are the same scope
624 (C99 6.2.1p4,6) so we do not push another scope structure. 911 (C99 6.2.1p4,6) so we do not push another scope structure.
625 next_is_function_body is set only by store_parm_decls, which 912 next_is_function_body is set only by store_parm_decls, which
626 in turn is called when and only when we are about to 913 in turn is called when and only when we are about to
627 encounter the opening curly brace for the function body. 914 encounter the opening curly brace for the function body.
628 915
629 The outermost block of a function always gets a BLOCK node, 916 The outermost block of a function always gets a BLOCK node,
630 because the debugging output routines expect that each 917 because the debugging output routines expect that each
631 function has at least one BLOCK. */ 918 function has at least one BLOCK. */
632 current_scope->parm_flag = false; 919 current_scope->parm_flag = false;
633 current_scope->function_body = true; 920 current_scope->function_body = true;
634 current_scope->keep = true; 921 current_scope->keep = true;
635 current_scope->outer_function = current_function_scope; 922 current_scope->outer_function = current_function_scope;
636 current_function_scope = current_scope; 923 current_function_scope = current_scope;
637 924
638 keep_next_level_flag = false; 925 keep_next_level_flag = false;
639 next_is_function_body = false; 926 next_is_function_body = false;
927
928 /* The FLOAT_CONST_DECIMAL64 pragma applies to nested scopes. */
929 if (current_scope->outer)
930 current_scope->float_const_decimal64
931 = current_scope->outer->float_const_decimal64;
932 else
933 current_scope->float_const_decimal64 = false;
640 } 934 }
641 else 935 else
642 { 936 {
643 struct c_scope *scope; 937 struct c_scope *scope;
644 if (scope_freelist) 938 if (scope_freelist)
645 { 939 {
646 scope = scope_freelist; 940 scope = scope_freelist;
647 scope_freelist = scope->outer; 941 scope_freelist = scope->outer;
648 } 942 }
649 else 943 else
650 scope = GGC_CNEW (struct c_scope); 944 scope = GGC_CNEW (struct c_scope);
945
946 /* The FLOAT_CONST_DECIMAL64 pragma applies to nested scopes. */
947 if (current_scope)
948 scope->float_const_decimal64 = current_scope->float_const_decimal64;
949 else
950 scope->float_const_decimal64 = false;
651 951
652 scope->keep = keep_next_level_flag; 952 scope->keep = keep_next_level_flag;
653 scope->outer = current_scope; 953 scope->outer = current_scope;
654 scope->depth = current_scope ? (current_scope->depth + 1) : 0; 954 scope->depth = current_scope ? (current_scope->depth + 1) : 0;
655 955
656 /* Check for scope depth overflow. Unlikely (2^28 == 268,435,456) but 956 /* Check for scope depth overflow. Unlikely (2^28 == 268,435,456) but
657 possible. */ 957 possible. */
658 if (current_scope && scope->depth == 0) 958 if (current_scope && scope->depth == 0)
659 { 959 {
660 scope->depth--; 960 scope->depth--;
661 sorry ("GCC supports only %u nested scopes", scope->depth); 961 sorry ("GCC supports only %u nested scopes", scope->depth);
662 } 962 }
663 963
664 current_scope = scope; 964 current_scope = scope;
665 keep_next_level_flag = false; 965 keep_next_level_flag = false;
966 }
967 }
968
969 /* This is called when we are leaving SCOPE. For each label defined
970 in SCOPE, add any appropriate decls to its decls_in_scope fields.
971 These are the decls whose initialization will be skipped by a goto
972 later in the function. */
973
974 static void
975 update_label_decls (struct c_scope *scope)
976 {
977 struct c_scope *s;
978
979 s = scope;
980 while (s != NULL)
981 {
982 if (s->has_label_bindings)
983 {
984 struct c_binding *b;
985
986 for (b = s->bindings; b != NULL; b = b->prev)
987 {
988 struct c_label_vars *label_vars;
989 struct c_binding *b1;
990 unsigned int ix;
991 struct c_goto_bindings *g;
992
993 if (TREE_CODE (b->decl) != LABEL_DECL)
994 continue;
995 label_vars = b->u.label;
996
997 b1 = label_vars->label_bindings.bindings_in_scope;
998 if (update_spot_bindings (scope, &label_vars->label_bindings))
999 {
1000 /* This label is defined in this scope. */
1001 for (; b1 != NULL; b1 = b1->prev)
1002 {
1003 /* A goto from later in the function to this
1004 label will never see the initialization of
1005 B1, if any. Save it to issue a warning if
1006 needed. */
1007 if (decl_jump_unsafe (b1->decl))
1008 VEC_safe_push (tree, gc, label_vars->decls_in_scope,
1009 b1->decl);
1010 }
1011 }
1012
1013 /* Update the bindings of any goto statements associated
1014 with this label. */
1015 for (ix = 0;
1016 VEC_iterate (c_goto_bindings_p, label_vars->gotos, ix, g);
1017 ++ix)
1018 update_spot_bindings (scope, &g->goto_bindings);
1019 }
1020 }
1021
1022 /* Don't search beyond the current function. */
1023 if (s == current_function_scope)
1024 break;
1025
1026 s = s->outer;
666 } 1027 }
667 } 1028 }
668 1029
669 /* Set the TYPE_CONTEXT of all of TYPE's variants to CONTEXT. */ 1030 /* Set the TYPE_CONTEXT of all of TYPE's variants to CONTEXT. */
670 1031
689 struct c_binding *b; 1050 struct c_binding *b;
690 1051
691 bool functionbody = scope->function_body; 1052 bool functionbody = scope->function_body;
692 bool keep = functionbody || scope->keep || scope->bindings; 1053 bool keep = functionbody || scope->keep || scope->bindings;
693 1054
694 c_end_vm_scope (scope->depth); 1055 update_label_decls (scope);
695 1056
696 /* If appropriate, create a BLOCK to record the decls for the life 1057 /* If appropriate, create a BLOCK to record the decls for the life
697 of this function. */ 1058 of this function. */
698 block = 0; 1059 block = 0;
699 if (keep) 1060 if (keep)
702 BLOCK_SUBBLOCKS (block) = scope->blocks; 1063 BLOCK_SUBBLOCKS (block) = scope->blocks;
703 TREE_USED (block) = 1; 1064 TREE_USED (block) = 1;
704 1065
705 /* In each subblock, record that this is its superior. */ 1066 /* In each subblock, record that this is its superior. */
706 for (p = scope->blocks; p; p = BLOCK_CHAIN (p)) 1067 for (p = scope->blocks; p; p = BLOCK_CHAIN (p))
707 BLOCK_SUPERCONTEXT (p) = block; 1068 BLOCK_SUPERCONTEXT (p) = block;
708 1069
709 BLOCK_VARS (block) = 0; 1070 BLOCK_VARS (block) = 0;
710 } 1071 }
711 1072
712 /* The TYPE_CONTEXTs for all of the tagged types belonging to this 1073 /* The TYPE_CONTEXTs for all of the tagged types belonging to this
724 "parameter list local" tagged types. */ 1085 "parameter list local" tagged types. */
725 if (scope->function_body) 1086 if (scope->function_body)
726 context = current_function_decl; 1087 context = current_function_decl;
727 else if (scope == file_scope) 1088 else if (scope == file_scope)
728 { 1089 {
729 tree file_decl = build_decl (TRANSLATION_UNIT_DECL, 0, 0); 1090 tree file_decl = build_decl (UNKNOWN_LOCATION,
1091 TRANSLATION_UNIT_DECL, 0, 0);
730 TREE_CHAIN (file_decl) = all_translation_units; 1092 TREE_CHAIN (file_decl) = all_translation_units;
731 all_translation_units = file_decl; 1093 all_translation_units = file_decl;
732 context = file_decl; 1094 context = file_decl;
733 } 1095 }
734 else 1096 else
737 /* Clear all bindings in this scope. */ 1099 /* Clear all bindings in this scope. */
738 for (b = scope->bindings; b; b = free_binding_and_advance (b)) 1100 for (b = scope->bindings; b; b = free_binding_and_advance (b))
739 { 1101 {
740 p = b->decl; 1102 p = b->decl;
741 switch (TREE_CODE (p)) 1103 switch (TREE_CODE (p))
742 { 1104 {
743 case LABEL_DECL: 1105 case LABEL_DECL:
744 /* Warnings for unused labels, errors for undefined labels. */ 1106 /* Warnings for unused labels, errors for undefined labels. */
745 if (TREE_USED (p) && !DECL_INITIAL (p)) 1107 if (TREE_USED (p) && !DECL_INITIAL (p))
746 { 1108 {
747 error ("label %q+D used but not defined", p); 1109 error ("label %q+D used but not defined", p);
748 DECL_INITIAL (p) = error_mark_node; 1110 DECL_INITIAL (p) = error_mark_node;
749 } 1111 }
750 else 1112 else
751 warn_for_unused_label (p); 1113 warn_for_unused_label (p);
752 1114
753 /* Labels go in BLOCK_VARS. */ 1115 /* Labels go in BLOCK_VARS. */
754 TREE_CHAIN (p) = BLOCK_VARS (block); 1116 TREE_CHAIN (p) = BLOCK_VARS (block);
755 BLOCK_VARS (block) = p; 1117 BLOCK_VARS (block) = p;
756 gcc_assert (I_LABEL_BINDING (b->id) == b); 1118 gcc_assert (I_LABEL_BINDING (b->id) == b);
757 I_LABEL_BINDING (b->id) = b->shadowed; 1119 I_LABEL_BINDING (b->id) = b->shadowed;
758 break; 1120
759 1121 /* Also pop back to the shadowed label_vars. */
760 case ENUMERAL_TYPE: 1122 release_tree_vector (b->u.label->decls_in_scope);
761 case UNION_TYPE: 1123 b->u.label = b->u.label->shadowed;
762 case RECORD_TYPE: 1124 break;
763 set_type_context (p, context); 1125
764 1126 case ENUMERAL_TYPE:
765 /* Types may not have tag-names, in which case the type 1127 case UNION_TYPE:
766 appears in the bindings list with b->id NULL. */ 1128 case RECORD_TYPE:
767 if (b->id) 1129 set_type_context (p, context);
768 { 1130
769 gcc_assert (I_TAG_BINDING (b->id) == b); 1131 /* Types may not have tag-names, in which case the type
770 I_TAG_BINDING (b->id) = b->shadowed; 1132 appears in the bindings list with b->id NULL. */
771 } 1133 if (b->id)
772 break; 1134 {
773 1135 gcc_assert (I_TAG_BINDING (b->id) == b);
774 case FUNCTION_DECL: 1136 I_TAG_BINDING (b->id) = b->shadowed;
775 /* Propagate TREE_ADDRESSABLE from nested functions to their 1137 }
776 containing functions. */ 1138 break;
777 if (!TREE_ASM_WRITTEN (p) 1139
778 && DECL_INITIAL (p) != 0 1140 case FUNCTION_DECL:
779 && TREE_ADDRESSABLE (p) 1141 /* Propagate TREE_ADDRESSABLE from nested functions to their
780 && DECL_ABSTRACT_ORIGIN (p) != 0 1142 containing functions. */
781 && DECL_ABSTRACT_ORIGIN (p) != p) 1143 if (!TREE_ASM_WRITTEN (p)
782 TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (p)) = 1; 1144 && DECL_INITIAL (p) != 0
783 if (!DECL_EXTERNAL (p) 1145 && TREE_ADDRESSABLE (p)
784 && !DECL_INITIAL (p) 1146 && DECL_ABSTRACT_ORIGIN (p) != 0
785 && scope != file_scope 1147 && DECL_ABSTRACT_ORIGIN (p) != p)
786 && scope != external_scope) 1148 TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (p)) = 1;
787 { 1149 if (!DECL_EXTERNAL (p)
788 error ("nested function %q+D declared but never defined", p); 1150 && !DECL_INITIAL (p)
789 undef_nested_function = true; 1151 && scope != file_scope
790 } 1152 && scope != external_scope)
791 else if (DECL_DECLARED_INLINE_P (p) 1153 {
792 && TREE_PUBLIC (p) 1154 error ("nested function %q+D declared but never defined", p);
793 && !DECL_INITIAL (p)) 1155 undef_nested_function = true;
794 { 1156 }
795 /* C99 6.7.4p6: "a function with external linkage... declared 1157 else if (DECL_DECLARED_INLINE_P (p)
796 with an inline function specifier ... shall also be defined 1158 && TREE_PUBLIC (p)
797 in the same translation unit." */ 1159 && !DECL_INITIAL (p))
798 if (!flag_gnu89_inline) 1160 {
799 pedwarn (input_location, 0, 1161 /* C99 6.7.4p6: "a function with external linkage... declared
800 "inline function %q+D declared but never defined", p); 1162 with an inline function specifier ... shall also be defined
801 DECL_EXTERNAL (p) = 1; 1163 in the same translation unit." */
802 } 1164 if (!flag_gnu89_inline)
803 1165 pedwarn (input_location, 0,
804 goto common_symbol; 1166 "inline function %q+D declared but never defined", p);
805 1167 DECL_EXTERNAL (p) = 1;
806 case VAR_DECL: 1168 }
807 /* Warnings for unused variables. */ 1169
808 if (!TREE_USED (p) 1170 goto common_symbol;
809 && !TREE_NO_WARNING (p) 1171
810 && !DECL_IN_SYSTEM_HEADER (p) 1172 case VAR_DECL:
811 && DECL_NAME (p) 1173 /* Warnings for unused variables. */
812 && !DECL_ARTIFICIAL (p) 1174 if (!TREE_USED (p)
813 && scope != file_scope 1175 && !TREE_NO_WARNING (p)
814 && scope != external_scope) 1176 && !DECL_IN_SYSTEM_HEADER (p)
815 warning (OPT_Wunused_variable, "unused variable %q+D", p); 1177 && DECL_NAME (p)
816 1178 && !DECL_ARTIFICIAL (p)
817 if (b->inner_comp) 1179 && scope != file_scope
818 { 1180 && scope != external_scope)
819 error ("type of array %q+D completed incompatibly with" 1181 warning (OPT_Wunused_variable, "unused variable %q+D", p);
820 " implicit initialization", p); 1182
821 } 1183 if (b->inner_comp)
822 1184 {
823 /* Fall through. */ 1185 error ("type of array %q+D completed incompatibly with"
824 case TYPE_DECL: 1186 " implicit initialization", p);
825 case CONST_DECL: 1187 }
826 common_symbol: 1188
827 /* All of these go in BLOCK_VARS, but only if this is the 1189 /* Fall through. */
828 binding in the home scope. */ 1190 case TYPE_DECL:
829 if (!b->nested) 1191 case CONST_DECL:
830 { 1192 common_symbol:
831 TREE_CHAIN (p) = BLOCK_VARS (block); 1193 /* All of these go in BLOCK_VARS, but only if this is the
832 BLOCK_VARS (block) = p; 1194 binding in the home scope. */
833 } 1195 if (!b->nested)
834 /* If this is the file scope, and we are processing more 1196 {
835 than one translation unit in this compilation, set 1197 TREE_CHAIN (p) = BLOCK_VARS (block);
836 DECL_CONTEXT of each decl to the TRANSLATION_UNIT_DECL. 1198 BLOCK_VARS (block) = p;
837 This makes same_translation_unit_p work, and causes 1199 }
838 static declarations to be given disambiguating suffixes. */ 1200 else if (VAR_OR_FUNCTION_DECL_P (p))
839 if (scope == file_scope && num_in_fnames > 1) 1201 {
840 { 1202 /* For block local externs add a special
841 DECL_CONTEXT (p) = context; 1203 DECL_EXTERNAL decl for debug info generation. */
842 if (TREE_CODE (p) == TYPE_DECL) 1204 tree extp = copy_node (p);
843 set_type_context (TREE_TYPE (p), context); 1205
844 } 1206 DECL_EXTERNAL (extp) = 1;
845 1207 TREE_STATIC (extp) = 0;
846 /* Fall through. */ 1208 TREE_PUBLIC (extp) = 1;
847 /* Parameters go in DECL_ARGUMENTS, not BLOCK_VARS, and have 1209 DECL_INITIAL (extp) = NULL_TREE;
848 already been put there by store_parm_decls. Unused- 1210 DECL_LANG_SPECIFIC (extp) = NULL;
849 parameter warnings are handled by function.c. 1211 DECL_CONTEXT (extp) = current_function_decl;
850 error_mark_node obviously does not go in BLOCK_VARS and 1212 if (TREE_CODE (p) == FUNCTION_DECL)
851 does not get unused-variable warnings. */ 1213 {
852 case PARM_DECL: 1214 DECL_RESULT (extp) = NULL_TREE;
853 case ERROR_MARK: 1215 DECL_SAVED_TREE (extp) = NULL_TREE;
854 /* It is possible for a decl not to have a name. We get 1216 DECL_STRUCT_FUNCTION (extp) = NULL;
855 here with b->id NULL in this case. */ 1217 }
856 if (b->id) 1218 if (b->locus != UNKNOWN_LOCATION)
857 { 1219 DECL_SOURCE_LOCATION (extp) = b->locus;
858 gcc_assert (I_SYMBOL_BINDING (b->id) == b); 1220 TREE_CHAIN (extp) = BLOCK_VARS (block);
859 I_SYMBOL_BINDING (b->id) = b->shadowed; 1221 BLOCK_VARS (block) = extp;
860 if (b->shadowed && b->shadowed->type) 1222 }
861 TREE_TYPE (b->shadowed->decl) = b->shadowed->type; 1223 /* If this is the file scope, and we are processing more
862 } 1224 than one translation unit in this compilation, set
863 break; 1225 DECL_CONTEXT of each decl to the TRANSLATION_UNIT_DECL.
864 1226 This makes same_translation_unit_p work, and causes
865 default: 1227 static declarations to be given disambiguating suffixes. */
866 gcc_unreachable (); 1228 if (scope == file_scope && num_in_fnames > 1)
867 } 1229 {
1230 DECL_CONTEXT (p) = context;
1231 if (TREE_CODE (p) == TYPE_DECL)
1232 set_type_context (TREE_TYPE (p), context);
1233 }
1234
1235 /* Fall through. */
1236 /* Parameters go in DECL_ARGUMENTS, not BLOCK_VARS, and have
1237 already been put there by store_parm_decls. Unused-
1238 parameter warnings are handled by function.c.
1239 error_mark_node obviously does not go in BLOCK_VARS and
1240 does not get unused-variable warnings. */
1241 case PARM_DECL:
1242 case ERROR_MARK:
1243 /* It is possible for a decl not to have a name. We get
1244 here with b->id NULL in this case. */
1245 if (b->id)
1246 {
1247 gcc_assert (I_SYMBOL_BINDING (b->id) == b);
1248 I_SYMBOL_BINDING (b->id) = b->shadowed;
1249 if (b->shadowed && b->shadowed->u.type)
1250 TREE_TYPE (b->shadowed->decl) = b->shadowed->u.type;
1251 }
1252 break;
1253
1254 default:
1255 gcc_unreachable ();
1256 }
868 } 1257 }
869 1258
870 1259
871 /* Dispose of the block that we just made inside some higher level. */ 1260 /* Dispose of the block that we just made inside some higher level. */
872 if ((scope->function_body || scope == file_scope) && context) 1261 if ((scope->function_body || scope == file_scope) && context)
875 BLOCK_SUPERCONTEXT (block) = context; 1264 BLOCK_SUPERCONTEXT (block) = context;
876 } 1265 }
877 else if (scope->outer) 1266 else if (scope->outer)
878 { 1267 {
879 if (block) 1268 if (block)
880 SCOPE_LIST_APPEND (scope->outer, blocks, block); 1269 SCOPE_LIST_APPEND (scope->outer, blocks, block);
881 /* If we did not make a block for the scope just exited, any 1270 /* If we did not make a block for the scope just exited, any
882 blocks made for inner scopes must be carried forward so they 1271 blocks made for inner scopes must be carried forward so they
883 will later become subblocks of something else. */ 1272 will later become subblocks of something else. */
884 else if (scope->blocks) 1273 else if (scope->blocks)
885 SCOPE_LIST_CONCAT (scope->outer, blocks, scope, blocks); 1274 SCOPE_LIST_CONCAT (scope->outer, blocks, scope, blocks);
886 } 1275 }
887 1276
888 /* Pop the current scope, and free the structure for reuse. */ 1277 /* Pop the current scope, and free the structure for reuse. */
889 current_scope = scope->outer; 1278 current_scope = scope->outer;
890 if (scope->function_body) 1279 if (scope->function_body)
910 1299
911 start_fname_decls (); 1300 start_fname_decls ();
912 1301
913 for (decl = visible_builtins; decl; decl = TREE_CHAIN (decl)) 1302 for (decl = visible_builtins; decl; decl = TREE_CHAIN (decl))
914 bind (DECL_NAME (decl), decl, file_scope, 1303 bind (DECL_NAME (decl), decl, file_scope,
915 /*invisible=*/false, /*nested=*/true); 1304 /*invisible=*/false, /*nested=*/true, DECL_SOURCE_LOCATION (decl));
916 } 1305 }
917 1306
918 void 1307 void
919 pop_file_scope (void) 1308 pop_file_scope (void)
920 { 1309 {
926 /* __FUNCTION__ is defined at file scope (""). This 1315 /* __FUNCTION__ is defined at file scope (""). This
927 call may not be necessary as my tests indicate it 1316 call may not be necessary as my tests indicate it
928 still works without it. */ 1317 still works without it. */
929 finish_fname_decls (); 1318 finish_fname_decls ();
930 1319
1320 check_inline_statics ();
1321
931 /* This is the point to write out a PCH if we're doing that. 1322 /* This is the point to write out a PCH if we're doing that.
932 In that case we do not want to do anything else. */ 1323 In that case we do not want to do anything else. */
933 if (pch_file) 1324 if (pch_file)
934 { 1325 {
935 c_common_write_pch (); 1326 c_common_write_pch ();
939 /* Pop off the file scope and close this translation unit. */ 1330 /* Pop off the file scope and close this translation unit. */
940 pop_scope (); 1331 pop_scope ();
941 file_scope = 0; 1332 file_scope = 0;
942 1333
943 maybe_apply_pending_pragma_weaks (); 1334 maybe_apply_pending_pragma_weaks ();
944 cgraph_finalize_compilation_unit (); 1335 }
945 } 1336
946 1337 /* Adjust the bindings for the start of a statement expression. */
1338
1339 void
1340 c_bindings_start_stmt_expr (struct c_spot_bindings* switch_bindings)
1341 {
1342 struct c_scope *scope;
1343
1344 for (scope = current_scope; scope != NULL; scope = scope->outer)
1345 {
1346 struct c_binding *b;
1347
1348 if (!scope->has_label_bindings)
1349 continue;
1350
1351 for (b = scope->bindings; b != NULL; b = b->prev)
1352 {
1353 struct c_label_vars *label_vars;
1354 unsigned int ix;
1355 struct c_goto_bindings *g;
1356
1357 if (TREE_CODE (b->decl) != LABEL_DECL)
1358 continue;
1359 label_vars = b->u.label;
1360 ++label_vars->label_bindings.stmt_exprs;
1361 for (ix = 0;
1362 VEC_iterate (c_goto_bindings_p, label_vars->gotos, ix, g);
1363 ++ix)
1364 ++g->goto_bindings.stmt_exprs;
1365 }
1366 }
1367
1368 if (switch_bindings != NULL)
1369 ++switch_bindings->stmt_exprs;
1370 }
1371
1372 /* Adjust the bindings for the end of a statement expression. */
1373
1374 void
1375 c_bindings_end_stmt_expr (struct c_spot_bindings *switch_bindings)
1376 {
1377 struct c_scope *scope;
1378
1379 for (scope = current_scope; scope != NULL; scope = scope->outer)
1380 {
1381 struct c_binding *b;
1382
1383 if (!scope->has_label_bindings)
1384 continue;
1385
1386 for (b = scope->bindings; b != NULL; b = b->prev)
1387 {
1388 struct c_label_vars *label_vars;
1389 unsigned int ix;
1390 struct c_goto_bindings *g;
1391
1392 if (TREE_CODE (b->decl) != LABEL_DECL)
1393 continue;
1394 label_vars = b->u.label;
1395 --label_vars->label_bindings.stmt_exprs;
1396 if (label_vars->label_bindings.stmt_exprs < 0)
1397 {
1398 label_vars->label_bindings.left_stmt_expr = true;
1399 label_vars->label_bindings.stmt_exprs = 0;
1400 }
1401 for (ix = 0;
1402 VEC_iterate (c_goto_bindings_p, label_vars->gotos, ix, g);
1403 ++ix)
1404 {
1405 --g->goto_bindings.stmt_exprs;
1406 if (g->goto_bindings.stmt_exprs < 0)
1407 {
1408 g->goto_bindings.left_stmt_expr = true;
1409 g->goto_bindings.stmt_exprs = 0;
1410 }
1411 }
1412 }
1413 }
1414
1415 if (switch_bindings != NULL)
1416 {
1417 --switch_bindings->stmt_exprs;
1418 gcc_assert (switch_bindings->stmt_exprs >= 0);
1419 }
1420 }
947 1421
948 /* Push a definition or a declaration of struct, union or enum tag "name". 1422 /* Push a definition or a declaration of struct, union or enum tag "name".
949 "type" should be the type node. 1423 "type" should be the type node.
950 We assume that the tag "name" is not already defined. 1424 We assume that the tag "name" is not already defined, and has a location
1425 of LOC.
951 1426
952 Note that the definition may really be just a forward reference. 1427 Note that the definition may really be just a forward reference.
953 In that case, the TYPE_SIZE will be zero. */ 1428 In that case, the TYPE_SIZE will be zero. */
954 1429
955 static void 1430 static void
956 pushtag (tree name, tree type) 1431 pushtag (location_t loc, tree name, tree type)
957 { 1432 {
958 /* Record the identifier as the type's name if it has none. */ 1433 /* Record the identifier as the type's name if it has none. */
959 if (name && !TYPE_NAME (type)) 1434 if (name && !TYPE_NAME (type))
960 TYPE_NAME (type) = name; 1435 TYPE_NAME (type) = name;
961 bind (name, type, current_scope, /*invisible=*/false, /*nested=*/false); 1436 bind (name, type, current_scope, /*invisible=*/false, /*nested=*/false, loc);
962 1437
963 /* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE will be the 1438 /* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE will be the
964 tagged type we just added to the current scope. This fake 1439 tagged type we just added to the current scope. This fake
965 NULL-named TYPE_DECL node helps dwarfout.c to know when it needs 1440 NULL-named TYPE_DECL node helps dwarfout.c to know when it needs
966 to output a representation of a tagged type, and it also gives 1441 to output a representation of a tagged type, and it also gives
967 us a convenient place to record the "scope start" address for the 1442 us a convenient place to record the "scope start" address for the
968 tagged type. */ 1443 tagged type. */
969 1444
970 TYPE_STUB_DECL (type) = pushdecl (build_decl (TYPE_DECL, NULL_TREE, type)); 1445 TYPE_STUB_DECL (type) = pushdecl (build_decl (loc,
1446 TYPE_DECL, NULL_TREE, type));
971 1447
972 /* An approximation for now, so we can tell this is a function-scope tag. 1448 /* An approximation for now, so we can tell this is a function-scope tag.
973 This will be updated in pop_scope. */ 1449 This will be updated in pop_scope. */
974 TYPE_CONTEXT (type) = DECL_CONTEXT (TYPE_STUB_DECL (type)); 1450 TYPE_CONTEXT (type) = DECL_CONTEXT (TYPE_STUB_DECL (type));
1451
1452 if (warn_cxx_compat && name != NULL_TREE)
1453 {
1454 struct c_binding *b = I_SYMBOL_BINDING (name);
1455
1456 if (b != NULL
1457 && b->decl != NULL_TREE
1458 && TREE_CODE (b->decl) == TYPE_DECL
1459 && (B_IN_CURRENT_SCOPE (b)
1460 || (current_scope == file_scope && B_IN_EXTERNAL_SCOPE (b)))
1461 && (TYPE_MAIN_VARIANT (TREE_TYPE (b->decl))
1462 != TYPE_MAIN_VARIANT (type)))
1463 {
1464 warning_at (loc, OPT_Wc___compat,
1465 ("using %qD as both a typedef and a tag is "
1466 "invalid in C++"),
1467 b->decl);
1468 if (b->locus != UNKNOWN_LOCATION)
1469 inform (b->locus, "originally defined here");
1470 }
1471 }
975 } 1472 }
976 1473
977 /* Subroutine of compare_decls. Allow harmless mismatches in return 1474 /* Subroutine of compare_decls. Allow harmless mismatches in return
978 and argument types provided that the type modes match. This function 1475 and argument types provided that the type modes match. This function
979 return a unified type given a suitable match, and 0 otherwise. */ 1476 return a unified type given a suitable match, and 0 otherwise. */
997 tryargs = newargs; 1494 tryargs = newargs;
998 1495
999 while (oldargs || newargs) 1496 while (oldargs || newargs)
1000 { 1497 {
1001 if (!oldargs 1498 if (!oldargs
1002 || !newargs 1499 || !newargs
1003 || !TREE_VALUE (oldargs) 1500 || !TREE_VALUE (oldargs)
1004 || !TREE_VALUE (newargs) 1501 || !TREE_VALUE (newargs)
1005 || TYPE_MODE (TREE_VALUE (oldargs)) 1502 || TYPE_MODE (TREE_VALUE (oldargs))
1006 != TYPE_MODE (TREE_VALUE (newargs))) 1503 != TYPE_MODE (TREE_VALUE (newargs)))
1007 return 0; 1504 return 0;
1008 1505
1009 oldargs = TREE_CHAIN (oldargs); 1506 oldargs = TREE_CHAIN (oldargs);
1010 newargs = TREE_CHAIN (newargs); 1507 newargs = TREE_CHAIN (newargs);
1011 } 1508 }
1012 1509
1017 /* Subroutine of diagnose_mismatched_decls. Check for function type 1514 /* Subroutine of diagnose_mismatched_decls. Check for function type
1018 mismatch involving an empty arglist vs a nonempty one and give clearer 1515 mismatch involving an empty arglist vs a nonempty one and give clearer
1019 diagnostics. */ 1516 diagnostics. */
1020 static void 1517 static void
1021 diagnose_arglist_conflict (tree newdecl, tree olddecl, 1518 diagnose_arglist_conflict (tree newdecl, tree olddecl,
1022 tree newtype, tree oldtype) 1519 tree newtype, tree oldtype)
1023 { 1520 {
1024 tree t; 1521 tree t;
1025 1522
1026 if (TREE_CODE (olddecl) != FUNCTION_DECL 1523 if (TREE_CODE (olddecl) != FUNCTION_DECL
1027 || !comptypes (TREE_TYPE (oldtype), TREE_TYPE (newtype)) 1524 || !comptypes (TREE_TYPE (oldtype), TREE_TYPE (newtype))
1028 || !((TYPE_ARG_TYPES (oldtype) == 0 && DECL_INITIAL (olddecl) == 0) 1525 || !((TYPE_ARG_TYPES (oldtype) == 0 && DECL_INITIAL (olddecl) == 0)
1029 || 1526 ||
1030 (TYPE_ARG_TYPES (newtype) == 0 && DECL_INITIAL (newdecl) == 0))) 1527 (TYPE_ARG_TYPES (newtype) == 0 && DECL_INITIAL (newdecl) == 0)))
1031 return; 1528 return;
1032 1529
1033 t = TYPE_ARG_TYPES (oldtype); 1530 t = TYPE_ARG_TYPES (oldtype);
1034 if (t == 0) 1531 if (t == 0)
1035 t = TYPE_ARG_TYPES (newtype); 1532 t = TYPE_ARG_TYPES (newtype);
1036 for (; t; t = TREE_CHAIN (t)) 1533 for (; t; t = TREE_CHAIN (t))
1037 { 1534 {
1038 tree type = TREE_VALUE (t); 1535 tree type = TREE_VALUE (t);
1039 1536
1040 if (TREE_CHAIN (t) == 0 1537 if (TREE_CHAIN (t) == 0
1041 && TYPE_MAIN_VARIANT (type) != void_type_node) 1538 && TYPE_MAIN_VARIANT (type) != void_type_node)
1042 { 1539 {
1043 inform (input_location, "a parameter list with an ellipsis can%'t match " 1540 inform (input_location, "a parameter list with an ellipsis can%'t match "
1044 "an empty parameter name list declaration"); 1541 "an empty parameter name list declaration");
1045 break; 1542 break;
1046 } 1543 }
1047 1544
1048 if (c_type_promotes_to (type) != type) 1545 if (c_type_promotes_to (type) != type)
1049 { 1546 {
1050 inform (input_location, "an argument type that has a default promotion can%'t match " 1547 inform (input_location, "an argument type that has a default promotion can%'t match "
1051 "an empty parameter name list declaration"); 1548 "an empty parameter name list declaration");
1052 break; 1549 break;
1053 } 1550 }
1054 } 1551 }
1055 } 1552 }
1056 1553
1057 /* Another subroutine of diagnose_mismatched_decls. OLDDECL is an 1554 /* Another subroutine of diagnose_mismatched_decls. OLDDECL is an
1058 old-style function definition, NEWDECL is a prototype declaration. 1555 old-style function definition, NEWDECL is a prototype declaration.
1074 { 1571 {
1075 tree oldargtype = TREE_VALUE (oldargs); 1572 tree oldargtype = TREE_VALUE (oldargs);
1076 tree newargtype = TREE_VALUE (newargs); 1573 tree newargtype = TREE_VALUE (newargs);
1077 1574
1078 if (oldargtype == error_mark_node || newargtype == error_mark_node) 1575 if (oldargtype == error_mark_node || newargtype == error_mark_node)
1079 return false; 1576 return false;
1080 1577
1081 oldargtype = TYPE_MAIN_VARIANT (oldargtype); 1578 oldargtype = TYPE_MAIN_VARIANT (oldargtype);
1082 newargtype = TYPE_MAIN_VARIANT (newargtype); 1579 newargtype = TYPE_MAIN_VARIANT (newargtype);
1083 1580
1084 if (END_OF_ARGLIST (oldargtype) && END_OF_ARGLIST (newargtype)) 1581 if (END_OF_ARGLIST (oldargtype) && END_OF_ARGLIST (newargtype))
1085 break; 1582 break;
1086 1583
1087 /* Reaching the end of just one list means the two decls don't 1584 /* Reaching the end of just one list means the two decls don't
1088 agree on the number of arguments. */ 1585 agree on the number of arguments. */
1089 if (END_OF_ARGLIST (oldargtype)) 1586 if (END_OF_ARGLIST (oldargtype))
1090 { 1587 {
1091 error ("prototype for %q+D declares more arguments " 1588 error ("prototype for %q+D declares more arguments "
1092 "than previous old-style definition", newdecl); 1589 "than previous old-style definition", newdecl);
1093 return false; 1590 return false;
1094 } 1591 }
1095 else if (END_OF_ARGLIST (newargtype)) 1592 else if (END_OF_ARGLIST (newargtype))
1096 { 1593 {
1097 error ("prototype for %q+D declares fewer arguments " 1594 error ("prototype for %q+D declares fewer arguments "
1098 "than previous old-style definition", newdecl); 1595 "than previous old-style definition", newdecl);
1099 return false; 1596 return false;
1100 } 1597 }
1101 1598
1102 /* Type for passing arg must be consistent with that declared 1599 /* Type for passing arg must be consistent with that declared
1103 for the arg. */ 1600 for the arg. */
1104 else if (!comptypes (oldargtype, newargtype)) 1601 else if (!comptypes (oldargtype, newargtype))
1105 { 1602 {
1106 error ("prototype for %q+D declares argument %d" 1603 error ("prototype for %q+D declares argument %d"
1107 " with incompatible type", 1604 " with incompatible type",
1108 newdecl, i); 1605 newdecl, i);
1109 return false; 1606 return false;
1110 } 1607 }
1111 1608
1112 oldargs = TREE_CHAIN (oldargs); 1609 oldargs = TREE_CHAIN (oldargs);
1113 newargs = TREE_CHAIN (newargs); 1610 newargs = TREE_CHAIN (newargs);
1114 i++; 1611 i++;
1115 } 1612 }
1116 1613
1117 /* If we get here, no errors were found, but do issue a warning 1614 /* If we get here, no errors were found, but do issue a warning
1118 for this poor-style construct. */ 1615 for this poor-style construct. */
1119 warning (0, "prototype for %q+D follows non-prototype definition", 1616 warning (0, "prototype for %q+D follows non-prototype definition",
1120 newdecl); 1617 newdecl);
1121 return true; 1618 return true;
1122 #undef END_OF_ARGLIST 1619 #undef END_OF_ARGLIST
1123 } 1620 }
1124 1621
1125 /* Subroutine of diagnose_mismatched_decls. Report the location of DECL, 1622 /* Subroutine of diagnose_mismatched_decls. Report the location of DECL,
1146 *NEWTYPEP and *OLDTYPEP - these may have been adjusted from 1643 *NEWTYPEP and *OLDTYPEP - these may have been adjusted from
1147 TREE_TYPE (NEWDECL, OLDDECL) respectively. */ 1644 TREE_TYPE (NEWDECL, OLDDECL) respectively. */
1148 1645
1149 static bool 1646 static bool
1150 diagnose_mismatched_decls (tree newdecl, tree olddecl, 1647 diagnose_mismatched_decls (tree newdecl, tree olddecl,
1151 tree *newtypep, tree *oldtypep) 1648 tree *newtypep, tree *oldtypep)
1152 { 1649 {
1153 tree newtype, oldtype; 1650 tree newtype, oldtype;
1154 bool pedwarned = false; 1651 bool pedwarned = false;
1155 bool warned = false; 1652 bool warned = false;
1156 bool retval = true; 1653 bool retval = true;
1157 1654
1158 #define DECL_EXTERN_INLINE(DECL) (DECL_DECLARED_INLINE_P (DECL) \ 1655 #define DECL_EXTERN_INLINE(DECL) (DECL_DECLARED_INLINE_P (DECL) \
1159 && DECL_EXTERNAL (DECL)) 1656 && DECL_EXTERNAL (DECL))
1160 1657
1161 /* If we have error_mark_node for either decl or type, just discard 1658 /* If we have error_mark_node for either decl or type, just discard
1162 the previous decl - we're in an error cascade already. */ 1659 the previous decl - we're in an error cascade already. */
1163 if (olddecl == error_mark_node || newdecl == error_mark_node) 1660 if (olddecl == error_mark_node || newdecl == error_mark_node)
1164 return false; 1661 return false;
1170 /* Two different categories of symbol altogether. This is an error 1667 /* Two different categories of symbol altogether. This is an error
1171 unless OLDDECL is a builtin. OLDDECL will be discarded in any case. */ 1668 unless OLDDECL is a builtin. OLDDECL will be discarded in any case. */
1172 if (TREE_CODE (olddecl) != TREE_CODE (newdecl)) 1669 if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
1173 { 1670 {
1174 if (!(TREE_CODE (olddecl) == FUNCTION_DECL 1671 if (!(TREE_CODE (olddecl) == FUNCTION_DECL
1175 && DECL_BUILT_IN (olddecl) 1672 && DECL_BUILT_IN (olddecl)
1176 && !C_DECL_DECLARED_BUILTIN (olddecl))) 1673 && !C_DECL_DECLARED_BUILTIN (olddecl)))
1177 { 1674 {
1178 error ("%q+D redeclared as different kind of symbol", newdecl); 1675 error ("%q+D redeclared as different kind of symbol", newdecl);
1179 locate_old_decl (olddecl); 1676 locate_old_decl (olddecl);
1180 } 1677 }
1181 else if (TREE_PUBLIC (newdecl)) 1678 else if (TREE_PUBLIC (newdecl))
1182 warning (0, "built-in function %q+D declared as non-function", 1679 warning (0, "built-in function %q+D declared as non-function",
1183 newdecl); 1680 newdecl);
1184 else 1681 else
1185 warning (OPT_Wshadow, "declaration of %q+D shadows " 1682 warning (OPT_Wshadow, "declaration of %q+D shadows "
1186 "a built-in function", newdecl); 1683 "a built-in function", newdecl);
1187 return false; 1684 return false;
1188 } 1685 }
1189 1686
1190 /* Enumerators have no linkage, so may only be declared once in a 1687 /* Enumerators have no linkage, so may only be declared once in a
1191 given scope. */ 1688 given scope. */
1197 } 1694 }
1198 1695
1199 if (!comptypes (oldtype, newtype)) 1696 if (!comptypes (oldtype, newtype))
1200 { 1697 {
1201 if (TREE_CODE (olddecl) == FUNCTION_DECL 1698 if (TREE_CODE (olddecl) == FUNCTION_DECL
1202 && DECL_BUILT_IN (olddecl) && !C_DECL_DECLARED_BUILTIN (olddecl)) 1699 && DECL_BUILT_IN (olddecl) && !C_DECL_DECLARED_BUILTIN (olddecl))
1203 { 1700 {
1204 /* Accept harmless mismatch in function types. 1701 /* Accept harmless mismatch in function types.
1205 This is for the ffs and fprintf builtins. */ 1702 This is for the ffs and fprintf builtins. */
1206 tree trytype = match_builtin_function_types (newtype, oldtype); 1703 tree trytype = match_builtin_function_types (newtype, oldtype);
1207 1704
1208 if (trytype && comptypes (newtype, trytype)) 1705 if (trytype && comptypes (newtype, trytype))
1209 *oldtypep = oldtype = trytype; 1706 *oldtypep = oldtype = trytype;
1210 else 1707 else
1211 { 1708 {
1212 /* If types don't match for a built-in, throw away the 1709 /* If types don't match for a built-in, throw away the
1213 built-in. No point in calling locate_old_decl here, it 1710 built-in. No point in calling locate_old_decl here, it
1214 won't print anything. */ 1711 won't print anything. */
1215 warning (0, "conflicting types for built-in function %q+D", 1712 warning (0, "conflicting types for built-in function %q+D",
1216 newdecl); 1713 newdecl);
1217 return false; 1714 return false;
1218 } 1715 }
1219 } 1716 }
1220 else if (TREE_CODE (olddecl) == FUNCTION_DECL 1717 else if (TREE_CODE (olddecl) == FUNCTION_DECL
1221 && DECL_IS_BUILTIN (olddecl)) 1718 && DECL_IS_BUILTIN (olddecl))
1222 { 1719 {
1223 /* A conflicting function declaration for a predeclared 1720 /* A conflicting function declaration for a predeclared
1224 function that isn't actually built in. Objective C uses 1721 function that isn't actually built in. Objective C uses
1225 these. The new declaration silently overrides everything 1722 these. The new declaration silently overrides everything
1226 but the volatility (i.e. noreturn) indication. See also 1723 but the volatility (i.e. noreturn) indication. See also
1227 below. FIXME: Make Objective C use normal builtins. */ 1724 below. FIXME: Make Objective C use normal builtins. */
1228 TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl); 1725 TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl);
1229 return false; 1726 return false;
1230 } 1727 }
1231 /* Permit void foo (...) to match int foo (...) if the latter is 1728 /* Permit void foo (...) to match int foo (...) if the latter is
1232 the definition and implicit int was used. See 1729 the definition and implicit int was used. See
1233 c-torture/compile/920625-2.c. */ 1730 c-torture/compile/920625-2.c. */
1234 else if (TREE_CODE (newdecl) == FUNCTION_DECL && DECL_INITIAL (newdecl) 1731 else if (TREE_CODE (newdecl) == FUNCTION_DECL && DECL_INITIAL (newdecl)
1235 && TYPE_MAIN_VARIANT (TREE_TYPE (oldtype)) == void_type_node 1732 && TYPE_MAIN_VARIANT (TREE_TYPE (oldtype)) == void_type_node
1236 && TYPE_MAIN_VARIANT (TREE_TYPE (newtype)) == integer_type_node 1733 && TYPE_MAIN_VARIANT (TREE_TYPE (newtype)) == integer_type_node
1237 && C_FUNCTION_IMPLICIT_INT (newdecl) && !DECL_INITIAL (olddecl)) 1734 && C_FUNCTION_IMPLICIT_INT (newdecl) && !DECL_INITIAL (olddecl))
1238 { 1735 {
1239 pedwarned = pedwarn (input_location, 0, 1736 pedwarned = pedwarn (input_location, 0,
1240 "conflicting types for %q+D", newdecl); 1737 "conflicting types for %q+D", newdecl);
1241 /* Make sure we keep void as the return type. */ 1738 /* Make sure we keep void as the return type. */
1242 TREE_TYPE (newdecl) = *newtypep = newtype = oldtype; 1739 TREE_TYPE (newdecl) = *newtypep = newtype = oldtype;
1243 C_FUNCTION_IMPLICIT_INT (newdecl) = 0; 1740 C_FUNCTION_IMPLICIT_INT (newdecl) = 0;
1244 } 1741 }
1245 /* Permit void foo (...) to match an earlier call to foo (...) with 1742 /* Permit void foo (...) to match an earlier call to foo (...) with
1246 no declared type (thus, implicitly int). */ 1743 no declared type (thus, implicitly int). */
1247 else if (TREE_CODE (newdecl) == FUNCTION_DECL 1744 else if (TREE_CODE (newdecl) == FUNCTION_DECL
1248 && TYPE_MAIN_VARIANT (TREE_TYPE (newtype)) == void_type_node 1745 && TYPE_MAIN_VARIANT (TREE_TYPE (newtype)) == void_type_node
1249 && TYPE_MAIN_VARIANT (TREE_TYPE (oldtype)) == integer_type_node 1746 && TYPE_MAIN_VARIANT (TREE_TYPE (oldtype)) == integer_type_node
1250 && C_DECL_IMPLICIT (olddecl) && !DECL_INITIAL (olddecl)) 1747 && C_DECL_IMPLICIT (olddecl) && !DECL_INITIAL (olddecl))
1251 { 1748 {
1252 pedwarned = pedwarn (input_location, 0, 1749 pedwarned = pedwarn (input_location, 0,
1253 "conflicting types for %q+D", newdecl); 1750 "conflicting types for %q+D", newdecl);
1254 /* Make sure we keep void as the return type. */ 1751 /* Make sure we keep void as the return type. */
1255 TREE_TYPE (olddecl) = *oldtypep = oldtype = newtype; 1752 TREE_TYPE (olddecl) = *oldtypep = oldtype = newtype;
1256 } 1753 }
1257 else 1754 else
1258 { 1755 {
1259 if (TYPE_QUALS (newtype) != TYPE_QUALS (oldtype)) 1756 int new_quals = TYPE_QUALS (newtype);
1260 error ("conflicting type qualifiers for %q+D", newdecl); 1757 int old_quals = TYPE_QUALS (oldtype);
1261 else 1758
1262 error ("conflicting types for %q+D", newdecl); 1759 if (new_quals != old_quals)
1263 diagnose_arglist_conflict (newdecl, olddecl, newtype, oldtype); 1760 {
1264 locate_old_decl (olddecl); 1761 addr_space_t new_addr = DECODE_QUAL_ADDR_SPACE (new_quals);
1265 return false; 1762 addr_space_t old_addr = DECODE_QUAL_ADDR_SPACE (old_quals);
1266 } 1763 if (new_addr != old_addr)
1764 {
1765 if (ADDR_SPACE_GENERIC_P (new_addr))
1766 error ("conflicting named address spaces (generic vs %s) "
1767 "for %q+D",
1768 c_addr_space_name (old_addr), newdecl);
1769 else if (ADDR_SPACE_GENERIC_P (old_addr))
1770 error ("conflicting named address spaces (%s vs generic) "
1771 "for %q+D",
1772 c_addr_space_name (new_addr), newdecl);
1773 else
1774 error ("conflicting named address spaces (%s vs %s) "
1775 "for %q+D",
1776 c_addr_space_name (new_addr),
1777 c_addr_space_name (old_addr),
1778 newdecl);
1779 }
1780
1781 if (CLEAR_QUAL_ADDR_SPACE (new_quals)
1782 != CLEAR_QUAL_ADDR_SPACE (old_quals))
1783 error ("conflicting type qualifiers for %q+D", newdecl);
1784 }
1785 else
1786 error ("conflicting types for %q+D", newdecl);
1787 diagnose_arglist_conflict (newdecl, olddecl, newtype, oldtype);
1788 locate_old_decl (olddecl);
1789 return false;
1790 }
1267 } 1791 }
1268 1792
1269 /* Redeclaration of a type is a constraint violation (6.7.2.3p1), 1793 /* Redeclaration of a type is a constraint violation (6.7.2.3p1),
1270 but silently ignore the redeclaration if either is in a system 1794 but silently ignore the redeclaration if either is in a system
1271 header. (Conflicting redeclarations were handled above.) */ 1795 header. (Conflicting redeclarations were handled above.) */
1272 if (TREE_CODE (newdecl) == TYPE_DECL) 1796 if (TREE_CODE (newdecl) == TYPE_DECL)
1273 { 1797 {
1274 if (DECL_IN_SYSTEM_HEADER (newdecl) 1798 if (DECL_IN_SYSTEM_HEADER (newdecl)
1275 || DECL_IN_SYSTEM_HEADER (olddecl) 1799 || DECL_IN_SYSTEM_HEADER (olddecl)
1276 || TREE_NO_WARNING (newdecl) 1800 || TREE_NO_WARNING (newdecl)
1277 || TREE_NO_WARNING (olddecl)) 1801 || TREE_NO_WARNING (olddecl))
1278 return true; /* Allow OLDDECL to continue in use. */ 1802 return true; /* Allow OLDDECL to continue in use. */
1279 1803
1280 error ("redefinition of typedef %q+D", newdecl); 1804 error ("redefinition of typedef %q+D", newdecl);
1281 locate_old_decl (olddecl); 1805 locate_old_decl (olddecl);
1282 return false; 1806 return false;
1283 } 1807 }
1291 extern-inline definition. */ 1815 extern-inline definition. */
1292 1816
1293 else if (TREE_CODE (newdecl) == FUNCTION_DECL) 1817 else if (TREE_CODE (newdecl) == FUNCTION_DECL)
1294 { 1818 {
1295 /* If you declare a built-in function name as static, or 1819 /* If you declare a built-in function name as static, or
1296 define the built-in with an old-style definition (so we 1820 define the built-in with an old-style definition (so we
1297 can't validate the argument list) the built-in definition is 1821 can't validate the argument list) the built-in definition is
1298 overridden, but optionally warn this was a bad choice of name. */ 1822 overridden, but optionally warn this was a bad choice of name. */
1299 if (DECL_BUILT_IN (olddecl) 1823 if (DECL_BUILT_IN (olddecl)
1300 && !C_DECL_DECLARED_BUILTIN (olddecl) 1824 && !C_DECL_DECLARED_BUILTIN (olddecl)
1301 && (!TREE_PUBLIC (newdecl) 1825 && (!TREE_PUBLIC (newdecl)
1302 || (DECL_INITIAL (newdecl) 1826 || (DECL_INITIAL (newdecl)
1303 && !TYPE_ARG_TYPES (TREE_TYPE (newdecl))))) 1827 && !TYPE_ARG_TYPES (TREE_TYPE (newdecl)))))
1304 { 1828 {
1305 warning (OPT_Wshadow, "declaration of %q+D shadows " 1829 warning (OPT_Wshadow, "declaration of %q+D shadows "
1306 "a built-in function", newdecl); 1830 "a built-in function", newdecl);
1307 /* Discard the old built-in function. */ 1831 /* Discard the old built-in function. */
1308 return false; 1832 return false;
1309 } 1833 }
1310 1834
1311 if (DECL_INITIAL (newdecl)) 1835 if (DECL_INITIAL (newdecl))
1312 { 1836 {
1313 if (DECL_INITIAL (olddecl)) 1837 if (DECL_INITIAL (olddecl))
1314 { 1838 {
1315 /* If both decls are in the same TU and the new declaration 1839 /* If both decls are in the same TU and the new declaration
1316 isn't overriding an extern inline reject the new decl. 1840 isn't overriding an extern inline reject the new decl.
1317 In c99, no overriding is allowed in the same translation 1841 In c99, no overriding is allowed in the same translation
1318 unit. */ 1842 unit. */
1319 if ((!DECL_EXTERN_INLINE (olddecl) 1843 if ((!DECL_EXTERN_INLINE (olddecl)
1320 || DECL_EXTERN_INLINE (newdecl) 1844 || DECL_EXTERN_INLINE (newdecl)
1321 || (!flag_gnu89_inline 1845 || (!flag_gnu89_inline
1322 && (!DECL_DECLARED_INLINE_P (olddecl) 1846 && (!DECL_DECLARED_INLINE_P (olddecl)
1323 || !lookup_attribute ("gnu_inline", 1847 || !lookup_attribute ("gnu_inline",
1324 DECL_ATTRIBUTES (olddecl))) 1848 DECL_ATTRIBUTES (olddecl)))
1325 && (!DECL_DECLARED_INLINE_P (newdecl) 1849 && (!DECL_DECLARED_INLINE_P (newdecl)
1326 || !lookup_attribute ("gnu_inline", 1850 || !lookup_attribute ("gnu_inline",
1327 DECL_ATTRIBUTES (newdecl)))) 1851 DECL_ATTRIBUTES (newdecl))))
1328 ) 1852 )
1329 && same_translation_unit_p (newdecl, olddecl)) 1853 && same_translation_unit_p (newdecl, olddecl))
1330 { 1854 {
1331 error ("redefinition of %q+D", newdecl); 1855 error ("redefinition of %q+D", newdecl);
1332 locate_old_decl (olddecl); 1856 locate_old_decl (olddecl);
1333 return false; 1857 return false;
1334 } 1858 }
1335 } 1859 }
1336 } 1860 }
1337 /* If we have a prototype after an old-style function definition, 1861 /* If we have a prototype after an old-style function definition,
1338 the argument types must be checked specially. */ 1862 the argument types must be checked specially. */
1339 else if (DECL_INITIAL (olddecl) 1863 else if (DECL_INITIAL (olddecl)
1340 && !TYPE_ARG_TYPES (oldtype) && TYPE_ARG_TYPES (newtype) 1864 && !TYPE_ARG_TYPES (oldtype) && TYPE_ARG_TYPES (newtype)
1341 && TYPE_ACTUAL_ARG_TYPES (oldtype) 1865 && TYPE_ACTUAL_ARG_TYPES (oldtype)
1342 && !validate_proto_after_old_defn (newdecl, newtype, oldtype)) 1866 && !validate_proto_after_old_defn (newdecl, newtype, oldtype))
1343 { 1867 {
1344 locate_old_decl (olddecl); 1868 locate_old_decl (olddecl);
1345 return false; 1869 return false;
1346 } 1870 }
1347 /* A non-static declaration (even an "extern") followed by a 1871 /* A non-static declaration (even an "extern") followed by a
1348 static declaration is undefined behavior per C99 6.2.2p3-5,7. 1872 static declaration is undefined behavior per C99 6.2.2p3-5,7.
1349 The same is true for a static forward declaration at block 1873 The same is true for a static forward declaration at block
1350 scope followed by a non-static declaration/definition at file 1874 scope followed by a non-static declaration/definition at file
1351 scope. Static followed by non-static at the same scope is 1875 scope. Static followed by non-static at the same scope is
1352 not undefined behavior, and is the most convenient way to get 1876 not undefined behavior, and is the most convenient way to get
1353 some effects (see e.g. what unwind-dw2-fde-glibc.c does to 1877 some effects (see e.g. what unwind-dw2-fde-glibc.c does to
1354 the definition of _Unwind_Find_FDE in unwind-dw2-fde.c), but 1878 the definition of _Unwind_Find_FDE in unwind-dw2-fde.c), but
1355 we do diagnose it if -Wtraditional. */ 1879 we do diagnose it if -Wtraditional. */
1356 if (TREE_PUBLIC (olddecl) && !TREE_PUBLIC (newdecl)) 1880 if (TREE_PUBLIC (olddecl) && !TREE_PUBLIC (newdecl))
1357 { 1881 {
1358 /* Two exceptions to the rule. If olddecl is an extern 1882 /* Two exceptions to the rule. If olddecl is an extern
1359 inline, or a predeclared function that isn't actually 1883 inline, or a predeclared function that isn't actually
1360 built in, newdecl silently overrides olddecl. The latter 1884 built in, newdecl silently overrides olddecl. The latter
1361 occur only in Objective C; see also above. (FIXME: Make 1885 occur only in Objective C; see also above. (FIXME: Make
1362 Objective C use normal builtins.) */ 1886 Objective C use normal builtins.) */
1363 if (!DECL_IS_BUILTIN (olddecl) 1887 if (!DECL_IS_BUILTIN (olddecl)
1364 && !DECL_EXTERN_INLINE (olddecl)) 1888 && !DECL_EXTERN_INLINE (olddecl))
1365 { 1889 {
1366 error ("static declaration of %q+D follows " 1890 error ("static declaration of %q+D follows "
1367 "non-static declaration", newdecl); 1891 "non-static declaration", newdecl);
1368 locate_old_decl (olddecl); 1892 locate_old_decl (olddecl);
1369 } 1893 }
1370 return false; 1894 return false;
1371 } 1895 }
1372 else if (TREE_PUBLIC (newdecl) && !TREE_PUBLIC (olddecl)) 1896 else if (TREE_PUBLIC (newdecl) && !TREE_PUBLIC (olddecl))
1373 { 1897 {
1374 if (DECL_CONTEXT (olddecl)) 1898 if (DECL_CONTEXT (olddecl))
1375 { 1899 {
1376 error ("non-static declaration of %q+D follows " 1900 error ("non-static declaration of %q+D follows "
1377 "static declaration", newdecl); 1901 "static declaration", newdecl);
1378 locate_old_decl (olddecl); 1902 locate_old_decl (olddecl);
1379 return false; 1903 return false;
1380 } 1904 }
1381 else if (warn_traditional) 1905 else if (warn_traditional)
1382 { 1906 {
1383 warned |= warning (OPT_Wtraditional, 1907 warned |= warning (OPT_Wtraditional,
1384 "non-static declaration of %q+D " 1908 "non-static declaration of %q+D "
1385 "follows static declaration", newdecl); 1909 "follows static declaration", newdecl);
1386 } 1910 }
1387 } 1911 }
1388 1912
1389 /* Make sure gnu_inline attribute is either not present, or 1913 /* Make sure gnu_inline attribute is either not present, or
1390 present on all inline decls. */ 1914 present on all inline decls. */
1391 if (DECL_DECLARED_INLINE_P (olddecl) 1915 if (DECL_DECLARED_INLINE_P (olddecl)
1392 && DECL_DECLARED_INLINE_P (newdecl)) 1916 && DECL_DECLARED_INLINE_P (newdecl))
1393 { 1917 {
1394 bool newa = lookup_attribute ("gnu_inline", 1918 bool newa = lookup_attribute ("gnu_inline",
1395 DECL_ATTRIBUTES (newdecl)) != NULL; 1919 DECL_ATTRIBUTES (newdecl)) != NULL;
1396 bool olda = lookup_attribute ("gnu_inline", 1920 bool olda = lookup_attribute ("gnu_inline",
1397 DECL_ATTRIBUTES (olddecl)) != NULL; 1921 DECL_ATTRIBUTES (olddecl)) != NULL;
1398 if (newa != olda) 1922 if (newa != olda)
1399 { 1923 {
1400 error ("%<gnu_inline%> attribute present on %q+D", 1924 error_at (input_location, "%<gnu_inline%> attribute present on %q+D",
1401 newa ? newdecl : olddecl); 1925 newa ? newdecl : olddecl);
1402 error ("%Jbut not here", newa ? olddecl : newdecl); 1926 error_at (DECL_SOURCE_LOCATION (newa ? olddecl : newdecl),
1403 } 1927 "but not here");
1404 } 1928 }
1929 }
1405 } 1930 }
1406 else if (TREE_CODE (newdecl) == VAR_DECL) 1931 else if (TREE_CODE (newdecl) == VAR_DECL)
1407 { 1932 {
1408 /* Only variables can be thread-local, and all declarations must 1933 /* Only variables can be thread-local, and all declarations must
1409 agree on this property. */ 1934 agree on this property. */
1410 if (C_DECL_THREADPRIVATE_P (olddecl) && !DECL_THREAD_LOCAL_P (newdecl)) 1935 if (C_DECL_THREADPRIVATE_P (olddecl) && !DECL_THREAD_LOCAL_P (newdecl))
1411 { 1936 {
1412 /* Nothing to check. Since OLDDECL is marked threadprivate 1937 /* Nothing to check. Since OLDDECL is marked threadprivate
1413 and NEWDECL does not have a thread-local attribute, we 1938 and NEWDECL does not have a thread-local attribute, we
1414 will merge the threadprivate attribute into NEWDECL. */ 1939 will merge the threadprivate attribute into NEWDECL. */
1415 ; 1940 ;
1416 } 1941 }
1417 else if (DECL_THREAD_LOCAL_P (newdecl) != DECL_THREAD_LOCAL_P (olddecl)) 1942 else if (DECL_THREAD_LOCAL_P (newdecl) != DECL_THREAD_LOCAL_P (olddecl))
1418 { 1943 {
1419 if (DECL_THREAD_LOCAL_P (newdecl)) 1944 if (DECL_THREAD_LOCAL_P (newdecl))
1420 error ("thread-local declaration of %q+D follows " 1945 error ("thread-local declaration of %q+D follows "
1421 "non-thread-local declaration", newdecl); 1946 "non-thread-local declaration", newdecl);
1422 else 1947 else
1423 error ("non-thread-local declaration of %q+D follows " 1948 error ("non-thread-local declaration of %q+D follows "
1424 "thread-local declaration", newdecl); 1949 "thread-local declaration", newdecl);
1425 1950
1426 locate_old_decl (olddecl); 1951 locate_old_decl (olddecl);
1427 return false; 1952 return false;
1428 } 1953 }
1429 1954
1430 /* Multiple initialized definitions are not allowed (6.9p3,5). */ 1955 /* Multiple initialized definitions are not allowed (6.9p3,5). */
1431 if (DECL_INITIAL (newdecl) && DECL_INITIAL (olddecl)) 1956 if (DECL_INITIAL (newdecl) && DECL_INITIAL (olddecl))
1432 { 1957 {
1433 error ("redefinition of %q+D", newdecl); 1958 error ("redefinition of %q+D", newdecl);
1434 locate_old_decl (olddecl); 1959 locate_old_decl (olddecl);
1435 return false; 1960 return false;
1436 } 1961 }
1437 1962
1438 /* Objects declared at file scope: if the first declaration had 1963 /* Objects declared at file scope: if the first declaration had
1439 external linkage (even if it was an external reference) the 1964 external linkage (even if it was an external reference) the
1440 second must have external linkage as well, or the behavior is 1965 second must have external linkage as well, or the behavior is
1441 undefined. If the first declaration had internal linkage, then 1966 undefined. If the first declaration had internal linkage, then
1442 the second must too, or else be an external reference (in which 1967 the second must too, or else be an external reference (in which
1443 case the composite declaration still has internal linkage). 1968 case the composite declaration still has internal linkage).
1444 As for function declarations, we warn about the static-then- 1969 As for function declarations, we warn about the static-then-
1445 extern case only for -Wtraditional. See generally 6.2.2p3-5,7. */ 1970 extern case only for -Wtraditional. See generally 6.2.2p3-5,7. */
1446 if (DECL_FILE_SCOPE_P (newdecl) 1971 if (DECL_FILE_SCOPE_P (newdecl)
1447 && TREE_PUBLIC (newdecl) != TREE_PUBLIC (olddecl)) 1972 && TREE_PUBLIC (newdecl) != TREE_PUBLIC (olddecl))
1448 { 1973 {
1449 if (DECL_EXTERNAL (newdecl)) 1974 if (DECL_EXTERNAL (newdecl))
1450 { 1975 {
1451 if (!DECL_FILE_SCOPE_P (olddecl)) 1976 if (!DECL_FILE_SCOPE_P (olddecl))
1452 { 1977 {
1453 error ("extern declaration of %q+D follows " 1978 error ("extern declaration of %q+D follows "
1454 "declaration with no linkage", newdecl); 1979 "declaration with no linkage", newdecl);
1455 locate_old_decl (olddecl); 1980 locate_old_decl (olddecl);
1456 return false; 1981 return false;
1457 } 1982 }
1458 else if (warn_traditional) 1983 else if (warn_traditional)
1459 { 1984 {
1460 warned |= warning (OPT_Wtraditional, 1985 warned |= warning (OPT_Wtraditional,
1461 "non-static declaration of %q+D " 1986 "non-static declaration of %q+D "
1462 "follows static declaration", newdecl); 1987 "follows static declaration", newdecl);
1463 } 1988 }
1464 } 1989 }
1465 else 1990 else
1466 { 1991 {
1467 if (TREE_PUBLIC (newdecl)) 1992 if (TREE_PUBLIC (newdecl))
1468 error ("non-static declaration of %q+D follows " 1993 error ("non-static declaration of %q+D follows "
1469 "static declaration", newdecl); 1994 "static declaration", newdecl);
1470 else 1995 else
1471 error ("static declaration of %q+D follows " 1996 error ("static declaration of %q+D follows "
1472 "non-static declaration", newdecl); 1997 "non-static declaration", newdecl);
1473 1998
1474 locate_old_decl (olddecl); 1999 locate_old_decl (olddecl);
1475 return false; 2000 return false;
1476 } 2001 }
1477 } 2002 }
1478 /* Two objects with the same name declared at the same block 2003 /* Two objects with the same name declared at the same block
1479 scope must both be external references (6.7p3). */ 2004 scope must both be external references (6.7p3). */
1480 else if (!DECL_FILE_SCOPE_P (newdecl)) 2005 else if (!DECL_FILE_SCOPE_P (newdecl))
1481 { 2006 {
1482 if (DECL_EXTERNAL (newdecl)) 2007 if (DECL_EXTERNAL (newdecl))
1483 { 2008 {
1484 /* Extern with initializer at block scope, which will 2009 /* Extern with initializer at block scope, which will
1485 already have received an error. */ 2010 already have received an error. */
1486 } 2011 }
1487 else if (DECL_EXTERNAL (olddecl)) 2012 else if (DECL_EXTERNAL (olddecl))
1488 { 2013 {
1489 error ("declaration of %q+D with no linkage follows " 2014 error ("declaration of %q+D with no linkage follows "
1490 "extern declaration", newdecl); 2015 "extern declaration", newdecl);
1491 locate_old_decl (olddecl); 2016 locate_old_decl (olddecl);
1492 } 2017 }
1493 else 2018 else
1494 { 2019 {
1495 error ("redeclaration of %q+D with no linkage", newdecl); 2020 error ("redeclaration of %q+D with no linkage", newdecl);
1496 locate_old_decl (olddecl); 2021 locate_old_decl (olddecl);
1497 } 2022 }
1498 2023
1499 return false; 2024 return false;
1500 } 2025 }
2026
2027 /* C++ does not permit a decl to appear multiple times at file
2028 scope. */
2029 if (warn_cxx_compat
2030 && DECL_FILE_SCOPE_P (newdecl)
2031 && !DECL_EXTERNAL (newdecl)
2032 && !DECL_EXTERNAL (olddecl))
2033 warned |= warning_at (DECL_SOURCE_LOCATION (newdecl),
2034 OPT_Wc___compat,
2035 ("duplicate declaration of %qD is "
2036 "invalid in C++"),
2037 newdecl);
1501 } 2038 }
1502 2039
1503 /* warnings */ 2040 /* warnings */
1504 /* All decls must agree on a visibility. */ 2041 /* All decls must agree on a visibility. */
1505 if (CODE_CONTAINS_STRUCT (TREE_CODE (newdecl), TS_DECL_WITH_VIS) 2042 if (CODE_CONTAINS_STRUCT (TREE_CODE (newdecl), TS_DECL_WITH_VIS)
1506 && DECL_VISIBILITY_SPECIFIED (newdecl) && DECL_VISIBILITY_SPECIFIED (olddecl) 2043 && DECL_VISIBILITY_SPECIFIED (newdecl) && DECL_VISIBILITY_SPECIFIED (olddecl)
1507 && DECL_VISIBILITY (newdecl) != DECL_VISIBILITY (olddecl)) 2044 && DECL_VISIBILITY (newdecl) != DECL_VISIBILITY (olddecl))
1508 { 2045 {
1509 warned |= warning (0, "redeclaration of %q+D with different visibility " 2046 warned |= warning (0, "redeclaration of %q+D with different visibility "
1510 "(old visibility preserved)", newdecl); 2047 "(old visibility preserved)", newdecl);
1511 } 2048 }
1512 2049
1513 if (TREE_CODE (newdecl) == FUNCTION_DECL) 2050 if (TREE_CODE (newdecl) == FUNCTION_DECL)
1514 { 2051 {
1515 /* Diagnose inline __attribute__ ((noinline)) which is silly. */ 2052 /* Diagnose inline __attribute__ ((noinline)) which is silly. */
1516 if (DECL_DECLARED_INLINE_P (newdecl) 2053 if (DECL_DECLARED_INLINE_P (newdecl)
1517 && lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl))) 2054 && lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl)))
1518 { 2055 {
1519 warned |= warning (OPT_Wattributes, 2056 warned |= warning (OPT_Wattributes,
1520 "inline declaration of %qD follows " 2057 "inline declaration of %qD follows "
1521 "declaration with attribute noinline", newdecl); 2058 "declaration with attribute noinline", newdecl);
1522 } 2059 }
1523 else if (DECL_DECLARED_INLINE_P (olddecl) 2060 else if (DECL_DECLARED_INLINE_P (olddecl)
1524 && lookup_attribute ("noinline", DECL_ATTRIBUTES (newdecl))) 2061 && lookup_attribute ("noinline", DECL_ATTRIBUTES (newdecl)))
1525 { 2062 {
1526 warned |= warning (OPT_Wattributes, 2063 warned |= warning (OPT_Wattributes,
1527 "declaration of %q+D with attribute " 2064 "declaration of %q+D with attribute "
1528 "noinline follows inline declaration ", newdecl); 2065 "noinline follows inline declaration ", newdecl);
1529 } 2066 }
1530 } 2067 }
1531 else /* PARM_DECL, VAR_DECL */ 2068 else /* PARM_DECL, VAR_DECL */
1532 { 2069 {
1533 /* Redeclaration of a parameter is a constraint violation (this is 2070 /* Redeclaration of a parameter is a constraint violation (this is
1534 not explicitly stated, but follows from C99 6.7p3 [no more than 2071 not explicitly stated, but follows from C99 6.7p3 [no more than
1535 one declaration of the same identifier with no linkage in the 2072 one declaration of the same identifier with no linkage in the
1536 same scope, except type tags] and 6.2.2p6 [parameters have no 2073 same scope, except type tags] and 6.2.2p6 [parameters have no
1537 linkage]). We must check for a forward parameter declaration, 2074 linkage]). We must check for a forward parameter declaration,
1538 indicated by TREE_ASM_WRITTEN on the old declaration - this is 2075 indicated by TREE_ASM_WRITTEN on the old declaration - this is
1539 an extension, the mandatory diagnostic for which is handled by 2076 an extension, the mandatory diagnostic for which is handled by
1540 mark_forward_parm_decls. */ 2077 mark_forward_parm_decls. */
1541 2078
1542 if (TREE_CODE (newdecl) == PARM_DECL 2079 if (TREE_CODE (newdecl) == PARM_DECL
1543 && (!TREE_ASM_WRITTEN (olddecl) || TREE_ASM_WRITTEN (newdecl))) 2080 && (!TREE_ASM_WRITTEN (olddecl) || TREE_ASM_WRITTEN (newdecl)))
1544 { 2081 {
1545 error ("redefinition of parameter %q+D", newdecl); 2082 error ("redefinition of parameter %q+D", newdecl);
1546 locate_old_decl (olddecl); 2083 locate_old_decl (olddecl);
1547 return false; 2084 return false;
1548 } 2085 }
1549 } 2086 }
1550 2087
1551 /* Optional warning for completely redundant decls. */ 2088 /* Optional warning for completely redundant decls. */
1552 if (!warned && !pedwarned 2089 if (!warned && !pedwarned
1553 && warn_redundant_decls 2090 && warn_redundant_decls
1554 /* Don't warn about a function declaration followed by a 2091 /* Don't warn about a function declaration followed by a
1555 definition. */ 2092 definition. */
1556 && !(TREE_CODE (newdecl) == FUNCTION_DECL 2093 && !(TREE_CODE (newdecl) == FUNCTION_DECL
1557 && DECL_INITIAL (newdecl) && !DECL_INITIAL (olddecl)) 2094 && DECL_INITIAL (newdecl) && !DECL_INITIAL (olddecl))
1558 /* Don't warn about redundant redeclarations of builtins. */ 2095 /* Don't warn about redundant redeclarations of builtins. */
1559 && !(TREE_CODE (newdecl) == FUNCTION_DECL 2096 && !(TREE_CODE (newdecl) == FUNCTION_DECL
1560 && !DECL_BUILT_IN (newdecl) 2097 && !DECL_BUILT_IN (newdecl)
1561 && DECL_BUILT_IN (olddecl) 2098 && DECL_BUILT_IN (olddecl)
1562 && !C_DECL_DECLARED_BUILTIN (olddecl)) 2099 && !C_DECL_DECLARED_BUILTIN (olddecl))
1563 /* Don't warn about an extern followed by a definition. */ 2100 /* Don't warn about an extern followed by a definition. */
1564 && !(DECL_EXTERNAL (olddecl) && !DECL_EXTERNAL (newdecl)) 2101 && !(DECL_EXTERNAL (olddecl) && !DECL_EXTERNAL (newdecl))
1565 /* Don't warn about forward parameter decls. */ 2102 /* Don't warn about forward parameter decls. */
1566 && !(TREE_CODE (newdecl) == PARM_DECL 2103 && !(TREE_CODE (newdecl) == PARM_DECL
1567 && TREE_ASM_WRITTEN (olddecl) && !TREE_ASM_WRITTEN (newdecl)) 2104 && TREE_ASM_WRITTEN (olddecl) && !TREE_ASM_WRITTEN (newdecl))
1568 /* Don't warn about a variable definition following a declaration. */ 2105 /* Don't warn about a variable definition following a declaration. */
1569 && !(TREE_CODE (newdecl) == VAR_DECL 2106 && !(TREE_CODE (newdecl) == VAR_DECL
1570 && DECL_INITIAL (newdecl) && !DECL_INITIAL (olddecl))) 2107 && DECL_INITIAL (newdecl) && !DECL_INITIAL (olddecl)))
1571 { 2108 {
1572 warned = warning (OPT_Wredundant_decls, "redundant redeclaration of %q+D", 2109 warned = warning (OPT_Wredundant_decls, "redundant redeclaration of %q+D",
1573 newdecl); 2110 newdecl);
1574 } 2111 }
1575 2112
1576 /* Report location of previous decl/defn. */ 2113 /* Report location of previous decl/defn. */
1577 if (warned || pedwarned) 2114 if (warned || pedwarned)
1578 locate_old_decl (olddecl); 2115 locate_old_decl (olddecl);
1589 2126
1590 static void 2127 static void
1591 merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype) 2128 merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype)
1592 { 2129 {
1593 bool new_is_definition = (TREE_CODE (newdecl) == FUNCTION_DECL 2130 bool new_is_definition = (TREE_CODE (newdecl) == FUNCTION_DECL
1594 && DECL_INITIAL (newdecl) != 0); 2131 && DECL_INITIAL (newdecl) != 0);
1595 bool new_is_prototype = (TREE_CODE (newdecl) == FUNCTION_DECL 2132 bool new_is_prototype = (TREE_CODE (newdecl) == FUNCTION_DECL
1596 && TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != 0); 2133 && TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != 0);
1597 bool old_is_prototype = (TREE_CODE (olddecl) == FUNCTION_DECL 2134 bool old_is_prototype = (TREE_CODE (olddecl) == FUNCTION_DECL
1598 && TYPE_ARG_TYPES (TREE_TYPE (olddecl)) != 0); 2135 && TYPE_ARG_TYPES (TREE_TYPE (olddecl)) != 0);
1599 bool extern_changed = false; 2136 bool extern_changed = false;
1600 2137
1601 /* For real parm decl following a forward decl, rechain the old decl 2138 /* For real parm decl following a forward decl, rechain the old decl
1602 in its new location and clear TREE_ASM_WRITTEN (it's not a 2139 in its new location and clear TREE_ASM_WRITTEN (it's not a
1603 forward decl anymore). */ 2140 forward decl anymore). */
1605 && TREE_ASM_WRITTEN (olddecl) && !TREE_ASM_WRITTEN (newdecl)) 2142 && TREE_ASM_WRITTEN (olddecl) && !TREE_ASM_WRITTEN (newdecl))
1606 { 2143 {
1607 struct c_binding *b, **here; 2144 struct c_binding *b, **here;
1608 2145
1609 for (here = &current_scope->bindings; *here; here = &(*here)->prev) 2146 for (here = &current_scope->bindings; *here; here = &(*here)->prev)
1610 if ((*here)->decl == olddecl) 2147 if ((*here)->decl == olddecl)
1611 goto found; 2148 goto found;
1612 gcc_unreachable (); 2149 gcc_unreachable ();
1613 2150
1614 found: 2151 found:
1615 b = *here; 2152 b = *here;
1616 *here = b->prev; 2153 *here = b->prev;
1630 2167
1631 /* Lay the type out, unless already done. */ 2168 /* Lay the type out, unless already done. */
1632 if (!comptypes (oldtype, TREE_TYPE (newdecl))) 2169 if (!comptypes (oldtype, TREE_TYPE (newdecl)))
1633 { 2170 {
1634 if (TREE_TYPE (newdecl) != error_mark_node) 2171 if (TREE_TYPE (newdecl) != error_mark_node)
1635 layout_type (TREE_TYPE (newdecl)); 2172 layout_type (TREE_TYPE (newdecl));
1636 if (TREE_CODE (newdecl) != FUNCTION_DECL 2173 if (TREE_CODE (newdecl) != FUNCTION_DECL
1637 && TREE_CODE (newdecl) != TYPE_DECL 2174 && TREE_CODE (newdecl) != TYPE_DECL
1638 && TREE_CODE (newdecl) != CONST_DECL) 2175 && TREE_CODE (newdecl) != CONST_DECL)
1639 layout_decl (newdecl, 0); 2176 layout_decl (newdecl, 0);
1640 } 2177 }
1641 else 2178 else
1642 { 2179 {
1643 /* Since the type is OLDDECL's, make OLDDECL's size go with. */ 2180 /* Since the type is OLDDECL's, make OLDDECL's size go with. */
1644 DECL_SIZE (newdecl) = DECL_SIZE (olddecl); 2181 DECL_SIZE (newdecl) = DECL_SIZE (olddecl);
1645 DECL_SIZE_UNIT (newdecl) = DECL_SIZE_UNIT (olddecl); 2182 DECL_SIZE_UNIT (newdecl) = DECL_SIZE_UNIT (olddecl);
1646 DECL_MODE (newdecl) = DECL_MODE (olddecl); 2183 DECL_MODE (newdecl) = DECL_MODE (olddecl);
1647 if (DECL_ALIGN (olddecl) > DECL_ALIGN (newdecl)) 2184 if (DECL_ALIGN (olddecl) > DECL_ALIGN (newdecl))
1648 { 2185 {
1649 DECL_ALIGN (newdecl) = DECL_ALIGN (olddecl); 2186 DECL_ALIGN (newdecl) = DECL_ALIGN (olddecl);
1650 DECL_USER_ALIGN (newdecl) |= DECL_USER_ALIGN (olddecl); 2187 DECL_USER_ALIGN (newdecl) |= DECL_USER_ALIGN (olddecl);
1651 } 2188 }
1652 } 2189 }
1653 2190
1654 /* Keep the old rtl since we can safely use it. */ 2191 /* Keep the old rtl since we can safely use it. */
1655 if (HAS_RTL_P (olddecl)) 2192 if (HAS_RTL_P (olddecl))
1656 COPY_DECL_RTL (olddecl, newdecl); 2193 COPY_DECL_RTL (olddecl, newdecl);
1673 if (CODE_CONTAINS_STRUCT (TREE_CODE (olddecl), TS_DECL_WITH_VIS) 2210 if (CODE_CONTAINS_STRUCT (TREE_CODE (olddecl), TS_DECL_WITH_VIS)
1674 && DECL_IN_SYSTEM_HEADER (olddecl) 2211 && DECL_IN_SYSTEM_HEADER (olddecl)
1675 && !DECL_IN_SYSTEM_HEADER (newdecl) ) 2212 && !DECL_IN_SYSTEM_HEADER (newdecl) )
1676 DECL_SOURCE_LOCATION (newdecl) = DECL_SOURCE_LOCATION (olddecl); 2213 DECL_SOURCE_LOCATION (newdecl) = DECL_SOURCE_LOCATION (olddecl);
1677 else if (CODE_CONTAINS_STRUCT (TREE_CODE (olddecl), TS_DECL_WITH_VIS) 2214 else if (CODE_CONTAINS_STRUCT (TREE_CODE (olddecl), TS_DECL_WITH_VIS)
1678 && DECL_IN_SYSTEM_HEADER (newdecl) 2215 && DECL_IN_SYSTEM_HEADER (newdecl)
1679 && !DECL_IN_SYSTEM_HEADER (olddecl)) 2216 && !DECL_IN_SYSTEM_HEADER (olddecl))
1680 DECL_SOURCE_LOCATION (olddecl) = DECL_SOURCE_LOCATION (newdecl); 2217 DECL_SOURCE_LOCATION (olddecl) = DECL_SOURCE_LOCATION (newdecl);
1681 else if ((DECL_INITIAL (newdecl) == 0 && DECL_INITIAL (olddecl) != 0) 2218 else if ((DECL_INITIAL (newdecl) == 0 && DECL_INITIAL (olddecl) != 0)
1682 || (old_is_prototype && !new_is_prototype 2219 || (old_is_prototype && !new_is_prototype
1683 && !C_DECL_BUILTIN_PROTOTYPE (olddecl))) 2220 && !C_DECL_BUILTIN_PROTOTYPE (olddecl)))
1684 DECL_SOURCE_LOCATION (newdecl) = DECL_SOURCE_LOCATION (olddecl); 2221 DECL_SOURCE_LOCATION (newdecl) = DECL_SOURCE_LOCATION (olddecl);
1685 2222
1686 /* Merge the initialization information. */ 2223 /* Merge the initialization information. */
1687 if (DECL_INITIAL (newdecl) == 0) 2224 if (DECL_INITIAL (newdecl) == 0)
1688 DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl); 2225 DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
1695 } 2232 }
1696 2233
1697 if (CODE_CONTAINS_STRUCT (TREE_CODE (olddecl), TS_DECL_WITH_VIS)) 2234 if (CODE_CONTAINS_STRUCT (TREE_CODE (olddecl), TS_DECL_WITH_VIS))
1698 { 2235 {
1699 /* Merge the section attribute. 2236 /* Merge the section attribute.
1700 We want to issue an error if the sections conflict but that 2237 We want to issue an error if the sections conflict but that
1701 must be done later in decl_attributes since we are called 2238 must be done later in decl_attributes since we are called
1702 before attributes are assigned. */ 2239 before attributes are assigned. */
1703 if (DECL_SECTION_NAME (newdecl) == NULL_TREE) 2240 if (DECL_SECTION_NAME (newdecl) == NULL_TREE)
1704 DECL_SECTION_NAME (newdecl) = DECL_SECTION_NAME (olddecl); 2241 DECL_SECTION_NAME (newdecl) = DECL_SECTION_NAME (olddecl);
1705 2242
1706 /* Copy the assembler name. 2243 /* Copy the assembler name.
1707 Currently, it can only be defined in the prototype. */ 2244 Currently, it can only be defined in the prototype. */
1708 COPY_DECL_ASSEMBLER_NAME (olddecl, newdecl); 2245 COPY_DECL_ASSEMBLER_NAME (olddecl, newdecl);
1709 2246
1710 /* Use visibility of whichever declaration had it specified */ 2247 /* Use visibility of whichever declaration had it specified */
1711 if (DECL_VISIBILITY_SPECIFIED (olddecl)) 2248 if (DECL_VISIBILITY_SPECIFIED (olddecl))
1712 { 2249 {
1713 DECL_VISIBILITY (newdecl) = DECL_VISIBILITY (olddecl); 2250 DECL_VISIBILITY (newdecl) = DECL_VISIBILITY (olddecl);
1714 DECL_VISIBILITY_SPECIFIED (newdecl) = 1; 2251 DECL_VISIBILITY_SPECIFIED (newdecl) = 1;
1715 } 2252 }
1716 2253
1717 if (TREE_CODE (newdecl) == FUNCTION_DECL) 2254 if (TREE_CODE (newdecl) == FUNCTION_DECL)
1718 { 2255 {
1719 DECL_STATIC_CONSTRUCTOR(newdecl) |= DECL_STATIC_CONSTRUCTOR(olddecl); 2256 DECL_STATIC_CONSTRUCTOR(newdecl) |= DECL_STATIC_CONSTRUCTOR(olddecl);
1720 DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl); 2257 DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl);
1721 DECL_NO_LIMIT_STACK (newdecl) |= DECL_NO_LIMIT_STACK (olddecl); 2258 DECL_NO_LIMIT_STACK (newdecl) |= DECL_NO_LIMIT_STACK (olddecl);
1722 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl) 2259 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl)
1723 |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl); 2260 |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl);
1724 TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl); 2261 TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl);
1725 DECL_IS_MALLOC (newdecl) |= DECL_IS_MALLOC (olddecl); 2262 DECL_IS_MALLOC (newdecl) |= DECL_IS_MALLOC (olddecl);
1726 DECL_IS_OPERATOR_NEW (newdecl) |= DECL_IS_OPERATOR_NEW (olddecl); 2263 DECL_IS_OPERATOR_NEW (newdecl) |= DECL_IS_OPERATOR_NEW (olddecl);
1727 TREE_READONLY (newdecl) |= TREE_READONLY (olddecl); 2264 TREE_READONLY (newdecl) |= TREE_READONLY (olddecl);
1728 DECL_PURE_P (newdecl) |= DECL_PURE_P (olddecl); 2265 DECL_PURE_P (newdecl) |= DECL_PURE_P (olddecl);
1729 DECL_IS_NOVOPS (newdecl) |= DECL_IS_NOVOPS (olddecl); 2266 DECL_IS_NOVOPS (newdecl) |= DECL_IS_NOVOPS (olddecl);
1730 } 2267 }
1731 2268
1732 /* Merge the storage class information. */ 2269 /* Merge the storage class information. */
1733 merge_weak (newdecl, olddecl); 2270 merge_weak (newdecl, olddecl);
1734 2271
1735 /* For functions, static overrides non-static. */ 2272 /* For functions, static overrides non-static. */
1736 if (TREE_CODE (newdecl) == FUNCTION_DECL) 2273 if (TREE_CODE (newdecl) == FUNCTION_DECL)
1737 { 2274 {
1738 TREE_PUBLIC (newdecl) &= TREE_PUBLIC (olddecl); 2275 TREE_PUBLIC (newdecl) &= TREE_PUBLIC (olddecl);
1739 /* This is since we don't automatically 2276 /* This is since we don't automatically
1740 copy the attributes of NEWDECL into OLDDECL. */ 2277 copy the attributes of NEWDECL into OLDDECL. */
1741 TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl); 2278 TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
1742 /* If this clears `static', clear it in the identifier too. */ 2279 /* If this clears `static', clear it in the identifier too. */
1743 if (!TREE_PUBLIC (olddecl)) 2280 if (!TREE_PUBLIC (olddecl))
1744 TREE_PUBLIC (DECL_NAME (olddecl)) = 0; 2281 TREE_PUBLIC (DECL_NAME (olddecl)) = 0;
1745 } 2282 }
1746 } 2283 }
1747 2284
1748 /* In c99, 'extern' declaration before (or after) 'inline' means this 2285 /* In c99, 'extern' declaration before (or after) 'inline' means this
1749 function is not DECL_EXTERNAL, unless 'gnu_inline' attribute 2286 function is not DECL_EXTERNAL, unless 'gnu_inline' attribute
1750 is present. */ 2287 is present. */
1751 if (TREE_CODE (newdecl) == FUNCTION_DECL 2288 if (TREE_CODE (newdecl) == FUNCTION_DECL
1752 && !flag_gnu89_inline 2289 && !flag_gnu89_inline
1753 && (DECL_DECLARED_INLINE_P (newdecl) 2290 && (DECL_DECLARED_INLINE_P (newdecl)
1754 || DECL_DECLARED_INLINE_P (olddecl)) 2291 || DECL_DECLARED_INLINE_P (olddecl))
1755 && (!DECL_DECLARED_INLINE_P (newdecl) 2292 && (!DECL_DECLARED_INLINE_P (newdecl)
1756 || !DECL_DECLARED_INLINE_P (olddecl) 2293 || !DECL_DECLARED_INLINE_P (olddecl)
1757 || !DECL_EXTERNAL (olddecl)) 2294 || !DECL_EXTERNAL (olddecl))
1758 && DECL_EXTERNAL (newdecl) 2295 && DECL_EXTERNAL (newdecl)
1759 && !lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (newdecl)) 2296 && !lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (newdecl))
1760 && !current_function_decl) 2297 && !current_function_decl)
1761 DECL_EXTERNAL (newdecl) = 0; 2298 DECL_EXTERNAL (newdecl) = 0;
1762 2299
1766 DECL_EXTERNAL (newdecl) = DECL_EXTERNAL (olddecl); 2303 DECL_EXTERNAL (newdecl) = DECL_EXTERNAL (olddecl);
1767 2304
1768 /* An extern decl does not override previous storage class. */ 2305 /* An extern decl does not override previous storage class. */
1769 TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl); 2306 TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
1770 if (!DECL_EXTERNAL (newdecl)) 2307 if (!DECL_EXTERNAL (newdecl))
1771 { 2308 {
1772 DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl); 2309 DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
1773 DECL_COMMON (newdecl) = DECL_COMMON (olddecl); 2310 DECL_COMMON (newdecl) = DECL_COMMON (olddecl);
1774 } 2311 }
1775 } 2312 }
1776 else 2313 else
1777 { 2314 {
1778 TREE_STATIC (olddecl) = TREE_STATIC (newdecl); 2315 TREE_STATIC (olddecl) = TREE_STATIC (newdecl);
1779 TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl); 2316 TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
1780 } 2317 }
1781 2318
1782 if (TREE_CODE (newdecl) == FUNCTION_DECL) 2319 if (TREE_CODE (newdecl) == FUNCTION_DECL)
1783 { 2320 {
1784 /* If we're redefining a function previously defined as extern 2321 /* If we're redefining a function previously defined as extern
1785 inline, make sure we emit debug info for the inline before we 2322 inline, make sure we emit debug info for the inline before we
1786 throw it away, in case it was inlined into a function that 2323 throw it away, in case it was inlined into a function that
1787 hasn't been written out yet. */ 2324 hasn't been written out yet. */
1788 if (new_is_definition && DECL_INITIAL (olddecl)) 2325 if (new_is_definition && DECL_INITIAL (olddecl))
1789 /* The new defn must not be inline. */ 2326 /* The new defn must not be inline. */
1790 DECL_UNINLINABLE (newdecl) = 1; 2327 DECL_UNINLINABLE (newdecl) = 1;
1791 else 2328 else
1792 { 2329 {
1793 /* If either decl says `inline', this fn is inline, unless 2330 /* If either decl says `inline', this fn is inline, unless
1794 its definition was passed already. */ 2331 its definition was passed already. */
1795 if (DECL_DECLARED_INLINE_P (newdecl) 2332 if (DECL_DECLARED_INLINE_P (newdecl)
1796 || DECL_DECLARED_INLINE_P (olddecl)) 2333 || DECL_DECLARED_INLINE_P (olddecl))
1797 DECL_DECLARED_INLINE_P (newdecl) = 1; 2334 DECL_DECLARED_INLINE_P (newdecl) = 1;
1798 2335
1799 DECL_UNINLINABLE (newdecl) = DECL_UNINLINABLE (olddecl) 2336 DECL_UNINLINABLE (newdecl) = DECL_UNINLINABLE (olddecl)
1800 = (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl)); 2337 = (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl));
1801 2338
1802 DECL_DISREGARD_INLINE_LIMITS (newdecl) 2339 DECL_DISREGARD_INLINE_LIMITS (newdecl)
1803 = DECL_DISREGARD_INLINE_LIMITS (olddecl) 2340 = DECL_DISREGARD_INLINE_LIMITS (olddecl)
1804 = (DECL_DISREGARD_INLINE_LIMITS (newdecl) 2341 = (DECL_DISREGARD_INLINE_LIMITS (newdecl)
1805 || DECL_DISREGARD_INLINE_LIMITS (olddecl)); 2342 || DECL_DISREGARD_INLINE_LIMITS (olddecl));
1806 } 2343 }
1807 2344
1808 if (DECL_BUILT_IN (olddecl)) 2345 if (DECL_BUILT_IN (olddecl))
1809 { 2346 {
1810 /* If redeclaring a builtin function, it stays built in. 2347 /* If redeclaring a builtin function, it stays built in.
1811 But it gets tagged as having been declared. */ 2348 But it gets tagged as having been declared. */
1812 DECL_BUILT_IN_CLASS (newdecl) = DECL_BUILT_IN_CLASS (olddecl); 2349 DECL_BUILT_IN_CLASS (newdecl) = DECL_BUILT_IN_CLASS (olddecl);
1813 DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl); 2350 DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl);
1814 C_DECL_DECLARED_BUILTIN (newdecl) = 1; 2351 C_DECL_DECLARED_BUILTIN (newdecl) = 1;
1815 if (new_is_prototype) 2352 if (new_is_prototype)
1816 C_DECL_BUILTIN_PROTOTYPE (newdecl) = 0; 2353 C_DECL_BUILTIN_PROTOTYPE (newdecl) = 0;
1817 else 2354 else
1818 C_DECL_BUILTIN_PROTOTYPE (newdecl) 2355 C_DECL_BUILTIN_PROTOTYPE (newdecl)
1819 = C_DECL_BUILTIN_PROTOTYPE (olddecl); 2356 = C_DECL_BUILTIN_PROTOTYPE (olddecl);
1820 } 2357 }
1821 2358
1822 /* Preserve function specific target and optimization options */ 2359 /* Preserve function specific target and optimization options */
1823 if (DECL_FUNCTION_SPECIFIC_TARGET (olddecl) 2360 if (DECL_FUNCTION_SPECIFIC_TARGET (olddecl)
1824 && !DECL_FUNCTION_SPECIFIC_TARGET (newdecl)) 2361 && !DECL_FUNCTION_SPECIFIC_TARGET (newdecl))
1825 DECL_FUNCTION_SPECIFIC_TARGET (newdecl) 2362 DECL_FUNCTION_SPECIFIC_TARGET (newdecl)
1826 = DECL_FUNCTION_SPECIFIC_TARGET (olddecl); 2363 = DECL_FUNCTION_SPECIFIC_TARGET (olddecl);
1827 2364
1828 if (DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl) 2365 if (DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl)
1829 && !DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl)) 2366 && !DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl))
1830 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl) 2367 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl)
1831 = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl); 2368 = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl);
1832 2369
1833 /* Also preserve various other info from the definition. */ 2370 /* Also preserve various other info from the definition. */
1834 if (!new_is_definition) 2371 if (!new_is_definition)
1835 { 2372 {
1836 DECL_RESULT (newdecl) = DECL_RESULT (olddecl); 2373 tree t;
1837 DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl); 2374 DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
1838 DECL_STRUCT_FUNCTION (newdecl) = DECL_STRUCT_FUNCTION (olddecl); 2375 DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
1839 DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl); 2376 DECL_STRUCT_FUNCTION (newdecl) = DECL_STRUCT_FUNCTION (olddecl);
1840 gimple_set_body (newdecl, gimple_body (olddecl)); 2377 DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl);
1841 DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl); 2378 gimple_set_body (newdecl, gimple_body (olddecl));
1842 2379 DECL_ARGUMENTS (newdecl) = copy_list (DECL_ARGUMENTS (olddecl));
1843 /* See if we've got a function to instantiate from. */ 2380 for (t = DECL_ARGUMENTS (newdecl); t ; t = TREE_CHAIN (t))
1844 if (DECL_SAVED_TREE (olddecl)) 2381 DECL_CONTEXT (t) = newdecl;
1845 DECL_ABSTRACT_ORIGIN (newdecl) 2382
1846 = DECL_ABSTRACT_ORIGIN (olddecl); 2383 /* See if we've got a function to instantiate from. */
1847 } 2384 if (DECL_SAVED_TREE (olddecl))
1848 } 2385 DECL_ABSTRACT_ORIGIN (newdecl)
1849 2386 = DECL_ABSTRACT_ORIGIN (olddecl);
1850 extern_changed = DECL_EXTERNAL (olddecl) && !DECL_EXTERNAL (newdecl); 2387 }
1851 2388 }
1852 /* Merge the USED information. */ 2389
1853 if (TREE_USED (olddecl)) 2390 extern_changed = DECL_EXTERNAL (olddecl) && !DECL_EXTERNAL (newdecl);
1854 TREE_USED (newdecl) = 1; 2391
1855 else if (TREE_USED (newdecl)) 2392 /* Merge the USED information. */
1856 TREE_USED (olddecl) = 1; 2393 if (TREE_USED (olddecl))
2394 TREE_USED (newdecl) = 1;
2395 else if (TREE_USED (newdecl))
2396 TREE_USED (olddecl) = 1;
1857 2397
1858 /* Copy most of the decl-specific fields of NEWDECL into OLDDECL. 2398 /* Copy most of the decl-specific fields of NEWDECL into OLDDECL.
1859 But preserve OLDDECL's DECL_UID and DECL_CONTEXT. */ 2399 But preserve OLDDECL's DECL_UID, DECL_CONTEXT and
2400 DECL_ARGUMENTS (if appropriate). */
1860 { 2401 {
1861 unsigned olddecl_uid = DECL_UID (olddecl); 2402 unsigned olddecl_uid = DECL_UID (olddecl);
1862 tree olddecl_context = DECL_CONTEXT (olddecl); 2403 tree olddecl_context = DECL_CONTEXT (olddecl);
2404 tree olddecl_arguments = NULL;
2405 if (TREE_CODE (olddecl) == FUNCTION_DECL)
2406 olddecl_arguments = DECL_ARGUMENTS (olddecl);
1863 2407
1864 memcpy ((char *) olddecl + sizeof (struct tree_common), 2408 memcpy ((char *) olddecl + sizeof (struct tree_common),
1865 (char *) newdecl + sizeof (struct tree_common), 2409 (char *) newdecl + sizeof (struct tree_common),
1866 sizeof (struct tree_decl_common) - sizeof (struct tree_common)); 2410 sizeof (struct tree_decl_common) - sizeof (struct tree_common));
1867 switch (TREE_CODE (olddecl)) 2411 switch (TREE_CODE (olddecl))
1868 { 2412 {
1869 case FUNCTION_DECL: 2413 case FUNCTION_DECL:
1870 gimple_set_body (olddecl, gimple_body (newdecl)); 2414 gimple_set_body (olddecl, gimple_body (newdecl));
1871 /* fall through */ 2415 /* fall through */
1872 2416
1873 case FIELD_DECL: 2417 case FIELD_DECL:
1874 case VAR_DECL: 2418 case VAR_DECL:
1875 case PARM_DECL: 2419 case PARM_DECL:
1876 case LABEL_DECL: 2420 case LABEL_DECL:
1877 case RESULT_DECL: 2421 case RESULT_DECL:
1878 case CONST_DECL: 2422 case CONST_DECL:
1879 case TYPE_DECL: 2423 case TYPE_DECL:
1880 memcpy ((char *) olddecl + sizeof (struct tree_decl_common), 2424 memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
1881 (char *) newdecl + sizeof (struct tree_decl_common), 2425 (char *) newdecl + sizeof (struct tree_decl_common),
1882 tree_code_size (TREE_CODE (olddecl)) - sizeof (struct tree_decl_common)); 2426 tree_code_size (TREE_CODE (olddecl)) - sizeof (struct tree_decl_common));
1883 break; 2427 break;
1884 2428
1885 default: 2429 default:
1886 2430
1887 memcpy ((char *) olddecl + sizeof (struct tree_decl_common), 2431 memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
1888 (char *) newdecl + sizeof (struct tree_decl_common), 2432 (char *) newdecl + sizeof (struct tree_decl_common),
1889 sizeof (struct tree_decl_non_common) - sizeof (struct tree_decl_common)); 2433 sizeof (struct tree_decl_non_common) - sizeof (struct tree_decl_common));
1890 } 2434 }
1891 DECL_UID (olddecl) = olddecl_uid; 2435 DECL_UID (olddecl) = olddecl_uid;
1892 DECL_CONTEXT (olddecl) = olddecl_context; 2436 DECL_CONTEXT (olddecl) = olddecl_context;
2437 if (TREE_CODE (olddecl) == FUNCTION_DECL)
2438 DECL_ARGUMENTS (olddecl) = olddecl_arguments;
1893 } 2439 }
1894 2440
1895 /* If OLDDECL had its DECL_RTL instantiated, re-invoke make_decl_rtl 2441 /* If OLDDECL had its DECL_RTL instantiated, re-invoke make_decl_rtl
1896 so that encode_section_info has a chance to look at the new decl 2442 so that encode_section_info has a chance to look at the new decl
1897 flags and attributes. */ 2443 flags and attributes. */
1898 if (DECL_RTL_SET_P (olddecl) 2444 if (DECL_RTL_SET_P (olddecl)
1899 && (TREE_CODE (olddecl) == FUNCTION_DECL 2445 && (TREE_CODE (olddecl) == FUNCTION_DECL
1900 || (TREE_CODE (olddecl) == VAR_DECL 2446 || (TREE_CODE (olddecl) == VAR_DECL
1901 && TREE_STATIC (olddecl)))) 2447 && TREE_STATIC (olddecl))))
1902 make_decl_rtl (olddecl); 2448 make_decl_rtl (olddecl);
1903 2449
1904 /* If we changed a function from DECL_EXTERNAL to !DECL_EXTERNAL, 2450 /* If we changed a function from DECL_EXTERNAL to !DECL_EXTERNAL,
1905 and the definition is coming from the old version, cgraph needs 2451 and the definition is coming from the old version, cgraph needs
1906 to be called again. */ 2452 to be called again. */
1949 2495
1950 /* Is anything being shadowed? Invisible decls do not count. */ 2496 /* Is anything being shadowed? Invisible decls do not count. */
1951 for (b = I_SYMBOL_BINDING (DECL_NAME (new_decl)); b; b = b->shadowed) 2497 for (b = I_SYMBOL_BINDING (DECL_NAME (new_decl)); b; b = b->shadowed)
1952 if (b->decl && b->decl != new_decl && !b->invisible) 2498 if (b->decl && b->decl != new_decl && !b->invisible)
1953 { 2499 {
1954 tree old_decl = b->decl; 2500 tree old_decl = b->decl;
1955 2501
1956 if (old_decl == error_mark_node) 2502 if (old_decl == error_mark_node)
1957 { 2503 {
1958 warning (OPT_Wshadow, "declaration of %q+D shadows previous " 2504 warning (OPT_Wshadow, "declaration of %q+D shadows previous "
1959 "non-variable", new_decl); 2505 "non-variable", new_decl);
1960 break; 2506 break;
1961 }
1962 else if (TREE_CODE (old_decl) == PARM_DECL)
1963 warning (OPT_Wshadow, "declaration of %q+D shadows a parameter",
1964 new_decl);
1965 else if (DECL_FILE_SCOPE_P (old_decl))
1966 warning (OPT_Wshadow, "declaration of %q+D shadows a global "
1967 "declaration", new_decl);
1968 else if (TREE_CODE (old_decl) == FUNCTION_DECL
1969 && DECL_BUILT_IN (old_decl))
1970 {
1971 warning (OPT_Wshadow, "declaration of %q+D shadows "
1972 "a built-in function", new_decl);
1973 break;
1974 }
1975 else
1976 warning (OPT_Wshadow, "declaration of %q+D shadows a previous local",
1977 new_decl);
1978
1979 warning (OPT_Wshadow, "%Jshadowed declaration is here", old_decl);
1980
1981 break;
1982 } 2507 }
1983 } 2508 else if (TREE_CODE (old_decl) == PARM_DECL)
1984 2509 warning (OPT_Wshadow, "declaration of %q+D shadows a parameter",
1985 2510 new_decl);
1986 /* Subroutine of pushdecl. 2511 else if (DECL_FILE_SCOPE_P (old_decl))
1987 2512 warning (OPT_Wshadow, "declaration of %q+D shadows a global "
1988 X is a TYPE_DECL for a typedef statement. Create a brand new 2513 "declaration", new_decl);
1989 ..._TYPE node (which will be just a variant of the existing 2514 else if (TREE_CODE (old_decl) == FUNCTION_DECL
1990 ..._TYPE node with identical properties) and then install X 2515 && DECL_BUILT_IN (old_decl))
1991 as the TYPE_NAME of this brand new (duplicate) ..._TYPE node. 2516 {
1992 2517 warning (OPT_Wshadow, "declaration of %q+D shadows "
1993 The whole point here is to end up with a situation where each 2518 "a built-in function", new_decl);
1994 and every ..._TYPE node the compiler creates will be uniquely 2519 break;
1995 associated with AT MOST one node representing a typedef name. 2520 }
1996 This way, even though the compiler substitutes corresponding 2521 else
1997 ..._TYPE nodes for TYPE_DECL (i.e. "typedef name") nodes very 2522 warning (OPT_Wshadow, "declaration of %q+D shadows a previous local",
1998 early on, later parts of the compiler can always do the reverse 2523 new_decl);
1999 translation and get back the corresponding typedef name. For 2524
2000 example, given: 2525 warning_at (DECL_SOURCE_LOCATION (old_decl), OPT_Wshadow,
2001 2526 "shadowed declaration is here");
2002 typedef struct S MY_TYPE; 2527
2003 MY_TYPE object; 2528 break;
2004 2529 }
2005 Later parts of the compiler might only know that `object' was of
2006 type `struct S' if it were not for code just below. With this
2007 code however, later parts of the compiler see something like:
2008
2009 struct S' == struct S
2010 typedef struct S' MY_TYPE;
2011 struct S' object;
2012
2013 And they can then deduce (from the node for type struct S') that
2014 the original object declaration was:
2015
2016 MY_TYPE object;
2017
2018 Being able to do this is important for proper support of protoize,
2019 and also for generating precise symbolic debugging information
2020 which takes full account of the programmer's (typedef) vocabulary.
2021
2022 Obviously, we don't want to generate a duplicate ..._TYPE node if
2023 the TYPE_DECL node that we are now processing really represents a
2024 standard built-in type. */
2025
2026 static void
2027 clone_underlying_type (tree x)
2028 {
2029 if (DECL_IS_BUILTIN (x))
2030 {
2031 if (TYPE_NAME (TREE_TYPE (x)) == 0)
2032 TYPE_NAME (TREE_TYPE (x)) = x;
2033 }
2034 else if (TREE_TYPE (x) != error_mark_node
2035 && DECL_ORIGINAL_TYPE (x) == NULL_TREE)
2036 {
2037 tree tt = TREE_TYPE (x);
2038 DECL_ORIGINAL_TYPE (x) = tt;
2039 tt = build_variant_type_copy (tt);
2040 TYPE_NAME (tt) = x;
2041 TREE_USED (tt) = TREE_USED (x);
2042 TREE_TYPE (x) = tt;
2043 }
2044 } 2530 }
2045 2531
2046 /* Record a decl-node X as belonging to the current lexical scope. 2532 /* Record a decl-node X as belonging to the current lexical scope.
2047 Check for errors (such as an incompatible declaration for the same 2533 Check for errors (such as an incompatible declaration for the same
2048 name already seen in the same scope). 2534 name already seen in the same scope).
2056 { 2542 {
2057 tree name = DECL_NAME (x); 2543 tree name = DECL_NAME (x);
2058 struct c_scope *scope = current_scope; 2544 struct c_scope *scope = current_scope;
2059 struct c_binding *b; 2545 struct c_binding *b;
2060 bool nested = false; 2546 bool nested = false;
2547 location_t locus = DECL_SOURCE_LOCATION (x);
2061 2548
2062 /* Must set DECL_CONTEXT for everything not at file scope or 2549 /* Must set DECL_CONTEXT for everything not at file scope or
2063 DECL_FILE_SCOPE_P won't work. Local externs don't count 2550 DECL_FILE_SCOPE_P won't work. Local externs don't count
2064 unless they have initializers (which generate code). */ 2551 unless they have initializers (which generate code). */
2065 if (current_function_decl 2552 if (current_function_decl
2066 && ((TREE_CODE (x) != FUNCTION_DECL && TREE_CODE (x) != VAR_DECL) 2553 && ((TREE_CODE (x) != FUNCTION_DECL && TREE_CODE (x) != VAR_DECL)
2067 || DECL_INITIAL (x) || !DECL_EXTERNAL (x))) 2554 || DECL_INITIAL (x) || !DECL_EXTERNAL (x)))
2068 DECL_CONTEXT (x) = current_function_decl; 2555 DECL_CONTEXT (x) = current_function_decl;
2069
2070 /* If this is of variably modified type, prevent jumping into its
2071 scope. */
2072 if ((TREE_CODE (x) == VAR_DECL || TREE_CODE (x) == TYPE_DECL)
2073 && variably_modified_type_p (TREE_TYPE (x), NULL_TREE))
2074 c_begin_vm_scope (scope->depth);
2075 2556
2076 /* Anonymous decls are just inserted in the scope. */ 2557 /* Anonymous decls are just inserted in the scope. */
2077 if (!name) 2558 if (!name)
2078 { 2559 {
2079 bind (name, x, scope, /*invisible=*/false, /*nested=*/false); 2560 bind (name, x, scope, /*invisible=*/false, /*nested=*/false,
2561 locus);
2080 return x; 2562 return x;
2081 } 2563 }
2082 2564
2083 /* First, see if there is another declaration with the same name in 2565 /* First, see if there is another declaration with the same name in
2084 the current scope. If there is, duplicate_decls may do all the 2566 the current scope. If there is, duplicate_decls may do all the
2093 struct c_binding *b_ext, *b_use; 2575 struct c_binding *b_ext, *b_use;
2094 tree type = TREE_TYPE (x); 2576 tree type = TREE_TYPE (x);
2095 tree visdecl = b->decl; 2577 tree visdecl = b->decl;
2096 tree vistype = TREE_TYPE (visdecl); 2578 tree vistype = TREE_TYPE (visdecl);
2097 if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE 2579 if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE
2098 && COMPLETE_TYPE_P (TREE_TYPE (x))) 2580 && COMPLETE_TYPE_P (TREE_TYPE (x)))
2099 b->inner_comp = false; 2581 b->inner_comp = false;
2100 b_use = b; 2582 b_use = b;
2101 b_ext = b; 2583 b_ext = b;
2102 /* If this is an external linkage declaration, we should check 2584 /* If this is an external linkage declaration, we should check
2103 for compatibility with the type in the external scope before 2585 for compatibility with the type in the external scope before
2104 setting the type at this scope based on the visible 2586 setting the type at this scope based on the visible
2105 information only. */ 2587 information only. */
2106 if (TREE_PUBLIC (x) && TREE_PUBLIC (visdecl)) 2588 if (TREE_PUBLIC (x) && TREE_PUBLIC (visdecl))
2107 { 2589 {
2108 while (b_ext && !B_IN_EXTERNAL_SCOPE (b_ext)) 2590 while (b_ext && !B_IN_EXTERNAL_SCOPE (b_ext))
2109 b_ext = b_ext->shadowed; 2591 b_ext = b_ext->shadowed;
2110 if (b_ext) 2592 if (b_ext)
2111 { 2593 {
2112 b_use = b_ext; 2594 b_use = b_ext;
2113 if (b_use->type) 2595 if (b_use->u.type)
2114 TREE_TYPE (b_use->decl) = b_use->type; 2596 TREE_TYPE (b_use->decl) = b_use->u.type;
2115 } 2597 }
2116 } 2598 }
2117 if (duplicate_decls (x, b_use->decl)) 2599 if (duplicate_decls (x, b_use->decl))
2118 { 2600 {
2119 if (b_use != b) 2601 if (b_use != b)
2120 { 2602 {
2121 /* Save the updated type in the external scope and 2603 /* Save the updated type in the external scope and
2122 restore the proper type for this scope. */ 2604 restore the proper type for this scope. */
2123 tree thistype; 2605 tree thistype;
2124 if (comptypes (vistype, type)) 2606 if (comptypes (vistype, type))
2125 thistype = composite_type (vistype, type); 2607 thistype = composite_type (vistype, type);
2126 else 2608 else
2127 thistype = TREE_TYPE (b_use->decl); 2609 thistype = TREE_TYPE (b_use->decl);
2128 b_use->type = TREE_TYPE (b_use->decl); 2610 b_use->u.type = TREE_TYPE (b_use->decl);
2129 if (TREE_CODE (b_use->decl) == FUNCTION_DECL 2611 if (TREE_CODE (b_use->decl) == FUNCTION_DECL
2130 && DECL_BUILT_IN (b_use->decl)) 2612 && DECL_BUILT_IN (b_use->decl))
2131 thistype 2613 thistype
2132 = build_type_attribute_variant (thistype, 2614 = build_type_attribute_variant (thistype,
2133 TYPE_ATTRIBUTES 2615 TYPE_ATTRIBUTES
2134 (b_use->type)); 2616 (b_use->u.type));
2135 TREE_TYPE (b_use->decl) = thistype; 2617 TREE_TYPE (b_use->decl) = thistype;
2136 } 2618 }
2137 return b_use->decl; 2619 return b_use->decl;
2138 } 2620 }
2139 else 2621 else
2140 goto skip_external_and_shadow_checks; 2622 goto skip_external_and_shadow_checks;
2141 } 2623 }
2142 2624
2143 /* All declarations with external linkage, and all external 2625 /* All declarations with external linkage, and all external
2144 references, go in the external scope, no matter what scope is 2626 references, go in the external scope, no matter what scope is
2145 current. However, the binding in that scope is ignored for 2627 current. However, the binding in that scope is ignored for
2157 tree type = TREE_TYPE (x); 2639 tree type = TREE_TYPE (x);
2158 tree vistype = 0; 2640 tree vistype = 0;
2159 tree visdecl = 0; 2641 tree visdecl = 0;
2160 bool type_saved = false; 2642 bool type_saved = false;
2161 if (b && !B_IN_EXTERNAL_SCOPE (b) 2643 if (b && !B_IN_EXTERNAL_SCOPE (b)
2162 && (TREE_CODE (b->decl) == FUNCTION_DECL 2644 && (TREE_CODE (b->decl) == FUNCTION_DECL
2163 || TREE_CODE (b->decl) == VAR_DECL) 2645 || TREE_CODE (b->decl) == VAR_DECL)
2164 && DECL_FILE_SCOPE_P (b->decl)) 2646 && DECL_FILE_SCOPE_P (b->decl))
2165 { 2647 {
2166 visdecl = b->decl; 2648 visdecl = b->decl;
2167 vistype = TREE_TYPE (visdecl); 2649 vistype = TREE_TYPE (visdecl);
2168 } 2650 }
2169 if (scope != file_scope 2651 if (scope != file_scope
2170 && !DECL_IN_SYSTEM_HEADER (x)) 2652 && !DECL_IN_SYSTEM_HEADER (x))
2171 warning (OPT_Wnested_externs, "nested extern declaration of %qD", x); 2653 warning (OPT_Wnested_externs, "nested extern declaration of %qD", x);
2172 2654
2173 while (b && !B_IN_EXTERNAL_SCOPE (b)) 2655 while (b && !B_IN_EXTERNAL_SCOPE (b))
2174 { 2656 {
2175 /* If this decl might be modified, save its type. This is 2657 /* If this decl might be modified, save its type. This is
2176 done here rather than when the decl is first bound 2658 done here rather than when the decl is first bound
2177 because the type may change after first binding, through 2659 because the type may change after first binding, through
2178 being completed or through attributes being added. If we 2660 being completed or through attributes being added. If we
2179 encounter multiple such decls, only the first should have 2661 encounter multiple such decls, only the first should have
2180 its type saved; the others will already have had their 2662 its type saved; the others will already have had their
2181 proper types saved and the types will not have changed as 2663 proper types saved and the types will not have changed as
2182 their scopes will not have been re-entered. */ 2664 their scopes will not have been re-entered. */
2183 if (DECL_P (b->decl) && DECL_FILE_SCOPE_P (b->decl) && !type_saved) 2665 if (DECL_P (b->decl) && DECL_FILE_SCOPE_P (b->decl) && !type_saved)
2184 { 2666 {
2185 b->type = TREE_TYPE (b->decl); 2667 b->u.type = TREE_TYPE (b->decl);
2186 type_saved = true; 2668 type_saved = true;
2187 } 2669 }
2188 if (B_IN_FILE_SCOPE (b) 2670 if (B_IN_FILE_SCOPE (b)
2189 && TREE_CODE (b->decl) == VAR_DECL 2671 && TREE_CODE (b->decl) == VAR_DECL
2190 && TREE_STATIC (b->decl) 2672 && TREE_STATIC (b->decl)
2191 && TREE_CODE (TREE_TYPE (b->decl)) == ARRAY_TYPE 2673 && TREE_CODE (TREE_TYPE (b->decl)) == ARRAY_TYPE
2192 && !TYPE_DOMAIN (TREE_TYPE (b->decl)) 2674 && !TYPE_DOMAIN (TREE_TYPE (b->decl))
2193 && TREE_CODE (type) == ARRAY_TYPE 2675 && TREE_CODE (type) == ARRAY_TYPE
2194 && TYPE_DOMAIN (type) 2676 && TYPE_DOMAIN (type)
2195 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) 2677 && TYPE_MAX_VALUE (TYPE_DOMAIN (type))
2196 && !integer_zerop (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))) 2678 && !integer_zerop (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
2197 { 2679 {
2198 /* Array type completed in inner scope, which should be 2680 /* Array type completed in inner scope, which should be
2199 diagnosed if the completion does not have size 1 and 2681 diagnosed if the completion does not have size 1 and
2200 it does not get completed in the file scope. */ 2682 it does not get completed in the file scope. */
2201 b->inner_comp = true; 2683 b->inner_comp = true;
2202 } 2684 }
2203 b = b->shadowed; 2685 b = b->shadowed;
2204 } 2686 }
2205 2687
2206 /* If a matching external declaration has been found, set its 2688 /* If a matching external declaration has been found, set its
2207 type to the composite of all the types of that declaration. 2689 type to the composite of all the types of that declaration.
2208 After the consistency checks, it will be reset to the 2690 After the consistency checks, it will be reset to the
2209 composite of the visible types only. */ 2691 composite of the visible types only. */
2210 if (b && (TREE_PUBLIC (x) || same_translation_unit_p (x, b->decl)) 2692 if (b && (TREE_PUBLIC (x) || same_translation_unit_p (x, b->decl))
2211 && b->type) 2693 && b->u.type)
2212 TREE_TYPE (b->decl) = b->type; 2694 TREE_TYPE (b->decl) = b->u.type;
2213 2695
2214 /* The point of the same_translation_unit_p check here is, 2696 /* The point of the same_translation_unit_p check here is,
2215 we want to detect a duplicate decl for a construct like 2697 we want to detect a duplicate decl for a construct like
2216 foo() { extern bar(); } ... static bar(); but not if 2698 foo() { extern bar(); } ... static bar(); but not if
2217 they are in different translation units. In any case, 2699 they are in different translation units. In any case,
2218 the static does not go in the externals scope. */ 2700 the static does not go in the externals scope. */
2219 if (b 2701 if (b
2220 && (TREE_PUBLIC (x) || same_translation_unit_p (x, b->decl)) 2702 && (TREE_PUBLIC (x) || same_translation_unit_p (x, b->decl))
2221 && duplicate_decls (x, b->decl)) 2703 && duplicate_decls (x, b->decl))
2222 { 2704 {
2223 tree thistype; 2705 tree thistype;
2224 if (vistype) 2706 if (vistype)
2225 { 2707 {
2226 if (comptypes (vistype, type)) 2708 if (comptypes (vistype, type))
2227 thistype = composite_type (vistype, type); 2709 thistype = composite_type (vistype, type);
2228 else 2710 else
2229 thistype = TREE_TYPE (b->decl); 2711 thistype = TREE_TYPE (b->decl);
2230 } 2712 }
2231 else 2713 else
2232 thistype = type; 2714 thistype = type;
2233 b->type = TREE_TYPE (b->decl); 2715 b->u.type = TREE_TYPE (b->decl);
2234 if (TREE_CODE (b->decl) == FUNCTION_DECL && DECL_BUILT_IN (b->decl)) 2716 if (TREE_CODE (b->decl) == FUNCTION_DECL && DECL_BUILT_IN (b->decl))
2235 thistype 2717 thistype
2236 = build_type_attribute_variant (thistype, 2718 = build_type_attribute_variant (thistype,
2237 TYPE_ATTRIBUTES (b->type)); 2719 TYPE_ATTRIBUTES (b->u.type));
2238 TREE_TYPE (b->decl) = thistype; 2720 TREE_TYPE (b->decl) = thistype;
2239 bind (name, b->decl, scope, /*invisible=*/false, /*nested=*/true); 2721 bind (name, b->decl, scope, /*invisible=*/false, /*nested=*/true,
2240 return b->decl; 2722 locus);
2241 } 2723 return b->decl;
2724 }
2242 else if (TREE_PUBLIC (x)) 2725 else if (TREE_PUBLIC (x))
2243 { 2726 {
2244 if (visdecl && !b && duplicate_decls (x, visdecl)) 2727 if (visdecl && !b && duplicate_decls (x, visdecl))
2245 { 2728 {
2246 /* An external declaration at block scope referring to a 2729 /* An external declaration at block scope referring to a
2247 visible entity with internal linkage. The composite 2730 visible entity with internal linkage. The composite
2248 type will already be correct for this scope, so we 2731 type will already be correct for this scope, so we
2249 just need to fall through to make the declaration in 2732 just need to fall through to make the declaration in
2250 this scope. */ 2733 this scope. */
2251 nested = true; 2734 nested = true;
2252 x = visdecl; 2735 x = visdecl;
2253 } 2736 }
2254 else 2737 else
2255 { 2738 {
2256 bind (name, x, external_scope, /*invisible=*/true, 2739 bind (name, x, external_scope, /*invisible=*/true,
2257 /*nested=*/false); 2740 /*nested=*/false, locus);
2258 nested = true; 2741 nested = true;
2259 } 2742 }
2260 } 2743 }
2261 } 2744 }
2262 2745
2263 if (TREE_CODE (x) != PARM_DECL) 2746 if (TREE_CODE (x) != PARM_DECL)
2264 warn_if_shadowing (x); 2747 warn_if_shadowing (x);
2265 2748
2266 skip_external_and_shadow_checks: 2749 skip_external_and_shadow_checks:
2267 if (TREE_CODE (x) == TYPE_DECL) 2750 if (TREE_CODE (x) == TYPE_DECL)
2268 clone_underlying_type (x); 2751 set_underlying_type (x);
2269 2752
2270 bind (name, x, scope, /*invisible=*/false, nested); 2753 bind (name, x, scope, /*invisible=*/false, nested, locus);
2271 2754
2272 /* If x's type is incomplete because it's based on a 2755 /* If x's type is incomplete because it's based on a
2273 structure or union which has not yet been fully declared, 2756 structure or union which has not yet been fully declared,
2274 attach it to that structure or union type, so we can go 2757 attach it to that structure or union type, so we can go
2275 back and complete the variable declaration later, if the 2758 back and complete the variable declaration later, if the
2282 && !COMPLETE_TYPE_P (TREE_TYPE (x))) 2765 && !COMPLETE_TYPE_P (TREE_TYPE (x)))
2283 { 2766 {
2284 tree element = TREE_TYPE (x); 2767 tree element = TREE_TYPE (x);
2285 2768
2286 while (TREE_CODE (element) == ARRAY_TYPE) 2769 while (TREE_CODE (element) == ARRAY_TYPE)
2287 element = TREE_TYPE (element); 2770 element = TREE_TYPE (element);
2288 element = TYPE_MAIN_VARIANT (element); 2771 element = TYPE_MAIN_VARIANT (element);
2289 2772
2290 if ((TREE_CODE (element) == RECORD_TYPE 2773 if ((TREE_CODE (element) == RECORD_TYPE
2291 || TREE_CODE (element) == UNION_TYPE) 2774 || TREE_CODE (element) == UNION_TYPE)
2292 && (TREE_CODE (x) != TYPE_DECL 2775 && (TREE_CODE (x) != TYPE_DECL
2293 || TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE) 2776 || TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE)
2294 && !COMPLETE_TYPE_P (element)) 2777 && !COMPLETE_TYPE_P (element))
2295 C_TYPE_INCOMPLETE_VARS (element) 2778 C_TYPE_INCOMPLETE_VARS (element)
2296 = tree_cons (NULL_TREE, x, C_TYPE_INCOMPLETE_VARS (element)); 2779 = tree_cons (NULL_TREE, x, C_TYPE_INCOMPLETE_VARS (element));
2297 } 2780 }
2298 return x; 2781 return x;
2299 } 2782 }
2300 2783
2301 /* Record X as belonging to file scope. 2784 /* Record X as belonging to file scope.
2314 2797
2315 gcc_assert (TREE_CODE (x) == CONST_DECL || !I_SYMBOL_BINDING (name)); 2798 gcc_assert (TREE_CODE (x) == CONST_DECL || !I_SYMBOL_BINDING (name));
2316 2799
2317 if (TREE_PUBLIC (x)) 2800 if (TREE_PUBLIC (x))
2318 { 2801 {
2319 bind (name, x, external_scope, /*invisible=*/true, /*nested=*/false); 2802 bind (name, x, external_scope, /*invisible=*/true, /*nested=*/false,
2803 UNKNOWN_LOCATION);
2320 nested = true; 2804 nested = true;
2321 } 2805 }
2322 if (file_scope) 2806 if (file_scope)
2323 bind (name, x, file_scope, /*invisible=*/false, nested); 2807 bind (name, x, file_scope, /*invisible=*/false, nested, UNKNOWN_LOCATION);
2324 2808
2325 return x; 2809 return x;
2326 } 2810 }
2327 2811
2328 static void 2812 static void
2331 if (warn_implicit_function_declaration) 2815 if (warn_implicit_function_declaration)
2332 { 2816 {
2333 bool warned; 2817 bool warned;
2334 2818
2335 if (flag_isoc99) 2819 if (flag_isoc99)
2336 warned = pedwarn (input_location, OPT_Wimplicit_function_declaration, 2820 warned = pedwarn (input_location, OPT_Wimplicit_function_declaration,
2337 "implicit declaration of function %qE", id); 2821 "implicit declaration of function %qE", id);
2338 else 2822 else
2339 warned = warning (OPT_Wimplicit_function_declaration, 2823 warned = warning (OPT_Wimplicit_function_declaration,
2340 G_("implicit declaration of function %qE"), id); 2824 G_("implicit declaration of function %qE"), id);
2341 if (olddecl && warned) 2825 if (olddecl && warned)
2342 locate_old_decl (olddecl); 2826 locate_old_decl (olddecl);
2343 } 2827 }
2344 } 2828 }
2345 2829
2346 /* Generate an implicit declaration for identifier FUNCTIONID as a 2830 /* Generate an implicit declaration for identifier FUNCTIONID at LOC as a
2347 function of type int (). */ 2831 function of type int (). */
2348 2832
2349 #ifndef noCbC 2833 #ifndef noCbC
2350 tree 2834 tree
2351 implicitly_declare (tree functionid, int fun) 2835 implicitly_declare (location_t loc, tree functionid, int fun)
2352 #else 2836 #else
2353 tree 2837 tree
2354 implicitly_declare (tree functionid) 2838 implicitly_declare (location_t loc, tree functionid)
2355 #endif 2839 #endif
2356 { 2840 {
2357 struct c_binding *b; 2841 struct c_binding *b;
2358 tree decl = 0; 2842 tree decl = 0;
2359 tree asmspec_tree; 2843 tree asmspec_tree;
2360 2844
2361 for (b = I_SYMBOL_BINDING (functionid); b; b = b->shadowed) 2845 for (b = I_SYMBOL_BINDING (functionid); b; b = b->shadowed)
2362 { 2846 {
2363 if (B_IN_SCOPE (b, external_scope)) 2847 if (B_IN_SCOPE (b, external_scope))
2364 { 2848 {
2365 decl = b->decl; 2849 decl = b->decl;
2366 break; 2850 break;
2367 } 2851 }
2368 } 2852 }
2369 2853
2370 if (decl) 2854 if (decl)
2371 { 2855 {
2372 if (decl == error_mark_node) 2856 if (decl == error_mark_node)
2373 return decl; 2857 return decl;
2374 2858
2375 /* FIXME: Objective-C has weird not-really-builtin functions 2859 /* FIXME: Objective-C has weird not-really-builtin functions
2376 which are supposed to be visible automatically. They wind up 2860 which are supposed to be visible automatically. They wind up
2377 in the external scope because they're pushed before the file 2861 in the external scope because they're pushed before the file
2378 scope gets created. Catch this here and rebind them into the 2862 scope gets created. Catch this here and rebind them into the
2379 file scope. */ 2863 file scope. */
2380 if (!DECL_BUILT_IN (decl) && DECL_IS_BUILTIN (decl)) 2864 if (!DECL_BUILT_IN (decl) && DECL_IS_BUILTIN (decl))
2381 { 2865 {
2382 bind (functionid, decl, file_scope, 2866 bind (functionid, decl, file_scope,
2383 /*invisible=*/false, /*nested=*/true); 2867 /*invisible=*/false, /*nested=*/true,
2384 return decl; 2868 DECL_SOURCE_LOCATION (decl));
2385 } 2869 return decl;
2870 }
2386 else 2871 else
2387 { 2872 {
2388 tree newtype = default_function_type; 2873 tree newtype = default_function_type;
2389 if (b->type) 2874 if (b->u.type)
2390 TREE_TYPE (decl) = b->type; 2875 TREE_TYPE (decl) = b->u.type;
2391 /* Implicit declaration of a function already declared 2876 /* Implicit declaration of a function already declared
2392 (somehow) in a different scope, or as a built-in. 2877 (somehow) in a different scope, or as a built-in.
2393 If this is the first time this has happened, warn; 2878 If this is the first time this has happened, warn;
2394 then recycle the old declaration but with the new type. */ 2879 then recycle the old declaration but with the new type. */
2395 if (!C_DECL_IMPLICIT (decl)) 2880 if (!C_DECL_IMPLICIT (decl))
2396 { 2881 {
2397 implicit_decl_warning (functionid, decl); 2882 implicit_decl_warning (functionid, decl);
2398 C_DECL_IMPLICIT (decl) = 1; 2883 C_DECL_IMPLICIT (decl) = 1;
2399 } 2884 }
2400 if (DECL_BUILT_IN (decl)) 2885 if (DECL_BUILT_IN (decl))
2401 { 2886 {
2402 newtype = build_type_attribute_variant (newtype, 2887 newtype = build_type_attribute_variant (newtype,
2403 TYPE_ATTRIBUTES 2888 TYPE_ATTRIBUTES
2404 (TREE_TYPE (decl))); 2889 (TREE_TYPE (decl)));
2405 if (!comptypes (newtype, TREE_TYPE (decl))) 2890 if (!comptypes (newtype, TREE_TYPE (decl)))
2406 { 2891 {
2407 warning (0, "incompatible implicit declaration of built-in" 2892 warning_at (loc, 0, "incompatible implicit declaration of "
2408 " function %qD", decl); 2893 "built-in function %qD", decl);
2409 newtype = TREE_TYPE (decl); 2894 newtype = TREE_TYPE (decl);
2410 } 2895 }
2411 } 2896 }
2412 else 2897 else
2413 { 2898 {
2414 if (!comptypes (newtype, TREE_TYPE (decl))) 2899 if (!comptypes (newtype, TREE_TYPE (decl)))
2415 { 2900 {
2416 error ("incompatible implicit declaration of function %qD", 2901 error_at (loc, "incompatible implicit declaration of function %qD", decl);
2417 decl); 2902 locate_old_decl (decl);
2418 locate_old_decl (decl); 2903 }
2419 } 2904 }
2420 } 2905 b->u.type = TREE_TYPE (decl);
2421 b->type = TREE_TYPE (decl); 2906 TREE_TYPE (decl) = newtype;
2422 TREE_TYPE (decl) = newtype; 2907 bind (functionid, decl, current_scope,
2423 bind (functionid, decl, current_scope, 2908 /*invisible=*/false, /*nested=*/true,
2424 /*invisible=*/false, /*nested=*/true); 2909 DECL_SOURCE_LOCATION (decl));
2425 return decl; 2910 return decl;
2426 } 2911 }
2427 } 2912 }
2428 2913
2429 /* Not seen before. */ 2914 /* Not seen before. */
2430 #ifndef noCbC 2915 #ifndef noCbC
2431 decl = build_decl (FUNCTION_DECL, functionid, 2916 decl = build_decl (loc, FUNCTION_DECL, functionid,
2432 fun==RID_CbC_CODE?build_function_type (void_type_node, NULL_TREE):default_function_type); 2917 fun==RID_CbC_CODE?build_function_type (void_type_node, NULL_TREE):default_function_type);
2433 #else 2918 #else
2434 decl = build_decl (FUNCTION_DECL, functionid, default_function_type); 2919 decl = build_decl (loc, FUNCTION_DECL, functionid, default_function_type);
2435 #endif 2920 #endif
2436 DECL_EXTERNAL (decl) = 1; 2921 DECL_EXTERNAL (decl) = 1;
2437 TREE_PUBLIC (decl) = 1; 2922 TREE_PUBLIC (decl) = 1;
2438 C_DECL_IMPLICIT (decl) = 1; 2923 C_DECL_IMPLICIT (decl) = 1;
2439 implicit_decl_warning (functionid, 0); 2924 implicit_decl_warning (functionid, 0);
2462 ID, including a reference to a builtin outside of function-call 2947 ID, including a reference to a builtin outside of function-call
2463 context. Establish a binding of the identifier to error_mark_node 2948 context. Establish a binding of the identifier to error_mark_node
2464 in an appropriate scope, which will suppress further errors for the 2949 in an appropriate scope, which will suppress further errors for the
2465 same identifier. The error message should be given location LOC. */ 2950 same identifier. The error message should be given location LOC. */
2466 void 2951 void
2467 undeclared_variable (tree id, location_t loc) 2952 undeclared_variable (location_t loc, tree id)
2468 { 2953 {
2469 static bool already = false; 2954 static bool already = false;
2470 struct c_scope *scope; 2955 struct c_scope *scope;
2471 2956
2472 if (current_function_decl == 0) 2957 if (current_function_decl == 0)
2473 { 2958 {
2474 error ("%H%qE undeclared here (not in a function)", &loc, id); 2959 error_at (loc, "%qE undeclared here (not in a function)", id);
2475 scope = current_scope; 2960 scope = current_scope;
2476 } 2961 }
2477 else 2962 else
2478 { 2963 {
2479 error ("%H%qE undeclared (first use in this function)", &loc, id); 2964 error_at (loc, "%qE undeclared (first use in this function)", id);
2480 2965
2481 if (!already) 2966 if (!already)
2482 { 2967 {
2483 error ("%H(Each undeclared identifier is reported only once", &loc); 2968 error_at (loc, "(Each undeclared identifier is reported only once");
2484 error ("%Hfor each function it appears in.)", &loc); 2969 error_at (loc, "for each function it appears in.)");
2485 already = true; 2970 already = true;
2486 } 2971 }
2487 2972
2488 /* If we are parsing old-style parameter decls, current_function_decl 2973 /* If we are parsing old-style parameter decls, current_function_decl
2489 will be nonnull but current_function_scope will be null. */ 2974 will be nonnull but current_function_scope will be null. */
2490 scope = current_function_scope ? current_function_scope : current_scope; 2975 scope = current_function_scope ? current_function_scope : current_scope;
2491 } 2976 }
2492 bind (id, error_mark_node, scope, /*invisible=*/false, /*nested=*/false); 2977 bind (id, error_mark_node, scope, /*invisible=*/false, /*nested=*/false,
2978 UNKNOWN_LOCATION);
2493 } 2979 }
2494 2980
2495 /* Subroutine of lookup_label, declare_label, define_label: construct a 2981 /* Subroutine of lookup_label, declare_label, define_label: construct a
2496 LABEL_DECL with all the proper frills. */ 2982 LABEL_DECL with all the proper frills. Also create a struct
2983 c_label_vars initialized for the current scope. */
2497 2984
2498 static tree 2985 static tree
2499 make_label (tree name, location_t location) 2986 make_label (location_t location, tree name, bool defining,
2500 { 2987 struct c_label_vars **p_label_vars)
2501 tree label = build_decl (LABEL_DECL, name, void_type_node); 2988 {
2989 tree label = build_decl (location, LABEL_DECL, name, void_type_node);
2990 struct c_label_vars *label_vars;
2502 2991
2503 DECL_CONTEXT (label) = current_function_decl; 2992 DECL_CONTEXT (label) = current_function_decl;
2504 DECL_MODE (label) = VOIDmode; 2993 DECL_MODE (label) = VOIDmode;
2505 DECL_SOURCE_LOCATION (label) = location; 2994
2995 label_vars = GGC_NEW (struct c_label_vars);
2996 label_vars->shadowed = NULL;
2997 set_spot_bindings (&label_vars->label_bindings, defining);
2998 label_vars->decls_in_scope = make_tree_vector ();
2999 label_vars->gotos = VEC_alloc (c_goto_bindings_p, gc, 0);
3000 *p_label_vars = label_vars;
2506 3001
2507 return label; 3002 return label;
2508 } 3003 }
2509 3004
2510 /* Get the LABEL_DECL corresponding to identifier NAME as a label. 3005 /* Get the LABEL_DECL corresponding to identifier NAME as a label.
2514 3009
2515 tree 3010 tree
2516 lookup_label (tree name) 3011 lookup_label (tree name)
2517 { 3012 {
2518 tree label; 3013 tree label;
3014 struct c_label_vars *label_vars;
2519 3015
2520 if (current_function_decl == 0) 3016 if (current_function_decl == 0)
2521 { 3017 {
2522 error ("label %qE referenced outside of any function", name); 3018 error ("label %qE referenced outside of any function", name);
2523 return 0; 3019 return 0;
2526 /* Use a label already defined or ref'd with this name, but not if 3022 /* Use a label already defined or ref'd with this name, but not if
2527 it is inherited from a containing function and wasn't declared 3023 it is inherited from a containing function and wasn't declared
2528 using __label__. */ 3024 using __label__. */
2529 label = I_LABEL_DECL (name); 3025 label = I_LABEL_DECL (name);
2530 if (label && (DECL_CONTEXT (label) == current_function_decl 3026 if (label && (DECL_CONTEXT (label) == current_function_decl
2531 || C_DECLARED_LABEL_FLAG (label))) 3027 || C_DECLARED_LABEL_FLAG (label)))
2532 { 3028 {
2533 /* If the label has only been declared, update its apparent 3029 /* If the label has only been declared, update its apparent
2534 location to point here, for better diagnostics if it 3030 location to point here, for better diagnostics if it
2535 turns out not to have been defined. */ 3031 turns out not to have been defined. */
2536 if (!TREE_USED (label)) 3032 if (DECL_INITIAL (label) == NULL_TREE)
2537 DECL_SOURCE_LOCATION (label) = input_location; 3033 DECL_SOURCE_LOCATION (label) = input_location;
2538 return label; 3034 return label;
2539 } 3035 }
2540 3036
2541 /* No label binding for that identifier; make one. */ 3037 /* No label binding for that identifier; make one. */
2542 label = make_label (name, input_location); 3038 label = make_label (input_location, name, false, &label_vars);
2543 3039
2544 /* Ordinary labels go in the current function scope. */ 3040 /* Ordinary labels go in the current function scope. */
2545 bind (name, label, current_function_scope, 3041 bind_label (name, label, current_function_scope, label_vars);
2546 /*invisible=*/false, /*nested=*/false); 3042
3043 return label;
3044 }
3045
3046 /* Issue a warning about DECL for a goto statement at GOTO_LOC going
3047 to LABEL. */
3048
3049 static void
3050 warn_about_goto (location_t goto_loc, tree label, tree decl)
3051 {
3052 if (variably_modified_type_p (TREE_TYPE (decl), NULL_TREE))
3053 error_at (goto_loc,
3054 "jump into scope of identifier with variably modified type");
3055 else
3056 warning_at (goto_loc, OPT_Wjump_misses_init,
3057 "jump skips variable initialization");
3058 inform (DECL_SOURCE_LOCATION (label), "label %qD defined here", label);
3059 inform (DECL_SOURCE_LOCATION (decl), "%qD declared here", decl);
3060 }
3061
3062 /* Look up a label because of a goto statement. This is like
3063 lookup_label, but also issues any appropriate warnings. */
3064
3065 tree
3066 lookup_label_for_goto (location_t loc, tree name)
3067 {
3068 tree label;
3069 struct c_label_vars *label_vars;
3070 unsigned int ix;
3071 tree decl;
3072
3073 label = lookup_label (name);
3074 if (label == NULL_TREE)
3075 return NULL_TREE;
3076
3077 /* If we are jumping to a different function, we can't issue any
3078 useful warnings. */
3079 if (DECL_CONTEXT (label) != current_function_decl)
3080 {
3081 gcc_assert (C_DECLARED_LABEL_FLAG (label));
3082 return label;
3083 }
3084
3085 label_vars = I_LABEL_BINDING (name)->u.label;
3086
3087 /* If the label has not yet been defined, then push this goto on a
3088 list for possible later warnings. */
3089 if (label_vars->label_bindings.scope == NULL)
3090 {
3091 struct c_goto_bindings *g;
3092
3093 g = GGC_NEW (struct c_goto_bindings);
3094 g->loc = loc;
3095 set_spot_bindings (&g->goto_bindings, true);
3096 VEC_safe_push (c_goto_bindings_p, gc, label_vars->gotos, g);
3097 return label;
3098 }
3099
3100 /* If there are any decls in label_vars->decls_in_scope, then this
3101 goto has missed the declaration of the decl. This happens for a
3102 case like
3103 int i = 1;
3104 lab:
3105 ...
3106 goto lab;
3107 Issue a warning or error. */
3108 for (ix = 0; VEC_iterate (tree, label_vars->decls_in_scope, ix, decl); ++ix)
3109 warn_about_goto (loc, label, decl);
3110
3111 if (label_vars->label_bindings.left_stmt_expr)
3112 {
3113 error_at (loc, "jump into statement expression");
3114 inform (DECL_SOURCE_LOCATION (label), "label %qD defined here", label);
3115 }
3116
2547 return label; 3117 return label;
2548 } 3118 }
2549 3119
2550 /* Make a label named NAME in the current function, shadowing silently 3120 /* Make a label named NAME in the current function, shadowing silently
2551 any that may be inherited from containing functions or containing 3121 any that may be inherited from containing functions or containing
2554 tree 3124 tree
2555 declare_label (tree name) 3125 declare_label (tree name)
2556 { 3126 {
2557 struct c_binding *b = I_LABEL_BINDING (name); 3127 struct c_binding *b = I_LABEL_BINDING (name);
2558 tree label; 3128 tree label;
3129 struct c_label_vars *label_vars;
2559 3130
2560 /* Check to make sure that the label hasn't already been declared 3131 /* Check to make sure that the label hasn't already been declared
2561 at this scope */ 3132 at this scope */
2562 if (b && B_IN_CURRENT_SCOPE (b)) 3133 if (b && B_IN_CURRENT_SCOPE (b))
2563 { 3134 {
2566 3137
2567 /* Just use the previous declaration. */ 3138 /* Just use the previous declaration. */
2568 return b->decl; 3139 return b->decl;
2569 } 3140 }
2570 3141
2571 label = make_label (name, input_location); 3142 label = make_label (input_location, name, false, &label_vars);
2572 C_DECLARED_LABEL_FLAG (label) = 1; 3143 C_DECLARED_LABEL_FLAG (label) = 1;
2573 3144
2574 /* Declared labels go in the current scope. */ 3145 /* Declared labels go in the current scope. */
2575 bind (name, label, current_scope, 3146 bind_label (name, label, current_scope, label_vars);
2576 /*invisible=*/false, /*nested=*/false); 3147
2577 return label; 3148 return label;
3149 }
3150
3151 /* When we define a label, issue any appropriate warnings if there are
3152 any gotos earlier in the function which jump to this label. */
3153
3154 static void
3155 check_earlier_gotos (tree label, struct c_label_vars* label_vars)
3156 {
3157 unsigned int ix;
3158 struct c_goto_bindings *g;
3159
3160 for (ix = 0;
3161 VEC_iterate (c_goto_bindings_p, label_vars->gotos, ix, g);
3162 ++ix)
3163 {
3164 struct c_binding *b;
3165 struct c_scope *scope;
3166
3167 /* We have a goto to this label. The goto is going forward. In
3168 g->scope, the goto is going to skip any binding which was
3169 defined after g->bindings_in_scope. */
3170 for (b = g->goto_bindings.scope->bindings;
3171 b != g->goto_bindings.bindings_in_scope;
3172 b = b->prev)
3173 {
3174 if (decl_jump_unsafe (b->decl))
3175 warn_about_goto (g->loc, label, b->decl);
3176 }
3177
3178 /* We also need to warn about decls defined in any scopes
3179 between the scope of the label and the scope of the goto. */
3180 for (scope = label_vars->label_bindings.scope;
3181 scope != g->goto_bindings.scope;
3182 scope = scope->outer)
3183 {
3184 gcc_assert (scope != NULL);
3185 if (scope == label_vars->label_bindings.scope)
3186 b = label_vars->label_bindings.bindings_in_scope;
3187 else
3188 b = scope->bindings;
3189 for (; b != NULL; b = b->prev)
3190 {
3191 if (decl_jump_unsafe (b->decl))
3192 warn_about_goto (g->loc, label, b->decl);
3193 }
3194 }
3195
3196 if (g->goto_bindings.stmt_exprs > 0)
3197 {
3198 error_at (g->loc, "jump into statement expression");
3199 inform (DECL_SOURCE_LOCATION (label), "label %qD defined here",
3200 label);
3201 }
3202 }
3203
3204 /* Now that the label is defined, we will issue warnings about
3205 subsequent gotos to this label when we see them. */
3206 VEC_truncate (c_goto_bindings_p, label_vars->gotos, 0);
3207 label_vars->gotos = NULL;
2578 } 3208 }
2579 3209
2580 /* Define a label, specifying the location in the source file. 3210 /* Define a label, specifying the location in the source file.
2581 Return the LABEL_DECL node for the label, if the definition is valid. 3211 Return the LABEL_DECL node for the label, if the definition is valid.
2582 Otherwise return 0. */ 3212 Otherwise return 0. */
2587 /* Find any preexisting label with this name. It is an error 3217 /* Find any preexisting label with this name. It is an error
2588 if that label has already been defined in this function, or 3218 if that label has already been defined in this function, or
2589 if there is a containing function with a declared label with 3219 if there is a containing function with a declared label with
2590 the same name. */ 3220 the same name. */
2591 tree label = I_LABEL_DECL (name); 3221 tree label = I_LABEL_DECL (name);
2592 struct c_label_list *nlist_se, *nlist_vm;
2593 3222
2594 if (label 3223 if (label
2595 && ((DECL_CONTEXT (label) == current_function_decl 3224 && ((DECL_CONTEXT (label) == current_function_decl
2596 && DECL_INITIAL (label) != 0) 3225 && DECL_INITIAL (label) != 0)
2597 || (DECL_CONTEXT (label) != current_function_decl 3226 || (DECL_CONTEXT (label) != current_function_decl
2598 && C_DECLARED_LABEL_FLAG (label)))) 3227 && C_DECLARED_LABEL_FLAG (label))))
2599 { 3228 {
2600 error ("%Hduplicate label %qD", &location, label); 3229 error_at (location, "duplicate label %qD", label);
2601 locate_old_decl (label); 3230 locate_old_decl (label);
2602 return 0; 3231 return 0;
2603 } 3232 }
2604 else if (label && DECL_CONTEXT (label) == current_function_decl) 3233 else if (label && DECL_CONTEXT (label) == current_function_decl)
2605 { 3234 {
3235 struct c_label_vars *label_vars = I_LABEL_BINDING (name)->u.label;
3236
2606 /* The label has been used or declared already in this function, 3237 /* The label has been used or declared already in this function,
2607 but not defined. Update its location to point to this 3238 but not defined. Update its location to point to this
2608 definition. */ 3239 definition. */
2609 if (C_DECL_UNDEFINABLE_STMT_EXPR (label))
2610 error ("%Jjump into statement expression", label);
2611 if (C_DECL_UNDEFINABLE_VM (label))
2612 error ("%Jjump into scope of identifier with variably modified type",
2613 label);
2614 DECL_SOURCE_LOCATION (label) = location; 3240 DECL_SOURCE_LOCATION (label) = location;
3241 set_spot_bindings (&label_vars->label_bindings, true);
3242
3243 /* Issue warnings as required about any goto statements from
3244 earlier in the function. */
3245 check_earlier_gotos (label, label_vars);
2615 } 3246 }
2616 else 3247 else
2617 { 3248 {
3249 struct c_label_vars *label_vars;
3250
2618 /* No label binding for that identifier; make one. */ 3251 /* No label binding for that identifier; make one. */
2619 label = make_label (name, location); 3252 label = make_label (location, name, true, &label_vars);
2620 3253
2621 /* Ordinary labels go in the current function scope. */ 3254 /* Ordinary labels go in the current function scope. */
2622 bind (name, label, current_function_scope, 3255 bind_label (name, label, current_function_scope, label_vars);
2623 /*invisible=*/false, /*nested=*/false);
2624 } 3256 }
2625 3257
2626 if (!in_system_header && lookup_name (name)) 3258 if (!in_system_header && lookup_name (name))
2627 warning (OPT_Wtraditional, "%Htraditional C lacks a separate namespace " 3259 warning_at (location, OPT_Wtraditional,
2628 "for labels, identifier %qE conflicts", &location, name); 3260 "traditional C lacks a separate namespace "
2629 3261 "for labels, identifier %qE conflicts", name);
2630 nlist_se = XOBNEW (&parser_obstack, struct c_label_list);
2631 nlist_se->next = label_context_stack_se->labels_def;
2632 nlist_se->label = label;
2633 label_context_stack_se->labels_def = nlist_se;
2634
2635 nlist_vm = XOBNEW (&parser_obstack, struct c_label_list);
2636 nlist_vm->next = label_context_stack_vm->labels_def;
2637 nlist_vm->label = label;
2638 label_context_stack_vm->labels_def = nlist_vm;
2639 3262
2640 /* Mark label as having been defined. */ 3263 /* Mark label as having been defined. */
2641 DECL_INITIAL (label) = error_mark_node; 3264 DECL_INITIAL (label) = error_mark_node;
2642 return label; 3265 return label;
3266 }
3267
3268 /* Get the bindings for a new switch statement. This is used to issue
3269 warnings as appropriate for jumps from the switch to case or
3270 default labels. */
3271
3272 struct c_spot_bindings *
3273 c_get_switch_bindings (void)
3274 {
3275 struct c_spot_bindings *switch_bindings;
3276
3277 switch_bindings = XNEW (struct c_spot_bindings);
3278 set_spot_bindings (switch_bindings, true);
3279 return switch_bindings;
3280 }
3281
3282 void
3283 c_release_switch_bindings (struct c_spot_bindings *bindings)
3284 {
3285 gcc_assert (bindings->stmt_exprs == 0 && !bindings->left_stmt_expr);
3286 XDELETE (bindings);
3287 }
3288
3289 /* This is called at the point of a case or default label to issue
3290 warnings about decls as needed. It returns true if it found an
3291 error, not just a warning. */
3292
3293 bool
3294 c_check_switch_jump_warnings (struct c_spot_bindings *switch_bindings,
3295 location_t switch_loc, location_t case_loc)
3296 {
3297 bool saw_error;
3298 struct c_scope *scope;
3299
3300 saw_error = false;
3301 for (scope = current_scope;
3302 scope != switch_bindings->scope;
3303 scope = scope->outer)
3304 {
3305 struct c_binding *b;
3306
3307 gcc_assert (scope != NULL);
3308 for (b = scope->bindings; b != NULL; b = b->prev)
3309 {
3310 if (decl_jump_unsafe (b->decl))
3311 {
3312 if (variably_modified_type_p (TREE_TYPE (b->decl), NULL_TREE))
3313 {
3314 saw_error = true;
3315 error_at (case_loc,
3316 ("switch jumps into scope of identifier with "
3317 "variably modified type"));
3318 }
3319 else
3320 warning_at (case_loc, OPT_Wjump_misses_init,
3321 "switch jumps over variable initialization");
3322 inform (switch_loc, "switch starts here");
3323 inform (DECL_SOURCE_LOCATION (b->decl), "%qD declared here",
3324 b->decl);
3325 }
3326 }
3327 }
3328
3329 if (switch_bindings->stmt_exprs > 0)
3330 {
3331 saw_error = true;
3332 error_at (case_loc, "switch jumps into statement expression");
3333 inform (switch_loc, "switch starts here");
3334 }
3335
3336 return saw_error;
2643 } 3337 }
2644 3338
2645 /* Given NAME, an IDENTIFIER_NODE, 3339 /* Given NAME, an IDENTIFIER_NODE,
2646 return the structure (or union or enum) definition for that name. 3340 return the structure (or union or enum) definition for that name.
2647 If THISLEVEL_ONLY is nonzero, searches only the current_scope. 3341 If THISLEVEL_ONLY is nonzero, searches only the current_scope.
2648 CODE says which kind of type the caller wants; 3342 CODE says which kind of type the caller wants;
2649 it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE. 3343 it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE.
3344 If PLOC is not NULL and this returns non-null, it sets *PLOC to the
3345 location where the tag was defined.
2650 If the wrong kind of type is found, an error is reported. */ 3346 If the wrong kind of type is found, an error is reported. */
2651 3347
2652 static tree 3348 static tree
2653 lookup_tag (enum tree_code code, tree name, int thislevel_only) 3349 lookup_tag (enum tree_code code, tree name, int thislevel_only,
3350 location_t *ploc)
2654 { 3351 {
2655 struct c_binding *b = I_TAG_BINDING (name); 3352 struct c_binding *b = I_TAG_BINDING (name);
2656 int thislevel = 0; 3353 int thislevel = 0;
2657 3354
2658 if (!b || !b->decl) 3355 if (!b || !b->decl)
2661 /* We only care about whether it's in this level if 3358 /* We only care about whether it's in this level if
2662 thislevel_only was set or it might be a type clash. */ 3359 thislevel_only was set or it might be a type clash. */
2663 if (thislevel_only || TREE_CODE (b->decl) != code) 3360 if (thislevel_only || TREE_CODE (b->decl) != code)
2664 { 3361 {
2665 /* For our purposes, a tag in the external scope is the same as 3362 /* For our purposes, a tag in the external scope is the same as
2666 a tag in the file scope. (Primarily relevant to Objective-C 3363 a tag in the file scope. (Primarily relevant to Objective-C
2667 and its builtin structure tags, which get pushed before the 3364 and its builtin structure tags, which get pushed before the
2668 file scope is created.) */ 3365 file scope is created.) */
2669 if (B_IN_CURRENT_SCOPE (b) 3366 if (B_IN_CURRENT_SCOPE (b)
2670 || (current_scope == file_scope && B_IN_EXTERNAL_SCOPE (b))) 3367 || (current_scope == file_scope && B_IN_EXTERNAL_SCOPE (b)))
2671 thislevel = 1; 3368 thislevel = 1;
2672 } 3369 }
2673 3370
2674 if (thislevel_only && !thislevel) 3371 if (thislevel_only && !thislevel)
2675 return 0; 3372 return 0;
2676 3373
2679 /* Definition isn't the kind we were looking for. */ 3376 /* Definition isn't the kind we were looking for. */
2680 pending_invalid_xref = name; 3377 pending_invalid_xref = name;
2681 pending_invalid_xref_location = input_location; 3378 pending_invalid_xref_location = input_location;
2682 3379
2683 /* If in the same binding level as a declaration as a tag 3380 /* If in the same binding level as a declaration as a tag
2684 of a different type, this must not be allowed to 3381 of a different type, this must not be allowed to
2685 shadow that tag, so give the error immediately. 3382 shadow that tag, so give the error immediately.
2686 (For example, "struct foo; union foo;" is invalid.) */ 3383 (For example, "struct foo; union foo;" is invalid.) */
2687 if (thislevel) 3384 if (thislevel)
2688 pending_xref_error (); 3385 pending_xref_error ();
2689 } 3386 }
3387
3388 if (ploc != NULL)
3389 *ploc = b->locus;
3390
2690 return b->decl; 3391 return b->decl;
2691 } 3392 }
2692 3393
2693 /* Print an error message now 3394 /* Print an error message now
2694 for a recent invalid struct, union or enum cross reference. 3395 for a recent invalid struct, union or enum cross reference.
2697 3398
2698 void 3399 void
2699 pending_xref_error (void) 3400 pending_xref_error (void)
2700 { 3401 {
2701 if (pending_invalid_xref != 0) 3402 if (pending_invalid_xref != 0)
2702 error ("%H%qE defined as wrong kind of tag", 3403 error_at (pending_invalid_xref_location, "%qE defined as wrong kind of tag",
2703 &pending_invalid_xref_location, pending_invalid_xref); 3404 pending_invalid_xref);
2704 pending_invalid_xref = 0; 3405 pending_invalid_xref = 0;
2705 } 3406 }
2706 3407
2707 3408
2708 /* Look up NAME in the current scope and its superiors 3409 /* Look up NAME in the current scope and its superiors
2766 truthvalue_type_node = integer_type_node; 3467 truthvalue_type_node = integer_type_node;
2767 truthvalue_true_node = integer_one_node; 3468 truthvalue_true_node = integer_one_node;
2768 truthvalue_false_node = integer_zero_node; 3469 truthvalue_false_node = integer_zero_node;
2769 3470
2770 /* Even in C99, which has a real boolean type. */ 3471 /* Even in C99, which has a real boolean type. */
2771 pushdecl (build_decl (TYPE_DECL, get_identifier ("_Bool"), 3472 pushdecl (build_decl (UNKNOWN_LOCATION, TYPE_DECL, get_identifier ("_Bool"),
2772 boolean_type_node)); 3473 boolean_type_node));
2773 3474
2774 input_location = save_loc; 3475 input_location = save_loc;
2775 3476
2776 pedantic_lvalues = true; 3477 pedantic_lvalues = true;
2777 3478
2778 make_fname_decl = c_make_fname_decl; 3479 make_fname_decl = c_make_fname_decl;
2779 start_fname_decls (); 3480 start_fname_decls ();
2780 } 3481 }
2781 3482
2782 /* Create the VAR_DECL for __FUNCTION__ etc. ID is the name to give the 3483 /* Create the VAR_DECL at LOC for __FUNCTION__ etc. ID is the name to
2783 decl, NAME is the initialization string and TYPE_DEP indicates whether 3484 give the decl, NAME is the initialization string and TYPE_DEP
2784 NAME depended on the type of the function. As we don't yet implement 3485 indicates whether NAME depended on the type of the function. As we
2785 delayed emission of static data, we mark the decl as emitted 3486 don't yet implement delayed emission of static data, we mark the
2786 so it is not placed in the output. Anything using it must therefore pull 3487 decl as emitted so it is not placed in the output. Anything using
2787 out the STRING_CST initializer directly. FIXME. */ 3488 it must therefore pull out the STRING_CST initializer directly.
3489 FIXME. */
2788 3490
2789 static tree 3491 static tree
2790 c_make_fname_decl (tree id, int type_dep) 3492 c_make_fname_decl (location_t loc, tree id, int type_dep)
2791 { 3493 {
2792 const char *name = fname_as_string (type_dep); 3494 const char *name = fname_as_string (type_dep);
2793 tree decl, type, init; 3495 tree decl, type, init;
2794 size_t length = strlen (name); 3496 size_t length = strlen (name);
2795 3497
2796 type = build_array_type (char_type_node, 3498 type = build_array_type (char_type_node,
2797 build_index_type (size_int (length))); 3499 build_index_type (size_int (length)));
2798 type = c_build_qualified_type (type, TYPE_QUAL_CONST); 3500 type = c_build_qualified_type (type, TYPE_QUAL_CONST);
2799 3501
2800 decl = build_decl (VAR_DECL, id, type); 3502 decl = build_decl (loc, VAR_DECL, id, type);
2801 3503
2802 TREE_STATIC (decl) = 1; 3504 TREE_STATIC (decl) = 1;
2803 TREE_READONLY (decl) = 1; 3505 TREE_READONLY (decl) = 1;
2804 DECL_ARTIFICIAL (decl) = 1; 3506 DECL_ARTIFICIAL (decl) = 1;
2805 3507
2810 3512
2811 TREE_USED (decl) = 1; 3513 TREE_USED (decl) = 1;
2812 3514
2813 if (current_function_decl 3515 if (current_function_decl
2814 /* For invalid programs like this: 3516 /* For invalid programs like this:
2815 3517
2816 void foo() 3518 void foo()
2817 const char* p = __FUNCTION__; 3519 const char* p = __FUNCTION__;
2818 3520
2819 the __FUNCTION__ is believed to appear in K&R style function 3521 the __FUNCTION__ is believed to appear in K&R style function
2820 parameter declarator. In that case we still don't have 3522 parameter declarator. In that case we still don't have
2821 function_scope. */ 3523 function_scope. */
2822 && (!errorcount || current_function_scope)) 3524 && (!errorcount || current_function_scope))
2823 { 3525 {
2824 DECL_CONTEXT (decl) = current_function_decl; 3526 DECL_CONTEXT (decl) = current_function_decl;
2825 bind (id, decl, current_function_scope, 3527 bind (id, decl, current_function_scope,
2826 /*invisible=*/false, /*nested=*/false); 3528 /*invisible=*/false, /*nested=*/false, UNKNOWN_LOCATION);
2827 } 3529 }
2828 3530
2829 finish_decl (decl, init, NULL_TREE); 3531 finish_decl (decl, loc, init, NULL_TREE, NULL_TREE);
2830 3532
2831 return decl; 3533 return decl;
2832 } 3534 }
2833 3535
2834 tree 3536 tree
2841 C_DECL_BUILTIN_PROTOTYPE (decl) = (TYPE_ARG_TYPES (type) != 0); 3543 C_DECL_BUILTIN_PROTOTYPE (decl) = (TYPE_ARG_TYPES (type) != 0);
2842 3544
2843 /* Should never be called on a symbol with a preexisting meaning. */ 3545 /* Should never be called on a symbol with a preexisting meaning. */
2844 gcc_assert (!I_SYMBOL_BINDING (id)); 3546 gcc_assert (!I_SYMBOL_BINDING (id));
2845 3547
2846 bind (id, decl, external_scope, /*invisible=*/true, /*nested=*/false); 3548 bind (id, decl, external_scope, /*invisible=*/true, /*nested=*/false,
3549 UNKNOWN_LOCATION);
2847 3550
2848 /* Builtins in the implementation namespace are made visible without 3551 /* Builtins in the implementation namespace are made visible without
2849 needing to be explicitly declared. See push_file_scope. */ 3552 needing to be explicitly declared. See push_file_scope. */
2850 if (name[0] == '_' && (name[1] == '_' || ISUPPER (name[1]))) 3553 if (name[0] == '_' && (name[1] == '_' || ISUPPER (name[1])))
2851 { 3554 {
2866 C_DECL_BUILTIN_PROTOTYPE (decl) = (TYPE_ARG_TYPES (type) != 0); 3569 C_DECL_BUILTIN_PROTOTYPE (decl) = (TYPE_ARG_TYPES (type) != 0);
2867 3570
2868 /* Should never be called on a symbol with a preexisting meaning. */ 3571 /* Should never be called on a symbol with a preexisting meaning. */
2869 gcc_assert (!I_SYMBOL_BINDING (id)); 3572 gcc_assert (!I_SYMBOL_BINDING (id));
2870 3573
2871 bind (id, decl, external_scope, /*invisible=*/false, /*nested=*/false); 3574 bind (id, decl, external_scope, /*invisible=*/false, /*nested=*/false,
3575 UNKNOWN_LOCATION);
2872 3576
2873 /* Builtins in the implementation namespace are made visible without 3577 /* Builtins in the implementation namespace are made visible without
2874 needing to be explicitly declared. See push_file_scope. */ 3578 needing to be explicitly declared. See push_file_scope. */
2875 if (name[0] == '_' && (name[1] == '_' || ISUPPER (name[1]))) 3579 if (name[0] == '_' && (name[1] == '_' || ISUPPER (name[1])))
2876 { 3580 {
2906 { 3610 {
2907 tree value = declspecs->type; 3611 tree value = declspecs->type;
2908 enum tree_code code = TREE_CODE (value); 3612 enum tree_code code = TREE_CODE (value);
2909 3613
2910 if (code == RECORD_TYPE || code == UNION_TYPE || code == ENUMERAL_TYPE) 3614 if (code == RECORD_TYPE || code == UNION_TYPE || code == ENUMERAL_TYPE)
2911 /* Used to test also that TYPE_SIZE (value) != 0. 3615 /* Used to test also that TYPE_SIZE (value) != 0.
2912 That caused warning for `struct foo;' at top level in the file. */ 3616 That caused warning for `struct foo;' at top level in the file. */
2913 { 3617 {
2914 tree name = TYPE_NAME (value); 3618 tree name = TYPE_NAME (value);
2915 tree t; 3619 tree t;
2916 3620
2917 found_tag = true; 3621 found_tag = true;
2918 3622
2919 if (name == 0) 3623 if (declspecs->restrict_p)
2920 { 3624 {
2921 if (warned != 1 && code != ENUMERAL_TYPE) 3625 error ("invalid use of %<restrict%>");
2922 /* Empty unnamed enum OK */ 3626 warned = 1;
2923 { 3627 }
2924 pedwarn (input_location, 0, 3628
2925 "unnamed struct/union that defines no instances"); 3629 if (name == 0)
2926 warned = 1; 3630 {
2927 } 3631 if (warned != 1 && code != ENUMERAL_TYPE)
2928 } 3632 /* Empty unnamed enum OK */
2929 else if (!declspecs->tag_defined_p 3633 {
2930 && declspecs->storage_class != csc_none) 3634 pedwarn (input_location, 0,
2931 { 3635 "unnamed struct/union that defines no instances");
2932 if (warned != 1) 3636 warned = 1;
2933 pedwarn (input_location, 0, 3637 }
2934 "empty declaration with storage class specifier " 3638 }
2935 "does not redeclare tag"); 3639 else if (!declspecs->tag_defined_p
2936 warned = 1; 3640 && declspecs->storage_class != csc_none)
2937 pending_xref_error (); 3641 {
2938 } 3642 if (warned != 1)
2939 else if (!declspecs->tag_defined_p 3643 pedwarn (input_location, 0,
2940 && (declspecs->const_p 3644 "empty declaration with storage class specifier "
2941 || declspecs->volatile_p 3645 "does not redeclare tag");
2942 || declspecs->restrict_p)) 3646 warned = 1;
2943 { 3647 pending_xref_error ();
2944 if (warned != 1) 3648 }
2945 pedwarn (input_location, 0, 3649 else if (!declspecs->tag_defined_p
2946 "empty declaration with type qualifier " 3650 && (declspecs->const_p
2947 "does not redeclare tag"); 3651 || declspecs->volatile_p
2948 warned = 1; 3652 || declspecs->restrict_p
2949 pending_xref_error (); 3653 || declspecs->address_space))
2950 } 3654 {
2951 else 3655 if (warned != 1)
2952 { 3656 pedwarn (input_location, 0,
2953 pending_invalid_xref = 0; 3657 "empty declaration with type qualifier "
2954 t = lookup_tag (code, name, 1); 3658 "does not redeclare tag");
2955 3659 warned = 1;
2956 if (t == 0) 3660 pending_xref_error ();
2957 { 3661 }
2958 t = make_node (code);
2959 pushtag (name, t);
2960 }
2961 }
2962 }
2963 else 3662 else
2964 { 3663 {
2965 if (warned != 1 && !in_system_header) 3664 pending_invalid_xref = 0;
2966 { 3665 t = lookup_tag (code, name, 1, NULL);
2967 pedwarn (input_location, 0, 3666
2968 "useless type name in empty declaration"); 3667 if (t == 0)
2969 warned = 1; 3668 {
2970 } 3669 t = make_node (code);
2971 } 3670 pushtag (input_location, name, t);
3671 }
3672 }
3673 }
3674 else
3675 {
3676 if (warned != 1 && !in_system_header)
3677 {
3678 pedwarn (input_location, 0,
3679 "useless type name in empty declaration");
3680 warned = 1;
3681 }
3682 }
2972 } 3683 }
2973 else if (warned != 1 && !in_system_header && declspecs->typedef_p) 3684 else if (warned != 1 && !in_system_header && declspecs->typedef_p)
2974 { 3685 {
2975 pedwarn (input_location, 0, "useless type name in empty declaration"); 3686 pedwarn (input_location, 0, "useless type name in empty declaration");
2976 warned = 1; 3687 warned = 1;
3007 warning (0, "useless %<__thread%> in empty declaration"); 3718 warning (0, "useless %<__thread%> in empty declaration");
3008 warned = 2; 3719 warned = 2;
3009 } 3720 }
3010 3721
3011 if (!warned && !in_system_header && (declspecs->const_p 3722 if (!warned && !in_system_header && (declspecs->const_p
3012 || declspecs->volatile_p 3723 || declspecs->volatile_p
3013 || declspecs->restrict_p)) 3724 || declspecs->restrict_p
3725 || declspecs->address_space))
3014 { 3726 {
3015 warning (0, "useless type qualifier in empty declaration"); 3727 warning (0, "useless type qualifier in empty declaration");
3016 warned = 2; 3728 warned = 2;
3017 } 3729 }
3018 3730
3019 if (warned != 1) 3731 if (warned != 1)
3020 { 3732 {
3021 if (!found_tag) 3733 if (!found_tag)
3022 pedwarn (input_location, 0, "empty declaration"); 3734 pedwarn (input_location, 0, "empty declaration");
3023 } 3735 }
3024 } 3736 }
3025 3737
3026 3738
3027 /* Return the qualifiers from SPECS as a bitwise OR of TYPE_QUAL_* 3739 /* Return the qualifiers from SPECS as a bitwise OR of TYPE_QUAL_*
3030 3742
3031 int 3743 int
3032 quals_from_declspecs (const struct c_declspecs *specs) 3744 quals_from_declspecs (const struct c_declspecs *specs)
3033 { 3745 {
3034 int quals = ((specs->const_p ? TYPE_QUAL_CONST : 0) 3746 int quals = ((specs->const_p ? TYPE_QUAL_CONST : 0)
3035 | (specs->volatile_p ? TYPE_QUAL_VOLATILE : 0) 3747 | (specs->volatile_p ? TYPE_QUAL_VOLATILE : 0)
3036 | (specs->restrict_p ? TYPE_QUAL_RESTRICT : 0)); 3748 | (specs->restrict_p ? TYPE_QUAL_RESTRICT : 0)
3749 | (ENCODE_QUAL_ADDR_SPACE (specs->address_space)));
3037 gcc_assert (!specs->type 3750 gcc_assert (!specs->type
3038 && !specs->decl_attr 3751 && !specs->decl_attr
3039 && specs->typespec_word == cts_none 3752 && specs->typespec_word == cts_none
3040 && specs->storage_class == csc_none 3753 && specs->storage_class == csc_none
3041 && !specs->typedef_p 3754 && !specs->typedef_p
3042 && !specs->explicit_signed_p 3755 && !specs->explicit_signed_p
3043 && !specs->deprecated_p 3756 && !specs->deprecated_p
3044 && !specs->long_p 3757 && !specs->long_p
3045 && !specs->long_long_p 3758 && !specs->long_long_p
3046 && !specs->short_p 3759 && !specs->short_p
3047 && !specs->signed_p 3760 && !specs->signed_p
3048 && !specs->unsigned_p 3761 && !specs->unsigned_p
3049 && !specs->complex_p 3762 && !specs->complex_p
3050 && !specs->inline_p 3763 && !specs->inline_p
3051 && !specs->thread_p); 3764 && !specs->thread_p);
3052 return quals; 3765 return quals;
3053 } 3766 }
3054 3767
3055 /* Construct an array declarator. EXPR is the expression inside [], 3768 /* Construct an array declarator. LOC is the location of the
3056 or NULL_TREE. QUALS are the type qualifiers inside the [] (to be 3769 beginning of the array (usually the opening brace). EXPR is the
3057 applied to the pointer to which a parameter array is converted). 3770 expression inside [], or NULL_TREE. QUALS are the type qualifiers
3058 STATIC_P is true if "static" is inside the [], false otherwise. 3771 inside the [] (to be applied to the pointer to which a parameter
3059 VLA_UNSPEC_P is true if the array is [*], a VLA of unspecified 3772 array is converted). STATIC_P is true if "static" is inside the
3060 length which is nevertheless a complete type, false otherwise. The 3773 [], false otherwise. VLA_UNSPEC_P is true if the array is [*], a
3061 field for the contained declarator is left to be filled in by 3774 VLA of unspecified length which is nevertheless a complete type,
3062 set_array_declarator_inner. */ 3775 false otherwise. The field for the contained declarator is left to
3776 be filled in by set_array_declarator_inner. */
3063 3777
3064 struct c_declarator * 3778 struct c_declarator *
3065 build_array_declarator (tree expr, struct c_declspecs *quals, bool static_p, 3779 build_array_declarator (location_t loc,
3066 bool vla_unspec_p) 3780 tree expr, struct c_declspecs *quals, bool static_p,
3781 bool vla_unspec_p)
3067 { 3782 {
3068 struct c_declarator *declarator = XOBNEW (&parser_obstack, 3783 struct c_declarator *declarator = XOBNEW (&parser_obstack,
3069 struct c_declarator); 3784 struct c_declarator);
3785 declarator->id_loc = loc;
3070 declarator->kind = cdk_array; 3786 declarator->kind = cdk_array;
3071 declarator->declarator = 0; 3787 declarator->declarator = 0;
3072 declarator->u.array.dimen = expr; 3788 declarator->u.array.dimen = expr;
3073 if (quals) 3789 if (quals)
3074 { 3790 {
3083 declarator->u.array.static_p = static_p; 3799 declarator->u.array.static_p = static_p;
3084 declarator->u.array.vla_unspec_p = vla_unspec_p; 3800 declarator->u.array.vla_unspec_p = vla_unspec_p;
3085 if (!flag_isoc99) 3801 if (!flag_isoc99)
3086 { 3802 {
3087 if (static_p || quals != NULL) 3803 if (static_p || quals != NULL)
3088 pedwarn (input_location, OPT_pedantic, 3804 pedwarn (loc, OPT_pedantic,
3089 "ISO C90 does not support %<static%> or type " 3805 "ISO C90 does not support %<static%> or type "
3090 "qualifiers in parameter array declarators"); 3806 "qualifiers in parameter array declarators");
3091 if (vla_unspec_p) 3807 if (vla_unspec_p)
3092 pedwarn (input_location, OPT_pedantic, 3808 pedwarn (loc, OPT_pedantic,
3093 "ISO C90 does not support %<[*]%> array declarators"); 3809 "ISO C90 does not support %<[*]%> array declarators");
3094 } 3810 }
3095 if (vla_unspec_p) 3811 if (vla_unspec_p)
3096 { 3812 {
3097 if (!current_scope->parm_flag) 3813 if (!current_scope->parm_flag)
3098 { 3814 {
3099 /* C99 6.7.5.2p4 */ 3815 /* C99 6.7.5.2p4 */
3100 error ("%<[*]%> not allowed in other than function prototype scope"); 3816 error_at (loc, "%<[*]%> not allowed in other than "
3101 declarator->u.array.vla_unspec_p = false; 3817 "function prototype scope");
3102 return NULL; 3818 declarator->u.array.vla_unspec_p = false;
3103 } 3819 return NULL;
3820 }
3104 current_scope->had_vla_unspec = true; 3821 current_scope->had_vla_unspec = true;
3105 } 3822 }
3106 return declarator; 3823 return declarator;
3107 } 3824 }
3108 3825
3110 declarator, as constructed by build_array_declarator; INNER is what 3827 declarator, as constructed by build_array_declarator; INNER is what
3111 appears on the left of the []. */ 3828 appears on the left of the []. */
3112 3829
3113 struct c_declarator * 3830 struct c_declarator *
3114 set_array_declarator_inner (struct c_declarator *decl, 3831 set_array_declarator_inner (struct c_declarator *decl,
3115 struct c_declarator *inner) 3832 struct c_declarator *inner)
3116 { 3833 {
3117 decl->declarator = inner; 3834 decl->declarator = inner;
3118 return decl; 3835 return decl;
3119 } 3836 }
3120 3837
3137 && TYPE_DOMAIN (type) != NULL_TREE 3854 && TYPE_DOMAIN (type) != NULL_TREE
3138 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL_TREE) 3855 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL_TREE)
3139 { 3856 {
3140 complete_array_type (&type, elt, false); 3857 complete_array_type (&type, elt, false);
3141 DECL_SIZE (decl) 3858 DECL_SIZE (decl)
3142 = size_binop (PLUS_EXPR, DECL_SIZE (decl), TYPE_SIZE (type)); 3859 = size_binop (PLUS_EXPR, DECL_SIZE (decl), TYPE_SIZE (type));
3143 DECL_SIZE_UNIT (decl) 3860 DECL_SIZE_UNIT (decl)
3144 = size_binop (PLUS_EXPR, DECL_SIZE_UNIT (decl), TYPE_SIZE_UNIT (type)); 3861 = size_binop (PLUS_EXPR, DECL_SIZE_UNIT (decl), TYPE_SIZE_UNIT (type));
3145 } 3862 }
3146 } 3863 }
3147 3864
3148 /* Decode a "typename", such as "int **", returning a ..._TYPE node. */ 3865 /* Decode a "typename", such as "int **", returning a ..._TYPE node.
3866 Set *EXPR, if EXPR not NULL, to any expression to be evaluated
3867 before the type name, and set *EXPR_CONST_OPERANDS, if
3868 EXPR_CONST_OPERANDS not NULL, to indicate whether the type name may
3869 appear in a constant expression. */
3149 3870
3150 tree 3871 tree
3151 groktypename (struct c_type_name *type_name) 3872 groktypename (struct c_type_name *type_name, tree *expr,
3873 bool *expr_const_operands)
3152 { 3874 {
3153 tree type; 3875 tree type;
3154 tree attrs = type_name->specs->attrs; 3876 tree attrs = type_name->specs->attrs;
3155 3877
3156 type_name->specs->attrs = NULL_TREE; 3878 type_name->specs->attrs = NULL_TREE;
3157 3879
3158 type = grokdeclarator (type_name->declarator, type_name->specs, TYPENAME, 3880 type = grokdeclarator (type_name->declarator, type_name->specs, TYPENAME,
3159 false, NULL, &attrs, DEPRECATED_NORMAL); 3881 false, NULL, &attrs, expr, expr_const_operands,
3882 DEPRECATED_NORMAL);
3160 3883
3161 /* Apply attributes. */ 3884 /* Apply attributes. */
3162 decl_attributes (&type, attrs, 0); 3885 decl_attributes (&type, attrs, 0);
3163 3886
3164 return type; 3887 return type;
3179 do go through here. Structure field declarations are done by 3902 do go through here. Structure field declarations are done by
3180 grokfield and not through here. */ 3903 grokfield and not through here. */
3181 3904
3182 tree 3905 tree
3183 start_decl (struct c_declarator *declarator, struct c_declspecs *declspecs, 3906 start_decl (struct c_declarator *declarator, struct c_declspecs *declspecs,
3184 bool initialized, tree attributes) 3907 bool initialized, tree attributes)
3185 { 3908 {
3186 tree decl; 3909 tree decl;
3187 tree tem; 3910 tree tem;
3911 tree expr = NULL_TREE;
3188 enum deprecated_states deprecated_state = DEPRECATED_NORMAL; 3912 enum deprecated_states deprecated_state = DEPRECATED_NORMAL;
3189 3913
3190 /* An object declared as __attribute__((deprecated)) suppresses 3914 /* An object declared as __attribute__((deprecated)) suppresses
3191 warnings of uses of other deprecated items. */ 3915 warnings of uses of other deprecated items. */
3192 if (lookup_attribute ("deprecated", attributes)) 3916 if (lookup_attribute ("deprecated", attributes))
3193 deprecated_state = DEPRECATED_SUPPRESS; 3917 deprecated_state = DEPRECATED_SUPPRESS;
3194 3918
3195 decl = grokdeclarator (declarator, declspecs, 3919 decl = grokdeclarator (declarator, declspecs,
3196 NORMAL, initialized, NULL, &attributes, 3920 NORMAL, initialized, NULL, &attributes, &expr, NULL,
3197 deprecated_state); 3921 deprecated_state);
3198 if (!decl) 3922 if (!decl)
3199 return 0; 3923 return 0;
3924
3925 if (expr)
3926 add_stmt (expr);
3200 3927
3201 if (TREE_CODE (decl) != FUNCTION_DECL && MAIN_NAME_P (DECL_NAME (decl))) 3928 if (TREE_CODE (decl) != FUNCTION_DECL && MAIN_NAME_P (DECL_NAME (decl)))
3202 warning (OPT_Wmain, "%q+D is usually a function", decl); 3929 warning (OPT_Wmain, "%q+D is usually a function", decl);
3203 3930
3204 if (initialized) 3931 if (initialized)
3206 If not, set INITIALIZED to zero, which will indirectly 3933 If not, set INITIALIZED to zero, which will indirectly
3207 tell 'finish_decl' to ignore the initializer once it is parsed. */ 3934 tell 'finish_decl' to ignore the initializer once it is parsed. */
3208 switch (TREE_CODE (decl)) 3935 switch (TREE_CODE (decl))
3209 { 3936 {
3210 case TYPE_DECL: 3937 case TYPE_DECL:
3211 error ("typedef %qD is initialized (use __typeof__ instead)", decl); 3938 error ("typedef %qD is initialized (use __typeof__ instead)", decl);
3212 initialized = 0; 3939 initialized = 0;
3213 break; 3940 break;
3214 3941
3215 case FUNCTION_DECL: 3942 case FUNCTION_DECL:
3216 error ("function %qD is initialized like a variable", decl); 3943 error ("function %qD is initialized like a variable", decl);
3217 initialized = 0; 3944 initialized = 0;
3218 break; 3945 break;
3219 3946
3220 case PARM_DECL: 3947 case PARM_DECL:
3221 /* DECL_INITIAL in a PARM_DECL is really DECL_ARG_TYPE. */ 3948 /* DECL_INITIAL in a PARM_DECL is really DECL_ARG_TYPE. */
3222 error ("parameter %qD is initialized", decl); 3949 error ("parameter %qD is initialized", decl);
3223 initialized = 0; 3950 initialized = 0;
3224 break; 3951 break;
3225 3952
3226 default: 3953 default:
3227 /* Don't allow initializations for incomplete types except for 3954 /* Don't allow initializations for incomplete types except for
3228 arrays which might be completed by the initialization. */ 3955 arrays which might be completed by the initialization. */
3229 3956
3230 /* This can happen if the array size is an undefined macro. 3957 /* This can happen if the array size is an undefined macro.
3231 We already gave a warning, so we don't need another one. */ 3958 We already gave a warning, so we don't need another one. */
3232 if (TREE_TYPE (decl) == error_mark_node) 3959 if (TREE_TYPE (decl) == error_mark_node)
3233 initialized = 0; 3960 initialized = 0;
3234 else if (COMPLETE_TYPE_P (TREE_TYPE (decl))) 3961 else if (COMPLETE_TYPE_P (TREE_TYPE (decl)))
3235 { 3962 {
3236 /* A complete type is ok if size is fixed. */ 3963 /* A complete type is ok if size is fixed. */
3237 3964
3238 if (TREE_CODE (TYPE_SIZE (TREE_TYPE (decl))) != INTEGER_CST 3965 if (TREE_CODE (TYPE_SIZE (TREE_TYPE (decl))) != INTEGER_CST
3239 || C_DECL_VARIABLE_SIZE (decl)) 3966 || C_DECL_VARIABLE_SIZE (decl))
3240 { 3967 {
3241 error ("variable-sized object may not be initialized"); 3968 error ("variable-sized object may not be initialized");
3242 initialized = 0; 3969 initialized = 0;
3243 } 3970 }
3244 }
3245 else if (TREE_CODE (TREE_TYPE (decl)) != ARRAY_TYPE)
3246 {
3247 error ("variable %qD has initializer but incomplete type", decl);
3248 initialized = 0;
3249 }
3250 else if (C_DECL_VARIABLE_SIZE (decl))
3251 {
3252 /* Although C99 is unclear about whether incomplete arrays
3253 of VLAs themselves count as VLAs, it does not make
3254 sense to permit them to be initialized given that
3255 ordinary VLAs may not be initialized. */
3256 error ("variable-sized object may not be initialized");
3257 initialized = 0;
3258 }
3259 } 3971 }
3972 else if (TREE_CODE (TREE_TYPE (decl)) != ARRAY_TYPE)
3973 {
3974 error ("variable %qD has initializer but incomplete type", decl);
3975 initialized = 0;
3976 }
3977 else if (C_DECL_VARIABLE_SIZE (decl))
3978 {
3979 /* Although C99 is unclear about whether incomplete arrays
3980 of VLAs themselves count as VLAs, it does not make
3981 sense to permit them to be initialized given that
3982 ordinary VLAs may not be initialized. */
3983 error ("variable-sized object may not be initialized");
3984 initialized = 0;
3985 }
3986 }
3260 3987
3261 if (initialized) 3988 if (initialized)
3262 { 3989 {
3263 if (current_scope == file_scope) 3990 if (current_scope == file_scope)
3264 TREE_STATIC (decl) = 1; 3991 TREE_STATIC (decl) = 1;
3265 3992
3266 /* Tell 'pushdecl' this is an initialized decl 3993 /* Tell 'pushdecl' this is an initialized decl
3267 even though we don't yet have the initializer expression. 3994 even though we don't yet have the initializer expression.
3268 Also tell 'finish_decl' it may store the real initializer. */ 3995 Also tell 'finish_decl' it may store the real initializer. */
3269 DECL_INITIAL (decl) = error_mark_node; 3996 DECL_INITIAL (decl) = error_mark_node;
3270 } 3997 }
3271 3998
3272 /* If this is a function declaration, write a record describing it to the 3999 /* If this is a function declaration, write a record describing it to the
3273 prototypes file (if requested). */ 4000 prototypes file (if requested). */
3299 /* Handle gnu_inline attribute. */ 4026 /* Handle gnu_inline attribute. */
3300 if (declspecs->inline_p 4027 if (declspecs->inline_p
3301 && !flag_gnu89_inline 4028 && !flag_gnu89_inline
3302 && TREE_CODE (decl) == FUNCTION_DECL 4029 && TREE_CODE (decl) == FUNCTION_DECL
3303 && (lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (decl)) 4030 && (lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (decl))
3304 || current_function_decl)) 4031 || current_function_decl))
3305 { 4032 {
3306 if (declspecs->storage_class == csc_auto && current_scope != file_scope) 4033 if (declspecs->storage_class == csc_auto && current_scope != file_scope)
3307 ; 4034 ;
3308 else if (declspecs->storage_class != csc_static) 4035 else if (declspecs->storage_class != csc_static)
3309 DECL_EXTERNAL (decl) = !DECL_EXTERNAL (decl); 4036 DECL_EXTERNAL (decl) = !DECL_EXTERNAL (decl);
3310 } 4037 }
3311 4038
3312 if (TREE_CODE (decl) == FUNCTION_DECL 4039 if (TREE_CODE (decl) == FUNCTION_DECL
3313 && targetm.calls.promote_prototypes (TREE_TYPE (decl))) 4040 && targetm.calls.promote_prototypes (TREE_TYPE (decl)))
3314 { 4041 {
3315 struct c_declarator *ce = declarator; 4042 struct c_declarator *ce = declarator;
3316 4043
3317 if (ce->kind == cdk_pointer) 4044 if (ce->kind == cdk_pointer)
3318 ce = declarator->declarator; 4045 ce = declarator->declarator;
3319 if (ce->kind == cdk_function) 4046 if (ce->kind == cdk_function)
3320 { 4047 {
3321 tree args = ce->u.arg_info->parms; 4048 tree args = ce->u.arg_info->parms;
3322 for (; args; args = TREE_CHAIN (args)) 4049 for (; args; args = TREE_CHAIN (args))
3323 { 4050 {
3324 tree type = TREE_TYPE (args); 4051 tree type = TREE_TYPE (args);
3325 if (type && INTEGRAL_TYPE_P (type) 4052 if (type && INTEGRAL_TYPE_P (type)
3326 && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)) 4053 && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
3327 DECL_ARG_TYPE (args) = integer_type_node; 4054 DECL_ARG_TYPE (args) = integer_type_node;
3328 } 4055 }
3329 } 4056 }
3330 } 4057 }
3331 4058
3332 if (TREE_CODE (decl) == FUNCTION_DECL 4059 if (TREE_CODE (decl) == FUNCTION_DECL
3333 && DECL_DECLARED_INLINE_P (decl) 4060 && DECL_DECLARED_INLINE_P (decl)
3334 && DECL_UNINLINABLE (decl) 4061 && DECL_UNINLINABLE (decl)
3335 && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl))) 4062 && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl)))
3336 warning (OPT_Wattributes, "inline function %q+D given attribute noinline", 4063 warning (OPT_Wattributes, "inline function %q+D given attribute noinline",
3337 decl); 4064 decl);
3338 4065
3339 /* C99 6.7.4p3: An inline definition of a function with external 4066 /* C99 6.7.4p3: An inline definition of a function with external
3340 linkage shall not contain a definition of a modifiable object 4067 linkage shall not contain a definition of a modifiable object
3341 with static storage duration... */ 4068 with static storage duration... */
3342 if (TREE_CODE (decl) == VAR_DECL 4069 if (TREE_CODE (decl) == VAR_DECL
3343 && current_scope != file_scope 4070 && current_scope != file_scope
3344 && TREE_STATIC (decl) 4071 && TREE_STATIC (decl)
3345 && !TREE_READONLY (decl) 4072 && !TREE_READONLY (decl)
3346 && DECL_DECLARED_INLINE_P (current_function_decl) 4073 && DECL_DECLARED_INLINE_P (current_function_decl)
3347 && DECL_EXTERNAL (current_function_decl)) 4074 && DECL_EXTERNAL (current_function_decl))
3348 pedwarn (input_location, 0, 4075 record_inline_static (input_location, current_function_decl,
3349 "%q+D is static but declared in inline function %qD " 4076 decl, csi_modifiable);
3350 "which is not static", decl, current_function_decl);
3351 4077
3352 /* Add this decl to the current scope. 4078 /* Add this decl to the current scope.
3353 TEM may equal DECL or it may be a previous decl of the same name. */ 4079 TEM may equal DECL or it may be a previous decl of the same name. */
3354 tem = pushdecl (decl); 4080 tem = pushdecl (decl);
3355 4081
3360 } 4086 }
3361 4087
3362 return tem; 4088 return tem;
3363 } 4089 }
3364 4090
3365 /* Initialize EH if not initialized yet and exceptions are enabled. */
3366
3367 void
3368 c_maybe_initialize_eh (void)
3369 {
3370 if (!flag_exceptions || c_eh_initialized_p)
3371 return;
3372
3373 c_eh_initialized_p = true;
3374 eh_personality_libfunc
3375 = init_one_libfunc (USING_SJLJ_EXCEPTIONS
3376 ? "__gcc_personality_sj0"
3377 : "__gcc_personality_v0");
3378 default_init_unwind_resume_libfunc ();
3379 using_eh_for_cleanups ();
3380 }
3381
3382 /* Finish processing of a declaration; 4091 /* Finish processing of a declaration;
3383 install its initial value. 4092 install its initial value.
4093 If ORIGTYPE is not NULL_TREE, it is the original type of INIT.
3384 If the length of an array type is not known before, 4094 If the length of an array type is not known before,
3385 it must be determined now, from the initial value, or it is an error. */ 4095 it must be determined now, from the initial value, or it is an error.
4096
4097 INIT_LOC is the location of the initial value. */
3386 4098
3387 void 4099 void
3388 finish_decl (tree decl, tree init, tree asmspec_tree) 4100 finish_decl (tree decl, location_t init_loc, tree init,
4101 tree origtype, tree asmspec_tree)
3389 { 4102 {
3390 tree type; 4103 tree type;
3391 int was_incomplete = (DECL_SIZE (decl) == 0); 4104 bool was_incomplete = (DECL_SIZE (decl) == 0);
3392 const char *asmspec = 0; 4105 const char *asmspec = 0;
3393 4106
3394 /* If a name was specified, get the string. */ 4107 /* If a name was specified, get the string. */
3395 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL) 4108 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
3396 && DECL_FILE_SCOPE_P (decl)) 4109 && DECL_FILE_SCOPE_P (decl))
3412 /* Don't crash if parm is initialized. */ 4125 /* Don't crash if parm is initialized. */
3413 if (TREE_CODE (decl) == PARM_DECL) 4126 if (TREE_CODE (decl) == PARM_DECL)
3414 init = 0; 4127 init = 0;
3415 4128
3416 if (init) 4129 if (init)
3417 store_init_value (decl, init); 4130 store_init_value (init_loc, decl, init, origtype);
3418 4131
3419 if (c_dialect_objc () && (TREE_CODE (decl) == VAR_DECL 4132 if (c_dialect_objc () && (TREE_CODE (decl) == VAR_DECL
3420 || TREE_CODE (decl) == FUNCTION_DECL 4133 || TREE_CODE (decl) == FUNCTION_DECL
3421 || TREE_CODE (decl) == FIELD_DECL)) 4134 || TREE_CODE (decl) == FIELD_DECL))
3422 objc_check_decl (decl); 4135 objc_check_decl (decl);
3423 4136
3424 type = TREE_TYPE (decl); 4137 type = TREE_TYPE (decl);
3425 4138
3426 /* Deduce size of array from initialization, if not already known. */ 4139 /* Deduce size of array from initialization, if not already known. */
3427 if (TREE_CODE (type) == ARRAY_TYPE 4140 if (TREE_CODE (type) == ARRAY_TYPE
3428 && TYPE_DOMAIN (type) == 0 4141 && TYPE_DOMAIN (type) == 0
3429 && TREE_CODE (decl) != TYPE_DECL) 4142 && TREE_CODE (decl) != TYPE_DECL)
3430 { 4143 {
3431 bool do_default 4144 bool do_default
3432 = (TREE_STATIC (decl) 4145 = (TREE_STATIC (decl)
3433 /* Even if pedantic, an external linkage array 4146 /* Even if pedantic, an external linkage array
3434 may have incomplete type at first. */ 4147 may have incomplete type at first. */
3435 ? pedantic && !TREE_PUBLIC (decl) 4148 ? pedantic && !TREE_PUBLIC (decl)
3436 : !DECL_EXTERNAL (decl)); 4149 : !DECL_EXTERNAL (decl));
3437 int failure 4150 int failure
3438 = complete_array_type (&TREE_TYPE (decl), DECL_INITIAL (decl), 4151 = complete_array_type (&TREE_TYPE (decl), DECL_INITIAL (decl),
3439 do_default); 4152 do_default);
3440 4153
3441 /* Get the completed type made by complete_array_type. */ 4154 /* Get the completed type made by complete_array_type. */
3442 type = TREE_TYPE (decl); 4155 type = TREE_TYPE (decl);
3443 4156
3444 switch (failure) 4157 switch (failure)
3445 { 4158 {
3446 case 1: 4159 case 1:
3447 error ("initializer fails to determine size of %q+D", decl); 4160 error ("initializer fails to determine size of %q+D", decl);
3448 break; 4161 break;
3449 4162
3450 case 2: 4163 case 2:
3451 if (do_default) 4164 if (do_default)
3452 error ("array size missing in %q+D", decl); 4165 error ("array size missing in %q+D", decl);
3453 /* If a `static' var's size isn't known, 4166 /* If a `static' var's size isn't known,
3454 make it extern as well as static, so it does not get 4167 make it extern as well as static, so it does not get
3455 allocated. 4168 allocated.
3456 If it is not `static', then do not mark extern; 4169 If it is not `static', then do not mark extern;
3457 finish_incomplete_decl will give it a default size 4170 finish_incomplete_decl will give it a default size
3458 and it will get allocated. */ 4171 and it will get allocated. */
3459 else if (!pedantic && TREE_STATIC (decl) && !TREE_PUBLIC (decl)) 4172 else if (!pedantic && TREE_STATIC (decl) && !TREE_PUBLIC (decl))
3460 DECL_EXTERNAL (decl) = 1; 4173 DECL_EXTERNAL (decl) = 1;
3461 break; 4174 break;
3462 4175
3463 case 3: 4176 case 3:
3464 error ("zero or negative size array %q+D", decl); 4177 error ("zero or negative size array %q+D", decl);
3465 break; 4178 break;
3466 4179
3467 case 0: 4180 case 0:
3468 /* For global variables, update the copy of the type that 4181 /* For global variables, update the copy of the type that
3469 exists in the binding. */ 4182 exists in the binding. */
3470 if (TREE_PUBLIC (decl)) 4183 if (TREE_PUBLIC (decl))
3471 { 4184 {
3472 struct c_binding *b_ext = I_SYMBOL_BINDING (DECL_NAME (decl)); 4185 struct c_binding *b_ext = I_SYMBOL_BINDING (DECL_NAME (decl));
3473 while (b_ext && !B_IN_EXTERNAL_SCOPE (b_ext)) 4186 while (b_ext && !B_IN_EXTERNAL_SCOPE (b_ext))
3474 b_ext = b_ext->shadowed; 4187 b_ext = b_ext->shadowed;
3475 if (b_ext) 4188 if (b_ext)
3476 { 4189 {
3477 if (b_ext->type) 4190 if (b_ext->u.type)
3478 b_ext->type = composite_type (b_ext->type, type); 4191 b_ext->u.type = composite_type (b_ext->u.type, type);
3479 else 4192 else
3480 b_ext->type = type; 4193 b_ext->u.type = type;
3481 } 4194 }
3482 } 4195 }
3483 break; 4196 break;
3484 4197
3485 default: 4198 default:
3486 gcc_unreachable (); 4199 gcc_unreachable ();
3487 } 4200 }
3488 4201
3489 if (DECL_INITIAL (decl)) 4202 if (DECL_INITIAL (decl))
3490 TREE_TYPE (DECL_INITIAL (decl)) = type; 4203 TREE_TYPE (DECL_INITIAL (decl)) = type;
3491 4204
3492 layout_decl (decl, 0); 4205 layout_decl (decl, 0);
3493 } 4206 }
3494 4207
3495 if (TREE_CODE (decl) == VAR_DECL) 4208 if (TREE_CODE (decl) == VAR_DECL)
3496 { 4209 {
3497 if (init && TREE_CODE (init) == CONSTRUCTOR) 4210 if (init && TREE_CODE (init) == CONSTRUCTOR)
3498 add_flexible_array_elts_to_size (decl, init); 4211 add_flexible_array_elts_to_size (decl, init);
3499 4212
3500 if (DECL_SIZE (decl) == 0 && TREE_TYPE (decl) != error_mark_node 4213 if (DECL_SIZE (decl) == 0 && TREE_TYPE (decl) != error_mark_node
3501 && COMPLETE_TYPE_P (TREE_TYPE (decl))) 4214 && COMPLETE_TYPE_P (TREE_TYPE (decl)))
3502 layout_decl (decl, 0); 4215 layout_decl (decl, 0);
3503 4216
3504 if (DECL_SIZE (decl) == 0 4217 if (DECL_SIZE (decl) == 0
3505 /* Don't give an error if we already gave one earlier. */ 4218 /* Don't give an error if we already gave one earlier. */
3506 && TREE_TYPE (decl) != error_mark_node 4219 && TREE_TYPE (decl) != error_mark_node
3507 && (TREE_STATIC (decl) 4220 && (TREE_STATIC (decl)
3508 /* A static variable with an incomplete type 4221 /* A static variable with an incomplete type
3509 is an error if it is initialized. 4222 is an error if it is initialized.
3510 Also if it is not file scope. 4223 Also if it is not file scope.
3511 Otherwise, let it through, but if it is not `extern' 4224 Otherwise, let it through, but if it is not `extern'
3512 then it may cause an error message later. */ 4225 then it may cause an error message later. */
3513 ? (DECL_INITIAL (decl) != 0 4226 ? (DECL_INITIAL (decl) != 0
3514 || !DECL_FILE_SCOPE_P (decl)) 4227 || !DECL_FILE_SCOPE_P (decl))
3515 /* An automatic variable with an incomplete type 4228 /* An automatic variable with an incomplete type
3516 is an error. */ 4229 is an error. */
3517 : !DECL_EXTERNAL (decl))) 4230 : !DECL_EXTERNAL (decl)))
3518 { 4231 {
3519 error ("storage size of %q+D isn%'t known", decl); 4232 error ("storage size of %q+D isn%'t known", decl);
3520 TREE_TYPE (decl) = error_mark_node; 4233 TREE_TYPE (decl) = error_mark_node;
3521 } 4234 }
3522 4235
3523 if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl)) 4236 if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl))
3524 && DECL_SIZE (decl) != 0) 4237 && DECL_SIZE (decl) != 0)
3525 { 4238 {
3526 if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST) 4239 if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST)
3527 constant_expression_warning (DECL_SIZE (decl)); 4240 constant_expression_warning (DECL_SIZE (decl));
3528 else 4241 else
3529 { 4242 {
3530 error ("storage size of %q+D isn%'t constant", decl); 4243 error ("storage size of %q+D isn%'t constant", decl);
3531 TREE_TYPE (decl) = error_mark_node; 4244 TREE_TYPE (decl) = error_mark_node;
3532 } 4245 }
3533 } 4246 }
3534 4247
3535 if (TREE_USED (type)) 4248 if (TREE_USED (type))
3536 TREE_USED (decl) = 1; 4249 TREE_USED (decl) = 1;
3537 } 4250 }
3538 4251
3539 /* If this is a function and an assembler name is specified, reset DECL_RTL 4252 /* If this is a function and an assembler name is specified, reset DECL_RTL
3540 so we can give it its new name. Also, update built_in_decls if it 4253 so we can give it its new name. Also, update built_in_decls if it
3541 was a normal built-in. */ 4254 was a normal built-in. */
3542 if (TREE_CODE (decl) == FUNCTION_DECL && asmspec) 4255 if (TREE_CODE (decl) == FUNCTION_DECL && asmspec)
3543 { 4256 {
3544 if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL) 4257 if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL)
3545 set_builtin_user_assembler_name (decl, asmspec); 4258 set_builtin_user_assembler_name (decl, asmspec);
3546 set_user_assembler_name (decl, asmspec); 4259 set_user_assembler_name (decl, asmspec);
3547 } 4260 }
3548 4261
3549 /* If #pragma weak was used, mark the decl weak now. */ 4262 /* If #pragma weak was used, mark the decl weak now. */
3550 maybe_apply_pragma_weak (decl); 4263 maybe_apply_pragma_weak (decl);
3555 4268
3556 if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL) 4269 if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL)
3557 { 4270 {
3558 /* Determine the ELF visibility. */ 4271 /* Determine the ELF visibility. */
3559 if (TREE_PUBLIC (decl)) 4272 if (TREE_PUBLIC (decl))
3560 c_determine_visibility (decl); 4273 c_determine_visibility (decl);
3561 4274
3562 /* This is a no-op in c-lang.c or something real in objc-act.c. */ 4275 /* This is a no-op in c-lang.c or something real in objc-act.c. */
3563 if (c_dialect_objc ()) 4276 if (c_dialect_objc ())
3564 objc_check_decl (decl); 4277 objc_check_decl (decl);
3565 4278
3566 if (asmspec) 4279 if (asmspec)
3567 { 4280 {
3568 /* If this is not a static variable, issue a warning. 4281 /* If this is not a static variable, issue a warning.
3569 It doesn't make any sense to give an ASMSPEC for an 4282 It doesn't make any sense to give an ASMSPEC for an
3570 ordinary, non-register local variable. Historically, 4283 ordinary, non-register local variable. Historically,
3571 GCC has accepted -- but ignored -- the ASMSPEC in 4284 GCC has accepted -- but ignored -- the ASMSPEC in
3572 this case. */ 4285 this case. */
3573 if (!DECL_FILE_SCOPE_P (decl) 4286 if (!DECL_FILE_SCOPE_P (decl)
3574 && TREE_CODE (decl) == VAR_DECL 4287 && TREE_CODE (decl) == VAR_DECL
3575 && !C_DECL_REGISTER (decl) 4288 && !C_DECL_REGISTER (decl)
3576 && !TREE_STATIC (decl)) 4289 && !TREE_STATIC (decl))
3577 warning (0, "ignoring asm-specifier for non-static local " 4290 warning (0, "ignoring asm-specifier for non-static local "
3578 "variable %q+D", decl); 4291 "variable %q+D", decl);
3579 else 4292 else
3580 set_user_assembler_name (decl, asmspec); 4293 set_user_assembler_name (decl, asmspec);
3581 } 4294 }
3582 4295
3583 if (DECL_FILE_SCOPE_P (decl)) 4296 if (DECL_FILE_SCOPE_P (decl))
3584 { 4297 {
3585 if (DECL_INITIAL (decl) == NULL_TREE 4298 if (DECL_INITIAL (decl) == NULL_TREE
3586 || DECL_INITIAL (decl) == error_mark_node) 4299 || DECL_INITIAL (decl) == error_mark_node)
3587 /* Don't output anything 4300 /* Don't output anything
3588 when a tentative file-scope definition is seen. 4301 when a tentative file-scope definition is seen.
3589 But at end of compilation, do output code for them. */ 4302 But at end of compilation, do output code for them. */
3590 DECL_DEFER_OUTPUT (decl) = 1; 4303 DECL_DEFER_OUTPUT (decl) = 1;
3591 rest_of_decl_compilation (decl, true, 0); 4304 rest_of_decl_compilation (decl, true, 0);
3592 } 4305 }
3593 else 4306 else
3594 { 4307 {
3595 /* In conjunction with an ASMSPEC, the `register' 4308 /* In conjunction with an ASMSPEC, the `register'
3596 keyword indicates that we should place the variable 4309 keyword indicates that we should place the variable
3597 in a particular register. */ 4310 in a particular register. */
3598 if (asmspec && C_DECL_REGISTER (decl)) 4311 if (asmspec && C_DECL_REGISTER (decl))
3599 { 4312 {
3600 DECL_HARD_REGISTER (decl) = 1; 4313 DECL_HARD_REGISTER (decl) = 1;
3601 /* This cannot be done for a structure with volatile 4314 /* This cannot be done for a structure with volatile
3602 fields, on which DECL_REGISTER will have been 4315 fields, on which DECL_REGISTER will have been
3603 reset. */ 4316 reset. */
3604 if (!DECL_REGISTER (decl)) 4317 if (!DECL_REGISTER (decl))
3605 error ("cannot put object with volatile field into register"); 4318 error ("cannot put object with volatile field into register");
3606 } 4319 }
3607 4320
3608 if (TREE_CODE (decl) != FUNCTION_DECL) 4321 if (TREE_CODE (decl) != FUNCTION_DECL)
3609 { 4322 {
3610 /* If we're building a variable sized type, and we might be 4323 /* If we're building a variable sized type, and we might be
3611 reachable other than via the top of the current binding 4324 reachable other than via the top of the current binding
3612 level, then create a new BIND_EXPR so that we deallocate 4325 level, then create a new BIND_EXPR so that we deallocate
3613 the object at the right time. */ 4326 the object at the right time. */
3614 /* Note that DECL_SIZE can be null due to errors. */ 4327 /* Note that DECL_SIZE can be null due to errors. */
3615 if (DECL_SIZE (decl) 4328 if (DECL_SIZE (decl)
3616 && !TREE_CONSTANT (DECL_SIZE (decl)) 4329 && !TREE_CONSTANT (DECL_SIZE (decl))
3617 && STATEMENT_LIST_HAS_LABEL (cur_stmt_list)) 4330 && STATEMENT_LIST_HAS_LABEL (cur_stmt_list))
3618 { 4331 {
3619 tree bind; 4332 tree bind;
3620 bind = build3 (BIND_EXPR, void_type_node, NULL, NULL, NULL); 4333 bind = build3 (BIND_EXPR, void_type_node, NULL, NULL, NULL);
3621 TREE_SIDE_EFFECTS (bind) = 1; 4334 TREE_SIDE_EFFECTS (bind) = 1;
3622 add_stmt (bind); 4335 add_stmt (bind);
3623 BIND_EXPR_BODY (bind) = push_stmt_list (); 4336 BIND_EXPR_BODY (bind) = push_stmt_list ();
3624 } 4337 }
3625 add_stmt (build_stmt (DECL_EXPR, decl)); 4338 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl),
3626 } 4339 DECL_EXPR, decl));
3627 } 4340 }
4341 }
3628 4342
3629 4343
3630 if (!DECL_FILE_SCOPE_P (decl)) 4344 if (!DECL_FILE_SCOPE_P (decl))
3631 { 4345 {
3632 /* Recompute the RTL of a local array now 4346 /* Recompute the RTL of a local array now
3633 if it used to be an incomplete type. */ 4347 if it used to be an incomplete type. */
3634 if (was_incomplete 4348 if (was_incomplete
3635 && !TREE_STATIC (decl) && !DECL_EXTERNAL (decl)) 4349 && !TREE_STATIC (decl) && !DECL_EXTERNAL (decl))
3636 { 4350 {
3637 /* If we used it already as memory, it must stay in memory. */ 4351 /* If we used it already as memory, it must stay in memory. */
3638 TREE_ADDRESSABLE (decl) = TREE_USED (decl); 4352 TREE_ADDRESSABLE (decl) = TREE_USED (decl);
3639 /* If it's still incomplete now, no init will save it. */ 4353 /* If it's still incomplete now, no init will save it. */
3640 if (DECL_SIZE (decl) == 0) 4354 if (DECL_SIZE (decl) == 0)
3641 DECL_INITIAL (decl) = 0; 4355 DECL_INITIAL (decl) = 0;
3642 } 4356 }
3643 } 4357 }
3644 } 4358 }
3645 4359
3646 if (TREE_CODE (decl) == TYPE_DECL) 4360 if (TREE_CODE (decl) == TYPE_DECL)
3647 { 4361 {
3648 if (!DECL_FILE_SCOPE_P (decl) 4362 if (!DECL_FILE_SCOPE_P (decl)
3649 && variably_modified_type_p (TREE_TYPE (decl), NULL_TREE)) 4363 && variably_modified_type_p (TREE_TYPE (decl), NULL_TREE))
3650 add_stmt (build_stmt (DECL_EXPR, decl)); 4364 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl));
3651 4365
3652 rest_of_decl_compilation (decl, DECL_FILE_SCOPE_P (decl), 0); 4366 rest_of_decl_compilation (decl, DECL_FILE_SCOPE_P (decl), 0);
3653 } 4367 }
3654 4368
3655 /* At the end of a declaration, throw away any variable type sizes 4369 /* At the end of a declaration, throw away any variable type sizes
3661 /* Install a cleanup (aka destructor) if one was given. */ 4375 /* Install a cleanup (aka destructor) if one was given. */
3662 if (TREE_CODE (decl) == VAR_DECL && !TREE_STATIC (decl)) 4376 if (TREE_CODE (decl) == VAR_DECL && !TREE_STATIC (decl))
3663 { 4377 {
3664 tree attr = lookup_attribute ("cleanup", DECL_ATTRIBUTES (decl)); 4378 tree attr = lookup_attribute ("cleanup", DECL_ATTRIBUTES (decl));
3665 if (attr) 4379 if (attr)
3666 { 4380 {
3667 tree cleanup_id = TREE_VALUE (TREE_VALUE (attr)); 4381 tree cleanup_id = TREE_VALUE (TREE_VALUE (attr));
3668 tree cleanup_decl = lookup_name (cleanup_id); 4382 tree cleanup_decl = lookup_name (cleanup_id);
3669 tree cleanup; 4383 tree cleanup;
3670 4384 VEC(tree,gc) *vec;
3671 /* Build "cleanup(&decl)" for the destructor. */ 4385
3672 cleanup = build_unary_op (input_location, ADDR_EXPR, decl, 0); 4386 /* Build "cleanup(&decl)" for the destructor. */
3673 cleanup = build_tree_list (NULL_TREE, cleanup); 4387 cleanup = build_unary_op (input_location, ADDR_EXPR, decl, 0);
3674 cleanup = build_function_call (cleanup_decl, cleanup); 4388 vec = VEC_alloc (tree, gc, 1);
3675 4389 VEC_quick_push (tree, vec, cleanup);
3676 /* Don't warn about decl unused; the cleanup uses it. */ 4390 cleanup = build_function_call_vec (DECL_SOURCE_LOCATION (decl),
3677 TREE_USED (decl) = 1; 4391 cleanup_decl, vec, NULL);
3678 TREE_USED (cleanup_decl) = 1; 4392 VEC_free (tree, gc, vec);
3679 4393
3680 /* Initialize EH, if we've been told to do so. */ 4394 /* Don't warn about decl unused; the cleanup uses it. */
3681 c_maybe_initialize_eh (); 4395 TREE_USED (decl) = 1;
3682 4396 TREE_USED (cleanup_decl) = 1;
3683 push_cleanup (decl, cleanup, false); 4397
3684 } 4398 push_cleanup (decl, cleanup, false);
3685 } 4399 }
4400 }
4401
4402 if (warn_cxx_compat
4403 && TREE_CODE (decl) == VAR_DECL
4404 && TREE_READONLY (decl)
4405 && !DECL_EXTERNAL (decl)
4406 && DECL_INITIAL (decl) == NULL_TREE)
4407 warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wc___compat,
4408 "uninitialized const %qD is invalid in C++", decl);
3686 } 4409 }
3687 4410
3688 /* Given a parsed parameter declaration, decode it into a PARM_DECL. */ 4411 /* Given a parsed parameter declaration, decode it into a PARM_DECL. */
3689 4412
3690 tree 4413 tree
3691 grokparm (const struct c_parm *parm) 4414 grokparm (const struct c_parm *parm)
3692 { 4415 {
3693 tree attrs = parm->attrs; 4416 tree attrs = parm->attrs;
3694 tree decl = grokdeclarator (parm->declarator, parm->specs, PARM, false, 4417 tree decl = grokdeclarator (parm->declarator, parm->specs, PARM, false,
3695 NULL, &attrs, DEPRECATED_NORMAL); 4418 NULL, &attrs, NULL, NULL, DEPRECATED_NORMAL);
3696 4419
3697 decl_attributes (&decl, attrs, 0); 4420 decl_attributes (&decl, attrs, 0);
3698 4421
3699 return decl; 4422 return decl;
3700 } 4423 }
3707 { 4430 {
3708 tree attrs = parm->attrs; 4431 tree attrs = parm->attrs;
3709 tree decl; 4432 tree decl;
3710 4433
3711 decl = grokdeclarator (parm->declarator, parm->specs, PARM, false, NULL, 4434 decl = grokdeclarator (parm->declarator, parm->specs, PARM, false, NULL,
3712 &attrs, DEPRECATED_NORMAL); 4435 &attrs, NULL, NULL, DEPRECATED_NORMAL);
3713 decl_attributes (&decl, attrs, 0); 4436 decl_attributes (&decl, attrs, 0);
3714 4437
3715 decl = pushdecl (decl); 4438 decl = pushdecl (decl);
3716 4439
3717 finish_decl (decl, NULL_TREE, NULL_TREE); 4440 finish_decl (decl, input_location, NULL_TREE, NULL_TREE, NULL_TREE);
3718 } 4441 }
3719 4442
3720 /* Mark all the parameter declarations to date as forward decls. 4443 /* Mark all the parameter declarations to date as forward decls.
3721 Also diagnose use of this extension. */ 4444 Also diagnose use of this extension. */
3722 4445
3726 struct c_binding *b; 4449 struct c_binding *b;
3727 4450
3728 if (pedantic && !current_scope->warned_forward_parm_decls) 4451 if (pedantic && !current_scope->warned_forward_parm_decls)
3729 { 4452 {
3730 pedwarn (input_location, OPT_pedantic, 4453 pedwarn (input_location, OPT_pedantic,
3731 "ISO C forbids forward parameter declarations"); 4454 "ISO C forbids forward parameter declarations");
3732 current_scope->warned_forward_parm_decls = true; 4455 current_scope->warned_forward_parm_decls = true;
3733 } 4456 }
3734 4457
3735 for (b = current_scope->bindings; b; b = b->prev) 4458 for (b = current_scope->bindings; b; b = b->prev)
3736 if (TREE_CODE (b->decl) == PARM_DECL) 4459 if (TREE_CODE (b->decl) == PARM_DECL)
3737 TREE_ASM_WRITTEN (b->decl) = 1; 4460 TREE_ASM_WRITTEN (b->decl) = 1;
3738 } 4461 }
3739 4462
3740 /* Build a COMPOUND_LITERAL_EXPR. TYPE is the type given in the compound 4463 /* Build a COMPOUND_LITERAL_EXPR. TYPE is the type given in the compound
3741 literal, which may be an incomplete array type completed by the 4464 literal, which may be an incomplete array type completed by the
3742 initializer; INIT is a CONSTRUCTOR that initializes the compound 4465 initializer; INIT is a CONSTRUCTOR at LOC that initializes the compound
3743 literal. */ 4466 literal. NON_CONST is true if the initializers contain something
4467 that cannot occur in a constant expression. */
3744 4468
3745 tree 4469 tree
3746 build_compound_literal (tree type, tree init) 4470 build_compound_literal (location_t loc, tree type, tree init, bool non_const)
3747 { 4471 {
3748 /* We do not use start_decl here because we have a type, not a declarator; 4472 /* We do not use start_decl here because we have a type, not a declarator;
3749 and do not use finish_decl because the decl should be stored inside 4473 and do not use finish_decl because the decl should be stored inside
3750 the COMPOUND_LITERAL_EXPR rather than added elsewhere as a DECL_EXPR. */ 4474 the COMPOUND_LITERAL_EXPR rather than added elsewhere as a DECL_EXPR. */
3751 tree decl; 4475 tree decl;
3753 tree stmt; 4477 tree stmt;
3754 4478
3755 if (type == error_mark_node) 4479 if (type == error_mark_node)
3756 return error_mark_node; 4480 return error_mark_node;
3757 4481
3758 decl = build_decl (VAR_DECL, NULL_TREE, type); 4482 decl = build_decl (loc, VAR_DECL, NULL_TREE, type);
3759 DECL_EXTERNAL (decl) = 0; 4483 DECL_EXTERNAL (decl) = 0;
3760 TREE_PUBLIC (decl) = 0; 4484 TREE_PUBLIC (decl) = 0;
3761 TREE_STATIC (decl) = (current_scope == file_scope); 4485 TREE_STATIC (decl) = (current_scope == file_scope);
3762 DECL_CONTEXT (decl) = current_function_decl; 4486 DECL_CONTEXT (decl) = current_function_decl;
3763 TREE_USED (decl) = 1; 4487 TREE_USED (decl) = 1;
3764 TREE_TYPE (decl) = type; 4488 TREE_TYPE (decl) = type;
3765 TREE_READONLY (decl) = TYPE_READONLY (type); 4489 TREE_READONLY (decl) = TYPE_READONLY (type);
3766 store_init_value (decl, init); 4490 store_init_value (loc, decl, init, NULL_TREE);
3767 4491
3768 if (TREE_CODE (type) == ARRAY_TYPE && !COMPLETE_TYPE_P (type)) 4492 if (TREE_CODE (type) == ARRAY_TYPE && !COMPLETE_TYPE_P (type))
3769 { 4493 {
3770 int failure = complete_array_type (&TREE_TYPE (decl), 4494 int failure = complete_array_type (&TREE_TYPE (decl),
3771 DECL_INITIAL (decl), true); 4495 DECL_INITIAL (decl), true);
3772 gcc_assert (!failure); 4496 gcc_assert (!failure);
3773 4497
3774 type = TREE_TYPE (decl); 4498 type = TREE_TYPE (decl);
3775 TREE_TYPE (DECL_INITIAL (decl)) = type; 4499 TREE_TYPE (DECL_INITIAL (decl)) = type;
3776 } 4500 }
3777 4501
3778 if (type == error_mark_node || !COMPLETE_TYPE_P (type)) 4502 if (type == error_mark_node || !COMPLETE_TYPE_P (type))
3779 return error_mark_node; 4503 return error_mark_node;
3780 4504
3781 stmt = build_stmt (DECL_EXPR, decl); 4505 stmt = build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl);
3782 complit = build1 (COMPOUND_LITERAL_EXPR, type, stmt); 4506 complit = build1 (COMPOUND_LITERAL_EXPR, type, stmt);
3783 TREE_SIDE_EFFECTS (complit) = 1; 4507 TREE_SIDE_EFFECTS (complit) = 1;
3784 4508
3785 layout_decl (decl, 0); 4509 layout_decl (decl, 0);
3786 4510
3794 DECL_IGNORED_P (decl) = 1; 4518 DECL_IGNORED_P (decl) = 1;
3795 pushdecl (decl); 4519 pushdecl (decl);
3796 rest_of_decl_compilation (decl, 1, 0); 4520 rest_of_decl_compilation (decl, 1, 0);
3797 } 4521 }
3798 4522
4523 if (non_const)
4524 {
4525 complit = build2 (C_MAYBE_CONST_EXPR, type, NULL, complit);
4526 C_MAYBE_CONST_EXPR_NON_CONST (complit) = 1;
4527 }
4528
3799 return complit; 4529 return complit;
4530 }
4531
4532 /* Check the type of a compound literal. Here we just check that it
4533 is valid for C++. */
4534
4535 void
4536 check_compound_literal_type (location_t loc, struct c_type_name *type_name)
4537 {
4538 if (warn_cxx_compat && type_name->specs->tag_defined_p)
4539 warning_at (loc, OPT_Wc___compat,
4540 "defining a type in a compound literal is invalid in C++");
3800 } 4541 }
3801 4542
3802 /* Determine whether TYPE is a structure with a flexible array member, 4543 /* Determine whether TYPE is a structure with a flexible array member,
3803 or a union containing such a structure (possibly recursively). */ 4544 or a union containing such a structure (possibly recursively). */
3804 4545
3809 switch (TREE_CODE (type)) 4550 switch (TREE_CODE (type))
3810 { 4551 {
3811 case RECORD_TYPE: 4552 case RECORD_TYPE:
3812 x = TYPE_FIELDS (type); 4553 x = TYPE_FIELDS (type);
3813 if (x == NULL_TREE) 4554 if (x == NULL_TREE)
3814 return false; 4555 return false;
3815 while (TREE_CHAIN (x) != NULL_TREE) 4556 while (TREE_CHAIN (x) != NULL_TREE)
3816 x = TREE_CHAIN (x); 4557 x = TREE_CHAIN (x);
3817 if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE 4558 if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE
3818 && TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE 4559 && TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE
3819 && TYPE_DOMAIN (TREE_TYPE (x)) != NULL_TREE 4560 && TYPE_DOMAIN (TREE_TYPE (x)) != NULL_TREE
3820 && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (x))) == NULL_TREE) 4561 && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (x))) == NULL_TREE)
3821 return true; 4562 return true;
3822 return false; 4563 return false;
3823 case UNION_TYPE: 4564 case UNION_TYPE:
3824 for (x = TYPE_FIELDS (type); x != NULL_TREE; x = TREE_CHAIN (x)) 4565 for (x = TYPE_FIELDS (type); x != NULL_TREE; x = TREE_CHAIN (x))
3825 { 4566 {
3826 if (flexible_array_type_p (TREE_TYPE (x))) 4567 if (flexible_array_type_p (TREE_TYPE (x)))
3827 return true; 4568 return true;
3828 } 4569 }
3829 return false; 4570 return false;
3830 default: 4571 default:
3831 return false; 4572 return false;
3832 } 4573 }
3833 } 4574 }
3834 4575
3835 /* Performs sanity checks on the TYPE and WIDTH of the bit-field NAME, 4576 /* Performs sanity checks on the TYPE and WIDTH of the bit-field NAME,
3836 replacing with appropriate values if they are invalid. */ 4577 replacing with appropriate values if they are invalid. */
3837 static void 4578 static void
3838 check_bitfield_type_and_width (tree *type, tree *width, const char *orig_name) 4579 check_bitfield_type_and_width (tree *type, tree *width, tree orig_name)
3839 { 4580 {
3840 tree type_mv; 4581 tree type_mv;
3841 unsigned int max_width; 4582 unsigned int max_width;
3842 unsigned HOST_WIDE_INT w; 4583 unsigned HOST_WIDE_INT w;
3843 const char *name = orig_name ? orig_name: _("<anonymous>"); 4584 const char *name = (orig_name
4585 ? identifier_to_locale (IDENTIFIER_POINTER (orig_name))
4586 : _("<anonymous>"));
3844 4587
3845 /* Detect and ignore out of range field width and process valid 4588 /* Detect and ignore out of range field width and process valid
3846 field widths. */ 4589 field widths. */
3847 if (!INTEGRAL_TYPE_P (TREE_TYPE (*width)) 4590 if (!INTEGRAL_TYPE_P (TREE_TYPE (*width)))
3848 || TREE_CODE (*width) != INTEGER_CST)
3849 { 4591 {
3850 error ("bit-field %qs width not an integer constant", name); 4592 error ("bit-field %qs width not an integer constant", name);
3851 *width = integer_one_node; 4593 *width = integer_one_node;
3852 } 4594 }
3853 else 4595 else
3854 { 4596 {
4597 if (TREE_CODE (*width) != INTEGER_CST)
4598 {
4599 *width = c_fully_fold (*width, false, NULL);
4600 if (TREE_CODE (*width) == INTEGER_CST)
4601 pedwarn (input_location, OPT_pedantic,
4602 "bit-field %qs width not an integer constant expression",
4603 name);
4604 }
4605 if (TREE_CODE (*width) != INTEGER_CST)
4606 {
4607 error ("bit-field %qs width not an integer constant", name);
4608 *width = integer_one_node;
4609 }
3855 constant_expression_warning (*width); 4610 constant_expression_warning (*width);
3856 if (tree_int_cst_sgn (*width) < 0) 4611 if (tree_int_cst_sgn (*width) < 0)
3857 { 4612 {
3858 error ("negative width in bit-field %qs", name); 4613 error ("negative width in bit-field %qs", name);
3859 *width = integer_one_node; 4614 *width = integer_one_node;
3860 } 4615 }
3861 else if (integer_zerop (*width) && orig_name) 4616 else if (integer_zerop (*width) && orig_name)
3862 { 4617 {
3863 error ("zero width for bit-field %qs", name); 4618 error ("zero width for bit-field %qs", name);
3864 *width = integer_one_node; 4619 *width = integer_one_node;
3865 } 4620 }
3866 } 4621 }
3867 4622
3868 /* Detect invalid bit-field type. */ 4623 /* Detect invalid bit-field type. */
3869 if (TREE_CODE (*type) != INTEGER_TYPE 4624 if (TREE_CODE (*type) != INTEGER_TYPE
3870 && TREE_CODE (*type) != BOOLEAN_TYPE 4625 && TREE_CODE (*type) != BOOLEAN_TYPE
3878 if (!in_system_header 4633 if (!in_system_header
3879 && type_mv != integer_type_node 4634 && type_mv != integer_type_node
3880 && type_mv != unsigned_type_node 4635 && type_mv != unsigned_type_node
3881 && type_mv != boolean_type_node) 4636 && type_mv != boolean_type_node)
3882 pedwarn (input_location, OPT_pedantic, 4637 pedwarn (input_location, OPT_pedantic,
3883 "type of bit-field %qs is a GCC extension", name); 4638 "type of bit-field %qs is a GCC extension", name);
3884 4639
3885 max_width = TYPE_PRECISION (*type); 4640 max_width = TYPE_PRECISION (*type);
3886 4641
3887 if (0 < compare_tree_int (*width, max_width)) 4642 if (0 < compare_tree_int (*width, max_width))
3888 { 4643 {
3895 4650
3896 if (TREE_CODE (*type) == ENUMERAL_TYPE) 4651 if (TREE_CODE (*type) == ENUMERAL_TYPE)
3897 { 4652 {
3898 struct lang_type *lt = TYPE_LANG_SPECIFIC (*type); 4653 struct lang_type *lt = TYPE_LANG_SPECIFIC (*type);
3899 if (!lt 4654 if (!lt
3900 || w < tree_int_cst_min_precision (lt->enum_min, TYPE_UNSIGNED (*type)) 4655 || w < tree_int_cst_min_precision (lt->enum_min, TYPE_UNSIGNED (*type))
3901 || w < tree_int_cst_min_precision (lt->enum_max, TYPE_UNSIGNED (*type))) 4656 || w < tree_int_cst_min_precision (lt->enum_max, TYPE_UNSIGNED (*type)))
3902 warning (0, "%qs is narrower than values of its type", name); 4657 warning (0, "%qs is narrower than values of its type", name);
3903 } 4658 }
3904 } 4659 }
3905 4660
3906 4661
3907 4662
3908 /* Print warning about variable length array if necessary. */ 4663 /* Print warning about variable length array if necessary. */
3909 4664
3910 static void 4665 static void
3911 warn_variable_length_array (const char *name, tree size) 4666 warn_variable_length_array (tree name, tree size)
3912 { 4667 {
3913 int const_size = TREE_CONSTANT (size); 4668 int const_size = TREE_CONSTANT (size);
3914 4669
3915 if (!flag_isoc99 && pedantic && warn_vla != 0) 4670 if (!flag_isoc99 && pedantic && warn_vla != 0)
3916 { 4671 {
3917 if (const_size) 4672 if (const_size)
3918 { 4673 {
3919 if (name) 4674 if (name)
3920 pedwarn (input_location, OPT_Wvla, "ISO C90 forbids array %qs whose size " 4675 pedwarn (input_location, OPT_Wvla,
3921 "can%'t be evaluated", 4676 "ISO C90 forbids array %qE whose size "
3922 name); 4677 "can%'t be evaluated",
3923 else 4678 name);
3924 pedwarn (input_location, OPT_Wvla, "ISO C90 forbids array whose size "
3925 "can%'t be evaluated");
3926 }
3927 else 4679 else
3928 { 4680 pedwarn (input_location, OPT_Wvla, "ISO C90 forbids array whose size "
3929 if (name) 4681 "can%'t be evaluated");
3930 pedwarn (input_location, OPT_Wvla, "ISO C90 forbids variable length array %qs", 4682 }
3931 name); 4683 else
3932 else 4684 {
3933 pedwarn (input_location, OPT_Wvla, "ISO C90 forbids variable length array"); 4685 if (name)
3934 } 4686 pedwarn (input_location, OPT_Wvla,
4687 "ISO C90 forbids variable length array %qE",
4688 name);
4689 else
4690 pedwarn (input_location, OPT_Wvla, "ISO C90 forbids variable length array");
4691 }
3935 } 4692 }
3936 else if (warn_vla > 0) 4693 else if (warn_vla > 0)
3937 { 4694 {
3938 if (const_size) 4695 if (const_size)
3939 { 4696 {
3940 if (name) 4697 if (name)
3941 warning (OPT_Wvla, 4698 warning (OPT_Wvla,
3942 "the size of array %qs can" 4699 "the size of array %qE can"
3943 "%'t be evaluated", name); 4700 "%'t be evaluated", name);
3944 else
3945 warning (OPT_Wvla,
3946 "the size of array can %'t be evaluated");
3947 }
3948 else 4701 else
3949 { 4702 warning (OPT_Wvla,
3950 if (name) 4703 "the size of array can %'t be evaluated");
3951 warning (OPT_Wvla, 4704 }
3952 "variable length array %qs is used", 4705 else
3953 name); 4706 {
3954 else 4707 if (name)
3955 warning (OPT_Wvla, 4708 warning (OPT_Wvla,
3956 "variable length array is used"); 4709 "variable length array %qE is used",
3957 } 4710 name);
3958 } 4711 else
4712 warning (OPT_Wvla,
4713 "variable length array is used");
4714 }
4715 }
4716 }
4717
4718 /* Given a size SIZE that may not be a constant, return a SAVE_EXPR to
4719 serve as the actual size-expression for a type or decl. This is
4720 like variable_size in stor-layout.c, but we make global_bindings_p
4721 return negative to avoid calls to that function from outside the
4722 front end resulting in errors at file scope, then call this version
4723 instead from front-end code. */
4724
4725 static tree
4726 c_variable_size (tree size)
4727 {
4728 tree save;
4729
4730 if (TREE_CONSTANT (size))
4731 return size;
4732
4733 size = save_expr (size);
4734
4735 save = skip_simple_arithmetic (size);
4736
4737 if (cfun && cfun->dont_save_pending_sizes_p)
4738 return size;
4739
4740 if (!global_bindings_p ())
4741 put_pending_size (save);
4742
4743 return size;
3959 } 4744 }
3960 4745
3961 /* Given declspecs and a declarator, 4746 /* Given declspecs and a declarator,
3962 determine the name and type of the object declared 4747 determine the name and type of the object declared
3963 and construct a ..._DECL node for it. 4748 and construct a ..._DECL node for it.
3980 WIDTH is non-NULL for bit-fields, and is a pointer to an INTEGER_CST node 4765 WIDTH is non-NULL for bit-fields, and is a pointer to an INTEGER_CST node
3981 representing the width of the bit-field. 4766 representing the width of the bit-field.
3982 DECL_ATTRS points to the list of attributes that should be added to this 4767 DECL_ATTRS points to the list of attributes that should be added to this
3983 decl. Any nested attributes that belong on the decl itself will be 4768 decl. Any nested attributes that belong on the decl itself will be
3984 added to this list. 4769 added to this list.
4770 If EXPR is not NULL, any expressions that need to be evaluated as
4771 part of evaluating variably modified types will be stored in *EXPR.
4772 If EXPR_CONST_OPERANDS is not NULL, *EXPR_CONST_OPERANDS will be
4773 set to indicate whether operands in *EXPR can be used in constant
4774 expressions.
3985 DEPRECATED_STATE is a deprecated_states value indicating whether 4775 DEPRECATED_STATE is a deprecated_states value indicating whether
3986 deprecation warnings should be suppressed. 4776 deprecation warnings should be suppressed.
3987 4777
3988 In the TYPENAME case, DECLARATOR is really an absolute declarator. 4778 In the TYPENAME case, DECLARATOR is really an absolute declarator.
3989 It may also be so in the PARM case, for a prototype where the 4779 It may also be so in the PARM case, for a prototype where the
3992 This function is where the complicated C meanings of `static' 4782 This function is where the complicated C meanings of `static'
3993 and `extern' are interpreted. */ 4783 and `extern' are interpreted. */
3994 4784
3995 static tree 4785 static tree
3996 grokdeclarator (const struct c_declarator *declarator, 4786 grokdeclarator (const struct c_declarator *declarator,
3997 struct c_declspecs *declspecs, 4787 struct c_declspecs *declspecs,
3998 enum decl_context decl_context, bool initialized, tree *width, 4788 enum decl_context decl_context, bool initialized, tree *width,
3999 tree *decl_attrs, enum deprecated_states deprecated_state) 4789 tree *decl_attrs, tree *expr, bool *expr_const_operands,
4790 enum deprecated_states deprecated_state)
4000 { 4791 {
4001 tree type = declspecs->type; 4792 tree type = declspecs->type;
4002 bool threadp = declspecs->thread_p; 4793 bool threadp = declspecs->thread_p;
4003 enum c_storage_class storage_class = declspecs->storage_class; 4794 enum c_storage_class storage_class = declspecs->storage_class;
4004 int constp; 4795 int constp;
4005 int restrictp; 4796 int restrictp;
4006 int volatilep; 4797 int volatilep;
4007 int type_quals = TYPE_UNQUALIFIED; 4798 int type_quals = TYPE_UNQUALIFIED;
4008 const char *name, *orig_name; 4799 tree name = NULL_TREE;
4009 bool funcdef_flag = false; 4800 bool funcdef_flag = false;
4010 bool funcdef_syntax = false; 4801 bool funcdef_syntax = false;
4011 int size_varies = 0; 4802 bool size_varies = false;
4012 tree decl_attr = declspecs->decl_attr; 4803 tree decl_attr = declspecs->decl_attr;
4013 int array_ptr_quals = TYPE_UNQUALIFIED; 4804 int array_ptr_quals = TYPE_UNQUALIFIED;
4014 tree array_ptr_attrs = NULL_TREE; 4805 tree array_ptr_attrs = NULL_TREE;
4015 int array_parm_static = 0; 4806 int array_parm_static = 0;
4016 bool array_parm_vla_unspec_p = false; 4807 bool array_parm_vla_unspec_p = false;
4017 tree returned_attrs = NULL_TREE; 4808 tree returned_attrs = NULL_TREE;
4018 bool bitfield = width != NULL; 4809 bool bitfield = width != NULL;
4019 tree element_type; 4810 tree element_type;
4020 struct c_arg_info *arg_info = 0; 4811 struct c_arg_info *arg_info = 0;
4812 addr_space_t as1, as2, address_space;
4813 location_t loc = UNKNOWN_LOCATION;
4814 const char *errmsg;
4815 tree expr_dummy;
4816 bool expr_const_operands_dummy;
4817
4818 if (expr == NULL)
4819 expr = &expr_dummy;
4820 if (expr_const_operands == NULL)
4821 expr_const_operands = &expr_const_operands_dummy;
4822
4823 *expr = declspecs->expr;
4824 *expr_const_operands = declspecs->expr_const_operands;
4021 4825
4022 if (decl_context == FUNCDEF) 4826 if (decl_context == FUNCDEF)
4023 funcdef_flag = true, decl_context = NORMAL; 4827 funcdef_flag = true, decl_context = NORMAL;
4024 4828
4025 /* Look inside a declarator for the name being declared 4829 /* Look inside a declarator for the name being declared
4026 and get it as a string, for an error message. */ 4830 and get it as an IDENTIFIER_NODE, for an error message. */
4027 { 4831 {
4028 const struct c_declarator *decl = declarator; 4832 const struct c_declarator *decl = declarator;
4029 name = 0;
4030 4833
4031 while (decl) 4834 while (decl)
4032 switch (decl->kind) 4835 switch (decl->kind)
4033 { 4836 {
4034 case cdk_function: 4837 case cdk_array:
4035 case cdk_array: 4838 loc = decl->id_loc;
4036 case cdk_pointer: 4839 /* FALL THRU. */
4037 funcdef_syntax = (decl->kind == cdk_function); 4840
4038 decl = decl->declarator; 4841 case cdk_function:
4039 break; 4842 case cdk_pointer:
4040 4843 funcdef_syntax = (decl->kind == cdk_function);
4041 case cdk_attrs: 4844 decl = decl->declarator;
4042 decl = decl->declarator; 4845 break;
4043 break; 4846
4044 4847 case cdk_attrs:
4045 case cdk_id: 4848 decl = decl->declarator;
4046 if (decl->u.id) 4849 break;
4047 name = IDENTIFIER_POINTER (decl->u.id); 4850
4048 decl = 0; 4851 case cdk_id:
4049 break; 4852 loc = decl->id_loc;
4050 4853 if (decl->u.id)
4051 default: 4854 name = decl->u.id;
4052 gcc_unreachable (); 4855 decl = 0;
4053 } 4856 break;
4054 orig_name = name; 4857
4858 default:
4859 gcc_unreachable ();
4860 }
4055 if (name == 0) 4861 if (name == 0)
4056 name = "type name"; 4862 {
4863 gcc_assert (decl_context == PARM
4864 || decl_context == TYPENAME
4865 || (decl_context == FIELD
4866 && declarator->kind == cdk_id));
4867 gcc_assert (!initialized);
4868 }
4057 } 4869 }
4058 4870
4059 /* A function definition's declarator must have the form of 4871 /* A function definition's declarator must have the form of
4060 a function declarator. */ 4872 a function declarator. */
4061 4873
4067 Then store_parm_decls will reject it and not use it as a parm. */ 4879 Then store_parm_decls will reject it and not use it as a parm. */
4068 if (decl_context == NORMAL && !funcdef_flag && current_scope->parm_flag) 4880 if (decl_context == NORMAL && !funcdef_flag && current_scope->parm_flag)
4069 decl_context = PARM; 4881 decl_context = PARM;
4070 4882
4071 if (declspecs->deprecated_p && deprecated_state != DEPRECATED_SUPPRESS) 4883 if (declspecs->deprecated_p && deprecated_state != DEPRECATED_SUPPRESS)
4072 warn_deprecated_use (declspecs->type); 4884 warn_deprecated_use (declspecs->type, declspecs->decl_attr);
4073 4885
4074 if ((decl_context == NORMAL || decl_context == FIELD) 4886 if ((decl_context == NORMAL || decl_context == FIELD)
4075 && current_scope == file_scope 4887 && current_scope == file_scope
4076 && variably_modified_type_p (type, NULL_TREE)) 4888 && variably_modified_type_p (type, NULL_TREE))
4077 { 4889 {
4078 error ("variably modified %qs at file scope", name); 4890 if (name)
4891 error_at (loc, "variably modified %qE at file scope", name);
4892 else
4893 error_at (loc, "variably modified field at file scope");
4079 type = integer_type_node; 4894 type = integer_type_node;
4080 } 4895 }
4081 4896
4082 size_varies = C_TYPE_VARIABLE_SIZE (type); 4897 size_varies = C_TYPE_VARIABLE_SIZE (type) != 0;
4083 4898
4084 /* Diagnose defaulting to "int". */ 4899 /* Diagnose defaulting to "int". */
4085 4900
4086 if (declspecs->default_int_p && !in_system_header) 4901 if (declspecs->default_int_p && !in_system_header)
4087 { 4902 {
4088 /* Issue a warning if this is an ISO C 99 program or if 4903 /* Issue a warning if this is an ISO C 99 program or if
4089 -Wreturn-type and this is a function, or if -Wimplicit; 4904 -Wreturn-type and this is a function, or if -Wimplicit;
4090 prefer the former warning since it is more explicit. */ 4905 prefer the former warning since it is more explicit. */
4091 if ((warn_implicit_int || warn_return_type || flag_isoc99) 4906 if ((warn_implicit_int || warn_return_type || flag_isoc99)
4092 && funcdef_flag) 4907 && funcdef_flag)
4093 warn_about_return_type = 1; 4908 warn_about_return_type = 1;
4094 else 4909 else
4095 pedwarn_c99 (input_location, flag_isoc99 ? 0 : OPT_Wimplicit_int, 4910 {
4096 "type defaults to %<int%> in declaration of %qs", name); 4911 if (name)
4912 pedwarn_c99 (loc, flag_isoc99 ? 0 : OPT_Wimplicit_int,
4913 "type defaults to %<int%> in declaration of %qE",
4914 name);
4915 else
4916 pedwarn_c99 (input_location, flag_isoc99 ? 0 : OPT_Wimplicit_int,
4917 "type defaults to %<int%> in type name");
4918 }
4097 } 4919 }
4098 4920
4099 /* Adjust the type if a bit-field is being declared, 4921 /* Adjust the type if a bit-field is being declared,
4100 -funsigned-bitfields applied and the type is not explicitly 4922 -funsigned-bitfields applied and the type is not explicitly
4101 "signed". */ 4923 "signed". */
4116 seems most appropriate to do so). */ 4938 seems most appropriate to do so). */
4117 element_type = strip_array_types (type); 4939 element_type = strip_array_types (type);
4118 constp = declspecs->const_p + TYPE_READONLY (element_type); 4940 constp = declspecs->const_p + TYPE_READONLY (element_type);
4119 restrictp = declspecs->restrict_p + TYPE_RESTRICT (element_type); 4941 restrictp = declspecs->restrict_p + TYPE_RESTRICT (element_type);
4120 volatilep = declspecs->volatile_p + TYPE_VOLATILE (element_type); 4942 volatilep = declspecs->volatile_p + TYPE_VOLATILE (element_type);
4943 as1 = declspecs->address_space;
4944 as2 = TYPE_ADDR_SPACE (element_type);
4945 address_space = ADDR_SPACE_GENERIC_P (as1)? as2 : as1;
4946
4121 if (pedantic && !flag_isoc99) 4947 if (pedantic && !flag_isoc99)
4122 { 4948 {
4123 if (constp > 1) 4949 if (constp > 1)
4124 pedwarn (input_location, OPT_pedantic, "duplicate %<const%>"); 4950 pedwarn (loc, OPT_pedantic, "duplicate %<const%>");
4125 if (restrictp > 1) 4951 if (restrictp > 1)
4126 pedwarn (input_location, OPT_pedantic, "duplicate %<restrict%>"); 4952 pedwarn (loc, OPT_pedantic, "duplicate %<restrict%>");
4127 if (volatilep > 1) 4953 if (volatilep > 1)
4128 pedwarn (input_location, OPT_pedantic, "duplicate %<volatile%>"); 4954 pedwarn (loc, OPT_pedantic, "duplicate %<volatile%>");
4129 } 4955 }
4956
4957 if (!ADDR_SPACE_GENERIC_P (as1) && !ADDR_SPACE_GENERIC_P (as2) && as1 != as2)
4958 error_at (loc, "conflicting named address spaces (%s vs %s)",
4959 c_addr_space_name (as1), c_addr_space_name (as2));
4960
4130 if (!flag_gen_aux_info && (TYPE_QUALS (element_type))) 4961 if (!flag_gen_aux_info && (TYPE_QUALS (element_type)))
4131 type = TYPE_MAIN_VARIANT (type); 4962 type = TYPE_MAIN_VARIANT (type);
4132 type_quals = ((constp ? TYPE_QUAL_CONST : 0) 4963 type_quals = ((constp ? TYPE_QUAL_CONST : 0)
4133 | (restrictp ? TYPE_QUAL_RESTRICT : 0) 4964 | (restrictp ? TYPE_QUAL_RESTRICT : 0)
4134 | (volatilep ? TYPE_QUAL_VOLATILE : 0)); 4965 | (volatilep ? TYPE_QUAL_VOLATILE : 0)
4966 | ENCODE_QUAL_ADDR_SPACE (address_space));
4135 4967
4136 /* Warn about storage classes that are invalid for certain 4968 /* Warn about storage classes that are invalid for certain
4137 kinds of declarations (parameters, typenames, etc.). */ 4969 kinds of declarations (parameters, typenames, etc.). */
4138 4970
4139 if (funcdef_flag 4971 if (funcdef_flag
4140 && (threadp 4972 && (threadp
4141 || storage_class == csc_auto 4973 || storage_class == csc_auto
4142 || storage_class == csc_register 4974 || storage_class == csc_register
4143 || storage_class == csc_typedef)) 4975 || storage_class == csc_typedef))
4144 { 4976 {
4145 if (storage_class == csc_auto) 4977 if (storage_class == csc_auto)
4146 pedwarn (input_location, 4978 pedwarn (loc,
4147 (current_scope == file_scope) ? 0 : OPT_pedantic, 4979 (current_scope == file_scope) ? 0 : OPT_pedantic,
4148 "function definition declared %<auto%>"); 4980 "function definition declared %<auto%>");
4149 if (storage_class == csc_register) 4981 if (storage_class == csc_register)
4150 error ("function definition declared %<register%>"); 4982 error_at (loc, "function definition declared %<register%>");
4151 if (storage_class == csc_typedef) 4983 if (storage_class == csc_typedef)
4152 error ("function definition declared %<typedef%>"); 4984 error_at (loc, "function definition declared %<typedef%>");
4153 if (threadp) 4985 if (threadp)
4154 error ("function definition declared %<__thread%>"); 4986 error_at (loc, "function definition declared %<__thread%>");
4155 threadp = false; 4987 threadp = false;
4156 if (storage_class == csc_auto 4988 if (storage_class == csc_auto
4157 || storage_class == csc_register 4989 || storage_class == csc_register
4158 || storage_class == csc_typedef) 4990 || storage_class == csc_typedef)
4159 storage_class = csc_none; 4991 storage_class = csc_none;
4160 } 4992 }
4161 else if (decl_context != NORMAL && (storage_class != csc_none || threadp)) 4993 else if (decl_context != NORMAL && (storage_class != csc_none || threadp))
4162 { 4994 {
4163 if (decl_context == PARM && storage_class == csc_register) 4995 if (decl_context == PARM && storage_class == csc_register)
4164 ; 4996 ;
4165 else 4997 else
4166 { 4998 {
4167 switch (decl_context) 4999 switch (decl_context)
4168 { 5000 {
4169 case FIELD: 5001 case FIELD:
4170 error ("storage class specified for structure field %qs", 5002 if (name)
4171 name); 5003 error_at (loc, "storage class specified for structure "
4172 break; 5004 "field %qE", name);
4173 case PARM: 5005 else
4174 error ("storage class specified for parameter %qs", name); 5006 error_at (loc, "storage class specified for structure field");
4175 break; 5007 break;
4176 default: 5008 case PARM:
4177 error ("storage class specified for typename"); 5009 if (name)
4178 break; 5010 error_at (loc, "storage class specified for parameter %qE",
4179 } 5011 name);
4180 storage_class = csc_none; 5012 else
4181 threadp = false; 5013 error_at (loc, "storage class specified for unnamed parameter");
4182 } 5014 break;
5015 default:
5016 error_at (loc, "storage class specified for typename");
5017 break;
5018 }
5019 storage_class = csc_none;
5020 threadp = false;
5021 }
4183 } 5022 }
4184 else if (storage_class == csc_extern 5023 else if (storage_class == csc_extern
4185 && initialized 5024 && initialized
4186 && !funcdef_flag) 5025 && !funcdef_flag)
4187 { 5026 {
4188 /* 'extern' with initialization is invalid if not at file scope. */ 5027 /* 'extern' with initialization is invalid if not at file scope. */
4189 if (current_scope == file_scope) 5028 if (current_scope == file_scope)
4190 { 5029 {
4191 /* It is fine to have 'extern const' when compiling at C 5030 /* It is fine to have 'extern const' when compiling at C
4192 and C++ intersection. */ 5031 and C++ intersection. */
4193 if (!(warn_cxx_compat && constp)) 5032 if (!(warn_cxx_compat && constp))
4194 warning (0, "%qs initialized and declared %<extern%>", name); 5033 warning_at (loc, 0, "%qE initialized and declared %<extern%>",
5034 name);
4195 } 5035 }
4196 else 5036 else
4197 error ("%qs has both %<extern%> and initializer", name); 5037 error_at (loc, "%qE has both %<extern%> and initializer", name);
4198 } 5038 }
4199 else if (current_scope == file_scope) 5039 else if (current_scope == file_scope)
4200 { 5040 {
4201 if (storage_class == csc_auto) 5041 if (storage_class == csc_auto)
4202 error ("file-scope declaration of %qs specifies %<auto%>", name); 5042 error_at (loc, "file-scope declaration of %qE specifies %<auto%>",
5043 name);
4203 if (pedantic && storage_class == csc_register) 5044 if (pedantic && storage_class == csc_register)
4204 pedwarn (input_location, OPT_pedantic, 5045 pedwarn (input_location, OPT_pedantic,
4205 "file-scope declaration of %qs specifies %<register%>", name); 5046 "file-scope declaration of %qE specifies %<register%>", name);
4206 } 5047 }
4207 else 5048 else
4208 { 5049 {
4209 if (storage_class == csc_extern && funcdef_flag) 5050 if (storage_class == csc_extern && funcdef_flag)
4210 error ("nested function %qs declared %<extern%>", name); 5051 error_at (loc, "nested function %qE declared %<extern%>", name);
4211 else if (threadp && storage_class == csc_none) 5052 else if (threadp && storage_class == csc_none)
4212 { 5053 {
4213 error ("function-scope %qs implicitly auto and declared " 5054 error_at (loc, "function-scope %qE implicitly auto and declared "
4214 "%<__thread%>", 5055 "%<__thread%>",
4215 name); 5056 name);
4216 threadp = false; 5057 threadp = false;
4217 } 5058 }
4218 } 5059 }
4219 5060
4220 /* Now figure out the structure of the declarator proper. 5061 /* Now figure out the structure of the declarator proper.
4221 Descend through it, creating more complex types, until we reach 5062 Descend through it, creating more complex types, until we reach
4222 the declared identifier (or NULL_TREE, in an absolute declarator). 5063 the declared identifier (or NULL_TREE, in an absolute declarator).
4228 TYPE_MAIN_VARIANT pointing to the unqualified form. */ 5069 TYPE_MAIN_VARIANT pointing to the unqualified form. */
4229 5070
4230 while (declarator && declarator->kind != cdk_id) 5071 while (declarator && declarator->kind != cdk_id)
4231 { 5072 {
4232 if (type == error_mark_node) 5073 if (type == error_mark_node)
4233 { 5074 {
4234 declarator = declarator->declarator; 5075 declarator = declarator->declarator;
4235 continue; 5076 continue;
4236 } 5077 }
4237 5078
4238 /* Each level of DECLARATOR is either a cdk_array (for ...[..]), 5079 /* Each level of DECLARATOR is either a cdk_array (for ...[..]),
4239 a cdk_pointer (for *...), 5080 a cdk_pointer (for *...),
4240 a cdk_function (for ...(...)), 5081 a cdk_function (for ...(...)),
4241 a cdk_attrs (for nested attributes), 5082 a cdk_attrs (for nested attributes),
4242 or a cdk_id (for the name being declared 5083 or a cdk_id (for the name being declared
4243 or the place in an absolute declarator 5084 or the place in an absolute declarator
4244 where the name was omitted). 5085 where the name was omitted).
4245 For the last case, we have just exited the loop. 5086 For the last case, we have just exited the loop.
4246 5087
4247 At this point, TYPE is the type of elements of an array, 5088 At this point, TYPE is the type of elements of an array,
4248 or for a function to return, or for a pointer to point to. 5089 or for a function to return, or for a pointer to point to.
4249 After this sequence of ifs, TYPE is the type of the 5090 After this sequence of ifs, TYPE is the type of the
4250 array or function or pointer, and DECLARATOR has had its 5091 array or function or pointer, and DECLARATOR has had its
4251 outermost layer removed. */ 5092 outermost layer removed. */
4252 5093
4253 if (array_ptr_quals != TYPE_UNQUALIFIED 5094 if (array_ptr_quals != TYPE_UNQUALIFIED
4254 || array_ptr_attrs != NULL_TREE 5095 || array_ptr_attrs != NULL_TREE
4255 || array_parm_static) 5096 || array_parm_static)
4256 { 5097 {
4257 /* Only the innermost declarator (making a parameter be of 5098 /* Only the innermost declarator (making a parameter be of
4258 array type which is converted to pointer type) 5099 array type which is converted to pointer type)
4259 may have static or type qualifiers. */ 5100 may have static or type qualifiers. */
4260 error ("static or type qualifiers in non-parameter array declarator"); 5101 error_at (loc, "static or type qualifiers in non-parameter array declarator");
4261 array_ptr_quals = TYPE_UNQUALIFIED; 5102 array_ptr_quals = TYPE_UNQUALIFIED;
4262 array_ptr_attrs = NULL_TREE; 5103 array_ptr_attrs = NULL_TREE;
4263 array_parm_static = 0; 5104 array_parm_static = 0;
4264 } 5105 }
4265 5106
4266 switch (declarator->kind) 5107 switch (declarator->kind)
4267 { 5108 {
4268 case cdk_attrs: 5109 case cdk_attrs:
4269 { 5110 {
4270 /* A declarator with embedded attributes. */ 5111 /* A declarator with embedded attributes. */
4271 tree attrs = declarator->u.attrs; 5112 tree attrs = declarator->u.attrs;
4272 const struct c_declarator *inner_decl; 5113 const struct c_declarator *inner_decl;
4273 int attr_flags = 0; 5114 int attr_flags = 0;
4274 declarator = declarator->declarator; 5115 declarator = declarator->declarator;
4275 inner_decl = declarator; 5116 inner_decl = declarator;
4276 while (inner_decl->kind == cdk_attrs) 5117 while (inner_decl->kind == cdk_attrs)
4277 inner_decl = inner_decl->declarator; 5118 inner_decl = inner_decl->declarator;
4278 if (inner_decl->kind == cdk_id) 5119 if (inner_decl->kind == cdk_id)
4279 attr_flags |= (int) ATTR_FLAG_DECL_NEXT; 5120 attr_flags |= (int) ATTR_FLAG_DECL_NEXT;
4280 else if (inner_decl->kind == cdk_function) 5121 else if (inner_decl->kind == cdk_function)
4281 attr_flags |= (int) ATTR_FLAG_FUNCTION_NEXT; 5122 attr_flags |= (int) ATTR_FLAG_FUNCTION_NEXT;
4282 else if (inner_decl->kind == cdk_array) 5123 else if (inner_decl->kind == cdk_array)
4283 attr_flags |= (int) ATTR_FLAG_ARRAY_NEXT; 5124 attr_flags |= (int) ATTR_FLAG_ARRAY_NEXT;
4284 returned_attrs = decl_attributes (&type, 5125 returned_attrs = decl_attributes (&type,
4285 chainon (returned_attrs, attrs), 5126 chainon (returned_attrs, attrs),
4286 attr_flags); 5127 attr_flags);
4287 break; 5128 break;
4288 } 5129 }
4289 case cdk_array: 5130 case cdk_array:
4290 { 5131 {
4291 tree itype = NULL_TREE; 5132 tree itype = NULL_TREE;
4292 tree size = declarator->u.array.dimen; 5133 tree size = declarator->u.array.dimen;
4293 /* The index is a signed object `sizetype' bits wide. */ 5134 /* The index is a signed object `sizetype' bits wide. */
4294 tree index_type = c_common_signed_type (sizetype); 5135 tree index_type = c_common_signed_type (sizetype);
4295 5136
4296 array_ptr_quals = declarator->u.array.quals; 5137 array_ptr_quals = declarator->u.array.quals;
4297 array_ptr_attrs = declarator->u.array.attrs; 5138 array_ptr_attrs = declarator->u.array.attrs;
4298 array_parm_static = declarator->u.array.static_p; 5139 array_parm_static = declarator->u.array.static_p;
4299 array_parm_vla_unspec_p = declarator->u.array.vla_unspec_p; 5140 array_parm_vla_unspec_p = declarator->u.array.vla_unspec_p;
4300 5141
4301 declarator = declarator->declarator; 5142 declarator = declarator->declarator;
4302 5143
4303 /* Check for some types that there cannot be arrays of. */ 5144 /* Check for some types that there cannot be arrays of. */
4304 5145
4305 if (VOID_TYPE_P (type)) 5146 if (VOID_TYPE_P (type))
4306 { 5147 {
4307 error ("declaration of %qs as array of voids", name); 5148 if (name)
4308 type = error_mark_node; 5149 error_at (loc, "declaration of %qE as array of voids", name);
4309 } 5150 else
4310 5151 error_at (loc, "declaration of type name as array of voids");
4311 if (TREE_CODE (type) == FUNCTION_TYPE) 5152 type = error_mark_node;
4312 { 5153 }
4313 error ("declaration of %qs as array of functions", name); 5154
4314 type = error_mark_node; 5155 if (TREE_CODE (type) == FUNCTION_TYPE)
4315 } 5156 {
4316 5157 if (name)
4317 if (pedantic && !in_system_header && flexible_array_type_p (type)) 5158 error_at (loc, "declaration of %qE as array of functions",
4318 pedwarn (input_location, OPT_pedantic, 5159 name);
4319 "invalid use of structure with flexible array member"); 5160 else
4320 5161 error_at (loc, "declaration of type name as array of "
4321 if (size == error_mark_node) 5162 "functions");
4322 type = error_mark_node; 5163 type = error_mark_node;
4323 5164 }
4324 if (type == error_mark_node) 5165
4325 continue; 5166 if (pedantic && !in_system_header && flexible_array_type_p (type))
4326 5167 pedwarn (loc, OPT_pedantic,
4327 /* If size was specified, set ITYPE to a range-type for 5168 "invalid use of structure with flexible array member");
4328 that size. Otherwise, ITYPE remains null. finish_decl 5169
4329 may figure it out from an initial value. */ 5170 if (size == error_mark_node)
4330 5171 type = error_mark_node;
4331 if (size) 5172
4332 { 5173 if (type == error_mark_node)
4333 /* Strip NON_LVALUE_EXPRs since we aren't using as an 5174 continue;
4334 lvalue. */ 5175
4335 STRIP_TYPE_NOPS (size); 5176 /* If size was specified, set ITYPE to a range-type for
4336 5177 that size. Otherwise, ITYPE remains null. finish_decl
4337 if (!INTEGRAL_TYPE_P (TREE_TYPE (size))) 5178 may figure it out from an initial value. */
4338 { 5179
4339 error ("size of array %qs has non-integer type", name); 5180 if (size)
4340 size = integer_one_node; 5181 {
4341 } 5182 bool size_maybe_const = true;
4342 5183 bool size_int_const = (TREE_CODE (size) == INTEGER_CST
4343 if (pedantic && integer_zerop (size)) 5184 && !TREE_OVERFLOW (size));
4344 pedwarn (input_location, OPT_pedantic, 5185 bool this_size_varies = false;
4345 "ISO C forbids zero-size array %qs", name); 5186
4346 5187 /* Strip NON_LVALUE_EXPRs since we aren't using as an
4347 if (TREE_CODE (size) == INTEGER_CST) 5188 lvalue. */
4348 { 5189 STRIP_TYPE_NOPS (size);
4349 constant_expression_warning (size); 5190
4350 if (tree_int_cst_sgn (size) < 0) 5191 if (!INTEGRAL_TYPE_P (TREE_TYPE (size)))
4351 { 5192 {
4352 error ("size of array %qs is negative", name); 5193 if (name)
4353 size = integer_one_node; 5194 error_at (loc, "size of array %qE has non-integer type",
4354 } 5195 name);
4355 } 5196 else
4356 else if ((decl_context == NORMAL || decl_context == FIELD) 5197 error_at (loc,
4357 && current_scope == file_scope) 5198 "size of unnamed array has non-integer type");
4358 { 5199 size = integer_one_node;
4359 error ("variably modified %qs at file scope", name); 5200 }
4360 size = integer_one_node; 5201
4361 } 5202 size = c_fully_fold (size, false, &size_maybe_const);
4362 else 5203
4363 { 5204 if (pedantic && size_maybe_const && integer_zerop (size))
4364 /* Make sure the array size remains visibly 5205 {
4365 nonconstant even if it is (eg) a const variable 5206 if (name)
4366 with known value. */ 5207 pedwarn (loc, OPT_pedantic,
4367 size_varies = 1; 5208 "ISO C forbids zero-size array %qE", name);
4368 warn_variable_length_array (orig_name, size); 5209 else
4369 } 5210 pedwarn (loc, OPT_pedantic,
4370 5211 "ISO C forbids zero-size array");
4371 if (integer_zerop (size)) 5212 }
4372 { 5213
4373 /* A zero-length array cannot be represented with 5214 if (TREE_CODE (size) == INTEGER_CST && size_maybe_const)
4374 an unsigned index type, which is what we'll 5215 {
4375 get with build_index_type. Create an 5216 constant_expression_warning (size);
4376 open-ended range instead. */ 5217 if (tree_int_cst_sgn (size) < 0)
4377 itype = build_range_type (sizetype, size, NULL_TREE); 5218 {
4378 } 5219 if (name)
4379 else 5220 error_at (loc, "size of array %qE is negative", name);
4380 { 5221 else
4381 /* Arrange for the SAVE_EXPR on the inside of the 5222 error_at (loc, "size of unnamed array is negative");
4382 MINUS_EXPR, which allows the -1 to get folded 5223 size = integer_one_node;
4383 with the +1 that happens when building TYPE_SIZE. */ 5224 }
4384 if (size_varies) 5225 /* Handle a size folded to an integer constant but
4385 size = variable_size (size); 5226 not an integer constant expression. */
4386 5227 if (!size_int_const)
4387 /* Compute the maximum valid index, that is, size 5228 {
4388 - 1. Do the calculation in index_type, so that 5229 /* If this is a file scope declaration of an
4389 if it is a variable the computations will be 5230 ordinary identifier, this is invalid code;
4390 done in the proper mode. */ 5231 diagnosing it here and not subsequently
4391 itype = fold_build2 (MINUS_EXPR, index_type, 5232 treating the type as variable-length avoids
4392 convert (index_type, size), 5233 more confusing diagnostics later. */
4393 convert (index_type, 5234 if ((decl_context == NORMAL || decl_context == FIELD)
4394 size_one_node)); 5235 && current_scope == file_scope)
4395 5236 pedwarn (input_location, 0,
4396 /* If that overflowed, the array is too big. ??? 5237 "variably modified %qE at file scope",
4397 While a size of INT_MAX+1 technically shouldn't 5238 name);
4398 cause an overflow (because we subtract 1), the 5239 else
4399 overflow is recorded during the conversion to 5240 this_size_varies = size_varies = true;
4400 index_type, before the subtraction. Handling 5241 warn_variable_length_array (name, size);
4401 this case seems like an unnecessary 5242 }
4402 complication. */ 5243 }
4403 if (TREE_CODE (itype) == INTEGER_CST 5244 else if ((decl_context == NORMAL || decl_context == FIELD)
4404 && TREE_OVERFLOW (itype)) 5245 && current_scope == file_scope)
4405 { 5246 {
4406 error ("size of array %qs is too large", name); 5247 error_at (loc, "variably modified %qE at file scope", name);
4407 type = error_mark_node; 5248 size = integer_one_node;
4408 continue; 5249 }
4409 } 5250 else
4410 5251 {
4411 itype = build_index_type (itype); 5252 /* Make sure the array size remains visibly
4412 } 5253 nonconstant even if it is (eg) a const variable
4413 } 5254 with known value. */
4414 else if (decl_context == FIELD) 5255 this_size_varies = size_varies = true;
4415 { 5256 warn_variable_length_array (name, size);
4416 bool flexible_array_member = false; 5257 }
4417 if (array_parm_vla_unspec_p) 5258
4418 /* Field names can in fact have function prototype 5259 if (integer_zerop (size) && !this_size_varies)
4419 scope so [*] is disallowed here through making 5260 {
4420 the field variably modified, not through being 5261 /* A zero-length array cannot be represented with
4421 something other than a declaration with function 5262 an unsigned index type, which is what we'll
4422 prototype scope. */ 5263 get with build_index_type. Create an
4423 size_varies = 1; 5264 open-ended range instead. */
4424 else 5265 itype = build_range_type (sizetype, size, NULL_TREE);
4425 { 5266 }
4426 const struct c_declarator *t = declarator; 5267 else
4427 while (t->kind == cdk_attrs) 5268 {
4428 t = t->declarator; 5269 /* Arrange for the SAVE_EXPR on the inside of the
4429 flexible_array_member = (t->kind == cdk_id); 5270 MINUS_EXPR, which allows the -1 to get folded
4430 } 5271 with the +1 that happens when building TYPE_SIZE. */
4431 if (flexible_array_member 5272 if (size_varies)
4432 && pedantic && !flag_isoc99 && !in_system_header) 5273 size = c_variable_size (size);
4433 pedwarn (input_location, OPT_pedantic, 5274 if (this_size_varies && TREE_CODE (size) == INTEGER_CST)
4434 "ISO C90 does not support flexible array members"); 5275 size = build2 (COMPOUND_EXPR, TREE_TYPE (size),
4435 5276 integer_zero_node, size);
4436 /* ISO C99 Flexible array members are effectively 5277
4437 identical to GCC's zero-length array extension. */ 5278 /* Compute the maximum valid index, that is, size
4438 if (flexible_array_member || array_parm_vla_unspec_p) 5279 - 1. Do the calculation in index_type, so that
4439 itype = build_range_type (sizetype, size_zero_node, 5280 if it is a variable the computations will be
4440 NULL_TREE); 5281 done in the proper mode. */
4441 } 5282 itype = fold_build2_loc (loc, MINUS_EXPR, index_type,
4442 else if (decl_context == PARM) 5283 convert (index_type, size),
4443 { 5284 convert (index_type,
4444 if (array_parm_vla_unspec_p) 5285 size_one_node));
4445 { 5286
4446 itype = build_range_type (sizetype, size_zero_node, NULL_TREE); 5287 /* If that overflowed, the array is too big. ???
4447 size_varies = 1; 5288 While a size of INT_MAX+1 technically shouldn't
4448 } 5289 cause an overflow (because we subtract 1), the
4449 } 5290 overflow is recorded during the conversion to
4450 else if (decl_context == TYPENAME) 5291 index_type, before the subtraction. Handling
4451 { 5292 this case seems like an unnecessary
4452 if (array_parm_vla_unspec_p) 5293 complication. */
4453 { 5294 if (TREE_CODE (itype) == INTEGER_CST
4454 /* C99 6.7.5.2p4 */ 5295 && TREE_OVERFLOW (itype))
4455 warning (0, "%<[*]%> not in a declaration"); 5296 {
4456 /* We use this to avoid messing up with incomplete 5297 if (name)
4457 array types of the same type, that would 5298 error_at (loc, "size of array %qE is too large",
4458 otherwise be modified below. */ 5299 name);
4459 itype = build_range_type (sizetype, size_zero_node, 5300 else
4460 NULL_TREE); 5301 error_at (loc, "size of unnamed array is too large");
4461 size_varies = 1; 5302 type = error_mark_node;
4462 } 5303 continue;
4463 } 5304 }
4464 5305
4465 /* Complain about arrays of incomplete types. */ 5306 itype = build_index_type (itype);
4466 if (!COMPLETE_TYPE_P (type)) 5307 }
4467 { 5308 if (this_size_varies)
4468 error ("array type has incomplete element type"); 5309 {
4469 type = error_mark_node; 5310 if (*expr)
4470 } 5311 *expr = build2 (COMPOUND_EXPR, TREE_TYPE (size),
4471 else 5312 *expr, size);
4472 /* When itype is NULL, a shared incomplete array type is 5313 else
4473 returned for all array of a given type. Elsewhere we 5314 *expr = size;
4474 make sure we don't complete that type before copying 5315 *expr_const_operands &= size_maybe_const;
4475 it, but here we want to make sure we don't ever 5316 }
4476 modify the shared type, so we gcc_assert (itype) 5317 }
4477 below. */ 5318 else if (decl_context == FIELD)
4478 type = build_array_type (type, itype); 5319 {
4479 5320 bool flexible_array_member = false;
4480 if (type != error_mark_node) 5321 if (array_parm_vla_unspec_p)
4481 { 5322 /* Field names can in fact have function prototype
4482 if (size_varies) 5323 scope so [*] is disallowed here through making
4483 { 5324 the field variably modified, not through being
4484 /* It is ok to modify type here even if itype is 5325 something other than a declaration with function
4485 NULL: if size_varies, we're in a 5326 prototype scope. */
4486 multi-dimensional array and the inner type has 5327 size_varies = true;
4487 variable size, so the enclosing shared array type 5328 else
4488 must too. */ 5329 {
4489 if (size && TREE_CODE (size) == INTEGER_CST) 5330 const struct c_declarator *t = declarator;
4490 type 5331 while (t->kind == cdk_attrs)
4491 = build_distinct_type_copy (TYPE_MAIN_VARIANT (type)); 5332 t = t->declarator;
4492 C_TYPE_VARIABLE_SIZE (type) = 1; 5333 flexible_array_member = (t->kind == cdk_id);
4493 } 5334 }
4494 5335 if (flexible_array_member
4495 /* The GCC extension for zero-length arrays differs from 5336 && pedantic && !flag_isoc99 && !in_system_header)
4496 ISO flexible array members in that sizeof yields 5337 pedwarn (loc, OPT_pedantic,
4497 zero. */ 5338 "ISO C90 does not support flexible array members");
4498 if (size && integer_zerop (size)) 5339
4499 { 5340 /* ISO C99 Flexible array members are effectively
4500 gcc_assert (itype); 5341 identical to GCC's zero-length array extension. */
4501 TYPE_SIZE (type) = bitsize_zero_node; 5342 if (flexible_array_member || array_parm_vla_unspec_p)
4502 TYPE_SIZE_UNIT (type) = size_zero_node; 5343 itype = build_range_type (sizetype, size_zero_node,
4503 } 5344 NULL_TREE);
4504 if (array_parm_vla_unspec_p) 5345 }
4505 { 5346 else if (decl_context == PARM)
4506 gcc_assert (itype); 5347 {
4507 /* The type is complete. C99 6.7.5.2p4 */ 5348 if (array_parm_vla_unspec_p)
4508 TYPE_SIZE (type) = bitsize_zero_node; 5349 {
4509 TYPE_SIZE_UNIT (type) = size_zero_node; 5350 itype = build_range_type (sizetype, size_zero_node, NULL_TREE);
4510 } 5351 size_varies = true;
4511 } 5352 }
4512 5353 }
4513 if (decl_context != PARM 5354 else if (decl_context == TYPENAME)
4514 && (array_ptr_quals != TYPE_UNQUALIFIED 5355 {
4515 || array_ptr_attrs != NULL_TREE 5356 if (array_parm_vla_unspec_p)
4516 || array_parm_static)) 5357 {
4517 { 5358 /* C99 6.7.5.2p4 */
4518 error ("static or type qualifiers in non-parameter array declarator"); 5359 warning (0, "%<[*]%> not in a declaration");
4519 array_ptr_quals = TYPE_UNQUALIFIED; 5360 /* We use this to avoid messing up with incomplete
4520 array_ptr_attrs = NULL_TREE; 5361 array types of the same type, that would
4521 array_parm_static = 0; 5362 otherwise be modified below. */
4522 } 5363 itype = build_range_type (sizetype, size_zero_node,
4523 break; 5364 NULL_TREE);
4524 } 5365 size_varies = true;
4525 case cdk_function: 5366 }
4526 { 5367 }
4527 /* Say it's a definition only for the declarator closest 5368
4528 to the identifier, apart possibly from some 5369 /* Complain about arrays of incomplete types. */
4529 attributes. */ 5370 if (!COMPLETE_TYPE_P (type))
4530 bool really_funcdef = false; 5371 {
4531 tree arg_types; 5372 error_at (loc, "array type has incomplete element type");
4532 if (funcdef_flag) 5373 type = error_mark_node;
4533 { 5374 }
4534 const struct c_declarator *t = declarator->declarator; 5375 else
4535 while (t->kind == cdk_attrs) 5376 /* When itype is NULL, a shared incomplete array type is
4536 t = t->declarator; 5377 returned for all array of a given type. Elsewhere we
4537 really_funcdef = (t->kind == cdk_id); 5378 make sure we don't complete that type before copying
4538 } 5379 it, but here we want to make sure we don't ever
4539 5380 modify the shared type, so we gcc_assert (itype)
4540 /* Declaring a function type. Make sure we have a valid 5381 below. */
4541 type for the function to return. */ 5382 {
4542 if (type == error_mark_node) 5383 addr_space_t as = DECODE_QUAL_ADDR_SPACE (type_quals);
4543 continue; 5384 if (!ADDR_SPACE_GENERIC_P (as) && as != TYPE_ADDR_SPACE (type))
4544 5385 type = build_qualified_type (type,
4545 size_varies = 0; 5386 ENCODE_QUAL_ADDR_SPACE (as));
4546 5387
4547 /* Warn about some types functions can't return. */ 5388 type = build_array_type (type, itype);
4548 if (TREE_CODE (type) == FUNCTION_TYPE) 5389 }
4549 { 5390
4550 error ("%qs declared as function returning a function", name); 5391 if (type != error_mark_node)
4551 type = integer_type_node; 5392 {
4552 } 5393 if (size_varies)
4553 if (TREE_CODE (type) == ARRAY_TYPE) 5394 {
4554 { 5395 /* It is ok to modify type here even if itype is
4555 error ("%qs declared as function returning an array", name); 5396 NULL: if size_varies, we're in a
4556 type = integer_type_node; 5397 multi-dimensional array and the inner type has
4557 } 5398 variable size, so the enclosing shared array type
4558 5399 must too. */
4559 /* Construct the function type and go to the next 5400 if (size && TREE_CODE (size) == INTEGER_CST)
4560 inner layer of declarator. */ 5401 type
4561 arg_info = declarator->u.arg_info; 5402 = build_distinct_type_copy (TYPE_MAIN_VARIANT (type));
4562 arg_types = grokparms (arg_info, really_funcdef); 5403 C_TYPE_VARIABLE_SIZE (type) = 1;
4563 if (really_funcdef) 5404 }
4564 put_pending_sizes (arg_info->pending_sizes); 5405
4565 5406 /* The GCC extension for zero-length arrays differs from
4566 /* Type qualifiers before the return type of the function 5407 ISO flexible array members in that sizeof yields
4567 qualify the return type, not the function type. */ 5408 zero. */
4568 if (type_quals) 5409 if (size && integer_zerop (size))
4569 { 5410 {
4570 /* Type qualifiers on a function return type are 5411 gcc_assert (itype);
4571 normally permitted by the standard but have no 5412 TYPE_SIZE (type) = bitsize_zero_node;
4572 effect, so give a warning at -Wreturn-type. 5413 TYPE_SIZE_UNIT (type) = size_zero_node;
4573 Qualifiers on a void return type are banned on 5414 }
4574 function definitions in ISO C; GCC used to used 5415 if (array_parm_vla_unspec_p)
4575 them for noreturn functions. */ 5416 {
4576 if (VOID_TYPE_P (type) && really_funcdef) 5417 gcc_assert (itype);
4577 pedwarn (input_location, 0, 5418 /* The type is complete. C99 6.7.5.2p4 */
4578 "function definition has qualified void return type"); 5419 TYPE_SIZE (type) = bitsize_zero_node;
4579 else 5420 TYPE_SIZE_UNIT (type) = size_zero_node;
4580 warning (OPT_Wignored_qualifiers, 5421 }
4581 "type qualifiers ignored on function return type"); 5422 }
4582 5423
4583 type = c_build_qualified_type (type, type_quals); 5424 if (decl_context != PARM
4584 } 5425 && (array_ptr_quals != TYPE_UNQUALIFIED
4585 type_quals = TYPE_UNQUALIFIED; 5426 || array_ptr_attrs != NULL_TREE
5427 || array_parm_static))
5428 {
5429 error_at (loc, "static or type qualifiers in non-parameter array declarator");
5430 array_ptr_quals = TYPE_UNQUALIFIED;
5431 array_ptr_attrs = NULL_TREE;
5432 array_parm_static = 0;
5433 }
5434 break;
5435 }
5436 case cdk_function:
5437 {
5438 /* Say it's a definition only for the declarator closest
5439 to the identifier, apart possibly from some
5440 attributes. */
5441 bool really_funcdef = false;
5442 tree arg_types;
5443 if (funcdef_flag)
5444 {
5445 const struct c_declarator *t = declarator->declarator;
5446 while (t->kind == cdk_attrs)
5447 t = t->declarator;
5448 really_funcdef = (t->kind == cdk_id);
5449 }
5450
5451 /* Declaring a function type. Make sure we have a valid
5452 type for the function to return. */
5453 if (type == error_mark_node)
5454 continue;
5455
5456 size_varies = false;
5457
5458 /* Warn about some types functions can't return. */
5459 if (TREE_CODE (type) == FUNCTION_TYPE)
5460 {
5461 if (name)
5462 error_at (loc, "%qE declared as function returning a "
5463 "function", name);
5464 else
5465 error_at (loc, "type name declared as function "
5466 "returning a function");
5467 type = integer_type_node;
5468 }
5469 if (TREE_CODE (type) == ARRAY_TYPE)
5470 {
5471 if (name)
5472 error_at (loc, "%qE declared as function returning an array",
5473 name);
5474 else
5475 error_at (loc, "type name declared as function returning "
5476 "an array");
5477 type = integer_type_node;
5478 }
5479 errmsg = targetm.invalid_return_type (type);
5480 if (errmsg)
5481 {
5482 error (errmsg);
5483 type = integer_type_node;
5484 }
5485
5486 /* Construct the function type and go to the next
5487 inner layer of declarator. */
5488 arg_info = declarator->u.arg_info;
5489 arg_types = grokparms (arg_info, really_funcdef);
5490 if (really_funcdef)
5491 put_pending_sizes (arg_info->pending_sizes);
5492
5493 /* Type qualifiers before the return type of the function
5494 qualify the return type, not the function type. */
5495 if (type_quals)
5496 {
5497 /* Type qualifiers on a function return type are
5498 normally permitted by the standard but have no
5499 effect, so give a warning at -Wreturn-type.
5500 Qualifiers on a void return type are banned on
5501 function definitions in ISO C; GCC used to used
5502 them for noreturn functions. */
5503 if (VOID_TYPE_P (type) && really_funcdef)
5504 pedwarn (loc, 0,
5505 "function definition has qualified void return type");
5506 else
5507 warning_at (loc, OPT_Wignored_qualifiers,
5508 "type qualifiers ignored on function return type");
5509
5510 type = c_build_qualified_type (type, type_quals);
5511 }
5512 type_quals = TYPE_UNQUALIFIED;
4586 5513
4587 #ifndef noCbC 5514 #ifndef noCbC
4588 if ( declspecs->typespec_word == cts_CbC_code ) 5515 if ( declspecs->typespec_word == cts_CbC_code )
4589 { 5516 {
4590 type = build_code_segment_type (type, arg_types); 5517 type = build_code_segment_type (type, arg_types);
4593 #endif 5520 #endif
4594 { 5521 {
4595 type = build_function_type (type, arg_types); 5522 type = build_function_type (type, arg_types);
4596 } 5523 }
4597 5524
4598 declarator = declarator->declarator; 5525 declarator = declarator->declarator;
4599 5526
4600 /* Set the TYPE_CONTEXTs for each tagged type which is local to 5527 /* Set the TYPE_CONTEXTs for each tagged type which is local to
4601 the formal parameter list of this FUNCTION_TYPE to point to 5528 the formal parameter list of this FUNCTION_TYPE to point to
4602 the FUNCTION_TYPE node itself. */ 5529 the FUNCTION_TYPE node itself. */
4603 { 5530 {
4604 tree link; 5531 tree link;
4605 5532
4606 for (link = arg_info->tags; 5533 for (link = arg_info->tags;
4607 link; 5534 link;
4608 link = TREE_CHAIN (link)) 5535 link = TREE_CHAIN (link))
4609 TYPE_CONTEXT (TREE_VALUE (link)) = type; 5536 TYPE_CONTEXT (TREE_VALUE (link)) = type;
4610 } 5537 }
4611 break; 5538 break;
4612 } 5539 }
4613 case cdk_pointer: 5540 case cdk_pointer:
4614 { 5541 {
4615 /* Merge any constancy or volatility into the target type 5542 /* Merge any constancy or volatility into the target type
4616 for the pointer. */ 5543 for the pointer. */
4617 5544
4618 if (pedantic && TREE_CODE (type) == FUNCTION_TYPE 5545 if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
4619 && type_quals) 5546 && type_quals)
4620 pedwarn (input_location, OPT_pedantic, 5547 pedwarn (loc, OPT_pedantic,
4621 "ISO C forbids qualified function types"); 5548 "ISO C forbids qualified function types");
4622 if (type_quals) 5549 if (type_quals)
4623 type = c_build_qualified_type (type, type_quals); 5550 type = c_build_qualified_type (type, type_quals);
4624 size_varies = 0; 5551 size_varies = false;
4625 5552
4626 /* When the pointed-to type involves components of variable size, 5553 /* When the pointed-to type involves components of variable size,
4627 care must be taken to ensure that the size evaluation code is 5554 care must be taken to ensure that the size evaluation code is
4628 emitted early enough to dominate all the possible later uses 5555 emitted early enough to dominate all the possible later uses
4629 and late enough for the variables on which it depends to have 5556 and late enough for the variables on which it depends to have
4630 been assigned. 5557 been assigned.
4631 5558
4632 This is expected to happen automatically when the pointed-to 5559 This is expected to happen automatically when the pointed-to
4633 type has a name/declaration of it's own, but special attention 5560 type has a name/declaration of it's own, but special attention
4634 is required if the type is anonymous. 5561 is required if the type is anonymous.
4635 5562
4636 We handle the NORMAL and FIELD contexts here by attaching an 5563 We handle the NORMAL and FIELD contexts here by attaching an
4637 artificial TYPE_DECL to such pointed-to type. This forces the 5564 artificial TYPE_DECL to such pointed-to type. This forces the
4638 sizes evaluation at a safe point and ensures it is not deferred 5565 sizes evaluation at a safe point and ensures it is not deferred
4639 until e.g. within a deeper conditional context. 5566 until e.g. within a deeper conditional context.
4640 5567
4641 We expect nothing to be needed here for PARM or TYPENAME. 5568 We expect nothing to be needed here for PARM or TYPENAME.
4642 Pushing a TYPE_DECL at this point for TYPENAME would actually 5569 Pushing a TYPE_DECL at this point for TYPENAME would actually
4643 be incorrect, as we might be in the middle of an expression 5570 be incorrect, as we might be in the middle of an expression
4644 with side effects on the pointed-to type size "arguments" prior 5571 with side effects on the pointed-to type size "arguments" prior
4645 to the pointer declaration point and the fake TYPE_DECL in the 5572 to the pointer declaration point and the fake TYPE_DECL in the
4646 enclosing context would force the size evaluation prior to the 5573 enclosing context would force the size evaluation prior to the
4647 side effects. */ 5574 side effects. */
4648 5575
4649 if (!TYPE_NAME (type) 5576 if (!TYPE_NAME (type)
4650 && (decl_context == NORMAL || decl_context == FIELD) 5577 && (decl_context == NORMAL || decl_context == FIELD)
4651 && variably_modified_type_p (type, NULL_TREE)) 5578 && variably_modified_type_p (type, NULL_TREE))
4652 { 5579 {
4653 tree decl = build_decl (TYPE_DECL, NULL_TREE, type); 5580 tree decl = build_decl (loc, TYPE_DECL, NULL_TREE, type);
4654 DECL_ARTIFICIAL (decl) = 1; 5581 DECL_ARTIFICIAL (decl) = 1;
4655 pushdecl (decl); 5582 pushdecl (decl);
4656 finish_decl (decl, NULL_TREE, NULL_TREE); 5583 finish_decl (decl, loc, NULL_TREE, NULL_TREE, NULL_TREE);
4657 TYPE_NAME (type) = decl; 5584 TYPE_NAME (type) = decl;
4658 } 5585 }
4659 5586
4660 type = build_pointer_type (type); 5587 type = build_pointer_type (type);
4661 5588
4662 /* Process type qualifiers (such as const or volatile) 5589 /* Process type qualifiers (such as const or volatile)
4663 that were given inside the `*'. */ 5590 that were given inside the `*'. */
4664 type_quals = declarator->u.pointer_quals; 5591 type_quals = declarator->u.pointer_quals;
4665 5592
4666 declarator = declarator->declarator; 5593 declarator = declarator->declarator;
4667 break; 5594 break;
4668 } 5595 }
4669 default: 5596 default:
4670 gcc_unreachable (); 5597 gcc_unreachable ();
4671 } 5598 }
4672 } 5599 }
4673 *decl_attrs = chainon (returned_attrs, *decl_attrs); 5600 *decl_attrs = chainon (returned_attrs, *decl_attrs);
4674 5601
4675 /* Now TYPE has the actual type, apart from any qualifiers in 5602 /* Now TYPE has the actual type, apart from any qualifiers in
4676 TYPE_QUALS. */ 5603 TYPE_QUALS. */
4677 5604
5605 /* Warn about address space used for things other than static memory or
5606 pointers. */
5607 address_space = DECODE_QUAL_ADDR_SPACE (type_quals);
5608 if (!ADDR_SPACE_GENERIC_P (address_space))
5609 {
5610 if (decl_context == NORMAL)
5611 {
5612 switch (storage_class)
5613 {
5614 case csc_auto:
5615 error ("%qs combined with %<auto%> qualifier for %qE",
5616 c_addr_space_name (address_space), name);
5617 break;
5618 case csc_register:
5619 error ("%qs combined with %<register%> qualifier for %qE",
5620 c_addr_space_name (address_space), name);
5621 break;
5622 case csc_none:
5623 if (current_function_scope)
5624 {
5625 error ("%qs specified for auto variable %qE",
5626 c_addr_space_name (address_space), name);
5627 break;
5628 }
5629 break;
5630 case csc_static:
5631 case csc_extern:
5632 case csc_typedef:
5633 break;
5634 default:
5635 gcc_unreachable ();
5636 }
5637 }
5638 else if (decl_context == PARM && TREE_CODE (type) != ARRAY_TYPE)
5639 {
5640 if (name)
5641 error ("%qs specified for parameter %qE",
5642 c_addr_space_name (address_space), name);
5643 else
5644 error ("%qs specified for unnamed parameter",
5645 c_addr_space_name (address_space));
5646 }
5647 else if (decl_context == FIELD)
5648 {
5649 if (name)
5650 error ("%qs specified for structure field %qE",
5651 c_addr_space_name (address_space), name);
5652 else
5653 error ("%qs specified for structure field",
5654 c_addr_space_name (address_space));
5655 }
5656 }
5657
4678 /* Check the type and width of a bit-field. */ 5658 /* Check the type and width of a bit-field. */
4679 if (bitfield) 5659 if (bitfield)
4680 check_bitfield_type_and_width (&type, width, orig_name); 5660 check_bitfield_type_and_width (&type, width, name);
4681 5661
4682 /* Did array size calculations overflow? */ 5662 /* Did array size calculations overflow? */
4683 5663
4684 if (TREE_CODE (type) == ARRAY_TYPE 5664 if (TREE_CODE (type) == ARRAY_TYPE
4685 && COMPLETE_TYPE_P (type) 5665 && COMPLETE_TYPE_P (type)
4686 && TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST 5666 && TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST
4687 && TREE_OVERFLOW (TYPE_SIZE_UNIT (type))) 5667 && TREE_OVERFLOW (TYPE_SIZE_UNIT (type)))
4688 { 5668 {
4689 error ("size of array %qs is too large", name); 5669 if (name)
5670 error_at (loc, "size of array %qE is too large", name);
5671 else
5672 error_at (loc, "size of unnamed array is too large");
4690 /* If we proceed with the array type as it is, we'll eventually 5673 /* If we proceed with the array type as it is, we'll eventually
4691 crash in tree_low_cst(). */ 5674 crash in tree_low_cst(). */
4692 type = error_mark_node; 5675 type = error_mark_node;
4693 } 5676 }
4694 5677
4695 /* If this is declaring a typedef name, return a TYPE_DECL. */ 5678 /* If this is declaring a typedef name, return a TYPE_DECL. */
4696 5679
4697 if (storage_class == csc_typedef) 5680 if (storage_class == csc_typedef)
4698 { 5681 {
4699 tree decl; 5682 tree decl;
4700 if (pedantic && TREE_CODE (type) == FUNCTION_TYPE 5683 if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
4701 && type_quals) 5684 && type_quals)
4702 pedwarn (input_location, OPT_pedantic, 5685 pedwarn (loc, OPT_pedantic,
4703 "ISO C forbids qualified function types"); 5686 "ISO C forbids qualified function types");
4704 if (type_quals) 5687 if (type_quals)
4705 type = c_build_qualified_type (type, type_quals); 5688 type = c_build_qualified_type (type, type_quals);
4706 decl = build_decl (TYPE_DECL, declarator->u.id, type); 5689 decl = build_decl (declarator->id_loc,
4707 DECL_SOURCE_LOCATION (decl) = declarator->id_loc; 5690 TYPE_DECL, declarator->u.id, type);
4708 if (declspecs->explicit_signed_p) 5691 if (declspecs->explicit_signed_p)
4709 C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1; 5692 C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1;
4710 if (declspecs->inline_p) 5693 if (declspecs->inline_p)
4711 pedwarn (input_location, 0,"typedef %q+D declared %<inline%>", decl); 5694 pedwarn (loc, 0,"typedef %q+D declared %<inline%>", decl);
5695
5696 if (warn_cxx_compat && declarator->u.id != NULL_TREE)
5697 {
5698 struct c_binding *b = I_TAG_BINDING (declarator->u.id);
5699
5700 if (b != NULL
5701 && b->decl != NULL_TREE
5702 && (B_IN_CURRENT_SCOPE (b)
5703 || (current_scope == file_scope && B_IN_EXTERNAL_SCOPE (b)))
5704 && TYPE_MAIN_VARIANT (b->decl) != TYPE_MAIN_VARIANT (type))
5705 {
5706 warning_at (declarator->id_loc, OPT_Wc___compat,
5707 ("using %qD as both a typedef and a tag is "
5708 "invalid in C++"),
5709 decl);
5710 if (b->locus != UNKNOWN_LOCATION)
5711 inform (b->locus, "originally defined here");
5712 }
5713 }
5714
4712 return decl; 5715 return decl;
4713 } 5716 }
4714 5717
4715 /* If this is a type name (such as, in a cast or sizeof), 5718 /* If this is a type name (such as, in a cast or sizeof),
4716 compute the type and return it now. */ 5719 compute the type and return it now. */
4717 5720
4718 if (decl_context == TYPENAME) 5721 if (decl_context == TYPENAME)
4719 { 5722 {
4720 /* Note that the grammar rejects storage classes in typenames 5723 /* Note that the grammar rejects storage classes in typenames
4721 and fields. */ 5724 and fields. */
4722 gcc_assert (storage_class == csc_none && !threadp 5725 gcc_assert (storage_class == csc_none && !threadp
4723 && !declspecs->inline_p); 5726 && !declspecs->inline_p);
4724 if (pedantic && TREE_CODE (type) == FUNCTION_TYPE 5727 if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
4725 && type_quals) 5728 && type_quals)
4726 pedwarn (input_location, OPT_pedantic, 5729 pedwarn (loc, OPT_pedantic,
4727 "ISO C forbids const or volatile function types"); 5730 "ISO C forbids const or volatile function types");
4728 if (type_quals) 5731 if (type_quals)
4729 type = c_build_qualified_type (type, type_quals); 5732 type = c_build_qualified_type (type, type_quals);
4730 return type; 5733 return type;
4731 } 5734 }
4732 5735
4733 if (pedantic && decl_context == FIELD 5736 if (pedantic && decl_context == FIELD
4734 && variably_modified_type_p (type, NULL_TREE)) 5737 && variably_modified_type_p (type, NULL_TREE))
4735 { 5738 {
4736 /* C99 6.7.2.1p8 */ 5739 /* C99 6.7.2.1p8 */
4737 pedwarn (input_location, OPT_pedantic, 5740 pedwarn (loc, OPT_pedantic, "a member of a structure or union cannot "
4738 "a member of a structure or union cannot have a variably modified type"); 5741 "have a variably modified type");
4739 } 5742 }
4740 5743
4741 /* Aside from typedefs and type names (handle above), 5744 /* Aside from typedefs and type names (handle above),
4742 `void' at top level (not within pointer) 5745 `void' at top level (not within pointer)
4743 is allowed only in public variables. 5746 is allowed only in public variables.
4744 We don't complain about parms either, but that is because 5747 We don't complain about parms either, but that is because
4745 a better error message can be made later. */ 5748 a better error message can be made later. */
4746 5749
4747 if (VOID_TYPE_P (type) && decl_context != PARM 5750 if (VOID_TYPE_P (type) && decl_context != PARM
4748 && !((decl_context != FIELD && TREE_CODE (type) != FUNCTION_TYPE) 5751 && !((decl_context != FIELD && TREE_CODE (type) != FUNCTION_TYPE)
4749 && (storage_class == csc_extern 5752 && (storage_class == csc_extern
4750 || (current_scope == file_scope 5753 || (current_scope == file_scope
4751 && !(storage_class == csc_static 5754 && !(storage_class == csc_static
4752 || storage_class == csc_register))))) 5755 || storage_class == csc_register)))))
4753 { 5756 {
4754 error ("variable or field %qs declared void", name); 5757 error_at (loc, "variable or field %qE declared void", name);
4755 type = integer_type_node; 5758 type = integer_type_node;
4756 } 5759 }
4757 5760
4758 /* Now create the decl, which may be a VAR_DECL, a PARM_DECL 5761 /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
4759 or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE. */ 5762 or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE. */
4761 { 5764 {
4762 tree decl; 5765 tree decl;
4763 5766
4764 if (decl_context == PARM) 5767 if (decl_context == PARM)
4765 { 5768 {
4766 tree promoted_type; 5769 tree promoted_type;
4767 5770
4768 /* A parameter declared as an array of T is really a pointer to T. 5771 /* A parameter declared as an array of T is really a pointer to T.
4769 One declared as a function is really a pointer to a function. */ 5772 One declared as a function is really a pointer to a function. */
4770 5773
4771 if (TREE_CODE (type) == ARRAY_TYPE) 5774 if (TREE_CODE (type) == ARRAY_TYPE)
4772 { 5775 {
4773 /* Transfer const-ness of array into that of type pointed to. */ 5776 /* Transfer const-ness of array into that of type pointed to. */
4774 type = TREE_TYPE (type); 5777 type = TREE_TYPE (type);
4775 if (type_quals) 5778 if (type_quals)
4776 type = c_build_qualified_type (type, type_quals); 5779 type = c_build_qualified_type (type, type_quals);
4777 type = build_pointer_type (type); 5780 type = build_pointer_type (type);
4778 type_quals = array_ptr_quals; 5781 type_quals = array_ptr_quals;
4779 if (type_quals) 5782 if (type_quals)
4780 type = c_build_qualified_type (type, type_quals); 5783 type = c_build_qualified_type (type, type_quals);
4781 5784
4782 /* We don't yet implement attributes in this context. */ 5785 /* We don't yet implement attributes in this context. */
4783 if (array_ptr_attrs != NULL_TREE) 5786 if (array_ptr_attrs != NULL_TREE)
4784 warning (OPT_Wattributes, 5787 warning_at (loc, OPT_Wattributes,
4785 "attributes in parameter array declarator ignored"); 5788 "attributes in parameter array declarator ignored");
4786 5789
4787 size_varies = 0; 5790 size_varies = false;
4788 } 5791 }
4789 else if (TREE_CODE (type) == FUNCTION_TYPE) 5792 else if (TREE_CODE (type) == FUNCTION_TYPE)
4790 { 5793 {
4791 if (type_quals) 5794 if (type_quals)
4792 pedwarn (input_location, OPT_pedantic, 5795 pedwarn (loc, OPT_pedantic,
4793 "ISO C forbids qualified function types"); 5796 "ISO C forbids qualified function types");
4794 if (type_quals) 5797 if (type_quals)
4795 type = c_build_qualified_type (type, type_quals); 5798 type = c_build_qualified_type (type, type_quals);
4796 type = build_pointer_type (type); 5799 type = build_pointer_type (type);
4797 type_quals = TYPE_UNQUALIFIED; 5800 type_quals = TYPE_UNQUALIFIED;
4798 } 5801 }
4799 else if (type_quals) 5802 else if (type_quals)
4800 type = c_build_qualified_type (type, type_quals); 5803 type = c_build_qualified_type (type, type_quals);
4801 5804
4802 decl = build_decl (PARM_DECL, declarator->u.id, type); 5805 decl = build_decl (declarator->id_loc,
4803 DECL_SOURCE_LOCATION (decl) = declarator->id_loc; 5806 PARM_DECL, declarator->u.id, type);
4804 if (size_varies) 5807 if (size_varies)
4805 C_DECL_VARIABLE_SIZE (decl) = 1; 5808 C_DECL_VARIABLE_SIZE (decl) = 1;
4806 5809
4807 /* Compute the type actually passed in the parmlist, 5810 /* Compute the type actually passed in the parmlist,
4808 for the case where there is no prototype. 5811 for the case where there is no prototype.
4809 (For example, shorts and chars are passed as ints.) 5812 (For example, shorts and chars are passed as ints.)
4810 When there is a prototype, this is overridden later. */ 5813 When there is a prototype, this is overridden later. */
4811 5814
4812 if (type == error_mark_node) 5815 if (type == error_mark_node)
4813 promoted_type = type; 5816 promoted_type = type;
4814 else 5817 else
4815 promoted_type = c_type_promotes_to (type); 5818 promoted_type = c_type_promotes_to (type);
4816 5819
4817 DECL_ARG_TYPE (decl) = promoted_type; 5820 DECL_ARG_TYPE (decl) = promoted_type;
4818 if (declspecs->inline_p) 5821 if (declspecs->inline_p)
4819 pedwarn (input_location, 0, "parameter %q+D declared %<inline%>", decl); 5822 pedwarn (loc, 0, "parameter %q+D declared %<inline%>", decl);
4820 } 5823 }
4821 else if (decl_context == FIELD) 5824 else if (decl_context == FIELD)
4822 { 5825 {
4823 /* Note that the grammar rejects storage classes in typenames 5826 /* Note that the grammar rejects storage classes in typenames
4824 and fields. */ 5827 and fields. */
4825 gcc_assert (storage_class == csc_none && !threadp 5828 gcc_assert (storage_class == csc_none && !threadp
4826 && !declspecs->inline_p); 5829 && !declspecs->inline_p);
4827 5830
4828 /* Structure field. It may not be a function. */ 5831 /* Structure field. It may not be a function. */
4829 5832
4830 if (TREE_CODE (type) == FUNCTION_TYPE) 5833 if (TREE_CODE (type) == FUNCTION_TYPE)
4831 { 5834 {
4832 error ("field %qs declared as a function", name); 5835 error_at (loc, "field %qE declared as a function", name);
4833 type = build_pointer_type (type); 5836 type = build_pointer_type (type);
4834 } 5837 }
4835 else if (TREE_CODE (type) != ERROR_MARK 5838 else if (TREE_CODE (type) != ERROR_MARK
4836 && !COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (type)) 5839 && !COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (type))
4837 { 5840 {
4838 error ("field %qs has incomplete type", name); 5841 if (name)
4839 type = error_mark_node; 5842 error_at (loc, "field %qE has incomplete type", name);
4840 } 5843 else
4841 type = c_build_qualified_type (type, type_quals); 5844 error_at (loc, "unnamed field has incomplete type");
4842 decl = build_decl (FIELD_DECL, declarator->u.id, type); 5845 type = error_mark_node;
4843 DECL_SOURCE_LOCATION (decl) = declarator->id_loc; 5846 }
4844 DECL_NONADDRESSABLE_P (decl) = bitfield; 5847 type = c_build_qualified_type (type, type_quals);
4845 if (bitfield && !declarator->u.id) 5848 decl = build_decl (declarator->id_loc,
4846 TREE_NO_WARNING (decl) = 1; 5849 FIELD_DECL, declarator->u.id, type);
4847 5850 DECL_NONADDRESSABLE_P (decl) = bitfield;
4848 if (size_varies) 5851 if (bitfield && !declarator->u.id)
4849 C_DECL_VARIABLE_SIZE (decl) = 1; 5852 TREE_NO_WARNING (decl) = 1;
5853
5854 if (size_varies)
5855 C_DECL_VARIABLE_SIZE (decl) = 1;
4850 } 5856 }
4851 else if (TREE_CODE (type) == FUNCTION_TYPE) 5857 else if (TREE_CODE (type) == FUNCTION_TYPE)
4852 { 5858 {
4853 if (storage_class == csc_register || threadp) 5859 if (storage_class == csc_register || threadp)
4854 { 5860 {
4855 error ("invalid storage class for function %qs", name); 5861 error_at (loc, "invalid storage class for function %qE", name);
4856 } 5862 }
4857 else if (current_scope != file_scope) 5863 else if (current_scope != file_scope)
4858 { 5864 {
4859 /* Function declaration not at file scope. Storage 5865 /* Function declaration not at file scope. Storage
4860 classes other than `extern' are not allowed, C99 5866 classes other than `extern' are not allowed, C99
4861 6.7.1p5, and `extern' makes no difference. However, 5867 6.7.1p5, and `extern' makes no difference. However,
4862 GCC allows 'auto', perhaps with 'inline', to support 5868 GCC allows 'auto', perhaps with 'inline', to support
4863 nested functions. */ 5869 nested functions. */
4864 if (storage_class == csc_auto) 5870 if (storage_class == csc_auto)
4865 pedwarn (input_location, OPT_pedantic, "invalid storage class for function %qs", name); 5871 pedwarn (loc, OPT_pedantic,
4866 else if (storage_class == csc_static) 5872 "invalid storage class for function %qE", name);
4867 { 5873 else if (storage_class == csc_static)
4868 error ("invalid storage class for function %qs", name); 5874 {
4869 if (funcdef_flag) 5875 error_at (loc, "invalid storage class for function %qE", name);
4870 storage_class = declspecs->storage_class = csc_none; 5876 if (funcdef_flag)
4871 else 5877 storage_class = declspecs->storage_class = csc_none;
4872 return 0; 5878 else
4873 } 5879 return 0;
4874 } 5880 }
4875 5881 }
4876 decl = build_decl (FUNCTION_DECL, declarator->u.id, type); 5882
4877 DECL_SOURCE_LOCATION (decl) = declarator->id_loc; 5883 decl = build_decl (declarator->id_loc,
4878 decl = build_decl_attribute_variant (decl, decl_attr); 5884 FUNCTION_DECL, declarator->u.id, type);
4879 5885 decl = build_decl_attribute_variant (decl, decl_attr);
4880 if (pedantic && type_quals && !DECL_IN_SYSTEM_HEADER (decl)) 5886
4881 pedwarn (input_location, OPT_pedantic, 5887 if (pedantic && type_quals && !DECL_IN_SYSTEM_HEADER (decl))
4882 "ISO C forbids qualified function types"); 5888 pedwarn (loc, OPT_pedantic,
4883 5889 "ISO C forbids qualified function types");
4884 /* GNU C interprets a volatile-qualified function type to indicate 5890
4885 that the function does not return. */ 5891 /* GNU C interprets a volatile-qualified function type to indicate
4886 if ((type_quals & TYPE_QUAL_VOLATILE) 5892 that the function does not return. */
4887 && !VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl)))) 5893 if ((type_quals & TYPE_QUAL_VOLATILE)
4888 warning (0, "%<noreturn%> function returns non-void value"); 5894 && !VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl))))
4889 5895 warning_at (loc, 0, "%<noreturn%> function returns non-void value");
4890 /* Every function declaration is an external reference 5896
4891 (DECL_EXTERNAL) except for those which are not at file 5897 /* Every function declaration is an external reference
4892 scope and are explicitly declared "auto". This is 5898 (DECL_EXTERNAL) except for those which are not at file
4893 forbidden by standard C (C99 6.7.1p5) and is interpreted by 5899 scope and are explicitly declared "auto". This is
4894 GCC to signify a forward declaration of a nested function. */ 5900 forbidden by standard C (C99 6.7.1p5) and is interpreted by
4895 if (storage_class == csc_auto && current_scope != file_scope) 5901 GCC to signify a forward declaration of a nested function. */
4896 DECL_EXTERNAL (decl) = 0; 5902 if (storage_class == csc_auto && current_scope != file_scope)
4897 /* In C99, a function which is declared 'inline' with 'extern' 5903 DECL_EXTERNAL (decl) = 0;
4898 is not an external reference (which is confusing). It 5904 /* In C99, a function which is declared 'inline' with 'extern'
4899 means that the later definition of the function must be output 5905 is not an external reference (which is confusing). It
4900 in this file, C99 6.7.4p6. In GNU C89, a function declared 5906 means that the later definition of the function must be output
4901 'extern inline' is an external reference. */ 5907 in this file, C99 6.7.4p6. In GNU C89, a function declared
4902 else if (declspecs->inline_p && storage_class != csc_static) 5908 'extern inline' is an external reference. */
4903 DECL_EXTERNAL (decl) = ((storage_class == csc_extern) 5909 else if (declspecs->inline_p && storage_class != csc_static)
4904 == flag_gnu89_inline); 5910 DECL_EXTERNAL (decl) = ((storage_class == csc_extern)
4905 else 5911 == flag_gnu89_inline);
4906 DECL_EXTERNAL (decl) = !initialized; 5912 else
4907 5913 DECL_EXTERNAL (decl) = !initialized;
4908 /* Record absence of global scope for `static' or `auto'. */ 5914
4909 TREE_PUBLIC (decl) 5915 /* Record absence of global scope for `static' or `auto'. */
4910 = !(storage_class == csc_static || storage_class == csc_auto); 5916 TREE_PUBLIC (decl)
4911 5917 = !(storage_class == csc_static || storage_class == csc_auto);
4912 /* For a function definition, record the argument information 5918
4913 block where store_parm_decls will look for it. */ 5919 /* For a function definition, record the argument information
4914 if (funcdef_flag) 5920 block where store_parm_decls will look for it. */
4915 current_function_arg_info = arg_info; 5921 if (funcdef_flag)
4916 5922 current_function_arg_info = arg_info;
4917 if (declspecs->default_int_p) 5923
4918 C_FUNCTION_IMPLICIT_INT (decl) = 1; 5924 if (declspecs->default_int_p)
4919 5925 C_FUNCTION_IMPLICIT_INT (decl) = 1;
4920 /* Record presence of `inline', if it is reasonable. */ 5926
4921 if (flag_hosted && MAIN_NAME_P (declarator->u.id)) 5927 /* Record presence of `inline', if it is reasonable. */
4922 { 5928 if (flag_hosted && MAIN_NAME_P (declarator->u.id))
4923 if (declspecs->inline_p) 5929 {
4924 pedwarn (input_location, 0, "cannot inline function %<main%>"); 5930 if (declspecs->inline_p)
4925 } 5931 pedwarn (loc, 0, "cannot inline function %<main%>");
4926 else if (declspecs->inline_p) 5932 }
4927 /* Record that the function is declared `inline'. */ 5933 else if (declspecs->inline_p)
4928 DECL_DECLARED_INLINE_P (decl) = 1; 5934 /* Record that the function is declared `inline'. */
5935 DECL_DECLARED_INLINE_P (decl) = 1;
4929 } 5936 }
4930 else 5937 else
4931 { 5938 {
4932 /* It's a variable. */ 5939 /* It's a variable. */
4933 /* An uninitialized decl with `extern' is a reference. */ 5940 /* An uninitialized decl with `extern' is a reference. */
4934 int extern_ref = !initialized && storage_class == csc_extern; 5941 int extern_ref = !initialized && storage_class == csc_extern;
4935 5942
4936 type = c_build_qualified_type (type, type_quals); 5943 type = c_build_qualified_type (type, type_quals);
4937 5944
4938 /* C99 6.2.2p7: It is invalid (compile-time undefined 5945 /* C99 6.2.2p7: It is invalid (compile-time undefined
4939 behavior) to create an 'extern' declaration for a 5946 behavior) to create an 'extern' declaration for a
4940 variable if there is a global declaration that is 5947 variable if there is a global declaration that is
4941 'static' and the global declaration is not visible. 5948 'static' and the global declaration is not visible.
4942 (If the static declaration _is_ currently visible, 5949 (If the static declaration _is_ currently visible,
4943 the 'extern' declaration is taken to refer to that decl.) */ 5950 the 'extern' declaration is taken to refer to that decl.) */
4944 if (extern_ref && current_scope != file_scope) 5951 if (extern_ref && current_scope != file_scope)
4945 { 5952 {
4946 tree global_decl = identifier_global_value (declarator->u.id); 5953 tree global_decl = identifier_global_value (declarator->u.id);
4947 tree visible_decl = lookup_name (declarator->u.id); 5954 tree visible_decl = lookup_name (declarator->u.id);
4948 5955
4949 if (global_decl 5956 if (global_decl
4950 && global_decl != visible_decl 5957 && global_decl != visible_decl
4951 && TREE_CODE (global_decl) == VAR_DECL 5958 && TREE_CODE (global_decl) == VAR_DECL
4952 && !TREE_PUBLIC (global_decl)) 5959 && !TREE_PUBLIC (global_decl))
4953 error ("variable previously declared %<static%> redeclared " 5960 error_at (loc, "variable previously declared %<static%> "
4954 "%<extern%>"); 5961 "redeclared %<extern%>");
4955 }
4956
4957 decl = build_decl (VAR_DECL, declarator->u.id, type);
4958 DECL_SOURCE_LOCATION (decl) = declarator->id_loc;
4959 if (size_varies)
4960 C_DECL_VARIABLE_SIZE (decl) = 1;
4961
4962 if (declspecs->inline_p)
4963 pedwarn (input_location, 0, "variable %q+D declared %<inline%>", decl);
4964
4965 /* At file scope, an initialized extern declaration may follow
4966 a static declaration. In that case, DECL_EXTERNAL will be
4967 reset later in start_decl. */
4968 DECL_EXTERNAL (decl) = (storage_class == csc_extern);
4969
4970 /* At file scope, the presence of a `static' or `register' storage
4971 class specifier, or the absence of all storage class specifiers
4972 makes this declaration a definition (perhaps tentative). Also,
4973 the absence of `static' makes it public. */
4974 if (current_scope == file_scope)
4975 {
4976 TREE_PUBLIC (decl) = storage_class != csc_static;
4977 TREE_STATIC (decl) = !extern_ref;
4978 }
4979 /* Not at file scope, only `static' makes a static definition. */
4980 else
4981 {
4982 TREE_STATIC (decl) = (storage_class == csc_static);
4983 TREE_PUBLIC (decl) = extern_ref;
4984 }
4985
4986 if (threadp)
4987 DECL_TLS_MODEL (decl) = decl_default_tls_model (decl);
4988 } 5962 }
4989 5963
4990 if (storage_class == csc_extern 5964 decl = build_decl (declarator->id_loc,
4991 && variably_modified_type_p (type, NULL_TREE)) 5965 VAR_DECL, declarator->u.id, type);
5966 if (size_varies)
5967 C_DECL_VARIABLE_SIZE (decl) = 1;
5968
5969 if (declspecs->inline_p)
5970 pedwarn (loc, 0, "variable %q+D declared %<inline%>", decl);
5971
5972 /* At file scope, an initialized extern declaration may follow
5973 a static declaration. In that case, DECL_EXTERNAL will be
5974 reset later in start_decl. */
5975 DECL_EXTERNAL (decl) = (storage_class == csc_extern);
5976
5977 /* At file scope, the presence of a `static' or `register' storage
5978 class specifier, or the absence of all storage class specifiers
5979 makes this declaration a definition (perhaps tentative). Also,
5980 the absence of `static' makes it public. */
5981 if (current_scope == file_scope)
4992 { 5982 {
4993 /* C99 6.7.5.2p2 */ 5983 TREE_PUBLIC (decl) = storage_class != csc_static;
4994 error ("object with variably modified type must have no linkage"); 5984 TREE_STATIC (decl) = !extern_ref;
5985 }
5986 /* Not at file scope, only `static' makes a static definition. */
5987 else
5988 {
5989 TREE_STATIC (decl) = (storage_class == csc_static);
5990 TREE_PUBLIC (decl) = extern_ref;
5991 }
5992
5993 if (threadp)
5994 DECL_TLS_MODEL (decl) = decl_default_tls_model (decl);
5995 }
5996
5997 if ((storage_class == csc_extern
5998 || (storage_class == csc_none
5999 && TREE_CODE (type) == FUNCTION_TYPE
6000 && !funcdef_flag))
6001 && variably_modified_type_p (type, NULL_TREE))
6002 {
6003 /* C99 6.7.5.2p2 */
6004 if (TREE_CODE (type) == FUNCTION_TYPE)
6005 error_at (loc, "non-nested function with variably modified type");
6006 else
6007 error_at (loc, "object with variably modified type must have "
6008 "no linkage");
4995 } 6009 }
4996 6010
4997 /* Record `register' declaration for warnings on & 6011 /* Record `register' declaration for warnings on &
4998 and in case doing stupid register allocation. */ 6012 and in case doing stupid register allocation. */
4999 6013
5000 if (storage_class == csc_register) 6014 if (storage_class == csc_register)
5001 { 6015 {
5002 C_DECL_REGISTER (decl) = 1; 6016 C_DECL_REGISTER (decl) = 1;
5003 DECL_REGISTER (decl) = 1; 6017 DECL_REGISTER (decl) = 1;
5004 } 6018 }
5005 6019
5006 /* Record constancy and volatility. */ 6020 /* Record constancy and volatility. */
5007 c_apply_type_quals_to_decl (type_quals, decl); 6021 c_apply_type_quals_to_decl (type_quals, decl);
5008 6022
5009 /* If a type has volatile components, it should be stored in memory. 6023 /* If a type has volatile components, it should be stored in memory.
5010 Otherwise, the fact that those components are volatile 6024 Otherwise, the fact that those components are volatile
5011 will be ignored, and would even crash the compiler. 6025 will be ignored, and would even crash the compiler.
5012 Of course, this only makes sense on VAR,PARM, and RESULT decl's. */ 6026 Of course, this only makes sense on VAR,PARM, and RESULT decl's. */
5013 if (C_TYPE_FIELDS_VOLATILE (TREE_TYPE (decl)) 6027 if (C_TYPE_FIELDS_VOLATILE (TREE_TYPE (decl))
5014 && (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL 6028 && (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
5015 || TREE_CODE (decl) == RESULT_DECL)) 6029 || TREE_CODE (decl) == RESULT_DECL))
5016 { 6030 {
5017 /* It is not an error for a structure with volatile fields to 6031 /* It is not an error for a structure with volatile fields to
5018 be declared register, but reset DECL_REGISTER since it 6032 be declared register, but reset DECL_REGISTER since it
5019 cannot actually go in a register. */ 6033 cannot actually go in a register. */
5020 int was_reg = C_DECL_REGISTER (decl); 6034 int was_reg = C_DECL_REGISTER (decl);
5021 C_DECL_REGISTER (decl) = 0; 6035 C_DECL_REGISTER (decl) = 0;
5022 DECL_REGISTER (decl) = 0; 6036 DECL_REGISTER (decl) = 0;
5023 c_mark_addressable (decl); 6037 c_mark_addressable (decl);
5024 C_DECL_REGISTER (decl) = was_reg; 6038 C_DECL_REGISTER (decl) = was_reg;
5025 } 6039 }
5026 6040
5027 /* This is the earliest point at which we might know the assembler 6041 /* This is the earliest point at which we might know the assembler
5028 name of a variable. Thus, if it's known before this, die horribly. */ 6042 name of a variable. Thus, if it's known before this, die horribly. */
5029 gcc_assert (!DECL_ASSEMBLER_NAME_SET_P (decl)); 6043 gcc_assert (!DECL_ASSEMBLER_NAME_SET_P (decl));
6044
6045 if (warn_cxx_compat
6046 && TREE_CODE (decl) == VAR_DECL
6047 && TREE_PUBLIC (decl)
6048 && TREE_STATIC (decl)
6049 && (TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
6050 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
6051 || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE)
6052 && TYPE_NAME (TREE_TYPE (decl)) == NULL_TREE)
6053 warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wc___compat,
6054 ("non-local variable %qD with anonymous type is "
6055 "questionable in C++"),
6056 decl);
5030 6057
5031 return decl; 6058 return decl;
5032 } 6059 }
5033 } 6060 }
5034 6061
5058 error ("%<[*]%> not allowed in other than function prototype scope"); 6085 error ("%<[*]%> not allowed in other than function prototype scope");
5059 } 6086 }
5060 6087
5061 if (arg_types == 0 && !funcdef_flag && !in_system_header) 6088 if (arg_types == 0 && !funcdef_flag && !in_system_header)
5062 warning (OPT_Wstrict_prototypes, 6089 warning (OPT_Wstrict_prototypes,
5063 "function declaration isn%'t a prototype"); 6090 "function declaration isn%'t a prototype");
5064 6091
5065 if (arg_types == error_mark_node) 6092 if (arg_types == error_mark_node)
5066 return 0; /* don't set TYPE_ARG_TYPES in this case */ 6093 return 0; /* don't set TYPE_ARG_TYPES in this case */
5067 6094
5068 else if (arg_types && TREE_CODE (TREE_VALUE (arg_types)) == IDENTIFIER_NODE) 6095 else if (arg_types && TREE_CODE (TREE_VALUE (arg_types)) == IDENTIFIER_NODE)
5069 { 6096 {
5070 if (!funcdef_flag) 6097 if (!funcdef_flag)
5071 pedwarn (input_location, 0, "parameter names (without types) in function declaration"); 6098 pedwarn (input_location, 0, "parameter names (without types) in function declaration");
5072 6099
5073 arg_info->parms = arg_info->types; 6100 arg_info->parms = arg_info->types;
5074 arg_info->types = 0; 6101 arg_info->types = 0;
5075 return 0; 6102 return 0;
5076 } 6103 }
5077 else 6104 else
5078 { 6105 {
5079 tree parm, type, typelt; 6106 tree parm, type, typelt;
5080 unsigned int parmno; 6107 unsigned int parmno;
6108 const char *errmsg;
5081 6109
5082 /* If there is a parameter of incomplete type in a definition, 6110 /* If there is a parameter of incomplete type in a definition,
5083 this is an error. In a declaration this is valid, and a 6111 this is an error. In a declaration this is valid, and a
5084 struct or union type may be completed later, before any calls 6112 struct or union type may be completed later, before any calls
5085 or definition of the function. In the case where the tag was 6113 or definition of the function. In the case where the tag was
5086 first declared within the parameter list, a warning has 6114 first declared within the parameter list, a warning has
5087 already been given. If a parameter has void type, then 6115 already been given. If a parameter has void type, then
5088 however the function cannot be defined or called, so 6116 however the function cannot be defined or called, so
5089 warn. */ 6117 warn. */
5090 6118
5091 for (parm = arg_info->parms, typelt = arg_types, parmno = 1; 6119 for (parm = arg_info->parms, typelt = arg_types, parmno = 1;
5092 parm; 6120 parm;
5093 parm = TREE_CHAIN (parm), typelt = TREE_CHAIN (typelt), parmno++) 6121 parm = TREE_CHAIN (parm), typelt = TREE_CHAIN (typelt), parmno++)
5094 { 6122 {
5095 type = TREE_VALUE (typelt); 6123 type = TREE_VALUE (typelt);
5096 if (type == error_mark_node) 6124 if (type == error_mark_node)
5097 continue; 6125 continue;
5098 6126
5099 if (!COMPLETE_TYPE_P (type)) 6127 if (!COMPLETE_TYPE_P (type))
5100 { 6128 {
5101 if (funcdef_flag) 6129 if (funcdef_flag)
5102 { 6130 {
5103 if (DECL_NAME (parm)) 6131 if (DECL_NAME (parm))
5104 error ("parameter %u (%q+D) has incomplete type", 6132 error_at (input_location,
5105 parmno, parm); 6133 "parameter %u (%q+D) has incomplete type",
5106 else 6134 parmno, parm);
5107 error ("%Jparameter %u has incomplete type", 6135 else
5108 parm, parmno); 6136 error_at (DECL_SOURCE_LOCATION (parm),
5109 6137 "parameter %u has incomplete type",
5110 TREE_VALUE (typelt) = error_mark_node; 6138 parmno);
5111 TREE_TYPE (parm) = error_mark_node; 6139
5112 } 6140 TREE_VALUE (typelt) = error_mark_node;
5113 else if (VOID_TYPE_P (type)) 6141 TREE_TYPE (parm) = error_mark_node;
5114 { 6142 }
5115 if (DECL_NAME (parm)) 6143 else if (VOID_TYPE_P (type))
5116 warning (0, "parameter %u (%q+D) has void type", 6144 {
5117 parmno, parm); 6145 if (DECL_NAME (parm))
5118 else 6146 warning_at (input_location, 0,
5119 warning (0, "%Jparameter %u has void type", 6147 "parameter %u (%q+D) has void type",
5120 parm, parmno); 6148 parmno, parm);
5121 } 6149 else
5122 } 6150 warning_at (DECL_SOURCE_LOCATION (parm), 0,
5123 6151 "parameter %u has void type",
5124 if (DECL_NAME (parm) && TREE_USED (parm)) 6152 parmno);
5125 warn_if_shadowing (parm); 6153 }
5126 } 6154 }
6155
6156 errmsg = targetm.invalid_parameter_type (type);
6157 if (errmsg)
6158 {
6159 error (errmsg);
6160 TREE_VALUE (typelt) = error_mark_node;
6161 TREE_TYPE (parm) = error_mark_node;
6162 }
6163
6164 if (DECL_NAME (parm) && TREE_USED (parm))
6165 warn_if_shadowing (parm);
6166 }
5127 return arg_types; 6167 return arg_types;
5128 } 6168 }
5129 } 6169 }
5130 6170
5131 /* Take apart the current scope and return a c_arg_info structure with 6171 /* Take apart the current scope and return a c_arg_info structure with
5139 struct c_arg_info * 6179 struct c_arg_info *
5140 get_parm_info (bool ellipsis) 6180 get_parm_info (bool ellipsis)
5141 { 6181 {
5142 struct c_binding *b = current_scope->bindings; 6182 struct c_binding *b = current_scope->bindings;
5143 struct c_arg_info *arg_info = XOBNEW (&parser_obstack, 6183 struct c_arg_info *arg_info = XOBNEW (&parser_obstack,
5144 struct c_arg_info); 6184 struct c_arg_info);
5145 tree parms = 0; 6185 tree parms = 0;
5146 tree tags = 0; 6186 tree tags = 0;
5147 tree types = 0; 6187 tree types = 0;
5148 tree others = 0; 6188 tree others = 0;
5149 6189
5168 /* A parameter list consisting solely of 'void' indicates that the 6208 /* A parameter list consisting solely of 'void' indicates that the
5169 function takes no arguments. But if the 'void' is qualified 6209 function takes no arguments. But if the 'void' is qualified
5170 (by 'const' or 'volatile'), or has a storage class specifier 6210 (by 'const' or 'volatile'), or has a storage class specifier
5171 ('register'), then the behavior is undefined; issue an error. 6211 ('register'), then the behavior is undefined; issue an error.
5172 Typedefs for 'void' are OK (see DR#157). */ 6212 Typedefs for 'void' are OK (see DR#157). */
5173 if (b->prev == 0 /* one binding */ 6213 if (b->prev == 0 /* one binding */
5174 && TREE_CODE (b->decl) == PARM_DECL /* which is a parameter */ 6214 && TREE_CODE (b->decl) == PARM_DECL /* which is a parameter */
5175 && !DECL_NAME (b->decl) /* anonymous */ 6215 && !DECL_NAME (b->decl) /* anonymous */
5176 && VOID_TYPE_P (TREE_TYPE (b->decl))) /* of void type */ 6216 && VOID_TYPE_P (TREE_TYPE (b->decl))) /* of void type */
5177 { 6217 {
5178 if (TREE_THIS_VOLATILE (b->decl) 6218 if (TREE_THIS_VOLATILE (b->decl)
5179 || TREE_READONLY (b->decl) 6219 || TREE_READONLY (b->decl)
5180 || C_DECL_REGISTER (b->decl)) 6220 || C_DECL_REGISTER (b->decl))
5181 error ("%<void%> as only parameter may not be qualified"); 6221 error ("%<void%> as only parameter may not be qualified");
5182 6222
5183 /* There cannot be an ellipsis. */ 6223 /* There cannot be an ellipsis. */
5184 if (ellipsis) 6224 if (ellipsis)
5185 error ("%<void%> must be the only parameter"); 6225 error ("%<void%> must be the only parameter");
5186 6226
5187 arg_info->types = void_list_node; 6227 arg_info->types = void_list_node;
5188 return arg_info; 6228 return arg_info;
5189 } 6229 }
5190 6230
5198 tree decl = b->decl; 6238 tree decl = b->decl;
5199 tree type = TREE_TYPE (decl); 6239 tree type = TREE_TYPE (decl);
5200 const char *keyword; 6240 const char *keyword;
5201 6241
5202 switch (TREE_CODE (decl)) 6242 switch (TREE_CODE (decl))
5203 { 6243 {
5204 case PARM_DECL: 6244 case PARM_DECL:
5205 if (b->id) 6245 if (b->id)
5206 { 6246 {
5207 gcc_assert (I_SYMBOL_BINDING (b->id) == b); 6247 gcc_assert (I_SYMBOL_BINDING (b->id) == b);
5208 I_SYMBOL_BINDING (b->id) = b->shadowed; 6248 I_SYMBOL_BINDING (b->id) = b->shadowed;
5209 } 6249 }
5210 6250
5211 /* Check for forward decls that never got their actual decl. */ 6251 /* Check for forward decls that never got their actual decl. */
5212 if (TREE_ASM_WRITTEN (decl)) 6252 if (TREE_ASM_WRITTEN (decl))
5213 error ("parameter %q+D has just a forward declaration", decl); 6253 error ("parameter %q+D has just a forward declaration", decl);
5214 /* Check for (..., void, ...) and issue an error. */ 6254 /* Check for (..., void, ...) and issue an error. */
5215 else if (VOID_TYPE_P (type) && !DECL_NAME (decl)) 6255 else if (VOID_TYPE_P (type) && !DECL_NAME (decl))
5216 { 6256 {
5217 if (!gave_void_only_once_err) 6257 if (!gave_void_only_once_err)
5218 { 6258 {
5219 error ("%<void%> must be the only parameter"); 6259 error ("%<void%> must be the only parameter");
5220 gave_void_only_once_err = true; 6260 gave_void_only_once_err = true;
5221 } 6261 }
5222 } 6262 }
5223 else 6263 else
5224 { 6264 {
5225 /* Valid parameter, add it to the list. */ 6265 /* Valid parameter, add it to the list. */
5226 TREE_CHAIN (decl) = parms; 6266 TREE_CHAIN (decl) = parms;
5227 parms = decl; 6267 parms = decl;
5228 6268
5229 /* Since there is a prototype, args are passed in their 6269 /* Since there is a prototype, args are passed in their
5230 declared types. The back end may override this later. */ 6270 declared types. The back end may override this later. */
5231 DECL_ARG_TYPE (decl) = type; 6271 DECL_ARG_TYPE (decl) = type;
5232 types = tree_cons (0, type, types); 6272 types = tree_cons (0, type, types);
5233 } 6273 }
5234 break; 6274 break;
5235 6275
5236 case ENUMERAL_TYPE: keyword = "enum"; goto tag; 6276 case ENUMERAL_TYPE: keyword = "enum"; goto tag;
5237 case UNION_TYPE: keyword = "union"; goto tag; 6277 case UNION_TYPE: keyword = "union"; goto tag;
5238 case RECORD_TYPE: keyword = "struct"; goto tag; 6278 case RECORD_TYPE: keyword = "struct"; goto tag;
5239 tag: 6279 tag:
5240 /* Types may not have tag-names, in which case the type 6280 /* Types may not have tag-names, in which case the type
5241 appears in the bindings list with b->id NULL. */ 6281 appears in the bindings list with b->id NULL. */
5242 if (b->id) 6282 if (b->id)
5243 { 6283 {
5244 gcc_assert (I_TAG_BINDING (b->id) == b); 6284 gcc_assert (I_TAG_BINDING (b->id) == b);
5245 I_TAG_BINDING (b->id) = b->shadowed; 6285 I_TAG_BINDING (b->id) = b->shadowed;
5246 } 6286 }
5247 6287
5248 /* Warn about any struct, union or enum tags defined in a 6288 /* Warn about any struct, union or enum tags defined in a
5249 parameter list. The scope of such types is limited to 6289 parameter list. The scope of such types is limited to
5250 the parameter list, which is rarely if ever desirable 6290 the parameter list, which is rarely if ever desirable
5251 (it's impossible to call such a function with type- 6291 (it's impossible to call such a function with type-
5252 correct arguments). An anonymous union parm type is 6292 correct arguments). An anonymous union parm type is
5253 meaningful as a GNU extension, so don't warn for that. */ 6293 meaningful as a GNU extension, so don't warn for that. */
5254 if (TREE_CODE (decl) != UNION_TYPE || b->id != 0) 6294 if (TREE_CODE (decl) != UNION_TYPE || b->id != 0)
5255 { 6295 {
5256 if (b->id) 6296 if (b->id)
5257 /* The %s will be one of 'struct', 'union', or 'enum'. */ 6297 /* The %s will be one of 'struct', 'union', or 'enum'. */
5258 warning (0, "%<%s %E%> declared inside parameter list", 6298 warning (0, "%<%s %E%> declared inside parameter list",
5259 keyword, b->id); 6299 keyword, b->id);
5260 else 6300 else
5261 /* The %s will be one of 'struct', 'union', or 'enum'. */ 6301 /* The %s will be one of 'struct', 'union', or 'enum'. */
5262 warning (0, "anonymous %s declared inside parameter list", 6302 warning (0, "anonymous %s declared inside parameter list",
5263 keyword); 6303 keyword);
5264 6304
5265 if (!explained_incomplete_types) 6305 if (!explained_incomplete_types)
5266 { 6306 {
5267 warning (0, "its scope is only this definition or declaration," 6307 warning (0, "its scope is only this definition or declaration,"
5268 " which is probably not what you want"); 6308 " which is probably not what you want");
5269 explained_incomplete_types = true; 6309 explained_incomplete_types = true;
5270 } 6310 }
5271 } 6311 }
5272 6312
5273 tags = tree_cons (b->id, decl, tags); 6313 tags = tree_cons (b->id, decl, tags);
5274 break; 6314 break;
5275 6315
5276 case CONST_DECL: 6316 case CONST_DECL:
5277 case TYPE_DECL: 6317 case TYPE_DECL:
5278 case FUNCTION_DECL: 6318 case FUNCTION_DECL:
5279 /* CONST_DECLs appear here when we have an embedded enum, 6319 /* CONST_DECLs appear here when we have an embedded enum,
5280 and TYPE_DECLs appear here when we have an embedded struct 6320 and TYPE_DECLs appear here when we have an embedded struct
5281 or union. No warnings for this - we already warned about the 6321 or union. No warnings for this - we already warned about the
5282 type itself. FUNCTION_DECLs appear when there is an implicit 6322 type itself. FUNCTION_DECLs appear when there is an implicit
5283 function declaration in the parameter list. */ 6323 function declaration in the parameter list. */
5284 6324
5285 TREE_CHAIN (decl) = others; 6325 TREE_CHAIN (decl) = others;
5286 others = decl; 6326 others = decl;
5287 /* fall through */ 6327 /* fall through */
5288 6328
5289 case ERROR_MARK: 6329 case ERROR_MARK:
5290 /* error_mark_node appears here when we have an undeclared 6330 /* error_mark_node appears here when we have an undeclared
5291 variable. Just throw it away. */ 6331 variable. Just throw it away. */
5292 if (b->id) 6332 if (b->id)
5293 { 6333 {
5294 gcc_assert (I_SYMBOL_BINDING (b->id) == b); 6334 gcc_assert (I_SYMBOL_BINDING (b->id) == b);
5295 I_SYMBOL_BINDING (b->id) = b->shadowed; 6335 I_SYMBOL_BINDING (b->id) = b->shadowed;
5296 } 6336 }
5297 break; 6337 break;
5298 6338
5299 /* Other things that might be encountered. */ 6339 /* Other things that might be encountered. */
5300 case LABEL_DECL: 6340 case LABEL_DECL:
5301 case VAR_DECL: 6341 case VAR_DECL:
5302 default: 6342 default:
5303 gcc_unreachable (); 6343 gcc_unreachable ();
5304 } 6344 }
5305 6345
5306 b = free_binding_and_advance (b); 6346 b = free_binding_and_advance (b);
5307 } 6347 }
5308 6348
5309 arg_info->parms = parms; 6349 arg_info->parms = parms;
5313 arg_info->pending_sizes = get_pending_sizes (); 6353 arg_info->pending_sizes = get_pending_sizes ();
5314 return arg_info; 6354 return arg_info;
5315 } 6355 }
5316 6356
5317 /* Get the struct, enum or union (CODE says which) with tag NAME. 6357 /* Get the struct, enum or union (CODE says which) with tag NAME.
5318 Define the tag as a forward-reference if it is not defined. 6358 Define the tag as a forward-reference with location LOC if it is
5319 Return a c_typespec structure for the type specifier. */ 6359 not defined. Return a c_typespec structure for the type
6360 specifier. */
5320 6361
5321 struct c_typespec 6362 struct c_typespec
5322 parser_xref_tag (enum tree_code code, tree name) 6363 parser_xref_tag (location_t loc, enum tree_code code, tree name)
5323 { 6364 {
5324 struct c_typespec ret; 6365 struct c_typespec ret;
6366 tree ref;
6367 location_t refloc;
6368
6369 ret.expr = NULL_TREE;
6370 ret.expr_const_operands = true;
6371
5325 /* If a cross reference is requested, look up the type 6372 /* If a cross reference is requested, look up the type
5326 already defined for this tag and return it. */ 6373 already defined for this tag and return it. */
5327 6374
5328 tree ref = lookup_tag (code, name, 0); 6375 ref = lookup_tag (code, name, 0, &refloc);
5329 /* If this is the right type of tag, return what we found. 6376 /* If this is the right type of tag, return what we found.
5330 (This reference will be shadowed by shadow_tag later if appropriate.) 6377 (This reference will be shadowed by shadow_tag later if appropriate.)
5331 If this is the wrong type of tag, do not return it. If it was the 6378 If this is the wrong type of tag, do not return it. If it was the
5332 wrong type in the same scope, we will have had an error 6379 wrong type in the same scope, we will have had an error
5333 message already; if in a different scope and declaring 6380 message already; if in a different scope and declaring
5338 (For example, with "struct foo" in an outer scope, "union foo;" 6385 (For example, with "struct foo" in an outer scope, "union foo;"
5339 must shadow that tag with a new one of union type.) */ 6386 must shadow that tag with a new one of union type.) */
5340 ret.kind = (ref ? ctsk_tagref : ctsk_tagfirstref); 6387 ret.kind = (ref ? ctsk_tagref : ctsk_tagfirstref);
5341 if (ref && TREE_CODE (ref) == code) 6388 if (ref && TREE_CODE (ref) == code)
5342 { 6389 {
6390 if (C_TYPE_DEFINED_IN_STRUCT (ref)
6391 && loc != UNKNOWN_LOCATION
6392 && warn_cxx_compat)
6393 {
6394 switch (code)
6395 {
6396 case ENUMERAL_TYPE:
6397 warning_at (loc, OPT_Wc___compat,
6398 ("enum type defined in struct or union "
6399 "is not visible in C++"));
6400 inform (refloc, "enum type defined here");
6401 break;
6402 case RECORD_TYPE:
6403 warning_at (loc, OPT_Wc___compat,
6404 ("struct defined in struct or union "
6405 "is not visible in C++"));
6406 inform (refloc, "struct defined here");
6407 break;
6408 case UNION_TYPE:
6409 warning_at (loc, OPT_Wc___compat,
6410 ("union defined in struct or union "
6411 "is not visible in C++"));
6412 inform (refloc, "union defined here");
6413 break;
6414 default:
6415 gcc_unreachable();
6416 }
6417 }
6418
5343 ret.spec = ref; 6419 ret.spec = ref;
5344 return ret; 6420 return ret;
5345 } 6421 }
5346 6422
5347 /* If no such tag is yet defined, create a forward-reference node 6423 /* If no such tag is yet defined, create a forward-reference node
5351 6427
5352 ref = make_node (code); 6428 ref = make_node (code);
5353 if (code == ENUMERAL_TYPE) 6429 if (code == ENUMERAL_TYPE)
5354 { 6430 {
5355 /* Give the type a default layout like unsigned int 6431 /* Give the type a default layout like unsigned int
5356 to avoid crashing if it does not get defined. */ 6432 to avoid crashing if it does not get defined. */
5357 SET_TYPE_MODE (ref, TYPE_MODE (unsigned_type_node)); 6433 SET_TYPE_MODE (ref, TYPE_MODE (unsigned_type_node));
5358 TYPE_ALIGN (ref) = TYPE_ALIGN (unsigned_type_node); 6434 TYPE_ALIGN (ref) = TYPE_ALIGN (unsigned_type_node);
5359 TYPE_USER_ALIGN (ref) = 0; 6435 TYPE_USER_ALIGN (ref) = 0;
5360 TYPE_UNSIGNED (ref) = 1; 6436 TYPE_UNSIGNED (ref) = 1;
5361 TYPE_PRECISION (ref) = TYPE_PRECISION (unsigned_type_node); 6437 TYPE_PRECISION (ref) = TYPE_PRECISION (unsigned_type_node);
5362 TYPE_MIN_VALUE (ref) = TYPE_MIN_VALUE (unsigned_type_node); 6438 TYPE_MIN_VALUE (ref) = TYPE_MIN_VALUE (unsigned_type_node);
5363 TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node); 6439 TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node);
5364 } 6440 }
5365 6441
5366 pushtag (name, ref); 6442 pushtag (loc, name, ref);
5367 6443
5368 ret.spec = ref; 6444 ret.spec = ref;
5369 return ret; 6445 return ret;
5370 } 6446 }
5371 6447
5374 Return a tree for the type. */ 6450 Return a tree for the type. */
5375 6451
5376 tree 6452 tree
5377 xref_tag (enum tree_code code, tree name) 6453 xref_tag (enum tree_code code, tree name)
5378 { 6454 {
5379 return parser_xref_tag (code, name).spec; 6455 return parser_xref_tag (input_location, code, name).spec;
5380 } 6456 }
5381 6457
5382 /* Make sure that the tag NAME is defined *in the current scope* 6458 /* Make sure that the tag NAME is defined *in the current scope*
5383 at least as a forward reference. 6459 at least as a forward reference.
5384 CODE says which kind of tag NAME ought to be. */ 6460 LOC is the location of the struct's definition.
6461 CODE says which kind of tag NAME ought to be.
6462
6463 This stores the current value of the file static STRUCT_PARSE_INFO
6464 in *ENCLOSING_STRUCT_PARSE_INFO, and points STRUCT_PARSE_INFO at a
6465 new c_struct_parse_info structure. The old value of
6466 STRUCT_PARSE_INFO is restored in finish_struct. */
5385 6467
5386 tree 6468 tree
5387 start_struct (enum tree_code code, tree name) 6469 start_struct (location_t loc, enum tree_code code, tree name,
6470 struct c_struct_parse_info **enclosing_struct_parse_info)
5388 { 6471 {
5389 /* If there is already a tag defined at this scope 6472 /* If there is already a tag defined at this scope
5390 (as a forward reference), just return it. */ 6473 (as a forward reference), just return it. */
5391 6474
5392 tree ref = 0; 6475 tree ref = NULL_TREE;
5393 6476 location_t refloc = UNKNOWN_LOCATION;
5394 if (name != 0) 6477
5395 ref = lookup_tag (code, name, 1); 6478 if (name != NULL_TREE)
6479 ref = lookup_tag (code, name, 1, &refloc);
5396 if (ref && TREE_CODE (ref) == code) 6480 if (ref && TREE_CODE (ref) == code)
5397 { 6481 {
5398 if (TYPE_SIZE (ref)) 6482 if (TYPE_SIZE (ref))
5399 { 6483 {
5400 if (code == UNION_TYPE) 6484 if (code == UNION_TYPE)
5401 error ("redefinition of %<union %E%>", name); 6485 error_at (loc, "redefinition of %<union %E%>", name);
5402 else 6486 else
5403 error ("redefinition of %<struct %E%>", name); 6487 error_at (loc, "redefinition of %<struct %E%>", name);
5404 /* Don't create structures using a name already in use. */ 6488 if (refloc != UNKNOWN_LOCATION)
5405 ref = NULL_TREE; 6489 inform (refloc, "originally defined here");
5406 } 6490 /* Don't create structures using a name already in use. */
6491 ref = NULL_TREE;
6492 }
5407 else if (C_TYPE_BEING_DEFINED (ref)) 6493 else if (C_TYPE_BEING_DEFINED (ref))
5408 { 6494 {
5409 if (code == UNION_TYPE) 6495 if (code == UNION_TYPE)
5410 error ("nested redefinition of %<union %E%>", name); 6496 error_at (loc, "nested redefinition of %<union %E%>", name);
5411 else 6497 else
5412 error ("nested redefinition of %<struct %E%>", name); 6498 error_at (loc, "nested redefinition of %<struct %E%>", name);
5413 /* Don't create structures that contain themselves. */ 6499 /* Don't bother to report "originally defined here" for a
5414 ref = NULL_TREE; 6500 nested redefinition; the original definition should be
5415 } 6501 obvious. */
6502 /* Don't create structures that contain themselves. */
6503 ref = NULL_TREE;
6504 }
5416 } 6505 }
5417 6506
5418 /* Otherwise create a forward-reference just so the tag is in scope. */ 6507 /* Otherwise create a forward-reference just so the tag is in scope. */
5419 6508
5420 if (ref == NULL_TREE || TREE_CODE (ref) != code) 6509 if (ref == NULL_TREE || TREE_CODE (ref) != code)
5421 { 6510 {
5422 ref = make_node (code); 6511 ref = make_node (code);
5423 pushtag (name, ref); 6512 pushtag (loc, name, ref);
5424 } 6513 }
5425 6514
5426 C_TYPE_BEING_DEFINED (ref) = 1; 6515 C_TYPE_BEING_DEFINED (ref) = 1;
5427 TYPE_PACKED (ref) = flag_pack_struct; 6516 TYPE_PACKED (ref) = flag_pack_struct;
6517
6518 *enclosing_struct_parse_info = struct_parse_info;
6519 struct_parse_info = XNEW (struct c_struct_parse_info);
6520 struct_parse_info->struct_types = VEC_alloc (tree, heap, 0);
6521 struct_parse_info->fields = VEC_alloc (c_binding_ptr, heap, 0);
6522 struct_parse_info->typedefs_seen = VEC_alloc (tree, heap, 0);
6523
6524 /* FIXME: This will issue a warning for a use of a type defined
6525 within a statement expr used within sizeof, et. al. This is not
6526 terribly serious as C++ doesn't permit statement exprs within
6527 sizeof anyhow. */
6528 if (warn_cxx_compat && (in_sizeof || in_typeof || in_alignof))
6529 warning_at (loc, OPT_Wc___compat,
6530 "defining type in %qs expression is invalid in C++",
6531 (in_sizeof
6532 ? "sizeof"
6533 : (in_typeof ? "typeof" : "alignof")));
6534
5428 return ref; 6535 return ref;
5429 } 6536 }
5430 6537
5431 /* Process the specs, declarator and width (NULL if omitted) 6538 /* Process the specs, declarator and width (NULL if omitted)
5432 of a structure component, returning a FIELD_DECL node. 6539 of a structure component, returning a FIELD_DECL node.
5439 The FIELD_DECL nodes are chained together and the lot of them 6546 The FIELD_DECL nodes are chained together and the lot of them
5440 are ultimately passed to `build_struct' to make the RECORD_TYPE node. */ 6547 are ultimately passed to `build_struct' to make the RECORD_TYPE node. */
5441 6548
5442 tree 6549 tree
5443 grokfield (location_t loc, 6550 grokfield (location_t loc,
5444 struct c_declarator *declarator, struct c_declspecs *declspecs, 6551 struct c_declarator *declarator, struct c_declspecs *declspecs,
5445 tree width, tree *decl_attrs) 6552 tree width, tree *decl_attrs)
5446 { 6553 {
5447 tree value; 6554 tree value;
5448 6555
5449 if (declarator->kind == cdk_id && declarator->u.id == NULL_TREE 6556 if (declarator->kind == cdk_id && declarator->u.id == NULL_TREE
5450 && width == NULL_TREE) 6557 && width == NULL_TREE)
5451 { 6558 {
5452 /* This is an unnamed decl. 6559 /* This is an unnamed decl.
5453 6560
5454 If we have something of the form "union { list } ;" then this 6561 If we have something of the form "union { list } ;" then this
5455 is the anonymous union extension. Similarly for struct. 6562 is the anonymous union extension. Similarly for struct.
5456 6563
5457 If this is something of the form "struct foo;", then 6564 If this is something of the form "struct foo;", then
5458 If MS extensions are enabled, this is handled as an 6565 If MS extensions are enabled, this is handled as an
5459 anonymous struct. 6566 anonymous struct.
5460 Otherwise this is a forward declaration of a structure tag. 6567 Otherwise this is a forward declaration of a structure tag.
5461 6568
5462 If this is something of the form "foo;" and foo is a TYPE_DECL, then 6569 If this is something of the form "foo;" and foo is a TYPE_DECL, then
5463 If MS extensions are enabled and foo names a structure, then 6570 If MS extensions are enabled and foo names a structure, then
5464 again this is an anonymous struct. 6571 again this is an anonymous struct.
5465 Otherwise this is an error. 6572 Otherwise this is an error.
5466 6573
5467 Oh what a horrid tangled web we weave. I wonder if MS consciously 6574 Oh what a horrid tangled web we weave. I wonder if MS consciously
5468 took this from Plan 9 or if it was an accident of implementation 6575 took this from Plan 9 or if it was an accident of implementation
5469 that took root before someone noticed the bug... */ 6576 that took root before someone noticed the bug... */
5470 6577
5471 tree type = declspecs->type; 6578 tree type = declspecs->type;
5472 bool type_ok = (TREE_CODE (type) == RECORD_TYPE 6579 bool type_ok = (TREE_CODE (type) == RECORD_TYPE
5473 || TREE_CODE (type) == UNION_TYPE); 6580 || TREE_CODE (type) == UNION_TYPE);
5474 bool ok = false; 6581 bool ok = false;
5475 6582
5476 if (type_ok 6583 if (type_ok
5477 && (flag_ms_extensions || !declspecs->typedef_p)) 6584 && (flag_ms_extensions || !declspecs->typedef_p))
5478 { 6585 {
5479 if (flag_ms_extensions) 6586 if (flag_ms_extensions)
5480 ok = true; 6587 ok = true;
5481 else if (flag_iso) 6588 else if (flag_iso)
5482 ok = false; 6589 ok = false;
5483 else if (TYPE_NAME (type) == NULL) 6590 else if (TYPE_NAME (type) == NULL)
5484 ok = true; 6591 ok = true;
5485 else 6592 else
5486 ok = false; 6593 ok = false;
5487 } 6594 }
5488 if (!ok) 6595 if (!ok)
5489 { 6596 {
5490 pedwarn (loc, 0, "declaration does not declare anything"); 6597 pedwarn (loc, 0, "declaration does not declare anything");
5491 return NULL_TREE; 6598 return NULL_TREE;
5492 } 6599 }
5493 pedwarn (loc, OPT_pedantic, "ISO C doesn%'t support unnamed structs/unions"); 6600 pedwarn (loc, OPT_pedantic, "ISO C doesn%'t support unnamed structs/unions");
5494 } 6601 }
5495 6602
5496 value = grokdeclarator (declarator, declspecs, FIELD, false, 6603 value = grokdeclarator (declarator, declspecs, FIELD, false,
5497 width ? &width : NULL, decl_attrs, 6604 width ? &width : NULL, decl_attrs, NULL, NULL,
5498 DEPRECATED_NORMAL); 6605 DEPRECATED_NORMAL);
5499 6606
5500 finish_decl (value, NULL_TREE, NULL_TREE); 6607 finish_decl (value, loc, NULL_TREE, NULL_TREE, NULL_TREE);
5501 DECL_INITIAL (value) = width; 6608 DECL_INITIAL (value) = width;
6609
6610 if (warn_cxx_compat && DECL_NAME (value) != NULL_TREE)
6611 {
6612 /* If we currently have a binding for this field, set the
6613 in_struct field in the binding, so that we warn about lookups
6614 which find it. */
6615 struct c_binding *b = I_SYMBOL_BINDING (DECL_NAME (value));
6616 if (b != NULL)
6617 {
6618 /* If the in_struct field is not yet set, push it on a list
6619 to be cleared when this struct is finished. */
6620 if (!b->in_struct)
6621 {
6622 VEC_safe_push (c_binding_ptr, heap,
6623 struct_parse_info->fields, b);
6624 b->in_struct = 1;
6625 }
6626 }
6627 }
5502 6628
5503 return value; 6629 return value;
5504 } 6630 }
5505 6631
5506 /* Generate an error for any duplicate field names in FIELDLIST. Munge 6632 /* Generate an error for any duplicate field names in FIELDLIST. Munge
5527 /* If there were "few" fields, avoid the overhead of allocating 6653 /* If there were "few" fields, avoid the overhead of allocating
5528 a hash table. Instead just do the nested traversal thing. */ 6654 a hash table. Instead just do the nested traversal thing. */
5529 if (timeout > 0) 6655 if (timeout > 0)
5530 { 6656 {
5531 for (x = TREE_CHAIN (fieldlist); x ; x = TREE_CHAIN (x)) 6657 for (x = TREE_CHAIN (fieldlist); x ; x = TREE_CHAIN (x))
5532 if (DECL_NAME (x)) 6658 if (DECL_NAME (x))
5533 { 6659 {
5534 for (y = fieldlist; y != x; y = TREE_CHAIN (y)) 6660 for (y = fieldlist; y != x; y = TREE_CHAIN (y))
5535 if (DECL_NAME (y) == DECL_NAME (x)) 6661 if (DECL_NAME (y) == DECL_NAME (x))
5536 { 6662 {
5537 error ("duplicate member %q+D", x); 6663 error ("duplicate member %q+D", x);
5538 DECL_NAME (x) = NULL_TREE; 6664 DECL_NAME (x) = NULL_TREE;
5539 } 6665 }
5540 } 6666 }
5541 } 6667 }
5542 else 6668 else
5543 { 6669 {
5544 htab_t htab = htab_create (37, htab_hash_pointer, htab_eq_pointer, NULL); 6670 htab_t htab = htab_create (37, htab_hash_pointer, htab_eq_pointer, NULL);
5545 void **slot; 6671 void **slot;
5546 6672
5547 for (x = fieldlist; x ; x = TREE_CHAIN (x)) 6673 for (x = fieldlist; x ; x = TREE_CHAIN (x))
5548 if ((y = DECL_NAME (x)) != 0) 6674 if ((y = DECL_NAME (x)) != 0)
5549 { 6675 {
5550 slot = htab_find_slot (htab, y, INSERT); 6676 slot = htab_find_slot (htab, y, INSERT);
5551 if (*slot) 6677 if (*slot)
5552 { 6678 {
5553 error ("duplicate member %q+D", x); 6679 error ("duplicate member %q+D", x);
5554 DECL_NAME (x) = NULL_TREE; 6680 DECL_NAME (x) = NULL_TREE;
5555 } 6681 }
5556 *slot = y; 6682 *slot = y;
5557 } 6683 }
5558 6684
5559 htab_delete (htab); 6685 htab_delete (htab);
5560 } 6686 }
5561 } 6687 }
5562 6688
6689 /* Finish up struct info used by -Wc++-compat. */
6690
6691 static void
6692 warn_cxx_compat_finish_struct (tree fieldlist)
6693 {
6694 unsigned int ix;
6695 tree x;
6696 struct c_binding *b;
6697
6698 /* Set the C_TYPE_DEFINED_IN_STRUCT flag for each type defined in
6699 the current struct. We do this now at the end of the struct
6700 because the flag is used to issue visibility warnings, and we
6701 only want to issue those warnings if the type is referenced
6702 outside of the struct declaration. */
6703 for (ix = 0; VEC_iterate (tree, struct_parse_info->struct_types, ix, x); ++ix)
6704 C_TYPE_DEFINED_IN_STRUCT (x) = 1;
6705
6706 /* The TYPEDEFS_SEEN field of STRUCT_PARSE_INFO is a list of
6707 typedefs used when declaring fields in this struct. If the name
6708 of any of the fields is also a typedef name then the struct would
6709 not parse in C++, because the C++ lookup rules say that the
6710 typedef name would be looked up in the context of the struct, and
6711 would thus be the field rather than the typedef. */
6712 if (!VEC_empty (tree, struct_parse_info->typedefs_seen)
6713 && fieldlist != NULL_TREE)
6714 {
6715 /* Use a pointer_set using the name of the typedef. We can use
6716 a pointer_set because identifiers are interned. */
6717 struct pointer_set_t *tset = pointer_set_create ();
6718
6719 for (ix = 0;
6720 VEC_iterate (tree, struct_parse_info->typedefs_seen, ix, x);
6721 ++ix)
6722 pointer_set_insert (tset, DECL_NAME (x));
6723
6724 for (x = fieldlist; x != NULL_TREE; x = TREE_CHAIN (x))
6725 {
6726 if (pointer_set_contains (tset, DECL_NAME (x)))
6727 {
6728 warning_at (DECL_SOURCE_LOCATION (x), OPT_Wc___compat,
6729 ("using %qD as both field and typedef name is "
6730 "invalid in C++"),
6731 x);
6732 /* FIXME: It would be nice to report the location where
6733 the typedef name is used. */
6734 }
6735 }
6736
6737 pointer_set_destroy (tset);
6738 }
6739
6740 /* For each field which has a binding and which was not defined in
6741 an enclosing struct, clear the in_struct field. */
6742 for (ix = 0;
6743 VEC_iterate (c_binding_ptr, struct_parse_info->fields, ix, b);
6744 ++ix)
6745 b->in_struct = 0;
6746 }
6747
5563 /* Fill in the fields of a RECORD_TYPE or UNION_TYPE node, T. 6748 /* Fill in the fields of a RECORD_TYPE or UNION_TYPE node, T.
6749 LOC is the location of the RECORD_TYPE or UNION_TYPE's definition.
5564 FIELDLIST is a chain of FIELD_DECL nodes for the fields. 6750 FIELDLIST is a chain of FIELD_DECL nodes for the fields.
5565 ATTRIBUTES are attributes to be applied to the structure. */ 6751 ATTRIBUTES are attributes to be applied to the structure.
6752
6753 ENCLOSING_STRUCT_PARSE_INFO is the value of STRUCT_PARSE_INFO when
6754 the struct was started. */
5566 6755
5567 tree 6756 tree
5568 finish_struct (tree t, tree fieldlist, tree attributes) 6757 finish_struct (location_t loc, tree t, tree fieldlist, tree attributes,
6758 struct c_struct_parse_info *enclosing_struct_parse_info)
5569 { 6759 {
5570 tree x; 6760 tree x;
5571 bool toplevel = file_scope == current_scope; 6761 bool toplevel = file_scope == current_scope;
5572 int saw_named_field; 6762 int saw_named_field;
5573 6763
5579 decl_attributes (&t, attributes, (int) ATTR_FLAG_TYPE_IN_PLACE); 6769 decl_attributes (&t, attributes, (int) ATTR_FLAG_TYPE_IN_PLACE);
5580 6770
5581 if (pedantic) 6771 if (pedantic)
5582 { 6772 {
5583 for (x = fieldlist; x; x = TREE_CHAIN (x)) 6773 for (x = fieldlist; x; x = TREE_CHAIN (x))
5584 if (DECL_NAME (x) != 0) 6774 if (DECL_NAME (x) != 0)
5585 break; 6775 break;
5586 6776
5587 if (x == 0) 6777 if (x == 0)
5588 { 6778 {
5589 if (TREE_CODE (t) == UNION_TYPE) 6779 if (TREE_CODE (t) == UNION_TYPE)
5590 { 6780 {
5591 if (fieldlist) 6781 if (fieldlist)
5592 pedwarn (input_location, OPT_pedantic, "union has no named members"); 6782 pedwarn (loc, OPT_pedantic, "union has no named members");
5593 else 6783 else
5594 pedwarn (input_location, OPT_pedantic, "union has no members"); 6784 pedwarn (loc, OPT_pedantic, "union has no members");
5595 } 6785 }
5596 else 6786 else
5597 { 6787 {
5598 if (fieldlist) 6788 if (fieldlist)
5599 pedwarn (input_location, OPT_pedantic, "struct has no named members"); 6789 pedwarn (loc, OPT_pedantic, "struct has no named members");
5600 else 6790 else
5601 pedwarn (input_location, OPT_pedantic, "struct has no members"); 6791 pedwarn (loc, OPT_pedantic, "struct has no members");
5602 } 6792 }
5603 } 6793 }
5604 } 6794 }
5605 6795
5606 /* Install struct as DECL_CONTEXT of each field decl. 6796 /* Install struct as DECL_CONTEXT of each field decl.
5607 Also process specified field sizes, found in the DECL_INITIAL, 6797 Also process specified field sizes, found in the DECL_INITIAL,
5608 storing 0 there after the type has been changed to precision equal 6798 storing 0 there after the type has been changed to precision equal
5612 6802
5613 saw_named_field = 0; 6803 saw_named_field = 0;
5614 for (x = fieldlist; x; x = TREE_CHAIN (x)) 6804 for (x = fieldlist; x; x = TREE_CHAIN (x))
5615 { 6805 {
5616 if (TREE_TYPE (x) == error_mark_node) 6806 if (TREE_TYPE (x) == error_mark_node)
5617 continue; 6807 continue;
5618 6808
5619 DECL_CONTEXT (x) = t; 6809 DECL_CONTEXT (x) = t;
5620 6810
5621 /* If any field is const, the structure type is pseudo-const. */ 6811 /* If any field is const, the structure type is pseudo-const. */
5622 if (TREE_READONLY (x)) 6812 if (TREE_READONLY (x))
5623 C_TYPE_FIELDS_READONLY (t) = 1; 6813 C_TYPE_FIELDS_READONLY (t) = 1;
5624 else 6814 else
5625 { 6815 {
5626 /* A field that is pseudo-const makes the structure likewise. */ 6816 /* A field that is pseudo-const makes the structure likewise. */
5627 tree t1 = TREE_TYPE (x); 6817 tree t1 = TREE_TYPE (x);
5628 while (TREE_CODE (t1) == ARRAY_TYPE) 6818 while (TREE_CODE (t1) == ARRAY_TYPE)
5629 t1 = TREE_TYPE (t1); 6819 t1 = TREE_TYPE (t1);
5630 if ((TREE_CODE (t1) == RECORD_TYPE || TREE_CODE (t1) == UNION_TYPE) 6820 if ((TREE_CODE (t1) == RECORD_TYPE || TREE_CODE (t1) == UNION_TYPE)
5631 && C_TYPE_FIELDS_READONLY (t1)) 6821 && C_TYPE_FIELDS_READONLY (t1))
5632 C_TYPE_FIELDS_READONLY (t) = 1; 6822 C_TYPE_FIELDS_READONLY (t) = 1;
5633 } 6823 }
5634 6824
5635 /* Any field that is volatile means variables of this type must be 6825 /* Any field that is volatile means variables of this type must be
5636 treated in some ways as volatile. */ 6826 treated in some ways as volatile. */
5637 if (TREE_THIS_VOLATILE (x)) 6827 if (TREE_THIS_VOLATILE (x))
5638 C_TYPE_FIELDS_VOLATILE (t) = 1; 6828 C_TYPE_FIELDS_VOLATILE (t) = 1;
5639 6829
5640 /* Any field of nominal variable size implies structure is too. */ 6830 /* Any field of nominal variable size implies structure is too. */
5641 if (C_DECL_VARIABLE_SIZE (x)) 6831 if (C_DECL_VARIABLE_SIZE (x))
5642 C_TYPE_VARIABLE_SIZE (t) = 1; 6832 C_TYPE_VARIABLE_SIZE (t) = 1;
5643 6833
5644 if (DECL_INITIAL (x)) 6834 if (DECL_INITIAL (x))
5645 { 6835 {
5646 unsigned HOST_WIDE_INT width = tree_low_cst (DECL_INITIAL (x), 1); 6836 unsigned HOST_WIDE_INT width = tree_low_cst (DECL_INITIAL (x), 1);
5647 DECL_SIZE (x) = bitsize_int (width); 6837 DECL_SIZE (x) = bitsize_int (width);
5648 DECL_BIT_FIELD (x) = 1; 6838 DECL_BIT_FIELD (x) = 1;
5649 SET_DECL_C_BIT_FIELD (x); 6839 SET_DECL_C_BIT_FIELD (x);
5650 } 6840 }
5651 6841
5652 if (TYPE_PACKED (t) 6842 if (TYPE_PACKED (t)
5653 && (DECL_BIT_FIELD (x) 6843 && (DECL_BIT_FIELD (x)
5654 || TYPE_ALIGN (TREE_TYPE (x)) > BITS_PER_UNIT)) 6844 || TYPE_ALIGN (TREE_TYPE (x)) > BITS_PER_UNIT))
5655 DECL_PACKED (x) = 1; 6845 DECL_PACKED (x) = 1;
5656 6846
5657 /* Detect flexible array member in an invalid context. */ 6847 /* Detect flexible array member in an invalid context. */
5658 if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE 6848 if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE
5659 && TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE 6849 && TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE
5660 && TYPE_DOMAIN (TREE_TYPE (x)) != NULL_TREE 6850 && TYPE_DOMAIN (TREE_TYPE (x)) != NULL_TREE
5661 && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (x))) == NULL_TREE) 6851 && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (x))) == NULL_TREE)
5662 { 6852 {
5663 if (TREE_CODE (t) == UNION_TYPE) 6853 if (TREE_CODE (t) == UNION_TYPE)
5664 { 6854 {
5665 error ("%Jflexible array member in union", x); 6855 error_at (DECL_SOURCE_LOCATION (x),
5666 TREE_TYPE (x) = error_mark_node; 6856 "flexible array member in union");
5667 } 6857 TREE_TYPE (x) = error_mark_node;
5668 else if (TREE_CHAIN (x) != NULL_TREE) 6858 }
5669 { 6859 else if (TREE_CHAIN (x) != NULL_TREE)
5670 error ("%Jflexible array member not at end of struct", x); 6860 {
5671 TREE_TYPE (x) = error_mark_node; 6861 error_at (DECL_SOURCE_LOCATION (x),
5672 } 6862 "flexible array member not at end of struct");
5673 else if (!saw_named_field) 6863 TREE_TYPE (x) = error_mark_node;
5674 { 6864 }
5675 error ("%Jflexible array member in otherwise empty struct", x); 6865 else if (!saw_named_field)
5676 TREE_TYPE (x) = error_mark_node; 6866 {
5677 } 6867 error_at (DECL_SOURCE_LOCATION (x),
5678 } 6868 "flexible array member in otherwise empty struct");
5679 6869 TREE_TYPE (x) = error_mark_node;
5680 if (pedantic && !in_system_header && TREE_CODE (t) == RECORD_TYPE 6870 }
5681 && flexible_array_type_p (TREE_TYPE (x))) 6871 }
5682 pedwarn (input_location, OPT_pedantic, 6872
5683 "%Jinvalid use of structure with flexible array member", x); 6873 if (pedantic && TREE_CODE (t) == RECORD_TYPE
6874 && flexible_array_type_p (TREE_TYPE (x)))
6875 pedwarn (DECL_SOURCE_LOCATION (x), OPT_pedantic,
6876 "invalid use of structure with flexible array member");
5684 6877
5685 if (DECL_NAME (x)) 6878 if (DECL_NAME (x))
5686 saw_named_field = 1; 6879 saw_named_field = 1;
5687 } 6880 }
5688 6881
5689 detect_field_duplicates (fieldlist); 6882 detect_field_duplicates (fieldlist);
5690 6883
5691 /* Now we have the nearly final fieldlist. Record it, 6884 /* Now we have the nearly final fieldlist. Record it,
5698 /* Give bit-fields their proper types. */ 6891 /* Give bit-fields their proper types. */
5699 { 6892 {
5700 tree *fieldlistp = &fieldlist; 6893 tree *fieldlistp = &fieldlist;
5701 while (*fieldlistp) 6894 while (*fieldlistp)
5702 if (TREE_CODE (*fieldlistp) == FIELD_DECL && DECL_INITIAL (*fieldlistp) 6895 if (TREE_CODE (*fieldlistp) == FIELD_DECL && DECL_INITIAL (*fieldlistp)
5703 && TREE_TYPE (*fieldlistp) != error_mark_node) 6896 && TREE_TYPE (*fieldlistp) != error_mark_node)
5704 { 6897 {
5705 unsigned HOST_WIDE_INT width 6898 unsigned HOST_WIDE_INT width
5706 = tree_low_cst (DECL_INITIAL (*fieldlistp), 1); 6899 = tree_low_cst (DECL_INITIAL (*fieldlistp), 1);
5707 tree type = TREE_TYPE (*fieldlistp); 6900 tree type = TREE_TYPE (*fieldlistp);
5708 if (width != TYPE_PRECISION (type)) 6901 if (width != TYPE_PRECISION (type))
5709 { 6902 {
5710 TREE_TYPE (*fieldlistp) 6903 TREE_TYPE (*fieldlistp)
5711 = c_build_bitfield_integer_type (width, TYPE_UNSIGNED (type)); 6904 = c_build_bitfield_integer_type (width, TYPE_UNSIGNED (type));
5712 DECL_MODE (*fieldlistp) = TYPE_MODE (TREE_TYPE (*fieldlistp)); 6905 DECL_MODE (*fieldlistp) = TYPE_MODE (TREE_TYPE (*fieldlistp));
5713 } 6906 }
5714 DECL_INITIAL (*fieldlistp) = 0; 6907 DECL_INITIAL (*fieldlistp) = 0;
5715 } 6908 }
5716 else 6909 else
5717 fieldlistp = &TREE_CHAIN (*fieldlistp); 6910 fieldlistp = &TREE_CHAIN (*fieldlistp);
5718 } 6911 }
5719 6912
5720 /* Now we have the truly final field list. 6913 /* Now we have the truly final field list.
5721 Store it in this type and in the variants. */ 6914 Store it in this type and in the variants. */
5722 6915
5728 { 6921 {
5729 int len = 0; 6922 int len = 0;
5730 6923
5731 for (x = fieldlist; x; x = TREE_CHAIN (x)) 6924 for (x = fieldlist; x; x = TREE_CHAIN (x))
5732 { 6925 {
5733 if (len > 15 || DECL_NAME (x) == NULL) 6926 if (len > 15 || DECL_NAME (x) == NULL)
5734 break; 6927 break;
5735 len += 1; 6928 len += 1;
5736 } 6929 }
5737 6930
5738 if (len > 15) 6931 if (len > 15)
5739 { 6932 {
5740 tree *field_array; 6933 tree *field_array;
5741 struct lang_type *space; 6934 struct lang_type *space;
5742 struct sorted_fields_type *space2; 6935 struct sorted_fields_type *space2;
5743 6936
5744 len += list_length (x); 6937 len += list_length (x);
5745 6938
5746 /* Use the same allocation policy here that make_node uses, to 6939 /* Use the same allocation policy here that make_node uses, to
5747 ensure that this lives as long as the rest of the struct decl. 6940 ensure that this lives as long as the rest of the struct decl.
5748 All decls in an inline function need to be saved. */ 6941 All decls in an inline function need to be saved. */
5749 6942
5750 space = GGC_CNEW (struct lang_type); 6943 space = GGC_CNEW (struct lang_type);
5751 space2 = GGC_NEWVAR (struct sorted_fields_type, 6944 space2 = GGC_NEWVAR (struct sorted_fields_type,
5752 sizeof (struct sorted_fields_type) + len * sizeof (tree)); 6945 sizeof (struct sorted_fields_type) + len * sizeof (tree));
5753 6946
5754 len = 0; 6947 len = 0;
5755 space->s = space2; 6948 space->s = space2;
5756 field_array = &space2->elts[0]; 6949 field_array = &space2->elts[0];
5757 for (x = fieldlist; x; x = TREE_CHAIN (x)) 6950 for (x = fieldlist; x; x = TREE_CHAIN (x))
5758 { 6951 {
5759 field_array[len++] = x; 6952 field_array[len++] = x;
5760 6953
5761 /* If there is anonymous struct or union, break out of the loop. */ 6954 /* If there is anonymous struct or union, break out of the loop. */
5762 if (DECL_NAME (x) == NULL) 6955 if (DECL_NAME (x) == NULL)
5763 break; 6956 break;
5764 } 6957 }
5765 /* Found no anonymous struct/union. Add the TYPE_LANG_SPECIFIC. */ 6958 /* Found no anonymous struct/union. Add the TYPE_LANG_SPECIFIC. */
5766 if (x == NULL) 6959 if (x == NULL)
5767 { 6960 {
5768 TYPE_LANG_SPECIFIC (t) = space; 6961 TYPE_LANG_SPECIFIC (t) = space;
5769 TYPE_LANG_SPECIFIC (t)->s->len = len; 6962 TYPE_LANG_SPECIFIC (t)->s->len = len;
5770 field_array = TYPE_LANG_SPECIFIC (t)->s->elts; 6963 field_array = TYPE_LANG_SPECIFIC (t)->s->elts;
5771 qsort (field_array, len, sizeof (tree), field_decl_cmp); 6964 qsort (field_array, len, sizeof (tree), field_decl_cmp);
5772 } 6965 }
5773 } 6966 }
5774 } 6967 }
5775 6968
5776 for (x = TYPE_MAIN_VARIANT (t); x; x = TYPE_NEXT_VARIANT (x)) 6969 for (x = TYPE_MAIN_VARIANT (t); x; x = TYPE_NEXT_VARIANT (x))
5777 { 6970 {
5787 if (TREE_CODE (t) == UNION_TYPE 6980 if (TREE_CODE (t) == UNION_TYPE
5788 && TYPE_TRANSPARENT_UNION (t) 6981 && TYPE_TRANSPARENT_UNION (t)
5789 && (!TYPE_FIELDS (t) || TYPE_MODE (t) != DECL_MODE (TYPE_FIELDS (t)))) 6982 && (!TYPE_FIELDS (t) || TYPE_MODE (t) != DECL_MODE (TYPE_FIELDS (t))))
5790 { 6983 {
5791 TYPE_TRANSPARENT_UNION (t) = 0; 6984 TYPE_TRANSPARENT_UNION (t) = 0;
5792 warning (0, "union cannot be made transparent"); 6985 warning_at (loc, 0, "union cannot be made transparent");
5793 } 6986 }
5794 6987
5795 /* If this structure or union completes the type of any previous 6988 /* If this structure or union completes the type of any previous
5796 variable declaration, lay it out and output its rtl. */ 6989 variable declaration, lay it out and output its rtl. */
5797 for (x = C_TYPE_INCOMPLETE_VARS (TYPE_MAIN_VARIANT (t)); 6990 for (x = C_TYPE_INCOMPLETE_VARS (TYPE_MAIN_VARIANT (t));
5798 x; 6991 x;
5799 x = TREE_CHAIN (x)) 6992 x = TREE_CHAIN (x))
5800 { 6993 {
5801 tree decl = TREE_VALUE (x); 6994 tree decl = TREE_VALUE (x);
5802 if (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE) 6995 if (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
5803 layout_array_type (TREE_TYPE (decl)); 6996 layout_array_type (TREE_TYPE (decl));
5804 if (TREE_CODE (decl) != TYPE_DECL) 6997 if (TREE_CODE (decl) != TYPE_DECL)
5805 { 6998 {
5806 layout_decl (decl, 0); 6999 layout_decl (decl, 0);
5807 if (c_dialect_objc ()) 7000 if (c_dialect_objc ())
5808 objc_check_decl (decl); 7001 objc_check_decl (decl);
5809 rest_of_decl_compilation (decl, toplevel, 0); 7002 rest_of_decl_compilation (decl, toplevel, 0);
5810 if (!toplevel) 7003 if (!toplevel)
5811 expand_decl (decl); 7004 expand_decl (decl);
5812 } 7005 }
5813 } 7006 }
5814 C_TYPE_INCOMPLETE_VARS (TYPE_MAIN_VARIANT (t)) = 0; 7007 C_TYPE_INCOMPLETE_VARS (TYPE_MAIN_VARIANT (t)) = 0;
7008
7009 /* Update type location to the one of the definition, instead of e.g.
7010 a forward declaration. */
7011 if (TYPE_STUB_DECL (t))
7012 DECL_SOURCE_LOCATION (TYPE_STUB_DECL (t)) = loc;
5815 7013
5816 /* Finish debugging output for this type. */ 7014 /* Finish debugging output for this type. */
5817 rest_of_type_compilation (t, toplevel); 7015 rest_of_type_compilation (t, toplevel);
5818 7016
5819 /* If we're inside a function proper, i.e. not file-scope and not still 7017 /* If we're inside a function proper, i.e. not file-scope and not still
5820 parsing parameters, then arrange for the size of a variable sized type 7018 parsing parameters, then arrange for the size of a variable sized type
5821 to be bound now. */ 7019 to be bound now. */
5822 if (cur_stmt_list && variably_modified_type_p (t, NULL_TREE)) 7020 if (cur_stmt_list && variably_modified_type_p (t, NULL_TREE))
5823 add_stmt (build_stmt (DECL_EXPR, build_decl (TYPE_DECL, NULL, t))); 7021 add_stmt (build_stmt (loc,
7022 DECL_EXPR, build_decl (loc, TYPE_DECL, NULL, t)));
7023
7024 if (warn_cxx_compat)
7025 warn_cxx_compat_finish_struct (fieldlist);
7026
7027 VEC_free (tree, heap, struct_parse_info->struct_types);
7028 VEC_free (c_binding_ptr, heap, struct_parse_info->fields);
7029 VEC_free (tree, heap, struct_parse_info->typedefs_seen);
7030 XDELETE (struct_parse_info);
7031
7032 struct_parse_info = enclosing_struct_parse_info;
7033
7034 /* If this struct is defined inside a struct, add it to
7035 struct_types. */
7036 if (warn_cxx_compat
7037 && struct_parse_info != NULL
7038 && !in_sizeof && !in_typeof && !in_alignof)
7039 VEC_safe_push (tree, heap, struct_parse_info->struct_types, t);
5824 7040
5825 return t; 7041 return t;
5826 } 7042 }
5827 7043
5828 /* Lay out the type T, and its element type, and so on. */ 7044 /* Lay out the type T, and its element type, and so on. */
5835 layout_type (t); 7051 layout_type (t);
5836 } 7052 }
5837 7053
5838 /* Begin compiling the definition of an enumeration type. 7054 /* Begin compiling the definition of an enumeration type.
5839 NAME is its name (or null if anonymous). 7055 NAME is its name (or null if anonymous).
7056 LOC is the enum's location.
5840 Returns the type object, as yet incomplete. 7057 Returns the type object, as yet incomplete.
5841 Also records info about it so that build_enumerator 7058 Also records info about it so that build_enumerator
5842 may be used to declare the individual values as they are read. */ 7059 may be used to declare the individual values as they are read. */
5843 7060
5844 tree 7061 tree
5845 start_enum (struct c_enum_contents *the_enum, tree name) 7062 start_enum (location_t loc, struct c_enum_contents *the_enum, tree name)
5846 { 7063 {
5847 tree enumtype = 0; 7064 tree enumtype = NULL_TREE;
7065 location_t enumloc = UNKNOWN_LOCATION;
5848 7066
5849 /* If this is the real definition for a previous forward reference, 7067 /* If this is the real definition for a previous forward reference,
5850 fill in the contents in the same object that used to be the 7068 fill in the contents in the same object that used to be the
5851 forward reference. */ 7069 forward reference. */
5852 7070
5853 if (name != 0) 7071 if (name != NULL_TREE)
5854 enumtype = lookup_tag (ENUMERAL_TYPE, name, 1); 7072 enumtype = lookup_tag (ENUMERAL_TYPE, name, 1, &enumloc);
5855 7073
5856 if (enumtype == 0 || TREE_CODE (enumtype) != ENUMERAL_TYPE) 7074 if (enumtype == 0 || TREE_CODE (enumtype) != ENUMERAL_TYPE)
5857 { 7075 {
5858 enumtype = make_node (ENUMERAL_TYPE); 7076 enumtype = make_node (ENUMERAL_TYPE);
5859 pushtag (name, enumtype); 7077 pushtag (loc, name, enumtype);
5860 } 7078 }
5861 7079
5862 if (C_TYPE_BEING_DEFINED (enumtype)) 7080 if (C_TYPE_BEING_DEFINED (enumtype))
5863 error ("nested redefinition of %<enum %E%>", name); 7081 error_at (loc, "nested redefinition of %<enum %E%>", name);
5864 7082
5865 C_TYPE_BEING_DEFINED (enumtype) = 1; 7083 C_TYPE_BEING_DEFINED (enumtype) = 1;
5866 7084
5867 if (TYPE_VALUES (enumtype) != 0) 7085 if (TYPE_VALUES (enumtype) != 0)
5868 { 7086 {
5869 /* This enum is a named one that has been declared already. */ 7087 /* This enum is a named one that has been declared already. */
5870 error ("redeclaration of %<enum %E%>", name); 7088 error_at (loc, "redeclaration of %<enum %E%>", name);
7089 if (enumloc != UNKNOWN_LOCATION)
7090 inform (enumloc, "originally defined here");
5871 7091
5872 /* Completely replace its old definition. 7092 /* Completely replace its old definition.
5873 The old enumerators remain defined, however. */ 7093 The old enumerators remain defined, however. */
5874 TYPE_VALUES (enumtype) = 0; 7094 TYPE_VALUES (enumtype) = 0;
5875 } 7095 }
5876 7096
5877 the_enum->enum_next_value = integer_zero_node; 7097 the_enum->enum_next_value = integer_zero_node;
5878 the_enum->enum_overflow = 0; 7098 the_enum->enum_overflow = 0;
5879 7099
5880 if (flag_short_enums) 7100 if (flag_short_enums)
5881 TYPE_PACKED (enumtype) = 1; 7101 TYPE_PACKED (enumtype) = 1;
7102
7103 /* FIXME: This will issue a warning for a use of a type defined
7104 within sizeof in a statement expr. This is not terribly serious
7105 as C++ doesn't permit statement exprs within sizeof anyhow. */
7106 if (warn_cxx_compat && (in_sizeof || in_typeof || in_alignof))
7107 warning_at (loc, OPT_Wc___compat,
7108 "defining type in %qs expression is invalid in C++",
7109 (in_sizeof
7110 ? "sizeof"
7111 : (in_typeof ? "typeof" : "alignof")));
5882 7112
5883 return enumtype; 7113 return enumtype;
5884 } 7114 }
5885 7115
5886 /* After processing and defining all the values of an enumeration type, 7116 /* After processing and defining all the values of an enumeration type,
5906 minnode = maxnode = integer_zero_node; 7136 minnode = maxnode = integer_zero_node;
5907 else 7137 else
5908 { 7138 {
5909 minnode = maxnode = TREE_VALUE (values); 7139 minnode = maxnode = TREE_VALUE (values);
5910 for (pair = TREE_CHAIN (values); pair; pair = TREE_CHAIN (pair)) 7140 for (pair = TREE_CHAIN (values); pair; pair = TREE_CHAIN (pair))
5911 { 7141 {
5912 tree value = TREE_VALUE (pair); 7142 tree value = TREE_VALUE (pair);
5913 if (tree_int_cst_lt (maxnode, value)) 7143 if (tree_int_cst_lt (maxnode, value))
5914 maxnode = value; 7144 maxnode = value;
5915 if (tree_int_cst_lt (value, minnode)) 7145 if (tree_int_cst_lt (value, minnode))
5916 minnode = value; 7146 minnode = value;
5917 } 7147 }
5918 } 7148 }
5919 7149
5920 /* Construct the final type of this enumeration. It is the same 7150 /* Construct the final type of this enumeration. It is the same
5921 as one of the integral types - the narrowest one that fits, except 7151 as one of the integral types - the narrowest one that fits, except
5922 that normally we only go as narrow as int - and signed iff any of 7152 that normally we only go as narrow as int - and signed iff any of
5923 the values are negative. */ 7153 the values are negative. */
5924 unsign = (tree_int_cst_sgn (minnode) >= 0); 7154 unsign = (tree_int_cst_sgn (minnode) >= 0);
5925 precision = MAX (tree_int_cst_min_precision (minnode, unsign), 7155 precision = MAX (tree_int_cst_min_precision (minnode, unsign),
5926 tree_int_cst_min_precision (maxnode, unsign)); 7156 tree_int_cst_min_precision (maxnode, unsign));
5927 7157
5928 if (TYPE_PACKED (enumtype) || precision > TYPE_PRECISION (integer_type_node)) 7158 if (TYPE_PACKED (enumtype) || precision > TYPE_PRECISION (integer_type_node))
5929 { 7159 {
5930 tem = c_common_type_for_size (precision, unsign); 7160 tem = c_common_type_for_size (precision, unsign);
5931 if (tem == NULL) 7161 if (tem == NULL)
5932 { 7162 {
5933 warning (0, "enumeration values exceed range of largest integer"); 7163 warning (0, "enumeration values exceed range of largest integer");
5934 tem = long_long_integer_type_node; 7164 tem = long_long_integer_type_node;
5935 } 7165 }
5936 } 7166 }
5937 else 7167 else
5938 tem = unsign ? unsigned_type_node : integer_type_node; 7168 tem = unsign ? unsigned_type_node : integer_type_node;
5939 7169
5940 TYPE_MIN_VALUE (enumtype) = TYPE_MIN_VALUE (tem); 7170 TYPE_MIN_VALUE (enumtype) = TYPE_MIN_VALUE (tem);
5945 /* If the precision of the type was specific with an attribute and it 7175 /* If the precision of the type was specific with an attribute and it
5946 was too small, give an error. Otherwise, use it. */ 7176 was too small, give an error. Otherwise, use it. */
5947 if (TYPE_PRECISION (enumtype)) 7177 if (TYPE_PRECISION (enumtype))
5948 { 7178 {
5949 if (precision > TYPE_PRECISION (enumtype)) 7179 if (precision > TYPE_PRECISION (enumtype))
5950 error ("specified mode too small for enumeral values"); 7180 error ("specified mode too small for enumeral values");
5951 } 7181 }
5952 else 7182 else
5953 TYPE_PRECISION (enumtype) = TYPE_PRECISION (tem); 7183 TYPE_PRECISION (enumtype) = TYPE_PRECISION (tem);
5954 7184
5955 layout_type (enumtype); 7185 layout_type (enumtype);
5956 7186
5957 if (values != error_mark_node) 7187 if (values != error_mark_node)
5958 { 7188 {
5959 /* Change the type of the enumerators to be the enum type. We 7189 /* Change the type of the enumerators to be the enum type. We
5960 need to do this irrespective of the size of the enum, for 7190 need to do this irrespective of the size of the enum, for
5961 proper type checking. Replace the DECL_INITIALs of the 7191 proper type checking. Replace the DECL_INITIALs of the
5962 enumerators, and the value slots of the list, with copies 7192 enumerators, and the value slots of the list, with copies
5963 that have the enum type; they cannot be modified in place 7193 that have the enum type; they cannot be modified in place
5964 because they may be shared (e.g. integer_zero_node) Finally, 7194 because they may be shared (e.g. integer_zero_node) Finally,
5965 change the purpose slots to point to the names of the decls. */ 7195 change the purpose slots to point to the names of the decls. */
5966 for (pair = values; pair; pair = TREE_CHAIN (pair)) 7196 for (pair = values; pair; pair = TREE_CHAIN (pair))
5967 { 7197 {
5968 tree enu = TREE_PURPOSE (pair); 7198 tree enu = TREE_PURPOSE (pair);
5969 tree ini = DECL_INITIAL (enu); 7199 tree ini = DECL_INITIAL (enu);
5970 7200
5971 TREE_TYPE (enu) = enumtype; 7201 TREE_TYPE (enu) = enumtype;
5972 7202
5973 /* The ISO C Standard mandates enumerators to have type int, 7203 /* The ISO C Standard mandates enumerators to have type int,
5974 even though the underlying type of an enum type is 7204 even though the underlying type of an enum type is
5975 unspecified. However, GCC allows enumerators of any 7205 unspecified. However, GCC allows enumerators of any
5976 integer type as an extensions. build_enumerator() 7206 integer type as an extensions. build_enumerator()
5977 converts any enumerators that fit in an int to type int, 7207 converts any enumerators that fit in an int to type int,
5978 to avoid promotions to unsigned types when comparing 7208 to avoid promotions to unsigned types when comparing
5979 integers with enumerators that fit in the int range. 7209 integers with enumerators that fit in the int range.
5980 When -pedantic is given, build_enumerator() would have 7210 When -pedantic is given, build_enumerator() would have
5981 already warned about those that don't fit. Here we 7211 already warned about those that don't fit. Here we
5982 convert the rest to the enumerator type. */ 7212 convert the rest to the enumerator type. */
5983 if (TREE_TYPE (ini) != integer_type_node) 7213 if (TREE_TYPE (ini) != integer_type_node)
5984 ini = convert (enumtype, ini); 7214 ini = convert (enumtype, ini);
5985 7215
5986 DECL_INITIAL (enu) = ini; 7216 DECL_INITIAL (enu) = ini;
5987 TREE_PURPOSE (pair) = DECL_NAME (enu); 7217 TREE_PURPOSE (pair) = DECL_NAME (enu);
5988 TREE_VALUE (pair) = ini; 7218 TREE_VALUE (pair) = ini;
5989 } 7219 }
5990 7220
5991 TYPE_VALUES (enumtype) = values; 7221 TYPE_VALUES (enumtype) = values;
5992 } 7222 }
5993 7223
5994 /* Record the min/max values so that we can warn about bit-field 7224 /* Record the min/max values so that we can warn about bit-field
6000 7230
6001 /* Fix up all variant types of this enum type. */ 7231 /* Fix up all variant types of this enum type. */
6002 for (tem = TYPE_MAIN_VARIANT (enumtype); tem; tem = TYPE_NEXT_VARIANT (tem)) 7232 for (tem = TYPE_MAIN_VARIANT (enumtype); tem; tem = TYPE_NEXT_VARIANT (tem))
6003 { 7233 {
6004 if (tem == enumtype) 7234 if (tem == enumtype)
6005 continue; 7235 continue;
6006 TYPE_VALUES (tem) = TYPE_VALUES (enumtype); 7236 TYPE_VALUES (tem) = TYPE_VALUES (enumtype);
6007 TYPE_MIN_VALUE (tem) = TYPE_MIN_VALUE (enumtype); 7237 TYPE_MIN_VALUE (tem) = TYPE_MIN_VALUE (enumtype);
6008 TYPE_MAX_VALUE (tem) = TYPE_MAX_VALUE (enumtype); 7238 TYPE_MAX_VALUE (tem) = TYPE_MAX_VALUE (enumtype);
6009 TYPE_SIZE (tem) = TYPE_SIZE (enumtype); 7239 TYPE_SIZE (tem) = TYPE_SIZE (enumtype);
6010 TYPE_SIZE_UNIT (tem) = TYPE_SIZE_UNIT (enumtype); 7240 TYPE_SIZE_UNIT (tem) = TYPE_SIZE_UNIT (enumtype);
6017 } 7247 }
6018 7248
6019 /* Finish debugging output for this type. */ 7249 /* Finish debugging output for this type. */
6020 rest_of_type_compilation (enumtype, toplevel); 7250 rest_of_type_compilation (enumtype, toplevel);
6021 7251
7252 /* If this enum is defined inside a struct, add it to
7253 struct_types. */
7254 if (warn_cxx_compat
7255 && struct_parse_info != NULL
7256 && !in_sizeof && !in_typeof && !in_alignof)
7257 VEC_safe_push (tree, heap, struct_parse_info->struct_types, enumtype);
7258
6022 return enumtype; 7259 return enumtype;
6023 } 7260 }
6024 7261
6025 /* Build and install a CONST_DECL for one value of the 7262 /* Build and install a CONST_DECL for one value of the
6026 current enumeration type (one that was begun with start_enum). 7263 current enumeration type (one that was begun with start_enum).
7264 LOC is the location of the enumerator.
6027 Return a tree-list containing the CONST_DECL and its value. 7265 Return a tree-list containing the CONST_DECL and its value.
6028 Assignment of sequential values by default is handled here. */ 7266 Assignment of sequential values by default is handled here. */
6029 7267
6030 tree 7268 tree
6031 build_enumerator (struct c_enum_contents *the_enum, tree name, tree value, 7269 build_enumerator (location_t loc,
6032 location_t value_loc) 7270 struct c_enum_contents *the_enum, tree name, tree value)
6033 { 7271 {
6034 tree decl, type; 7272 tree decl, type;
6035 7273
6036 /* Validate and default VALUE. */ 7274 /* Validate and default VALUE. */
6037 7275
6038 if (value != 0) 7276 if (value != 0)
6039 { 7277 {
6040 /* Don't issue more errors for error_mark_node (i.e. an 7278 /* Don't issue more errors for error_mark_node (i.e. an
6041 undeclared identifier) - just ignore the value expression. */ 7279 undeclared identifier) - just ignore the value expression. */
6042 if (value == error_mark_node) 7280 if (value == error_mark_node)
6043 value = 0; 7281 value = 0;
6044 else if (!INTEGRAL_TYPE_P (TREE_TYPE (value)) 7282 else if (!INTEGRAL_TYPE_P (TREE_TYPE (value)))
6045 || TREE_CODE (value) != INTEGER_CST) 7283 {
6046 { 7284 error_at (loc, "enumerator value for %qE is not an integer constant",
6047 error ("enumerator value for %qE is not an integer constant", name); 7285 name);
6048 value = 0; 7286 value = 0;
6049 } 7287 }
6050 else 7288 else
6051 { 7289 {
6052 value = default_conversion (value); 7290 if (TREE_CODE (value) != INTEGER_CST)
6053 constant_expression_warning (value); 7291 {
6054 } 7292 value = c_fully_fold (value, false, NULL);
7293 if (TREE_CODE (value) == INTEGER_CST)
7294 pedwarn (loc, OPT_pedantic,
7295 "enumerator value for %qE is not an integer "
7296 "constant expression", name);
7297 }
7298 if (TREE_CODE (value) != INTEGER_CST)
7299 {
7300 error ("enumerator value for %qE is not an integer constant",
7301 name);
7302 value = 0;
7303 }
7304 else
7305 {
7306 value = default_conversion (value);
7307 constant_expression_warning (value);
7308 }
7309 }
6055 } 7310 }
6056 7311
6057 /* Default based on previous value. */ 7312 /* Default based on previous value. */
6058 /* It should no longer be possible to have NON_LVALUE_EXPR 7313 /* It should no longer be possible to have NON_LVALUE_EXPR
6059 in the default. */ 7314 in the default. */
6060 if (value == 0) 7315 if (value == 0)
6061 { 7316 {
6062 value = the_enum->enum_next_value; 7317 value = the_enum->enum_next_value;
6063 if (the_enum->enum_overflow) 7318 if (the_enum->enum_overflow)
6064 error ("overflow in enumeration values"); 7319 error_at (loc, "overflow in enumeration values");
6065 } 7320 }
6066 /* Even though the underlying type of an enum is unspecified, the 7321 /* Even though the underlying type of an enum is unspecified, the
6067 type of enumeration constants is explicitly defined as int 7322 type of enumeration constants is explicitly defined as int
6068 (6.4.4.3/2 in the C99 Standard). GCC allows any integer type as 7323 (6.4.4.3/2 in the C99 Standard). GCC allows any integer type as
6069 an extension. */ 7324 an extension. */
6070 else if (!int_fits_type_p (value, integer_type_node)) 7325 else if (!int_fits_type_p (value, integer_type_node))
6071 pedwarn (value_loc, OPT_pedantic, 7326 pedwarn (loc, OPT_pedantic,
6072 "ISO C restricts enumerator values to range of %<int%>"); 7327 "ISO C restricts enumerator values to range of %<int%>");
6073 7328
6074 /* The ISO C Standard mandates enumerators to have type int, even 7329 /* The ISO C Standard mandates enumerators to have type int, even
6075 though the underlying type of an enum type is unspecified. 7330 though the underlying type of an enum type is unspecified.
6076 However, GCC allows enumerators of any integer type as an 7331 However, GCC allows enumerators of any integer type as an
6077 extensions. Here we convert any enumerators that fit in an int 7332 extensions. Here we convert any enumerators that fit in an int
6085 7340
6086 /* Set basis for default for next value. */ 7341 /* Set basis for default for next value. */
6087 the_enum->enum_next_value 7342 the_enum->enum_next_value
6088 = build_binary_op 7343 = build_binary_op
6089 (EXPR_HAS_LOCATION (value) ? EXPR_LOCATION (value) : input_location, 7344 (EXPR_HAS_LOCATION (value) ? EXPR_LOCATION (value) : input_location,
6090 PLUS_EXPR, value, integer_one_node, 0); 7345 PLUS_EXPR, value, integer_one_node, 0);
6091 the_enum->enum_overflow = tree_int_cst_lt (the_enum->enum_next_value, value); 7346 the_enum->enum_overflow = tree_int_cst_lt (the_enum->enum_next_value, value);
6092 7347
6093 /* Now create a declaration for the enum value name. */ 7348 /* Now create a declaration for the enum value name. */
6094 7349
6095 type = TREE_TYPE (value); 7350 type = TREE_TYPE (value);
6096 type = c_common_type_for_size (MAX (TYPE_PRECISION (type), 7351 type = c_common_type_for_size (MAX (TYPE_PRECISION (type),
6097 TYPE_PRECISION (integer_type_node)), 7352 TYPE_PRECISION (integer_type_node)),
6098 (TYPE_PRECISION (type) 7353 (TYPE_PRECISION (type)
6099 >= TYPE_PRECISION (integer_type_node) 7354 >= TYPE_PRECISION (integer_type_node)
6100 && TYPE_UNSIGNED (type))); 7355 && TYPE_UNSIGNED (type)));
6101 7356
6102 decl = build_decl (CONST_DECL, name, type); 7357 decl = build_decl (loc, CONST_DECL, name, type);
6103 DECL_INITIAL (decl) = convert (type, value); 7358 DECL_INITIAL (decl) = convert (type, value);
6104 pushdecl (decl); 7359 pushdecl (decl);
6105 7360
6106 return tree_cons (decl, value, NULL_TREE); 7361 return tree_cons (decl, value, NULL_TREE);
6107 } 7362 }
6127 tree type = args ? TREE_VALUE (args) : 0; 7382 tree type = args ? TREE_VALUE (args) : 0;
6128 tree type_size; 7383 tree type_size;
6129 unsigned int size; 7384 unsigned int size;
6130 7385
6131 if (type == void_type_node) 7386 if (type == void_type_node)
6132 break; 7387 break;
6133 7388
6134 type_size = TYPE_SIZE (type); 7389 type_size = TYPE_SIZE (type);
6135 size = TREE_INT_CST_LOW (type_size); 7390 size = TREE_INT_CST_LOW (type_size);
6136 padding_size -= size; 7391 padding_size -= size;
6137 7392
6181 (it defines a datum instead), we return 0, which tells 7436 (it defines a datum instead), we return 0, which tells
6182 yyparse to report a parse error. */ 7437 yyparse to report a parse error. */
6183 7438
6184 int 7439 int
6185 start_function (struct c_declspecs *declspecs, struct c_declarator *declarator, 7440 start_function (struct c_declspecs *declspecs, struct c_declarator *declarator,
6186 tree attributes) 7441 tree attributes)
6187 { 7442 {
6188 tree decl1, old_decl; 7443 tree decl1, old_decl;
6189 tree restype, resdecl; 7444 tree restype, resdecl;
6190 struct c_label_context_se *nstack_se; 7445 location_t loc;
6191 struct c_label_context_vm *nstack_vm;
6192 7446
6193 current_function_returns_value = 0; /* Assume, until we see it does. */ 7447 current_function_returns_value = 0; /* Assume, until we see it does. */
6194 current_function_returns_null = 0; 7448 current_function_returns_null = 0;
6195 current_function_returns_abnormally = 0; 7449 current_function_returns_abnormally = 0;
6196 warn_about_return_type = 0; 7450 warn_about_return_type = 0;
6197 c_switch_stack = NULL; 7451 c_switch_stack = NULL;
6198 7452
6199 nstack_se = XOBNEW (&parser_obstack, struct c_label_context_se);
6200 nstack_se->labels_def = NULL;
6201 nstack_se->labels_used = NULL;
6202 nstack_se->next = label_context_stack_se;
6203 label_context_stack_se = nstack_se;
6204
6205 nstack_vm = XOBNEW (&parser_obstack, struct c_label_context_vm);
6206 nstack_vm->labels_def = NULL;
6207 nstack_vm->labels_used = NULL;
6208 nstack_vm->scope = 0;
6209 nstack_vm->next = label_context_stack_vm;
6210 label_context_stack_vm = nstack_vm;
6211
6212 /* Indicate no valid break/continue context by setting these variables 7453 /* Indicate no valid break/continue context by setting these variables
6213 to some non-null, non-label value. We'll notice and emit the proper 7454 to some non-null, non-label value. We'll notice and emit the proper
6214 error message in c_finish_bc_stmt. */ 7455 error message in c_finish_bc_stmt. */
6215 c_break_label = c_cont_label = size_zero_node; 7456 c_break_label = c_cont_label = size_zero_node;
6216 7457
6217 decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, true, NULL, 7458 decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, true, NULL,
6218 &attributes, DEPRECATED_NORMAL); 7459 &attributes, NULL, NULL, DEPRECATED_NORMAL);
6219 7460
6220 #ifndef noCbC 7461 #ifndef noCbC
6221 cbc_return_f = NULL_TREE; 7462 cbc_return_f = NULL_TREE;
6222 cbc_env = NULL_TREE; 7463 cbc_env = NULL_TREE;
6223 if ( declspecs->typespec_word == cts_CbC_code ) 7464 if ( declspecs->typespec_word == cts_CbC_code )
6224 { 7465 {
6225 cbc_set_codesegment(decl1); 7466 cbc_set_codesegment(decl1);
6226 //CbC_IS_CODE_SEGMENT(TREE_TYPE(decl1)) = 1; 7467 //CbC_IS_CODE_SEGMENT(TREE_TYPE(decl1)) = 1;
6227 } 7468 }
6228 #endif 7469 #endif
6229 7470
6230 /* If the declarator is not suitable for a function definition, 7471 /* If the declarator is not suitable for a function definition,
6231 cause a syntax error. */ 7472 cause a syntax error. */
6232 if (decl1 == 0) 7473 if (decl1 == 0)
6233 { 7474 return 0;
6234 label_context_stack_se = label_context_stack_se->next; 7475
6235 label_context_stack_vm = label_context_stack_vm->next; 7476 loc = DECL_SOURCE_LOCATION (decl1);
6236 return 0;
6237 }
6238 7477
6239 decl_attributes (&decl1, attributes, 0); 7478 decl_attributes (&decl1, attributes, 0);
6240 7479
6241 if (DECL_DECLARED_INLINE_P (decl1) 7480 if (DECL_DECLARED_INLINE_P (decl1)
6242 && DECL_UNINLINABLE (decl1) 7481 && DECL_UNINLINABLE (decl1)
6243 && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl1))) 7482 && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl1)))
6244 warning (OPT_Wattributes, "inline function %q+D given attribute noinline", 7483 warning_at (loc, OPT_Wattributes,
6245 decl1); 7484 "inline function %qD given attribute noinline",
7485 decl1);
6246 7486
6247 /* Handle gnu_inline attribute. */ 7487 /* Handle gnu_inline attribute. */
6248 if (declspecs->inline_p 7488 if (declspecs->inline_p
6249 && !flag_gnu89_inline 7489 && !flag_gnu89_inline
6250 && TREE_CODE (decl1) == FUNCTION_DECL 7490 && TREE_CODE (decl1) == FUNCTION_DECL
6251 && (lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (decl1)) 7491 && (lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (decl1))
6252 || current_function_decl)) 7492 || current_function_decl))
6253 { 7493 {
6254 if (declspecs->storage_class != csc_static) 7494 if (declspecs->storage_class != csc_static)
6255 DECL_EXTERNAL (decl1) = !DECL_EXTERNAL (decl1); 7495 DECL_EXTERNAL (decl1) = !DECL_EXTERNAL (decl1);
6256 } 7496 }
6257 7497
6258 announce_function (decl1); 7498 announce_function (decl1);
6259 7499
6260 if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl1)))) 7500 if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl1))))
6261 { 7501 {
6262 error ("return type is an incomplete type"); 7502 error_at (loc, "return type is an incomplete type");
6263 /* Make it return void instead. */ 7503 /* Make it return void instead. */
6264 TREE_TYPE (decl1) 7504 TREE_TYPE (decl1)
6265 = build_function_type (void_type_node, 7505 = build_function_type (void_type_node,
6266 TYPE_ARG_TYPES (TREE_TYPE (decl1))); 7506 TYPE_ARG_TYPES (TREE_TYPE (decl1)));
6267 } 7507 }
6268 7508
6269 if (warn_about_return_type) 7509 if (warn_about_return_type)
6270 pedwarn_c99 (input_location, flag_isoc99 ? 0 7510 pedwarn_c99 (loc, flag_isoc99 ? 0
6271 : (warn_return_type ? OPT_Wreturn_type : OPT_Wimplicit_int), 7511 : (warn_return_type ? OPT_Wreturn_type : OPT_Wimplicit_int),
6272 "return type defaults to %<int%>"); 7512 "return type defaults to %<int%>");
6273 7513
6274 /* Make the init_value nonzero so pushdecl knows this is not tentative. 7514 /* Make the init_value nonzero so pushdecl knows this is not tentative.
6275 error_mark_node is replaced below (in pop_scope) with the BLOCK. */ 7515 error_mark_node is replaced below (in pop_scope) with the BLOCK. */
6276 DECL_INITIAL (decl1) = error_mark_node; 7516 DECL_INITIAL (decl1) = error_mark_node;
6277 7517
6284 current_function_prototype_built_in = false; 7524 current_function_prototype_built_in = false;
6285 current_function_prototype_arg_types = NULL_TREE; 7525 current_function_prototype_arg_types = NULL_TREE;
6286 if (TYPE_ARG_TYPES (TREE_TYPE (decl1)) == 0) 7526 if (TYPE_ARG_TYPES (TREE_TYPE (decl1)) == 0)
6287 { 7527 {
6288 if (old_decl != 0 && TREE_CODE (TREE_TYPE (old_decl)) == FUNCTION_TYPE 7528 if (old_decl != 0 && TREE_CODE (TREE_TYPE (old_decl)) == FUNCTION_TYPE
6289 && comptypes (TREE_TYPE (TREE_TYPE (decl1)), 7529 && comptypes (TREE_TYPE (TREE_TYPE (decl1)),
6290 TREE_TYPE (TREE_TYPE (old_decl)))) 7530 TREE_TYPE (TREE_TYPE (old_decl))))
6291 { 7531 {
6292 TREE_TYPE (decl1) = composite_type (TREE_TYPE (old_decl), 7532 TREE_TYPE (decl1) = composite_type (TREE_TYPE (old_decl),
6293 TREE_TYPE (decl1)); 7533 TREE_TYPE (decl1));
6294 current_function_prototype_locus = DECL_SOURCE_LOCATION (old_decl); 7534 current_function_prototype_locus = DECL_SOURCE_LOCATION (old_decl);
6295 current_function_prototype_built_in 7535 current_function_prototype_built_in
6296 = C_DECL_BUILTIN_PROTOTYPE (old_decl); 7536 = C_DECL_BUILTIN_PROTOTYPE (old_decl);
6297 current_function_prototype_arg_types 7537 current_function_prototype_arg_types
6298 = TYPE_ARG_TYPES (TREE_TYPE (decl1)); 7538 = TYPE_ARG_TYPES (TREE_TYPE (decl1));
6299 } 7539 }
6300 if (TREE_PUBLIC (decl1)) 7540 if (TREE_PUBLIC (decl1))
6301 { 7541 {
6302 /* If there is an external prototype declaration of this 7542 /* If there is an external prototype declaration of this
6303 function, record its location but do not copy information 7543 function, record its location but do not copy information
6304 to this decl. This may be an invisible declaration 7544 to this decl. This may be an invisible declaration
6305 (built-in or in a scope which has finished) or simply 7545 (built-in or in a scope which has finished) or simply
6306 have more refined argument types than any declaration 7546 have more refined argument types than any declaration
6307 found above. */ 7547 found above. */
6308 struct c_binding *b; 7548 struct c_binding *b;
6309 for (b = I_SYMBOL_BINDING (DECL_NAME (decl1)); b; b = b->shadowed) 7549 for (b = I_SYMBOL_BINDING (DECL_NAME (decl1)); b; b = b->shadowed)
6310 if (B_IN_SCOPE (b, external_scope)) 7550 if (B_IN_SCOPE (b, external_scope))
6311 break; 7551 break;
6312 if (b) 7552 if (b)
6313 { 7553 {
6314 tree ext_decl, ext_type; 7554 tree ext_decl, ext_type;
6315 ext_decl = b->decl; 7555 ext_decl = b->decl;
6316 ext_type = b->type ? b->type : TREE_TYPE (ext_decl); 7556 ext_type = b->u.type ? b->u.type : TREE_TYPE (ext_decl);
6317 if (TREE_CODE (ext_type) == FUNCTION_TYPE 7557 if (TREE_CODE (ext_type) == FUNCTION_TYPE
6318 && comptypes (TREE_TYPE (TREE_TYPE (decl1)), 7558 && comptypes (TREE_TYPE (TREE_TYPE (decl1)),
6319 TREE_TYPE (ext_type))) 7559 TREE_TYPE (ext_type)))
6320 { 7560 {
6321 current_function_prototype_locus 7561 current_function_prototype_locus
6322 = DECL_SOURCE_LOCATION (ext_decl); 7562 = DECL_SOURCE_LOCATION (ext_decl);
6323 current_function_prototype_built_in 7563 current_function_prototype_built_in
6324 = C_DECL_BUILTIN_PROTOTYPE (ext_decl); 7564 = C_DECL_BUILTIN_PROTOTYPE (ext_decl);
6325 current_function_prototype_arg_types 7565 current_function_prototype_arg_types
6326 = TYPE_ARG_TYPES (ext_type); 7566 = TYPE_ARG_TYPES (ext_type);
6327 } 7567 }
6328 } 7568 }
6329 } 7569 }
6330 } 7570 }
6331 7571
6332 /* Optionally warn of old-fashioned def with no previous prototype. */ 7572 /* Optionally warn of old-fashioned def with no previous prototype. */
6333 if (warn_strict_prototypes 7573 if (warn_strict_prototypes
6334 && old_decl != error_mark_node 7574 && old_decl != error_mark_node
6335 && TYPE_ARG_TYPES (TREE_TYPE (decl1)) == 0 7575 && TYPE_ARG_TYPES (TREE_TYPE (decl1)) == 0
6336 && C_DECL_ISNT_PROTOTYPE (old_decl)) 7576 && C_DECL_ISNT_PROTOTYPE (old_decl))
6337 warning (OPT_Wstrict_prototypes, 7577 warning_at (loc, OPT_Wstrict_prototypes,
6338 "function declaration isn%'t a prototype"); 7578 "function declaration isn%'t a prototype");
6339 /* Optionally warn of any global def with no previous prototype. */ 7579 /* Optionally warn of any global def with no previous prototype. */
6340 else if (warn_missing_prototypes 7580 else if (warn_missing_prototypes
6341 && old_decl != error_mark_node 7581 && old_decl != error_mark_node
6342 && TREE_PUBLIC (decl1) 7582 && TREE_PUBLIC (decl1)
6343 && !MAIN_NAME_P (DECL_NAME (decl1)) 7583 && !MAIN_NAME_P (DECL_NAME (decl1))
6344 && C_DECL_ISNT_PROTOTYPE (old_decl)) 7584 && C_DECL_ISNT_PROTOTYPE (old_decl))
6345 warning (OPT_Wmissing_prototypes, "no previous prototype for %q+D", decl1); 7585 warning_at (loc, OPT_Wmissing_prototypes,
7586 "no previous prototype for %qD", decl1);
6346 /* Optionally warn of any def with no previous prototype 7587 /* Optionally warn of any def with no previous prototype
6347 if the function has already been used. */ 7588 if the function has already been used. */
6348 else if (warn_missing_prototypes 7589 else if (warn_missing_prototypes
6349 && old_decl != 0 7590 && old_decl != 0
6350 && old_decl != error_mark_node 7591 && old_decl != error_mark_node
6351 && TREE_USED (old_decl) 7592 && TREE_USED (old_decl)
6352 && TYPE_ARG_TYPES (TREE_TYPE (old_decl)) == 0) 7593 && TYPE_ARG_TYPES (TREE_TYPE (old_decl)) == 0)
6353 warning (OPT_Wmissing_prototypes, 7594 warning_at (loc, OPT_Wmissing_prototypes,
6354 "%q+D was used with no prototype before its definition", decl1); 7595 "%qD was used with no prototype before its definition", decl1);
6355 /* Optionally warn of any global def with no previous declaration. */ 7596 /* Optionally warn of any global def with no previous declaration. */
6356 else if (warn_missing_declarations 7597 else if (warn_missing_declarations
6357 && TREE_PUBLIC (decl1) 7598 && TREE_PUBLIC (decl1)
6358 && old_decl == 0 7599 && old_decl == 0
6359 && !MAIN_NAME_P (DECL_NAME (decl1))) 7600 && !MAIN_NAME_P (DECL_NAME (decl1)))
6360 warning (OPT_Wmissing_declarations, "no previous declaration for %q+D", 7601 warning_at (loc, OPT_Wmissing_declarations,
6361 decl1); 7602 "no previous declaration for %qD",
7603 decl1);
6362 /* Optionally warn of any def with no previous declaration 7604 /* Optionally warn of any def with no previous declaration
6363 if the function has already been used. */ 7605 if the function has already been used. */
6364 else if (warn_missing_declarations 7606 else if (warn_missing_declarations
6365 && old_decl != 0 7607 && old_decl != 0
6366 && old_decl != error_mark_node 7608 && old_decl != error_mark_node
6367 && TREE_USED (old_decl) 7609 && TREE_USED (old_decl)
6368 && C_DECL_IMPLICIT (old_decl)) 7610 && C_DECL_IMPLICIT (old_decl))
6369 warning (OPT_Wmissing_declarations, 7611 warning_at (loc, OPT_Wmissing_declarations,
6370 "%q+D was used with no declaration before its definition", decl1); 7612 "%qD was used with no declaration before its definition", decl1);
6371 7613
6372 /* This function exists in static storage. 7614 /* This function exists in static storage.
6373 (This does not mean `static' in the C sense!) */ 7615 (This does not mean `static' in the C sense!) */
6374 TREE_STATIC (decl1) = 1; 7616 TREE_STATIC (decl1) = 1;
6375 7617
6387 7629
6388 /* Warn for unlikely, improbable, or stupid declarations of `main'. */ 7630 /* Warn for unlikely, improbable, or stupid declarations of `main'. */
6389 if (warn_main && MAIN_NAME_P (DECL_NAME (decl1))) 7631 if (warn_main && MAIN_NAME_P (DECL_NAME (decl1)))
6390 { 7632 {
6391 if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (decl1))) 7633 if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (decl1)))
6392 != integer_type_node) 7634 != integer_type_node)
6393 pedwarn (input_location, OPT_Wmain, "return type of %q+D is not %<int%>", decl1); 7635 pedwarn (loc, OPT_Wmain, "return type of %qD is not %<int%>", decl1);
6394 7636
6395 check_main_parameter_types (decl1); 7637 check_main_parameter_types (decl1);
6396 7638
6397 if (!TREE_PUBLIC (decl1)) 7639 if (!TREE_PUBLIC (decl1))
6398 pedwarn (input_location, OPT_Wmain, "%q+D is normally a non-static function", decl1); 7640 pedwarn (loc, OPT_Wmain,
7641 "%qD is normally a non-static function", decl1);
6399 } 7642 }
6400 7643
6401 /* Record the decl so that the function name is defined. 7644 /* Record the decl so that the function name is defined.
6402 If we already have a decl for this name, and it is a FUNCTION_DECL, 7645 If we already have a decl for this name, and it is a FUNCTION_DECL,
6403 use the old decl. */ 7646 use the old decl. */
6406 7649
6407 push_scope (); 7650 push_scope ();
6408 declare_parm_level (); 7651 declare_parm_level ();
6409 7652
6410 restype = TREE_TYPE (TREE_TYPE (current_function_decl)); 7653 restype = TREE_TYPE (TREE_TYPE (current_function_decl));
6411 resdecl = build_decl (RESULT_DECL, NULL_TREE, restype); 7654 resdecl = build_decl (loc, RESULT_DECL, NULL_TREE, restype);
6412 DECL_ARTIFICIAL (resdecl) = 1; 7655 DECL_ARTIFICIAL (resdecl) = 1;
6413 DECL_IGNORED_P (resdecl) = 1; 7656 DECL_IGNORED_P (resdecl) = 1;
6414 DECL_RESULT (current_function_decl) = resdecl; 7657 DECL_RESULT (current_function_decl) = resdecl;
6415 7658
6416 start_fname_decls (); 7659 start_fname_decls ();
6427 { 7670 {
6428 tree decl; 7671 tree decl;
6429 7672
6430 if (current_scope->bindings) 7673 if (current_scope->bindings)
6431 { 7674 {
6432 error ("%Jold-style parameter declarations in prototyped " 7675 error_at (DECL_SOURCE_LOCATION (fndecl),
6433 "function definition", fndecl); 7676 "old-style parameter declarations in prototyped "
7677 "function definition");
6434 7678
6435 /* Get rid of the old-style declarations. */ 7679 /* Get rid of the old-style declarations. */
6436 pop_scope (); 7680 pop_scope ();
6437 push_scope (); 7681 push_scope ();
6438 } 7682 }
6439 /* Don't issue this warning for nested functions, and don't issue this 7683 /* Don't issue this warning for nested functions, and don't issue this
6440 warning if we got here because ARG_INFO_TYPES was error_mark_node 7684 warning if we got here because ARG_INFO_TYPES was error_mark_node
6441 (this happens when a function definition has just an ellipsis in 7685 (this happens when a function definition has just an ellipsis in
6442 its parameter list). */ 7686 its parameter list). */
6443 else if (!in_system_header && !current_function_scope 7687 else if (!in_system_header && !current_function_scope
6444 && arg_info->types != error_mark_node) 7688 && arg_info->types != error_mark_node)
6445 warning (OPT_Wtraditional, 7689 warning_at (DECL_SOURCE_LOCATION (fndecl), OPT_Wtraditional,
6446 "%Jtraditional C rejects ISO C style function definitions", 7690 "traditional C rejects ISO C style function definitions");
6447 fndecl);
6448 7691
6449 /* Now make all the parameter declarations visible in the function body. 7692 /* Now make all the parameter declarations visible in the function body.
6450 We can bypass most of the grunt work of pushdecl. */ 7693 We can bypass most of the grunt work of pushdecl. */
6451 for (decl = arg_info->parms; decl; decl = TREE_CHAIN (decl)) 7694 for (decl = arg_info->parms; decl; decl = TREE_CHAIN (decl))
6452 { 7695 {
6453 DECL_CONTEXT (decl) = current_function_decl; 7696 DECL_CONTEXT (decl) = current_function_decl;
6454 if (DECL_NAME (decl)) 7697 if (DECL_NAME (decl))
6455 { 7698 {
6456 bind (DECL_NAME (decl), decl, current_scope, 7699 bind (DECL_NAME (decl), decl, current_scope,
6457 /*invisible=*/false, /*nested=*/false); 7700 /*invisible=*/false, /*nested=*/false,
6458 if (!TREE_USED (decl)) 7701 UNKNOWN_LOCATION);
6459 warn_if_shadowing (decl); 7702 if (!TREE_USED (decl))
6460 } 7703 warn_if_shadowing (decl);
7704 }
6461 else 7705 else
6462 error ("%Jparameter name omitted", decl); 7706 error_at (DECL_SOURCE_LOCATION (decl), "parameter name omitted");
6463 } 7707 }
6464 7708
6465 /* Record the parameter list in the function declaration. */ 7709 /* Record the parameter list in the function declaration. */
6466 DECL_ARGUMENTS (fndecl) = arg_info->parms; 7710 DECL_ARGUMENTS (fndecl) = arg_info->parms;
6467 7711
6468 /* Now make all the ancillary declarations visible, likewise. */ 7712 /* Now make all the ancillary declarations visible, likewise. */
6469 for (decl = arg_info->others; decl; decl = TREE_CHAIN (decl)) 7713 for (decl = arg_info->others; decl; decl = TREE_CHAIN (decl))
6470 { 7714 {
6471 DECL_CONTEXT (decl) = current_function_decl; 7715 DECL_CONTEXT (decl) = current_function_decl;
6472 if (DECL_NAME (decl)) 7716 if (DECL_NAME (decl))
6473 bind (DECL_NAME (decl), decl, current_scope, 7717 bind (DECL_NAME (decl), decl, current_scope,
6474 /*invisible=*/false, /*nested=*/false); 7718 /*invisible=*/false, /*nested=*/false, UNKNOWN_LOCATION);
6475 } 7719 }
6476 7720
6477 /* And all the tag declarations. */ 7721 /* And all the tag declarations. */
6478 for (decl = arg_info->tags; decl; decl = TREE_CHAIN (decl)) 7722 for (decl = arg_info->tags; decl; decl = TREE_CHAIN (decl))
6479 if (TREE_PURPOSE (decl)) 7723 if (TREE_PURPOSE (decl))
6480 bind (TREE_PURPOSE (decl), TREE_VALUE (decl), current_scope, 7724 bind (TREE_PURPOSE (decl), TREE_VALUE (decl), current_scope,
6481 /*invisible=*/false, /*nested=*/false); 7725 /*invisible=*/false, /*nested=*/false, UNKNOWN_LOCATION);
6482 } 7726 }
6483 7727
6484 /* Subroutine of store_parm_decls which handles old-style function 7728 /* Subroutine of store_parm_decls which handles old-style function
6485 definitions (separate parameter list and declarations). */ 7729 definitions (separate parameter list and declarations). */
6486 7730
6491 tree parm, decl, last; 7735 tree parm, decl, last;
6492 tree parmids = arg_info->parms; 7736 tree parmids = arg_info->parms;
6493 struct pointer_set_t *seen_args = pointer_set_create (); 7737 struct pointer_set_t *seen_args = pointer_set_create ();
6494 7738
6495 if (!in_system_header) 7739 if (!in_system_header)
6496 warning (OPT_Wold_style_definition, "%Jold-style function definition", 7740 warning_at (DECL_SOURCE_LOCATION (fndecl),
6497 fndecl); 7741 OPT_Wold_style_definition, "old-style function definition");
6498 7742
6499 /* Match each formal parameter name with its declaration. Save each 7743 /* Match each formal parameter name with its declaration. Save each
6500 decl in the appropriate TREE_PURPOSE slot of the parmids chain. */ 7744 decl in the appropriate TREE_PURPOSE slot of the parmids chain. */
6501 for (parm = parmids; parm; parm = TREE_CHAIN (parm)) 7745 for (parm = parmids; parm; parm = TREE_CHAIN (parm))
6502 { 7746 {
6503 if (TREE_VALUE (parm) == 0) 7747 if (TREE_VALUE (parm) == 0)
6504 { 7748 {
6505 error ("%Jparameter name missing from parameter list", fndecl); 7749 error_at (DECL_SOURCE_LOCATION (fndecl),
6506 TREE_PURPOSE (parm) = 0; 7750 "parameter name missing from parameter list");
6507 continue; 7751 TREE_PURPOSE (parm) = 0;
6508 } 7752 continue;
7753 }
6509 7754
6510 b = I_SYMBOL_BINDING (TREE_VALUE (parm)); 7755 b = I_SYMBOL_BINDING (TREE_VALUE (parm));
6511 if (b && B_IN_CURRENT_SCOPE (b)) 7756 if (b && B_IN_CURRENT_SCOPE (b))
6512 { 7757 {
6513 decl = b->decl; 7758 decl = b->decl;
6514 /* If we got something other than a PARM_DECL it is an error. */ 7759 /* If we got something other than a PARM_DECL it is an error. */
6515 if (TREE_CODE (decl) != PARM_DECL) 7760 if (TREE_CODE (decl) != PARM_DECL)
6516 error ("%q+D declared as a non-parameter", decl); 7761 error_at (DECL_SOURCE_LOCATION (decl),
6517 /* If the declaration is already marked, we have a duplicate 7762 "%qD declared as a non-parameter", decl);
6518 name. Complain and ignore the duplicate. */ 7763 /* If the declaration is already marked, we have a duplicate
6519 else if (pointer_set_contains (seen_args, decl)) 7764 name. Complain and ignore the duplicate. */
6520 { 7765 else if (pointer_set_contains (seen_args, decl))
6521 error ("multiple parameters named %q+D", decl); 7766 {
6522 TREE_PURPOSE (parm) = 0; 7767 error_at (DECL_SOURCE_LOCATION (decl),
6523 continue; 7768 "multiple parameters named %qD", decl);
6524 } 7769 TREE_PURPOSE (parm) = 0;
6525 /* If the declaration says "void", complain and turn it into 7770 continue;
6526 an int. */ 7771 }
6527 else if (VOID_TYPE_P (TREE_TYPE (decl))) 7772 /* If the declaration says "void", complain and turn it into
6528 { 7773 an int. */
6529 error ("parameter %q+D declared with void type", decl); 7774 else if (VOID_TYPE_P (TREE_TYPE (decl)))
6530 TREE_TYPE (decl) = integer_type_node; 7775 {
6531 DECL_ARG_TYPE (decl) = integer_type_node; 7776 error_at (DECL_SOURCE_LOCATION (decl),
6532 layout_decl (decl, 0); 7777 "parameter %qD declared with void type", decl);
6533 } 7778 TREE_TYPE (decl) = integer_type_node;
6534 warn_if_shadowing (decl); 7779 DECL_ARG_TYPE (decl) = integer_type_node;
6535 } 7780 layout_decl (decl, 0);
7781 }
7782 warn_if_shadowing (decl);
7783 }
6536 /* If no declaration found, default to int. */ 7784 /* If no declaration found, default to int. */
6537 else 7785 else
6538 { 7786 {
6539 decl = build_decl (PARM_DECL, TREE_VALUE (parm), integer_type_node); 7787 /* FIXME diagnostics: This should be the location of the argument,
6540 DECL_ARG_TYPE (decl) = TREE_TYPE (decl); 7788 not the FNDECL. E.g., for an old-style declaration
6541 DECL_SOURCE_LOCATION (decl) = DECL_SOURCE_LOCATION (fndecl); 7789
6542 pushdecl (decl); 7790 int f10(v) { blah; }
6543 warn_if_shadowing (decl); 7791
6544 7792 We should use the location of the V, not the F10.
6545 if (flag_isoc99) 7793 Unfortunately, the V is an IDENTIFIER_NODE which has no
6546 pedwarn (input_location, 0, "type of %q+D defaults to %<int%>", decl); 7794 location. In the future we need locations for c_arg_info
6547 else 7795 entries.
6548 warning (OPT_Wmissing_parameter_type, "type of %q+D defaults to %<int%>", decl); 7796
6549 } 7797 See gcc.dg/Wshadow-3.c for an example of this problem. */
7798 decl = build_decl (DECL_SOURCE_LOCATION (fndecl),
7799 PARM_DECL, TREE_VALUE (parm), integer_type_node);
7800 DECL_ARG_TYPE (decl) = TREE_TYPE (decl);
7801 pushdecl (decl);
7802 warn_if_shadowing (decl);
7803
7804 if (flag_isoc99)
7805 pedwarn (DECL_SOURCE_LOCATION (decl),
7806 0, "type of %qD defaults to %<int%>", decl);
7807 else
7808 warning_at (DECL_SOURCE_LOCATION (decl),
7809 OPT_Wmissing_parameter_type,
7810 "type of %qD defaults to %<int%>", decl);
7811 }
6550 7812
6551 TREE_PURPOSE (parm) = decl; 7813 TREE_PURPOSE (parm) = decl;
6552 pointer_set_insert (seen_args, decl); 7814 pointer_set_insert (seen_args, decl);
6553 } 7815 }
6554 7816
6557 7819
6558 for (b = current_scope->bindings; b; b = b->prev) 7820 for (b = current_scope->bindings; b; b = b->prev)
6559 { 7821 {
6560 parm = b->decl; 7822 parm = b->decl;
6561 if (TREE_CODE (parm) != PARM_DECL) 7823 if (TREE_CODE (parm) != PARM_DECL)
6562 continue; 7824 continue;
6563 7825
6564 if (TREE_TYPE (parm) != error_mark_node 7826 if (TREE_TYPE (parm) != error_mark_node
6565 && !COMPLETE_TYPE_P (TREE_TYPE (parm))) 7827 && !COMPLETE_TYPE_P (TREE_TYPE (parm)))
6566 { 7828 {
6567 error ("parameter %q+D has incomplete type", parm); 7829 error_at (DECL_SOURCE_LOCATION (parm),
6568 TREE_TYPE (parm) = error_mark_node; 7830 "parameter %qD has incomplete type", parm);
6569 } 7831 TREE_TYPE (parm) = error_mark_node;
7832 }
6570 7833
6571 if (!pointer_set_contains (seen_args, parm)) 7834 if (!pointer_set_contains (seen_args, parm))
6572 { 7835 {
6573 error ("declaration for parameter %q+D but no such parameter", parm); 7836 error_at (DECL_SOURCE_LOCATION (parm),
6574 7837 "declaration for parameter %qD but no such parameter",
6575 /* Pretend the parameter was not missing. 7838 parm);
6576 This gets us to a standard state and minimizes 7839
6577 further error messages. */ 7840 /* Pretend the parameter was not missing.
6578 parmids = chainon (parmids, tree_cons (parm, 0, 0)); 7841 This gets us to a standard state and minimizes
6579 } 7842 further error messages. */
7843 parmids = chainon (parmids, tree_cons (parm, 0, 0));
7844 }
6580 } 7845 }
6581 7846
6582 /* Chain the declarations together in the order of the list of 7847 /* Chain the declarations together in the order of the list of
6583 names. Store that chain in the function decl, replacing the 7848 names. Store that chain in the function decl, replacing the
6584 list of names. Update the current scope to match. */ 7849 list of names. Update the current scope to match. */
6591 { 7856 {
6592 last = TREE_PURPOSE (parm); 7857 last = TREE_PURPOSE (parm);
6593 DECL_ARGUMENTS (fndecl) = last; 7858 DECL_ARGUMENTS (fndecl) = last;
6594 7859
6595 for (parm = TREE_CHAIN (parm); parm; parm = TREE_CHAIN (parm)) 7860 for (parm = TREE_CHAIN (parm); parm; parm = TREE_CHAIN (parm))
6596 if (TREE_PURPOSE (parm)) 7861 if (TREE_PURPOSE (parm))
6597 { 7862 {
6598 TREE_CHAIN (last) = TREE_PURPOSE (parm); 7863 TREE_CHAIN (last) = TREE_PURPOSE (parm);
6599 last = TREE_PURPOSE (parm); 7864 last = TREE_PURPOSE (parm);
6600 } 7865 }
6601 TREE_CHAIN (last) = 0; 7866 TREE_CHAIN (last) = 0;
6602 } 7867 }
6603 7868
6604 pointer_set_destroy (seen_args); 7869 pointer_set_destroy (seen_args);
6605 7870
6609 7874
6610 if (current_function_prototype_arg_types) 7875 if (current_function_prototype_arg_types)
6611 { 7876 {
6612 tree type; 7877 tree type;
6613 for (parm = DECL_ARGUMENTS (fndecl), 7878 for (parm = DECL_ARGUMENTS (fndecl),
6614 type = current_function_prototype_arg_types; 7879 type = current_function_prototype_arg_types;
6615 parm || (type && TREE_VALUE (type) != error_mark_node 7880 parm || (type && TREE_VALUE (type) != error_mark_node
6616 && (TYPE_MAIN_VARIANT (TREE_VALUE (type)) != void_type_node)); 7881 && (TYPE_MAIN_VARIANT (TREE_VALUE (type)) != void_type_node));
6617 parm = TREE_CHAIN (parm), type = TREE_CHAIN (type)) 7882 parm = TREE_CHAIN (parm), type = TREE_CHAIN (type))
6618 { 7883 {
6619 if (parm == 0 || type == 0 7884 if (parm == 0 || type == 0
6620 || TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node) 7885 || TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node)
6621 { 7886 {
6622 if (current_function_prototype_built_in) 7887 if (current_function_prototype_built_in)
6623 warning (0, "number of arguments doesn%'t match " 7888 warning_at (DECL_SOURCE_LOCATION (fndecl),
6624 "built-in prototype"); 7889 0, "number of arguments doesn%'t match "
6625 else 7890 "built-in prototype");
6626 { 7891 else
6627 error ("number of arguments doesn%'t match prototype"); 7892 {
6628 error ("%Hprototype declaration", 7893 /* FIXME diagnostics: This should be the location of
6629 &current_function_prototype_locus); 7894 FNDECL, but there is bug when a prototype is
6630 } 7895 declared inside function context, but defined
6631 break; 7896 outside of it (e.g., gcc.dg/pr15698-2.c). In
6632 } 7897 which case FNDECL gets the location of the
6633 /* Type for passing arg must be consistent with that 7898 prototype, not the definition. */
6634 declared for the arg. ISO C says we take the unqualified 7899 error_at (input_location,
6635 type for parameters declared with qualified type. */ 7900 "number of arguments doesn%'t match prototype");
6636 if (TREE_TYPE (parm) != error_mark_node 7901
6637 && TREE_TYPE (type) != error_mark_node 7902 error_at (current_function_prototype_locus,
6638 && !comptypes (TYPE_MAIN_VARIANT (DECL_ARG_TYPE (parm)), 7903 "prototype declaration");
6639 TYPE_MAIN_VARIANT (TREE_VALUE (type)))) 7904 }
6640 { 7905 break;
6641 if (TYPE_MAIN_VARIANT (TREE_TYPE (parm)) 7906 }
6642 == TYPE_MAIN_VARIANT (TREE_VALUE (type))) 7907 /* Type for passing arg must be consistent with that
6643 { 7908 declared for the arg. ISO C says we take the unqualified
6644 /* Adjust argument to match prototype. E.g. a previous 7909 type for parameters declared with qualified type. */
6645 `int foo(float);' prototype causes 7910 if (TREE_TYPE (parm) != error_mark_node
6646 `int foo(x) float x; {...}' to be treated like 7911 && TREE_TYPE (type) != error_mark_node
6647 `int foo(float x) {...}'. This is particularly 7912 && !comptypes (TYPE_MAIN_VARIANT (DECL_ARG_TYPE (parm)),
6648 useful for argument types like uid_t. */ 7913 TYPE_MAIN_VARIANT (TREE_VALUE (type))))
6649 DECL_ARG_TYPE (parm) = TREE_TYPE (parm); 7914 {
6650 7915 if (TYPE_MAIN_VARIANT (TREE_TYPE (parm))
6651 if (targetm.calls.promote_prototypes (TREE_TYPE (current_function_decl)) 7916 == TYPE_MAIN_VARIANT (TREE_VALUE (type)))
6652 && INTEGRAL_TYPE_P (TREE_TYPE (parm)) 7917 {
6653 && TYPE_PRECISION (TREE_TYPE (parm)) 7918 /* Adjust argument to match prototype. E.g. a previous
6654 < TYPE_PRECISION (integer_type_node)) 7919 `int foo(float);' prototype causes
6655 DECL_ARG_TYPE (parm) = integer_type_node; 7920 `int foo(x) float x; {...}' to be treated like
6656 7921 `int foo(float x) {...}'. This is particularly
6657 /* ??? Is it possible to get here with a 7922 useful for argument types like uid_t. */
6658 built-in prototype or will it always have 7923 DECL_ARG_TYPE (parm) = TREE_TYPE (parm);
6659 been diagnosed as conflicting with an 7924
6660 old-style definition and discarded? */ 7925 if (targetm.calls.promote_prototypes (TREE_TYPE (current_function_decl))
6661 if (current_function_prototype_built_in) 7926 && INTEGRAL_TYPE_P (TREE_TYPE (parm))
6662 warning (OPT_pedantic, "promoted argument %qD " 7927 && TYPE_PRECISION (TREE_TYPE (parm))
6663 "doesn%'t match built-in prototype", parm); 7928 < TYPE_PRECISION (integer_type_node))
6664 else 7929 DECL_ARG_TYPE (parm) = integer_type_node;
6665 { 7930
6666 pedwarn (input_location, OPT_pedantic, "promoted argument %qD " 7931 /* ??? Is it possible to get here with a
6667 "doesn%'t match prototype", parm); 7932 built-in prototype or will it always have
6668 pedwarn (current_function_prototype_locus, OPT_pedantic, 7933 been diagnosed as conflicting with an
6669 "prototype declaration"); 7934 old-style definition and discarded? */
6670 } 7935 if (current_function_prototype_built_in)
6671 } 7936 warning_at (DECL_SOURCE_LOCATION (parm),
6672 else 7937 OPT_pedantic, "promoted argument %qD "
6673 { 7938 "doesn%'t match built-in prototype", parm);
6674 if (current_function_prototype_built_in) 7939 else
6675 warning (0, "argument %qD doesn%'t match " 7940 {
6676 "built-in prototype", parm); 7941 pedwarn (DECL_SOURCE_LOCATION (parm),
6677 else 7942 OPT_pedantic, "promoted argument %qD "
6678 { 7943 "doesn%'t match prototype", parm);
6679 error ("argument %qD doesn%'t match prototype", parm); 7944 pedwarn (current_function_prototype_locus, OPT_pedantic,
6680 error ("%Hprototype declaration", 7945 "prototype declaration");
6681 &current_function_prototype_locus); 7946 }
6682 } 7947 }
6683 } 7948 else
6684 } 7949 {
6685 } 7950 if (current_function_prototype_built_in)
7951 warning_at (DECL_SOURCE_LOCATION (parm),
7952 0, "argument %qD doesn%'t match "
7953 "built-in prototype", parm);
7954 else
7955 {
7956 error_at (DECL_SOURCE_LOCATION (parm),
7957 "argument %qD doesn%'t match prototype", parm);
7958 error_at (current_function_prototype_locus,
7959 "prototype declaration");
7960 }
7961 }
7962 }
7963 }
6686 TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = 0; 7964 TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = 0;
6687 } 7965 }
6688 7966
6689 /* Otherwise, create a prototype that would match. */ 7967 /* Otherwise, create a prototype that would match. */
6690 7968
6691 else 7969 else
6692 { 7970 {
6693 tree actual = 0, last = 0, type; 7971 tree actual = 0, last = 0, type;
6694 7972
6695 for (parm = DECL_ARGUMENTS (fndecl); parm; parm = TREE_CHAIN (parm)) 7973 for (parm = DECL_ARGUMENTS (fndecl); parm; parm = TREE_CHAIN (parm))
6696 { 7974 {
6697 type = tree_cons (NULL_TREE, DECL_ARG_TYPE (parm), NULL_TREE); 7975 type = tree_cons (NULL_TREE, DECL_ARG_TYPE (parm), NULL_TREE);
6698 if (last) 7976 if (last)
6699 TREE_CHAIN (last) = type; 7977 TREE_CHAIN (last) = type;
6700 else 7978 else
6701 actual = type; 7979 actual = type;
6702 last = type; 7980 last = type;
6703 } 7981 }
6704 type = tree_cons (NULL_TREE, void_type_node, NULL_TREE); 7982 type = tree_cons (NULL_TREE, void_type_node, NULL_TREE);
6705 if (last) 7983 if (last)
6706 TREE_CHAIN (last) = type; 7984 TREE_CHAIN (last) = type;
6707 else 7985 else
6708 actual = type; 7986 actual = type;
6709 7987
6710 /* We are going to assign a new value for the TYPE_ACTUAL_ARG_TYPES 7988 /* We are going to assign a new value for the TYPE_ACTUAL_ARG_TYPES
6711 of the type of this function, but we need to avoid having this 7989 of the type of this function, but we need to avoid having this
6712 affect the types of other similarly-typed functions, so we must 7990 affect the types of other similarly-typed functions, so we must
6713 first force the generation of an identical (but separate) type 7991 first force the generation of an identical (but separate) type
6714 node for the relevant function type. The new node we create 7992 node for the relevant function type. The new node we create
6715 will be a variant of the main variant of the original function 7993 will be a variant of the main variant of the original function
6716 type. */ 7994 type. */
6717 7995
6718 TREE_TYPE (fndecl) = build_variant_type_copy (TREE_TYPE (fndecl)); 7996 TREE_TYPE (fndecl) = build_variant_type_copy (TREE_TYPE (fndecl));
6719 7997
6720 TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = actual; 7998 TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = actual;
6721 } 7999 }
6775 /* Begin the statement tree for this function. */ 8053 /* Begin the statement tree for this function. */
6776 DECL_SAVED_TREE (fndecl) = push_stmt_list (); 8054 DECL_SAVED_TREE (fndecl) = push_stmt_list ();
6777 8055
6778 /* ??? Insert the contents of the pending sizes list into the function 8056 /* ??? Insert the contents of the pending sizes list into the function
6779 to be evaluated. The only reason left to have this is 8057 to be evaluated. The only reason left to have this is
6780 void foo(int n, int array[n++]) 8058 void foo(int n, int array[n++])
6781 because we throw away the array type in favor of a pointer type, and 8059 because we throw away the array type in favor of a pointer type, and
6782 thus won't naturally see the SAVE_EXPR containing the increment. All 8060 thus won't naturally see the SAVE_EXPR containing the increment. All
6783 other pending sizes would be handled by gimplify_parameters. */ 8061 other pending sizes would be handled by gimplify_parameters. */
6784 { 8062 {
6785 tree t; 8063 tree t;
6792 We haven't necessarily assigned RTL to all variables yet, so it's 8070 We haven't necessarily assigned RTL to all variables yet, so it's
6793 not safe to try to expand expressions involving them. */ 8071 not safe to try to expand expressions involving them. */
6794 cfun->dont_save_pending_sizes_p = 1; 8072 cfun->dont_save_pending_sizes_p = 1;
6795 } 8073 }
6796 8074
6797 /* Emit diagnostics that require gimple input for detection. Operate on
6798 FNDECL and all its nested functions. */
6799
6800 static void
6801 c_gimple_diagnostics_recursively (tree fndecl)
6802 {
6803 struct cgraph_node *cgn;
6804 gimple_seq body = gimple_body (fndecl);
6805
6806 /* Handle attribute((warn_unused_result)). Relies on gimple input. */
6807 c_warn_unused_result (body);
6808
6809 /* Notice when OpenMP structured block constraints are violated. */
6810 if (flag_openmp)
6811 diagnose_omp_structured_block_errors (fndecl);
6812
6813 /* Finalize all nested functions now. */
6814 cgn = cgraph_node (fndecl);
6815 for (cgn = cgn->nested; cgn ; cgn = cgn->next_nested)
6816 c_gimple_diagnostics_recursively (cgn->decl);
6817 }
6818 8075
6819 /* Finish up a function declaration and compile that function 8076 /* Finish up a function declaration and compile that function
6820 all the way to assembler language output. The free the storage 8077 all the way to assembler language output. The free the storage
6821 for the function definition. 8078 for the function definition.
6822 8079
6825 void 8082 void
6826 finish_function (void) 8083 finish_function (void)
6827 { 8084 {
6828 tree fndecl = current_function_decl; 8085 tree fndecl = current_function_decl;
6829 8086
6830 label_context_stack_se = label_context_stack_se->next;
6831 label_context_stack_vm = label_context_stack_vm->next;
6832
6833 if (TREE_CODE (fndecl) == FUNCTION_DECL 8087 if (TREE_CODE (fndecl) == FUNCTION_DECL
6834 && targetm.calls.promote_prototypes (TREE_TYPE (fndecl))) 8088 && targetm.calls.promote_prototypes (TREE_TYPE (fndecl)))
6835 { 8089 {
6836 tree args = DECL_ARGUMENTS (fndecl); 8090 tree args = DECL_ARGUMENTS (fndecl);
6837 for (; args; args = TREE_CHAIN (args)) 8091 for (; args; args = TREE_CHAIN (args))
6838 { 8092 {
6839 tree type = TREE_TYPE (args); 8093 tree type = TREE_TYPE (args);
6840 if (INTEGRAL_TYPE_P (type) 8094 if (INTEGRAL_TYPE_P (type)
6841 && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)) 8095 && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
6842 DECL_ARG_TYPE (args) = integer_type_node; 8096 DECL_ARG_TYPE (args) = integer_type_node;
6843 } 8097 }
6844 } 8098 }
6845 8099
6846 if (DECL_INITIAL (fndecl) && DECL_INITIAL (fndecl) != error_mark_node) 8100 if (DECL_INITIAL (fndecl) && DECL_INITIAL (fndecl) != error_mark_node)
6847 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl; 8101 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
6848 8102
6853 8107
6854 if (MAIN_NAME_P (DECL_NAME (fndecl)) && flag_hosted 8108 if (MAIN_NAME_P (DECL_NAME (fndecl)) && flag_hosted
6855 && TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl))) 8109 && TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl)))
6856 == integer_type_node && flag_isoc99) 8110 == integer_type_node && flag_isoc99)
6857 { 8111 {
6858 tree stmt = c_finish_return (integer_zero_node);
6859 /* Hack. We don't want the middle-end to warn that this return 8112 /* Hack. We don't want the middle-end to warn that this return
6860 is unreachable, so we mark its location as special. Using 8113 is unreachable, so we mark its location as special. Using
6861 UNKNOWN_LOCATION has the problem that it gets clobbered in 8114 UNKNOWN_LOCATION has the problem that it gets clobbered in
6862 annotate_one_with_locus. A cleaner solution might be to 8115 annotate_one_with_locus. A cleaner solution might be to
6863 ensure ! should_carry_locus_p (stmt), but that needs a flag. 8116 ensure ! should_carry_locus_p (stmt), but that needs a flag.
6864 */ 8117 */
6865 SET_EXPR_LOCATION (stmt, BUILTINS_LOCATION); 8118 c_finish_return (BUILTINS_LOCATION, integer_zero_node, NULL_TREE);
6866 } 8119 }
6867 8120
6868 /* Tie off the statement tree for this function. */ 8121 /* Tie off the statement tree for this function. */
6869 DECL_SAVED_TREE (fndecl) = pop_stmt_list (DECL_SAVED_TREE (fndecl)); 8122 DECL_SAVED_TREE (fndecl) = pop_stmt_list (DECL_SAVED_TREE (fndecl));
6870 8123
6874 if (warn_return_type 8127 if (warn_return_type
6875 && TREE_CODE (TREE_TYPE (TREE_TYPE (fndecl))) != VOID_TYPE 8128 && TREE_CODE (TREE_TYPE (TREE_TYPE (fndecl))) != VOID_TYPE
6876 && !current_function_returns_value && !current_function_returns_null 8129 && !current_function_returns_value && !current_function_returns_null
6877 /* Don't complain if we are no-return. */ 8130 /* Don't complain if we are no-return. */
6878 && !current_function_returns_abnormally 8131 && !current_function_returns_abnormally
6879 /* Don't complain if we are declared noreturn. */
6880 && !TREE_THIS_VOLATILE (fndecl)
6881 /* Don't warn for main(). */ 8132 /* Don't warn for main(). */
6882 && !MAIN_NAME_P (DECL_NAME (fndecl)) 8133 && !MAIN_NAME_P (DECL_NAME (fndecl))
6883 /* Or if they didn't actually specify a return type. */ 8134 /* Or if they didn't actually specify a return type. */
6884 && !C_FUNCTION_IMPLICIT_INT (fndecl) 8135 && !C_FUNCTION_IMPLICIT_INT (fndecl)
6885 /* Normally, with -Wreturn-type, flow will complain, but we might 8136 /* Normally, with -Wreturn-type, flow will complain, but we might
6886 optimize out static functions. */ 8137 optimize out static functions. */
6887 && !TREE_PUBLIC (fndecl)) 8138 && !TREE_PUBLIC (fndecl))
6888 { 8139 {
6889 warning (OPT_Wreturn_type, 8140 warning (OPT_Wreturn_type,
6890 "no return statement in function returning non-void"); 8141 "no return statement in function returning non-void");
6891 TREE_NO_WARNING (fndecl) = 1; 8142 TREE_NO_WARNING (fndecl) = 1;
6892 } 8143 }
6893 8144
6894 /* Store the end of the function, so that we get good line number 8145 /* Store the end of the function, so that we get good line number
6895 info for the epilogue. */ 8146 info for the epilogue. */
6897 8148
6898 /* Finalize the ELF visibility for the function. */ 8149 /* Finalize the ELF visibility for the function. */
6899 c_determine_visibility (fndecl); 8150 c_determine_visibility (fndecl);
6900 8151
6901 /* For GNU C extern inline functions disregard inline limits. */ 8152 /* For GNU C extern inline functions disregard inline limits. */
6902 if (DECL_EXTERNAL (fndecl) 8153 if (DECL_EXTERNAL (fndecl)
6903 && DECL_DECLARED_INLINE_P (fndecl)) 8154 && DECL_DECLARED_INLINE_P (fndecl))
6904 DECL_DISREGARD_INLINE_LIMITS (fndecl) = 1; 8155 DECL_DISREGARD_INLINE_LIMITS (fndecl) = 1;
6905 8156
6906 /* Genericize before inlining. Delay genericizing nested functions 8157 /* Genericize before inlining. Delay genericizing nested functions
6907 until their parent function is genericized. Since finalizing 8158 until their parent function is genericized. Since finalizing
6909 8160
6910 if (DECL_INITIAL (fndecl) && DECL_INITIAL (fndecl) != error_mark_node 8161 if (DECL_INITIAL (fndecl) && DECL_INITIAL (fndecl) != error_mark_node
6911 && !undef_nested_function) 8162 && !undef_nested_function)
6912 { 8163 {
6913 if (!decl_function_context (fndecl)) 8164 if (!decl_function_context (fndecl))
6914 { 8165 {
6915 c_genericize (fndecl); 8166 invoke_plugin_callbacks (PLUGIN_PRE_GENERICIZE, fndecl);
6916 c_gimple_diagnostics_recursively (fndecl); 8167 c_genericize (fndecl);
6917 8168
6918 /* ??? Objc emits functions after finalizing the compilation unit. 8169 /* ??? Objc emits functions after finalizing the compilation unit.
6919 This should be cleaned up later and this conditional removed. */ 8170 This should be cleaned up later and this conditional removed. */
6920 if (cgraph_global_info_ready) 8171 if (cgraph_global_info_ready)
6921 { 8172 {
6922 cgraph_add_new_function (fndecl, false); 8173 cgraph_add_new_function (fndecl, false);
6923 return; 8174 return;
6924 } 8175 }
6925 8176 cgraph_finalize_function (fndecl, false);
6926 cgraph_finalize_function (fndecl, false); 8177 }
6927 }
6928 else 8178 else
6929 { 8179 {
6930 /* Register this function with cgraph just far enough to get it 8180 /* Register this function with cgraph just far enough to get it
6931 added to our parent's nested function list. Handy, since the 8181 added to our parent's nested function list. Handy, since the
6932 C front end doesn't have such a list. */ 8182 C front end doesn't have such a list. */
6933 (void) cgraph_node (fndecl); 8183 (void) cgraph_node (fndecl);
6934 } 8184 }
6935 } 8185 }
6936 8186
6937 if (!decl_function_context (fndecl)) 8187 if (!decl_function_context (fndecl))
6938 undef_nested_function = false; 8188 undef_nested_function = false;
6939 8189
6943 set_cfun (NULL); 8193 set_cfun (NULL);
6944 current_function_decl = NULL; 8194 current_function_decl = NULL;
6945 } 8195 }
6946 8196
6947 /* Check the declarations given in a for-loop for satisfying the C99 8197 /* Check the declarations given in a for-loop for satisfying the C99
6948 constraints. If exactly one such decl is found, return it. */ 8198 constraints. If exactly one such decl is found, return it. LOC is
8199 the location of the opening parenthesis of the for loop. */
6949 8200
6950 tree 8201 tree
6951 check_for_loop_decls (void) 8202 check_for_loop_decls (location_t loc)
6952 { 8203 {
6953 struct c_binding *b; 8204 struct c_binding *b;
6954 tree one_decl = NULL_TREE; 8205 tree one_decl = NULL_TREE;
6955 int n_decls = 0; 8206 int n_decls = 0;
6956 8207
6957 if (!flag_isoc99) 8208 if (!flag_isoc99)
6958 { 8209 {
6959 static bool hint = true; 8210 static bool hint = true;
6960 /* If we get here, declarations have been used in a for loop without 8211 /* If we get here, declarations have been used in a for loop without
6961 the C99 for loop scope. This doesn't make much sense, so don't 8212 the C99 for loop scope. This doesn't make much sense, so don't
6962 allow it. */ 8213 allow it. */
6963 error ("%<for%> loop initial declarations are only allowed in C99 mode"); 8214 error_at (loc, "%<for%> loop initial declarations "
8215 "are only allowed in C99 mode");
6964 if (hint) 8216 if (hint)
6965 { 8217 {
6966 inform (input_location, 8218 inform (loc,
6967 "use option -std=c99 or -std=gnu99 to compile your code"); 8219 "use option -std=c99 or -std=gnu99 to compile your code");
6968 hint = false; 8220 hint = false;
6969 } 8221 }
6970 return NULL_TREE; 8222 return NULL_TREE;
6971 } 8223 }
6972 /* C99 subclause 6.8.5 paragraph 3: 8224 /* C99 subclause 6.8.5 paragraph 3:
6973 8225
6974 [#3] The declaration part of a for statement shall only 8226 [#3] The declaration part of a for statement shall only
6987 { 8239 {
6988 tree id = b->id; 8240 tree id = b->id;
6989 tree decl = b->decl; 8241 tree decl = b->decl;
6990 8242
6991 if (!id) 8243 if (!id)
6992 continue; 8244 continue;
6993 8245
6994 switch (TREE_CODE (decl)) 8246 switch (TREE_CODE (decl))
6995 { 8247 {
6996 case VAR_DECL: 8248 case VAR_DECL:
6997 if (TREE_STATIC (decl)) 8249 {
6998 error ("declaration of static variable %q+D in %<for%> loop " 8250 location_t decl_loc = DECL_SOURCE_LOCATION (decl);
6999 "initial declaration", decl); 8251 if (TREE_STATIC (decl))
7000 else if (DECL_EXTERNAL (decl)) 8252 error_at (decl_loc,
7001 error ("declaration of %<extern%> variable %q+D in %<for%> loop " 8253 "declaration of static variable %qD in %<for%> loop "
7002 "initial declaration", decl); 8254 "initial declaration", decl);
7003 break; 8255 else if (DECL_EXTERNAL (decl))
7004 8256 error_at (decl_loc,
7005 case RECORD_TYPE: 8257 "declaration of %<extern%> variable %qD in %<for%> loop "
7006 error ("%<struct %E%> declared in %<for%> loop initial declaration", 8258 "initial declaration", decl);
7007 id); 8259 }
7008 break; 8260 break;
7009 case UNION_TYPE: 8261
7010 error ("%<union %E%> declared in %<for%> loop initial declaration", 8262 case RECORD_TYPE:
7011 id); 8263 error_at (loc,
7012 break; 8264 "%<struct %E%> declared in %<for%> loop initial "
7013 case ENUMERAL_TYPE: 8265 "declaration", id);
7014 error ("%<enum %E%> declared in %<for%> loop initial declaration", 8266 break;
7015 id); 8267 case UNION_TYPE:
7016 break; 8268 error_at (loc,
7017 default: 8269 "%<union %E%> declared in %<for%> loop initial declaration",
7018 error ("declaration of non-variable %q+D in %<for%> loop " 8270 id);
7019 "initial declaration", decl); 8271 break;
7020 } 8272 case ENUMERAL_TYPE:
8273 error_at (loc, "%<enum %E%> declared in %<for%> loop "
8274 "initial declaration", id);
8275 break;
8276 default:
8277 error_at (loc, "declaration of non-variable "
8278 "%qD in %<for%> loop initial declaration", decl);
8279 }
7021 8280
7022 n_decls++; 8281 n_decls++;
7023 one_decl = decl; 8282 one_decl = decl;
7024 } 8283 }
7025 8284
7063 if (DECL_STRUCT_FUNCTION (current_function_decl) == 0 8322 if (DECL_STRUCT_FUNCTION (current_function_decl) == 0
7064 && DECL_SAVED_TREE (current_function_decl) == NULL_TREE) 8323 && DECL_SAVED_TREE (current_function_decl) == NULL_TREE)
7065 { 8324 {
7066 /* Stop pointing to the local nodes about to be freed. */ 8325 /* Stop pointing to the local nodes about to be freed. */
7067 /* But DECL_INITIAL must remain nonzero so we know this 8326 /* But DECL_INITIAL must remain nonzero so we know this
7068 was an actual function definition. */ 8327 was an actual function definition. */
7069 DECL_INITIAL (current_function_decl) = error_mark_node; 8328 DECL_INITIAL (current_function_decl) = error_mark_node;
7070 DECL_ARGUMENTS (current_function_decl) = 0; 8329 DECL_ARGUMENTS (current_function_decl) = 0;
7071 } 8330 }
7072 8331
7073 c_stmt_tree = p->base.x_stmt_tree; 8332 c_stmt_tree = p->base.x_stmt_tree;
7079 current_function_returns_null = p->returns_null; 8338 current_function_returns_null = p->returns_null;
7080 current_function_returns_abnormally = p->returns_abnormally; 8339 current_function_returns_abnormally = p->returns_abnormally;
7081 warn_about_return_type = p->warn_about_return_type; 8340 warn_about_return_type = p->warn_about_return_type;
7082 } 8341 }
7083 8342
7084 /* Copy the DECL_LANG_SPECIFIC data associated with DECL. */
7085
7086 void
7087 c_dup_lang_specific_decl (tree decl)
7088 {
7089 struct lang_decl *ld;
7090
7091 if (!DECL_LANG_SPECIFIC (decl))
7092 return;
7093
7094 ld = GGC_NEW (struct lang_decl);
7095 memcpy (ld, DECL_LANG_SPECIFIC (decl), sizeof (struct lang_decl));
7096 DECL_LANG_SPECIFIC (decl) = ld;
7097 }
7098
7099 /* The functions below are required for functionality of doing 8343 /* The functions below are required for functionality of doing
7100 function at once processing in the C front end. Currently these 8344 function at once processing in the C front end. Currently these
7101 functions are not called from anywhere in the C front end, but as 8345 functions are not called from anywhere in the C front end, but as
7102 these changes continue, that will change. */ 8346 these changes continue, that will change. */
7103 8347
7112 } 8356 }
7113 8357
7114 /* Return the global value of T as a symbol. */ 8358 /* Return the global value of T as a symbol. */
7115 8359
7116 tree 8360 tree
7117 identifier_global_value (tree t) 8361 identifier_global_value (tree t)
7118 { 8362 {
7119 struct c_binding *b; 8363 struct c_binding *b;
7120 8364
7121 for (b = I_SYMBOL_BINDING (t); b; b = b->shadowed) 8365 for (b = I_SYMBOL_BINDING (t); b; b = b->shadowed)
7122 if (B_IN_FILE_SCOPE (b) || B_IN_EXTERNAL_SCOPE (b)) 8366 if (B_IN_FILE_SCOPE (b) || B_IN_EXTERNAL_SCOPE (b))
7134 tree id, decl; 8378 tree id, decl;
7135 if (name == 0) 8379 if (name == 0)
7136 id = ridpointers[(int) rid_index]; 8380 id = ridpointers[(int) rid_index];
7137 else 8381 else
7138 id = get_identifier (name); 8382 id = get_identifier (name);
7139 decl = build_decl (TYPE_DECL, id, type); 8383 decl = build_decl (UNKNOWN_LOCATION, TYPE_DECL, id, type);
7140 pushdecl (decl); 8384 pushdecl (decl);
7141 if (debug_hooks->type_decl) 8385 if (debug_hooks->type_decl)
7142 debug_hooks->type_decl (decl, false); 8386 debug_hooks->type_decl (decl, false);
7143 } 8387 }
7144 8388
7152 8396
7153 /* Return a c_parm structure with the given SPECS, ATTRS and DECLARATOR. */ 8397 /* Return a c_parm structure with the given SPECS, ATTRS and DECLARATOR. */
7154 8398
7155 struct c_parm * 8399 struct c_parm *
7156 build_c_parm (struct c_declspecs *specs, tree attrs, 8400 build_c_parm (struct c_declspecs *specs, tree attrs,
7157 struct c_declarator *declarator) 8401 struct c_declarator *declarator)
7158 { 8402 {
7159 struct c_parm *ret = XOBNEW (&parser_obstack, struct c_parm); 8403 struct c_parm *ret = XOBNEW (&parser_obstack, struct c_parm);
7160 ret->specs = specs; 8404 ret->specs = specs;
7161 ret->attrs = attrs; 8405 ret->attrs = attrs;
7162 ret->declarator = declarator; 8406 ret->declarator = declarator;
7180 /* Return a declarator for a function with arguments specified by ARGS 8424 /* Return a declarator for a function with arguments specified by ARGS
7181 and return type specified by TARGET. */ 8425 and return type specified by TARGET. */
7182 8426
7183 struct c_declarator * 8427 struct c_declarator *
7184 build_function_declarator (struct c_arg_info *args, 8428 build_function_declarator (struct c_arg_info *args,
7185 struct c_declarator *target) 8429 struct c_declarator *target)
7186 { 8430 {
7187 struct c_declarator *ret = XOBNEW (&parser_obstack, struct c_declarator); 8431 struct c_declarator *ret = XOBNEW (&parser_obstack, struct c_declarator);
7188 ret->kind = cdk_function; 8432 ret->kind = cdk_function;
7189 ret->declarator = target; 8433 ret->declarator = target;
7190 ret->u.arg_info = args; 8434 ret->u.arg_info = args;
7211 TYPE_QUALS_ATTRS is a structure for type qualifiers and attributes 8455 TYPE_QUALS_ATTRS is a structure for type qualifiers and attributes
7212 to apply to the pointer type. */ 8456 to apply to the pointer type. */
7213 8457
7214 struct c_declarator * 8458 struct c_declarator *
7215 make_pointer_declarator (struct c_declspecs *type_quals_attrs, 8459 make_pointer_declarator (struct c_declspecs *type_quals_attrs,
7216 struct c_declarator *target) 8460 struct c_declarator *target)
7217 { 8461 {
7218 tree attrs; 8462 tree attrs;
7219 int quals = 0; 8463 int quals = 0;
7220 struct c_declarator *itarget = target; 8464 struct c_declarator *itarget = target;
7221 struct c_declarator *ret = XOBNEW (&parser_obstack, struct c_declarator); 8465 struct c_declarator *ret = XOBNEW (&parser_obstack, struct c_declarator);
7222 if (type_quals_attrs) 8466 if (type_quals_attrs)
7223 { 8467 {
7224 attrs = type_quals_attrs->attrs; 8468 attrs = type_quals_attrs->attrs;
7225 quals = quals_from_declspecs (type_quals_attrs); 8469 quals = quals_from_declspecs (type_quals_attrs);
7226 if (attrs != NULL_TREE) 8470 if (attrs != NULL_TREE)
7227 itarget = build_attrs_declarator (attrs, target); 8471 itarget = build_attrs_declarator (attrs, target);
7228 } 8472 }
7229 ret->kind = cdk_pointer; 8473 ret->kind = cdk_pointer;
7230 ret->declarator = itarget; 8474 ret->declarator = itarget;
7231 ret->u.pointer_quals = quals; 8475 ret->u.pointer_quals = quals;
7232 return ret; 8476 return ret;
7238 struct c_declspecs * 8482 struct c_declspecs *
7239 build_null_declspecs (void) 8483 build_null_declspecs (void)
7240 { 8484 {
7241 struct c_declspecs *ret = XOBNEW (&parser_obstack, struct c_declspecs); 8485 struct c_declspecs *ret = XOBNEW (&parser_obstack, struct c_declspecs);
7242 ret->type = 0; 8486 ret->type = 0;
8487 ret->expr = 0;
7243 ret->decl_attr = 0; 8488 ret->decl_attr = 0;
7244 ret->attrs = 0; 8489 ret->attrs = 0;
7245 ret->typespec_word = cts_none; 8490 ret->typespec_word = cts_none;
7246 ret->storage_class = csc_none; 8491 ret->storage_class = csc_none;
8492 ret->expr_const_operands = true;
7247 ret->declspecs_seen_p = false; 8493 ret->declspecs_seen_p = false;
7248 ret->type_seen_p = false; 8494 ret->type_seen_p = false;
7249 ret->non_sc_seen_p = false; 8495 ret->non_sc_seen_p = false;
7250 ret->typedef_p = false; 8496 ret->typedef_p = false;
7251 ret->tag_defined_p = false; 8497 ret->tag_defined_p = false;
7262 ret->thread_p = false; 8508 ret->thread_p = false;
7263 ret->const_p = false; 8509 ret->const_p = false;
7264 ret->volatile_p = false; 8510 ret->volatile_p = false;
7265 ret->restrict_p = false; 8511 ret->restrict_p = false;
7266 ret->saturating_p = false; 8512 ret->saturating_p = false;
8513 ret->address_space = ADDR_SPACE_GENERIC;
7267 return ret; 8514 return ret;
8515 }
8516
8517 /* Add the address space ADDRSPACE to the declaration specifiers
8518 SPECS, returning SPECS. */
8519
8520 struct c_declspecs *
8521 declspecs_add_addrspace (struct c_declspecs *specs, addr_space_t as)
8522 {
8523 specs->non_sc_seen_p = true;
8524 specs->declspecs_seen_p = true;
8525
8526 if (!ADDR_SPACE_GENERIC_P (specs->address_space)
8527 && specs->address_space != as)
8528 error ("incompatible address space qualifiers %qs and %qs",
8529 c_addr_space_name (as),
8530 c_addr_space_name (specs->address_space));
8531 else
8532 specs->address_space = as;
8533 return specs;
7268 } 8534 }
7269 8535
7270 /* Add the type qualifier QUAL to the declaration specifiers SPECS, 8536 /* Add the type qualifier QUAL to the declaration specifiers SPECS,
7271 returning SPECS. */ 8537 returning SPECS. */
7272 8538
7276 enum rid i; 8542 enum rid i;
7277 bool dupe = false; 8543 bool dupe = false;
7278 specs->non_sc_seen_p = true; 8544 specs->non_sc_seen_p = true;
7279 specs->declspecs_seen_p = true; 8545 specs->declspecs_seen_p = true;
7280 gcc_assert (TREE_CODE (qual) == IDENTIFIER_NODE 8546 gcc_assert (TREE_CODE (qual) == IDENTIFIER_NODE
7281 && C_IS_RESERVED_WORD (qual)); 8547 && C_IS_RESERVED_WORD (qual));
7282 i = C_RID_CODE (qual); 8548 i = C_RID_CODE (qual);
7283 switch (i) 8549 switch (i)
7284 { 8550 {
7285 case RID_CONST: 8551 case RID_CONST:
7286 dupe = specs->const_p; 8552 dupe = specs->const_p;
7304 8570
7305 /* Add the type specifier TYPE to the declaration specifiers SPECS, 8571 /* Add the type specifier TYPE to the declaration specifiers SPECS,
7306 returning SPECS. */ 8572 returning SPECS. */
7307 8573
7308 struct c_declspecs * 8574 struct c_declspecs *
7309 declspecs_add_type (struct c_declspecs *specs, struct c_typespec spec) 8575 declspecs_add_type (location_t loc, struct c_declspecs *specs,
8576 struct c_typespec spec)
7310 { 8577 {
7311 tree type = spec.spec; 8578 tree type = spec.spec;
7312 specs->non_sc_seen_p = true; 8579 specs->non_sc_seen_p = true;
7313 specs->declspecs_seen_p = true; 8580 specs->declspecs_seen_p = true;
7314 specs->type_seen_p = true; 8581 specs->type_seen_p = true;
7320 && C_IS_RESERVED_WORD (type) 8587 && C_IS_RESERVED_WORD (type)
7321 && C_RID_CODE (type) != RID_CXX_COMPAT_WARN) 8588 && C_RID_CODE (type) != RID_CXX_COMPAT_WARN)
7322 { 8589 {
7323 enum rid i = C_RID_CODE (type); 8590 enum rid i = C_RID_CODE (type);
7324 if (specs->type) 8591 if (specs->type)
7325 { 8592 {
7326 error ("two or more data types in declaration specifiers"); 8593 error_at (loc, "two or more data types in declaration specifiers");
7327 return specs; 8594 return specs;
7328 } 8595 }
7329 if ((int) i <= (int) RID_LAST_MODIFIER) 8596 if ((int) i <= (int) RID_LAST_MODIFIER)
7330 { 8597 {
7331 /* "long", "short", "signed", "unsigned", "_Complex" or "_Sat". */ 8598 /* "long", "short", "signed", "unsigned", "_Complex" or "_Sat". */
7332 bool dupe = false; 8599 bool dupe = false;
7333 switch (i) 8600 switch (i)
7334 { 8601 {
7335 case RID_LONG: 8602 case RID_LONG:
7336 if (specs->long_long_p) 8603 if (specs->long_long_p)
7337 { 8604 {
7338 error ("%<long long long%> is too long for GCC"); 8605 error_at (loc, "%<long long long%> is too long for GCC");
7339 break; 8606 break;
7340 } 8607 }
7341 if (specs->long_p) 8608 if (specs->long_p)
7342 { 8609 {
7343 if (specs->typespec_word == cts_double) 8610 if (specs->typespec_word == cts_double)
7344 { 8611 {
7345 error ("both %<long long%> and %<double%> in " 8612 error_at (loc,
7346 "declaration specifiers"); 8613 ("both %<long long%> and %<double%> in "
7347 break; 8614 "declaration specifiers"));
7348 } 8615 break;
7349 if (pedantic && !flag_isoc99 && !in_system_header) 8616 }
7350 pedwarn (input_location, OPT_Wlong_long, "ISO C90 does not support %<long long%>"); 8617 pedwarn_c90 (loc, OPT_Wlong_long,
7351 specs->long_long_p = 1; 8618 "ISO C90 does not support %<long long%>");
7352 break; 8619 specs->long_long_p = 1;
7353 } 8620 break;
7354 if (specs->short_p) 8621 }
7355 error ("both %<long%> and %<short%> in " 8622 if (specs->short_p)
7356 "declaration specifiers"); 8623 error_at (loc,
7357 else if (specs->typespec_word == cts_void) 8624 ("both %<long%> and %<short%> in "
7358 error ("both %<long%> and %<void%> in " 8625 "declaration specifiers"));
7359 "declaration specifiers"); 8626 else if (specs->typespec_word == cts_void)
8627 error_at (loc,
8628 ("both %<long%> and %<void%> in "
8629 "declaration specifiers"));
7360 #ifndef noCbC 8630 #ifndef noCbC
7361 else if (specs->typespec_word == cts_CbC_code) 8631 else if (specs->typespec_word == cts_CbC_code)
7362 error ("both %<long%> and %<void%> in " 8632 error_at (loc,
7363 "declaration specifiers"); 8633 ("both %<long%> and %<void%> in "
8634 "declaration specifiers"));
7364 #endif 8635 #endif
7365 else if (specs->typespec_word == cts_bool) 8636 else if (specs->typespec_word == cts_bool)
7366 error ("both %<long%> and %<_Bool%> in " 8637 error_at (loc,
7367 "declaration specifiers"); 8638 ("both %<long%> and %<_Bool%> in "
7368 else if (specs->typespec_word == cts_char) 8639 "declaration specifiers"));
7369 error ("both %<long%> and %<char%> in " 8640 else if (specs->typespec_word == cts_char)
7370 "declaration specifiers"); 8641 error_at (loc,
7371 else if (specs->typespec_word == cts_float) 8642 ("both %<long%> and %<char%> in "
7372 error ("both %<long%> and %<float%> in " 8643 "declaration specifiers"));
7373 "declaration specifiers"); 8644 else if (specs->typespec_word == cts_float)
7374 else if (specs->typespec_word == cts_dfloat32) 8645 error_at (loc,
7375 error ("both %<long%> and %<_Decimal32%> in " 8646 ("both %<long%> and %<float%> in "
7376 "declaration specifiers"); 8647 "declaration specifiers"));
7377 else if (specs->typespec_word == cts_dfloat64) 8648 else if (specs->typespec_word == cts_dfloat32)
7378 error ("both %<long%> and %<_Decimal64%> in " 8649 error_at (loc,
7379 "declaration specifiers"); 8650 ("both %<long%> and %<_Decimal32%> in "
7380 else if (specs->typespec_word == cts_dfloat128) 8651 "declaration specifiers"));
7381 error ("both %<long%> and %<_Decimal128%> in " 8652 else if (specs->typespec_word == cts_dfloat64)
7382 "declaration specifiers"); 8653 error_at (loc,
7383 else 8654 ("both %<long%> and %<_Decimal64%> in "
7384 specs->long_p = true; 8655 "declaration specifiers"));
7385 break; 8656 else if (specs->typespec_word == cts_dfloat128)
7386 case RID_SHORT: 8657 error_at (loc,
7387 dupe = specs->short_p; 8658 ("both %<long%> and %<_Decimal128%> in "
7388 if (specs->long_p) 8659 "declaration specifiers"));
7389 error ("both %<long%> and %<short%> in " 8660 else
7390 "declaration specifiers"); 8661 specs->long_p = true;
7391 else if (specs->typespec_word == cts_void) 8662 break;
7392 error ("both %<short%> and %<void%> in " 8663 case RID_SHORT:
7393 "declaration specifiers"); 8664 dupe = specs->short_p;
8665 if (specs->long_p)
8666 error_at (loc,
8667 ("both %<long%> and %<short%> in "
8668 "declaration specifiers"));
8669 else if (specs->typespec_word == cts_void)
8670 error_at (loc,
8671 ("both %<short%> and %<void%> in "
8672 "declaration specifiers"));
7394 #ifndef noCbC 8673 #ifndef noCbC
7395 else if (specs->typespec_word == cts_CbC_code) 8674 else if (specs->typespec_word == cts_CbC_code)
7396 error ("both %<short%> and %<void%> in " 8675 error_at (loc,
7397 "declaration specifiers"); 8676 ("both %<short%> and %<void%> in "
8677 "declaration specifiers"));
7398 #endif 8678 #endif
7399 else if (specs->typespec_word == cts_bool) 8679 else if (specs->typespec_word == cts_bool)
7400 error ("both %<short%> and %<_Bool%> in " 8680 error_at (loc,
7401 "declaration specifiers"); 8681 ("both %<short%> and %<_Bool%> in "
7402 else if (specs->typespec_word == cts_char) 8682 "declaration specifiers"));
7403 error ("both %<short%> and %<char%> in " 8683 else if (specs->typespec_word == cts_char)
7404 "declaration specifiers"); 8684 error_at (loc,
7405 else if (specs->typespec_word == cts_float) 8685 ("both %<short%> and %<char%> in "
7406 error ("both %<short%> and %<float%> in " 8686 "declaration specifiers"));
7407 "declaration specifiers"); 8687 else if (specs->typespec_word == cts_float)
7408 else if (specs->typespec_word == cts_double) 8688 error_at (loc,
7409 error ("both %<short%> and %<double%> in " 8689 ("both %<short%> and %<float%> in "
7410 "declaration specifiers"); 8690 "declaration specifiers"));
7411 else if (specs->typespec_word == cts_dfloat32) 8691 else if (specs->typespec_word == cts_double)
7412 error ("both %<short%> and %<_Decimal32%> in " 8692 error_at (loc,
7413 "declaration specifiers"); 8693 ("both %<short%> and %<double%> in "
7414 else if (specs->typespec_word == cts_dfloat64) 8694 "declaration specifiers"));
7415 error ("both %<short%> and %<_Decimal64%> in " 8695 else if (specs->typespec_word == cts_dfloat32)
7416 "declaration specifiers"); 8696 error_at (loc,
7417 else if (specs->typespec_word == cts_dfloat128) 8697 ("both %<short%> and %<_Decimal32%> in "
7418 error ("both %<short%> and %<_Decimal128%> in " 8698 "declaration specifiers"));
7419 "declaration specifiers"); 8699 else if (specs->typespec_word == cts_dfloat64)
7420 else 8700 error_at (loc,
7421 specs->short_p = true; 8701 ("both %<short%> and %<_Decimal64%> in "
7422 break; 8702 "declaration specifiers"));
7423 case RID_SIGNED: 8703 else if (specs->typespec_word == cts_dfloat128)
7424 dupe = specs->signed_p; 8704 error_at (loc,
7425 if (specs->unsigned_p) 8705 ("both %<short%> and %<_Decimal128%> in "
7426 error ("both %<signed%> and %<unsigned%> in " 8706 "declaration specifiers"));
7427 "declaration specifiers"); 8707 else
7428 else if (specs->typespec_word == cts_void) 8708 specs->short_p = true;
7429 error ("both %<signed%> and %<void%> in " 8709 break;
7430 "declaration specifiers"); 8710 case RID_SIGNED:
8711 dupe = specs->signed_p;
8712 if (specs->unsigned_p)
8713 error_at (loc,
8714 ("both %<signed%> and %<unsigned%> in "
8715 "declaration specifiers"));
8716 else if (specs->typespec_word == cts_void)
8717 error_at (loc,
8718 ("both %<signed%> and %<void%> in "
8719 "declaration specifiers"));
7431 #ifndef noCbC 8720 #ifndef noCbC
7432 else if (specs->typespec_word == cts_CbC_code) 8721 else if (specs->typespec_word == cts_CbC_code)
7433 error ("both %<signed%> and %<void%> in " 8722 error_at (loc,
7434 "declaration specifiers"); 8723 ("both %<signed%> and %<void%> in "
8724 "declaration specifiers"));
7435 #endif 8725 #endif
7436 else if (specs->typespec_word == cts_bool) 8726 else if (specs->typespec_word == cts_bool)
7437 error ("both %<signed%> and %<_Bool%> in " 8727 error_at (loc,
7438 "declaration specifiers"); 8728 ("both %<signed%> and %<_Bool%> in "
7439 else if (specs->typespec_word == cts_float) 8729 "declaration specifiers"));
7440 error ("both %<signed%> and %<float%> in " 8730 else if (specs->typespec_word == cts_float)
7441 "declaration specifiers"); 8731 error_at (loc,
7442 else if (specs->typespec_word == cts_double) 8732 ("both %<signed%> and %<float%> in "
7443 error ("both %<signed%> and %<double%> in " 8733 "declaration specifiers"));
7444 "declaration specifiers"); 8734 else if (specs->typespec_word == cts_double)
7445 else if (specs->typespec_word == cts_dfloat32) 8735 error_at (loc,
7446 error ("both %<signed%> and %<_Decimal32%> in " 8736 ("both %<signed%> and %<double%> in "
7447 "declaration specifiers"); 8737 "declaration specifiers"));
7448 else if (specs->typespec_word == cts_dfloat64) 8738 else if (specs->typespec_word == cts_dfloat32)
7449 error ("both %<signed%> and %<_Decimal64%> in " 8739 error_at (loc,
7450 "declaration specifiers"); 8740 ("both %<signed%> and %<_Decimal32%> in "
7451 else if (specs->typespec_word == cts_dfloat128) 8741 "declaration specifiers"));
7452 error ("both %<signed%> and %<_Decimal128%> in " 8742 else if (specs->typespec_word == cts_dfloat64)
7453 "declaration specifiers"); 8743 error_at (loc,
7454 else 8744 ("both %<signed%> and %<_Decimal64%> in "
7455 specs->signed_p = true; 8745 "declaration specifiers"));
7456 break; 8746 else if (specs->typespec_word == cts_dfloat128)
7457 case RID_UNSIGNED: 8747 error_at (loc,
7458 dupe = specs->unsigned_p; 8748 ("both %<signed%> and %<_Decimal128%> in "
7459 if (specs->signed_p) 8749 "declaration specifiers"));
7460 error ("both %<signed%> and %<unsigned%> in " 8750 else
7461 "declaration specifiers"); 8751 specs->signed_p = true;
7462 else if (specs->typespec_word == cts_void) 8752 break;
7463 error ("both %<unsigned%> and %<void%> in " 8753 case RID_UNSIGNED:
7464 "declaration specifiers"); 8754 dupe = specs->unsigned_p;
8755 if (specs->signed_p)
8756 error_at (loc,
8757 ("both %<signed%> and %<unsigned%> in "
8758 "declaration specifiers"));
8759 else if (specs->typespec_word == cts_void)
8760 error_at (loc,
8761 ("both %<unsigned%> and %<void%> in "
8762 "declaration specifiers"));
7465 #ifndef noCbC 8763 #ifndef noCbC
7466 else if (specs->typespec_word == cts_CbC_code) 8764 else if (specs->typespec_word == cts_CbC_code)
7467 error ("both %<unsigned%> and %<void%> in " 8765 error_at (loc,
7468 "declaration specifiers"); 8766 ("both %<unsigned%> and %<void%> in "
8767 "declaration specifiers"));
7469 #endif 8768 #endif
7470 else if (specs->typespec_word == cts_bool) 8769 else if (specs->typespec_word == cts_bool)
7471 error ("both %<unsigned%> and %<_Bool%> in " 8770 error_at (loc,
7472 "declaration specifiers"); 8771 ("both %<unsigned%> and %<_Bool%> in "
7473 else if (specs->typespec_word == cts_float) 8772 "declaration specifiers"));
7474 error ("both %<unsigned%> and %<float%> in " 8773 else if (specs->typespec_word == cts_float)
7475 "declaration specifiers"); 8774 error_at (loc,
7476 else if (specs->typespec_word == cts_double) 8775 ("both %<unsigned%> and %<float%> in "
7477 error ("both %<unsigned%> and %<double%> in " 8776 "declaration specifiers"));
7478 "declaration specifiers"); 8777 else if (specs->typespec_word == cts_double)
8778 error_at (loc,
8779 ("both %<unsigned%> and %<double%> in "
8780 "declaration specifiers"));
7479 else if (specs->typespec_word == cts_dfloat32) 8781 else if (specs->typespec_word == cts_dfloat32)
7480 error ("both %<unsigned%> and %<_Decimal32%> in " 8782 error_at (loc,
7481 "declaration specifiers"); 8783 ("both %<unsigned%> and %<_Decimal32%> in "
7482 else if (specs->typespec_word == cts_dfloat64) 8784 "declaration specifiers"));
7483 error ("both %<unsigned%> and %<_Decimal64%> in " 8785 else if (specs->typespec_word == cts_dfloat64)
7484 "declaration specifiers"); 8786 error_at (loc,
7485 else if (specs->typespec_word == cts_dfloat128) 8787 ("both %<unsigned%> and %<_Decimal64%> in "
7486 error ("both %<unsigned%> and %<_Decimal128%> in " 8788 "declaration specifiers"));
7487 "declaration specifiers"); 8789 else if (specs->typespec_word == cts_dfloat128)
7488 else 8790 error_at (loc,
7489 specs->unsigned_p = true; 8791 ("both %<unsigned%> and %<_Decimal128%> in "
7490 break; 8792 "declaration specifiers"));
7491 case RID_COMPLEX: 8793 else
7492 dupe = specs->complex_p; 8794 specs->unsigned_p = true;
7493 if (!flag_isoc99 && !in_system_header) 8795 break;
7494 pedwarn (input_location, OPT_pedantic, "ISO C90 does not support complex types"); 8796 case RID_COMPLEX:
7495 if (specs->typespec_word == cts_void) 8797 dupe = specs->complex_p;
7496 error ("both %<complex%> and %<void%> in " 8798 if (!flag_isoc99 && !in_system_header)
7497 "declaration specifiers"); 8799 pedwarn (loc, OPT_pedantic,
8800 "ISO C90 does not support complex types");
8801 if (specs->typespec_word == cts_void)
8802 error_at (loc,
8803 ("both %<complex%> and %<void%> in "
8804 "declaration specifiers"));
7498 #ifndef noCbC 8805 #ifndef noCbC
7499 else if (specs->typespec_word == cts_CbC_code) 8806 else if (specs->typespec_word == cts_CbC_code)
7500 error ("both %<complex%> and %<void%> in " 8807 error_at (loc,
7501 "declaration specifiers"); 8808 ("both %<complex%> and %<void%> in "
8809 "declaration specifiers"));
7502 #endif 8810 #endif
7503 else if (specs->typespec_word == cts_bool) 8811 else if (specs->typespec_word == cts_bool)
7504 error ("both %<complex%> and %<_Bool%> in " 8812 error_at (loc,
7505 "declaration specifiers"); 8813 ("both %<complex%> and %<_Bool%> in "
8814 "declaration specifiers"));
7506 else if (specs->typespec_word == cts_dfloat32) 8815 else if (specs->typespec_word == cts_dfloat32)
7507 error ("both %<complex%> and %<_Decimal32%> in " 8816 error_at (loc,
7508 "declaration specifiers"); 8817 ("both %<complex%> and %<_Decimal32%> in "
7509 else if (specs->typespec_word == cts_dfloat64) 8818 "declaration specifiers"));
7510 error ("both %<complex%> and %<_Decimal64%> in " 8819 else if (specs->typespec_word == cts_dfloat64)
7511 "declaration specifiers"); 8820 error_at (loc,
7512 else if (specs->typespec_word == cts_dfloat128) 8821 ("both %<complex%> and %<_Decimal64%> in "
7513 error ("both %<complex%> and %<_Decimal128%> in " 8822 "declaration specifiers"));
7514 "declaration specifiers"); 8823 else if (specs->typespec_word == cts_dfloat128)
7515 else if (specs->typespec_word == cts_fract) 8824 error_at (loc,
7516 error ("both %<complex%> and %<_Fract%> in " 8825 ("both %<complex%> and %<_Decimal128%> in "
7517 "declaration specifiers"); 8826 "declaration specifiers"));
7518 else if (specs->typespec_word == cts_accum) 8827 else if (specs->typespec_word == cts_fract)
7519 error ("both %<complex%> and %<_Accum%> in " 8828 error_at (loc,
7520 "declaration specifiers"); 8829 ("both %<complex%> and %<_Fract%> in "
7521 else if (specs->saturating_p) 8830 "declaration specifiers"));
7522 error ("both %<complex%> and %<_Sat%> in " 8831 else if (specs->typespec_word == cts_accum)
7523 "declaration specifiers"); 8832 error_at (loc,
7524 else 8833 ("both %<complex%> and %<_Accum%> in "
7525 specs->complex_p = true; 8834 "declaration specifiers"));
7526 break; 8835 else if (specs->saturating_p)
7527 case RID_SAT: 8836 error_at (loc,
7528 dupe = specs->saturating_p; 8837 ("both %<complex%> and %<_Sat%> in "
7529 pedwarn (input_location, OPT_pedantic, "ISO C does not support saturating types"); 8838 "declaration specifiers"));
7530 if (specs->typespec_word == cts_void) 8839 else
7531 error ("both %<_Sat%> and %<void%> in " 8840 specs->complex_p = true;
7532 "declaration specifiers"); 8841 break;
7533 else if (specs->typespec_word == cts_bool) 8842 case RID_SAT:
7534 error ("both %<_Sat%> and %<_Bool%> in " 8843 dupe = specs->saturating_p;
7535 "declaration specifiers"); 8844 pedwarn (loc, OPT_pedantic,
7536 else if (specs->typespec_word == cts_char) 8845 "ISO C does not support saturating types");
7537 error ("both %<_Sat%> and %<char%> in " 8846 if (specs->typespec_word == cts_void)
7538 "declaration specifiers"); 8847 error_at (loc,
7539 else if (specs->typespec_word == cts_int) 8848 ("both %<_Sat%> and %<void%> in "
7540 error ("both %<_Sat%> and %<int%> in " 8849 "declaration specifiers"));
7541 "declaration specifiers"); 8850 else if (specs->typespec_word == cts_bool)
7542 else if (specs->typespec_word == cts_float) 8851 error_at (loc,
7543 error ("both %<_Sat%> and %<float%> in " 8852 ("both %<_Sat%> and %<_Bool%> in "
7544 "declaration specifiers"); 8853 "declaration specifiers"));
7545 else if (specs->typespec_word == cts_double) 8854 else if (specs->typespec_word == cts_char)
7546 error ("both %<_Sat%> and %<double%> in " 8855 error_at (loc,
7547 "declaration specifiers"); 8856 ("both %<_Sat%> and %<char%> in "
8857 "declaration specifiers"));
8858 else if (specs->typespec_word == cts_int)
8859 error_at (loc,
8860 ("both %<_Sat%> and %<int%> in "
8861 "declaration specifiers"));
8862 else if (specs->typespec_word == cts_float)
8863 error_at (loc,
8864 ("both %<_Sat%> and %<float%> in "
8865 "declaration specifiers"));
8866 else if (specs->typespec_word == cts_double)
8867 error_at (loc,
8868 ("both %<_Sat%> and %<double%> in "
8869 "declaration specifiers"));
7548 else if (specs->typespec_word == cts_dfloat32) 8870 else if (specs->typespec_word == cts_dfloat32)
7549 error ("both %<_Sat%> and %<_Decimal32%> in " 8871 error_at (loc,
7550 "declaration specifiers"); 8872 ("both %<_Sat%> and %<_Decimal32%> in "
7551 else if (specs->typespec_word == cts_dfloat64) 8873 "declaration specifiers"));
7552 error ("both %<_Sat%> and %<_Decimal64%> in " 8874 else if (specs->typespec_word == cts_dfloat64)
7553 "declaration specifiers"); 8875 error_at (loc,
7554 else if (specs->typespec_word == cts_dfloat128) 8876 ("both %<_Sat%> and %<_Decimal64%> in "
7555 error ("both %<_Sat%> and %<_Decimal128%> in " 8877 "declaration specifiers"));
7556 "declaration specifiers"); 8878 else if (specs->typespec_word == cts_dfloat128)
7557 else if (specs->complex_p) 8879 error_at (loc,
7558 error ("both %<_Sat%> and %<complex%> in " 8880 ("both %<_Sat%> and %<_Decimal128%> in "
7559 "declaration specifiers"); 8881 "declaration specifiers"));
7560 else 8882 else if (specs->complex_p)
7561 specs->saturating_p = true; 8883 error_at (loc,
7562 break; 8884 ("both %<_Sat%> and %<complex%> in "
7563 default: 8885 "declaration specifiers"));
7564 gcc_unreachable (); 8886 else
7565 } 8887 specs->saturating_p = true;
7566 8888 break;
7567 if (dupe) 8889 default:
7568 error ("duplicate %qE", type); 8890 gcc_unreachable ();
7569 8891 }
7570 return specs; 8892
7571 } 8893 if (dupe)
8894 error_at (loc, "duplicate %qE", type);
8895
8896 return specs;
8897 }
7572 else 8898 else
7573 { 8899 {
7574 /* "void", "_Bool", "char", "int", "float", "double", "_Decimal32", 8900 /* "void", "_Bool", "char", "int", "float", "double", "_Decimal32",
7575 "_Decimal64", "_Decimal128", "_Fract" or "_Accum". */ 8901 "_Decimal64", "_Decimal128", "_Fract" or "_Accum". */
7576 if (specs->typespec_word != cts_none) 8902 if (specs->typespec_word != cts_none)
7577 { 8903 {
7578 error ("two or more data types in declaration specifiers"); 8904 error_at (loc,
7579 return specs; 8905 "two or more data types in declaration specifiers");
7580 } 8906 return specs;
7581 switch (i) 8907 }
7582 { 8908 switch (i)
7583 case RID_VOID: 8909 {
7584 if (specs->long_p) 8910 case RID_VOID:
7585 error ("both %<long%> and %<void%> in " 8911 if (specs->long_p)
7586 "declaration specifiers"); 8912 error_at (loc,
7587 else if (specs->short_p) 8913 ("both %<long%> and %<void%> in "
7588 error ("both %<short%> and %<void%> in " 8914 "declaration specifiers"));
7589 "declaration specifiers"); 8915 else if (specs->short_p)
7590 else if (specs->signed_p) 8916 error_at (loc,
7591 error ("both %<signed%> and %<void%> in " 8917 ("both %<short%> and %<void%> in "
7592 "declaration specifiers"); 8918 "declaration specifiers"));
7593 else if (specs->unsigned_p) 8919 else if (specs->signed_p)
7594 error ("both %<unsigned%> and %<void%> in " 8920 error_at (loc,
7595 "declaration specifiers"); 8921 ("both %<signed%> and %<void%> in "
7596 else if (specs->complex_p) 8922 "declaration specifiers"));
7597 error ("both %<complex%> and %<void%> in " 8923 else if (specs->unsigned_p)
7598 "declaration specifiers"); 8924 error_at (loc,
7599 else if (specs->saturating_p) 8925 ("both %<unsigned%> and %<void%> in "
7600 error ("both %<_Sat%> and %<void%> in " 8926 "declaration specifiers"));
7601 "declaration specifiers"); 8927 else if (specs->complex_p)
7602 else 8928 error_at (loc,
7603 specs->typespec_word = cts_void; 8929 ("both %<complex%> and %<void%> in "
7604 return specs; 8930 "declaration specifiers"));
8931 else if (specs->saturating_p)
8932 error_at (loc,
8933 ("both %<_Sat%> and %<void%> in "
8934 "declaration specifiers"));
8935 else
8936 specs->typespec_word = cts_void;
8937 return specs;
7605 #ifndef noCbC 8938 #ifndef noCbC
7606 case RID_CbC_CODE: 8939 case RID_CbC_CODE:
7607 if (specs->long_p) 8940 if (specs->long_p)
7608 error ("both %<long%> and %<void%> in " 8941 error ("both %<long%> and %<void%> in "
7609 "declaration specifiers"); 8942 "declaration specifiers");
7610 else if (specs->short_p) 8943 else if (specs->short_p)
7611 error ("both %<short%> and %<void%> in " 8944 error ("both %<short%> and %<void%> in "
7612 "declaration specifiers"); 8945 "declaration specifiers");
7613 else if (specs->signed_p) 8946 else if (specs->signed_p)
7614 error ("both %<signed%> and %<void%> in " 8947 error ("both %<signed%> and %<void%> in "
7615 "declaration specifiers"); 8948 "declaration specifiers");
7616 else if (specs->unsigned_p) 8949 else if (specs->unsigned_p)
7617 error ("both %<unsigned%> and %<void%> in " 8950 error ("both %<unsigned%> and %<void%> in "
7618 "declaration specifiers"); 8951 "declaration specifiers");
7619 else if (specs->complex_p) 8952 else if (specs->complex_p)
7620 error ("both %<complex%> and %<void%> in " 8953 error ("both %<complex%> and %<void%> in "
7621 "declaration specifiers"); 8954 "declaration specifiers");
7622 else 8955 else
7623 specs->typespec_word = cts_CbC_code; 8956 specs->typespec_word = cts_CbC_code;
7624 return specs; 8957 return specs;
7625 #endif 8958 #endif
7626 case RID_BOOL: 8959 case RID_BOOL:
7627 if (specs->long_p) 8960 if (specs->long_p)
7628 error ("both %<long%> and %<_Bool%> in " 8961 error_at (loc,
7629 "declaration specifiers"); 8962 ("both %<long%> and %<_Bool%> in "
7630 else if (specs->short_p) 8963 "declaration specifiers"));
7631 error ("both %<short%> and %<_Bool%> in " 8964 else if (specs->short_p)
7632 "declaration specifiers"); 8965 error_at (loc,
7633 else if (specs->signed_p) 8966 ("both %<short%> and %<_Bool%> in "
7634 error ("both %<signed%> and %<_Bool%> in " 8967 "declaration specifiers"));
7635 "declaration specifiers"); 8968 else if (specs->signed_p)
7636 else if (specs->unsigned_p) 8969 error_at (loc,
7637 error ("both %<unsigned%> and %<_Bool%> in " 8970 ("both %<signed%> and %<_Bool%> in "
7638 "declaration specifiers"); 8971 "declaration specifiers"));
7639 else if (specs->complex_p) 8972 else if (specs->unsigned_p)
7640 error ("both %<complex%> and %<_Bool%> in " 8973 error_at (loc,
7641 "declaration specifiers"); 8974 ("both %<unsigned%> and %<_Bool%> in "
7642 else if (specs->saturating_p) 8975 "declaration specifiers"));
7643 error ("both %<_Sat%> and %<_Bool%> in " 8976 else if (specs->complex_p)
7644 "declaration specifiers"); 8977 error_at (loc,
7645 else 8978 ("both %<complex%> and %<_Bool%> in "
7646 specs->typespec_word = cts_bool; 8979 "declaration specifiers"));
7647 return specs; 8980 else if (specs->saturating_p)
7648 case RID_CHAR: 8981 error_at (loc,
7649 if (specs->long_p) 8982 ("both %<_Sat%> and %<_Bool%> in "
7650 error ("both %<long%> and %<char%> in " 8983 "declaration specifiers"));
7651 "declaration specifiers"); 8984 else
7652 else if (specs->short_p) 8985 specs->typespec_word = cts_bool;
7653 error ("both %<short%> and %<char%> in " 8986 return specs;
7654 "declaration specifiers"); 8987 case RID_CHAR:
7655 else if (specs->saturating_p) 8988 if (specs->long_p)
7656 error ("both %<_Sat%> and %<char%> in " 8989 error_at (loc,
7657 "declaration specifiers"); 8990 ("both %<long%> and %<char%> in "
7658 else 8991 "declaration specifiers"));
7659 specs->typespec_word = cts_char; 8992 else if (specs->short_p)
7660 return specs; 8993 error_at (loc,
7661 case RID_INT: 8994 ("both %<short%> and %<char%> in "
7662 if (specs->saturating_p) 8995 "declaration specifiers"));
7663 error ("both %<_Sat%> and %<int%> in " 8996 else if (specs->saturating_p)
7664 "declaration specifiers"); 8997 error_at (loc,
7665 else 8998 ("both %<_Sat%> and %<char%> in "
7666 specs->typespec_word = cts_int; 8999 "declaration specifiers"));
7667 return specs; 9000 else
7668 case RID_FLOAT: 9001 specs->typespec_word = cts_char;
7669 if (specs->long_p) 9002 return specs;
7670 error ("both %<long%> and %<float%> in " 9003 case RID_INT:
7671 "declaration specifiers"); 9004 if (specs->saturating_p)
7672 else if (specs->short_p) 9005 error_at (loc,
7673 error ("both %<short%> and %<float%> in " 9006 ("both %<_Sat%> and %<int%> in "
7674 "declaration specifiers"); 9007 "declaration specifiers"));
7675 else if (specs->signed_p) 9008 else
7676 error ("both %<signed%> and %<float%> in " 9009 specs->typespec_word = cts_int;
7677 "declaration specifiers"); 9010 return specs;
7678 else if (specs->unsigned_p) 9011 case RID_FLOAT:
7679 error ("both %<unsigned%> and %<float%> in " 9012 if (specs->long_p)
7680 "declaration specifiers"); 9013 error_at (loc,
7681 else if (specs->saturating_p) 9014 ("both %<long%> and %<float%> in "
7682 error ("both %<_Sat%> and %<float%> in " 9015 "declaration specifiers"));
7683 "declaration specifiers"); 9016 else if (specs->short_p)
7684 else 9017 error_at (loc,
7685 specs->typespec_word = cts_float; 9018 ("both %<short%> and %<float%> in "
7686 return specs; 9019 "declaration specifiers"));
7687 case RID_DOUBLE: 9020 else if (specs->signed_p)
7688 if (specs->long_long_p) 9021 error_at (loc,
7689 error ("both %<long long%> and %<double%> in " 9022 ("both %<signed%> and %<float%> in "
7690 "declaration specifiers"); 9023 "declaration specifiers"));
7691 else if (specs->short_p) 9024 else if (specs->unsigned_p)
7692 error ("both %<short%> and %<double%> in " 9025 error_at (loc,
7693 "declaration specifiers"); 9026 ("both %<unsigned%> and %<float%> in "
7694 else if (specs->signed_p) 9027 "declaration specifiers"));
7695 error ("both %<signed%> and %<double%> in " 9028 else if (specs->saturating_p)
7696 "declaration specifiers"); 9029 error_at (loc,
7697 else if (specs->unsigned_p) 9030 ("both %<_Sat%> and %<float%> in "
7698 error ("both %<unsigned%> and %<double%> in " 9031 "declaration specifiers"));
7699 "declaration specifiers"); 9032 else
7700 else if (specs->saturating_p) 9033 specs->typespec_word = cts_float;
7701 error ("both %<_Sat%> and %<double%> in " 9034 return specs;
7702 "declaration specifiers"); 9035 case RID_DOUBLE:
7703 else 9036 if (specs->long_long_p)
7704 specs->typespec_word = cts_double; 9037 error_at (loc,
7705 return specs; 9038 ("both %<long long%> and %<double%> in "
7706 case RID_DFLOAT32: 9039 "declaration specifiers"));
7707 case RID_DFLOAT64: 9040 else if (specs->short_p)
7708 case RID_DFLOAT128: 9041 error_at (loc,
7709 { 9042 ("both %<short%> and %<double%> in "
7710 const char *str; 9043 "declaration specifiers"));
7711 if (i == RID_DFLOAT32) 9044 else if (specs->signed_p)
7712 str = "_Decimal32"; 9045 error_at (loc,
7713 else if (i == RID_DFLOAT64) 9046 ("both %<signed%> and %<double%> in "
7714 str = "_Decimal64"; 9047 "declaration specifiers"));
7715 else 9048 else if (specs->unsigned_p)
7716 str = "_Decimal128"; 9049 error_at (loc,
7717 if (specs->long_long_p) 9050 ("both %<unsigned%> and %<double%> in "
7718 error ("both %<long long%> and %<%s%> in " 9051 "declaration specifiers"));
7719 "declaration specifiers", str); 9052 else if (specs->saturating_p)
7720 if (specs->long_p) 9053 error_at (loc,
7721 error ("both %<long%> and %<%s%> in " 9054 ("both %<_Sat%> and %<double%> in "
7722 "declaration specifiers", str); 9055 "declaration specifiers"));
7723 else if (specs->short_p) 9056 else
7724 error ("both %<short%> and %<%s%> in " 9057 specs->typespec_word = cts_double;
7725 "declaration specifiers", str); 9058 return specs;
7726 else if (specs->signed_p) 9059 case RID_DFLOAT32:
7727 error ("both %<signed%> and %<%s%> in " 9060 case RID_DFLOAT64:
7728 "declaration specifiers", str); 9061 case RID_DFLOAT128:
7729 else if (specs->unsigned_p) 9062 {
7730 error ("both %<unsigned%> and %<%s%> in " 9063 const char *str;
7731 "declaration specifiers", str); 9064 if (i == RID_DFLOAT32)
9065 str = "_Decimal32";
9066 else if (i == RID_DFLOAT64)
9067 str = "_Decimal64";
9068 else
9069 str = "_Decimal128";
9070 if (specs->long_long_p)
9071 error_at (loc,
9072 ("both %<long long%> and %<%s%> in "
9073 "declaration specifiers"),
9074 str);
9075 if (specs->long_p)
9076 error_at (loc,
9077 ("both %<long%> and %<%s%> in "
9078 "declaration specifiers"),
9079 str);
9080 else if (specs->short_p)
9081 error_at (loc,
9082 ("both %<short%> and %<%s%> in "
9083 "declaration specifiers"),
9084 str);
9085 else if (specs->signed_p)
9086 error_at (loc,
9087 ("both %<signed%> and %<%s%> in "
9088 "declaration specifiers"),
9089 str);
9090 else if (specs->unsigned_p)
9091 error_at (loc,
9092 ("both %<unsigned%> and %<%s%> in "
9093 "declaration specifiers"),
9094 str);
7732 else if (specs->complex_p) 9095 else if (specs->complex_p)
7733 error ("both %<complex%> and %<%s%> in " 9096 error_at (loc,
7734 "declaration specifiers", str); 9097 ("both %<complex%> and %<%s%> in "
9098 "declaration specifiers"),
9099 str);
7735 else if (specs->saturating_p) 9100 else if (specs->saturating_p)
7736 error ("both %<_Sat%> and %<%s%> in " 9101 error_at (loc,
7737 "declaration specifiers", str); 9102 ("both %<_Sat%> and %<%s%> in "
7738 else if (i == RID_DFLOAT32) 9103 "declaration specifiers"),
7739 specs->typespec_word = cts_dfloat32; 9104 str);
7740 else if (i == RID_DFLOAT64) 9105 else if (i == RID_DFLOAT32)
7741 specs->typespec_word = cts_dfloat64; 9106 specs->typespec_word = cts_dfloat32;
7742 else 9107 else if (i == RID_DFLOAT64)
7743 specs->typespec_word = cts_dfloat128; 9108 specs->typespec_word = cts_dfloat64;
7744 } 9109 else
7745 if (!targetm.decimal_float_supported_p ()) 9110 specs->typespec_word = cts_dfloat128;
7746 error ("decimal floating point not supported for this target"); 9111 }
7747 pedwarn (input_location, OPT_pedantic, 9112 if (!targetm.decimal_float_supported_p ())
7748 "ISO C does not support decimal floating point"); 9113 error_at (loc,
7749 return specs; 9114 ("decimal floating point not supported "
7750 case RID_FRACT: 9115 "for this target"));
7751 case RID_ACCUM: 9116 pedwarn (loc, OPT_pedantic,
7752 { 9117 "ISO C does not support decimal floating point");
7753 const char *str; 9118 return specs;
7754 if (i == RID_FRACT) 9119 case RID_FRACT:
7755 str = "_Fract"; 9120 case RID_ACCUM:
7756 else 9121 {
7757 str = "_Accum"; 9122 const char *str;
9123 if (i == RID_FRACT)
9124 str = "_Fract";
9125 else
9126 str = "_Accum";
7758 if (specs->complex_p) 9127 if (specs->complex_p)
7759 error ("both %<complex%> and %<%s%> in " 9128 error_at (loc,
7760 "declaration specifiers", str); 9129 ("both %<complex%> and %<%s%> in "
7761 else if (i == RID_FRACT) 9130 "declaration specifiers"),
7762 specs->typespec_word = cts_fract; 9131 str);
7763 else 9132 else if (i == RID_FRACT)
7764 specs->typespec_word = cts_accum; 9133 specs->typespec_word = cts_fract;
7765 } 9134 else
7766 if (!targetm.fixed_point_supported_p ()) 9135 specs->typespec_word = cts_accum;
7767 error ("fixed-point types not supported for this target"); 9136 }
7768 pedwarn (input_location, OPT_pedantic, 9137 if (!targetm.fixed_point_supported_p ())
7769 "ISO C does not support fixed-point types"); 9138 error_at (loc,
7770 return specs; 9139 "fixed-point types not supported for this target");
7771 default: 9140 pedwarn (loc, OPT_pedantic,
7772 /* ObjC reserved word "id", handled below. */ 9141 "ISO C does not support fixed-point types");
7773 break; 9142 return specs;
7774 } 9143 default:
7775 } 9144 /* ObjC reserved word "id", handled below. */
9145 break;
9146 }
9147 }
7776 } 9148 }
7777 9149
7778 /* Now we have a typedef (a TYPE_DECL node), an identifier (some 9150 /* Now we have a typedef (a TYPE_DECL node), an identifier (some
7779 form of ObjC type, cases such as "int" and "long" being handled 9151 form of ObjC type, cases such as "int" and "long" being handled
7780 above), a TYPE (struct, union, enum and typeof specifiers) or an 9152 above), a TYPE (struct, union, enum and typeof specifiers) or an
7781 ERROR_MARK. In none of these cases may there have previously 9153 ERROR_MARK. In none of these cases may there have previously
7782 been any type specifiers. */ 9154 been any type specifiers. */
7783 if (specs->type || specs->typespec_word != cts_none 9155 if (specs->type || specs->typespec_word != cts_none
7784 || specs->long_p || specs->short_p || specs->signed_p 9156 || specs->long_p || specs->short_p || specs->signed_p
7785 || specs->unsigned_p || specs->complex_p) 9157 || specs->unsigned_p || specs->complex_p)
7786 error ("two or more data types in declaration specifiers"); 9158 error_at (loc, "two or more data types in declaration specifiers");
7787 else if (TREE_CODE (type) == TYPE_DECL) 9159 else if (TREE_CODE (type) == TYPE_DECL)
7788 { 9160 {
7789 if (TREE_TYPE (type) == error_mark_node) 9161 if (TREE_TYPE (type) == error_mark_node)
7790 ; /* Allow the type to default to int to avoid cascading errors. */ 9162 ; /* Allow the type to default to int to avoid cascading errors. */
7791 else 9163 else
7792 { 9164 {
7793 specs->type = TREE_TYPE (type); 9165 specs->type = TREE_TYPE (type);
7794 specs->decl_attr = DECL_ATTRIBUTES (type); 9166 specs->decl_attr = DECL_ATTRIBUTES (type);
7795 specs->typedef_p = true; 9167 specs->typedef_p = true;
7796 specs->explicit_signed_p = C_TYPEDEF_EXPLICITLY_SIGNED (type); 9168 specs->explicit_signed_p = C_TYPEDEF_EXPLICITLY_SIGNED (type);
7797 } 9169
9170 /* If this typedef name is defined in a struct, then a C++
9171 lookup would return a different value. */
9172 if (warn_cxx_compat
9173 && I_SYMBOL_BINDING (DECL_NAME (type))->in_struct)
9174 warning_at (loc, OPT_Wc___compat,
9175 "C++ lookup of %qD would return a field, not a type",
9176 type);
9177
9178 /* If we are parsing a struct, record that a struct field
9179 used a typedef. */
9180 if (warn_cxx_compat && struct_parse_info != NULL)
9181 VEC_safe_push (tree, heap, struct_parse_info->typedefs_seen, type);
9182 }
7798 } 9183 }
7799 else if (TREE_CODE (type) == IDENTIFIER_NODE) 9184 else if (TREE_CODE (type) == IDENTIFIER_NODE)
7800 { 9185 {
7801 tree t = lookup_name (type); 9186 tree t = lookup_name (type);
7802 if (!t || TREE_CODE (t) != TYPE_DECL) 9187 if (!t || TREE_CODE (t) != TYPE_DECL)
7803 error ("%qE fails to be a typedef or built in type", type); 9188 error_at (loc, "%qE fails to be a typedef or built in type", type);
7804 else if (TREE_TYPE (t) == error_mark_node) 9189 else if (TREE_TYPE (t) == error_mark_node)
7805 ; 9190 ;
7806 else 9191 else
7807 specs->type = TREE_TYPE (t); 9192 specs->type = TREE_TYPE (t);
7808 } 9193 }
7809 else if (TREE_CODE (type) != ERROR_MARK) 9194 else if (TREE_CODE (type) != ERROR_MARK)
7810 { 9195 {
7811 if (spec.kind == ctsk_tagdef || spec.kind == ctsk_tagfirstref) 9196 if (spec.kind == ctsk_tagdef || spec.kind == ctsk_tagfirstref)
7812 specs->tag_defined_p = true; 9197 specs->tag_defined_p = true;
7813 if (spec.kind == ctsk_typeof) 9198 if (spec.kind == ctsk_typeof)
7814 specs->typedef_p = true; 9199 {
9200 specs->typedef_p = true;
9201 if (spec.expr)
9202 {
9203 if (specs->expr)
9204 specs->expr = build2 (COMPOUND_EXPR, TREE_TYPE (spec.expr),
9205 specs->expr, spec.expr);
9206 else
9207 specs->expr = spec.expr;
9208 specs->expr_const_operands &= spec.expr_const_operands;
9209 }
9210 }
7815 specs->type = type; 9211 specs->type = type;
7816 } 9212 }
7817 9213
7818 return specs; 9214 return specs;
7819 } 9215 }
7827 enum rid i; 9223 enum rid i;
7828 enum c_storage_class n = csc_none; 9224 enum c_storage_class n = csc_none;
7829 bool dupe = false; 9225 bool dupe = false;
7830 specs->declspecs_seen_p = true; 9226 specs->declspecs_seen_p = true;
7831 gcc_assert (TREE_CODE (scspec) == IDENTIFIER_NODE 9227 gcc_assert (TREE_CODE (scspec) == IDENTIFIER_NODE
7832 && C_IS_RESERVED_WORD (scspec)); 9228 && C_IS_RESERVED_WORD (scspec));
7833 i = C_RID_CODE (scspec); 9229 i = C_RID_CODE (scspec);
7834 if (specs->non_sc_seen_p) 9230 if (specs->non_sc_seen_p)
7835 warning (OPT_Wold_style_declaration, 9231 warning (OPT_Wold_style_declaration,
7836 "%qE is not at beginning of declaration", scspec); 9232 "%qE is not at beginning of declaration", scspec);
7837 switch (i) 9233 switch (i)
7838 { 9234 {
7839 case RID_INLINE: 9235 case RID_INLINE:
7840 /* C99 permits duplicate inline. Although of doubtful utility, 9236 /* C99 permits duplicate inline. Although of doubtful utility,
7841 it seems simplest to permit it in gnu89 mode as well, as 9237 it seems simplest to permit it in gnu89 mode as well, as
7842 there is also little utility in maintaining this as a 9238 there is also little utility in maintaining this as a
7843 difference between gnu89 and C99 inline. */ 9239 difference between gnu89 and C99 inline. */
7844 dupe = false; 9240 dupe = false;
7845 specs->inline_p = true; 9241 specs->inline_p = true;
7846 break; 9242 break;
7847 case RID_THREAD: 9243 case RID_THREAD:
7848 dupe = specs->thread_p; 9244 dupe = specs->thread_p;
7849 if (specs->storage_class == csc_auto) 9245 if (specs->storage_class == csc_auto)
7850 error ("%<__thread%> used with %<auto%>"); 9246 error ("%<__thread%> used with %<auto%>");
7851 else if (specs->storage_class == csc_register) 9247 else if (specs->storage_class == csc_register)
7852 error ("%<__thread%> used with %<register%>"); 9248 error ("%<__thread%> used with %<register%>");
7853 else if (specs->storage_class == csc_typedef) 9249 else if (specs->storage_class == csc_typedef)
7854 error ("%<__thread%> used with %<typedef%>"); 9250 error ("%<__thread%> used with %<typedef%>");
7855 else 9251 else
7856 specs->thread_p = true; 9252 specs->thread_p = true;
7857 break; 9253 break;
7858 case RID_AUTO: 9254 case RID_AUTO:
7859 n = csc_auto; 9255 n = csc_auto;
7860 break; 9256 break;
7861 case RID_EXTERN: 9257 case RID_EXTERN:
7862 n = csc_extern; 9258 n = csc_extern;
7863 /* Diagnose "__thread extern". */ 9259 /* Diagnose "__thread extern". */
7864 if (specs->thread_p) 9260 if (specs->thread_p)
7865 error ("%<__thread%> before %<extern%>"); 9261 error ("%<__thread%> before %<extern%>");
7866 break; 9262 break;
7867 case RID_REGISTER: 9263 case RID_REGISTER:
7868 n = csc_register; 9264 n = csc_register;
7869 break; 9265 break;
7870 case RID_STATIC: 9266 case RID_STATIC:
7871 n = csc_static; 9267 n = csc_static;
7872 /* Diagnose "__thread static". */ 9268 /* Diagnose "__thread static". */
7873 if (specs->thread_p) 9269 if (specs->thread_p)
7874 error ("%<__thread%> before %<static%>"); 9270 error ("%<__thread%> before %<static%>");
7875 break; 9271 break;
7876 case RID_TYPEDEF: 9272 case RID_TYPEDEF:
7877 n = csc_typedef; 9273 n = csc_typedef;
7878 break; 9274 break;
7879 default: 9275 default:
7884 if (dupe) 9280 if (dupe)
7885 error ("duplicate %qE", scspec); 9281 error ("duplicate %qE", scspec);
7886 if (n != csc_none) 9282 if (n != csc_none)
7887 { 9283 {
7888 if (specs->storage_class != csc_none && n != specs->storage_class) 9284 if (specs->storage_class != csc_none && n != specs->storage_class)
7889 { 9285 {
7890 error ("multiple storage classes in declaration specifiers"); 9286 error ("multiple storage classes in declaration specifiers");
7891 } 9287 }
7892 else 9288 else
7893 { 9289 {
7894 specs->storage_class = n; 9290 specs->storage_class = n;
7895 if (n != csc_extern && n != csc_static && specs->thread_p) 9291 if (n != csc_extern && n != csc_static && specs->thread_p)
7896 { 9292 {
7897 error ("%<__thread%> used with %qE", scspec); 9293 error ("%<__thread%> used with %qE", scspec);
7898 specs->thread_p = false; 9294 specs->thread_p = false;
7899 } 9295 }
7900 } 9296 }
7901 } 9297 }
7902 return specs; 9298 return specs;
7903 } 9299 }
7904 9300
7905 /* Add the attributes ATTRS to the declaration specifiers SPECS, 9301 /* Add the attributes ATTRS to the declaration specifiers SPECS,
7925 /* If a type was specified as a whole, we have no modifiers and are 9321 /* If a type was specified as a whole, we have no modifiers and are
7926 done. */ 9322 done. */
7927 if (specs->type != NULL_TREE) 9323 if (specs->type != NULL_TREE)
7928 { 9324 {
7929 gcc_assert (!specs->long_p && !specs->long_long_p && !specs->short_p 9325 gcc_assert (!specs->long_p && !specs->long_long_p && !specs->short_p
7930 && !specs->signed_p && !specs->unsigned_p 9326 && !specs->signed_p && !specs->unsigned_p
7931 && !specs->complex_p); 9327 && !specs->complex_p);
7932 return specs; 9328 return specs;
7933 } 9329 }
7934 9330
7935 /* If none of "void", "_Bool", "char", "int", "float" or "double" 9331 /* If none of "void", "_Bool", "char", "int", "float" or "double"
7936 has been specified, treat it as "int" unless "_Complex" is 9332 has been specified, treat it as "int" unless "_Complex" is
7938 "_Complex", it is equivalent to "_Complex double", but e.g. 9334 "_Complex", it is equivalent to "_Complex double", but e.g.
7939 "_Complex short" is equivalent to "_Complex short int". */ 9335 "_Complex short" is equivalent to "_Complex short int". */
7940 if (specs->typespec_word == cts_none) 9336 if (specs->typespec_word == cts_none)
7941 { 9337 {
7942 if (specs->saturating_p) 9338 if (specs->saturating_p)
7943 { 9339 {
7944 error ("%<_Sat%> is used without %<_Fract%> or %<_Accum%>"); 9340 error ("%<_Sat%> is used without %<_Fract%> or %<_Accum%>");
7945 if (!targetm.fixed_point_supported_p ()) 9341 if (!targetm.fixed_point_supported_p ())
7946 error ("fixed-point types not supported for this target"); 9342 error ("fixed-point types not supported for this target");
7947 specs->typespec_word = cts_fract; 9343 specs->typespec_word = cts_fract;
7948 } 9344 }
7949 else if (specs->long_p || specs->short_p 9345 else if (specs->long_p || specs->short_p
7950 || specs->signed_p || specs->unsigned_p) 9346 || specs->signed_p || specs->unsigned_p)
7951 { 9347 {
7952 specs->typespec_word = cts_int; 9348 specs->typespec_word = cts_int;
7953 } 9349 }
7954 else if (specs->complex_p) 9350 else if (specs->complex_p)
7955 { 9351 {
7956 specs->typespec_word = cts_double; 9352 specs->typespec_word = cts_double;
7957 pedwarn (input_location, OPT_pedantic, 9353 pedwarn (input_location, OPT_pedantic,
7958 "ISO C does not support plain %<complex%> meaning " 9354 "ISO C does not support plain %<complex%> meaning "
7959 "%<double complex%>"); 9355 "%<double complex%>");
7960 } 9356 }
7961 else 9357 else
7962 { 9358 {
7963 specs->typespec_word = cts_int; 9359 specs->typespec_word = cts_int;
7964 specs->default_int_p = true; 9360 specs->default_int_p = true;
7965 /* We don't diagnose this here because grokdeclarator will 9361 /* We don't diagnose this here because grokdeclarator will
7966 give more specific diagnostics according to whether it is 9362 give more specific diagnostics according to whether it is
7967 a function definition. */ 9363 a function definition. */
7968 } 9364 }
7969 } 9365 }
7970 9366
7971 /* If "signed" was specified, record this to distinguish "int" and 9367 /* If "signed" was specified, record this to distinguish "int" and
7972 "signed int" in the case of a bit-field with 9368 "signed int" in the case of a bit-field with
7973 -funsigned-bitfields. */ 9369 -funsigned-bitfields. */
7979 case cts_void: 9375 case cts_void:
7980 #ifndef noCbC 9376 #ifndef noCbC
7981 case cts_CbC_code: 9377 case cts_CbC_code:
7982 #endif 9378 #endif
7983 gcc_assert (!specs->long_p && !specs->short_p 9379 gcc_assert (!specs->long_p && !specs->short_p
7984 && !specs->signed_p && !specs->unsigned_p 9380 && !specs->signed_p && !specs->unsigned_p
7985 && !specs->complex_p); 9381 && !specs->complex_p);
7986 specs->type = void_type_node; 9382 specs->type = void_type_node;
7987 break; 9383 break;
7988 case cts_bool: 9384 case cts_bool:
7989 gcc_assert (!specs->long_p && !specs->short_p 9385 gcc_assert (!specs->long_p && !specs->short_p
7990 && !specs->signed_p && !specs->unsigned_p 9386 && !specs->signed_p && !specs->unsigned_p
7991 && !specs->complex_p); 9387 && !specs->complex_p);
7992 specs->type = boolean_type_node; 9388 specs->type = boolean_type_node;
7993 break; 9389 break;
7994 case cts_char: 9390 case cts_char:
7995 gcc_assert (!specs->long_p && !specs->short_p); 9391 gcc_assert (!specs->long_p && !specs->short_p);
7996 gcc_assert (!(specs->signed_p && specs->unsigned_p)); 9392 gcc_assert (!(specs->signed_p && specs->unsigned_p));
7997 if (specs->signed_p) 9393 if (specs->signed_p)
7998 specs->type = signed_char_type_node; 9394 specs->type = signed_char_type_node;
7999 else if (specs->unsigned_p) 9395 else if (specs->unsigned_p)
8000 specs->type = unsigned_char_type_node; 9396 specs->type = unsigned_char_type_node;
8001 else 9397 else
8002 specs->type = char_type_node; 9398 specs->type = char_type_node;
8003 if (specs->complex_p) 9399 if (specs->complex_p)
8004 { 9400 {
8005 pedwarn (input_location, OPT_pedantic, 9401 pedwarn (input_location, OPT_pedantic,
8006 "ISO C does not support complex integer types"); 9402 "ISO C does not support complex integer types");
8007 specs->type = build_complex_type (specs->type); 9403 specs->type = build_complex_type (specs->type);
8008 } 9404 }
8009 break; 9405 break;
8010 case cts_int: 9406 case cts_int:
8011 gcc_assert (!(specs->long_p && specs->short_p)); 9407 gcc_assert (!(specs->long_p && specs->short_p));
8012 gcc_assert (!(specs->signed_p && specs->unsigned_p)); 9408 gcc_assert (!(specs->signed_p && specs->unsigned_p));
8013 if (specs->long_long_p) 9409 if (specs->long_long_p)
8014 specs->type = (specs->unsigned_p 9410 specs->type = (specs->unsigned_p
8015 ? long_long_unsigned_type_node 9411 ? long_long_unsigned_type_node
8016 : long_long_integer_type_node); 9412 : long_long_integer_type_node);
8017 else if (specs->long_p) 9413 else if (specs->long_p)
8018 specs->type = (specs->unsigned_p 9414 specs->type = (specs->unsigned_p
8019 ? long_unsigned_type_node 9415 ? long_unsigned_type_node
8020 : long_integer_type_node); 9416 : long_integer_type_node);
8021 else if (specs->short_p) 9417 else if (specs->short_p)
8022 specs->type = (specs->unsigned_p 9418 specs->type = (specs->unsigned_p
8023 ? short_unsigned_type_node 9419 ? short_unsigned_type_node
8024 : short_integer_type_node); 9420 : short_integer_type_node);
8025 else 9421 else
8026 specs->type = (specs->unsigned_p 9422 specs->type = (specs->unsigned_p
8027 ? unsigned_type_node 9423 ? unsigned_type_node
8028 : integer_type_node); 9424 : integer_type_node);
8029 if (specs->complex_p) 9425 if (specs->complex_p)
8030 { 9426 {
8031 pedwarn (input_location, OPT_pedantic, 9427 pedwarn (input_location, OPT_pedantic,
8032 "ISO C does not support complex integer types"); 9428 "ISO C does not support complex integer types");
8033 specs->type = build_complex_type (specs->type); 9429 specs->type = build_complex_type (specs->type);
8034 } 9430 }
8035 break; 9431 break;
8036 case cts_float: 9432 case cts_float:
8037 gcc_assert (!specs->long_p && !specs->short_p 9433 gcc_assert (!specs->long_p && !specs->short_p
8038 && !specs->signed_p && !specs->unsigned_p); 9434 && !specs->signed_p && !specs->unsigned_p);
8039 specs->type = (specs->complex_p 9435 specs->type = (specs->complex_p
8040 ? complex_float_type_node 9436 ? complex_float_type_node
8041 : float_type_node); 9437 : float_type_node);
8042 break; 9438 break;
8043 case cts_double: 9439 case cts_double:
8044 gcc_assert (!specs->long_long_p && !specs->short_p 9440 gcc_assert (!specs->long_long_p && !specs->short_p
8045 && !specs->signed_p && !specs->unsigned_p); 9441 && !specs->signed_p && !specs->unsigned_p);
8046 if (specs->long_p) 9442 if (specs->long_p)
8047 { 9443 {
8048 specs->type = (specs->complex_p 9444 specs->type = (specs->complex_p
8049 ? complex_long_double_type_node 9445 ? complex_long_double_type_node
8050 : long_double_type_node); 9446 : long_double_type_node);
8051 } 9447 }
8052 else 9448 else
8053 { 9449 {
8054 specs->type = (specs->complex_p 9450 specs->type = (specs->complex_p
8055 ? complex_double_type_node 9451 ? complex_double_type_node
8056 : double_type_node); 9452 : double_type_node);
8057 } 9453 }
8058 break; 9454 break;
8059 case cts_dfloat32: 9455 case cts_dfloat32:
8060 case cts_dfloat64: 9456 case cts_dfloat64:
8061 case cts_dfloat128: 9457 case cts_dfloat128:
8062 gcc_assert (!specs->long_p && !specs->long_long_p && !specs->short_p 9458 gcc_assert (!specs->long_p && !specs->long_long_p && !specs->short_p
8063 && !specs->signed_p && !specs->unsigned_p && !specs->complex_p); 9459 && !specs->signed_p && !specs->unsigned_p && !specs->complex_p);
8064 if (specs->typespec_word == cts_dfloat32) 9460 if (specs->typespec_word == cts_dfloat32)
8065 specs->type = dfloat32_type_node; 9461 specs->type = dfloat32_type_node;
8066 else if (specs->typespec_word == cts_dfloat64) 9462 else if (specs->typespec_word == cts_dfloat64)
8067 specs->type = dfloat64_type_node; 9463 specs->type = dfloat64_type_node;
8068 else 9464 else
8069 specs->type = dfloat128_type_node; 9465 specs->type = dfloat128_type_node;
8070 break; 9466 break;
8071 case cts_fract: 9467 case cts_fract:
8072 gcc_assert (!specs->complex_p); 9468 gcc_assert (!specs->complex_p);
8073 if (!targetm.fixed_point_supported_p ()) 9469 if (!targetm.fixed_point_supported_p ())
8074 specs->type = integer_type_node; 9470 specs->type = integer_type_node;
8075 else if (specs->saturating_p) 9471 else if (specs->saturating_p)
8076 { 9472 {
8077 if (specs->long_long_p) 9473 if (specs->long_long_p)
8078 specs->type = specs->unsigned_p 9474 specs->type = specs->unsigned_p
8079 ? sat_unsigned_long_long_fract_type_node 9475 ? sat_unsigned_long_long_fract_type_node
8080 : sat_long_long_fract_type_node; 9476 : sat_long_long_fract_type_node;
8081 else if (specs->long_p) 9477 else if (specs->long_p)
8082 specs->type = specs->unsigned_p 9478 specs->type = specs->unsigned_p
8083 ? sat_unsigned_long_fract_type_node 9479 ? sat_unsigned_long_fract_type_node
8084 : sat_long_fract_type_node; 9480 : sat_long_fract_type_node;
8085 else if (specs->short_p) 9481 else if (specs->short_p)
8086 specs->type = specs->unsigned_p 9482 specs->type = specs->unsigned_p
8087 ? sat_unsigned_short_fract_type_node 9483 ? sat_unsigned_short_fract_type_node
8088 : sat_short_fract_type_node; 9484 : sat_short_fract_type_node;
8089 else
8090 specs->type = specs->unsigned_p
8091 ? sat_unsigned_fract_type_node
8092 : sat_fract_type_node;
8093 }
8094 else 9485 else
8095 { 9486 specs->type = specs->unsigned_p
8096 if (specs->long_long_p) 9487 ? sat_unsigned_fract_type_node
8097 specs->type = specs->unsigned_p 9488 : sat_fract_type_node;
8098 ? unsigned_long_long_fract_type_node 9489 }
8099 : long_long_fract_type_node; 9490 else
8100 else if (specs->long_p) 9491 {
8101 specs->type = specs->unsigned_p 9492 if (specs->long_long_p)
8102 ? unsigned_long_fract_type_node 9493 specs->type = specs->unsigned_p
8103 : long_fract_type_node; 9494 ? unsigned_long_long_fract_type_node
8104 else if (specs->short_p) 9495 : long_long_fract_type_node;
8105 specs->type = specs->unsigned_p 9496 else if (specs->long_p)
8106 ? unsigned_short_fract_type_node 9497 specs->type = specs->unsigned_p
8107 : short_fract_type_node; 9498 ? unsigned_long_fract_type_node
8108 else 9499 : long_fract_type_node;
8109 specs->type = specs->unsigned_p 9500 else if (specs->short_p)
8110 ? unsigned_fract_type_node 9501 specs->type = specs->unsigned_p
8111 : fract_type_node; 9502 ? unsigned_short_fract_type_node
8112 } 9503 : short_fract_type_node;
9504 else
9505 specs->type = specs->unsigned_p
9506 ? unsigned_fract_type_node
9507 : fract_type_node;
9508 }
8113 break; 9509 break;
8114 case cts_accum: 9510 case cts_accum:
8115 gcc_assert (!specs->complex_p); 9511 gcc_assert (!specs->complex_p);
8116 if (!targetm.fixed_point_supported_p ()) 9512 if (!targetm.fixed_point_supported_p ())
8117 specs->type = integer_type_node; 9513 specs->type = integer_type_node;
8118 else if (specs->saturating_p) 9514 else if (specs->saturating_p)
8119 { 9515 {
8120 if (specs->long_long_p) 9516 if (specs->long_long_p)
8121 specs->type = specs->unsigned_p 9517 specs->type = specs->unsigned_p
8122 ? sat_unsigned_long_long_accum_type_node 9518 ? sat_unsigned_long_long_accum_type_node
8123 : sat_long_long_accum_type_node; 9519 : sat_long_long_accum_type_node;
8124 else if (specs->long_p) 9520 else if (specs->long_p)
8125 specs->type = specs->unsigned_p 9521 specs->type = specs->unsigned_p
8126 ? sat_unsigned_long_accum_type_node 9522 ? sat_unsigned_long_accum_type_node
8127 : sat_long_accum_type_node; 9523 : sat_long_accum_type_node;
8128 else if (specs->short_p) 9524 else if (specs->short_p)
8129 specs->type = specs->unsigned_p 9525 specs->type = specs->unsigned_p
8130 ? sat_unsigned_short_accum_type_node 9526 ? sat_unsigned_short_accum_type_node
8131 : sat_short_accum_type_node; 9527 : sat_short_accum_type_node;
8132 else
8133 specs->type = specs->unsigned_p
8134 ? sat_unsigned_accum_type_node
8135 : sat_accum_type_node;
8136 }
8137 else 9528 else
8138 { 9529 specs->type = specs->unsigned_p
8139 if (specs->long_long_p) 9530 ? sat_unsigned_accum_type_node
8140 specs->type = specs->unsigned_p 9531 : sat_accum_type_node;
8141 ? unsigned_long_long_accum_type_node 9532 }
8142 : long_long_accum_type_node; 9533 else
8143 else if (specs->long_p) 9534 {
8144 specs->type = specs->unsigned_p 9535 if (specs->long_long_p)
8145 ? unsigned_long_accum_type_node 9536 specs->type = specs->unsigned_p
8146 : long_accum_type_node; 9537 ? unsigned_long_long_accum_type_node
8147 else if (specs->short_p) 9538 : long_long_accum_type_node;
8148 specs->type = specs->unsigned_p 9539 else if (specs->long_p)
8149 ? unsigned_short_accum_type_node 9540 specs->type = specs->unsigned_p
8150 : short_accum_type_node; 9541 ? unsigned_long_accum_type_node
8151 else 9542 : long_accum_type_node;
8152 specs->type = specs->unsigned_p 9543 else if (specs->short_p)
8153 ? unsigned_accum_type_node 9544 specs->type = specs->unsigned_p
8154 : accum_type_node; 9545 ? unsigned_short_accum_type_node
8155 } 9546 : short_accum_type_node;
9547 else
9548 specs->type = specs->unsigned_p
9549 ? unsigned_accum_type_node
9550 : accum_type_node;
9551 }
8156 break; 9552 break;
8157 default: 9553 default:
8158 gcc_unreachable (); 9554 gcc_unreachable ();
8159 } 9555 }
8160 9556
8173 9569
8174 /* Process the decls in the order they were written. */ 9570 /* Process the decls in the order they were written. */
8175 for (decl = globals; decl; decl = TREE_CHAIN (decl)) 9571 for (decl = globals; decl; decl = TREE_CHAIN (decl))
8176 { 9572 {
8177 /* Check for used but undefined static functions using the C 9573 /* Check for used but undefined static functions using the C
8178 standard's definition of "used", and set TREE_NO_WARNING so 9574 standard's definition of "used", and set TREE_NO_WARNING so
8179 that check_global_declarations doesn't repeat the check. */ 9575 that check_global_declarations doesn't repeat the check. */
8180 if (TREE_CODE (decl) == FUNCTION_DECL 9576 if (TREE_CODE (decl) == FUNCTION_DECL
8181 && DECL_INITIAL (decl) == 0 9577 && DECL_INITIAL (decl) == 0
8182 && DECL_EXTERNAL (decl) 9578 && DECL_EXTERNAL (decl)
8183 && !TREE_PUBLIC (decl) 9579 && !TREE_PUBLIC (decl)
8184 && C_DECL_USED (decl)) 9580 && C_DECL_USED (decl))
8185 { 9581 {
8186 pedwarn (input_location, 0, "%q+F used but never defined", decl); 9582 pedwarn (input_location, 0, "%q+F used but never defined", decl);
8187 TREE_NO_WARNING (decl) = 1; 9583 TREE_NO_WARNING (decl) = 1;
8188 } 9584 }
8189 9585
8190 wrapup_global_declaration_1 (decl); 9586 wrapup_global_declaration_1 (decl);
8191 } 9587 }
8192 9588
8193 do 9589 do
8194 { 9590 {
8195 reconsider = false; 9591 reconsider = false;
8196 for (decl = globals; decl; decl = TREE_CHAIN (decl)) 9592 for (decl = globals; decl; decl = TREE_CHAIN (decl))
8197 reconsider |= wrapup_global_declaration_2 (decl); 9593 reconsider |= wrapup_global_declaration_2 (decl);
8198 } 9594 }
8199 while (reconsider); 9595 while (reconsider);
8200 9596
8201 for (decl = globals; decl; decl = TREE_CHAIN (decl)) 9597 for (decl = globals; decl; decl = TREE_CHAIN (decl))
8202 check_global_declaration_1 (decl); 9598 check_global_declaration_1 (decl);
8224 9620
8225 /* We don't want to do this if generating a PCH. */ 9621 /* We don't want to do this if generating a PCH. */
8226 if (pch_file) 9622 if (pch_file)
8227 return; 9623 return;
8228 9624
8229 /* Don't waste time on further processing if -fsyntax-only or we've 9625 /* Don't waste time on further processing if -fsyntax-only.
8230 encountered errors. */ 9626 Continue for warning and errors issued during lowering though. */
8231 if (flag_syntax_only || errorcount || sorrycount || cpp_errors (parse_in)) 9627 if (flag_syntax_only)
8232 return; 9628 return;
8233 9629
8234 /* Close the external scope. */ 9630 /* Close the external scope. */
8235 ext_block = pop_scope (); 9631 ext_block = pop_scope ();
8236 external_scope = 0; 9632 external_scope = 0;
8240 { 9636 {
8241 tree tmp = BLOCK_VARS (ext_block); 9637 tree tmp = BLOCK_VARS (ext_block);
8242 int flags; 9638 int flags;
8243 FILE * stream = dump_begin (TDI_tu, &flags); 9639 FILE * stream = dump_begin (TDI_tu, &flags);
8244 if (stream && tmp) 9640 if (stream && tmp)
8245 { 9641 {
8246 dump_node (tmp, flags & ~TDF_SLIM, stream); 9642 dump_node (tmp, flags & ~TDF_SLIM, stream);
8247 dump_end (TDI_tu, stream); 9643 dump_end (TDI_tu, stream);
8248 } 9644 }
8249 } 9645 }
8250 9646
8251 /* Process all file scopes in this compilation, and the external_scope, 9647 /* Process all file scopes in this compilation, and the external_scope,
8252 through wrapup_global_declarations and check_global_declarations. */ 9648 through wrapup_global_declarations and check_global_declarations. */
8253 for (t = all_translation_units; t; t = TREE_CHAIN (t)) 9649 for (t = all_translation_units; t; t = TREE_CHAIN (t))
8254 c_write_global_declarations_1 (BLOCK_VARS (DECL_INITIAL (t))); 9650 c_write_global_declarations_1 (BLOCK_VARS (DECL_INITIAL (t)));
8255 c_write_global_declarations_1 (BLOCK_VARS (ext_block)); 9651 c_write_global_declarations_1 (BLOCK_VARS (ext_block));
8256 9652
8257 /* We're done parsing; proceed to optimize and emit assembly. 9653 /* We're done parsing; proceed to optimize and emit assembly.
8258 FIXME: shouldn't be the front end's responsibility to call this. */ 9654 FIXME: shouldn't be the front end's responsibility to call this. */
8259 cgraph_optimize (); 9655 cgraph_finalize_compilation_unit ();
8260 9656
8261 /* After cgraph has had a chance to emit everything that's going to 9657 /* After cgraph has had a chance to emit everything that's going to
8262 be emitted, output debug information for globals. */ 9658 be emitted, output debug information for globals. */
8263 if (errorcount == 0 && sorrycount == 0) 9659 if (errorcount == 0 && sorrycount == 0)
8264 { 9660 {
8265 timevar_push (TV_SYMOUT); 9661 timevar_push (TV_SYMOUT);
8266 for (t = all_translation_units; t; t = TREE_CHAIN (t)) 9662 for (t = all_translation_units; t; t = TREE_CHAIN (t))
8267 c_write_global_declarations_2 (BLOCK_VARS (DECL_INITIAL (t))); 9663 c_write_global_declarations_2 (BLOCK_VARS (DECL_INITIAL (t)));
8268 c_write_global_declarations_2 (BLOCK_VARS (ext_block)); 9664 c_write_global_declarations_2 (BLOCK_VARS (ext_block));
8269 timevar_pop (TV_SYMOUT); 9665 timevar_pop (TV_SYMOUT);
8270 } 9666 }
8271 9667
8272 ext_block = NULL; 9668 ext_block = NULL;