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 tests/lint: fix and extend tests for C90...



details:   https://anonhg.NetBSD.org/src/rev/e9b816b87fba
branches:  trunk
changeset: 373587:e9b816b87fba
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Feb 19 11:50:29 2023 +0000

description:
tests/lint: fix and extend tests for C90 migration warning

diffstat:

 tests/usr.bin/xlint/lint1/lex_integer_ilp32.c |   3 +-
 tests/usr.bin/xlint/lint1/msg_218.c           |  42 +++++++++++++++++++++++++-
 usr.bin/xlint/lint1/lex.c                     |   6 +--
 3 files changed, 43 insertions(+), 8 deletions(-)

diffs (105 lines):

diff -r a8efff091449 -r e9b816b87fba tests/usr.bin/xlint/lint1/lex_integer_ilp32.c
--- a/tests/usr.bin/xlint/lint1/lex_integer_ilp32.c     Sun Feb 19 11:19:51 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/lex_integer_ilp32.c     Sun Feb 19 11:50:29 2023 +0000
@@ -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 @@
 
        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);
 }
diff -r a8efff091449 -r e9b816b87fba tests/usr.bin/xlint/lint1/msg_218.c
--- a/tests/usr.bin/xlint/lint1/msg_218.c       Sun Feb 19 11:19:51 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_218.c       Sun Feb 19 11:50:29 2023 +0000
@@ -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;
+}
diff -r a8efff091449 -r e9b816b87fba usr.bin/xlint/lint1/lex.c
--- a/usr.bin/xlint/lint1/lex.c Sun Feb 19 11:19:51 2023 +0000
+++ b/usr.bin/xlint/lint1/lex.c Sun Feb 19 11:50:29 2023 +0000
@@ -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 @@
                                /*
                                 * Remember that the constant is unsigned
                                 * only in ANSI C.
-                                *
-                                * TODO: C99 behaves like C90 here.
                                 */
                                ansiu = true;
                        }



Home | Main Index | Thread Index | Old Index