| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: func.c,v 1.114 2021/07/20 19:35:53 rillig Exp $ */ | | 1 | /* $NetBSD: func.c,v 1.115 2021/07/23 17:06:37 rillig Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1994, 1995 Jochen Pohl | | 4 | * Copyright (c) 1994, 1995 Jochen Pohl |
5 | * All Rights Reserved. | | 5 | * All Rights Reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -27,27 +27,27 @@ | | | @@ -27,27 +27,27 @@ |
27 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | | 27 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
28 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | | 28 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
29 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | 29 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | | 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
31 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | | 31 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
32 | */ | | 32 | */ |
33 | | | 33 | |
34 | #if HAVE_NBTOOL_CONFIG_H | | 34 | #if HAVE_NBTOOL_CONFIG_H |
35 | #include "nbtool_config.h" | | 35 | #include "nbtool_config.h" |
36 | #endif | | 36 | #endif |
37 | | | 37 | |
38 | #include <sys/cdefs.h> | | 38 | #include <sys/cdefs.h> |
39 | #if defined(__RCSID) && !defined(lint) | | 39 | #if defined(__RCSID) && !defined(lint) |
40 | __RCSID("$NetBSD: func.c,v 1.114 2021/07/20 19:35:53 rillig Exp $"); | | 40 | __RCSID("$NetBSD: func.c,v 1.115 2021/07/23 17:06:37 rillig Exp $"); |
41 | #endif | | 41 | #endif |
42 | | | 42 | |
43 | #include <stdlib.h> | | 43 | #include <stdlib.h> |
44 | #include <string.h> | | 44 | #include <string.h> |
45 | | | 45 | |
46 | #include "lint1.h" | | 46 | #include "lint1.h" |
47 | #include "cgram.h" | | 47 | #include "cgram.h" |
48 | | | 48 | |
49 | /* | | 49 | /* |
50 | * Contains a pointer to the symbol table entry of the current function | | 50 | * Contains a pointer to the symbol table entry of the current function |
51 | * definition. | | 51 | * definition. |
52 | */ | | 52 | */ |
53 | sym_t *funcsym; | | 53 | sym_t *funcsym; |
| @@ -66,27 +66,27 @@ bool warn_about_unreachable; | | | @@ -66,27 +66,27 @@ bool warn_about_unreachable; |
66 | * warnings. | | 66 | * warnings. |
67 | * Reset by each statement and set by FALLTHROUGH, switch (switch1()) | | 67 | * Reset by each statement and set by FALLTHROUGH, switch (switch1()) |
68 | * and case (label()). | | 68 | * and case (label()). |
69 | * | | 69 | * |
70 | * Control statements if, for, while and switch do not reset seen_fallthrough | | 70 | * Control statements if, for, while and switch do not reset seen_fallthrough |
71 | * because this must be done by the controlled statement. At least for if this | | 71 | * because this must be done by the controlled statement. At least for if this |
72 | * is important because ** FALLTHROUGH ** after "if (expr) statement" is | | 72 | * is important because ** FALLTHROUGH ** after "if (expr) statement" is |
73 | * evaluated before the following token, which causes reduction of above. | | 73 | * evaluated before the following token, which causes reduction of above. |
74 | * This means that ** FALLTHROUGH ** after "if ..." would always be ignored. | | 74 | * This means that ** FALLTHROUGH ** after "if ..." would always be ignored. |
75 | */ | | 75 | */ |
76 | bool seen_fallthrough; | | 76 | bool seen_fallthrough; |
77 | | | 77 | |
78 | /* The innermost control statement */ | | 78 | /* The innermost control statement */ |
79 | cstk_t *cstmt; | | 79 | control_statement *cstmt; |
80 | | | 80 | |
81 | /* | | 81 | /* |
82 | * Number of arguments which will be checked for usage in following | | 82 | * Number of arguments which will be checked for usage in following |
83 | * function definition. -1 stands for all arguments. | | 83 | * function definition. -1 stands for all arguments. |
84 | * | | 84 | * |
85 | * The position of the last ARGSUSED comment is stored in argsused_pos. | | 85 | * The position of the last ARGSUSED comment is stored in argsused_pos. |
86 | */ | | 86 | */ |
87 | int nargusg = -1; | | 87 | int nargusg = -1; |
88 | pos_t argsused_pos; | | 88 | pos_t argsused_pos; |
89 | | | 89 | |
90 | /* | | 90 | /* |
91 | * Number of arguments of the following function definition whose types | | 91 | * Number of arguments of the following function definition whose types |
92 | * shall be checked by lint2. -1 stands for all arguments. | | 92 | * shall be checked by lint2. -1 stands for all arguments. |
| @@ -145,58 +145,58 @@ bool bitfieldtype_ok; | | | @@ -145,58 +145,58 @@ bool bitfieldtype_ok; |
145 | | | 145 | |
146 | /* | | 146 | /* |
147 | * Whether complaints about use of "long long" are suppressed in | | 147 | * Whether complaints about use of "long long" are suppressed in |
148 | * the next statement or declaration. | | 148 | * the next statement or declaration. |
149 | */ | | 149 | */ |
150 | bool quadflg; | | 150 | bool quadflg; |
151 | | | 151 | |
152 | /* | | 152 | /* |
153 | * Puts a new element at the top of the stack used for control statements. | | 153 | * Puts a new element at the top of the stack used for control statements. |
154 | */ | | 154 | */ |
155 | void | | 155 | void |
156 | begin_control_statement(control_statement_kind kind) | | 156 | begin_control_statement(control_statement_kind kind) |
157 | { | | 157 | { |
158 | cstk_t *ci; | | 158 | control_statement *cs; |
159 | | | 159 | |
160 | ci = xcalloc(1, sizeof(*ci)); | | 160 | cs = xcalloc(1, sizeof(*cs)); |
161 | ci->c_kind = kind; | | 161 | cs->c_kind = kind; |
162 | ci->c_surrounding = cstmt; | | 162 | cs->c_surrounding = cstmt; |
163 | cstmt = ci; | | 163 | cstmt = cs; |
164 | } | | 164 | } |
165 | | | 165 | |
166 | /* | | 166 | /* |
167 | * Removes the top element of the stack used for control statements. | | 167 | * Removes the top element of the stack used for control statements. |
168 | */ | | 168 | */ |
169 | void | | 169 | void |
170 | end_control_statement(control_statement_kind kind) | | 170 | end_control_statement(control_statement_kind kind) |
171 | { | | 171 | { |
172 | cstk_t *ci; | | 172 | control_statement *cs; |
173 | case_label_t *cl, *next; | | 173 | case_label_t *cl, *next; |
174 | | | 174 | |
175 | lint_assert(cstmt != NULL); | | 175 | lint_assert(cstmt != NULL); |
176 | | | 176 | |
177 | while (cstmt->c_kind != kind) | | 177 | while (cstmt->c_kind != kind) |
178 | cstmt = cstmt->c_surrounding; | | 178 | cstmt = cstmt->c_surrounding; |
179 | | | 179 | |
180 | ci = cstmt; | | 180 | cs = cstmt; |
181 | cstmt = ci->c_surrounding; | | 181 | cstmt = cs->c_surrounding; |
182 | | | 182 | |
183 | for (cl = ci->c_case_labels; cl != NULL; cl = next) { | | 183 | for (cl = cs->c_case_labels; cl != NULL; cl = next) { |
184 | next = cl->cl_next; | | 184 | next = cl->cl_next; |
185 | free(cl); | | 185 | free(cl); |
186 | } | | 186 | } |
187 | | | 187 | |
188 | free(ci->c_switch_type); | | 188 | free(cs->c_switch_type); |
189 | free(ci); | | 189 | free(cs); |
190 | } | | 190 | } |
191 | | | 191 | |
192 | static void | | 192 | static void |
193 | set_reached(bool new_reached) | | 193 | set_reached(bool new_reached) |
194 | { | | 194 | { |
195 | #ifdef DEBUG | | 195 | #ifdef DEBUG |
196 | printf("%s:%d: %s -> %s\n", curr_pos.p_file, curr_pos.p_line, | | 196 | printf("%s:%d: %s -> %s\n", curr_pos.p_file, curr_pos.p_line, |
197 | reached ? "reachable" : "unreachable", | | 197 | reached ? "reachable" : "unreachable", |
198 | new_reached ? "reachable" : "unreachable"); | | 198 | new_reached ? "reachable" : "unreachable"); |
199 | #endif | | 199 | #endif |
200 | reached = new_reached; | | 200 | reached = new_reached; |
201 | warn_about_unreachable = true; | | 201 | warn_about_unreachable = true; |
202 | } | | 202 | } |
| @@ -455,157 +455,157 @@ check_case_label_bitand(const tnode_t *c | | | @@ -455,157 +455,157 @@ check_case_label_bitand(const tnode_t *c |
455 | return; | | 455 | return; |
456 | | | 456 | |
457 | lint_assert(case_expr->tn_op == CON); | | 457 | lint_assert(case_expr->tn_op == CON); |
458 | case_value = case_expr->tn_val->v_quad; | | 458 | case_value = case_expr->tn_val->v_quad; |
459 | mask = switch_expr->tn_right->tn_val->v_quad; | | 459 | mask = switch_expr->tn_right->tn_val->v_quad; |
460 | | | 460 | |
461 | if ((case_value & ~mask) != 0) { | | 461 | if ((case_value & ~mask) != 0) { |
462 | /* statement not reached */ | | 462 | /* statement not reached */ |
463 | warning(193); | | 463 | warning(193); |
464 | } | | 464 | } |
465 | } | | 465 | } |
466 | | | 466 | |
467 | static void | | 467 | static void |
468 | check_case_label_enum(const tnode_t *tn, const cstk_t *ci) | | 468 | check_case_label_enum(const tnode_t *tn, const control_statement *cs) |
469 | { | | 469 | { |
470 | /* similar to typeok_enum in tree.c */ | | 470 | /* similar to typeok_enum in tree.c */ |
471 | | | 471 | |
472 | if (!(tn->tn_type->t_is_enum || ci->c_switch_type->t_is_enum)) | | 472 | if (!(tn->tn_type->t_is_enum || cs->c_switch_type->t_is_enum)) |
473 | return; | | 473 | return; |
474 | if (tn->tn_type->t_is_enum && ci->c_switch_type->t_is_enum && | | 474 | if (tn->tn_type->t_is_enum && cs->c_switch_type->t_is_enum && |
475 | tn->tn_type->t_enum == ci->c_switch_type->t_enum) | | 475 | tn->tn_type->t_enum == cs->c_switch_type->t_enum) |
476 | return; | | 476 | return; |
477 | | | 477 | |
478 | #if 0 /* not yet ready, see msg_130.c */ | | 478 | #if 0 /* not yet ready, see msg_130.c */ |
479 | /* enum type mismatch: '%s' '%s' '%s' */ | | 479 | /* enum type mismatch: '%s' '%s' '%s' */ |
480 | warning(130, type_name(ci->c_switch_type), op_name(EQ), | | 480 | warning(130, type_name(cs->c_switch_type), op_name(EQ), |
481 | type_name(tn->tn_type)); | | 481 | type_name(tn->tn_type)); |
482 | #endif | | 482 | #endif |
483 | } | | 483 | } |
484 | | | 484 | |
485 | static void | | 485 | static void |
486 | check_case_label(tnode_t *tn, cstk_t *ci) | | 486 | check_case_label(tnode_t *tn, control_statement *cs) |
487 | { | | 487 | { |
488 | case_label_t *cl; | | 488 | case_label_t *cl; |
489 | val_t *v; | | 489 | val_t *v; |
490 | val_t nv; | | 490 | val_t nv; |
491 | tspec_t t; | | 491 | tspec_t t; |
492 | | | 492 | |
493 | if (ci == NULL) { | | 493 | if (cs == NULL) { |
494 | /* case not in switch */ | | 494 | /* case not in switch */ |
495 | error(195); | | 495 | error(195); |
496 | return; | | 496 | return; |
497 | } | | 497 | } |
498 | | | 498 | |
499 | if (tn != NULL && tn->tn_op != CON) { | | 499 | if (tn != NULL && tn->tn_op != CON) { |
500 | /* non-constant case expression */ | | 500 | /* non-constant case expression */ |
501 | error(197); | | 501 | error(197); |
502 | return; | | 502 | return; |
503 | } | | 503 | } |
504 | | | 504 | |
505 | if (tn != NULL && !is_integer(tn->tn_type->t_tspec)) { | | 505 | if (tn != NULL && !is_integer(tn->tn_type->t_tspec)) { |
506 | /* non-integral case expression */ | | 506 | /* non-integral case expression */ |
507 | error(198); | | 507 | error(198); |
508 | return; | | 508 | return; |
509 | } | | 509 | } |
510 | | | 510 | |
511 | check_case_label_bitand(tn, ci->c_switch_expr); | | 511 | check_case_label_bitand(tn, cs->c_switch_expr); |
512 | check_case_label_enum(tn, ci); | | 512 | check_case_label_enum(tn, cs); |
513 | | | 513 | |
514 | lint_assert(ci->c_switch_type != NULL); | | 514 | lint_assert(cs->c_switch_type != NULL); |
515 | | | 515 | |
516 | if (reached && !seen_fallthrough) { | | 516 | if (reached && !seen_fallthrough) { |
517 | if (hflag) | | 517 | if (hflag) |
518 | /* fallthrough on case statement */ | | 518 | /* fallthrough on case statement */ |
519 | warning(220); | | 519 | warning(220); |
520 | } | | 520 | } |
521 | | | 521 | |
522 | t = tn->tn_type->t_tspec; | | 522 | t = tn->tn_type->t_tspec; |
523 | if (t == LONG || t == ULONG || | | 523 | if (t == LONG || t == ULONG || |
524 | t == QUAD || t == UQUAD) { | | 524 | t == QUAD || t == UQUAD) { |
525 | if (tflag) | | 525 | if (tflag) |
526 | /* case label must be of type `int' in traditional C */ | | 526 | /* case label must be of type `int' in traditional C */ |
527 | warning(203); | | 527 | warning(203); |
528 | } | | 528 | } |
529 | | | 529 | |
530 | /* | | 530 | /* |
531 | * get the value of the expression and convert it | | 531 | * get the value of the expression and convert it |
532 | * to the type of the switch expression | | 532 | * to the type of the switch expression |
533 | */ | | 533 | */ |
534 | v = constant(tn, true); | | 534 | v = constant(tn, true); |
535 | (void)memset(&nv, 0, sizeof(nv)); | | 535 | (void)memset(&nv, 0, sizeof(nv)); |
536 | convert_constant(CASE, 0, ci->c_switch_type, &nv, v); | | 536 | convert_constant(CASE, 0, cs->c_switch_type, &nv, v); |
537 | free(v); | | 537 | free(v); |
538 | | | 538 | |
539 | /* look if we had this value already */ | | 539 | /* look if we had this value already */ |
540 | for (cl = ci->c_case_labels; cl != NULL; cl = cl->cl_next) { | | 540 | for (cl = cs->c_case_labels; cl != NULL; cl = cl->cl_next) { |
541 | if (cl->cl_val.v_quad == nv.v_quad) | | 541 | if (cl->cl_val.v_quad == nv.v_quad) |
542 | break; | | 542 | break; |
543 | } | | 543 | } |
544 | if (cl != NULL && is_uinteger(nv.v_tspec)) { | | 544 | if (cl != NULL && is_uinteger(nv.v_tspec)) { |
545 | /* duplicate case in switch: %lu */ | | 545 | /* duplicate case in switch: %lu */ |
546 | error(200, (u_long)nv.v_quad); | | 546 | error(200, (u_long)nv.v_quad); |
547 | } else if (cl != NULL) { | | 547 | } else if (cl != NULL) { |
548 | /* duplicate case in switch: %ld */ | | 548 | /* duplicate case in switch: %ld */ |
549 | error(199, (long)nv.v_quad); | | 549 | error(199, (long)nv.v_quad); |
550 | } else { | | 550 | } else { |
551 | check_getopt_case_label(nv.v_quad); | | 551 | check_getopt_case_label(nv.v_quad); |
552 | | | 552 | |
553 | /* append the value to the list of case values */ | | 553 | /* append the value to the list of case values */ |
554 | cl = xcalloc(1, sizeof(*cl)); | | 554 | cl = xcalloc(1, sizeof(*cl)); |
555 | cl->cl_val = nv; | | 555 | cl->cl_val = nv; |
556 | cl->cl_next = ci->c_case_labels; | | 556 | cl->cl_next = cs->c_case_labels; |
557 | ci->c_case_labels = cl; | | 557 | cs->c_case_labels = cl; |
558 | } | | 558 | } |
559 | } | | 559 | } |
560 | | | 560 | |
561 | void | | 561 | void |
562 | case_label(tnode_t *tn) | | 562 | case_label(tnode_t *tn) |
563 | { | | 563 | { |
564 | cstk_t *ci; | | 564 | control_statement *cs; |
565 | | | 565 | |
566 | /* find the innermost switch statement */ | | 566 | /* find the innermost switch statement */ |
567 | for (ci = cstmt; ci != NULL && !ci->c_switch; ci = ci->c_surrounding) | | 567 | for (cs = cstmt; cs != NULL && !cs->c_switch; cs = cs->c_surrounding) |
568 | continue; | | 568 | continue; |
569 | | | 569 | |
570 | check_case_label(tn, ci); | | 570 | check_case_label(tn, cs); |
571 | | | 571 | |
572 | expr_free_all(); | | 572 | expr_free_all(); |
573 | | | 573 | |
574 | set_reached(true); | | 574 | set_reached(true); |
575 | } | | 575 | } |
576 | | | 576 | |
577 | void | | 577 | void |
578 | default_label(void) | | 578 | default_label(void) |
579 | { | | 579 | { |
580 | cstk_t *ci; | | 580 | control_statement *cs; |
581 | | | 581 | |
582 | /* find the innermost switch statement */ | | 582 | /* find the innermost switch statement */ |
583 | for (ci = cstmt; ci != NULL && !ci->c_switch; ci = ci->c_surrounding) | | 583 | for (cs = cstmt; cs != NULL && !cs->c_switch; cs = cs->c_surrounding) |
584 | continue; | | 584 | continue; |
585 | | | 585 | |
586 | if (ci == NULL) { | | 586 | if (cs == NULL) { |
587 | /* default outside switch */ | | 587 | /* default outside switch */ |
588 | error(201); | | 588 | error(201); |
589 | } else if (ci->c_default) { | | 589 | } else if (cs->c_default) { |
590 | /* duplicate default in switch */ | | 590 | /* duplicate default in switch */ |
591 | error(202); | | 591 | error(202); |
592 | } else { | | 592 | } else { |
593 | if (reached && !seen_fallthrough) { | | 593 | if (reached && !seen_fallthrough) { |
594 | if (hflag) | | 594 | if (hflag) |
595 | /* fallthrough on default statement */ | | 595 | /* fallthrough on default statement */ |
596 | warning(284); | | 596 | warning(284); |
597 | } | | 597 | } |
598 | ci->c_default = true; | | 598 | cs->c_default = true; |
599 | } | | 599 | } |
600 | | | 600 | |
601 | set_reached(true); | | 601 | set_reached(true); |
602 | } | | 602 | } |
603 | | | 603 | |
604 | static tnode_t * | | 604 | static tnode_t * |
605 | check_controlling_expression(tnode_t *tn) | | 605 | check_controlling_expression(tnode_t *tn) |
606 | { | | 606 | { |
607 | | | 607 | |
608 | if (tn != NULL) | | 608 | if (tn != NULL) |
609 | tn = cconv(tn); | | 609 | tn = cconv(tn); |
610 | if (tn != NULL) | | 610 | if (tn != NULL) |
611 | tn = promote(NOOP, false, tn); | | 611 | tn = promote(NOOP, false, tn); |
| @@ -991,95 +991,95 @@ do_goto(sym_t *lab) | | | @@ -991,95 +991,95 @@ do_goto(sym_t *lab) |
991 | mark_as_used(lab, false, false); | | 991 | mark_as_used(lab, false, false); |
992 | | | 992 | |
993 | check_statement_reachable(); | | 993 | check_statement_reachable(); |
994 | | | 994 | |
995 | set_reached(false); | | 995 | set_reached(false); |
996 | } | | 996 | } |
997 | | | 997 | |
998 | /* | | 998 | /* |
999 | * T_BREAK T_SEMI | | 999 | * T_BREAK T_SEMI |
1000 | */ | | 1000 | */ |
1001 | void | | 1001 | void |
1002 | do_break(void) | | 1002 | do_break(void) |
1003 | { | | 1003 | { |
1004 | cstk_t *ci; | | 1004 | control_statement *cs; |
1005 | | | 1005 | |
1006 | ci = cstmt; | | 1006 | cs = cstmt; |
1007 | while (ci != NULL && !ci->c_loop && !ci->c_switch) | | 1007 | while (cs != NULL && !cs->c_loop && !cs->c_switch) |
1008 | ci = ci->c_surrounding; | | 1008 | cs = cs->c_surrounding; |
1009 | | | 1009 | |
1010 | if (ci == NULL) { | | 1010 | if (cs == NULL) { |
1011 | /* break outside loop or switch */ | | 1011 | /* break outside loop or switch */ |
1012 | error(208); | | 1012 | error(208); |
1013 | } else { | | 1013 | } else { |
1014 | if (reached) | | 1014 | if (reached) |
1015 | ci->c_break = true; | | 1015 | cs->c_break = true; |
1016 | } | | 1016 | } |
1017 | | | 1017 | |
1018 | if (bflag) | | 1018 | if (bflag) |
1019 | check_statement_reachable(); | | 1019 | check_statement_reachable(); |
1020 | | | 1020 | |
1021 | set_reached(false); | | 1021 | set_reached(false); |
1022 | } | | 1022 | } |
1023 | | | 1023 | |
1024 | /* | | 1024 | /* |
1025 | * T_CONTINUE T_SEMI | | 1025 | * T_CONTINUE T_SEMI |
1026 | */ | | 1026 | */ |
1027 | void | | 1027 | void |
1028 | do_continue(void) | | 1028 | do_continue(void) |
1029 | { | | 1029 | { |
1030 | cstk_t *ci; | | 1030 | control_statement *cs; |
1031 | | | 1031 | |
1032 | for (ci = cstmt; ci != NULL && !ci->c_loop; ci = ci->c_surrounding) | | 1032 | for (cs = cstmt; cs != NULL && !cs->c_loop; cs = cs->c_surrounding) |
1033 | continue; | | 1033 | continue; |
1034 | | | 1034 | |
1035 | if (ci == NULL) { | | 1035 | if (cs == NULL) { |
1036 | /* continue outside loop */ | | 1036 | /* continue outside loop */ |
1037 | error(209); | | 1037 | error(209); |
1038 | } else { | | 1038 | } else { |
1039 | /* TODO: only if reachable, for symmetry with c_break */ | | 1039 | /* TODO: only if reachable, for symmetry with c_break */ |
1040 | ci->c_continue = true; | | 1040 | cs->c_continue = true; |
1041 | } | | 1041 | } |
1042 | | | 1042 | |
1043 | check_statement_reachable(); | | 1043 | check_statement_reachable(); |
1044 | | | 1044 | |
1045 | set_reached(false); | | 1045 | set_reached(false); |
1046 | } | | 1046 | } |
1047 | | | 1047 | |
1048 | /* | | 1048 | /* |
1049 | * T_RETURN T_SEMI | | 1049 | * T_RETURN T_SEMI |
1050 | * T_RETURN expr T_SEMI | | 1050 | * T_RETURN expr T_SEMI |
1051 | */ | | 1051 | */ |
1052 | void | | 1052 | void |
1053 | do_return(tnode_t *tn) | | 1053 | do_return(tnode_t *tn) |
1054 | { | | 1054 | { |
1055 | tnode_t *ln, *rn; | | 1055 | tnode_t *ln, *rn; |
1056 | cstk_t *ci; | | 1056 | control_statement *cs; |
1057 | op_t op; | | 1057 | op_t op; |
1058 | | | 1058 | |
1059 | ci = cstmt; | | 1059 | cs = cstmt; |
1060 | if (ci == NULL) { | | 1060 | if (cs == NULL) { |
1061 | /* syntax error '%s' */ | | 1061 | /* syntax error '%s' */ |
1062 | error(249, "return outside function"); | | 1062 | error(249, "return outside function"); |
1063 | return; | | 1063 | return; |
1064 | } | | 1064 | } |
1065 | | | 1065 | |
1066 | for (; ci->c_surrounding != NULL; ci = ci->c_surrounding) | | 1066 | for (; cs->c_surrounding != NULL; cs = cs->c_surrounding) |
1067 | continue; | | 1067 | continue; |
1068 | | | 1068 | |
1069 | if (tn != NULL) | | 1069 | if (tn != NULL) |
1070 | ci->c_had_return_value = true; | | 1070 | cs->c_had_return_value = true; |
1071 | else | | 1071 | else |
1072 | ci->c_had_return_noval = true; | | 1072 | cs->c_had_return_noval = true; |
1073 | | | 1073 | |
1074 | if (tn != NULL && funcsym->s_type->t_subt->t_tspec == VOID) { | | 1074 | if (tn != NULL && funcsym->s_type->t_subt->t_tspec == VOID) { |
1075 | /* void function %s cannot return value */ | | 1075 | /* void function %s cannot return value */ |
1076 | error(213, funcsym->s_name); | | 1076 | error(213, funcsym->s_name); |
1077 | expr_free_all(); | | 1077 | expr_free_all(); |
1078 | tn = NULL; | | 1078 | tn = NULL; |
1079 | } else if (tn == NULL && funcsym->s_type->t_subt->t_tspec != VOID) { | | 1079 | } else if (tn == NULL && funcsym->s_type->t_subt->t_tspec != VOID) { |
1080 | /* | | 1080 | /* |
1081 | * Assume that the function has a return value only if it | | 1081 | * Assume that the function has a return value only if it |
1082 | * is explicitly declared. | | 1082 | * is explicitly declared. |
1083 | */ | | 1083 | */ |
1084 | if (!funcsym->s_return_type_implicit_int) | | 1084 | if (!funcsym->s_return_type_implicit_int) |
1085 | /* function %s expects to return value */ | | 1085 | /* function %s expects to return value */ |