Source-Changes-HG archive

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

[src/trunk]: src tests/lint: add tests for ILP32 platforms



details:   https://anonhg.NetBSD.org/src/rev/534f9a87a864
branches:  trunk
changeset: 984241:534f9a87a864
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Jun 29 09:19:17 2021 +0000

description:
tests/lint: add tests for ILP32 platforms

Previously, all tests for lint had to produce the exact same output, no
matter which platform they ran on.  This differs from practical needs
since lint is intended to produce different results depending on whether
the platform is ILP32 or LP64.

Examples for these are type conversions and the widths of the integer
types during lexical analysis.

diffstat:

 distrib/sets/lists/tests/mi                     |   6 ++-
 tests/usr.bin/xlint/lint1/Makefile              |   6 ++-
 tests/usr.bin/xlint/lint1/lex_integer_ilp32.c   |  44 +++++++++++++++++++++++++
 tests/usr.bin/xlint/lint1/lex_integer_ilp32.exp |   4 ++
 tests/usr.bin/xlint/lint1/msg_259.c             |   3 +-
 tests/usr.bin/xlint/lint1/msg_259.exp           |   2 +-
 tests/usr.bin/xlint/lint1/msg_259_ilp32.c       |  30 +++++++++++++++++
 tests/usr.bin/xlint/lint1/msg_259_ilp32.exp     |   3 +
 tests/usr.bin/xlint/lint1/t_integration.sh      |   4 +-
 9 files changed, 96 insertions(+), 6 deletions(-)

diffs (189 lines):

diff -r 5e85948fc4af -r 534f9a87a864 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Tue Jun 29 08:51:03 2021 +0000
+++ b/distrib/sets/lists/tests/mi       Tue Jun 29 09:19:17 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1067 2021/06/27 19:10:29 rillig Exp $
+# $NetBSD: mi,v 1.1068 2021/06/29 09:19:17 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -6228,6 +6228,8 @@
 ./usr/tests/usr.bin/xlint/lint1/lex_floating.exp               tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/lex_integer.c                  tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/lex_integer.exp                        tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/lex_integer_ilp32.c            tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/lex_integer_ilp32.exp          tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/lex_string.c                   tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/lex_string.exp                 tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/lex_wide_char.c                        tests-usr.bin-tests     compattestfile,atf
@@ -6754,6 +6756,8 @@
 ./usr/tests/usr.bin/xlint/lint1/msg_258.exp                    tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/msg_259.c                      tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/msg_259.exp                    tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/msg_259_ilp32.c                        tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/msg_259_ilp32.exp              tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/msg_260.c                      tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/msg_260.exp                    tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/msg_261.c                      tests-usr.bin-tests     compattestfile,atf
diff -r 5e85948fc4af -r 534f9a87a864 tests/usr.bin/xlint/lint1/Makefile
--- a/tests/usr.bin/xlint/lint1/Makefile        Tue Jun 29 08:51:03 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/Makefile        Tue Jun 29 09:19:17 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.68 2021/06/27 19:10:29 rillig Exp $
+# $NetBSD: Makefile,v 1.69 2021/06/29 09:19:17 rillig Exp $
 
 NOMAN=         # defined
 MAX_MESSAGE=   345             # see lint1/err.c
@@ -131,6 +131,8 @@
 FILES+=                lex_floating.exp
 FILES+=                lex_integer.c
 FILES+=                lex_integer.exp
+FILES+=                lex_integer_ilp32.c
+FILES+=                lex_integer_ilp32.exp
 FILES+=                lex_string.c
 FILES+=                lex_string.exp
 FILES+=                lex_wide_char.c
@@ -138,6 +140,8 @@
 FILES+=                lex_wide_string.c
 FILES+=                lex_wide_string.exp
 FILES+=                ${:U0 ${:U:${:Urange=${MAX_MESSAGE}}}:C,^.$,0&,:C,^..$,0&,:@i@msg_${i}.c msg_${i}.exp@:Nmsg_176.exp}
+FILES+=                msg_259_ilp32.c
+FILES+=                msg_259_ilp32.exp
 FILES+=                op_colon.c
 FILES+=                op_colon.exp
 FILES+=                stmt_for.c
