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 reachability computation in if...



details:   https://anonhg.NetBSD.org/src/rev/e0ae19ea7be7
branches:  trunk
changeset: 960574:e0ae19ea7be7
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Mar 21 14:36:59 2021 +0000

description:
lint: fix reachability computation in if statements

Previously, only loop statements were considered for reachability.  This
ignored the possibility of an early return in an if statement, or
unreachable branches.

diffstat:

 tests/usr.bin/xlint/lint1/d_c99_bool_strict.c   |   4 +-
 tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp |   1 +
 tests/usr.bin/xlint/lint1/msg_193.c             |  48 ++++++++++++------------
 tests/usr.bin/xlint/lint1/msg_193.exp           |  22 +++++++++++
 tests/usr.bin/xlint/lint1/msg_217.c             |   4 +-
 tests/usr.bin/xlint/lint1/msg_217.exp           |   1 +
 tests/usr.bin/xlint/lint1/msg_333.c             |   4 +-
 tests/usr.bin/xlint/lint1/msg_333.exp           |   1 +
 usr.bin/xlint/lint1/func.c                      |  11 ++++-
 usr.bin/xlint/lint1/lint1.h                     |   5 +-
 10 files changed, 66 insertions(+), 35 deletions(-)

diffs (truncated from 391 to 300 lines):

diff -r 7ded7ac7b895 -r e0ae19ea7be7 tests/usr.bin/xlint/lint1/d_c99_bool_strict.c
--- a/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c     Sun Mar 21 14:12:46 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c     Sun Mar 21 14:36:59 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: d_c99_bool_strict.c,v 1.25 2021/03/21 14:12:46 rillig Exp $    */
+/*     $NetBSD: d_c99_bool_strict.c,v 1.26 2021/03/21 14:36:59 rillig Exp $    */
 # 3 "d_c99_bool_strict.c"
 
 /*
@@ -365,7 +365,7 @@
 strict_bool_controlling_expression(bool b, int i, double d, const void *p)
 {
        if (__lint_false)       /* expect: 161 */
-               do_nothing();
+               do_nothing();   /* expect: statement not reached */
 
        if (__lint_true)        /* expect: 161 */
                do_nothing();
diff -r 7ded7ac7b895 -r e0ae19ea7be7 tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp
--- a/tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp   Sun Mar 21 14:12:46 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp   Sun Mar 21 14:36:59 2021 +0000
@@ -55,6 +55,7 @@
 d_c99_bool_strict.c(355): operands of '=' have incompatible types (pointer != _Bool) [107]
 d_c99_bool_strict.c(345): warning: argument b unused in function strict_bool_conversion_from_bool_to_scalar [231]
 d_c99_bool_strict.c(367): warning: constant in conditional context [161]
+d_c99_bool_strict.c(368): warning: statement not reached [193]
 d_c99_bool_strict.c(370): warning: constant in conditional context [161]
 d_c99_bool_strict.c(376): controlling expression must be bool, not 'int' [333]
 d_c99_bool_strict.c(379): controlling expression must be bool, not 'int' [333]
diff -r 7ded7ac7b895 -r e0ae19ea7be7 tests/usr.bin/xlint/lint1/msg_193.c
--- a/tests/usr.bin/xlint/lint1/msg_193.c       Sun Mar 21 14:12:46 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_193.c       Sun Mar 21 14:36:59 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_193.c,v 1.3 2021/03/21 14:09:40 rillig Exp $       */
+/*     $NetBSD: msg_193.c,v 1.4 2021/03/21 14:36:59 rillig Exp $       */
 # 3 "msg_193.c"
 
 // Test for message: statement not reached [193]
@@ -52,7 +52,7 @@
                reachable();
        reachable();
        if (0)
-               unreachable();          /* TODO: expect: 193 */
+               unreachable();          /* expect: 193 */
        reachable();
 }
 
@@ -71,12 +71,12 @@
        }
 
        if (0) {
-               unreachable();          /* TODO: expect: 193 */
+               unreachable();          /* expect: 193 */
        }
        if (0) {
                {
                        {
-                               unreachable();  /* TODO: expect: 193 */
+                               unreachable();  /* expect: 193 */
                        }
                }
        }
@@ -90,7 +90,7 @@
        reachable();
 
        if (0)
-               unreachable();          /* TODO: expect: 193 */
+               unreachable();          /* expect: 193 */
        reachable();
 }
 
@@ -100,11 +100,11 @@
        if (1)
                reachable();
        else
