--- p/statements.c.orig Sat Apr 8 01:45:22 2006 +++ p/statements.c Tue Mar 6 13:10:46 2007 @@ -1302,9 +1302,10 @@ length = integer_zero_node; else { - /* Use save_expr, so the length is not computed twice (for the - number of chars to move and the assignment to the target length). */ - length = save_expr (fold (build_pascal_binary_op (MIN_EXPR, PASCAL_STRING_LENGTH (source), capacity))); + /* Use save_expr_string, so the string is not evaluated 2 or 3 times (for the + number of chars to move, assignment to the target length and the chars). */ + source = save_expr_string (source); + length = fold (build_pascal_binary_op (MIN_EXPR, PASCAL_STRING_LENGTH (source), capacity)); /* The target needs to be an lvalue, but the source might be e.g. an array returned by a function or whatever. */ expr1 = build_memcpy (build_unary_op (ADDR_EXPR, PASCAL_STRING_VALUE (target), 1), --- p/test/roland2.pas.orig Tue Mar 6 15:42:02 2007 +++ p/test/roland2.pas Tue Mar 6 12:39:23 2007 @@ -0,0 +1,21 @@ +program Roland2; + +{$R-} { Range-checking prevented this instance of the bug in some GPC versions + as a side-effect, though the actual bug was still there. } + +var + i: Integer value 0; + s: String (3); + c: array [1 .. 2] of String (3) = ('K', 'abc'); + +function f: Integer; +begin + Write ('O'); + Inc (i); + f := i +end; + +begin + s := c[f]; + WriteLn (s) +end.