| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: func.c,v 1.74 2021/02/28 19:16:05 rillig Exp $ */ | | 1 | /* $NetBSD: func.c,v 1.75 2021/03/05 17:10:05 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.74 2021/02/28 19:16:05 rillig Exp $"); | | 40 | __RCSID("$NetBSD: func.c,v 1.75 2021/03/05 17:10:05 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; |
| @@ -417,51 +417,69 @@ named_label(sym_t *sym) | | | @@ -417,51 +417,69 @@ named_label(sym_t *sym) |
417 | { | | 417 | { |
418 | | | 418 | |
419 | if (sym->s_set) { | | 419 | if (sym->s_set) { |
420 | /* label %s redefined */ | | 420 | /* label %s redefined */ |
421 | error(194, sym->s_name); | | 421 | error(194, sym->s_name); |
422 | } else { | | 422 | } else { |
423 | mark_as_set(sym); | | 423 | mark_as_set(sym); |
424 | } | | 424 | } |
425 | | | 425 | |
426 | reached = true; | | 426 | reached = true; |
427 | } | | 427 | } |
428 | | | 428 | |
429 | static void | | 429 | static void |
| | | 430 | check_case_label_enum(const tnode_t *tn, const cstk_t *ci) |
| | | 431 | { |
| | | 432 | /* similar to typeok_enum in tree.c */ |
| | | 433 | |
| | | 434 | if (!(tn->tn_type->t_is_enum || ci->c_swtype->t_is_enum)) |
| | | 435 | return; |
| | | 436 | if (tn->tn_type->t_is_enum && ci->c_swtype->t_is_enum && |
| | | 437 | tn->tn_type->t_enum == ci->c_swtype->t_enum) |
| | | 438 | return; |
| | | 439 | |
| | | 440 | /* enum type mismatch: '%s' '%s' '%s' */ |
| | | 441 | warning(130, type_name(ci->c_swtype), getopname(EQ), |
| | | 442 | type_name(tn->tn_type)); |
| | | 443 | } |
| | | 444 | |
| | | 445 | static void |
430 | check_case_label(tnode_t *tn, cstk_t *ci) | | 446 | check_case_label(tnode_t *tn, cstk_t *ci) |
431 | { | | 447 | { |
432 | clst_t *cl; | | 448 | clst_t *cl; |
433 | val_t *v; | | 449 | val_t *v; |
434 | val_t nv; | | 450 | val_t nv; |
435 | tspec_t t; | | 451 | tspec_t t; |
436 | | | 452 | |
437 | if (ci == NULL) { | | 453 | if (ci == NULL) { |
438 | /* case not in switch */ | | 454 | /* case not in switch */ |
439 | error(195); | | 455 | error(195); |
440 | return; | | 456 | return; |
441 | } | | 457 | } |
442 | | | 458 | |
443 | if (tn != NULL && tn->tn_op != CON) { | | 459 | if (tn != NULL && tn->tn_op != CON) { |
444 | /* non-constant case expression */ | | 460 | /* non-constant case expression */ |
445 | error(197); | | 461 | error(197); |
446 | return; | | 462 | return; |
447 | } | | 463 | } |
448 | | | 464 | |
449 | if (tn != NULL && !is_integer(tn->tn_type->t_tspec)) { | | 465 | if (tn != NULL && !is_integer(tn->tn_type->t_tspec)) { |
450 | /* non-integral case expression */ | | 466 | /* non-integral case expression */ |
451 | error(198); | | 467 | error(198); |
452 | return; | | 468 | return; |
453 | } | | 469 | } |
454 | | | 470 | |
| | | 471 | check_case_label_enum(tn, ci); |
| | | 472 | |
455 | lint_assert(ci->c_swtype != NULL); | | 473 | lint_assert(ci->c_swtype != NULL); |
456 | | | 474 | |
457 | if (reached && !ftflg) { | | 475 | if (reached && !ftflg) { |
458 | if (hflag) | | 476 | if (hflag) |
459 | /* fallthrough on case statement */ | | 477 | /* fallthrough on case statement */ |
460 | warning(220); | | 478 | warning(220); |
461 | } | | 479 | } |
462 | | | 480 | |
463 | t = tn->tn_type->t_tspec; | | 481 | t = tn->tn_type->t_tspec; |
464 | if (t == LONG || t == ULONG || | | 482 | if (t == LONG || t == ULONG || |
465 | t == QUAD || t == UQUAD) { | | 483 | t == QUAD || t == UQUAD) { |
466 | if (tflag) | | 484 | if (tflag) |
467 | /* case label must be of type `int' in traditional C */ | | 485 | /* case label must be of type `int' in traditional C */ |