Module Name:    src
Committed By:   rillig
Date:           Wed Mar 27 20:09:44 UTC 2024

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

Log Message:
lint: clean up; extend overflow test


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/tests/usr.bin/xlint/lint1/msg_141.c
cvs rdiff -u -r1.93 -r1.94 src/usr.bin/xlint/lint1/emit1.c
cvs rdiff -u -r1.627 -r1.628 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/msg_141.c
diff -u src/tests/usr.bin/xlint/lint1/msg_141.c:1.16 src/tests/usr.bin/xlint/lint1/msg_141.c:1.17
--- src/tests/usr.bin/xlint/lint1/msg_141.c:1.16	Sun Mar 10 19:45:14 2024
+++ src/tests/usr.bin/xlint/lint1/msg_141.c	Wed Mar 27 20:09:43 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_141.c,v 1.16 2024/03/10 19:45:14 rillig Exp $	*/
+/*	$NetBSD: msg_141.c,v 1.17 2024/03/27 20:09:43 rillig Exp $	*/
 # 3 "msg_141.c"
 
 // Test for message: '%s' overflows '%s' [141]
@@ -12,6 +12,7 @@ signed int s32;
 unsigned int u32;
 signed long long s64;
 unsigned long long u64;
+_Bool cond;
 
 void
 compl_s32(void)
@@ -406,7 +407,16 @@ minus_s64(void)
 void
 minus_u64(void)
 {
-	// TODO
+	u64 = 0x0000000000000000ULL - 0x0000000000000000ULL;
+	/* expect+1: warning: '0 - 1' overflows 'unsigned long long' [141] */
+	u64 = 0x0000000000000000ULL - 0x0000000000000001ULL;
+	/* expect+1: warning: '0 - 9223372036854775808' overflows 'unsigned long long' [141] */
+	u64 = 0x0000000000000000ULL - 0x8000000000000000ULL;
+	u64 = 0x8000000000000000ULL - 0x0000000000000001ULL;
+	/* expect+1: warning: '0 - 18446744073709551615' overflows 'unsigned long long' [141] */
+	u64 = 0x0000000000000000ULL - 0xffffffffffffffffULL;
+	u64 = 0xffffffffffffffffULL - 0x0000000000000000ULL;
+	u64 = 0xffffffffffffffffULL - 0xffffffffffffffffULL;
 }
 
 void
@@ -439,13 +449,19 @@ shl_u32(void)
 void
 shl_s64(void)
 {
-	// TODO
+	s64 = 1LL << 62;
+	s64 = 1LL << 63;
+	/* expect+1: warning: shift amount 64 equals bit-size of 'long long' [267] */
+	s64 = 1LL << 64;
 }
 
 void
 shl_u64(void)
 {
-	// TODO
+	s64 = 1ULL << 62;
+	s64 = 1ULL << 63;
+	/* expect+1: warning: shift amount 64 equals bit-size of 'unsigned long long' [267] */
+	s64 = 1ULL << 64;
 }
 
 void
@@ -483,13 +499,13 @@ shr_s64(void)
 	// TODO
 
 	/* expect+1: error: negative array dimension (-16) [20] */
-	typedef int shr_minus_1_shr_0[-16LL >> 0];
+	typedef int minus_16_shr_0[-16LL >> 0];
 	/* expect+1: error: negative array dimension (-8) [20] */
-	typedef int shr_minus_1_shr_1[-16LL >> 1];
+	typedef int minus_16_shr_1[-16LL >> 1];
 	/* expect+1: error: negative array dimension (-1) [20] */
-	typedef int shr_minus_1_shr_16[-16LL >> 16];
+	typedef int minus_16_shr_16[-16LL >> 16];
 	/* expect+1: error: negative array dimension (-1) [20] */
-	typedef int shr_minus_1_shr_40[-16LL >> 40];
+	typedef int minus_16_shr_40[-16LL >> 40];
 }
 
 void
@@ -501,25 +517,45 @@ shr_u64(void)
 void
 compare_s32(void)
 {
-	// TODO
+	cond = 0x7fffffff <  (-0x7fffffff - 1);
+	cond = 0x7fffffff <= (-0x7fffffff - 1);
+	cond = 0x7fffffff >  (-0x7fffffff - 1);
+	cond = 0x7fffffff >= (-0x7fffffff - 1);
+	cond = 0x7fffffff == (-0x7fffffff - 1);
+	cond = 0x7fffffff != (-0x7fffffff - 1);
 }
 
 void
 compare_u32(void)
 {
-	// TODO
+	cond = 0xffffffffU <  0x00000000U;
+	cond = 0xffffffffU <= 0x00000000U;
+	cond = 0xffffffffU >  0x00000000U;
+	cond = 0xffffffffU >= 0x00000000U;
+	cond = 0xffffffffU == 0x00000000U;
+	cond = 0xffffffffU != 0x00000000U;
 }
 
 void
 compare_s64(void)
 {
-	// TODO
+	cond = 0x7fffffffffffffffLL <  (-0x7fffffffffffffffLL - 1);
+	cond = 0x7fffffffffffffffLL <= (-0x7fffffffffffffffLL - 1);
+	cond = 0x7fffffffffffffffLL >  (-0x7fffffffffffffffLL - 1);
+	cond = 0x7fffffffffffffffLL >= (-0x7fffffffffffffffLL - 1);
+	cond = 0x7fffffffffffffffLL == (-0x7fffffffffffffffLL - 1);
+	cond = 0x7fffffffffffffffLL != (-0x7fffffffffffffffLL - 1);
 }
 
 void
 compare_u64(void)
 {
-	// TODO
+	cond = 0xffffffffffffffffULL <  0x0000000000000000ULL;
+	cond = 0xffffffffffffffffULL <= 0x0000000000000000ULL;
+	cond = 0xffffffffffffffffULL >  0x0000000000000000ULL;
+	cond = 0xffffffffffffffffULL >= 0x0000000000000000ULL;
+	cond = 0xffffffffffffffffULL == 0x0000000000000000ULL;
+	cond = 0xffffffffffffffffULL != 0x0000000000000000ULL;
 }
 
 void
