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 tests/lint: add tests for several ...



details:   https://anonhg.NetBSD.org/src/rev/6ecc7ebed0d6
branches:  trunk
changeset: 1022972:6ecc7ebed0d6
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Aug 16 18:51:58 2021 +0000

description:
tests/lint: add tests for several messages about type mismatch

diffstat:

 tests/usr.bin/xlint/lint1/msg_123.c   |  11 ++++++++++-
 tests/usr.bin/xlint/lint1/msg_123.exp |   2 ++
 tests/usr.bin/xlint/lint1/msg_182.c   |  17 ++++++++++++++---
 tests/usr.bin/xlint/lint1/msg_182.exp |   3 ++-
 tests/usr.bin/xlint/lint1/msg_211.c   |  21 ++++++++++++++++++---
 tests/usr.bin/xlint/lint1/msg_211.exp |   3 ++-
 tests/usr.bin/xlint/lint1/msg_241.c   |  11 ++++++++++-
 tests/usr.bin/xlint/lint1/msg_241.exp |   2 ++
 tests/usr.bin/xlint/lint1/msg_303.c   |  22 ++++++++++++++++++----
 tests/usr.bin/xlint/lint1/msg_303.exp |   3 ++-
 tests/usr.bin/xlint/lint1/msg_304.c   |  20 ++++++++++++++++----
 tests/usr.bin/xlint/lint1/msg_304.exp |   3 ++-
 tests/usr.bin/xlint/lint1/msg_305.c   |  21 +++++++++++++++++----
 tests/usr.bin/xlint/lint1/msg_305.exp |   3 ++-
 tests/usr.bin/xlint/lint1/msg_346.c   |  10 +++++++++-
 tests/usr.bin/xlint/lint1/msg_346.exp |   1 +
 16 files changed, 127 insertions(+), 26 deletions(-)

diffs (264 lines):

diff -r c903c40cdcac -r 6ecc7ebed0d6 tests/usr.bin/xlint/lint1/msg_123.c
--- a/tests/usr.bin/xlint/lint1/msg_123.c       Mon Aug 16 18:51:03 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_123.c       Mon Aug 16 18:51:58 2021 +0000
@@ -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 @@
        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;
+}
diff -r c903c40cdcac -r 6ecc7ebed0d6 tests/usr.bin/xlint/lint1/msg_123.exp
--- a/tests/usr.bin/xlint/lint1/msg_123.exp     Mon Aug 16 18:51:03 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_123.exp     Mon Aug 16 18:51:58 2021 +0000
@@ -4,3 +4,5 @@
 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]
diff -r c903c40cdcac -r 6ecc7ebed0d6 tests/usr.bin/xlint/lint1/msg_182.c
--- a/tests/usr.bin/xlint/lint1/msg_182.c       Mon Aug 16 18:51:03 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_182.c       Mon Aug 16 18:51:58 2021 +0000
@@ -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 };
+}
diff -r c903c40cdcac -r 6ecc7ebed0d6 tests/usr.bin/xlint/lint1/msg_182.exp
--- a/tests/usr.bin/xlint/lint1/msg_182.exp     Mon Aug 16 18:51:03 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_182.exp     Mon Aug 16 18:51:58 2021 +0000
@@ -1,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]
diff -r c903c40cdcac -r 6ecc7ebed0d6 tests/usr.bin/xlint/lint1/msg_211.c
--- a/tests/usr.bin/xlint/lint1/msg_211.c       Mon Aug 16 18:51:03 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_211.c       Mon Aug 16 18:51:58 2021 +0000
@@ -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;
+}
diff -r c903c40cdcac -r 6ecc7ebed0d6 tests/usr.bin/xlint/lint1/msg_211.exp
--- a/tests/usr.bin/xlint/lint1/msg_211.exp     Mon Aug 16 18:51:03 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_211.exp     Mon Aug 16 18:51:58 2021 +0000
@@ -1,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]
diff -r c903c40cdcac -r 6ecc7ebed0d6 tests/usr.bin/xlint/lint1/msg_241.c
--- a/tests/usr.bin/xlint/lint1/msg_241.c       Mon Aug 16 18:51:03 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_241.c       Mon Aug 16 18:51:58 2021 +0000
@@ -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 @@
        /* 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;
+}
diff -r c903c40cdcac -r 6ecc7ebed0d6 tests/usr.bin/xlint/lint1/msg_241.exp
--- a/tests/usr.bin/xlint/lint1/msg_241.exp     Mon Aug 16 18:51:03 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_241.exp     Mon Aug 16 18:51:58 2021 +0000
@@ -29,3 +29,5 @@
 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]
diff -r c903c40cdcac -r 6ecc7ebed0d6 tests/usr.bin/xlint/lint1/msg_303.c
--- a/tests/usr.bin/xlint/lint1/msg_303.c       Mon Aug 16 18:51:03 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_303.c       Mon Aug 16 18:51:58 2021 +0000
@@ -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] */
+
+/* lint1-flags: -sw */
+
+void take_void_pointer(void *);
 
