Module Name:    src
Committed By:   rillig
Date:           Sun Feb 19 11:50:29 UTC 2023

Modified Files:
        src/tests/usr.bin/xlint/lint1: lex_integer_ilp32.c msg_218.c
        src/usr.bin/xlint/lint1: lex.c

Log Message:
tests/lint: fix and extend tests for C90 migration warning


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/xlint/lint1/lex_integer_ilp32.c
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/msg_218.c
cvs rdiff -u -r1.152 -r1.153 src/usr.bin/xlint/lint1/lex.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/lex_integer_ilp32.c
diff -u src/tests/usr.bin/xlint/lint1/lex_integer_ilp32.c:1.6 src/tests/usr.bin/xlint/lint1/lex_integer_ilp32.c:1.7
--- src/tests/usr.bin/xlint/lint1/lex_integer_ilp32.c:1.6	Sun Feb  5 12:25:11 2023
+++ src/tests/usr.bin/xlint/lint1/lex_integer_ilp32.c	Sun Feb 19 11:50:29 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: lex_integer_ilp32.c,v 1.6 2023/02/05 12:25:11 rillig Exp $	*/
+/*	$NetBSD: lex_integer_ilp32.c,v 1.7 2023/02/19 11:50:29 rillig Exp $	*/
 # 3 "lex_integer_ilp32.c"
 
 /*
@@ -27,7 +27,6 @@ test_signed_int(void)
 
 	sinki(-2147483647);
 
-	/* expect+2: warning: ANSI C treats constant as unsigned, op '-' [218] */
 	/* expect+1: warning: conversion of 'unsigned long' to 'int' is out of range, arg #1 [295] */
 	sinki(-2147483648);
 }

Index: src/tests/usr.bin/xlint/lint1/msg_218.c
diff -u src/tests/usr.bin/xlint/lint1/msg_218.c:1.4 src/tests/usr.bin/xlint/lint1/msg_218.c:1.5
--- src/tests/usr.bin/xlint/lint1/msg_218.c:1.4	Wed Jun 22 19:23:18 2022
+++ src/tests/usr.bin/xlint/lint1/msg_218.c	Sun Feb 19 11:50:29 2023
@@ -1,17 +1,55 @@
-/*	$NetBSD: msg_218.c,v 1.4 2022/06/22 19:23:18 rillig Exp $	*/
+/*	$NetBSD: msg_218.c,v 1.5 2023/02/19 11:50:29 rillig Exp $	*/
 # 3 "msg_218.c"
 
 // Test for message: ANSI C treats constant as unsigned, op '%s' [218]
 
 /* lint1-only-if: ilp32 */
 
+_Bool cond;
+signed int s32;
+unsigned int u32;
+signed long long s64;
+unsigned long long u64;
+
 void sink_int(int);
 
 /* All platforms supported by lint have 32-bit int in two's complement. */
 void
 test_signed_int(void)
 {
-	/* expect+2: warning: ANSI C treats constant as unsigned, op '-' [218] */
 	/* expect+1: warning: conversion of 'unsigned long' to 'int' is out of range, arg #1 [295] */
 	sink_int(-2147483648);
 }
+
+/*
+ * In traditional C, integer constants with an 'L' suffix that didn't fit
+ * into 'long' were promoted to the next larger integer type, if that existed
+ * at all, as the suffix 'LL' was introduced by C90.
+ *
+ * Starting with C90, integer constants with an 'L' suffix that didn't fit
+ * into 'long' were promoted to 'unsigned long' first, before trying 'long
+ * long'.
+ *
+ * In C99 mode, this distinction is no longer necessary since it is far
+ * enough from traditional C.
+ */
+void
+compare_large_constant(void)
+{
+	/* expect+1: warning: ANSI C treats constant as unsigned, op '<' [218] */
+	cond = s32 < 3000000000L;
+	/* expect+1: warning: ANSI C treats constant as unsigned, op '<' [218] */
+	cond = 3000000000L < s32;
+	/* expect+1: warning: ANSI C treats constant as unsigned, op '<' [218] */
+	cond = u32 < 3000000000L;
+	/* expect+1: warning: ANSI C treats constant as unsigned, op '<' [218] */
+	cond = 3000000000L < u32;
+	/* expect+1: warning: ANSI C treats constant as unsigned, op '<' [218] */
+	cond = s64 < 3000000000L;
+	/* expect+1: warning: ANSI C treats constant as unsigned, op '<' [218] */
+	cond = 3000000000L < s64;
+	/* expect+1: warning: ANSI C treats constant as unsigned, op '<' [218] */
+	cond = u64 < 3000000000L;
+	/* expect+1: warning: ANSI C treats constant as unsigned, op '<' [218] */
+	cond = 3000000000L < u64;
+}

Index: src/usr.bin/xlint/lint1/lex.c
diff -u src/usr.bin/xlint/lint1/lex.c:1.152 src/usr.bin/xlint/lint1/lex.c:1.153
--- src/usr.bin/xlint/lint1/lex.c:1.152	Sat Feb 18 15:09:10 2023
+++ src/usr.bin/xlint/lint1/lex.c	Sun Feb 19 11:50:29 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.152 2023/02/18 15:09:10 rillig Exp $ */
+/* $NetBSD: lex.c,v 1.153 2023/02/19 11:50:29 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: lex.c,v 1.152 2023/02/18 15:09:10 rillig Exp $");
+__RCSID("$NetBSD: lex.c,v 1.153 2023/02/19 11:50:29 rillig Exp $");
 #endif
 
 #include <ctype.h>
@@ -541,8 +541,6 @@ lex_integer_constant(const char *yytext,
 				/*
 				 * Remember that the constant is unsigned
 				 * only in ANSI C.
-				 *
-				 * TODO: C99 behaves like C90 here.
 				 */
 				ansiu = true;
 			}

Reply via email to