From d14f4870a8069ca446c0528a39b75e7d081ba3d5 Mon Sep 17 00:00:00 2001 From: Zeex Date: Fri, 1 May 2015 16:13:16 +0600 Subject: [PATCH] Fix 4d array initialization adjust_indirectiontables() generated wrong values for certain array dimensions in 4d arrays. Fixes #43 --- source/compiler/sc1.c | 79 ++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 42 deletions(-) diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index 084816e..a7af6bb 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -2321,52 +2321,47 @@ static cell calc_arraysize(int dim[],int numdim,int cur) return newsize; } -static cell adjust_indirectiontables(int dim[],int numdim,int cur,cell increment, - int startlit,constvalue *lastdim,int *skipdim) +static void adjust_indirectiontables(int dim[],int numdim,int startlit, + constvalue *lastdim,int *skipdim) { static int base; - int d; + int cur; + int i,d; cell accum; + cell size; - assert(cur>=0 && cur=0); assert(cur>0 && startlit==-1 || startlit>=0 && startlit<=litidx); - if (cur==0) - base=startlit; - if (cur==numdim-1) - return 0; - /* 2 or more dimensions left, fill in an indirection vector */ - if (dim[cur+1]>0) { - for (d=0; dnext; d<*skipdim; d++,ld=ld->next) { - assert(ld!=NULL); + base=startlit; + size=1; + for (cur=0; cur0) { + for (d=0; dnext; d<*skipdim; d++,ld=ld->next) { + assert(ld!=NULL); + } /* for */ + for (d=0; dname,NULL,16)==d); + litq[base++]=((size+i)*dim[cur]+accum) * sizeof(cell); + accum+=ld->value-1; + *skipdim+=1; + ld=ld->next; + } /* for */ + } /* if */ } /* for */ - for (d=0; dname,NULL,16)==d); - litq[base++]=(dim[cur]+accum+increment) * sizeof(cell); - accum+=ld->value-1; - *skipdim+=1; - ld=ld->next; - } /* for */ - } /* if */ - /* create the indirection tables for the lower level */ - if (cur+20; tablesize--) litadd(0); if (dim[numdim-1]!=0) /* error 9 has already been given */ - adjust_indirectiontables(dim,numdim,0,0,curlit,NULL,NULL); + adjust_indirectiontables(dim,numdim,curlit,NULL,NULL); } /* if */ return; } /* if */ @@ -2473,7 +2468,7 @@ static void initials(int ident,int tag,cell *size,int dim[],int numdim, * of the array and we can properly adjust the indirection vectors */ if (err==0) - adjust_indirectiontables(dim,numdim,0,0,curlit,&lastdim,&skipdim); + adjust_indirectiontables(dim,numdim,curlit,&lastdim,&skipdim); delete_consttable(&lastdim); /* clear list of minor dimension sizes */ } /* if */ } /* if */