-               unreachable();          /* TODO: expect: 193 */
+               unreachable();          /* expect: 193 */
        reachable();
 
        if (0)
-               unreachable();          /* TODO: expect: 193 */
+               unreachable();          /* expect: 193 */
        else
                reachable();
        reachable();
@@ -115,22 +115,22 @@
 {
        if (1)
                reachable();
-       else if (1)
-               unreachable();          /* TODO: expect: 193 */
+       else if (1)                     /* expect: 193 */
+               unreachable();
        else
-               unreachable();          /* TODO: expect: 193 */
+               unreachable();          /* expect: 193 */
 
        if (0)
-               unreachable();          /* TODO: expect: 193 */
+               unreachable();          /* expect: 193 */
        else if (1)
                reachable();
        else
-               unreachable();          /* TODO: expect: 193 */
+               unreachable();          /* expect: 193 */
 
        if (0)
-               unreachable();          /* TODO: expect: 193 */
+               unreachable();          /* expect: 193 */
        else if (0)
-               unreachable();          /* TODO: expect: 193 */
+               unreachable();          /* expect: 193 */
        else
                reachable();
 }
@@ -149,7 +149,7 @@
        if (1)
                reachable();
        else
-               return;
+               return;                 /* expect: 193 */
        reachable();
 }
 