-TODO: "Add example code that triggers the above message." /* expect: 249 */
-TODO: "Add example code that almost triggers the above message."
+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;
+}
diff -r c903c40cdcac -r 6ecc7ebed0d6 tests/usr.bin/xlint/lint1/msg_303.exp
--- a/tests/usr.bin/xlint/lint1/msg_303.exp     Mon Aug 16 18:51:03 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_303.exp     Mon Aug 16 18:51:58 2021 +0000
@@ -1,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]
diff -r c903c40cdcac -r 6ecc7ebed0d6 tests/usr.bin/xlint/lint1/msg_304.c
--- a/tests/usr.bin/xlint/lint1/msg_304.c       Mon Aug 16 18:51:03 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_304.c       Mon Aug 16 18:51:58 2021 +0000
@@ -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] */
+
+/* lint1-flags: -sw */
+
+void take_void_pointer(void *);
+void take_function_pointer(void (*)(void));
 
-TODO: "Add example code that triggers the above message." /* expect: 249 */
-TODO: "Add example code that almost triggers the above message."
+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);
+}
diff -r c903c40cdcac -r 6ecc7ebed0d6 tests/usr.bin/xlint/lint1/msg_304.exp
--- a/tests/usr.bin/xlint/lint1/msg_304.exp     Mon Aug 16 18:51:03 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_304.exp     Mon Aug 16 18:51:58 2021 +0000
@@ -1,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]
diff -r c903c40cdcac -r 6ecc7ebed0d6 tests/usr.bin/xlint/lint1/msg_305.c
--- a/tests/usr.bin/xlint/lint1/msg_305.c       Mon Aug 16 18:51:03 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_305.c       Mon Aug 16 18:51:58 2021 +0000
@@ -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] */
+
+/* lint1-flags: -sw */
+
+void take_void_pointer(void *);
+
+typedef void (*function)(void);
 
-TODO: "Add example code that triggers the above message." /* expect: 249 */
-TODO: "Add example code that almost triggers the above message."
+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;
+}
diff -r c903c40cdcac -r 6ecc7ebed0d6 tests/usr.bin/xlint/lint1/msg_305.exp
--- a/tests/usr.bin/xlint/lint1/msg_305.exp     Mon Aug 16 18:51:03 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_305.exp     Mon Aug 16 18:51:58 2021 +0000
@@ -1,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]
diff -r c903c40cdcac -r 6ecc7ebed0d6 tests/usr.bin/xlint/lint1/msg_346.c
--- a/tests/usr.bin/xlint/lint1/msg_346.c       Mon Aug 16 18:51:03 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_346.c       Mon Aug 16 18:51:58 2021 +0000
@@ -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 @@
        /* 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());
+}
diff -r c903c40cdcac -r 6ecc7ebed0d6 tests/usr.bin/xlint/lint1/msg_346.exp
--- a/tests/usr.bin/xlint/lint1/msg_346.exp     Mon Aug 16 18:51:03 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_346.exp     Mon Aug 16 18:51:58 2021 +0000
@@ -6,3 +6,4 @@
 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]



Home | Main Index | Thread Index | Old Index