COBOL variable assignments can have ON SIZE ERROR clauses. When an error
occurs and there is such a clause, the original destination value is
not changed. Since the discovery of an error happens near the end, I
chose to create a data stash for the original value; when an error is
detected, the starting value is restored from the stash.
The stash area is created using malloc, but never freed. It gets
realloced as necessary when subsequently needed. (This avoids repeated
malloc/free calls during execution.)
My mistake: I created the pointer to that area as an automatic variable
on the stack, but assigned it to a static tree. The mistake manifested
here as a temporary variable with the function context as
stored-char-length, but then later showing up with a context of prog,
leading to the ICE, because automatic variables have to have the correct
function context.
The fix was to give that variable a name and give it file-static scope.
PR cobol/126391
gcc/cobol/ChangeLog:
* move.cc (move_helper): static tree stash has file-static scope.
cbl_refer_t sourceref, // Call move_helper with this resolved.
TREEPLET &tsource,
cbl_round_t rounded,
- bool check_for_error, // True means our called wants to know about truncation errors
+ // True means our caller wants to know about truncation errors
+ bool check_for_error,
bool restore_on_error
)
{
gg_assign(size_error, integer_zero_node);
}
- static tree stash = gg_define_variable(UCHAR_P);
+ static tree stash =
+ gg_define_variable(UCHAR_P, "..move_stasher", vs_file_static);
tree st_data = NULL_TREE;
tree st_size = NULL_TREE;