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: extend test for return...



details:   https://anonhg.NetBSD.org/src/rev/af1e9cd816ab
branches:  trunk
changeset: 374256:af1e9cd816ab
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Apr 15 10:53:59 2023 +0000

description:
tests/lint: extend test for returning local address

diffstat:

 tests/usr.bin/xlint/lint1/msg_302.c |  35 +++++++++++++++++++++++++----------
 1 files changed, 25 insertions(+), 10 deletions(-)

diffs (51 lines):

diff -r 70cee793e5b8 -r af1e9cd816ab tests/usr.bin/xlint/lint1/msg_302.c
--- a/tests/usr.bin/xlint/lint1/msg_302.c       Sat Apr 15 10:32:46 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_302.c       Sat Apr 15 10:53:59 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_302.c,v 1.4 2022/06/22 19:23:18 rillig Exp $       */
+/*     $NetBSD: msg_302.c,v 1.5 2023/04/15 10:53:59 rillig Exp $       */
 # 3 "msg_302.c"
 
 // Test for message: '%s' returns pointer to automatic object [302]
@@ -19,17 +19,32 @@ return_local(void)
 }
 
 void *
-return_local_array(_Bool cond)
+return_local_array(int x)
 {
-       int local[5];
-       int *p = local;
+       int local[5], *indirect = local;
 
-       /* XXX: lint doesn't track this indirection, but Clang-tidy does. */
-       if (cond)
-               return p;
-
-       /* expect+1: warning: 'return_local_array' returns pointer to automatic object [302] */
-       return local + 5;
+       switch (x) {
+       case 0:
+               /* expect+1: warning: 'return_local_array' returns pointer to automatic object [302] */
+               return local;
+       case 1:
+               /* expect+1: warning: 'return_local_array' returns pointer to automatic object [302] */
+               return &local[3];
+       case 2:
+               /* expect+1: warning: 'return_local_array' returns pointer to automatic object [302] */
+               return 5 + local;
+       case 3:
+               /* expect+1: warning: 'return_local_array' returns pointer to automatic object [302] */
+               return local + 5;
+       case 4:
+               /* XXX: lint only checks '+' but not '-'. */
+               return local - -3;
+       case 5:
+               /* XXX: lint doesn't track this indirection, but Clang-tidy does. */
+               return indirect;
+       default:
+               return "OK";
+       }
 }
 
 void *



Home | Main Index | Thread Index | Old Index