Browse Source

LLVM: fix currency parameters passed on the stack on x86-64

Resolves #40496
Jonas Maebe 1 year ago
parent
commit
0ca260e08c
2 changed files with 39 additions and 1 deletions
  1. 10 1
      compiler/x86_64/cpupara.pas
  2. 29 0
      tests/webtbs/tw40496.pp

+ 10 - 1
compiler/x86_64/cpupara.pas

@@ -1855,7 +1855,7 @@ unit cpupara;
                                 end;
                                 end;
 {$endif not LLVM}
 {$endif not LLVM}
                               paraloc^.size:=def_cgsize(paraloc^.def);
                               paraloc^.size:=def_cgsize(paraloc^.def);
-                              { s64comp is pushed in an int register }
+                              { s64comp/s64currency is pushed in an int register }
                               if paraloc^.size=OS_C64 then
                               if paraloc^.size=OS_C64 then
                                 begin
                                 begin
                                   paraloc^.size:=OS_64;
                                   paraloc^.size:=OS_64;
@@ -1972,6 +1972,15 @@ unit cpupara;
                           paraloc:=hp.paraloc[side].add_location;
                           paraloc:=hp.paraloc[side].add_location;
                           paraloc^.loc:=LOC_REFERENCE;
                           paraloc^.loc:=LOC_REFERENCE;
                           paraloc^.def:=loc[locidx].def;
                           paraloc^.def:=loc[locidx].def;
+
+                          { s64comp/s64currency are passed as integer types
+                            (important for LLVM here) }
+                          if paracgsize=OS_C64 then
+                            begin
+                              paraloc^.size:=OS_64;
+                              paraloc^.def:=u64inttype;
+                            end;
+
                           {Hack alert!!! We should modify int_cgsize to handle OS_128,
                           {Hack alert!!! We should modify int_cgsize to handle OS_128,
                            however, since int_cgsize is called in many places in the
                            however, since int_cgsize is called in many places in the
                            compiler where only a few can already handle OS_128, fixing it
                            compiler where only a few can already handle OS_128, fixing it

+ 29 - 0
tests/webtbs/tw40496.pp

@@ -0,0 +1,29 @@
+program llvmccy5ParamTest;
+
+type
+
+	TTestObjFail = object
+		constructor Init(
+			P1, P2, P3, P4: Currency; P5: Currency);
+	end;
+
+constructor TTestObjFail.Init(
+			P1, P2, P3, P4: Currency; P5: Currency);
+begin
+  if p1<>1 then
+    halt(1);
+  if p2<>2 then
+    halt(2);
+  if p3<>3 then
+    halt(3);
+  if p4<>4 then
+    halt(4);
+  if p5<>5 then
+    halt(5);
+end;
+
+var
+	TestObj	: TTestObjFail;
+begin
+	TestObj.Init(1, 2, 3, 4, 5);
+end.