drd: Add a consistency check
[valgrind.git] / memcheck / tests / origin4-many.c
blob6bb850ecd588392fdefc9b8645773d9b00c7386c
2 /* This test case was originally written by Nicholas Nethercote. */
7 /* For 'x', we get an uninitialised error for every addition to it. For
8 each one we get one origin identified, even though most of them involve
9 more than one undefined value. */
11 /* For 'y', we get a single uninitialised value error, on the value handed
12 to the exit() system call. Fair enough.
14 An important question is: which of the origins is reported in the
15 error? Well, considering that (1) m_execontext allocates ECUs
16 (origin tags, basically) in increasing order, and (2) memcheck's
17 instrumentation for dealing with two uninitialised sources simply
18 involves 'max'-ing the otags, we expect the origin to be attributed
19 to the last of the 8 mallocs, that is, to p_ui8.
22 #include <stdlib.h>
23 #include <stdio.h>
25 static int x = 0;
26 static int y = 0;
28 int main(void)
30 // Do them separately rather than all in one array so they all have
31 // different origins.
32 int* p_ui1 = malloc(sizeof(int));
33 int* p_ui2 = malloc(sizeof(int));
34 int* p_ui3 = malloc(sizeof(int));
35 int* p_ui4 = malloc(sizeof(int));
36 int* p_ui5 = malloc(sizeof(int));
37 int* p_ui6 = malloc(sizeof(int));
38 int* p_ui7 = malloc(sizeof(int));
39 int* p_ui8 = malloc(sizeof(int));
40 int ui1 = *p_ui1;
41 int ui2 = *p_ui2;
42 int ui3 = *p_ui3;
43 int ui4 = *p_ui4;
44 int ui5 = *p_ui5;
45 int ui6 = *p_ui6;
46 int ui7 = *p_ui7;
47 int ui8 = *p_ui8;
49 #define P printf("huh?")
51 x += (ui1 == 0x12345678 ? P : 23);
52 x += (ui1 +ui2 == 0x12345678 ? P : 24);
53 x += (ui1 +ui2 +ui3 == 0x12345678 ? P : 25);
54 x += (ui1 +ui2 +ui3 +ui4 == 0x12345678 ? P : 26);
55 x += (ui1 +ui2 +ui3 +ui4 +ui5 == 0x12345678 ? P : 27);
56 x += (ui1 +ui2 +ui3 +ui4 +ui5 +ui6 == 0x12345678 ? P : 28);
57 x += (ui1 +ui2 +ui3 +ui4 +ui5 +ui6 +ui7 == 0x12345678 ? P : 29);
58 x += (ui1 +ui2 +ui3 +ui4 +ui5 +ui6 +ui7 +ui8 == 0x12345678 ? P : 30);
60 y += (ui1 );
61 y += (ui1 +ui2 );
62 y += (ui1 +ui2 +ui3 );
63 y += (ui1 +ui2 +ui3 +ui4 );
64 y += (ui1 +ui2 +ui3 +ui4 +ui5 );
65 y += (ui1 +ui2 +ui3 +ui4 +ui5 +ui6 );
66 y += (ui1 +ui2 +ui3 +ui4 +ui5 +ui6 +ui7 );
67 y += (ui1 +ui2 +ui3 +ui4 +ui5 +ui6 +ui7 +ui8);
69 return y & 1;