Browse Source

+ add proper int type conversions for huge pointer arithmetic in pass_typecheck
of the add node

git-svn-id: trunk@28094 -

nickysn 11 years ago
parent
commit
89db1e4118
2 changed files with 23 additions and 5 deletions
  1. 18 0
      compiler/defutil.pas
  2. 5 5
      compiler/nadd.pas

+ 18 - 0
compiler/defutil.pas

@@ -331,6 +331,13 @@ interface
     { returns true of def is a methodpointer }
     { returns true of def is a methodpointer }
     function is_methodpointer(def : tdef) : boolean;
     function is_methodpointer(def : tdef) : boolean;
 
 
+    {# returns the appropriate int type for pointer arithmetic with the given pointer type.
+       When adding or subtracting a number to/from a pointer, this function returns the
+       int type to which that number has to be converted, before the operation can be performed.
+       Normally, this is sinttype, except on i8086, where it takes into account the
+       special i8086 pointer types (near, far, huge). }
+    function get_int_type_for_pointer_arithmetic(p : tdef) : tdef;
+
 {$ifdef i8086}
 {$ifdef i8086}
     {# Returns true if p is a far pointer def }
     {# Returns true if p is a far pointer def }
     function is_farpointer(p : tdef) : boolean;
     function is_farpointer(p : tdef) : boolean;
@@ -1433,6 +1440,17 @@ implementation
         result:=(def.typ=procvardef) and (po_methodpointer in tprocvardef(def).procoptions);
         result:=(def.typ=procvardef) and (po_methodpointer in tprocvardef(def).procoptions);
       end;
       end;
 
 
+
+    function get_int_type_for_pointer_arithmetic(p : tdef) : tdef;
+      begin
+{$ifdef i8086}
+        if is_hugepointer(p) then
+          result:=s32inttype
+        else
+{$endif i8086}
+          result:=sinttype;
+      end;
+
 {$ifdef i8086}
 {$ifdef i8086}
     { true if p is a far pointer def }
     { true if p is a far pointer def }
     function is_farpointer(p : tdef) : boolean;
     function is_farpointer(p : tdef) : boolean;

+ 5 - 5
compiler/nadd.pas

@@ -1960,7 +1960,7 @@ implementation
               end
               end
             else
             else
               resultdef:=right.resultdef;
               resultdef:=right.resultdef;
-            inserttypeconv(left,sinttype);
+            inserttypeconv(left,get_int_type_for_pointer_arithmetic(rd));
             if nodetype=addn then
             if nodetype=addn then
               begin
               begin
                 if not(cs_extsyntax in current_settings.moduleswitches) or
                 if not(cs_extsyntax in current_settings.moduleswitches) or
@@ -1972,7 +1972,7 @@ implementation
                    (tpointerdef(rd).pointeddef.size>1) then
                    (tpointerdef(rd).pointeddef.size>1) then
                    begin
                    begin
                      left:=caddnode.create(muln,left,
                      left:=caddnode.create(muln,left,
-                       cordconstnode.create(tpointerdef(rd).pointeddef.size,sinttype,true));
+                       cordconstnode.create(tpointerdef(rd).pointeddef.size,get_int_type_for_pointer_arithmetic(rd),true));
                      typecheckpass(left);
                      typecheckpass(left);
                    end;
                    end;
               end
               end
@@ -1991,7 +1991,7 @@ implementation
              else
              else
                resultdef:=left.resultdef;
                resultdef:=left.resultdef;
 
 
-             inserttypeconv(right,sinttype);
+             inserttypeconv(right,get_int_type_for_pointer_arithmetic(ld));
              if nodetype in [addn,subn] then
              if nodetype in [addn,subn] then
                begin
                begin
                  if (lt=niln) then
                  if (lt=niln) then
@@ -2008,7 +2008,7 @@ implementation
                    if (tpointerdef(ld).pointeddef.size>1) then
                    if (tpointerdef(ld).pointeddef.size>1) then
                    begin
                    begin
                      right:=caddnode.create(muln,right,
                      right:=caddnode.create(muln,right,
-                       cordconstnode.create(tpointerdef(ld).pointeddef.size,sinttype,true));
+                       cordconstnode.create(tpointerdef(ld).pointeddef.size,get_int_type_for_pointer_arithmetic(ld),true));
                      typecheckpass(right);
                      typecheckpass(right);
                    end
                    end
                  end else
                  end else
@@ -2016,7 +2016,7 @@ implementation
                       (tarraydef(ld).elementdef.size>1) then
                       (tarraydef(ld).elementdef.size>1) then
                      begin
                      begin
                        right:=caddnode.create(muln,right,
                        right:=caddnode.create(muln,right,
-                         cordconstnode.create(tarraydef(ld).elementdef.size,sinttype,true));
+                         cordconstnode.create(tarraydef(ld).elementdef.size,get_int_type_for_pointer_arithmetic(ld),true));
                        typecheckpass(right);
                        typecheckpass(right);
                      end;
                      end;
                end
                end