Source-Changes-HG archive

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

[src/trunk]: src/tests/usr.bin/xlint/lint1 lint: add tests for a few messages



details:   https://anonhg.NetBSD.org/src/rev/13e795f28c1f
branches:  trunk
changeset: 1018164:13e795f28c1f
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Jan 24 16:12:45 2021 +0000

description:
lint: add tests for a few messages

diffstat:

 tests/usr.bin/xlint/lint1/msg_168.c   |  28 +++++++++++++++++++++++++---
 tests/usr.bin/xlint/lint1/msg_168.exp |   2 +-
 tests/usr.bin/xlint/lint1/msg_171.c   |  18 +++++++++++++++---
 tests/usr.bin/xlint/lint1/msg_171.exp |   5 ++++-
 tests/usr.bin/xlint/lint1/msg_175.c   |   9 ++++++---
 tests/usr.bin/xlint/lint1/msg_175.exp |   4 +++-
 tests/usr.bin/xlint/lint1/msg_177.c   |  11 ++++++++---
 tests/usr.bin/xlint/lint1/msg_177.exp |   3 ++-
 tests/usr.bin/xlint/lint1/msg_178.c   |   7 ++++---
 tests/usr.bin/xlint/lint1/msg_178.exp |   2 +-
 10 files changed, 69 insertions(+), 20 deletions(-)

diffs (149 lines):

diff -r 6564d2721169 -r 13e795f28c1f tests/usr.bin/xlint/lint1/msg_168.c
--- a/tests/usr.bin/xlint/lint1/msg_168.c       Sun Jan 24 15:59:35 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_168.c       Sun Jan 24 16:12:45 2021 +0000
@@ -1,7 +1,29 @@
-/*     $NetBSD: msg_168.c,v 1.1 2021/01/02 10:22:43 rillig Exp $       */
+/*     $NetBSD: msg_168.c,v 1.2 2021/01/24 16:12:45 rillig Exp $       */
 # 3 "msg_168.c"
 
 // Test for message: array subscript cannot be > %d: %ld [168]
 
-TODO: "Add example code that triggers the above message."
-TODO: "Add example code that almost triggers the above message."
+void print_string(const char *);
+void print_char(char);
+
+void
+example(void)
+{
+       char buf[20] = {};
+
+       print_string(buf + 19); /* inside the array */
+
+       /*
+        * It is valid to point at the end of the array, but reading a
+        * character from there invokes undefined behavior.
+        *
+        * The pointer to the end of the array is typically used in (begin,
+        * end) tuples.  These are more common in C++ than in C though.
+        */
+       print_string(buf + 20);
+
+       print_string(buf + 21); /* undefined behavior, not detected */
+
+       print_char(buf[19]);
+       print_char(buf[20]);    /* expect: 168 */
+}
diff -r 6564d2721169 -r 13e795f28c1f tests/usr.bin/xlint/lint1/msg_168.exp
--- a/tests/usr.bin/xlint/lint1/msg_168.exp     Sun Jan 24 15:59:35 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_168.exp     Sun Jan 24 16:12:45 2021 +0000
@@ -1,1 +1,1 @@
-msg_168.c(6): syntax error ':' [249]
+msg_168.c(28): warning: array subscript cannot be > 19: 20 [168]
diff -r 6564d2721169 -r 13e795f28c1f tests/usr.bin/xlint/lint1/msg_171.c
--- a/tests/usr.bin/xlint/lint1/msg_171.c       Sun Jan 24 15:59:35 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_171.c       Sun Jan 24 16:12:45 2021 +0000
@@ -1,7 +1,19 @@
-/*     $NetBSD: msg_171.c,v 1.1 2021/01/02 10:22:43 rillig Exp $       */
+/*     $NetBSD: msg_171.c,v 1.2 2021/01/24 16:12:45 rillig Exp $       */
 # 3 "msg_171.c"
 
 // Test for message: assignment type mismatch (%s != %s) [171]
 
