Module Name: src
Committed By: rillig
Date: Mon Aug 16 20:11:03 UTC 2021
Modified Files:
src/distrib/sets/lists/tests: mi
src/tests/usr.bin/xlint/lint1: Makefile msg_241.c msg_277.c msg_277.exp
Added Files:
src/tests/usr.bin/xlint/lint1: expr_promote.c expr_promote.exp-ln
expr_promote_trad.c expr_promote_trad.exp-ln
Log Message:
tests/lint: test arithmetic promotions and enums
To generate a diff of this commit:
cvs rdiff -u -r1.1111 -r1.1112 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.103 -r1.104 src/tests/usr.bin/xlint/lint1/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/xlint/lint1/expr_promote.c \
src/tests/usr.bin/xlint/lint1/expr_promote.exp-ln \
src/tests/usr.bin/xlint/lint1/expr_promote_trad.c \
src/tests/usr.bin/xlint/lint1/expr_promote_trad.exp-ln
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/msg_241.c
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/msg_277.c
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/msg_277.exp
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.1111 src/distrib/sets/lists/tests/mi:1.1112
--- src/distrib/sets/lists/tests/mi:1.1111 Thu Aug 12 15:06:39 2021
+++ src/distrib/sets/lists/tests/mi Mon Aug 16 20:11:03 2021
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1111 2021/08/12 15:06:39 martin Exp $
+# $NetBSD: mi,v 1.1112 2021/08/16 20:11:03 rillig Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -6249,6 +6249,10 @@
./usr/tests/usr.bin/xlint/lint1/expr_cast.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/expr_precedence.c tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/expr_precedence.exp tests-usr.bin-tests compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/expr_promote.c tests-usr.bin-tests compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/expr_promote.exp-ln tests-usr.bin-tests compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/expr_promote_trad.c tests-usr.bin-tests compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/expr_promote_trad.exp-ln tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/expr_range.c tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/expr_range.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/feat_stacktrace.c tests-usr.bin-tests compattestfile,atf
Index: src/tests/usr.bin/xlint/lint1/Makefile
diff -u src/tests/usr.bin/xlint/lint1/Makefile:1.103 src/tests/usr.bin/xlint/lint1/Makefile:1.104
--- src/tests/usr.bin/xlint/lint1/Makefile:1.103 Mon Aug 9 20:07:24 2021
+++ src/tests/usr.bin/xlint/lint1/Makefile Mon Aug 16 20:11:03 2021
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.103 2021/08/09 20:07:24 rillig Exp $
+# $NetBSD: Makefile,v 1.104 2021/08/16 20:11:03 rillig Exp $
NOMAN= # defined
MAX_MESSAGE= 346 # see lint1/err.c
@@ -141,6 +141,10 @@ FILES+= expr_cast.c
FILES+= expr_cast.exp
FILES+= expr_precedence.c
FILES+= expr_precedence.exp
+FILES+= expr_promote.c
+FILES+= expr_promote.exp-ln
+FILES+= expr_promote_trad.c
+FILES+= expr_promote_trad.exp-ln
FILES+= expr_range.c
FILES+= expr_range.exp
FILES+= feat_stacktrace.c
Index: src/tests/usr.bin/xlint/lint1/msg_241.c
diff -u src/tests/usr.bin/xlint/lint1/msg_241.c:1.5 src/tests/usr.bin/xlint/lint1/msg_241.c:1.6
--- src/tests/usr.bin/xlint/lint1/msg_241.c:1.5 Mon Aug 16 18:51:58 2021
+++ src/tests/usr.bin/xlint/lint1/msg_241.c Mon Aug 16 20:11:03 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: msg_241.c,v 1.5 2021/08/16 18:51:58 rillig Exp $ */
+/* $NetBSD: msg_241.c,v 1.6 2021/08/16 20:11:03 rillig Exp $ */
# 3 "msg_241.c"
// Test for message: dubious operation on enum, op %s [241]
@@ -82,3 +82,15 @@ cover_typeok_enum(enum color c, int i)
if (c * i > 5)
return;
}
+
+const char *
+color_name(enum color c)
+{
+ static const char *name[] = { "red", "green", "blue" };
+
+ if (c == RED)
+ return *(c + name); /* unusual but allowed */
+ if (c == GREEN)
+ return c[name]; /* even more unusual */
+ return name[c];
+}
Index: src/tests/usr.bin/xlint/lint1/msg_277.c
diff -u src/tests/usr.bin/xlint/lint1/msg_277.c:1.4 src/tests/usr.bin/xlint/lint1/msg_277.c:1.5
--- src/tests/usr.bin/xlint/lint1/msg_277.c:1.4 Sat Feb 27 18:01:29 2021
+++ src/tests/usr.bin/xlint/lint1/msg_277.c Mon Aug 16 20:11:03 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: msg_277.c,v 1.4 2021/02/27 18:01:29 rillig Exp $ */
+/* $NetBSD: msg_277.c,v 1.5 2021/08/16 20:11:03 rillig Exp $ */
# 3 "msg_277.c"
// Test for message: initialization of '%s' with '%s' [277]
@@ -24,4 +24,8 @@ example(enum E e, int i)
sink_enum(e3);
sink_int(i2);
sink_int(i3);
+
+ enum E init_0 = 0;
+ /* expect+1: warning: initialization of 'enum E' with 'int' [277] */
+ enum E init_1 = 1;
}
Index: src/tests/usr.bin/xlint/lint1/msg_277.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_277.exp:1.2 src/tests/usr.bin/xlint/lint1/msg_277.exp:1.3
--- src/tests/usr.bin/xlint/lint1/msg_277.exp:1.2 Sat Feb 27 18:01:29 2021
+++ src/tests/usr.bin/xlint/lint1/msg_277.exp Mon Aug 16 20:11:03 2021
@@ -1,2 +1,3 @@
msg_277.c(19): warning: initialization of 'enum E' with 'int' [277]
msg_277.c(20): warning: initialization of 'int' with 'enum E' [277]
+msg_277.c(30): warning: initialization of 'enum E' with 'int' [277]
Added files:
Index: src/tests/usr.bin/xlint/lint1/expr_promote.c
diff -u /dev/null src/tests/usr.bin/xlint/lint1/expr_promote.c:1.1
--- /dev/null Mon Aug 16 20:11:03 2021
+++ src/tests/usr.bin/xlint/lint1/expr_promote.c Mon Aug 16 20:11:03 2021
@@ -0,0 +1,57 @@
+/* $NetBSD: expr_promote.c,v 1.1 2021/08/16 20:11:03 rillig Exp $ */
+# 3 "expr_promote.c"
+
+/*
+ * Test arithmetic promotions in C90 and later.
+ */
+
+/* lint1-flags: -Sw */
+
+void sink(const char *, ...);
+
+struct arithmetic_types {
+ _Bool boolean;
+ char plain_char;
+ signed char signed_char;
+ unsigned char unsigned_char;
+ short signed_short;
+ unsigned short unsigned_short;
+ int signed_int;
+ unsigned int unsigned_int;
+ long signed_long;
+ unsigned long unsigned_long;
+ long long signed_long_long;
+ unsigned long long unsigned_long_long;
+ float float_floating;
+ double double_floating;
+ long double long_floating;
+ float _Complex float_complex;
+ double _Complex double_complex;
+ long double _Complex long_double_complex;
+};
+
+void
+caller(struct arithmetic_types *arg)
+{
+ sink("",
+ arg->boolean, /* gets promoted to 'int' */
+ arg->plain_char, /* gets promoted to 'int' */
+ arg->signed_char, /* gets promoted to 'int' */
+ arg->unsigned_char, /* gets promoted to 'int' */
+ arg->signed_short, /* gets promoted to 'int' */
+ arg->unsigned_short, /* gets promoted to 'int' */
+ arg->signed_int,
+ arg->unsigned_int,
+ arg->signed_long,
+ arg->unsigned_long,
+ arg->signed_long_long,
+ arg->unsigned_long_long,
+ arg->float_floating, /* gets promoted to 'double' */
+ arg->double_floating,
+ arg->long_floating,
+ arg->float_complex,
+ arg->double_complex,
+ arg->long_double_complex);
+}
+
+/* XXX: _Bool is not promoted but should. */
Index: src/tests/usr.bin/xlint/lint1/expr_promote.exp-ln
diff -u /dev/null src/tests/usr.bin/xlint/lint1/expr_promote.exp-ln:1.1
--- /dev/null Mon Aug 16 20:11:03 2021
+++ src/tests/usr.bin/xlint/lint1/expr_promote.exp-ln Mon Aug 16 20:11:03 2021
@@ -0,0 +1,5 @@
+0sexpr_promote.c
+Sexpr_promote.c
+10d0.10e4sinkF2PcCEV
+54c0.54i4sinkf19PcCBIIIIIIuILuLQuQDDlDsXXlXV
+34d0.34d6callerF1PsT116arithmetic_typesV
Index: src/tests/usr.bin/xlint/lint1/expr_promote_trad.c
diff -u /dev/null src/tests/usr.bin/xlint/lint1/expr_promote_trad.c:1.1
--- /dev/null Mon Aug 16 20:11:03 2021
+++ src/tests/usr.bin/xlint/lint1/expr_promote_trad.c Mon Aug 16 20:11:03 2021
@@ -0,0 +1,46 @@
+/* $NetBSD: expr_promote_trad.c,v 1.1 2021/08/16 20:11:03 rillig Exp $ */
+# 3 "expr_promote_trad.c"
+
+/*
+ * Test arithmetic promotions in traditional C.
+ */
+
+/* lint1-flags: -tw */
+
+sink();
+
+struct arithmetic_types {
+ /* _Bool is not available in traditional C */
+ char plain_char;
+ /* signed char is not available in traditional C */
+ unsigned char unsigned_char;
+ short signed_short;
+ unsigned short unsigned_short;
+ int signed_int;
+ unsigned int unsigned_int;
+ long signed_long;
+ unsigned long unsigned_long;
+ /* (unsigned) long long is not available in traditional C */
+ /* __int128_t is not available in traditional C */
+ /* __uint128_t is not available in traditional C */
+ float single_floating;
+ double double_floating;
+ /* long double is not available in traditional C */
+ /* _Complex is not available in traditional C */
+};
+
+caller(arg)
+ struct arithmetic_types *arg;
+{
+ sink("",
+ arg->plain_char, /* gets promoted to 'int' */
+ arg->unsigned_char, /* gets promoted to 'unsigned int' */
+ arg->signed_short, /* gets promoted to 'int' */
+ arg->unsigned_short, /* gets promoted to 'unsigned int' */
+ arg->signed_int,
+ arg->unsigned_int,
+ arg->signed_long,
+ arg->unsigned_long,
+ arg->single_floating, /* gets promoted to 'double' */
+ arg->double_floating);
+}
Index: src/tests/usr.bin/xlint/lint1/expr_promote_trad.exp-ln
diff -u /dev/null src/tests/usr.bin/xlint/lint1/expr_promote_trad.exp-ln:1.1
--- /dev/null Mon Aug 16 20:11:03 2021
+++ src/tests/usr.bin/xlint/lint1/expr_promote_trad.exp-ln Mon Aug 16 20:11:03 2021
@@ -0,0 +1,5 @@
+0sexpr_promote_trad.c
+Sexpr_promote_trad.c
+10d0.10e4sinkFI
+45c0.45s1""i4sinkf11PCIuIIuIIuILuLDDI
+32d0.32do6callerf1PsT116arithmetic_typesI