Răsfoiți Sursa

* fixed if-simplication for C-style booleans by considering all values
different from 0 to be "true", instead of only 1 (patch by Jeppe Johansen,
mantis #23436)

git-svn-id: trunk@23117 -

Jonas Maebe 12 ani în urmă
părinte
comite
29095e9dd3
4 a modificat fișierele cu 47 adăugiri și 2 ștergeri
  1. 1 0
      .gitattributes
  2. 1 1
      compiler/nflw.pas
  3. 1 1
      tests/test/tdefault1.pp
  4. 44 0
      tests/webtbs/tw23436.pp

+ 1 - 0
.gitattributes

@@ -13012,6 +13012,7 @@ tests/webtbs/tw23270.pp svneol=native#text/pascal
 tests/webtbs/tw2328.pp svneol=native#text/plain
 tests/webtbs/tw2332.pp svneol=native#text/plain
 tests/webtbs/tw23342.pp svneol=native#text/pascal
+tests/webtbs/tw23436.pp svneol=native#text/plain
 tests/webtbs/tw2351.pp svneol=native#text/plain
 tests/webtbs/tw2363.pp svneol=native#text/plain
 tests/webtbs/tw2377.pp svneol=native#text/plain

+ 1 - 1
compiler/nflw.pas

@@ -1333,7 +1333,7 @@ implementation
         { optimize constant expressions }
         if (left.nodetype=ordconstn) then
           begin
-             if tordconstnode(left).value.uvalue=1 then
+             if tordconstnode(left).value.uvalue<>0 then
                begin
                   if assigned(right) then
                     result:=right

+ 1 - 1
tests/test/tdefault1.pp

@@ -92,7 +92,7 @@ begin
   if Default(LongBool) then
     Halt(15);
 {$ifdef fpc}
-  if not Default(QWordBool) then
+  if Default(QWordBool) then
     Halt(16);
 {$endif}
   (* comma types *)

+ 44 - 0
tests/webtbs/tw23436.pp

@@ -0,0 +1,44 @@
+program testcase;
+
+{$APPTYPE CONSOLE}
+{$mode objfpc}
+
+begin
+  if ByteBool(true) then
+    writeln('ByteBool(true) ok')
+  else
+    halt(1);
+  if not ByteBool(false) then
+    writeln('ByteBool(not false) ok')
+  else
+    halt(2);
+  if WordBool(true) then
+    writeln('WordBool(true) ok')
+  else
+    halt(3);
+  if not WordBool(false) then
+    writeln('WordBool(not false) ok')
+  else
+    halt(4);
+  if LongBool(true) then
+    writeln('LongBool(true) ok')
+  else
+    halt(5);
+  if not LongBool(false) then
+    writeln('LongBool(not false) ok')
+  else
+    halt(6);
+{$ifdef FPC}
+  if QWordBool(true) then
+    writeln('QWordBool(true) ok')
+  else
+    halt(7);
+  if not QWordBool(false) then
+    writeln('QWordBool(not false) ok')
+  else
+    halt(8);
+{$endif FPC}
+
+  Writeln('ok');
+end.
+