tests/lint: extend test for returning local address

This commit is contained in:
rillig 2023-04-15 10:53:59 +00:00
parent 4f718dd96a
commit e7d3b23c6b
1 changed files with 25 additions and 10 deletions

View File

@ -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 *