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 conversion of non-constant sca...



details:   https://anonhg.NetBSD.org/src/rev/aa1c542d29db
branches:  trunk
changeset: 949349:aa1c542d29db
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Jan 10 12:46:38 2021 +0000

description:
lint: fix conversion of non-constant scalar to _Bool

diffstat:

 tests/usr.bin/xlint/lint1/d_c99_bool.c   |  10 +++++-----
 tests/usr.bin/xlint/lint1/d_c99_bool.exp |   4 ----
 usr.bin/xlint/lint1/tree.c               |  13 ++++++++-----
 3 files changed, 13 insertions(+), 14 deletions(-)

diffs (103 lines):

diff -r 2e970371b7b8 -r aa1c542d29db tests/usr.bin/xlint/lint1/d_c99_bool.c
--- a/tests/usr.bin/xlint/lint1/d_c99_bool.c    Sun Jan 10 12:38:40 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_bool.c    Sun Jan 10 12:46:38 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: d_c99_bool.c,v 1.3 2021/01/10 12:34:56 rillig Exp $    */
+/*     $NetBSD: d_c99_bool.c,v 1.4 2021/01/10 12:46:38 rillig Exp $    */
 # 3 "d_bool.c"
 
 /*
@@ -26,8 +26,8 @@
 int null_pointer_converts_to_false[(_Bool)(void *)0 ? -1 : 1];
 int null_pointer_converts_to_true_[(_Bool)(void *)0 ? 1 : -1];
 
-int nonnull_pointer_converts_to_false[(_Bool)"not null" ? -1 : 1]; // FIXME 133
-int nonnull_pointer_converts_to_true_[(_Bool)"not null" ? 1 : -1]; // FIXME 133
+int nonnull_pointer_converts_to_false[(_Bool)"not null" ? -1 : 1];
+int nonnull_pointer_converts_to_true_[(_Bool)"not null" ? 1 : -1];
 
 int double_minus_1_0_converts_to_false[(_Bool)-1.0 ? -1 : 1];
 int double_minus_1_0_converts_to_true_[(_Bool)-1.0 ? 1 : -1];
@@ -85,13 +85,13 @@
 _Bool
 pointer_to_bool(const char *p)
 {
-       return p; // FIXME 183
+       return p;
 }
 
 _Bool
 function_pointer_to_bool(void (*f)(void))
 {
-       return f; // FIXME 183
+       return f;
 }
 
 _Bool
diff -r 2e970371b7b8 -r aa1c542d29db tests/usr.bin/xlint/lint1/d_c99_bool.exp
--- a/tests/usr.bin/xlint/lint1/d_c99_bool.exp  Sun Jan 10 12:38:40 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_bool.exp  Sun Jan 10 12:46:38 2021 +0000
@@ -3,13 +3,9 @@
 d_bool.c(20): negative array dimension (-1) [20]
 d_bool.c(23): negative array dimension (-1) [20]
 d_bool.c(27): negative array dimension (-1) [20]
-d_bool.c(29): warning: conversion of pointer to '_Bool' loses bits [133]
-d_bool.c(30): warning: conversion of pointer to '_Bool' loses bits [133]
 d_bool.c(32): negative array dimension (-1) [20]
 d_bool.c(35): negative array dimension (-1) [20]
 d_bool.c(39): negative array dimension (-1) [20]
 d_bool.c(42): negative array dimension (-1) [20]
 d_bool.c(45): negative array dimension (-1) [20]
 d_bool.c(48): negative array dimension (-1) [20]
-d_bool.c(88): warning: illegal combination of integer (_Bool) and pointer (pointer to const char) [183]
-d_bool.c(94): warning: illegal combination of integer (_Bool) and pointer (pointer to function() returning void) [183]
diff -r 2e970371b7b8 -r aa1c542d29db usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Sun Jan 10 12:38:40 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Sun Jan 10 12:46:38 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.147 2021/01/10 12:34:56 rillig Exp $        */
+/*     $NetBSD: tree.c,v 1.148 2021/01/10 12:46:38 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.147 2021/01/10 12:34:56 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.148 2021/01/10 12:46:38 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -1296,6 +1296,9 @@
                rst = (rstp = rtp->t_subt)->t_tspec;
        mp = &modtab[op];
 
+       if (lt == BOOL && is_scalar(rt))        /* C99 6.3.1.2 */
+               return 1;
+
        if (is_arithmetic(lt) && is_arithmetic(rt))
                return 1;
 
@@ -1787,7 +1790,7 @@
                                 is_integer(ot)) && tn->tn_op == CON &&
                   tn->tn_val->v_quad == 0) {
                /* 0, 0L and (void *)0 may be assigned to any pointer. */
-       } else if (is_integer(nt) && ot == PTR) {
+       } else if (is_integer(nt) && nt != BOOL && ot == PTR) {
                check_pointer_integer_conversion(op, nt, tp, tn);
        } else if (nt == PTR && ot == PTR) {
                check_pointer_conversion(op, tn, tp);
@@ -1948,10 +1951,10 @@
 
        if (psize(nt) < psize(PTR)) {
                if (pflag && size(nt) >= size(PTR)) {
-                       /* conv. of pointer to '%s' may lose bits */
+                       /* conversion of pointer to '%s' may lose bits */
                        warning(134, type_name(tp));
                } else {
-                       /* conv. of pointer to '%s' loses bits */
+                       /* conversion of pointer to '%s' loses bits */
                        warning(133, type_name(tp));
                }
        }



Home | Main Index | Thread Index | Old Index