-TODO: "Add example code that triggers the above message."
-TODO: "Add example code that almost triggers the above message."
+struct s {
+       int member;
+};
+
+/*ARGSUSED*/
+void
+example(int i, void *vp, struct s *s)
+{
+       i = *s;                 /* expect: 171 */
+       *s = i;                 /* expect: 171 */
+
+       vp = *s;                /* expect: 171 */
+       *s = vp;                /* expect: 171 */
+}
diff -r 6564d2721169 -r 13e795f28c1f tests/usr.bin/xlint/lint1/msg_171.exp
--- a/tests/usr.bin/xlint/lint1/msg_171.exp     Sun Jan 24 15:59:35 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_171.exp     Sun Jan 24 16:12:45 2021 +0000
@@ -1,1 +1,4 @@
-msg_171.c(6): syntax error ':' [249]
+msg_171.c(14): assignment type mismatch (int != struct) [171]
+msg_171.c(15): assignment type mismatch (struct != int) [171]
+msg_171.c(17): assignment type mismatch (pointer != struct) [171]
+msg_171.c(18): assignment type mismatch (struct != pointer) [171]
diff -r 6564d2721169 -r 13e795f28c1f tests/usr.bin/xlint/lint1/msg_175.c
--- a/tests/usr.bin/xlint/lint1/msg_175.c       Sun Jan 24 15:59:35 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_175.c       Sun Jan 24 16:12:45 2021 +0000
@@ -1,7 +1,10 @@
-/*     $NetBSD: msg_175.c,v 1.1 2021/01/02 10:22:43 rillig Exp $       */
+/*     $NetBSD: msg_175.c,v 1.2 2021/01/24 16:12:45 rillig Exp $       */
 # 3 "msg_175.c"
 
 // Test for message: initialisation of an incomplete type [175]
 
-TODO: "Add example code that triggers the above message."
-TODO: "Add example code that almost triggers the above message."
+struct incomplete;                     /* expect: 233 */
+
+struct incomplete incomplete = {       /* expect: 175 */
+       "invalid"
+};                                     /* expect: 31 */
diff -r 6564d2721169 -r 13e795f28c1f tests/usr.bin/xlint/lint1/msg_175.exp
--- a/tests/usr.bin/xlint/lint1/msg_175.exp     Sun Jan 24 15:59:35 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_175.exp     Sun Jan 24 16:12:45 2021 +0000
@@ -1,1 +1,3 @@
-msg_175.c(6): syntax error ':' [249]
+msg_175.c(8): initialisation of an incomplete type [175]
+msg_175.c(10): incomplete structure or union incomplete: incomplete [31]
+msg_175.c(6): warning: struct incomplete never defined [233]
diff -r 6564d2721169 -r 13e795f28c1f tests/usr.bin/xlint/lint1/msg_177.c
--- a/tests/usr.bin/xlint/lint1/msg_177.c       Sun Jan 24 15:59:35 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_177.c       Sun Jan 24 16:12:45 2021 +0000
@@ -1,7 +1,12 @@
-/*     $NetBSD: msg_177.c,v 1.1 2021/01/02 10:22:43 rillig Exp $       */
+/*     $NetBSD: msg_177.c,v 1.2 2021/01/24 16:12:45 rillig Exp $       */
 # 3 "msg_177.c"
 
 // Test for message: non-constant initializer [177]
 
-TODO: "Add example code that triggers the above message."
-TODO: "Add example code that almost triggers the above message."
+extern int function(void);
+
+static const int not_a_constant = 13;
+
+const int var = not_a_constant;                        /* expect: 177 */
+
+const int calling_function = function();       /* expect: 177 */
diff -r 6564d2721169 -r 13e795f28c1f tests/usr.bin/xlint/lint1/msg_177.exp
--- a/tests/usr.bin/xlint/lint1/msg_177.exp     Sun Jan 24 15:59:35 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_177.exp     Sun Jan 24 16:12:45 2021 +0000
@@ -1,1 +1,2 @@
-msg_177.c(6): syntax error ':' [249]
+msg_177.c(10): non-constant initializer [177]
+msg_177.c(12): non-constant initializer [177]
diff -r 6564d2721169 -r 13e795f28c1f tests/usr.bin/xlint/lint1/msg_178.c
--- a/tests/usr.bin/xlint/lint1/msg_178.c       Sun Jan 24 15:59:35 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_178.c       Sun Jan 24 16:12:45 2021 +0000
@@ -1,7 +1,8 @@
-/*     $NetBSD: msg_178.c,v 1.1 2021/01/02 10:22:43 rillig Exp $       */
+/*     $NetBSD: msg_178.c,v 1.2 2021/01/24 16:12:45 rillig Exp $       */
 # 3 "msg_178.c"
 
 // Test for message: initializer does not fit [178]
 
-TODO: "Add example code that triggers the above message."
-TODO: "Add example code that almost triggers the above message."
+char fits = 123;
+
+char does_not_fit = 0x12345678;                /* expect: 178 */
diff -r 6564d2721169 -r 13e795f28c1f tests/usr.bin/xlint/lint1/msg_178.exp
--- a/tests/usr.bin/xlint/lint1/msg_178.exp     Sun Jan 24 15:59:35 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_178.exp     Sun Jan 24 16:12:45 2021 +0000
@@ -1,1 +1,1 @@
-msg_178.c(6): syntax error ':' [249]
+msg_178.c(8): warning: initializer does not fit [178]



Home | Main Index | Thread Index | Old Index