Pārlūkot izejas kodu

* always specify an explicit alignment for tgobj.gettemp (so e.g.
shortstring temps don't get maximum alignment)
* changed some gettemptyed() calls into gettemp() calls (gettemptyped
means that this temp can only be used for temps of that type,
which is necessary for refcounted types but not for floats)

git-svn-id: trunk@12036 -

Jonas Maebe 16 gadi atpakaļ
vecāks
revīzija
718694d1d6

+ 2 - 2
compiler/cgobj.pas

@@ -2534,7 +2534,7 @@ implementation
             LOC_REGISTER,LOC_CREGISTER:
             LOC_REGISTER,LOC_CREGISTER:
               begin
               begin
                 { paramfpu_ref does the check_simpe_location check here if necessary }
                 { paramfpu_ref does the check_simpe_location check here if necessary }
-                tg.GetTemp(list,TCGSize2Size[size],tt_normal,ref);
+                tg.GetTemp(list,TCGSize2Size[size],TCGSize2Size[size],tt_normal,ref);
                 a_loadfpu_reg_ref(list,size,size,r,ref);
                 a_loadfpu_reg_ref(list,size,size,r,ref);
                 a_paramfpu_ref(list,size,ref,cgpara);
                 a_paramfpu_ref(list,size,ref,cgpara);
                 tg.Ungettemp(list,ref);
                 tg.Ungettemp(list,ref);
@@ -3670,7 +3670,7 @@ implementation
 
 
         if size>0 then
         if size>0 then
           begin
           begin
-            tg.GetTemp(list,size,tt_noreuse,current_procinfo.save_regs_ref);
+            tg.GetTemp(list,size,sizeof(aint),tt_noreuse,current_procinfo.save_regs_ref);
             include(current_procinfo.flags,pi_has_saved_regs);
             include(current_procinfo.flags,pi_has_saved_regs);
 
 
             { Copy registers to temp }
             { Copy registers to temp }

+ 2 - 1
compiler/globals.pas

@@ -265,7 +265,8 @@ interface
      { Memory sizes }
      { Memory sizes }
        heapsize,
        heapsize,
        stacksize,
        stacksize,
-       jmp_buf_size : longint;
+       jmp_buf_size,
+       jmp_buf_align : longint;
 
 
 {$Ifdef EXTDEBUG}
 {$Ifdef EXTDEBUG}
      { parameter switches }
      { parameter switches }

+ 1 - 1
compiler/ncgbas.pas

@@ -429,7 +429,7 @@ interface
         else
         else
           begin
           begin
             location_reset(tempinfo^.location,LOC_REFERENCE,def_cgsize(tempinfo^.typedef));
             location_reset(tempinfo^.location,LOC_REFERENCE,def_cgsize(tempinfo^.typedef));
-            tg.GetTemp(current_asmdata.CurrAsmList,size,tempinfo^.temptype,tempinfo^.location.reference);
+            tg.GetTemp(current_asmdata.CurrAsmList,size,tempinfo^.typedef.alignment,tempinfo^.temptype,tempinfo^.location.reference);
           end;
           end;
         include(tempinfo^.flags,ti_valid);
         include(tempinfo^.flags,ti_valid);
       end;
       end;

+ 1 - 1
compiler/ncgcal.pas

@@ -555,7 +555,7 @@ implementation
                     structs with up to 16 bytes are returned in registers }
                     structs with up to 16 bytes are returned in registers }
                   if cgsize in [OS_128,OS_S128] then
                   if cgsize in [OS_128,OS_S128] then
                     begin
                     begin
-                      tg.GetTemp(current_asmdata.CurrAsmList,16,tt_normal,ref);
+                      tg.GetTemp(current_asmdata.CurrAsmList,16,8,tt_normal,ref);
                       location_reset(location,LOC_REFERENCE,OS_NO);
                       location_reset(location,LOC_REFERENCE,OS_NO);
                       location.reference:=ref;
                       location.reference:=ref;
                       cg.a_load_reg_ref(current_asmdata.CurrAsmList,OS_64,OS_64,procdefinition.funcretloc[callerside].register,ref);
                       cg.a_load_reg_ref(current_asmdata.CurrAsmList,OS_64,OS_64,procdefinition.funcretloc[callerside].register,ref);

+ 3 - 3
compiler/ncgcnv.pas

@@ -243,7 +243,7 @@ interface
          case tstringdef(resultdef).stringtype of
          case tstringdef(resultdef).stringtype of
            st_shortstring :
            st_shortstring :
              begin
              begin
