aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/validation/sizeof-function.c
blob: 8ff67f2149981de7a9c13c912b0525df3ec207a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
extern int fun(void);
extern int (*ptr)(void);

static inline int inl(int *a)
{
	return *a + 1;
}


int test(void);
int test(void)
{
	unsigned int s = 0;

	// OK
	s += sizeof &fun;
	s += sizeof  ptr;
	s += sizeof &ptr;
	s += sizeof &inl;

	// KO
	s += sizeof  fun;
	s += sizeof *fun;

	s += sizeof *ptr;

	s += sizeof  inl;
	s += sizeof *inl;

	s += sizeof  __builtin_trap;
	s += sizeof *__builtin_trap;

	return s;
}

/*
 * check-name: sizeof-function
 * check-command: sparse -Wpointer-arith -Wno-decl $file
 *
 * check-error-start
sizeof-function.c:22:14: warning: expression using sizeof on a function
sizeof-function.c:23:14: warning: expression using sizeof on a function
sizeof-function.c:25:14: warning: expression using sizeof on a function
sizeof-function.c:27:14: warning: expression using sizeof on a function
sizeof-function.c:28:14: warning: expression using sizeof on a function
sizeof-function.c:30:14: warning: expression using sizeof on a function
sizeof-function.c:31:14: warning: expression using sizeof on a function
 * check-error-end
 */