Pick three bugfixes from next branch to trunk for inclusion in 4.5.0 RC2, as discusse...
[sdcc.git] / sdcc / support / regression / tests / gcc-torture-execute-pr33870.c
blob83927cf969957ffd79c0e62a6227d774a8d34aa3
1 /*
2 pr33870.c from the execute part of the gcc torture tests.
3 */
5 #include <testfwk.h>
7 #ifdef __SDCC
8 #pragma std_c99
9 #endif
11 #include <string.h>
13 typedef struct PgHdr PgHdr;
14 typedef unsigned char u8;
15 struct PgHdr {
16 unsigned int pgno;
17 PgHdr *pNextHash, *pPrevHash;
18 PgHdr *pNextFree, *pPrevFree;
19 PgHdr *pNextAll;
20 u8 inJournal;
21 short int nRef;
22 PgHdr *pDirty, *pPrevDirty;
23 unsigned int notUsed;
26 #if !defined(__SDCC_mcs51) && !defined(__SDCC_pdk14) && !defined (__SDCC_pdk15) // Lack of memory
27 static inline PgHdr *merge_pagelist(PgHdr *pA, PgHdr *pB)
29 PgHdr result;
30 PgHdr *pTail;
31 pTail = &result;
32 while( pA && pB ){
33 if( pA->pgno<pB->pgno ){
34 pTail->pDirty = pA;
35 pTail = pA;
36 pA = pA->pDirty;
37 }else{
38 pTail->pDirty = pB;
39 pTail = pB;
40 pB = pB->pDirty;
43 if( pA ){
44 pTail->pDirty = pA;
45 }else if( pB ){
46 pTail->pDirty = pB;
47 }else{
48 pTail->pDirty = 0;
50 return result.pDirty;
53 PgHdr *sort_pagelist(PgHdr *pIn)
55 PgHdr *a[25], *p;
56 int i;
57 memset (a, 0, sizeof (a));
58 while( pIn ){
59 p = pIn;
60 pIn = p->pDirty;
61 p->pDirty = 0;
62 for(i=0; i<25 -1; i++){
63 if( a[i]==0 ){
64 a[i] = p;
65 break;
66 }else{
67 p = merge_pagelist(a[i], p);
68 a[i] = 0;
71 if( i==25 -1 ){
72 a[i] = merge_pagelist(a[i], p);
75 p = a[0];
76 for(i=1; i<25; i++){
77 p = merge_pagelist (p, a[i]);
79 return p;
81 #endif
83 void
84 testTortureExecute (void)
86 #if !defined(__SDCC_mcs51) && !defined(__SDCC_pdk14) && !defined (__SDCC_pdk15) // Lack of memory
87 PgHdr a[5];
88 PgHdr *p;
89 a[0].pgno = 5;
90 a[0].pDirty = &a[1];
91 a[1].pgno = 4;
92 a[1].pDirty = &a[2];
93 a[2].pgno = 1;
94 a[2].pDirty = &a[3];
95 a[3].pgno = 3;
96 a[3].pDirty = 0;
97 p = sort_pagelist (&a[0]);
98 if (p->pDirty == p)
99 ASSERT (0);
100 return;
101 #endif