struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / bug-3127.c
blob04d19cfcee8c015eefab69eeb7308c0e4b112acb
1 /* bug-3126.c
2 32-bit addition used a register that held already-computed result bytes as temporary for upper bytes of literal operand.
3 */
5 #include <testfwk.h>
7 #include <limits.h>
8 #include <stdarg.h>
10 #ifndef __SDCC_pdk14 // Lack of memory
12 #if ULONG_MAX == 0xffffffff
13 typedef unsigned long UINT4;
14 #elif UINT_MAX == 0xffffffff
15 typedef unsigned UINT4;
16 #elif USHRT_MAX == 0xffffffff
17 #else
18 #error No suitable UINT4 type
19 #endif
21 void check(const char *format, ...)
23 va_list arg;
24 static int i;
26 va_start (arg, format);
28 ASSERT(va_arg(arg, UINT4) == (i ? 0xd76ae33a : 0x67452301));
29 ASSERT(va_arg(arg, UINT4) == 0xefcdab89);
30 ASSERT(va_arg(arg, UINT4) == 0x98badcfe);
31 ASSERT(va_arg(arg, UINT4) == (i > 1 ? 0xc8d2cb98 : 0x10325476));
33 i++;
35 va_end (arg);
38 void func(UINT4 *buf, UINT4 *in)
40 UINT4 a = buf[0], b = buf[1], c = buf[2], d = buf[3];
42 check("%lx %lx %lx %lx\n",a,b,c,d);
44 {( a ) += ((( ( b ) ) & ( ( c ) )) | ((~ ( b ) ) & ( ( d ) ))) + ( in[ 0] ) + (UINT4)( 3614090360 );} // Bug affected addition here
46 check("%lx %lx %lx %lx\n",a,b,c,d);
48 {( d ) += ((( ( a ) ) & ( ( b ) )) | ((~ ( a ) ) & ( ( c ) ))) + ( in[ 1] ) + (UINT4)( 3905402710 ); }
50 check("%lx %lx %lx %lx\n",a,b,c,d);
52 #endif
54 void
55 testBug (void)
57 #ifndef __SDCC_pdk14 // Lack of memory
58 UINT4 buf[] = {0x67452301,0xefcdab89,0x98badcfe,0x10325476};
59 UINT4 in[] = {0x3ec3,0x0,0x3dc3,0x0,0x3ac3};
61 func(buf, in);
62 #endif