1
2#include <stdlib.h>
3
4int main ( void )
5{
6   int* x3 = malloc(3);    float         f,   *f3   = malloc(3);
7   int* x4 = malloc(4);    double        d,   *d7   = malloc(7);
8   int* x5 = malloc(5);    long long int lli, *lli7 = malloc(7);
9   int* x6 = malloc(6);    char          c,   *c0   = malloc(0);
10   int* x7 = malloc(7);    short int     s,   *s1   = malloc(1);
11   int  x;
12   int* y4 = malloc(4);
13   int* y5 = malloc(5);
14   int* y6 = malloc(6);
15   int* y7 = malloc(7);
16
17   #define ADDB(ptr, n)  ((int*)(((unsigned long)(ptr)) + (n)))
18
19   // All these overrun by a single byte;  the reads are happening at
20   // different alignments.
21   x = * ADDB(x3,0);    // ok if --partial-loads-ok=yes
22   x = * ADDB(x4,1);
23   x = * ADDB(x5,2);
24   x = * ADDB(x6,3);
25   x = * ADDB(x7,4);    // ok if --partial-loads-ok=yes
26
27   // These are fine
28   x = * ADDB(y4,0);
29   x = * ADDB(y5,1);
30   x = * ADDB(y6,2);
31   x = * ADDB(y7,3);
32
33   // These are all bad, at different points along
34   x = * ADDB(x3,-1);   // before
35   x = * ADDB(x3, 0);   // inside      // ok if --partial-loads-ok=yes ...
36   x = * ADDB(x3, 1);   // inside      // ... but only on 32 bit platforms
37   x = * ADDB(x3, 2);   // inside      // ... ditto
38   x = * ADDB(x3, 3);   // after
39
40   // These are all bad
41   f   = * f3;    // ok if --partial-loads-ok=yes  // ... ditto
42   d   = * d7;
43   lli = * lli7;  // ok if --partial-loads-ok=yes  see XXX below
44   c   = * c0;
45   s   = * s1;
46
47   return 0;
48}
49
50/* Note re XXX, this gives different behaviour on 32 and 64 bit
51platforms, because on 64-bit it's one load whereas as on 32 bit
52platforms it's necessarily 2 32-bit loads, and the first one is OK. */
53