lint: fix wrong warning about out-of-range value '\xff' for char

This only affects platforms where char has the same representation as
unsigned char.
This commit is contained in:
rillig 2021-06-29 21:33:08 +00:00
parent 731d783606
commit 95d33e8c9b
5 changed files with 15 additions and 14 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: mi,v 1.1069 2021/06/29 13:58:13 rillig Exp $
# $NetBSD: mi,v 1.1070 2021/06/29 21:33:08 rillig Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@ -6205,7 +6205,7 @@
./usr/tests/usr.bin/xlint/lint1/emit.c tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/emit.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/emit.exp-ln tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/emit.ln obsolete obsolete
./usr/tests/usr.bin/xlint/lint1/emit.ln tests-obsolete obsolete
./usr/tests/usr.bin/xlint/lint1/expr_range.c tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/expr_range.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/feat_stacktrace.c tests-usr.bin-tests compattestfile,atf
@ -6223,7 +6223,7 @@
./usr/tests/usr.bin/xlint/lint1/lex_char.c tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/lex_char.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/lex_char_uchar.c tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/lex_char_uchar.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/lex_char_uchar.exp tests-obsolete obsolete
./usr/tests/usr.bin/xlint/lint1/lex_comment.c tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/lex_comment.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/lex_floating.c tests-usr.bin-tests compattestfile,atf

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.71 2021/06/29 13:58:13 rillig Exp $
# $NetBSD: Makefile,v 1.72 2021/06/29 21:33:09 rillig Exp $
NOMAN= # defined
MAX_MESSAGE= 345 # see lint1/err.c
@ -126,7 +126,6 @@ FILES+= gcc_typeof_after_statement.exp
FILES+= lex_char.c
FILES+= lex_char.exp
FILES+= lex_char_uchar.c
FILES+= lex_char_uchar.exp
FILES+= lex_comment.c
FILES+= lex_comment.exp
FILES+= lex_floating.c

View File

@ -1,4 +1,4 @@
/* $NetBSD: lex_char_uchar.c,v 1.2 2021/06/29 14:19:51 rillig Exp $ */
/* $NetBSD: lex_char_uchar.c,v 1.3 2021/06/29 21:33:09 rillig Exp $ */
# 3 "lex_char_uchar.c"
/*
@ -9,9 +9,11 @@
/* lint1-only-if uchar */
/*
* FIXME: The warning is bogus; it must be possible to initialize a char
* variable with a character constant.
* See tree.c, function convert_constant.
* Before inittyp.c 1.23 from 2021-06-29, the following initialization
* triggered a wrong warning "conversion of 'int' to 'char' is out of range",
* but only on platforms where char has the same representation as unsigned
* char. There are only few of these platforms, which allowed this bug to
* survive for almost 26 years, since the initial commit of lint on
* 1995-07-03.
*/
/* expect+1: conversion of 'int' to 'char' is out of range [119] */
char ch = '\xff';

View File

@ -1 +0,0 @@
lex_char_uchar.c(17): warning: conversion of 'int' to 'char' is out of range [119]

View File

@ -1,4 +1,4 @@
/* $NetBSD: inittyp.c,v 1.22 2021/03/27 11:08:00 rillig Exp $ */
/* $NetBSD: inittyp.c,v 1.23 2021/06/29 21:33:09 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: inittyp.c,v 1.22 2021/03/27 11:08:00 rillig Exp $");
__RCSID("$NetBSD: inittyp.c,v 1.23 2021/06/29 21:33:09 rillig Exp $");
#endif
#include <limits.h>
@ -77,7 +77,8 @@ inittyp(void)
typeinfo(BOOL, BOOL, BOOL, CHAR_SIZE, 1,
1, 1, 0, 1, 1, 0, "_Bool"),
typeinfo(CHAR, SCHAR, UCHAR, CHAR_SIZE, 8,
1, 0, 0, 1, 1, 0, "char"),
1, /*CONSTCOND*/ TARG_CHAR_MIN == 0 ? 1 : 0,
/* */ 0, 1, 1, 0, "char"),
typeinfo(SCHAR, SCHAR, UCHAR, CHAR_SIZE, 8,
1, 0, 0, 1, 1, 0, "signed char"),
typeinfo(UCHAR, SCHAR, UCHAR, CHAR_SIZE, 8,