Mercurial > hg > CbC > CbC_gcc
comparison gcc/c-decl.c @ 55:77e2b8dfacca gcc-4.4.5
update it from 4.4.3 to 4.5.0
author | ryoma <e075725@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 12 Feb 2010 23:39:51 +0900 |
parents | 3bfb6c00c1e0 |
children | 326d9e06c2e3 b7f97abdc517 |
comparison
equal
deleted
inserted
replaced
52:c156f1bd5cd9 | 55:77e2b8dfacca |
---|---|
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" |
61 #include "libfuncs.h" | 62 #include "libfuncs.h" |
62 #include "except.h" | 63 #include "except.h" |
63 #include "langhooks-def.h" | 64 #include "langhooks-def.h" |
64 #include "pointer-set.h" | 65 #include "pointer-set.h" |
65 #include "gimple.h" | 66 #include "gimple.h" |
67 #include "plugin.h" | |
66 | 68 |
67 /* In grokdeclarator, distinguish syntactic contexts of declarators. */ | 69 /* In grokdeclarator, distinguish syntactic contexts of declarators. */ |
68 enum decl_context | 70 enum decl_context |
69 { NORMAL, /* Ordinary declaration */ | 71 { NORMAL, /* Ordinary declaration */ |
70 FUNCDEF, /* Function definition */ | 72 FUNCDEF, /* Function definition */ |
88 tree pending_invalid_xref; | 90 tree pending_invalid_xref; |
89 | 91 |
90 /* File and line to appear in the eventual error message. */ | 92 /* File and line to appear in the eventual error message. */ |
91 location_t pending_invalid_xref_location; | 93 location_t pending_invalid_xref_location; |
92 | 94 |
93 /* True means we've initialized exception handling. */ | |
94 bool c_eh_initialized_p; | |
95 | |
96 /* The file and line that the prototype came from if this is an | 95 /* The file and line that the prototype came from if this is an |
97 old-style definition; used for diagnostics in | 96 old-style definition; used for diagnostics in |
98 store_parm_decls_oldstyle. */ | 97 store_parm_decls_oldstyle. */ |
99 | 98 |
100 static location_t current_function_prototype_locus; | 99 static location_t current_function_prototype_locus; |
176 RECORD_TYPE, UNION_TYPE, or ENUMERAL_TYPE node. If an undeclared | 175 RECORD_TYPE, UNION_TYPE, or ENUMERAL_TYPE node. If an undeclared |
177 identifier is encountered, it is bound to error_mark_node to | 176 identifier is encountered, it is bound to error_mark_node to |
178 suppress further errors about that identifier in the current | 177 suppress further errors about that identifier in the current |
179 function. | 178 function. |
180 | 179 |
181 The ->type field stores the type of the declaration in this scope; | 180 The ->u.type field stores the type of the declaration in this scope; |
182 if NULL, the type is the type of the ->decl field. This is only of | 181 if NULL, the type is the type of the ->decl field. This is only of |
183 relevance for objects with external or internal linkage which may | 182 relevance for objects with external or internal linkage which may |
184 be redeclared in inner scopes, forming composite types that only | 183 be redeclared in inner scopes, forming composite types that only |
185 persist for the duration of those scopes. In the external scope, | 184 persist for the duration of those scopes. In the external scope, |
186 this stores the composite of all the types declared for this | 185 this stores the composite of all the types declared for this |
187 object, visible or not. The ->inner_comp field (used only at file | 186 object, visible or not. The ->inner_comp field (used only at file |
188 scope) stores whether an incomplete array type at file scope was | 187 scope) stores whether an incomplete array type at file scope was |
189 completed at an inner scope to an array size other than 1. | 188 completed at an inner scope to an array size other than 1. |
190 | 189 |
190 The ->u.label field is used for labels. It points to a structure | |
191 which stores additional information used for warnings. | |
192 | |
191 The depth field is copied from the scope structure that holds this | 193 The depth field is copied from the scope structure that holds this |
192 decl. It is used to preserve the proper ordering of the ->shadowed | 194 decl. It is used to preserve the proper ordering of the ->shadowed |
193 field (see bind()) and also for a handful of special-case checks. | 195 field (see bind()) and also for a handful of special-case checks. |
194 Finally, the invisible bit is true for a decl which should be | 196 Finally, the invisible bit is true for a decl which should be |
195 ignored for purposes of normal name lookup, and the nested bit is | 197 ignored for purposes of normal name lookup, and the nested bit is |
196 true for a decl that's been bound a second time in an inner scope; | 198 true for a decl that's been bound a second time in an inner scope; |
197 in all such cases, the binding in the outer scope will have its | 199 in all such cases, the binding in the outer scope will have its |
198 invisible bit true. */ | 200 invisible bit true. */ |
199 | 201 |
200 struct c_binding GTY((chain_next ("%h.prev"))) | 202 struct GTY((chain_next ("%h.prev"))) c_binding { |
201 { | 203 union GTY(()) { /* first so GTY desc can use decl */ |
204 tree GTY((tag ("0"))) type; /* the type in this scope */ | |
205 struct c_label_vars * GTY((tag ("1"))) label; /* for warnings */ | |
206 } GTY((desc ("TREE_CODE (%0.decl) == LABEL_DECL"))) u; | |
202 tree decl; /* the decl bound */ | 207 tree decl; /* the decl bound */ |
203 tree type; /* the type in this scope */ | |
204 tree id; /* the identifier it's bound to */ | 208 tree id; /* the identifier it's bound to */ |
205 struct c_binding *prev; /* the previous decl in this scope */ | 209 struct c_binding *prev; /* the previous decl in this scope */ |
206 struct c_binding *shadowed; /* the innermost decl shadowed by this one */ | 210 struct c_binding *shadowed; /* the innermost decl shadowed by this one */ |
207 unsigned int depth : 28; /* depth of this scope */ | 211 unsigned int depth : 28; /* depth of this scope */ |
208 BOOL_BITFIELD invisible : 1; /* normal lookup should ignore this binding */ | 212 BOOL_BITFIELD invisible : 1; /* normal lookup should ignore this binding */ |
209 BOOL_BITFIELD nested : 1; /* do not set DECL_CONTEXT when popping */ | 213 BOOL_BITFIELD nested : 1; /* do not set DECL_CONTEXT when popping */ |
210 BOOL_BITFIELD inner_comp : 1; /* incomplete array completed in inner scope */ | 214 BOOL_BITFIELD inner_comp : 1; /* incomplete array completed in inner scope */ |
211 /* one free bit */ | 215 BOOL_BITFIELD in_struct : 1; /* currently defined as struct field */ |
216 location_t locus; /* location for nested bindings */ | |
212 }; | 217 }; |
213 #define B_IN_SCOPE(b1, b2) ((b1)->depth == (b2)->depth) | 218 #define B_IN_SCOPE(b1, b2) ((b1)->depth == (b2)->depth) |
214 #define B_IN_CURRENT_SCOPE(b) ((b)->depth == current_scope->depth) | 219 #define B_IN_CURRENT_SCOPE(b) ((b)->depth == current_scope->depth) |
215 #define B_IN_FILE_SCOPE(b) ((b)->depth == 1 /*file_scope->depth*/) | 220 #define B_IN_FILE_SCOPE(b) ((b)->depth == 1 /*file_scope->depth*/) |
216 #define B_IN_EXTERNAL_SCOPE(b) ((b)->depth == 0 /*external_scope->depth*/) | 221 #define B_IN_EXTERNAL_SCOPE(b) ((b)->depth == 0 /*external_scope->depth*/) |
232 | 237 |
233 /* Each C symbol points to three linked lists of c_binding structures. | 238 /* Each C symbol points to three linked lists of c_binding structures. |
234 These describe the values of the identifier in the three different | 239 These describe the values of the identifier in the three different |
235 namespaces defined by the language. */ | 240 namespaces defined by the language. */ |
236 | 241 |
237 struct lang_identifier GTY(()) | 242 struct GTY(()) lang_identifier { |
238 { | |
239 struct c_common_identifier common_id; | 243 struct c_common_identifier common_id; |
240 struct c_binding *symbol_binding; /* vars, funcs, constants, typedefs */ | 244 struct c_binding *symbol_binding; /* vars, funcs, constants, typedefs */ |
241 struct c_binding *tag_binding; /* struct/union/enum tags */ | 245 struct c_binding *tag_binding; /* struct/union/enum tags */ |
242 struct c_binding *label_binding; /* labels */ | 246 struct c_binding *label_binding; /* labels */ |
243 }; | 247 }; |
246 extern char C_SIZEOF_STRUCT_LANG_IDENTIFIER_isnt_accurate | 250 extern char C_SIZEOF_STRUCT_LANG_IDENTIFIER_isnt_accurate |
247 [(sizeof(struct lang_identifier) == C_SIZEOF_STRUCT_LANG_IDENTIFIER) ? 1 : -1]; | 251 [(sizeof(struct lang_identifier) == C_SIZEOF_STRUCT_LANG_IDENTIFIER) ? 1 : -1]; |
248 | 252 |
249 /* The resulting tree type. */ | 253 /* The resulting tree type. */ |
250 | 254 |
251 union lang_tree_node | 255 union GTY((desc ("TREE_CODE (&%h.generic) == IDENTIFIER_NODE"), |
252 GTY((desc ("TREE_CODE (&%h.generic) == IDENTIFIER_NODE"), | 256 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 |
253 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))"))) | 257 { |
254 { | |
255 union tree_node GTY ((tag ("0"), | 258 union tree_node GTY ((tag ("0"), |
256 desc ("tree_node_structure (&%h)"))) | 259 desc ("tree_node_structure (&%h)"))) |
257 generic; | 260 generic; |
258 struct lang_identifier GTY ((tag ("1"))) identifier; | 261 struct lang_identifier GTY ((tag ("1"))) identifier; |
259 }; | 262 }; |
260 | 263 |
264 /* Track bindings and other things that matter for goto warnings. For | |
265 efficiency, we do not gather all the decls at the point of | |
266 definition. Instead, we point into the bindings structure. As | |
267 scopes are popped, we update these structures and gather the decls | |
268 that matter at that time. */ | |
269 | |
270 struct GTY(()) c_spot_bindings { | |
271 /* The currently open scope which holds bindings defined when the | |
272 label was defined or the goto statement was found. */ | |
273 struct c_scope *scope; | |
274 /* The bindings in the scope field which were defined at the point | |
275 of the label or goto. This lets us look at older or newer | |
276 bindings in the scope, as appropriate. */ | |
277 struct c_binding *bindings_in_scope; | |
278 /* The number of statement expressions that have started since this | |
279 label or goto statement was defined. This is zero if we are at | |
280 the same statement expression level. It is positive if we are in | |
281 a statement expression started since this spot. It is negative | |
282 if this spot was in a statement expression and we have left | |
283 it. */ | |
284 int stmt_exprs; | |
285 /* Whether we started in a statement expression but are no longer in | |
286 it. This is set to true if stmt_exprs ever goes negative. */ | |
287 bool left_stmt_expr; | |
288 }; | |
289 | |
290 /* This structure is used to keep track of bindings seen when a goto | |
291 statement is defined. This is only used if we see the goto | |
292 statement before we see the label. */ | |
293 | |
294 struct GTY(()) c_goto_bindings { | |
295 /* The location of the goto statement. */ | |
296 location_t loc; | |
297 /* The bindings of the goto statement. */ | |
298 struct c_spot_bindings goto_bindings; | |
299 }; | |
300 | |
301 typedef struct c_goto_bindings *c_goto_bindings_p; | |
302 DEF_VEC_P(c_goto_bindings_p); | |
303 DEF_VEC_ALLOC_P(c_goto_bindings_p,gc); | |
304 | |
305 /* The additional information we keep track of for a label binding. | |
306 These fields are updated as scopes are popped. */ | |
307 | |
308 struct GTY(()) c_label_vars { | |
309 /* The shadowed c_label_vars, when one label shadows another (which | |
310 can only happen using a __label__ declaration). */ | |
311 struct c_label_vars *shadowed; | |
312 /* The bindings when the label was defined. */ | |
313 struct c_spot_bindings label_bindings; | |
314 /* A list of decls that we care about: decls about which we should | |
315 warn if a goto branches to this label from later in the function. | |
316 Decls are added to this list as scopes are popped. We only add | |
317 the decls that matter. */ | |
318 VEC(tree,gc) *decls_in_scope; | |
319 /* A list of goto statements to this label. This is only used for | |
320 goto statements seen before the label was defined, so that we can | |
321 issue appropriate warnings for them. */ | |
322 VEC(c_goto_bindings_p,gc) *gotos; | |
323 }; | |
324 | |
261 /* Each c_scope structure describes the complete contents of one | 325 /* Each c_scope structure describes the complete contents of one |
262 scope. Four scopes are distinguished specially: the innermost or | 326 scope. Four scopes are distinguished specially: the innermost or |
263 current scope, the innermost function scope, the file scope (always | 327 current scope, the innermost function scope, the file scope (always |
264 the second to outermost) and the outermost or external scope. | 328 the second to outermost) and the outermost or external scope. |
265 | 329 |
301 | 365 |
302 The bindings list is strictly in reverse order of declarations; | 366 The bindings list is strictly in reverse order of declarations; |
303 pop_scope relies on this. */ | 367 pop_scope relies on this. */ |
304 | 368 |
305 | 369 |
306 struct c_scope GTY((chain_next ("%h.outer"))) | 370 struct GTY((chain_next ("%h.outer"))) c_scope { |
307 { | |
308 /* The scope containing this one. */ | 371 /* The scope containing this one. */ |
309 struct c_scope *outer; | 372 struct c_scope *outer; |
310 | 373 |
311 /* The next outermost function scope. */ | 374 /* The next outermost function scope. */ |
312 struct c_scope *outer_function; | 375 struct c_scope *outer_function; |
342 nested functions, or declared at block scope with __label__). */ | 405 nested functions, or declared at block scope with __label__). */ |
343 BOOL_BITFIELD function_body : 1; | 406 BOOL_BITFIELD function_body : 1; |
344 | 407 |
345 /* True means make a BLOCK for this scope no matter what. */ | 408 /* True means make a BLOCK for this scope no matter what. */ |
346 BOOL_BITFIELD keep : 1; | 409 BOOL_BITFIELD keep : 1; |
410 | |
411 /* True means that an unsuffixed float constant is _Decimal64. */ | |
412 BOOL_BITFIELD float_const_decimal64 : 1; | |
413 | |
414 /* True if this scope has any label bindings. This is used to speed | |
415 up searching for labels when popping scopes, particularly since | |
416 labels are normally only found at function scope. */ | |
417 BOOL_BITFIELD has_label_bindings : 1; | |
347 }; | 418 }; |
348 | 419 |
349 /* The scope currently in effect. */ | 420 /* The scope currently in effect. */ |
350 | 421 |
351 static GTY(()) struct c_scope *current_scope; | 422 static GTY(()) struct c_scope *current_scope; |
393 else \ | 464 else \ |
394 t_->to = f_->from; \ | 465 t_->to = f_->from; \ |
395 t_->to##_last = f_->from##_last; \ | 466 t_->to##_last = f_->from##_last; \ |
396 } while (0) | 467 } while (0) |
397 | 468 |
469 /* A c_inline_static structure stores details of a static identifier | |
470 referenced in a definition of a function that may be an inline | |
471 definition if no subsequent declaration of that function uses | |
472 "extern" or does not use "inline". */ | |
473 | |
474 struct GTY((chain_next ("%h.next"))) c_inline_static { | |
475 /* The location for a diagnostic. */ | |
476 location_t location; | |
477 | |
478 /* The function that may be an inline definition. */ | |
479 tree function; | |
480 | |
481 /* The object or function referenced. */ | |
482 tree static_decl; | |
483 | |
484 /* What sort of reference this is. */ | |
485 enum c_inline_static_type type; | |
486 | |
487 /* The next such structure or NULL. */ | |
488 struct c_inline_static *next; | |
489 }; | |
490 | |
491 /* List of static identifiers used or referenced in functions that may | |
492 be inline definitions. */ | |
493 static GTY(()) struct c_inline_static *c_inline_statics; | |
494 | |
398 /* True means unconditionally make a BLOCK for the next scope pushed. */ | 495 /* True means unconditionally make a BLOCK for the next scope pushed. */ |
399 | 496 |
400 static bool keep_next_level_flag; | 497 static bool keep_next_level_flag; |
401 | 498 |
402 /* True means the next call to push_scope will be the outermost scope | 499 /* True means the next call to push_scope will be the outermost scope |
403 of a function body, so do not push a new scope, merely cease | 500 of a function body, so do not push a new scope, merely cease |
404 expecting parameter decls. */ | 501 expecting parameter decls. */ |
405 | 502 |
406 static bool next_is_function_body; | 503 static bool next_is_function_body; |
407 | 504 |
505 /* A VEC of pointers to c_binding structures. */ | |
506 | |
507 typedef struct c_binding *c_binding_ptr; | |
508 DEF_VEC_P(c_binding_ptr); | |
509 DEF_VEC_ALLOC_P(c_binding_ptr,heap); | |
510 | |
511 /* Information that we keep for a struct or union while it is being | |
512 parsed. */ | |
513 | |
514 struct c_struct_parse_info | |
515 { | |
516 /* If warn_cxx_compat, a list of types defined within this | |
517 struct. */ | |
518 VEC(tree,heap) *struct_types; | |
519 /* If warn_cxx_compat, a list of field names which have bindings, | |
520 and which are defined in this struct, but which are not defined | |
521 in any enclosing struct. This is used to clear the in_struct | |
522 field of the c_bindings structure. */ | |
523 VEC(c_binding_ptr,heap) *fields; | |
524 /* If warn_cxx_compat, a list of typedef names used when defining | |
525 fields in this struct. */ | |
526 VEC(tree,heap) *typedefs_seen; | |
527 }; | |
528 | |
529 /* Information for the struct or union currently being parsed, or | |
530 NULL if not parsing a struct or union. */ | |
531 static struct c_struct_parse_info *struct_parse_info; | |
532 | |
408 /* Forward declarations. */ | 533 /* Forward declarations. */ |
409 static tree lookup_name_in_scope (tree, struct c_scope *); | 534 static tree lookup_name_in_scope (tree, struct c_scope *); |
410 static tree c_make_fname_decl (tree, int); | 535 static tree c_make_fname_decl (location_t, tree, int); |
411 static tree grokdeclarator (const struct c_declarator *, | 536 static tree grokdeclarator (const struct c_declarator *, |
412 struct c_declspecs *, | 537 struct c_declspecs *, |
413 enum decl_context, bool, tree *, tree *, | 538 enum decl_context, bool, tree *, tree *, tree *, |
414 enum deprecated_states); | 539 bool *, enum deprecated_states); |
415 static tree grokparms (struct c_arg_info *, bool); | 540 static tree grokparms (struct c_arg_info *, bool); |
416 static void layout_array_type (tree); | 541 static void layout_array_type (tree); |
417 | 542 |
418 /* T is a statement. Add it to the statement-tree. This is the | 543 /* T is a statement. Add it to the statement-tree. This is the |
419 C/ObjC version--C++ has a slightly different version of this | 544 C/ObjC version--C++ has a slightly different version of this |
449 print_node (file, "label", I_LABEL_DECL (node), indent + 4); | 574 print_node (file, "label", I_LABEL_DECL (node), indent + 4); |
450 if (C_IS_RESERVED_WORD (node) && C_RID_CODE (node) != RID_CXX_COMPAT_WARN) | 575 if (C_IS_RESERVED_WORD (node) && C_RID_CODE (node) != RID_CXX_COMPAT_WARN) |
451 { | 576 { |
452 tree rid = ridpointers[C_RID_CODE (node)]; | 577 tree rid = ridpointers[C_RID_CODE (node)]; |
453 indent_to (file, indent + 4); | 578 indent_to (file, indent + 4); |
454 fprintf (file, "rid %p \"%s\"", | 579 fprintf (file, "rid " HOST_PTR_PRINTF " \"%s\"", |
455 (void *) rid, IDENTIFIER_POINTER (rid)); | 580 (void *) rid, IDENTIFIER_POINTER (rid)); |
456 } | 581 } |
457 } | 582 } |
458 | 583 |
459 /* Establish a binding between NAME, an IDENTIFIER_NODE, and DECL, | 584 /* Establish a binding between NAME, an IDENTIFIER_NODE, and DECL, |
460 which may be any of several kinds of DECL or TYPE or error_mark_node, | 585 which may be any of several kinds of DECL or TYPE or error_mark_node, |
461 in the scope SCOPE. */ | 586 in the scope SCOPE. */ |
462 static void | 587 static void |
463 bind (tree name, tree decl, struct c_scope *scope, bool invisible, bool nested) | 588 bind (tree name, tree decl, struct c_scope *scope, bool invisible, |
589 bool nested, location_t locus) | |
464 { | 590 { |
465 struct c_binding *b, **here; | 591 struct c_binding *b, **here; |
466 | 592 |
467 if (binding_freelist) | 593 if (binding_freelist) |
468 { | 594 { |
477 b->id = name; | 603 b->id = name; |
478 b->depth = scope->depth; | 604 b->depth = scope->depth; |
479 b->invisible = invisible; | 605 b->invisible = invisible; |
480 b->nested = nested; | 606 b->nested = nested; |
481 b->inner_comp = 0; | 607 b->inner_comp = 0; |
482 | 608 b->in_struct = 0; |
483 b->type = 0; | 609 b->locus = locus; |
610 | |
611 b->u.type = NULL; | |
484 | 612 |
485 b->prev = scope->bindings; | 613 b->prev = scope->bindings; |
486 scope->bindings = b; | 614 scope->bindings = b; |
487 | 615 |
488 if (!name) | 616 if (!name) |
529 binding_freelist = b; | 657 binding_freelist = b; |
530 | 658 |
531 return prev; | 659 return prev; |
532 } | 660 } |
533 | 661 |
662 /* Bind a label. Like bind, but skip fields which aren't used for | |
663 labels, and add the LABEL_VARS value. */ | |
664 static void | |
665 bind_label (tree name, tree label, struct c_scope *scope, | |
666 struct c_label_vars *label_vars) | |
667 { | |
668 struct c_binding *b; | |
669 | |
670 bind (name, label, scope, /*invisible=*/false, /*nested=*/false, | |
671 UNKNOWN_LOCATION); | |
672 | |
673 scope->has_label_bindings = true; | |
674 | |
675 b = scope->bindings; | |
676 gcc_assert (b->decl == label); | |
677 label_vars->shadowed = b->u.label; | |
678 b->u.label = label_vars; | |
679 } | |
534 | 680 |
535 /* Hook called at end of compilation to assume 1 elt | 681 /* Hook called at end of compilation to assume 1 elt |
536 for a file-scope tentative array defn that wasn't complete before. */ | 682 for a file-scope tentative array defn that wasn't complete before. */ |
537 | 683 |
538 void | 684 void |
544 if (type != error_mark_node | 690 if (type != error_mark_node |
545 && TREE_CODE (type) == ARRAY_TYPE | 691 && TREE_CODE (type) == ARRAY_TYPE |
546 && !DECL_EXTERNAL (decl) | 692 && !DECL_EXTERNAL (decl) |
547 && TYPE_DOMAIN (type) == 0) | 693 && TYPE_DOMAIN (type) == 0) |
548 { | 694 { |
549 warning (0, "array %q+D assumed to have one element", decl); | 695 warning_at (DECL_SOURCE_LOCATION (decl), |
696 0, "array %q+D assumed to have one element", decl); | |
550 | 697 |
551 complete_array_type (&TREE_TYPE (decl), NULL_TREE, true); | 698 complete_array_type (&TREE_TYPE (decl), NULL_TREE, true); |
552 | 699 |
553 layout_decl (decl, 0); | 700 layout_decl (decl, 0); |
554 } | 701 } |
555 } | 702 } |
703 } | |
704 | |
705 /* Record that inline function FUNC contains a reference (location | |
706 LOC) to static DECL (file-scope or function-local according to | |
707 TYPE). */ | |
708 | |
709 void | |
710 record_inline_static (location_t loc, tree func, tree decl, | |
711 enum c_inline_static_type type) | |
712 { | |
713 struct c_inline_static *csi = GGC_NEW (struct c_inline_static); | |
714 csi->location = loc; | |
715 csi->function = func; | |
716 csi->static_decl = decl; | |
717 csi->type = type; | |
718 csi->next = c_inline_statics; | |
719 c_inline_statics = csi; | |
720 } | |
721 | |
722 /* Check for references to static declarations in inline functions at | |
723 the end of the translation unit and diagnose them if the functions | |
724 are still inline definitions. */ | |
725 | |
726 static void | |
727 check_inline_statics (void) | |
728 { | |
729 struct c_inline_static *csi; | |
730 for (csi = c_inline_statics; csi; csi = csi->next) | |
731 { | |
732 if (DECL_EXTERNAL (csi->function)) | |
733 switch (csi->type) | |
734 { | |
735 case csi_internal: | |
736 pedwarn (csi->location, 0, | |
737 "%qD is static but used in inline function %qD " | |
738 "which is not static", csi->static_decl, csi->function); | |
739 break; | |
740 case csi_modifiable: | |
741 pedwarn (csi->location, 0, | |
742 "%q+D is static but declared in inline function %qD " | |
743 "which is not static", csi->static_decl, csi->function); | |
744 break; | |
745 default: | |
746 gcc_unreachable (); | |
747 } | |
748 } | |
749 c_inline_statics = NULL; | |
750 } | |
751 | |
752 /* Fill in a c_spot_bindings structure. If DEFINING is true, set it | |
753 for the current state, otherwise set it to uninitialized. */ | |
754 | |
755 static void | |
756 set_spot_bindings (struct c_spot_bindings *p, bool defining) | |
757 { | |
758 if (defining) | |
759 { | |
760 p->scope = current_scope; | |
761 p->bindings_in_scope = current_scope->bindings; | |
762 } | |
763 else | |
764 { | |
765 p->scope = NULL; | |
766 p->bindings_in_scope = NULL; | |
767 } | |
768 p->stmt_exprs = 0; | |
769 p->left_stmt_expr = false; | |
770 } | |
771 | |
772 /* Return true if we will want to say something if a goto statement | |
773 crosses DECL. */ | |
774 | |
775 static bool | |
776 decl_jump_unsafe (tree decl) | |
777 { | |
778 if (decl == error_mark_node || TREE_TYPE (decl) == error_mark_node) | |
779 return false; | |
780 | |
781 /* Always warn about crossing variably modified types. */ | |
782 if ((TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == TYPE_DECL) | |
783 && variably_modified_type_p (TREE_TYPE (decl), NULL_TREE)) | |
784 return true; | |
785 | |
786 /* Otherwise, only warn if -Wgoto-misses-init and this is an | |
787 initialized automatic decl. */ | |
788 if (warn_jump_misses_init | |
789 && TREE_CODE (decl) == VAR_DECL | |
790 && !TREE_STATIC (decl) | |
791 && DECL_INITIAL (decl) != NULL_TREE) | |
792 return true; | |
793 | |
794 return false; | |
795 } | |
796 | |
797 /* Update spot bindings P as we pop out of SCOPE. Return true if we | |
798 should push decls for a label. */ | |
799 | |
800 static bool | |
801 update_spot_bindings (struct c_scope *scope, struct c_spot_bindings *p) | |
802 { | |
803 if (p->scope != scope) | |
804 { | |
805 /* This label or goto is defined in some other scope, or it is a | |
806 label which is not yet defined. There is nothing to | |
807 update. */ | |
808 return false; | |
809 } | |
810 | |
811 /* Adjust the spot bindings to refer to the bindings already defined | |
812 in the enclosing scope. */ | |
813 p->scope = scope->outer; | |
814 p->bindings_in_scope = p->scope->bindings; | |
815 | |
816 return true; | |
556 } | 817 } |
557 | 818 |
558 /* The Objective-C front-end often needs to determine the current scope. */ | 819 /* The Objective-C front-end often needs to determine the current scope. */ |
559 | 820 |
560 void * | 821 void * |
588 /* Nonzero if we are currently in file scope. */ | 849 /* Nonzero if we are currently in file scope. */ |
589 | 850 |
590 int | 851 int |
591 global_bindings_p (void) | 852 global_bindings_p (void) |
592 { | 853 { |
593 return current_scope == file_scope && !c_override_global_bindings_to_false; | 854 return (current_scope == file_scope && !c_override_global_bindings_to_false |
855 ? -1 | |
856 : 0); | |
594 } | 857 } |
595 | 858 |
596 void | 859 void |
597 keep_next_level (void) | 860 keep_next_level (void) |
598 { | 861 { |
599 keep_next_level_flag = true; | 862 keep_next_level_flag = true; |
863 } | |
864 | |
865 /* Set the flag for the FLOAT_CONST_DECIMAL64 pragma being ON. */ | |
866 | |
867 void | |
868 set_float_const_decimal64 (void) | |
869 { | |
870 current_scope->float_const_decimal64 = true; | |
871 } | |
872 | |
873 /* Clear the flag for the FLOAT_CONST_DECIMAL64 pragma. */ | |
874 | |
875 void | |
876 clear_float_const_decimal64 (void) | |
877 { | |
878 current_scope->float_const_decimal64 = false; | |
879 } | |
880 | |
881 /* Return nonzero if an unsuffixed float constant is _Decimal64. */ | |
882 | |
883 bool | |
884 float_const_decimal64_p (void) | |
885 { | |
886 return current_scope->float_const_decimal64; | |
600 } | 887 } |
601 | 888 |
602 /* Identify this scope as currently being filled with parameters. */ | 889 /* Identify this scope as currently being filled with parameters. */ |
603 | 890 |
604 void | 891 void |
628 current_scope->outer_function = current_function_scope; | 915 current_scope->outer_function = current_function_scope; |
629 current_function_scope = current_scope; | 916 current_function_scope = current_scope; |
630 | 917 |
631 keep_next_level_flag = false; | 918 keep_next_level_flag = false; |
632 next_is_function_body = false; | 919 next_is_function_body = false; |
920 | |
921 /* The FLOAT_CONST_DECIMAL64 pragma applies to nested scopes. */ | |
922 if (current_scope->outer) | |
923 current_scope->float_const_decimal64 | |
924 = current_scope->outer->float_const_decimal64; | |
925 else | |
926 current_scope->float_const_decimal64 = false; | |
633 } | 927 } |
634 else | 928 else |
635 { | 929 { |
636 struct c_scope *scope; | 930 struct c_scope *scope; |
637 if (scope_freelist) | 931 if (scope_freelist) |
639 scope = scope_freelist; | 933 scope = scope_freelist; |
640 scope_freelist = scope->outer; | 934 scope_freelist = scope->outer; |
641 } | 935 } |
642 else | 936 else |
643 scope = GGC_CNEW (struct c_scope); | 937 scope = GGC_CNEW (struct c_scope); |
938 | |
939 /* The FLOAT_CONST_DECIMAL64 pragma applies to nested scopes. */ | |
940 if (current_scope) | |
941 scope->float_const_decimal64 = current_scope->float_const_decimal64; | |
942 else | |
943 scope->float_const_decimal64 = false; | |
644 | 944 |
645 scope->keep = keep_next_level_flag; | 945 scope->keep = keep_next_level_flag; |
646 scope->outer = current_scope; | 946 scope->outer = current_scope; |
647 scope->depth = current_scope ? (current_scope->depth + 1) : 0; | 947 scope->depth = current_scope ? (current_scope->depth + 1) : 0; |
648 | 948 |
654 sorry ("GCC supports only %u nested scopes", scope->depth); | 954 sorry ("GCC supports only %u nested scopes", scope->depth); |
655 } | 955 } |
656 | 956 |
657 current_scope = scope; | 957 current_scope = scope; |
658 keep_next_level_flag = false; | 958 keep_next_level_flag = false; |
959 } | |
960 } | |
961 | |
962 /* This is called when we are leaving SCOPE. For each label defined | |
963 in SCOPE, add any appropriate decls to its decls_in_scope fields. | |
964 These are the decls whose initialization will be skipped by a goto | |
965 later in the function. */ | |
966 | |
967 static void | |
968 update_label_decls (struct c_scope *scope) | |
969 { | |
970 struct c_scope *s; | |
971 | |
972 s = scope; | |
973 while (s != NULL) | |
974 { | |
975 if (s->has_label_bindings) | |
976 { | |
977 struct c_binding *b; | |
978 | |
979 for (b = s->bindings; b != NULL; b = b->prev) | |
980 { | |
981 struct c_label_vars *label_vars; | |
982 struct c_binding *b1; | |
983 unsigned int ix; | |
984 struct c_goto_bindings *g; | |
985 | |
986 if (TREE_CODE (b->decl) != LABEL_DECL) | |
987 continue; | |
988 label_vars = b->u.label; | |
989 | |
990 b1 = label_vars->label_bindings.bindings_in_scope; | |
991 if (update_spot_bindings (scope, &label_vars->label_bindings)) | |
992 { | |
993 /* This label is defined in this scope. */ | |
994 for (; b1 != NULL; b1 = b1->prev) | |
995 { | |
996 /* A goto from later in the function to this | |
997 label will never see the initialization of | |
998 B1, if any. Save it to issue a warning if | |
999 needed. */ | |
1000 if (decl_jump_unsafe (b1->decl)) | |
1001 VEC_safe_push (tree, gc, label_vars->decls_in_scope, | |
1002 b1->decl); | |
1003 } | |
1004 } | |
1005 | |
1006 /* Update the bindings of any goto statements associated | |
1007 with this label. */ | |
1008 for (ix = 0; | |
1009 VEC_iterate (c_goto_bindings_p, label_vars->gotos, ix, g); | |
1010 ++ix) | |
1011 update_spot_bindings (scope, &g->goto_bindings); | |
1012 } | |
1013 } | |
1014 | |
1015 /* Don't search beyond the current function. */ | |
1016 if (s == current_function_scope) | |
1017 break; | |
1018 | |
1019 s = s->outer; | |
659 } | 1020 } |
660 } | 1021 } |
661 | 1022 |
662 /* Set the TYPE_CONTEXT of all of TYPE's variants to CONTEXT. */ | 1023 /* Set the TYPE_CONTEXT of all of TYPE's variants to CONTEXT. */ |
663 | 1024 |
682 struct c_binding *b; | 1043 struct c_binding *b; |
683 | 1044 |
684 bool functionbody = scope->function_body; | 1045 bool functionbody = scope->function_body; |
685 bool keep = functionbody || scope->keep || scope->bindings; | 1046 bool keep = functionbody || scope->keep || scope->bindings; |
686 | 1047 |
687 c_end_vm_scope (scope->depth); | 1048 update_label_decls (scope); |
688 | 1049 |
689 /* If appropriate, create a BLOCK to record the decls for the life | 1050 /* If appropriate, create a BLOCK to record the decls for the life |
690 of this function. */ | 1051 of this function. */ |
691 block = 0; | 1052 block = 0; |
692 if (keep) | 1053 if (keep) |
717 "parameter list local" tagged types. */ | 1078 "parameter list local" tagged types. */ |
718 if (scope->function_body) | 1079 if (scope->function_body) |
719 context = current_function_decl; | 1080 context = current_function_decl; |
720 else if (scope == file_scope) | 1081 else if (scope == file_scope) |
721 { | 1082 { |
722 tree file_decl = build_decl (TRANSLATION_UNIT_DECL, 0, 0); | 1083 tree file_decl = build_decl (UNKNOWN_LOCATION, |
1084 TRANSLATION_UNIT_DECL, 0, 0); | |
723 TREE_CHAIN (file_decl) = all_translation_units; | 1085 TREE_CHAIN (file_decl) = all_translation_units; |
724 all_translation_units = file_decl; | 1086 all_translation_units = file_decl; |
725 context = file_decl; | 1087 context = file_decl; |
726 } | 1088 } |
727 else | 1089 else |
738 if (TREE_USED (p) && !DECL_INITIAL (p)) | 1100 if (TREE_USED (p) && !DECL_INITIAL (p)) |
739 { | 1101 { |
740 error ("label %q+D used but not defined", p); | 1102 error ("label %q+D used but not defined", p); |
741 DECL_INITIAL (p) = error_mark_node; | 1103 DECL_INITIAL (p) = error_mark_node; |
742 } | 1104 } |
743 else | 1105 else |
744 warn_for_unused_label (p); | 1106 warn_for_unused_label (p); |
745 | 1107 |
746 /* Labels go in BLOCK_VARS. */ | 1108 /* Labels go in BLOCK_VARS. */ |
747 TREE_CHAIN (p) = BLOCK_VARS (block); | 1109 TREE_CHAIN (p) = BLOCK_VARS (block); |
748 BLOCK_VARS (block) = p; | 1110 BLOCK_VARS (block) = p; |
749 gcc_assert (I_LABEL_BINDING (b->id) == b); | 1111 gcc_assert (I_LABEL_BINDING (b->id) == b); |
750 I_LABEL_BINDING (b->id) = b->shadowed; | 1112 I_LABEL_BINDING (b->id) = b->shadowed; |
1113 | |
1114 /* Also pop back to the shadowed label_vars. */ | |
1115 release_tree_vector (b->u.label->decls_in_scope); | |
1116 b->u.label = b->u.label->shadowed; | |
751 break; | 1117 break; |
752 | 1118 |
753 case ENUMERAL_TYPE: | 1119 case ENUMERAL_TYPE: |
754 case UNION_TYPE: | 1120 case UNION_TYPE: |
755 case RECORD_TYPE: | 1121 case RECORD_TYPE: |
822 if (!b->nested) | 1188 if (!b->nested) |
823 { | 1189 { |
824 TREE_CHAIN (p) = BLOCK_VARS (block); | 1190 TREE_CHAIN (p) = BLOCK_VARS (block); |
825 BLOCK_VARS (block) = p; | 1191 BLOCK_VARS (block) = p; |
826 } | 1192 } |
1193 else if (VAR_OR_FUNCTION_DECL_P (p)) | |
1194 { | |
1195 /* For block local externs add a special | |
1196 DECL_EXTERNAL decl for debug info generation. */ | |
1197 tree extp = copy_node (p); | |
1198 | |
1199 DECL_EXTERNAL (extp) = 1; | |
1200 TREE_STATIC (extp) = 0; | |
1201 TREE_PUBLIC (extp) = 1; | |
1202 DECL_INITIAL (extp) = NULL_TREE; | |
1203 DECL_LANG_SPECIFIC (extp) = NULL; | |
1204 DECL_CONTEXT (extp) = current_function_decl; | |
1205 if (TREE_CODE (p) == FUNCTION_DECL) | |
1206 { | |
1207 DECL_RESULT (extp) = NULL_TREE; | |
1208 DECL_SAVED_TREE (extp) = NULL_TREE; | |
1209 DECL_STRUCT_FUNCTION (extp) = NULL; | |
1210 } | |
1211 if (b->locus != UNKNOWN_LOCATION) | |
1212 DECL_SOURCE_LOCATION (extp) = b->locus; | |
1213 TREE_CHAIN (extp) = BLOCK_VARS (block); | |
1214 BLOCK_VARS (block) = extp; | |
1215 } | |
827 /* If this is the file scope, and we are processing more | 1216 /* If this is the file scope, and we are processing more |
828 than one translation unit in this compilation, set | 1217 than one translation unit in this compilation, set |
829 DECL_CONTEXT of each decl to the TRANSLATION_UNIT_DECL. | 1218 DECL_CONTEXT of each decl to the TRANSLATION_UNIT_DECL. |
830 This makes same_translation_unit_p work, and causes | 1219 This makes same_translation_unit_p work, and causes |
831 static declarations to be given disambiguating suffixes. */ | 1220 static declarations to be given disambiguating suffixes. */ |
848 here with b->id NULL in this case. */ | 1237 here with b->id NULL in this case. */ |
849 if (b->id) | 1238 if (b->id) |
850 { | 1239 { |
851 gcc_assert (I_SYMBOL_BINDING (b->id) == b); | 1240 gcc_assert (I_SYMBOL_BINDING (b->id) == b); |
852 I_SYMBOL_BINDING (b->id) = b->shadowed; | 1241 I_SYMBOL_BINDING (b->id) = b->shadowed; |
853 if (b->shadowed && b->shadowed->type) | 1242 if (b->shadowed && b->shadowed->u.type) |
854 TREE_TYPE (b->shadowed->decl) = b->shadowed->type; | 1243 TREE_TYPE (b->shadowed->decl) = b->shadowed->u.type; |
855 } | 1244 } |
856 break; | 1245 break; |
857 | 1246 |
858 default: | 1247 default: |
859 gcc_unreachable (); | 1248 gcc_unreachable (); |
903 | 1292 |
904 start_fname_decls (); | 1293 start_fname_decls (); |
905 | 1294 |
906 for (decl = visible_builtins; decl; decl = TREE_CHAIN (decl)) | 1295 for (decl = visible_builtins; decl; decl = TREE_CHAIN (decl)) |
907 bind (DECL_NAME (decl), decl, file_scope, | 1296 bind (DECL_NAME (decl), decl, file_scope, |
908 /*invisible=*/false, /*nested=*/true); | 1297 /*invisible=*/false, /*nested=*/true, DECL_SOURCE_LOCATION (decl)); |
909 } | 1298 } |
910 | 1299 |
911 void | 1300 void |
912 pop_file_scope (void) | 1301 pop_file_scope (void) |
913 { | 1302 { |
919 /* __FUNCTION__ is defined at file scope (""). This | 1308 /* __FUNCTION__ is defined at file scope (""). This |
920 call may not be necessary as my tests indicate it | 1309 call may not be necessary as my tests indicate it |
921 still works without it. */ | 1310 still works without it. */ |
922 finish_fname_decls (); | 1311 finish_fname_decls (); |
923 | 1312 |
1313 check_inline_statics (); | |
1314 | |
924 /* This is the point to write out a PCH if we're doing that. | 1315 /* This is the point to write out a PCH if we're doing that. |
925 In that case we do not want to do anything else. */ | 1316 In that case we do not want to do anything else. */ |
926 if (pch_file) | 1317 if (pch_file) |
927 { | 1318 { |
928 c_common_write_pch (); | 1319 c_common_write_pch (); |
932 /* Pop off the file scope and close this translation unit. */ | 1323 /* Pop off the file scope and close this translation unit. */ |
933 pop_scope (); | 1324 pop_scope (); |
934 file_scope = 0; | 1325 file_scope = 0; |
935 | 1326 |
936 maybe_apply_pending_pragma_weaks (); | 1327 maybe_apply_pending_pragma_weaks (); |
937 cgraph_finalize_compilation_unit (); | 1328 } |
938 } | 1329 |
939 | 1330 /* Adjust the bindings for the start of a statement expression. */ |
1331 | |
1332 void | |
1333 c_bindings_start_stmt_expr (struct c_spot_bindings* switch_bindings) | |
1334 { | |
1335 struct c_scope *scope; | |
1336 | |
1337 for (scope = current_scope; scope != NULL; scope = scope->outer) | |
1338 { | |
1339 struct c_binding *b; | |
1340 | |
1341 if (!scope->has_label_bindings) | |
1342 continue; | |
1343 | |
1344 for (b = scope->bindings; b != NULL; b = b->prev) | |
1345 { | |
1346 struct c_label_vars *label_vars; | |
1347 unsigned int ix; | |
1348 struct c_goto_bindings *g; | |
1349 | |
1350 if (TREE_CODE (b->decl) != LABEL_DECL) | |
1351 continue; | |
1352 label_vars = b->u.label; | |
1353 ++label_vars->label_bindings.stmt_exprs; | |
1354 for (ix = 0; | |
1355 VEC_iterate (c_goto_bindings_p, label_vars->gotos, ix, g); | |
1356 ++ix) | |
1357 ++g->goto_bindings.stmt_exprs; | |
1358 } | |
1359 } | |
1360 | |
1361 if (switch_bindings != NULL) | |
1362 ++switch_bindings->stmt_exprs; | |
1363 } | |
1364 | |
1365 /* Adjust the bindings for the end of a statement expression. */ | |
1366 | |
1367 void | |
1368 c_bindings_end_stmt_expr (struct c_spot_bindings *switch_bindings) | |
1369 { | |
1370 struct c_scope *scope; | |
1371 | |
1372 for (scope = current_scope; scope != NULL; scope = scope->outer) | |
1373 { | |
1374 struct c_binding *b; | |
1375 | |
1376 if (!scope->has_label_bindings) | |
1377 continue; | |
1378 | |
1379 for (b = scope->bindings; b != NULL; b = b->prev) | |
1380 { | |
1381 struct c_label_vars *label_vars; | |
1382 unsigned int ix; | |
1383 struct c_goto_bindings *g; | |
1384 | |
1385 if (TREE_CODE (b->decl) != LABEL_DECL) | |
1386 continue; | |
1387 label_vars = b->u.label; | |
1388 --label_vars->label_bindings.stmt_exprs; | |
1389 if (label_vars->label_bindings.stmt_exprs < 0) | |
1390 { | |
1391 label_vars->label_bindings.left_stmt_expr = true; | |
1392 label_vars->label_bindings.stmt_exprs = 0; | |
1393 } | |
1394 for (ix = 0; | |
1395 VEC_iterate (c_goto_bindings_p, label_vars->gotos, ix, g); | |
1396 ++ix) | |
1397 { | |
1398 --g->goto_bindings.stmt_exprs; | |
1399 if (g->goto_bindings.stmt_exprs < 0) | |
1400 { | |
1401 g->goto_bindings.left_stmt_expr = true; | |
1402 g->goto_bindings.stmt_exprs = 0; | |
1403 } | |
1404 } | |
1405 } | |
1406 } | |
1407 | |
1408 if (switch_bindings != NULL) | |
1409 { | |
1410 --switch_bindings->stmt_exprs; | |
1411 gcc_assert (switch_bindings->stmt_exprs >= 0); | |
1412 } | |
1413 } | |
940 | 1414 |
941 /* Push a definition or a declaration of struct, union or enum tag "name". | 1415 /* Push a definition or a declaration of struct, union or enum tag "name". |
942 "type" should be the type node. | 1416 "type" should be the type node. |
943 We assume that the tag "name" is not already defined. | 1417 We assume that the tag "name" is not already defined, and has a location |
1418 of LOC. | |
944 | 1419 |
945 Note that the definition may really be just a forward reference. | 1420 Note that the definition may really be just a forward reference. |
946 In that case, the TYPE_SIZE will be zero. */ | 1421 In that case, the TYPE_SIZE will be zero. */ |
947 | 1422 |
948 static void | 1423 static void |
949 pushtag (tree name, tree type) | 1424 pushtag (location_t loc, tree name, tree type) |
950 { | 1425 { |
951 /* Record the identifier as the type's name if it has none. */ | 1426 /* Record the identifier as the type's name if it has none. */ |
952 if (name && !TYPE_NAME (type)) | 1427 if (name && !TYPE_NAME (type)) |
953 TYPE_NAME (type) = name; | 1428 TYPE_NAME (type) = name; |
954 bind (name, type, current_scope, /*invisible=*/false, /*nested=*/false); | 1429 bind (name, type, current_scope, /*invisible=*/false, /*nested=*/false, loc); |
955 | 1430 |
956 /* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE will be the | 1431 /* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE will be the |
957 tagged type we just added to the current scope. This fake | 1432 tagged type we just added to the current scope. This fake |
958 NULL-named TYPE_DECL node helps dwarfout.c to know when it needs | 1433 NULL-named TYPE_DECL node helps dwarfout.c to know when it needs |
959 to output a representation of a tagged type, and it also gives | 1434 to output a representation of a tagged type, and it also gives |
960 us a convenient place to record the "scope start" address for the | 1435 us a convenient place to record the "scope start" address for the |
961 tagged type. */ | 1436 tagged type. */ |
962 | 1437 |
963 TYPE_STUB_DECL (type) = pushdecl (build_decl (TYPE_DECL, NULL_TREE, type)); | 1438 TYPE_STUB_DECL (type) = pushdecl (build_decl (loc, |
1439 TYPE_DECL, NULL_TREE, type)); | |
964 | 1440 |
965 /* An approximation for now, so we can tell this is a function-scope tag. | 1441 /* An approximation for now, so we can tell this is a function-scope tag. |
966 This will be updated in pop_scope. */ | 1442 This will be updated in pop_scope. */ |
967 TYPE_CONTEXT (type) = DECL_CONTEXT (TYPE_STUB_DECL (type)); | 1443 TYPE_CONTEXT (type) = DECL_CONTEXT (TYPE_STUB_DECL (type)); |
1444 | |
1445 if (warn_cxx_compat && name != NULL_TREE) | |
1446 { | |
1447 struct c_binding *b = I_SYMBOL_BINDING (name); | |
1448 | |
1449 if (b != NULL | |
1450 && b->decl != NULL_TREE | |
1451 && TREE_CODE (b->decl) == TYPE_DECL | |
1452 && (B_IN_CURRENT_SCOPE (b) | |
1453 || (current_scope == file_scope && B_IN_EXTERNAL_SCOPE (b))) | |
1454 && (TYPE_MAIN_VARIANT (TREE_TYPE (b->decl)) | |
1455 != TYPE_MAIN_VARIANT (type))) | |
1456 { | |
1457 warning_at (loc, OPT_Wc___compat, | |
1458 ("using %qD as both a typedef and a tag is " | |
1459 "invalid in C++"), | |
1460 b->decl); | |
1461 if (b->locus != UNKNOWN_LOCATION) | |
1462 inform (b->locus, "originally defined here"); | |
1463 } | |
1464 } | |
968 } | 1465 } |
969 | 1466 |
970 /* Subroutine of compare_decls. Allow harmless mismatches in return | 1467 /* Subroutine of compare_decls. Allow harmless mismatches in return |
971 and argument types provided that the type modes match. This function | 1468 and argument types provided that the type modes match. This function |
972 return a unified type given a suitable match, and 0 otherwise. */ | 1469 return a unified type given a suitable match, and 0 otherwise. */ |
1247 /* Make sure we keep void as the return type. */ | 1744 /* Make sure we keep void as the return type. */ |
1248 TREE_TYPE (olddecl) = *oldtypep = oldtype = newtype; | 1745 TREE_TYPE (olddecl) = *oldtypep = oldtype = newtype; |
1249 } | 1746 } |
1250 else | 1747 else |
1251 { | 1748 { |
1252 if (TYPE_QUALS (newtype) != TYPE_QUALS (oldtype)) | 1749 int new_quals = TYPE_QUALS (newtype); |
1253 error ("conflicting type qualifiers for %q+D", newdecl); | 1750 int old_quals = TYPE_QUALS (oldtype); |
1751 | |
1752 if (new_quals != old_quals) | |
1753 { | |
1754 addr_space_t new_addr = DECODE_QUAL_ADDR_SPACE (new_quals); | |
1755 addr_space_t old_addr = DECODE_QUAL_ADDR_SPACE (old_quals); | |
1756 if (new_addr != old_addr) | |
1757 { | |
1758 if (ADDR_SPACE_GENERIC_P (new_addr)) | |
1759 error ("conflicting named address spaces (generic vs %s) " | |
1760 "for %q+D", | |
1761 c_addr_space_name (old_addr), newdecl); | |
1762 else if (ADDR_SPACE_GENERIC_P (old_addr)) | |
1763 error ("conflicting named address spaces (%s vs generic) " | |
1764 "for %q+D", | |
1765 c_addr_space_name (new_addr), newdecl); | |
1766 else | |
1767 error ("conflicting named address spaces (%s vs %s) " | |
1768 "for %q+D", | |
1769 c_addr_space_name (new_addr), | |
1770 c_addr_space_name (old_addr), | |
1771 newdecl); | |
1772 } | |
1773 | |
1774 if (CLEAR_QUAL_ADDR_SPACE (new_quals) | |
1775 != CLEAR_QUAL_ADDR_SPACE (old_quals)) | |
1776 error ("conflicting type qualifiers for %q+D", newdecl); | |
1777 } | |
1254 else | 1778 else |
1255 error ("conflicting types for %q+D", newdecl); | 1779 error ("conflicting types for %q+D", newdecl); |
1256 diagnose_arglist_conflict (newdecl, olddecl, newtype, oldtype); | 1780 diagnose_arglist_conflict (newdecl, olddecl, newtype, oldtype); |
1257 locate_old_decl (olddecl); | 1781 locate_old_decl (olddecl); |
1258 return false; | 1782 return false; |
1371 locate_old_decl (olddecl); | 1895 locate_old_decl (olddecl); |
1372 return false; | 1896 return false; |
1373 } | 1897 } |
1374 else if (warn_traditional) | 1898 else if (warn_traditional) |
1375 { | 1899 { |
1376 warned |= warning (OPT_Wtraditional, | 1900 warned |= warning (OPT_Wtraditional, |
1377 "non-static declaration of %q+D " | 1901 "non-static declaration of %q+D " |
1378 "follows static declaration", newdecl); | 1902 "follows static declaration", newdecl); |
1379 } | 1903 } |
1380 } | 1904 } |
1381 | 1905 |
1388 DECL_ATTRIBUTES (newdecl)) != NULL; | 1912 DECL_ATTRIBUTES (newdecl)) != NULL; |
1389 bool olda = lookup_attribute ("gnu_inline", | 1913 bool olda = lookup_attribute ("gnu_inline", |
1390 DECL_ATTRIBUTES (olddecl)) != NULL; | 1914 DECL_ATTRIBUTES (olddecl)) != NULL; |
1391 if (newa != olda) | 1915 if (newa != olda) |
1392 { | 1916 { |
1393 error ("%<gnu_inline%> attribute present on %q+D", | 1917 error_at (input_location, "%<gnu_inline%> attribute present on %q+D", |
1394 newa ? newdecl : olddecl); | 1918 newa ? newdecl : olddecl); |
1395 error ("%Jbut not here", newa ? olddecl : newdecl); | 1919 error_at (DECL_SOURCE_LOCATION (newa ? olddecl : newdecl), |
1920 "but not here"); | |
1396 } | 1921 } |
1397 } | 1922 } |
1398 } | 1923 } |
1399 else if (TREE_CODE (newdecl) == VAR_DECL) | 1924 else if (TREE_CODE (newdecl) == VAR_DECL) |
1400 { | 1925 { |
1448 locate_old_decl (olddecl); | 1973 locate_old_decl (olddecl); |
1449 return false; | 1974 return false; |
1450 } | 1975 } |
1451 else if (warn_traditional) | 1976 else if (warn_traditional) |
1452 { | 1977 { |
1453 warned |= warning (OPT_Wtraditional, | 1978 warned |= warning (OPT_Wtraditional, |
1454 "non-static declaration of %q+D " | 1979 "non-static declaration of %q+D " |
1455 "follows static declaration", newdecl); | 1980 "follows static declaration", newdecl); |
1456 } | 1981 } |
1457 } | 1982 } |
1458 else | 1983 else |
1489 locate_old_decl (olddecl); | 2014 locate_old_decl (olddecl); |
1490 } | 2015 } |
1491 | 2016 |
1492 return false; | 2017 return false; |
1493 } | 2018 } |
2019 | |
2020 /* C++ does not permit a decl to appear multiple times at file | |
2021 scope. */ | |
2022 if (warn_cxx_compat | |
2023 && DECL_FILE_SCOPE_P (newdecl) | |
2024 && !DECL_EXTERNAL (newdecl) | |
2025 && !DECL_EXTERNAL (olddecl)) | |
2026 warned |= warning_at (DECL_SOURCE_LOCATION (newdecl), | |
2027 OPT_Wc___compat, | |
2028 ("duplicate declaration of %qD is " | |
2029 "invalid in C++"), | |
2030 newdecl); | |
1494 } | 2031 } |
1495 | 2032 |
1496 /* warnings */ | 2033 /* warnings */ |
1497 /* All decls must agree on a visibility. */ | 2034 /* All decls must agree on a visibility. */ |
1498 if (CODE_CONTAINS_STRUCT (TREE_CODE (newdecl), TS_DECL_WITH_VIS) | 2035 if (CODE_CONTAINS_STRUCT (TREE_CODE (newdecl), TS_DECL_WITH_VIS) |
1507 { | 2044 { |
1508 /* Diagnose inline __attribute__ ((noinline)) which is silly. */ | 2045 /* Diagnose inline __attribute__ ((noinline)) which is silly. */ |
1509 if (DECL_DECLARED_INLINE_P (newdecl) | 2046 if (DECL_DECLARED_INLINE_P (newdecl) |
1510 && lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl))) | 2047 && lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl))) |
1511 { | 2048 { |
1512 warned |= warning (OPT_Wattributes, | 2049 warned |= warning (OPT_Wattributes, |
1513 "inline declaration of %qD follows " | 2050 "inline declaration of %qD follows " |
1514 "declaration with attribute noinline", newdecl); | 2051 "declaration with attribute noinline", newdecl); |
1515 } | 2052 } |
1516 else if (DECL_DECLARED_INLINE_P (olddecl) | 2053 else if (DECL_DECLARED_INLINE_P (olddecl) |
1517 && lookup_attribute ("noinline", DECL_ATTRIBUTES (newdecl))) | 2054 && lookup_attribute ("noinline", DECL_ATTRIBUTES (newdecl))) |
1518 { | 2055 { |
1519 warned |= warning (OPT_Wattributes, | 2056 warned |= warning (OPT_Wattributes, |
1520 "declaration of %q+D with attribute " | 2057 "declaration of %q+D with attribute " |
1521 "noinline follows inline declaration ", newdecl); | 2058 "noinline follows inline declaration ", newdecl); |
1522 } | 2059 } |
1523 } | 2060 } |
1524 else /* PARM_DECL, VAR_DECL */ | 2061 else /* PARM_DECL, VAR_DECL */ |
1824 = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl); | 2361 = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl); |
1825 | 2362 |
1826 /* Also preserve various other info from the definition. */ | 2363 /* Also preserve various other info from the definition. */ |
1827 if (!new_is_definition) | 2364 if (!new_is_definition) |
1828 { | 2365 { |
2366 tree t; | |
1829 DECL_RESULT (newdecl) = DECL_RESULT (olddecl); | 2367 DECL_RESULT (newdecl) = DECL_RESULT (olddecl); |
1830 DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl); | 2368 DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl); |
1831 DECL_STRUCT_FUNCTION (newdecl) = DECL_STRUCT_FUNCTION (olddecl); | 2369 DECL_STRUCT_FUNCTION (newdecl) = DECL_STRUCT_FUNCTION (olddecl); |
1832 DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl); | 2370 DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl); |
1833 gimple_set_body (newdecl, gimple_body (olddecl)); | 2371 gimple_set_body (newdecl, gimple_body (olddecl)); |
1834 DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl); | 2372 DECL_ARGUMENTS (newdecl) = copy_list (DECL_ARGUMENTS (olddecl)); |
2373 for (t = DECL_ARGUMENTS (newdecl); t ; t = TREE_CHAIN (t)) | |
2374 DECL_CONTEXT (t) = newdecl; | |
1835 | 2375 |
1836 /* See if we've got a function to instantiate from. */ | 2376 /* See if we've got a function to instantiate from. */ |
1837 if (DECL_SAVED_TREE (olddecl)) | 2377 if (DECL_SAVED_TREE (olddecl)) |
1838 DECL_ABSTRACT_ORIGIN (newdecl) | 2378 DECL_ABSTRACT_ORIGIN (newdecl) |
1839 = DECL_ABSTRACT_ORIGIN (olddecl); | 2379 = DECL_ABSTRACT_ORIGIN (olddecl); |
1840 } | 2380 } |
1841 } | 2381 } |
1842 | 2382 |
1843 extern_changed = DECL_EXTERNAL (olddecl) && !DECL_EXTERNAL (newdecl); | 2383 extern_changed = DECL_EXTERNAL (olddecl) && !DECL_EXTERNAL (newdecl); |
1844 | 2384 |
1845 /* Merge the USED information. */ | 2385 /* Merge the USED information. */ |
1846 if (TREE_USED (olddecl)) | 2386 if (TREE_USED (olddecl)) |
1847 TREE_USED (newdecl) = 1; | 2387 TREE_USED (newdecl) = 1; |
1848 else if (TREE_USED (newdecl)) | 2388 else if (TREE_USED (newdecl)) |
1849 TREE_USED (olddecl) = 1; | 2389 TREE_USED (olddecl) = 1; |
1850 | 2390 |
1851 /* Copy most of the decl-specific fields of NEWDECL into OLDDECL. | 2391 /* Copy most of the decl-specific fields of NEWDECL into OLDDECL. |
1852 But preserve OLDDECL's DECL_UID and DECL_CONTEXT. */ | 2392 But preserve OLDDECL's DECL_UID, DECL_CONTEXT and |
2393 DECL_ARGUMENTS (if appropriate). */ | |
1853 { | 2394 { |
1854 unsigned olddecl_uid = DECL_UID (olddecl); | 2395 unsigned olddecl_uid = DECL_UID (olddecl); |
1855 tree olddecl_context = DECL_CONTEXT (olddecl); | 2396 tree olddecl_context = DECL_CONTEXT (olddecl); |
2397 tree olddecl_arguments = NULL; | |
2398 if (TREE_CODE (olddecl) == FUNCTION_DECL) | |
2399 olddecl_arguments = DECL_ARGUMENTS (olddecl); | |
1856 | 2400 |
1857 memcpy ((char *) olddecl + sizeof (struct tree_common), | 2401 memcpy ((char *) olddecl + sizeof (struct tree_common), |
1858 (char *) newdecl + sizeof (struct tree_common), | 2402 (char *) newdecl + sizeof (struct tree_common), |
1859 sizeof (struct tree_decl_common) - sizeof (struct tree_common)); | 2403 sizeof (struct tree_decl_common) - sizeof (struct tree_common)); |
1860 switch (TREE_CODE (olddecl)) | 2404 switch (TREE_CODE (olddecl)) |
1881 (char *) newdecl + sizeof (struct tree_decl_common), | 2425 (char *) newdecl + sizeof (struct tree_decl_common), |
1882 sizeof (struct tree_decl_non_common) - sizeof (struct tree_decl_common)); | 2426 sizeof (struct tree_decl_non_common) - sizeof (struct tree_decl_common)); |
1883 } | 2427 } |
1884 DECL_UID (olddecl) = olddecl_uid; | 2428 DECL_UID (olddecl) = olddecl_uid; |
1885 DECL_CONTEXT (olddecl) = olddecl_context; | 2429 DECL_CONTEXT (olddecl) = olddecl_context; |
2430 if (TREE_CODE (olddecl) == FUNCTION_DECL) | |
2431 DECL_ARGUMENTS (olddecl) = olddecl_arguments; | |
1886 } | 2432 } |
1887 | 2433 |
1888 /* If OLDDECL had its DECL_RTL instantiated, re-invoke make_decl_rtl | 2434 /* If OLDDECL had its DECL_RTL instantiated, re-invoke make_decl_rtl |
1889 so that encode_section_info has a chance to look at the new decl | 2435 so that encode_section_info has a chance to look at the new decl |
1890 flags and attributes. */ | 2436 flags and attributes. */ |
1967 } | 2513 } |
1968 else | 2514 else |
1969 warning (OPT_Wshadow, "declaration of %q+D shadows a previous local", | 2515 warning (OPT_Wshadow, "declaration of %q+D shadows a previous local", |
1970 new_decl); | 2516 new_decl); |
1971 | 2517 |
1972 warning (OPT_Wshadow, "%Jshadowed declaration is here", old_decl); | 2518 warning_at (DECL_SOURCE_LOCATION (old_decl), OPT_Wshadow, |
2519 "shadowed declaration is here"); | |
1973 | 2520 |
1974 break; | 2521 break; |
1975 } | 2522 } |
1976 } | |
1977 | |
1978 | |
1979 /* Subroutine of pushdecl. | |
1980 | |
1981 X is a TYPE_DECL for a typedef statement. Create a brand new | |
1982 ..._TYPE node (which will be just a variant of the existing | |
1983 ..._TYPE node with identical properties) and then install X | |
1984 as the TYPE_NAME of this brand new (duplicate) ..._TYPE node. | |
1985 | |
1986 The whole point here is to end up with a situation where each | |
1987 and every ..._TYPE node the compiler creates will be uniquely | |
1988 associated with AT MOST one node representing a typedef name. | |
1989 This way, even though the compiler substitutes corresponding | |
1990 ..._TYPE nodes for TYPE_DECL (i.e. "typedef name") nodes very | |
1991 early on, later parts of the compiler can always do the reverse | |
1992 translation and get back the corresponding typedef name. For | |
1993 example, given: | |
1994 | |
1995 typedef struct S MY_TYPE; | |
1996 MY_TYPE object; | |
1997 | |
1998 Later parts of the compiler might only know that `object' was of | |
1999 type `struct S' if it were not for code just below. With this | |
2000 code however, later parts of the compiler see something like: | |
2001 | |
2002 struct S' == struct S | |
2003 typedef struct S' MY_TYPE; | |
2004 struct S' object; | |
2005 | |
2006 And they can then deduce (from the node for type struct S') that | |
2007 the original object declaration was: | |
2008 | |
2009 MY_TYPE object; | |
2010 | |
2011 Being able to do this is important for proper support of protoize, | |
2012 and also for generating precise symbolic debugging information | |
2013 which takes full account of the programmer's (typedef) vocabulary. | |
2014 | |
2015 Obviously, we don't want to generate a duplicate ..._TYPE node if | |
2016 the TYPE_DECL node that we are now processing really represents a | |
2017 standard built-in type. */ | |
2018 | |
2019 static void | |
2020 clone_underlying_type (tree x) | |
2021 { | |
2022 if (DECL_IS_BUILTIN (x)) | |
2023 { | |
2024 if (TYPE_NAME (TREE_TYPE (x)) == 0) | |
2025 TYPE_NAME (TREE_TYPE (x)) = x; | |
2026 } | |
2027 else if (TREE_TYPE (x) != error_mark_node | |
2028 && DECL_ORIGINAL_TYPE (x) == NULL_TREE) | |
2029 { | |
2030 tree tt = TREE_TYPE (x); | |
2031 DECL_ORIGINAL_TYPE (x) = tt; | |
2032 tt = build_variant_type_copy (tt); | |
2033 TYPE_NAME (tt) = x; | |
2034 TREE_USED (tt) = TREE_USED (x); | |
2035 TREE_TYPE (x) = tt; | |
2036 } | |
2037 } | 2523 } |
2038 | 2524 |
2039 /* Record a decl-node X as belonging to the current lexical scope. | 2525 /* Record a decl-node X as belonging to the current lexical scope. |
2040 Check for errors (such as an incompatible declaration for the same | 2526 Check for errors (such as an incompatible declaration for the same |
2041 name already seen in the same scope). | 2527 name already seen in the same scope). |
2049 { | 2535 { |
2050 tree name = DECL_NAME (x); | 2536 tree name = DECL_NAME (x); |
2051 struct c_scope *scope = current_scope; | 2537 struct c_scope *scope = current_scope; |
2052 struct c_binding *b; | 2538 struct c_binding *b; |
2053 bool nested = false; | 2539 bool nested = false; |
2540 location_t locus = DECL_SOURCE_LOCATION (x); | |
2054 | 2541 |
2055 /* Must set DECL_CONTEXT for everything not at file scope or | 2542 /* Must set DECL_CONTEXT for everything not at file scope or |
2056 DECL_FILE_SCOPE_P won't work. Local externs don't count | 2543 DECL_FILE_SCOPE_P won't work. Local externs don't count |
2057 unless they have initializers (which generate code). */ | 2544 unless they have initializers (which generate code). */ |
2058 if (current_function_decl | 2545 if (current_function_decl |
2059 && ((TREE_CODE (x) != FUNCTION_DECL && TREE_CODE (x) != VAR_DECL) | 2546 && ((TREE_CODE (x) != FUNCTION_DECL && TREE_CODE (x) != VAR_DECL) |
2060 || DECL_INITIAL (x) || !DECL_EXTERNAL (x))) | 2547 || DECL_INITIAL (x) || !DECL_EXTERNAL (x))) |
2061 DECL_CONTEXT (x) = current_function_decl; | 2548 DECL_CONTEXT (x) = current_function_decl; |
2062 | 2549 |
2063 /* If this is of variably modified type, prevent jumping into its | |
2064 scope. */ | |
2065 if ((TREE_CODE (x) == VAR_DECL || TREE_CODE (x) == TYPE_DECL) | |
2066 && variably_modified_type_p (TREE_TYPE (x), NULL_TREE)) | |
2067 c_begin_vm_scope (scope->depth); | |
2068 | |
2069 /* Anonymous decls are just inserted in the scope. */ | 2550 /* Anonymous decls are just inserted in the scope. */ |
2070 if (!name) | 2551 if (!name) |
2071 { | 2552 { |
2072 bind (name, x, scope, /*invisible=*/false, /*nested=*/false); | 2553 bind (name, x, scope, /*invisible=*/false, /*nested=*/false, |
2554 locus); | |
2073 return x; | 2555 return x; |
2074 } | 2556 } |
2075 | 2557 |
2076 /* First, see if there is another declaration with the same name in | 2558 /* First, see if there is another declaration with the same name in |
2077 the current scope. If there is, duplicate_decls may do all the | 2559 the current scope. If there is, duplicate_decls may do all the |
2101 while (b_ext && !B_IN_EXTERNAL_SCOPE (b_ext)) | 2583 while (b_ext && !B_IN_EXTERNAL_SCOPE (b_ext)) |
2102 b_ext = b_ext->shadowed; | 2584 b_ext = b_ext->shadowed; |
2103 if (b_ext) | 2585 if (b_ext) |
2104 { | 2586 { |
2105 b_use = b_ext; | 2587 b_use = b_ext; |
2106 if (b_use->type) | 2588 if (b_use->u.type) |
2107 TREE_TYPE (b_use->decl) = b_use->type; | 2589 TREE_TYPE (b_use->decl) = b_use->u.type; |
2108 } | 2590 } |
2109 } | 2591 } |
2110 if (duplicate_decls (x, b_use->decl)) | 2592 if (duplicate_decls (x, b_use->decl)) |
2111 { | 2593 { |
2112 if (b_use != b) | 2594 if (b_use != b) |
2116 tree thistype; | 2598 tree thistype; |
2117 if (comptypes (vistype, type)) | 2599 if (comptypes (vistype, type)) |
2118 thistype = composite_type (vistype, type); | 2600 thistype = composite_type (vistype, type); |
2119 else | 2601 else |
2120 thistype = TREE_TYPE (b_use->decl); | 2602 thistype = TREE_TYPE (b_use->decl); |
2121 b_use->type = TREE_TYPE (b_use->decl); | 2603 b_use->u.type = TREE_TYPE (b_use->decl); |
2122 if (TREE_CODE (b_use->decl) == FUNCTION_DECL | 2604 if (TREE_CODE (b_use->decl) == FUNCTION_DECL |
2123 && DECL_BUILT_IN (b_use->decl)) | 2605 && DECL_BUILT_IN (b_use->decl)) |
2124 thistype | 2606 thistype |
2125 = build_type_attribute_variant (thistype, | 2607 = build_type_attribute_variant (thistype, |
2126 TYPE_ATTRIBUTES | 2608 TYPE_ATTRIBUTES |
2127 (b_use->type)); | 2609 (b_use->u.type)); |
2128 TREE_TYPE (b_use->decl) = thistype; | 2610 TREE_TYPE (b_use->decl) = thistype; |
2129 } | 2611 } |
2130 return b_use->decl; | 2612 return b_use->decl; |
2131 } | 2613 } |
2132 else | 2614 else |
2173 its type saved; the others will already have had their | 2655 its type saved; the others will already have had their |
2174 proper types saved and the types will not have changed as | 2656 proper types saved and the types will not have changed as |
2175 their scopes will not have been re-entered. */ | 2657 their scopes will not have been re-entered. */ |
2176 if (DECL_P (b->decl) && DECL_FILE_SCOPE_P (b->decl) && !type_saved) | 2658 if (DECL_P (b->decl) && DECL_FILE_SCOPE_P (b->decl) && !type_saved) |
2177 { | 2659 { |
2178 b->type = TREE_TYPE (b->decl); | 2660 b->u.type = TREE_TYPE (b->decl); |
2179 type_saved = true; | 2661 type_saved = true; |
2180 } | 2662 } |
2181 if (B_IN_FILE_SCOPE (b) | 2663 if (B_IN_FILE_SCOPE (b) |
2182 && TREE_CODE (b->decl) == VAR_DECL | 2664 && TREE_CODE (b->decl) == VAR_DECL |
2183 && TREE_STATIC (b->decl) | 2665 && TREE_STATIC (b->decl) |
2199 /* If a matching external declaration has been found, set its | 2681 /* If a matching external declaration has been found, set its |
2200 type to the composite of all the types of that declaration. | 2682 type to the composite of all the types of that declaration. |
2201 After the consistency checks, it will be reset to the | 2683 After the consistency checks, it will be reset to the |
2202 composite of the visible types only. */ | 2684 composite of the visible types only. */ |
2203 if (b && (TREE_PUBLIC (x) || same_translation_unit_p (x, b->decl)) | 2685 if (b && (TREE_PUBLIC (x) || same_translation_unit_p (x, b->decl)) |
2204 && b->type) | 2686 && b->u.type) |
2205 TREE_TYPE (b->decl) = b->type; | 2687 TREE_TYPE (b->decl) = b->u.type; |
2206 | 2688 |
2207 /* The point of the same_translation_unit_p check here is, | 2689 /* The point of the same_translation_unit_p check here is, |
2208 we want to detect a duplicate decl for a construct like | 2690 we want to detect a duplicate decl for a construct like |
2209 foo() { extern bar(); } ... static bar(); but not if | 2691 foo() { extern bar(); } ... static bar(); but not if |
2210 they are in different translation units. In any case, | 2692 they are in different translation units. In any case, |
2221 else | 2703 else |
2222 thistype = TREE_TYPE (b->decl); | 2704 thistype = TREE_TYPE (b->decl); |
2223 } | 2705 } |
2224 else | 2706 else |
2225 thistype = type; | 2707 thistype = type; |
2226 b->type = TREE_TYPE (b->decl); | 2708 b->u.type = TREE_TYPE (b->decl); |
2227 if (TREE_CODE (b->decl) == FUNCTION_DECL && DECL_BUILT_IN (b->decl)) | 2709 if (TREE_CODE (b->decl) == FUNCTION_DECL && DECL_BUILT_IN (b->decl)) |
2228 thistype | 2710 thistype |
2229 = build_type_attribute_variant (thistype, | 2711 = build_type_attribute_variant (thistype, |
2230 TYPE_ATTRIBUTES (b->type)); | 2712 TYPE_ATTRIBUTES (b->u.type)); |
2231 TREE_TYPE (b->decl) = thistype; | 2713 TREE_TYPE (b->decl) = thistype; |
2232 bind (name, b->decl, scope, /*invisible=*/false, /*nested=*/true); | 2714 bind (name, b->decl, scope, /*invisible=*/false, /*nested=*/true, |
2715 locus); | |
2233 return b->decl; | 2716 return b->decl; |
2234 } | 2717 } |
2235 else if (TREE_PUBLIC (x)) | 2718 else if (TREE_PUBLIC (x)) |
2236 { | 2719 { |
2237 if (visdecl && !b && duplicate_decls (x, visdecl)) | 2720 if (visdecl && !b && duplicate_decls (x, visdecl)) |
2245 x = visdecl; | 2728 x = visdecl; |
2246 } | 2729 } |
2247 else | 2730 else |
2248 { | 2731 { |
2249 bind (name, x, external_scope, /*invisible=*/true, | 2732 bind (name, x, external_scope, /*invisible=*/true, |
2250 /*nested=*/false); | 2733 /*nested=*/false, locus); |
2251 nested = true; | 2734 nested = true; |
2252 } | 2735 } |
2253 } | 2736 } |
2254 } | 2737 } |
2255 | 2738 |
2256 if (TREE_CODE (x) != PARM_DECL) | 2739 if (TREE_CODE (x) != PARM_DECL) |
2257 warn_if_shadowing (x); | 2740 warn_if_shadowing (x); |
2258 | 2741 |
2259 skip_external_and_shadow_checks: | 2742 skip_external_and_shadow_checks: |
2260 if (TREE_CODE (x) == TYPE_DECL) | 2743 if (TREE_CODE (x) == TYPE_DECL) |
2261 clone_underlying_type (x); | 2744 set_underlying_type (x); |
2262 | 2745 |
2263 bind (name, x, scope, /*invisible=*/false, nested); | 2746 bind (name, x, scope, /*invisible=*/false, nested, locus); |
2264 | 2747 |
2265 /* If x's type is incomplete because it's based on a | 2748 /* If x's type is incomplete because it's based on a |
2266 structure or union which has not yet been fully declared, | 2749 structure or union which has not yet been fully declared, |
2267 attach it to that structure or union type, so we can go | 2750 attach it to that structure or union type, so we can go |
2268 back and complete the variable declaration later, if the | 2751 back and complete the variable declaration later, if the |
2307 | 2790 |
2308 gcc_assert (TREE_CODE (x) == CONST_DECL || !I_SYMBOL_BINDING (name)); | 2791 gcc_assert (TREE_CODE (x) == CONST_DECL || !I_SYMBOL_BINDING (name)); |
2309 | 2792 |
2310 if (TREE_PUBLIC (x)) | 2793 if (TREE_PUBLIC (x)) |
2311 { | 2794 { |
2312 bind (name, x, external_scope, /*invisible=*/true, /*nested=*/false); | 2795 bind (name, x, external_scope, /*invisible=*/true, /*nested=*/false, |
2796 UNKNOWN_LOCATION); | |
2313 nested = true; | 2797 nested = true; |
2314 } | 2798 } |
2315 if (file_scope) | 2799 if (file_scope) |
2316 bind (name, x, file_scope, /*invisible=*/false, nested); | 2800 bind (name, x, file_scope, /*invisible=*/false, nested, UNKNOWN_LOCATION); |
2317 | 2801 |
2318 return x; | 2802 return x; |
2319 } | 2803 } |
2320 | 2804 |
2321 static void | 2805 static void |
2326 bool warned; | 2810 bool warned; |
2327 | 2811 |
2328 if (flag_isoc99) | 2812 if (flag_isoc99) |
2329 warned = pedwarn (input_location, OPT_Wimplicit_function_declaration, | 2813 warned = pedwarn (input_location, OPT_Wimplicit_function_declaration, |
2330 "implicit declaration of function %qE", id); | 2814 "implicit declaration of function %qE", id); |
2331 else | 2815 else |
2332 warned = warning (OPT_Wimplicit_function_declaration, | 2816 warned = warning (OPT_Wimplicit_function_declaration, |
2333 G_("implicit declaration of function %qE"), id); | 2817 G_("implicit declaration of function %qE"), id); |
2334 if (olddecl && warned) | 2818 if (olddecl && warned) |
2335 locate_old_decl (olddecl); | 2819 locate_old_decl (olddecl); |
2336 } | 2820 } |
2337 } | 2821 } |
2338 | 2822 |
2339 /* Generate an implicit declaration for identifier FUNCTIONID as a | 2823 /* Generate an implicit declaration for identifier FUNCTIONID at LOC as a |
2340 function of type int (). */ | 2824 function of type int (). */ |
2341 | 2825 |
2342 tree | 2826 tree |
2343 implicitly_declare (tree functionid) | 2827 implicitly_declare (location_t loc, tree functionid) |
2344 { | 2828 { |
2345 struct c_binding *b; | 2829 struct c_binding *b; |
2346 tree decl = 0; | 2830 tree decl = 0; |
2347 tree asmspec_tree; | 2831 tree asmspec_tree; |
2348 | 2832 |
2366 scope gets created. Catch this here and rebind them into the | 2850 scope gets created. Catch this here and rebind them into the |
2367 file scope. */ | 2851 file scope. */ |
2368 if (!DECL_BUILT_IN (decl) && DECL_IS_BUILTIN (decl)) | 2852 if (!DECL_BUILT_IN (decl) && DECL_IS_BUILTIN (decl)) |
2369 { | 2853 { |
2370 bind (functionid, decl, file_scope, | 2854 bind (functionid, decl, file_scope, |
2371 /*invisible=*/false, /*nested=*/true); | 2855 /*invisible=*/false, /*nested=*/true, |
2856 DECL_SOURCE_LOCATION (decl)); | |
2372 return decl; | 2857 return decl; |
2373 } | 2858 } |
2374 else | 2859 else |
2375 { | 2860 { |
2376 tree newtype = default_function_type; | 2861 tree newtype = default_function_type; |
2377 if (b->type) | 2862 if (b->u.type) |
2378 TREE_TYPE (decl) = b->type; | 2863 TREE_TYPE (decl) = b->u.type; |
2379 /* Implicit declaration of a function already declared | 2864 /* Implicit declaration of a function already declared |
2380 (somehow) in a different scope, or as a built-in. | 2865 (somehow) in a different scope, or as a built-in. |
2381 If this is the first time this has happened, warn; | 2866 If this is the first time this has happened, warn; |
2382 then recycle the old declaration but with the new type. */ | 2867 then recycle the old declaration but with the new type. */ |
2383 if (!C_DECL_IMPLICIT (decl)) | 2868 if (!C_DECL_IMPLICIT (decl)) |
2390 newtype = build_type_attribute_variant (newtype, | 2875 newtype = build_type_attribute_variant (newtype, |
2391 TYPE_ATTRIBUTES | 2876 TYPE_ATTRIBUTES |
2392 (TREE_TYPE (decl))); | 2877 (TREE_TYPE (decl))); |
2393 if (!comptypes (newtype, TREE_TYPE (decl))) | 2878 if (!comptypes (newtype, TREE_TYPE (decl))) |
2394 { | 2879 { |
2395 warning (0, "incompatible implicit declaration of built-in" | 2880 warning_at (loc, 0, "incompatible implicit declaration of " |
2396 " function %qD", decl); | 2881 "built-in function %qD", decl); |
2397 newtype = TREE_TYPE (decl); | 2882 newtype = TREE_TYPE (decl); |
2398 } | 2883 } |
2399 } | 2884 } |
2400 else | 2885 else |
2401 { | 2886 { |
2402 if (!comptypes (newtype, TREE_TYPE (decl))) | 2887 if (!comptypes (newtype, TREE_TYPE (decl))) |
2403 { | 2888 { |
2404 error ("incompatible implicit declaration of function %qD", | 2889 error_at (loc, "incompatible implicit declaration of function %qD", decl); |
2405 decl); | |
2406 locate_old_decl (decl); | 2890 locate_old_decl (decl); |
2407 } | 2891 } |
2408 } | 2892 } |
2409 b->type = TREE_TYPE (decl); | 2893 b->u.type = TREE_TYPE (decl); |
2410 TREE_TYPE (decl) = newtype; | 2894 TREE_TYPE (decl) = newtype; |
2411 bind (functionid, decl, current_scope, | 2895 bind (functionid, decl, current_scope, |
2412 /*invisible=*/false, /*nested=*/true); | 2896 /*invisible=*/false, /*nested=*/true, |
2897 DECL_SOURCE_LOCATION (decl)); | |
2413 return decl; | 2898 return decl; |
2414 } | 2899 } |
2415 } | 2900 } |
2416 | 2901 |
2417 /* Not seen before. */ | 2902 /* Not seen before. */ |
2418 decl = build_decl (FUNCTION_DECL, functionid, default_function_type); | 2903 decl = build_decl (loc, FUNCTION_DECL, functionid, default_function_type); |
2419 DECL_EXTERNAL (decl) = 1; | 2904 DECL_EXTERNAL (decl) = 1; |
2420 TREE_PUBLIC (decl) = 1; | 2905 TREE_PUBLIC (decl) = 1; |
2421 C_DECL_IMPLICIT (decl) = 1; | 2906 C_DECL_IMPLICIT (decl) = 1; |
2422 implicit_decl_warning (functionid, 0); | 2907 implicit_decl_warning (functionid, 0); |
2423 asmspec_tree = maybe_apply_renaming_pragma (decl, /*asmname=*/NULL); | 2908 asmspec_tree = maybe_apply_renaming_pragma (decl, /*asmname=*/NULL); |
2445 ID, including a reference to a builtin outside of function-call | 2930 ID, including a reference to a builtin outside of function-call |
2446 context. Establish a binding of the identifier to error_mark_node | 2931 context. Establish a binding of the identifier to error_mark_node |
2447 in an appropriate scope, which will suppress further errors for the | 2932 in an appropriate scope, which will suppress further errors for the |
2448 same identifier. The error message should be given location LOC. */ | 2933 same identifier. The error message should be given location LOC. */ |
2449 void | 2934 void |
2450 undeclared_variable (tree id, location_t loc) | 2935 undeclared_variable (location_t loc, tree id) |
2451 { | 2936 { |
2452 static bool already = false; | 2937 static bool already = false; |
2453 struct c_scope *scope; | 2938 struct c_scope *scope; |
2454 | 2939 |
2455 if (current_function_decl == 0) | 2940 if (current_function_decl == 0) |
2456 { | 2941 { |
2457 error ("%H%qE undeclared here (not in a function)", &loc, id); | 2942 error_at (loc, "%qE undeclared here (not in a function)", id); |
2458 scope = current_scope; | 2943 scope = current_scope; |
2459 } | 2944 } |
2460 else | 2945 else |
2461 { | 2946 { |
2462 error ("%H%qE undeclared (first use in this function)", &loc, id); | 2947 error_at (loc, "%qE undeclared (first use in this function)", id); |
2463 | 2948 |
2464 if (!already) | 2949 if (!already) |
2465 { | 2950 { |
2466 error ("%H(Each undeclared identifier is reported only once", &loc); | 2951 error_at (loc, "(Each undeclared identifier is reported only once"); |
2467 error ("%Hfor each function it appears in.)", &loc); | 2952 error_at (loc, "for each function it appears in.)"); |
2468 already = true; | 2953 already = true; |
2469 } | 2954 } |
2470 | 2955 |
2471 /* If we are parsing old-style parameter decls, current_function_decl | 2956 /* If we are parsing old-style parameter decls, current_function_decl |
2472 will be nonnull but current_function_scope will be null. */ | 2957 will be nonnull but current_function_scope will be null. */ |
2473 scope = current_function_scope ? current_function_scope : current_scope; | 2958 scope = current_function_scope ? current_function_scope : current_scope; |
2474 } | 2959 } |
2475 bind (id, error_mark_node, scope, /*invisible=*/false, /*nested=*/false); | 2960 bind (id, error_mark_node, scope, /*invisible=*/false, /*nested=*/false, |
2961 UNKNOWN_LOCATION); | |
2476 } | 2962 } |
2477 | 2963 |
2478 /* Subroutine of lookup_label, declare_label, define_label: construct a | 2964 /* Subroutine of lookup_label, declare_label, define_label: construct a |
2479 LABEL_DECL with all the proper frills. */ | 2965 LABEL_DECL with all the proper frills. Also create a struct |
2966 c_label_vars initialized for the current scope. */ | |
2480 | 2967 |
2481 static tree | 2968 static tree |
2482 make_label (tree name, location_t location) | 2969 make_label (location_t location, tree name, bool defining, |
2483 { | 2970 struct c_label_vars **p_label_vars) |
2484 tree label = build_decl (LABEL_DECL, name, void_type_node); | 2971 { |
2972 tree label = build_decl (location, LABEL_DECL, name, void_type_node); | |
2973 struct c_label_vars *label_vars; | |
2485 | 2974 |
2486 DECL_CONTEXT (label) = current_function_decl; | 2975 DECL_CONTEXT (label) = current_function_decl; |
2487 DECL_MODE (label) = VOIDmode; | 2976 DECL_MODE (label) = VOIDmode; |
2488 DECL_SOURCE_LOCATION (label) = location; | 2977 |
2978 label_vars = GGC_NEW (struct c_label_vars); | |
2979 label_vars->shadowed = NULL; | |
2980 set_spot_bindings (&label_vars->label_bindings, defining); | |
2981 label_vars->decls_in_scope = make_tree_vector (); | |
2982 label_vars->gotos = VEC_alloc (c_goto_bindings_p, gc, 0); | |
2983 *p_label_vars = label_vars; | |
2489 | 2984 |
2490 return label; | 2985 return label; |
2491 } | 2986 } |
2492 | 2987 |
2493 /* Get the LABEL_DECL corresponding to identifier NAME as a label. | 2988 /* Get the LABEL_DECL corresponding to identifier NAME as a label. |
2497 | 2992 |
2498 tree | 2993 tree |
2499 lookup_label (tree name) | 2994 lookup_label (tree name) |
2500 { | 2995 { |
2501 tree label; | 2996 tree label; |
2997 struct c_label_vars *label_vars; | |
2502 | 2998 |
2503 if (current_function_decl == 0) | 2999 if (current_function_decl == 0) |
2504 { | 3000 { |
2505 error ("label %qE referenced outside of any function", name); | 3001 error ("label %qE referenced outside of any function", name); |
2506 return 0; | 3002 return 0; |
2514 || C_DECLARED_LABEL_FLAG (label))) | 3010 || C_DECLARED_LABEL_FLAG (label))) |
2515 { | 3011 { |
2516 /* If the label has only been declared, update its apparent | 3012 /* If the label has only been declared, update its apparent |
2517 location to point here, for better diagnostics if it | 3013 location to point here, for better diagnostics if it |
2518 turns out not to have been defined. */ | 3014 turns out not to have been defined. */ |
2519 if (!TREE_USED (label)) | 3015 if (DECL_INITIAL (label) == NULL_TREE) |
2520 DECL_SOURCE_LOCATION (label) = input_location; | 3016 DECL_SOURCE_LOCATION (label) = input_location; |
2521 return label; | 3017 return label; |
2522 } | 3018 } |
2523 | 3019 |
2524 /* No label binding for that identifier; make one. */ | 3020 /* No label binding for that identifier; make one. */ |
2525 label = make_label (name, input_location); | 3021 label = make_label (input_location, name, false, &label_vars); |
2526 | 3022 |
2527 /* Ordinary labels go in the current function scope. */ | 3023 /* Ordinary labels go in the current function scope. */ |
2528 bind (name, label, current_function_scope, | 3024 bind_label (name, label, current_function_scope, label_vars); |
2529 /*invisible=*/false, /*nested=*/false); | 3025 |
3026 return label; | |
3027 } | |
3028 | |
3029 /* Issue a warning about DECL for a goto statement at GOTO_LOC going | |
3030 to LABEL. */ | |
3031 | |
3032 static void | |
3033 warn_about_goto (location_t goto_loc, tree label, tree decl) | |
3034 { | |
3035 if (variably_modified_type_p (TREE_TYPE (decl), NULL_TREE)) | |
3036 error_at (goto_loc, | |
3037 "jump into scope of identifier with variably modified type"); | |
3038 else | |
3039 warning_at (goto_loc, OPT_Wjump_misses_init, | |
3040 "jump skips variable initialization"); | |
3041 inform (DECL_SOURCE_LOCATION (label), "label %qD defined here", label); | |
3042 inform (DECL_SOURCE_LOCATION (decl), "%qD declared here", decl); | |
3043 } | |
3044 | |
3045 /* Look up a label because of a goto statement. This is like | |
3046 lookup_label, but also issues any appropriate warnings. */ | |
3047 | |
3048 tree | |
3049 lookup_label_for_goto (location_t loc, tree name) | |
3050 { | |
3051 tree label; | |
3052 struct c_label_vars *label_vars; | |
3053 unsigned int ix; | |
3054 tree decl; | |
3055 | |
3056 label = lookup_label (name); | |
3057 if (label == NULL_TREE) | |
3058 return NULL_TREE; | |
3059 | |
3060 /* If we are jumping to a different function, we can't issue any | |
3061 useful warnings. */ | |
3062 if (DECL_CONTEXT (label) != current_function_decl) | |
3063 { | |
3064 gcc_assert (C_DECLARED_LABEL_FLAG (label)); | |
3065 return label; | |
3066 } | |
3067 | |
3068 label_vars = I_LABEL_BINDING (name)->u.label; | |
3069 | |
3070 /* If the label has not yet been defined, then push this goto on a | |
3071 list for possible later warnings. */ | |
3072 if (label_vars->label_bindings.scope == NULL) | |
3073 { | |
3074 struct c_goto_bindings *g; | |
3075 | |
3076 g = GGC_NEW (struct c_goto_bindings); | |
3077 g->loc = loc; | |
3078 set_spot_bindings (&g->goto_bindings, true); | |
3079 VEC_safe_push (c_goto_bindings_p, gc, label_vars->gotos, g); | |
3080 return label; | |
3081 } | |
3082 | |
3083 /* If there are any decls in label_vars->decls_in_scope, then this | |
3084 goto has missed the declaration of the decl. This happens for a | |
3085 case like | |
3086 int i = 1; | |
3087 lab: | |
3088 ... | |
3089 goto lab; | |
3090 Issue a warning or error. */ | |
3091 for (ix = 0; VEC_iterate (tree, label_vars->decls_in_scope, ix, decl); ++ix) | |
3092 warn_about_goto (loc, label, decl); | |
3093 | |
3094 if (label_vars->label_bindings.left_stmt_expr) | |
3095 { | |
3096 error_at (loc, "jump into statement expression"); | |
3097 inform (DECL_SOURCE_LOCATION (label), "label %qD defined here", label); | |
3098 } | |
3099 | |
2530 return label; | 3100 return label; |
2531 } | 3101 } |
2532 | 3102 |
2533 /* Make a label named NAME in the current function, shadowing silently | 3103 /* Make a label named NAME in the current function, shadowing silently |
2534 any that may be inherited from containing functions or containing | 3104 any that may be inherited from containing functions or containing |
2537 tree | 3107 tree |
2538 declare_label (tree name) | 3108 declare_label (tree name) |
2539 { | 3109 { |
2540 struct c_binding *b = I_LABEL_BINDING (name); | 3110 struct c_binding *b = I_LABEL_BINDING (name); |
2541 tree label; | 3111 tree label; |
3112 struct c_label_vars *label_vars; | |
2542 | 3113 |
2543 /* Check to make sure that the label hasn't already been declared | 3114 /* Check to make sure that the label hasn't already been declared |
2544 at this scope */ | 3115 at this scope */ |
2545 if (b && B_IN_CURRENT_SCOPE (b)) | 3116 if (b && B_IN_CURRENT_SCOPE (b)) |
2546 { | 3117 { |
2549 | 3120 |
2550 /* Just use the previous declaration. */ | 3121 /* Just use the previous declaration. */ |
2551 return b->decl; | 3122 return b->decl; |
2552 } | 3123 } |
2553 | 3124 |
2554 label = make_label (name, input_location); | 3125 label = make_label (input_location, name, false, &label_vars); |
2555 C_DECLARED_LABEL_FLAG (label) = 1; | 3126 C_DECLARED_LABEL_FLAG (label) = 1; |
2556 | 3127 |
2557 /* Declared labels go in the current scope. */ | 3128 /* Declared labels go in the current scope. */ |
2558 bind (name, label, current_scope, | 3129 bind_label (name, label, current_scope, label_vars); |
2559 /*invisible=*/false, /*nested=*/false); | 3130 |
2560 return label; | 3131 return label; |
3132 } | |
3133 | |
3134 /* When we define a label, issue any appropriate warnings if there are | |
3135 any gotos earlier in the function which jump to this label. */ | |
3136 | |
3137 static void | |
3138 check_earlier_gotos (tree label, struct c_label_vars* label_vars) | |
3139 { | |
3140 unsigned int ix; | |
3141 struct c_goto_bindings *g; | |
3142 | |
3143 for (ix = 0; | |
3144 VEC_iterate (c_goto_bindings_p, label_vars->gotos, ix, g); | |
3145 ++ix) | |
3146 { | |
3147 struct c_binding *b; | |
3148 struct c_scope *scope; | |
3149 | |
3150 /* We have a goto to this label. The goto is going forward. In | |
3151 g->scope, the goto is going to skip any binding which was | |
3152 defined after g->bindings_in_scope. */ | |
3153 for (b = g->goto_bindings.scope->bindings; | |
3154 b != g->goto_bindings.bindings_in_scope; | |
3155 b = b->prev) | |
3156 { | |
3157 if (decl_jump_unsafe (b->decl)) | |
3158 warn_about_goto (g->loc, label, b->decl); | |
3159 } | |
3160 | |
3161 /* We also need to warn about decls defined in any scopes | |
3162 between the scope of the label and the scope of the goto. */ | |
3163 for (scope = label_vars->label_bindings.scope; | |
3164 scope != g->goto_bindings.scope; | |
3165 scope = scope->outer) | |
3166 { | |
3167 gcc_assert (scope != NULL); | |
3168 if (scope == label_vars->label_bindings.scope) | |
3169 b = label_vars->label_bindings.bindings_in_scope; | |
3170 else | |
3171 b = scope->bindings; | |
3172 for (; b != NULL; b = b->prev) | |
3173 { | |
3174 if (decl_jump_unsafe (b->decl)) | |
3175 warn_about_goto (g->loc, label, b->decl); | |
3176 } | |
3177 } | |
3178 | |
3179 if (g->goto_bindings.stmt_exprs > 0) | |
3180 { | |
3181 error_at (g->loc, "jump into statement expression"); | |
3182 inform (DECL_SOURCE_LOCATION (label), "label %qD defined here", | |
3183 label); | |
3184 } | |
3185 } | |
3186 | |
3187 /* Now that the label is defined, we will issue warnings about | |
3188 subsequent gotos to this label when we see them. */ | |
3189 VEC_truncate (c_goto_bindings_p, label_vars->gotos, 0); | |
3190 label_vars->gotos = NULL; | |
2561 } | 3191 } |
2562 | 3192 |
2563 /* Define a label, specifying the location in the source file. | 3193 /* Define a label, specifying the location in the source file. |
2564 Return the LABEL_DECL node for the label, if the definition is valid. | 3194 Return the LABEL_DECL node for the label, if the definition is valid. |
2565 Otherwise return 0. */ | 3195 Otherwise return 0. */ |
2570 /* Find any preexisting label with this name. It is an error | 3200 /* Find any preexisting label with this name. It is an error |
2571 if that label has already been defined in this function, or | 3201 if that label has already been defined in this function, or |
2572 if there is a containing function with a declared label with | 3202 if there is a containing function with a declared label with |
2573 the same name. */ | 3203 the same name. */ |
2574 tree label = I_LABEL_DECL (name); | 3204 tree label = I_LABEL_DECL (name); |
2575 struct c_label_list *nlist_se, *nlist_vm; | |
2576 | 3205 |
2577 if (label | 3206 if (label |
2578 && ((DECL_CONTEXT (label) == current_function_decl | 3207 && ((DECL_CONTEXT (label) == current_function_decl |
2579 && DECL_INITIAL (label) != 0) | 3208 && DECL_INITIAL (label) != 0) |
2580 || (DECL_CONTEXT (label) != current_function_decl | 3209 || (DECL_CONTEXT (label) != current_function_decl |
2581 && C_DECLARED_LABEL_FLAG (label)))) | 3210 && C_DECLARED_LABEL_FLAG (label)))) |
2582 { | 3211 { |
2583 error ("%Hduplicate label %qD", &location, label); | 3212 error_at (location, "duplicate label %qD", label); |
2584 locate_old_decl (label); | 3213 locate_old_decl (label); |
2585 return 0; | 3214 return 0; |
2586 } | 3215 } |
2587 else if (label && DECL_CONTEXT (label) == current_function_decl) | 3216 else if (label && DECL_CONTEXT (label) == current_function_decl) |
2588 { | 3217 { |
3218 struct c_label_vars *label_vars = I_LABEL_BINDING (name)->u.label; | |
3219 | |
2589 /* The label has been used or declared already in this function, | 3220 /* The label has been used or declared already in this function, |
2590 but not defined. Update its location to point to this | 3221 but not defined. Update its location to point to this |
2591 definition. */ | 3222 definition. */ |
2592 if (C_DECL_UNDEFINABLE_STMT_EXPR (label)) | |
2593 error ("%Jjump into statement expression", label); | |
2594 if (C_DECL_UNDEFINABLE_VM (label)) | |
2595 error ("%Jjump into scope of identifier with variably modified type", | |
2596 label); | |
2597 DECL_SOURCE_LOCATION (label) = location; | 3223 DECL_SOURCE_LOCATION (label) = location; |
3224 set_spot_bindings (&label_vars->label_bindings, true); | |
3225 | |
3226 /* Issue warnings as required about any goto statements from | |
3227 earlier in the function. */ | |
3228 check_earlier_gotos (label, label_vars); | |
2598 } | 3229 } |
2599 else | 3230 else |
2600 { | 3231 { |
3232 struct c_label_vars *label_vars; | |
3233 | |
2601 /* No label binding for that identifier; make one. */ | 3234 /* No label binding for that identifier; make one. */ |
2602 label = make_label (name, location); | 3235 label = make_label (location, name, true, &label_vars); |
2603 | 3236 |
2604 /* Ordinary labels go in the current function scope. */ | 3237 /* Ordinary labels go in the current function scope. */ |
2605 bind (name, label, current_function_scope, | 3238 bind_label (name, label, current_function_scope, label_vars); |
2606 /*invisible=*/false, /*nested=*/false); | |
2607 } | 3239 } |
2608 | 3240 |
2609 if (!in_system_header && lookup_name (name)) | 3241 if (!in_system_header && lookup_name (name)) |
2610 warning (OPT_Wtraditional, "%Htraditional C lacks a separate namespace " | 3242 warning_at (location, OPT_Wtraditional, |
2611 "for labels, identifier %qE conflicts", &location, name); | 3243 "traditional C lacks a separate namespace " |
2612 | 3244 "for labels, identifier %qE conflicts", name); |
2613 nlist_se = XOBNEW (&parser_obstack, struct c_label_list); | |
2614 nlist_se->next = label_context_stack_se->labels_def; | |
2615 nlist_se->label = label; | |
2616 label_context_stack_se->labels_def = nlist_se; | |
2617 | |
2618 nlist_vm = XOBNEW (&parser_obstack, struct c_label_list); | |
2619 nlist_vm->next = label_context_stack_vm->labels_def; | |
2620 nlist_vm->label = label; | |
2621 label_context_stack_vm->labels_def = nlist_vm; | |
2622 | 3245 |
2623 /* Mark label as having been defined. */ | 3246 /* Mark label as having been defined. */ |
2624 DECL_INITIAL (label) = error_mark_node; | 3247 DECL_INITIAL (label) = error_mark_node; |
2625 return label; | 3248 return label; |
3249 } | |
3250 | |
3251 /* Get the bindings for a new switch statement. This is used to issue | |
3252 warnings as appropriate for jumps from the switch to case or | |
3253 default labels. */ | |
3254 | |
3255 struct c_spot_bindings * | |
3256 c_get_switch_bindings (void) | |
3257 { | |
3258 struct c_spot_bindings *switch_bindings; | |
3259 | |
3260 switch_bindings = XNEW (struct c_spot_bindings); | |
3261 set_spot_bindings (switch_bindings, true); | |
3262 return switch_bindings; | |
3263 } | |
3264 | |
3265 void | |
3266 c_release_switch_bindings (struct c_spot_bindings *bindings) | |
3267 { | |
3268 gcc_assert (bindings->stmt_exprs == 0 && !bindings->left_stmt_expr); | |
3269 XDELETE (bindings); | |
3270 } | |
3271 | |
3272 /* This is called at the point of a case or default label to issue | |
3273 warnings about decls as needed. It returns true if it found an | |
3274 error, not just a warning. */ | |
3275 | |
3276 bool | |
3277 c_check_switch_jump_warnings (struct c_spot_bindings *switch_bindings, | |
3278 location_t switch_loc, location_t case_loc) | |
3279 { | |
3280 bool saw_error; | |
3281 struct c_scope *scope; | |
3282 | |
3283 saw_error = false; | |
3284 for (scope = current_scope; | |
3285 scope != switch_bindings->scope; | |
3286 scope = scope->outer) | |
3287 { | |
3288 struct c_binding *b; | |
3289 | |
3290 gcc_assert (scope != NULL); | |
3291 for (b = scope->bindings; b != NULL; b = b->prev) | |
3292 { | |
3293 if (decl_jump_unsafe (b->decl)) | |
3294 { | |
3295 if (variably_modified_type_p (TREE_TYPE (b->decl), NULL_TREE)) | |
3296 { | |
3297 saw_error = true; | |
3298 error_at (case_loc, | |
3299 ("switch jumps into scope of identifier with " | |
3300 "variably modified type")); | |
3301 } | |
3302 else | |
3303 warning_at (case_loc, OPT_Wjump_misses_init, | |
3304 "switch jumps over variable initialization"); | |
3305 inform (switch_loc, "switch starts here"); | |
3306 inform (DECL_SOURCE_LOCATION (b->decl), "%qD declared here", | |
3307 b->decl); | |
3308 } | |
3309 } | |
3310 } | |
3311 | |
3312 if (switch_bindings->stmt_exprs > 0) | |
3313 { | |
3314 saw_error = true; | |
3315 error_at (case_loc, "switch jumps into statement expression"); | |
3316 inform (switch_loc, "switch starts here"); | |
3317 } | |
3318 | |
3319 return saw_error; | |
2626 } | 3320 } |
2627 | 3321 |
2628 /* Given NAME, an IDENTIFIER_NODE, | 3322 /* Given NAME, an IDENTIFIER_NODE, |
2629 return the structure (or union or enum) definition for that name. | 3323 return the structure (or union or enum) definition for that name. |
2630 If THISLEVEL_ONLY is nonzero, searches only the current_scope. | 3324 If THISLEVEL_ONLY is nonzero, searches only the current_scope. |
2631 CODE says which kind of type the caller wants; | 3325 CODE says which kind of type the caller wants; |
2632 it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE. | 3326 it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE. |
3327 If PLOC is not NULL and this returns non-null, it sets *PLOC to the | |
3328 location where the tag was defined. | |
2633 If the wrong kind of type is found, an error is reported. */ | 3329 If the wrong kind of type is found, an error is reported. */ |
2634 | 3330 |
2635 static tree | 3331 static tree |
2636 lookup_tag (enum tree_code code, tree name, int thislevel_only) | 3332 lookup_tag (enum tree_code code, tree name, int thislevel_only, |
3333 location_t *ploc) | |
2637 { | 3334 { |
2638 struct c_binding *b = I_TAG_BINDING (name); | 3335 struct c_binding *b = I_TAG_BINDING (name); |
2639 int thislevel = 0; | 3336 int thislevel = 0; |
2640 | 3337 |
2641 if (!b || !b->decl) | 3338 if (!b || !b->decl) |
2668 shadow that tag, so give the error immediately. | 3365 shadow that tag, so give the error immediately. |
2669 (For example, "struct foo; union foo;" is invalid.) */ | 3366 (For example, "struct foo; union foo;" is invalid.) */ |
2670 if (thislevel) | 3367 if (thislevel) |
2671 pending_xref_error (); | 3368 pending_xref_error (); |
2672 } | 3369 } |
3370 | |
3371 if (ploc != NULL) | |
3372 *ploc = b->locus; | |
3373 | |
2673 return b->decl; | 3374 return b->decl; |
2674 } | 3375 } |
2675 | 3376 |
2676 /* Print an error message now | 3377 /* Print an error message now |
2677 for a recent invalid struct, union or enum cross reference. | 3378 for a recent invalid struct, union or enum cross reference. |
2680 | 3381 |
2681 void | 3382 void |
2682 pending_xref_error (void) | 3383 pending_xref_error (void) |
2683 { | 3384 { |
2684 if (pending_invalid_xref != 0) | 3385 if (pending_invalid_xref != 0) |
2685 error ("%H%qE defined as wrong kind of tag", | 3386 error_at (pending_invalid_xref_location, "%qE defined as wrong kind of tag", |
2686 &pending_invalid_xref_location, pending_invalid_xref); | 3387 pending_invalid_xref); |
2687 pending_invalid_xref = 0; | 3388 pending_invalid_xref = 0; |
2688 } | 3389 } |
2689 | 3390 |
2690 | 3391 |
2691 /* Look up NAME in the current scope and its superiors | 3392 /* Look up NAME in the current scope and its superiors |
2749 truthvalue_type_node = integer_type_node; | 3450 truthvalue_type_node = integer_type_node; |
2750 truthvalue_true_node = integer_one_node; | 3451 truthvalue_true_node = integer_one_node; |
2751 truthvalue_false_node = integer_zero_node; | 3452 truthvalue_false_node = integer_zero_node; |
2752 | 3453 |
2753 /* Even in C99, which has a real boolean type. */ | 3454 /* Even in C99, which has a real boolean type. */ |
2754 pushdecl (build_decl (TYPE_DECL, get_identifier ("_Bool"), | 3455 pushdecl (build_decl (UNKNOWN_LOCATION, TYPE_DECL, get_identifier ("_Bool"), |
2755 boolean_type_node)); | 3456 boolean_type_node)); |
2756 | 3457 |
2757 input_location = save_loc; | 3458 input_location = save_loc; |
2758 | 3459 |
2759 pedantic_lvalues = true; | 3460 pedantic_lvalues = true; |
2760 | 3461 |
2761 make_fname_decl = c_make_fname_decl; | 3462 make_fname_decl = c_make_fname_decl; |
2762 start_fname_decls (); | 3463 start_fname_decls (); |
2763 } | 3464 } |
2764 | 3465 |
2765 /* Create the VAR_DECL for __FUNCTION__ etc. ID is the name to give the | 3466 /* Create the VAR_DECL at LOC for __FUNCTION__ etc. ID is the name to |
2766 decl, NAME is the initialization string and TYPE_DEP indicates whether | 3467 give the decl, NAME is the initialization string and TYPE_DEP |
2767 NAME depended on the type of the function. As we don't yet implement | 3468 indicates whether NAME depended on the type of the function. As we |
2768 delayed emission of static data, we mark the decl as emitted | 3469 don't yet implement delayed emission of static data, we mark the |
2769 so it is not placed in the output. Anything using it must therefore pull | 3470 decl as emitted so it is not placed in the output. Anything using |
2770 out the STRING_CST initializer directly. FIXME. */ | 3471 it must therefore pull out the STRING_CST initializer directly. |
3472 FIXME. */ | |
2771 | 3473 |
2772 static tree | 3474 static tree |
2773 c_make_fname_decl (tree id, int type_dep) | 3475 c_make_fname_decl (location_t loc, tree id, int type_dep) |
2774 { | 3476 { |
2775 const char *name = fname_as_string (type_dep); | 3477 const char *name = fname_as_string (type_dep); |
2776 tree decl, type, init; | 3478 tree decl, type, init; |
2777 size_t length = strlen (name); | 3479 size_t length = strlen (name); |
2778 | 3480 |
2779 type = build_array_type (char_type_node, | 3481 type = build_array_type (char_type_node, |
2780 build_index_type (size_int (length))); | 3482 build_index_type (size_int (length))); |
2781 type = c_build_qualified_type (type, TYPE_QUAL_CONST); | 3483 type = c_build_qualified_type (type, TYPE_QUAL_CONST); |
2782 | 3484 |
2783 decl = build_decl (VAR_DECL, id, type); | 3485 decl = build_decl (loc, VAR_DECL, id, type); |
2784 | 3486 |
2785 TREE_STATIC (decl) = 1; | 3487 TREE_STATIC (decl) = 1; |
2786 TREE_READONLY (decl) = 1; | 3488 TREE_READONLY (decl) = 1; |
2787 DECL_ARTIFICIAL (decl) = 1; | 3489 DECL_ARTIFICIAL (decl) = 1; |
2788 | 3490 |
2793 | 3495 |
2794 TREE_USED (decl) = 1; | 3496 TREE_USED (decl) = 1; |
2795 | 3497 |
2796 if (current_function_decl | 3498 if (current_function_decl |
2797 /* For invalid programs like this: | 3499 /* For invalid programs like this: |
2798 | 3500 |
2799 void foo() | 3501 void foo() |
2800 const char* p = __FUNCTION__; | 3502 const char* p = __FUNCTION__; |
2801 | 3503 |
2802 the __FUNCTION__ is believed to appear in K&R style function | 3504 the __FUNCTION__ is believed to appear in K&R style function |
2803 parameter declarator. In that case we still don't have | 3505 parameter declarator. In that case we still don't have |
2804 function_scope. */ | 3506 function_scope. */ |
2805 && (!errorcount || current_function_scope)) | 3507 && (!errorcount || current_function_scope)) |
2806 { | 3508 { |
2807 DECL_CONTEXT (decl) = current_function_decl; | 3509 DECL_CONTEXT (decl) = current_function_decl; |
2808 bind (id, decl, current_function_scope, | 3510 bind (id, decl, current_function_scope, |
2809 /*invisible=*/false, /*nested=*/false); | 3511 /*invisible=*/false, /*nested=*/false, UNKNOWN_LOCATION); |
2810 } | 3512 } |
2811 | 3513 |
2812 finish_decl (decl, init, NULL_TREE); | 3514 finish_decl (decl, loc, init, NULL_TREE, NULL_TREE); |
2813 | 3515 |
2814 return decl; | 3516 return decl; |
2815 } | 3517 } |
2816 | 3518 |
2817 tree | 3519 tree |
2824 C_DECL_BUILTIN_PROTOTYPE (decl) = (TYPE_ARG_TYPES (type) != 0); | 3526 C_DECL_BUILTIN_PROTOTYPE (decl) = (TYPE_ARG_TYPES (type) != 0); |
2825 | 3527 |
2826 /* Should never be called on a symbol with a preexisting meaning. */ | 3528 /* Should never be called on a symbol with a preexisting meaning. */ |
2827 gcc_assert (!I_SYMBOL_BINDING (id)); | 3529 gcc_assert (!I_SYMBOL_BINDING (id)); |
2828 | 3530 |
2829 bind (id, decl, external_scope, /*invisible=*/true, /*nested=*/false); | 3531 bind (id, decl, external_scope, /*invisible=*/true, /*nested=*/false, |
3532 UNKNOWN_LOCATION); | |
2830 | 3533 |
2831 /* Builtins in the implementation namespace are made visible without | 3534 /* Builtins in the implementation namespace are made visible without |
2832 needing to be explicitly declared. See push_file_scope. */ | 3535 needing to be explicitly declared. See push_file_scope. */ |
2833 if (name[0] == '_' && (name[1] == '_' || ISUPPER (name[1]))) | 3536 if (name[0] == '_' && (name[1] == '_' || ISUPPER (name[1]))) |
2834 { | 3537 { |
2849 C_DECL_BUILTIN_PROTOTYPE (decl) = (TYPE_ARG_TYPES (type) != 0); | 3552 C_DECL_BUILTIN_PROTOTYPE (decl) = (TYPE_ARG_TYPES (type) != 0); |
2850 | 3553 |
2851 /* Should never be called on a symbol with a preexisting meaning. */ | 3554 /* Should never be called on a symbol with a preexisting meaning. */ |
2852 gcc_assert (!I_SYMBOL_BINDING (id)); | 3555 gcc_assert (!I_SYMBOL_BINDING (id)); |
2853 | 3556 |
2854 bind (id, decl, external_scope, /*invisible=*/false, /*nested=*/false); | 3557 bind (id, decl, external_scope, /*invisible=*/false, /*nested=*/false, |
3558 UNKNOWN_LOCATION); | |
2855 | 3559 |
2856 /* Builtins in the implementation namespace are made visible without | 3560 /* Builtins in the implementation namespace are made visible without |
2857 needing to be explicitly declared. See push_file_scope. */ | 3561 needing to be explicitly declared. See push_file_scope. */ |
2858 if (name[0] == '_' && (name[1] == '_' || ISUPPER (name[1]))) | 3562 if (name[0] == '_' && (name[1] == '_' || ISUPPER (name[1]))) |
2859 { | 3563 { |
2896 { | 3600 { |
2897 tree name = TYPE_NAME (value); | 3601 tree name = TYPE_NAME (value); |
2898 tree t; | 3602 tree t; |
2899 | 3603 |
2900 found_tag = true; | 3604 found_tag = true; |
3605 | |
3606 if (declspecs->restrict_p) | |
3607 { | |
3608 error ("invalid use of %<restrict%>"); | |
3609 warned = 1; | |
3610 } | |
2901 | 3611 |
2902 if (name == 0) | 3612 if (name == 0) |
2903 { | 3613 { |
2904 if (warned != 1 && code != ENUMERAL_TYPE) | 3614 if (warned != 1 && code != ENUMERAL_TYPE) |
2905 /* Empty unnamed enum OK */ | 3615 /* Empty unnamed enum OK */ |
2920 pending_xref_error (); | 3630 pending_xref_error (); |
2921 } | 3631 } |
2922 else if (!declspecs->tag_defined_p | 3632 else if (!declspecs->tag_defined_p |
2923 && (declspecs->const_p | 3633 && (declspecs->const_p |
2924 || declspecs->volatile_p | 3634 || declspecs->volatile_p |
2925 || declspecs->restrict_p)) | 3635 || declspecs->restrict_p |
3636 || declspecs->address_space)) | |
2926 { | 3637 { |
2927 if (warned != 1) | 3638 if (warned != 1) |
2928 pedwarn (input_location, 0, | 3639 pedwarn (input_location, 0, |
2929 "empty declaration with type qualifier " | 3640 "empty declaration with type qualifier " |
2930 "does not redeclare tag"); | 3641 "does not redeclare tag"); |
2932 pending_xref_error (); | 3643 pending_xref_error (); |
2933 } | 3644 } |
2934 else | 3645 else |
2935 { | 3646 { |
2936 pending_invalid_xref = 0; | 3647 pending_invalid_xref = 0; |
2937 t = lookup_tag (code, name, 1); | 3648 t = lookup_tag (code, name, 1, NULL); |
2938 | 3649 |
2939 if (t == 0) | 3650 if (t == 0) |
2940 { | 3651 { |
2941 t = make_node (code); | 3652 t = make_node (code); |
2942 pushtag (name, t); | 3653 pushtag (input_location, name, t); |
2943 } | 3654 } |
2944 } | 3655 } |
2945 } | 3656 } |
2946 else | 3657 else |
2947 { | 3658 { |
2991 warned = 2; | 3702 warned = 2; |
2992 } | 3703 } |
2993 | 3704 |
2994 if (!warned && !in_system_header && (declspecs->const_p | 3705 if (!warned && !in_system_header && (declspecs->const_p |
2995 || declspecs->volatile_p | 3706 || declspecs->volatile_p |
2996 || declspecs->restrict_p)) | 3707 || declspecs->restrict_p |
3708 || declspecs->address_space)) | |
2997 { | 3709 { |
2998 warning (0, "useless type qualifier in empty declaration"); | 3710 warning (0, "useless type qualifier in empty declaration"); |
2999 warned = 2; | 3711 warned = 2; |
3000 } | 3712 } |
3001 | 3713 |
3014 int | 3726 int |
3015 quals_from_declspecs (const struct c_declspecs *specs) | 3727 quals_from_declspecs (const struct c_declspecs *specs) |
3016 { | 3728 { |
3017 int quals = ((specs->const_p ? TYPE_QUAL_CONST : 0) | 3729 int quals = ((specs->const_p ? TYPE_QUAL_CONST : 0) |
3018 | (specs->volatile_p ? TYPE_QUAL_VOLATILE : 0) | 3730 | (specs->volatile_p ? TYPE_QUAL_VOLATILE : 0) |
3019 | (specs->restrict_p ? TYPE_QUAL_RESTRICT : 0)); | 3731 | (specs->restrict_p ? TYPE_QUAL_RESTRICT : 0) |
3732 | (ENCODE_QUAL_ADDR_SPACE (specs->address_space))); | |
3020 gcc_assert (!specs->type | 3733 gcc_assert (!specs->type |
3021 && !specs->decl_attr | 3734 && !specs->decl_attr |
3022 && specs->typespec_word == cts_none | 3735 && specs->typespec_word == cts_none |
3023 && specs->storage_class == csc_none | 3736 && specs->storage_class == csc_none |
3024 && !specs->typedef_p | 3737 && !specs->typedef_p |
3033 && !specs->inline_p | 3746 && !specs->inline_p |
3034 && !specs->thread_p); | 3747 && !specs->thread_p); |
3035 return quals; | 3748 return quals; |
3036 } | 3749 } |
3037 | 3750 |
3038 /* Construct an array declarator. EXPR is the expression inside [], | 3751 /* Construct an array declarator. LOC is the location of the |
3039 or NULL_TREE. QUALS are the type qualifiers inside the [] (to be | 3752 beginning of the array (usually the opening brace). EXPR is the |
3040 applied to the pointer to which a parameter array is converted). | 3753 expression inside [], or NULL_TREE. QUALS are the type qualifiers |
3041 STATIC_P is true if "static" is inside the [], false otherwise. | 3754 inside the [] (to be applied to the pointer to which a parameter |
3042 VLA_UNSPEC_P is true if the array is [*], a VLA of unspecified | 3755 array is converted). STATIC_P is true if "static" is inside the |
3043 length which is nevertheless a complete type, false otherwise. The | 3756 [], false otherwise. VLA_UNSPEC_P is true if the array is [*], a |
3044 field for the contained declarator is left to be filled in by | 3757 VLA of unspecified length which is nevertheless a complete type, |
3045 set_array_declarator_inner. */ | 3758 false otherwise. The field for the contained declarator is left to |
3759 be filled in by set_array_declarator_inner. */ | |
3046 | 3760 |
3047 struct c_declarator * | 3761 struct c_declarator * |
3048 build_array_declarator (tree expr, struct c_declspecs *quals, bool static_p, | 3762 build_array_declarator (location_t loc, |
3763 tree expr, struct c_declspecs *quals, bool static_p, | |
3049 bool vla_unspec_p) | 3764 bool vla_unspec_p) |
3050 { | 3765 { |
3051 struct c_declarator *declarator = XOBNEW (&parser_obstack, | 3766 struct c_declarator *declarator = XOBNEW (&parser_obstack, |
3052 struct c_declarator); | 3767 struct c_declarator); |
3768 declarator->id_loc = loc; | |
3053 declarator->kind = cdk_array; | 3769 declarator->kind = cdk_array; |
3054 declarator->declarator = 0; | 3770 declarator->declarator = 0; |
3055 declarator->u.array.dimen = expr; | 3771 declarator->u.array.dimen = expr; |
3056 if (quals) | 3772 if (quals) |
3057 { | 3773 { |
3066 declarator->u.array.static_p = static_p; | 3782 declarator->u.array.static_p = static_p; |
3067 declarator->u.array.vla_unspec_p = vla_unspec_p; | 3783 declarator->u.array.vla_unspec_p = vla_unspec_p; |
3068 if (!flag_isoc99) | 3784 if (!flag_isoc99) |
3069 { | 3785 { |
3070 if (static_p || quals != NULL) | 3786 if (static_p || quals != NULL) |
3071 pedwarn (input_location, OPT_pedantic, | 3787 pedwarn (loc, OPT_pedantic, |
3072 "ISO C90 does not support %<static%> or type " | 3788 "ISO C90 does not support %<static%> or type " |
3073 "qualifiers in parameter array declarators"); | 3789 "qualifiers in parameter array declarators"); |
3074 if (vla_unspec_p) | 3790 if (vla_unspec_p) |
3075 pedwarn (input_location, OPT_pedantic, | 3791 pedwarn (loc, OPT_pedantic, |
3076 "ISO C90 does not support %<[*]%> array declarators"); | 3792 "ISO C90 does not support %<[*]%> array declarators"); |
3077 } | 3793 } |
3078 if (vla_unspec_p) | 3794 if (vla_unspec_p) |
3079 { | 3795 { |
3080 if (!current_scope->parm_flag) | 3796 if (!current_scope->parm_flag) |
3081 { | 3797 { |
3082 /* C99 6.7.5.2p4 */ | 3798 /* C99 6.7.5.2p4 */ |
3083 error ("%<[*]%> not allowed in other than function prototype scope"); | 3799 error_at (loc, "%<[*]%> not allowed in other than " |
3800 "function prototype scope"); | |
3084 declarator->u.array.vla_unspec_p = false; | 3801 declarator->u.array.vla_unspec_p = false; |
3085 return NULL; | 3802 return NULL; |
3086 } | 3803 } |
3087 current_scope->had_vla_unspec = true; | 3804 current_scope->had_vla_unspec = true; |
3088 } | 3805 } |
3126 DECL_SIZE_UNIT (decl) | 3843 DECL_SIZE_UNIT (decl) |
3127 = size_binop (PLUS_EXPR, DECL_SIZE_UNIT (decl), TYPE_SIZE_UNIT (type)); | 3844 = size_binop (PLUS_EXPR, DECL_SIZE_UNIT (decl), TYPE_SIZE_UNIT (type)); |
3128 } | 3845 } |
3129 } | 3846 } |
3130 | 3847 |
3131 /* Decode a "typename", such as "int **", returning a ..._TYPE node. */ | 3848 /* Decode a "typename", such as "int **", returning a ..._TYPE node. |
3849 Set *EXPR, if EXPR not NULL, to any expression to be evaluated | |
3850 before the type name, and set *EXPR_CONST_OPERANDS, if | |
3851 EXPR_CONST_OPERANDS not NULL, to indicate whether the type name may | |
3852 appear in a constant expression. */ | |
3132 | 3853 |
3133 tree | 3854 tree |
3134 groktypename (struct c_type_name *type_name) | 3855 groktypename (struct c_type_name *type_name, tree *expr, |
3856 bool *expr_const_operands) | |
3135 { | 3857 { |
3136 tree type; | 3858 tree type; |
3137 tree attrs = type_name->specs->attrs; | 3859 tree attrs = type_name->specs->attrs; |
3138 | 3860 |
3139 type_name->specs->attrs = NULL_TREE; | 3861 type_name->specs->attrs = NULL_TREE; |
3140 | 3862 |
3141 type = grokdeclarator (type_name->declarator, type_name->specs, TYPENAME, | 3863 type = grokdeclarator (type_name->declarator, type_name->specs, TYPENAME, |
3142 false, NULL, &attrs, DEPRECATED_NORMAL); | 3864 false, NULL, &attrs, expr, expr_const_operands, |
3865 DEPRECATED_NORMAL); | |
3143 | 3866 |
3144 /* Apply attributes. */ | 3867 /* Apply attributes. */ |
3145 decl_attributes (&type, attrs, 0); | 3868 decl_attributes (&type, attrs, 0); |
3146 | 3869 |
3147 return type; | 3870 return type; |
3166 start_decl (struct c_declarator *declarator, struct c_declspecs *declspecs, | 3889 start_decl (struct c_declarator *declarator, struct c_declspecs *declspecs, |
3167 bool initialized, tree attributes) | 3890 bool initialized, tree attributes) |
3168 { | 3891 { |
3169 tree decl; | 3892 tree decl; |
3170 tree tem; | 3893 tree tem; |
3894 tree expr = NULL_TREE; | |
3171 enum deprecated_states deprecated_state = DEPRECATED_NORMAL; | 3895 enum deprecated_states deprecated_state = DEPRECATED_NORMAL; |
3172 | 3896 |
3173 /* An object declared as __attribute__((deprecated)) suppresses | 3897 /* An object declared as __attribute__((deprecated)) suppresses |
3174 warnings of uses of other deprecated items. */ | 3898 warnings of uses of other deprecated items. */ |
3175 if (lookup_attribute ("deprecated", attributes)) | 3899 if (lookup_attribute ("deprecated", attributes)) |
3176 deprecated_state = DEPRECATED_SUPPRESS; | 3900 deprecated_state = DEPRECATED_SUPPRESS; |
3177 | 3901 |
3178 decl = grokdeclarator (declarator, declspecs, | 3902 decl = grokdeclarator (declarator, declspecs, |
3179 NORMAL, initialized, NULL, &attributes, | 3903 NORMAL, initialized, NULL, &attributes, &expr, NULL, |
3180 deprecated_state); | 3904 deprecated_state); |
3181 if (!decl) | 3905 if (!decl) |
3182 return 0; | 3906 return 0; |
3907 | |
3908 if (expr) | |
3909 add_stmt (expr); | |
3183 | 3910 |
3184 if (TREE_CODE (decl) != FUNCTION_DECL && MAIN_NAME_P (DECL_NAME (decl))) | 3911 if (TREE_CODE (decl) != FUNCTION_DECL && MAIN_NAME_P (DECL_NAME (decl))) |
3185 warning (OPT_Wmain, "%q+D is usually a function", decl); | 3912 warning (OPT_Wmain, "%q+D is usually a function", decl); |
3186 | 3913 |
3187 if (initialized) | 3914 if (initialized) |
3326 && current_scope != file_scope | 4053 && current_scope != file_scope |
3327 && TREE_STATIC (decl) | 4054 && TREE_STATIC (decl) |
3328 && !TREE_READONLY (decl) | 4055 && !TREE_READONLY (decl) |
3329 && DECL_DECLARED_INLINE_P (current_function_decl) | 4056 && DECL_DECLARED_INLINE_P (current_function_decl) |
3330 && DECL_EXTERNAL (current_function_decl)) | 4057 && DECL_EXTERNAL (current_function_decl)) |
3331 pedwarn (input_location, 0, | 4058 record_inline_static (input_location, current_function_decl, |
3332 "%q+D is static but declared in inline function %qD " | 4059 decl, csi_modifiable); |
3333 "which is not static", decl, current_function_decl); | |
3334 | 4060 |
3335 /* Add this decl to the current scope. | 4061 /* Add this decl to the current scope. |
3336 TEM may equal DECL or it may be a previous decl of the same name. */ | 4062 TEM may equal DECL or it may be a previous decl of the same name. */ |
3337 tem = pushdecl (decl); | 4063 tem = pushdecl (decl); |
3338 | 4064 |
3343 } | 4069 } |
3344 | 4070 |
3345 return tem; | 4071 return tem; |
3346 } | 4072 } |
3347 | 4073 |
3348 /* Initialize EH if not initialized yet and exceptions are enabled. */ | |
3349 | |
3350 void | |
3351 c_maybe_initialize_eh (void) | |
3352 { | |
3353 if (!flag_exceptions || c_eh_initialized_p) | |
3354 return; | |
3355 | |
3356 c_eh_initialized_p = true; | |
3357 eh_personality_libfunc | |
3358 = init_one_libfunc (USING_SJLJ_EXCEPTIONS | |
3359 ? "__gcc_personality_sj0" | |
3360 : "__gcc_personality_v0"); | |
3361 default_init_unwind_resume_libfunc (); | |
3362 using_eh_for_cleanups (); | |
3363 } | |
3364 | |
3365 /* Finish processing of a declaration; | 4074 /* Finish processing of a declaration; |
3366 install its initial value. | 4075 install its initial value. |
4076 If ORIGTYPE is not NULL_TREE, it is the original type of INIT. | |
3367 If the length of an array type is not known before, | 4077 If the length of an array type is not known before, |
3368 it must be determined now, from the initial value, or it is an error. */ | 4078 it must be determined now, from the initial value, or it is an error. |
4079 | |
4080 INIT_LOC is the location of the initial value. */ | |
3369 | 4081 |
3370 void | 4082 void |
3371 finish_decl (tree decl, tree init, tree asmspec_tree) | 4083 finish_decl (tree decl, location_t init_loc, tree init, |
4084 tree origtype, tree asmspec_tree) | |
3372 { | 4085 { |
3373 tree type; | 4086 tree type; |
3374 int was_incomplete = (DECL_SIZE (decl) == 0); | 4087 bool was_incomplete = (DECL_SIZE (decl) == 0); |
3375 const char *asmspec = 0; | 4088 const char *asmspec = 0; |
3376 | 4089 |
3377 /* If a name was specified, get the string. */ | 4090 /* If a name was specified, get the string. */ |
3378 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL) | 4091 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL) |
3379 && DECL_FILE_SCOPE_P (decl)) | 4092 && DECL_FILE_SCOPE_P (decl)) |
3395 /* Don't crash if parm is initialized. */ | 4108 /* Don't crash if parm is initialized. */ |
3396 if (TREE_CODE (decl) == PARM_DECL) | 4109 if (TREE_CODE (decl) == PARM_DECL) |
3397 init = 0; | 4110 init = 0; |
3398 | 4111 |
3399 if (init) | 4112 if (init) |
3400 store_init_value (decl, init); | 4113 store_init_value (init_loc, decl, init, origtype); |
3401 | 4114 |
3402 if (c_dialect_objc () && (TREE_CODE (decl) == VAR_DECL | 4115 if (c_dialect_objc () && (TREE_CODE (decl) == VAR_DECL |
3403 || TREE_CODE (decl) == FUNCTION_DECL | 4116 || TREE_CODE (decl) == FUNCTION_DECL |
3404 || TREE_CODE (decl) == FIELD_DECL)) | 4117 || TREE_CODE (decl) == FIELD_DECL)) |
3405 objc_check_decl (decl); | 4118 objc_check_decl (decl); |
3455 struct c_binding *b_ext = I_SYMBOL_BINDING (DECL_NAME (decl)); | 4168 struct c_binding *b_ext = I_SYMBOL_BINDING (DECL_NAME (decl)); |
3456 while (b_ext && !B_IN_EXTERNAL_SCOPE (b_ext)) | 4169 while (b_ext && !B_IN_EXTERNAL_SCOPE (b_ext)) |
3457 b_ext = b_ext->shadowed; | 4170 b_ext = b_ext->shadowed; |
3458 if (b_ext) | 4171 if (b_ext) |
3459 { | 4172 { |
3460 if (b_ext->type) | 4173 if (b_ext->u.type) |
3461 b_ext->type = composite_type (b_ext->type, type); | 4174 b_ext->u.type = composite_type (b_ext->u.type, type); |
3462 else | 4175 else |
3463 b_ext->type = type; | 4176 b_ext->u.type = type; |
3464 } | 4177 } |
3465 } | 4178 } |
3466 break; | 4179 break; |
3467 | 4180 |
3468 default: | 4181 default: |
3603 bind = build3 (BIND_EXPR, void_type_node, NULL, NULL, NULL); | 4316 bind = build3 (BIND_EXPR, void_type_node, NULL, NULL, NULL); |
3604 TREE_SIDE_EFFECTS (bind) = 1; | 4317 TREE_SIDE_EFFECTS (bind) = 1; |
3605 add_stmt (bind); | 4318 add_stmt (bind); |
3606 BIND_EXPR_BODY (bind) = push_stmt_list (); | 4319 BIND_EXPR_BODY (bind) = push_stmt_list (); |
3607 } | 4320 } |
3608 add_stmt (build_stmt (DECL_EXPR, decl)); | 4321 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), |
4322 DECL_EXPR, decl)); | |
3609 } | 4323 } |
3610 } | 4324 } |
3611 | 4325 |
3612 | 4326 |
3613 if (!DECL_FILE_SCOPE_P (decl)) | 4327 if (!DECL_FILE_SCOPE_P (decl)) |
3628 | 4342 |
3629 if (TREE_CODE (decl) == TYPE_DECL) | 4343 if (TREE_CODE (decl) == TYPE_DECL) |
3630 { | 4344 { |
3631 if (!DECL_FILE_SCOPE_P (decl) | 4345 if (!DECL_FILE_SCOPE_P (decl) |
3632 && variably_modified_type_p (TREE_TYPE (decl), NULL_TREE)) | 4346 && variably_modified_type_p (TREE_TYPE (decl), NULL_TREE)) |
3633 add_stmt (build_stmt (DECL_EXPR, decl)); | 4347 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl)); |
3634 | 4348 |
3635 rest_of_decl_compilation (decl, DECL_FILE_SCOPE_P (decl), 0); | 4349 rest_of_decl_compilation (decl, DECL_FILE_SCOPE_P (decl), 0); |
3636 } | 4350 } |
3637 | 4351 |
3638 /* At the end of a declaration, throw away any variable type sizes | 4352 /* At the end of a declaration, throw away any variable type sizes |
3648 if (attr) | 4362 if (attr) |
3649 { | 4363 { |
3650 tree cleanup_id = TREE_VALUE (TREE_VALUE (attr)); | 4364 tree cleanup_id = TREE_VALUE (TREE_VALUE (attr)); |
3651 tree cleanup_decl = lookup_name (cleanup_id); | 4365 tree cleanup_decl = lookup_name (cleanup_id); |
3652 tree cleanup; | 4366 tree cleanup; |
4367 VEC(tree,gc) *vec; | |
3653 | 4368 |
3654 /* Build "cleanup(&decl)" for the destructor. */ | 4369 /* Build "cleanup(&decl)" for the destructor. */ |
3655 cleanup = build_unary_op (input_location, ADDR_EXPR, decl, 0); | 4370 cleanup = build_unary_op (input_location, ADDR_EXPR, decl, 0); |
3656 cleanup = build_tree_list (NULL_TREE, cleanup); | 4371 vec = VEC_alloc (tree, gc, 1); |
3657 cleanup = build_function_call (cleanup_decl, cleanup); | 4372 VEC_quick_push (tree, vec, cleanup); |
4373 cleanup = build_function_call_vec (DECL_SOURCE_LOCATION (decl), | |
4374 cleanup_decl, vec, NULL); | |
4375 VEC_free (tree, gc, vec); | |
3658 | 4376 |
3659 /* Don't warn about decl unused; the cleanup uses it. */ | 4377 /* Don't warn about decl unused; the cleanup uses it. */ |
3660 TREE_USED (decl) = 1; | 4378 TREE_USED (decl) = 1; |
3661 TREE_USED (cleanup_decl) = 1; | 4379 TREE_USED (cleanup_decl) = 1; |
3662 | 4380 |
3663 /* Initialize EH, if we've been told to do so. */ | |
3664 c_maybe_initialize_eh (); | |
3665 | |
3666 push_cleanup (decl, cleanup, false); | 4381 push_cleanup (decl, cleanup, false); |
3667 } | 4382 } |
3668 } | 4383 } |
4384 | |
4385 if (warn_cxx_compat | |
4386 && TREE_CODE (decl) == VAR_DECL | |
4387 && TREE_READONLY (decl) | |
4388 && !DECL_EXTERNAL (decl) | |
4389 && DECL_INITIAL (decl) == NULL_TREE) | |
4390 warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wc___compat, | |
4391 "uninitialized const %qD is invalid in C++", decl); | |
3669 } | 4392 } |
3670 | 4393 |
3671 /* Given a parsed parameter declaration, decode it into a PARM_DECL. */ | 4394 /* Given a parsed parameter declaration, decode it into a PARM_DECL. */ |
3672 | 4395 |
3673 tree | 4396 tree |
3674 grokparm (const struct c_parm *parm) | 4397 grokparm (const struct c_parm *parm) |
3675 { | 4398 { |
3676 tree attrs = parm->attrs; | 4399 tree attrs = parm->attrs; |
3677 tree decl = grokdeclarator (parm->declarator, parm->specs, PARM, false, | 4400 tree decl = grokdeclarator (parm->declarator, parm->specs, PARM, false, |
3678 NULL, &attrs, DEPRECATED_NORMAL); | 4401 NULL, &attrs, NULL, NULL, DEPRECATED_NORMAL); |
3679 | 4402 |
3680 decl_attributes (&decl, attrs, 0); | 4403 decl_attributes (&decl, attrs, 0); |
3681 | 4404 |
3682 return decl; | 4405 return decl; |
3683 } | 4406 } |
3690 { | 4413 { |
3691 tree attrs = parm->attrs; | 4414 tree attrs = parm->attrs; |
3692 tree decl; | 4415 tree decl; |
3693 | 4416 |
3694 decl = grokdeclarator (parm->declarator, parm->specs, PARM, false, NULL, | 4417 decl = grokdeclarator (parm->declarator, parm->specs, PARM, false, NULL, |
3695 &attrs, DEPRECATED_NORMAL); | 4418 &attrs, NULL, NULL, DEPRECATED_NORMAL); |
3696 decl_attributes (&decl, attrs, 0); | 4419 decl_attributes (&decl, attrs, 0); |
3697 | 4420 |
3698 decl = pushdecl (decl); | 4421 decl = pushdecl (decl); |
3699 | 4422 |
3700 finish_decl (decl, NULL_TREE, NULL_TREE); | 4423 finish_decl (decl, input_location, NULL_TREE, NULL_TREE, NULL_TREE); |
3701 } | 4424 } |
3702 | 4425 |
3703 /* Mark all the parameter declarations to date as forward decls. | 4426 /* Mark all the parameter declarations to date as forward decls. |
3704 Also diagnose use of this extension. */ | 4427 Also diagnose use of this extension. */ |
3705 | 4428 |
3720 TREE_ASM_WRITTEN (b->decl) = 1; | 4443 TREE_ASM_WRITTEN (b->decl) = 1; |
3721 } | 4444 } |
3722 | 4445 |
3723 /* Build a COMPOUND_LITERAL_EXPR. TYPE is the type given in the compound | 4446 /* Build a COMPOUND_LITERAL_EXPR. TYPE is the type given in the compound |
3724 literal, which may be an incomplete array type completed by the | 4447 literal, which may be an incomplete array type completed by the |
3725 initializer; INIT is a CONSTRUCTOR that initializes the compound | 4448 initializer; INIT is a CONSTRUCTOR at LOC that initializes the compound |
3726 literal. */ | 4449 literal. NON_CONST is true if the initializers contain something |
4450 that cannot occur in a constant expression. */ | |
3727 | 4451 |
3728 tree | 4452 tree |
3729 build_compound_literal (tree type, tree init) | 4453 build_compound_literal (location_t loc, tree type, tree init, bool non_const) |
3730 { | 4454 { |
3731 /* We do not use start_decl here because we have a type, not a declarator; | 4455 /* We do not use start_decl here because we have a type, not a declarator; |
3732 and do not use finish_decl because the decl should be stored inside | 4456 and do not use finish_decl because the decl should be stored inside |
3733 the COMPOUND_LITERAL_EXPR rather than added elsewhere as a DECL_EXPR. */ | 4457 the COMPOUND_LITERAL_EXPR rather than added elsewhere as a DECL_EXPR. */ |
3734 tree decl; | 4458 tree decl; |
3736 tree stmt; | 4460 tree stmt; |
3737 | 4461 |
3738 if (type == error_mark_node) | 4462 if (type == error_mark_node) |
3739 return error_mark_node; | 4463 return error_mark_node; |
3740 | 4464 |
3741 decl = build_decl (VAR_DECL, NULL_TREE, type); | 4465 decl = build_decl (loc, VAR_DECL, NULL_TREE, type); |
3742 DECL_EXTERNAL (decl) = 0; | 4466 DECL_EXTERNAL (decl) = 0; |
3743 TREE_PUBLIC (decl) = 0; | 4467 TREE_PUBLIC (decl) = 0; |
3744 TREE_STATIC (decl) = (current_scope == file_scope); | 4468 TREE_STATIC (decl) = (current_scope == file_scope); |
3745 DECL_CONTEXT (decl) = current_function_decl; | 4469 DECL_CONTEXT (decl) = current_function_decl; |
3746 TREE_USED (decl) = 1; | 4470 TREE_USED (decl) = 1; |
3747 TREE_TYPE (decl) = type; | 4471 TREE_TYPE (decl) = type; |
3748 TREE_READONLY (decl) = TYPE_READONLY (type); | 4472 TREE_READONLY (decl) = TYPE_READONLY (type); |
3749 store_init_value (decl, init); | 4473 store_init_value (loc, decl, init, NULL_TREE); |
3750 | 4474 |
3751 if (TREE_CODE (type) == ARRAY_TYPE && !COMPLETE_TYPE_P (type)) | 4475 if (TREE_CODE (type) == ARRAY_TYPE && !COMPLETE_TYPE_P (type)) |
3752 { | 4476 { |
3753 int failure = complete_array_type (&TREE_TYPE (decl), | 4477 int failure = complete_array_type (&TREE_TYPE (decl), |
3754 DECL_INITIAL (decl), true); | 4478 DECL_INITIAL (decl), true); |
3759 } | 4483 } |
3760 | 4484 |
3761 if (type == error_mark_node || !COMPLETE_TYPE_P (type)) | 4485 if (type == error_mark_node || !COMPLETE_TYPE_P (type)) |
3762 return error_mark_node; | 4486 return error_mark_node; |
3763 | 4487 |
3764 stmt = build_stmt (DECL_EXPR, decl); | 4488 stmt = build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl); |
3765 complit = build1 (COMPOUND_LITERAL_EXPR, type, stmt); | 4489 complit = build1 (COMPOUND_LITERAL_EXPR, type, stmt); |
3766 TREE_SIDE_EFFECTS (complit) = 1; | 4490 TREE_SIDE_EFFECTS (complit) = 1; |
3767 | 4491 |
3768 layout_decl (decl, 0); | 4492 layout_decl (decl, 0); |
3769 | 4493 |
3777 DECL_IGNORED_P (decl) = 1; | 4501 DECL_IGNORED_P (decl) = 1; |
3778 pushdecl (decl); | 4502 pushdecl (decl); |
3779 rest_of_decl_compilation (decl, 1, 0); | 4503 rest_of_decl_compilation (decl, 1, 0); |
3780 } | 4504 } |
3781 | 4505 |
4506 if (non_const) | |
4507 { | |
4508 complit = build2 (C_MAYBE_CONST_EXPR, type, NULL, complit); | |
4509 C_MAYBE_CONST_EXPR_NON_CONST (complit) = 1; | |
4510 } | |
4511 | |
3782 return complit; | 4512 return complit; |
4513 } | |
4514 | |
4515 /* Check the type of a compound literal. Here we just check that it | |
4516 is valid for C++. */ | |
4517 | |
4518 void | |
4519 check_compound_literal_type (location_t loc, struct c_type_name *type_name) | |
4520 { | |
4521 if (warn_cxx_compat && type_name->specs->tag_defined_p) | |
4522 warning_at (loc, OPT_Wc___compat, | |
4523 "defining a type in a compound literal is invalid in C++"); | |
3783 } | 4524 } |
3784 | 4525 |
3785 /* Determine whether TYPE is a structure with a flexible array member, | 4526 /* Determine whether TYPE is a structure with a flexible array member, |
3786 or a union containing such a structure (possibly recursively). */ | 4527 or a union containing such a structure (possibly recursively). */ |
3787 | 4528 |
3816 } | 4557 } |
3817 | 4558 |
3818 /* Performs sanity checks on the TYPE and WIDTH of the bit-field NAME, | 4559 /* Performs sanity checks on the TYPE and WIDTH of the bit-field NAME, |
3819 replacing with appropriate values if they are invalid. */ | 4560 replacing with appropriate values if they are invalid. */ |
3820 static void | 4561 static void |
3821 check_bitfield_type_and_width (tree *type, tree *width, const char *orig_name) | 4562 check_bitfield_type_and_width (tree *type, tree *width, tree orig_name) |
3822 { | 4563 { |
3823 tree type_mv; | 4564 tree type_mv; |
3824 unsigned int max_width; | 4565 unsigned int max_width; |
3825 unsigned HOST_WIDE_INT w; | 4566 unsigned HOST_WIDE_INT w; |
3826 const char *name = orig_name ? orig_name: _("<anonymous>"); | 4567 const char *name = (orig_name |
4568 ? identifier_to_locale (IDENTIFIER_POINTER (orig_name)) | |
4569 : _("<anonymous>")); | |
3827 | 4570 |
3828 /* Detect and ignore out of range field width and process valid | 4571 /* Detect and ignore out of range field width and process valid |
3829 field widths. */ | 4572 field widths. */ |
3830 if (!INTEGRAL_TYPE_P (TREE_TYPE (*width)) | 4573 if (!INTEGRAL_TYPE_P (TREE_TYPE (*width))) |
3831 || TREE_CODE (*width) != INTEGER_CST) | |
3832 { | 4574 { |
3833 error ("bit-field %qs width not an integer constant", name); | 4575 error ("bit-field %qs width not an integer constant", name); |
3834 *width = integer_one_node; | 4576 *width = integer_one_node; |
3835 } | 4577 } |
3836 else | 4578 else |
3837 { | 4579 { |
4580 if (TREE_CODE (*width) != INTEGER_CST) | |
4581 { | |
4582 *width = c_fully_fold (*width, false, NULL); | |
4583 if (TREE_CODE (*width) == INTEGER_CST) | |
4584 pedwarn (input_location, OPT_pedantic, | |
4585 "bit-field %qs width not an integer constant expression", | |
4586 name); | |
4587 } | |
4588 if (TREE_CODE (*width) != INTEGER_CST) | |
4589 { | |
4590 error ("bit-field %qs width not an integer constant", name); | |
4591 *width = integer_one_node; | |
4592 } | |
3838 constant_expression_warning (*width); | 4593 constant_expression_warning (*width); |
3839 if (tree_int_cst_sgn (*width) < 0) | 4594 if (tree_int_cst_sgn (*width) < 0) |
3840 { | 4595 { |
3841 error ("negative width in bit-field %qs", name); | 4596 error ("negative width in bit-field %qs", name); |
3842 *width = integer_one_node; | 4597 *width = integer_one_node; |
3889 | 4644 |
3890 | 4645 |
3891 /* Print warning about variable length array if necessary. */ | 4646 /* Print warning about variable length array if necessary. */ |
3892 | 4647 |
3893 static void | 4648 static void |
3894 warn_variable_length_array (const char *name, tree size) | 4649 warn_variable_length_array (tree name, tree size) |
3895 { | 4650 { |
3896 int const_size = TREE_CONSTANT (size); | 4651 int const_size = TREE_CONSTANT (size); |
3897 | 4652 |
3898 if (!flag_isoc99 && pedantic && warn_vla != 0) | 4653 if (!flag_isoc99 && pedantic && warn_vla != 0) |
3899 { | 4654 { |
3900 if (const_size) | 4655 if (const_size) |
3901 { | 4656 { |
3902 if (name) | 4657 if (name) |
3903 pedwarn (input_location, OPT_Wvla, "ISO C90 forbids array %qs whose size " | 4658 pedwarn (input_location, OPT_Wvla, |
4659 "ISO C90 forbids array %qE whose size " | |
3904 "can%'t be evaluated", | 4660 "can%'t be evaluated", |
3905 name); | 4661 name); |
3906 else | 4662 else |
3907 pedwarn (input_location, OPT_Wvla, "ISO C90 forbids array whose size " | 4663 pedwarn (input_location, OPT_Wvla, "ISO C90 forbids array whose size " |
3908 "can%'t be evaluated"); | 4664 "can%'t be evaluated"); |
3909 } | 4665 } |
3910 else | 4666 else |
3911 { | 4667 { |
3912 if (name) | 4668 if (name) |
3913 pedwarn (input_location, OPT_Wvla, "ISO C90 forbids variable length array %qs", | 4669 pedwarn (input_location, OPT_Wvla, |
4670 "ISO C90 forbids variable length array %qE", | |
3914 name); | 4671 name); |
3915 else | 4672 else |
3916 pedwarn (input_location, OPT_Wvla, "ISO C90 forbids variable length array"); | 4673 pedwarn (input_location, OPT_Wvla, "ISO C90 forbids variable length array"); |
3917 } | 4674 } |
3918 } | 4675 } |
3920 { | 4677 { |
3921 if (const_size) | 4678 if (const_size) |
3922 { | 4679 { |
3923 if (name) | 4680 if (name) |
3924 warning (OPT_Wvla, | 4681 warning (OPT_Wvla, |
3925 "the size of array %qs can" | 4682 "the size of array %qE can" |
3926 "%'t be evaluated", name); | 4683 "%'t be evaluated", name); |
3927 else | 4684 else |
3928 warning (OPT_Wvla, | 4685 warning (OPT_Wvla, |
3929 "the size of array can %'t be evaluated"); | 4686 "the size of array can %'t be evaluated"); |
3930 } | 4687 } |
3931 else | 4688 else |
3932 { | 4689 { |
3933 if (name) | 4690 if (name) |
3934 warning (OPT_Wvla, | 4691 warning (OPT_Wvla, |
3935 "variable length array %qs is used", | 4692 "variable length array %qE is used", |
3936 name); | 4693 name); |
3937 else | 4694 else |
3938 warning (OPT_Wvla, | 4695 warning (OPT_Wvla, |
3939 "variable length array is used"); | 4696 "variable length array is used"); |
3940 } | 4697 } |
3941 } | 4698 } |
4699 } | |
4700 | |
4701 /* Given a size SIZE that may not be a constant, return a SAVE_EXPR to | |
4702 serve as the actual size-expression for a type or decl. This is | |
4703 like variable_size in stor-layout.c, but we make global_bindings_p | |
4704 return negative to avoid calls to that function from outside the | |
4705 front end resulting in errors at file scope, then call this version | |
4706 instead from front-end code. */ | |
4707 | |
4708 static tree | |
4709 c_variable_size (tree size) | |
4710 { | |
4711 tree save; | |
4712 | |
4713 if (TREE_CONSTANT (size)) | |
4714 return size; | |
4715 | |
4716 size = save_expr (size); | |
4717 | |
4718 save = skip_simple_arithmetic (size); | |
4719 | |
4720 if (cfun && cfun->dont_save_pending_sizes_p) | |
4721 return size; | |
4722 | |
4723 if (!global_bindings_p ()) | |
4724 put_pending_size (save); | |
4725 | |
4726 return size; | |
3942 } | 4727 } |
3943 | 4728 |
3944 /* Given declspecs and a declarator, | 4729 /* Given declspecs and a declarator, |
3945 determine the name and type of the object declared | 4730 determine the name and type of the object declared |
3946 and construct a ..._DECL node for it. | 4731 and construct a ..._DECL node for it. |
3963 WIDTH is non-NULL for bit-fields, and is a pointer to an INTEGER_CST node | 4748 WIDTH is non-NULL for bit-fields, and is a pointer to an INTEGER_CST node |
3964 representing the width of the bit-field. | 4749 representing the width of the bit-field. |
3965 DECL_ATTRS points to the list of attributes that should be added to this | 4750 DECL_ATTRS points to the list of attributes that should be added to this |
3966 decl. Any nested attributes that belong on the decl itself will be | 4751 decl. Any nested attributes that belong on the decl itself will be |
3967 added to this list. | 4752 added to this list. |
4753 If EXPR is not NULL, any expressions that need to be evaluated as | |
4754 part of evaluating variably modified types will be stored in *EXPR. | |
4755 If EXPR_CONST_OPERANDS is not NULL, *EXPR_CONST_OPERANDS will be | |
4756 set to indicate whether operands in *EXPR can be used in constant | |
4757 expressions. | |
3968 DEPRECATED_STATE is a deprecated_states value indicating whether | 4758 DEPRECATED_STATE is a deprecated_states value indicating whether |
3969 deprecation warnings should be suppressed. | 4759 deprecation warnings should be suppressed. |
3970 | 4760 |
3971 In the TYPENAME case, DECLARATOR is really an absolute declarator. | 4761 In the TYPENAME case, DECLARATOR is really an absolute declarator. |
3972 It may also be so in the PARM case, for a prototype where the | 4762 It may also be so in the PARM case, for a prototype where the |
3977 | 4767 |
3978 static tree | 4768 static tree |
3979 grokdeclarator (const struct c_declarator *declarator, | 4769 grokdeclarator (const struct c_declarator *declarator, |
3980 struct c_declspecs *declspecs, | 4770 struct c_declspecs *declspecs, |
3981 enum decl_context decl_context, bool initialized, tree *width, | 4771 enum decl_context decl_context, bool initialized, tree *width, |
3982 tree *decl_attrs, enum deprecated_states deprecated_state) | 4772 tree *decl_attrs, tree *expr, bool *expr_const_operands, |
4773 enum deprecated_states deprecated_state) | |
3983 { | 4774 { |
3984 tree type = declspecs->type; | 4775 tree type = declspecs->type; |
3985 bool threadp = declspecs->thread_p; | 4776 bool threadp = declspecs->thread_p; |
3986 enum c_storage_class storage_class = declspecs->storage_class; | 4777 enum c_storage_class storage_class = declspecs->storage_class; |
3987 int constp; | 4778 int constp; |
3988 int restrictp; | 4779 int restrictp; |
3989 int volatilep; | 4780 int volatilep; |
3990 int type_quals = TYPE_UNQUALIFIED; | 4781 int type_quals = TYPE_UNQUALIFIED; |
3991 const char *name, *orig_name; | 4782 tree name = NULL_TREE; |
3992 bool funcdef_flag = false; | 4783 bool funcdef_flag = false; |
3993 bool funcdef_syntax = false; | 4784 bool funcdef_syntax = false; |
3994 int size_varies = 0; | 4785 bool size_varies = false; |
3995 tree decl_attr = declspecs->decl_attr; | 4786 tree decl_attr = declspecs->decl_attr; |
3996 int array_ptr_quals = TYPE_UNQUALIFIED; | 4787 int array_ptr_quals = TYPE_UNQUALIFIED; |
3997 tree array_ptr_attrs = NULL_TREE; | 4788 tree array_ptr_attrs = NULL_TREE; |
3998 int array_parm_static = 0; | 4789 int array_parm_static = 0; |
3999 bool array_parm_vla_unspec_p = false; | 4790 bool array_parm_vla_unspec_p = false; |
4000 tree returned_attrs = NULL_TREE; | 4791 tree returned_attrs = NULL_TREE; |
4001 bool bitfield = width != NULL; | 4792 bool bitfield = width != NULL; |
4002 tree element_type; | 4793 tree element_type; |
4003 struct c_arg_info *arg_info = 0; | 4794 struct c_arg_info *arg_info = 0; |
4795 addr_space_t as1, as2, address_space; | |
4796 location_t loc = UNKNOWN_LOCATION; | |
4797 const char *errmsg; | |
4798 tree expr_dummy; | |
4799 bool expr_const_operands_dummy; | |
4800 | |
4801 if (expr == NULL) | |
4802 expr = &expr_dummy; | |
4803 if (expr_const_operands == NULL) | |
4804 expr_const_operands = &expr_const_operands_dummy; | |
4805 | |
4806 *expr = declspecs->expr; | |
4807 *expr_const_operands = declspecs->expr_const_operands; | |
4004 | 4808 |
4005 if (decl_context == FUNCDEF) | 4809 if (decl_context == FUNCDEF) |
4006 funcdef_flag = true, decl_context = NORMAL; | 4810 funcdef_flag = true, decl_context = NORMAL; |
4007 | 4811 |
4008 /* Look inside a declarator for the name being declared | 4812 /* Look inside a declarator for the name being declared |
4009 and get it as a string, for an error message. */ | 4813 and get it as an IDENTIFIER_NODE, for an error message. */ |
4010 { | 4814 { |
4011 const struct c_declarator *decl = declarator; | 4815 const struct c_declarator *decl = declarator; |
4012 name = 0; | |
4013 | 4816 |
4014 while (decl) | 4817 while (decl) |
4015 switch (decl->kind) | 4818 switch (decl->kind) |
4016 { | 4819 { |
4820 case cdk_array: | |
4821 loc = decl->id_loc; | |
4822 /* FALL THRU. */ | |
4823 | |
4017 case cdk_function: | 4824 case cdk_function: |
4018 case cdk_array: | |
4019 case cdk_pointer: | 4825 case cdk_pointer: |
4020 funcdef_syntax = (decl->kind == cdk_function); | 4826 funcdef_syntax = (decl->kind == cdk_function); |
4021 decl = decl->declarator; | 4827 decl = decl->declarator; |
4022 break; | 4828 break; |
4023 | 4829 |
4024 case cdk_attrs: | 4830 case cdk_attrs: |
4025 decl = decl->declarator; | 4831 decl = decl->declarator; |
4026 break; | 4832 break; |
4027 | 4833 |
4028 case cdk_id: | 4834 case cdk_id: |
4835 loc = decl->id_loc; | |
4029 if (decl->u.id) | 4836 if (decl->u.id) |
4030 name = IDENTIFIER_POINTER (decl->u.id); | 4837 name = decl->u.id; |
4031 decl = 0; | 4838 decl = 0; |
4032 break; | 4839 break; |
4033 | 4840 |
4034 default: | 4841 default: |
4035 gcc_unreachable (); | 4842 gcc_unreachable (); |
4036 } | 4843 } |
4037 orig_name = name; | |
4038 if (name == 0) | 4844 if (name == 0) |
4039 name = "type name"; | 4845 { |
4846 gcc_assert (decl_context == PARM | |
4847 || decl_context == TYPENAME | |
4848 || (decl_context == FIELD | |
4849 && declarator->kind == cdk_id)); | |
4850 gcc_assert (!initialized); | |
4851 } | |
4040 } | 4852 } |
4041 | 4853 |
4042 /* A function definition's declarator must have the form of | 4854 /* A function definition's declarator must have the form of |
4043 a function declarator. */ | 4855 a function declarator. */ |
4044 | 4856 |
4050 Then store_parm_decls will reject it and not use it as a parm. */ | 4862 Then store_parm_decls will reject it and not use it as a parm. */ |
4051 if (decl_context == NORMAL && !funcdef_flag && current_scope->parm_flag) | 4863 if (decl_context == NORMAL && !funcdef_flag && current_scope->parm_flag) |
4052 decl_context = PARM; | 4864 decl_context = PARM; |
4053 | 4865 |
4054 if (declspecs->deprecated_p && deprecated_state != DEPRECATED_SUPPRESS) | 4866 if (declspecs->deprecated_p && deprecated_state != DEPRECATED_SUPPRESS) |
4055 warn_deprecated_use (declspecs->type); | 4867 warn_deprecated_use (declspecs->type, declspecs->decl_attr); |
4056 | 4868 |
4057 if ((decl_context == NORMAL || decl_context == FIELD) | 4869 if ((decl_context == NORMAL || decl_context == FIELD) |
4058 && current_scope == file_scope | 4870 && current_scope == file_scope |
4059 && variably_modified_type_p (type, NULL_TREE)) | 4871 && variably_modified_type_p (type, NULL_TREE)) |
4060 { | 4872 { |
4061 error ("variably modified %qs at file scope", name); | 4873 if (name) |
4874 error_at (loc, "variably modified %qE at file scope", name); | |
4875 else | |
4876 error_at (loc, "variably modified field at file scope"); | |
4062 type = integer_type_node; | 4877 type = integer_type_node; |
4063 } | 4878 } |
4064 | 4879 |
4065 size_varies = C_TYPE_VARIABLE_SIZE (type); | 4880 size_varies = C_TYPE_VARIABLE_SIZE (type) != 0; |
4066 | 4881 |
4067 /* Diagnose defaulting to "int". */ | 4882 /* Diagnose defaulting to "int". */ |
4068 | 4883 |
4069 if (declspecs->default_int_p && !in_system_header) | 4884 if (declspecs->default_int_p && !in_system_header) |
4070 { | 4885 { |
4072 -Wreturn-type and this is a function, or if -Wimplicit; | 4887 -Wreturn-type and this is a function, or if -Wimplicit; |
4073 prefer the former warning since it is more explicit. */ | 4888 prefer the former warning since it is more explicit. */ |
4074 if ((warn_implicit_int || warn_return_type || flag_isoc99) | 4889 if ((warn_implicit_int || warn_return_type || flag_isoc99) |
4075 && funcdef_flag) | 4890 && funcdef_flag) |
4076 warn_about_return_type = 1; | 4891 warn_about_return_type = 1; |
4077 else | 4892 else |
4078 pedwarn_c99 (input_location, flag_isoc99 ? 0 : OPT_Wimplicit_int, | 4893 { |
4079 "type defaults to %<int%> in declaration of %qs", name); | 4894 if (name) |
4895 pedwarn_c99 (loc, flag_isoc99 ? 0 : OPT_Wimplicit_int, | |
4896 "type defaults to %<int%> in declaration of %qE", | |
4897 name); | |
4898 else | |
4899 pedwarn_c99 (input_location, flag_isoc99 ? 0 : OPT_Wimplicit_int, | |
4900 "type defaults to %<int%> in type name"); | |
4901 } | |
4080 } | 4902 } |
4081 | 4903 |
4082 /* Adjust the type if a bit-field is being declared, | 4904 /* Adjust the type if a bit-field is being declared, |
4083 -funsigned-bitfields applied and the type is not explicitly | 4905 -funsigned-bitfields applied and the type is not explicitly |
4084 "signed". */ | 4906 "signed". */ |
4099 seems most appropriate to do so). */ | 4921 seems most appropriate to do so). */ |
4100 element_type = strip_array_types (type); | 4922 element_type = strip_array_types (type); |
4101 constp = declspecs->const_p + TYPE_READONLY (element_type); | 4923 constp = declspecs->const_p + TYPE_READONLY (element_type); |
4102 restrictp = declspecs->restrict_p + TYPE_RESTRICT (element_type); | 4924 restrictp = declspecs->restrict_p + TYPE_RESTRICT (element_type); |
4103 volatilep = declspecs->volatile_p + TYPE_VOLATILE (element_type); | 4925 volatilep = declspecs->volatile_p + TYPE_VOLATILE (element_type); |
4926 as1 = declspecs->address_space; | |
4927 as2 = TYPE_ADDR_SPACE (element_type); | |
4928 address_space = ADDR_SPACE_GENERIC_P (as1)? as2 : as1; | |
4929 | |
4104 if (pedantic && !flag_isoc99) | 4930 if (pedantic && !flag_isoc99) |
4105 { | 4931 { |
4106 if (constp > 1) | 4932 if (constp > 1) |
4107 pedwarn (input_location, OPT_pedantic, "duplicate %<const%>"); | 4933 pedwarn (loc, OPT_pedantic, "duplicate %<const%>"); |
4108 if (restrictp > 1) | 4934 if (restrictp > 1) |
4109 pedwarn (input_location, OPT_pedantic, "duplicate %<restrict%>"); | 4935 pedwarn (loc, OPT_pedantic, "duplicate %<restrict%>"); |
4110 if (volatilep > 1) | 4936 if (volatilep > 1) |
4111 pedwarn (input_location, OPT_pedantic, "duplicate %<volatile%>"); | 4937 pedwarn (loc, OPT_pedantic, "duplicate %<volatile%>"); |
4112 } | 4938 } |
4939 | |
4940 if (!ADDR_SPACE_GENERIC_P (as1) && !ADDR_SPACE_GENERIC_P (as2) && as1 != as2) | |
4941 error_at (loc, "conflicting named address spaces (%s vs %s)", | |
4942 c_addr_space_name (as1), c_addr_space_name (as2)); | |
4943 | |
4113 if (!flag_gen_aux_info && (TYPE_QUALS (element_type))) | 4944 if (!flag_gen_aux_info && (TYPE_QUALS (element_type))) |
4114 type = TYPE_MAIN_VARIANT (type); | 4945 type = TYPE_MAIN_VARIANT (type); |
4115 type_quals = ((constp ? TYPE_QUAL_CONST : 0) | 4946 type_quals = ((constp ? TYPE_QUAL_CONST : 0) |
4116 | (restrictp ? TYPE_QUAL_RESTRICT : 0) | 4947 | (restrictp ? TYPE_QUAL_RESTRICT : 0) |
4117 | (volatilep ? TYPE_QUAL_VOLATILE : 0)); | 4948 | (volatilep ? TYPE_QUAL_VOLATILE : 0) |
4949 | ENCODE_QUAL_ADDR_SPACE (address_space)); | |
4118 | 4950 |
4119 /* Warn about storage classes that are invalid for certain | 4951 /* Warn about storage classes that are invalid for certain |
4120 kinds of declarations (parameters, typenames, etc.). */ | 4952 kinds of declarations (parameters, typenames, etc.). */ |
4121 | 4953 |
4122 if (funcdef_flag | 4954 if (funcdef_flag |
4124 || storage_class == csc_auto | 4956 || storage_class == csc_auto |
4125 || storage_class == csc_register | 4957 || storage_class == csc_register |
4126 || storage_class == csc_typedef)) | 4958 || storage_class == csc_typedef)) |
4127 { | 4959 { |
4128 if (storage_class == csc_auto) | 4960 if (storage_class == csc_auto) |
4129 pedwarn (input_location, | 4961 pedwarn (loc, |
4130 (current_scope == file_scope) ? 0 : OPT_pedantic, | 4962 (current_scope == file_scope) ? 0 : OPT_pedantic, |
4131 "function definition declared %<auto%>"); | 4963 "function definition declared %<auto%>"); |
4132 if (storage_class == csc_register) | 4964 if (storage_class == csc_register) |
4133 error ("function definition declared %<register%>"); | 4965 error_at (loc, "function definition declared %<register%>"); |
4134 if (storage_class == csc_typedef) | 4966 if (storage_class == csc_typedef) |
4135 error ("function definition declared %<typedef%>"); | 4967 error_at (loc, "function definition declared %<typedef%>"); |
4136 if (threadp) | 4968 if (threadp) |
4137 error ("function definition declared %<__thread%>"); | 4969 error_at (loc, "function definition declared %<__thread%>"); |
4138 threadp = false; | 4970 threadp = false; |
4139 if (storage_class == csc_auto | 4971 if (storage_class == csc_auto |
4140 || storage_class == csc_register | 4972 || storage_class == csc_register |
4141 || storage_class == csc_typedef) | 4973 || storage_class == csc_typedef) |
4142 storage_class = csc_none; | 4974 storage_class = csc_none; |
4148 else | 4980 else |
4149 { | 4981 { |
4150 switch (decl_context) | 4982 switch (decl_context) |
4151 { | 4983 { |
4152 case FIELD: | 4984 case FIELD: |
4153 error ("storage class specified for structure field %qs", | 4985 if (name) |
4154 name); | 4986 error_at (loc, "storage class specified for structure " |
4987 "field %qE", name); | |
4988 else | |
4989 error_at (loc, "storage class specified for structure field"); | |
4155 break; | 4990 break; |
4156 case PARM: | 4991 case PARM: |
4157 error ("storage class specified for parameter %qs", name); | 4992 if (name) |
4993 error_at (loc, "storage class specified for parameter %qE", | |
4994 name); | |
4995 else | |
4996 error_at (loc, "storage class specified for unnamed parameter"); | |
4158 break; | 4997 break; |
4159 default: | 4998 default: |
4160 error ("storage class specified for typename"); | 4999 error_at (loc, "storage class specified for typename"); |
4161 break; | 5000 break; |
4162 } | 5001 } |
4163 storage_class = csc_none; | 5002 storage_class = csc_none; |
4164 threadp = false; | 5003 threadp = false; |
4165 } | 5004 } |
4172 if (current_scope == file_scope) | 5011 if (current_scope == file_scope) |
4173 { | 5012 { |
4174 /* It is fine to have 'extern const' when compiling at C | 5013 /* It is fine to have 'extern const' when compiling at C |
4175 and C++ intersection. */ | 5014 and C++ intersection. */ |
4176 if (!(warn_cxx_compat && constp)) | 5015 if (!(warn_cxx_compat && constp)) |
4177 warning (0, "%qs initialized and declared %<extern%>", name); | 5016 warning_at (loc, 0, "%qE initialized and declared %<extern%>", |
5017 name); | |
4178 } | 5018 } |
4179 else | 5019 else |
4180 error ("%qs has both %<extern%> and initializer", name); | 5020 error_at (loc, "%qE has both %<extern%> and initializer", name); |
4181 } | 5021 } |
4182 else if (current_scope == file_scope) | 5022 else if (current_scope == file_scope) |
4183 { | 5023 { |
4184 if (storage_class == csc_auto) | 5024 if (storage_class == csc_auto) |
4185 error ("file-scope declaration of %qs specifies %<auto%>", name); | 5025 error_at (loc, "file-scope declaration of %qE specifies %<auto%>", |
5026 name); | |
4186 if (pedantic && storage_class == csc_register) | 5027 if (pedantic && storage_class == csc_register) |
4187 pedwarn (input_location, OPT_pedantic, | 5028 pedwarn (input_location, OPT_pedantic, |
4188 "file-scope declaration of %qs specifies %<register%>", name); | 5029 "file-scope declaration of %qE specifies %<register%>", name); |
4189 } | 5030 } |
4190 else | 5031 else |
4191 { | 5032 { |
4192 if (storage_class == csc_extern && funcdef_flag) | 5033 if (storage_class == csc_extern && funcdef_flag) |
4193 error ("nested function %qs declared %<extern%>", name); | 5034 error_at (loc, "nested function %qE declared %<extern%>", name); |
4194 else if (threadp && storage_class == csc_none) | 5035 else if (threadp && storage_class == csc_none) |
4195 { | 5036 { |
4196 error ("function-scope %qs implicitly auto and declared " | 5037 error_at (loc, "function-scope %qE implicitly auto and declared " |
4197 "%<__thread%>", | 5038 "%<__thread%>", |
4198 name); | 5039 name); |
4199 threadp = false; | 5040 threadp = false; |
4200 } | 5041 } |
4201 } | 5042 } |
4202 | 5043 |
4203 /* Now figure out the structure of the declarator proper. | 5044 /* Now figure out the structure of the declarator proper. |
4238 || array_parm_static) | 5079 || array_parm_static) |
4239 { | 5080 { |
4240 /* Only the innermost declarator (making a parameter be of | 5081 /* Only the innermost declarator (making a parameter be of |
4241 array type which is converted to pointer type) | 5082 array type which is converted to pointer type) |
4242 may have static or type qualifiers. */ | 5083 may have static or type qualifiers. */ |
4243 error ("static or type qualifiers in non-parameter array declarator"); | 5084 error_at (loc, "static or type qualifiers in non-parameter array declarator"); |
4244 array_ptr_quals = TYPE_UNQUALIFIED; | 5085 array_ptr_quals = TYPE_UNQUALIFIED; |
4245 array_ptr_attrs = NULL_TREE; | 5086 array_ptr_attrs = NULL_TREE; |
4246 array_parm_static = 0; | 5087 array_parm_static = 0; |
4247 } | 5088 } |
4248 | 5089 |
4285 | 5126 |
4286 /* Check for some types that there cannot be arrays of. */ | 5127 /* Check for some types that there cannot be arrays of. */ |
4287 | 5128 |
4288 if (VOID_TYPE_P (type)) | 5129 if (VOID_TYPE_P (type)) |
4289 { | 5130 { |
4290 error ("declaration of %qs as array of voids", name); | 5131 if (name) |
5132 error_at (loc, "declaration of %qE as array of voids", name); | |
5133 else | |
5134 error_at (loc, "declaration of type name as array of voids"); | |
4291 type = error_mark_node; | 5135 type = error_mark_node; |
4292 } | 5136 } |
4293 | 5137 |
4294 if (TREE_CODE (type) == FUNCTION_TYPE) | 5138 if (TREE_CODE (type) == FUNCTION_TYPE) |
4295 { | 5139 { |
4296 error ("declaration of %qs as array of functions", name); | 5140 if (name) |
5141 error_at (loc, "declaration of %qE as array of functions", | |
5142 name); | |
5143 else | |
5144 error_at (loc, "declaration of type name as array of " | |
5145 "functions"); | |
4297 type = error_mark_node; | 5146 type = error_mark_node; |
4298 } | 5147 } |
4299 | 5148 |
4300 if (pedantic && !in_system_header && flexible_array_type_p (type)) | 5149 if (pedantic && !in_system_header && flexible_array_type_p (type)) |
4301 pedwarn (input_location, OPT_pedantic, | 5150 pedwarn (loc, OPT_pedantic, |
4302 "invalid use of structure with flexible array member"); | 5151 "invalid use of structure with flexible array member"); |
4303 | 5152 |
4304 if (size == error_mark_node) | 5153 if (size == error_mark_node) |
4305 type = error_mark_node; | 5154 type = error_mark_node; |
4306 | 5155 |
4311 that size. Otherwise, ITYPE remains null. finish_decl | 5160 that size. Otherwise, ITYPE remains null. finish_decl |
4312 may figure it out from an initial value. */ | 5161 may figure it out from an initial value. */ |
4313 | 5162 |
4314 if (size) | 5163 if (size) |
4315 { | 5164 { |
5165 bool size_maybe_const = true; | |
5166 bool size_int_const = (TREE_CODE (size) == INTEGER_CST | |
5167 && !TREE_OVERFLOW (size)); | |
5168 bool this_size_varies = false; | |
5169 | |
4316 /* Strip NON_LVALUE_EXPRs since we aren't using as an | 5170 /* Strip NON_LVALUE_EXPRs since we aren't using as an |
4317 lvalue. */ | 5171 lvalue. */ |
4318 STRIP_TYPE_NOPS (size); | 5172 STRIP_TYPE_NOPS (size); |
4319 | 5173 |
4320 if (!INTEGRAL_TYPE_P (TREE_TYPE (size))) | 5174 if (!INTEGRAL_TYPE_P (TREE_TYPE (size))) |
4321 { | 5175 { |
4322 error ("size of array %qs has non-integer type", name); | 5176 if (name) |
5177 error_at (loc, "size of array %qE has non-integer type", | |
5178 name); | |
5179 else | |
5180 error_at (loc, | |
5181 "size of unnamed array has non-integer type"); | |
4323 size = integer_one_node; | 5182 size = integer_one_node; |
4324 } | 5183 } |
4325 | 5184 |
4326 if (pedantic && integer_zerop (size)) | 5185 size = c_fully_fold (size, false, &size_maybe_const); |
4327 pedwarn (input_location, OPT_pedantic, | 5186 |
4328 "ISO C forbids zero-size array %qs", name); | 5187 if (pedantic && size_maybe_const && integer_zerop (size)) |
4329 | 5188 { |
4330 if (TREE_CODE (size) == INTEGER_CST) | 5189 if (name) |
5190 pedwarn (loc, OPT_pedantic, | |
5191 "ISO C forbids zero-size array %qE", name); | |
5192 else | |
5193 pedwarn (loc, OPT_pedantic, | |
5194 "ISO C forbids zero-size array"); | |
5195 } | |
5196 | |
5197 if (TREE_CODE (size) == INTEGER_CST && size_maybe_const) | |
4331 { | 5198 { |
4332 constant_expression_warning (size); | 5199 constant_expression_warning (size); |
4333 if (tree_int_cst_sgn (size) < 0) | 5200 if (tree_int_cst_sgn (size) < 0) |
4334 { | 5201 { |
4335 error ("size of array %qs is negative", name); | 5202 if (name) |
5203 error_at (loc, "size of array %qE is negative", name); | |
5204 else | |
5205 error_at (loc, "size of unnamed array is negative"); | |
4336 size = integer_one_node; | 5206 size = integer_one_node; |
5207 } | |
5208 /* Handle a size folded to an integer constant but | |
5209 not an integer constant expression. */ | |
5210 if (!size_int_const) | |
5211 { | |
5212 /* If this is a file scope declaration of an | |
5213 ordinary identifier, this is invalid code; | |
5214 diagnosing it here and not subsequently | |
5215 treating the type as variable-length avoids | |
5216 more confusing diagnostics later. */ | |
5217 if ((decl_context == NORMAL || decl_context == FIELD) | |
5218 && current_scope == file_scope) | |
5219 pedwarn (input_location, 0, | |
5220 "variably modified %qE at file scope", | |
5221 name); | |
5222 else | |
5223 this_size_varies = size_varies = true; | |
5224 warn_variable_length_array (name, size); | |
4337 } | 5225 } |
4338 } | 5226 } |
4339 else if ((decl_context == NORMAL || decl_context == FIELD) | 5227 else if ((decl_context == NORMAL || decl_context == FIELD) |
4340 && current_scope == file_scope) | 5228 && current_scope == file_scope) |
4341 { | 5229 { |
4342 error ("variably modified %qs at file scope", name); | 5230 error_at (loc, "variably modified %qE at file scope", name); |
4343 size = integer_one_node; | 5231 size = integer_one_node; |
4344 } | 5232 } |
4345 else | 5233 else |
4346 { | 5234 { |
4347 /* Make sure the array size remains visibly | 5235 /* Make sure the array size remains visibly |
4348 nonconstant even if it is (eg) a const variable | 5236 nonconstant even if it is (eg) a const variable |
4349 with known value. */ | 5237 with known value. */ |
4350 size_varies = 1; | 5238 this_size_varies = size_varies = true; |
4351 warn_variable_length_array (orig_name, size); | 5239 warn_variable_length_array (name, size); |
4352 } | 5240 } |
4353 | 5241 |
4354 if (integer_zerop (size)) | 5242 if (integer_zerop (size) && !this_size_varies) |
4355 { | 5243 { |
4356 /* A zero-length array cannot be represented with | 5244 /* A zero-length array cannot be represented with |
4357 an unsigned index type, which is what we'll | 5245 an unsigned index type, which is what we'll |
4358 get with build_index_type. Create an | 5246 get with build_index_type. Create an |
4359 open-ended range instead. */ | 5247 open-ended range instead. */ |
4363 { | 5251 { |
4364 /* Arrange for the SAVE_EXPR on the inside of the | 5252 /* Arrange for the SAVE_EXPR on the inside of the |
4365 MINUS_EXPR, which allows the -1 to get folded | 5253 MINUS_EXPR, which allows the -1 to get folded |
4366 with the +1 that happens when building TYPE_SIZE. */ | 5254 with the +1 that happens when building TYPE_SIZE. */ |
4367 if (size_varies) | 5255 if (size_varies) |
4368 size = variable_size (size); | 5256 size = c_variable_size (size); |
5257 if (this_size_varies && TREE_CODE (size) == INTEGER_CST) | |
5258 size = build2 (COMPOUND_EXPR, TREE_TYPE (size), | |
5259 integer_zero_node, size); | |
4369 | 5260 |
4370 /* Compute the maximum valid index, that is, size | 5261 /* Compute the maximum valid index, that is, size |
4371 - 1. Do the calculation in index_type, so that | 5262 - 1. Do the calculation in index_type, so that |
4372 if it is a variable the computations will be | 5263 if it is a variable the computations will be |
4373 done in the proper mode. */ | 5264 done in the proper mode. */ |
4374 itype = fold_build2 (MINUS_EXPR, index_type, | 5265 itype = fold_build2_loc (loc, MINUS_EXPR, index_type, |
4375 convert (index_type, size), | 5266 convert (index_type, size), |
4376 convert (index_type, | 5267 convert (index_type, |
4377 size_one_node)); | 5268 size_one_node)); |
4378 | 5269 |
4379 /* If that overflowed, the array is too big. ??? | 5270 /* If that overflowed, the array is too big. ??? |
4380 While a size of INT_MAX+1 technically shouldn't | 5271 While a size of INT_MAX+1 technically shouldn't |
4381 cause an overflow (because we subtract 1), the | 5272 cause an overflow (because we subtract 1), the |
4382 overflow is recorded during the conversion to | 5273 overflow is recorded during the conversion to |
4384 this case seems like an unnecessary | 5275 this case seems like an unnecessary |
4385 complication. */ | 5276 complication. */ |
4386 if (TREE_CODE (itype) == INTEGER_CST | 5277 if (TREE_CODE (itype) == INTEGER_CST |
4387 && TREE_OVERFLOW (itype)) | 5278 && TREE_OVERFLOW (itype)) |
4388 { | 5279 { |
4389 error ("size of array %qs is too large", name); | 5280 if (name) |
5281 error_at (loc, "size of array %qE is too large", | |
5282 name); | |
5283 else | |
5284 error_at (loc, "size of unnamed array is too large"); | |
4390 type = error_mark_node; | 5285 type = error_mark_node; |
4391 continue; | 5286 continue; |
4392 } | 5287 } |
4393 | 5288 |
4394 itype = build_index_type (itype); | 5289 itype = build_index_type (itype); |
5290 } | |
5291 if (this_size_varies) | |
5292 { | |
5293 if (*expr) | |
5294 *expr = build2 (COMPOUND_EXPR, TREE_TYPE (size), | |
5295 *expr, size); | |
5296 else | |
5297 *expr = size; | |
5298 *expr_const_operands &= size_maybe_const; | |
4395 } | 5299 } |
4396 } | 5300 } |
4397 else if (decl_context == FIELD) | 5301 else if (decl_context == FIELD) |
4398 { | 5302 { |
4399 bool flexible_array_member = false; | 5303 bool flexible_array_member = false; |
4401 /* Field names can in fact have function prototype | 5305 /* Field names can in fact have function prototype |
4402 scope so [*] is disallowed here through making | 5306 scope so [*] is disallowed here through making |
4403 the field variably modified, not through being | 5307 the field variably modified, not through being |
4404 something other than a declaration with function | 5308 something other than a declaration with function |
4405 prototype scope. */ | 5309 prototype scope. */ |
4406 size_varies = 1; | 5310 size_varies = true; |
4407 else | 5311 else |
4408 { | 5312 { |
4409 const struct c_declarator *t = declarator; | 5313 const struct c_declarator *t = declarator; |
4410 while (t->kind == cdk_attrs) | 5314 while (t->kind == cdk_attrs) |
4411 t = t->declarator; | 5315 t = t->declarator; |
4412 flexible_array_member = (t->kind == cdk_id); | 5316 flexible_array_member = (t->kind == cdk_id); |
4413 } | 5317 } |
4414 if (flexible_array_member | 5318 if (flexible_array_member |
4415 && pedantic && !flag_isoc99 && !in_system_header) | 5319 && pedantic && !flag_isoc99 && !in_system_header) |
4416 pedwarn (input_location, OPT_pedantic, | 5320 pedwarn (loc, OPT_pedantic, |
4417 "ISO C90 does not support flexible array members"); | 5321 "ISO C90 does not support flexible array members"); |
4418 | 5322 |
4419 /* ISO C99 Flexible array members are effectively | 5323 /* ISO C99 Flexible array members are effectively |
4420 identical to GCC's zero-length array extension. */ | 5324 identical to GCC's zero-length array extension. */ |
4421 if (flexible_array_member || array_parm_vla_unspec_p) | 5325 if (flexible_array_member || array_parm_vla_unspec_p) |
4425 else if (decl_context == PARM) | 5329 else if (decl_context == PARM) |
4426 { | 5330 { |
4427 if (array_parm_vla_unspec_p) | 5331 if (array_parm_vla_unspec_p) |
4428 { | 5332 { |
4429 itype = build_range_type (sizetype, size_zero_node, NULL_TREE); | 5333 itype = build_range_type (sizetype, size_zero_node, NULL_TREE); |
4430 size_varies = 1; | 5334 size_varies = true; |
4431 } | 5335 } |
4432 } | 5336 } |
4433 else if (decl_context == TYPENAME) | 5337 else if (decl_context == TYPENAME) |
4434 { | 5338 { |
4435 if (array_parm_vla_unspec_p) | 5339 if (array_parm_vla_unspec_p) |
4439 /* We use this to avoid messing up with incomplete | 5343 /* We use this to avoid messing up with incomplete |
4440 array types of the same type, that would | 5344 array types of the same type, that would |
4441 otherwise be modified below. */ | 5345 otherwise be modified below. */ |
4442 itype = build_range_type (sizetype, size_zero_node, | 5346 itype = build_range_type (sizetype, size_zero_node, |
4443 NULL_TREE); | 5347 NULL_TREE); |
4444 size_varies = 1; | 5348 size_varies = true; |
4445 } | 5349 } |
4446 } | 5350 } |
4447 | 5351 |
4448 /* Complain about arrays of incomplete types. */ | 5352 /* Complain about arrays of incomplete types. */ |
4449 if (!COMPLETE_TYPE_P (type)) | 5353 if (!COMPLETE_TYPE_P (type)) |
4450 { | 5354 { |
4451 error ("array type has incomplete element type"); | 5355 error_at (loc, "array type has incomplete element type"); |
4452 type = error_mark_node; | 5356 type = error_mark_node; |
4453 } | 5357 } |
4454 else | 5358 else |
4455 /* When itype is NULL, a shared incomplete array type is | 5359 /* When itype is NULL, a shared incomplete array type is |
4456 returned for all array of a given type. Elsewhere we | 5360 returned for all array of a given type. Elsewhere we |
4457 make sure we don't complete that type before copying | 5361 make sure we don't complete that type before copying |
4458 it, but here we want to make sure we don't ever | 5362 it, but here we want to make sure we don't ever |
4459 modify the shared type, so we gcc_assert (itype) | 5363 modify the shared type, so we gcc_assert (itype) |
4460 below. */ | 5364 below. */ |
4461 type = build_array_type (type, itype); | 5365 { |
5366 addr_space_t as = DECODE_QUAL_ADDR_SPACE (type_quals); | |
5367 if (!ADDR_SPACE_GENERIC_P (as) && as != TYPE_ADDR_SPACE (type)) | |
5368 type = build_qualified_type (type, | |
5369 ENCODE_QUAL_ADDR_SPACE (as)); | |
5370 | |
5371 type = build_array_type (type, itype); | |
5372 } | |
4462 | 5373 |
4463 if (type != error_mark_node) | 5374 if (type != error_mark_node) |
4464 { | 5375 { |
4465 if (size_varies) | 5376 if (size_varies) |
4466 { | 5377 { |
4496 if (decl_context != PARM | 5407 if (decl_context != PARM |
4497 && (array_ptr_quals != TYPE_UNQUALIFIED | 5408 && (array_ptr_quals != TYPE_UNQUALIFIED |
4498 || array_ptr_attrs != NULL_TREE | 5409 || array_ptr_attrs != NULL_TREE |
4499 || array_parm_static)) | 5410 || array_parm_static)) |
4500 { | 5411 { |
4501 error ("static or type qualifiers in non-parameter array declarator"); | 5412 error_at (loc, "static or type qualifiers in non-parameter array declarator"); |
4502 array_ptr_quals = TYPE_UNQUALIFIED; | 5413 array_ptr_quals = TYPE_UNQUALIFIED; |
4503 array_ptr_attrs = NULL_TREE; | 5414 array_ptr_attrs = NULL_TREE; |
4504 array_parm_static = 0; | 5415 array_parm_static = 0; |
4505 } | 5416 } |
4506 break; | 5417 break; |
4523 /* Declaring a function type. Make sure we have a valid | 5434 /* Declaring a function type. Make sure we have a valid |
4524 type for the function to return. */ | 5435 type for the function to return. */ |
4525 if (type == error_mark_node) | 5436 if (type == error_mark_node) |
4526 continue; | 5437 continue; |
4527 | 5438 |
4528 size_varies = 0; | 5439 size_varies = false; |
4529 | 5440 |
4530 /* Warn about some types functions can't return. */ | 5441 /* Warn about some types functions can't return. */ |
4531 if (TREE_CODE (type) == FUNCTION_TYPE) | 5442 if (TREE_CODE (type) == FUNCTION_TYPE) |
4532 { | 5443 { |
4533 error ("%qs declared as function returning a function", name); | 5444 if (name) |
5445 error_at (loc, "%qE declared as function returning a " | |
5446 "function", name); | |
5447 else | |
5448 error_at (loc, "type name declared as function " | |
5449 "returning a function"); | |
4534 type = integer_type_node; | 5450 type = integer_type_node; |
4535 } | 5451 } |
4536 if (TREE_CODE (type) == ARRAY_TYPE) | 5452 if (TREE_CODE (type) == ARRAY_TYPE) |
4537 { | 5453 { |
4538 error ("%qs declared as function returning an array", name); | 5454 if (name) |
5455 error_at (loc, "%qE declared as function returning an array", | |
5456 name); | |
5457 else | |
5458 error_at (loc, "type name declared as function returning " | |
5459 "an array"); | |
5460 type = integer_type_node; | |
5461 } | |
5462 errmsg = targetm.invalid_return_type (type); | |
5463 if (errmsg) | |
5464 { | |
5465 error (errmsg); | |
4539 type = integer_type_node; | 5466 type = integer_type_node; |
4540 } | 5467 } |
4541 | 5468 |
4542 /* Construct the function type and go to the next | 5469 /* Construct the function type and go to the next |
4543 inner layer of declarator. */ | 5470 inner layer of declarator. */ |
4555 effect, so give a warning at -Wreturn-type. | 5482 effect, so give a warning at -Wreturn-type. |
4556 Qualifiers on a void return type are banned on | 5483 Qualifiers on a void return type are banned on |
4557 function definitions in ISO C; GCC used to used | 5484 function definitions in ISO C; GCC used to used |
4558 them for noreturn functions. */ | 5485 them for noreturn functions. */ |
4559 if (VOID_TYPE_P (type) && really_funcdef) | 5486 if (VOID_TYPE_P (type) && really_funcdef) |
4560 pedwarn (input_location, 0, | 5487 pedwarn (loc, 0, |
4561 "function definition has qualified void return type"); | 5488 "function definition has qualified void return type"); |
4562 else | 5489 else |
4563 warning (OPT_Wignored_qualifiers, | 5490 warning_at (loc, OPT_Wignored_qualifiers, |
4564 "type qualifiers ignored on function return type"); | 5491 "type qualifiers ignored on function return type"); |
4565 | 5492 |
4566 type = c_build_qualified_type (type, type_quals); | 5493 type = c_build_qualified_type (type, type_quals); |
4567 } | 5494 } |
4568 type_quals = TYPE_UNQUALIFIED; | 5495 type_quals = TYPE_UNQUALIFIED; |
4588 /* Merge any constancy or volatility into the target type | 5515 /* Merge any constancy or volatility into the target type |
4589 for the pointer. */ | 5516 for the pointer. */ |
4590 | 5517 |
4591 if (pedantic && TREE_CODE (type) == FUNCTION_TYPE | 5518 if (pedantic && TREE_CODE (type) == FUNCTION_TYPE |
4592 && type_quals) | 5519 && type_quals) |
4593 pedwarn (input_location, OPT_pedantic, | 5520 pedwarn (loc, OPT_pedantic, |
4594 "ISO C forbids qualified function types"); | 5521 "ISO C forbids qualified function types"); |
4595 if (type_quals) | 5522 if (type_quals) |
4596 type = c_build_qualified_type (type, type_quals); | 5523 type = c_build_qualified_type (type, type_quals); |
4597 size_varies = 0; | 5524 size_varies = false; |
4598 | 5525 |
4599 /* When the pointed-to type involves components of variable size, | 5526 /* When the pointed-to type involves components of variable size, |
4600 care must be taken to ensure that the size evaluation code is | 5527 care must be taken to ensure that the size evaluation code is |
4601 emitted early enough to dominate all the possible later uses | 5528 emitted early enough to dominate all the possible later uses |
4602 and late enough for the variables on which it depends to have | 5529 and late enough for the variables on which it depends to have |
4621 | 5548 |
4622 if (!TYPE_NAME (type) | 5549 if (!TYPE_NAME (type) |
4623 && (decl_context == NORMAL || decl_context == FIELD) | 5550 && (decl_context == NORMAL || decl_context == FIELD) |
4624 && variably_modified_type_p (type, NULL_TREE)) | 5551 && variably_modified_type_p (type, NULL_TREE)) |
4625 { | 5552 { |
4626 tree decl = build_decl (TYPE_DECL, NULL_TREE, type); | 5553 tree decl = build_decl (loc, TYPE_DECL, NULL_TREE, type); |
4627 DECL_ARTIFICIAL (decl) = 1; | 5554 DECL_ARTIFICIAL (decl) = 1; |
4628 pushdecl (decl); | 5555 pushdecl (decl); |
4629 finish_decl (decl, NULL_TREE, NULL_TREE); | 5556 finish_decl (decl, loc, NULL_TREE, NULL_TREE, NULL_TREE); |
4630 TYPE_NAME (type) = decl; | 5557 TYPE_NAME (type) = decl; |
4631 } | 5558 } |
4632 | 5559 |
4633 type = build_pointer_type (type); | 5560 type = build_pointer_type (type); |
4634 | 5561 |
4646 *decl_attrs = chainon (returned_attrs, *decl_attrs); | 5573 *decl_attrs = chainon (returned_attrs, *decl_attrs); |
4647 | 5574 |
4648 /* Now TYPE has the actual type, apart from any qualifiers in | 5575 /* Now TYPE has the actual type, apart from any qualifiers in |
4649 TYPE_QUALS. */ | 5576 TYPE_QUALS. */ |
4650 | 5577 |
5578 /* Warn about address space used for things other than static memory or | |
5579 pointers. */ | |
5580 address_space = DECODE_QUAL_ADDR_SPACE (type_quals); | |
5581 if (!ADDR_SPACE_GENERIC_P (address_space)) | |
5582 { | |
5583 if (decl_context == NORMAL) | |
5584 { | |
5585 switch (storage_class) | |
5586 { | |
5587 case csc_auto: | |
5588 error ("%qs combined with %<auto%> qualifier for %qE", | |
5589 c_addr_space_name (address_space), name); | |
5590 break; | |
5591 case csc_register: | |
5592 error ("%qs combined with %<register%> qualifier for %qE", | |
5593 c_addr_space_name (address_space), name); | |
5594 break; | |
5595 case csc_none: | |
5596 if (current_function_scope) | |
5597 { | |
5598 error ("%qs specified for auto variable %qE", | |
5599 c_addr_space_name (address_space), name); | |
5600 break; | |
5601 } | |
5602 break; | |
5603 case csc_static: | |
5604 case csc_extern: | |
5605 case csc_typedef: | |
5606 break; | |
5607 default: | |
5608 gcc_unreachable (); | |
5609 } | |
5610 } | |
5611 else if (decl_context == PARM && TREE_CODE (type) != ARRAY_TYPE) | |
5612 { | |
5613 if (name) | |
5614 error ("%qs specified for parameter %qE", | |
5615 c_addr_space_name (address_space), name); | |
5616 else | |
5617 error ("%qs specified for unnamed parameter", | |
5618 c_addr_space_name (address_space)); | |
5619 } | |
5620 else if (decl_context == FIELD) | |
5621 { | |
5622 if (name) | |
5623 error ("%qs specified for structure field %qE", | |
5624 c_addr_space_name (address_space), name); | |
5625 else | |
5626 error ("%qs specified for structure field", | |
5627 c_addr_space_name (address_space)); | |
5628 } | |
5629 } | |
5630 | |
4651 /* Check the type and width of a bit-field. */ | 5631 /* Check the type and width of a bit-field. */ |
4652 if (bitfield) | 5632 if (bitfield) |
4653 check_bitfield_type_and_width (&type, width, orig_name); | 5633 check_bitfield_type_and_width (&type, width, name); |
4654 | 5634 |
4655 /* Did array size calculations overflow? */ | 5635 /* Did array size calculations overflow? */ |
4656 | 5636 |
4657 if (TREE_CODE (type) == ARRAY_TYPE | 5637 if (TREE_CODE (type) == ARRAY_TYPE |
4658 && COMPLETE_TYPE_P (type) | 5638 && COMPLETE_TYPE_P (type) |
4659 && TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST | 5639 && TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST |
4660 && TREE_OVERFLOW (TYPE_SIZE_UNIT (type))) | 5640 && TREE_OVERFLOW (TYPE_SIZE_UNIT (type))) |
4661 { | 5641 { |
4662 error ("size of array %qs is too large", name); | 5642 if (name) |
5643 error_at (loc, "size of array %qE is too large", name); | |
5644 else | |
5645 error_at (loc, "size of unnamed array is too large"); | |
4663 /* If we proceed with the array type as it is, we'll eventually | 5646 /* If we proceed with the array type as it is, we'll eventually |
4664 crash in tree_low_cst(). */ | 5647 crash in tree_low_cst(). */ |
4665 type = error_mark_node; | 5648 type = error_mark_node; |
4666 } | 5649 } |
4667 | 5650 |
4670 if (storage_class == csc_typedef) | 5653 if (storage_class == csc_typedef) |
4671 { | 5654 { |
4672 tree decl; | 5655 tree decl; |
4673 if (pedantic && TREE_CODE (type) == FUNCTION_TYPE | 5656 if (pedantic && TREE_CODE (type) == FUNCTION_TYPE |
4674 && type_quals) | 5657 && type_quals) |
4675 pedwarn (input_location, OPT_pedantic, | 5658 pedwarn (loc, OPT_pedantic, |
4676 "ISO C forbids qualified function types"); | 5659 "ISO C forbids qualified function types"); |
4677 if (type_quals) | 5660 if (type_quals) |
4678 type = c_build_qualified_type (type, type_quals); | 5661 type = c_build_qualified_type (type, type_quals); |
4679 decl = build_decl (TYPE_DECL, declarator->u.id, type); | 5662 decl = build_decl (declarator->id_loc, |
4680 DECL_SOURCE_LOCATION (decl) = declarator->id_loc; | 5663 TYPE_DECL, declarator->u.id, type); |
4681 if (declspecs->explicit_signed_p) | 5664 if (declspecs->explicit_signed_p) |
4682 C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1; | 5665 C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1; |
4683 if (declspecs->inline_p) | 5666 if (declspecs->inline_p) |
4684 pedwarn (input_location, 0,"typedef %q+D declared %<inline%>", decl); | 5667 pedwarn (loc, 0,"typedef %q+D declared %<inline%>", decl); |
5668 | |
5669 if (warn_cxx_compat && declarator->u.id != NULL_TREE) | |
5670 { | |
5671 struct c_binding *b = I_TAG_BINDING (declarator->u.id); | |
5672 | |
5673 if (b != NULL | |
5674 && b->decl != NULL_TREE | |
5675 && (B_IN_CURRENT_SCOPE (b) | |
5676 || (current_scope == file_scope && B_IN_EXTERNAL_SCOPE (b))) | |
5677 && TYPE_MAIN_VARIANT (b->decl) != TYPE_MAIN_VARIANT (type)) | |
5678 { | |
5679 warning_at (declarator->id_loc, OPT_Wc___compat, | |
5680 ("using %qD as both a typedef and a tag is " | |
5681 "invalid in C++"), | |
5682 decl); | |
5683 if (b->locus != UNKNOWN_LOCATION) | |
5684 inform (b->locus, "originally defined here"); | |
5685 } | |
5686 } | |
5687 | |
4685 return decl; | 5688 return decl; |
4686 } | 5689 } |
4687 | 5690 |
4688 /* If this is a type name (such as, in a cast or sizeof), | 5691 /* If this is a type name (such as, in a cast or sizeof), |
4689 compute the type and return it now. */ | 5692 compute the type and return it now. */ |
4694 and fields. */ | 5697 and fields. */ |
4695 gcc_assert (storage_class == csc_none && !threadp | 5698 gcc_assert (storage_class == csc_none && !threadp |
4696 && !declspecs->inline_p); | 5699 && !declspecs->inline_p); |
4697 if (pedantic && TREE_CODE (type) == FUNCTION_TYPE | 5700 if (pedantic && TREE_CODE (type) == FUNCTION_TYPE |
4698 && type_quals) | 5701 && type_quals) |
4699 pedwarn (input_location, OPT_pedantic, | 5702 pedwarn (loc, OPT_pedantic, |
4700 "ISO C forbids const or volatile function types"); | 5703 "ISO C forbids const or volatile function types"); |
4701 if (type_quals) | 5704 if (type_quals) |
4702 type = c_build_qualified_type (type, type_quals); | 5705 type = c_build_qualified_type (type, type_quals); |
4703 return type; | 5706 return type; |
4704 } | 5707 } |
4705 | 5708 |
4706 if (pedantic && decl_context == FIELD | 5709 if (pedantic && decl_context == FIELD |
4707 && variably_modified_type_p (type, NULL_TREE)) | 5710 && variably_modified_type_p (type, NULL_TREE)) |
4708 { | 5711 { |
4709 /* C99 6.7.2.1p8 */ | 5712 /* C99 6.7.2.1p8 */ |
4710 pedwarn (input_location, OPT_pedantic, | 5713 pedwarn (loc, OPT_pedantic, "a member of a structure or union cannot " |
4711 "a member of a structure or union cannot have a variably modified type"); | 5714 "have a variably modified type"); |
4712 } | 5715 } |
4713 | 5716 |
4714 /* Aside from typedefs and type names (handle above), | 5717 /* Aside from typedefs and type names (handle above), |
4715 `void' at top level (not within pointer) | 5718 `void' at top level (not within pointer) |
4716 is allowed only in public variables. | 5719 is allowed only in public variables. |
4722 && (storage_class == csc_extern | 5725 && (storage_class == csc_extern |
4723 || (current_scope == file_scope | 5726 || (current_scope == file_scope |
4724 && !(storage_class == csc_static | 5727 && !(storage_class == csc_static |
4725 || storage_class == csc_register))))) | 5728 || storage_class == csc_register))))) |
4726 { | 5729 { |
4727 error ("variable or field %qs declared void", name); | 5730 error_at (loc, "variable or field %qE declared void", name); |
4728 type = integer_type_node; | 5731 type = integer_type_node; |
4729 } | 5732 } |
4730 | 5733 |
4731 /* Now create the decl, which may be a VAR_DECL, a PARM_DECL | 5734 /* Now create the decl, which may be a VAR_DECL, a PARM_DECL |
4732 or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE. */ | 5735 or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE. */ |
4752 if (type_quals) | 5755 if (type_quals) |
4753 type = c_build_qualified_type (type, type_quals); | 5756 type = c_build_qualified_type (type, type_quals); |
4754 | 5757 |
4755 /* We don't yet implement attributes in this context. */ | 5758 /* We don't yet implement attributes in this context. */ |
4756 if (array_ptr_attrs != NULL_TREE) | 5759 if (array_ptr_attrs != NULL_TREE) |
4757 warning (OPT_Wattributes, | 5760 warning_at (loc, OPT_Wattributes, |
4758 "attributes in parameter array declarator ignored"); | 5761 "attributes in parameter array declarator ignored"); |
4759 | 5762 |
4760 size_varies = 0; | 5763 size_varies = false; |
4761 } | 5764 } |
4762 else if (TREE_CODE (type) == FUNCTION_TYPE) | 5765 else if (TREE_CODE (type) == FUNCTION_TYPE) |
4763 { | 5766 { |
4764 if (type_quals) | 5767 if (type_quals) |
4765 pedwarn (input_location, OPT_pedantic, | 5768 pedwarn (loc, OPT_pedantic, |
4766 "ISO C forbids qualified function types"); | 5769 "ISO C forbids qualified function types"); |
4767 if (type_quals) | 5770 if (type_quals) |
4768 type = c_build_qualified_type (type, type_quals); | 5771 type = c_build_qualified_type (type, type_quals); |
4769 type = build_pointer_type (type); | 5772 type = build_pointer_type (type); |
4770 type_quals = TYPE_UNQUALIFIED; | 5773 type_quals = TYPE_UNQUALIFIED; |
4771 } | 5774 } |
4772 else if (type_quals) | 5775 else if (type_quals) |
4773 type = c_build_qualified_type (type, type_quals); | 5776 type = c_build_qualified_type (type, type_quals); |
4774 | 5777 |
4775 decl = build_decl (PARM_DECL, declarator->u.id, type); | 5778 decl = build_decl (declarator->id_loc, |
4776 DECL_SOURCE_LOCATION (decl) = declarator->id_loc; | 5779 PARM_DECL, declarator->u.id, type); |
4777 if (size_varies) | 5780 if (size_varies) |
4778 C_DECL_VARIABLE_SIZE (decl) = 1; | 5781 C_DECL_VARIABLE_SIZE (decl) = 1; |
4779 | 5782 |
4780 /* Compute the type actually passed in the parmlist, | 5783 /* Compute the type actually passed in the parmlist, |
4781 for the case where there is no prototype. | 5784 for the case where there is no prototype. |
4787 else | 5790 else |
4788 promoted_type = c_type_promotes_to (type); | 5791 promoted_type = c_type_promotes_to (type); |
4789 | 5792 |
4790 DECL_ARG_TYPE (decl) = promoted_type; | 5793 DECL_ARG_TYPE (decl) = promoted_type; |
4791 if (declspecs->inline_p) | 5794 if (declspecs->inline_p) |
4792 pedwarn (input_location, 0, "parameter %q+D declared %<inline%>", decl); | 5795 pedwarn (loc, 0, "parameter %q+D declared %<inline%>", decl); |
4793 } | 5796 } |
4794 else if (decl_context == FIELD) | 5797 else if (decl_context == FIELD) |
4795 { | 5798 { |
4796 /* Note that the grammar rejects storage classes in typenames | 5799 /* Note that the grammar rejects storage classes in typenames |
4797 and fields. */ | 5800 and fields. */ |
4800 | 5803 |
4801 /* Structure field. It may not be a function. */ | 5804 /* Structure field. It may not be a function. */ |
4802 | 5805 |
4803 if (TREE_CODE (type) == FUNCTION_TYPE) | 5806 if (TREE_CODE (type) == FUNCTION_TYPE) |
4804 { | 5807 { |
4805 error ("field %qs declared as a function", name); | 5808 error_at (loc, "field %qE declared as a function", name); |
4806 type = build_pointer_type (type); | 5809 type = build_pointer_type (type); |
4807 } | 5810 } |
4808 else if (TREE_CODE (type) != ERROR_MARK | 5811 else if (TREE_CODE (type) != ERROR_MARK |
4809 && !COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (type)) | 5812 && !COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (type)) |
4810 { | 5813 { |
4811 error ("field %qs has incomplete type", name); | 5814 if (name) |
5815 error_at (loc, "field %qE has incomplete type", name); | |
5816 else | |
5817 error_at (loc, "unnamed field has incomplete type"); | |
4812 type = error_mark_node; | 5818 type = error_mark_node; |
4813 } | 5819 } |
4814 type = c_build_qualified_type (type, type_quals); | 5820 type = c_build_qualified_type (type, type_quals); |
4815 decl = build_decl (FIELD_DECL, declarator->u.id, type); | 5821 decl = build_decl (declarator->id_loc, |
4816 DECL_SOURCE_LOCATION (decl) = declarator->id_loc; | 5822 FIELD_DECL, declarator->u.id, type); |
4817 DECL_NONADDRESSABLE_P (decl) = bitfield; | 5823 DECL_NONADDRESSABLE_P (decl) = bitfield; |
4818 if (bitfield && !declarator->u.id) | 5824 if (bitfield && !declarator->u.id) |
4819 TREE_NO_WARNING (decl) = 1; | 5825 TREE_NO_WARNING (decl) = 1; |
4820 | 5826 |
4821 if (size_varies) | 5827 if (size_varies) |
4823 } | 5829 } |
4824 else if (TREE_CODE (type) == FUNCTION_TYPE) | 5830 else if (TREE_CODE (type) == FUNCTION_TYPE) |
4825 { | 5831 { |
4826 if (storage_class == csc_register || threadp) | 5832 if (storage_class == csc_register || threadp) |
4827 { | 5833 { |
4828 error ("invalid storage class for function %qs", name); | 5834 error_at (loc, "invalid storage class for function %qE", name); |
4829 } | 5835 } |
4830 else if (current_scope != file_scope) | 5836 else if (current_scope != file_scope) |
4831 { | 5837 { |
4832 /* Function declaration not at file scope. Storage | 5838 /* Function declaration not at file scope. Storage |
4833 classes other than `extern' are not allowed, C99 | 5839 classes other than `extern' are not allowed, C99 |
4834 6.7.1p5, and `extern' makes no difference. However, | 5840 6.7.1p5, and `extern' makes no difference. However, |
4835 GCC allows 'auto', perhaps with 'inline', to support | 5841 GCC allows 'auto', perhaps with 'inline', to support |
4836 nested functions. */ | 5842 nested functions. */ |
4837 if (storage_class == csc_auto) | 5843 if (storage_class == csc_auto) |
4838 pedwarn (input_location, OPT_pedantic, "invalid storage class for function %qs", name); | 5844 pedwarn (loc, OPT_pedantic, |
5845 "invalid storage class for function %qE", name); | |
4839 else if (storage_class == csc_static) | 5846 else if (storage_class == csc_static) |
4840 { | 5847 { |
4841 error ("invalid storage class for function %qs", name); | 5848 error_at (loc, "invalid storage class for function %qE", name); |
4842 if (funcdef_flag) | 5849 if (funcdef_flag) |
4843 storage_class = declspecs->storage_class = csc_none; | 5850 storage_class = declspecs->storage_class = csc_none; |
4844 else | 5851 else |
4845 return 0; | 5852 return 0; |
4846 } | 5853 } |
4847 } | 5854 } |
4848 | 5855 |
4849 decl = build_decl (FUNCTION_DECL, declarator->u.id, type); | 5856 decl = build_decl (declarator->id_loc, |
4850 DECL_SOURCE_LOCATION (decl) = declarator->id_loc; | 5857 FUNCTION_DECL, declarator->u.id, type); |
4851 decl = build_decl_attribute_variant (decl, decl_attr); | 5858 decl = build_decl_attribute_variant (decl, decl_attr); |
4852 | 5859 |
4853 if (pedantic && type_quals && !DECL_IN_SYSTEM_HEADER (decl)) | 5860 if (pedantic && type_quals && !DECL_IN_SYSTEM_HEADER (decl)) |
4854 pedwarn (input_location, OPT_pedantic, | 5861 pedwarn (loc, OPT_pedantic, |
4855 "ISO C forbids qualified function types"); | 5862 "ISO C forbids qualified function types"); |
4856 | 5863 |
4857 /* GNU C interprets a volatile-qualified function type to indicate | 5864 /* GNU C interprets a volatile-qualified function type to indicate |
4858 that the function does not return. */ | 5865 that the function does not return. */ |
4859 if ((type_quals & TYPE_QUAL_VOLATILE) | 5866 if ((type_quals & TYPE_QUAL_VOLATILE) |
4860 && !VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl)))) | 5867 && !VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl)))) |
4861 warning (0, "%<noreturn%> function returns non-void value"); | 5868 warning_at (loc, 0, "%<noreturn%> function returns non-void value"); |
4862 | 5869 |
4863 /* Every function declaration is an external reference | 5870 /* Every function declaration is an external reference |
4864 (DECL_EXTERNAL) except for those which are not at file | 5871 (DECL_EXTERNAL) except for those which are not at file |
4865 scope and are explicitly declared "auto". This is | 5872 scope and are explicitly declared "auto". This is |
4866 forbidden by standard C (C99 6.7.1p5) and is interpreted by | 5873 forbidden by standard C (C99 6.7.1p5) and is interpreted by |
4892 | 5899 |
4893 /* Record presence of `inline', if it is reasonable. */ | 5900 /* Record presence of `inline', if it is reasonable. */ |
4894 if (flag_hosted && MAIN_NAME_P (declarator->u.id)) | 5901 if (flag_hosted && MAIN_NAME_P (declarator->u.id)) |
4895 { | 5902 { |
4896 if (declspecs->inline_p) | 5903 if (declspecs->inline_p) |
4897 pedwarn (input_location, 0, "cannot inline function %<main%>"); | 5904 pedwarn (loc, 0, "cannot inline function %<main%>"); |
4898 } | 5905 } |
4899 else if (declspecs->inline_p) | 5906 else if (declspecs->inline_p) |
4900 /* Record that the function is declared `inline'. */ | 5907 /* Record that the function is declared `inline'. */ |
4901 DECL_DECLARED_INLINE_P (decl) = 1; | 5908 DECL_DECLARED_INLINE_P (decl) = 1; |
4902 } | 5909 } |
4921 | 5928 |
4922 if (global_decl | 5929 if (global_decl |
4923 && global_decl != visible_decl | 5930 && global_decl != visible_decl |
4924 && TREE_CODE (global_decl) == VAR_DECL | 5931 && TREE_CODE (global_decl) == VAR_DECL |
4925 && !TREE_PUBLIC (global_decl)) | 5932 && !TREE_PUBLIC (global_decl)) |
4926 error ("variable previously declared %<static%> redeclared " | 5933 error_at (loc, "variable previously declared %<static%> " |
4927 "%<extern%>"); | 5934 "redeclared %<extern%>"); |
4928 } | 5935 } |
4929 | 5936 |
4930 decl = build_decl (VAR_DECL, declarator->u.id, type); | 5937 decl = build_decl (declarator->id_loc, |
4931 DECL_SOURCE_LOCATION (decl) = declarator->id_loc; | 5938 VAR_DECL, declarator->u.id, type); |
4932 if (size_varies) | 5939 if (size_varies) |
4933 C_DECL_VARIABLE_SIZE (decl) = 1; | 5940 C_DECL_VARIABLE_SIZE (decl) = 1; |
4934 | 5941 |
4935 if (declspecs->inline_p) | 5942 if (declspecs->inline_p) |
4936 pedwarn (input_location, 0, "variable %q+D declared %<inline%>", decl); | 5943 pedwarn (loc, 0, "variable %q+D declared %<inline%>", decl); |
4937 | 5944 |
4938 /* At file scope, an initialized extern declaration may follow | 5945 /* At file scope, an initialized extern declaration may follow |
4939 a static declaration. In that case, DECL_EXTERNAL will be | 5946 a static declaration. In that case, DECL_EXTERNAL will be |
4940 reset later in start_decl. */ | 5947 reset later in start_decl. */ |
4941 DECL_EXTERNAL (decl) = (storage_class == csc_extern); | 5948 DECL_EXTERNAL (decl) = (storage_class == csc_extern); |
4958 | 5965 |
4959 if (threadp) | 5966 if (threadp) |
4960 DECL_TLS_MODEL (decl) = decl_default_tls_model (decl); | 5967 DECL_TLS_MODEL (decl) = decl_default_tls_model (decl); |
4961 } | 5968 } |
4962 | 5969 |
4963 if (storage_class == csc_extern | 5970 if ((storage_class == csc_extern |
5971 || (storage_class == csc_none | |
5972 && TREE_CODE (type) == FUNCTION_TYPE | |
5973 && !funcdef_flag)) | |
4964 && variably_modified_type_p (type, NULL_TREE)) | 5974 && variably_modified_type_p (type, NULL_TREE)) |
4965 { | 5975 { |
4966 /* C99 6.7.5.2p2 */ | 5976 /* C99 6.7.5.2p2 */ |
4967 error ("object with variably modified type must have no linkage"); | 5977 if (TREE_CODE (type) == FUNCTION_TYPE) |
5978 error_at (loc, "non-nested function with variably modified type"); | |
5979 else | |
5980 error_at (loc, "object with variably modified type must have " | |
5981 "no linkage"); | |
4968 } | 5982 } |
4969 | 5983 |
4970 /* Record `register' declaration for warnings on & | 5984 /* Record `register' declaration for warnings on & |
4971 and in case doing stupid register allocation. */ | 5985 and in case doing stupid register allocation. */ |
4972 | 5986 |
4999 | 6013 |
5000 /* This is the earliest point at which we might know the assembler | 6014 /* This is the earliest point at which we might know the assembler |
5001 name of a variable. Thus, if it's known before this, die horribly. */ | 6015 name of a variable. Thus, if it's known before this, die horribly. */ |
5002 gcc_assert (!DECL_ASSEMBLER_NAME_SET_P (decl)); | 6016 gcc_assert (!DECL_ASSEMBLER_NAME_SET_P (decl)); |
5003 | 6017 |
6018 if (warn_cxx_compat | |
6019 && TREE_CODE (decl) == VAR_DECL | |
6020 && TREE_PUBLIC (decl) | |
6021 && TREE_STATIC (decl) | |
6022 && (TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE | |
6023 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE | |
6024 || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE) | |
6025 && TYPE_NAME (TREE_TYPE (decl)) == NULL_TREE) | |
6026 warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wc___compat, | |
6027 ("non-local variable %qD with anonymous type is " | |
6028 "questionable in C++"), | |
6029 decl); | |
6030 | |
5004 return decl; | 6031 return decl; |
5005 } | 6032 } |
5006 } | 6033 } |
5007 | 6034 |
5008 /* Decode the parameter-list info for a function type or function definition. | 6035 /* Decode the parameter-list info for a function type or function definition. |
5049 } | 6076 } |
5050 else | 6077 else |
5051 { | 6078 { |
5052 tree parm, type, typelt; | 6079 tree parm, type, typelt; |
5053 unsigned int parmno; | 6080 unsigned int parmno; |
6081 const char *errmsg; | |
5054 | 6082 |
5055 /* If there is a parameter of incomplete type in a definition, | 6083 /* If there is a parameter of incomplete type in a definition, |
5056 this is an error. In a declaration this is valid, and a | 6084 this is an error. In a declaration this is valid, and a |
5057 struct or union type may be completed later, before any calls | 6085 struct or union type may be completed later, before any calls |
5058 or definition of the function. In the case where the tag was | 6086 or definition of the function. In the case where the tag was |
5072 if (!COMPLETE_TYPE_P (type)) | 6100 if (!COMPLETE_TYPE_P (type)) |
5073 { | 6101 { |
5074 if (funcdef_flag) | 6102 if (funcdef_flag) |
5075 { | 6103 { |
5076 if (DECL_NAME (parm)) | 6104 if (DECL_NAME (parm)) |
5077 error ("parameter %u (%q+D) has incomplete type", | 6105 error_at (input_location, |
5078 parmno, parm); | 6106 "parameter %u (%q+D) has incomplete type", |
6107 parmno, parm); | |
5079 else | 6108 else |
5080 error ("%Jparameter %u has incomplete type", | 6109 error_at (DECL_SOURCE_LOCATION (parm), |
5081 parm, parmno); | 6110 "parameter %u has incomplete type", |
6111 parmno); | |
5082 | 6112 |
5083 TREE_VALUE (typelt) = error_mark_node; | 6113 TREE_VALUE (typelt) = error_mark_node; |
5084 TREE_TYPE (parm) = error_mark_node; | 6114 TREE_TYPE (parm) = error_mark_node; |
5085 } | 6115 } |
5086 else if (VOID_TYPE_P (type)) | 6116 else if (VOID_TYPE_P (type)) |
5087 { | 6117 { |
5088 if (DECL_NAME (parm)) | 6118 if (DECL_NAME (parm)) |
5089 warning (0, "parameter %u (%q+D) has void type", | 6119 warning_at (input_location, 0, |
5090 parmno, parm); | 6120 "parameter %u (%q+D) has void type", |
6121 parmno, parm); | |
5091 else | 6122 else |
5092 warning (0, "%Jparameter %u has void type", | 6123 warning_at (DECL_SOURCE_LOCATION (parm), 0, |
5093 parm, parmno); | 6124 "parameter %u has void type", |
6125 parmno); | |
5094 } | 6126 } |
6127 } | |
6128 | |
6129 errmsg = targetm.invalid_parameter_type (type); | |
6130 if (errmsg) | |
6131 { | |
6132 error (errmsg); | |
6133 TREE_VALUE (typelt) = error_mark_node; | |
6134 TREE_TYPE (parm) = error_mark_node; | |
5095 } | 6135 } |
5096 | 6136 |
5097 if (DECL_NAME (parm) && TREE_USED (parm)) | 6137 if (DECL_NAME (parm) && TREE_USED (parm)) |
5098 warn_if_shadowing (parm); | 6138 warn_if_shadowing (parm); |
5099 } | 6139 } |
5286 arg_info->pending_sizes = get_pending_sizes (); | 6326 arg_info->pending_sizes = get_pending_sizes (); |
5287 return arg_info; | 6327 return arg_info; |
5288 } | 6328 } |
5289 | 6329 |
5290 /* Get the struct, enum or union (CODE says which) with tag NAME. | 6330 /* Get the struct, enum or union (CODE says which) with tag NAME. |
5291 Define the tag as a forward-reference if it is not defined. | 6331 Define the tag as a forward-reference with location LOC if it is |
5292 Return a c_typespec structure for the type specifier. */ | 6332 not defined. Return a c_typespec structure for the type |
6333 specifier. */ | |
5293 | 6334 |
5294 struct c_typespec | 6335 struct c_typespec |
5295 parser_xref_tag (enum tree_code code, tree name) | 6336 parser_xref_tag (location_t loc, enum tree_code code, tree name) |
5296 { | 6337 { |
5297 struct c_typespec ret; | 6338 struct c_typespec ret; |
6339 tree ref; | |
6340 location_t refloc; | |
6341 | |
6342 ret.expr = NULL_TREE; | |
6343 ret.expr_const_operands = true; | |
6344 | |
5298 /* If a cross reference is requested, look up the type | 6345 /* If a cross reference is requested, look up the type |
5299 already defined for this tag and return it. */ | 6346 already defined for this tag and return it. */ |
5300 | 6347 |
5301 tree ref = lookup_tag (code, name, 0); | 6348 ref = lookup_tag (code, name, 0, &refloc); |
5302 /* If this is the right type of tag, return what we found. | 6349 /* If this is the right type of tag, return what we found. |
5303 (This reference will be shadowed by shadow_tag later if appropriate.) | 6350 (This reference will be shadowed by shadow_tag later if appropriate.) |
5304 If this is the wrong type of tag, do not return it. If it was the | 6351 If this is the wrong type of tag, do not return it. If it was the |
5305 wrong type in the same scope, we will have had an error | 6352 wrong type in the same scope, we will have had an error |
5306 message already; if in a different scope and declaring | 6353 message already; if in a different scope and declaring |
5311 (For example, with "struct foo" in an outer scope, "union foo;" | 6358 (For example, with "struct foo" in an outer scope, "union foo;" |
5312 must shadow that tag with a new one of union type.) */ | 6359 must shadow that tag with a new one of union type.) */ |
5313 ret.kind = (ref ? ctsk_tagref : ctsk_tagfirstref); | 6360 ret.kind = (ref ? ctsk_tagref : ctsk_tagfirstref); |
5314 if (ref && TREE_CODE (ref) == code) | 6361 if (ref && TREE_CODE (ref) == code) |
5315 { | 6362 { |
6363 if (C_TYPE_DEFINED_IN_STRUCT (ref) | |
6364 && loc != UNKNOWN_LOCATION | |
6365 && warn_cxx_compat) | |
6366 { | |
6367 switch (code) | |
6368 { | |
6369 case ENUMERAL_TYPE: | |
6370 warning_at (loc, OPT_Wc___compat, | |
6371 ("enum type defined in struct or union " | |
6372 "is not visible in C++")); | |
6373 inform (refloc, "enum type defined here"); | |
6374 break; | |
6375 case RECORD_TYPE: | |
6376 warning_at (loc, OPT_Wc___compat, | |
6377 ("struct defined in struct or union " | |
6378 "is not visible in C++")); | |
6379 inform (refloc, "struct defined here"); | |
6380 break; | |
6381 case UNION_TYPE: | |
6382 warning_at (loc, OPT_Wc___compat, | |
6383 ("union defined in struct or union " | |
6384 "is not visible in C++")); | |
6385 inform (refloc, "union defined here"); | |
6386 break; | |
6387 default: | |
6388 gcc_unreachable(); | |
6389 } | |
6390 } | |
6391 | |
5316 ret.spec = ref; | 6392 ret.spec = ref; |
5317 return ret; | 6393 return ret; |
5318 } | 6394 } |
5319 | 6395 |
5320 /* If no such tag is yet defined, create a forward-reference node | 6396 /* If no such tag is yet defined, create a forward-reference node |
5334 TYPE_PRECISION (ref) = TYPE_PRECISION (unsigned_type_node); | 6410 TYPE_PRECISION (ref) = TYPE_PRECISION (unsigned_type_node); |
5335 TYPE_MIN_VALUE (ref) = TYPE_MIN_VALUE (unsigned_type_node); | 6411 TYPE_MIN_VALUE (ref) = TYPE_MIN_VALUE (unsigned_type_node); |
5336 TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node); | 6412 TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node); |
5337 } | 6413 } |
5338 | 6414 |
5339 pushtag (name, ref); | 6415 pushtag (loc, name, ref); |
5340 | 6416 |
5341 ret.spec = ref; | 6417 ret.spec = ref; |
5342 return ret; | 6418 return ret; |
5343 } | 6419 } |
5344 | 6420 |
5347 Return a tree for the type. */ | 6423 Return a tree for the type. */ |
5348 | 6424 |
5349 tree | 6425 tree |
5350 xref_tag (enum tree_code code, tree name) | 6426 xref_tag (enum tree_code code, tree name) |
5351 { | 6427 { |
5352 return parser_xref_tag (code, name).spec; | 6428 return parser_xref_tag (input_location, code, name).spec; |
5353 } | 6429 } |
5354 | 6430 |
5355 /* Make sure that the tag NAME is defined *in the current scope* | 6431 /* Make sure that the tag NAME is defined *in the current scope* |
5356 at least as a forward reference. | 6432 at least as a forward reference. |
5357 CODE says which kind of tag NAME ought to be. */ | 6433 LOC is the location of the struct's definition. |
6434 CODE says which kind of tag NAME ought to be. | |
6435 | |
6436 This stores the current value of the file static STRUCT_PARSE_INFO | |
6437 in *ENCLOSING_STRUCT_PARSE_INFO, and points STRUCT_PARSE_INFO at a | |
6438 new c_struct_parse_info structure. The old value of | |
6439 STRUCT_PARSE_INFO is restored in finish_struct. */ | |
5358 | 6440 |
5359 tree | 6441 tree |
5360 start_struct (enum tree_code code, tree name) | 6442 start_struct (location_t loc, enum tree_code code, tree name, |
6443 struct c_struct_parse_info **enclosing_struct_parse_info) | |
5361 { | 6444 { |
5362 /* If there is already a tag defined at this scope | 6445 /* If there is already a tag defined at this scope |
5363 (as a forward reference), just return it. */ | 6446 (as a forward reference), just return it. */ |
5364 | 6447 |
5365 tree ref = 0; | 6448 tree ref = NULL_TREE; |
5366 | 6449 location_t refloc = UNKNOWN_LOCATION; |
5367 if (name != 0) | 6450 |
5368 ref = lookup_tag (code, name, 1); | 6451 if (name != NULL_TREE) |
6452 ref = lookup_tag (code, name, 1, &refloc); | |
5369 if (ref && TREE_CODE (ref) == code) | 6453 if (ref && TREE_CODE (ref) == code) |
5370 { | 6454 { |
5371 if (TYPE_SIZE (ref)) | 6455 if (TYPE_SIZE (ref)) |
5372 { | 6456 { |
5373 if (code == UNION_TYPE) | 6457 if (code == UNION_TYPE) |
5374 error ("redefinition of %<union %E%>", name); | 6458 error_at (loc, "redefinition of %<union %E%>", name); |
5375 else | 6459 else |
5376 error ("redefinition of %<struct %E%>", name); | 6460 error_at (loc, "redefinition of %<struct %E%>", name); |
6461 if (refloc != UNKNOWN_LOCATION) | |
6462 inform (refloc, "originally defined here"); | |
5377 /* Don't create structures using a name already in use. */ | 6463 /* Don't create structures using a name already in use. */ |
5378 ref = NULL_TREE; | 6464 ref = NULL_TREE; |
5379 } | 6465 } |
5380 else if (C_TYPE_BEING_DEFINED (ref)) | 6466 else if (C_TYPE_BEING_DEFINED (ref)) |
5381 { | 6467 { |
5382 if (code == UNION_TYPE) | 6468 if (code == UNION_TYPE) |
5383 error ("nested redefinition of %<union %E%>", name); | 6469 error_at (loc, "nested redefinition of %<union %E%>", name); |
5384 else | 6470 else |
5385 error ("nested redefinition of %<struct %E%>", name); | 6471 error_at (loc, "nested redefinition of %<struct %E%>", name); |
6472 /* Don't bother to report "originally defined here" for a | |
6473 nested redefinition; the original definition should be | |
6474 obvious. */ | |
5386 /* Don't create structures that contain themselves. */ | 6475 /* Don't create structures that contain themselves. */ |
5387 ref = NULL_TREE; | 6476 ref = NULL_TREE; |
5388 } | 6477 } |
5389 } | 6478 } |
5390 | 6479 |
5391 /* Otherwise create a forward-reference just so the tag is in scope. */ | 6480 /* Otherwise create a forward-reference just so the tag is in scope. */ |
5392 | 6481 |
5393 if (ref == NULL_TREE || TREE_CODE (ref) != code) | 6482 if (ref == NULL_TREE || TREE_CODE (ref) != code) |
5394 { | 6483 { |
5395 ref = make_node (code); | 6484 ref = make_node (code); |
5396 pushtag (name, ref); | 6485 pushtag (loc, name, ref); |
5397 } | 6486 } |
5398 | 6487 |
5399 C_TYPE_BEING_DEFINED (ref) = 1; | 6488 C_TYPE_BEING_DEFINED (ref) = 1; |
5400 TYPE_PACKED (ref) = flag_pack_struct; | 6489 TYPE_PACKED (ref) = flag_pack_struct; |
6490 | |
6491 *enclosing_struct_parse_info = struct_parse_info; | |
6492 struct_parse_info = XNEW (struct c_struct_parse_info); | |
6493 struct_parse_info->struct_types = VEC_alloc (tree, heap, 0); | |
6494 struct_parse_info->fields = VEC_alloc (c_binding_ptr, heap, 0); | |
6495 struct_parse_info->typedefs_seen = VEC_alloc (tree, heap, 0); | |
6496 | |
6497 /* FIXME: This will issue a warning for a use of a type defined | |
6498 within a statement expr used within sizeof, et. al. This is not | |
6499 terribly serious as C++ doesn't permit statement exprs within | |
6500 sizeof anyhow. */ | |
6501 if (warn_cxx_compat && (in_sizeof || in_typeof || in_alignof)) | |
6502 warning_at (loc, OPT_Wc___compat, | |
6503 "defining type in %qs expression is invalid in C++", | |
6504 (in_sizeof | |
6505 ? "sizeof" | |
6506 : (in_typeof ? "typeof" : "alignof"))); | |
6507 | |
5401 return ref; | 6508 return ref; |
5402 } | 6509 } |
5403 | 6510 |
5404 /* Process the specs, declarator and width (NULL if omitted) | 6511 /* Process the specs, declarator and width (NULL if omitted) |
5405 of a structure component, returning a FIELD_DECL node. | 6512 of a structure component, returning a FIELD_DECL node. |
5465 } | 6572 } |
5466 pedwarn (loc, OPT_pedantic, "ISO C doesn%'t support unnamed structs/unions"); | 6573 pedwarn (loc, OPT_pedantic, "ISO C doesn%'t support unnamed structs/unions"); |
5467 } | 6574 } |
5468 | 6575 |
5469 value = grokdeclarator (declarator, declspecs, FIELD, false, | 6576 value = grokdeclarator (declarator, declspecs, FIELD, false, |
5470 width ? &width : NULL, decl_attrs, | 6577 width ? &width : NULL, decl_attrs, NULL, NULL, |
5471 DEPRECATED_NORMAL); | 6578 DEPRECATED_NORMAL); |
5472 | 6579 |
5473 finish_decl (value, NULL_TREE, NULL_TREE); | 6580 finish_decl (value, loc, NULL_TREE, NULL_TREE, NULL_TREE); |
5474 DECL_INITIAL (value) = width; | 6581 DECL_INITIAL (value) = width; |
6582 | |
6583 if (warn_cxx_compat && DECL_NAME (value) != NULL_TREE) | |
6584 { | |
6585 /* If we currently have a binding for this field, set the | |
6586 in_struct field in the binding, so that we warn about lookups | |
6587 which find it. */ | |
6588 struct c_binding *b = I_SYMBOL_BINDING (DECL_NAME (value)); | |
6589 if (b != NULL) | |
6590 { | |
6591 /* If the in_struct field is not yet set, push it on a list | |
6592 to be cleared when this struct is finished. */ | |
6593 if (!b->in_struct) | |
6594 { | |
6595 VEC_safe_push (c_binding_ptr, heap, | |
6596 struct_parse_info->fields, b); | |
6597 b->in_struct = 1; | |
6598 } | |
6599 } | |
6600 } | |
5475 | 6601 |
5476 return value; | 6602 return value; |
5477 } | 6603 } |
5478 | 6604 |
5479 /* Generate an error for any duplicate field names in FIELDLIST. Munge | 6605 /* Generate an error for any duplicate field names in FIELDLIST. Munge |
5531 | 6657 |
5532 htab_delete (htab); | 6658 htab_delete (htab); |
5533 } | 6659 } |
5534 } | 6660 } |
5535 | 6661 |
6662 /* Finish up struct info used by -Wc++-compat. */ | |
6663 | |
6664 static void | |
6665 warn_cxx_compat_finish_struct (tree fieldlist) | |
6666 { | |
6667 unsigned int ix; | |
6668 tree x; | |
6669 struct c_binding *b; | |
6670 | |
6671 /* Set the C_TYPE_DEFINED_IN_STRUCT flag for each type defined in | |
6672 the current struct. We do this now at the end of the struct | |
6673 because the flag is used to issue visibility warnings, and we | |
6674 only want to issue those warnings if the type is referenced | |
6675 outside of the struct declaration. */ | |
6676 for (ix = 0; VEC_iterate (tree, struct_parse_info->struct_types, ix, x); ++ix) | |
6677 C_TYPE_DEFINED_IN_STRUCT (x) = 1; | |
6678 | |
6679 /* The TYPEDEFS_SEEN field of STRUCT_PARSE_INFO is a list of | |
6680 typedefs used when declaring fields in this struct. If the name | |
6681 of any of the fields is also a typedef name then the struct would | |
6682 not parse in C++, because the C++ lookup rules say that the | |
6683 typedef name would be looked up in the context of the struct, and | |
6684 would thus be the field rather than the typedef. */ | |
6685 if (!VEC_empty (tree, struct_parse_info->typedefs_seen) | |
6686 && fieldlist != NULL_TREE) | |
6687 { | |
6688 /* Use a pointer_set using the name of the typedef. We can use | |
6689 a pointer_set because identifiers are interned. */ | |
6690 struct pointer_set_t *tset = pointer_set_create (); | |
6691 | |
6692 for (ix = 0; | |
6693 VEC_iterate (tree, struct_parse_info->typedefs_seen, ix, x); | |
6694 ++ix) | |
6695 pointer_set_insert (tset, DECL_NAME (x)); | |
6696 | |
6697 for (x = fieldlist; x != NULL_TREE; x = TREE_CHAIN (x)) | |
6698 { | |
6699 if (pointer_set_contains (tset, DECL_NAME (x))) | |
6700 { | |
6701 warning_at (DECL_SOURCE_LOCATION (x), OPT_Wc___compat, | |
6702 ("using %qD as both field and typedef name is " | |
6703 "invalid in C++"), | |
6704 x); | |
6705 /* FIXME: It would be nice to report the location where | |
6706 the typedef name is used. */ | |
6707 } | |
6708 } | |
6709 | |
6710 pointer_set_destroy (tset); | |
6711 } | |
6712 | |
6713 /* For each field which has a binding and which was not defined in | |
6714 an enclosing struct, clear the in_struct field. */ | |
6715 for (ix = 0; | |
6716 VEC_iterate (c_binding_ptr, struct_parse_info->fields, ix, b); | |
6717 ++ix) | |
6718 b->in_struct = 0; | |
6719 } | |
6720 | |
5536 /* Fill in the fields of a RECORD_TYPE or UNION_TYPE node, T. | 6721 /* Fill in the fields of a RECORD_TYPE or UNION_TYPE node, T. |
6722 LOC is the location of the RECORD_TYPE or UNION_TYPE's definition. | |
5537 FIELDLIST is a chain of FIELD_DECL nodes for the fields. | 6723 FIELDLIST is a chain of FIELD_DECL nodes for the fields. |
5538 ATTRIBUTES are attributes to be applied to the structure. */ | 6724 ATTRIBUTES are attributes to be applied to the structure. |
6725 | |
6726 ENCLOSING_STRUCT_PARSE_INFO is the value of STRUCT_PARSE_INFO when | |
6727 the struct was started. */ | |
5539 | 6728 |
5540 tree | 6729 tree |
5541 finish_struct (tree t, tree fieldlist, tree attributes) | 6730 finish_struct (location_t loc, tree t, tree fieldlist, tree attributes, |
6731 struct c_struct_parse_info *enclosing_struct_parse_info) | |
5542 { | 6732 { |
5543 tree x; | 6733 tree x; |
5544 bool toplevel = file_scope == current_scope; | 6734 bool toplevel = file_scope == current_scope; |
5545 int saw_named_field; | 6735 int saw_named_field; |
5546 | 6736 |
5560 if (x == 0) | 6750 if (x == 0) |
5561 { | 6751 { |
5562 if (TREE_CODE (t) == UNION_TYPE) | 6752 if (TREE_CODE (t) == UNION_TYPE) |
5563 { | 6753 { |
5564 if (fieldlist) | 6754 if (fieldlist) |
5565 pedwarn (input_location, OPT_pedantic, "union has no named members"); | 6755 pedwarn (loc, OPT_pedantic, "union has no named members"); |
5566 else | 6756 else |
5567 pedwarn (input_location, OPT_pedantic, "union has no members"); | 6757 pedwarn (loc, OPT_pedantic, "union has no members"); |
5568 } | 6758 } |
5569 else | 6759 else |
5570 { | 6760 { |
5571 if (fieldlist) | 6761 if (fieldlist) |
5572 pedwarn (input_location, OPT_pedantic, "struct has no named members"); | 6762 pedwarn (loc, OPT_pedantic, "struct has no named members"); |
5573 else | 6763 else |
5574 pedwarn (input_location, OPT_pedantic, "struct has no members"); | 6764 pedwarn (loc, OPT_pedantic, "struct has no members"); |
5575 } | 6765 } |
5576 } | 6766 } |
5577 } | 6767 } |
5578 | 6768 |
5579 /* Install struct as DECL_CONTEXT of each field decl. | 6769 /* Install struct as DECL_CONTEXT of each field decl. |
5633 && TYPE_DOMAIN (TREE_TYPE (x)) != NULL_TREE | 6823 && TYPE_DOMAIN (TREE_TYPE (x)) != NULL_TREE |
5634 && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (x))) == NULL_TREE) | 6824 && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (x))) == NULL_TREE) |
5635 { | 6825 { |
5636 if (TREE_CODE (t) == UNION_TYPE) | 6826 if (TREE_CODE (t) == UNION_TYPE) |
5637 { | 6827 { |
5638 error ("%Jflexible array member in union", x); | 6828 error_at (DECL_SOURCE_LOCATION (x), |
6829 "flexible array member in union"); | |
5639 TREE_TYPE (x) = error_mark_node; | 6830 TREE_TYPE (x) = error_mark_node; |
5640 } | 6831 } |
5641 else if (TREE_CHAIN (x) != NULL_TREE) | 6832 else if (TREE_CHAIN (x) != NULL_TREE) |
5642 { | 6833 { |
5643 error ("%Jflexible array member not at end of struct", x); | 6834 error_at (DECL_SOURCE_LOCATION (x), |
6835 "flexible array member not at end of struct"); | |
5644 TREE_TYPE (x) = error_mark_node; | 6836 TREE_TYPE (x) = error_mark_node; |
5645 } | 6837 } |
5646 else if (!saw_named_field) | 6838 else if (!saw_named_field) |
5647 { | 6839 { |
5648 error ("%Jflexible array member in otherwise empty struct", x); | 6840 error_at (DECL_SOURCE_LOCATION (x), |
6841 "flexible array member in otherwise empty struct"); | |
5649 TREE_TYPE (x) = error_mark_node; | 6842 TREE_TYPE (x) = error_mark_node; |
5650 } | 6843 } |
5651 } | 6844 } |
5652 | 6845 |
5653 if (pedantic && !in_system_header && TREE_CODE (t) == RECORD_TYPE | 6846 if (pedantic && TREE_CODE (t) == RECORD_TYPE |
5654 && flexible_array_type_p (TREE_TYPE (x))) | 6847 && flexible_array_type_p (TREE_TYPE (x))) |
5655 pedwarn (input_location, OPT_pedantic, | 6848 pedwarn (DECL_SOURCE_LOCATION (x), OPT_pedantic, |
5656 "%Jinvalid use of structure with flexible array member", x); | 6849 "invalid use of structure with flexible array member"); |
5657 | 6850 |
5658 if (DECL_NAME (x)) | 6851 if (DECL_NAME (x)) |
5659 saw_named_field = 1; | 6852 saw_named_field = 1; |
5660 } | 6853 } |
5661 | 6854 |
5760 if (TREE_CODE (t) == UNION_TYPE | 6953 if (TREE_CODE (t) == UNION_TYPE |
5761 && TYPE_TRANSPARENT_UNION (t) | 6954 && TYPE_TRANSPARENT_UNION (t) |
5762 && (!TYPE_FIELDS (t) || TYPE_MODE (t) != DECL_MODE (TYPE_FIELDS (t)))) | 6955 && (!TYPE_FIELDS (t) || TYPE_MODE (t) != DECL_MODE (TYPE_FIELDS (t)))) |
5763 { | 6956 { |
5764 TYPE_TRANSPARENT_UNION (t) = 0; | 6957 TYPE_TRANSPARENT_UNION (t) = 0; |
5765 warning (0, "union cannot be made transparent"); | 6958 warning_at (loc, 0, "union cannot be made transparent"); |
5766 } | 6959 } |
5767 | 6960 |
5768 /* If this structure or union completes the type of any previous | 6961 /* If this structure or union completes the type of any previous |
5769 variable declaration, lay it out and output its rtl. */ | 6962 variable declaration, lay it out and output its rtl. */ |
5770 for (x = C_TYPE_INCOMPLETE_VARS (TYPE_MAIN_VARIANT (t)); | 6963 for (x = C_TYPE_INCOMPLETE_VARS (TYPE_MAIN_VARIANT (t)); |
5784 expand_decl (decl); | 6977 expand_decl (decl); |
5785 } | 6978 } |
5786 } | 6979 } |
5787 C_TYPE_INCOMPLETE_VARS (TYPE_MAIN_VARIANT (t)) = 0; | 6980 C_TYPE_INCOMPLETE_VARS (TYPE_MAIN_VARIANT (t)) = 0; |
5788 | 6981 |
6982 /* Update type location to the one of the definition, instead of e.g. | |
6983 a forward declaration. */ | |
6984 if (TYPE_STUB_DECL (t)) | |
6985 DECL_SOURCE_LOCATION (TYPE_STUB_DECL (t)) = loc; | |
6986 | |
5789 /* Finish debugging output for this type. */ | 6987 /* Finish debugging output for this type. */ |
5790 rest_of_type_compilation (t, toplevel); | 6988 rest_of_type_compilation (t, toplevel); |
5791 | 6989 |
5792 /* If we're inside a function proper, i.e. not file-scope and not still | 6990 /* If we're inside a function proper, i.e. not file-scope and not still |
5793 parsing parameters, then arrange for the size of a variable sized type | 6991 parsing parameters, then arrange for the size of a variable sized type |
5794 to be bound now. */ | 6992 to be bound now. */ |
5795 if (cur_stmt_list && variably_modified_type_p (t, NULL_TREE)) | 6993 if (cur_stmt_list && variably_modified_type_p (t, NULL_TREE)) |
5796 add_stmt (build_stmt (DECL_EXPR, build_decl (TYPE_DECL, NULL, t))); | 6994 add_stmt (build_stmt (loc, |
6995 DECL_EXPR, build_decl (loc, TYPE_DECL, NULL, t))); | |
6996 | |
6997 if (warn_cxx_compat) | |
6998 warn_cxx_compat_finish_struct (fieldlist); | |
6999 | |
7000 VEC_free (tree, heap, struct_parse_info->struct_types); | |
7001 VEC_free (c_binding_ptr, heap, struct_parse_info->fields); | |
7002 VEC_free (tree, heap, struct_parse_info->typedefs_seen); | |
7003 XDELETE (struct_parse_info); | |
7004 | |
7005 struct_parse_info = enclosing_struct_parse_info; | |
7006 | |
7007 /* If this struct is defined inside a struct, add it to | |
7008 struct_types. */ | |
7009 if (warn_cxx_compat | |
7010 && struct_parse_info != NULL | |
7011 && !in_sizeof && !in_typeof && !in_alignof) | |
7012 VEC_safe_push (tree, heap, struct_parse_info->struct_types, t); | |
5797 | 7013 |
5798 return t; | 7014 return t; |
5799 } | 7015 } |
5800 | 7016 |
5801 /* Lay out the type T, and its element type, and so on. */ | 7017 /* Lay out the type T, and its element type, and so on. */ |
5808 layout_type (t); | 7024 layout_type (t); |
5809 } | 7025 } |
5810 | 7026 |
5811 /* Begin compiling the definition of an enumeration type. | 7027 /* Begin compiling the definition of an enumeration type. |
5812 NAME is its name (or null if anonymous). | 7028 NAME is its name (or null if anonymous). |
7029 LOC is the enum's location. | |
5813 Returns the type object, as yet incomplete. | 7030 Returns the type object, as yet incomplete. |
5814 Also records info about it so that build_enumerator | 7031 Also records info about it so that build_enumerator |
5815 may be used to declare the individual values as they are read. */ | 7032 may be used to declare the individual values as they are read. */ |
5816 | 7033 |
5817 tree | 7034 tree |
5818 start_enum (struct c_enum_contents *the_enum, tree name) | 7035 start_enum (location_t loc, struct c_enum_contents *the_enum, tree name) |
5819 { | 7036 { |
5820 tree enumtype = 0; | 7037 tree enumtype = NULL_TREE; |
7038 location_t enumloc = UNKNOWN_LOCATION; | |
5821 | 7039 |
5822 /* If this is the real definition for a previous forward reference, | 7040 /* If this is the real definition for a previous forward reference, |
5823 fill in the contents in the same object that used to be the | 7041 fill in the contents in the same object that used to be the |
5824 forward reference. */ | 7042 forward reference. */ |
5825 | 7043 |
5826 if (name != 0) | 7044 if (name != NULL_TREE) |
5827 enumtype = lookup_tag (ENUMERAL_TYPE, name, 1); | 7045 enumtype = lookup_tag (ENUMERAL_TYPE, name, 1, &enumloc); |
5828 | 7046 |
5829 if (enumtype == 0 || TREE_CODE (enumtype) != ENUMERAL_TYPE) | 7047 if (enumtype == 0 || TREE_CODE (enumtype) != ENUMERAL_TYPE) |
5830 { | 7048 { |
5831 enumtype = make_node (ENUMERAL_TYPE); | 7049 enumtype = make_node (ENUMERAL_TYPE); |
5832 pushtag (name, enumtype); | 7050 pushtag (loc, name, enumtype); |
5833 } | 7051 } |
5834 | 7052 |
5835 if (C_TYPE_BEING_DEFINED (enumtype)) | 7053 if (C_TYPE_BEING_DEFINED (enumtype)) |
5836 error ("nested redefinition of %<enum %E%>", name); | 7054 error_at (loc, "nested redefinition of %<enum %E%>", name); |
5837 | 7055 |
5838 C_TYPE_BEING_DEFINED (enumtype) = 1; | 7056 C_TYPE_BEING_DEFINED (enumtype) = 1; |
5839 | 7057 |
5840 if (TYPE_VALUES (enumtype) != 0) | 7058 if (TYPE_VALUES (enumtype) != 0) |
5841 { | 7059 { |
5842 /* This enum is a named one that has been declared already. */ | 7060 /* This enum is a named one that has been declared already. */ |
5843 error ("redeclaration of %<enum %E%>", name); | 7061 error_at (loc, "redeclaration of %<enum %E%>", name); |
7062 if (enumloc != UNKNOWN_LOCATION) | |
7063 inform (enumloc, "originally defined here"); | |
5844 | 7064 |
5845 /* Completely replace its old definition. | 7065 /* Completely replace its old definition. |
5846 The old enumerators remain defined, however. */ | 7066 The old enumerators remain defined, however. */ |
5847 TYPE_VALUES (enumtype) = 0; | 7067 TYPE_VALUES (enumtype) = 0; |
5848 } | 7068 } |
5850 the_enum->enum_next_value = integer_zero_node; | 7070 the_enum->enum_next_value = integer_zero_node; |
5851 the_enum->enum_overflow = 0; | 7071 the_enum->enum_overflow = 0; |
5852 | 7072 |
5853 if (flag_short_enums) | 7073 if (flag_short_enums) |
5854 TYPE_PACKED (enumtype) = 1; | 7074 TYPE_PACKED (enumtype) = 1; |
7075 | |
7076 /* FIXME: This will issue a warning for a use of a type defined | |
7077 within sizeof in a statement expr. This is not terribly serious | |
7078 as C++ doesn't permit statement exprs within sizeof anyhow. */ | |
7079 if (warn_cxx_compat && (in_sizeof || in_typeof || in_alignof)) | |
7080 warning_at (loc, OPT_Wc___compat, | |
7081 "defining type in %qs expression is invalid in C++", | |
7082 (in_sizeof | |
7083 ? "sizeof" | |
7084 : (in_typeof ? "typeof" : "alignof"))); | |
5855 | 7085 |
5856 return enumtype; | 7086 return enumtype; |
5857 } | 7087 } |
5858 | 7088 |
5859 /* After processing and defining all the values of an enumeration type, | 7089 /* After processing and defining all the values of an enumeration type, |
5990 } | 7220 } |
5991 | 7221 |
5992 /* Finish debugging output for this type. */ | 7222 /* Finish debugging output for this type. */ |
5993 rest_of_type_compilation (enumtype, toplevel); | 7223 rest_of_type_compilation (enumtype, toplevel); |
5994 | 7224 |
7225 /* If this enum is defined inside a struct, add it to | |
7226 struct_types. */ | |
7227 if (warn_cxx_compat | |
7228 && struct_parse_info != NULL | |
7229 && !in_sizeof && !in_typeof && !in_alignof) | |
7230 VEC_safe_push (tree, heap, struct_parse_info->struct_types, enumtype); | |
7231 | |
5995 return enumtype; | 7232 return enumtype; |
5996 } | 7233 } |
5997 | 7234 |
5998 /* Build and install a CONST_DECL for one value of the | 7235 /* Build and install a CONST_DECL for one value of the |
5999 current enumeration type (one that was begun with start_enum). | 7236 current enumeration type (one that was begun with start_enum). |
7237 LOC is the location of the enumerator. | |
6000 Return a tree-list containing the CONST_DECL and its value. | 7238 Return a tree-list containing the CONST_DECL and its value. |
6001 Assignment of sequential values by default is handled here. */ | 7239 Assignment of sequential values by default is handled here. */ |
6002 | 7240 |
6003 tree | 7241 tree |
6004 build_enumerator (struct c_enum_contents *the_enum, tree name, tree value, | 7242 build_enumerator (location_t loc, |
6005 location_t value_loc) | 7243 struct c_enum_contents *the_enum, tree name, tree value) |
6006 { | 7244 { |
6007 tree decl, type; | 7245 tree decl, type; |
6008 | 7246 |
6009 /* Validate and default VALUE. */ | 7247 /* Validate and default VALUE. */ |
6010 | 7248 |
6012 { | 7250 { |
6013 /* Don't issue more errors for error_mark_node (i.e. an | 7251 /* Don't issue more errors for error_mark_node (i.e. an |
6014 undeclared identifier) - just ignore the value expression. */ | 7252 undeclared identifier) - just ignore the value expression. */ |
6015 if (value == error_mark_node) | 7253 if (value == error_mark_node) |
6016 value = 0; | 7254 value = 0; |
6017 else if (!INTEGRAL_TYPE_P (TREE_TYPE (value)) | 7255 else if (!INTEGRAL_TYPE_P (TREE_TYPE (value))) |
6018 || TREE_CODE (value) != INTEGER_CST) | 7256 { |
6019 { | 7257 error_at (loc, "enumerator value for %qE is not an integer constant", |
6020 error ("enumerator value for %qE is not an integer constant", name); | 7258 name); |
6021 value = 0; | 7259 value = 0; |
6022 } | 7260 } |
6023 else | 7261 else |
6024 { | 7262 { |
6025 value = default_conversion (value); | 7263 if (TREE_CODE (value) != INTEGER_CST) |
6026 constant_expression_warning (value); | 7264 { |
7265 value = c_fully_fold (value, false, NULL); | |
7266 if (TREE_CODE (value) == INTEGER_CST) | |
7267 pedwarn (loc, OPT_pedantic, | |
7268 "enumerator value for %qE is not an integer " | |
7269 "constant expression", name); | |
7270 } | |
7271 if (TREE_CODE (value) != INTEGER_CST) | |
7272 { | |
7273 error ("enumerator value for %qE is not an integer constant", | |
7274 name); | |
7275 value = 0; | |
7276 } | |
7277 else | |
7278 { | |
7279 value = default_conversion (value); | |
7280 constant_expression_warning (value); | |
7281 } | |
6027 } | 7282 } |
6028 } | 7283 } |
6029 | 7284 |
6030 /* Default based on previous value. */ | 7285 /* Default based on previous value. */ |
6031 /* It should no longer be possible to have NON_LVALUE_EXPR | 7286 /* It should no longer be possible to have NON_LVALUE_EXPR |
6032 in the default. */ | 7287 in the default. */ |
6033 if (value == 0) | 7288 if (value == 0) |
6034 { | 7289 { |
6035 value = the_enum->enum_next_value; | 7290 value = the_enum->enum_next_value; |
6036 if (the_enum->enum_overflow) | 7291 if (the_enum->enum_overflow) |
6037 error ("overflow in enumeration values"); | 7292 error_at (loc, "overflow in enumeration values"); |
6038 } | 7293 } |
6039 /* Even though the underlying type of an enum is unspecified, the | 7294 /* Even though the underlying type of an enum is unspecified, the |
6040 type of enumeration constants is explicitly defined as int | 7295 type of enumeration constants is explicitly defined as int |
6041 (6.4.4.3/2 in the C99 Standard). GCC allows any integer type as | 7296 (6.4.4.3/2 in the C99 Standard). GCC allows any integer type as |
6042 an extension. */ | 7297 an extension. */ |
6043 else if (!int_fits_type_p (value, integer_type_node)) | 7298 else if (!int_fits_type_p (value, integer_type_node)) |
6044 pedwarn (value_loc, OPT_pedantic, | 7299 pedwarn (loc, OPT_pedantic, |
6045 "ISO C restricts enumerator values to range of %<int%>"); | 7300 "ISO C restricts enumerator values to range of %<int%>"); |
6046 | 7301 |
6047 /* The ISO C Standard mandates enumerators to have type int, even | 7302 /* The ISO C Standard mandates enumerators to have type int, even |
6048 though the underlying type of an enum type is unspecified. | 7303 though the underlying type of an enum type is unspecified. |
6049 However, GCC allows enumerators of any integer type as an | 7304 However, GCC allows enumerators of any integer type as an |
6070 TYPE_PRECISION (integer_type_node)), | 7325 TYPE_PRECISION (integer_type_node)), |
6071 (TYPE_PRECISION (type) | 7326 (TYPE_PRECISION (type) |
6072 >= TYPE_PRECISION (integer_type_node) | 7327 >= TYPE_PRECISION (integer_type_node) |
6073 && TYPE_UNSIGNED (type))); | 7328 && TYPE_UNSIGNED (type))); |
6074 | 7329 |
6075 decl = build_decl (CONST_DECL, name, type); | 7330 decl = build_decl (loc, CONST_DECL, name, type); |
6076 DECL_INITIAL (decl) = convert (type, value); | 7331 DECL_INITIAL (decl) = convert (type, value); |
6077 pushdecl (decl); | 7332 pushdecl (decl); |
6078 | 7333 |
6079 return tree_cons (decl, value, NULL_TREE); | 7334 return tree_cons (decl, value, NULL_TREE); |
6080 } | 7335 } |
6096 start_function (struct c_declspecs *declspecs, struct c_declarator *declarator, | 7351 start_function (struct c_declspecs *declspecs, struct c_declarator *declarator, |
6097 tree attributes) | 7352 tree attributes) |
6098 { | 7353 { |
6099 tree decl1, old_decl; | 7354 tree decl1, old_decl; |
6100 tree restype, resdecl; | 7355 tree restype, resdecl; |
6101 struct c_label_context_se *nstack_se; | 7356 location_t loc; |
6102 struct c_label_context_vm *nstack_vm; | |
6103 | 7357 |
6104 current_function_returns_value = 0; /* Assume, until we see it does. */ | 7358 current_function_returns_value = 0; /* Assume, until we see it does. */ |
6105 current_function_returns_null = 0; | 7359 current_function_returns_null = 0; |
6106 current_function_returns_abnormally = 0; | 7360 current_function_returns_abnormally = 0; |
6107 warn_about_return_type = 0; | 7361 warn_about_return_type = 0; |
6108 c_switch_stack = NULL; | 7362 c_switch_stack = NULL; |
6109 | 7363 |
6110 nstack_se = XOBNEW (&parser_obstack, struct c_label_context_se); | |
6111 nstack_se->labels_def = NULL; | |
6112 nstack_se->labels_used = NULL; | |
6113 nstack_se->next = label_context_stack_se; | |
6114 label_context_stack_se = nstack_se; | |
6115 | |
6116 nstack_vm = XOBNEW (&parser_obstack, struct c_label_context_vm); | |
6117 nstack_vm->labels_def = NULL; | |
6118 nstack_vm->labels_used = NULL; | |
6119 nstack_vm->scope = 0; | |
6120 nstack_vm->next = label_context_stack_vm; | |
6121 label_context_stack_vm = nstack_vm; | |
6122 | |
6123 /* Indicate no valid break/continue context by setting these variables | 7364 /* Indicate no valid break/continue context by setting these variables |
6124 to some non-null, non-label value. We'll notice and emit the proper | 7365 to some non-null, non-label value. We'll notice and emit the proper |
6125 error message in c_finish_bc_stmt. */ | 7366 error message in c_finish_bc_stmt. */ |
6126 c_break_label = c_cont_label = size_zero_node; | 7367 c_break_label = c_cont_label = size_zero_node; |
6127 | 7368 |
6128 decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, true, NULL, | 7369 decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, true, NULL, |
6129 &attributes, DEPRECATED_NORMAL); | 7370 &attributes, NULL, NULL, DEPRECATED_NORMAL); |
6130 | 7371 |
6131 /* If the declarator is not suitable for a function definition, | 7372 /* If the declarator is not suitable for a function definition, |
6132 cause a syntax error. */ | 7373 cause a syntax error. */ |
6133 if (decl1 == 0) | 7374 if (decl1 == 0) |
6134 { | 7375 return 0; |
6135 label_context_stack_se = label_context_stack_se->next; | 7376 |
6136 label_context_stack_vm = label_context_stack_vm->next; | 7377 loc = DECL_SOURCE_LOCATION (decl1); |
6137 return 0; | |
6138 } | |
6139 | 7378 |
6140 decl_attributes (&decl1, attributes, 0); | 7379 decl_attributes (&decl1, attributes, 0); |
6141 | 7380 |
6142 if (DECL_DECLARED_INLINE_P (decl1) | 7381 if (DECL_DECLARED_INLINE_P (decl1) |
6143 && DECL_UNINLINABLE (decl1) | 7382 && DECL_UNINLINABLE (decl1) |
6144 && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl1))) | 7383 && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl1))) |
6145 warning (OPT_Wattributes, "inline function %q+D given attribute noinline", | 7384 warning_at (loc, OPT_Wattributes, |
6146 decl1); | 7385 "inline function %qD given attribute noinline", |
7386 decl1); | |
6147 | 7387 |
6148 /* Handle gnu_inline attribute. */ | 7388 /* Handle gnu_inline attribute. */ |
6149 if (declspecs->inline_p | 7389 if (declspecs->inline_p |
6150 && !flag_gnu89_inline | 7390 && !flag_gnu89_inline |
6151 && TREE_CODE (decl1) == FUNCTION_DECL | 7391 && TREE_CODE (decl1) == FUNCTION_DECL |
6158 | 7398 |
6159 announce_function (decl1); | 7399 announce_function (decl1); |
6160 | 7400 |
6161 if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl1)))) | 7401 if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl1)))) |
6162 { | 7402 { |
6163 error ("return type is an incomplete type"); | 7403 error_at (loc, "return type is an incomplete type"); |
6164 /* Make it return void instead. */ | 7404 /* Make it return void instead. */ |
6165 TREE_TYPE (decl1) | 7405 TREE_TYPE (decl1) |
6166 = build_function_type (void_type_node, | 7406 = build_function_type (void_type_node, |
6167 TYPE_ARG_TYPES (TREE_TYPE (decl1))); | 7407 TYPE_ARG_TYPES (TREE_TYPE (decl1))); |
6168 } | 7408 } |
6169 | 7409 |
6170 if (warn_about_return_type) | 7410 if (warn_about_return_type) |
6171 pedwarn_c99 (input_location, flag_isoc99 ? 0 | 7411 pedwarn_c99 (loc, flag_isoc99 ? 0 |
6172 : (warn_return_type ? OPT_Wreturn_type : OPT_Wimplicit_int), | 7412 : (warn_return_type ? OPT_Wreturn_type : OPT_Wimplicit_int), |
6173 "return type defaults to %<int%>"); | 7413 "return type defaults to %<int%>"); |
6174 | 7414 |
6175 /* Make the init_value nonzero so pushdecl knows this is not tentative. | 7415 /* Make the init_value nonzero so pushdecl knows this is not tentative. |
6176 error_mark_node is replaced below (in pop_scope) with the BLOCK. */ | 7416 error_mark_node is replaced below (in pop_scope) with the BLOCK. */ |
6212 break; | 7452 break; |
6213 if (b) | 7453 if (b) |
6214 { | 7454 { |
6215 tree ext_decl, ext_type; | 7455 tree ext_decl, ext_type; |
6216 ext_decl = b->decl; | 7456 ext_decl = b->decl; |
6217 ext_type = b->type ? b->type : TREE_TYPE (ext_decl); | 7457 ext_type = b->u.type ? b->u.type : TREE_TYPE (ext_decl); |
6218 if (TREE_CODE (ext_type) == FUNCTION_TYPE | 7458 if (TREE_CODE (ext_type) == FUNCTION_TYPE |
6219 && comptypes (TREE_TYPE (TREE_TYPE (decl1)), | 7459 && comptypes (TREE_TYPE (TREE_TYPE (decl1)), |
6220 TREE_TYPE (ext_type))) | 7460 TREE_TYPE (ext_type))) |
6221 { | 7461 { |
6222 current_function_prototype_locus | 7462 current_function_prototype_locus |
6233 /* Optionally warn of old-fashioned def with no previous prototype. */ | 7473 /* Optionally warn of old-fashioned def with no previous prototype. */ |
6234 if (warn_strict_prototypes | 7474 if (warn_strict_prototypes |
6235 && old_decl != error_mark_node | 7475 && old_decl != error_mark_node |
6236 && TYPE_ARG_TYPES (TREE_TYPE (decl1)) == 0 | 7476 && TYPE_ARG_TYPES (TREE_TYPE (decl1)) == 0 |
6237 && C_DECL_ISNT_PROTOTYPE (old_decl)) | 7477 && C_DECL_ISNT_PROTOTYPE (old_decl)) |
6238 warning (OPT_Wstrict_prototypes, | 7478 warning_at (loc, OPT_Wstrict_prototypes, |
6239 "function declaration isn%'t a prototype"); | 7479 "function declaration isn%'t a prototype"); |
6240 /* Optionally warn of any global def with no previous prototype. */ | 7480 /* Optionally warn of any global def with no previous prototype. */ |
6241 else if (warn_missing_prototypes | 7481 else if (warn_missing_prototypes |
6242 && old_decl != error_mark_node | 7482 && old_decl != error_mark_node |
6243 && TREE_PUBLIC (decl1) | 7483 && TREE_PUBLIC (decl1) |
6244 && !MAIN_NAME_P (DECL_NAME (decl1)) | 7484 && !MAIN_NAME_P (DECL_NAME (decl1)) |
6245 && C_DECL_ISNT_PROTOTYPE (old_decl)) | 7485 && C_DECL_ISNT_PROTOTYPE (old_decl)) |
6246 warning (OPT_Wmissing_prototypes, "no previous prototype for %q+D", decl1); | 7486 warning_at (loc, OPT_Wmissing_prototypes, |
7487 "no previous prototype for %qD", decl1); | |
6247 /* Optionally warn of any def with no previous prototype | 7488 /* Optionally warn of any def with no previous prototype |
6248 if the function has already been used. */ | 7489 if the function has already been used. */ |
6249 else if (warn_missing_prototypes | 7490 else if (warn_missing_prototypes |
6250 && old_decl != 0 | 7491 && old_decl != 0 |
6251 && old_decl != error_mark_node | 7492 && old_decl != error_mark_node |
6252 && TREE_USED (old_decl) | 7493 && TREE_USED (old_decl) |
6253 && TYPE_ARG_TYPES (TREE_TYPE (old_decl)) == 0) | 7494 && TYPE_ARG_TYPES (TREE_TYPE (old_decl)) == 0) |
6254 warning (OPT_Wmissing_prototypes, | 7495 warning_at (loc, OPT_Wmissing_prototypes, |
6255 "%q+D was used with no prototype before its definition", decl1); | 7496 "%qD was used with no prototype before its definition", decl1); |
6256 /* Optionally warn of any global def with no previous declaration. */ | 7497 /* Optionally warn of any global def with no previous declaration. */ |
6257 else if (warn_missing_declarations | 7498 else if (warn_missing_declarations |
6258 && TREE_PUBLIC (decl1) | 7499 && TREE_PUBLIC (decl1) |
6259 && old_decl == 0 | 7500 && old_decl == 0 |
6260 && !MAIN_NAME_P (DECL_NAME (decl1))) | 7501 && !MAIN_NAME_P (DECL_NAME (decl1))) |
6261 warning (OPT_Wmissing_declarations, "no previous declaration for %q+D", | 7502 warning_at (loc, OPT_Wmissing_declarations, |
6262 decl1); | 7503 "no previous declaration for %qD", |
7504 decl1); | |
6263 /* Optionally warn of any def with no previous declaration | 7505 /* Optionally warn of any def with no previous declaration |
6264 if the function has already been used. */ | 7506 if the function has already been used. */ |
6265 else if (warn_missing_declarations | 7507 else if (warn_missing_declarations |
6266 && old_decl != 0 | 7508 && old_decl != 0 |
6267 && old_decl != error_mark_node | 7509 && old_decl != error_mark_node |
6268 && TREE_USED (old_decl) | 7510 && TREE_USED (old_decl) |
6269 && C_DECL_IMPLICIT (old_decl)) | 7511 && C_DECL_IMPLICIT (old_decl)) |
6270 warning (OPT_Wmissing_declarations, | 7512 warning_at (loc, OPT_Wmissing_declarations, |
6271 "%q+D was used with no declaration before its definition", decl1); | 7513 "%qD was used with no declaration before its definition", decl1); |
6272 | 7514 |
6273 /* This function exists in static storage. | 7515 /* This function exists in static storage. |
6274 (This does not mean `static' in the C sense!) */ | 7516 (This does not mean `static' in the C sense!) */ |
6275 TREE_STATIC (decl1) = 1; | 7517 TREE_STATIC (decl1) = 1; |
6276 | 7518 |
6289 /* Warn for unlikely, improbable, or stupid declarations of `main'. */ | 7531 /* Warn for unlikely, improbable, or stupid declarations of `main'. */ |
6290 if (warn_main && MAIN_NAME_P (DECL_NAME (decl1))) | 7532 if (warn_main && MAIN_NAME_P (DECL_NAME (decl1))) |
6291 { | 7533 { |
6292 if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (decl1))) | 7534 if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (decl1))) |
6293 != integer_type_node) | 7535 != integer_type_node) |
6294 pedwarn (input_location, OPT_Wmain, "return type of %q+D is not %<int%>", decl1); | 7536 pedwarn (loc, OPT_Wmain, "return type of %qD is not %<int%>", decl1); |
6295 | 7537 |
6296 check_main_parameter_types (decl1); | 7538 check_main_parameter_types (decl1); |
6297 | 7539 |
6298 if (!TREE_PUBLIC (decl1)) | 7540 if (!TREE_PUBLIC (decl1)) |
6299 pedwarn (input_location, OPT_Wmain, "%q+D is normally a non-static function", decl1); | 7541 pedwarn (loc, OPT_Wmain, |
7542 "%qD is normally a non-static function", decl1); | |
6300 } | 7543 } |
6301 | 7544 |
6302 /* Record the decl so that the function name is defined. | 7545 /* Record the decl so that the function name is defined. |
6303 If we already have a decl for this name, and it is a FUNCTION_DECL, | 7546 If we already have a decl for this name, and it is a FUNCTION_DECL, |
6304 use the old decl. */ | 7547 use the old decl. */ |
6307 | 7550 |
6308 push_scope (); | 7551 push_scope (); |
6309 declare_parm_level (); | 7552 declare_parm_level (); |
6310 | 7553 |
6311 restype = TREE_TYPE (TREE_TYPE (current_function_decl)); | 7554 restype = TREE_TYPE (TREE_TYPE (current_function_decl)); |
6312 resdecl = build_decl (RESULT_DECL, NULL_TREE, restype); | 7555 resdecl = build_decl (loc, RESULT_DECL, NULL_TREE, restype); |
6313 DECL_ARTIFICIAL (resdecl) = 1; | 7556 DECL_ARTIFICIAL (resdecl) = 1; |
6314 DECL_IGNORED_P (resdecl) = 1; | 7557 DECL_IGNORED_P (resdecl) = 1; |
6315 DECL_RESULT (current_function_decl) = resdecl; | 7558 DECL_RESULT (current_function_decl) = resdecl; |
6316 | 7559 |
6317 start_fname_decls (); | 7560 start_fname_decls (); |
6328 { | 7571 { |
6329 tree decl; | 7572 tree decl; |
6330 | 7573 |
6331 if (current_scope->bindings) | 7574 if (current_scope->bindings) |
6332 { | 7575 { |
6333 error ("%Jold-style parameter declarations in prototyped " | 7576 error_at (DECL_SOURCE_LOCATION (fndecl), |
6334 "function definition", fndecl); | 7577 "old-style parameter declarations in prototyped " |
7578 "function definition"); | |
6335 | 7579 |
6336 /* Get rid of the old-style declarations. */ | 7580 /* Get rid of the old-style declarations. */ |
6337 pop_scope (); | 7581 pop_scope (); |
6338 push_scope (); | 7582 push_scope (); |
6339 } | 7583 } |
6341 warning if we got here because ARG_INFO_TYPES was error_mark_node | 7585 warning if we got here because ARG_INFO_TYPES was error_mark_node |
6342 (this happens when a function definition has just an ellipsis in | 7586 (this happens when a function definition has just an ellipsis in |
6343 its parameter list). */ | 7587 its parameter list). */ |
6344 else if (!in_system_header && !current_function_scope | 7588 else if (!in_system_header && !current_function_scope |
6345 && arg_info->types != error_mark_node) | 7589 && arg_info->types != error_mark_node) |
6346 warning (OPT_Wtraditional, | 7590 warning_at (DECL_SOURCE_LOCATION (fndecl), OPT_Wtraditional, |
6347 "%Jtraditional C rejects ISO C style function definitions", | 7591 "traditional C rejects ISO C style function definitions"); |
6348 fndecl); | |
6349 | 7592 |
6350 /* Now make all the parameter declarations visible in the function body. | 7593 /* Now make all the parameter declarations visible in the function body. |
6351 We can bypass most of the grunt work of pushdecl. */ | 7594 We can bypass most of the grunt work of pushdecl. */ |
6352 for (decl = arg_info->parms; decl; decl = TREE_CHAIN (decl)) | 7595 for (decl = arg_info->parms; decl; decl = TREE_CHAIN (decl)) |
6353 { | 7596 { |
6354 DECL_CONTEXT (decl) = current_function_decl; | 7597 DECL_CONTEXT (decl) = current_function_decl; |
6355 if (DECL_NAME (decl)) | 7598 if (DECL_NAME (decl)) |
6356 { | 7599 { |
6357 bind (DECL_NAME (decl), decl, current_scope, | 7600 bind (DECL_NAME (decl), decl, current_scope, |
6358 /*invisible=*/false, /*nested=*/false); | 7601 /*invisible=*/false, /*nested=*/false, |
7602 UNKNOWN_LOCATION); | |
6359 if (!TREE_USED (decl)) | 7603 if (!TREE_USED (decl)) |
6360 warn_if_shadowing (decl); | 7604 warn_if_shadowing (decl); |
6361 } | 7605 } |
6362 else | 7606 else |
6363 error ("%Jparameter name omitted", decl); | 7607 error_at (DECL_SOURCE_LOCATION (decl), "parameter name omitted"); |
6364 } | 7608 } |
6365 | 7609 |
6366 /* Record the parameter list in the function declaration. */ | 7610 /* Record the parameter list in the function declaration. */ |
6367 DECL_ARGUMENTS (fndecl) = arg_info->parms; | 7611 DECL_ARGUMENTS (fndecl) = arg_info->parms; |
6368 | 7612 |
6370 for (decl = arg_info->others; decl; decl = TREE_CHAIN (decl)) | 7614 for (decl = arg_info->others; decl; decl = TREE_CHAIN (decl)) |
6371 { | 7615 { |
6372 DECL_CONTEXT (decl) = current_function_decl; | 7616 DECL_CONTEXT (decl) = current_function_decl; |
6373 if (DECL_NAME (decl)) | 7617 if (DECL_NAME (decl)) |
6374 bind (DECL_NAME (decl), decl, current_scope, | 7618 bind (DECL_NAME (decl), decl, current_scope, |
6375 /*invisible=*/false, /*nested=*/false); | 7619 /*invisible=*/false, /*nested=*/false, UNKNOWN_LOCATION); |
6376 } | 7620 } |
6377 | 7621 |
6378 /* And all the tag declarations. */ | 7622 /* And all the tag declarations. */ |
6379 for (decl = arg_info->tags; decl; decl = TREE_CHAIN (decl)) | 7623 for (decl = arg_info->tags; decl; decl = TREE_CHAIN (decl)) |
6380 if (TREE_PURPOSE (decl)) | 7624 if (TREE_PURPOSE (decl)) |
6381 bind (TREE_PURPOSE (decl), TREE_VALUE (decl), current_scope, | 7625 bind (TREE_PURPOSE (decl), TREE_VALUE (decl), current_scope, |
6382 /*invisible=*/false, /*nested=*/false); | 7626 /*invisible=*/false, /*nested=*/false, UNKNOWN_LOCATION); |
6383 } | 7627 } |
6384 | 7628 |
6385 /* Subroutine of store_parm_decls which handles old-style function | 7629 /* Subroutine of store_parm_decls which handles old-style function |
6386 definitions (separate parameter list and declarations). */ | 7630 definitions (separate parameter list and declarations). */ |
6387 | 7631 |
6392 tree parm, decl, last; | 7636 tree parm, decl, last; |
6393 tree parmids = arg_info->parms; | 7637 tree parmids = arg_info->parms; |
6394 struct pointer_set_t *seen_args = pointer_set_create (); | 7638 struct pointer_set_t *seen_args = pointer_set_create (); |
6395 | 7639 |
6396 if (!in_system_header) | 7640 if (!in_system_header) |
6397 warning (OPT_Wold_style_definition, "%Jold-style function definition", | 7641 warning_at (DECL_SOURCE_LOCATION (fndecl), |
6398 fndecl); | 7642 OPT_Wold_style_definition, "old-style function definition"); |
6399 | 7643 |
6400 /* Match each formal parameter name with its declaration. Save each | 7644 /* Match each formal parameter name with its declaration. Save each |
6401 decl in the appropriate TREE_PURPOSE slot of the parmids chain. */ | 7645 decl in the appropriate TREE_PURPOSE slot of the parmids chain. */ |
6402 for (parm = parmids; parm; parm = TREE_CHAIN (parm)) | 7646 for (parm = parmids; parm; parm = TREE_CHAIN (parm)) |
6403 { | 7647 { |
6404 if (TREE_VALUE (parm) == 0) | 7648 if (TREE_VALUE (parm) == 0) |
6405 { | 7649 { |
6406 error ("%Jparameter name missing from parameter list", fndecl); | 7650 error_at (DECL_SOURCE_LOCATION (fndecl), |
7651 "parameter name missing from parameter list"); | |
6407 TREE_PURPOSE (parm) = 0; | 7652 TREE_PURPOSE (parm) = 0; |
6408 continue; | 7653 continue; |
6409 } | 7654 } |
6410 | 7655 |
6411 b = I_SYMBOL_BINDING (TREE_VALUE (parm)); | 7656 b = I_SYMBOL_BINDING (TREE_VALUE (parm)); |
6412 if (b && B_IN_CURRENT_SCOPE (b)) | 7657 if (b && B_IN_CURRENT_SCOPE (b)) |
6413 { | 7658 { |
6414 decl = b->decl; | 7659 decl = b->decl; |
6415 /* If we got something other than a PARM_DECL it is an error. */ | 7660 /* If we got something other than a PARM_DECL it is an error. */ |
6416 if (TREE_CODE (decl) != PARM_DECL) | 7661 if (TREE_CODE (decl) != PARM_DECL) |
6417 error ("%q+D declared as a non-parameter", decl); | 7662 error_at (DECL_SOURCE_LOCATION (decl), |
7663 "%qD declared as a non-parameter", decl); | |
6418 /* If the declaration is already marked, we have a duplicate | 7664 /* If the declaration is already marked, we have a duplicate |
6419 name. Complain and ignore the duplicate. */ | 7665 name. Complain and ignore the duplicate. */ |
6420 else if (pointer_set_contains (seen_args, decl)) | 7666 else if (pointer_set_contains (seen_args, decl)) |
6421 { | 7667 { |
6422 error ("multiple parameters named %q+D", decl); | 7668 error_at (DECL_SOURCE_LOCATION (decl), |
7669 "multiple parameters named %qD", decl); | |
6423 TREE_PURPOSE (parm) = 0; | 7670 TREE_PURPOSE (parm) = 0; |
6424 continue; | 7671 continue; |
6425 } | 7672 } |
6426 /* If the declaration says "void", complain and turn it into | 7673 /* If the declaration says "void", complain and turn it into |
6427 an int. */ | 7674 an int. */ |
6428 else if (VOID_TYPE_P (TREE_TYPE (decl))) | 7675 else if (VOID_TYPE_P (TREE_TYPE (decl))) |
6429 { | 7676 { |
6430 error ("parameter %q+D declared with void type", decl); | 7677 error_at (DECL_SOURCE_LOCATION (decl), |
7678 "parameter %qD declared with void type", decl); | |
6431 TREE_TYPE (decl) = integer_type_node; | 7679 TREE_TYPE (decl) = integer_type_node; |
6432 DECL_ARG_TYPE (decl) = integer_type_node; | 7680 DECL_ARG_TYPE (decl) = integer_type_node; |
6433 layout_decl (decl, 0); | 7681 layout_decl (decl, 0); |
6434 } | 7682 } |
6435 warn_if_shadowing (decl); | 7683 warn_if_shadowing (decl); |
6436 } | 7684 } |
6437 /* If no declaration found, default to int. */ | 7685 /* If no declaration found, default to int. */ |
6438 else | 7686 else |
6439 { | 7687 { |
6440 decl = build_decl (PARM_DECL, TREE_VALUE (parm), integer_type_node); | 7688 /* FIXME diagnostics: This should be the location of the argument, |
7689 not the FNDECL. E.g., for an old-style declaration | |
7690 | |
7691 int f10(v) { blah; } | |
7692 | |
7693 We should use the location of the V, not the F10. | |
7694 Unfortunately, the V is an IDENTIFIER_NODE which has no | |
7695 location. In the future we need locations for c_arg_info | |
7696 entries. | |
7697 | |
7698 See gcc.dg/Wshadow-3.c for an example of this problem. */ | |
7699 decl = build_decl (DECL_SOURCE_LOCATION (fndecl), | |
7700 PARM_DECL, TREE_VALUE (parm), integer_type_node); | |
6441 DECL_ARG_TYPE (decl) = TREE_TYPE (decl); | 7701 DECL_ARG_TYPE (decl) = TREE_TYPE (decl); |
6442 DECL_SOURCE_LOCATION (decl) = DECL_SOURCE_LOCATION (fndecl); | |
6443 pushdecl (decl); | 7702 pushdecl (decl); |
6444 warn_if_shadowing (decl); | 7703 warn_if_shadowing (decl); |
6445 | 7704 |
6446 if (flag_isoc99) | 7705 if (flag_isoc99) |
6447 pedwarn (input_location, 0, "type of %q+D defaults to %<int%>", decl); | 7706 pedwarn (DECL_SOURCE_LOCATION (decl), |
6448 else | 7707 0, "type of %qD defaults to %<int%>", decl); |
6449 warning (OPT_Wmissing_parameter_type, "type of %q+D defaults to %<int%>", decl); | 7708 else |
7709 warning_at (DECL_SOURCE_LOCATION (decl), | |
7710 OPT_Wmissing_parameter_type, | |
7711 "type of %qD defaults to %<int%>", decl); | |
6450 } | 7712 } |
6451 | 7713 |
6452 TREE_PURPOSE (parm) = decl; | 7714 TREE_PURPOSE (parm) = decl; |
6453 pointer_set_insert (seen_args, decl); | 7715 pointer_set_insert (seen_args, decl); |
6454 } | 7716 } |
6463 continue; | 7725 continue; |
6464 | 7726 |
6465 if (TREE_TYPE (parm) != error_mark_node | 7727 if (TREE_TYPE (parm) != error_mark_node |
6466 && !COMPLETE_TYPE_P (TREE_TYPE (parm))) | 7728 && !COMPLETE_TYPE_P (TREE_TYPE (parm))) |
6467 { | 7729 { |
6468 error ("parameter %q+D has incomplete type", parm); | 7730 error_at (DECL_SOURCE_LOCATION (parm), |
7731 "parameter %qD has incomplete type", parm); | |
6469 TREE_TYPE (parm) = error_mark_node; | 7732 TREE_TYPE (parm) = error_mark_node; |
6470 } | 7733 } |
6471 | 7734 |
6472 if (!pointer_set_contains (seen_args, parm)) | 7735 if (!pointer_set_contains (seen_args, parm)) |
6473 { | 7736 { |
6474 error ("declaration for parameter %q+D but no such parameter", parm); | 7737 error_at (DECL_SOURCE_LOCATION (parm), |
7738 "declaration for parameter %qD but no such parameter", | |
7739 parm); | |
6475 | 7740 |
6476 /* Pretend the parameter was not missing. | 7741 /* Pretend the parameter was not missing. |
6477 This gets us to a standard state and minimizes | 7742 This gets us to a standard state and minimizes |
6478 further error messages. */ | 7743 further error messages. */ |
6479 parmids = chainon (parmids, tree_cons (parm, 0, 0)); | 7744 parmids = chainon (parmids, tree_cons (parm, 0, 0)); |
6519 { | 7784 { |
6520 if (parm == 0 || type == 0 | 7785 if (parm == 0 || type == 0 |
6521 || TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node) | 7786 || TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node) |
6522 { | 7787 { |
6523 if (current_function_prototype_built_in) | 7788 if (current_function_prototype_built_in) |
6524 warning (0, "number of arguments doesn%'t match " | 7789 warning_at (DECL_SOURCE_LOCATION (fndecl), |
6525 "built-in prototype"); | 7790 0, "number of arguments doesn%'t match " |
7791 "built-in prototype"); | |
6526 else | 7792 else |
6527 { | 7793 { |
6528 error ("number of arguments doesn%'t match prototype"); | 7794 /* FIXME diagnostics: This should be the location of |
6529 error ("%Hprototype declaration", | 7795 FNDECL, but there is bug when a prototype is |
6530 ¤t_function_prototype_locus); | 7796 declared inside function context, but defined |
7797 outside of it (e.g., gcc.dg/pr15698-2.c). In | |
7798 which case FNDECL gets the location of the | |
7799 prototype, not the definition. */ | |
7800 error_at (input_location, | |
7801 "number of arguments doesn%'t match prototype"); | |
7802 | |
7803 error_at (current_function_prototype_locus, | |
7804 "prototype declaration"); | |
6531 } | 7805 } |
6532 break; | 7806 break; |
6533 } | 7807 } |
6534 /* Type for passing arg must be consistent with that | 7808 /* Type for passing arg must be consistent with that |
6535 declared for the arg. ISO C says we take the unqualified | 7809 declared for the arg. ISO C says we take the unqualified |
6558 /* ??? Is it possible to get here with a | 7832 /* ??? Is it possible to get here with a |
6559 built-in prototype or will it always have | 7833 built-in prototype or will it always have |
6560 been diagnosed as conflicting with an | 7834 been diagnosed as conflicting with an |
6561 old-style definition and discarded? */ | 7835 old-style definition and discarded? */ |
6562 if (current_function_prototype_built_in) | 7836 if (current_function_prototype_built_in) |
6563 warning (OPT_pedantic, "promoted argument %qD " | 7837 warning_at (DECL_SOURCE_LOCATION (parm), |
6564 "doesn%'t match built-in prototype", parm); | 7838 OPT_pedantic, "promoted argument %qD " |
7839 "doesn%'t match built-in prototype", parm); | |
6565 else | 7840 else |
6566 { | 7841 { |
6567 pedwarn (input_location, OPT_pedantic, "promoted argument %qD " | 7842 pedwarn (DECL_SOURCE_LOCATION (parm), |
7843 OPT_pedantic, "promoted argument %qD " | |
6568 "doesn%'t match prototype", parm); | 7844 "doesn%'t match prototype", parm); |
6569 pedwarn (current_function_prototype_locus, OPT_pedantic, | 7845 pedwarn (current_function_prototype_locus, OPT_pedantic, |
6570 "prototype declaration"); | 7846 "prototype declaration"); |
6571 } | 7847 } |
6572 } | 7848 } |
6573 else | 7849 else |
6574 { | 7850 { |
6575 if (current_function_prototype_built_in) | 7851 if (current_function_prototype_built_in) |
6576 warning (0, "argument %qD doesn%'t match " | 7852 warning_at (DECL_SOURCE_LOCATION (parm), |
6577 "built-in prototype", parm); | 7853 0, "argument %qD doesn%'t match " |
7854 "built-in prototype", parm); | |
6578 else | 7855 else |
6579 { | 7856 { |
6580 error ("argument %qD doesn%'t match prototype", parm); | 7857 error_at (DECL_SOURCE_LOCATION (parm), |
6581 error ("%Hprototype declaration", | 7858 "argument %qD doesn%'t match prototype", parm); |
6582 ¤t_function_prototype_locus); | 7859 error_at (current_function_prototype_locus, |
7860 "prototype declaration"); | |
6583 } | 7861 } |
6584 } | 7862 } |
6585 } | 7863 } |
6586 } | 7864 } |
6587 TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = 0; | 7865 TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = 0; |
6693 We haven't necessarily assigned RTL to all variables yet, so it's | 7971 We haven't necessarily assigned RTL to all variables yet, so it's |
6694 not safe to try to expand expressions involving them. */ | 7972 not safe to try to expand expressions involving them. */ |
6695 cfun->dont_save_pending_sizes_p = 1; | 7973 cfun->dont_save_pending_sizes_p = 1; |
6696 } | 7974 } |
6697 | 7975 |
6698 /* Emit diagnostics that require gimple input for detection. Operate on | |
6699 FNDECL and all its nested functions. */ | |
6700 | |
6701 static void | |
6702 c_gimple_diagnostics_recursively (tree fndecl) | |
6703 { | |
6704 struct cgraph_node *cgn; | |
6705 gimple_seq body = gimple_body (fndecl); | |
6706 | |
6707 /* Handle attribute((warn_unused_result)). Relies on gimple input. */ | |
6708 c_warn_unused_result (body); | |
6709 | |
6710 /* Notice when OpenMP structured block constraints are violated. */ | |
6711 if (flag_openmp) | |
6712 diagnose_omp_structured_block_errors (fndecl); | |
6713 | |
6714 /* Finalize all nested functions now. */ | |
6715 cgn = cgraph_node (fndecl); | |
6716 for (cgn = cgn->nested; cgn ; cgn = cgn->next_nested) | |
6717 c_gimple_diagnostics_recursively (cgn->decl); | |
6718 } | |
6719 | 7976 |
6720 /* Finish up a function declaration and compile that function | 7977 /* Finish up a function declaration and compile that function |
6721 all the way to assembler language output. The free the storage | 7978 all the way to assembler language output. The free the storage |
6722 for the function definition. | 7979 for the function definition. |
6723 | 7980 |
6725 | 7982 |
6726 void | 7983 void |
6727 finish_function (void) | 7984 finish_function (void) |
6728 { | 7985 { |
6729 tree fndecl = current_function_decl; | 7986 tree fndecl = current_function_decl; |
6730 | |
6731 label_context_stack_se = label_context_stack_se->next; | |
6732 label_context_stack_vm = label_context_stack_vm->next; | |
6733 | 7987 |
6734 if (TREE_CODE (fndecl) == FUNCTION_DECL | 7988 if (TREE_CODE (fndecl) == FUNCTION_DECL |
6735 && targetm.calls.promote_prototypes (TREE_TYPE (fndecl))) | 7989 && targetm.calls.promote_prototypes (TREE_TYPE (fndecl))) |
6736 { | 7990 { |
6737 tree args = DECL_ARGUMENTS (fndecl); | 7991 tree args = DECL_ARGUMENTS (fndecl); |
6754 | 8008 |
6755 if (MAIN_NAME_P (DECL_NAME (fndecl)) && flag_hosted | 8009 if (MAIN_NAME_P (DECL_NAME (fndecl)) && flag_hosted |
6756 && TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl))) | 8010 && TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl))) |
6757 == integer_type_node && flag_isoc99) | 8011 == integer_type_node && flag_isoc99) |
6758 { | 8012 { |
6759 tree stmt = c_finish_return (integer_zero_node); | |
6760 /* Hack. We don't want the middle-end to warn that this return | 8013 /* Hack. We don't want the middle-end to warn that this return |
6761 is unreachable, so we mark its location as special. Using | 8014 is unreachable, so we mark its location as special. Using |
6762 UNKNOWN_LOCATION has the problem that it gets clobbered in | 8015 UNKNOWN_LOCATION has the problem that it gets clobbered in |
6763 annotate_one_with_locus. A cleaner solution might be to | 8016 annotate_one_with_locus. A cleaner solution might be to |
6764 ensure ! should_carry_locus_p (stmt), but that needs a flag. | 8017 ensure ! should_carry_locus_p (stmt), but that needs a flag. |
6765 */ | 8018 */ |
6766 SET_EXPR_LOCATION (stmt, BUILTINS_LOCATION); | 8019 c_finish_return (BUILTINS_LOCATION, integer_zero_node, NULL_TREE); |
6767 } | 8020 } |
6768 | 8021 |
6769 /* Tie off the statement tree for this function. */ | 8022 /* Tie off the statement tree for this function. */ |
6770 DECL_SAVED_TREE (fndecl) = pop_stmt_list (DECL_SAVED_TREE (fndecl)); | 8023 DECL_SAVED_TREE (fndecl) = pop_stmt_list (DECL_SAVED_TREE (fndecl)); |
6771 | 8024 |
6775 if (warn_return_type | 8028 if (warn_return_type |
6776 && TREE_CODE (TREE_TYPE (TREE_TYPE (fndecl))) != VOID_TYPE | 8029 && TREE_CODE (TREE_TYPE (TREE_TYPE (fndecl))) != VOID_TYPE |
6777 && !current_function_returns_value && !current_function_returns_null | 8030 && !current_function_returns_value && !current_function_returns_null |
6778 /* Don't complain if we are no-return. */ | 8031 /* Don't complain if we are no-return. */ |
6779 && !current_function_returns_abnormally | 8032 && !current_function_returns_abnormally |
6780 /* Don't complain if we are declared noreturn. */ | |
6781 && !TREE_THIS_VOLATILE (fndecl) | |
6782 /* Don't warn for main(). */ | 8033 /* Don't warn for main(). */ |
6783 && !MAIN_NAME_P (DECL_NAME (fndecl)) | 8034 && !MAIN_NAME_P (DECL_NAME (fndecl)) |
6784 /* Or if they didn't actually specify a return type. */ | 8035 /* Or if they didn't actually specify a return type. */ |
6785 && !C_FUNCTION_IMPLICIT_INT (fndecl) | 8036 && !C_FUNCTION_IMPLICIT_INT (fndecl) |
6786 /* Normally, with -Wreturn-type, flow will complain, but we might | 8037 /* Normally, with -Wreturn-type, flow will complain, but we might |
6798 | 8049 |
6799 /* Finalize the ELF visibility for the function. */ | 8050 /* Finalize the ELF visibility for the function. */ |
6800 c_determine_visibility (fndecl); | 8051 c_determine_visibility (fndecl); |
6801 | 8052 |
6802 /* For GNU C extern inline functions disregard inline limits. */ | 8053 /* For GNU C extern inline functions disregard inline limits. */ |
6803 if (DECL_EXTERNAL (fndecl) | 8054 if (DECL_EXTERNAL (fndecl) |
6804 && DECL_DECLARED_INLINE_P (fndecl)) | 8055 && DECL_DECLARED_INLINE_P (fndecl)) |
6805 DECL_DISREGARD_INLINE_LIMITS (fndecl) = 1; | 8056 DECL_DISREGARD_INLINE_LIMITS (fndecl) = 1; |
6806 | 8057 |
6807 /* Genericize before inlining. Delay genericizing nested functions | 8058 /* Genericize before inlining. Delay genericizing nested functions |
6808 until their parent function is genericized. Since finalizing | 8059 until their parent function is genericized. Since finalizing |
6811 if (DECL_INITIAL (fndecl) && DECL_INITIAL (fndecl) != error_mark_node | 8062 if (DECL_INITIAL (fndecl) && DECL_INITIAL (fndecl) != error_mark_node |
6812 && !undef_nested_function) | 8063 && !undef_nested_function) |
6813 { | 8064 { |
6814 if (!decl_function_context (fndecl)) | 8065 if (!decl_function_context (fndecl)) |
6815 { | 8066 { |
8067 invoke_plugin_callbacks (PLUGIN_PRE_GENERICIZE, fndecl); | |
6816 c_genericize (fndecl); | 8068 c_genericize (fndecl); |
6817 c_gimple_diagnostics_recursively (fndecl); | |
6818 | 8069 |
6819 /* ??? Objc emits functions after finalizing the compilation unit. | 8070 /* ??? Objc emits functions after finalizing the compilation unit. |
6820 This should be cleaned up later and this conditional removed. */ | 8071 This should be cleaned up later and this conditional removed. */ |
6821 if (cgraph_global_info_ready) | 8072 if (cgraph_global_info_ready) |
6822 { | 8073 { |
6823 cgraph_add_new_function (fndecl, false); | 8074 cgraph_add_new_function (fndecl, false); |
6824 return; | 8075 return; |
6825 } | 8076 } |
6826 | |
6827 cgraph_finalize_function (fndecl, false); | 8077 cgraph_finalize_function (fndecl, false); |
6828 } | 8078 } |
6829 else | 8079 else |
6830 { | 8080 { |
6831 /* Register this function with cgraph just far enough to get it | 8081 /* Register this function with cgraph just far enough to get it |
6844 set_cfun (NULL); | 8094 set_cfun (NULL); |
6845 current_function_decl = NULL; | 8095 current_function_decl = NULL; |
6846 } | 8096 } |
6847 | 8097 |
6848 /* Check the declarations given in a for-loop for satisfying the C99 | 8098 /* Check the declarations given in a for-loop for satisfying the C99 |
6849 constraints. If exactly one such decl is found, return it. */ | 8099 constraints. If exactly one such decl is found, return it. LOC is |
8100 the location of the opening parenthesis of the for loop. */ | |
6850 | 8101 |
6851 tree | 8102 tree |
6852 check_for_loop_decls (void) | 8103 check_for_loop_decls (location_t loc) |
6853 { | 8104 { |
6854 struct c_binding *b; | 8105 struct c_binding *b; |
6855 tree one_decl = NULL_TREE; | 8106 tree one_decl = NULL_TREE; |
6856 int n_decls = 0; | 8107 int n_decls = 0; |
6857 | 8108 |
6859 { | 8110 { |
6860 static bool hint = true; | 8111 static bool hint = true; |
6861 /* If we get here, declarations have been used in a for loop without | 8112 /* If we get here, declarations have been used in a for loop without |
6862 the C99 for loop scope. This doesn't make much sense, so don't | 8113 the C99 for loop scope. This doesn't make much sense, so don't |
6863 allow it. */ | 8114 allow it. */ |
6864 error ("%<for%> loop initial declarations are only allowed in C99 mode"); | 8115 error_at (loc, "%<for%> loop initial declarations " |
8116 "are only allowed in C99 mode"); | |
6865 if (hint) | 8117 if (hint) |
6866 { | 8118 { |
6867 inform (input_location, | 8119 inform (loc, |
6868 "use option -std=c99 or -std=gnu99 to compile your code"); | 8120 "use option -std=c99 or -std=gnu99 to compile your code"); |
6869 hint = false; | 8121 hint = false; |
6870 } | 8122 } |
6871 return NULL_TREE; | 8123 return NULL_TREE; |
6872 } | 8124 } |
6893 continue; | 8145 continue; |
6894 | 8146 |
6895 switch (TREE_CODE (decl)) | 8147 switch (TREE_CODE (decl)) |
6896 { | 8148 { |
6897 case VAR_DECL: | 8149 case VAR_DECL: |
6898 if (TREE_STATIC (decl)) | 8150 { |
6899 error ("declaration of static variable %q+D in %<for%> loop " | 8151 location_t decl_loc = DECL_SOURCE_LOCATION (decl); |
6900 "initial declaration", decl); | 8152 if (TREE_STATIC (decl)) |
6901 else if (DECL_EXTERNAL (decl)) | 8153 error_at (decl_loc, |
6902 error ("declaration of %<extern%> variable %q+D in %<for%> loop " | 8154 "declaration of static variable %qD in %<for%> loop " |
6903 "initial declaration", decl); | 8155 "initial declaration", decl); |
8156 else if (DECL_EXTERNAL (decl)) | |
8157 error_at (decl_loc, | |
8158 "declaration of %<extern%> variable %qD in %<for%> loop " | |
8159 "initial declaration", decl); | |
8160 } | |
6904 break; | 8161 break; |
6905 | 8162 |
6906 case RECORD_TYPE: | 8163 case RECORD_TYPE: |
6907 error ("%<struct %E%> declared in %<for%> loop initial declaration", | 8164 error_at (loc, |
6908 id); | 8165 "%<struct %E%> declared in %<for%> loop initial " |
8166 "declaration", id); | |
6909 break; | 8167 break; |
6910 case UNION_TYPE: | 8168 case UNION_TYPE: |
6911 error ("%<union %E%> declared in %<for%> loop initial declaration", | 8169 error_at (loc, |
6912 id); | 8170 "%<union %E%> declared in %<for%> loop initial declaration", |
8171 id); | |
6913 break; | 8172 break; |
6914 case ENUMERAL_TYPE: | 8173 case ENUMERAL_TYPE: |
6915 error ("%<enum %E%> declared in %<for%> loop initial declaration", | 8174 error_at (loc, "%<enum %E%> declared in %<for%> loop " |
6916 id); | 8175 "initial declaration", id); |
6917 break; | 8176 break; |
6918 default: | 8177 default: |
6919 error ("declaration of non-variable %q+D in %<for%> loop " | 8178 error_at (loc, "declaration of non-variable " |
6920 "initial declaration", decl); | 8179 "%qD in %<for%> loop initial declaration", decl); |
6921 } | 8180 } |
6922 | 8181 |
6923 n_decls++; | 8182 n_decls++; |
6924 one_decl = decl; | 8183 one_decl = decl; |
6925 } | 8184 } |
6980 current_function_returns_null = p->returns_null; | 8239 current_function_returns_null = p->returns_null; |
6981 current_function_returns_abnormally = p->returns_abnormally; | 8240 current_function_returns_abnormally = p->returns_abnormally; |
6982 warn_about_return_type = p->warn_about_return_type; | 8241 warn_about_return_type = p->warn_about_return_type; |
6983 } | 8242 } |
6984 | 8243 |
6985 /* Copy the DECL_LANG_SPECIFIC data associated with DECL. */ | |
6986 | |
6987 void | |
6988 c_dup_lang_specific_decl (tree decl) | |
6989 { | |
6990 struct lang_decl *ld; | |
6991 | |
6992 if (!DECL_LANG_SPECIFIC (decl)) | |
6993 return; | |
6994 | |
6995 ld = GGC_NEW (struct lang_decl); | |
6996 memcpy (ld, DECL_LANG_SPECIFIC (decl), sizeof (struct lang_decl)); | |
6997 DECL_LANG_SPECIFIC (decl) = ld; | |
6998 } | |
6999 | |
7000 /* The functions below are required for functionality of doing | 8244 /* The functions below are required for functionality of doing |
7001 function at once processing in the C front end. Currently these | 8245 function at once processing in the C front end. Currently these |
7002 functions are not called from anywhere in the C front end, but as | 8246 functions are not called from anywhere in the C front end, but as |
7003 these changes continue, that will change. */ | 8247 these changes continue, that will change. */ |
7004 | 8248 |
7035 tree id, decl; | 8279 tree id, decl; |
7036 if (name == 0) | 8280 if (name == 0) |
7037 id = ridpointers[(int) rid_index]; | 8281 id = ridpointers[(int) rid_index]; |
7038 else | 8282 else |
7039 id = get_identifier (name); | 8283 id = get_identifier (name); |
7040 decl = build_decl (TYPE_DECL, id, type); | 8284 decl = build_decl (UNKNOWN_LOCATION, TYPE_DECL, id, type); |
7041 pushdecl (decl); | 8285 pushdecl (decl); |
7042 if (debug_hooks->type_decl) | 8286 if (debug_hooks->type_decl) |
7043 debug_hooks->type_decl (decl, false); | 8287 debug_hooks->type_decl (decl, false); |
7044 } | 8288 } |
7045 | 8289 |
7139 struct c_declspecs * | 8383 struct c_declspecs * |
7140 build_null_declspecs (void) | 8384 build_null_declspecs (void) |
7141 { | 8385 { |
7142 struct c_declspecs *ret = XOBNEW (&parser_obstack, struct c_declspecs); | 8386 struct c_declspecs *ret = XOBNEW (&parser_obstack, struct c_declspecs); |
7143 ret->type = 0; | 8387 ret->type = 0; |
8388 ret->expr = 0; | |
7144 ret->decl_attr = 0; | 8389 ret->decl_attr = 0; |
7145 ret->attrs = 0; | 8390 ret->attrs = 0; |
7146 ret->typespec_word = cts_none; | 8391 ret->typespec_word = cts_none; |
7147 ret->storage_class = csc_none; | 8392 ret->storage_class = csc_none; |
8393 ret->expr_const_operands = true; | |
7148 ret->declspecs_seen_p = false; | 8394 ret->declspecs_seen_p = false; |
7149 ret->type_seen_p = false; | 8395 ret->type_seen_p = false; |
7150 ret->non_sc_seen_p = false; | 8396 ret->non_sc_seen_p = false; |
7151 ret->typedef_p = false; | 8397 ret->typedef_p = false; |
7152 ret->tag_defined_p = false; | 8398 ret->tag_defined_p = false; |
7163 ret->thread_p = false; | 8409 ret->thread_p = false; |
7164 ret->const_p = false; | 8410 ret->const_p = false; |
7165 ret->volatile_p = false; | 8411 ret->volatile_p = false; |
7166 ret->restrict_p = false; | 8412 ret->restrict_p = false; |
7167 ret->saturating_p = false; | 8413 ret->saturating_p = false; |
8414 ret->address_space = ADDR_SPACE_GENERIC; | |
7168 return ret; | 8415 return ret; |
8416 } | |
8417 | |
8418 /* Add the address space ADDRSPACE to the declaration specifiers | |
8419 SPECS, returning SPECS. */ | |
8420 | |
8421 struct c_declspecs * | |
8422 declspecs_add_addrspace (struct c_declspecs *specs, addr_space_t as) | |
8423 { | |
8424 specs->non_sc_seen_p = true; | |
8425 specs->declspecs_seen_p = true; | |
8426 | |
8427 if (!ADDR_SPACE_GENERIC_P (specs->address_space) | |
8428 && specs->address_space != as) | |
8429 error ("incompatible address space qualifiers %qs and %qs", | |
8430 c_addr_space_name (as), | |
8431 c_addr_space_name (specs->address_space)); | |
8432 else | |
8433 specs->address_space = as; | |
8434 return specs; | |
7169 } | 8435 } |
7170 | 8436 |
7171 /* Add the type qualifier QUAL to the declaration specifiers SPECS, | 8437 /* Add the type qualifier QUAL to the declaration specifiers SPECS, |
7172 returning SPECS. */ | 8438 returning SPECS. */ |
7173 | 8439 |
7205 | 8471 |
7206 /* Add the type specifier TYPE to the declaration specifiers SPECS, | 8472 /* Add the type specifier TYPE to the declaration specifiers SPECS, |
7207 returning SPECS. */ | 8473 returning SPECS. */ |
7208 | 8474 |
7209 struct c_declspecs * | 8475 struct c_declspecs * |
7210 declspecs_add_type (struct c_declspecs *specs, struct c_typespec spec) | 8476 declspecs_add_type (location_t loc, struct c_declspecs *specs, |
8477 struct c_typespec spec) | |
7211 { | 8478 { |
7212 tree type = spec.spec; | 8479 tree type = spec.spec; |
7213 specs->non_sc_seen_p = true; | 8480 specs->non_sc_seen_p = true; |
7214 specs->declspecs_seen_p = true; | 8481 specs->declspecs_seen_p = true; |
7215 specs->type_seen_p = true; | 8482 specs->type_seen_p = true; |
7222 && C_RID_CODE (type) != RID_CXX_COMPAT_WARN) | 8489 && C_RID_CODE (type) != RID_CXX_COMPAT_WARN) |
7223 { | 8490 { |
7224 enum rid i = C_RID_CODE (type); | 8491 enum rid i = C_RID_CODE (type); |
7225 if (specs->type) | 8492 if (specs->type) |
7226 { | 8493 { |
7227 error ("two or more data types in declaration specifiers"); | 8494 error_at (loc, "two or more data types in declaration specifiers"); |
7228 return specs; | 8495 return specs; |
7229 } | 8496 } |
7230 if ((int) i <= (int) RID_LAST_MODIFIER) | 8497 if ((int) i <= (int) RID_LAST_MODIFIER) |
7231 { | 8498 { |
7232 /* "long", "short", "signed", "unsigned", "_Complex" or "_Sat". */ | 8499 /* "long", "short", "signed", "unsigned", "_Complex" or "_Sat". */ |
7234 switch (i) | 8501 switch (i) |
7235 { | 8502 { |
7236 case RID_LONG: | 8503 case RID_LONG: |
7237 if (specs->long_long_p) | 8504 if (specs->long_long_p) |
7238 { | 8505 { |
7239 error ("%<long long long%> is too long for GCC"); | 8506 error_at (loc, "%<long long long%> is too long for GCC"); |
7240 break; | 8507 break; |
7241 } | 8508 } |
7242 if (specs->long_p) | 8509 if (specs->long_p) |
7243 { | 8510 { |
7244 if (specs->typespec_word == cts_double) | 8511 if (specs->typespec_word == cts_double) |
7245 { | 8512 { |
7246 error ("both %<long long%> and %<double%> in " | 8513 error_at (loc, |
7247 "declaration specifiers"); | 8514 ("both %<long long%> and %<double%> in " |
8515 "declaration specifiers")); | |
7248 break; | 8516 break; |
7249 } | 8517 } |
7250 if (pedantic && !flag_isoc99 && !in_system_header) | 8518 pedwarn_c90 (loc, OPT_Wlong_long, |
7251 pedwarn (input_location, OPT_Wlong_long, "ISO C90 does not support %<long long%>"); | 8519 "ISO C90 does not support %<long long%>"); |
7252 specs->long_long_p = 1; | 8520 specs->long_long_p = 1; |
7253 break; | 8521 break; |
7254 } | 8522 } |
7255 if (specs->short_p) | 8523 if (specs->short_p) |
7256 error ("both %<long%> and %<short%> in " | 8524 error_at (loc, |
7257 "declaration specifiers"); | 8525 ("both %<long%> and %<short%> in " |
8526 "declaration specifiers")); | |
7258 else if (specs->typespec_word == cts_void) | 8527 else if (specs->typespec_word == cts_void) |
7259 error ("both %<long%> and %<void%> in " | 8528 error_at (loc, |
7260 "declaration specifiers"); | 8529 ("both %<long%> and %<void%> in " |
8530 "declaration specifiers")); | |
7261 else if (specs->typespec_word == cts_bool) | 8531 else if (specs->typespec_word == cts_bool) |
7262 error ("both %<long%> and %<_Bool%> in " | 8532 error_at (loc, |
7263 "declaration specifiers"); | 8533 ("both %<long%> and %<_Bool%> in " |
8534 "declaration specifiers")); | |
7264 else if (specs->typespec_word == cts_char) | 8535 else if (specs->typespec_word == cts_char) |
7265 error ("both %<long%> and %<char%> in " | 8536 error_at (loc, |
7266 "declaration specifiers"); | 8537 ("both %<long%> and %<char%> in " |
8538 "declaration specifiers")); | |
7267 else if (specs->typespec_word == cts_float) | 8539 else if (specs->typespec_word == cts_float) |
7268 error ("both %<long%> and %<float%> in " | 8540 error_at (loc, |
7269 "declaration specifiers"); | 8541 ("both %<long%> and %<float%> in " |
8542 "declaration specifiers")); | |
7270 else if (specs->typespec_word == cts_dfloat32) | 8543 else if (specs->typespec_word == cts_dfloat32) |
7271 error ("both %<long%> and %<_Decimal32%> in " | 8544 error_at (loc, |
7272 "declaration specifiers"); | 8545 ("both %<long%> and %<_Decimal32%> in " |
8546 "declaration specifiers")); | |
7273 else if (specs->typespec_word == cts_dfloat64) | 8547 else if (specs->typespec_word == cts_dfloat64) |
7274 error ("both %<long%> and %<_Decimal64%> in " | 8548 error_at (loc, |
7275 "declaration specifiers"); | 8549 ("both %<long%> and %<_Decimal64%> in " |
8550 "declaration specifiers")); | |
7276 else if (specs->typespec_word == cts_dfloat128) | 8551 else if (specs->typespec_word == cts_dfloat128) |
7277 error ("both %<long%> and %<_Decimal128%> in " | 8552 error_at (loc, |
7278 "declaration specifiers"); | 8553 ("both %<long%> and %<_Decimal128%> in " |
8554 "declaration specifiers")); | |
7279 else | 8555 else |
7280 specs->long_p = true; | 8556 specs->long_p = true; |
7281 break; | 8557 break; |
7282 case RID_SHORT: | 8558 case RID_SHORT: |
7283 dupe = specs->short_p; | 8559 dupe = specs->short_p; |
7284 if (specs->long_p) | 8560 if (specs->long_p) |
7285 error ("both %<long%> and %<short%> in " | 8561 error_at (loc, |
7286 "declaration specifiers"); | 8562 ("both %<long%> and %<short%> in " |
8563 "declaration specifiers")); | |
7287 else if (specs->typespec_word == cts_void) | 8564 else if (specs->typespec_word == cts_void) |
7288 error ("both %<short%> and %<void%> in " | 8565 error_at (loc, |
7289 "declaration specifiers"); | 8566 ("both %<short%> and %<void%> in " |
8567 "declaration specifiers")); | |
7290 else if (specs->typespec_word == cts_bool) | 8568 else if (specs->typespec_word == cts_bool) |
7291 error ("both %<short%> and %<_Bool%> in " | 8569 error_at (loc, |
7292 "declaration specifiers"); | 8570 ("both %<short%> and %<_Bool%> in " |
8571 "declaration specifiers")); | |
7293 else if (specs->typespec_word == cts_char) | 8572 else if (specs->typespec_word == cts_char) |
7294 error ("both %<short%> and %<char%> in " | 8573 error_at (loc, |
7295 "declaration specifiers"); | 8574 ("both %<short%> and %<char%> in " |
8575 "declaration specifiers")); | |
7296 else if (specs->typespec_word == cts_float) | 8576 else if (specs->typespec_word == cts_float) |
7297 error ("both %<short%> and %<float%> in " | 8577 error_at (loc, |
7298 "declaration specifiers"); | 8578 ("both %<short%> and %<float%> in " |
8579 "declaration specifiers")); | |
7299 else if (specs->typespec_word == cts_double) | 8580 else if (specs->typespec_word == cts_double) |
7300 error ("both %<short%> and %<double%> in " | 8581 error_at (loc, |
7301 "declaration specifiers"); | 8582 ("both %<short%> and %<double%> in " |
8583 "declaration specifiers")); | |
7302 else if (specs->typespec_word == cts_dfloat32) | 8584 else if (specs->typespec_word == cts_dfloat32) |
7303 error ("both %<short%> and %<_Decimal32%> in " | 8585 error_at (loc, |
7304 "declaration specifiers"); | 8586 ("both %<short%> and %<_Decimal32%> in " |
8587 "declaration specifiers")); | |
7305 else if (specs->typespec_word == cts_dfloat64) | 8588 else if (specs->typespec_word == cts_dfloat64) |
7306 error ("both %<short%> and %<_Decimal64%> in " | 8589 error_at (loc, |
7307 "declaration specifiers"); | 8590 ("both %<short%> and %<_Decimal64%> in " |
8591 "declaration specifiers")); | |
7308 else if (specs->typespec_word == cts_dfloat128) | 8592 else if (specs->typespec_word == cts_dfloat128) |
7309 error ("both %<short%> and %<_Decimal128%> in " | 8593 error_at (loc, |
7310 "declaration specifiers"); | 8594 ("both %<short%> and %<_Decimal128%> in " |
8595 "declaration specifiers")); | |
7311 else | 8596 else |
7312 specs->short_p = true; | 8597 specs->short_p = true; |
7313 break; | 8598 break; |
7314 case RID_SIGNED: | 8599 case RID_SIGNED: |
7315 dupe = specs->signed_p; | 8600 dupe = specs->signed_p; |
7316 if (specs->unsigned_p) | 8601 if (specs->unsigned_p) |
7317 error ("both %<signed%> and %<unsigned%> in " | 8602 error_at (loc, |
7318 "declaration specifiers"); | 8603 ("both %<signed%> and %<unsigned%> in " |
8604 "declaration specifiers")); | |
7319 else if (specs->typespec_word == cts_void) | 8605 else if (specs->typespec_word == cts_void) |
7320 error ("both %<signed%> and %<void%> in " | 8606 error_at (loc, |
7321 "declaration specifiers"); | 8607 ("both %<signed%> and %<void%> in " |
8608 "declaration specifiers")); | |
7322 else if (specs->typespec_word == cts_bool) | 8609 else if (specs->typespec_word == cts_bool) |
7323 error ("both %<signed%> and %<_Bool%> in " | 8610 error_at (loc, |
7324 "declaration specifiers"); | 8611 ("both %<signed%> and %<_Bool%> in " |
8612 "declaration specifiers")); | |
7325 else if (specs->typespec_word == cts_float) | 8613 else if (specs->typespec_word == cts_float) |
7326 error ("both %<signed%> and %<float%> in " | 8614 error_at (loc, |
7327 "declaration specifiers"); | 8615 ("both %<signed%> and %<float%> in " |
8616 "declaration specifiers")); | |
7328 else if (specs->typespec_word == cts_double) | 8617 else if (specs->typespec_word == cts_double) |
7329 error ("both %<signed%> and %<double%> in " | 8618 error_at (loc, |
7330 "declaration specifiers"); | 8619 ("both %<signed%> and %<double%> in " |
8620 "declaration specifiers")); | |
7331 else if (specs->typespec_word == cts_dfloat32) | 8621 else if (specs->typespec_word == cts_dfloat32) |
7332 error ("both %<signed%> and %<_Decimal32%> in " | 8622 error_at (loc, |
7333 "declaration specifiers"); | 8623 ("both %<signed%> and %<_Decimal32%> in " |
8624 "declaration specifiers")); | |
7334 else if (specs->typespec_word == cts_dfloat64) | 8625 else if (specs->typespec_word == cts_dfloat64) |
7335 error ("both %<signed%> and %<_Decimal64%> in " | 8626 error_at (loc, |
7336 "declaration specifiers"); | 8627 ("both %<signed%> and %<_Decimal64%> in " |
8628 "declaration specifiers")); | |
7337 else if (specs->typespec_word == cts_dfloat128) | 8629 else if (specs->typespec_word == cts_dfloat128) |
7338 error ("both %<signed%> and %<_Decimal128%> in " | 8630 error_at (loc, |
7339 "declaration specifiers"); | 8631 ("both %<signed%> and %<_Decimal128%> in " |
8632 "declaration specifiers")); | |
7340 else | 8633 else |
7341 specs->signed_p = true; | 8634 specs->signed_p = true; |
7342 break; | 8635 break; |
7343 case RID_UNSIGNED: | 8636 case RID_UNSIGNED: |
7344 dupe = specs->unsigned_p; | 8637 dupe = specs->unsigned_p; |
7345 if (specs->signed_p) | 8638 if (specs->signed_p) |
7346 error ("both %<signed%> and %<unsigned%> in " | 8639 error_at (loc, |
7347 "declaration specifiers"); | 8640 ("both %<signed%> and %<unsigned%> in " |
8641 "declaration specifiers")); | |
7348 else if (specs->typespec_word == cts_void) | 8642 else if (specs->typespec_word == cts_void) |
7349 error ("both %<unsigned%> and %<void%> in " | 8643 error_at (loc, |
7350 "declaration specifiers"); | 8644 ("both %<unsigned%> and %<void%> in " |
8645 "declaration specifiers")); | |
7351 else if (specs->typespec_word == cts_bool) | 8646 else if (specs->typespec_word == cts_bool) |
7352 error ("both %<unsigned%> and %<_Bool%> in " | 8647 error_at (loc, |
7353 "declaration specifiers"); | 8648 ("both %<unsigned%> and %<_Bool%> in " |
8649 "declaration specifiers")); | |
7354 else if (specs->typespec_word == cts_float) | 8650 else if (specs->typespec_word == cts_float) |
7355 error ("both %<unsigned%> and %<float%> in " | 8651 error_at (loc, |
7356 "declaration specifiers"); | 8652 ("both %<unsigned%> and %<float%> in " |
8653 "declaration specifiers")); | |
7357 else if (specs->typespec_word == cts_double) | 8654 else if (specs->typespec_word == cts_double) |
7358 error ("both %<unsigned%> and %<double%> in " | 8655 error_at (loc, |
7359 "declaration specifiers"); | 8656 ("both %<unsigned%> and %<double%> in " |
8657 "declaration specifiers")); | |
7360 else if (specs->typespec_word == cts_dfloat32) | 8658 else if (specs->typespec_word == cts_dfloat32) |
7361 error ("both %<unsigned%> and %<_Decimal32%> in " | 8659 error_at (loc, |
7362 "declaration specifiers"); | 8660 ("both %<unsigned%> and %<_Decimal32%> in " |
8661 "declaration specifiers")); | |
7363 else if (specs->typespec_word == cts_dfloat64) | 8662 else if (specs->typespec_word == cts_dfloat64) |
7364 error ("both %<unsigned%> and %<_Decimal64%> in " | 8663 error_at (loc, |
7365 "declaration specifiers"); | 8664 ("both %<unsigned%> and %<_Decimal64%> in " |
8665 "declaration specifiers")); | |
7366 else if (specs->typespec_word == cts_dfloat128) | 8666 else if (specs->typespec_word == cts_dfloat128) |
7367 error ("both %<unsigned%> and %<_Decimal128%> in " | 8667 error_at (loc, |
7368 "declaration specifiers"); | 8668 ("both %<unsigned%> and %<_Decimal128%> in " |
8669 "declaration specifiers")); | |
7369 else | 8670 else |
7370 specs->unsigned_p = true; | 8671 specs->unsigned_p = true; |
7371 break; | 8672 break; |
7372 case RID_COMPLEX: | 8673 case RID_COMPLEX: |
7373 dupe = specs->complex_p; | 8674 dupe = specs->complex_p; |
7374 if (!flag_isoc99 && !in_system_header) | 8675 if (!flag_isoc99 && !in_system_header) |
7375 pedwarn (input_location, OPT_pedantic, "ISO C90 does not support complex types"); | 8676 pedwarn (loc, OPT_pedantic, |
8677 "ISO C90 does not support complex types"); | |
7376 if (specs->typespec_word == cts_void) | 8678 if (specs->typespec_word == cts_void) |
7377 error ("both %<complex%> and %<void%> in " | 8679 error_at (loc, |
7378 "declaration specifiers"); | 8680 ("both %<complex%> and %<void%> in " |
8681 "declaration specifiers")); | |
7379 else if (specs->typespec_word == cts_bool) | 8682 else if (specs->typespec_word == cts_bool) |
7380 error ("both %<complex%> and %<_Bool%> in " | 8683 error_at (loc, |
7381 "declaration specifiers"); | 8684 ("both %<complex%> and %<_Bool%> in " |
8685 "declaration specifiers")); | |
7382 else if (specs->typespec_word == cts_dfloat32) | 8686 else if (specs->typespec_word == cts_dfloat32) |
7383 error ("both %<complex%> and %<_Decimal32%> in " | 8687 error_at (loc, |
7384 "declaration specifiers"); | 8688 ("both %<complex%> and %<_Decimal32%> in " |
8689 "declaration specifiers")); | |
7385 else if (specs->typespec_word == cts_dfloat64) | 8690 else if (specs->typespec_word == cts_dfloat64) |
7386 error ("both %<complex%> and %<_Decimal64%> in " | 8691 error_at (loc, |
7387 "declaration specifiers"); | 8692 ("both %<complex%> and %<_Decimal64%> in " |
8693 "declaration specifiers")); | |
7388 else if (specs->typespec_word == cts_dfloat128) | 8694 else if (specs->typespec_word == cts_dfloat128) |
7389 error ("both %<complex%> and %<_Decimal128%> in " | 8695 error_at (loc, |
7390 "declaration specifiers"); | 8696 ("both %<complex%> and %<_Decimal128%> in " |
8697 "declaration specifiers")); | |
7391 else if (specs->typespec_word == cts_fract) | 8698 else if (specs->typespec_word == cts_fract) |
7392 error ("both %<complex%> and %<_Fract%> in " | 8699 error_at (loc, |
7393 "declaration specifiers"); | 8700 ("both %<complex%> and %<_Fract%> in " |
8701 "declaration specifiers")); | |
7394 else if (specs->typespec_word == cts_accum) | 8702 else if (specs->typespec_word == cts_accum) |
7395 error ("both %<complex%> and %<_Accum%> in " | 8703 error_at (loc, |
7396 "declaration specifiers"); | 8704 ("both %<complex%> and %<_Accum%> in " |
8705 "declaration specifiers")); | |
7397 else if (specs->saturating_p) | 8706 else if (specs->saturating_p) |
7398 error ("both %<complex%> and %<_Sat%> in " | 8707 error_at (loc, |
7399 "declaration specifiers"); | 8708 ("both %<complex%> and %<_Sat%> in " |
8709 "declaration specifiers")); | |
7400 else | 8710 else |
7401 specs->complex_p = true; | 8711 specs->complex_p = true; |
7402 break; | 8712 break; |
7403 case RID_SAT: | 8713 case RID_SAT: |
7404 dupe = specs->saturating_p; | 8714 dupe = specs->saturating_p; |
7405 pedwarn (input_location, OPT_pedantic, "ISO C does not support saturating types"); | 8715 pedwarn (loc, OPT_pedantic, |
8716 "ISO C does not support saturating types"); | |
7406 if (specs->typespec_word == cts_void) | 8717 if (specs->typespec_word == cts_void) |
7407 error ("both %<_Sat%> and %<void%> in " | 8718 error_at (loc, |
7408 "declaration specifiers"); | 8719 ("both %<_Sat%> and %<void%> in " |
8720 "declaration specifiers")); | |
7409 else if (specs->typespec_word == cts_bool) | 8721 else if (specs->typespec_word == cts_bool) |
7410 error ("both %<_Sat%> and %<_Bool%> in " | 8722 error_at (loc, |
7411 "declaration specifiers"); | 8723 ("both %<_Sat%> and %<_Bool%> in " |
8724 "declaration specifiers")); | |
7412 else if (specs->typespec_word == cts_char) | 8725 else if (specs->typespec_word == cts_char) |
7413 error ("both %<_Sat%> and %<char%> in " | 8726 error_at (loc, |
7414 "declaration specifiers"); | 8727 ("both %<_Sat%> and %<char%> in " |
8728 "declaration specifiers")); | |
7415 else if (specs->typespec_word == cts_int) | 8729 else if (specs->typespec_word == cts_int) |
7416 error ("both %<_Sat%> and %<int%> in " | 8730 error_at (loc, |
7417 "declaration specifiers"); | 8731 ("both %<_Sat%> and %<int%> in " |
8732 "declaration specifiers")); | |
7418 else if (specs->typespec_word == cts_float) | 8733 else if (specs->typespec_word == cts_float) |
7419 error ("both %<_Sat%> and %<float%> in " | 8734 error_at (loc, |
7420 "declaration specifiers"); | 8735 ("both %<_Sat%> and %<float%> in " |
8736 "declaration specifiers")); | |
7421 else if (specs->typespec_word == cts_double) | 8737 else if (specs->typespec_word == cts_double) |
7422 error ("both %<_Sat%> and %<double%> in " | 8738 error_at (loc, |
7423 "declaration specifiers"); | 8739 ("both %<_Sat%> and %<double%> in " |
8740 "declaration specifiers")); | |
7424 else if (specs->typespec_word == cts_dfloat32) | 8741 else if (specs->typespec_word == cts_dfloat32) |
7425 error ("both %<_Sat%> and %<_Decimal32%> in " | 8742 error_at (loc, |
7426 "declaration specifiers"); | 8743 ("both %<_Sat%> and %<_Decimal32%> in " |
8744 "declaration specifiers")); | |
7427 else if (specs->typespec_word == cts_dfloat64) | 8745 else if (specs->typespec_word == cts_dfloat64) |
7428 error ("both %<_Sat%> and %<_Decimal64%> in " | 8746 error_at (loc, |
7429 "declaration specifiers"); | 8747 ("both %<_Sat%> and %<_Decimal64%> in " |
8748 "declaration specifiers")); | |
7430 else if (specs->typespec_word == cts_dfloat128) | 8749 else if (specs->typespec_word == cts_dfloat128) |
7431 error ("both %<_Sat%> and %<_Decimal128%> in " | 8750 error_at (loc, |
7432 "declaration specifiers"); | 8751 ("both %<_Sat%> and %<_Decimal128%> in " |
8752 "declaration specifiers")); | |
7433 else if (specs->complex_p) | 8753 else if (specs->complex_p) |
7434 error ("both %<_Sat%> and %<complex%> in " | 8754 error_at (loc, |
7435 "declaration specifiers"); | 8755 ("both %<_Sat%> and %<complex%> in " |
8756 "declaration specifiers")); | |
7436 else | 8757 else |
7437 specs->saturating_p = true; | 8758 specs->saturating_p = true; |
7438 break; | 8759 break; |
7439 default: | 8760 default: |
7440 gcc_unreachable (); | 8761 gcc_unreachable (); |
7441 } | 8762 } |
7442 | 8763 |
7443 if (dupe) | 8764 if (dupe) |
7444 error ("duplicate %qE", type); | 8765 error_at (loc, "duplicate %qE", type); |
7445 | 8766 |
7446 return specs; | 8767 return specs; |
7447 } | 8768 } |
7448 else | 8769 else |
7449 { | 8770 { |
7450 /* "void", "_Bool", "char", "int", "float", "double", "_Decimal32", | 8771 /* "void", "_Bool", "char", "int", "float", "double", "_Decimal32", |
7451 "_Decimal64", "_Decimal128", "_Fract" or "_Accum". */ | 8772 "_Decimal64", "_Decimal128", "_Fract" or "_Accum". */ |
7452 if (specs->typespec_word != cts_none) | 8773 if (specs->typespec_word != cts_none) |
7453 { | 8774 { |
7454 error ("two or more data types in declaration specifiers"); | 8775 error_at (loc, |
8776 "two or more data types in declaration specifiers"); | |
7455 return specs; | 8777 return specs; |
7456 } | 8778 } |
7457 switch (i) | 8779 switch (i) |
7458 { | 8780 { |
7459 case RID_VOID: | 8781 case RID_VOID: |
7460 if (specs->long_p) | 8782 if (specs->long_p) |
7461 error ("both %<long%> and %<void%> in " | 8783 error_at (loc, |
7462 "declaration specifiers"); | 8784 ("both %<long%> and %<void%> in " |
8785 "declaration specifiers")); | |
7463 else if (specs->short_p) | 8786 else if (specs->short_p) |
7464 error ("both %<short%> and %<void%> in " | 8787 error_at (loc, |
7465 "declaration specifiers"); | 8788 ("both %<short%> and %<void%> in " |
8789 "declaration specifiers")); | |
7466 else if (specs->signed_p) | 8790 else if (specs->signed_p) |
7467 error ("both %<signed%> and %<void%> in " | 8791 error_at (loc, |
7468 "declaration specifiers"); | 8792 ("both %<signed%> and %<void%> in " |
8793 "declaration specifiers")); | |
7469 else if (specs->unsigned_p) | 8794 else if (specs->unsigned_p) |
7470 error ("both %<unsigned%> and %<void%> in " | 8795 error_at (loc, |
7471 "declaration specifiers"); | 8796 ("both %<unsigned%> and %<void%> in " |
8797 "declaration specifiers")); | |
7472 else if (specs->complex_p) | 8798 else if (specs->complex_p) |
7473 error ("both %<complex%> and %<void%> in " | 8799 error_at (loc, |
7474 "declaration specifiers"); | 8800 ("both %<complex%> and %<void%> in " |
8801 "declaration specifiers")); | |
7475 else if (specs->saturating_p) | 8802 else if (specs->saturating_p) |
7476 error ("both %<_Sat%> and %<void%> in " | 8803 error_at (loc, |
7477 "declaration specifiers"); | 8804 ("both %<_Sat%> and %<void%> in " |
8805 "declaration specifiers")); | |
7478 else | 8806 else |
7479 specs->typespec_word = cts_void; | 8807 specs->typespec_word = cts_void; |
7480 return specs; | 8808 return specs; |
7481 case RID_BOOL: | 8809 case RID_BOOL: |
7482 if (specs->long_p) | 8810 if (specs->long_p) |
7483 error ("both %<long%> and %<_Bool%> in " | 8811 error_at (loc, |
7484 "declaration specifiers"); | 8812 ("both %<long%> and %<_Bool%> in " |
8813 "declaration specifiers")); | |
7485 else if (specs->short_p) | 8814 else if (specs->short_p) |
7486 error ("both %<short%> and %<_Bool%> in " | 8815 error_at (loc, |
7487 "declaration specifiers"); | 8816 ("both %<short%> and %<_Bool%> in " |
8817 "declaration specifiers")); | |
7488 else if (specs->signed_p) | 8818 else if (specs->signed_p) |
7489 error ("both %<signed%> and %<_Bool%> in " | 8819 error_at (loc, |
7490 "declaration specifiers"); | 8820 ("both %<signed%> and %<_Bool%> in " |
8821 "declaration specifiers")); | |
7491 else if (specs->unsigned_p) | 8822 else if (specs->unsigned_p) |
7492 error ("both %<unsigned%> and %<_Bool%> in " | 8823 error_at (loc, |
7493 "declaration specifiers"); | 8824 ("both %<unsigned%> and %<_Bool%> in " |
8825 "declaration specifiers")); | |
7494 else if (specs->complex_p) | 8826 else if (specs->complex_p) |
7495 error ("both %<complex%> and %<_Bool%> in " | 8827 error_at (loc, |
7496 "declaration specifiers"); | 8828 ("both %<complex%> and %<_Bool%> in " |
8829 "declaration specifiers")); | |
7497 else if (specs->saturating_p) | 8830 else if (specs->saturating_p) |
7498 error ("both %<_Sat%> and %<_Bool%> in " | 8831 error_at (loc, |
7499 "declaration specifiers"); | 8832 ("both %<_Sat%> and %<_Bool%> in " |
8833 "declaration specifiers")); | |
7500 else | 8834 else |
7501 specs->typespec_word = cts_bool; | 8835 specs->typespec_word = cts_bool; |
7502 return specs; | 8836 return specs; |
7503 case RID_CHAR: | 8837 case RID_CHAR: |
7504 if (specs->long_p) | 8838 if (specs->long_p) |
7505 error ("both %<long%> and %<char%> in " | 8839 error_at (loc, |
7506 "declaration specifiers"); | 8840 ("both %<long%> and %<char%> in " |
8841 "declaration specifiers")); | |
7507 else if (specs->short_p) | 8842 else if (specs->short_p) |
7508 error ("both %<short%> and %<char%> in " | 8843 error_at (loc, |
7509 "declaration specifiers"); | 8844 ("both %<short%> and %<char%> in " |
8845 "declaration specifiers")); | |
7510 else if (specs->saturating_p) | 8846 else if (specs->saturating_p) |
7511 error ("both %<_Sat%> and %<char%> in " | 8847 error_at (loc, |
7512 "declaration specifiers"); | 8848 ("both %<_Sat%> and %<char%> in " |
8849 "declaration specifiers")); | |
7513 else | 8850 else |
7514 specs->typespec_word = cts_char; | 8851 specs->typespec_word = cts_char; |
7515 return specs; | 8852 return specs; |
7516 case RID_INT: | 8853 case RID_INT: |
7517 if (specs->saturating_p) | 8854 if (specs->saturating_p) |
7518 error ("both %<_Sat%> and %<int%> in " | 8855 error_at (loc, |
7519 "declaration specifiers"); | 8856 ("both %<_Sat%> and %<int%> in " |
8857 "declaration specifiers")); | |
7520 else | 8858 else |
7521 specs->typespec_word = cts_int; | 8859 specs->typespec_word = cts_int; |
7522 return specs; | 8860 return specs; |
7523 case RID_FLOAT: | 8861 case RID_FLOAT: |
7524 if (specs->long_p) | 8862 if (specs->long_p) |
7525 error ("both %<long%> and %<float%> in " | 8863 error_at (loc, |
7526 "declaration specifiers"); | 8864 ("both %<long%> and %<float%> in " |
8865 "declaration specifiers")); | |
7527 else if (specs->short_p) | 8866 else if (specs->short_p) |
7528 error ("both %<short%> and %<float%> in " | 8867 error_at (loc, |
7529 "declaration specifiers"); | 8868 ("both %<short%> and %<float%> in " |
8869 "declaration specifiers")); | |
7530 else if (specs->signed_p) | 8870 else if (specs->signed_p) |
7531 error ("both %<signed%> and %<float%> in " | 8871 error_at (loc, |
7532 "declaration specifiers"); | 8872 ("both %<signed%> and %<float%> in " |
8873 "declaration specifiers")); | |
7533 else if (specs->unsigned_p) | 8874 else if (specs->unsigned_p) |
7534 error ("both %<unsigned%> and %<float%> in " | 8875 error_at (loc, |
7535 "declaration specifiers"); | 8876 ("both %<unsigned%> and %<float%> in " |
8877 "declaration specifiers")); | |
7536 else if (specs->saturating_p) | 8878 else if (specs->saturating_p) |
7537 error ("both %<_Sat%> and %<float%> in " | 8879 error_at (loc, |
7538 "declaration specifiers"); | 8880 ("both %<_Sat%> and %<float%> in " |
8881 "declaration specifiers")); | |
7539 else | 8882 else |
7540 specs->typespec_word = cts_float; | 8883 specs->typespec_word = cts_float; |
7541 return specs; | 8884 return specs; |
7542 case RID_DOUBLE: | 8885 case RID_DOUBLE: |
7543 if (specs->long_long_p) | 8886 if (specs->long_long_p) |
7544 error ("both %<long long%> and %<double%> in " | 8887 error_at (loc, |
7545 "declaration specifiers"); | 8888 ("both %<long long%> and %<double%> in " |
8889 "declaration specifiers")); | |
7546 else if (specs->short_p) | 8890 else if (specs->short_p) |
7547 error ("both %<short%> and %<double%> in " | 8891 error_at (loc, |
7548 "declaration specifiers"); | 8892 ("both %<short%> and %<double%> in " |
8893 "declaration specifiers")); | |
7549 else if (specs->signed_p) | 8894 else if (specs->signed_p) |
7550 error ("both %<signed%> and %<double%> in " | 8895 error_at (loc, |
7551 "declaration specifiers"); | 8896 ("both %<signed%> and %<double%> in " |
8897 "declaration specifiers")); | |
7552 else if (specs->unsigned_p) | 8898 else if (specs->unsigned_p) |
7553 error ("both %<unsigned%> and %<double%> in " | 8899 error_at (loc, |
7554 "declaration specifiers"); | 8900 ("both %<unsigned%> and %<double%> in " |
8901 "declaration specifiers")); | |
7555 else if (specs->saturating_p) | 8902 else if (specs->saturating_p) |
7556 error ("both %<_Sat%> and %<double%> in " | 8903 error_at (loc, |
7557 "declaration specifiers"); | 8904 ("both %<_Sat%> and %<double%> in " |
8905 "declaration specifiers")); | |
7558 else | 8906 else |
7559 specs->typespec_word = cts_double; | 8907 specs->typespec_word = cts_double; |
7560 return specs; | 8908 return specs; |
7561 case RID_DFLOAT32: | 8909 case RID_DFLOAT32: |
7562 case RID_DFLOAT64: | 8910 case RID_DFLOAT64: |
7563 case RID_DFLOAT128: | 8911 case RID_DFLOAT128: |
7564 { | 8912 { |
7565 const char *str; | 8913 const char *str; |
7566 if (i == RID_DFLOAT32) | 8914 if (i == RID_DFLOAT32) |
7567 str = "_Decimal32"; | 8915 str = "_Decimal32"; |
7568 else if (i == RID_DFLOAT64) | 8916 else if (i == RID_DFLOAT64) |
7569 str = "_Decimal64"; | 8917 str = "_Decimal64"; |
7570 else | 8918 else |
7571 str = "_Decimal128"; | 8919 str = "_Decimal128"; |
7572 if (specs->long_long_p) | 8920 if (specs->long_long_p) |
7573 error ("both %<long long%> and %<%s%> in " | 8921 error_at (loc, |
7574 "declaration specifiers", str); | 8922 ("both %<long long%> and %<%s%> in " |
8923 "declaration specifiers"), | |
8924 str); | |
7575 if (specs->long_p) | 8925 if (specs->long_p) |
7576 error ("both %<long%> and %<%s%> in " | 8926 error_at (loc, |
7577 "declaration specifiers", str); | 8927 ("both %<long%> and %<%s%> in " |
8928 "declaration specifiers"), | |
8929 str); | |
7578 else if (specs->short_p) | 8930 else if (specs->short_p) |
7579 error ("both %<short%> and %<%s%> in " | 8931 error_at (loc, |
7580 "declaration specifiers", str); | 8932 ("both %<short%> and %<%s%> in " |
8933 "declaration specifiers"), | |
8934 str); | |
7581 else if (specs->signed_p) | 8935 else if (specs->signed_p) |
7582 error ("both %<signed%> and %<%s%> in " | 8936 error_at (loc, |
7583 "declaration specifiers", str); | 8937 ("both %<signed%> and %<%s%> in " |
8938 "declaration specifiers"), | |
8939 str); | |
7584 else if (specs->unsigned_p) | 8940 else if (specs->unsigned_p) |
7585 error ("both %<unsigned%> and %<%s%> in " | 8941 error_at (loc, |
7586 "declaration specifiers", str); | 8942 ("both %<unsigned%> and %<%s%> in " |
8943 "declaration specifiers"), | |
8944 str); | |
7587 else if (specs->complex_p) | 8945 else if (specs->complex_p) |
7588 error ("both %<complex%> and %<%s%> in " | 8946 error_at (loc, |
7589 "declaration specifiers", str); | 8947 ("both %<complex%> and %<%s%> in " |
8948 "declaration specifiers"), | |
8949 str); | |
7590 else if (specs->saturating_p) | 8950 else if (specs->saturating_p) |
7591 error ("both %<_Sat%> and %<%s%> in " | 8951 error_at (loc, |
7592 "declaration specifiers", str); | 8952 ("both %<_Sat%> and %<%s%> in " |
8953 "declaration specifiers"), | |
8954 str); | |
7593 else if (i == RID_DFLOAT32) | 8955 else if (i == RID_DFLOAT32) |
7594 specs->typespec_word = cts_dfloat32; | 8956 specs->typespec_word = cts_dfloat32; |
7595 else if (i == RID_DFLOAT64) | 8957 else if (i == RID_DFLOAT64) |
7596 specs->typespec_word = cts_dfloat64; | 8958 specs->typespec_word = cts_dfloat64; |
7597 else | 8959 else |
7598 specs->typespec_word = cts_dfloat128; | 8960 specs->typespec_word = cts_dfloat128; |
7599 } | 8961 } |
7600 if (!targetm.decimal_float_supported_p ()) | 8962 if (!targetm.decimal_float_supported_p ()) |
7601 error ("decimal floating point not supported for this target"); | 8963 error_at (loc, |
7602 pedwarn (input_location, OPT_pedantic, | 8964 ("decimal floating point not supported " |
8965 "for this target")); | |
8966 pedwarn (loc, OPT_pedantic, | |
7603 "ISO C does not support decimal floating point"); | 8967 "ISO C does not support decimal floating point"); |
7604 return specs; | 8968 return specs; |
7605 case RID_FRACT: | 8969 case RID_FRACT: |
7606 case RID_ACCUM: | 8970 case RID_ACCUM: |
7607 { | 8971 { |
7609 if (i == RID_FRACT) | 8973 if (i == RID_FRACT) |
7610 str = "_Fract"; | 8974 str = "_Fract"; |
7611 else | 8975 else |
7612 str = "_Accum"; | 8976 str = "_Accum"; |
7613 if (specs->complex_p) | 8977 if (specs->complex_p) |
7614 error ("both %<complex%> and %<%s%> in " | 8978 error_at (loc, |
7615 "declaration specifiers", str); | 8979 ("both %<complex%> and %<%s%> in " |
8980 "declaration specifiers"), | |
8981 str); | |
7616 else if (i == RID_FRACT) | 8982 else if (i == RID_FRACT) |
7617 specs->typespec_word = cts_fract; | 8983 specs->typespec_word = cts_fract; |
7618 else | 8984 else |
7619 specs->typespec_word = cts_accum; | 8985 specs->typespec_word = cts_accum; |
7620 } | 8986 } |
7621 if (!targetm.fixed_point_supported_p ()) | 8987 if (!targetm.fixed_point_supported_p ()) |
7622 error ("fixed-point types not supported for this target"); | 8988 error_at (loc, |
7623 pedwarn (input_location, OPT_pedantic, | 8989 "fixed-point types not supported for this target"); |
8990 pedwarn (loc, OPT_pedantic, | |
7624 "ISO C does not support fixed-point types"); | 8991 "ISO C does not support fixed-point types"); |
7625 return specs; | 8992 return specs; |
7626 default: | 8993 default: |
7627 /* ObjC reserved word "id", handled below. */ | 8994 /* ObjC reserved word "id", handled below. */ |
7628 break; | 8995 break; |
7636 ERROR_MARK. In none of these cases may there have previously | 9003 ERROR_MARK. In none of these cases may there have previously |
7637 been any type specifiers. */ | 9004 been any type specifiers. */ |
7638 if (specs->type || specs->typespec_word != cts_none | 9005 if (specs->type || specs->typespec_word != cts_none |
7639 || specs->long_p || specs->short_p || specs->signed_p | 9006 || specs->long_p || specs->short_p || specs->signed_p |
7640 || specs->unsigned_p || specs->complex_p) | 9007 || specs->unsigned_p || specs->complex_p) |
7641 error ("two or more data types in declaration specifiers"); | 9008 error_at (loc, "two or more data types in declaration specifiers"); |
7642 else if (TREE_CODE (type) == TYPE_DECL) | 9009 else if (TREE_CODE (type) == TYPE_DECL) |
7643 { | 9010 { |
7644 if (TREE_TYPE (type) == error_mark_node) | 9011 if (TREE_TYPE (type) == error_mark_node) |
7645 ; /* Allow the type to default to int to avoid cascading errors. */ | 9012 ; /* Allow the type to default to int to avoid cascading errors. */ |
7646 else | 9013 else |
7647 { | 9014 { |
7648 specs->type = TREE_TYPE (type); | 9015 specs->type = TREE_TYPE (type); |
7649 specs->decl_attr = DECL_ATTRIBUTES (type); | 9016 specs->decl_attr = DECL_ATTRIBUTES (type); |
7650 specs->typedef_p = true; | 9017 specs->typedef_p = true; |
7651 specs->explicit_signed_p = C_TYPEDEF_EXPLICITLY_SIGNED (type); | 9018 specs->explicit_signed_p = C_TYPEDEF_EXPLICITLY_SIGNED (type); |
9019 | |
9020 /* If this typedef name is defined in a struct, then a C++ | |
9021 lookup would return a different value. */ | |
9022 if (warn_cxx_compat | |
9023 && I_SYMBOL_BINDING (DECL_NAME (type))->in_struct) | |
9024 warning_at (loc, OPT_Wc___compat, | |
9025 "C++ lookup of %qD would return a field, not a type", | |
9026 type); | |
9027 | |
9028 /* If we are parsing a struct, record that a struct field | |
9029 used a typedef. */ | |
9030 if (warn_cxx_compat && struct_parse_info != NULL) | |
9031 VEC_safe_push (tree, heap, struct_parse_info->typedefs_seen, type); | |
7652 } | 9032 } |
7653 } | 9033 } |
7654 else if (TREE_CODE (type) == IDENTIFIER_NODE) | 9034 else if (TREE_CODE (type) == IDENTIFIER_NODE) |
7655 { | 9035 { |
7656 tree t = lookup_name (type); | 9036 tree t = lookup_name (type); |
7657 if (!t || TREE_CODE (t) != TYPE_DECL) | 9037 if (!t || TREE_CODE (t) != TYPE_DECL) |
7658 error ("%qE fails to be a typedef or built in type", type); | 9038 error_at (loc, "%qE fails to be a typedef or built in type", type); |
7659 else if (TREE_TYPE (t) == error_mark_node) | 9039 else if (TREE_TYPE (t) == error_mark_node) |
7660 ; | 9040 ; |
7661 else | 9041 else |
7662 specs->type = TREE_TYPE (t); | 9042 specs->type = TREE_TYPE (t); |
7663 } | 9043 } |
7664 else if (TREE_CODE (type) != ERROR_MARK) | 9044 else if (TREE_CODE (type) != ERROR_MARK) |
7665 { | 9045 { |
7666 if (spec.kind == ctsk_tagdef || spec.kind == ctsk_tagfirstref) | 9046 if (spec.kind == ctsk_tagdef || spec.kind == ctsk_tagfirstref) |
7667 specs->tag_defined_p = true; | 9047 specs->tag_defined_p = true; |
7668 if (spec.kind == ctsk_typeof) | 9048 if (spec.kind == ctsk_typeof) |
7669 specs->typedef_p = true; | 9049 { |
9050 specs->typedef_p = true; | |
9051 if (spec.expr) | |
9052 { | |
9053 if (specs->expr) | |
9054 specs->expr = build2 (COMPOUND_EXPR, TREE_TYPE (spec.expr), | |
9055 specs->expr, spec.expr); | |
9056 else | |
9057 specs->expr = spec.expr; | |
9058 specs->expr_const_operands &= spec.expr_const_operands; | |
9059 } | |
9060 } | |
7670 specs->type = type; | 9061 specs->type = type; |
7671 } | 9062 } |
7672 | 9063 |
7673 return specs; | 9064 return specs; |
7674 } | 9065 } |
7685 specs->declspecs_seen_p = true; | 9076 specs->declspecs_seen_p = true; |
7686 gcc_assert (TREE_CODE (scspec) == IDENTIFIER_NODE | 9077 gcc_assert (TREE_CODE (scspec) == IDENTIFIER_NODE |
7687 && C_IS_RESERVED_WORD (scspec)); | 9078 && C_IS_RESERVED_WORD (scspec)); |
7688 i = C_RID_CODE (scspec); | 9079 i = C_RID_CODE (scspec); |
7689 if (specs->non_sc_seen_p) | 9080 if (specs->non_sc_seen_p) |
7690 warning (OPT_Wold_style_declaration, | 9081 warning (OPT_Wold_style_declaration, |
7691 "%qE is not at beginning of declaration", scspec); | 9082 "%qE is not at beginning of declaration", scspec); |
7692 switch (i) | 9083 switch (i) |
7693 { | 9084 { |
7694 case RID_INLINE: | 9085 case RID_INLINE: |
7695 /* C99 permits duplicate inline. Although of doubtful utility, | 9086 /* C99 permits duplicate inline. Although of doubtful utility, |
7807 specs->typespec_word = cts_int; | 9198 specs->typespec_word = cts_int; |
7808 } | 9199 } |
7809 else if (specs->complex_p) | 9200 else if (specs->complex_p) |
7810 { | 9201 { |
7811 specs->typespec_word = cts_double; | 9202 specs->typespec_word = cts_double; |
7812 pedwarn (input_location, OPT_pedantic, | 9203 pedwarn (input_location, OPT_pedantic, |
7813 "ISO C does not support plain %<complex%> meaning " | 9204 "ISO C does not support plain %<complex%> meaning " |
7814 "%<double complex%>"); | 9205 "%<double complex%>"); |
7815 } | 9206 } |
7816 else | 9207 else |
7817 { | 9208 { |
7852 specs->type = unsigned_char_type_node; | 9243 specs->type = unsigned_char_type_node; |
7853 else | 9244 else |
7854 specs->type = char_type_node; | 9245 specs->type = char_type_node; |
7855 if (specs->complex_p) | 9246 if (specs->complex_p) |
7856 { | 9247 { |
7857 pedwarn (input_location, OPT_pedantic, | 9248 pedwarn (input_location, OPT_pedantic, |
7858 "ISO C does not support complex integer types"); | 9249 "ISO C does not support complex integer types"); |
7859 specs->type = build_complex_type (specs->type); | 9250 specs->type = build_complex_type (specs->type); |
7860 } | 9251 } |
7861 break; | 9252 break; |
7862 case cts_int: | 9253 case cts_int: |
7878 specs->type = (specs->unsigned_p | 9269 specs->type = (specs->unsigned_p |
7879 ? unsigned_type_node | 9270 ? unsigned_type_node |
7880 : integer_type_node); | 9271 : integer_type_node); |
7881 if (specs->complex_p) | 9272 if (specs->complex_p) |
7882 { | 9273 { |
7883 pedwarn (input_location, OPT_pedantic, | 9274 pedwarn (input_location, OPT_pedantic, |
7884 "ISO C does not support complex integer types"); | 9275 "ISO C does not support complex integer types"); |
7885 specs->type = build_complex_type (specs->type); | 9276 specs->type = build_complex_type (specs->type); |
7886 } | 9277 } |
7887 break; | 9278 break; |
7888 case cts_float: | 9279 case cts_float: |
8076 | 9467 |
8077 /* We don't want to do this if generating a PCH. */ | 9468 /* We don't want to do this if generating a PCH. */ |
8078 if (pch_file) | 9469 if (pch_file) |
8079 return; | 9470 return; |
8080 | 9471 |
8081 /* Don't waste time on further processing if -fsyntax-only or we've | 9472 /* Don't waste time on further processing if -fsyntax-only. |
8082 encountered errors. */ | 9473 Continue for warning and errors issued during lowering though. */ |
8083 if (flag_syntax_only || errorcount || sorrycount || cpp_errors (parse_in)) | 9474 if (flag_syntax_only) |
8084 return; | 9475 return; |
8085 | 9476 |
8086 /* Close the external scope. */ | 9477 /* Close the external scope. */ |
8087 ext_block = pop_scope (); | 9478 ext_block = pop_scope (); |
8088 external_scope = 0; | 9479 external_scope = 0; |
8106 c_write_global_declarations_1 (BLOCK_VARS (DECL_INITIAL (t))); | 9497 c_write_global_declarations_1 (BLOCK_VARS (DECL_INITIAL (t))); |
8107 c_write_global_declarations_1 (BLOCK_VARS (ext_block)); | 9498 c_write_global_declarations_1 (BLOCK_VARS (ext_block)); |
8108 | 9499 |
8109 /* We're done parsing; proceed to optimize and emit assembly. | 9500 /* We're done parsing; proceed to optimize and emit assembly. |
8110 FIXME: shouldn't be the front end's responsibility to call this. */ | 9501 FIXME: shouldn't be the front end's responsibility to call this. */ |
8111 cgraph_optimize (); | 9502 cgraph_finalize_compilation_unit (); |
8112 | 9503 |
8113 /* After cgraph has had a chance to emit everything that's going to | 9504 /* After cgraph has had a chance to emit everything that's going to |
8114 be emitted, output debug information for globals. */ | 9505 be emitted, output debug information for globals. */ |
8115 if (errorcount == 0 && sorrycount == 0) | 9506 if (errorcount == 0 && sorrycount == 0) |
8116 { | 9507 { |