Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src tests/lint: add test that only runs where char == unsigned char



details:   https://anonhg.NetBSD.org/src/rev/330797aea628
branches:  trunk
changeset: 379974:330797aea628
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Jun 29 13:58:13 2021 +0000

description:
tests/lint: add test that only runs where char == unsigned char

There a 4 regular NetBSD builds where lint is activated.  All these
builds run on platforms where char == signed char.

The official test runs from https://releng.netbsd.org/test-results.html
mostly have char == signed char as well.

However, lint behaves differently on platforms with char == unsigned
char.  On these platforms, a simple "char ch = '\xff'" leads to the
bogus warning that "conversion of 'int' to 'char' is out of range".

diffstat:

 distrib/sets/lists/tests/mi                   |   4 +-
 tests/usr.bin/xlint/lint1/Makefile            |   4 +-
 tests/usr.bin/xlint/lint1/lex_char_uchar.c    |  16 ++++++++
 tests/usr.bin/xlint/lint1/lex_char_uchar.exp  |   1 +
 tests/usr.bin/xlint/lint1/lex_integer.c       |   4 +-
 tests/usr.bin/xlint/lint1/lex_integer_ilp32.c |   4 +-
 tests/usr.bin/xlint/lint1/msg_259.c           |   4 +-
 tests/usr.bin/xlint/lint1/msg_259_ilp32.c     |   4 +-
 tests/usr.bin/xlint/lint1/t_integration.sh    |  49 ++++++++++++++++++++++----
 9 files changed, 71 insertions(+), 19 deletions(-)

diffs (205 lines):

diff -r 8e0fedea6e1b -r 330797aea628 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Tue Jun 29 13:48:24 2021 +0000
+++ b/distrib/sets/lists/tests/mi       Tue Jun 29 13:58:13 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1068 2021/06/29 09:19:17 rillig Exp $
+# $NetBSD: mi,v 1.1069 2021/06/29 13:58:13 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -6222,6 +6222,8 @@
 ./usr/tests/usr.bin/xlint/lint1/gcc_typeof_after_statement.exp tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/lex_char.c                     tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/lex_char.exp                   tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/lex_char_uchar.c               tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/lex_char_uchar.exp             tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/lex_comment.c                  tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/lex_comment.exp                        tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/lex_floating.c                 tests-usr.bin-tests     compattestfile,atf
diff -r 8e0fedea6e1b -r 330797aea628 tests/usr.bin/xlint/lint1/Makefile
--- a/tests/usr.bin/xlint/lint1/Makefile        Tue Jun 29 13:48:24 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/Makefile        Tue Jun 29 13:58:13 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.70 2021/06/29 09:44:25 rillig Exp $
+# $NetBSD: Makefile,v 1.71 2021/06/29 13:58:13 rillig Exp $
 
 NOMAN=         # defined
 MAX_MESSAGE=   345             # see lint1/err.c
@@ -125,6 +125,8 @@ FILES+=             gcc_typeof_after_statement.c
 FILES+=                gcc_typeof_after_statement.exp
 FILES+=                lex_char.c
 FILES+=                lex_char.exp
+FILES+=                lex_char_uchar.c
+FILES+=                lex_char_uchar.exp
 FILES+=                lex_comment.c
 FILES+=                lex_comment.exp
 FILES+=                lex_floating.c
