Explorar o código

* fixed bug that caused 'c in ['a'..'z']' to fail on the WebAssembly target, when code is compiled with {$packset 1}

Nikolay Nikolov hai 1 ano
pai
achega
a8b4c0772c
Modificáronse 2 ficheiros con 39 adicións e 1 borrados
  1. 6 1
      compiler/ncgset.pas
  2. 33 0
      tests/test/tset8.pp

+ 6 - 1
compiler/ncgset.pas

@@ -474,7 +474,12 @@ implementation
                  { allocate a register for the result }
                  location.register := hlcg.getintregister(current_asmdata.CurrAsmList, uopdef);
 
-                 if right.location.loc=LOC_CONSTANT then
+                 if (right.location.loc=LOC_CONSTANT) and
+                      (opsize < OS_S8) and { = if unsigned }
+                      (((left.resultdef.typ=orddef) and
+                        (torddef(left.resultdef).low >= int64(tsetdef(right.resultdef).setbase))) or
+                       ((left.resultdef.typ=enumdef) and
+                        (tenumdef(left.resultdef).min >= aint(tsetdef(right.resultdef).setbase)))) then
                    begin
                      { can it actually occur currently? CEC }
                      { yes: "if bytevar in [1,3,5,7,9,11,13,15]" (JM) }

+ 33 - 0
tests/test/tset8.pp

@@ -0,0 +1,33 @@
+program tset8;
+
+{$packset 1}
+
+procedure CheckIn(C: Char);
+begin
+  if (C < 'a') or (C > 'z') then
+  begin
+    Writeln('Error!');
+    Halt(1);
+  end;
+end;
+
+procedure CheckOut(C: Char);
+begin
+  if (C >= 'a') and (C <= 'z') then
+  begin
+    Writeln('Error!');
+    Halt(1);
+  end;
+end;
+
+var
+  C: Char;
+begin
+  for C := #0 to #255 do
+  begin
+    if C in ['a'..'z'] then
+      CheckIn(C)
+    else
+      CheckOut(C);
+  end;
+end.