aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/validation/crazy02-not-so.c
blob: 19ee25299f745cc84d7e0f667bf850343a2a813a (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
int foo(int *ptr, int i)
{
	int *p;

	switch (i - i) {		// will be optimized to 0
	case 0:
		return 0;
	case 1:				// will be optimized away
		p = ptr;
		do {			// will be an unreachable loop
			*p++ = 123;
		} while (--i);
		break;
	}

	return 1;
}

int bar(int *ptr, int i)
{
	int *p;

	switch (i - i) {		// will be optimized to 0
	case 0:
		return 0;
	case 1:				// will be optimized away
					// p is uninitialized
		do {			// will be an unreachable loop
			*p++ = 123;
		} while (--i);
		break;
	}

	return 1;
}

/*
 * check-name: crazy02-not-so.c
 * check-command: sparse -Wno-decl $file
 */