Tue Jul 20 19:35:53 2021 UTC ()
lint: split 'build' into build_binary and build_unary

No functional change.


(rillig)
diff -r1.328 -r1.329 src/usr.bin/xlint/lint1/cgram.y
diff -r1.118 -r1.119 src/usr.bin/xlint/lint1/externs1.h
diff -r1.113 -r1.114 src/usr.bin/xlint/lint1/func.c
diff -r1.201 -r1.202 src/usr.bin/xlint/lint1/init.c
diff -r1.316 -r1.317 src/usr.bin/xlint/lint1/tree.c

cvs diff -r1.328 -r1.329 src/usr.bin/xlint/lint1/cgram.y (expand / switch to unified diff)

--- src/usr.bin/xlint/lint1/cgram.y 2021/07/15 20:05:49 1.328
+++ src/usr.bin/xlint/lint1/cgram.y 2021/07/20 19:35:53 1.329
@@ -1,15 +1,15 @@ @@ -1,15 +1,15 @@
1%{ 1%{
2/* $NetBSD: cgram.y,v 1.328 2021/07/15 20:05:49 rillig Exp $ */ 2/* $NetBSD: cgram.y,v 1.329 2021/07/20 19:35:53 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.328 2021/07/15 20:05:49 rillig Exp $"); 38__RCSID("$NetBSD: cgram.y,v 1.329 2021/07/20 19:35:53 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
47extern char *yytext; 47extern 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.
@@ -460,39 +460,39 @@ generic_association: @@ -460,39 +460,39 @@ generic_association:
460 $$->ga_result = $3; 460 $$->ga_result = $3;
461 } 461 }
462 | T_DEFAULT T_COLON assignment_expression { 462 | T_DEFAULT T_COLON assignment_expression {
463 $$ = getblk(sizeof(*$$)); 463 $$ = getblk(sizeof(*$$));
464 $$->ga_arg = NULL; 464 $$->ga_arg = NULL;
465 $$->ga_result = $3; 465 $$->ga_result = $3;
466 } 466 }
467 ; 467 ;
468 468
469/* K&R 7.1, C90 ???, C99 6.5.2, C11 6.5.2 */ 469/* K&R 7.1, C90 ???, C99 6.5.2, C11 6.5.2 */
470postfix_expression: 470postfix_expression:
471 primary_expression 471 primary_expression
472 | postfix_expression T_LBRACK expression T_RBRACK { 472 | postfix_expression T_LBRACK expression T_RBRACK {
473 $$ = build(INDIR, build(PLUS, $1, $3), NULL); 473 $$ = build_unary(INDIR, build_binary($1, PLUS, $3));
474 } 474 }
475 | postfix_expression T_LPAREN T_RPAREN { 475 | postfix_expression T_LPAREN T_RPAREN {
476 $$ = new_function_call_node($1, NULL); 476 $$ = new_function_call_node($1, NULL);
477 } 477 }
478 | postfix_expression T_LPAREN argument_expression_list T_RPAREN { 478 | postfix_expression T_LPAREN argument_expression_list T_RPAREN {
479 $$ = new_function_call_node($1, $3); 479 $$ = new_function_call_node($1, $3);
480 } 480 }
481 | postfix_expression point_or_arrow T_NAME { 481 | postfix_expression point_or_arrow T_NAME {
482 $$ = build_member_access($1, $2, $3); 482 $$ = build_member_access($1, $2, $3);
483 } 483 }
484 | postfix_expression T_INCDEC { 484 | postfix_expression T_INCDEC {
485 $$ = build($2 == INC ? INCAFT : DECAFT, $1, NULL); 485 $$ = build_unary($2 == INC ? INCAFT : DECAFT, $1);
486 } 486 }
487 | T_LPAREN type_name T_RPAREN { /* C99 6.5.2.5 "Compound literals" */ 487 | T_LPAREN type_name T_RPAREN { /* C99 6.5.2.5 "Compound literals" */
488 sym_t *tmp = mktempsym($2); 488 sym_t *tmp = mktempsym($2);
489 begin_initialization(tmp); 489 begin_initialization(tmp);
490 cgram_declare(tmp, true, NULL); 490 cgram_declare(tmp, true, NULL);
491 } init_lbrace initializer_list comma_opt init_rbrace { 491 } init_lbrace initializer_list comma_opt init_rbrace {
492 if (!Sflag) 492 if (!Sflag)
493 /* compound literals are a C9X/GCC extension */ 493 /* compound literals are a C9X/GCC extension */
494 gnuism(319); 494 gnuism(319);
495 $$ = new_name_node(*current_initsym(), 0); 495 $$ = new_name_node(*current_initsym(), 0);
496 end_initialization(); 496 end_initialization();
497 } 497 }
498 | T_LPAREN compound_statement_lbrace gcc_statement_expr_list { 498 | T_LPAREN compound_statement_lbrace gcc_statement_expr_list {
@@ -565,52 +565,52 @@ point_or_arrow: /* helper for 'postfix @@ -565,52 +565,52 @@ point_or_arrow: /* helper for 'postfix
565argument_expression_list: 565argument_expression_list:
566 assignment_expression { 566 assignment_expression {
567 $$ = new_function_argument_node(NULL, $1); 567 $$ = new_function_argument_node(NULL, $1);
568 } 568 }
569 | argument_expression_list T_COMMA assignment_expression { 569 | argument_expression_list T_COMMA assignment_expression {
570 $$ = new_function_argument_node($1, $3); 570 $$ = new_function_argument_node($1, $3);
571 } 571 }
572 ; 572 ;
573 573
574/* K&R 7.2, C90 ???, C99 6.5.3, C11 6.5.3 */ 574/* K&R 7.2, C90 ???, C99 6.5.3, C11 6.5.3 */
575unary_expression: 575unary_expression:
576 postfix_expression 576 postfix_expression
577 | T_INCDEC unary_expression { 577 | T_INCDEC unary_expression {
578 $$ = build($1 == INC ? INCBEF : DECBEF, $2, NULL); 578 $$ = build_unary($1 == INC ? INCBEF : DECBEF, $2);
579 } 579 }
580 | T_AMPER cast_expression { 580 | T_AMPER cast_expression {
581 $$ = build(ADDR, $2, NULL); 581 $$ = build_unary(ADDR, $2);
582 } 582 }
583 | T_ASTERISK cast_expression { 583 | T_ASTERISK cast_expression {
584 $$ = build(INDIR, $2, NULL); 584 $$ = build_unary(INDIR, $2);
585 } 585 }
586 | T_ADDITIVE cast_expression { 586 | T_ADDITIVE cast_expression {
587 if (tflag && $1 == PLUS) { 587 if (tflag && $1 == PLUS) {
588 /* unary + is illegal in traditional C */ 588 /* unary + is illegal in traditional C */
589 warning(100); 589 warning(100);
590 } 590 }
591 $$ = build($1 == PLUS ? UPLUS : UMINUS, $2, NULL); 591 $$ = build_unary($1 == PLUS ? UPLUS : UMINUS, $2);
592 } 592 }
593 | T_COMPLEMENT cast_expression { 593 | T_COMPLEMENT cast_expression {
594 $$ = build(COMPL, $2, NULL); 594 $$ = build_unary(COMPL, $2);
595 } 595 }
596 | T_LOGNOT cast_expression { 596 | T_LOGNOT cast_expression {
597 $$ = build(NOT, $2, NULL); 597 $$ = build_unary(NOT, $2);
598 } 598 }
599 | T_REAL cast_expression { /* GCC c_parser_unary_expression */ 599 | T_REAL cast_expression { /* GCC c_parser_unary_expression */
600 $$ = build(REAL, $2, NULL); 600 $$ = build_unary(REAL, $2);
601 } 601 }
602 | T_IMAG cast_expression { /* GCC c_parser_unary_expression */ 602 | T_IMAG cast_expression { /* GCC c_parser_unary_expression */
603 $$ = build(IMAG, $2, NULL); 603 $$ = build_unary(IMAG, $2);
604 } 604 }
605 | T_EXTENSION cast_expression { /* GCC c_parser_unary_expression */ 605 | T_EXTENSION cast_expression { /* GCC c_parser_unary_expression */
606 $$ = $2; 606 $$ = $2;
607 } 607 }
608 | T_SIZEOF unary_expression { 608 | T_SIZEOF unary_expression {
609 $$ = $2 == NULL ? NULL : build_sizeof($2->tn_type); 609 $$ = $2 == NULL ? NULL : build_sizeof($2->tn_type);
610 if ($$ != NULL) 610 if ($$ != NULL)
611 check_expr_misc($2, false, false, false, false, false, true); 611 check_expr_misc($2, false, false, false, false, false, true);
612 } 612 }
613 | T_SIZEOF T_LPAREN type_name T_RPAREN { 613 | T_SIZEOF T_LPAREN type_name T_RPAREN {
614 $$ = build_sizeof($3); 614 $$ = build_sizeof($3);
615 } 615 }
616 /* K&R ---, C90 ---, C99 ---, C11 6.5.3 */ 616 /* K&R ---, C90 ---, C99 ---, C11 6.5.3 */
@@ -639,80 +639,80 @@ expression_opt: @@ -639,80 +639,80 @@ expression_opt:
639/* 'conditional_expression' also implements 'multiplicative_expression'. */ 639/* 'conditional_expression' also implements 'multiplicative_expression'. */
640/* 'conditional_expression' also implements 'additive_expression'. */ 640/* 'conditional_expression' also implements 'additive_expression'. */
641/* 'conditional_expression' also implements 'shift_expression'. */ 641/* 'conditional_expression' also implements 'shift_expression'. */
642/* 'conditional_expression' also implements 'relational_expression'. */ 642/* 'conditional_expression' also implements 'relational_expression'. */
643/* 'conditional_expression' also implements 'equality_expression'. */ 643/* 'conditional_expression' also implements 'equality_expression'. */
644/* 'conditional_expression' also implements 'AND_expression'. */ 644/* 'conditional_expression' also implements 'AND_expression'. */
645/* 'conditional_expression' also implements 'exclusive_OR_expression'. */ 645/* 'conditional_expression' also implements 'exclusive_OR_expression'. */
646/* 'conditional_expression' also implements 'inclusive_OR_expression'. */ 646/* 'conditional_expression' also implements 'inclusive_OR_expression'. */
647/* 'conditional_expression' also implements 'logical_AND_expression'. */ 647/* 'conditional_expression' also implements 'logical_AND_expression'. */
648/* 'conditional_expression' also implements 'logical_OR_expression'. */ 648/* 'conditional_expression' also implements 'logical_OR_expression'. */
649/* K&R ???, C90 ???, C99 6.5.5 to 6.5.15, C11 6.5.5 to 6.5.15 */ 649/* K&R ???, C90 ???, C99 6.5.5 to 6.5.15, C11 6.5.5 to 6.5.15 */
650conditional_expression: 650conditional_expression:
651 conditional_expression T_ASTERISK conditional_expression { 651 conditional_expression T_ASTERISK conditional_expression {
652 $$ = build(MULT, $1, $3); 652 $$ = build_binary($1, MULT, $3);
653 } 653 }
654 | conditional_expression T_MULTIPLICATIVE conditional_expression { 654 | conditional_expression T_MULTIPLICATIVE conditional_expression {
655 $$ = build($2, $1, $3); 655 $$ = build_binary($1, $2, $3);
656 } 656 }
657 | conditional_expression T_ADDITIVE conditional_expression { 657 | conditional_expression T_ADDITIVE conditional_expression {
658 $$ = build($2, $1, $3); 658 $$ = build_binary($1, $2, $3);
659 } 659 }
660 | conditional_expression T_SHIFT conditional_expression { 660 | conditional_expression T_SHIFT conditional_expression {
661 $$ = build($2, $1, $3); 661 $$ = build_binary($1, $2, $3);
662 } 662 }
663 | conditional_expression T_RELATIONAL conditional_expression { 663 | conditional_expression T_RELATIONAL conditional_expression {
664 $$ = build($2, $1, $3); 664 $$ = build_binary($1, $2, $3);
665 } 665 }
666 | conditional_expression T_EQUALITY conditional_expression { 666 | conditional_expression T_EQUALITY conditional_expression {
667 $$ = build($2, $1, $3); 667 $$ = build_binary($1, $2, $3);
668 } 668 }
669 | conditional_expression T_AMPER conditional_expression { 669 | conditional_expression T_AMPER conditional_expression {
670 $$ = build(BITAND, $1, $3); 670 $$ = build_binary($1, BITAND, $3);
671 } 671 }
672 | conditional_expression T_BITXOR conditional_expression { 672 | conditional_expression T_BITXOR conditional_expression {
673 $$ = build(BITXOR, $1, $3); 673 $$ = build_binary($1, BITXOR, $3);
674 } 674 }
675 | conditional_expression T_BITOR conditional_expression { 675 | conditional_expression T_BITOR conditional_expression {
676 $$ = build(BITOR, $1, $3); 676 $$ = build_binary($1, BITOR, $3);
677 } 677 }
678 | conditional_expression T_LOGAND conditional_expression { 678 | conditional_expression T_LOGAND conditional_expression {
679 $$ = build(LOGAND, $1, $3); 679 $$ = build_binary($1, LOGAND, $3);
680 } 680 }
681 | conditional_expression T_LOGOR conditional_expression { 681 | conditional_expression T_LOGOR conditional_expression {
682 $$ = build(LOGOR, $1, $3); 682 $$ = build_binary($1, LOGOR, $3);
683 } 683 }
684 | conditional_expression T_QUEST conditional_expression 684 | conditional_expression T_QUEST conditional_expression
685 T_COLON conditional_expression { 685 T_COLON conditional_expression {
686 $$ = build(QUEST, $1, build(COLON, $3, $5)); 686 $$ = build_binary($1, QUEST, build_binary($3, COLON, $5));
687 } 687 }
688 | cast_expression; 688 | cast_expression;
689 689
690/* K&R ???, C90 ???, C99 6.5.16, C11 6.5.16 */ 690/* K&R ???, C90 ???, C99 6.5.16, C11 6.5.16 */
691assignment_expression: 691assignment_expression:
692 conditional_expression 692 conditional_expression
693 | assignment_expression T_ASSIGN conditional_expression { 693 | assignment_expression T_ASSIGN conditional_expression {
694 $$ = build(ASSIGN, $1, $3); 694 $$ = build_binary($1, ASSIGN, $3);
695 } 695 }
696 | assignment_expression T_OPASSIGN conditional_expression { 696 | assignment_expression T_OPASSIGN conditional_expression {
697 $$ = build($2, $1, $3); 697 $$ = build_binary($1, $2, $3);
698 } 698 }
699 ; 699 ;
700 700
701/* K&R ???, C90 ???, C99 6.5.17, C11 6.5.17 */ 701/* K&R ???, C90 ???, C99 6.5.17, C11 6.5.17 */
702expression: 702expression:
703 assignment_expression 703 assignment_expression
704 | expression T_COMMA assignment_expression { 704 | expression T_COMMA assignment_expression {
705 $$ = build(COMMA, $1, $3); 705 $$ = build_binary($1, COMMA, $3);
706 } 706 }
707 ; 707 ;
708 708
709constant_expr_list_opt: /* helper for gcc_attribute */ 709constant_expr_list_opt: /* helper for gcc_attribute */
710 /* empty */ 710 /* empty */
711 | constant_expr_list 711 | constant_expr_list
712 ; 712 ;
713 713
714constant_expr_list: /* helper for gcc_attribute */ 714constant_expr_list: /* helper for gcc_attribute */
715 constant_expr 715 constant_expr
716 | constant_expr_list T_COMMA constant_expr 716 | constant_expr_list T_COMMA constant_expr
717 ; 717 ;
718 718

cvs diff -r1.118 -r1.119 src/usr.bin/xlint/lint1/externs1.h (expand / switch to unified diff)

--- src/usr.bin/xlint/lint1/externs1.h 2021/07/15 17:03:50 1.118
+++ src/usr.bin/xlint/lint1/externs1.h 2021/07/20 19:35:53 1.119
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: externs1.h,v 1.118 2021/07/15 17:03:50 rillig Exp $ */ 1/* $NetBSD: externs1.h,v 1.119 2021/07/20 19:35:53 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.
@@ -201,27 +201,28 @@ extern int to_int_constant(tnode_t *, bo @@ -201,27 +201,28 @@ extern int to_int_constant(tnode_t *, bo
201/* 201/*
202 * tree.c 202 * tree.c
203 */ 203 */
204extern const tnode_t *before_conversion(const tnode_t *); 204extern const tnode_t *before_conversion(const tnode_t *);
205extern type_t *derive_type(type_t *, tspec_t); 205extern type_t *derive_type(type_t *, tspec_t);
206extern type_t *expr_derive_type(type_t *, tspec_t); 206extern type_t *expr_derive_type(type_t *, tspec_t);
207extern tnode_t *expr_new_constant(type_t *, val_t *); 207extern tnode_t *expr_new_constant(type_t *, val_t *);
208extern tnode_t *new_name_node(sym_t *, int); 208extern tnode_t *new_name_node(sym_t *, int);
209extern tnode_t *new_string_node(strg_t *); 209extern tnode_t *new_string_node(strg_t *);
210extern sym_t *struct_or_union_member(tnode_t *, op_t, sym_t *); 210extern sym_t *struct_or_union_member(tnode_t *, op_t, sym_t *);
211extern tnode_t *build_generic_selection(const tnode_t *, 211extern tnode_t *build_generic_selection(const tnode_t *,
212 struct generic_association *); 212 struct generic_association *);
213 213
214extern tnode_t *build(op_t, tnode_t *, tnode_t *); 214extern tnode_t *build_binary(tnode_t *, op_t, tnode_t *);
 215extern tnode_t *build_unary(op_t, tnode_t *);
215extern tnode_t *build_member_access(tnode_t *, op_t, sbuf_t *); 216extern tnode_t *build_member_access(tnode_t *, op_t, sbuf_t *);
216extern tnode_t *cconv(tnode_t *); 217extern tnode_t *cconv(tnode_t *);
217extern bool is_typeok_bool_operand(const tnode_t *); 218extern bool is_typeok_bool_operand(const tnode_t *);
218extern bool typeok(op_t, int, const tnode_t *, const tnode_t *); 219extern bool typeok(op_t, int, const tnode_t *, const tnode_t *);
219extern tnode_t *promote(op_t, bool, tnode_t *); 220extern tnode_t *promote(op_t, bool, tnode_t *);
220extern tnode_t *convert(op_t, int, type_t *, tnode_t *); 221extern tnode_t *convert(op_t, int, type_t *, tnode_t *);
221extern void convert_constant(op_t, int, const type_t *, val_t *, val_t *); 222extern void convert_constant(op_t, int, const type_t *, val_t *, val_t *);
222extern tnode_t *build_sizeof(const type_t *); 223extern tnode_t *build_sizeof(const type_t *);
223extern tnode_t *build_offsetof(const type_t *, const sym_t *); 224extern tnode_t *build_offsetof(const type_t *, const sym_t *);
224extern tnode_t *build_alignof(const type_t *); 225extern tnode_t *build_alignof(const type_t *);
225extern tnode_t *cast(tnode_t *, type_t *); 226extern tnode_t *cast(tnode_t *, type_t *);
226extern tnode_t *new_function_argument_node(tnode_t *, tnode_t *); 227extern tnode_t *new_function_argument_node(tnode_t *, tnode_t *);
227extern tnode_t *new_function_call_node(tnode_t *, tnode_t *); 228extern tnode_t *new_function_call_node(tnode_t *, tnode_t *);

cvs diff -r1.113 -r1.114 src/usr.bin/xlint/lint1/func.c (expand / switch to unified diff)

--- src/usr.bin/xlint/lint1/func.c 2021/07/04 07:09:39 1.113
+++ src/usr.bin/xlint/lint1/func.c 2021/07/20 19:35:53 1.114
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: func.c,v 1.113 2021/07/04 07:09:39 rillig Exp $ */ 1/* $NetBSD: func.c,v 1.114 2021/07/20 19:35:53 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.113 2021/07/04 07:09:39 rillig Exp $"); 40__RCSID("$NetBSD: func.c,v 1.114 2021/07/20 19:35:53 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 */
53sym_t *funcsym; 53sym_t *funcsym;
@@ -1086,27 +1086,27 @@ do_return(tnode_t *tn) @@ -1086,27 +1086,27 @@ do_return(tnode_t *tn)
1086 warning(214, funcsym->s_name); 1086 warning(214, funcsym->s_name);
1087 } 1087 }
1088 1088
1089 if (tn != NULL) { 1089 if (tn != NULL) {
1090 1090
1091 /* Create a temporary node for the left side */ 1091 /* Create a temporary node for the left side */
1092 ln = expr_zalloc(sizeof(*ln)); 1092 ln = expr_zalloc(sizeof(*ln));
1093 ln->tn_op = NAME; 1093 ln->tn_op = NAME;
1094 ln->tn_type = expr_dup_type(funcsym->s_type->t_subt); 1094 ln->tn_type = expr_dup_type(funcsym->s_type->t_subt);
1095 ln->tn_type->t_const = false; 1095 ln->tn_type->t_const = false;
1096 ln->tn_lvalue = true; 1096 ln->tn_lvalue = true;
1097 ln->tn_sym = funcsym; /* better than nothing */ 1097 ln->tn_sym = funcsym; /* better than nothing */
1098 1098
1099 tn = build(RETURN, ln, tn); 1099 tn = build_binary(ln, RETURN, tn);
1100 1100
1101 if (tn != NULL) { 1101 if (tn != NULL) {
1102 rn = tn->tn_right; 1102 rn = tn->tn_right;
1103 while ((op = rn->tn_op) == CVT || op == PLUS) 1103 while ((op = rn->tn_op) == CVT || op == PLUS)
1104 rn = rn->tn_left; 1104 rn = rn->tn_left;
1105 if (rn->tn_op == ADDR && rn->tn_left->tn_op == NAME && 1105 if (rn->tn_op == ADDR && rn->tn_left->tn_op == NAME &&
1106 rn->tn_left->tn_sym->s_scl == AUTO) { 1106 rn->tn_left->tn_sym->s_scl == AUTO) {
1107 /* %s returns pointer to automatic object */ 1107 /* %s returns pointer to automatic object */
1108 warning(302, funcsym->s_name); 1108 warning(302, funcsym->s_name);
1109 } 1109 }
1110 } 1110 }
1111 1111
1112 expr(tn, true, false, true, false); 1112 expr(tn, true, false, true, false);

cvs diff -r1.201 -r1.202 src/usr.bin/xlint/lint1/init.c (expand / switch to unified diff)

--- src/usr.bin/xlint/lint1/init.c 2021/07/02 22:46:43 1.201
+++ src/usr.bin/xlint/lint1/init.c 2021/07/20 19:35:53 1.202
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: init.c,v 1.201 2021/07/02 22:46:43 rillig Exp $ */ 1/* $NetBSD: init.c,v 1.202 2021/07/20 19:35:53 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1994, 1995 Jochen Pohl 4 * Copyright (c) 1994, 1995 Jochen Pohl
5 * Copyright (c) 2021 Roland Illig 5 * Copyright (c) 2021 Roland Illig
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: init.c,v 1.201 2021/07/02 22:46:43 rillig Exp $"); 41__RCSID("$NetBSD: init.c,v 1.202 2021/07/20 19:35:53 rillig Exp $");
42#endif 42#endif
43 43
44#include <stdlib.h> 44#include <stdlib.h>
45#include <string.h> 45#include <string.h>
46 46
47#include "lint1.h" 47#include "lint1.h"
48 48
49 49
50/* 50/*
51 * Initialization of global or local objects, like in: 51 * Initialization of global or local objects, like in:
52 * 52 *
53 * int number = 12345; 53 * int number = 12345;
54 * int number_with_braces = { 12345 }; 54 * int number_with_braces = { 12345 };
@@ -893,27 +893,27 @@ initialization_expr_using_assign(struct  @@ -893,27 +893,27 @@ initialization_expr_using_assign(struct
893 if (!has_automatic_storage_duration(in->in_sym)) 893 if (!has_automatic_storage_duration(in->in_sym))
894 return false; 894 return false;
895 if (in->in_brace_level != NULL) 895 if (in->in_brace_level != NULL)
896 return false; 896 return false;
897 if (in->in_sym->s_type->t_tspec == ARRAY) 897 if (in->in_sym->s_type->t_tspec == ARRAY)
898 return false; 898 return false;
899 899
900 debug_step0("handing over to ASSIGN"); 900 debug_step0("handing over to ASSIGN");
901 901
902 ln = new_name_node(in->in_sym, 0); 902 ln = new_name_node(in->in_sym, 0);
903 ln->tn_type = expr_dup_type(ln->tn_type); 903 ln->tn_type = expr_dup_type(ln->tn_type);
904 ln->tn_type->t_const = false; 904 ln->tn_type->t_const = false;
905 905
906 tn = build(ASSIGN, ln, rn); 906 tn = build_binary(ln, ASSIGN, rn);
907 expr(tn, false, false, false, false); 907 expr(tn, false, false, false, false);
908 908
909 return true; 909 return true;
910} 910}
911 911
912/* Initialize a character array or wchar_t array with a string literal. */ 912/* Initialize a character array or wchar_t array with a string literal. */
913static bool 913static bool
914initialization_init_array_using_string(struct initialization *in, tnode_t *tn) 914initialization_init_array_using_string(struct initialization *in, tnode_t *tn)
915{ 915{
916 struct brace_level *bl; 916 struct brace_level *bl;
917 const type_t *tp; 917 const type_t *tp;
918 strg_t *strg; 918 strg_t *strg;
919 919

cvs diff -r1.316 -r1.317 src/usr.bin/xlint/lint1/tree.c (expand / switch to unified diff)

--- src/usr.bin/xlint/lint1/tree.c 2021/07/15 21:22:19 1.316
+++ src/usr.bin/xlint/lint1/tree.c 2021/07/20 19:35:53 1.317
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: tree.c,v 1.316 2021/07/15 21:22:19 rillig Exp $ */ 1/* $NetBSD: tree.c,v 1.317 2021/07/20 19:35:53 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: tree.c,v 1.316 2021/07/15 21:22:19 rillig Exp $"); 40__RCSID("$NetBSD: tree.c,v 1.317 2021/07/20 19:35:53 rillig Exp $");
41#endif 41#endif
42 42
43#include <float.h> 43#include <float.h>
44#include <limits.h> 44#include <limits.h>
45#include <math.h> 45#include <math.h>
46#include <signal.h> 46#include <signal.h>
47#include <stdlib.h> 47#include <stdlib.h>
48#include <string.h> 48#include <string.h>
49 49
50#include "lint1.h" 50#include "lint1.h"
51#include "cgram.h" 51#include "cgram.h"
52 52
53static tnode_t *expr_new_integer_constant(tspec_t, int64_t); 53static tnode_t *expr_new_integer_constant(tspec_t, int64_t);
@@ -499,27 +499,27 @@ build_generic_selection(const tnode_t *e @@ -499,27 +499,27 @@ build_generic_selection(const tnode_t *e
499 default_result = sel->ga_result; 499 default_result = sel->ga_result;
500 return default_result; 500 return default_result;
501} 501}
502 502
503/* 503/*
504 * Create a tree node. Called for most operands except function calls, 504 * Create a tree node. Called for most operands except function calls,
505 * sizeof and casts. 505 * sizeof and casts.
506 * 506 *
507 * op operator 507 * op operator
508 * ln left operand 508 * ln left operand
509 * rn if not NULL, right operand 509 * rn if not NULL, right operand
510 */ 510 */
511tnode_t * 511tnode_t *
512build(op_t op, tnode_t *ln, tnode_t *rn) 512build_binary(tnode_t *ln, op_t op, tnode_t *rn)
513{ 513{
514 const mod_t *mp; 514 const mod_t *mp;
515 tnode_t *ntn; 515 tnode_t *ntn;
516 type_t *rettp; 516 type_t *rettp;
517 517
518 mp = &modtab[op]; 518 mp = &modtab[op];
519 519
520 /* If there was an error in one of the operands, return. */ 520 /* If there was an error in one of the operands, return. */
521 if (ln == NULL || (mp->m_binary && rn == NULL)) 521 if (ln == NULL || (mp->m_binary && rn == NULL))
522 return NULL; 522 return NULL;
523 523
524 /* 524 /*
525 * Apply class conversions to the left operand, but only if its 525 * Apply class conversions to the left operand, but only if its
@@ -678,39 +678,45 @@ build(op_t op, tnode_t *ln, tnode_t *rn) @@ -678,39 +678,45 @@ build(op_t op, tnode_t *ln, tnode_t *rn)
678 } else { 678 } else {
679 ntn = fold(ntn); 679 ntn = fold(ntn);
680 } 680 }
681 } else if (op == QUEST && ln->tn_op == CON) { 681 } else if (op == QUEST && ln->tn_op == CON) {
682 ntn = ln->tn_val->v_quad != 0 682 ntn = ln->tn_val->v_quad != 0
683 ? rn->tn_left : rn->tn_right; 683 ? rn->tn_left : rn->tn_right;
684 } 684 }
685 } 685 }
686 686
687 return ntn; 687 return ntn;
688} 688}
689 689
690tnode_t * 690tnode_t *
 691build_unary(op_t op, tnode_t *tn)
 692{
 693 return build_binary(tn, op, NULL);
 694}
 695
 696tnode_t *
691build_member_access(tnode_t *ln, op_t op, sbuf_t *member) 697build_member_access(tnode_t *ln, op_t op, sbuf_t *member)
692{ 698{
693 sym_t *msym; 699 sym_t *msym;
694 700
695 if (ln == NULL) 701 if (ln == NULL)
696 return NULL; 702 return NULL;
697 703
698 if (op == ARROW) { 704 if (op == ARROW) {
699 /* must do this before struct_or_union_member is called */ 705 /* must do this before struct_or_union_member is called */
700 ln = cconv(ln); 706 ln = cconv(ln);
701 } 707 }
702 msym = struct_or_union_member(ln, op, getsym(member)); 708 msym = struct_or_union_member(ln, op, getsym(member));
703 return build(op, ln, new_name_node(msym, 0)); 709 return build_binary(ln, op, new_name_node(msym, 0));
704} 710}
705 711
706/* 712/*
707 * Perform class conversions. 713 * Perform class conversions.
708 * 714 *
709 * Arrays of type T are converted into pointers to type T. 715 * Arrays of type T are converted into pointers to type T.
710 * Functions are converted to pointers to functions. 716 * Functions are converted to pointers to functions.
711 * Lvalues are converted to rvalues. 717 * Lvalues are converted to rvalues.
712 * 718 *
713 * C99 6.3 "Conversions" 719 * C99 6.3 "Conversions"
714 * C99 6.3.2 "Other operands" 720 * C99 6.3.2 "Other operands"
715 * C99 6.3.2.1 "Lvalues, arrays, and function designators" 721 * C99 6.3.2.1 "Lvalues, arrays, and function designators"
716 */ 722 */
@@ -3672,29 +3678,29 @@ constant(tnode_t *tn, bool required) @@ -3672,29 +3678,29 @@ constant(tnode_t *tn, bool required)
3672 v->v_tspec = INT; 3678 v->v_tspec = INT;
3673 3679
3674 return v; 3680 return v;
3675} 3681}
3676 3682
3677static bool 3683static bool
3678is_constcond_false(const tnode_t *tn, tspec_t t) 3684is_constcond_false(const tnode_t *tn, tspec_t t)
3679{ 3685{
3680 return (t == BOOL || t == INT) && 3686 return (t == BOOL || t == INT) &&
3681 tn->tn_op == CON && tn->tn_val->v_quad == 0; 3687 tn->tn_op == CON && tn->tn_val->v_quad == 0;
3682} 3688}
3683 3689
3684/* 3690/*
3685 * Perform some tests on expressions which can't be done in build() and 3691 * Perform some tests on expressions which can't be done in build_binary()
3686 * functions called by build(). These tests must be done here because 3692 * and functions called by build_binary(). These tests must be done here
3687 * we need some information about the context in which the operations 3693 * because we need some information about the context in which the operations
3688 * are performed. 3694 * are performed.
3689 * After all tests are performed and dofreeblk is true, expr() frees the 3695 * After all tests are performed and dofreeblk is true, expr() frees the
3690 * memory which is used for the expression. 3696 * memory which is used for the expression.
3691 */ 3697 */
3692void 3698void
3693expr(tnode_t *tn, bool vctx, bool tctx, bool dofreeblk, bool is_do_while) 3699expr(tnode_t *tn, bool vctx, bool tctx, bool dofreeblk, bool is_do_while)
3694{ 3700{
3695 3701
3696 if (tn == NULL) { /* in case of errors */ 3702 if (tn == NULL) { /* in case of errors */
3697 expr_free_all(); 3703 expr_free_all();
3698 return; 3704 return;
3699 } 3705 }
3700 3706