lint: enter full C90 compatibility mode The C99 comment in tree.c:3468 has been there since 2017-03-06, without anyone complaining that their compiler would not handle it. Strangely, running GCC 10.3.0 in '-std=c90' mode does not complain about declarations after statements, '-Wdeclaration-after-statement' is needed separately. No functional change.diff -r1.16 -r1.17 src/usr.bin/xlint/Makefile.inc
(rillig)
--- src/usr.bin/xlint/Makefile.inc 2021/11/01 19:10:07 1.16
+++ src/usr.bin/xlint/Makefile.inc 2021/11/01 19:48:51 1.17
@@ -1,25 +1,26 @@ | @@ -1,25 +1,26 @@ | |||
1 | # $NetBSD: Makefile.inc,v 1.16 2021/11/01 19:10:07 rillig Exp $ | 1 | # $NetBSD: Makefile.inc,v 1.17 2021/11/01 19:48:51 rillig Exp $ | |
2 | 2 | |||
3 | .include <bsd.own.mk> | 3 | .include <bsd.own.mk> | |
4 | 4 | |||
5 | .PATH: ${.CURDIR}/../common | 5 | .PATH: ${.CURDIR}/../common | |
6 | 6 | |||
7 | # Special cases first, then check for a MACHINE_ARCH specific | 7 | # Special cases first, then check for a MACHINE_ARCH specific | |
8 | # subdir before looking for MACHINE_CPU. | 8 | # subdir before looking for MACHINE_CPU. | |
9 | .if exists(${.CURDIR}/../arch/${MACHINE_ARCH}) | 9 | .if exists(${.CURDIR}/../arch/${MACHINE_ARCH}) | |
10 | ARCHSUBDIR= ${MACHINE_ARCH} | 10 | ARCHSUBDIR= ${MACHINE_ARCH} | |
11 | .elif exists(${.CURDIR}/../arch/${MACHINE_ARCH:C/e[lb]$//}) | 11 | .elif exists(${.CURDIR}/../arch/${MACHINE_ARCH:C/e[lb]$//}) | |
12 | ARCHSUBDIR= ${MACHINE_ARCH:C/e[lb]$//} | 12 | ARCHSUBDIR= ${MACHINE_ARCH:C/e[lb]$//} | |
13 | .else | 13 | .else | |
14 | ARCHSUBDIR= ${MACHINE_CPU} | 14 | ARCHSUBDIR= ${MACHINE_CPU} | |
15 | .endif | 15 | .endif | |
16 | 16 | |||
17 | CPPFLAGS+= -I${.CURDIR}/../arch/${ARCHSUBDIR} | 17 | CPPFLAGS+= -I${.CURDIR}/../arch/${ARCHSUBDIR} | |
18 | CPPFLAGS+= -I${.CURDIR}/../common | 18 | CPPFLAGS+= -I${.CURDIR}/../common | |
19 | CWARNFLAGS+= -Wdeclaration-after-statement # it's a build tool | 19 | CWARNFLAGS.gcc+=-Wdeclaration-after-statement # see tools/README | |
20 | CWARNFLAGS.gcc+=-std=c90 # see tools/README | |||
20 | 21 | |||
21 | CLEANFILES+= *.gcno *.gcda *.gcov | 22 | CLEANFILES+= *.gcno *.gcda *.gcov | |
22 | 23 | |||
23 | .if exists(${.CURDIR}/../../Makefile.inc) | 24 | .if exists(${.CURDIR}/../../Makefile.inc) | |
24 | .include "${.CURDIR}/../../Makefile.inc" | 25 | .include "${.CURDIR}/../../Makefile.inc" | |
25 | .endif | 26 | .endif |
--- src/usr.bin/xlint/common/lint.h 2021/09/05 18:17:15 1.32
+++ src/usr.bin/xlint/common/lint.h 2021/11/01 19:48:51 1.33
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: lint.h,v 1.32 2021/09/05 18:17:15 rillig Exp $ */ | 1 | /* $NetBSD: lint.h,v 1.33 2021/11/01 19:48:51 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. | |
@@ -139,23 +139,31 @@ typedef struct ob { | @@ -139,23 +139,31 @@ typedef struct ob { | |||
139 | char *o_end; /* first byte after buffer */ | 139 | char *o_end; /* first byte after buffer */ | |
140 | size_t o_len; /* length of buffer */ | 140 | size_t o_len; /* length of buffer */ | |
141 | char *o_next; /* next free byte in buffer */ | 141 | char *o_next; /* next free byte in buffer */ | |
142 | } ob_t; | 142 | } ob_t; | |
143 | 143 | |||
144 | #if defined(IS_LINT1) | 144 | #if defined(IS_LINT1) | |
145 | typedef struct lint1_type type_t; | 145 | typedef struct lint1_type type_t; | |
146 | #else | 146 | #else | |
147 | typedef struct lint2_type type_t; | 147 | typedef struct lint2_type type_t; | |
148 | #endif | 148 | #endif | |
149 | 149 | |||
150 | #include "externs.h" | 150 | #include "externs.h" | |
151 | 151 | |||
152 | static inline bool | 152 | #if __STDC_VERSION__ >= 199901L | |
153 | #define INLINE_FUNC static inline | |||
154 | #elif __GNUC__ | |||
155 | #define INLINE_FUNC static __attribute__((__unused__)) | |||
156 | #else | |||
157 | #define INLINE_FUNC static | |||
158 | #endif | |||
159 | ||||
160 | INLINE_FUNC bool | |||
153 | ch_isalnum(char ch) { return isalnum((unsigned char)ch) != 0; } | 161 | ch_isalnum(char ch) { return isalnum((unsigned char)ch) != 0; } | |
154 | static inline bool | 162 | INLINE_FUNC bool | |
155 | ch_isdigit(char ch) { return isdigit((unsigned char)ch) != 0; } | 163 | ch_isdigit(char ch) { return isdigit((unsigned char)ch) != 0; } | |
156 | static inline bool | 164 | INLINE_FUNC bool | |
157 | ch_isprint(char ch) { return isprint((unsigned char)ch) != 0; } | 165 | ch_isprint(char ch) { return isprint((unsigned char)ch) != 0; } | |
158 | static inline bool | 166 | INLINE_FUNC bool | |
159 | ch_isspace(char ch) { return isspace((unsigned char)ch) != 0; } | 167 | ch_isspace(char ch) { return isspace((unsigned char)ch) != 0; } | |
160 | static inline bool | 168 | INLINE_FUNC bool | |
161 | ch_isupper(char ch) { return isupper((unsigned char)ch) != 0; } | 169 | ch_isupper(char ch) { return isupper((unsigned char)ch) != 0; } |
--- src/usr.bin/xlint/lint1/ckgetopt.c 2021/11/01 19:10:07 1.13
+++ src/usr.bin/xlint/lint1/ckgetopt.c 2021/11/01 19:48:51 1.14
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: ckgetopt.c,v 1.13 2021/11/01 19:10:07 rillig Exp $ */ | 1 | /* $NetBSD: ckgetopt.c,v 1.14 2021/11/01 19:48:51 rillig Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2021 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2021 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to The NetBSD Foundation | 7 | * This code is derived from software contributed to The NetBSD Foundation | |
8 | * by Roland Illig <rillig@NetBSD.org>. | 8 | * by Roland Illig <rillig@NetBSD.org>. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -25,27 +25,27 @@ | @@ -25,27 +25,27 @@ | |||
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
29 | * POSSIBILITY OF SUCH DAMAGE. | 29 | * POSSIBILITY OF SUCH DAMAGE. | |
30 | */ | 30 | */ | |
31 | 31 | |||
32 | #if HAVE_NBTOOL_CONFIG_H | 32 | #if HAVE_NBTOOL_CONFIG_H | |
33 | #include "nbtool_config.h" | 33 | #include "nbtool_config.h" | |
34 | #endif | 34 | #endif | |
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: ckgetopt.c,v 1.13 2021/11/01 19:10:07 rillig Exp $"); | 38 | __RCSID("$NetBSD: ckgetopt.c,v 1.14 2021/11/01 19:48:51 rillig Exp $"); | |
39 | #endif | 39 | #endif | |
40 | 40 | |||
41 | #include <stdbool.h> | 41 | #include <stdbool.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 | /* | 47 | /* | |
48 | * In a typical while loop for parsing getopt options, ensure that each | 48 | * In a typical while loop for parsing getopt options, ensure that each | |
49 | * option from the options string is handled, and that each handled option | 49 | * option from the options string is handled, and that each handled option | |
50 | * is listed in the options string. | 50 | * is listed in the options string. | |
51 | */ | 51 | */ | |
@@ -123,29 +123,31 @@ check_unlisted_option(char opt) | @@ -123,29 +123,31 @@ check_unlisted_option(char opt) | |||
123 | optptr = strchr(ck.options, opt); | 123 | optptr = strchr(ck.options, opt); | |
124 | if (optptr != NULL) | 124 | if (optptr != NULL) | |
125 | *optptr = ' '; | 125 | *optptr = ' '; | |
126 | else if (opt != '?') { | 126 | else if (opt != '?') { | |
127 | warn: | 127 | warn: | |
128 | /* option '%c' should be listed in the options string */ | 128 | /* option '%c' should be listed in the options string */ | |
129 | warning(339, opt); | 129 | warning(339, opt); | |
130 | } | 130 | } | |
131 | } | 131 | } | |
132 | 132 | |||
133 | static void | 133 | static void | |
134 | check_unhandled_option(void) | 134 | check_unhandled_option(void) | |
135 | { | 135 | { | |
136 | const char *opt; | |||
137 | ||||
136 | lint_assert(ck.options != NULL); | 138 | lint_assert(ck.options != NULL); | |
137 | 139 | |||
138 | for (const char *opt = ck.options; *opt != '\0'; opt++) { | 140 | for (opt = ck.options; *opt != '\0'; opt++) { | |
139 | if (*opt == ' ' || *opt == ':') | 141 | if (*opt == ' ' || *opt == ':') | |
140 | continue; | 142 | continue; | |
141 | 143 | |||
142 | /* option '%c' should be handled in the switch */ | 144 | /* option '%c' should be handled in the switch */ | |
143 | warning_at(338, &ck.options_pos, *opt); | 145 | warning_at(338, &ck.options_pos, *opt); | |
144 | } | 146 | } | |
145 | } | 147 | } | |
146 | 148 | |||
147 | 149 | |||
148 | void | 150 | void | |
149 | check_getopt_begin_while(const tnode_t *tn) | 151 | check_getopt_begin_while(const tnode_t *tn) | |
150 | { | 152 | { | |
151 | if (ck.while_level == 0) { | 153 | if (ck.while_level == 0) { |
--- src/usr.bin/xlint/lint1/lint1.h 2021/09/14 19:44:40 1.129
+++ src/usr.bin/xlint/lint1/lint1.h 2021/11/01 19:48:51 1.130
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: lint1.h,v 1.129 2021/09/14 19:44:40 rillig Exp $ */ | 1 | /* $NetBSD: lint1.h,v 1.130 2021/11/01 19:48:51 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 | |
@@ -487,27 +487,27 @@ typedef struct err_set { | @@ -487,27 +487,27 @@ typedef struct err_set { | |||
487 | #ifdef BLKDEBUG | 487 | #ifdef BLKDEBUG | |
488 | #define ZERO 0xa5 | 488 | #define ZERO 0xa5 | |
489 | #else | 489 | #else | |
490 | #define ZERO 0 | 490 | #define ZERO 0 | |
491 | #endif | 491 | #endif | |
492 | 492 | |||
493 | extern err_set msgset; | 493 | extern err_set msgset; | |
494 | 494 | |||
495 | 495 | |||
496 | #ifdef DEBUG | 496 | #ifdef DEBUG | |
497 | # include "err-msgs.h" | 497 | # include "err-msgs.h" | |
498 | 498 | |||
499 | /* ARGSUSED */ | 499 | /* ARGSUSED */ | |
500 | static inline void __attribute__((format(printf, 1, 2))) | 500 | INLINE_FUNC void __attribute__((format(printf, 1, 2))) | |
501 | check_printf(const char *fmt, ...) | 501 | check_printf(const char *fmt, ...) | |
502 | { | 502 | { | |
503 | } | 503 | } | |
504 | 504 | |||
505 | # define wrap_check_printf_at(func, msgid, pos, args...) \ | 505 | # define wrap_check_printf_at(func, msgid, pos, args...) \ | |
506 | do { \ | 506 | do { \ | |
507 | check_printf(__CONCAT(MSG_, msgid), ##args); \ | 507 | check_printf(__CONCAT(MSG_, msgid), ##args); \ | |
508 | (func)(msgid, pos, ##args); \ | 508 | (func)(msgid, pos, ##args); \ | |
509 | } while (false) | 509 | } while (false) | |
510 | 510 | |||
511 | # define error_at(msgid, pos, args...) \ | 511 | # define error_at(msgid, pos, args...) \ | |
512 | wrap_check_printf_at(error_at, msgid, pos, ##args) | 512 | wrap_check_printf_at(error_at, msgid, pos, ##args) | |
513 | # define warning_at(msgid, pos, args...) \ | 513 | # define warning_at(msgid, pos, args...) \ | |
@@ -518,90 +518,90 @@ check_printf(const char *fmt, ...) | @@ -518,90 +518,90 @@ check_printf(const char *fmt, ...) | |||
518 | # define wrap_check_printf(func, msgid, args...) \ | 518 | # define wrap_check_printf(func, msgid, args...) \ | |
519 | do { \ | 519 | do { \ | |
520 | check_printf(__CONCAT(MSG_, msgid), ##args); \ | 520 | check_printf(__CONCAT(MSG_, msgid), ##args); \ | |
521 | (func)(msgid, ##args); \ | 521 | (func)(msgid, ##args); \ | |
522 | } while (false) | 522 | } while (false) | |
523 | 523 | |||
524 | # define error(msgid, args...) wrap_check_printf(error, msgid, ##args) | 524 | # define error(msgid, args...) wrap_check_printf(error, msgid, ##args) | |
525 | # define warning(msgid, args...) wrap_check_printf(warning, msgid, ##args) | 525 | # define warning(msgid, args...) wrap_check_printf(warning, msgid, ##args) | |
526 | # define gnuism(msgid, args...) wrap_check_printf(gnuism, msgid, ##args) | 526 | # define gnuism(msgid, args...) wrap_check_printf(gnuism, msgid, ##args) | |
527 | # define c99ism(msgid, args...) wrap_check_printf(c99ism, msgid, ##args) | 527 | # define c99ism(msgid, args...) wrap_check_printf(c99ism, msgid, ##args) | |
528 | # define c11ism(msgid, args...) wrap_check_printf(c11ism, msgid, ##args) | 528 | # define c11ism(msgid, args...) wrap_check_printf(c11ism, msgid, ##args) | |
529 | #endif | 529 | #endif | |
530 | 530 | |||
531 | static inline bool | 531 | INLINE_FUNC bool | |
532 | is_nonzero_val(const val_t *val) | 532 | is_nonzero_val(const val_t *val) | |
533 | { | 533 | { | |
534 | return is_floating(val->v_tspec) | 534 | return is_floating(val->v_tspec) | |
535 | ? val->v_ldbl != 0.0 | 535 | ? val->v_ldbl != 0.0 | |
536 | : val->v_quad != 0; | 536 | : val->v_quad != 0; | |
537 | } | 537 | } | |
538 | 538 | |||
539 | static inline bool | 539 | INLINE_FUNC bool | |
540 | constant_is_nonzero(const tnode_t *tn) | 540 | constant_is_nonzero(const tnode_t *tn) | |
541 | { | 541 | { | |
542 | lint_assert(tn->tn_op == CON); | 542 | lint_assert(tn->tn_op == CON); | |
543 | lint_assert(tn->tn_type->t_tspec == tn->tn_val->v_tspec); | 543 | lint_assert(tn->tn_type->t_tspec == tn->tn_val->v_tspec); | |
544 | return is_nonzero_val(tn->tn_val); | 544 | return is_nonzero_val(tn->tn_val); | |
545 | } | 545 | } | |
546 | 546 | |||
547 | static inline bool | 547 | INLINE_FUNC bool | |
548 | is_zero(const tnode_t *tn) | 548 | is_zero(const tnode_t *tn) | |
549 | { | 549 | { | |
550 | return tn != NULL && tn->tn_op == CON && !is_nonzero_val(tn->tn_val); | 550 | return tn != NULL && tn->tn_op == CON && !is_nonzero_val(tn->tn_val); | |
551 | } | 551 | } | |
552 | 552 | |||
553 | static inline bool | 553 | INLINE_FUNC bool | |
554 | is_nonzero(const tnode_t *tn) | 554 | is_nonzero(const tnode_t *tn) | |
555 | { | 555 | { | |
556 | return tn != NULL && tn->tn_op == CON && is_nonzero_val(tn->tn_val); | 556 | return tn != NULL && tn->tn_op == CON && is_nonzero_val(tn->tn_val); | |
557 | } | 557 | } | |
558 | 558 | |||
559 | static inline bool | 559 | INLINE_FUNC bool | |
560 | is_binary(const tnode_t *tn) | 560 | is_binary(const tnode_t *tn) | |
561 | { | 561 | { | |
562 | return modtab[tn->tn_op].m_binary; | 562 | return modtab[tn->tn_op].m_binary; | |
563 | } | 563 | } | |
564 | 564 | |||
565 | static inline uint64_t | 565 | INLINE_FUNC uint64_t | |
566 | bit(unsigned i) | 566 | bit(unsigned i) | |
567 | { | 567 | { | |
568 | /* | 568 | /* | |
569 | * TODO: Add proper support for INT128. | 569 | * TODO: Add proper support for INT128. | |
570 | * This involves changing val_t to 128 bits. | 570 | * This involves changing val_t to 128 bits. | |
571 | */ | 571 | */ | |
572 | if (i >= 64) | 572 | if (i >= 64) | |
573 | return 0; /* XXX: not correct for INT128 and UINT128 */ | 573 | return 0; /* XXX: not correct for INT128 and UINT128 */ | |
574 | 574 | |||
575 | lint_assert(i < 64); | 575 | lint_assert(i < 64); | |
576 | return (uint64_t)1 << i; | 576 | return (uint64_t)1 << i; | |
577 | } | 577 | } | |
578 | 578 | |||
579 | static inline bool | 579 | INLINE_FUNC bool | |
580 | msb(int64_t q, tspec_t t) | 580 | msb(int64_t q, tspec_t t) | |
581 | { | 581 | { | |
582 | return (q & bit((unsigned int)size_in_bits(t) - 1)) != 0; | 582 | return (q & bit((unsigned int)size_in_bits(t) - 1)) != 0; | |
583 | } | 583 | } | |
584 | 584 | |||
585 | static inline uint64_t | 585 | INLINE_FUNC uint64_t | |
586 | value_bits(unsigned bitsize) | 586 | value_bits(unsigned bitsize) | |
587 | { | 587 | { | |
588 | lint_assert(bitsize > 0); | 588 | lint_assert(bitsize > 0); | |
589 | 589 | |||
590 | /* for long double (80 or 128), double _Complex (128) */ | 590 | /* for long double (80 or 128), double _Complex (128) */ | |
591 | /* | 591 | /* | |
592 | * XXX: double _Complex does not have 128 bits of precision, | 592 | * XXX: double _Complex does not have 128 bits of precision, | |
593 | * therefore it should never be necessary to query the value bits | 593 | * therefore it should never be necessary to query the value bits | |
594 | * of such a type; see d_c99_complex_split.c to trigger this case. | 594 | * of such a type; see d_c99_complex_split.c to trigger this case. | |
595 | */ | 595 | */ | |
596 | if (bitsize >= 64) | 596 | if (bitsize >= 64) | |
597 | return ~((uint64_t)0); | 597 | return ~((uint64_t)0); | |
598 | 598 | |||
599 | return ~(~(uint64_t)0 << bitsize); | 599 | return ~(~(uint64_t)0 << bitsize); | |
600 | } | 600 | } | |
601 | 601 | |||
602 | /* C99 6.7.8p7 */ | 602 | /* C99 6.7.8p7 */ | |
603 | static inline bool | 603 | INLINE_FUNC bool | |
604 | is_struct_or_union(tspec_t t) | 604 | is_struct_or_union(tspec_t t) | |
605 | { | 605 | { | |
606 | return t == STRUCT || t == UNION; | 606 | return t == STRUCT || t == UNION; | |
607 | } | 607 | } |
--- src/usr.bin/xlint/lint1/tree.c 2021/11/01 19:10:07 1.392
+++ src/usr.bin/xlint/lint1/tree.c 2021/11/01 19:48:51 1.393
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: tree.c,v 1.392 2021/11/01 19:10:07 rillig Exp $ */ | 1 | /* $NetBSD: tree.c,v 1.393 2021/11/01 19:48:51 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.392 2021/11/01 19:10:07 rillig Exp $"); | 40 | __RCSID("$NetBSD: tree.c,v 1.393 2021/11/01 19:48:51 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 | |||
53 | static tnode_t *build_integer_constant(tspec_t, int64_t); | 53 | static tnode_t *build_integer_constant(tspec_t, int64_t); | |
@@ -3455,27 +3455,27 @@ build_sizeof(const type_t *tp) | @@ -3455,27 +3455,27 @@ build_sizeof(const type_t *tp) | |||
3455 | * Create a constant node for offsetof. | 3455 | * Create a constant node for offsetof. | |
3456 | */ | 3456 | */ | |
3457 | /* ARGSUSED */ /* See implementation comments. */ | 3457 | /* ARGSUSED */ /* See implementation comments. */ | |
3458 | tnode_t * | 3458 | tnode_t * | |
3459 | build_offsetof(const type_t *tp, const sym_t *sym) | 3459 | build_offsetof(const type_t *tp, const sym_t *sym) | |
3460 | { | 3460 | { | |
3461 | unsigned int offset_in_bytes; | 3461 | unsigned int offset_in_bytes; | |
3462 | tnode_t *tn; | 3462 | tnode_t *tn; | |
3463 | 3463 | |||
3464 | if (!is_struct_or_union(tp->t_tspec)) | 3464 | if (!is_struct_or_union(tp->t_tspec)) | |
3465 | /* unacceptable operand of '%s' */ | 3465 | /* unacceptable operand of '%s' */ | |
3466 | error(111, "offsetof"); | 3466 | error(111, "offsetof"); | |
3467 | 3467 | |||
3468 | // XXX: wrong size, no checking for sym fixme | 3468 | /* XXX: wrong size, no checking for sym fixme */ | |
3469 | offset_in_bytes = type_size_in_bits(tp) / CHAR_SIZE; | 3469 | offset_in_bytes = type_size_in_bits(tp) / CHAR_SIZE; | |
3470 | tn = build_integer_constant(SIZEOF_TSPEC, offset_in_bytes); | 3470 | tn = build_integer_constant(SIZEOF_TSPEC, offset_in_bytes); | |
3471 | tn->tn_system_dependent = true; | 3471 | tn->tn_system_dependent = true; | |
3472 | return tn; | 3472 | return tn; | |
3473 | } | 3473 | } | |
3474 | 3474 | |||
3475 | unsigned int | 3475 | unsigned int | |
3476 | type_size_in_bits(const type_t *tp) | 3476 | type_size_in_bits(const type_t *tp) | |
3477 | { | 3477 | { | |
3478 | unsigned int elem, elsz; | 3478 | unsigned int elem, elsz; | |
3479 | bool flex; | 3479 | bool flex; | |
3480 | 3480 | |||
3481 | elem = 1; | 3481 | elem = 1; | |
@@ -3925,27 +3925,27 @@ expr(tnode_t *tn, bool vctx, bool tctx, | @@ -3925,27 +3925,27 @@ expr(tnode_t *tn, bool vctx, bool tctx, | |||
3925 | * printed | 3925 | * printed | |
3926 | */ | 3926 | */ | |
3927 | if (tn->tn_op != COMMA && !vctx && !tctx) | 3927 | if (tn->tn_op != COMMA && !vctx && !tctx) | |
3928 | check_null_effect(tn); | 3928 | check_null_effect(tn); | |
3929 | } | 3929 | } | |
3930 | debug_node(tn); | 3930 | debug_node(tn); | |
3931 | 3931 | |||
3932 | /* free the tree memory */ | 3932 | /* free the tree memory */ | |
3933 | if (dofreeblk) | 3933 | if (dofreeblk) | |
3934 | expr_free_all(); | 3934 | expr_free_all(); | |
3935 | } | 3935 | } | |
3936 | 3936 | |||
3937 | static bool | 3937 | static bool | |
3938 | has_side_effect(const tnode_t *tn) // NOLINT(misc-no-recursion) | 3938 | has_side_effect(const tnode_t *tn) /* NOLINT(misc-no-recursion) */ | |
3939 | { | 3939 | { | |
3940 | op_t op = tn->tn_op; | 3940 | op_t op = tn->tn_op; | |
3941 | 3941 | |||
3942 | if (modtab[op].m_has_side_effect) | 3942 | if (modtab[op].m_has_side_effect) | |
3943 | return true; | 3943 | return true; | |
3944 | 3944 | |||
3945 | if (op == CVT && tn->tn_type->t_tspec == VOID) | 3945 | if (op == CVT && tn->tn_type->t_tspec == VOID) | |
3946 | return has_side_effect(tn->tn_left); | 3946 | return has_side_effect(tn->tn_left); | |
3947 | 3947 | |||
3948 | /* XXX: Why not has_side_effect(tn->tn_left) as well? */ | 3948 | /* XXX: Why not has_side_effect(tn->tn_left) as well? */ | |
3949 | if (op == LOGAND || op == LOGOR) | 3949 | if (op == LOGAND || op == LOGOR) | |
3950 | return has_side_effect(tn->tn_right); | 3950 | return has_side_effect(tn->tn_right); | |
3951 | 3951 |
--- src/usr.bin/xlint/lint2/lint2.h 2021/08/29 10:13:02 1.19
+++ src/usr.bin/xlint/lint2/lint2.h 2021/11/01 19:48:51 1.20
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: lint2.h,v 1.19 2021/08/29 10:13:02 rillig Exp $ */ | 1 | /* $NetBSD: lint2.h,v 1.20 2021/11/01 19:48:51 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 | |
@@ -176,18 +176,18 @@ typedef struct hte { | @@ -176,18 +176,18 @@ typedef struct hte { | |||
176 | sym_t *h_syms; /* declarations and definitions */ | 176 | sym_t *h_syms; /* declarations and definitions */ | |
177 | sym_t **h_lsym; /* points to s_next of last decl./def. */ | 177 | sym_t **h_lsym; /* points to s_next of last decl./def. */ | |
178 | fcall_t *h_calls; /* function calls */ | 178 | fcall_t *h_calls; /* function calls */ | |
179 | fcall_t **h_lcall; /* points to f_next of last call */ | 179 | fcall_t **h_lcall; /* points to f_next of last call */ | |
180 | usym_t *h_usyms; /* usage info */ | 180 | usym_t *h_usyms; /* usage info */ | |
181 | usym_t **h_lusym; /* points to u_next of last usage info */ | 181 | usym_t **h_lusym; /* points to u_next of last usage info */ | |
182 | struct hte *h_link; /* next hte with same hash function */ | 182 | struct hte *h_link; /* next hte with same hash function */ | |
183 | struct hte *h_hte; /* pointer to other htes (for renames) */ | 183 | struct hte *h_hte; /* pointer to other htes (for renames) */ | |
184 | } hte_t; | 184 | } hte_t; | |
185 | 185 | |||
186 | #include "externs2.h" | 186 | #include "externs2.h" | |
187 | 187 | |||
188 | /* maps type indices into pointers to type structs */ | 188 | /* maps type indices into pointers to type structs */ | |
189 | static inline type_t * | 189 | INLINE_FUNC type_t * | |
190 | TP(unsigned short type_id) { | 190 | TP(unsigned short type_id) { | |
191 | /* force sequence point for newly parsed type_id */ | 191 | /* force sequence point for newly parsed type_id */ | |
192 | return tlst[type_id]; | 192 | return tlst[type_id]; | |
193 | } | 193 | } |