From c994b5efe8809ce84b3ba52046c32fc37909a65e Mon Sep 17 00:00:00 2001 From: Sven/Sarah Barth Date: Fri, 30 Jun 2023 17:41:58 +0200 Subject: [PATCH] * fix #39447: when checking whether the parameters are valid for pointer arithmetic check the *correct* parameter for being valid pointer-like type (I'd say that this was a copy&paste mistake...) + added test --- compiler/nadd.pas | 4 ++-- tests/webtbs/tw39447.pp | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 tests/webtbs/tw39447.pp diff --git a/compiler/nadd.pas b/compiler/nadd.pas index 473a839233..c95b60f765 100644 --- a/compiler/nadd.pas +++ b/compiler/nadd.pas @@ -3068,9 +3068,9 @@ implementation if (rt=niln) then CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),ld.typename,'NIL'); if (not(cs_extsyntax in current_settings.moduleswitches) and not(nf_internal in flags)) or - (not (is_pchar(ld) or is_chararray(ld) or is_open_chararray(ld) or is_widechar(ld) or is_widechararray(ld) or is_open_widechararray(ld)) and + (not (is_pchar(rd) or is_chararray(rd) or is_open_chararray(rd) or is_widechar(rd) or is_widechararray(rd) or is_open_widechararray(rd)) and not(cs_pointermath in current_settings.localswitches) and - not((ld.typ=pointerdef) and tpointerdef(ld).has_pointer_math)) then + not((rd.typ=pointerdef) and tpointerdef(rd).has_pointer_math)) then CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),ld.typename,rd.typename); if (rd.typ=pointerdef) and (tpointerdef(rd).pointeddef.size>1) then diff --git a/tests/webtbs/tw39447.pp b/tests/webtbs/tw39447.pp new file mode 100644 index 0000000000..c9a0d88b37 --- /dev/null +++ b/tests/webtbs/tw39447.pp @@ -0,0 +1,30 @@ +unit tw39447; +{$IFDEF FPC} +{$MODE Delphi} +{$ENDIF} + +interface +uses sysutils; + +function ptr_twist() : boolean; + +implementation + +function ptr_twist() : boolean; +var + x : pchar; + x2 : pchar; +const + str : ShortString = '123456789'; +begin + + x := @(str[2]); + x := x + 5; + x2:= 5 + x; // FPC fails here + + result := (x = x2); + +end; + +end. +