145
|
1 #include <stdio.h>
|
|
2 #include <stdlib.h>
|
|
3 #include "analyzer-decls.h"
|
|
4
|
|
5 extern void foo ();
|
|
6 extern void bar ();
|
|
7
|
|
8 void test_1 (int i)
|
|
9 {
|
|
10 if (i == 42)
|
|
11 abort ();
|
|
12
|
|
13 __analyzer_eval (i != 42); /* { dg-warning "TRUE" } */
|
|
14 }
|
|
15
|
|
16 void test_2 (int i)
|
|
17 {
|
|
18 if (i)
|
|
19 foo ();
|
|
20 else
|
|
21 bar ();
|
|
22
|
|
23 foo ();
|
|
24
|
|
25 if (i)
|
|
26 foo ();
|
|
27 else
|
|
28 abort ();
|
|
29
|
|
30 __analyzer_eval (i != 0); /* { dg-warning "TRUE" } */
|
|
31 }
|
|
32
|
|
33 /**************************************************************************/
|
|
34
|
|
35 void calls_abort (const char *msg)
|
|
36 {
|
|
37 fprintf (stderr, "%s", msg);
|
|
38 abort ();
|
|
39 }
|
|
40
|
|
41 void test_3 (void *ptr)
|
|
42 {
|
|
43 if (!ptr)
|
|
44 calls_abort ("ptr was NULL");
|
|
45
|
|
46 __analyzer_eval (ptr != 0); /* { dg-warning "TRUE" } */
|
|
47 }
|
|
48
|
|
49 /**************************************************************************/
|
|
50
|
|
51 extern void marked_noreturn (const char *msg)
|
|
52 __attribute__ ((__noreturn__));
|
|
53
|
|
54 void test_4 (void *ptr)
|
|
55 {
|
|
56 if (!ptr)
|
|
57 marked_noreturn ("ptr was NULL");
|
|
58
|
|
59 __analyzer_eval (ptr != 0); /* { dg-warning "TRUE" } */
|
|
60 }
|
|
61
|
|
62 /**************************************************************************/
|
|
63
|
|
64 /* Verify that we discover conditions from assertions if the assert macro
|
|
65 isn't disabled, and that it has its failure-handler labelled with
|
|
66 __attribute__ ((__noreturn__)).
|
|
67 This attribute isn't present for all implementations of <assert.h>, so
|
|
68 we have to test the idea using our own assert macro. */
|
|
69
|
|
70 extern void my_assert_fail (const char *expr, const char *file, int line)
|
|
71 __attribute__ ((__noreturn__));
|
|
72
|
|
73 #define MY_ASSERT(EXPR) \
|
|
74 do { if (!(EXPR)) my_assert_fail (#EXPR, __FILE__, __LINE__); } while (0)
|
|
75
|
|
76 void test_5 (int i)
|
|
77 {
|
|
78 MY_ASSERT (i < 10);
|
|
79 __analyzer_eval (i < 10); /* { dg-warning "TRUE" } */
|
|
80 }
|