origin4-many.c revision e739ac0589b4fb43561f801c4faba8c1b89f8680
1
2/* This test case was originally written by Nicholas Nethercote. */
3
4
5
6
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. */
10
11/* For 'y', we get a single uninitialised value error, on the value handed
12   to the exit() system call.  Fair enough.
13
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.
20*/
21
22#include <stdlib.h>
23#include <stdio.h>
24
25static int x = 0;
26static int y = 0;
27
28int main(void)
29{
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;
48
49#define P   printf("huh?")
50
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);
59
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);
68
69   return y & 1;
70}
71