Browse Source

* make sure that all references used in the inline int->real conversion code
are properly PICified (mantis #17714)

git-svn-id: trunk@16255 -

Jonas Maebe 15 years ago
parent
commit
3aea9b134a
3 changed files with 59 additions and 13 deletions
  1. 1 0
      .gitattributes
  2. 16 13
      compiler/x86/nx86cnv.pas
  3. 42 0
      tests/webtbs/tw17714.pp

+ 1 - 0
.gitattributes

@@ -10720,6 +10720,7 @@ tests/webtbs/tw17646.pp svneol=native#text/plain
 tests/webtbs/tw1765.pp svneol=native#text/plain
 tests/webtbs/tw1765.pp svneol=native#text/plain
 tests/webtbs/tw17675.pp svneol=native#text/plain
 tests/webtbs/tw17675.pp svneol=native#text/plain
 tests/webtbs/tw17675a.pp svneol=native#text/plain
 tests/webtbs/tw17675a.pp svneol=native#text/plain
+tests/webtbs/tw17714.pp svneol=native#text/plain
 tests/webtbs/tw17715.pp svneol=native#text/plain
 tests/webtbs/tw17715.pp svneol=native#text/plain
 tests/webtbs/tw1779.pp svneol=native#text/plain
 tests/webtbs/tw1779.pp svneol=native#text/plain
 tests/webtbs/tw1780.pp svneol=native#text/plain
 tests/webtbs/tw1780.pp svneol=native#text/plain

+ 16 - 13
compiler/x86/nx86cnv.pas

@@ -235,6 +235,7 @@ implementation
     procedure tx86typeconvnode.second_int_to_real;
     procedure tx86typeconvnode.second_int_to_real;
 
 
       var
       var
+         leftref,
          href : treference;
          href : treference;
          l1,l2 : tasmlabel;
          l1,l2 : tasmlabel;
          op: tasmop;
          op: tasmop;
@@ -301,18 +302,24 @@ implementation
     
     
             { We need to load from a reference }
             { We need to load from a reference }
             location_force_mem(current_asmdata.CurrAsmList,left.location);
             location_force_mem(current_asmdata.CurrAsmList,left.location);
-    
+            { don't change left.location.reference, because if it's a temp we
+              need the original location at the end so we can free it }
+            leftref:=left.location.reference;
+            tcgx86(cg).make_simple_ref(current_asmdata.CurrAsmList,leftref);
+
             { For u32bit we need to load it as comp and need to
             { For u32bit we need to load it as comp and need to
               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,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,leftref,href);
                 inc(href.offset,4);
                 inc(href.offset,4);
                 cg.a_load_const_ref(current_asmdata.CurrAsmList,OS_32,0,href);
                 cg.a_load_const_ref(current_asmdata.CurrAsmList,OS_32,0,href);
                 dec(href.offset,4);
                 dec(href.offset,4);
-                left.location.reference:=href;
+                { could be a temp with an offset > 32 bit on x86_64 }
+                tcgx86(cg).make_simple_ref(current_asmdata.CurrAsmList,href);
+                leftref:=href;
               end;
               end;
     
     
             { Load from reference to fpu reg }
             { Load from reference to fpu reg }
@@ -321,9 +328,7 @@ implementation
               scurrency,
               scurrency,
               s64bit:
               s64bit:
                 begin
                 begin
-                  href:=left.location.reference;
-                  tcgx86(cg).make_simple_ref(current_asmdata.CurrAsmList,href);
-                  current_asmdata.CurrAsmList.concat(taicpu.op_ref(A_FILD,S_IQ,href));
+                  current_asmdata.CurrAsmList.concat(taicpu.op_ref(A_FILD,S_IQ,leftref));
                 end;
                 end;
               u64bit:
               u64bit:
                 begin
                 begin
@@ -336,12 +341,12 @@ implementation
     
     
                    if not(signtested) then
                    if not(signtested) then
                      begin
                      begin
-                       inc(left.location.reference.offset,4);
-                       emit_const_ref(A_BT,S_L,31,left.location.reference);
-                       dec(left.location.reference.offset,4);
+                       inc(leftref.offset,4);
+                       emit_const_ref(A_BT,S_L,31,leftref);
+                       dec(leftref.offset,4);
                      end;
                      end;
     
     
-                   current_asmdata.CurrAsmList.concat(taicpu.op_ref(A_FILD,S_IQ,left.location.reference));
+                   current_asmdata.CurrAsmList.concat(taicpu.op_ref(A_FILD,S_IQ,leftref));
                    cg.a_jmp_flags(current_asmdata.CurrAsmList,F_NC,l2);
                    cg.a_jmp_flags(current_asmdata.CurrAsmList,F_NC,l2);
                    current_asmdata.asmlists[al_typedconsts].concat(Tai_label.Create(l1));
                    current_asmdata.asmlists[al_typedconsts].concat(Tai_label.Create(l1));
                    { I got this constant from a test program (FK) }
                    { I got this constant from a test program (FK) }
@@ -358,9 +363,7 @@ implementation
                 begin
                 begin
                   if left.resultdef.size<4 then
                   if left.resultdef.size<4 then
                     internalerror(2007120901);
                     internalerror(2007120901);
-                 href:=left.location.reference;
-                 tcgx86(cg).make_simple_ref(current_asmdata.CurrAsmList,href);
-                 current_asmdata.CurrAsmList.concat(taicpu.op_ref(A_FILD,S_IL,href));
+                 current_asmdata.CurrAsmList.concat(taicpu.op_ref(A_FILD,S_IL,leftref));
                 end;
                 end;
             end;
             end;
             tcgx86(cg).inc_fpu_stack;
             tcgx86(cg).inc_fpu_stack;

+ 42 - 0
tests/webtbs/tw17714.pp

@@ -0,0 +1,42 @@
+uses
+  Math;
+
+var
+  l: longint;
+  c: cardinal;
+  i: int64;
+  q: qword;
+  s: single;
+  d: double;
+begin
+  l:=-12345;
+  c:=56789;
+  i:=-56789;
+  q:=12345;
+
+  s:=l;
+  if s<>-12345 then
+    halt(1);
+  s:=c;
+  if s<>56789 then
+    halt(2);
+  s:=i;
+  if s<>-56789 then
+    halt(3);
+  s:=q;
+  if s<>12345 then
+    halt(4);
+  
+  d:=l;
+  if d<>-12345 then
+    halt(5);
+  d:=c;
+  if d<>56789 then
+    halt(6);
+  d:=i;
+  if d<>-56789 then
+    halt(7);
+  d:=q;
+  if d<>12345 then
+    halt(8);
+end.