Browse Source

* throw an error if varargs is used without appropriate calling conventions, resolves #40342

florian 1 year ago
parent
commit
4a4eadc60e
2 changed files with 17 additions and 1 deletions
  1. 1 1
      compiler/pparautl.pas
  2. 16 0
      tests/tbf/tw40342.pp

+ 1 - 1
compiler/pparautl.pas

@@ -649,7 +649,7 @@ implementation
                   { both must be defined now }
                   { both must be defined now }
                   if not((po_external in pd.procoptions) or
                   if not((po_external in pd.procoptions) or
                          (pd.typ=procvardef)) or
                          (pd.typ=procvardef)) or
-                     not(pd.proccalloption in (cdecl_pocalls + [pocall_stdcall])) then
+                     not(pd.proccalloption in cstylearrayofconst) then
                     Message(parser_e_varargs_need_cdecl_and_external);
                     Message(parser_e_varargs_need_cdecl_and_external);
                 end;
                 end;
              end;
              end;

+ 16 - 0
tests/tbf/tw40342.pp

@@ -0,0 +1,16 @@
+{ %fail }
+{$mode objfpc}
+
+program test;
+
+type
+  TMyRecord = record
+  end;
+
+function printf(format: PChar): Integer; external; varargs;
+
+var
+  r: TMyRecord;
+begin
+  printf('test', r); // Fatal: Internal error 2004102303
+end.