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: make messages for incompatible poi...



details:   https://anonhg.NetBSD.org/src/rev/cb540883429f
branches:  trunk
changeset: 953160:cb540883429f
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Feb 28 01:06:57 2021 +0000

description:
lint: make messages for incompatible pointers more specific

Message 153 didn't state obviously which of the pointer types was the
one before conversion (or cast) and which was the resulting type.

Message 229 didn't have any type information at all.

diffstat:

 tests/usr.bin/xlint/lint1/msg_153.c   |  17 ++++++++++++-----
 tests/usr.bin/xlint/lint1/msg_153.exp |   3 ++-
 tests/usr.bin/xlint/lint1/msg_229.c   |  12 +++++++++---
 tests/usr.bin/xlint/lint1/msg_229.exp |   3 ++-
 usr.bin/xlint/lint1/err.c             |   8 ++++----
 usr.bin/xlint/lint1/tree.c            |  16 ++++++++--------
 6 files changed, 37 insertions(+), 22 deletions(-)

diffs (158 lines):

diff -r 684b707b8f09 -r cb540883429f tests/usr.bin/xlint/lint1/msg_153.c
--- a/tests/usr.bin/xlint/lint1/msg_153.c       Sun Feb 28 00:52:16 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_153.c       Sun Feb 28 01:06:57 2021 +0000
@@ -1,15 +1,22 @@
-/*     $NetBSD: msg_153.c,v 1.3 2021/02/28 00:52:16 rillig Exp $       */
+/*     $NetBSD: msg_153.c,v 1.4 2021/02/28 01:06:57 rillig Exp $       */
 # 3 "msg_153.c"
 
-// Test for message: argument has incompatible pointer type, arg #%d (%s != %s) [153]
+// Test for message: converting '%s' to incompatible '%s' for argument %d [153]
 
 
 typedef double (*unary_operator)(double);
 
-void sink_unary_operator(unary_operator);
+void sink_function_pointer(unary_operator);
+void sink_int_pointer(int *);
 
 void
-example(int x)
+to_function_pointer(int *x)
 {
-       sink_unary_operator(&x);
+       sink_function_pointer(x);
 }
+
+void
+to_int_pointer(unary_operator op)
+{
+       sink_int_pointer(op);
+}
diff -r 684b707b8f09 -r cb540883429f tests/usr.bin/xlint/lint1/msg_153.exp
--- a/tests/usr.bin/xlint/lint1/msg_153.exp     Sun Feb 28 00:52:16 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_153.exp     Sun Feb 28 01:06:57 2021 +0000
@@ -1,1 +1,2 @@
-msg_153.c(14): warning: argument has incompatible pointer type, arg #1 (pointer to function(double) returning double != pointer to int) [153]
+msg_153.c(15): warning: converting 'pointer to int' to incompatible 'pointer to function(double) returning double' for argument 1 [153]
+msg_153.c(21): warning: converting 'pointer to function(double) returning double' to incompatible 'pointer to int' for argument 1 [153]
diff -r 684b707b8f09 -r cb540883429f tests/usr.bin/xlint/lint1/msg_229.c
--- a/tests/usr.bin/xlint/lint1/msg_229.c       Sun Feb 28 00:52:16 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_229.c       Sun Feb 28 01:06:57 2021 +0000
@@ -1,12 +1,18 @@
-/*     $NetBSD: msg_229.c,v 1.3 2021/02/28 00:52:16 rillig Exp $       */
+/*     $NetBSD: msg_229.c,v 1.4 2021/02/28 01:06:57 rillig Exp $       */
 # 3 "msg_229.c"
 
-// Test for message: questionable conversion of function pointer [229]
+// Test for message: converting '%s' to '%s' is questionable [229]
 
 typedef double (*unary_operator)(double);
 
 int *
-example(unary_operator op)
+to_int_pointer(unary_operator op)
 {
        return (int *)op;
 }
