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: fix the result type of '?:' for vo...



details:   https://anonhg.NetBSD.org/src/rev/ede0434ff8a4
branches:  trunk
changeset: 372911:ede0434ff8a4
user:      rillig <rillig%NetBSD.org@localhost>
date:      Wed Jan 04 05:08:22 2023 +0000

description:
lint: fix the result type of '?:' for void pointers

The change from 2015-07-29 was wrong since that rule only applies to
null pointer constants but not to other void pointers.

diffstat:

 tests/usr.bin/xlint/lint1/op_colon.c |  24 +++++++++---------------
 usr.bin/xlint/lint1/tree.c           |  17 +++++++++--------
 2 files changed, 18 insertions(+), 23 deletions(-)

diffs (111 lines):

diff -r b5571a91b15b -r ede0434ff8a4 tests/usr.bin/xlint/lint1/op_colon.c
--- a/tests/usr.bin/xlint/lint1/op_colon.c      Wed Jan 04 03:33:54 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/op_colon.c      Wed Jan 04 05:08:22 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: op_colon.c,v 1.4 2023/01/03 22:02:20 rillig Exp $      */
+/*     $NetBSD: op_colon.c,v 1.5 2023/01/04 05:08:22 rillig Exp $      */
 # 3 "op_colon.c"
 
 /*
@@ -7,12 +7,12 @@
 
 /* lint1-extra-flags: -p */
 
-struct unknown {
+struct canary {
        int member;
 };
 
 void
-sink(struct unknown *);
+sink(struct canary);
 
 void
 test_merge_qualifiers(_Bool cond, int *p, const int *c, volatile int *v,
@@ -66,10 +66,8 @@
     const char *c_cp
 )
 {
-       /* FIXME: expect+2: ... 'pointer to const void' ... */
-       /* FIXME: expect+2: ... 'pointer to const void' ... */
-       /* expect+2: ... 'pointer to const int' ... */
-       /* expect+2: ... 'pointer to const int' ... */
+       /* expect+2: ... 'pointer to const void' ... */
+       /* expect+2: ... 'pointer to const void' ... */
        sink(cond ? c_vp : c_ip);
        sink(cond ? c_ip : c_vp);
 
@@ -83,10 +81,8 @@
        sink(cond ? c_ip : v_ip);
        sink(cond ? v_ip : c_ip);
 
-       /* FIXME: expect+2: ... 'pointer to const void' ... */
-       /* FIXME: expect+2: ... 'pointer to const void' ... */
-       /* expect+2: ... 'pointer to const char' ... */
-       /* expect+2: ... 'pointer to const char' ... */
+       /* expect+2: ... 'pointer to const void' ... */
+       /* expect+2: ... 'pointer to const void' ... */
        sink(cond ? vp : c_cp);
        sink(cond ? c_cp : vp);
 
@@ -95,10 +91,8 @@
        sink(cond ? ip : c_ip);
        sink(cond ? c_ip : ip);
 
-       /* FIXME: expect+2: ... 'pointer to void' ... */
-       /* FIXME: expect+2: ... 'pointer to void' ... */
-       /* expect+2: ... 'pointer to int' ... */
-       /* expect+2: ... 'pointer to int' ... */
+       /* expect+2: ... 'pointer to void' ... */
+       /* expect+2: ... 'pointer to void' ... */
        sink(cond ? vp : ip);
        sink(cond ? ip : vp);
 }
diff -r b5571a91b15b -r ede0434ff8a4 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Wed Jan 04 03:33:54 2023 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Wed Jan 04 05:08:22 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.485 2023/01/03 21:14:14 rillig Exp $        */
+/*     $NetBSD: tree.c,v 1.486 2023/01/04 05:08: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.485 2023/01/03 21:14:14 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.486 2023/01/04 05:08:22 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -3303,11 +3303,8 @@
        lt = ln->tn_type->t_tspec;
        rt = rn->tn_type->t_tspec;
 
-       /*
-        * Arithmetic types are balanced, all other type combinations
-        * still need to be handled.
-        */
        if (is_arithmetic(lt) && is_arithmetic(rt)) {
+               /* The operands were already balanced in build_binary. */
                tp = ln->tn_type;
        } else if (lt == BOOL && rt == BOOL) {
                tp = ln->tn_type;
@@ -3331,10 +3328,14 @@
                if (lt != PTRDIFF_TSPEC)
                        ln = convert(NOOP, 0, gettyp(PTRDIFF_TSPEC), ln);
                tp = rn->tn_type;
-       } else if (lt == PTR && ln->tn_type->t_subt->t_tspec == VOID) {
+       } else if (lt == PTR && is_null_pointer(rn)) {
+               tp = merge_qualifiers(ln->tn_type, rn->tn_type);
+       } else if (rt == PTR && is_null_pointer(ln)) {
                tp = merge_qualifiers(rn->tn_type, ln->tn_type);
+       } else if (lt == PTR && ln->tn_type->t_subt->t_tspec == VOID) {
+               tp = merge_qualifiers(ln->tn_type, rn->tn_type);
        } else if (rt == PTR && rn->tn_type->t_subt->t_tspec == VOID) {
-               tp = merge_qualifiers(ln->tn_type, rn->tn_type);
+               tp = merge_qualifiers(rn->tn_type, ln->tn_type);
        } else {
                /*
                 * XXX For now we simply take the left type. This is



Home | Main Index | Thread Index | Old Index