From: Robert Dubner <[email protected]>
Date: Tue, 29 Sep 2026 14:26:27 -0400
Subject: [PATCH] cobol: Update CALL processing when -fno-static-call is
operative.

This code works properly when the CALL is the last statement in a COBOL
source code module.  It also works properly with various combinations
of CALL "xyz", with or without ON EXCEPTION and whether or not EXCEPTION
processing is enabled.

Co-authored-by: James K. Lowden <[email protected]>

gcc/cobol/ChangeLog:

        * genapi.cc (parser_call): Proper handling of the ON EXCEPTION
        clause.
        * parse.y: Handle missing target when the CALL is the final
        statement of the source code module.
        * parse_ante.h: Likewise.
---
 gcc/cobol/genapi.cc    | 5 +++--
 gcc/cobol/parse.y      | 8 +++-----
 gcc/cobol/parse_ante.h | 1 +
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/gcc/cobol/genapi.cc b/gcc/cobol/genapi.cc
index acedc4a7250..c0f2b448964 100644
--- a/gcc/cobol/genapi.cc
+++ b/gcc/cobol/genapi.cc
@@ -13443,9 +13443,10 @@ parser_call(   cbl_refer_t name,
 
       if( except )
         {
-        // Preserve the existing ON EXCEPTION routing and reset
placement.
-        gg_append_statement(except->structs.call_exception->into.go_to);
+        // Set the exception data, but clear the code, because
+        // ON EXCEPTION prevents exception process.
         gg_assign(var_decl_exception_code, integer_zero_node);
+        gg_append_statement(except->structs.call_exception->into.go_to);
         }
       else if( !literal_call && issue_warning )
         {
diff --git a/gcc/cobol/parse.y b/gcc/cobol/parse.y
index 441c4de259e..78d7f22d894 100644
--- a/gcc/cobol/parse.y
+++ b/gcc/cobol/parse.y
@@ -13105,13 +13105,11 @@ possible_ec() {
  */
 static void
 statement_epilog( int token ) {
-  cbl_enabled_exceptions_t& enabled_exceptions( cdf_enabled_exceptions()
);
   if( possible_ec() && token != CONTINUE ) {
-    if( enabled_exceptions.size() ) {
-      current.declaratives_evaluate();
-    }
+    current.declaratives_evaluate();
+  } else {
+    parser_check_fatal_exception();
   }
-  parser_check_fatal_exception();
 }
 
 static inline void
diff --git a/gcc/cobol/parse_ante.h b/gcc/cobol/parse_ante.h
index 0f190d042d1..db624c78128 100644
--- a/gcc/cobol/parse_ante.h
+++ b/gcc/cobol/parse_ante.h
@@ -2401,6 +2401,7 @@ static class current_t {
     if( enabled_exceptions.size() ) {
       declaratives_evaluate();
     }
+    parser_check_fatal_exception();
 
     assert(!programs.empty());
 
-- 
2.34.1

Reply via email to