Module Name: src Committed By: rillig Date: Sat Apr 27 10:08:55 UTC 2024
Modified Files: src/tests/usr.bin/xlint/lint1: queries.c t_usage.sh src/usr.bin/xlint/lint1: err.c tree.c Log Message: lint: add query for conversion from void pointer to other pointer To generate a diff of this commit: cvs rdiff -u -r1.27 -r1.28 src/tests/usr.bin/xlint/lint1/queries.c cvs rdiff -u -r1.19 -r1.20 src/tests/usr.bin/xlint/lint1/t_usage.sh cvs rdiff -u -r1.240 -r1.241 src/usr.bin/xlint/lint1/err.c cvs rdiff -u -r1.635 -r1.636 src/usr.bin/xlint/lint1/tree.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/tests/usr.bin/xlint/lint1/queries.c diff -u src/tests/usr.bin/xlint/lint1/queries.c:1.27 src/tests/usr.bin/xlint/lint1/queries.c:1.28 --- src/tests/usr.bin/xlint/lint1/queries.c:1.27 Sat Mar 30 19:12:37 2024 +++ src/tests/usr.bin/xlint/lint1/queries.c Sat Apr 27 10:08:54 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: queries.c,v 1.27 2024/03/30 19:12:37 rillig Exp $ */ +/* $NetBSD: queries.c,v 1.28 2024/04/27 10:08:54 rillig Exp $ */ # 3 "queries.c" /* @@ -16,7 +16,7 @@ */ /* lint1-extra-flags: -q 1,2,3,4,5,6,7,8,9,10 */ -/* lint1-extra-flags: -q 11,12,13,14,15,16,17,18,19 */ +/* lint1-extra-flags: -q 11,12,13,14,15,16,17,18,19,20 */ /* lint1-extra-flags: -X 351 */ typedef unsigned char u8_t; @@ -73,6 +73,8 @@ volatile char *vstr; void *void_ptr; const void *const_void_ptr; +char *char_ptr; +int *int_ptr; int Q1(double dbl) @@ -359,9 +361,9 @@ Q9(int x) return (0.0); case 9: return -# 363 "queries.c" 3 4 +# 365 "queries.c" 3 4 ((void *)0) -# 365 "queries.c" +# 367 "queries.c" /* expect+1: warning: illegal combination of integer 'int' and pointer 'pointer to void' [183] */ ; case 10: @@ -509,10 +511,25 @@ convert_from_integer_to_floating(void) f64 = (double)u32; } -/* - * Since queries do not affect the exit status, force a warning to make this - * test conform to the general expectation that a test that produces output - * exits non-successfully. - */ -/* expect+1: warning: static variable 'unused' unused [226] */ -static int unused; +// C allows implicit narrowing conversions from a void pointer to an arbitrary +// object pointer. C++ doesn't allow this conversion since it is narrowing. +void +Q20_void_pointer_conversion(void) +{ + /* expect+1: warning: operands of '=' have incompatible pointer types to 'void' and 'const void' [128] */ + void_ptr = const_void_ptr; + const_void_ptr = void_ptr; + /* expect+1: implicit narrowing conversion from void pointer to 'pointer to int' [Q20] */ + int_ptr = void_ptr; + /* expect+1: redundant cast from 'pointer to void' to 'pointer to int' before assignment [Q7] */ + int_ptr = (int *)void_ptr; + /* expect+1: implicit narrowing conversion from void pointer to 'pointer to char' [Q20] */ + char_ptr = void_ptr; + void_ptr = char_ptr; + /* expect+1: implicit narrowing conversion from void pointer to 'pointer to int' [Q20] */ + int_ptr = void_ptr; + /* expect+1: warning: illegal combination of 'pointer to int' and 'pointer to char', op '=' [124] */ + int_ptr = char_ptr; + /* expect+1: warning: illegal combination of 'pointer to char' and 'pointer to int', op '=' [124] */ + char_ptr = int_ptr; +} Index: src/tests/usr.bin/xlint/lint1/t_usage.sh diff -u src/tests/usr.bin/xlint/lint1/t_usage.sh:1.19 src/tests/usr.bin/xlint/lint1/t_usage.sh:1.20 --- src/tests/usr.bin/xlint/lint1/t_usage.sh:1.19 Sat Mar 30 17:23:13 2024 +++ src/tests/usr.bin/xlint/lint1/t_usage.sh Sat Apr 27 10:08:54 2024 @@ -1,4 +1,4 @@ -# $NetBSD: t_usage.sh,v 1.19 2024/03/30 17:23:13 rillig Exp $ +# $NetBSD: t_usage.sh,v 1.20 2024/04/27 10:08:54 rillig Exp $ # # Copyright (c) 2023 The NetBSD Foundation, Inc. # All rights reserved. @@ -89,13 +89,13 @@ enable_queries_body() # The largest known query. atf_check \ - "$lint1" -q 19 code.c /dev/null + "$lint1" -q 20 code.c /dev/null # Larger than the largest known query. atf_check \ -s 'exit:1' \ - -e "inline:lint1: invalid query ID '20'\n" \ - "$lint1" -q 20 code.c /dev/null + -e "inline:lint1: invalid query ID '21'\n" \ + "$lint1" -q 21 code.c /dev/null # Whitespace is not allowed before a query ID. atf_check \ Index: src/usr.bin/xlint/lint1/err.c diff -u src/usr.bin/xlint/lint1/err.c:1.240 src/usr.bin/xlint/lint1/err.c:1.241 --- src/usr.bin/xlint/lint1/err.c:1.240 Fri Apr 12 05:17:48 2024 +++ src/usr.bin/xlint/lint1/err.c Sat Apr 27 10:08:54 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: err.c,v 1.240 2024/04/12 05:17:48 rillig Exp $ */ +/* $NetBSD: err.c,v 1.241 2024/04/27 10:08:54 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) -__RCSID("$NetBSD: err.c,v 1.240 2024/04/12 05:17:48 rillig Exp $"); +__RCSID("$NetBSD: err.c,v 1.241 2024/04/27 10:08:54 rillig Exp $"); #endif #include <limits.h> @@ -741,6 +741,7 @@ static const char *queries[] = { "invisible character U+%04X in %s", // Q17 "const automatic variable '%s'", // Q18 "implicit conversion from integer '%s' to floating point '%s'", // Q19 + "implicit narrowing conversion from void pointer to '%s'", // Q20 }; bool any_query_enabled; /* for optimizing non-query scenarios */ Index: src/usr.bin/xlint/lint1/tree.c diff -u src/usr.bin/xlint/lint1/tree.c:1.635 src/usr.bin/xlint/lint1/tree.c:1.636 --- src/usr.bin/xlint/lint1/tree.c:1.635 Fri Apr 12 05:44:38 2024 +++ src/usr.bin/xlint/lint1/tree.c Sat Apr 27 10:08:54 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: tree.c,v 1.635 2024/04/12 05:44:38 rillig Exp $ */ +/* $NetBSD: tree.c,v 1.636 2024/04/27 10:08:54 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) -__RCSID("$NetBSD: tree.c,v 1.635 2024/04/12 05:44:38 rillig Exp $"); +__RCSID("$NetBSD: tree.c,v 1.636 2024/04/27 10:08:54 rillig Exp $"); #endif #include <float.h> @@ -1432,6 +1432,12 @@ build_assignment(op_t op, bool sys, tnod rt = lt; } + if (is_query_enabled[20] + && lt == PTR && ln->tn_type->t_subt->t_tspec != VOID + && rt == PTR && rn->tn_type->t_subt->t_tspec == VOID) + /* implicit narrowing conversion from void ... */ + query_message(20, type_name(ln->tn_type)); + if (any_query_enabled && rn->tn_op == CVT && rn->tn_cast && types_compatible(ln->tn_type, rn->tn_type, false, false, NULL) && is_cast_redundant(rn)) {