瀏覽代碼

* fixed assignments to integer regvars typecasted to a type
of equal size but with different signdness + test

git-svn-id: trunk@9871 -

Jonas Maebe 17 年之前
父節點
當前提交
53be0147d4
共有 3 個文件被更改,包括 48 次插入0 次删除
  1. 1 0
      .gitattributes
  2. 11 0
      compiler/htypechk.pas
  3. 36 0
      tests/tbs/tb0172a.pp

+ 1 - 0
.gitattributes

@@ -6377,6 +6377,7 @@ tests/tbs/tb0168.pp svneol=native#text/plain
 tests/tbs/tb0169.pp svneol=native#text/plain
 tests/tbs/tb0170.pp svneol=native#text/plain
 tests/tbs/tb0172.pp svneol=native#text/plain
+tests/tbs/tb0172a.pp svneol=native#text/plain
 tests/tbs/tb0173.pp svneol=native#text/plain
 tests/tbs/tb0174.pp svneol=native#text/plain
 tests/tbs/tb0175.pp svneol=native#text/plain

+ 11 - 0
compiler/htypechk.pas

@@ -1072,6 +1072,17 @@ implementation
                       if report_errors then
                         CGMessagePos2(hp.fileinfo,type_e_typecast_wrong_size_for_assignment,tostr(fromdef.size),tostr(todef.size));
                   end;
+                  
+                 { when typecasting to the same size but changing the signdness of
+                   an ordinal, the value cannot be in a register if it's < sizeof(aint).
+                   The reason is that a tc_int_2_int type conversion changing the sign
+                   of a such value in a register also has to modify this register (JM)   }
+                 if is_ordinal(fromdef) and is_ordinal(todef) and
+                    (fromdef.size=todef.size) and
+                    (fromdef.size<sizeof(aint)) and
+                    (is_signed(fromdef) xor is_signed(todef)) then
+                   make_not_regable(hp,[ra_addr_regable]);
+
                  { don't allow assignments to typeconvs that need special code }
                  if not(gotsubscript or gotvec or gotderef) and
                     not(ttypeconvnode(hp).assign_allowed) then

+ 36 - 0
tests/tbs/tb0172a.pp

@@ -0,0 +1,36 @@
+{ Old file: tbs0204.pp }
+{ can typecast the result var in an assignment          OK 0.99.11 (PM) }
+
+{ boolean(byte) byte(boolean)
+  word(wordbool) wordbool(word)
+  longint(longbool) and longbool(longint)
+  must be accepted as var parameters
+  or a left of an assignment }
+
+procedure error;
+begin
+   Writeln('Error in tb0172a');
+   Halt(1);
+end;
+
+procedure test;
+var
+  b : shortint;
+  wb : smallint;
+  lb : longint;
+
+begin
+  b:=0;
+  wb:=0;
+  lb:=0;
+
+  byte(b):=128;
+  word(wb):=32768;
+  cardinal(lb):=$80000000;
+  if (b<>low(shortint)) or (wb<>low(smallint)) or (lb<>low(longint)) then
+    error;
+end;
+
+begin
+  test;
+end.