Browse Source

LLVM: only add sret attribute for first parameter on caller side

We already did this when generating the definitions, but not yet
when generating the calls
Jonas Maebe 2 years ago
parent
commit
2949d0b548
1 changed files with 6 additions and 1 deletions
  1. 6 1
      compiler/llvm/llvmpara.pas

+ 6 - 1
compiler/llvm/llvmpara.pas

@@ -163,7 +163,12 @@ unit llvmpara;
         paralocs }
         paralocs }
       while assigned(paraloc) do
       while assigned(paraloc) do
         begin
         begin
-          if (vo_is_funcret in parasym.varoptions)
+          if (vo_is_funcret in parasym.varoptions) and
+             { sret attribute is only valid for the first parameter; sometimes
+               FPC will place other parameters first (e.g. self), and then
+               we can't use it; we use other attributes in that case to
+               approximate the optimisations that LLVM can do for sret }
+             (tabstractprocdef(parasym.owner.defowner).paras[0] = parasym)
  {$ifdef aarch64}
  {$ifdef aarch64}
              { see AArch64's tcpuparamanager.create_paraloc_info_intern() }
              { see AArch64's tcpuparamanager.create_paraloc_info_intern() }
              and not is_managed_type(parasym.vardef)
              and not is_managed_type(parasym.vardef)