Module Name:    src
Committed By:   rillig
Date:           Tue May  4 05:40:10 UTC 2021

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

Log Message:
lint: fix assertion failure when promoting a bit-field larger than int


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/gcc_bit_field_types.c
cvs rdiff -u -r1.280 -r1.281 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/gcc_bit_field_types.c
diff -u src/tests/usr.bin/xlint/lint1/gcc_bit_field_types.c:1.4 src/tests/usr.bin/xlint/lint1/gcc_bit_field_types.c:1.5
--- src/tests/usr.bin/xlint/lint1/gcc_bit_field_types.c:1.4	Tue May  4 05:32:52 2021
+++ src/tests/usr.bin/xlint/lint1/gcc_bit_field_types.c	Tue May  4 05:40:10 2021
@@ -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;
 }

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.280 src/usr.bin/xlint/lint1/tree.c:1.281
--- src/usr.bin/xlint/lint1/tree.c:1.280	Sun Apr 18 17:54:33 2021
+++ src/usr.bin/xlint/lint1/tree.c	Tue May  4 05:40:10 2021
@@ -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)

Reply via email to