Переглянути джерело

* do not apply range test optimization if the variable is a string being compared against a char constants, resolves #37476

git-svn-id: trunk@46453 -
florian 5 роки тому
батько
коміт
18b8b9c566
3 змінених файлів з 10 додано та 2 видалено
  1. 1 0
      .gitattributes
  2. 4 2
      compiler/nadd.pas
  3. 5 0
      tests/webtbf/tw37476.pp

+ 1 - 0
.gitattributes

@@ -16559,6 +16559,7 @@ tests/webtbf/tw3740.pp svneol=native#text/plain
 tests/webtbf/tw37460.pp svneol=native#text/pascal
 tests/webtbf/tw37462.pp svneol=native#text/pascal
 tests/webtbf/tw37475.pp svneol=native#text/pascal
+tests/webtbf/tw37476.pp svneol=native#text/pascal
 tests/webtbf/tw3790.pp svneol=native#text/plain
 tests/webtbf/tw3812.pp svneol=native#text/plain
 tests/webtbf/tw3930a.pp svneol=native#text/plain

+ 4 - 2
compiler/nadd.pas

@@ -1326,7 +1326,9 @@ implementation
                    (right.nodetype in [ltn,lten,gtn,gten]) and
                    (not might_have_sideeffects(left)) and
                    (not might_have_sideeffects(right)) and
-                   is_range_test(taddnode(left),taddnode(right),vl,cl,cr) then
+                   is_range_test(taddnode(left),taddnode(right),vl,cl,cr) and
+                   { avoid optimization being applied to (<string. var > charconst1) and (<string. var < charconst2) }
+                   (vl.resultdef.typ in [orddef,enumdef]) then
                   begin
                     hdef:=get_unsigned_inttype(vl.resultdef);
                     vl:=ctypeconvnode.create_internal(vl.getcopy,hdef);
@@ -3000,7 +3002,7 @@ implementation
             end;
           end;
 
-         if not codegenerror and
+         if (errorcount=0) and
             not assigned(result) then
            result:=simplify(false);
       end;

+ 5 - 0
tests/webtbf/tw37476.pp

@@ -0,0 +1,5 @@
+{ %fail }
+var a : string = (a >= 'A') and (a <= 'F');
+
+begin
+end.