Pick three bugfixes from next branch to trunk for inclusion in 4.5.0 RC2, as discusse...
[sdcc.git] / sdcc / support / regression / tests / mm-pnvi-ae-udi-pointer_offset_xor_auto.c
blob2db2c06ab0bef04b2cfd62b38bcca69d5af80905
1 // Derived from test case from the memory model study group of SC22 WG14
2 // For this test, behaviour is defined in the PNVI-ae-udi memory model.
4 /*
5 Original test copyright (c) 2012-2016 David Chisnall, Kayvan Memarian, and Peter Sewell.
7 Permission to use, copy, modify, and/or distribute this software for
8 any purpose with or without fee is hereby granted, provided that the
9 above copyright notice and this permission notice appear in all
10 copies.
12 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 PERFORMANCE OF THIS SOFTWARE.
22 // Adapted for SDCC by Philipp Klaus Krause in 2020.
24 #include <testfwk.h>
26 #pragma disable_warning 127
28 #include <stdint.h>
30 void
31 testMM(void)
33 int x=1, y=2;
34 int *p = &x;
35 int *q = &y;
36 uintptr_t i = (uintptr_t) p;
37 uintptr_t j = (uintptr_t) q;
38 uintptr_t k = i ^ j;
39 uintptr_t l = k ^ i;
40 int *r = (int *)l;
41 // are r and q now equivalent?
42 *r = 11; // does this have defined behaviour?
43 _Bool b = (r==q);
44 if (b)
45 ASSERT (*r == y);