@@ -194,7 +194,7 @@
        for (;;) {
                reachable();
                if (0) {
-                       unreachable();  /* TODO: expect: 193 */
+                       unreachable();  /* expect: 193 */
                        break;
                        unreachable();  /* expect: 193 */
                }
@@ -225,7 +225,7 @@
        for (;;) {
                reachable();
                if (0) {
-                       unreachable();  /* TODO: expect: 193 */
+                       unreachable();  /* expect: 193 */
                        continue;
                        unreachable();  /* expect: 193 */
                }
@@ -256,7 +256,7 @@
        for (;;) {
                reachable();
                if (0) {
-                       unreachable();  /* TODO: expect: 193 */
+                       unreachable();  /* expect: 193 */
                        return;
                        unreachable();  /* expect: 193 */
                }
@@ -303,7 +303,7 @@
        while (1) {
                reachable();
                if (0) {
-                       unreachable();  /* TODO: expect: 193 */
+                       unreachable();  /* expect: 193 */
                        break;
                        unreachable();  /* expect: 193 */
                }
@@ -334,7 +334,7 @@
        while (1) {
                reachable();
                if (0) {
-                       unreachable();  /* TODO: expect: 193 */
+                       unreachable();  /* expect: 193 */
                        continue;
                        unreachable();  /* expect: 193 */
                }
@@ -365,7 +365,7 @@
        while (1) {
                reachable();
                if (0) {
-                       unreachable();  /* TODO: expect: 193 */
+                       unreachable();  /* expect: 193 */
                        return;
                        unreachable();  /* expect: 193 */
                }
@@ -414,7 +414,7 @@
        do {
                reachable();
                if (0) {
-                       unreachable();  /* TODO: expect: 193 */
+                       unreachable();  /* expect: 193 */
                        break;
                        unreachable();  /* expect: 193 */
                }
@@ -445,7 +445,7 @@
        do {
                reachable();
                if (0) {
-                       unreachable();  /* TODO: expect: 193 */
+                       unreachable();  /* expect: 193 */
                        continue;
                        unreachable();  /* expect: 193 */
                }
@@ -476,7 +476,7 @@
        do {
                reachable();
                if (0) {
-                       unreachable();  /* TODO: expect: 193 */
+                       unreachable();  /* expect: 193 */
                        return;
                        unreachable();  /* expect: 193 */
                }
diff -r 7ded7ac7b895 -r e0ae19ea7be7 tests/usr.bin/xlint/lint1/msg_193.exp
--- a/tests/usr.bin/xlint/lint1/msg_193.exp     Sun Mar 21 14:12:46 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_193.exp     Sun Mar 21 14:36:59 2021 +0000
@@ -1,43 +1,65 @@
+msg_193.c(55): warning: statement not reached [193]
+msg_193.c(74): warning: statement not reached [193]
+msg_193.c(79): warning: statement not reached [193]
+msg_193.c(93): warning: statement not reached [193]
+msg_193.c(103): warning: statement not reached [193]
+msg_193.c(107): warning: statement not reached [193]
+msg_193.c(118): warning: statement not reached [193]
+msg_193.c(121): warning: statement not reached [193]
+msg_193.c(124): warning: statement not reached [193]
+msg_193.c(128): warning: statement not reached [193]
+msg_193.c(131): warning: statement not reached [193]
+msg_193.c(133): warning: statement not reached [193]
+msg_193.c(152): warning: statement not reached [193]
 msg_193.c(161): warning: statement not reached [193]
 msg_193.c(169): warning: statement not reached [193]
 msg_193.c(186): warning: statement not reached [193]
+msg_193.c(197): warning: statement not reached [193]
 msg_193.c(199): warning: statement not reached [193]
 msg_193.c(204): warning: statement not reached [193]
 msg_193.c(217): warning: statement not reached [193]
 msg_193.c(219): warning: statement not reached [193]
+msg_193.c(228): warning: statement not reached [193]
 msg_193.c(230): warning: statement not reached [193]
 msg_193.c(235): warning: statement not reached [193]
 msg_193.c(239): warning: statement not reached [193]
 msg_193.c(248): warning: statement not reached [193]
 msg_193.c(250): warning: statement not reached [193]
+msg_193.c(259): warning: statement not reached [193]
 msg_193.c(261): warning: statement not reached [193]
 msg_193.c(266): warning: statement not reached [193]
 msg_193.c(270): warning: statement not reached [193]
 msg_193.c(278): warning: statement not reached [193]
 msg_193.c(295): warning: statement not reached [193]
+msg_193.c(306): warning: statement not reached [193]
 msg_193.c(308): warning: statement not reached [193]
 msg_193.c(313): warning: statement not reached [193]
 msg_193.c(326): warning: statement not reached [193]
 msg_193.c(328): warning: statement not reached [193]
+msg_193.c(337): warning: statement not reached [193]
 msg_193.c(339): warning: statement not reached [193]
 msg_193.c(344): warning: statement not reached [193]
 msg_193.c(348): warning: statement not reached [193]
 msg_193.c(357): warning: statement not reached [193]
 msg_193.c(359): warning: statement not reached [193]
+msg_193.c(368): warning: statement not reached [193]
 msg_193.c(370): warning: statement not reached [193]
 msg_193.c(375): warning: statement not reached [193]
 msg_193.c(379): warning: statement not reached [193]
 msg_193.c(388): warning: statement not reached [193]
 msg_193.c(406): warning: statement not reached [193]
+msg_193.c(417): warning: statement not reached [193]
 msg_193.c(419): warning: statement not reached [193]
 msg_193.c(424): warning: statement not reached [193]
 msg_193.c(437): warning: statement not reached [193]
 msg_193.c(439): warning: statement not reached [193]
+msg_193.c(448): warning: statement not reached [193]
 msg_193.c(450): warning: statement not reached [193]
 msg_193.c(455): warning: statement not reached [193]
 msg_193.c(459): warning: statement not reached [193]
 msg_193.c(468): warning: statement not reached [193]
 msg_193.c(470): warning: statement not reached [193]
+msg_193.c(479): warning: statement not reached [193]
 msg_193.c(481): warning: statement not reached [193]
 msg_193.c(486): warning: statement not reached [193]
 msg_193.c(490): warning: statement not reached [193]
diff -r 7ded7ac7b895 -r e0ae19ea7be7 tests/usr.bin/xlint/lint1/msg_217.c
--- a/tests/usr.bin/xlint/lint1/msg_217.c       Sun Mar 21 14:12:46 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_217.c       Sun Mar 21 14:36:59 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_217.c,v 1.7 2021/03/21 12:19:36 rillig Exp $       */
+/*     $NetBSD: msg_217.c,v 1.8 2021/03/21 14:36:59 rillig Exp $       */
 # 3 "msg_217.c"
 
 // Test for message: function %s falls off bottom without returning value [217]
@@ -62,7 +62,7 @@
 {
        for (;;) {
                if (0)
-                       continue;
+                       continue; /* expect: statement not reached */
                break;
        }
 }                              /* expect: 217 */
diff -r 7ded7ac7b895 -r e0ae19ea7be7 tests/usr.bin/xlint/lint1/msg_217.exp
--- a/tests/usr.bin/xlint/lint1/msg_217.exp     Sun Mar 21 14:12:46 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_217.exp     Sun Mar 21 14:36:59 2021 +0000
@@ -1,3 +1,4 @@
 msg_217.c(11): warning: function random falls off bottom without returning value [217]
 msg_217.c(58): warning: function reachable_continue_leads_to_endless_loop falls off bottom without returning value [217]
+msg_217.c(65): warning: statement not reached [193]
 msg_217.c(68): warning: function unreachable_continue_falls_through falls off bottom without returning value [217]



Home | Main Index | Thread Index | Old Index