Source-Changes-HG archive

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

[src/trunk]: src tests/lint: test arithmetic promotions and enums



details:   https://anonhg.NetBSD.org/src/rev/3cf63678f0b6
branches:  trunk
changeset: 985287:3cf63678f0b6
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Aug 16 20:11:03 2021 +0000

description:
tests/lint: test arithmetic promotions and enums

diffstat:

 distrib/sets/lists/tests/mi                        |   6 +-
 tests/usr.bin/xlint/lint1/Makefile                 |   6 +-
 tests/usr.bin/xlint/lint1/expr_promote.c           |  57 ++++++++++++++++++++++
 tests/usr.bin/xlint/lint1/expr_promote.exp-ln      |   5 +
 tests/usr.bin/xlint/lint1/expr_promote_trad.c      |  46 +++++++++++++++++
 tests/usr.bin/xlint/lint1/expr_promote_trad.exp-ln |   5 +
 tests/usr.bin/xlint/lint1/msg_241.c                |  14 +++++-
 tests/usr.bin/xlint/lint1/msg_277.c                |   6 +-
 tests/usr.bin/xlint/lint1/msg_277.exp              |   1 +
 9 files changed, 142 insertions(+), 4 deletions(-)

diffs (219 lines):

diff -r 226c25a0b9a8 -r 3cf63678f0b6 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Mon Aug 16 18:51:58 2021 +0000
+++ b/distrib/sets/lists/tests/mi       Mon Aug 16 20:11:03 2021 +0000
@@ -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
diff -r 226c25a0b9a8 -r 3cf63678f0b6 tests/usr.bin/xlint/lint1/Makefile
--- a/tests/usr.bin/xlint/lint1/Makefile        Mon Aug 16 18:51:58 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/Makefile        Mon Aug 16 20:11:03 2021 +0000
@@ -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.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
diff -r 226c25a0b9a8 -r 3cf63678f0b6 tests/usr.bin/xlint/lint1/expr_promote.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/expr_promote.c  Mon Aug 16 20:11:03 2021 +0000
@@ -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. */
diff -r 226c25a0b9a8 -r 3cf63678f0b6 tests/usr.bin/xlint/lint1/expr_promote.exp-ln
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/expr_promote.exp-ln     Mon Aug 16 20:11:03 2021 +0000
@@ -0,0 +1,5 @@
+0sexpr_promote.c
+Sexpr_promote.c
+10d0.10e4sinkF2PcCEV
+54c0.54i4sinkf19PcCBIIIIIIuILuLQuQDDlDsXXlXV
+34d0.34d6callerF1PsT116arithmetic_typesV
diff -r 226c25a0b9a8 -r 3cf63678f0b6 tests/usr.bin/xlint/lint1/expr_promote_trad.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/expr_promote_trad.c     Mon Aug 16 20:11:03 2021 +0000
@@ -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);
+}
diff -r 226c25a0b9a8 -r 3cf63678f0b6 tests/usr.bin/xlint/lint1/expr_promote_trad.exp-ln
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/expr_promote_trad.exp-ln        Mon Aug 16 20:11:03 2021 +0000
@@ -0,0 +1,5 @@
+0sexpr_promote_trad.c
+Sexpr_promote_trad.c
+10d0.10e4sinkFI
+45c0.45s1""i4sinkf11PCIuIIuIIuILuLDDI
+32d0.32do6callerf1PsT116arithmetic_typesI
diff -r 226c25a0b9a8 -r 3cf63678f0b6 tests/usr.bin/xlint/lint1/msg_241.c
--- a/tests/usr.bin/xlint/lint1/msg_241.c       Mon Aug 16 18:51:58 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_241.c       Mon Aug 16 20:11:03 2021 +0000
@@ -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 @@
        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];
+}
diff -r 226c25a0b9a8 -r 3cf63678f0b6 tests/usr.bin/xlint/lint1/msg_277.c
--- a/tests/usr.bin/xlint/lint1/msg_277.c       Mon Aug 16 18:51:58 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_277.c       Mon Aug 16 20:11:03 2021 +0000
@@ -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 @@
        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;
 }
diff -r 226c25a0b9a8 -r 3cf63678f0b6 tests/usr.bin/xlint/lint1/msg_277.exp
--- a/tests/usr.bin/xlint/lint1/msg_277.exp     Mon Aug 16 18:51:58 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_277.exp     Mon Aug 16 20:11:03 2021 +0000
@@ -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]



Home | Main Index | Thread Index | Old Index