From d97d34ee9c538f4d9d9f0cb4ac1b2fbec6c91deb Mon Sep 17 00:00:00 2001 From: Sven/Sarah Barth Date: Fri, 30 Jun 2023 15:35:28 +0200 Subject: [PATCH] * fix #40332: apply patch by Rika to avoid a crash when an overload can't be picked outside of a function (e.g. when using intrinsics inside constants) + added test --- compiler/ncal.pas | 2 +- tests/webtbs/tw40332.pp | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 tests/webtbs/tw40332.pp diff --git a/compiler/ncal.pas b/compiler/ncal.pas index 87b5d7de7a..795da93548 100644 --- a/compiler/ncal.pas +++ b/compiler/ncal.pas @@ -3823,7 +3823,7 @@ implementation with generic types as arguments we don't complain in the generic, but only during the specialization } ignoregenericparacall:=false; - if df_generic in current_procinfo.procdef.defoptions then + if assigned(current_procinfo) and (df_generic in current_procinfo.procdef.defoptions) then begin pt:=tcallparanode(left); while assigned(pt) do diff --git a/tests/webtbs/tw40332.pp b/tests/webtbs/tw40332.pp new file mode 100644 index 0000000000..7904af9bcc --- /dev/null +++ b/tests/webtbs/tw40332.pp @@ -0,0 +1,21 @@ +{$mode objfpc} +unit tw40332; + +interface + + function Bsr(const value: byte): byte; internproc: fpc_in_bsr_x; + function Bsr(const value: word): cardinal; internproc: fpc_in_bsr_x; + function Bsr(const value: dword): cardinal; internproc: fpc_in_bsr_x; +{$ifdef cpu64} + function Bsr(const value: qword): cardinal; internproc: fpc_in_bsr_x; +{$endif} + +type + SomeEnum = (A, B, C, D); + +const + SomeEnumBits = 1 + Bsr(ord(High(SomeEnum)) or 1); + +implementation + +end.