Browse Source

Fixed optimization `Length(W)=0` -> `(Pointer(W)=nil) or (PLongword(Pointer(W)-4)^=0)` for WideString

Sergey Larin 3 years ago
parent
commit
35db2b2da3
1 changed files with 8 additions and 3 deletions
  1. 8 3
      compiler/nadd.pas

+ 8 - 3
compiler/nadd.pas

@@ -460,11 +460,16 @@ implementation
       function TransformLengthZero(n1,n2 : tnode) : tnode;
         var
           len : Tconstexprint;
+          lentype : tdef;
         begin
           if is_dynamic_array(tinlinenode(n1).left.resultdef) then
             len:=-1
           else
             len:=0;
+          if is_widestring(tinlinenode(n1).left.resultdef) and (tf_winlikewidestring in target_info.flags) then
+            lentype:=u32inttype
+          else
+            lentype:=sizesinttype;
           result:=caddnode.create_internal(orn,
             caddnode.create_internal(equaln,ctypeconvnode.create_internal(tinlinenode(n1).left.getcopy,voidpointertype),
                 cpointerconstnode.create(0,voidpointertype)),
@@ -472,10 +477,10 @@ implementation
                 ctypeconvnode.create_internal(
                   cderefnode.create(
                     caddnode.create_internal(subn,ctypeconvnode.create_internal(tinlinenode(n1).left.getcopy,voidpointertype),
-                      cordconstnode.create(sizesinttype.size,sizesinttype,false))
-                  ),sizesinttype
+                      cordconstnode.create(lentype.size,lentype,false))
+                  ),lentype
                 ),
-              cordconstnode.create(len,sizesinttype,false))
+              cordconstnode.create(len,lentype,false))
             );
         end;