-               tg.GetTemp(current_asmdata.CurrAsmList,256,tt_normal,location.reference);
+               tg.GetTemp(current_asmdata.CurrAsmList,256,1,tt_normal,location.reference);
                cg.a_load_loc_ref(current_asmdata.CurrAsmList,left.location.size,left.location,
                cg.a_load_loc_ref(current_asmdata.CurrAsmList,left.location.size,left.location,
                  location.reference);
                  location.reference);
                location_freetemp(current_asmdata.CurrAsmList,left.location);
                location_freetemp(current_asmdata.CurrAsmList,left.location);
@@ -272,7 +272,7 @@ interface
              if (left.location.loc in [LOC_CREFERENCE,LOC_REFERENCE]) then
              if (left.location.loc in [LOC_CREFERENCE,LOC_REFERENCE]) then
                location_force_fpureg(current_asmdata.CurrAsmList,left.location,false);
                location_force_fpureg(current_asmdata.CurrAsmList,left.location,false);
              { round them down to the proper precision }
              { round them down to the proper precision }
-             tg.gettemp(current_asmdata.currasmlist,resultdef.size,tt_normal,tr);
+             tg.gettemp(current_asmdata.currasmlist,resultdef.size,resultdef.alignment,tt_normal,tr);
              cg.a_loadfpu_reg_ref(current_asmdata.CurrAsmList,left.location.size,location.size,left.location.register,tr);
              cg.a_loadfpu_reg_ref(current_asmdata.CurrAsmList,left.location.size,location.size,left.location.register,tr);
              location_reset(left.location,LOC_REFERENCE,location.size);
              location_reset(left.location,LOC_REFERENCE,location.size);
              left.location.reference:=tr;
              left.location.reference:=tr;
@@ -368,7 +368,7 @@ interface
     var r:Treference;
     var r:Treference;
 
 
     begin
     begin
-      tg.gettemp(current_asmdata.currasmlist,2*sizeof(puint),tt_normal,r);
+      tg.gettemp(current_asmdata.currasmlist,2*sizeof(puint),sizeof(puint),tt_normal,r);
       location_reset(location,LOC_REFERENCE,OS_NO);
       location_reset(location,LOC_REFERENCE,OS_NO);
       location.reference:=r;
       location.reference:=r;
       cg.a_load_const_ref(current_asmdata.currasmlist,OS_ADDR,0,r);
       cg.a_load_const_ref(current_asmdata.currasmlist,OS_ADDR,0,r);

+ 1 - 1
compiler/ncgflw.pas

@@ -1323,7 +1323,7 @@ implementation
            end
            end
          else
          else
            begin
            begin
-             tg.GetTemp(current_asmdata.CurrAsmList,sizeof(pint),tt_normal,exceptref);
+             tg.GetTemp(current_asmdata.CurrAsmList,sizeof(pint),sizeof(pint),tt_normal,exceptref);
              cg.a_load_reg_ref(current_asmdata.CurrAsmList,OS_ADDR,OS_ADDR,NR_FUNCTION_RESULT_REG,exceptref);
              cg.a_load_reg_ref(current_asmdata.CurrAsmList,OS_ADDR,OS_ADDR,NR_FUNCTION_RESULT_REG,exceptref);
            end;
            end;
 
 

+ 20 - 13
compiler/ncgld.pas

@@ -432,7 +432,7 @@ implementation
                       {$else}
                       {$else}
                          internalerror(20020520);
                          internalerror(20020520);
                       {$endif} {$endif}
                       {$endif} {$endif}
-                      tg.GetTemp(current_asmdata.CurrAsmList,2*sizeof(pint),tt_normal,location.reference);
+                      tg.GetTemp(current_asmdata.CurrAsmList,2*sizeof(pint),sizeof(pint),tt_normal,location.reference);
                       secondpass(left);
                       secondpass(left);
 
 
                       { load class instance/classrefdef address }
                       { load class instance/classrefdef address }
