Some consistency changes to library & headers flags.
[splint-patched.git] / test / alias3.c
blobcee156e20367dac66484bac1c02b62e6383f3c1f
1 /*
2 ** tests aliasing of arrays, structs and unions
3 */
5 # include "alias3.lh"
7 st gst;
8 ut *gu;
10 void model (int ia[])
12 int *ip;
14 ip = &(ia[6]);
15 *ip = 3;
16 gst.a = 3; /* 1. Suspect modification of gst.a */
17 gu->a = 5; /* 2. Suspect modification of gu->a */
20 void modst (st s1)
22 s1.a = 3;
23 *(s1.b) = 6;
26 void modu (ut *u)
28 u->a = 5;
31 int f (int ia[], st s1, ut *u1)
33 int *ip;
34 st sl;
35 ut *ul;
37 ip = &(ia[3]);
38 *ip = 7; /* modifies ia[3] */
40 ip = &(ia[*ip]);
42 *ip = 8; /* modifies ia[?] */
44 model(ia); /* modifies ia[6] */
45 ip = ia;
46 model(ip); /* modifies ia[6] */
48 s1.a = 3; /* okay */
49 *(s1.b) = 7; /* modifies *(s1.b) */
51 sl = s1; /* okay (sl is NOT an alias for s1) */
52 modst(sl); /* was: does not modify anything --- structure is passed by value */
53 /* NOT TRUE: does modify sl since *s1.b is the same reference */
54 sl.a = 3; /* okay */
55 ip = s1.b; /* okay, ip aliases s1.b */
56 *(s1.b) = 3; /* modifies s1.b */
57 *ip = 6; /* modifies s1.b */
58 *(sl.b) = 3; /* okay */
60 ul = u1; /* ul aliases u1 */
61 modu(ul); /* okay */
62 ul->a = 3; /* modifies u1->a */
63 sl = ul->s; /* okay */
64 sl.a = 3; /* okay */
65 *(sl.b) = 6; /* modifies *(u1->s.b) through alias */
66 return 5;