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: document bug in typeok_eq



details:   https://anonhg.NetBSD.org/src/rev/5c491d828b97
branches:  trunk
changeset: 980107:5c491d828b97
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Jan 24 10:50:42 2021 +0000

description:
lint: document bug in typeok_eq

Since rt is an alias for rn->tn_type->t_tspec, it cannot be PTR and VOID
at the same time.  This makes the condition unsatisfiable.  Removing
that part of the code didn't show any change in behavior, as expected.

It may even be that fixing this obvious bug doesn't show any change in
behavior since that function is only used in a single place and
check_pointer_comparison performs its own checks before issuing any
warning.

At least the test cases added to msg_124.c all run as expected.

diffstat:

 tests/usr.bin/xlint/lint1/msg_124.c   |  34 ++++++++++++++++++++++++++++++----
 tests/usr.bin/xlint/lint1/msg_124.exp |   2 ++
 usr.bin/xlint/lint1/tree.c            |   6 ++++--
 3 files changed, 36 insertions(+), 6 deletions(-)

diffs (87 lines):

diff -r 30f52bd5cfec -r 5c491d828b97 tests/usr.bin/xlint/lint1/msg_124.c
--- a/tests/usr.bin/xlint/lint1/msg_124.c       Sun Jan 24 09:44:35 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_124.c       Sun Jan 24 10:50:42 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_124.c,v 1.2 2021/01/03 15:44:35 rillig Exp $       */
+/*     $NetBSD: msg_124.c,v 1.3 2021/01/24 10:50:42 rillig Exp $       */
 # 3 "msg_124.c"
 
 // Test for message: illegal pointer combination, op %s [124]
@@ -13,7 +13,33 @@
 void
 example(int *ptr)
 {
-       signal_handler handler = ptr;
-       sys_signal signal = ptr;
-       printflike printf = ptr;
+       signal_handler handler = ptr;   /* expect: 124 */
+       sys_signal signal = ptr;        /* expect: 124 */
+       printflike printf = ptr;        /* expect: 124 */
 }
+
+void ok(_Bool);
+void not_ok(_Bool);
+
+void
+compare_pointers(const void *vp, const char *cp, const int *ip,
+                signal_handler fp)
+{
+       ok(vp == cp);
+       ok(vp == ip);
+       ok(vp == fp);
+       not_ok(cp == ip);       /* expect: 124 */
+       not_ok(cp == fp);       /* expect: 124 */
+       ok(vp == (void *)0);
+       ok(cp == (void *)0);
+       ok(ip == (void *)0);
+       ok(fp == (void *)0);
+       ok(vp == 0);
+       ok(cp == 0);
+       ok(ip == 0);
+       ok(fp == 0);
+       ok(vp == 0L);
+       ok(cp == 0L);
+       ok(ip == 0L);
+       ok(fp == 0L);
+}
diff -r 30f52bd5cfec -r 5c491d828b97 tests/usr.bin/xlint/lint1/msg_124.exp
--- a/tests/usr.bin/xlint/lint1/msg_124.exp     Sun Jan 24 09:44:35 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_124.exp     Sun Jan 24 10:50:42 2021 +0000
@@ -1,3 +1,5 @@
 msg_124.c(16): warning: illegal pointer combination (pointer to function(int) returning void) and (pointer to int), op = [124]
 msg_124.c(17): warning: illegal pointer combination (pointer to function(pointer to function(int) returning void) returning pointer to function(int) returning void) and (pointer to int), op = [124]
 msg_124.c(18): warning: illegal pointer combination (pointer to function(pointer to const char, ...) returning int) and (pointer to int), op = [124]
+msg_124.c(31): warning: illegal pointer combination (pointer to const char) and (pointer to const int), op == [124]
+msg_124.c(32): warning: illegal pointer combination (pointer to const char) and (pointer to function(int) returning void), op == [124]
diff -r 30f52bd5cfec -r 5c491d828b97 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Sun Jan 24 09:44:35 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Sun Jan 24 10:50:42 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.185 2021/01/24 00:15:20 rillig Exp $        */
+/*     $NetBSD: tree.c,v 1.186 2021/01/24 10:50:42 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.185 2021/01/24 00:15:20 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.186 2021/01/24 10:50:42 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -952,11 +952,13 @@
 static bool
 typeok_eq(const tnode_t *ln, tspec_t lt, const tnode_t *rn, tspec_t rt)
 {
+       /* FIXME: missing tn_subt */
        if (lt == PTR && ((rt == PTR && rn->tn_type->t_tspec == VOID) ||
                          is_integer(rt))) {
                if (rn->tn_op == CON && rn->tn_val->v_quad == 0)
                        return true;
        }
+       /* FIXME: missing tn_subt */
        if (rt == PTR && ((lt == PTR && ln->tn_type->t_tspec == VOID) ||
                          is_integer(lt))) {
                if (ln->tn_op == CON && ln->tn_val->v_quad == 0)



Home | Main Index | Thread Index | Old Index