https://gcc.gnu.org/g:4e8b7c1a35b93017ae4a293f2de978cfb70b190a
commit r17-4166-g4e8b7c1a35b93017ae4a293f2de978cfb70b190a Author: James K. Lowden <[email protected]> Date: Wed Sep 9 12:58:41 2026 -0400 cobol: Validate ADD CORRESPONDING takes 2 operands only. New error message, fixes RT 3665. Also prevent ICE for WRITE during syntax-only mode. gcc/cobol/ChangeLog: * genapi.cc (parser_file_write): Use RETURN_IF_PARSE_ONLY. * parse.y: Diagnose ADD CORRESPONDING operand count. Diff: --- gcc/cobol/genapi.cc | 1 + gcc/cobol/parse.y | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/gcc/cobol/genapi.cc b/gcc/cobol/genapi.cc index 11c0cfad7212..71fc31852c36 100644 --- a/gcc/cobol/genapi.cc +++ b/gcc/cobol/genapi.cc @@ -9484,6 +9484,7 @@ parser_file_write( cbl_file_t *file, bool sequentially ) { + RETURN_IF_PARSE_ONLY; if( !file ) { cbl_internal_error("%s: called with NULL *file", __func__); diff --git a/gcc/cobol/parse.y b/gcc/cobol/parse.y index 24a9977c8116..91c6cd0c2342 100644 --- a/gcc/cobol/parse.y +++ b/gcc/cobol/parse.y @@ -6229,6 +6229,16 @@ add_body: sum TO rnames *$$ = std::for_each( pairs.begin(), pairs.end(), *$$ ); $$->A.pop_front(); $$->tgts.pop_front(); + if( 1 < $sum->size() ) { + unsigned long n = $sum->size(); + error_msg(@sum, "ADD CORRESPONDING accepts only 1 sending operand, " + "%lu provided", n); + } + if( 1 < rhs.size() ) { + unsigned long n = rhs.size(); + error_msg(@rnames, "ADD CORRESPONDING accepts only 1 TO operand, " + "%lu provided", n); + } rhs.clear(); } ;
