Sfoglia il codice sorgente

* fixed cbool "and" with full boolean evaluation, and cbool "xor"
(mantis #35272)

git-svn-id: trunk@42167 -

Jonas Maebe 6 anni fa
parent
commit
eab079c7bd
3 ha cambiato i file con 54 aggiunte e 0 eliminazioni
  1. 1 0
      .gitattributes
  2. 34 0
      compiler/nadd.pas
  3. 19 0
      tests/webtbs/tw35272.pp

+ 1 - 0
.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

+ 34 - 0
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

+ 19 - 0
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.