lint: rename clrtyp/deftyp to begin_type/end_type The abbreviations clr/def did not make it obvious that these two functions or grammar rules form pairs. No functional change.diff -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/decl_struct_member.c
(rillig)
--- src/tests/usr.bin/xlint/lint1/decl_struct_member.c 2021/06/20 11:24:32 1.2
+++ src/tests/usr.bin/xlint/lint1/decl_struct_member.c 2021/07/10 17:35:54 1.3
@@ -1,25 +1,25 @@ | @@ -1,25 +1,25 @@ | |||
1 | /* $NetBSD: decl_struct_member.c,v 1.2 2021/06/20 11:24:32 rillig Exp $ */ | 1 | /* $NetBSD: decl_struct_member.c,v 1.3 2021/07/10 17:35:54 rillig Exp $ */ | |
2 | # 3 "decl_struct_member.c" | 2 | # 3 "decl_struct_member.c" | |
3 | 3 | |||
4 | /* | 4 | /* | |
5 | * Before cgram.y 1.228 from 2021-06-19, lint ran into an assertion failure: | 5 | * Before cgram.y 1.228 from 2021-06-19, lint ran into an assertion failure: | |
6 | * | 6 | * | |
7 | * "is_struct_or_union(dcs->d_type->t_tspec)" at cgram.y:846 | 7 | * "is_struct_or_union(dcs->d_type->t_tspec)" at cgram.y:846 | |
8 | */ | 8 | */ | |
9 | 9 | |||
10 | struct { | 10 | struct { | |
11 | char; /* expect: syntax error 'unnamed member' */ | 11 | char; /* expect: syntax error 'unnamed member' */ | |
12 | }; | 12 | }; | |
13 | 13 | |||
14 | /* | 14 | /* | |
15 | * Before decl.c 1.188 from 2021-06-20, lint ran into a segmentation fault. | 15 | * Before decl.c 1.188 from 2021-06-20, lint ran into a segmentation fault. | |
16 | */ | 16 | */ | |
17 | struct { | 17 | struct { | |
18 | char a(_)0 /* expect: syntax error '0' */ | 18 | char a(_)0 /* expect: syntax error '0' */ | |
19 | } /* expect: ';' after last */ | 19 | } /* expect: ';' after last */ | |
20 | /* | 20 | /* | |
21 | * FIXME: adding a semicolon here triggers another assertion: | 21 | * FIXME: adding a semicolon here triggers another assertion: | |
22 | * | 22 | * | |
23 | * assertion "t == NOTSPEC" failed in deftyp at decl.c:774 | 23 | * assertion "t == NOTSPEC" failed in end_type at decl.c:774 | |
24 | */ | 24 | */ | |
25 | /* expect+1: cannot recover from previous errors */ | 25 | /* expect+1: cannot recover from previous errors */ |
--- src/tests/usr.bin/xlint/lint1/msg_247.c 2021/04/09 20:00:07 1.13
+++ src/tests/usr.bin/xlint/lint1/msg_247.c 2021/07/10 17:35:54 1.14
@@ -1,39 +1,39 @@ | @@ -1,39 +1,39 @@ | |||
1 | /* $NetBSD: msg_247.c,v 1.13 2021/04/09 20:00:07 rillig Exp $ */ | 1 | /* $NetBSD: msg_247.c,v 1.14 2021/07/10 17:35:54 rillig Exp $ */ | |
2 | # 3 "msg_247.c" | 2 | # 3 "msg_247.c" | |
3 | 3 | |||
4 | // Test for message: pointer cast from '%s' to '%s' may be troublesome [247] | 4 | // Test for message: pointer cast from '%s' to '%s' may be troublesome [247] | |
5 | 5 | |||
6 | /* lint1-extra-flags: -c */ | 6 | /* lint1-extra-flags: -c */ | |
7 | 7 | |||
8 | /* example taken from Xlib.h */ | 8 | /* example taken from Xlib.h */ | |
9 | typedef struct { | 9 | typedef struct { | |
10 | int id; | 10 | int id; | |
11 | } *PDisplay; | 11 | } *PDisplay; | |
12 | 12 | |||
13 | struct Other { | 13 | struct Other { | |
14 | int id; | 14 | int id; | |
15 | }; | 15 | }; | |
16 | 16 | |||
17 | void | 17 | void | |
18 | example(struct Other *arg) | 18 | example(struct Other *arg) | |
19 | { | 19 | { | |
20 | PDisplay display; | 20 | PDisplay display; | |
21 | 21 | |||
22 | /* | 22 | /* | |
23 | * XXX: The target type is reported as 'struct <unnamed>'. In cases | 23 | * XXX: The target type is reported as 'struct <unnamed>'. In cases | |
24 | * like these, it would be helpful to print at least the type name | 24 | * like these, it would be helpful to print at least the type name | |
25 | * of the pointer. This type name though is discarded immediately | 25 | * of the pointer. This type name though is discarded immediately | |
26 | * when the parser reduces 'T_TYPENAME clrtyp' to 'clrtyp_typespec'. | 26 | * in the grammar rule 'typespec: T_TYPENAME'. | |
27 | * After that, the target type of the cast is just an unnamed struct, | 27 | * After that, the target type of the cast is just an unnamed struct, | |
28 | * with no hint at all that there is a typedef for a pointer to the | 28 | * with no hint at all that there is a typedef for a pointer to the | |
29 | * struct. | 29 | * struct. | |
30 | */ | 30 | */ | |
31 | display = (PDisplay)arg; /* expect: 247 */ | 31 | display = (PDisplay)arg; /* expect: 247 */ | |
32 | } | 32 | } | |
33 | 33 | |||
34 | /* | 34 | /* | |
35 | * C code with a long history that has existed in pre-C90 times already often | 35 | * C code with a long history that has existed in pre-C90 times already often | |
36 | * uses 'pointer to char' where modern code would use 'pointer to void'. | 36 | * uses 'pointer to char' where modern code would use 'pointer to void'. | |
37 | * Since 'char' is the most general underlying type, there is nothing wrong | 37 | * Since 'char' is the most general underlying type, there is nothing wrong | |
38 | * with casting to it. An example for this type of code is X11. | 38 | * with casting to it. An example for this type of code is X11. | |
39 | * | 39 | * |
--- src/tests/usr.bin/xlint/lint1/msg_249.c 2021/07/10 11:22:19 1.7
+++ src/tests/usr.bin/xlint/lint1/msg_249.c 2021/07/10 17:35:54 1.8
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: msg_249.c,v 1.7 2021/07/10 11:22:19 rillig Exp $ */ | 1 | /* $NetBSD: msg_249.c,v 1.8 2021/07/10 17:35:54 rillig Exp $ */ | |
2 | # 3 "msg_249.c" | 2 | # 3 "msg_249.c" | |
3 | 3 | |||
4 | // Test for message: syntax error '%s' [249] | 4 | // Test for message: syntax error '%s' [249] | |
5 | 5 | |||
6 | /* | 6 | /* | |
7 | * Cover the grammar rule 'top_level_declaration: error T_SEMI'. | 7 | * Cover the grammar rule 'top_level_declaration: error T_SEMI'. | |
8 | */ | 8 | */ | |
9 | /* expect+1: syntax error '"' [249] */ | 9 | /* expect+1: syntax error '"' [249] */ | |
10 | "syntax error in top_level_declaration"; | 10 | "syntax error in top_level_declaration"; | |
11 | 11 | |||
12 | /* XXX: This is necessary to recover the yacc parser. */ | 12 | /* XXX: This is necessary to recover the yacc parser. */ | |
13 | int recover_from_semi; | 13 | int recover_from_semi; | |
14 | 14 | |||
@@ -43,17 +43,17 @@ double recover_from_rparen; | @@ -43,17 +43,17 @@ double recover_from_rparen; | |||
43 | double * | 43 | double * | |
44 | access_declaration_after_syntax_error(void) | 44 | access_declaration_after_syntax_error(void) | |
45 | { | 45 | { | |
46 | return &recover_from_rparen; | 46 | return &recover_from_rparen; | |
47 | } | 47 | } | |
48 | 48 | |||
49 | struct cover_member_declaration { | 49 | struct cover_member_declaration { | |
50 | /* cover 'noclass_declmods ... notype_member_decls' */ | 50 | /* cover 'noclass_declmods ... notype_member_decls' */ | |
51 | const noclass_declmods; | 51 | const noclass_declmods; | |
52 | 52 | |||
53 | /* cover 'noclass_declspecs ...' */ | 53 | /* cover 'noclass_declspecs ...' */ | |
54 | const int noclass_declspecs; | 54 | const int noclass_declspecs; | |
55 | 55 | |||
56 | /* cover 'noclass_declmods deftyp ...' */ | 56 | /* cover 'add_type_qualifier_list end_type' */ | |
57 | /* expect+1: error: syntax error 'member without type' [249] */ | 57 | /* expect+1: error: syntax error 'member without type' [249] */ | |
58 | const; | 58 | const; | |
59 | }; | 59 | }; |
--- src/usr.bin/xlint/lint1/cgram.y 2021/07/10 17:17:05 1.295
+++ src/usr.bin/xlint/lint1/cgram.y 2021/07/10 17:35:54 1.296
@@ -1,15 +1,15 @@ | @@ -1,15 +1,15 @@ | |||
1 | %{ | 1 | %{ | |
2 | /* $NetBSD: cgram.y,v 1.295 2021/07/10 17:17:05 rillig Exp $ */ | 2 | /* $NetBSD: cgram.y,v 1.296 2021/07/10 17:35:54 rillig Exp $ */ | |
3 | 3 | |||
4 | /* | 4 | /* | |
5 | * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. | 5 | * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. | |
6 | * Copyright (c) 1994, 1995 Jochen Pohl | 6 | * Copyright (c) 1994, 1995 Jochen Pohl | |
7 | * All Rights Reserved. | 7 | * All Rights Reserved. | |
8 | * | 8 | * | |
9 | * Redistribution and use in source and binary forms, with or without | 9 | * Redistribution and use in source and binary forms, with or without | |
10 | * modification, are permitted provided that the following conditions | 10 | * modification, are permitted provided that the following conditions | |
11 | * are met: | 11 | * are met: | |
12 | * 1. Redistributions of source code must retain the above copyright | 12 | * 1. Redistributions of source code must retain the above copyright | |
13 | * notice, this list of conditions and the following disclaimer. | 13 | * notice, this list of conditions and the following disclaimer. | |
14 | * 2. Redistributions in binary form must reproduce the above copyright | 14 | * 2. Redistributions in binary form must reproduce the above copyright | |
15 | * notice, this list of conditions and the following disclaimer in the | 15 | * notice, this list of conditions and the following disclaimer in the | |
@@ -25,27 +25,27 @@ | @@ -25,27 +25,27 @@ | |||
25 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | 25 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |
26 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | 26 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |
27 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | 27 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | |
28 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | 28 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
29 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 29 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
30 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 30 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
31 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 31 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
32 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 32 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
33 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 33 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
34 | */ | 34 | */ | |
35 | 35 | |||
36 | #include <sys/cdefs.h> | 36 | #include <sys/cdefs.h> | |
37 | #if defined(__RCSID) && !defined(lint) | 37 | #if defined(__RCSID) && !defined(lint) | |
38 | __RCSID("$NetBSD: cgram.y,v 1.295 2021/07/10 17:17:05 rillig Exp $"); | 38 | __RCSID("$NetBSD: cgram.y,v 1.296 2021/07/10 17:35:54 rillig Exp $"); | |
39 | #endif | 39 | #endif | |
40 | 40 | |||
41 | #include <limits.h> | 41 | #include <limits.h> | |
42 | #include <stdlib.h> | 42 | #include <stdlib.h> | |
43 | #include <string.h> | 43 | #include <string.h> | |
44 | 44 | |||
45 | #include "lint1.h" | 45 | #include "lint1.h" | |
46 | 46 | |||
47 | extern char *yytext; | 47 | extern char *yytext; | |
48 | 48 | |||
49 | /* | 49 | /* | |
50 | * Contains the level of current declaration, used for symbol table entries. | 50 | * Contains the level of current declaration, used for symbol table entries. | |
51 | * 0 is the top-level, > 0 is inside a function body. | 51 | * 0 is the top-level, > 0 is inside a function body. | |
@@ -383,27 +383,27 @@ external_declaration: /* C99 6.9 */ | @@ -383,27 +383,27 @@ external_declaration: /* C99 6.9 */ | |||
383 | * | 383 | * | |
384 | * See 'declaration' for all other declarations. | 384 | * See 'declaration' for all other declarations. | |
385 | */ | 385 | */ | |
386 | top_level_declaration: /* C99 6.9 calls this 'declaration' */ | 386 | top_level_declaration: /* C99 6.9 calls this 'declaration' */ | |
387 | T_SEMI { | 387 | T_SEMI { | |
388 | if (sflag) { | 388 | if (sflag) { | |
389 | /* empty declaration */ | 389 | /* empty declaration */ | |
390 | error(0); | 390 | error(0); | |
391 | } else if (!tflag) { | 391 | } else if (!tflag) { | |
392 | /* empty declaration */ | 392 | /* empty declaration */ | |
393 | warning(0); | 393 | warning(0); | |
394 | } | 394 | } | |
395 | } | 395 | } | |
396 | | clrtyp deftyp notype_init_decls T_SEMI { | 396 | | begin_type end_type notype_init_decls T_SEMI { | |
397 | if (sflag) { | 397 | if (sflag) { | |
398 | /* old style declaration; add 'int' */ | 398 | /* old style declaration; add 'int' */ | |
399 | error(1); | 399 | error(1); | |
400 | } else if (!tflag) { | 400 | } else if (!tflag) { | |
401 | /* old style declaration; add 'int' */ | 401 | /* old style declaration; add 'int' */ | |
402 | warning(1); | 402 | warning(1); | |
403 | } | 403 | } | |
404 | } | 404 | } | |
405 | | declaration_noerror | 405 | | declaration_noerror | |
406 | | error T_SEMI { | 406 | | error T_SEMI { | |
407 | global_clean_up(); | 407 | global_clean_up(); | |
408 | } | 408 | } | |
409 | | error T_RBRACE { | 409 | | error T_RBRACE { | |
@@ -431,115 +431,115 @@ function_definition: /* C99 6.9.1 */ | @@ -431,115 +431,115 @@ function_definition: /* C99 6.9.1 */ | |||
431 | } arg_declaration_list_opt { | 431 | } arg_declaration_list_opt { | |
432 | end_declaration_level(); | 432 | end_declaration_level(); | |
433 | block_level--; | 433 | block_level--; | |
434 | check_func_lint_directives(); | 434 | check_func_lint_directives(); | |
435 | check_func_old_style_arguments(); | 435 | check_func_old_style_arguments(); | |
436 | begin_control_statement(CS_FUNCTION_BODY); | 436 | begin_control_statement(CS_FUNCTION_BODY); | |
437 | } compound_statement { | 437 | } compound_statement { | |
438 | funcend(); | 438 | funcend(); | |
439 | end_control_statement(CS_FUNCTION_BODY); | 439 | end_control_statement(CS_FUNCTION_BODY); | |
440 | } | 440 | } | |
441 | ; | 441 | ; | |
442 | 442 | |||
443 | func_decl: | 443 | func_decl: | |
444 | clrtyp deftyp notype_decl { | 444 | begin_type end_type notype_decl { | |
445 | $$ = $3; | 445 | $$ = $3; | |
446 | } | 446 | } | |
447 | | clrtyp declmods deftyp notype_decl { | 447 | | begin_type declmods end_type notype_decl { | |
448 | $$ = $4; | 448 | $$ = $4; | |
449 | } | 449 | } | |
450 | | clrtyp declaration_specifiers deftyp type_decl { | 450 | | begin_type declaration_specifiers end_type type_decl { | |
451 | $$ = $4; | 451 | $$ = $4; | |
452 | } | 452 | } | |
453 | ; | 453 | ; | |
454 | 454 | |||
455 | arg_declaration_list_opt: /* C99 6.9.1p13 example 1 */ | 455 | arg_declaration_list_opt: /* C99 6.9.1p13 example 1 */ | |
456 | /* empty */ | 456 | /* empty */ | |
457 | | arg_declaration_list | 457 | | arg_declaration_list | |
458 | ; | 458 | ; | |
459 | 459 | |||
460 | arg_declaration_list: /* C99 6.9.1p13 example 1 */ | 460 | arg_declaration_list: /* C99 6.9.1p13 example 1 */ | |
461 | arg_declaration | 461 | arg_declaration | |
462 | | arg_declaration_list arg_declaration | 462 | | arg_declaration_list arg_declaration | |
463 | /* XXX or better "arg_declaration error" ? */ | 463 | /* XXX or better "arg_declaration error" ? */ | |
464 | | error | 464 | | error | |
465 | ; | 465 | ; | |
466 | 466 | |||
467 | /* | 467 | /* | |
468 | * "arg_declaration" is separated from "declaration" because it | 468 | * "arg_declaration" is separated from "declaration" because it | |
469 | * needs other error handling. | 469 | * needs other error handling. | |
470 | */ | 470 | */ | |
471 | arg_declaration: | 471 | arg_declaration: | |
472 | clrtyp declmods deftyp T_SEMI { | 472 | begin_type declmods end_type T_SEMI { | |
473 | /* empty declaration */ | 473 | /* empty declaration */ | |
474 | warning(2); | 474 | warning(2); | |
475 | } | 475 | } | |
476 | | clrtyp declmods deftyp notype_init_decls T_SEMI | 476 | | begin_type declmods end_type notype_init_decls T_SEMI | |
477 | | clrtyp declaration_specifiers deftyp T_SEMI { | 477 | | begin_type declaration_specifiers end_type T_SEMI { | |
478 | if (!dcs->d_nonempty_decl) { | 478 | if (!dcs->d_nonempty_decl) { | |
479 | /* empty declaration */ | 479 | /* empty declaration */ | |
480 | warning(2); | 480 | warning(2); | |
481 | } else { | 481 | } else { | |
482 | /* '%s' declared in argument declaration list */ | 482 | /* '%s' declared in argument declaration list */ | |
483 | warning(3, type_name(dcs->d_type)); | 483 | warning(3, type_name(dcs->d_type)); | |
484 | } | 484 | } | |
485 | } | 485 | } | |
486 | | clrtyp declaration_specifiers deftyp type_init_decls T_SEMI { | 486 | | begin_type declaration_specifiers end_type type_init_decls T_SEMI { | |
487 | if (dcs->d_nonempty_decl) { | 487 | if (dcs->d_nonempty_decl) { | |
488 | /* '%s' declared in argument declaration list */ | 488 | /* '%s' declared in argument declaration list */ | |
489 | warning(3, type_name(dcs->d_type)); | 489 | warning(3, type_name(dcs->d_type)); | |
490 | } | 490 | } | |
491 | } | 491 | } | |
492 | | clrtyp declmods error | 492 | | begin_type declmods error | |
493 | | clrtyp declaration_specifiers error | 493 | | begin_type declaration_specifiers error | |
494 | ; | 494 | ; | |
495 | 495 | |||
496 | declaration: /* C99 6.7 */ | 496 | declaration: /* C99 6.7 */ | |
497 | declaration_noerror | 497 | declaration_noerror | |
498 | | error T_SEMI | 498 | | error T_SEMI | |
499 | ; | 499 | ; | |
500 | 500 | |||
501 | declaration_noerror: /* see C99 6.7 'declaration' */ | 501 | declaration_noerror: /* see C99 6.7 'declaration' */ | |
502 | clrtyp declmods deftyp T_SEMI { | 502 | begin_type declmods end_type T_SEMI { | |
503 | if (dcs->d_scl == TYPEDEF) { | 503 | if (dcs->d_scl == TYPEDEF) { | |
504 | /* typedef declares no type name */ | 504 | /* typedef declares no type name */ | |
505 | warning(72); | 505 | warning(72); | |
506 | } else { | 506 | } else { | |
507 | /* empty declaration */ | 507 | /* empty declaration */ | |
508 | warning(2); | 508 | warning(2); | |
509 | } | 509 | } | |
510 | } | 510 | } | |
511 | | clrtyp declmods deftyp notype_init_decls T_SEMI | 511 | | begin_type declmods end_type notype_init_decls T_SEMI | |
512 | | clrtyp declaration_specifiers deftyp T_SEMI { | 512 | | begin_type declaration_specifiers end_type T_SEMI { | |
513 | if (dcs->d_scl == TYPEDEF) { | 513 | if (dcs->d_scl == TYPEDEF) { | |
514 | /* typedef declares no type name */ | 514 | /* typedef declares no type name */ | |
515 | warning(72); | 515 | warning(72); | |
516 | } else if (!dcs->d_nonempty_decl) { | 516 | } else if (!dcs->d_nonempty_decl) { | |
517 | /* empty declaration */ | 517 | /* empty declaration */ | |
518 | warning(2); | 518 | warning(2); | |
519 | } | 519 | } | |
520 | } | 520 | } | |
521 | | clrtyp declaration_specifiers deftyp type_init_decls T_SEMI | 521 | | begin_type declaration_specifiers end_type type_init_decls T_SEMI | |
522 | ; | 522 | ; | |
523 | 523 | |||
524 | clrtyp: | 524 | begin_type: | |
525 | /* empty */ { | 525 | /* empty */ { | |
526 | clrtyp(); | 526 | begin_type(); | |
527 | } | 527 | } | |
528 | ; | 528 | ; | |
529 | 529 | |||
530 | deftyp: | 530 | end_type: | |
531 | /* empty */ { | 531 | /* empty */ { | |
532 | deftyp(); | 532 | end_type(); | |
533 | } | 533 | } | |
534 | ; | 534 | ; | |
535 | 535 | |||
536 | declaration_specifiers: /* C99 6.7 */ | 536 | declaration_specifiers: /* C99 6.7 */ | |
537 | typespec { | 537 | typespec { | |
538 | add_type($1); | 538 | add_type($1); | |
539 | } | 539 | } | |
540 | | declmods typespec { | 540 | | declmods typespec { | |
541 | add_type($2); | 541 | add_type($2); | |
542 | } | 542 | } | |
543 | | type_attribute declaration_specifiers | 543 | | type_attribute declaration_specifiers | |
544 | | declaration_specifiers declmod | 544 | | declaration_specifiers declmod | |
545 | | declaration_specifiers notype_typespec { | 545 | | declaration_specifiers notype_typespec { | |
@@ -655,45 +655,45 @@ member_declaration_list_semi: | @@ -655,45 +655,45 @@ member_declaration_list_semi: | |||
655 | } | 655 | } | |
656 | $$ = $1; | 656 | $$ = $1; | |
657 | } | 657 | } | |
658 | ; | 658 | ; | |
659 | 659 | |||
660 | member_declaration_list: | 660 | member_declaration_list: | |
661 | member_declaration | 661 | member_declaration | |
662 | | member_declaration_list T_SEMI member_declaration { | 662 | | member_declaration_list T_SEMI member_declaration { | |
663 | $$ = lnklst($1, $3); | 663 | $$ = lnklst($1, $3); | |
664 | } | 664 | } | |
665 | ; | 665 | ; | |
666 | 666 | |||
667 | member_declaration: | 667 | member_declaration: | |
668 | clrtyp add_type_qualifier_list deftyp { | 668 | begin_type add_type_qualifier_list end_type { | |
669 | /* too late, i know, but getsym() compensates it */ | 669 | /* too late, i know, but getsym() compensates it */ | |
670 | symtyp = FMEMBER; | 670 | symtyp = FMEMBER; | |
671 | } notype_member_decls type_attribute_opt { | 671 | } notype_member_decls type_attribute_opt { | |
672 | symtyp = FVFT; | 672 | symtyp = FVFT; | |
673 | $$ = $5; | 673 | $$ = $5; | |
674 | } | 674 | } | |
675 | | clrtyp noclass_declspecs deftyp { | 675 | | begin_type noclass_declspecs end_type { | |
676 | symtyp = FMEMBER; | 676 | symtyp = FMEMBER; | |
677 | } type_member_decls type_attribute_opt { | 677 | } type_member_decls type_attribute_opt { | |
678 | symtyp = FVFT; | 678 | symtyp = FVFT; | |
679 | $$ = $5; | 679 | $$ = $5; | |
680 | } | 680 | } | |
681 | | clrtyp add_type_qualifier_list deftyp type_attribute_opt { | 681 | | begin_type add_type_qualifier_list end_type type_attribute_opt { | |
682 | /* syntax error '%s' */ | 682 | /* syntax error '%s' */ | |
683 | error(249, "member without type"); | 683 | error(249, "member without type"); | |
684 | $$ = NULL; | 684 | $$ = NULL; | |
685 | } | 685 | } | |
686 | | clrtyp noclass_declspecs deftyp type_attribute_opt { | 686 | | begin_type noclass_declspecs end_type type_attribute_opt { | |
687 | symtyp = FVFT; | 687 | symtyp = FVFT; | |
688 | if (!Sflag) | 688 | if (!Sflag) | |
689 | /* anonymous struct/union members is a C9X feature */ | 689 | /* anonymous struct/union members is a C9X feature */ | |
690 | warning(49); | 690 | warning(49); | |
691 | if (is_struct_or_union(dcs->d_type->t_tspec)) { | 691 | if (is_struct_or_union(dcs->d_type->t_tspec)) { | |
692 | $$ = dcs->d_type->t_str->sou_first_member; | 692 | $$ = dcs->d_type->t_str->sou_first_member; | |
693 | /* add all the members of the anonymous struct/union */ | 693 | /* add all the members of the anonymous struct/union */ | |
694 | anonymize($$); | 694 | anonymize($$); | |
695 | } else { | 695 | } else { | |
696 | /* syntax error '%s' */ | 696 | /* syntax error '%s' */ | |
697 | error(249, "unnamed member"); | 697 | error(249, "unnamed member"); | |
698 | $$ = NULL; | 698 | $$ = NULL; | |
699 | } | 699 | } | |
@@ -1140,42 +1140,42 @@ vararg_parameter_type_list: | @@ -1140,42 +1140,42 @@ vararg_parameter_type_list: | |||
1140 | $$ = NULL; | 1140 | $$ = NULL; | |
1141 | } | 1141 | } | |
1142 | ; | 1142 | ; | |
1143 | 1143 | |||
1144 | parameter_type_list: | 1144 | parameter_type_list: | |
1145 | parameter_declaration | 1145 | parameter_declaration | |
1146 | | parameter_type_list T_COMMA parameter_declaration { | 1146 | | parameter_type_list T_COMMA parameter_declaration { | |
1147 | $$ = lnklst($1, $3); | 1147 | $$ = lnklst($1, $3); | |
1148 | } | 1148 | } | |
1149 | ; | 1149 | ; | |
1150 | 1150 | |||
1151 | /* XXX: C99 6.7.5 defines the same name, but it looks completely different. */ | 1151 | /* XXX: C99 6.7.5 defines the same name, but it looks completely different. */ | |
1152 | parameter_declaration: | 1152 | parameter_declaration: | |
1153 | clrtyp declmods deftyp { | 1153 | begin_type declmods end_type { | |
1154 | $$ = declare_argument(abstract_name(), false); | 1154 | $$ = declare_argument(abstract_name(), false); | |
1155 | } | 1155 | } | |
1156 | | clrtyp declaration_specifiers deftyp { | 1156 | | begin_type declaration_specifiers end_type { | |
1157 | $$ = declare_argument(abstract_name(), false); | 1157 | $$ = declare_argument(abstract_name(), false); | |
1158 | } | 1158 | } | |
1159 | | clrtyp declmods deftyp notype_param_decl { | 1159 | | begin_type declmods end_type notype_param_decl { | |
1160 | $$ = declare_argument($4, false); | 1160 | $$ = declare_argument($4, false); | |
1161 | } | 1161 | } | |
1162 | | clrtyp declaration_specifiers deftyp type_param_decl { | 1162 | | begin_type declaration_specifiers end_type type_param_decl { | |
1163 | $$ = declare_argument($4, false); | 1163 | $$ = declare_argument($4, false); | |
1164 | } | 1164 | } | |
1165 | | clrtyp declmods deftyp abstract_declarator { | 1165 | | begin_type declmods end_type abstract_declarator { | |
1166 | $$ = declare_argument($4, false); | 1166 | $$ = declare_argument($4, false); | |
1167 | } | 1167 | } | |
1168 | | clrtyp declaration_specifiers deftyp abstract_declarator { | 1168 | | begin_type declaration_specifiers end_type abstract_declarator { | |
1169 | $$ = declare_argument($4, false); | 1169 | $$ = declare_argument($4, false); | |
1170 | } | 1170 | } | |
1171 | ; | 1171 | ; | |
1172 | 1172 | |||
1173 | asm_or_symbolrename_opt: /* expect only one */ | 1173 | asm_or_symbolrename_opt: /* expect only one */ | |
1174 | /* empty */ { | 1174 | /* empty */ { | |
1175 | $$ = NULL; | 1175 | $$ = NULL; | |
1176 | } | 1176 | } | |
1177 | | T_ASM T_LPAREN T_STRING T_RPAREN { | 1177 | | T_ASM T_LPAREN T_STRING T_RPAREN { | |
1178 | freeyyv(&$3, T_STRING); | 1178 | freeyyv(&$3, T_STRING); | |
1179 | $$ = NULL; | 1179 | $$ = NULL; | |
1180 | } | 1180 | } | |
1181 | | T_SYMBOLRENAME T_LPAREN T_NAME T_RPAREN { | 1181 | | T_SYMBOLRENAME T_LPAREN T_NAME T_RPAREN { | |
@@ -1258,36 +1258,36 @@ init_rbrace: | @@ -1258,36 +1258,36 @@ init_rbrace: | |||
1258 | } | 1258 | } | |
1259 | ; | 1259 | ; | |
1260 | 1260 | |||
1261 | type_name: /* C99 6.7.6 */ | 1261 | type_name: /* C99 6.7.6 */ | |
1262 | { | 1262 | { | |
1263 | begin_declaration_level(ABSTRACT); | 1263 | begin_declaration_level(ABSTRACT); | |
1264 | } abstract_declaration { | 1264 | } abstract_declaration { | |
1265 | end_declaration_level(); | 1265 | end_declaration_level(); | |
1266 | $$ = $2->s_type; | 1266 | $$ = $2->s_type; | |
1267 | } | 1267 | } | |
1268 | ; | 1268 | ; | |
1269 | 1269 | |||
1270 | abstract_declaration: | 1270 | abstract_declaration: | |
1271 | clrtyp add_type_qualifier_list deftyp { | 1271 | begin_type add_type_qualifier_list end_type { | |
1272 | $$ = declare_1_abstract(abstract_name()); | 1272 | $$ = declare_1_abstract(abstract_name()); | |
1273 | } | 1273 | } | |
1274 | | clrtyp noclass_declspecs deftyp { | 1274 | | begin_type noclass_declspecs end_type { | |
1275 | $$ = declare_1_abstract(abstract_name()); | 1275 | $$ = declare_1_abstract(abstract_name()); | |
1276 | } | 1276 | } | |
1277 | | clrtyp add_type_qualifier_list deftyp abstract_declarator { | 1277 | | begin_type add_type_qualifier_list end_type abstract_declarator { | |
1278 | $$ = declare_1_abstract($4); | 1278 | $$ = declare_1_abstract($4); | |
1279 | } | 1279 | } | |
1280 | | clrtyp noclass_declspecs deftyp abstract_declarator { | 1280 | | begin_type noclass_declspecs end_type abstract_declarator { | |
1281 | $$ = declare_1_abstract($4); | 1281 | $$ = declare_1_abstract($4); | |
1282 | } | 1282 | } | |
1283 | ; | 1283 | ; | |
1284 | 1284 | |||
1285 | abstract_declarator: /* C99 6.7.6 */ | 1285 | abstract_declarator: /* C99 6.7.6 */ | |
1286 | pointer { | 1286 | pointer { | |
1287 | $$ = add_pointer(abstract_name(), $1); | 1287 | $$ = add_pointer(abstract_name(), $1); | |
1288 | } | 1288 | } | |
1289 | | direct_abstract_declarator | 1289 | | direct_abstract_declarator | |
1290 | | pointer direct_abstract_declarator { | 1290 | | pointer direct_abstract_declarator { | |
1291 | $$ = add_pointer($2, $1); | 1291 | $$ = add_pointer($2, $1); | |
1292 | } | 1292 | } | |
1293 | | T_TYPEOF term { /* GCC extension */ | 1293 | | T_TYPEOF term { /* GCC extension */ | |
@@ -1530,27 +1530,27 @@ do: /* see C99 6.8.5 */ | @@ -1530,27 +1530,27 @@ do: /* see C99 6.8.5 */ | |||
1530 | do1(); | 1530 | do1(); | |
1531 | } | 1531 | } | |
1532 | ; | 1532 | ; | |
1533 | 1533 | |||
1534 | for_start: /* see C99 6.8.5 */ | 1534 | for_start: /* see C99 6.8.5 */ | |
1535 | T_FOR T_LPAREN { | 1535 | T_FOR T_LPAREN { | |
1536 | begin_declaration_level(AUTO); | 1536 | begin_declaration_level(AUTO); | |
1537 | block_level++; | 1537 | block_level++; | |
1538 | } | 1538 | } | |
1539 | ; | 1539 | ; | |
1540 | 1540 | |||
1541 | for_exprs: /* see C99 6.8.5 */ | 1541 | for_exprs: /* see C99 6.8.5 */ | |
1542 | for_start | 1542 | for_start | |
1543 | clrtyp declaration_specifiers deftyp notype_init_decls T_SEMI | 1543 | begin_type declaration_specifiers end_type notype_init_decls T_SEMI | |
1544 | expr_opt T_SEMI | 1544 | expr_opt T_SEMI | |
1545 | expr_opt T_RPAREN { | 1545 | expr_opt T_RPAREN { | |
1546 | /* variable declaration in for loop */ | 1546 | /* variable declaration in for loop */ | |
1547 | c99ism(325); | 1547 | c99ism(325); | |
1548 | for1(NULL, $7, $9); | 1548 | for1(NULL, $7, $9); | |
1549 | clear_warning_flags(); | 1549 | clear_warning_flags(); | |
1550 | } | 1550 | } | |
1551 | | for_start expr_opt T_SEMI expr_opt T_SEMI expr_opt T_RPAREN { | 1551 | | for_start expr_opt T_SEMI expr_opt T_SEMI expr_opt T_RPAREN { | |
1552 | for1($2, $4, $6); | 1552 | for1($2, $4, $6); | |
1553 | clear_warning_flags(); | 1553 | clear_warning_flags(); | |
1554 | } | 1554 | } | |
1555 | ; | 1555 | ; | |
1556 | 1556 |
--- src/usr.bin/xlint/lint1/decl.c 2021/07/10 12:10:39 1.196
+++ src/usr.bin/xlint/lint1/decl.c 2021/07/10 17:35:54 1.197
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: decl.c,v 1.196 2021/07/10 12:10:39 rillig Exp $ */ | 1 | /* $NetBSD: decl.c,v 1.197 2021/07/10 17:35:54 rillig Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. | 4 | * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. | |
5 | * Copyright (c) 1994, 1995 Jochen Pohl | 5 | * Copyright (c) 1994, 1995 Jochen Pohl | |
6 | * All Rights Reserved. | 6 | * All Rights Reserved. | |
7 | * | 7 | * | |
8 | * Redistribution and use in source and binary forms, with or without | 8 | * Redistribution and use in source and binary forms, with or without | |
9 | * modification, are permitted provided that the following conditions | 9 | * modification, are permitted provided that the following conditions | |
10 | * are met: | 10 | * are met: | |
11 | * 1. Redistributions of source code must retain the above copyright | 11 | * 1. Redistributions of source code must retain the above copyright | |
12 | * notice, this list of conditions and the following disclaimer. | 12 | * notice, this list of conditions and the following disclaimer. | |
13 | * 2. Redistributions in binary form must reproduce the above copyright | 13 | * 2. Redistributions in binary form must reproduce the above copyright | |
14 | * notice, this list of conditions and the following disclaimer in the | 14 | * notice, this list of conditions and the following disclaimer in the | |
@@ -28,27 +28,27 @@ | @@ -28,27 +28,27 @@ | |||
28 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 28 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
32 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 32 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
33 | */ | 33 | */ | |
34 | 34 | |||
35 | #if HAVE_NBTOOL_CONFIG_H | 35 | #if HAVE_NBTOOL_CONFIG_H | |
36 | #include "nbtool_config.h" | 36 | #include "nbtool_config.h" | |
37 | #endif | 37 | #endif | |
38 | 38 | |||
39 | #include <sys/cdefs.h> | 39 | #include <sys/cdefs.h> | |
40 | #if defined(__RCSID) && !defined(lint) | 40 | #if defined(__RCSID) && !defined(lint) | |
41 | __RCSID("$NetBSD: decl.c,v 1.196 2021/07/10 12:10:39 rillig Exp $"); | 41 | __RCSID("$NetBSD: decl.c,v 1.197 2021/07/10 17:35:54 rillig Exp $"); | |
42 | #endif | 42 | #endif | |
43 | 43 | |||
44 | #include <sys/param.h> | 44 | #include <sys/param.h> | |
45 | #include <limits.h> | 45 | #include <limits.h> | |
46 | #include <stdlib.h> | 46 | #include <stdlib.h> | |
47 | #include <string.h> | 47 | #include <string.h> | |
48 | 48 | |||
49 | #include "lint1.h" | 49 | #include "lint1.h" | |
50 | 50 | |||
51 | const char *unnamed = "<unnamed>"; | 51 | const char *unnamed = "<unnamed>"; | |
52 | 52 | |||
53 | /* shared type structures for arithmetic types and void */ | 53 | /* shared type structures for arithmetic types and void */ | |
54 | static type_t *typetab; | 54 | static type_t *typetab; | |
@@ -225,36 +225,36 @@ add_storage_class(scl_t sc) | @@ -225,36 +225,36 @@ add_storage_class(scl_t sc) | |||
225 | dcs->d_inline = true; | 225 | dcs->d_inline = true; | |
226 | return; | 226 | return; | |
227 | } | 227 | } | |
228 | if (dcs->d_type != NULL || dcs->d_abstract_type != NOTSPEC || | 228 | if (dcs->d_type != NULL || dcs->d_abstract_type != NOTSPEC || | |
229 | dcs->d_sign_mod != NOTSPEC || dcs->d_rank_mod != NOTSPEC) { | 229 | dcs->d_sign_mod != NOTSPEC || dcs->d_rank_mod != NOTSPEC) { | |
230 | /* storage class after type is obsolescent */ | 230 | /* storage class after type is obsolescent */ | |
231 | warning(83); | 231 | warning(83); | |
232 | } | 232 | } | |
233 | if (dcs->d_scl == NOSCL) { | 233 | if (dcs->d_scl == NOSCL) { | |
234 | dcs->d_scl = sc; | 234 | dcs->d_scl = sc; | |
235 | } else { | 235 | } else { | |
236 | /* | 236 | /* | |
237 | * multiple storage classes. An error will be reported in | 237 | * multiple storage classes. An error will be reported in | |
238 | * deftyp(). | 238 | * end_type(). | |
239 | */ | 239 | */ | |
240 | dcs->d_mscl = true; | 240 | dcs->d_mscl = true; | |
241 | } | 241 | } | |
242 | } | 242 | } | |
243 | 243 | |||
244 | /* | 244 | /* | |
245 | * Remember the type, modifier or typedef name returned by the parser | 245 | * Remember the type, modifier or typedef name returned by the parser | |
246 | * in *dcs (top element of decl stack). This information is used in | 246 | * in *dcs (top element of decl stack). This information is used in | |
247 | * deftyp() to build the type used for all declarators in this | 247 | * end_type() to build the type used for all declarators in this | |
248 | * declaration. | 248 | * declaration. | |
249 | * | 249 | * | |
250 | * If tp->t_typedef is 1, the type comes from a previously defined typename. | 250 | * If tp->t_typedef is 1, the type comes from a previously defined typename. | |
251 | * Otherwise it comes from a type specifier (int, long, ...) or a | 251 | * Otherwise it comes from a type specifier (int, long, ...) or a | |
252 | * struct/union/enum tag. | 252 | * struct/union/enum tag. | |
253 | */ | 253 | */ | |
254 | void | 254 | void | |
255 | add_type(type_t *tp) | 255 | add_type(type_t *tp) | |
256 | { | 256 | { | |
257 | tspec_t t; | 257 | tspec_t t; | |
258 | #ifdef DEBUG | 258 | #ifdef DEBUG | |
259 | printf("%s: %s\n", __func__, type_name(tp)); | 259 | printf("%s: %s\n", __func__, type_name(tp)); | |
260 | #endif | 260 | #endif | |
@@ -273,27 +273,27 @@ add_type(type_t *tp) | @@ -273,27 +273,27 @@ add_type(type_t *tp) | |||
273 | } | 273 | } | |
274 | 274 | |||
275 | t = tp->t_tspec; | 275 | t = tp->t_tspec; | |
276 | 276 | |||
277 | if (t == STRUCT || t == UNION || t == ENUM) { | 277 | if (t == STRUCT || t == UNION || t == ENUM) { | |
278 | /* | 278 | /* | |
279 | * something like "int struct a ..." | 279 | * something like "int struct a ..." | |
280 | * struct/union/enum with anything else is not allowed | 280 | * struct/union/enum with anything else is not allowed | |
281 | */ | 281 | */ | |
282 | if (dcs->d_type != NULL || dcs->d_abstract_type != NOTSPEC || | 282 | if (dcs->d_type != NULL || dcs->d_abstract_type != NOTSPEC || | |
283 | dcs->d_rank_mod != NOTSPEC || dcs->d_sign_mod != NOTSPEC) { | 283 | dcs->d_rank_mod != NOTSPEC || dcs->d_sign_mod != NOTSPEC) { | |
284 | /* | 284 | /* | |
285 | * remember that an error must be reported in | 285 | * remember that an error must be reported in | |
286 | * deftyp(). | 286 | * end_type(). | |
287 | */ | 287 | */ | |
288 | dcs->d_terr = true; | 288 | dcs->d_terr = true; | |
289 | dcs->d_abstract_type = NOTSPEC; | 289 | dcs->d_abstract_type = NOTSPEC; | |
290 | dcs->d_sign_mod = NOTSPEC; | 290 | dcs->d_sign_mod = NOTSPEC; | |
291 | dcs->d_rank_mod = NOTSPEC; | 291 | dcs->d_rank_mod = NOTSPEC; | |
292 | } | 292 | } | |
293 | dcs->d_type = tp; | 293 | dcs->d_type = tp; | |
294 | return; | 294 | return; | |
295 | } | 295 | } | |
296 | 296 | |||
297 | if (dcs->d_type != NULL && !dcs->d_type->t_typedef) { | 297 | if (dcs->d_type != NULL && !dcs->d_type->t_typedef) { | |
298 | /* | 298 | /* | |
299 | * something like "struct a int" | 299 | * something like "struct a int" | |
@@ -330,59 +330,59 @@ add_type(type_t *tp) | @@ -330,59 +330,59 @@ add_type(type_t *tp) | |||
330 | dcs->d_type = tdeferr(dcs->d_type, t); | 330 | dcs->d_type = tdeferr(dcs->d_type, t); | |
331 | return; | 331 | return; | |
332 | } | 332 | } | |
333 | 333 | |||
334 | /* now it can be only a combination of arithmetic types and void */ | 334 | /* now it can be only a combination of arithmetic types and void */ | |
335 | if (t == SIGNED || t == UNSIGN) { | 335 | if (t == SIGNED || t == UNSIGN) { | |
336 | /* | 336 | /* | |
337 | * remember specifiers "signed" & "unsigned" in | 337 | * remember specifiers "signed" & "unsigned" in | |
338 | * dcs->d_sign_mod | 338 | * dcs->d_sign_mod | |
339 | */ | 339 | */ | |
340 | if (dcs->d_sign_mod != NOTSPEC) | 340 | if (dcs->d_sign_mod != NOTSPEC) | |
341 | /* | 341 | /* | |
342 | * more than one "signed" and/or "unsigned"; print | 342 | * more than one "signed" and/or "unsigned"; print | |
343 | * an error in deftyp() | 343 | * an error in end_type() | |
344 | */ | 344 | */ | |
345 | dcs->d_terr = true; | 345 | dcs->d_terr = true; | |
346 | dcs->d_sign_mod = t; | 346 | dcs->d_sign_mod = t; | |
347 | } else if (t == SHORT || t == LONG || t == QUAD) { | 347 | } else if (t == SHORT || t == LONG || t == QUAD) { | |
348 | /* | 348 | /* | |
349 | * remember specifiers "short", "long" and "long long" in | 349 | * remember specifiers "short", "long" and "long long" in | |
350 | * dcs->d_rank_mod | 350 | * dcs->d_rank_mod | |
351 | */ | 351 | */ | |
352 | if (dcs->d_rank_mod != NOTSPEC) | 352 | if (dcs->d_rank_mod != NOTSPEC) | |
353 | /* more than one, print error in deftyp() */ | 353 | /* more than one, print error in end_type() */ | |
354 | dcs->d_terr = true; | 354 | dcs->d_terr = true; | |
355 | dcs->d_rank_mod = t; | 355 | dcs->d_rank_mod = t; | |
356 | } else if (t == FLOAT || t == DOUBLE) { | 356 | } else if (t == FLOAT || t == DOUBLE) { | |
357 | if (dcs->d_rank_mod == NOTSPEC || dcs->d_rank_mod == LONG) { | 357 | if (dcs->d_rank_mod == NOTSPEC || dcs->d_rank_mod == LONG) { | |
358 | if (dcs->d_complex_mod != NOTSPEC | 358 | if (dcs->d_complex_mod != NOTSPEC | |
359 | || (t == FLOAT && dcs->d_rank_mod == LONG)) | 359 | || (t == FLOAT && dcs->d_rank_mod == LONG)) | |
360 | dcs->d_terr = true; | 360 | dcs->d_terr = true; | |
361 | dcs->d_complex_mod = t; | 361 | dcs->d_complex_mod = t; | |
362 | } else { | 362 | } else { | |
363 | if (dcs->d_abstract_type != NOTSPEC) | 363 | if (dcs->d_abstract_type != NOTSPEC) | |
364 | dcs->d_terr = true; | 364 | dcs->d_terr = true; | |
365 | dcs->d_abstract_type = t; | 365 | dcs->d_abstract_type = t; | |
366 | } | 366 | } | |
367 | } else if (t == PTR) { | 367 | } else if (t == PTR) { | |
368 | dcs->d_type = tp; | 368 | dcs->d_type = tp; | |
369 | } else { | 369 | } else { | |
370 | /* | 370 | /* | |
371 | * remember specifiers "void", "char", "int", | 371 | * remember specifiers "void", "char", "int", | |
372 | * or "_Complex" in dcs->d_abstract_type | 372 | * or "_Complex" in dcs->d_abstract_type | |
373 | */ | 373 | */ | |
374 | if (dcs->d_abstract_type != NOTSPEC) | 374 | if (dcs->d_abstract_type != NOTSPEC) | |
375 | /* more than one, print error in deftyp() */ | 375 | /* more than one, print error in end_type() */ | |
376 | dcs->d_terr = true; | 376 | dcs->d_terr = true; | |
377 | dcs->d_abstract_type = t; | 377 | dcs->d_abstract_type = t; | |
378 | } | 378 | } | |
379 | } | 379 | } | |
380 | 380 | |||
381 | /* | 381 | /* | |
382 | * called if a list of declaration specifiers contains a typedef name | 382 | * called if a list of declaration specifiers contains a typedef name | |
383 | * and other specifiers (except struct, union, enum, typedef name) | 383 | * and other specifiers (except struct, union, enum, typedef name) | |
384 | */ | 384 | */ | |
385 | static type_t * | 385 | static type_t * | |
386 | tdeferr(type_t *td, tspec_t t) | 386 | tdeferr(type_t *td, tspec_t t) | |
387 | { | 387 | { | |
388 | tspec_t t2; | 388 | tspec_t t2; | |
@@ -551,27 +551,27 @@ addpacked(void) | @@ -551,27 +551,27 @@ addpacked(void) | |||
551 | } | 551 | } | |
552 | 552 | |||
553 | void | 553 | void | |
554 | add_attr_used(void) | 554 | add_attr_used(void) | |
555 | { | 555 | { | |
556 | dcs->d_used = true; | 556 | dcs->d_used = true; | |
557 | } | 557 | } | |
558 | 558 | |||
559 | /* | 559 | /* | |
560 | * Remember a qualifier which is part of the declaration specifiers | 560 | * Remember a qualifier which is part of the declaration specifiers | |
561 | * (and not the declarator) in the top element of the declaration stack. | 561 | * (and not the declarator) in the top element of the declaration stack. | |
562 | * Also detect multiple qualifiers of the same kind. | 562 | * Also detect multiple qualifiers of the same kind. | |
563 | 563 | |||
564 | * The remembered qualifier is used by deftyp() to construct the type | 564 | * The remembered qualifier is used by end_type() to construct the type | |
565 | * for all declarators. | 565 | * for all declarators. | |
566 | */ | 566 | */ | |
567 | void | 567 | void | |
568 | add_qualifier(tqual_t q) | 568 | add_qualifier(tqual_t q) | |
569 | { | 569 | { | |
570 | 570 | |||
571 | if (q == CONST) { | 571 | if (q == CONST) { | |
572 | if (dcs->d_const) { | 572 | if (dcs->d_const) { | |
573 | /* duplicate '%s' */ | 573 | /* duplicate '%s' */ | |
574 | warning(10, "const"); | 574 | warning(10, "const"); | |
575 | } | 575 | } | |
576 | dcs->d_const = true; | 576 | dcs->d_const = true; | |
577 | } else if (q == VOLATILE) { | 577 | } else if (q == VOLATILE) { | |
@@ -677,46 +677,46 @@ end_declaration_level(void) | @@ -677,46 +677,46 @@ end_declaration_level(void) | |||
677 | 677 | |||
678 | /* | 678 | /* | |
679 | * Set flag d_asm in all declaration stack elements up to the | 679 | * Set flag d_asm in all declaration stack elements up to the | |
680 | * outermost one. | 680 | * outermost one. | |
681 | * | 681 | * | |
682 | * This is used to mark compound statements which have, possibly in | 682 | * This is used to mark compound statements which have, possibly in | |
683 | * nested compound statements, asm statements. For these compound | 683 | * nested compound statements, asm statements. For these compound | |
684 | * statements no warnings about unused or uninitialized variables are | 684 | * statements no warnings about unused or uninitialized variables are | |
685 | * printed. | 685 | * printed. | |
686 | * | 686 | * | |
687 | * There is no need to clear d_asm in dinfo structs with context AUTO, | 687 | * There is no need to clear d_asm in dinfo structs with context AUTO, | |
688 | * because these structs are freed at the end of the compound statement. | 688 | * because these structs are freed at the end of the compound statement. | |
689 | * But it must be cleared in the outermost dinfo struct, which has | 689 | * But it must be cleared in the outermost dinfo struct, which has | |
690 | * context EXTERN. This could be done in clrtyp() and would work for C90, | 690 | * context EXTERN. This could be done in begin_type() and would work for C90, | |
691 | * but not for C99 or C++ (due to mixed statements and declarations). Thus | 691 | * but not for C99 or C++ (due to mixed statements and declarations). Thus | |
692 | * we clear it in global_clean_up_decl(), which is used to do some cleanup | 692 | * we clear it in global_clean_up_decl(), which is used to do some cleanup | |
693 | * after global declarations/definitions. | 693 | * after global declarations/definitions. | |
694 | */ | 694 | */ | |
695 | void | 695 | void | |
696 | setasm(void) | 696 | setasm(void) | |
697 | { | 697 | { | |
698 | dinfo_t *di; | 698 | dinfo_t *di; | |
699 | 699 | |||
700 | for (di = dcs; di != NULL; di = di->d_next) | 700 | for (di = dcs; di != NULL; di = di->d_next) | |
701 | di->d_asm = true; | 701 | di->d_asm = true; | |
702 | } | 702 | } | |
703 | 703 | |||
704 | /* | 704 | /* | |
705 | * Clean all elements of the top element of declaration stack which | 705 | * Clean all elements of the top element of declaration stack which | |
706 | * will be used by the next declaration | 706 | * will be used by the next declaration | |
707 | */ | 707 | */ | |
708 | void | 708 | void | |
709 | clrtyp(void) | 709 | begin_type(void) | |
710 | { | 710 | { | |
711 | 711 | |||
712 | dcs->d_abstract_type = NOTSPEC; | 712 | dcs->d_abstract_type = NOTSPEC; | |
713 | dcs->d_complex_mod = NOTSPEC; | 713 | dcs->d_complex_mod = NOTSPEC; | |
714 | dcs->d_sign_mod = NOTSPEC; | 714 | dcs->d_sign_mod = NOTSPEC; | |
715 | dcs->d_rank_mod = NOTSPEC; | 715 | dcs->d_rank_mod = NOTSPEC; | |
716 | dcs->d_scl = NOSCL; | 716 | dcs->d_scl = NOSCL; | |
717 | dcs->d_type = NULL; | 717 | dcs->d_type = NULL; | |
718 | dcs->d_const = false; | 718 | dcs->d_const = false; | |
719 | dcs->d_volatile = false; | 719 | dcs->d_volatile = false; | |
720 | dcs->d_inline = false; | 720 | dcs->d_inline = false; | |
721 | dcs->d_mscl = false; | 721 | dcs->d_mscl = false; | |
722 | dcs->d_terr = false; | 722 | dcs->d_terr = false; | |
@@ -739,27 +739,27 @@ dcs_adjust_storage_class(void) | @@ -739,27 +739,27 @@ dcs_adjust_storage_class(void) | |||
739 | error(9); | 739 | error(9); | |
740 | dcs->d_scl = NOSCL; | 740 | dcs->d_scl = NOSCL; | |
741 | } | 741 | } | |
742 | } | 742 | } | |
743 | } | 743 | } | |
744 | 744 | |||
745 | /* | 745 | /* | |
746 | * Create a type structure from the information gathered in | 746 | * Create a type structure from the information gathered in | |
747 | * the declaration stack. | 747 | * the declaration stack. | |
748 | * Complain about storage classes which are not possible in current | 748 | * Complain about storage classes which are not possible in current | |
749 | * context. | 749 | * context. | |
750 | */ | 750 | */ | |
751 | void | 751 | void | |
752 | deftyp(void) | 752 | end_type(void) | |
753 | { | 753 | { | |
754 | tspec_t t, s, l, c; | 754 | tspec_t t, s, l, c; | |
755 | type_t *tp; | 755 | type_t *tp; | |
756 | 756 | |||
757 | t = dcs->d_abstract_type; /* VOID, BOOL, CHAR, INT or COMPLEX */ | 757 | t = dcs->d_abstract_type; /* VOID, BOOL, CHAR, INT or COMPLEX */ | |
758 | c = dcs->d_complex_mod; /* FLOAT or DOUBLE */ | 758 | c = dcs->d_complex_mod; /* FLOAT or DOUBLE */ | |
759 | s = dcs->d_sign_mod; /* SIGNED or UNSIGN */ | 759 | s = dcs->d_sign_mod; /* SIGNED or UNSIGN */ | |
760 | l = dcs->d_rank_mod; /* SHORT, LONG or QUAD */ | 760 | l = dcs->d_rank_mod; /* SHORT, LONG or QUAD */ | |
761 | tp = dcs->d_type; | 761 | tp = dcs->d_type; | |
762 | 762 | |||
763 | #ifdef DEBUG | 763 | #ifdef DEBUG | |
764 | printf("%s: %s\n", __func__, type_name(tp)); | 764 | printf("%s: %s\n", __func__, type_name(tp)); | |
765 | #endif | 765 | #endif | |
@@ -816,27 +816,27 @@ deftyp(void) | @@ -816,27 +816,27 @@ deftyp(void) | |||
816 | if (l == LONG) { | 816 | if (l == LONG) { | |
817 | l = NOTSPEC; | 817 | l = NOTSPEC; | |
818 | t = LCOMPLEX; | 818 | t = LCOMPLEX; | |
819 | if (tflag) | 819 | if (tflag) | |
820 | /* 'long double' is illegal in ... */ | 820 | /* 'long double' is illegal in ... */ | |
821 | warning(266); | 821 | warning(266); | |
822 | } | 822 | } | |
823 | break; | 823 | break; | |
824 | case VOID: | 824 | case VOID: | |
825 | case FCOMPLEX: | 825 | case FCOMPLEX: | |
826 | case LCOMPLEX: | 826 | case LCOMPLEX: | |
827 | break; | 827 | break; | |
828 | default: | 828 | default: | |
829 | INTERNAL_ERROR("deftyp(%s)", tspec_name(t)); | 829 | INTERNAL_ERROR("end_type(%s)", tspec_name(t)); | |
830 | } | 830 | } | |
831 | if (t != INT && t != CHAR && (s != NOTSPEC || l != NOTSPEC)) { | 831 | if (t != INT && t != CHAR && (s != NOTSPEC || l != NOTSPEC)) { | |
832 | dcs->d_terr = true; | 832 | dcs->d_terr = true; | |
833 | l = s = NOTSPEC; | 833 | l = s = NOTSPEC; | |
834 | } | 834 | } | |
835 | if (l != NOTSPEC) | 835 | if (l != NOTSPEC) | |
836 | t = l; | 836 | t = l; | |
837 | dcs->d_type = gettyp(merge_type_specifiers(t, s)); | 837 | dcs->d_type = gettyp(merge_type_specifiers(t, s)); | |
838 | } | 838 | } | |
839 | 839 | |||
840 | if (dcs->d_mscl) { | 840 | if (dcs->d_mscl) { | |
841 | /* only one storage class allowed */ | 841 | /* only one storage class allowed */ | |
842 | error(7); | 842 | error(7); | |
@@ -1320,27 +1320,27 @@ merge_qualified_pointer(qual_ptr *p1, qu | @@ -1320,27 +1320,27 @@ merge_qualified_pointer(qual_ptr *p1, qu | |||
1320 | /* duplicate '%s' */ | 1320 | /* duplicate '%s' */ | |
1321 | warning(10, "volatile"); | 1321 | warning(10, "volatile"); | |
1322 | } | 1322 | } | |
1323 | p1->p_volatile = true; | 1323 | p1->p_volatile = true; | |
1324 | } | 1324 | } | |
1325 | free(p2); | 1325 | free(p2); | |
1326 | return p1; | 1326 | return p1; | |
1327 | } | 1327 | } | |
1328 | 1328 | |||
1329 | /* | 1329 | /* | |
1330 | * The following 3 functions extend the type of a declarator with | 1330 | * The following 3 functions extend the type of a declarator with | |
1331 | * pointer, function and array types. | 1331 | * pointer, function and array types. | |
1332 | * | 1332 | * | |
1333 | * The current type is the type built by deftyp() (dcs->d_type) and | 1333 | * The current type is the type built by end_type() (dcs->d_type) and | |
1334 | * pointer, function and array types already added for this | 1334 | * pointer, function and array types already added for this | |
1335 | * declarator. The new type extension is inserted between both. | 1335 | * declarator. The new type extension is inserted between both. | |
1336 | */ | 1336 | */ | |
1337 | sym_t * | 1337 | sym_t * | |
1338 | add_pointer(sym_t *decl, qual_ptr *p) | 1338 | add_pointer(sym_t *decl, qual_ptr *p) | |
1339 | { | 1339 | { | |
1340 | type_t **tpp, *tp; | 1340 | type_t **tpp, *tp; | |
1341 | qual_ptr *next; | 1341 | qual_ptr *next; | |
1342 | 1342 | |||
1343 | tpp = &decl->s_type; | 1343 | tpp = &decl->s_type; | |
1344 | while (*tpp != NULL && *tpp != dcs->d_type) | 1344 | while (*tpp != NULL && *tpp != dcs->d_type) | |
1345 | tpp = &(*tpp)->t_subt; | 1345 | tpp = &(*tpp)->t_subt; | |
1346 | if (*tpp == NULL) | 1346 | if (*tpp == NULL) |
--- src/usr.bin/xlint/lint1/externs1.h 2021/07/06 04:44:20 1.115
+++ src/usr.bin/xlint/lint1/externs1.h 2021/07/10 17:35:54 1.116
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: externs1.h,v 1.115 2021/07/06 04:44:20 rillig Exp $ */ | 1 | /* $NetBSD: externs1.h,v 1.116 2021/07/10 17:35:54 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. | |
@@ -145,28 +145,28 @@ extern void initdecl(void); | @@ -145,28 +145,28 @@ extern void initdecl(void); | |||
145 | extern type_t *gettyp(tspec_t); | 145 | extern type_t *gettyp(tspec_t); | |
146 | extern type_t *dup_type(const type_t *); | 146 | extern type_t *dup_type(const type_t *); | |
147 | extern type_t *expr_dup_type(const type_t *); | 147 | extern type_t *expr_dup_type(const type_t *); | |
148 | extern bool is_incomplete(const type_t *); | 148 | extern bool is_incomplete(const type_t *); | |
149 | extern void setcomplete(type_t *, bool); | 149 | extern void setcomplete(type_t *, bool); | |
150 | extern void add_storage_class(scl_t); | 150 | extern void add_storage_class(scl_t); | |
151 | extern void add_type(type_t *); | 151 | extern void add_type(type_t *); | |
152 | extern void add_qualifier(tqual_t); | 152 | extern void add_qualifier(tqual_t); | |
153 | extern void addpacked(void); | 153 | extern void addpacked(void); | |
154 | extern void add_attr_used(void); | 154 | extern void add_attr_used(void); | |
155 | extern void begin_declaration_level(scl_t); | 155 | extern void begin_declaration_level(scl_t); | |
156 | extern void end_declaration_level(void); | 156 | extern void end_declaration_level(void); | |
157 | extern void setasm(void); | 157 | extern void setasm(void); | |
158 | extern void clrtyp(void); | 158 | extern void begin_type(void); | |
159 | extern void deftyp(void); | 159 | extern void end_type(void); | |
160 | extern int length(const type_t *, const char *); | 160 | extern int length(const type_t *, const char *); | |
161 | extern int alignment_in_bits(const type_t *); | 161 | extern int alignment_in_bits(const type_t *); | |
162 | extern sym_t *lnklst(sym_t *, sym_t *); | 162 | extern sym_t *lnklst(sym_t *, sym_t *); | |
163 | extern void check_type(sym_t *); | 163 | extern void check_type(sym_t *); | |
164 | extern sym_t *declarator_1_struct_union(sym_t *); | 164 | extern sym_t *declarator_1_struct_union(sym_t *); | |
165 | extern sym_t *bitfield(sym_t *, int); | 165 | extern sym_t *bitfield(sym_t *, int); | |
166 | extern qual_ptr *merge_qualified_pointer(qual_ptr *, qual_ptr *); | 166 | extern qual_ptr *merge_qualified_pointer(qual_ptr *, qual_ptr *); | |
167 | extern sym_t *add_pointer(sym_t *, qual_ptr *); | 167 | extern sym_t *add_pointer(sym_t *, qual_ptr *); | |
168 | extern sym_t *add_array(sym_t *, bool, int); | 168 | extern sym_t *add_array(sym_t *, bool, int); | |
169 | extern sym_t *add_function(sym_t *, sym_t *); | 169 | extern sym_t *add_function(sym_t *, sym_t *); | |
170 | extern void check_function_definition(sym_t *, bool); | 170 | extern void check_function_definition(sym_t *, bool); | |
171 | extern sym_t *declarator_name(sym_t *); | 171 | extern sym_t *declarator_name(sym_t *); | |
172 | extern sym_t *old_style_function_name(sym_t *); | 172 | extern sym_t *old_style_function_name(sym_t *); |
--- src/usr.bin/xlint/lint1/lint1.h 2021/07/08 02:59:22 1.113
+++ src/usr.bin/xlint/lint1/lint1.h 2021/07/10 17:35:54 1.114
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: lint1.h,v 1.113 2021/07/08 02:59:22 rillig Exp $ */ | 1 | /* $NetBSD: lint1.h,v 1.114 2021/07/10 17:35:54 rillig Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. | 4 | * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. | |
5 | * Copyright (c) 1994, 1995 Jochen Pohl | 5 | * Copyright (c) 1994, 1995 Jochen Pohl | |
6 | * All Rights Reserved. | 6 | * All Rights Reserved. | |
7 | * | 7 | * | |
8 | * Redistribution and use in source and binary forms, with or without | 8 | * Redistribution and use in source and binary forms, with or without | |
9 | * modification, are permitted provided that the following conditions | 9 | * modification, are permitted provided that the following conditions | |
10 | * are met: | 10 | * are met: | |
11 | * 1. Redistributions of source code must retain the above copyright | 11 | * 1. Redistributions of source code must retain the above copyright | |
12 | * notice, this list of conditions and the following disclaimer. | 12 | * notice, this list of conditions and the following disclaimer. | |
13 | * 2. Redistributions in binary form must reproduce the above copyright | 13 | * 2. Redistributions in binary form must reproduce the above copyright | |
14 | * notice, this list of conditions and the following disclaimer in the | 14 | * notice, this list of conditions and the following disclaimer in the | |
@@ -347,27 +347,27 @@ struct generic_association { | @@ -347,27 +347,27 @@ struct generic_association { | |||
347 | * ARG declaration of arguments in old-style function | 347 | * ARG declaration of arguments in old-style function | |
348 | * definitions | 348 | * definitions | |
349 | * PROTO_ARG declaration of arguments in function prototypes | 349 | * PROTO_ARG declaration of arguments in function prototypes | |
350 | * AUTO declaration of local symbols | 350 | * AUTO declaration of local symbols | |
351 | * ABSTRACT abstract declarations (sizeof, casts) | 351 | * ABSTRACT abstract declarations (sizeof, casts) | |
352 | * | 352 | * | |
353 | */ | 353 | */ | |
354 | typedef struct dinfo { | 354 | typedef struct dinfo { | |
355 | tspec_t d_abstract_type;/* VOID, BOOL, CHAR, INT or COMPLEX */ | 355 | tspec_t d_abstract_type;/* VOID, BOOL, CHAR, INT or COMPLEX */ | |
356 | tspec_t d_complex_mod; /* FLOAT or DOUBLE */ | 356 | tspec_t d_complex_mod; /* FLOAT or DOUBLE */ | |
357 | tspec_t d_sign_mod; /* SIGNED or UNSIGN */ | 357 | tspec_t d_sign_mod; /* SIGNED or UNSIGN */ | |
358 | tspec_t d_rank_mod; /* SHORT, LONG or QUAD */ | 358 | tspec_t d_rank_mod; /* SHORT, LONG or QUAD */ | |
359 | scl_t d_scl; /* storage class */ | 359 | scl_t d_scl; /* storage class */ | |
360 | type_t *d_type; /* after deftyp() pointer to the type used | 360 | type_t *d_type; /* after end_type() pointer to the type used | |
361 | for all declarators */ | 361 | for all declarators */ | |
362 | sym_t *d_redeclared_symbol; | 362 | sym_t *d_redeclared_symbol; | |
363 | int d_offset; /* offset of next structure member */ | 363 | int d_offset; /* offset of next structure member */ | |
364 | int d_sou_align_in_bits; /* alignment required for current | 364 | int d_sou_align_in_bits; /* alignment required for current | |
365 | * structure */ | 365 | * structure */ | |
366 | scl_t d_ctx; /* context of declaration */ | 366 | scl_t d_ctx; /* context of declaration */ | |
367 | bool d_const : 1; /* const in declaration specifiers */ | 367 | bool d_const : 1; /* const in declaration specifiers */ | |
368 | bool d_volatile : 1; /* volatile in declaration specifiers */ | 368 | bool d_volatile : 1; /* volatile in declaration specifiers */ | |
369 | bool d_inline : 1; /* inline in declaration specifiers */ | 369 | bool d_inline : 1; /* inline in declaration specifiers */ | |
370 | bool d_mscl : 1; /* multiple storage classes */ | 370 | bool d_mscl : 1; /* multiple storage classes */ | |
371 | bool d_terr : 1; /* invalid type combination */ | 371 | bool d_terr : 1; /* invalid type combination */ | |
372 | bool d_nonempty_decl : 1; /* if at least one tag is declared | 372 | bool d_nonempty_decl : 1; /* if at least one tag is declared | |
373 | * ... in the current function decl. */ | 373 | * ... in the current function decl. */ |