https://gcc.gnu.org/g:c1b0d255ab0ee9850f5753afdcdb772f039137f2

commit r17-4444-gc1b0d255ab0ee9850f5753afdcdb772f039137f2
Author: Xavier Del Campo Romero <[email protected]>
Date:   Fri Sep 18 12:27:24 2026 +0200

    cobol: Reapply "cobol: Correct CBL_CREATE_FILE and improve parameter 
validation for ANY LENGTH."
    
    The "improve parameter validation for ANY LENGTH" part of this commit
    was valid from the beginning and should have not been reverted.
    
    This partly reverts commit 65c058c33c276d87cc6f4b233c5bd1b84cb5b6a8.
    
    gcc/cobol/ChangeLog:
    
            * parse.y: Reapply.
            * symbols.h: Likewise.

Diff:
---
 gcc/cobol/parse.y   | 11 ++++++++---
 gcc/cobol/symbols.h |  6 ++++++
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/gcc/cobol/parse.y b/gcc/cobol/parse.y
index 2de650c70b85..9b07e9c46c8e 100644
--- a/gcc/cobol/parse.y
+++ b/gcc/cobol/parse.y
@@ -12986,7 +12986,7 @@ cbl_ffi_arg_t::matches( const cbl_ffi_arg_t& that ) 
const {
   case by_reference_e:
     if( crv == by_reference_e ) {
       if( (formal->attr & mask) == (actual->attr & mask) ) {
-        if( formal->data.capacity() == actual->data.capacity() ) {
+        if( capacity_ok(formal, actual) ) {
           if( formal->type == actual->type ) { // captures USAGE except COMP-X
             return true;
           }
@@ -12995,13 +12995,17 @@ cbl_ffi_arg_t::matches( const cbl_ffi_arg_t& that ) 
const {
           return true;
       }
     }
-    // If actual is by reference, so must the formal be. 
+    // If actual is by reference, so must the formal be.
+    dbgmsg("%s:%d: failed, reference feature mismatch", __func__, __LINE__);
     return false;
     break;
   case by_content_e:
     break;
   case by_value_e:
-    if( crv != by_value_e ) return false;
+    if( crv != by_value_e ) {
+      dbgmsg("%s:%d: failed, actual %s not by value", __func__, __LINE__, 
actual->name);
+      return false;
+    }
     if( formal->type == FldPointer && that.refer.is_pointer() ) return true;
     break;
   }
@@ -13018,6 +13022,7 @@ cbl_ffi_arg_t::matches( const cbl_ffi_arg_t& that ) 
const {
     return actual->data.capacity() == formal->data.capacity()
         && actual->codeset.encoding == formal->codeset.encoding;
   }          
+  dbgmsg("%s:%d: failed, for some reason", __func__, __LINE__);
   return false;
 }
 
diff --git a/gcc/cobol/symbols.h b/gcc/cobol/symbols.h
index 3887b275b7b0..6c6142ed1a93 100644
--- a/gcc/cobol/symbols.h
+++ b/gcc/cobol/symbols.h
@@ -1444,6 +1444,12 @@ protected:
     if( crv == by_reference_e ) return false;
     return refer.field != NULL;
   }
+  static bool capacity_ok( const cbl_field_t *formal, const cbl_field_t 
*actual ) {
+    if( formal->data.capacity() == actual->data.capacity() ) return true;
+    if( formal->data.capacity() == 1 && formal->has_attr(any_length_e) ) 
return true;
+    if( actual->data.capacity() == 1 && actual->has_attr(any_length_e) ) 
return true;
+    return false;
+  }
 };
 
 // In support of serial/linear search:

Reply via email to