Module Name:    src
Committed By:   rillig
Date:           Sun Mar 21 15:24:56 UTC 2021

Modified Files:
        src/tests/usr.bin/xlint/lint1: msg_130.c msg_130.exp msg_193.c
            msg_193.exp msg_217.c msg_217.exp
        src/usr.bin/xlint/lint1: func.c

Log Message:
lint: fix reachability for if-then-else statements


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/tests/usr.bin/xlint/lint1/msg_130.c
cvs rdiff -u -r1.9 -r1.10 src/tests/usr.bin/xlint/lint1/msg_130.exp
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/msg_193.c \
    src/tests/usr.bin/xlint/lint1/msg_193.exp
cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/xlint/lint1/msg_217.c
cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/xlint/lint1/msg_217.exp
cvs rdiff -u -r1.89 -r1.90 src/usr.bin/xlint/lint1/func.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/usr.bin/xlint/lint1/msg_130.c
diff -u src/tests/usr.bin/xlint/lint1/msg_130.c:1.11 src/tests/usr.bin/xlint/lint1/msg_130.c:1.12
--- src/tests/usr.bin/xlint/lint1/msg_130.c:1.11	Wed Mar 10 00:02:00 2021
+++ src/tests/usr.bin/xlint/lint1/msg_130.c	Sun Mar 21 15:24:56 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_130.c,v 1.11 2021/03/10 00:02:00 rillig Exp $	*/
+/*	$NetBSD: msg_130.c,v 1.12 2021/03/21 15:24:56 rillig Exp $	*/
 # 3 "msg_130.c"
 
 // Test for message: enum type mismatch: '%s' '%s' '%s' [130]
@@ -89,7 +89,7 @@ enum_constant_from_unnamed_type(int x)
 	if (sizeof_int == sizeof_uint)	/* expect: 130 *//* FIXME */
 		return 6;
 
-	return 0;
+	return 0;		/* expect: statement not reached */
 }
 
 /*

Index: src/tests/usr.bin/xlint/lint1/msg_130.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_130.exp:1.9 src/tests/usr.bin/xlint/lint1/msg_130.exp:1.10
--- src/tests/usr.bin/xlint/lint1/msg_130.exp:1.9	Wed Mar 10 00:02:00 2021
+++ src/tests/usr.bin/xlint/lint1/msg_130.exp	Sun Mar 21 15:24:56 2021
@@ -2,4 +2,5 @@ msg_130.c(29): warning: enum type mismat
 msg_130.c(31): warning: enum type mismatch: 'enum color' '!=' 'enum size' [130]
 msg_130.c(32): warning: enum type mismatch: 'enum color' '==' 'enum size' [130]
 msg_130.c(89): warning: enum type mismatch: 'enum <unnamed>' '==' 'enum <unnamed>' [130]
+msg_130.c(92): warning: statement not reached [193]
 msg_130.c(127): warning: enum type mismatch: 'enum <unnamed>' '==' 'enum <unnamed>' [130]

Index: src/tests/usr.bin/xlint/lint1/msg_193.c
diff -u src/tests/usr.bin/xlint/lint1/msg_193.c:1.4 src/tests/usr.bin/xlint/lint1/msg_193.c:1.5
--- src/tests/usr.bin/xlint/lint1/msg_193.c:1.4	Sun Mar 21 14:36:59 2021
+++ src/tests/usr.bin/xlint/lint1/msg_193.c	Sun Mar 21 15:24:56 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_193.c,v 1.4 2021/03/21 14:36:59 rillig Exp $	*/
+/*	$NetBSD: msg_193.c,v 1.5 2021/03/21 15:24:56 rillig Exp $	*/
 # 3 "msg_193.c"
 
 // Test for message: statement not reached [193]
@@ -140,7 +140,7 @@ test_if_return(void)
 {
 	if (1)
 		return;
-	unreachable();			/* TODO: expect: 193 */
+	unreachable();			/* expect: 193 */
 }
 
 void
Index: src/tests/usr.bin/xlint/lint1/msg_193.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_193.exp:1.4 src/tests/usr.bin/xlint/lint1/msg_193.exp:1.5
--- src/tests/usr.bin/xlint/lint1/msg_193.exp:1.4	Sun Mar 21 14:36:59 2021
+++ src/tests/usr.bin/xlint/lint1/msg_193.exp	Sun Mar 21 15:24:56 2021
@@ -10,6 +10,7 @@ msg_193.c(124): warning: statement not r
 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(143): 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]

Index: src/tests/usr.bin/xlint/lint1/msg_217.c
diff -u src/tests/usr.bin/xlint/lint1/msg_217.c:1.8 src/tests/usr.bin/xlint/lint1/msg_217.c:1.9
--- src/tests/usr.bin/xlint/lint1/msg_217.c:1.8	Sun Mar 21 14:36:59 2021
+++ src/tests/usr.bin/xlint/lint1/msg_217.c	Sun Mar 21 15:24:56 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_217.c,v 1.8 2021/03/21 14:36:59 rillig Exp $	*/
+/*	$NetBSD: msg_217.c,v 1.9 2021/03/21 15:24:56 rillig Exp $	*/
 # 3 "msg_217.c"
 
 // Test for message: function %s falls off bottom without returning value [217]
@@ -55,7 +55,7 @@ reachable_continue_leads_to_endless_loop
 			continue;
 		break;
 	}
-}				/* FIXME *//* expect: 217 */
+}
 
 int
 unreachable_continue_falls_through(void)

Index: src/tests/usr.bin/xlint/lint1/msg_217.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_217.exp:1.7 src/tests/usr.bin/xlint/lint1/msg_217.exp:1.8
--- src/tests/usr.bin/xlint/lint1/msg_217.exp:1.7	Sun Mar 21 14:36:59 2021
+++ src/tests/usr.bin/xlint/lint1/msg_217.exp	Sun Mar 21 15:24:56 2021
@@ -1,4 +1,3 @@
 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]

Index: src/usr.bin/xlint/lint1/func.c
diff -u src/usr.bin/xlint/lint1/func.c:1.89 src/usr.bin/xlint/lint1/func.c:1.90
--- src/usr.bin/xlint/lint1/func.c:1.89	Sun Mar 21 14:49:21 2021
+++ src/usr.bin/xlint/lint1/func.c	Sun Mar 21 15:24:55 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: func.c,v 1.89 2021/03/21 14:49:21 rillig Exp $	*/
+/*	$NetBSD: func.c,v 1.90 2021/03/21 15:24:55 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: func.c,v 1.89 2021/03/21 14:49:21 rillig Exp $");
+__RCSID("$NetBSD: func.c,v 1.90 2021/03/21 15:24:55 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -631,12 +631,13 @@ if2(void)
 void
 if3(bool els)
 {
-
-	if (els) {
-		reached |= cstmt->c_reached_end_of_then;
-	} else {
+	if (cstmt->c_reached_end_of_then)
 		reached = true;
-	}
+	else if (cstmt->c_always_then)
+		reached = false;
+	else if (!els)
+		reached = true;
+
 	popctrl(T_IF);
 }
 

Reply via email to