diff -r 5e85948fc4af -r 534f9a87a864 tests/usr.bin/xlint/lint1/lex_integer_ilp32.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/lex_integer_ilp32.c     Tue Jun 29 09:19:17 2021 +0000
@@ -0,0 +1,44 @@
+/*     $NetBSD: lex_integer_ilp32.c,v 1.1 2021/06/29 09:19:17 rillig Exp $     */
+# 3 "lex_integer_ilp32.c"
+
+/*
+ * Tests for lexical analysis of integer constants.
+ *
+ * C99 6.4.4.1 "Integer constants"
+ */
+
+/* lint1-only-on-ilp32 */
+
+void sinki(int);
+void sinku(unsigned int);
+
+/* All platforms supported by lint have 32-bit int in two's complement. */
+void
+test_signed_int(void)
+{
+       sinki(0);
+
+       sinki(-1);
+
+       sinki(2147483647);
+
+       /* expect+1: 'unsigned long' to 'int' is out of range, arg #1 [295] */
+       sinki(2147483648);
+
+       sinki(-2147483647);
+
+       /* expect+2: ANSI C treats constant as unsigned, op - [218] */
+       /* expect+1: 'unsigned long' to 'int' is out of range, arg #1 [295] */
+       sinki(-2147483648);
+}
+
+void
+test_unsigned_int(void)
+{
+       sinku(0);
+
+       sinku(4294967295U);
+
+       /* expect+1: integer constant out of range [252] */
+       sinku(4294967296U);
+}
diff -r 5e85948fc4af -r 534f9a87a864 tests/usr.bin/xlint/lint1/lex_integer_ilp32.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/lex_integer_ilp32.exp   Tue Jun 29 09:19:17 2021 +0000
@@ -0,0 +1,4 @@
+lex_integer_ilp32.c(26): warning: conversion of 'unsigned long' to 'int' is out of range, arg #1 [295]
+lex_integer_ilp32.c(32): warning: ANSI C treats constant as unsigned, op - [218]
+lex_integer_ilp32.c(32): warning: conversion of 'unsigned long' to 'int' is out of range, arg #1 [295]
+lex_integer_ilp32.c(43): warning: integer constant out of range [252]
diff -r 5e85948fc4af -r 534f9a87a864 tests/usr.bin/xlint/lint1/msg_259.c
--- a/tests/usr.bin/xlint/lint1/msg_259.c       Tue Jun 29 08:51:03 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_259.c       Tue Jun 29 09:19:17 2021 +0000
@@ -1,8 +1,9 @@
-/*     $NetBSD: msg_259.c,v 1.6 2021/02/04 07:39:39 rillig Exp $       */
+/*     $NetBSD: msg_259.c,v 1.7 2021/06/29 09:19:17 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-extra-flags: -h */
 
 void farg_char(char);
diff -r 5e85948fc4af -r 534f9a87a864 tests/usr.bin/xlint/lint1/msg_259.exp
--- a/tests/usr.bin/xlint/lint1/msg_259.exp     Tue Jun 29 08:51:03 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_259.exp     Tue Jun 29 09:19:17 2021 +0000
@@ -1,1 +1,1 @@
-msg_259.c(22): warning: argument #1 is converted from 'long' to 'int' due to prototype [259]
+msg_259.c(23): warning: argument #1 is converted from 'long' to 'int' due to prototype [259]
diff -r 5e85948fc4af -r 534f9a87a864 tests/usr.bin/xlint/lint1/msg_259_ilp32.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_259_ilp32.c Tue Jun 29 09:19:17 2021 +0000
@@ -0,0 +1,30 @@
+/*     $NetBSD: msg_259_ilp32.c,v 1.1 2021/06/29 09:19:17 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-extra-flags: -h */
+
+void farg_char(char);
+void farg_int(int);
+void farg_long(long);
+
+void
+example(char c, int i, long l)
+{
+       farg_char(c);
+       farg_int(c);
+       /* expect+1: from 'char' to 'long' due to prototype [259] */
+       farg_long(c);
+
+       farg_char(i);           /* XXX: why no warning? */
+       farg_int(i);
+       /* expect+1: from 'int' to 'long' due to prototype [259] */
+       farg_long(i);
+
+       farg_char(l);           /* XXX: why no warning? */
+       /* expect+1: from 'long' to 'int' due to prototype [259] */
+       farg_int(l);
+       farg_long(l);
+}
diff -r 5e85948fc4af -r 534f9a87a864 tests/usr.bin/xlint/lint1/msg_259_ilp32.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_259_ilp32.exp       Tue Jun 29 09:19:17 2021 +0000
@@ -0,0 +1,3 @@
+msg_259_ilp32.c(19): warning: argument #1 is converted from 'char' to 'long' due to prototype [259]
+msg_259_ilp32.c(24): warning: argument #1 is converted from 'int' to 'long' due to prototype [259]
+msg_259_ilp32.c(28): warning: argument #1 is converted from 'long' to 'int' due to prototype [259]
diff -r 5e85948fc4af -r 534f9a87a864 tests/usr.bin/xlint/lint1/t_integration.sh
--- a/tests/usr.bin/xlint/lint1/t_integration.sh        Tue Jun 29 08:51:03 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/t_integration.sh        Tue Jun 29 09:19:17 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: t_integration.sh,v 1.64 2021/06/29 08:46:10 rillig Exp $
+# $NetBSD: t_integration.sh,v 1.65 2021/06/29 09:19:17 rillig Exp $
 #
 # Copyright (c) 2008, 2010 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -27,7 +27,7 @@
 
 lint1=/usr/libexec/lint1
 
-machine_arch="$(sysctl -n hw.machine_arch)"
+: "${machine_arch:="$(sysctl -n hw.machine_arch)"}"
 
 
 configure_test_case()



Home | Main Index | Thread Index | Old Index