@@ -757,7 +757,7 @@ implementation
                             { convert an extended into a double/single, since sse   }
                             { convert an extended into a double/single, since sse   }
                             { doesn't support extended)                             }
                             { doesn't support extended)                             }
                             r:=cg.getfpuregister(current_asmdata.CurrAsmList,right.location.size);
                             r:=cg.getfpuregister(current_asmdata.CurrAsmList,right.location.size);
-                            tg.gettemp(current_asmdata.CurrAsmList,left.resultdef.size,tt_normal,href);
+                            tg.gettemp(current_asmdata.CurrAsmList,left.resultdef.size,left.resultdef.alignment,tt_normal,href);
                             cg.a_loadfpu_ref_reg(current_asmdata.CurrAsmList,right.location.size,right.location.size,right.location.reference,r);
                             cg.a_loadfpu_ref_reg(current_asmdata.CurrAsmList,right.location.size,right.location.size,right.location.reference,r);
                             cg.a_loadfpu_reg_ref(current_asmdata.CurrAsmList,right.location.size,left.location.size,r,href);
                             cg.a_loadfpu_reg_ref(current_asmdata.CurrAsmList,right.location.size,left.location.size,r,href);
                             if releaseright then
                             if releaseright then
@@ -834,7 +834,7 @@ implementation
                         begin
                         begin
                           { perform size conversion if needed (the mm-code cannot convert an   }
                           { perform size conversion if needed (the mm-code cannot convert an   }
                           { extended into a double/single, since sse doesn't support extended) }
                           { extended into a double/single, since sse doesn't support extended) }
-                          tg.gettemp(current_asmdata.CurrAsmList,left.resultdef.size,tt_normal,href);
+                          tg.gettemp(current_asmdata.CurrAsmList,left.resultdef.size,left.resultdef.alignment,tt_normal,href);
                           cg.a_loadfpu_reg_ref(current_asmdata.CurrAsmList,right.location.size,left.location.size,right.location.register,href);
                           cg.a_loadfpu_reg_ref(current_asmdata.CurrAsmList,right.location.size,left.location.size,right.location.register,href);
                           location_reset(right.location,LOC_REFERENCE,left.location.size);
                           location_reset(right.location,LOC_REFERENCE,left.location.size);
                           right.location.reference:=href;
                           right.location.reference:=href;
@@ -951,31 +951,38 @@ implementation
         hp    : tarrayconstructornode;
         hp    : tarrayconstructornode;
         href  : treference;
         href  : treference;
         lt    : tdef;
         lt    : tdef;
-        vaddr : boolean;
-        vtype : longint;
-        freetemp,
-        dovariant : boolean;
-        elesize : longint;
-        tmpreg  : tregister;
         paraloc : tcgparalocation;
         paraloc : tcgparalocation;
         otlabel,
         otlabel,
         oflabel : tasmlabel;
         oflabel : tasmlabel;
+        vtype : longint;
+        elesize,
+        elealign : longint;
+        tmpreg  : tregister;
+        vaddr : boolean;
+        freetemp,
+        dovariant : boolean;
       begin
       begin
         if is_packed_array(resultdef) then
         if is_packed_array(resultdef) then
           internalerror(200608042);
           internalerror(200608042);
         dovariant:=(nf_forcevaria in flags) or is_variant_array(resultdef);
         dovariant:=(nf_forcevaria in flags) or is_variant_array(resultdef);
         if dovariant then
         if dovariant then
-          elesize:=sizeof(pint)+sizeof(pint)
+          begin
+            elesize:=sizeof(pint)+sizeof(pint);
+            elealign:=sizeof(pint);
+          end
         else
         else
-          elesize:=tarraydef(resultdef).elesize;
+          begin
+            elesize:=tarraydef(resultdef).elesize;
+            elealign:=tarraydef(resultdef).elementdef.alignment;
+          end;
         location_reset(location,LOC_CREFERENCE,OS_NO);
         location_reset(location,LOC_CREFERENCE,OS_NO);
         fillchar(paraloc,sizeof(paraloc),0);
         fillchar(paraloc,sizeof(paraloc),0);
         { Allocate always a temp, also if no elements are required, to
         { Allocate always a temp, also if no elements are required, to
           be sure that location is valid (PFV) }
           be sure that location is valid (PFV) }
          if tarraydef(resultdef).highrange=-1 then
          if tarraydef(resultdef).highrange=-1 then
-           tg.GetTemp(current_asmdata.CurrAsmList,elesize,tt_normal,location.reference)
+           tg.GetTemp(current_asmdata.CurrAsmList,elesize,elealign,tt_normal,location.reference)
          else
          else
-           tg.GetTemp(current_asmdata.CurrAsmList,(tarraydef(resultdef).highrange+1)*elesize,tt_normal,location.reference);
+           tg.GetTemp(current_asmdata.CurrAsmList,(tarraydef(resultdef).highrange+1)*elesize,resultdef.alignment,tt_normal,location.reference);
          href:=location.reference;
          href:=location.reference;
         { Process nodes in array constructor }
         { Process nodes in array constructor }
         hp:=self;
         hp:=self;

+ 1 - 1
compiler/ncgmat.pas

@@ -149,7 +149,7 @@ implementation
         { get a temporary memory reference to store the floating
         { get a temporary memory reference to store the floating
           point value
           point value
         }
         }
-        tg.gettemp(current_asmdata.CurrAsmList,tcgsize2size[_size],tt_normal,href);
+        tg.gettemp(current_asmdata.CurrAsmList,tcgsize2size[_size],tcgsize2size[_size],tt_normal,href);
         { store the floating point value in the temporary memory area }
         { store the floating point value in the temporary memory area }
         cg.a_loadfpu_reg_ref(current_asmdata.CurrAsmList,_size,_size,r,href);
         cg.a_loadfpu_reg_ref(current_asmdata.CurrAsmList,_size,_size,r,href);
         { only single and double ieee are supported, for little endian
         { only single and double ieee are supported, for little endian

+ 1 - 1
compiler/ncgopt.pas

@@ -90,7 +90,7 @@ begin
   if not(tg.istemp(left.location.reference) and
   if not(tg.istemp(left.location.reference) and
          (tg.sizeoftemp(current_asmdata.CurrAsmList,left.location.reference) = 256)) then
          (tg.sizeoftemp(current_asmdata.CurrAsmList,left.location.reference) = 256)) then
     begin
     begin
-       tg.Gettemp(current_asmdata.CurrAsmList,256,tt_normal,href);
+       tg.Gettemp(current_asmdata.CurrAsmList,256,1,tt_normal,href);
        cg.g_copyshortstring(current_asmdata.CurrAsmList,left.location.reference,href,255);
        cg.g_copyshortstring(current_asmdata.CurrAsmList,left.location.reference,href,255);
        location_freetemp(current_asmdata.CurrAsmList,left.location);
        location_freetemp(current_asmdata.CurrAsmList,left.location);
        { return temp reference }
        { return temp reference }

+ 11 - 10
compiler/ncgutil.pas

@@ -361,10 +361,11 @@ implementation
           begin
           begin
             srsym:=search_system_type('JMP_BUF');
             srsym:=search_system_type('JMP_BUF');
             jmp_buf_size:=srsym.typedef.size;
             jmp_buf_size:=srsym.typedef.size;
+            jmp_buf_align:=srsym.typedef.alignment;
           end;
           end;
-        tg.GetTemp(list,EXCEPT_BUF_SIZE,tt_persistent,t.envbuf);
-        tg.GetTemp(list,jmp_buf_size,tt_persistent,t.jmpbuf);
-        tg.GetTemp(list,sizeof(pint),tt_persistent,t.reasonbuf);
+        tg.GetTemp(list,EXCEPT_BUF_SIZE,sizeof(pint),tt_persistent,t.envbuf);
+        tg.GetTemp(list,jmp_buf_size,jmp_buf_align,tt_persistent,t.jmpbuf);
+        tg.GetTemp(list,sizeof(pint),sizeof(pint),tt_persistent,t.reasonbuf);
       end;
       end;
 
 
 
 
@@ -682,7 +683,7 @@ implementation
             { if it's in an mm register, store to memory first }
             { if it's in an mm register, store to memory first }
             if (l.loc in [LOC_MMREGISTER,LOC_CMMREGISTER]) then
             if (l.loc in [LOC_MMREGISTER,LOC_CMMREGISTER]) then
               begin
               begin
-                tg.GetTemp(list,tcgsize2size[l.size],tt_normal,href);
+                tg.GetTemp(list,tcgsize2size[l.size],tcgsize2size[l.size],tt_normal,href);
                 cg.a_loadmm_reg_ref(list,l.size,l.size,l.register,href,mms_movescalar);
                 cg.a_loadmm_reg_ref(list,l.size,l.size,l.register,href,mms_movescalar);
                 location_reset(l,LOC_REFERENCE,l.size);
                 location_reset(l,LOC_REFERENCE,l.size);
                 l.reference:=href;
                 l.reference:=href;
@@ -707,7 +708,7 @@ implementation
             { if it's in an fpu register, store to memory first }
             { if it's in an fpu register, store to memory first }
             if (l.loc in [LOC_FPUREGISTER,LOC_CFPUREGISTER]) then
             if (l.loc in [LOC_FPUREGISTER,LOC_CFPUREGISTER]) then
               begin
               begin
-                tg.GetTemp(list,tcgsize2size[l.size],tt_normal,href);
+                tg.GetTemp(list,tcgsize2size[l.size],tcgsize2size[l.size],tt_normal,href);
                 cg.a_loadfpu_reg_ref(list,l.size,l.size,l.register,href);
                 cg.a_loadfpu_reg_ref(list,l.size,l.size,l.register,href);
                 location_reset(l,LOC_REFERENCE,l.size);
                 location_reset(l,LOC_REFERENCE,l.size);
                 l.reference:=href;
                 l.reference:=href;
@@ -771,7 +772,7 @@ implementation
           LOC_FPUREGISTER,
           LOC_FPUREGISTER,
           LOC_CFPUREGISTER :
           LOC_CFPUREGISTER :
             begin
             begin
-              tg.GetTemp(list,TCGSize2Size[l.size],tt_normal,r);
+              tg.GetTemp(list,TCGSize2Size[l.size],TCGSize2Size[l.size],tt_normal,r);
               cg.a_loadfpu_reg_ref(list,l.size,l.size,l.register,r);
               cg.a_loadfpu_reg_ref(list,l.size,l.size,l.register,r);
               location_reset(l,LOC_REFERENCE,l.size);
               location_reset(l,LOC_REFERENCE,l.size);
               l.reference:=r;
               l.reference:=r;
@@ -779,7 +780,7 @@ implementation
           LOC_MMREGISTER,
           LOC_MMREGISTER,
           LOC_CMMREGISTER:
           LOC_CMMREGISTER:
             begin
             begin
-              tg.GetTemp(list,TCGSize2Size[l.size],tt_normal,r);
+              tg.GetTemp(list,TCGSize2Size[l.size],TCGSize2Size[l.size],tt_normal,r);
               cg.a_loadmm_reg_ref(list,l.size,l.size,l.register,r,mms_movescalar);
               cg.a_loadmm_reg_ref(list,l.size,l.size,l.register,r,mms_movescalar);
               location_reset(l,LOC_REFERENCE,l.size);
               location_reset(l,LOC_REFERENCE,l.size);
               l.reference:=r;
               l.reference:=r;
@@ -788,7 +789,7 @@ implementation
           LOC_REGISTER,
           LOC_REGISTER,
           LOC_CREGISTER :
           LOC_CREGISTER :
             begin
             begin
-              tg.GetTemp(list,TCGSize2Size[l.size],tt_normal,r);
+              tg.GetTemp(list,TCGSize2Size[l.size],TCGSize2Size[l.size],tt_normal,r);
 {$ifndef cpu64bitalu}
 {$ifndef cpu64bitalu}
               if l.size in [OS_64,OS_S64] then
               if l.size in [OS_64,OS_S64] then
                 cg64.a_load64_loc_ref(list,l,r)
                 cg64.a_load64_loc_ref(list,l,r)
@@ -803,7 +804,7 @@ implementation
           LOC_SUBSETREF,
           LOC_SUBSETREF,
           LOC_CSUBSETREF:
           LOC_CSUBSETREF:
             begin
             begin
-              tg.GetTemp(list,TCGSize2Size[l.size],tt_normal,r);
+              tg.GetTemp(list,TCGSize2Size[l.size],TCGSize2Size[l.size],tt_normal,r);
               cg.a_load_loc_ref(list,l.size,l,r);
               cg.a_load_loc_ref(list,l.size,l,r);
               location_reset(l,LOC_REFERENCE,l.size);
               location_reset(l,LOC_REFERENCE,l.size);
               l.reference:=r;
               l.reference:=r;
@@ -1828,7 +1829,7 @@ implementation
                   { Arm and Sparc passes floats in int registers, when loading to fpu register
                   { Arm and Sparc passes floats in int registers, when loading to fpu register
                     we need a temp }
                     we need a temp }
                   sizeleft := TCGSize2Size[currpara.initialloc.size];
                   sizeleft := TCGSize2Size[currpara.initialloc.size];
-                  tg.GetTemp(list,sizeleft,tt_normal,tempref);
+                  tg.GetTemp(list,sizeleft,sizeleft,tt_normal,tempref);
                   href:=tempref;
                   href:=tempref;
                   while assigned(paraloc) do
                   while assigned(paraloc) do
                     begin
                     begin

+ 1 - 1
compiler/paramgr.pas

@@ -340,7 +340,7 @@ implementation
                 newparaloc^.register:=cg.getmmregister(list,paraloc^.size);
                 newparaloc^.register:=cg.getmmregister(list,paraloc^.size);
               LOC_REFERENCE :
               LOC_REFERENCE :
                 begin
                 begin
-                  tg.gettemp(list,len,tt_persistent,href);
+                  tg.gettemp(list,len,cgpara.alignment,tt_persistent,href);
                   newparaloc^.reference.index:=href.base;
                   newparaloc^.reference.index:=href.base;
                   newparaloc^.reference.offset:=href.offset;
                   newparaloc^.reference.offset:=href.offset;
                 end;
                 end;

+ 1 - 1
compiler/powerpc/nppccnv.pas

@@ -144,7 +144,7 @@ implementation
         { stw R3,disp+4(R1)   # store lower half            }
         { stw R3,disp+4(R1)   # store lower half            }
         { lfd FR1,disp(R1)    # float load double of value  }
         { lfd FR1,disp(R1)    # float load double of value  }
         { fsub FR1,FR1,FR2    # subtract 0x4330000000000000 }
         { fsub FR1,FR1,FR2    # subtract 0x4330000000000000 }
-        tg.Gettemp(current_asmdata.CurrAsmList,8,tt_normal,ref);
+        tg.Gettemp(current_asmdata.CurrAsmList,8,8,tt_normal,ref);
 
 
         signed := is_signed(left.resultdef);
         signed := is_signed(left.resultdef);
 
 

+ 2 - 2
compiler/powerpc64/nppccnv.pas

@@ -125,7 +125,7 @@ begin
   { fcfid frD,frD # point integer (no round) }
   { fcfid frD,frD # point integer (no round) }
   { fmadd frD,frC,frT1,frD # (2^32)*high + low }
   { fmadd frD,frC,frT1,frD # (2^32)*high + low }
   { # (only add can round) }
   { # (only add can round) }
-  tg.Gettemp(current_asmdata.CurrAsmList, 8, tt_normal, disp);
+  tg.Gettemp(current_asmdata.CurrAsmList, 8, 8, tt_normal, disp);
 
 
   { do the signed case for everything but 64 bit unsigned integers }
   { do the signed case for everything but 64 bit unsigned integers }
   signed := (left.location.size <> OS_64);
   signed := (left.location.size <> OS_64);
@@ -143,7 +143,7 @@ begin
       internalerror(200110011);
       internalerror(200110011);
 
 
     // allocate second temp memory
     // allocate second temp memory
-    tg.Gettemp(current_asmdata.CurrAsmList, 8, tt_normal, disp2);
+    tg.Gettemp(current_asmdata.CurrAsmList, 8, 8, tt_normal, disp2);
   end;
   end;
 
 
   if not(left.location.loc in [LOC_REGISTER,LOC_CREGISTER,LOC_REFERENCE,LOC_CREFERENCE]) then
   if not(left.location.loc in [LOC_REGISTER,LOC_CREGISTER,LOC_REFERENCE,LOC_CREFERENCE]) then

+ 4 - 2
compiler/rgobj.pas

@@ -1718,6 +1718,7 @@ unit rgobj;
         spill_temps : ^Tspill_temp_list;
         spill_temps : ^Tspill_temp_list;
         supreg : tsuperregister;
         supreg : tsuperregister;
         templist : TAsmList;
         templist : TAsmList;
+        size: ptrint;
       begin
       begin
         spill_registers:=false;
         spill_registers:=false;
         live_registers.clear;
         live_registers.clear;
@@ -1739,9 +1740,10 @@ unit rgobj;
               {Get a temp for the spilled register, the size must at least equal a complete register,
               {Get a temp for the spilled register, the size must at least equal a complete register,
                take also care of the fact that subreg can be larger than a single register like doubles
                take also care of the fact that subreg can be larger than a single register like doubles
                that occupy 2 registers }
                that occupy 2 registers }
+              size:=max(tcgsize2size[reg_cgsize(newreg(regtype,t,R_SUBWHOLE))],
+                             tcgsize2size[reg_cgsize(newreg(regtype,t,reginfo[t].subreg))]);
               tg.gettemp(templist,
               tg.gettemp(templist,
-                         max(tcgsize2size[reg_cgsize(newreg(regtype,t,R_SUBWHOLE))],
-                             tcgsize2size[reg_cgsize(newreg(regtype,t,reginfo[t].subreg))]),
+                         size,size,
                          tt_noreuse,spill_temps^[t]);
                          tt_noreuse,spill_temps^[t]);
             end;
             end;
         list.insertlistafter(headertai,templist);
         list.insertlistafter(headertai,templist);

+ 1 - 1
compiler/sparc/cgcpu.pas

@@ -423,7 +423,7 @@ implementation
       var
       var
         href : treference;
         href : treference;
       begin
       begin
-        tg.GetTemp(list,TCGSize2Size[size],tt_normal,href);
+        tg.GetTemp(list,TCGSize2Size[size],TCGSize2Size[size],tt_normal,href);
         a_loadfpu_reg_ref(list,size,size,r,href);
         a_loadfpu_reg_ref(list,size,size,r,href);
         a_paramfpu_ref(list,size,href,paraloc);
         a_paramfpu_ref(list,size,href,paraloc);
         tg.Ungettemp(list,href);
         tg.Ungettemp(list,href);

+ 5 - 4
compiler/tgobj.pas

@@ -80,7 +80,7 @@ unit tgobj;
           }
           }
           procedure setfirsttemp(l : longint);
           procedure setfirsttemp(l : longint);
 
 
-          procedure gettemp(list: TAsmList; size : longint;temptype:ttemptype;out ref : treference);
+          procedure gettemp(list: TAsmList; size, alignment : longint;temptype:ttemptype;out ref : treference);
           procedure gettemptyped(list: TAsmList; def:tdef;temptype:ttemptype;out ref : treference);
           procedure gettemptyped(list: TAsmList; def:tdef;temptype:ttemptype;out ref : treference);
           procedure ungettemp(list: TAsmList; const ref : treference);
           procedure ungettemp(list: TAsmList; const ref : treference);
 
 
@@ -491,17 +491,17 @@ implementation
       end;
       end;
 
 
 
 
-    procedure ttgobj.gettemp(list: TAsmList; size : longint;temptype:ttemptype;out ref : treference);
+    procedure ttgobj.gettemp(list: TAsmList; size, alignment : longint;temptype:ttemptype;out ref : treference);
       var
       var
         varalign : shortint;
         varalign : shortint;
       begin
       begin
-        varalign:=size_2_align(size);
-        varalign:=used_align(varalign,current_settings.alignment.localalignmin,current_settings.alignment.localalignmax);
+        varalign:=used_align(alignment,current_settings.alignment.localalignmin,current_settings.alignment.localalignmax);
         { can't use reference_reset_base, because that will let tgobj depend
         { can't use reference_reset_base, because that will let tgobj depend
           on cgobj (PFV) }
           on cgobj (PFV) }
         fillchar(ref,sizeof(ref),0);
         fillchar(ref,sizeof(ref),0);
         ref.base:=current_procinfo.framepointer;
         ref.base:=current_procinfo.framepointer;
         ref.offset:=alloctemp(list,size,varalign,temptype,nil);
         ref.offset:=alloctemp(list,size,varalign,temptype,nil);
+        ref.alignment:=varalign;
       end;
       end;
 
 
 
 
@@ -516,6 +516,7 @@ implementation
         fillchar(ref,sizeof(ref),0);
         fillchar(ref,sizeof(ref),0);
         ref.base:=current_procinfo.framepointer;
         ref.base:=current_procinfo.framepointer;
         ref.offset:=alloctemp(list,def.size,varalign,temptype,def);
         ref.offset:=alloctemp(list,def.size,varalign,temptype,def);
+        ref.alignment:=varalign;
       end;
       end;
 
 
 
 

+ 1 - 1
compiler/x86/cgx86.pas

@@ -946,7 +946,7 @@ unit cgx86;
             (tosize<fromsize) then
             (tosize<fromsize) then
            begin
            begin
              { can't round down to lower precision in x87 :/ }
              { can't round down to lower precision in x87 :/ }
-             tg.gettemp(list,tcgsize2size[tosize],tt_normal,href);
+             tg.gettemp(list,tcgsize2size[tosize],tcgsize2size[tosize],tt_normal,href);
              a_loadfpu_reg_ref(list,fromsize,tosize,NR_ST,href);
              a_loadfpu_reg_ref(list,fromsize,tosize,NR_ST,href);
              a_loadfpu_ref_reg(list,tosize,tosize,href,NR_ST);
              a_loadfpu_ref_reg(list,tosize,tosize,href,NR_ST);
              tg.ungettemp(list,href);
              tg.ungettemp(list,href);

+ 1 - 1
compiler/x86/nx86cnv.pas

@@ -305,7 +305,7 @@ implementation
               make it 64bits }
               make it 64bits }
             if (torddef(left.resultdef).ordtype=u32bit) then
             if (torddef(left.resultdef).ordtype=u32bit) then
               begin
               begin
-                tg.GetTemp(current_asmdata.CurrAsmList,8,tt_normal,href);
+                tg.GetTemp(current_asmdata.CurrAsmList,8,8,tt_normal,href);
                 location_freetemp(current_asmdata.CurrAsmList,left.location);
                 location_freetemp(current_asmdata.CurrAsmList,left.location);
                 cg.a_load_ref_ref(current_asmdata.CurrAsmList,left.location.size,OS_32,left.location.reference,href);
                 cg.a_load_ref_ref(current_asmdata.CurrAsmList,left.location.size,OS_32,left.location.reference,href);
                 inc(href.offset,4);
                 inc(href.offset,4);

+ 5 - 5
compiler/x86/nx86inl.pas

@@ -268,7 +268,7 @@ implementation
           begin
           begin
             load_fpu_location;
             load_fpu_location;
             location_reset(location,LOC_REFERENCE,OS_S64);
             location_reset(location,LOC_REFERENCE,OS_S64);
-            tg.GetTempTyped(current_asmdata.CurrAsmList,resultdef,tt_normal,location.reference);
+            tg.GetTemp(current_asmdata.CurrAsmList,resultdef.size,resultdef.alignment,tt_normal,location.reference);
             emit_ref(A_FISTP,S_IQ,location.reference);
             emit_ref(A_FISTP,S_IQ,location.reference);
             emit_none(A_FWAIT,S_NO);
             emit_none(A_FWAIT,S_NO);
            end;
            end;
@@ -303,20 +303,20 @@ implementation
               begin
               begin
                 load_fpu_location;
                 load_fpu_location;
                 location_reset(location,LOC_REFERENCE,OS_S64);
                 location_reset(location,LOC_REFERENCE,OS_S64);
-                tg.GetTempTyped(current_asmdata.CurrAsmList,resultdef,tt_normal,location.reference);
+                tg.GetTemp(current_asmdata.CurrAsmList,resultdef.size,resultdef.alignment,tt_normal,location.reference);
                 emit_ref(A_FISTTP,S_IQ,location.reference);
                 emit_ref(A_FISTTP,S_IQ,location.reference);
               end
               end
             else
             else
               begin
               begin
-                tg.GetTemp(current_asmdata.CurrAsmList,2,tt_normal,oldcw);
-                tg.GetTemp(current_asmdata.CurrAsmList,2,tt_normal,newcw);
+                tg.GetTemp(current_asmdata.CurrAsmList,2,2,tt_normal,oldcw);
+                tg.GetTemp(current_asmdata.CurrAsmList,2,2,tt_normal,newcw);
                 emit_ref(A_FNSTCW,S_NO,newcw);
                 emit_ref(A_FNSTCW,S_NO,newcw);
                 emit_ref(A_FNSTCW,S_NO,oldcw);
                 emit_ref(A_FNSTCW,S_NO,oldcw);
                 emit_const_ref(A_OR,S_W,$0f00,newcw);
                 emit_const_ref(A_OR,S_W,$0f00,newcw);
                 load_fpu_location;
                 load_fpu_location;
                 emit_ref(A_FLDCW,S_NO,newcw);
                 emit_ref(A_FLDCW,S_NO,newcw);
                 location_reset(location,LOC_REFERENCE,OS_S64);
                 location_reset(location,LOC_REFERENCE,OS_S64);
-                tg.GetTempTyped(current_asmdata.CurrAsmList,resultdef,tt_normal,location.reference);
+                tg.GetTemp(current_asmdata.CurrAsmList,resultdef.size,resultdef.alignment,tt_normal,location.reference);
                 emit_ref(A_FISTP,S_IQ,location.reference);
                 emit_ref(A_FISTP,S_IQ,location.reference);
                 emit_ref(A_FLDCW,S_NO,oldcw);
                 emit_ref(A_FLDCW,S_NO,oldcw);
                 emit_none(A_FWAIT,S_NO);
                 emit_none(A_FWAIT,S_NO);