Skip to content

Commit c552ba3

Browse files
Better ec-size checking
1 parent d69551c commit c552ba3

File tree

3 files changed

+43
-64
lines changed

3 files changed

+43
-64
lines changed

cobc/codegen.c

Lines changed: 30 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -8722,60 +8722,38 @@ static void
87228722
output_ec_size_handler (void)
87238723
{
87248724
int ec_checked = 0;
8725-
8726-
output_line ("if (unlikely ((cob_glob_ptr->cob_exception_code & 0xff00) == 0x%04x)"
8727-
" && (cob_glob_ptr->cob_got_exception > 0))",
8728-
CB_EXCEPTION_CODE (COB_EC_SIZE));
8729-
output_block_open();
8730-
if (CB_EXCEPTION_ENABLE(COB_EC_SIZE_ADDRESS)) {
8731-
ec_checked = 1;
8732-
output_line("if (cob_glob_ptr->cob_exception_code == %d) "
8733-
"cob_fatal_exception (cob_glob_ptr->cob_exception_code);",
8734-
CB_EXCEPTION_CODE(COB_EC_SIZE_ADDRESS));
8735-
}
8736-
if (CB_EXCEPTION_ENABLE(COB_EC_SIZE_EXPONENTIATION)) {
8737-
ec_checked = 1;
8738-
output_line("if (cob_glob_ptr->cob_exception_code == %d) "
8739-
"cob_fatal_exception (cob_glob_ptr->cob_exception_code);",
8740-
CB_EXCEPTION_CODE(COB_EC_SIZE_EXPONENTIATION));
8741-
}
8742-
if (CB_EXCEPTION_ENABLE(COB_EC_SIZE_IMP)) {
8743-
ec_checked = 1;
8744-
output_line("if (cob_glob_ptr->cob_exception_code == %d) "
8745-
"cob_fatal_exception (cob_glob_ptr->cob_exception_code);",
8746-
CB_EXCEPTION_CODE(COB_EC_SIZE_IMP));
8747-
}
8748-
if (CB_EXCEPTION_ENABLE(COB_EC_SIZE_OVERFLOW)) {
8749-
ec_checked = 1;
8750-
output_line("if (cob_glob_ptr->cob_exception_code == %d) "
8751-
"cob_fatal_exception (cob_glob_ptr->cob_exception_code);",
8752-
CB_EXCEPTION_CODE(COB_EC_SIZE_OVERFLOW));
8753-
}
8754-
if (CB_EXCEPTION_ENABLE(COB_EC_SIZE_TRUNCATION)) {
8755-
ec_checked = 1;
8756-
output_line("if (cob_glob_ptr->cob_exception_code == %d) "
8757-
"cob_fatal_exception (cob_glob_ptr->cob_exception_code);",
8758-
CB_EXCEPTION_CODE(COB_EC_SIZE_TRUNCATION));
8759-
}
8760-
if (CB_EXCEPTION_ENABLE(COB_EC_SIZE_UNDERFLOW)) {
8761-
ec_checked = 1;
8762-
output_line("if (cob_glob_ptr->cob_exception_code == %d) "
8763-
"cob_fatal_exception (cob_glob_ptr->cob_exception_code);",
8764-
CB_EXCEPTION_CODE(COB_EC_SIZE_UNDERFLOW));
8765-
}
8766-
if (CB_EXCEPTION_ENABLE(COB_EC_SIZE_ZERO_DIVIDE)) {
8767-
ec_checked = 1;
8768-
output_line("if (cob_glob_ptr->cob_exception_code == %d) "
8769-
"cob_fatal_exception (cob_glob_ptr->cob_exception_code);",
8770-
CB_EXCEPTION_CODE(COB_EC_SIZE_ZERO_DIVIDE));
8771-
}
8772-
8773-
output_block_close();
8774-
8725+
if (CB_EXCEPTION_ENABLE (COB_EC_SIZE_ADDRESS)) {
8726+
ec_checked |= CB_EXCEPTION_CODE (COB_EC_SIZE_ADDRESS);
8727+
}
8728+
if (CB_EXCEPTION_ENABLE (COB_EC_SIZE_EXPONENTIATION)) {
8729+
ec_checked |= CB_EXCEPTION_CODE (COB_EC_SIZE_EXPONENTIATION);
8730+
}
8731+
if (CB_EXCEPTION_ENABLE (COB_EC_SIZE_IMP)) {
8732+
ec_checked |= CB_EXCEPTION_CODE (COB_EC_SIZE_IMP);
8733+
}
8734+
if (CB_EXCEPTION_ENABLE (COB_EC_SIZE_OVERFLOW)) {
8735+
ec_checked |= CB_EXCEPTION_CODE (COB_EC_SIZE_OVERFLOW);
8736+
}
8737+
if (CB_EXCEPTION_ENABLE (COB_EC_SIZE_TRUNCATION)) {
8738+
ec_checked |= CB_EXCEPTION_CODE (COB_EC_SIZE_TRUNCATION);
8739+
}
8740+
if (CB_EXCEPTION_ENABLE (COB_EC_SIZE_UNDERFLOW)) {
8741+
ec_checked |= CB_EXCEPTION_CODE (COB_EC_SIZE_UNDERFLOW);
8742+
}
8743+
if (CB_EXCEPTION_ENABLE (COB_EC_SIZE_ZERO_DIVIDE)) {
8744+
ec_checked |= CB_EXCEPTION_CODE (COB_EC_SIZE_ZERO_DIVIDE);
8745+
}
87758746
if (ec_checked) {
8776-
output_line("cob_reset_exception ();");
8747+
output_line (
8748+
"if (((cob_glob_ptr->cob_exception_code & 0x%04x) == 0x%04x)"
8749+
" && ((cob_glob_ptr->cob_exception_code & 0x%04x) != 0)"
8750+
" && (cob_glob_ptr->cob_got_exception > 0))",
8751+
CB_EXCEPTION_CODE (COB_EC_SIZE),
8752+
CB_EXCEPTION_CODE (COB_EC_SIZE),
8753+
ec_checked & 0x00FF);
8754+
output_line ("\t" "cob_fatal_exception (cob_glob_ptr->cob_exception_code);");
87778755
}
8778-
8756+
87798757
}
87808758

