瀏覽代碼

* set types of start value calculation correctly when doing strength reduction, resolves #41054

florian 7 月之前
父節點
當前提交
9d94ccdc38
共有 2 個文件被更改,包括 24 次插入1 次删除
  1. 1 1
      compiler/optloop.pas
  2. 23 0
      tests/webtbs/tw41054.pp

+ 1 - 1
compiler/optloop.pas

@@ -507,7 +507,7 @@ unit optloop;
 
 
                       startvaltemp:=maybereplacewithtemp(tfornode(arg).right,initcode,initcodestatements,tfornode(arg).right.resultdef.size,true);
                       startvaltemp:=maybereplacewithtemp(tfornode(arg).right,initcode,initcodestatements,tfornode(arg).right.resultdef.size,true);
                       nn:=caddrnode.create(
                       nn:=caddrnode.create(
-                          cvecnode.create(tvecnode(n).left.getcopy,tfornode(arg).right.getcopy)
+                          cvecnode.create(tvecnode(n).left.getcopy,ctypeconvnode.create_internal(tfornode(arg).right.getcopy,tvecnode(n).right.resultdef))
                         );
                         );
                       { If the calculation is not performed at the end
                       { If the calculation is not performed at the end
                         it is needed to adjust the starting value }
                         it is needed to adjust the starting value }

+ 23 - 0
tests/webtbs/tw41054.pp

@@ -0,0 +1,23 @@
+type
+	myrec=record
+		f1,f2,f3:byte;
+	end;
+	myenum=(
+		asd=0
+	);
+
+const
+	myarr:array [myenum] of myrec=(
+		(f1:1;f2:2;f3:3)
+	);
+
+procedure foo;
+var
+	i:byte;
+begin
+	for i:=0 to 0 do
+		writeln(myarr[myenum(i)].f2);
+end;
+
+begin
+end.