[gcc r17-2766] cobol: Fix LENGTH OF group data item as value for constants.

"James K. Lowden via Gcc-cvs" <[email protected]> Tue, 28 Jul 2026 22:28:10 +0000 (GMT)
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:9ac6fe6f17ede1d728bdcc745ff15c5031eb73ef

commit r17-2766-g9ac6fe6f17ede1d728bdcc745ff15c5031eb73ef
Author: James K. Lowden <[email protected]>
Date:   Tue Jul 28 18:09:12 2026 -0400

    cobol: Fix LENGTH OF group data item as value for constants.
    
    The size of groups is normally not set until Data Division
    ends. Provide a function to update the size for use of compile-time
    constants.
    
    gcc/cobol/ChangeLog:
    
            * parse_ante.h (set_real_from_capacity): Use symbol_field_capacity_set().
            * symbols.cc (calculate_capacity): Whitespace.
            (symbol_field_capacity_set): New function.
            * symbols.h (symbol_field_capacity_set): Declare function.

Diff:
---
 gcc/cobol/parse_ante.h | 3 +++
 gcc/cobol/symbols.cc   | 8 +++++++-
 gcc/cobol/symbols.h    | 2 ++
 3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/gcc/cobol/parse_ante.h b/gcc/cobol/parse_ante.h
index 097d8f621731..477ed3478480 100644
--- a/gcc/cobol/parse_ante.h
+++ b/gcc/cobol/parse_ante.h
@@ -3376,6 +3376,9 @@ set_real_from_capacity( const cbl_loc_t& loc,
     error_msg(loc, "cannot define %s via self-reference", field->name);
     return;
   }
+  if( field->type == FldGroup ) {
+    symbol_field_capacity_set(field);
+  }
   field->data.set_real_from_capacity(r);
 }
 
diff --git a/gcc/cobol/symbols.cc b/gcc/cobol/symbols.cc
index a70c4fed411c..7b6902a36e23 100644
--- a/gcc/cobol/symbols.cc
+++ b/gcc/cobol/symbols.cc
@@ -1250,7 +1250,7 @@ grow_redefined_group( cbl_field_t *redefined, const cbl_field_t *field ) {
  * For groups, return the element after the last field in the group.
  */
 static struct symbol_elem_t *
- calculate_capacity( struct symbol_elem_t *e) {
+calculate_capacity( struct symbol_elem_t *e) {
   // For each group, sum capacities of children.  Exclude:
   //    FldClass, FldForward
   //    FldIndex with level 0 (really, any level 0)
@@ -1408,6 +1408,12 @@ static struct symbol_elem_t *
   return e;
 }
 
+void
+symbol_field_capacity_set( cbl_field_t *field ) {
+  gcc_assert(field->type == FldGroup);
+  calculate_capacity( symbol_elem_of(field) );
+}
+
 static void
 verify_block( const struct symbol_elem_t *block,
               const struct symbol_elem_t *eoblock )
diff --git a/gcc/cobol/symbols.h b/gcc/cobol/symbols.h
index 2d8c9cee4585..374554877889 100644
--- a/gcc/cobol/symbols.h
+++ b/gcc/cobol/symbols.h
@@ -1180,6 +1180,8 @@ bool
 symbol_field_type_update( cbl_field_t *field,
                           cbl_field_type_t type, bool is_usage );
 
+void symbol_field_capacity_set( cbl_field_t *field );
+
 struct sort_key_t;
 struct sort_key_t;