Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/xlint/lint1 lint: add query for assigning an integer...



details:   https://anonhg.NetBSD.org/src/rev/e9b5989374e9
branches:  trunk
changeset: 377181:e9b5989374e9
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Jun 30 08:45:22 2023 +0000

description:
lint: add query for assigning an integer 0 to a pointer

diffstat:

 tests/usr.bin/xlint/lint1/queries.c  |  22 ++++++++++++++++++++--
 tests/usr.bin/xlint/lint1/t_usage.sh |   8 ++++----
 usr.bin/xlint/lint1/err.c            |   5 +++--
 usr.bin/xlint/lint1/tree.c           |  10 +++++++---
 4 files changed, 34 insertions(+), 11 deletions(-)

diffs (127 lines):

diff -r 263a3d89c6e6 -r e9b5989374e9 tests/usr.bin/xlint/lint1/queries.c
--- a/tests/usr.bin/xlint/lint1/queries.c       Fri Jun 30 08:03:01 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/queries.c       Fri Jun 30 08:45:22 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: queries.c,v 1.17 2023/06/24 08:11:12 rillig Exp $      */
+/*     $NetBSD: queries.c,v 1.18 2023/06/30 08:45:22 rillig Exp $      */
 # 3 "queries.c"
 
 /*
@@ -15,7 +15,7 @@
  *     such as casts between arithmetic types.
  */
 
-/* lint1-extra-flags: -q 1,2,3,4,5,6,7,8,9,10,11,12,13,14 -X 351 */
+/* lint1-extra-flags: -q 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 -X 351 */
 
 typedef unsigned char u8_t;
 typedef unsigned short u16_t;
@@ -423,6 +423,24 @@ Q14(char c, signed char sc, unsigned cha
        return 5;
 }
 
+void *
+Q15(void)
+{
+       /* expect+1: implicit conversion from integer 0 to pointer 'pointer to void' [Q15] */
+       void *ptr_from_int = 0;
+       /* expect+1: implicit conversion from integer 0 to pointer 'pointer to void' [Q15] */
+       void *ptr_from_uint = 0U;
+       /* expect+1: implicit conversion from integer 0 to pointer 'pointer to void' [Q15] */
+       void *ptr_from_long = 0L;
+
+       ptr_from_int = &ptr_from_int;
+       ptr_from_uint = &ptr_from_uint;
+       ptr_from_long = &ptr_from_long;
+
+       /* expect+1: implicit conversion from integer 0 to pointer 'pointer to void' [Q15] */
+       return 0;
+}
+
 /*
  * 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
diff -r 263a3d89c6e6 -r e9b5989374e9 tests/usr.bin/xlint/lint1/t_usage.sh
--- a/tests/usr.bin/xlint/lint1/t_usage.sh      Fri Jun 30 08:03:01 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/t_usage.sh      Fri Jun 30 08:45:22 2023 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: t_usage.sh,v 1.8 2023/06/28 09:35:42 rillig Exp $
+# $NetBSD: t_usage.sh,v 1.9 2023/06/30 08:45:22 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 14 code.c /dev/null
+           "$lint1" -q 15 code.c /dev/null
 
        # Larger than the largest known query.
        atf_check \
            -s 'exit:1' \
-           -e "inline:lint1: invalid query ID '15'\n" \
-           "$lint1" -q 15 code.c /dev/null
+           -e "inline:lint1: invalid query ID '16'\n" \
+           "$lint1" -q 16 code.c /dev/null
 
        # Whitespace is not allowed before a query ID.
        atf_check \
diff -r 263a3d89c6e6 -r e9b5989374e9 usr.bin/xlint/lint1/err.c
--- a/usr.bin/xlint/lint1/err.c Fri Jun 30 08:03:01 2023 +0000
+++ b/usr.bin/xlint/lint1/err.c Fri Jun 30 08:45:22 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: err.c,v 1.202 2023/06/24 08:11:12 rillig Exp $ */
+/*     $NetBSD: err.c,v 1.203 2023/06/30 08:45:22 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.202 2023/06/24 08:11:12 rillig Exp $");
+__RCSID("$NetBSD: err.c,v 1.203 2023/06/30 08:45:22 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -710,6 +710,7 @@ static const char *queries[] = {
        "comma operator with types '%s' and '%s'",                    /* Q12 */
        "redundant 'extern' in function declaration of '%s'",         /* Q13 */
        "comparison '%s' of 'char' with plain integer %d",            /* Q14 */
+       "implicit conversion from integer 0 to pointer '%s'",         /* Q15 */
 };
 
 bool any_query_enabled;                /* for optimizing non-query scenarios */
diff -r 263a3d89c6e6 -r e9b5989374e9 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Fri Jun 30 08:03:01 2023 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Fri Jun 30 08:45:22 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.532 2023/06/29 12:52:06 rillig Exp $        */
+/*     $NetBSD: tree.c,v 1.533 2023/06/30 08:45:22 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.532 2023/06/29 12:52:06 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.533 2023/06/30 08:45:22 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -2912,8 +2912,12 @@ check_assign_types_compatible(op_t op, i
                return ltp->t_sou == rtp->t_sou;
 
        /* a null pointer may be assigned to any pointer */
-       if (lt == PTR && is_null_pointer(rn))
+       if (lt == PTR && is_null_pointer(rn)) {
+               if (is_integer(rn->tn_type->t_tspec))
+                       /* implicit conversion from integer 0 to pointer ... */
+                       query_message(15, type_name(ltp));
                return true;
+       }
 
        check_assign_void_pointer(op, arg, lt, lst, rt, rst);
 



Home | Main Index | Thread Index | Old Index