Browse Source

* stop generation of typed array constants if the size does not match, resolves #39980

florian 2 years ago
parent
commit
3f7bf0fd70
2 changed files with 45 additions and 1 deletions
  1. 2 1
      compiler/ngtcon.pas
  2. 43 0
      tests/webtbf/tw39980.pp

+ 2 - 1
compiler/ngtcon.pas

@@ -1359,7 +1359,8 @@ function get_next_varsym(def: tabstractrecorddef; const SymList:TFPHashObjectLis
                 consume(_RKLAMMER);
               end;
             curoffset:=oldoffset;
-            ftcb.maybe_end_aggregate(def);
+            if ErrorCount=0 then
+              ftcb.maybe_end_aggregate(def);
           end
         { if array of char then we allow also a string }
         else if is_anychar(def.elementdef) then

+ 43 - 0
tests/webtbf/tw39980.pp

@@ -0,0 +1,43 @@
+{ %opt=-O3 }
+{ %fail }
+
+{ This test has been known to generate internal error 2014091205 }
+  
+program tcond1.pp;
+
+const
+  Expected: array[0..3] of array[0..2] of Integer =
+    ((-10, 3), (-10, 4), (0, -10), (0, -10));
+
+function TestInput(Input, TestAns: Integer): Boolean;
+  var
+    O1, O2, O3: Integer;
+  begin
+    if Input < 2 then 
+      begin
+		O1 := -10;
+		O2 := TestAns;
+	  end
+	else
+	  begin
+	    O1 := 0;
+		O2 := -10;
+	  end;
+	  
+	TestInput :=
+	  (O1 = Expected[Input][0]) and
+	  (O2 = Expected[Input][1]);
+  end;
+  
+var
+  X: Integer;
+  
+begin
+  for X := 0 to 3 do
+    begin
+	  if not TestInput(X, X + 3) then
+	    Halt(1);
+	end;
+	
+  WriteLn('ok');
+end.