87818759
static void

libcob/ChangeLog

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,17 @@
88
* fileio.c (cob_file_close): close file depending on internal state, not
99
depending on file organization
1010

11+
2025-12-04 Emilien Lemaire <[email protected]>
12+
13+
* exception.def: exceptions values for EC-SIZE are now bit exclusive
14+
1115
2025-11-24 Emilien Lemaire <[email protected]>
1216

1317
* common.h, common.c: add `cob_reset_exception` which disable an
1418
exception check after one was performed, but still allows the
1519
exception intrinsic functions to check for them
20+
* common.h, common.c: add `cob_last_exception_fatal`, to check if the
21+
last raised exception was fatal
1622
* common.h, common.c: add enum member `COB_FERROR_FATAL_EC` for
1723
`struct cob_fatal_error` which can be used when terminating the
1824
program due to a fatal exception
@@ -46,13 +52,10 @@
4652
parsing and general handling of finished/not finished also when built
4753
without libxml2
4854

49-
<<<<<<< HEAD
5055
2025-11-10 Emilien Lemaire <[email protected]>
5156

5257
* common.h, common.c: add `cob_exception_tab_fatal`, which informs
5358
whether an exception is fatal or not
54-
* common.h, common.c: add `cob_last_exception_fatal`, to check if the
55-
last raised exception was fatal
5659
* common.h, common.c: add enum member `COB_FERROR_FATAL_EC` for
5760
`struct cob_fatal_error` which can be used when terminating the
5861
program due to a fatal exception
@@ -65,8 +68,6 @@
6568
* call.c (add_to_preload): remove usage of cob_strcat and directly
6669
concatenate preload paths instead
6770

68-
=======
69-
>>>>>>> 1d54c863 (Edits after review)
7071
2025-10-31 Simon Sobisch <[email protected]>
7172

7273
first performance-tweaks for JSON GENERATE and XML GENERATE

libcob/exception.def

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -571,31 +571,31 @@ COB_EXCEPTION (1000, COB_EC_SIZE,
571571
"EC-SIZE", 0)
572572

573573
/* Invalid pointer arithmetic */
574-
COB_EXCEPTION (1001, COB_EC_SIZE_ADDRESS,
574+
COB_EXCEPTION (1000 | (1 << 0), COB_EC_SIZE_ADDRESS,
575575
"EC-SIZE-ADDRESS", 1)
576576

577577
/* Exponentiation rules violated */
578-
COB_EXCEPTION (1002, COB_EC_SIZE_EXPONENTIATION,
578+
COB_EXCEPTION (1000 | (1 << 1), COB_EC_SIZE_EXPONENTIATION,
579579
"EC-SIZE-EXPONENTIATION", 1)
580580

581581
/* Implementation-defined size error exception */
582-
COB_EXCEPTION (1003, COB_EC_SIZE_IMP,
582+
COB_EXCEPTION (1000 | (1 << 2), COB_EC_SIZE_IMP,
583583
"EC-SIZE-IMP", 0)
584584

585585
/* Arithmetic overflow in calculation */
586-
COB_EXCEPTION (1004, COB_EC_SIZE_OVERFLOW,
586+
COB_EXCEPTION (1000 | (1 << 3), COB_EC_SIZE_OVERFLOW,
587587
"EC-SIZE-OVERFLOW", 1)
588588

589589
/* Significant digits truncated in store */
590-
COB_EXCEPTION (1005, COB_EC_SIZE_TRUNCATION,
590+
COB_EXCEPTION (1000 | (1 << 4), COB_EC_SIZE_TRUNCATION,
591591
"EC-SIZE-TRUNCATION", 1)
592592

593593
/* Floating-point underflow */
594-
COB_EXCEPTION (1006, COB_EC_SIZE_UNDERFLOW,
594+
COB_EXCEPTION (1000 | (1 << 5), COB_EC_SIZE_UNDERFLOW,
595595
"EC-SIZE-UNDERFLOW", 1)
596596

597597
/* Division by zero */
598-
COB_EXCEPTION (1007, COB_EC_SIZE_ZERO_DIVIDE,
598+
COB_EXCEPTION (1000 | (1 << 6), COB_EC_SIZE_ZERO_DIVIDE,
599599
"EC-SIZE-ZERO-DIVIDE", 1)
600600

601601

0 commit comments

Comments
 (0)