Module Name: src Committed By: rillig Date: Sun Jan 24 16:12:45 UTC 2021
Modified Files: src/tests/usr.bin/xlint/lint1: msg_168.c msg_168.exp msg_171.c msg_171.exp msg_175.c msg_175.exp msg_177.c msg_177.exp msg_178.c msg_178.exp Log Message: lint: add tests for a few messages To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/xlint/lint1/msg_168.c \ src/tests/usr.bin/xlint/lint1/msg_168.exp \ src/tests/usr.bin/xlint/lint1/msg_171.c \ src/tests/usr.bin/xlint/lint1/msg_171.exp \ src/tests/usr.bin/xlint/lint1/msg_175.c \ src/tests/usr.bin/xlint/lint1/msg_175.exp \ src/tests/usr.bin/xlint/lint1/msg_177.c \ src/tests/usr.bin/xlint/lint1/msg_177.exp \ src/tests/usr.bin/xlint/lint1/msg_178.c \ src/tests/usr.bin/xlint/lint1/msg_178.exp Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/tests/usr.bin/xlint/lint1/msg_168.c diff -u src/tests/usr.bin/xlint/lint1/msg_168.c:1.1 src/tests/usr.bin/xlint/lint1/msg_168.c:1.2 --- src/tests/usr.bin/xlint/lint1/msg_168.c:1.1 Sat Jan 2 10:22:43 2021 +++ src/tests/usr.bin/xlint/lint1/msg_168.c Sun Jan 24 16:12:45 2021 @@ -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 */ +} Index: src/tests/usr.bin/xlint/lint1/msg_168.exp diff -u src/tests/usr.bin/xlint/lint1/msg_168.exp:1.1 src/tests/usr.bin/xlint/lint1/msg_168.exp:1.2 --- src/tests/usr.bin/xlint/lint1/msg_168.exp:1.1 Sat Jan 2 10:22:43 2021 +++ src/tests/usr.bin/xlint/lint1/msg_168.exp Sun Jan 24 16:12:45 2021 @@ -1 +1 @@ -msg_168.c(6): syntax error ':' [249] +msg_168.c(28): warning: array subscript cannot be > 19: 20 [168] Index: src/tests/usr.bin/xlint/lint1/msg_171.c diff -u src/tests/usr.bin/xlint/lint1/msg_171.c:1.1 src/tests/usr.bin/xlint/lint1/msg_171.c:1.2 --- src/tests/usr.bin/xlint/lint1/msg_171.c:1.1 Sat Jan 2 10:22:43 2021 +++ src/tests/usr.bin/xlint/lint1/msg_171.c Sun Jan 24 16:12:45 2021 @@ -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 */ +} Index: src/tests/usr.bin/xlint/lint1/msg_171.exp diff -u src/tests/usr.bin/xlint/lint1/msg_171.exp:1.1 src/tests/usr.bin/xlint/lint1/msg_171.exp:1.2 --- src/tests/usr.bin/xlint/lint1/msg_171.exp:1.1 Sat Jan 2 10:22:43 2021 +++ src/tests/usr.bin/xlint/lint1/msg_171.exp Sun Jan 24 16:12:45 2021 @@ -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] Index: src/tests/usr.bin/xlint/lint1/msg_175.c diff -u src/tests/usr.bin/xlint/lint1/msg_175.c:1.1 src/tests/usr.bin/xlint/lint1/msg_175.c:1.2 --- src/tests/usr.bin/xlint/lint1/msg_175.c:1.1 Sat Jan 2 10:22:43 2021 +++ src/tests/usr.bin/xlint/lint1/msg_175.c Sun Jan 24 16:12:45 2021 @@ -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 */ Index: src/tests/usr.bin/xlint/lint1/msg_175.exp diff -u src/tests/usr.bin/xlint/lint1/msg_175.exp:1.1 src/tests/usr.bin/xlint/lint1/msg_175.exp:1.2 --- src/tests/usr.bin/xlint/lint1/msg_175.exp:1.1 Sat Jan 2 10:22:43 2021 +++ src/tests/usr.bin/xlint/lint1/msg_175.exp Sun Jan 24 16:12:45 2021 @@ -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] Index: src/tests/usr.bin/xlint/lint1/msg_177.c diff -u src/tests/usr.bin/xlint/lint1/msg_177.c:1.1 src/tests/usr.bin/xlint/lint1/msg_177.c:1.2 --- src/tests/usr.bin/xlint/lint1/msg_177.c:1.1 Sat Jan 2 10:22:43 2021 +++ src/tests/usr.bin/xlint/lint1/msg_177.c Sun Jan 24 16:12:45 2021 @@ -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 */ Index: src/tests/usr.bin/xlint/lint1/msg_177.exp diff -u src/tests/usr.bin/xlint/lint1/msg_177.exp:1.1 src/tests/usr.bin/xlint/lint1/msg_177.exp:1.2 --- src/tests/usr.bin/xlint/lint1/msg_177.exp:1.1 Sat Jan 2 10:22:43 2021 +++ src/tests/usr.bin/xlint/lint1/msg_177.exp Sun Jan 24 16:12:45 2021 @@ -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] Index: src/tests/usr.bin/xlint/lint1/msg_178.c diff -u src/tests/usr.bin/xlint/lint1/msg_178.c:1.1 src/tests/usr.bin/xlint/lint1/msg_178.c:1.2 --- src/tests/usr.bin/xlint/lint1/msg_178.c:1.1 Sat Jan 2 10:22:43 2021 +++ src/tests/usr.bin/xlint/lint1/msg_178.c Sun Jan 24 16:12:45 2021 @@ -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 */ Index: src/tests/usr.bin/xlint/lint1/msg_178.exp diff -u src/tests/usr.bin/xlint/lint1/msg_178.exp:1.1 src/tests/usr.bin/xlint/lint1/msg_178.exp:1.2 --- src/tests/usr.bin/xlint/lint1/msg_178.exp:1.1 Sat Jan 2 10:22:43 2021 +++ src/tests/usr.bin/xlint/lint1/msg_178.exp Sun Jan 24 16:12:45 2021 @@ -1 +1 @@ -msg_178.c(6): syntax error ':' [249] +msg_178.c(8): warning: initializer does not fit [178]