diff --git a/cobc/ChangeLog b/cobc/ChangeLog index cce36250c..e22f8351b 100644 --- a/cobc/ChangeLog +++ b/cobc/ChangeLog @@ -32,6 +32,11 @@ to XML PARSE statement to fix out-of-scope memory trashing * codegen.c (output_param): resolve reference value only once +2025-10-21 Roger Bowler + + * field.c (setup_parameters): set flag_binary_swap for COMP-5 fields + when comp-5-uses-binary-byteorder dialect option is set + 2025-10-17 Simon Sobisch * parser.y (file_description_entry): create an unnamed file in case diff --git a/cobc/config.def b/cobc/config.def index 6c137a5c5..616e53cd5 100644 --- a/cobc/config.def +++ b/cobc/config.def @@ -111,6 +111,9 @@ CB_CONFIG_BOOLEAN (cb_pretty_display, "pretty-display", CB_CONFIG_BOOLEAN (cb_binary_truncate, "binary-truncate", _("numeric truncation according to ANSI")) +CB_CONFIG_BOOLEAN (cb_comp_5_uses_binary_byteorder, "comp-5-uses-binary-byteorder", + _("COMP-5 uses the same byte order as BINARY")) + CB_CONFIG_BOOLEAN (cb_complex_odo, "complex-odo", _("allow non-standard OCCURS DEPENDING ON syntax")) diff --git a/cobc/field.c b/cobc/field.c index bc1f458cf..b734a0424 100644 --- a/cobc/field.c +++ b/cobc/field.c @@ -2530,6 +2530,11 @@ setup_parameters (struct cb_field *f) } } #ifndef WORDS_BIGENDIAN + if (f->usage == CB_USAGE_COMP_5 && + cb_comp_5_uses_binary_byteorder && + cb_binary_byteorder == CB_BYTEORDER_BIG_ENDIAN) { + f->flag_binary_swap = 1; + } if (f->usage == CB_USAGE_COMP_X && cb_binary_byteorder == CB_BYTEORDER_BIG_ENDIAN) { f->flag_binary_swap = 1; diff --git a/config/ChangeLog b/config/ChangeLog index 15f49cb77..ae659c5a0 100644 --- a/config/ChangeLog +++ b/config/ChangeLog @@ -4,6 +4,10 @@ * runtime.cfg: add runtime configuration COB_SIGNAL_REGIME to allow configuration of installed signal handlers +2025-10-21 Roger Bowler + + * general: add option comp-5-uses-binary-byteorder + 2025-04-22 Chuck Haatvedt * runtime.cfg: add runtime configuration COB_HEAP_MEMORY and diff --git a/config/acu-strict.conf b/config/acu-strict.conf index 2b9e45b17..9622b9c82 100644 --- a/config/acu-strict.conf +++ b/config/acu-strict.conf @@ -97,6 +97,9 @@ binary-truncate: yes # Value: 'native', 'big-endian' binary-byteorder: big-endian +# COMP-5 uses binary byte order instead of native byte order +comp-5-uses-binary-byteorder: no + # Allow larger REDEFINES items other than 01 non-external larger-redefines: ok # not verified yet diff --git a/config/bs2000-strict.conf b/config/bs2000-strict.conf index 2c0a1fae8..8ae20041e 100644 --- a/config/bs2000-strict.conf +++ b/config/bs2000-strict.conf @@ -99,6 +99,9 @@ binary-truncate: yes # TO-DO: For BINARY, *not* for COMP or COMP-5! # Value: 'native', 'big-endian' binary-byteorder: big-endian +# COMP-5 uses binary byte order instead of native byte order +comp-5-uses-binary-byteorder: no + # Allow larger REDEFINES items other than 01 non-external larger-redefines: error diff --git a/config/cobol2002.conf b/config/cobol2002.conf index 6548f790c..ecc407e40 100644 --- a/config/cobol2002.conf +++ b/config/cobol2002.conf @@ -98,6 +98,9 @@ binary-truncate: yes # Value: 'native', 'big-endian' binary-byteorder: big-endian +# COMP-5 uses binary byte order instead of native byte order +comp-5-uses-binary-byteorder: no + # Allow larger REDEFINES items other than 01 non-external larger-redefines: error diff --git a/config/cobol2014.conf b/config/cobol2014.conf index 7f1492468..70ed454a3 100644 --- a/config/cobol2014.conf +++ b/config/cobol2014.conf @@ -98,6 +98,9 @@ binary-truncate: yes # Value: 'native', 'big-endian' binary-byteorder: big-endian +# COMP-5 uses binary byte order instead of native byte order +comp-5-uses-binary-byteorder: no + # Allow larger REDEFINES items other than 01 non-external larger-redefines: error diff --git a/config/cobol85.conf b/config/cobol85.conf index f05669281..cd93147ac 100644 --- a/config/cobol85.conf +++ b/config/cobol85.conf @@ -98,6 +98,9 @@ binary-truncate: yes # Value: 'native', 'big-endian' binary-byteorder: big-endian +# COMP-5 uses binary byte order instead of native byte order +comp-5-uses-binary-byteorder: no + # Allow larger REDEFINES items other than 01 non-external larger-redefines: error diff --git a/config/default.conf b/config/default.conf index c4510e71c..c5bcbfadc 100644 --- a/config/default.conf +++ b/config/default.conf @@ -118,6 +118,9 @@ binary-truncate: yes # Value: 'native', 'big-endian' binary-byteorder: big-endian +# COMP-5 uses binary byte order instead of native byte order +comp-5-uses-binary-byteorder: no + # Allow larger REDEFINES items other than 01 non-external larger-redefines: error diff --git a/config/gcos-strict.conf b/config/gcos-strict.conf index 123d2d5e7..066360046 100644 --- a/config/gcos-strict.conf +++ b/config/gcos-strict.conf @@ -97,6 +97,9 @@ binary-truncate: yes # Value: 'native', 'big-endian' binary-byteorder: big-endian +# COMP-5 uses binary byte order instead of native byte order +comp-5-uses-binary-byteorder: no + # Allow larger REDEFINES items larger-redefines: error diff --git a/config/ibm-strict.conf b/config/ibm-strict.conf index 41c6b4727..3c1405ee8 100644 --- a/config/ibm-strict.conf +++ b/config/ibm-strict.conf @@ -97,6 +97,9 @@ binary-truncate: no # Value: 'native', 'big-endian' binary-byteorder: big-endian +# COMP-5 uses binary byte order instead of native byte order +comp-5-uses-binary-byteorder: no + # Allow larger REDEFINES items other than 01 non-external larger-redefines: error diff --git a/config/mf-strict.conf b/config/mf-strict.conf index ee5d8b8fb..c9c4d8d69 100644 --- a/config/mf-strict.conf +++ b/config/mf-strict.conf @@ -100,6 +100,9 @@ binary-truncate: no # Value: 'native', 'big-endian' binary-byteorder: big-endian +# COMP-5 uses binary byte order instead of native byte order +comp-5-uses-binary-byteorder: no + # Allow larger REDEFINES items other than 01 non-external larger-redefines: ok diff --git a/config/mvs-strict.conf b/config/mvs-strict.conf index fe928cb75..ef2d1f94c 100644 --- a/config/mvs-strict.conf +++ b/config/mvs-strict.conf @@ -97,6 +97,9 @@ binary-truncate: no # Value: 'native', 'big-endian' binary-byteorder: big-endian +# COMP-5 uses binary byte order instead of native byte order +comp-5-uses-binary-byteorder: no + # Allow larger REDEFINES items other than 01 non-external larger-redefines: error diff --git a/config/realia-strict.conf b/config/realia-strict.conf index 1e40d19e1..14e2f32f7 100644 --- a/config/realia-strict.conf +++ b/config/realia-strict.conf @@ -97,6 +97,9 @@ binary-truncate: no # to check # Value: 'native', 'big-endian' binary-byteorder: big-endian # to check +# COMP-5 uses binary byte order instead of native byte order +comp-5-uses-binary-byteorder: no + # Allow larger REDEFINES items other than 01 non-external larger-redefines: error # not verified yet diff --git a/config/rm-strict.conf b/config/rm-strict.conf index 0af678a73..46f36cebe 100644 --- a/config/rm-strict.conf +++ b/config/rm-strict.conf @@ -103,6 +103,9 @@ binary-truncate: yes # Value: 'native', 'big-endian' binary-byteorder: big-endian +# COMP-5 uses binary byte order instead of native byte order +comp-5-uses-binary-byteorder: no + # Allow larger REDEFINES items other than 01 non-external larger-redefines: ok # (see p. 134) diff --git a/config/xopen.conf b/config/xopen.conf index 8bb576113..2c19b4da5 100644 --- a/config/xopen.conf +++ b/config/xopen.conf @@ -111,6 +111,9 @@ binary-truncate: yes # Value: 'native', 'big-endian' binary-byteorder: big-endian +# COMP-5 uses binary byte order instead of native byte order +comp-5-uses-binary-byteorder: no + # Allow larger REDEFINES items other than 01 non-external larger-redefines: error diff --git a/tests/testsuite.src/configuration.at b/tests/testsuite.src/configuration.at index e2035b0cf..ee86e40de 100644 --- a/tests/testsuite.src/configuration.at +++ b/tests/testsuite.src/configuration.at @@ -431,6 +431,7 @@ test.conf: missing definitions: no definition of 'filename-mapping' no definition of 'pretty-display' no definition of 'binary-truncate' + no definition of 'comp-5-uses-binary-byteorder' no definition of 'complex-odo' no definition of 'odoslide' no definition of 'init-justify' diff --git a/tests/testsuite.src/data_binary.at b/tests/testsuite.src/data_binary.at index 6dbee7a41..3d37b37b0 100644 --- a/tests/testsuite.src/data_binary.at +++ b/tests/testsuite.src/data_binary.at @@ -1406,6 +1406,96 @@ DISPLAY: 85 != BINARY : 217 AT_CLEANUP +# comp-5 byteorder + +AT_SETUP([COMP-5 byteorder]) +AT_KEYWORDS([binary comp-5 byteorder]) + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 X-P2 BINARY-SHORT UNSIGNED VALUE 23456. + 01 X-P3 BINARY-LONG UNSIGNED VALUE 2345678901. + 01 X-P4 BINARY-DOUBLE UNSIGNED VALUE 2345678901234567891. + 01 X-P6 PIC 9(4) COMP-5 VALUE 23456. + 01 X-P7 PIC 9(8) COMP-5 VALUE 2345678901. + 01 X-P8 PIC 9(18) COMP-5 VALUE 2345678901234567891. + 01 X-N2 BINARY-SHORT VALUE -12345. + 01 X-N3 BINARY-LONG VALUE -1234567890. + 01 X-N4 BINARY-DOUBLE VALUE -1234567890123456789. + 01 X-N6 PIC S9(4) COMP-5 VALUE -12345. + 01 X-N7 PIC S9(8) COMP-5 VALUE -1234567890. + 01 X-N8 PIC S9(18) COMP-5 VALUE -1234567890123456789. + PROCEDURE DIVISION. + DISPLAY 'BINARY-SHORT UNSIGNED ' FUNCTION HEX-OF(X-P2) + DISPLAY 'BINARY-LONG UNSIGNED ' FUNCTION HEX-OF(X-P3) + DISPLAY 'BINARY-DOUBLE UNSIGNED ' FUNCTION HEX-OF(X-P4) + DISPLAY 'PIC 9(4) COMP-5 ' FUNCTION HEX-OF(X-P6) + DISPLAY 'PIC 9(8) COMP-5 ' FUNCTION HEX-OF(X-P7) + DISPLAY 'PIC 9(18) COMP-5 ' FUNCTION HEX-OF(X-P8) + DISPLAY 'BINARY-SHORT ' FUNCTION HEX-OF(X-N2) + DISPLAY 'BINARY-LONG ' FUNCTION HEX-OF(X-N3) + DISPLAY 'BINARY-DOUBLE ' FUNCTION HEX-OF(X-N4) + DISPLAY 'PIC S9(4) COMP-5 ' FUNCTION HEX-OF(X-N6) + DISPLAY 'PIC S9(8) COMP-5 ' FUNCTION HEX-OF(X-N7) + DISPLAY 'PIC S9(18) COMP-5 ' FUNCTION HEX-OF(X-N8) + STOP RUN. +]) + +if test "x$COB_BIGENDIAN" = "xyes"; then +AT_CHECK([true]) +else + +# COMP-5 BINARY-SHORT BINARY-LONG and BINARY-DOUBLE +# are stored in native (little-endian) format, +# even when binary-byteorder=big-endian is specified, +# unless comp-5-uses-binary-byteorder is also specified +AT_CHECK([$COMPILE -fbinary-size=2-4-8 \ + -fbinary-byteorder=big-endian \ + prog.cob -o prog3], [0], [], []) +AT_CHECK([$COBCRUN_DIRECT ./prog3], [0], +[BINARY-SHORT UNSIGNED A05B +BINARY-LONG UNSIGNED 3538D08B +BINARY-DOUBLE UNSIGNED D30A376188868D20 +PIC 9(4) COMP-5 A05B +PIC 9(8) COMP-5 3538D08B +PIC 9(18) COMP-5 D30A376188868D20 +BINARY-SHORT C7CF +BINARY-LONG 2EFD69B6 +BINARY-DOUBLE EB7E16820BEFDDEE +PIC S9(4) COMP-5 C7CF +PIC S9(8) COMP-5 2EFD69B6 +PIC S9(18) COMP-5 EB7E16820BEFDDEE +]) +fi + +# COMP-5 BINARY-SHORT BINARY-LONG and BINARY-DOUBLE +# are stored in big-endian format only when specifying both +# binary-byteorder=big-endian and comp-5-uses-binary-byteorder +AT_CHECK([$COMPILE -fbinary-size=2-4-8 \ + -fbinary-byteorder=big-endian \ + -fcomp-5-uses-binary-byteorder \ + prog.cob -o prog4], [0], [], []) +AT_CHECK([$COBCRUN_DIRECT ./prog4], [0], +[BINARY-SHORT UNSIGNED 5BA0 +BINARY-LONG UNSIGNED 8BD03835 +BINARY-DOUBLE UNSIGNED 208D868861370AD3 +PIC 9(4) COMP-5 5BA0 +PIC 9(8) COMP-5 8BD03835 +PIC 9(18) COMP-5 208D868861370AD3 +BINARY-SHORT CFC7 +BINARY-LONG B669FD2E +BINARY-DOUBLE EEDDEF0B82167EEB +PIC S9(4) COMP-5 CFC7 +PIC S9(8) COMP-5 B669FD2E +PIC S9(18) COMP-5 EEDDEF0B82167EEB +]) + +AT_CLEANUP + + AT_SETUP([MOVE DISPLAY to BINARY]) AT_KEYWORDS([fundamental PPP])