[gcc r17-2888] cobol: Make pointer to stash location file-static. [PR126391]

Robert Dubner via Gcc-cvs <[email protected]> Sun, 2 Aug 2026 19:53:34 +0000 (GMT)
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:c4b00249c26ea79cdca47d15b9697dac592de7de

commit r17-2888-gc4b00249c26ea79cdca47d15b9697dac592de7de
Author: Robert Dubner <[email protected]>
Date:   Sun Aug 2 15:28:50 2026 -0400

    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:
---
 gcc/cobol/move.cc | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/gcc/cobol/move.cc b/gcc/cobol/move.cc
index e0d198d9e3be..5e49c56c3fd2 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;