Module Name: src Committed By: rillig Date: Mon Aug 16 18:51:58 UTC 2021
Modified Files: src/tests/usr.bin/xlint/lint1: msg_123.c msg_123.exp msg_182.c msg_182.exp msg_211.c msg_211.exp msg_241.c msg_241.exp msg_303.c msg_303.exp msg_304.c msg_304.exp msg_305.c msg_305.exp msg_346.c msg_346.exp Log Message: tests/lint: add tests for several messages about type mismatch To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/msg_123.c \ src/tests/usr.bin/xlint/lint1/msg_182.c \ src/tests/usr.bin/xlint/lint1/msg_182.exp \ src/tests/usr.bin/xlint/lint1/msg_211.c \ src/tests/usr.bin/xlint/lint1/msg_211.exp \ src/tests/usr.bin/xlint/lint1/msg_303.c \ src/tests/usr.bin/xlint/lint1/msg_303.exp \ src/tests/usr.bin/xlint/lint1/msg_304.c \ src/tests/usr.bin/xlint/lint1/msg_304.exp \ src/tests/usr.bin/xlint/lint1/msg_305.c \ src/tests/usr.bin/xlint/lint1/msg_305.exp cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/msg_123.exp \ src/tests/usr.bin/xlint/lint1/msg_241.exp \ src/tests/usr.bin/xlint/lint1/msg_346.c \ src/tests/usr.bin/xlint/lint1/msg_346.exp cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/msg_241.c 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_123.c diff -u src/tests/usr.bin/xlint/lint1/msg_123.c:1.2 src/tests/usr.bin/xlint/lint1/msg_123.c:1.3 --- src/tests/usr.bin/xlint/lint1/msg_123.c:1.2 Sun Jan 17 16:00:16 2021 +++ src/tests/usr.bin/xlint/lint1/msg_123.c Mon Aug 16 18:51:58 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: msg_123.c,v 1.2 2021/01/17 16:00:16 rillig Exp $ */ +/* $NetBSD: msg_123.c,v 1.3 2021/08/16 18:51:58 rillig Exp $ */ # 3 "msg_123.c" // Test for message: illegal combination of %s (%s) and %s (%s), op %s [123] @@ -26,3 +26,12 @@ compare(_Bool b, int i, double d, const bad(p < d); /* expect: 107 */ ok(p < p); } + +void +cover_check_assign_types_compatible(int *int_pointer, int i) +{ + /* expect+1: warning: illegal combination of pointer (pointer to int) and integer (int), op = [123] */ + int_pointer = i; + /* expect+1: warning: illegal combination of integer (int) and pointer (pointer to int), op = [123] */ + i = int_pointer; +} Index: src/tests/usr.bin/xlint/lint1/msg_182.c diff -u src/tests/usr.bin/xlint/lint1/msg_182.c:1.2 src/tests/usr.bin/xlint/lint1/msg_182.c:1.3 --- src/tests/usr.bin/xlint/lint1/msg_182.c:1.2 Sun Feb 21 09:07:58 2021 +++ src/tests/usr.bin/xlint/lint1/msg_182.c Mon Aug 16 18:51:58 2021 @@ -1,7 +1,18 @@ -/* $NetBSD: msg_182.c,v 1.2 2021/02/21 09:07:58 rillig Exp $ */ +/* $NetBSD: msg_182.c,v 1.3 2021/08/16 18:51:58 rillig Exp $ */ # 3 "msg_182.c" // Test for message: incompatible pointer types (%s != %s) [182] -TODO: "Add example code that triggers the above message." /* expect: 249 */ -TODO: "Add example code that almost triggers the above message." +void * +return_discarding_volatile(volatile void *arg) +{ + /* expect+1: warning: incompatible pointer types (void != volatile void) [182] */ + return arg; +} + +void +init_discarding_volatile(volatile void *arg) +{ + /* expect+1: warning: incompatible pointer types (void != volatile void) [182] */ + void *array[] = { arg }; +} Index: src/tests/usr.bin/xlint/lint1/msg_182.exp diff -u src/tests/usr.bin/xlint/lint1/msg_182.exp:1.2 src/tests/usr.bin/xlint/lint1/msg_182.exp:1.3 --- src/tests/usr.bin/xlint/lint1/msg_182.exp:1.2 Sun Mar 21 20:45:00 2021 +++ src/tests/usr.bin/xlint/lint1/msg_182.exp Mon Aug 16 18:51:58 2021 @@ -1 +1,2 @@ -msg_182.c(6): error: syntax error ':' [249] +msg_182.c(10): warning: incompatible pointer types (void != volatile void) [182] +msg_182.c(17): warning: incompatible pointer types (void != volatile void) [182] Index: src/tests/usr.bin/xlint/lint1/msg_211.c diff -u src/tests/usr.bin/xlint/lint1/msg_211.c:1.2 src/tests/usr.bin/xlint/lint1/msg_211.c:1.3 --- src/tests/usr.bin/xlint/lint1/msg_211.c:1.2 Sun Feb 21 09:07:58 2021 +++ src/tests/usr.bin/xlint/lint1/msg_211.c Mon Aug 16 18:51:58 2021 @@ -1,7 +1,22 @@ -/* $NetBSD: msg_211.c,v 1.2 2021/02/21 09:07:58 rillig Exp $ */ +/* $NetBSD: msg_211.c,v 1.3 2021/08/16 18:51:58 rillig Exp $ */ # 3 "msg_211.c" // Test for message: return value type mismatch (%s) and (%s) [211] -TODO: "Add example code that triggers the above message." /* expect: 249 */ -TODO: "Add example code that almost triggers the above message." +struct str { + int member; +}; + +int +return_int(double dbl, void *ptr, struct str str) +{ + if (dbl > 0.0) + return dbl; + if (ptr != (void *)0) + /* expect+1: warning: illegal combination of integer (int) and pointer (pointer to void) [183] */ + return ptr; + if (str.member > 0) + /* expect+1: error: return value type mismatch (int) and (struct str) [211 */ + return str; + return 3; +} Index: src/tests/usr.bin/xlint/lint1/msg_211.exp diff -u src/tests/usr.bin/xlint/lint1/msg_211.exp:1.2 src/tests/usr.bin/xlint/lint1/msg_211.exp:1.3 --- src/tests/usr.bin/xlint/lint1/msg_211.exp:1.2 Sun Mar 21 20:45:00 2021 +++ src/tests/usr.bin/xlint/lint1/msg_211.exp Mon Aug 16 18:51:58 2021 @@ -1 +1,2 @@ -msg_211.c(6): error: syntax error ':' [249] +msg_211.c(17): warning: illegal combination of integer (int) and pointer (pointer to void) [183] +msg_211.c(20): error: return value type mismatch (int) and (struct str) [211] Index: src/tests/usr.bin/xlint/lint1/msg_303.c diff -u src/tests/usr.bin/xlint/lint1/msg_303.c:1.2 src/tests/usr.bin/xlint/lint1/msg_303.c:1.3 --- src/tests/usr.bin/xlint/lint1/msg_303.c:1.2 Sun Feb 21 09:07:58 2021 +++ src/tests/usr.bin/xlint/lint1/msg_303.c Mon Aug 16 18:51:58 2021 @@ -1,7 +1,21 @@ -/* $NetBSD: msg_303.c,v 1.2 2021/02/21 09:07:58 rillig Exp $ */ +/* $NetBSD: msg_303.c,v 1.3 2021/08/16 18:51:58 rillig Exp $ */ # 3 "msg_303.c" -// Test for message: ANSI C forbids conversion of %s to %s [303] +/* Test for message: ANSI C forbids conversion of %s to %s [303] */ -TODO: "Add example code that triggers the above message." /* expect: 249 */ -TODO: "Add example code that almost triggers the above message." +/* lint1-flags: -sw */ + +void take_void_pointer(void *); + +void * +to_void_pointer(void) +{ + /* expect+1: warning: ANSI C forbids conversion of function pointer to 'void *' [303] */ + return to_void_pointer; +} + +void (*to_function_pointer(void *arg))(void) +{ + /* expect+1: warning: ANSI C forbids conversion of 'void *' to function pointer [303] */ + return arg; +} Index: src/tests/usr.bin/xlint/lint1/msg_303.exp diff -u src/tests/usr.bin/xlint/lint1/msg_303.exp:1.2 src/tests/usr.bin/xlint/lint1/msg_303.exp:1.3 --- src/tests/usr.bin/xlint/lint1/msg_303.exp:1.2 Sun Mar 21 20:45:00 2021 +++ src/tests/usr.bin/xlint/lint1/msg_303.exp Mon Aug 16 18:51:58 2021 @@ -1 +1,2 @@ -msg_303.c(6): error: syntax error ':' [249] +msg_303.c(14): warning: ANSI C forbids conversion of function pointer to 'void *' [303] +msg_303.c(20): warning: ANSI C forbids conversion of 'void *' to function pointer [303] Index: src/tests/usr.bin/xlint/lint1/msg_304.c diff -u src/tests/usr.bin/xlint/lint1/msg_304.c:1.2 src/tests/usr.bin/xlint/lint1/msg_304.c:1.3 --- src/tests/usr.bin/xlint/lint1/msg_304.c:1.2 Sun Feb 21 09:07:58 2021 +++ src/tests/usr.bin/xlint/lint1/msg_304.c Mon Aug 16 18:51:58 2021 @@ -1,7 +1,19 @@ -/* $NetBSD: msg_304.c,v 1.2 2021/02/21 09:07:58 rillig Exp $ */ +/* $NetBSD: msg_304.c,v 1.3 2021/08/16 18:51:58 rillig Exp $ */ # 3 "msg_304.c" -// Test for message: ANSI C forbids conversion of %s to %s, arg #%d [304] +/* Test for message: ANSI C forbids conversion of %s to %s, arg #%d [304] */ -TODO: "Add example code that triggers the above message." /* expect: 249 */ -TODO: "Add example code that almost triggers the above message." +/* lint1-flags: -sw */ + +void take_void_pointer(void *); +void take_function_pointer(void (*)(void)); + +void +caller(void *arg) +{ + /* expect+1: warning: ANSI C forbids conversion of function pointer to 'void *', arg #1 [304] */ + take_void_pointer(caller); + + /* expect+1: warning: ANSI C forbids conversion of 'void *' to function pointer, arg #1 [304] */ + take_function_pointer(arg); +} Index: src/tests/usr.bin/xlint/lint1/msg_304.exp diff -u src/tests/usr.bin/xlint/lint1/msg_304.exp:1.2 src/tests/usr.bin/xlint/lint1/msg_304.exp:1.3 --- src/tests/usr.bin/xlint/lint1/msg_304.exp:1.2 Sun Mar 21 20:45:00 2021 +++ src/tests/usr.bin/xlint/lint1/msg_304.exp Mon Aug 16 18:51:58 2021 @@ -1 +1,2 @@ -msg_304.c(6): error: syntax error ':' [249] +msg_304.c(15): warning: ANSI C forbids conversion of function pointer to 'void *', arg #1 [304] +msg_304.c(18): warning: ANSI C forbids conversion of 'void *' to function pointer, arg #1 [304] Index: src/tests/usr.bin/xlint/lint1/msg_305.c diff -u src/tests/usr.bin/xlint/lint1/msg_305.c:1.2 src/tests/usr.bin/xlint/lint1/msg_305.c:1.3 --- src/tests/usr.bin/xlint/lint1/msg_305.c:1.2 Sun Feb 21 09:07:58 2021 +++ src/tests/usr.bin/xlint/lint1/msg_305.c Mon Aug 16 18:51:58 2021 @@ -1,7 +1,20 @@ -/* $NetBSD: msg_305.c,v 1.2 2021/02/21 09:07:58 rillig Exp $ */ +/* $NetBSD: msg_305.c,v 1.3 2021/08/16 18:51:58 rillig Exp $ */ # 3 "msg_305.c" -// Test for message: ANSI C forbids conversion of %s to %s, op %s [305] +/* Test for message: ANSI C forbids conversion of %s to %s, op %s [305] */ -TODO: "Add example code that triggers the above message." /* expect: 249 */ -TODO: "Add example code that almost triggers the above message." +/* lint1-flags: -sw */ + +void take_void_pointer(void *); + +typedef void (*function)(void); + +void +caller(void **void_pointer, function *function_pointer) +{ + /* expect+1: warning: ANSI C forbids conversion of function pointer to 'void *', op = [305] */ + *void_pointer = *function_pointer; + + /* expect+1: warning: ANSI C forbids conversion of 'void *' to function pointer, op = [305] */ + *function_pointer = *void_pointer; +} Index: src/tests/usr.bin/xlint/lint1/msg_305.exp diff -u src/tests/usr.bin/xlint/lint1/msg_305.exp:1.2 src/tests/usr.bin/xlint/lint1/msg_305.exp:1.3 --- src/tests/usr.bin/xlint/lint1/msg_305.exp:1.2 Sun Mar 21 20:45:00 2021 +++ src/tests/usr.bin/xlint/lint1/msg_305.exp Mon Aug 16 18:51:58 2021 @@ -1 +1,2 @@ -msg_305.c(6): error: syntax error ':' [249] +msg_305.c(16): warning: ANSI C forbids conversion of function pointer to 'void *', op = [305] +msg_305.c(19): warning: ANSI C forbids conversion of 'void *' to function pointer, op = [305] Index: src/tests/usr.bin/xlint/lint1/msg_123.exp diff -u src/tests/usr.bin/xlint/lint1/msg_123.exp:1.3 src/tests/usr.bin/xlint/lint1/msg_123.exp:1.4 --- src/tests/usr.bin/xlint/lint1/msg_123.exp:1.3 Sun Mar 21 20:44:59 2021 +++ src/tests/usr.bin/xlint/lint1/msg_123.exp Mon Aug 16 18:51:58 2021 @@ -4,3 +4,5 @@ msg_123.c(23): error: operands of '<' ha msg_123.c(24): warning: illegal combination of pointer (pointer to const char) and integer (_Bool), op < [123] msg_123.c(25): warning: illegal combination of pointer (pointer to const char) and integer (int), op < [123] msg_123.c(26): error: operands of '<' have incompatible types (pointer != double) [107] +msg_123.c(34): warning: illegal combination of pointer (pointer to int) and integer (int), op = [123] +msg_123.c(36): warning: illegal combination of integer (int) and pointer (pointer to int), op = [123] Index: src/tests/usr.bin/xlint/lint1/msg_241.exp diff -u src/tests/usr.bin/xlint/lint1/msg_241.exp:1.3 src/tests/usr.bin/xlint/lint1/msg_241.exp:1.4 --- src/tests/usr.bin/xlint/lint1/msg_241.exp:1.3 Sat Feb 27 15:29:15 2021 +++ src/tests/usr.bin/xlint/lint1/msg_241.exp Mon Aug 16 18:51:58 2021 @@ -29,3 +29,5 @@ msg_241.c(69): warning: dubious operatio msg_241.c(70): warning: dubious operation on enum, op ^= [241] msg_241.c(71): warning: dubious operation on enum, op |= [241] msg_241.c(74): warning: dubious operation on enum, op &= [241] +msg_241.c(82): warning: dubious operation on enum, op * [241] +msg_241.c(82): warning: combination of 'enum color' and 'int', op > [242] Index: src/tests/usr.bin/xlint/lint1/msg_346.c diff -u src/tests/usr.bin/xlint/lint1/msg_346.c:1.3 src/tests/usr.bin/xlint/lint1/msg_346.c:1.4 --- src/tests/usr.bin/xlint/lint1/msg_346.c:1.3 Sun Aug 15 14:26:39 2021 +++ src/tests/usr.bin/xlint/lint1/msg_346.c Mon Aug 16 18:51:58 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: msg_346.c,v 1.3 2021/08/15 14:26:39 rillig Exp $ */ +/* $NetBSD: msg_346.c,v 1.4 2021/08/16 18:51:58 rillig Exp $ */ # 3 "msg_346.c" // Test for message: call to '%s' effectively discards 'const' from argument [346] @@ -51,3 +51,11 @@ all_functions(void) /* expect+1: warning: call to 'strstr' effectively discards 'const' from argument [346] */ take_char_ptr(strstr("string", "c")); } + +void +edge_cases(void) +{ + /* No arguments, to cover the 'an == NULL' in is_first_arg_const. */ + /* expect+1: error: argument mismatch: 0 arg passed, 2 expected [150] */ + take_char_ptr(strchr()); +} Index: src/tests/usr.bin/xlint/lint1/msg_346.exp diff -u src/tests/usr.bin/xlint/lint1/msg_346.exp:1.3 src/tests/usr.bin/xlint/lint1/msg_346.exp:1.4 --- src/tests/usr.bin/xlint/lint1/msg_346.exp:1.3 Sun Aug 15 14:26:39 2021 +++ src/tests/usr.bin/xlint/lint1/msg_346.exp Mon Aug 16 18:51:58 2021 @@ -6,3 +6,4 @@ msg_346.c(46): warning: call to 'strchr' msg_346.c(48): warning: call to 'strpbrk' effectively discards 'const' from argument [346] msg_346.c(50): warning: call to 'strrchr' effectively discards 'const' from argument [346] msg_346.c(52): warning: call to 'strstr' effectively discards 'const' from argument [346] +msg_346.c(60): error: argument mismatch: 0 arg passed, 2 expected [150] Index: src/tests/usr.bin/xlint/lint1/msg_241.c diff -u src/tests/usr.bin/xlint/lint1/msg_241.c:1.4 src/tests/usr.bin/xlint/lint1/msg_241.c:1.5 --- src/tests/usr.bin/xlint/lint1/msg_241.c:1.4 Sat Feb 27 15:29:15 2021 +++ src/tests/usr.bin/xlint/lint1/msg_241.c Mon Aug 16 18:51:58 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: msg_241.c,v 1.4 2021/02/27 15:29:15 rillig Exp $ */ +/* $NetBSD: msg_241.c,v 1.5 2021/08/16 18:51:58 rillig Exp $ */ # 3 "msg_241.c" // Test for message: dubious operation on enum, op %s [241] @@ -73,3 +73,12 @@ example(void) /* The cast to unsigned is required by GCC at WARNS=6. */ c &= ~(unsigned)GREEN; /* expect: 241 */ } + +void +cover_typeok_enum(enum color c, int i) +{ + /* expect+2: warning: dubious operation on enum, op * [241] */ + /* expect+1: warning: combination of 'enum color' and 'int', op > [242] */ + if (c * i > 5) + return; +}