@@ -538,13 +574,13 @@ bitand_u32(void)
 void
 bitand_s64(void)
 {
-	// TODO
+	u64 = ~0x7fffeeeeddddccccLL & 0x1111222233334444LL;
 }
 
 void
 bitand_u64(void)
 {
-	// TODO
+	u64 = 0xffffeeeeddddccccULL & 0x1111222233334444ULL;
 }
 
 void
@@ -563,13 +599,13 @@ bitxor_u32(void)
 void
 bitxor_s64(void)
 {
-	// TODO
+	s64 = ~0x123456789abcdef0LL ^ 0x0123456789abcdefLL;
 }
 
 void
 bitxor_u64(void)
 {
-	// TODO
+	u64 = 0xfedcba9876543210ULL ^ 0x0123456789abcdefULL;
 }
 
 void
@@ -589,11 +625,11 @@ bitor_u32(void)
 void
 bitor_s64(void)
 {
-	// TODO
+	s64 = 0x1111222233334444LL | ~0x0000111122223333LL;
 }
 
 void
 bitor_u64(void)
 {
-	// TODO
+	u64 = 0x1111222233334444ULL | 0xffffeeeeddddccccULL;
 }

Index: src/usr.bin/xlint/lint1/emit1.c
diff -u src/usr.bin/xlint/lint1/emit1.c:1.93 src/usr.bin/xlint/lint1/emit1.c:1.94
--- src/usr.bin/xlint/lint1/emit1.c:1.93	Tue Mar 19 23:19:03 2024
+++ src/usr.bin/xlint/lint1/emit1.c	Wed Mar 27 20:09:43 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: emit1.c,v 1.93 2024/03/19 23:19:03 rillig Exp $ */
+/* $NetBSD: emit1.c,v 1.94 2024/03/27 20:09:43 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: emit1.c,v 1.93 2024/03/19 23:19:03 rillig Exp $");
+__RCSID("$NetBSD: emit1.c,v 1.94 2024/03/27 20:09:43 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -187,7 +187,7 @@ outsym(const sym_t *sym, scl_t sc, def_t
 	 */
 	if (sc != EXTERN && !(sc == STATIC && sym->s_type->t_tspec == FUNC))
 		return;
-	if (isdigit((unsigned char)sym->s_name[0]))	/* 00000000_tmp */
+	if (isdigit((unsigned char)sym->s_name[0]))	/* see mktempsym */
 		return;
 
 	outint(csrc_pos.p_line);

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.627 src/usr.bin/xlint/lint1/tree.c:1.628
--- src/usr.bin/xlint/lint1/tree.c:1.627	Wed Mar 27 19:28:20 2024
+++ src/usr.bin/xlint/lint1/tree.c	Wed Mar 27 20:09:43 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.627 2024/03/27 19:28:20 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.628 2024/03/27 20:09:43 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: tree.c,v 1.627 2024/03/27 19:28:20 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.628 2024/03/27 20:09:43 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -829,11 +829,11 @@ fold_unsigned_integer(op_t op, uint64_t 
 		*overflow = l < r;
 		return l - r;
 	case SHL:
-		/* TODO: warn about out-of-bounds 'sr'. */
+		/* TODO: warn about out-of-bounds 'r'. */
 		/* TODO: warn about overflow. */
 		return l << (r & 63);
 	case SHR:
-		/* TODO: warn about out-of-bounds 'sr'. */
+		/* TODO: warn about out-of-bounds 'r'. */
 		return l >> (r & 63);
 	case LT:
 		return l < r ? 1 : 0;
@@ -924,11 +924,11 @@ fold_signed_integer(op_t op, int64_t l, 
 		}
 		return l - r;
 	case SHL:
-		/* TODO: warn about out-of-bounds 'sr'. */
+		/* TODO: warn about out-of-bounds 'r'. */
 		/* TODO: warn about overflow. */
 		return l << (r & 63);
 	case SHR:
-		/* TODO: warn about out-of-bounds 'sr'. */
+		/* TODO: warn about out-of-bounds 'r'. */
 		if (l < 0)
 			return (int64_t)~(~(uint64_t)l >> (r & 63));
 		return (int64_t)((uint64_t)l >> (r & 63));
@@ -4241,8 +4241,7 @@ check_function_arguments(const function_
 			error(151, i + 1);
 			return;
 		}
-		if (is_struct_or_union(at) &&
-		    is_incomplete(arg->tn_type)) {
+		if (is_struct_or_union(at) && is_incomplete(arg->tn_type)) {
 			/* argument cannot have unknown size, arg #%d */
 			error(152, i + 1);
 			return;

Reply via email to