diff -r 8e0fedea6e1b -r 330797aea628 tests/usr.bin/xlint/lint1/lex_char_uchar.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/lex_char_uchar.c        Tue Jun 29 13:58:13 2021 +0000
@@ -0,0 +1,16 @@
+/*     $NetBSD: lex_char_uchar.c,v 1.1 2021/06/29 13:58:13 rillig Exp $        */
+# 3 "lex_char_uchar.c"
+
+/*
+ * Test lexical analysis of character constants on platforms where plain
+ * char has the same representation as unsigned char.
+ */
+
+/* lint1-only-if uchar */
+
+/*
+ * FIXME: The warning is bogus; it must be possible to initialize a char
+ *  variable with a character constant.
+ */
+/* expect+1: conversion of 'int' to 'char' is out of range [119] */
+char ch = '\xff';
diff -r 8e0fedea6e1b -r 330797aea628 tests/usr.bin/xlint/lint1/lex_char_uchar.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/lex_char_uchar.exp      Tue Jun 29 13:58:13 2021 +0000
@@ -0,0 +1,1 @@
+lex_char_uchar.c(16): warning: conversion of 'int' to 'char' is out of range [119]
diff -r 8e0fedea6e1b -r 330797aea628 tests/usr.bin/xlint/lint1/lex_integer.c
--- a/tests/usr.bin/xlint/lint1/lex_integer.c   Tue Jun 29 13:48:24 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/lex_integer.c   Tue Jun 29 13:58:13 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lex_integer.c,v 1.3 2021/06/29 08:46:10 rillig Exp $   */
+/*     $NetBSD: lex_integer.c,v 1.4 2021/06/29 13:58:13 rillig Exp $   */
 # 3 "lex_integer.c"
 
 /*
@@ -7,7 +7,7 @@
  * C99 6.4.4.1 "Integer constants"
  */
 
-/* lint1-only-on-lp64 */
+/* lint1-only-if lp64 */
 
 void sinki(int);
 void sinku(unsigned int);
diff -r 8e0fedea6e1b -r 330797aea628 tests/usr.bin/xlint/lint1/lex_integer_ilp32.c
--- a/tests/usr.bin/xlint/lint1/lex_integer_ilp32.c     Tue Jun 29 13:48:24 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/lex_integer_ilp32.c     Tue Jun 29 13:58:13 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lex_integer_ilp32.c,v 1.1 2021/06/29 09:19:17 rillig Exp $     */
+/*     $NetBSD: lex_integer_ilp32.c,v 1.2 2021/06/29 13:58:13 rillig Exp $     */
 # 3 "lex_integer_ilp32.c"
 
 /*
@@ -7,7 +7,7 @@
  * C99 6.4.4.1 "Integer constants"
  */
 
-/* lint1-only-on-ilp32 */
+/* lint1-only-if ilp32 */
 
 void sinki(int);
 void sinku(unsigned int);
diff -r 8e0fedea6e1b -r 330797aea628 tests/usr.bin/xlint/lint1/msg_259.c
--- a/tests/usr.bin/xlint/lint1/msg_259.c       Tue Jun 29 13:48:24 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_259.c       Tue Jun 29 13:58:13 2021 +0000
@@ -1,9 +1,9 @@
-/*     $NetBSD: msg_259.c,v 1.7 2021/06/29 09:19:17 rillig Exp $       */
+/*     $NetBSD: msg_259.c,v 1.8 2021/06/29 13:58:13 rillig Exp $       */
 # 3 "msg_259.c"
 
 // Test for message: argument #%d is converted from '%s' to '%s' due to prototype [259]
 
-/* lint1-only-on-lp64 */
+/* lint1-only-if lp64 */
 /* lint1-extra-flags: -h */
 
 void farg_char(char);
diff -r 8e0fedea6e1b -r 330797aea628 tests/usr.bin/xlint/lint1/msg_259_ilp32.c
--- a/tests/usr.bin/xlint/lint1/msg_259_ilp32.c Tue Jun 29 13:48:24 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_259_ilp32.c Tue Jun 29 13:58:13 2021 +0000
@@ -1,9 +1,9 @@
-/*     $NetBSD: msg_259_ilp32.c,v 1.1 2021/06/29 09:19:17 rillig Exp $ */
+/*     $NetBSD: msg_259_ilp32.c,v 1.2 2021/06/29 13:58:13 rillig Exp $ */
 # 3 "msg_259_ilp32.c"
 
 // Test for message: argument #%d is converted from '%s' to '%s' due to prototype [259]
 
-/* lint1-only-on-ilp32 */
+/* lint1-only-if ilp32 */
 /* lint1-extra-flags: -h */
 
 void farg_char(char);
diff -r 8e0fedea6e1b -r 330797aea628 tests/usr.bin/xlint/lint1/t_integration.sh
--- a/tests/usr.bin/xlint/lint1/t_integration.sh        Tue Jun 29 13:48:24 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/t_integration.sh        Tue Jun 29 13:58:13 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: t_integration.sh,v 1.65 2021/06/29 09:19:17 rillig Exp $
+# $NetBSD: t_integration.sh,v 1.66 2021/06/29 13:58:13 rillig Exp $
 #
 # Copyright (c) 2008, 2010 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -36,12 +36,43 @@ configure_test_case()
 
        # shellcheck disable=SC2016
        awk='
