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 assertion failure when promoti...
details: https://anonhg.NetBSD.org/src/rev/03af1b41a938
branches: trunk
changeset: 379010:03af1b41a938
user: rillig <rillig%NetBSD.org@localhost>
date: Tue May 04 05:40:10 2021 +0000
description:
lint: fix assertion failure when promoting a bit-field larger than int
diffstat:
tests/usr.bin/xlint/lint1/gcc_bit_field_types.c | 5 ++---
usr.bin/xlint/lint1/tree.c | 23 ++++++++++-------------
2 files changed, 12 insertions(+), 16 deletions(-)
diffs (65 lines):
diff -r 5908bf93ca20 -r 03af1b41a938 tests/usr.bin/xlint/lint1/gcc_bit_field_types.c
--- a/tests/usr.bin/xlint/lint1/gcc_bit_field_types.c Tue May 04 05:32:52 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/gcc_bit_field_types.c Tue May 04 05:40:10 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: gcc_bit_field_types.c,v 1.4 2021/05/04 05:32:52 rillig Exp $ */
+/* $NetBSD: gcc_bit_field_types.c,v 1.5 2021/05/04 05:40:10 rillig Exp $ */
# 3 "gcc_bit_field_types.c"
/*
@@ -32,6 +32,5 @@ promote_large_bit_field(struct large_bit
* lint: assertion "len == size_in_bits(INT)" failed
* in promote at tree.c:1698
*/
- /* TODO: remove the cast since it hides an assertion failure */
- return (unsigned long long)lbf.member & 0xf;
+ return lbf.member & 0xf;
}
diff -r 5908bf93ca20 -r 03af1b41a938 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c Tue May 04 05:32:52 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c Tue May 04 05:40:10 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tree.c,v 1.280 2021/04/18 17:54:33 rillig Exp $ */
+/* $NetBSD: tree.c,v 1.281 2021/05/04 05:40:10 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.280 2021/04/18 17:54:33 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.281 2021/05/04 05:40:10 rillig Exp $");
#endif
#include <float.h>
@@ -1686,21 +1686,18 @@ promote(op_t op, bool farg, tnode_t *tn)
if (!tflag) {
/*
- * ANSI C requires that the result is always of type INT
- * if INT can represent all possible values of the previous
- * type.
+ * C99 6.3.1.1p2 requires for types with lower rank than int
+ * that "If an int can represent all the values of the
+ * original type, the value is converted to an int; otherwise
+ * it is converted to an unsigned int", and that "All other
+ * types are unchanged by the integer promotions".
*/
if (tn->tn_type->t_bitfield) {
len = tn->tn_type->t_flen;
- if (size_in_bits(INT) > len) {
+ if (len < size_in_bits(INT)) {
t = INT;
- } else {
- lint_assert(len == size_in_bits(INT));
- if (is_uinteger(t)) {
- t = UINT;
- } else {
- t = INT;
- }
+ } else if (len == size_in_bits(INT)) {
+ t = is_uinteger(t) ? UINT : INT;
}
} else if (t == CHAR || t == UCHAR || t == SCHAR) {
t = (size_in_bits(CHAR) < size_in_bits(INT)
Home |
Main Index |
Thread Index |
Old Index