Module Name:    src
Committed By:   rillig
Date:           Sun Jan 10 12:34:56 UTC 2021

Modified Files:
        src/tests/usr.bin/xlint/lint1: d_c99_bool.c d_c99_bool.exp
        src/usr.bin/xlint/lint1: tree.c

Log Message:
lint: fix conversion of constant expressions to _Bool


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/d_c99_bool.c \
    src/tests/usr.bin/xlint/lint1/d_c99_bool.exp
cvs rdiff -u -r1.146 -r1.147 src/usr.bin/xlint/lint1/tree.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/d_c99_bool.c
diff -u src/tests/usr.bin/xlint/lint1/d_c99_bool.c:1.2 src/tests/usr.bin/xlint/lint1/d_c99_bool.c:1.3
--- src/tests/usr.bin/xlint/lint1/d_c99_bool.c:1.2	Sun Jan 10 12:29:46 2021
+++ src/tests/usr.bin/xlint/lint1/d_c99_bool.c	Sun Jan 10 12:34:56 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: d_c99_bool.c,v 1.2 2021/01/10 12:29:46 rillig Exp $	*/
+/*	$NetBSD: d_c99_bool.c,v 1.3 2021/01/10 12:34:56 rillig Exp $	*/
 # 3 "d_bool.c"
 
 /*
@@ -20,8 +20,8 @@ int int_1_converts_to_true_[(_Bool)1 ? 1
 int int_2_converts_to_false[(_Bool)2 ? -1 : 1];
 int int_2_converts_to_true_[(_Bool)2 ? 1 : -1];
 
-int int_256_converts_to_false[(_Bool)256 ? -1 : 1]; // FIXME
-int int_256_converts_to_true_[(_Bool)256 ? 1 : -1]; // FIXME
+int int_256_converts_to_false[(_Bool)256 ? -1 : 1];
+int int_256_converts_to_true_[(_Bool)256 ? 1 : -1];
 
 int null_pointer_converts_to_false[(_Bool)(void *)0 ? -1 : 1];
 int null_pointer_converts_to_true_[(_Bool)(void *)0 ? 1 : -1];
@@ -29,11 +29,11 @@ int null_pointer_converts_to_true_[(_Boo
 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 double_minus_1_0_converts_to_false[(_Bool)-1.0 ? -1 : 1]; // FIXME 119
-int double_minus_1_0_converts_to_true_[(_Bool)-1.0 ? 1 : -1]; // FIXME 20, 119
+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];
 
-int double_minus_0_5_converts_to_false[(_Bool)-0.5 ? -1 : 1]; // FIXME 119
-int double_minus_0_5_converts_to_true_[(_Bool)-0.5 ? 1 : -1]; // FIXME 20, 119
+int double_minus_0_5_converts_to_false[(_Bool)-0.5 ? -1 : 1];
+int double_minus_0_5_converts_to_true_[(_Bool)-0.5 ? 1 : -1];
 
 int double_minus_0_0_converts_to_false[(_Bool)-0.0 ? -1 : 1];
 int double_minus_0_0_converts_to_true_[(_Bool)-0.0 ? 1 : -1];
@@ -42,8 +42,8 @@ int double_0_0_converts_to_false[(_Bool)
 int double_0_0_converts_to_true_[(_Bool)0.0 ? 1 : -1];
 
 /* The C99 rationale explains in 6.3.1.2 why (_Bool)0.5 is true. */
-int double_0_5_converts_to_false[(_Bool)0.5 ? -1 : 1]; // FIXME 20
-int double_0_5_converts_to_true_[(_Bool)0.5 ? 1 : -1]; // FIXME 20
+int double_0_5_converts_to_false[(_Bool)0.5 ? -1 : 1];
+int double_0_5_converts_to_true_[(_Bool)0.5 ? 1 : -1];
 
 int double_1_0_converts_to_false[(_Bool)1.0 ? -1 : 1];
 int double_1_0_converts_to_true_[(_Bool)1.0 ? 1 : -1];
Index: src/tests/usr.bin/xlint/lint1/d_c99_bool.exp
diff -u src/tests/usr.bin/xlint/lint1/d_c99_bool.exp:1.2 src/tests/usr.bin/xlint/lint1/d_c99_bool.exp:1.3
--- src/tests/usr.bin/xlint/lint1/d_c99_bool.exp:1.2	Sun Jan 10 12:29:46 2021
+++ src/tests/usr.bin/xlint/lint1/d_c99_bool.exp	Sun Jan 10 12:34:56 2021
@@ -1,19 +1,15 @@
 d_bool.c(15): negative array dimension (-1) [20]
 d_bool.c(17): negative array dimension (-1) [20]
 d_bool.c(20): negative array dimension (-1) [20]
-d_bool.c(24): 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): warning: conversion of 'double' to '_Bool' is out of range [119]
-d_bool.c(33): warning: conversion of 'double' to '_Bool' is out of range [119]
-d_bool.c(33): negative array dimension (-1) [20]
-d_bool.c(35): warning: conversion of 'double' to '_Bool' is out of range [119]
-d_bool.c(36): warning: conversion of 'double' to '_Bool' is out of range [119]
-d_bool.c(36): negative array dimension (-1) [20]
+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(46): 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]

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.146 src/usr.bin/xlint/lint1/tree.c:1.147
--- src/usr.bin/xlint/lint1/tree.c:1.146	Sun Jan 10 11:17:53 2021
+++ src/usr.bin/xlint/lint1/tree.c	Sun Jan 10 12:34:56 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.146 2021/01/10 11:17:53 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.147 2021/01/10 12:34:56 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.146 2021/01/10 11:17:53 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.147 2021/01/10 12:34:56 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -2030,10 +2030,16 @@ convert_constant(op_t op, int arg, type_
 	nt = nv->v_tspec = tp->t_tspec;
 	rchk = 0;
 
+	if (nt == BOOL) {	/* C99 6.3.1.2 */
+		nv->v_ansiu = 0;
+		nv->v_quad = ot == FLOAT || ot == DOUBLE || ot == LDOUBLE
+		    ? v->v_ldbl != 0.0
+		    : v->v_quad != 0;
+		return;
+	}
+
 	if (ot == FLOAT || ot == DOUBLE || ot == LDOUBLE) {
 		switch (nt) {
-		case BOOL:
-			max = 1;		min = 0;		break;
 		case CHAR:
 			max = TARG_CHAR_MAX;	min = TARG_CHAR_MIN;	break;
 		case UCHAR:

Reply via email to