Przeglądaj źródła

* disable overflow checking when performing pointer arithmetic
(mantis 8049)

git-svn-id: trunk@5822 -

Jonas Maebe 18 lat temu
rodzic
commit
d0b6292137

+ 1 - 0
.gitattributes

@@ -7944,6 +7944,7 @@ tests/webtbs/tw7975.pp svneol=native#text/plain
 tests/webtbs/tw7975a.pp svneol=native#text/plain
 tests/webtbs/tw8018.pp svneol=native#text/plain
 tests/webtbs/tw8028.pp svneol=native#text/plain
+tests/webtbs/tw8049.pp svneol=native#text/plain
 tests/webtbs/ub1873.pp svneol=native#text/plain
 tests/webtbs/ub1883.pp svneol=native#text/plain
 tests/webtbs/uw0555.pp svneol=native#text/plain

+ 10 - 0
compiler/ncgadd.pas

@@ -498,6 +498,11 @@ interface
             internalerror(2002072705);
         end;
 
+        checkoverflow:=
+          checkoverflow and
+          (left.resultdef.typ<>pointerdef) and 
+          (right.resultdef.typ<>pointerdef);
+
 {$ifdef cpu64bit}
         case nodetype of
           xorn,orn,andn,addn:
@@ -684,6 +689,11 @@ interface
             end;
         end;
 
+       checkoverflow:=
+         checkoverflow and
+          (left.resultdef.typ<>pointerdef) and 
+          (right.resultdef.typ<>pointerdef);
+
        if nodetype<>subn then
         begin
           if (right.location.loc<>LOC_CONSTANT) then

+ 9 - 6
compiler/powerpc/nppcadd.pas

@@ -744,9 +744,9 @@ interface
          tmpreg     : tregister;
          hl         : tasmlabel;
          cmpop      : boolean;
-
          { true, if unsigned types are compared }
          unsigned : boolean;
+         checkoverflow : boolean;
 
       begin
          { to make it more readable, string and set (not smallset!) have their
@@ -819,15 +819,18 @@ interface
           else
            location_reset(location,LOC_FLAGS,OS_NO);
 
-         load_left_right(cmpop, (cs_check_overflow in current_settings.localswitches) and
-            (nodetype in [addn,subn,muln]));
+         checkoverflow:=
+           (nodetype in [addn,subn,muln]) and
+           (cs_check_overflow in current_settings.localswitches) and
+           (left.resultdef.typ<>pointerdef) and 
+           (right.resultdef.typ<>pointerdef);
+
+         load_left_right(cmpop, checkoverflow);
 
          if not(cmpop) then
            location.register := cg.getintregister(current_asmdata.CurrAsmList,OS_INT);
 
-         if not(cs_check_overflow in current_settings.localswitches) or
-            (cmpop) or
-            (nodetype in [orn,andn,xorn]) then
+         if not(checkoverflow) then
            begin
              case nodetype of
                addn, muln, xorn, orn, andn:

+ 9 - 4
compiler/powerpc64/nppcadd.pas

@@ -146,6 +146,7 @@ var
   tmpreg: tregister;
   hl: tasmlabel;
   cmpop: boolean;
+  checkoverflow: boolean;
 
   { true, if unsigned types are compared }
   unsigned: boolean;
@@ -214,14 +215,18 @@ begin
   else
     location_reset(location, LOC_FLAGS, OS_NO);
 
-  load_left_right(cmpop, (cs_check_overflow in current_settings.localswitches) and
-    (nodetype in [addn, subn, muln]));
+  checkoverflow:=
+    (nodetype in [addn,subn,muln]) and
+    (cs_check_overflow in current_settings.localswitches) and
+    (left.resultdef.typ<>pointerdef) and 
+    (right.resultdef.typ<>pointerdef);
+
+  load_left_right(cmpop, checkoverflow);
 
   if not (cmpop) then
     location.register := cg.getintregister(current_asmdata.CurrAsmList, OS_INT);
 
-  if not (cs_check_overflow in current_settings.localswitches) or (cmpop) or
-    (nodetype in [orn, andn, xorn]) then begin
+  if not (checkoverflow) then begin
     case nodetype of
       addn, muln, xorn, orn, andn:
         begin

+ 15 - 0
tests/webtbs/tw8049.pp

@@ -0,0 +1,15 @@
+program bug;
+
+{$Q+}
+
+const s:array[0..31] of char='Hell* world';
+	  index:longint=-6;
+
+var c:char;
+    p,q:Pchar;
+
+begin 
+  p:=s;
+  q:=p-index;
+  writeln('Hello ',q);
+end.