+
+unary_operator
+to_function_pointer(int *p)
+{
+       return (unary_operator)p;
+}
diff -r 684b707b8f09 -r cb540883429f tests/usr.bin/xlint/lint1/msg_229.exp
--- a/tests/usr.bin/xlint/lint1/msg_229.exp     Sun Feb 28 00:52:16 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_229.exp     Sun Feb 28 01:06:57 2021 +0000
@@ -1,1 +1,2 @@
-msg_229.c(11): warning: questionable conversion of function pointer [229]
+msg_229.c(11): warning: converting 'pointer to function(double) returning double' to 'pointer to int' is questionable [229]
+msg_229.c(17): warning: converting 'pointer to int' to 'pointer to function(double) returning double' is questionable [229]
diff -r 684b707b8f09 -r cb540883429f usr.bin/xlint/lint1/err.c
--- a/usr.bin/xlint/lint1/err.c Sun Feb 28 00:52:16 2021 +0000
+++ b/usr.bin/xlint/lint1/err.c Sun Feb 28 01:06:57 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: err.c,v 1.82 2021/02/28 00:40:22 rillig Exp $  */
+/*     $NetBSD: err.c,v 1.83 2021/02/28 01:06:57 rillig Exp $  */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: err.c,v 1.82 2021/02/28 00:40:22 rillig Exp $");
+__RCSID("$NetBSD: err.c,v 1.83 2021/02/28 01:06:57 rillig Exp $");
 #endif
 
 #include <sys/types.h>
@@ -212,7 +212,7 @@
        "argument mismatch: %d arg%s passed, %d expected",            /* 150 */
        "void expressions may not be arguments, arg #%d",             /* 151 */
        "argument cannot have unknown size, arg #%d",                 /* 152 */
-       "argument has incompatible pointer type, arg #%d (%s != %s)", /* 153 */
+       "converting '%s' to incompatible '%s' for argument %d",       /* 153 */
        "illegal combination of %s (%s) and %s (%s), arg #%d",        /* 154 */
        "argument is incompatible with prototype, arg #%d",           /* 155 */
        "enum type mismatch, arg #%d (%s != %s)",                     /* 156 */
@@ -288,7 +288,7 @@
        "static variable %s unused",                                  /* 226 */
        "const object %s should have initializer",                    /* 227 */
        "function cannot return const or volatile object",            /* 228 */
-       "questionable conversion of function pointer",                /* 229 */
+       "converting '%s' to '%s' is questionable",                    /* 229 */
        "nonportable character comparison, op %s",                    /* 230 */
        "argument %s unused in function %s",                          /* 231 */
        "label %s unused in function %s",                             /* 232 */
diff -r 684b707b8f09 -r cb540883429f usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Sun Feb 28 00:52:16 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Sun Feb 28 01:06:57 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.222 2021/02/28 00:40:22 rillig Exp $        */
+/*     $NetBSD: tree.c,v 1.223 2021/02/28 01:06:57 rillig Exp $        */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tree.c,v 1.222 2021/02/28 00:40:22 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.223 2021/02/28 01:06:57 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -1597,9 +1597,9 @@
                                warning(182, type_name(lstp), type_name(rstp));
                                break;
                        case FARG:
-                               /* argument has incompatible pointer type... */
+                               /* converting '%s' to incompatible '%s' ... */
                                warning(153,
-                                   arg, type_name(lstp), type_name(rstp));
+                                   type_name(rtp), type_name(ltp), arg);
                                break;
                        default:
                                /* operands have incompatible pointer type... */
@@ -1642,8 +1642,8 @@
                        warn_incompatible_pointers(NULL, ltp, rtp);
                        break;
                case FARG:
-                       /* arg. has incomp. pointer type, arg #%d (%s != %s) */
-                       warning(153, arg, type_name(ltp), type_name(rtp));
+                       /* converting '%s' to incompatible '%s' for ... */
+                       warning(153, type_name(rtp), type_name(ltp), arg);
                        break;
                default:
                        warn_incompatible_pointers(mp, ltp, rtp);
@@ -2238,8 +2238,8 @@
        } else if (nt == FUNC && ot == FUNC) {
                return;
        } else if (nt == FUNC || ot == FUNC) {
-               /* questionable conversion of function pointer */
-               warning(229);
+               /* converting '%s' to '%s' is questionable */
+               warning(229, type_name(tn->tn_type), type_name(tp));
                return;
        }
 



Home | Main Index | Thread Index | Old Index