From: Robert Dubner Date: Sun, 2 Aug 2026 19:28:50 +0000 (-0400) Subject: cobol: Make pointer to stash location file-static. [PR126391] X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c4b00249c26ea79cdca47d15b9697dac592de7de;p=thirdparty%2Fgcc.git cobol: Make pointer to stash location file-static. [PR126391] 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. --- diff --git a/gcc/cobol/move.cc b/gcc/cobol/move.cc index e0d198d9e3b..5e49c56c3fd 100644 --- a/gcc/cobol/move.cc +++ b/gcc/cobol/move.cc @@ -3495,7 +3495,8 @@ move_helper(tree size_error, // This is an INT 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 ) { @@ -3511,7 +3512,8 @@ move_helper(tree size_error, // This is an INT 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;