Browse Source

* fix empty varargs codegeneration for x86_64

peter 20 years ago
parent
commit
20ad7813c2
2 changed files with 29 additions and 6 deletions
  1. 14 3
      compiler/ncal.pas
  2. 15 3
      compiler/x86_64/nx64cal.pas

+ 14 - 3
compiler/ncal.pas

@@ -44,7 +44,8 @@ interface
          cnf_anon_inherited,
          cnf_anon_inherited,
          cnf_new_call,
          cnf_new_call,
          cnf_dispose_call,
          cnf_dispose_call,
-         cnf_member_call        { called with implicit methodpointer tree }
+         cnf_member_call,        { called with implicit methodpointer tree }
+         cnf_uses_varargs        { varargs are used in the declaration }
        );
        );
        tcallnodeflags = set of tcallnodeflag;
        tcallnodeflags = set of tcallnodeflag;
 
 
@@ -1018,6 +1019,7 @@ type
             CGMessage1(type_e_wrong_type_in_array_constructor,oldleft.left.resulttype.def.typename);
             CGMessage1(type_e_wrong_type_in_array_constructor,oldleft.left.resulttype.def.typename);
             exit;
             exit;
           end;
           end;
+        include(callnodeflags,cnf_uses_varargs);
         { Get arrayconstructor node and insert typeconvs }
         { Get arrayconstructor node and insert typeconvs }
         hp:=tarrayconstructornode(oldleft.left);
         hp:=tarrayconstructornode(oldleft.left);
         hp.insert_typeconvs;
         hp.insert_typeconvs;
@@ -1442,6 +1444,7 @@ type
            pt:=tcallparanode(pt.right);
            pt:=tcallparanode(pt.right);
          end;
          end;
 
 
+
         { Create parasyms for varargs, first count the number of varargs paras,
         { Create parasyms for varargs, first count the number of varargs paras,
           then insert the parameters with numbering in reverse order. The SortParas
           then insert the parameters with numbering in reverse order. The SortParas
           will set the correct order at the end}
           will set the correct order at the end}
@@ -1767,7 +1770,7 @@ type
               error and to prevent users from generating non-working code
               error and to prevent users from generating non-working code
               when they expect to clone the current instance, see bug 3662 (PFV) }
               when they expect to clone the current instance, see bug 3662 (PFV) }
               if (procdefinition.proctypeoption=potype_constructor) and
               if (procdefinition.proctypeoption=potype_constructor) and
-		 is_class(tprocdef(procdefinition)._class) and
+                 is_class(tprocdef(procdefinition)._class) and
                  assigned(methodpointer) and
                  assigned(methodpointer) and
                  (nf_is_self in methodpointer.flags) then
                  (nf_is_self in methodpointer.flags) then
                 resulttype:=voidtype
                 resulttype:=voidtype
@@ -1856,6 +1859,11 @@ type
               internalerror(200305061);
               internalerror(200305061);
           end;
           end;
 
 
+         { Set flag that the procedure uses varargs, also if they are not passed it is still
+           needed for x86_64 to pass the number of SSE registers used }
+         if po_varargs in procdefinition.procoptions then
+           include(callnodeflags,cnf_uses_varargs);
+
          { Change loading of array of const to varargs }
          { Change loading of array of const to varargs }
          if assigned(left) and
          if assigned(left) and
             is_array_of_const(tparavarsym(procdefinition.paras[procdefinition.paras.count-1]).vartype.def) and
             is_array_of_const(tparavarsym(procdefinition.paras[procdefinition.paras.count-1]).vartype.def) and
@@ -2508,7 +2516,10 @@ begin
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.279  2005-02-17 17:50:26  peter
+  Revision 1.280  2005-03-14 20:18:46  peter
+    * fix empty varargs codegeneration for x86_64
+
+  Revision 1.279  2005/02/17 17:50:26  peter
     * member call to constructor returns void to prevent
     * member call to constructor returns void to prevent
       generating unexpected code. Otherwise the return value is always
       generating unexpected code. Otherwise the return value is always
       equal to self, which can also be directly accessed
       equal to self, which can also be directly accessed

+ 15 - 3
compiler/x86_64/nx64cal.pas

@@ -38,14 +38,23 @@ interface
 implementation
 implementation
 
 
     uses
     uses
+      globtype,
       cpubase,
       cpubase,
       aasmtai,aasmcpu;
       aasmtai,aasmcpu;
 
 
     procedure tx8664callnode.extra_call_code;
     procedure tx8664callnode.extra_call_code;
+      var
+        mmregs : aint;
       begin
       begin
         { x86_64 requires %al to contain the no. SSE regs passed }
         { x86_64 requires %al to contain the no. SSE regs passed }
-        if assigned(varargsparas) then
-          exprasmlist.concat(taicpu.op_const_reg(A_MOV,S_Q,varargsparas.mmregsused,NR_RAX));
+        if cnf_uses_varargs in callnodeflags then
+          begin
+            if assigned(varargsparas) then
+              mmregs:=varargsparas.mmregsused
+            else
+              mmregs:=0;
+            exprasmlist.concat(taicpu.op_const_reg(A_MOV,S_Q,mmregs,NR_RAX))
+          end;
       end;
       end;
 
 
 
 
@@ -54,7 +63,10 @@ begin
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.3  2005-02-14 17:13:10  peter
+  Revision 1.4  2005-03-14 20:18:46  peter
+    * fix empty varargs codegeneration for x86_64
+
+  Revision 1.3  2005/02/14 17:13:10  peter
     * truncate log
     * truncate log
 
 
 }
 }