Skip to content

Commit 7a7b37e

Browse files
[Save] Generate exception handler in tree
1 parent 7f8a9c6 commit 7a7b37e

File tree

6 files changed

+40
-11
lines changed

6 files changed

+40
-11
lines changed

cobc/ChangeLog

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
2025-10-07 Emilien Lemaire <[email protected]>
1+
2025-11-10 Emilien Lemaire <[email protected]>
22

33
* codegen.c (output_size_exception_handler): generate a check for a
44
size exception on statements that can raise them

cobc/codegen.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9033,7 +9033,7 @@ output_assign (const struct cb_assign *ap)
90339033
#endif /* Nonaligned */
90349034
}
90359035

9036-
static void
9036+
/* static void
90379037
output_size_exception_handler(const struct cb_statement *p) {
90389038
unsigned i;
90399039
const int enabled_size_ec[8] = {
@@ -9086,7 +9086,7 @@ output_size_exception_handler(const struct cb_statement *p) {
90869086
default:
90879087
break;
90889088
}
9089-
}
9089+
} */
90909090

90919091
static void
90929092
output_stmt (cb_tree x)
@@ -9206,9 +9206,9 @@ output_stmt (cb_tree x)
92069206
}
92079207
}
92089208

9209-
if ((!p->ex_handler || (p->ex_handler && p->handler_type != SIZE_ERROR_HANDLER))) {
9209+
/* if ((!p->ex_handler || (p->ex_handler && p->handler_type != SIZE_ERROR_HANDLER))) {
92109210
output_size_exception_handler(p);
9211-
}
9211+
} */
92129212

92139213
break;
92149214
}

cobc/parser.y

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18134,13 +18134,25 @@ on_size_error_phrases:
1813418134
%prec SHIFT_PREFER
1813518135
{
1813618136
/* no [NOT] ON SIZE ERROR is specified (= no explicit handling) */
18137+
if (CB_EXCEPTION_ENABLE(EC-SIZE)) {
18138+
current_statement->handler_type = SIZE_ERROR_HANDLER;
18139+
current_statement->ex_handler = cb_build_direct("cob_call_size_error ();", 1);
18140+
}
1813718141
}
1813818142
| on_size_error _not_on_size_error
1813918143
| not_on_size_error _on_size_error
1814018144
{
1814118145
if ($2) {
1814218146
cb_verify (cb_not_exception_before_exception,
1814318147
_("NOT SIZE ERROR before SIZE ERROR"));
18148+
} else if ($1 && $1 != cb_int1) {
18149+
/* One NOT ON SIZE ERROR, but no ON SIZE ERROR, so we need to
18150+
check on exceptions */
18151+
if (CB_EXCEPTION_ENABLE(EC-SIZE)) {
18152+
current_statement->handler_type = SIZE_ERROR_HANDLER;
18153+
current_statement->ex_handler =
18154+
cb_build_direct("cob_call_size_error ();", 1);
18155+
}
1814418156
}
1814518157
}
1814618158
;
@@ -18176,6 +18188,7 @@ _not_on_size_error:
1817618188
not_on_size_error:
1817718189
NOT_SIZE_ERROR statement_list
1817818190
{
18191+
$$ = cb_int2;
1817918192
current_statement->handler_type = SIZE_ERROR_HANDLER;
1818018193
if (is_valid_statement_tree ($2)) {
1818118194
current_statement->not_ex_handler = $2;

libcob/call.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
*/
2020

2121

22+
#include "common.h"
2223
#include "config.h"
2324

2425
#ifndef _GNU_SOURCE
@@ -1044,6 +1045,17 @@ cob_call_error (void)
10441045
cob_hard_failure ();
10451046
}
10461047

1048+
void
1049+
cob_call_size_error (void) {
1050+
int last_exception_code;
1051+
last_exception_code = cob_get_global_ptr()->cob_exception_code;
1052+
if (last_exception_code) {
1053+
cob_runtime_error("Fatal size exception not handled: %s",
1054+
cob_get_last_exception_name());
1055+
cob_hard_failure ();
1056+
}
1057+
}
1058+
10471059
void
10481060
cob_set_cancel (cob_module *m)
10491061
{

libcob/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2085,6 +2085,7 @@ COB_EXPIMP cob_s64_t cob_s64_pow (cob_s64_t, cob_s64_t);
20852085
/* Functions in call.c */
20862086

20872087
DECLNORET COB_EXPIMP void cob_call_error (void) COB_A_NORETURN;
2088+
DECLNORET COB_EXPIMP void cob_call_size_error (void) COB_A_NORETURN;
20882089
COB_EXPIMP void cob_field_constant (cob_field *f, cob_field *t, cob_field_attr *a, void *d);
20892090

20902091
COB_EXPIMP void cob_set_cancel (cob_module *);

tests/ChangeLog

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11

2-
2025-11-10 Emilien Lemaire <[email protected]>
2+
2025-10-30 Simon Sobisch <[email protected]>
33

4-
* testsuite.src/data_binary.at, testsuite.src/data_display.at,
5-
testsuite.src/data_packed.at, testsuite.src/run_extenstions.at,
6-
testsuite.src/run_fundamental.at testsuite.src/run_misc.at: add a
7-
`-fno-ec=EC-SIZE` on tests that rely on a non standard exception
8-
handling
4+
* atlocal.in (perf_stat, perf_record): moved calling of perf out to a
5+
function and added a second call for recording
6+
* atlocal.in, atlocal_win: fixed quoting (2025-09-17 change)
7+
8+
2025-09-17 Simon Sobisch <[email protected]>
9+
10+
* atlocal.in, atlocal_win: quote local include and library directories
11+
to support the rare scenario of space-embedded paths, fixing #1142
912

1013
2025-05-22 David Declerck <[email protected]>
1114

0 commit comments

Comments
 (0)