From eab079c7bd9d93bc3f02309e9ada641a7c43c60d Mon Sep 17 00:00:00 2001 From: Jonas Maebe Date: Sun, 2 Jun 2019 20:04:06 +0000 Subject: [PATCH] * fixed cbool "and" with full boolean evaluation, and cbool "xor" (mantis #35272) git-svn-id: trunk@42167 - --- .gitattributes | 1 + compiler/nadd.pas | 34 ++++++++++++++++++++++++++++++++++ tests/webtbs/tw35272.pp | 19 +++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 tests/webtbs/tw35272.pp diff --git a/.gitattributes b/.gitattributes index 48e04bb14d..d50747e9e6 100644 --- a/.gitattributes +++ b/.gitattributes @@ -16628,6 +16628,7 @@ tests/webtbs/tw35187.pp svneol=native#text/pascal tests/webtbs/tw35224.pp svneol=native#text/plain tests/webtbs/tw3523.pp svneol=native#text/plain tests/webtbs/tw35233.pp svneol=native#text/plain +tests/webtbs/tw35272.pp svneol=native#text/plain tests/webtbs/tw3529.pp svneol=native#text/plain tests/webtbs/tw3531.pp svneol=native#text/plain tests/webtbs/tw3533.pp svneol=native#text/plain diff --git a/compiler/nadd.pas b/compiler/nadd.pas index 25db9f4da5..af07bc79be 100644 --- a/compiler/nadd.pas +++ b/compiler/nadd.pas @@ -1650,6 +1650,40 @@ implementation andn, orn: begin + { in case of xor, or 'and' with full and cbool: convert both to Pascal bool and then + perform the xor/and to prevent issues with "longbool(1) and/xor + longbool(2)" } + if (is_cbool(ld) or is_cbool(rd)) and + ((nodetype=xorn) or + ((nodetype=andn) and + ((cs_full_boolean_eval in current_settings.localswitches) or + not(nf_short_bool in flags) + ) + ) + ) then + begin + resultdef:=nil; + if is_cbool(ld) then + begin + inserttypeconv(left,pasbool8type); + ttypeconvnode(left).convtype:=tc_bool_2_bool; + if not is_cbool(rd) or + (ld.size>=rd.size) then + resultdef:=ld; + end; + if is_cbool(rd) then + begin + inserttypeconv(right,pasbool8type); + ttypeconvnode(right).convtype:=tc_bool_2_bool; + if not assigned(resultdef) then + resultdef:=rd; + end; + result:=ctypeconvnode.create_explicit(caddnode.create(nodetype,left,right),resultdef); + ttypeconvnode(result).convtype:=tc_bool_2_bool; + left:=nil; + right:=nil; + exit; + end; { Make sides equal to the largest boolean } if (torddef(left.resultdef).size>torddef(right.resultdef).size) or (is_cbool(left.resultdef) and not is_cbool(right.resultdef)) then diff --git a/tests/webtbs/tw35272.pp b/tests/webtbs/tw35272.pp new file mode 100644 index 0000000000..a68abce9f5 --- /dev/null +++ b/tests/webtbs/tw35272.pp @@ -0,0 +1,19 @@ +var + b1, b2, b3: longbool; +begin + b1:=longbool(1); + b2:=longbool(2); + b3:=b1 and b2; + if not b3 then + halt(1); + b3:=b1 xor b2; + if b3 then + halt(2); +{$b+} + b3:=b1 and b2; + if not b3 then + halt(3); + b3:=b1 xor b2; + if b3 then + halt(4); +end.