-               function is_ilp32() {
-                       return match(machine_arch, /^(arm|coldfire|hppa|i386|m68000|m68k|mips|mips64|or1k|powerpc|riscv32|sh3|sparc|vax)$/)
+               BEGIN {
+                       # see usr.bin/xlint/arch/.../targparam.h
+                       platform["aarch64"]     = "schar lp64  long ldbl-128"
+                       platform["alpha"]       = "schar lp64  long ldbl-64"
+                       platform["arm"]         = "uchar ilp32 long ldbl-64"
+                       platform["coldfire"]    = "schar ilp32 int  ldbl-64"
+                       platform["hppa"]        = "schar ilp32 long ldbl-64"
+                       platform["i386"]        = "schar ilp32 int  ldbl-96"
+                       platform["ia64"]        = "schar lp64  long ldbl-128"
+                       platform["m68000"]      = "schar ilp32 int  ldbl-64"
+                       platform["m68k"]        = "schar ilp32 int  ldbl-96"
+                       platform["mips"]        = "schar ilp32 ???? ldbl-64"
+                       platform["mips64"]      = "schar ilp32 long ldbl-128"
+                       platform["mipsn64"]     = "schar lp64  long ldbl-128"
+                       platform["or1k"]        = "schar ilp32 int  ldbl-64"
+                       platform["powerpc"]     = "uchar ilp32 int  ldbl-64"
+                       platform["powerpc64"]   = "uchar lp64  long ldbl-64"
+                       platform["powerpc64"]   = "uchar lp64  long ldbl-64"
+                       platform["riscv32"]     = "schar ilp32 int  ldbl-64"
+                       platform["riscv64"]     = "schar lp64  long ldbl-64"
+                       platform["sh3"]         = "schar ilp32 int  ldbl-64"
+                       platform["sparc"]       = "schar ilp32 long ldbl-64"
+                       platform["sparc64"]     = "schar lp64  long ldbl-128"
+                       platform["vax"]         = "schar ilp32 long ldbl-64"
+                       platform["x86_64"]      = "schar lp64  long ldbl-128"
                }
 
-               function is_lp64() {
-                       return match(machine_arch, /^(aarch64|alpha|ia64|mipsn64|powerpc64|riscv64|sparc64|x86_64)$/)
+               function platform_has(prop) {
+                       if (!match(prop, /^(schar|uchar|ilp32|lp64|int|long|ldbl-64|ldbl-96|ldbl-128)$/)) {
+                               printf("bad property '\''%s'\''\n", prop) > "/dev/stderr";
+                               exit(1);
+                       }
+                       if (platform[machine_arch] == "") {
+                               printf("bad machine_arch '\''%s'\''\n", machine_arch) > "/dev/stderr";
+                               exit(1);
+                       }
+                       return match(" " platform[machine_arch] " ", " " prop " ")
                }
 
                BEGIN {
@@ -58,16 +89,16 @@ configure_test_case()
                                for (i = 3; i < NF; i++)
                                        flags = flags " " $i
                        }
-                       if ($2 == "lint1-only-on-arch") {
+                       if ($2 == "lint1-only-if-arch") {
                                seen_only_on_arch = 1
                                if ($3 == machine_arch)
                                        match_only_on_arch = 1
                        }
-                       if ($2 == "lint1-not-on-arch" && $3 == machine_arch)
+                       if ($2 == "lint1-skip-if-arch" && $3 == machine_arch)
                                skip = 1
-                       if ($2 == "lint1-only-on-ilp32" && !is_ilp32())
+                       if ($2 == "lint1-only-if" && !platform_has($3))
                                skip = 1
-                       if ($2 == "lint1-only-on-lp64" && !is_lp64())
+                       if ($2 == "lint1-skip-if" && platform_has($3))
                                skip = 1
                }
 



Home | Main Index | Thread Index | Old Index