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 constant express...
details: https://anonhg.NetBSD.org/src/rev/89ed857e262e
branches: trunk
changeset: 958551:89ed857e262e
user: rillig <rillig%NetBSD.org@localhost>
date: Sun Jan 10 12:34:56 2021 +0000
description:
lint: fix conversion of constant expressions to _Bool
diffstat:
tests/usr.bin/xlint/lint1/d_c99_bool.c | 18 +++++++++---------
tests/usr.bin/xlint/lint1/d_c99_bool.exp | 12 ++++--------
usr.bin/xlint/lint1/tree.c | 14 ++++++++++----
3 files changed, 23 insertions(+), 21 deletions(-)
diffs (111 lines):
diff -r d6d9de790763 -r 89ed857e262e tests/usr.bin/xlint/lint1/d_c99_bool.c
--- a/tests/usr.bin/xlint/lint1/d_c99_bool.c Sun Jan 10 12:29:46 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_bool.c Sun Jan 10 12:34:56 2021 +0000
@@ -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_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 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_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];
diff -r d6d9de790763 -r 89ed857e262e tests/usr.bin/xlint/lint1/d_c99_bool.exp
--- a/tests/usr.bin/xlint/lint1/d_c99_bool.exp Sun Jan 10 12:29:46 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_bool.exp Sun Jan 10 12:34:56 2021 +0000
@@ -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]
diff -r d6d9de790763 -r 89ed857e262e usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c Sun Jan 10 12:29:46 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c Sun Jan 10 12:34:56 2021 +0000
@@ -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 @@
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:
Home |
Main Index |
Thread Index |
Old Index