lint: add query for conversion from void pointer to other pointerdiff -r1.27 -r1.28 src/tests/usr.bin/xlint/lint1/queries.c
(rillig)
--- src/tests/usr.bin/xlint/lint1/queries.c 2024/03/30 19:12:37 1.27
+++ src/tests/usr.bin/xlint/lint1/queries.c 2024/04/27 10:08:54 1.28
@@ -1,32 +1,32 @@ | @@ -1,32 +1,32 @@ | |||
1 | /* $NetBSD: queries.c,v 1.27 2024/03/30 19:12:37 rillig Exp $ */ | 1 | /* $NetBSD: queries.c,v 1.28 2024/04/27 10:08:54 rillig Exp $ */ | |
2 | # 3 "queries.c" | 2 | # 3 "queries.c" | |
3 | 3 | |||
4 | /* | 4 | /* | |
5 | * Demonstrate the case-by-case queries. Unlike warnings, queries do not | 5 | * Demonstrate the case-by-case queries. Unlike warnings, queries do not | |
6 | * point to questionable code but rather to code that may be interesting to | 6 | * point to questionable code but rather to code that may be interesting to | |
7 | * inspect manually on a case-by-case basis. | 7 | * inspect manually on a case-by-case basis. | |
8 | * | 8 | * | |
9 | * Possible use cases are: | 9 | * Possible use cases are: | |
10 | * | 10 | * | |
11 | * Understanding how C works internally, by making the usual arithmetic | 11 | * Understanding how C works internally, by making the usual arithmetic | |
12 | * conversions visible. | 12 | * conversions visible. | |
13 | * | 13 | * | |
14 | * Finding code that intentionally suppresses a regular lint warning, | 14 | * Finding code that intentionally suppresses a regular lint warning, | |
15 | * such as casts between arithmetic types. | 15 | * such as casts between arithmetic types. | |
16 | */ | 16 | */ | |
17 | 17 | |||
18 | /* lint1-extra-flags: -q 1,2,3,4,5,6,7,8,9,10 */ | 18 | /* lint1-extra-flags: -q 1,2,3,4,5,6,7,8,9,10 */ | |
19 | /* lint1-extra-flags: -q 11,12,13,14,15,16,17,18,19 */ | 19 | /* lint1-extra-flags: -q 11,12,13,14,15,16,17,18,19,20 */ | |
20 | /* lint1-extra-flags: -X 351 */ | 20 | /* lint1-extra-flags: -X 351 */ | |
21 | 21 | |||
22 | typedef unsigned char u8_t; | 22 | typedef unsigned char u8_t; | |
23 | typedef unsigned short u16_t; | 23 | typedef unsigned short u16_t; | |
24 | typedef unsigned int u32_t; | 24 | typedef unsigned int u32_t; | |
25 | typedef unsigned long long u64_t; | 25 | typedef unsigned long long u64_t; | |
26 | typedef signed char s8_t; | 26 | typedef signed char s8_t; | |
27 | typedef signed short s16_t; | 27 | typedef signed short s16_t; | |
28 | typedef signed int s32_t; | 28 | typedef signed int s32_t; | |
29 | typedef signed long long s64_t; | 29 | typedef signed long long s64_t; | |
30 | 30 | |||
31 | typedef float f32_t; | 31 | typedef float f32_t; | |
32 | typedef double f64_t; | 32 | typedef double f64_t; | |
@@ -63,26 +63,28 @@ struct { | @@ -63,26 +63,28 @@ struct { | |||
63 | 63 | |||
64 | f32_t f32; | 64 | f32_t f32; | |
65 | f64_t f64; | 65 | f64_t f64; | |
66 | 66 | |||
67 | c32_t c32; | 67 | c32_t c32; | |
68 | c64_t c64; | 68 | c64_t c64; | |
69 | 69 | |||
70 | char *str; | 70 | char *str; | |
71 | const char *cstr; | 71 | const char *cstr; | |
72 | volatile char *vstr; | 72 | volatile char *vstr; | |
73 | 73 | |||
74 | void *void_ptr; | 74 | void *void_ptr; | |
75 | const void *const_void_ptr; | 75 | const void *const_void_ptr; | |
76 | char *char_ptr; | |||
77 | int *int_ptr; | |||
76 | 78 | |||
77 | int | 79 | int | |
78 | Q1(double dbl) | 80 | Q1(double dbl) | |
79 | { | 81 | { | |
80 | /* expect+1: implicit conversion from floating point 'double' to integer 'int' [Q1] */ | 82 | /* expect+1: implicit conversion from floating point 'double' to integer 'int' [Q1] */ | |
81 | return dbl; | 83 | return dbl; | |
82 | } | 84 | } | |
83 | 85 | |||
84 | int | 86 | int | |
85 | Q2(double dbl) | 87 | Q2(double dbl) | |
86 | { | 88 | { | |
87 | /* expect+1: cast from floating point 'double' to integer 'int' [Q2] */ | 89 | /* expect+1: cast from floating point 'double' to integer 'int' [Q2] */ | |
88 | return (int)dbl; | 90 | return (int)dbl; | |
@@ -349,29 +351,29 @@ Q9(int x) | @@ -349,29 +351,29 @@ Q9(int x) | |||
349 | return (0, 1); | 351 | return (0, 1); | |
350 | case 6: | 352 | case 6: | |
351 | /* expect+1: comma operator with types 'int' and 'int' [Q12] */ | 353 | /* expect+1: comma operator with types 'int' and 'int' [Q12] */ | |
352 | return 0, 1; | 354 | return 0, 1; | |
353 | case 7: | 355 | case 7: | |
354 | /* expect+1: implicit conversion from floating point 'double' to integer 'int' [Q1] */ | 356 | /* expect+1: implicit conversion from floating point 'double' to integer 'int' [Q1] */ | |
355 | return 0.0; | 357 | return 0.0; | |
356 | case 8: | 358 | case 8: | |
357 | /* expect+2: parenthesized return value [Q9] */ | 359 | /* expect+2: parenthesized return value [Q9] */ | |
358 | /* expect+1: implicit conversion from floating point 'double' to integer 'int' [Q1] */ | 360 | /* expect+1: implicit conversion from floating point 'double' to integer 'int' [Q1] */ | |
359 | return (0.0); | 361 | return (0.0); | |
360 | case 9: | 362 | case 9: | |
361 | return | 363 | return | |
362 | # 363 "queries.c" 3 4 | 364 | # 365 "queries.c" 3 4 | |
363 | ((void *)0) | 365 | ((void *)0) | |
364 | # 365 "queries.c" | 366 | # 367 "queries.c" | |
365 | /* expect+1: warning: illegal combination of integer 'int' and pointer 'pointer to void' [183] */ | 367 | /* expect+1: warning: illegal combination of integer 'int' and pointer 'pointer to void' [183] */ | |
366 | ; | 368 | ; | |
367 | case 10: | 369 | case 10: | |
368 | /* expect+1: warning: illegal combination of integer 'int' and pointer 'pointer to void' [183] */ | 370 | /* expect+1: warning: illegal combination of integer 'int' and pointer 'pointer to void' [183] */ | |
369 | return (void *)(0); | 371 | return (void *)(0); | |
370 | default: | 372 | default: | |
371 | return 0; | 373 | return 0; | |
372 | } | 374 | } | |
373 | } | 375 | } | |
374 | 376 | |||
375 | void | 377 | void | |
376 | Q10(void) | 378 | Q10(void) | |
377 | { | 379 | { | |
@@ -499,20 +501,35 @@ convert_from_integer_to_floating(void) | @@ -499,20 +501,35 @@ convert_from_integer_to_floating(void) | |||
499 | /* expect+1: implicit conversion from integer 'long long' to floating point 'double' [Q19] */ | 501 | /* expect+1: implicit conversion from integer 'long long' to floating point 'double' [Q19] */ | |
500 | f64 = s64; | 502 | f64 = s64; | |
501 | /* expect+1: implicit conversion from integer 'unsigned long long' to floating point 'double' [Q19] */ | 503 | /* expect+1: implicit conversion from integer 'unsigned long long' to floating point 'double' [Q19] */ | |
502 | f64 = u64; | 504 | f64 = u64; | |
503 | 505 | |||
504 | f32 = 0.0F; | 506 | f32 = 0.0F; | |
505 | f32 = 0.0; | 507 | f32 = 0.0; | |
506 | f64 = 0.0; | 508 | f64 = 0.0; | |
507 | 509 | |||
508 | f64 = (double)0; | 510 | f64 = (double)0; | |
509 | f64 = (double)u32; | 511 | f64 = (double)u32; | |
510 | } | 512 | } | |
511 | 513 | |||
512 | /* | 514 | // C allows implicit narrowing conversions from a void pointer to an arbitrary | |
513 | * Since queries do not affect the exit status, force a warning to make this | 515 | // object pointer. C++ doesn't allow this conversion since it is narrowing. | |
514 | * test conform to the general expectation that a test that produces output | 516 | void | |
515 | * exits non-successfully. | 517 | Q20_void_pointer_conversion(void) | |
516 | */ | 518 | { | |
517 | /* expect+1: warning: static variable 'unused' unused [226] */ | 519 | /* expect+1: warning: operands of '=' have incompatible pointer types to 'void' and 'const void' [128] */ | |
518 | static int unused; | 520 | void_ptr = const_void_ptr; | |
521 | const_void_ptr = void_ptr; | |||
522 | /* expect+1: implicit narrowing conversion from void pointer to 'pointer to int' [Q20] */ | |||
523 | int_ptr = void_ptr; | |||
524 | /* expect+1: redundant cast from 'pointer to void' to 'pointer to int' before assignment [Q7] */ | |||
525 | int_ptr = (int *)void_ptr; | |||
526 | /* expect+1: implicit narrowing conversion from void pointer to 'pointer to char' [Q20] */ | |||
527 | char_ptr = void_ptr; | |||
528 | void_ptr = char_ptr; | |||
529 | /* expect+1: implicit narrowing conversion from void pointer to 'pointer to int' [Q20] */ | |||
530 | int_ptr = void_ptr; | |||
531 | /* expect+1: warning: illegal combination of 'pointer to int' and 'pointer to char', op '=' [124] */ | |||
532 | int_ptr = char_ptr; | |||
533 | /* expect+1: warning: illegal combination of 'pointer to char' and 'pointer to int', op '=' [124] */ | |||
534 | char_ptr = int_ptr; | |||
535 | } |
--- src/tests/usr.bin/xlint/lint1/t_usage.sh 2024/03/30 17:23:13 1.19
+++ src/tests/usr.bin/xlint/lint1/t_usage.sh 2024/04/27 10:08:54 1.20
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | # $NetBSD: t_usage.sh,v 1.19 2024/03/30 17:23:13 rillig Exp $ | 1 | # $NetBSD: t_usage.sh,v 1.20 2024/04/27 10:08:54 rillig Exp $ | |
2 | # | 2 | # | |
3 | # Copyright (c) 2023 The NetBSD Foundation, Inc. | 3 | # Copyright (c) 2023 The NetBSD Foundation, Inc. | |
4 | # All rights reserved. | 4 | # All rights reserved. | |
5 | # | 5 | # | |
6 | # Redistribution and use in source and binary forms, with or without | 6 | # Redistribution and use in source and binary forms, with or without | |
7 | # modification, are permitted provided that the following conditions | 7 | # modification, are permitted provided that the following conditions | |
8 | # are met: | 8 | # are met: | |
9 | # 1. Redistributions of source code must retain the above copyright | 9 | # 1. Redistributions of source code must retain the above copyright | |
10 | # notice, this list of conditions and the following disclaimer. | 10 | # notice, this list of conditions and the following disclaimer. | |
11 | # 2. Redistributions in binary form must reproduce the above copyright | 11 | # 2. Redistributions in binary form must reproduce the above copyright | |
12 | # notice, this list of conditions and the following disclaimer in the | 12 | # notice, this list of conditions and the following disclaimer in the | |
13 | # documentation and/or other materials provided with the distribution. | 13 | # documentation and/or other materials provided with the distribution. | |
14 | # | 14 | # | |
@@ -79,33 +79,33 @@ suppress_messages_body() | @@ -79,33 +79,33 @@ suppress_messages_body() | |||
79 | atf_test_case 'enable_queries' | 79 | atf_test_case 'enable_queries' | |
80 | enable_queries_body() | 80 | enable_queries_body() | |
81 | { | 81 | { | |
82 | printf 'typedef int dummy;\n' > code.c | 82 | printf 'typedef int dummy;\n' > code.c | |
83 | 83 | |||
84 | # Query IDs are 1-based. | 84 | # Query IDs are 1-based. | |
85 | atf_check \ | 85 | atf_check \ | |
86 | -s 'exit:1' \ | 86 | -s 'exit:1' \ | |
87 | -e "inline:lint1: invalid query ID '0'\n" \ | 87 | -e "inline:lint1: invalid query ID '0'\n" \ | |
88 | "$lint1" -q 0 code.c /dev/null | 88 | "$lint1" -q 0 code.c /dev/null | |
89 | 89 | |||
90 | # The largest known query. | 90 | # The largest known query. | |
91 | atf_check \ | 91 | atf_check \ | |
92 | "$lint1" -q 19 code.c /dev/null | 92 | "$lint1" -q 20 code.c /dev/null | |
93 | 93 | |||
94 | # Larger than the largest known query. | 94 | # Larger than the largest known query. | |
95 | atf_check \ | 95 | atf_check \ | |
96 | -s 'exit:1' \ | 96 | -s 'exit:1' \ | |
97 | -e "inline:lint1: invalid query ID '20'\n" \ | 97 | -e "inline:lint1: invalid query ID '21'\n" \ | |
98 | "$lint1" -q 20 code.c /dev/null | 98 | "$lint1" -q 21 code.c /dev/null | |
99 | 99 | |||
100 | # Whitespace is not allowed before a query ID. | 100 | # Whitespace is not allowed before a query ID. | |
101 | atf_check \ | 101 | atf_check \ | |
102 | -s 'exit:1' \ | 102 | -s 'exit:1' \ | |
103 | -e "inline:lint1: invalid query ID ' 1'\n" \ | 103 | -e "inline:lint1: invalid query ID ' 1'\n" \ | |
104 | "$lint1" -q ' 1' code.c /dev/null | 104 | "$lint1" -q ' 1' code.c /dev/null | |
105 | 105 | |||
106 | # Whitespace is not allowed after a query ID. | 106 | # Whitespace is not allowed after a query ID. | |
107 | atf_check \ | 107 | atf_check \ | |
108 | -s 'exit:1' \ | 108 | -s 'exit:1' \ | |
109 | -e "inline:lint1: invalid query ID '1 '\n" \ | 109 | -e "inline:lint1: invalid query ID '1 '\n" \ | |
110 | "$lint1" -q '1 ' code.c /dev/null | 110 | "$lint1" -q '1 ' code.c /dev/null | |
111 | 111 |
--- src/usr.bin/xlint/lint1/err.c 2024/04/12 05:17:48 1.240
+++ src/usr.bin/xlint/lint1/err.c 2024/04/27 10:08:54 1.241
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: err.c,v 1.240 2024/04/12 05:17:48 rillig Exp $ */ | 1 | /* $NetBSD: err.c,v 1.241 2024/04/27 10:08: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. | |
@@ -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) | 39 | #if defined(__RCSID) | |
40 | __RCSID("$NetBSD: err.c,v 1.240 2024/04/12 05:17:48 rillig Exp $"); | 40 | __RCSID("$NetBSD: err.c,v 1.241 2024/04/27 10:08:54 rillig Exp $"); | |
41 | #endif | 41 | #endif | |
42 | 42 | |||
43 | #include <limits.h> | 43 | #include <limits.h> | |
44 | #include <stdarg.h> | 44 | #include <stdarg.h> | |
45 | #include <stdlib.h> | 45 | #include <stdlib.h> | |
46 | #include <string.h> | 46 | #include <string.h> | |
47 | 47 | |||
48 | #include "lint1.h" | 48 | #include "lint1.h" | |
49 | 49 | |||
50 | bool seen_error; | 50 | bool seen_error; | |
51 | bool seen_warning; | 51 | bool seen_warning; | |
52 | 52 | |||
53 | /* number of syntax errors */ | 53 | /* number of syntax errors */ | |
@@ -731,26 +731,27 @@ static const char *queries[] = { | @@ -731,26 +731,27 @@ static const char *queries[] = { | |||
731 | "redundant cast from '%s' to '%s' before assignment", // Q7 | 731 | "redundant cast from '%s' to '%s' before assignment", // Q7 | |
732 | "octal number '%.*s'", // Q8 | 732 | "octal number '%.*s'", // Q8 | |
733 | "parenthesized return value", // Q9 | 733 | "parenthesized return value", // Q9 | |
734 | "chained assignment with '%s' and '%s'", // Q10 | 734 | "chained assignment with '%s' and '%s'", // Q10 | |
735 | "static variable '%s' in function", // Q11 | 735 | "static variable '%s' in function", // Q11 | |
736 | "comma operator with types '%s' and '%s'", // Q12 | 736 | "comma operator with types '%s' and '%s'", // Q12 | |
737 | "redundant 'extern' in function declaration of '%s'", // Q13 | 737 | "redundant 'extern' in function declaration of '%s'", // Q13 | |
738 | "comparison '%s' of 'char' with plain integer %d", // Q14 | 738 | "comparison '%s' of 'char' with plain integer %d", // Q14 | |
739 | "implicit conversion from integer 0 to pointer '%s'", // Q15 | 739 | "implicit conversion from integer 0 to pointer '%s'", // Q15 | |
740 | "'%s' was declared 'static', now non-'static'", // Q16 | 740 | "'%s' was declared 'static', now non-'static'", // Q16 | |
741 | "invisible character U+%04X in %s", // Q17 | 741 | "invisible character U+%04X in %s", // Q17 | |
742 | "const automatic variable '%s'", // Q18 | 742 | "const automatic variable '%s'", // Q18 | |
743 | "implicit conversion from integer '%s' to floating point '%s'", // Q19 | 743 | "implicit conversion from integer '%s' to floating point '%s'", // Q19 | |
744 | "implicit narrowing conversion from void pointer to '%s'", // Q20 | |||
744 | }; | 745 | }; | |
745 | 746 | |||
746 | bool any_query_enabled; /* for optimizing non-query scenarios */ | 747 | bool any_query_enabled; /* for optimizing non-query scenarios */ | |
747 | bool is_query_enabled[sizeof(queries) / sizeof(queries[0])]; | 748 | bool is_query_enabled[sizeof(queries) / sizeof(queries[0])]; | |
748 | 749 | |||
749 | void | 750 | void | |
750 | (query_message)(int query_id, ...) | 751 | (query_message)(int query_id, ...) | |
751 | { | 752 | { | |
752 | 753 | |||
753 | if (!is_query_enabled[query_id]) | 754 | if (!is_query_enabled[query_id]) | |
754 | return; | 755 | return; | |
755 | 756 | |||
756 | va_list ap; | 757 | va_list ap; |
--- src/usr.bin/xlint/lint1/tree.c 2024/04/12 05:44:38 1.635
+++ src/usr.bin/xlint/lint1/tree.c 2024/04/27 10:08:54 1.636
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: tree.c,v 1.635 2024/04/12 05:44:38 rillig Exp $ */ | 1 | /* $NetBSD: tree.c,v 1.636 2024/04/27 10:08: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. | |
@@ -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) | 39 | #if defined(__RCSID) | |
40 | __RCSID("$NetBSD: tree.c,v 1.635 2024/04/12 05:44:38 rillig Exp $"); | 40 | __RCSID("$NetBSD: tree.c,v 1.636 2024/04/27 10:08:54 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 | 51 | |||
52 | 52 | |||
53 | typedef struct integer_constraints { | 53 | typedef struct integer_constraints { | |
@@ -1422,26 +1422,32 @@ build_assignment(op_t op, bool sys, tnod | @@ -1422,26 +1422,32 @@ build_assignment(op_t op, bool sys, tnod | |||
1422 | 1422 | |||
1423 | if (op == SHLASS && hflag && allow_trad && allow_c90 | 1423 | if (op == SHLASS && hflag && allow_trad && allow_c90 | |
1424 | && portable_rank_cmp(lt, rt) < 0) | 1424 | && portable_rank_cmp(lt, rt) < 0) | |
1425 | /* semantics of '%s' change in C90; ... */ | 1425 | /* semantics of '%s' change in C90; ... */ | |
1426 | warning(118, "<<="); | 1426 | warning(118, "<<="); | |
1427 | 1427 | |||
1428 | if (op != SHLASS && op != SHRASS | 1428 | if (op != SHLASS && op != SHRASS | |
1429 | && (op == ASSIGN || lt != PTR) | 1429 | && (op == ASSIGN || lt != PTR) | |
1430 | && (lt != rt || (ln->tn_type->t_bitfield && rn->tn_op == CON))) { | 1430 | && (lt != rt || (ln->tn_type->t_bitfield && rn->tn_op == CON))) { | |
1431 | rn = convert(op, 0, ln->tn_type, rn); | 1431 | rn = convert(op, 0, ln->tn_type, rn); | |
1432 | rt = lt; | 1432 | rt = lt; | |
1433 | } | 1433 | } | |
1434 | 1434 | |||
1435 | if (is_query_enabled[20] | |||
1436 | && lt == PTR && ln->tn_type->t_subt->t_tspec != VOID | |||
1437 | && rt == PTR && rn->tn_type->t_subt->t_tspec == VOID) | |||
1438 | /* implicit narrowing conversion from void ... */ | |||
1439 | query_message(20, type_name(ln->tn_type)); | |||
1440 | ||||
1435 | if (any_query_enabled && rn->tn_op == CVT && rn->tn_cast && | 1441 | if (any_query_enabled && rn->tn_op == CVT && rn->tn_cast && | |
1436 | types_compatible(ln->tn_type, rn->tn_type, false, false, NULL) && | 1442 | types_compatible(ln->tn_type, rn->tn_type, false, false, NULL) && | |
1437 | is_cast_redundant(rn)) { | 1443 | is_cast_redundant(rn)) { | |
1438 | /* redundant cast from '%s' to '%s' before assignment */ | 1444 | /* redundant cast from '%s' to '%s' before assignment */ | |
1439 | query_message(7, type_name(rn->u.ops.left->tn_type), | 1445 | query_message(7, type_name(rn->u.ops.left->tn_type), | |
1440 | type_name(rn->tn_type)); | 1446 | type_name(rn->tn_type)); | |
1441 | } | 1447 | } | |
1442 | 1448 | |||
1443 | return build_op(op, sys, ln->tn_type, ln, rn); | 1449 | return build_op(op, sys, ln->tn_type, ln, rn); | |
1444 | } | 1450 | } | |
1445 | 1451 | |||
1446 | static tnode_t * | 1452 | static tnode_t * | |
1447 | build_real_imag(op_t op, bool sys, tnode_t *ln) | 1453 | build_real_imag(op_t op, bool sys, tnode_t *ln) |