[gcc r15-8261] cobol: Bring the code base into compliance with C++14
https://gcc.gnu.org/g:c49382fd221fd40bce35a954d64bbda0fd14edef commit r15-8261-gc49382fd221fd40bce35a954d64bbda0fd14edef Author: Bob Dubner Date: Tue Mar 18 07:47:39 2025 -0400 cobol: Bring the code base into compliance with C++14 gcc/cobol * cdf.y: Make compatible with C++14. * copybook.h: Likewise. * dts.h: Likewise. * except.cc: Likewise. * genapi.cc: Likewise. * genutil.cc: Likewise. * genutil.h: Likewise. * lexio.cc: Likewise. * parse.y: Likewise. * parse_ante.h: Likewise. * show_parse.h: Likewise. * symbols.cc: Likewise. * symbols.h: Likewise. * util.cc: Likewise. Diff: --- gcc/cobol/cdf.y| 12 +- gcc/cobol/copybook.h | 21 +-- gcc/cobol/dts.h| 6 +- gcc/cobol/except.cc| 9 +- gcc/cobol/genapi.cc| 79 +- gcc/cobol/genutil.cc | 3 + gcc/cobol/genutil.h| 4 + gcc/cobol/lexio.cc | 23 +-- gcc/cobol/parse.y | 406 - gcc/cobol/parse_ante.h | 79 +- gcc/cobol/show_parse.h | 2 +- gcc/cobol/symbols.cc | 268 gcc/cobol/symbols.h| 230 +--- gcc/cobol/util.cc | 66 14 files changed, 724 insertions(+), 484 deletions(-) diff --git a/gcc/cobol/cdf.y b/gcc/cobol/cdf.y index beb4697b8419..12d11e78116e 100644 --- a/gcc/cobol/cdf.y +++ b/gcc/cobol/cdf.y @@ -702,7 +702,9 @@ suppress: %empty ; name_any: namelit - | PSEUDOTEXT { $$ = (cdf_arg_t){YDF_PSEUDOTEXT, $1}; } + | PSEUDOTEXT { + $$ = cdf_arg_t{YDF_PSEUDOTEXT, $1}; + } ; name_one: NAME @@ -715,8 +717,8 @@ name_one: NAME } $$ = arg; } - | NUMSTR { $$ = (cdf_arg_t){YDF_NUMSTR, $1}; } - | LITERAL { $$ = (cdf_arg_t){YDF_LITERAL, $1}; } + | NUMSTR { $$ = cdf_arg_t{YDF_NUMSTR, $1}; } + | LITERAL { $$ = cdf_arg_t{YDF_LITERAL, $1}; } ; namelit: name @@ -738,8 +740,8 @@ namelit:name cdf_arg_t arg = { YDF_NAME, s }; $$ = arg; } - | NUMSTR { $$ = (cdf_arg_t){YDF_NUMSTR, $1}; } - | LITERAL { $$ = (cdf_arg_t){YDF_LITERAL, $1}; } + | NUMSTR { $$ = cdf_arg_t{YDF_NUMSTR, $1}; } + | LITERAL { $$ = cdf_arg_t{YDF_LITERAL, $1}; } ; name: NAME diff --git a/gcc/cobol/copybook.h b/gcc/cobol/copybook.h index 3e2cf9d934e8..e509bf35bb72 100644 --- a/gcc/cobol/copybook.h +++ b/gcc/cobol/copybook.h @@ -128,25 +128,28 @@ private: char *regex_text; }; +class uppername_t { + std::string upper; + public: + uppername_t( const std::string input ) : upper(input) { +std::transform(input.begin(), input.end(), upper.begin(), + []( char ch ) { return TOUPPER(ch); } ); + } + const char *data() const { return upper.data(); } +}; + class copybook_t { std::list directories; copybook_elem_t book; // Take copybook name from the environment, if defined, else use it verbatim. static const char * transform_name( const char name[] ) { -char uname[ strlen(name) ]; +uppername_t uname(name); const char *value = getenv(name); if( !value ) { - auto ename = name + strlen(name); - std::transform( name, ename, uname, - []( char ch ) { return TOUPPER(ch); } ); - value = getenv(uname); // try uppercase of envar name + value = getenv(uname.data()); // try uppercase of envar name if( !value ) value = name; // keep original unmodified } -if( false && value != uname ) { - dbgmsg("using copybook file '%s' from environment variable '%s'", - value, name); -} return xstrdup(value); } diff --git a/gcc/cobol/dts.h b/gcc/cobol/dts.h index 618f649c2e1e..c345dc7e64ab 100644 --- a/gcc/cobol/dts.h +++ b/gcc/cobol/dts.h @@ -93,12 +93,12 @@ namespace dts { if( eoinput == NULL ) eoinput = strchr(input, '\0'); auto ncm = re.size(); cm.resize(ncm); -regmatch_t cms[ncm]; +std::vector cms(ncm); -int erc = regexec( &re, input, ncm, cms, 0 ); +int erc = regexec( &re, input, ncm, cms.data(), 0 ); if( erc != 0 ) return false; -std::transform( cms, cms+ncm, cm.begin(), +std::transform( cms.begin(), cms.end(), cm.begin(), [input]( const regmatch_t& m ) { return csub_match( input, m ); } ); diff --git a/gcc/cobol/except.cc b/gcc/cobol/except.cc index 3510ca3ac218..5374201b4c82 100644 --- a/gcc/cobol/except.cc +++ b/gcc/cobol/except.cc @@ -279,10 +279,11 @@ symbol_declaratives_add( size_t program, char achBlob[32]; sprintf(achBlob, "_DECL
[gcc r15-8263] cobol: Fifteen new cobol.dg testscases.
https://gcc.gnu.org/g:82bb1890aeab275541f8d3606641e8c0cadc9659 commit r15-8263-g82bb1890aeab275541f8d3606641e8c0cadc9659 Author: Bob Dubner Date: Mon Mar 17 21:47:05 2025 -0400 cobol: Fifteen new cobol.dg testscases. gcc/testsuite * cobol.dg/group1/check_88.cob: New testcase. * cobol.dg/group1/comp5.cob: Likewise. * cobol.dg/group1/declarative_1.cob: Likewise. * cobol.dg/group1/display.cob: Likewise. * cobol.dg/group1/display2.cob: Likewise. * cobol.dg/group1/line-sequential.cob: Likewise. * cobol.dg/group1/multiple-compares.cob: Likewise. * cobol.dg/group1/multiply2.cob: Likewise. * cobol.dg/group1/packed.cob: Likewise. * cobol.dg/group1/perform-nested-exit.cob: Likewise. * cobol.dg/group1/pointer1.cob: Likewise. * cobol.dg/group1/simple-arithmetic.cob: Likewise. * cobol.dg/group1/simple-classes.cob: Likewise. * cobol.dg/group1/simple-if.cob: Likewise. * cobol.dg/group1/simple-perform.cob: Likewise. Diff: --- gcc/testsuite/cobol.dg/group1/check_88.cob | 101 +++ gcc/testsuite/cobol.dg/group1/comp5.cob| 72 gcc/testsuite/cobol.dg/group1/declarative_1.cob| 116 + gcc/testsuite/cobol.dg/group1/display.cob | 14 ++ gcc/testsuite/cobol.dg/group1/display2.cob | 7 + gcc/testsuite/cobol.dg/group1/line-sequential.cob | 34 .../cobol.dg/group1/multiple-compares.cob | 192 + gcc/testsuite/cobol.dg/group1/multiply2.cob| 68 gcc/testsuite/cobol.dg/group1/packed.cob | 73 .../cobol.dg/group1/perform-nested-exit.cob| 84 + gcc/testsuite/cobol.dg/group1/pointer1.cob | 98 +++ .../cobol.dg/group1/simple-arithmetic.cob | 61 +++ gcc/testsuite/cobol.dg/group1/simple-classes.cob | 68 gcc/testsuite/cobol.dg/group1/simple-if.cob| 143 +++ gcc/testsuite/cobol.dg/group1/simple-perform.cob | 52 ++ 15 files changed, 1183 insertions(+) diff --git a/gcc/testsuite/cobol.dg/group1/check_88.cob b/gcc/testsuite/cobol.dg/group1/check_88.cob new file mode 100644 index ..4a7723eb92a3 --- /dev/null +++ b/gcc/testsuite/cobol.dg/group1/check_88.cob @@ -0,0 +1,101 @@ +*> { dg-do run } +*> { dg-output {\-><\-(\n|\r\n|\r)} } +*> { dg-output {\-> <\-(\n|\r\n|\r)} } +*> { dg-output {\->"""<\-(\n|\r\n|\r)} } +*> { dg-output {\->000<\-(\n|\r\n|\r)} } +*> { dg-output {\->ÿÿÿ<\-(\n|\r\n|\r)} } +*> { dg-output { (\n|\r\n|\r)} } +*> { dg-output {\-><\-(\n|\r\n|\r)} } +*> { dg-output {\-><\-(\n|\r\n|\r)} } +*> { dg-output {\-><\-(\n|\r\n|\r)} } +*> { dg-output {\-><\-(\n|\r\n|\r)} } +*> { dg-output {\-><\-(\n|\r\n|\r)} } +*> { dg-output { (\n|\r\n|\r)} } +*> { dg-output {There should be no garbage after character 32(\n|\r\n|\r)} } +*> { dg-output {\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\*\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-(\n|\r\n|\r)} } +*> { dg-output {üüü Bundesstraße (\n|\r\n|\r)} } +*> { dg-output {üüü Bundesstraße (\n|\r\n|\r)} } +*> { dg-output { (\n|\r\n|\r)} } +*> { dg-output {There should be no spaces before the final quote(\n|\r\n|\r)} } +*> { dg-output {"üüü Bundesstraße"(\n|\r\n|\r)} } +*> { dg-output { (\n|\r\n|\r)} } +*> { dg-output { IsLow ""(\n|\r\n|\r)} } +*> { dg-output { IsZero "000"(\n|\r\n|\r)} } +*> { dg-output { IsHi"ÿÿÿ"(\n|\r\n|\r)} } +*> { dg-output { IsBob "bob"(\n|\r\n|\r)} } +*> { dg-output { IsQuote "(\n|\r\n|\r)} } +*> { dg-output { IsSpace " "(\n|\r\n|\r)} } +*> { dg-output { (\n|\r\n|\r)} } +*> { dg-output {CheckBinary Properly True(\n|\r\n|\r)} } +*> { dg-output {CheckBinary Properly False} } +IDENTIFICATION DIVISION. +PROGRAM-ID. check88. +DATA DIVISION. +WORKING-STORAGE SECTION. +01 Check88 PIC XXX VALUE SPACE. + 88 CheckSpace VALUE SPACE. + 88 CheckHi VALUE HIGH-VALUES. + 88 CheckLo VALUE LOW-VALUES. + 88 CheckZero VALUE ZERO. + 88 CheckQuotes VALUE QUOTE. + 88 CheckBobVALUE "bob". + 88 CheckBinary VALUE X"000102". *> { dg-warning embedded } +01 000VARL PIC XXX VALUE LOW-VALUE. +01 000VARS PIC XXX VALUE SPACE. +01 000VARQ PIC XXX VALUE QUOTE. +01 000VARZ PIC XXX VALUE ZERO. +01 000VARH PIC XXX VALUE HIGH-VALUE. +01 MOVE-TARGET PIC . +01 VAR-UTF8 PIC X(64) VALUE "üüü Bundesstraße". + *> 01 VAR20 PIC 9V9(20) value "1.1". +01 VAR99 PIC 999 VALUE ZERO. +PROCEDURE DIVISION. +DISPLAY "->" 000VARL "<-" +DISPLAY "->" 0
[gcc r15-8076] cobol: add cobol.dg/group1/escape.cob test; modify cobol.dg/gd.exp to handle it
https://gcc.gnu.org/g:427972b2f1335c7430785ad4afd15386a17156ec commit r15-8076-g427972b2f1335c7430785ad4afd15386a17156ec Author: Robert Dubner Date: Sun Mar 16 12:20:01 2025 -0400 cobol: add cobol.dg/group1/escape.cob test; modify cobol.dg/gd.exp to handle it gcc/testsuite * cobol.dg/dg.exp: modified to recurse into directories without .exp files and find *.cob files therein. * cobol.dg/group1/escape.cob: New testcase. Diff: --- gcc/testsuite/cobol.dg/dg.exp| 17 +++-- gcc/testsuite/cobol.dg/group1/escape.cob | 11 +++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/gcc/testsuite/cobol.dg/dg.exp b/gcc/testsuite/cobol.dg/dg.exp index e75e3ab18954..d40cbd54e99d 100644 --- a/gcc/testsuite/cobol.dg/dg.exp +++ b/gcc/testsuite/cobol.dg/dg.exp @@ -33,10 +33,23 @@ set cobol_test_path $srcdir/$subdir set all_flags $DEFAULT_COBFLAGS +# Recursively find files in $dir and subdirs, do not walk into subdirs +# that contain their own .exp file. +proc find-cob-tests { dir suffix } { +set tests [lsort [glob -nocomplain -directory $dir "*.$suffix" ]] +foreach subdir [lsort [glob -nocomplain -type d -directory $dir *]] { +if { [glob -nocomplain -directory $subdir *.exp] eq "" } { +eval lappend tests [find-cob-tests $subdir $suffix] +} +} +return $tests +} + +set tests [find-cob-tests $srcdir/$subdir {cob}] + # Main loop. if [check_effective_target_cobol] { -cobol-dg-runtest [lsort \ - [glob -nocomplain $srcdir/$subdir/*.cob ] ] "" $all_flags +cobol-dg-runtest $tests "" $all_flags } # All done. diff --git a/gcc/testsuite/cobol.dg/group1/escape.cob b/gcc/testsuite/cobol.dg/group1/escape.cob new file mode 100644 index ..0ab52398cfe3 --- /dev/null +++ b/gcc/testsuite/cobol.dg/group1/escape.cob @@ -0,0 +1,11 @@ +*> { dg-do run } +*> { dg-output {Testing the testing(\n|\r|\r\n)} } +*> { dg-output {\.\^\$\*\+\-\?\(\)\[\]\{\}\\\|(\n|\r|\r\n)} } +*> { dg-output {"\.\^\$\*\+\-\?\(\)\[\]\{\}\\\|"} } +identification division. +program-id. escape. +procedure division. +display "Testing the testing" +display ".^$*+-?()[]{}\|" +display '".^$*+-?()[]{}\|"' . +end program escape.
[gcc r15-8239] cobol: Eliminate CPPFLAGS assignment from Make-lang.in [PR119213].
https://gcc.gnu.org/g:aa68eb8d5687f8e0944512cbc8533a77cd312873 commit r15-8239-gaa68eb8d5687f8e0944512cbc8533a77cd312873 Author: Bob Dubner Date: Mon Mar 17 13:13:50 2025 -0400 cobol: Eliminate CPPFLAGS assignment from Make-lang.in [PR119213]. A number of gcc/cobol files had to be modified to '#include "../../libgcobol/xxx.h" instead of "xxx.h" gcc/cobol PR cobol/119213 * Make-lang.in: Eliminate CPPFLAGS= assignment. * cdf.y: Modify #includes that reference libgcobol. * cobol1.cc: Modify #includes that reference libgcobol. * except.cc: Modify #includes that reference libgcobol. * gcobolspec.cc: Modify #includes that reference libgcobol. * genapi.cc: Modify #includes that reference libgcobol. * gengen.cc: Modify #includes that reference libgcobol. * genmath.cc: Modify #includes that reference libgcobol. * genutil.cc: Modify #includes that reference libgcobol. * parse.y: Modify #includes that reference libgcobol. * scan.l: Modify #includes that reference libgcobol. * structs.cc: Modify #includes that reference libgcobol. * symbols.cc: Modify #includes that reference libgcobol. * symfind.cc: Modify #includes that reference libgcobol. * util.cc: Modify #includes that reference libgcobol. Diff: --- gcc/cobol/Make-lang.in | 45 - gcc/cobol/cdf.y | 6 +++--- gcc/cobol/cobol1.cc | 8 gcc/cobol/except.cc | 10 +- gcc/cobol/gcobolspec.cc | 7 +++ gcc/cobol/genapi.cc | 14 +++--- gcc/cobol/gengen.cc | 4 ++-- gcc/cobol/genmath.cc| 10 +- gcc/cobol/genutil.cc| 14 +++--- gcc/cobol/parse.y | 16 gcc/cobol/scan.l| 6 +++--- gcc/cobol/structs.cc| 4 ++-- gcc/cobol/symbols.cc| 6 +++--- gcc/cobol/symfind.cc| 6 +++--- gcc/cobol/util.cc | 6 +++--- 15 files changed, 82 insertions(+), 80 deletions(-) diff --git a/gcc/cobol/Make-lang.in b/gcc/cobol/Make-lang.in index 650b695e7ef5..eccc1c43f23b 100644 --- a/gcc/cobol/Make-lang.in +++ b/gcc/cobol/Make-lang.in @@ -43,26 +43,8 @@ cobol: cobol1$(exeext) cobol.serial = cobol1$(exeext) .PHONY: cobol -BINCLUDE ?= ./gcc -LIB_INCLUDE ?= $(srcdir)/../libgcobol LIB_SOURCE ?= $(srcdir)/../libgcobol -# -# At this point, as of 2022-10-21, CPPFLAGS is an empty string and can be -# altered. CFLAGS and CXXFLAGS are being established upstream, and thus -# cannot, at this point, be changed. -# -# Note further that we are producing only a 64-bit version of libgcobol.so, so -# it is safe to hard-code the lib64 location. This obviously has to match the -# installation code in libgcobol/Makefile.in -# -CPPFLAGS = \ - -std=c++14\ - -I$(BINCLUDE) \ - -I$(LIB_INCLUDE) \ - -DEXEC_LIB=\"$(prefix)/lib64\"\ - $(END) - YFLAGS = -Werror -Wmidrule-values -Wno-yacc \ --debug --verbose @@ -96,16 +78,37 @@ cobol1_OBJS =\ # There is source code in libgcobol/charmaps.cc and # libgcobol/valconv.cc that needs to be compiled into both libgcobol # and cobol1. We copy those two source code files from libgcobol to -# here to avoid the nightmare of one file appearing in more than one -# place. For simplicity, we make those compilations dependent on all -# of the libgcobol/*.h files, which might lead to the occasional +# build/gcc/cobol to avoid the nightmare of one file appearing in more +# than one place. For simplicity, we make those compilations dependent +# on all of the libgcobol/*.h files, which might lead to the occasional # unnecessary compilation. The impact of that is negligible. # +# Various #includes in the files copied from gcc/libgcobol need to be modified +# so that the .h files can be found. + cobol/charmaps.cc: $(LIB_SOURCE)/charmaps.cc cp $^ $@ + sed -i "s|\"ec[.]h\"|\"$(LIB_SOURCE)/ec.h\"|g" $@ + sed -i "s|\"common-defs[.]h\"|\"$(LIB_SOURCE)/common-defs.h\"|g" $@ + sed -i "s|\"io[.]h\"|\"$(LIB_SOURCE)/io.h\"|g" $@ + sed -i "s|\"gcobolio[.]h\"|\"$(LIB_SOURCE)/gcobolio.h\"|g" $@ + sed -i "s|\"libgcobol[.]h\"|\"$(LIB_SOURCE)/libgcobol.h\"|g" $@ + sed -i "s|\"gfileio[.]h\"|\"$(LIB_SOURCE)/gfileio.h\"|g" $@ + sed -i "s|\"charmaps[.]h\"|\"$(LIB_SOURCE)/charmaps.h\"|g" $@ + sed -i "s|\"valconv[.]h\"|\"$(LIB_SOURCE)/valconv.h\"|g" $@ + sed -i "s|\"exceptl[.]h\"|\"$(LIB_SOURCE)/exceptl.h\"|g" $@ cobol/valconv.cc: $(LIB_SOURCE)/valconv.cc cp $^ $@ + sed -i "s|\"ec[.]h\"|\"$(LIB_SOURCE)/ec.h\"|g" $@ + sed -i "s|\"common-defs[.]h\"|\"$(LIB_SOURCE)/common-defs.h\"|g" $@ + sed -i "s|\"io[.]h\"|\"$(LIB_SOURCE)/io.h\"|g" $@ + sed -i "s|\"g
[gcc r15-8238] libgcobol: Remove unused headers from shared sources.
https://gcc.gnu.org/g:80ef26563f17e724af15edd9d5836901192bd26e commit r15-8238-g80ef26563f17e724af15edd9d5836901192bd26e Author: Bob Dubner Date: Mon Mar 17 16:45:17 2025 -0400 libgcobol: Remove unused headers from shared sources. This reduces the number of headers included in sources that are shared with the Front End. libgcobol/ChangeLog: * charmaps.cc: Remove unused headers * libgcobol.h: Likewise. * valconv.cc: Likewise. Signed-off-by: Iain Sandoe Diff: --- libgcobol/charmaps.cc | 6 -- libgcobol/libgcobol.h | 1 - libgcobol/valconv.cc | 16 3 files changed, 23 deletions(-) diff --git a/libgcobol/charmaps.cc b/libgcobol/charmaps.cc index 561fe2301215..6a7975030df0 100644 --- a/libgcobol/charmaps.cc +++ b/libgcobol/charmaps.cc @@ -30,16 +30,10 @@ */ #include -#include -#include -#include #include -#include #include #include -#include #include -#include #include #include #include diff --git a/libgcobol/libgcobol.h b/libgcobol/libgcobol.h index bd9446adf601..513f34ab2b95 100644 --- a/libgcobol/libgcobol.h +++ b/libgcobol/libgcobol.h @@ -33,7 +33,6 @@ #include #include -#include #include #define MIN_FIELD_BLOCK_SIZE (16) diff --git a/libgcobol/valconv.cc b/libgcobol/valconv.cc index 02dd3cc55007..0b80d72cc3a6 100644 --- a/libgcobol/valconv.cc +++ b/libgcobol/valconv.cc @@ -30,31 +30,15 @@ */ #include -#include -#include -#include -#include #include -#include #include -#include -#include #include #include -#include #include "ec.h" #include "common-defs.h" -#include "io.h" -#include "gcobolio.h" -#include "libgcobol.h" -#include "gfileio.h" #include "charmaps.h" -#include -#include -#include - #include "valconv.h" #include "exceptl.h"
[gcc r15-8937] cobol: Bring trunk in line with Dubner's test system.
https://gcc.gnu.org/g:4c05d6d26dbc0e8799325cc1c1a8221b52e7e28e commit r15-8937-g4c05d6d26dbc0e8799325cc1c1a8221b52e7e28e Author: Bob Dubner Date: Wed Mar 26 16:07:44 2025 -0400 cobol: Bring trunk in line with Dubner's test system. gcc/cobol * genapi.cc: (parser_display_internal): Adjust for E vs e exponent notation. * parse.y: (literal_refmod_valid): Display correct value in error message. Diff: --- gcc/cobol/genapi.cc | 24 ++-- gcc/cobol/parse.y | 4 ++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/gcc/cobol/genapi.cc b/gcc/cobol/genapi.cc index dc0bb79e1532..032236b15dba 100644 --- a/gcc/cobol/genapi.cc +++ b/gcc/cobol/genapi.cc @@ -4818,14 +4818,34 @@ parser_display_internal(tree file_descriptor, if( !p ) { // Probably INF -INF NAN or -NAN, so ach has our result + // Except that real_to_decimal prints -0.0 and 0.0 like that with + // no e. + if( ach[0] == '0' || ( ach[0] == '-' && ach[1] == '0' )) +__gg__remove_trailing_zeroes(ach); } else { - p += 1; - int exp = atoi(p); + int exp = atoi(p+1); if( exp >= 6 || exp <= -5 ) { // We are going to stick with the E notation, so ach has our result +// Except that real_to_decimal prints with e notation rather than E +// and doesn't guarantee at least two exponent digits. +*p = 'E'; +if( exp < 0 && exp >= -9 ) + { +p[1] = '-'; +p[2] = '0'; +p[3] = '0' - exp; +p[4] = '\0'; + } +else if( exp >= 0 && exp <= 9 ) + { +p[1] = '+'; +p[2] = '0'; +p[3] = '0' + exp; +p[4] = '\0'; + } } else if (exp == 0) { diff --git a/gcc/cobol/parse.y b/gcc/cobol/parse.y index bad99528e599..538e56fa64d1 100644 --- a/gcc/cobol/parse.y +++ b/gcc/cobol/parse.y @@ -12856,14 +12856,14 @@ literal_refmod_valid( YYLTYPE loc, const cbl_refer_t& r ) { if( ! is_literal(refmod.len->field) ) return true; auto edge = refmod.len->field->as_integer(); if( 0 < edge ) { - if( --edge < r.field->data.capacity ) return true; + if( edge-1 < r.field->data.capacity ) return true; } // len < 0 or not: 0 < from + len <= capacity error_msg(loc, "%s(%s:%zu) out of bounds, " "size is %u", r.field->name, refmod.from->name(), - size_t(refmod.len->field->data.value_of()), + size_t(edge), static_cast(r.field->data.capacity) ); return false; }
[gcc r15-9215] cobol: Set compile-time and run-time signable_e bits the same for RETURN-CODE.
https://gcc.gnu.org/g:6602fc076a883cf0cd20a37655a6bd9c146a2770 commit r15-9215-g6602fc076a883cf0cd20a37655a6bd9c146a2770 Author: Bob Dubner Date: Fri Apr 4 18:33:42 2025 -0400 cobol: Set compile-time and run-time signable_e bits the same for RETURN-CODE. This fix reverts the recent cobol_langhook_post_options change setting flag_strict_aliasing = 0. It isn't necessary. gcc/cobol * cobol1.cc: Eliminate cobol_langhook_post_options. * symbols.cc: Definition of RETURN-CODE special register sets ::attr member to signable_e. Diff: --- gcc/cobol/cobol1.cc | 19 --- gcc/cobol/symbols.cc | 2 +- 2 files changed, 1 insertion(+), 20 deletions(-) diff --git a/gcc/cobol/cobol1.cc b/gcc/cobol/cobol1.cc index d175ab11e3f2..0d07c460d416 100644 --- a/gcc/cobol/cobol1.cc +++ b/gcc/cobol/cobol1.cc @@ -646,22 +646,6 @@ cobol_get_sarif_source_language(const char *) return "cobol"; } -bool -cobol_langhook_post_options(const char**) - { - // This flag, when set to 0, results in calls to gg_exit working properly. - // I don't know why it is necessary. There is something going on with the - // definition of __gg__data_return_code in constants.cc, and with how it - // is used through var_decl_return_code in genapi.cc. Without it, the value - // delivered to exit@PLT is zero, and not __gg__data_return_code - // Dubner, 2025-04-04. - flag_strict_aliasing = 0; - - /* Returning false means that the backend should be used. */ - return false; - } - - #undef LANG_HOOKS_BUILTIN_FUNCTION #undef LANG_HOOKS_GETDECLS #undef LANG_HOOKS_GLOBAL_BINDINGS_P @@ -676,7 +660,6 @@ cobol_langhook_post_options(const char**) #undef LANG_HOOKS_TYPE_FOR_SIZE #undef LANG_HOOKS_SET_DECL_ASSEMBLER_NAME #undef LANG_HOOKS_GET_SARIF_SOURCE_LANGUAGE -#undef LANG_HOOKS_POST_OPTIONS // We use GCC in the name, not GNU, as others do, // because "GnuCOBOL" refers to a different GNU project. @@ -702,8 +685,6 @@ cobol_langhook_post_options(const char**) #define LANG_HOOKS_GET_SARIF_SOURCE_LANGUAGE cobol_get_sarif_source_language -#define LANG_HOOKS_POST_OPTIONS cobol_langhook_post_options - struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER; #include "gt-cobol-cobol1.h" diff --git a/gcc/cobol/symbols.cc b/gcc/cobol/symbols.cc index 2373bfe6cc5a..50431251a0f1 100644 --- a/gcc/cobol/symbols.cc +++ b/gcc/cobol/symbols.cc @@ -2350,7 +2350,7 @@ symbol_table_init(void) { 0, {}, {2,2,2,0, NULL}, NULL }, { 0, FldNumericBin5, FldInvalid, 0, 0, 0, 0, nonarray, 0, "UPSI-0", 0, {}, {2,2,4,0, NULL}, NULL }, -{ 0, FldNumericBin5, FldInvalid, 0, 0, 0, 0, nonarray, 0, "RETURN-CODE", +{ 0, FldNumericBin5, FldInvalid, signable_e, 0, 0, 0, nonarray, 0, "RETURN-CODE", 0, {}, {2,2,4,0, NULL}, NULL }, { 0, FldNumericBin5, FldInvalid, 0, 0, 0, 0, nonarray, 0, "LINAGE-COUNTER", 0, {}, {2,2,4,0, NULL}, NULL },
[gcc r15-8913] cobol: Changes to eliminate _Float128 from the front end [PR119241]
https://gcc.gnu.org/g:e9adfb839f0d6aa05fd35d332b015623a33c3ce8 commit r15-8913-ge9adfb839f0d6aa05fd35d332b015623a33c3ce8 Author: Bob Dubner Date: Tue Mar 25 15:38:38 2025 -0400 cobol: Changes to eliminate _Float128 from the front end [PR119241] These changes switch _Float128 types to REAL_VALUE_TYPE in the front end. Some __int128 variables and function return values are changed to FIXED_WIDE_INT(128) gcc/cobol PR cobol/119241 * cdf.y: (cdfval_base_t::operator()): Return const. * cdfval.h: (struct cdfval_base_t): Add const cdfval_base_t& operator(). (struct cdfval_t): Add cdfval_t constructor. Change cdf_value definitions. * gcobolspec.cc (lang_specific_driver): Formatting fix. * genapi.cc: Include fold-const.h and realmpfr.h. (initialize_variable_internal): Use real_to_decimal instead of strfromf128. (get_binary_value_from_float): Use wide_int_to_tree instead of build_int_cst_type. (psa_FldLiteralN): Use fold_convert instead of strfromf128, real_from_string and build_real. (parser_display_internal): Rewritten to work on REAL_VALUE_TYPE rather than _Float128. (mh_source_is_literalN): Use FIXED_WIDE_INT(128) rather than __int128, wide_int_to_tree rather than build_int_cst_type, fold_convert rather than build_string_literal. (real_powi10): New function. (binary_initial_from_float128): Change type of last argument from _Float128 to REAL_VALUE_TYPE, process it using real.cc and mpfr APIs. (digits_from_float128): Likewise. (initial_from_float128): Make static. Remove value argument, add local REAL_VALUE_TYPE value variable instead, process it using real.cc and native_encode_expr APIs. (parser_symbol_add): Adjust initial_from_float128 caller. * genapi.h (initial_from_float128): Remove declaration. * genutil.cc (get_power_of_ten): Change return type from __int128 to FIXED_WIDE_INT(128), ditto for retval type, change type of pos from __int128 to unsigned long long. (scale_by_power_of_ten_N): Use wide_int_to_tree instead of build_int_cst_type. Use FIXED_WIDE_INT(128) instead of __int128 as power_of_ten variable type. (copy_little_endian_into_place): Likewise. * genutil.h (get_power_of_ten): Change return type from __int128 to FIXED_WIDE_INT(128). * parse.y (%union): Change type of float128 from _Float128 to REAL_VALUE_TYPE. (string_of): Change argument type from _Float128 to const REAL_VALUE_TYPE &, use real_to_decimal rather than strfromf128. Add another overload with tree argument type. (field: cdf): Use real_zerop rather than comparison against 0.0. (occurs_clause, const_value): Use real_to_integer. (value78): Use build_real and real_to_integer. (data_descr1): Use real_to_integer. (count): Use real_to_integer, real_from_integer and real_identical instead of direct comparison. (value_clause): Use real_from_string3 instead of num_str2i. Use real_identical instead of direct comparison. Use build_real. (allocate): Use real_isneg and real_iszero instead of <= 0 comparison. (move_tgt): Use real_to_integer, real_value_truncate, real_from_integer and real_identical instead of comparison of casts. (cce_expr): Use real_arithmetic and real_convert or real_value_negate instead of direct arithmetics on _Float128. (cce_factor): Use real_from_string3 instead of numstr2i. (literal_refmod_valid): Use real_to_integer. * symbols.cc (symbol_table_t::registers_t::registers_t): Formatting fix. (ERROR_FIELD): Likewise. (extend_66_capacity): Likewise. (cbl_occurs_t::subscript_ok): Use real_to_integer, real_from_integer and real_identical. * symbols.h (cbl_field_data_t::etc_t::value): Change type from _Float128 to tree. (cbl_field_data_t::etc_t::etc_t): Adjust defaulted argument value. (cbl_field_data_t::cbl_field_data_t): Formatting fix. Use etc() rather than etc(0). (cbl_field_data_t::value_of): Change return type from _Float128 to tree. (cbl_field_data_t::operator=): Change return and argument type from _Float128 to tree. (cbl_field_data_t::valify): Use real_from_string, real_value_truncate and build_real. (cbl_field_t::same_as): Use build_zero_cst instead of _Float128(0.0). gcc/t
[gcc r15-8991] cobol: Incorporate new testcases from the cobolworx UAT tests.
https://gcc.gnu.org/g:72ecfe355ad528e7e21d0c5ec24d33ae8cfc5b31 commit r15-8991-g72ecfe355ad528e7e21d0c5ec24d33ae8cfc5b31 Author: Bob Dubner Date: Thu Mar 27 17:55:53 2025 -0400 cobol: Incorporate new testcases from the cobolworx UAT tests. The author notes that some of the file names are regrettably lengthy, which is because they are derived from the descriptive names of the autom4te tests. gcc/testsuite * cobol.dg/group2/ACCEPT_DATE___DAY_and_intrinsic_functions__1_.cob: New testcase. * cobol.dg/group2/ACCEPT_DATE___DAY_and_intrinsic_functions__2_.cob: Likewise. * cobol.dg/group2/ACCEPT_FROM_TIME___DATE___DAY___DAY-OF-WEEK__1_.cob: Likewise. * cobol.dg/group2/ACCEPT_FROM_TIME___DATE___DAY___DAY-OF-WEEK__2_.cob: Likewise. * cobol.dg/group2/COMP-6_arithmetic.cob: Likewise. * cobol.dg/group2/COMP-6_numeric_test.cob: Likewise. * cobol.dg/group2/COMP-6_used_with_DISPLAY.cob: Likewise. * cobol.dg/group2/COMP-6_used_with_MOVE.cob: Likewise. * cobol.dg/group2/COMPUTE_multiplication_to_FIX4.cob: Likewise. * cobol.dg/group2/DISPLAY__Sign_ASCII__2_.cob: Likewise. * cobol.dg/group2/DISPLAY__Sign_ASCII.cob: Likewise. * cobol.dg/group2/Floating_continuation_indicator__1_.cob: Likewise. * cobol.dg/group2/floating-point_ADD_FORMAT_1.cob: Likewise. * cobol.dg/group2/floating-point_ADD_FORMAT_2.cob: Likewise. * cobol.dg/group2/floating-point_DIVIDE_FORMAT_1.cob: Likewise. * cobol.dg/group2/floating-point_DIVIDE_FORMAT_2.cob: Likewise. * cobol.dg/group2/floating-point_literals.cob: Likewise. * cobol.dg/group2/floating-point_MULTIPLY_FORMAT_1.cob: Likewise. * cobol.dg/group2/floating-point_MULTIPLY_FORMAT_2.cob: Likewise. * cobol.dg/group2/floating-point_SUBTRACT_FORMAT_1.cob: Likewise. * cobol.dg/group2/floating-point_SUBTRACT_FORMAT_2.cob: Likewise. * cobol.dg/group2/IBM_dialect_COMP_redefined_by_POINTER_as_64-bit.cob: Likewise. * cobol.dg/group2/Indicators___-D__.cob: Likewise. * cobol.dg/group2/MULTIPLY_to_FIX4.cob: Likewise. * cobol.dg/group2/PACKED-DECIMAL_arithmetic.cob: Likewise. * cobol.dg/group2/PACKED-DECIMAL_basic_comp-3_comp-6__1_.cob: Likewise. * cobol.dg/group2/PACKED-DECIMAL_basic_comp-3_comp-6__2_.cob: Likewise. * cobol.dg/group2/PACKED-DECIMAL_dump.cob: Likewise. * cobol.dg/group2/PACKED-DECIMAL_numeric_test__1_.cob: Likewise. * cobol.dg/group2/PACKED-DECIMAL_numeric_test__2_.cob: Likewise. * cobol.dg/group2/PACKED-DECIMAL_used_with_DISPLAY.cob: Likewise. * cobol.dg/group2/PACKED-DECIMAL_used_with_INITIALIZE.cob: Likewise. * cobol.dg/group2/PACKED-DECIMAL_used_with_MOVE.cob: Likewise. * cobol.dg/group2/POINTER__display.cob: Likewise. * cobol.dg/group2/Simple_floating-point_MOVE.cob: Likewise. * cobol.dg/group2/Simple_floating-point_VALUE_and_MOVE.cob: Likewise. * cobol.dg/group2/ACCEPT_FROM_TIME___DATE___DAY___DAY-OF-WEEK__2_.out: Known-good result. * cobol.dg/group2/COMP-6_arithmetic.out: Likewise. * cobol.dg/group2/COMP-6_numeric_test.out: Likewise. * cobol.dg/group2/COMP-6_used_with_DISPLAY.out: Likewise. * cobol.dg/group2/COMP-6_used_with_MOVE.out: Likewise. * cobol.dg/group2/COMPUTE_multiplication_to_FIX4.out: Likewise. * cobol.dg/group2/DISPLAY__Sign_ASCII__2_.out: Likewise. * cobol.dg/group2/DISPLAY__Sign_ASCII.out: Likewise. * cobol.dg/group2/Floating_continuation_indicator__1_.out: Likewise. * cobol.dg/group2/floating-point_ADD_FORMAT_1.out: Likewise. * cobol.dg/group2/floating-point_ADD_FORMAT_2.out: Likewise. * cobol.dg/group2/floating-point_DIVIDE_FORMAT_1.out: Likewise. * cobol.dg/group2/floating-point_DIVIDE_FORMAT_2.out: Likewise. * cobol.dg/group2/floating-point_literals.out: Likewise. * cobol.dg/group2/floating-point_MULTIPLY_FORMAT_1.out: Likewise. * cobol.dg/group2/floating-point_MULTIPLY_FORMAT_2.out: Likewise. * cobol.dg/group2/floating-point_SUBTRACT_FORMAT_1.out: Likewise. * cobol.dg/group2/floating-point_SUBTRACT_FORMAT_2.out: Likewise. * cobol.dg/group2/IBM_dialect_COMP_redefined_by_POINTER_as_64-bit.out: Likewise. * cobol.dg/group2/Indicators___-D__.out: Likewise. * cobol.dg/group2/MULTIPLY_to_FIX4.out: Likewise. * cobol.dg/group2/PACKED-DECIMAL_arithmetic.out: Likewise. * cobol.dg/group2/PACKED-DECIMAL_basic_comp-3_comp-6__1_.out: Likewise. * cobol.dg/group2/PACKED-DECIMAL_basic_comp-3_comp-6
[gcc r15-9363] cobol: New testcases for reference modification.
https://gcc.gnu.org/g:6ddcbb3ec8cf5e0ab38c28f40e92e0a77d6f1fdd commit r15-9363-g6ddcbb3ec8cf5e0ab38c28f40e92e0a77d6f1fdd Author: Bob Dubner Date: Thu Apr 10 09:52:49 2025 -0400 cobol: New testcases for reference modification. gcc/testsuite * cobol.dg/group2/Dynamic_reference_modification.cob: New testcase. * cobol.dg/group2/Length_overflow__1_.cob: Likewise. * cobol.dg/group2/Length_overflow__2_.cob: Likewise. * cobol.dg/group2/Length_overflow_with_offset__1_.cob: Likewise. * cobol.dg/group2/Length_overflow_with_offset__2_.cob: Likewise. * cobol.dg/group2/Length_overflow_with_offset__3_.cob: Likewise. * cobol.dg/group2/Offset_overflow.cob: Likewise. * cobol.dg/group2/Offset_underflow.cob: Likewise. * cobol.dg/group2/Refmod__comparisons_inside_numeric-display.cob: Likewise. * cobol.dg/group2/Refmod_sources_are_figurative_constants.cob: Likewise. * cobol.dg/group2/Static_reference_modification.cob: Likewise. * cobol.dg/group2/Dynamic_reference_modification.out: New known-good result. * cobol.dg/group2/Length_overflow__1_.out: Likewise. * cobol.dg/group2/Length_overflow__2_.out: Likewise. * cobol.dg/group2/Length_overflow_with_offset__1_.out: Likewise. * cobol.dg/group2/Length_overflow_with_offset__2_.out: Likewise. * cobol.dg/group2/Length_overflow_with_offset__3_.out: Likewise. * cobol.dg/group2/Offset_overflow.out: Likewise. * cobol.dg/group2/Offset_underflow.out: Likewise. * cobol.dg/group2/Refmod__comparisons_inside_numeric-display.out: Likewise. * cobol.dg/group2/Refmod_sources_are_figurative_constants.out: Likewise. * cobol.dg/group2/Static_reference_modification.out: Likewise. Diff: --- .../group2/Dynamic_reference_modification.cob | 24 ++ .../group2/Dynamic_reference_modification.out | 5 .../cobol.dg/group2/Length_overflow__1_.cob| 16 .../cobol.dg/group2/Length_overflow__1_.out| 1 + .../cobol.dg/group2/Length_overflow__2_.cob| 16 .../cobol.dg/group2/Length_overflow__2_.out| 1 + .../group2/Length_overflow_with_offset__1_.cob | 15 +++ .../group2/Length_overflow_with_offset__1_.out | 1 + .../group2/Length_overflow_with_offset__2_.cob | 16 .../group2/Length_overflow_with_offset__2_.out | 1 + .../group2/Length_overflow_with_offset__3_.cob | 22 .../group2/Length_overflow_with_offset__3_.out | 1 + gcc/testsuite/cobol.dg/group2/Offset_overflow.cob | 16 gcc/testsuite/cobol.dg/group2/Offset_overflow.out | 1 + gcc/testsuite/cobol.dg/group2/Offset_underflow.cob | 16 gcc/testsuite/cobol.dg/group2/Offset_underflow.out | 1 + .../Refmod__comparisons_inside_numeric-display.cob | 20 +++ .../Refmod__comparisons_inside_numeric-display.out | 9 +++ .../Refmod_sources_are_figurative_constants.cob| 29 ++ .../Refmod_sources_are_figurative_constants.out| 9 +++ .../group2/Static_reference_modification.cob | 19 ++ .../group2/Static_reference_modification.out | 5 22 files changed, 244 insertions(+) diff --git a/gcc/testsuite/cobol.dg/group2/Dynamic_reference_modification.cob b/gcc/testsuite/cobol.dg/group2/Dynamic_reference_modification.cob new file mode 100644 index ..99690da57327 --- /dev/null +++ b/gcc/testsuite/cobol.dg/group2/Dynamic_reference_modification.cob @@ -0,0 +1,24 @@ + *> { dg-do run } + *> { dg-output-file "group2/Dynamic_reference_modification.out" } + + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 X PIC X(4) VALUE "abcd". + 01 I PIC 9. + PROCEDUREDIVISION. + MOVE 1 TO I. + DISPLAY X(I:1) + END-DISPLAY. + MOVE 4 TO I. + DISPLAY X(I:1) + END-DISPLAY. + MOVE 1 TO I. + DISPLAY X(1:I) + END-DISPLAY. + MOVE 4 TO I. + DISPLAY X(1:I) + END-DISPLAY. + STOP RUN. + diff --git a/gcc/testsuite/cobol.dg/group2/Dynamic_reference_modification.out b/gcc/testsuite/cobol.dg/group2/Dynamic_reference_modification.out new file mode 100644 index ..42a4b69544ec --- /dev/null +++ b/gcc/testsuite/cobol.dg/group2/Dynamic_reference_modification.out @@ -0,0 +1,5 @@ +a +d +a +abcd + diff --git a/gcc/testsuite/cobol.dg/group2/Length_overflow__1_.cob b/gcc/testsuite/cobol.dg/group2/Length_overflow__1_.cob new file mode 100644 index ..647535675756 --- /dev/null +++ b/gcc/testsuite/cobol.dg/group2/Length_overflow__1_.cob @@ -0,0 +1,16 @@ + *> { dg-
[gcc r15-9349] cobol: Proper comparison of alphanumeric to refmoded numeric-display [PR119682]
https://gcc.gnu.org/g:6704d95ec859d9e7480da130bff1e6b58fe37350 commit r15-9349-g6704d95ec859d9e7480da130bff1e6b58fe37350 Author: Bob Dubner Date: Wed Apr 9 16:23:53 2025 -0400 cobol: Proper comparison of alphanumeric to refmoded numeric-display [PR119682] gcc/cobol PR cobol/119682 * genapi.cc: (cobol_compare): Change the call to __gg__compare(). libgcobol PR cobol/119682 * common-defs.h: Define the REFER_T_REFMOD constant. * intrinsic.cc: (__gg__max): Change the calls to __gg__compare_2(), (__gg__min): Likewise, (__gg__ord_min): Likewise, (__gg__ord_max): Likewise. * libgcobol.cc: (__gg__compare_2): Change definition of calling parameters, eliminate separate flag bit for ALL and ADDRESS_OF, change comparison of alphanumeric to numeric when the numeric is a refmod. * libgcobol.h: Change declaration of __gg__compare_2. Diff: --- gcc/cobol/genapi.cc | 11 +++--- libgcobol/common-defs.h | 1 + libgcobol/intrinsic.cc | 94 ++--- libgcobol/libgcobol.cc | 51 +-- libgcobol/libgcobol.h | 6 ++-- 5 files changed, 77 insertions(+), 86 deletions(-) diff --git a/gcc/cobol/genapi.cc b/gcc/cobol/genapi.cc index c91237bd8d2c..fdf76aad7b14 100644 --- a/gcc/cobol/genapi.cc +++ b/gcc/cobol/genapi.cc @@ -2028,10 +2028,12 @@ cobol_compare( tree return_int, { // None of our explicit comparisons up above worked, so we revert to the // general case: -int leftflags = (left_side_ref.all ? REFER_T_MOVE_ALL : 0) -+ (left_side_ref.addr_of ? REFER_T_ADDRESS_OF : 0); -int rightflags = (right_side_ref.all ? REFER_T_MOVE_ALL : 0) -+ (right_side_ref.addr_of ? REFER_T_ADDRESS_OF : 0); +int leftflags = (left_side_ref.all ? REFER_T_MOVE_ALL : 0) ++ (left_side_ref.addr_of ? REFER_T_ADDRESS_OF : 0) ++ (left_side_ref.refmod.from ? REFER_T_REFMOD : 0); +int rightflags = (right_side_ref.all ? REFER_T_MOVE_ALL : 0) ++ (right_side_ref.addr_of ? REFER_T_ADDRESS_OF : 0) ++ (right_side_ref.refmod.from ? REFER_T_REFMOD : 0); gg_assign( return_int, gg_call_expr( INT, "__gg__compare", @@ -2045,6 +2047,7 @@ cobol_compare( tree return_int, build_int_cst_type(INT, rightflags), integer_zero_node, NULL_TREE)); +compared = true; } // gg_printf(" result is %d\n", return_int, NULL_TREE); diff --git a/libgcobol/common-defs.h b/libgcobol/common-defs.h index f9d9c56a0d8d..6bf32ef79cf0 100644 --- a/libgcobol/common-defs.h +++ b/libgcobol/common-defs.h @@ -70,6 +70,7 @@ #define REFER_T_ALL_FLAGS_MASK 0x0FF // We allow for seven subscripts #define REFER_T_MOVE_ALL 0x100 // This is the move_all flag #define REFER_T_ADDRESS_OF 0x200 // This is the address_of flag +#define REFER_T_REFMOD 0x400 // Indicates to library the refer was a refmod #define MIN_FIELD_BLOCK_SIZE (16) diff --git a/libgcobol/intrinsic.cc b/libgcobol/intrinsic.cc index 4bce481b0c04..e0bd3339708e 100644 --- a/libgcobol/intrinsic.cc +++ b/libgcobol/intrinsic.cc @@ -1867,8 +1867,7 @@ __gg__max(cblc_field_t *dest, unsigned char *best_location ; size_t best_length ; intbest_attr ; -bool best_move_all ; -bool best_address_of ; +intbest_flags ; bool first_time = true; assert(ncount); @@ -1887,8 +1886,7 @@ __gg__max(cblc_field_t *dest, best_location = __gg__treeplet_1f[i]->data + __gg__treeplet_1o[i]; best_length = __gg__treeplet_1s[i]; best_attr = __gg__treeplet_1f[i]->attr; - best_move_all = !!(__gg__fourplet_flags[i] & REFER_T_MOVE_ALL); - best_address_of = !!(__gg__fourplet_flags[i] & REFER_T_ADDRESS_OF); + best_flags = __gg__fourplet_flags[i]; } else { @@ -1896,31 +1894,27 @@ __gg__max(cblc_field_t *dest, unsigned char *candidate_location = __gg__treeplet_1f[i]->data + __gg__treeplet_1o[i]; size_t candidate_length = __gg__treeplet_1s[i]; intcandidate_attr = __gg__treeplet_1f[i]->attr; - bool candidate_move_all = !!(__gg__fourplet_flags[i] & REFER_T_MOVE_ALL); - bool candidate_address_of = !!(__gg__fourplet_flags[i] & REFER_T_ADDRESS_OF); + intcandidate_flags = __gg__fourplet_flags[i]; int compare_result = __gg__compare_2( candidate_field, candidate_location,
[gcc r15-9012] cobol: Confine all __int128/_Float128 references to libgcobol.
https://gcc.gnu.org/g:137e294883407d227ad20767ea3363a37d22c1e9 commit r15-9012-g137e294883407d227ad20767ea3363a37d22c1e9 Author: Bob Dubner Date: Fri Mar 28 12:09:39 2025 -0400 cobol: Confine all __int128/_Float128 references to libgcobol. These changes are part of the effort to make possible cross compilation for hosts that don't support __int128 or _Float128. gcc/cobol * Make-lang.in: Eliminate libgcobol.h from gcc/cobol files. * genapi.cc: Eliminate "#include libgcobol.h". (parser_display_internal): Change comment. * genmath.cc: Eliminate "#include libgcobol.h". * genutil.cc: Likewise. (get_power_of_ten): Change comment. * structs.cc: Eliminate cblc_int128_type_node. * structs.h: Likewise. * symbols.h: Receive comment from libgcobol.h libgcobol * charmaps.cc:Eliminate "#include libgcobol.h". Change comment about _Float128. * common-defs.h: Change comment about _Float128. Receive #defines from libgcobol.h. * constants.cc: Eliminate #include libgcobol.h. Eliminate other unneeded #includes. * ec.h: Receive declarations from libgcobol.h. * gcobolio.h: Likewise. * gfileio.cc: (__gg__file_init): Use file_flag_none_e instead of zero in assignment. (__gg__file_reopen): Likewise. (__io__file_open): Likewise. * gfileio.h: Receive declarations from libgcobol.h. * libgcobol.h: Numerous declarations moved elsewhere. Diff: --- gcc/cobol/Make-lang.in | 2 - gcc/cobol/genapi.cc | 8 +-- gcc/cobol/genmath.cc| 1 - gcc/cobol/genutil.cc| 3 +- gcc/cobol/structs.cc| 30 - gcc/cobol/structs.h | 1 - gcc/cobol/symbols.h | 8 +++ libgcobol/charmaps.cc | 1 - libgcobol/common-defs.h | 24 +++- libgcobol/constants.cc | 9 --- libgcobol/ec.h | 60 ++ libgcobol/gcobolio.h| 38 libgcobol/gfileio.cc| 8 +-- libgcobol/gfileio.h | 24 libgcobol/libgcobol.h | 157 +++- 15 files changed, 169 insertions(+), 205 deletions(-) diff --git a/gcc/cobol/Make-lang.in b/gcc/cobol/Make-lang.in index 02c867ea22a1..ee048b09d9de 100644 --- a/gcc/cobol/Make-lang.in +++ b/gcc/cobol/Make-lang.in @@ -93,7 +93,6 @@ cobol/charmaps.cc: $(LIB_SOURCE)/charmaps.cc sed -i "s|\"common-defs[.]h\"|\"$(LIB_SOURCE)/common-defs.h\"|g" $@ sed -i "s|\"io[.]h\"|\"$(LIB_SOURCE)/io.h\"|g" $@ sed -i "s|\"gcobolio[.]h\"|\"$(LIB_SOURCE)/gcobolio.h\"|g" $@ - sed -i "s|\"libgcobol[.]h\"|\"$(LIB_SOURCE)/libgcobol.h\"|g" $@ sed -i "s|\"gfileio[.]h\"|\"$(LIB_SOURCE)/gfileio.h\"|g" $@ sed -i "s|\"charmaps[.]h\"|\"$(LIB_SOURCE)/charmaps.h\"|g" $@ sed -i "s|\"valconv[.]h\"|\"$(LIB_SOURCE)/valconv.h\"|g" $@ @@ -105,7 +104,6 @@ cobol/valconv.cc: $(LIB_SOURCE)/valconv.cc sed -i "s|\"common-defs[.]h\"|\"$(LIB_SOURCE)/common-defs.h\"|g" $@ sed -i "s|\"io[.]h\"|\"$(LIB_SOURCE)/io.h\"|g" $@ sed -i "s|\"gcobolio[.]h\"|\"$(LIB_SOURCE)/gcobolio.h\"|g" $@ - sed -i "s|\"libgcobol[.]h\"|\"$(LIB_SOURCE)/libgcobol.h\"|g" $@ sed -i "s|\"gfileio[.]h\"|\"$(LIB_SOURCE)/gfileio.h\"|g" $@ sed -i "s|\"charmaps[.]h\"|\"$(LIB_SOURCE)/charmaps.h\"|g" $@ sed -i "s|\"valconv[.]h\"|\"$(LIB_SOURCE)/valconv.h\"|g" $@ diff --git a/gcc/cobol/genapi.cc b/gcc/cobol/genapi.cc index 8adc07ec57fa..be463f26bdfd 100644 --- a/gcc/cobol/genapi.cc +++ b/gcc/cobol/genapi.cc @@ -48,7 +48,6 @@ #include "genmath.h" #include "structs.h" #include "../../libgcobol/gcobolio.h" -#include "../../libgcobol/libgcobol.h" #include "../../libgcobol/charmaps.h" #include "../../libgcobol/valconv.h" #include "show_parse.h" @@ -4800,14 +4799,13 @@ parser_display_internal(tree file_descriptor, else if( refer.field->type == FldLiteralN ) { // The parser found the string of digits from the source code and converted -// it to a _Float128. +// it to a 128-bit binary floating point number. // The bad news is that something like 555.55 can't be expressed exactly; // internally it is 555.54 -// The good news is that we know any string of 33 or fewer digits is -// converted to _Float128 and then converted back again, you get the same -// string. +// The good news is that we know any string of 33 or fewer decimal digits +// can be converted to and from IEEE 754 binary128 without being changes // We make use of that here diff --git a/gcc/cobol/genmath.cc b/gcc/cobol/genmath.cc index 56254e88cc6c..9725754eae15 100644 --- a/gcc/cobol/genmath.cc +++ b/gcc/cobol/genmath.cc @@ -42,7 +42,6 @@ #include "gengen.h" #include "structs.h" #include "../../libgcobol/gcobolio.h" -#include "../../libgc
[gcc r15-9138] cobol: Change some dubious sprintf() calls to xasprintf in genapi.cc
https://gcc.gnu.org/g:f63ec684a18fbc7d37cd74e062404bb518dadc9b commit r15-9138-gf63ec684a18fbc7d37cd74e062404bb518dadc9b Author: Bob Dubner Date: Tue Apr 1 17:01:59 2025 -0400 cobol: Change some dubious sprintf() calls to xasprintf in genapi.cc These calls were into fixed-length arrays that might be too small. gcc/cobol * genapi.cc: (section_label): Use xasprintf() instead of sprintf(). (paragraph_label): Likewise. (leave_procedure): Likewise. (find_procedure): Likewise. (parser_goto): Likewise. (parser_enter_file): Likewise. Diff: --- gcc/cobol/genapi.cc | 98 ++--- 1 file changed, 41 insertions(+), 57 deletions(-) diff --git a/gcc/cobol/genapi.cc b/gcc/cobol/genapi.cc index be463f26bdfd..92ab460e2c0b 100644 --- a/gcc/cobol/genapi.cc +++ b/gcc/cobol/genapi.cc @@ -2354,34 +2354,25 @@ section_label(struct cbl_proc_t *procedure) cbl_label_t *label = procedure->label; // The _initialize_program section isn't relevant. - static size_t psz_length = 256; - static char *psz = (char *)xmalloc(psz_length); - sprintf(psz, - "# SECTION %s in %s (%ld)", - label->name, - current_function->our_unmangled_name, - deconflictor); + char *psz = xasprintf("# SECTION %s in %s (%ld)", +label->name, +current_function->our_unmangled_name, +deconflictor); gg_insert_into_assembler(psz); + free(psz); // The label has to start with an underscore. I tried a period, but those // don't seem to show up in GDB's internal symbol tables. - char *combined = combined_name(procedure->label); - if( psz_length < strlen(combined) + 36 + 1 ) -{ -free(psz); -psz_length = strlen(combined) + 36 + 1; -psz= (char *)xmalloc(psz_length); -} - sprintf(psz, - "_sect.%s", - combined_name(procedure->label)); + char *psz2 = xasprintf( "_sect.%s", + combined_name(procedure->label)); SHOW_PARSE { SHOW_PARSE_HEADER -SHOW_PARSE_TEXT(psz); +SHOW_PARSE_TEXT(psz2); SHOW_PARSE_END } - assembler_label(psz); + assembler_label(psz2); + free(psz2); gg_assign(var_decl_nop, build_int_cst_type(INT, 108)); } @@ -2410,40 +2401,32 @@ paragraph_label(struct cbl_proc_t *procedure) char *para_name= paragraph->name; char *section_name = section ? section->name : nullptr; - static size_t psz_length = 256; - static char *psz = (char *)xmalloc(psz_length); - - static size_t deconflictor = symbol_label_id(procedure->label); - - sprintf(psz, + size_t deconflictor = symbol_label_id(procedure->label); + + char *psz1 = + xasprintf( "# PARAGRAPH %s of %s in %s (%ld)", - para_name, - section_name, - current_function->our_unmangled_name, - deconflictor); - gg_insert_into_assembler(psz); + para_name ? para_name: "" , + section_name ? section_name: "(null)" , + current_function->our_unmangled_name ? current_function->our_unmangled_name: "" , + deconflictor ); + + gg_insert_into_assembler(psz1); SHOW_PARSE { SHOW_PARSE_HEADER -SHOW_PARSE_TEXT(psz); +SHOW_PARSE_TEXT(psz1); SHOW_PARSE_END } + free(psz1); // The label has to start with an underscore. I tried a period, but those // don't seem to show up in GDB's internal symbol tables. - char *combined = combined_name(procedure->label); - if( psz_length < strlen(combined) + 36 + 1 ) -{ -free(psz); -psz_length = strlen(combined) + 36 + 1; -psz= (char *)xmalloc(psz_length); -} - - sprintf(psz, - "_para.%s", - combined_name(procedure->label)); - assembler_label(psz); + char *psz2 = xasprintf( "_para.%s", + combined_name(procedure->label)); + assembler_label(psz2); + free(psz2); gg_assign(var_decl_nop, build_int_cst_type(INT, 109)); } @@ -2537,11 +2520,11 @@ leave_procedure(struct cbl_proc_t *procedure, bool /*section*/) // new program, or after somebody else has cleared it out. gg_append_statement(procedure->exit.label); -char ach[256]; -sprintf(ach, -"_procret.%ld:", -symbol_label_id(procedure->label)); -gg_insert_into_assembler(ach); +char *psz; +psz = xasprintf("_procret.%ld:", +symbol_label_id(procedure->label)); +gg_insert_into_assembler(psz); +free(psz); pseudo_return_pop(procedure); gg_append_statement(procedure->bottom.label); } @@ -2650,7 +2633,6 @@ find_procedure(cbl_label_t *label) if( !retval ) { static int counter=1; -char ach[2*sizeof(cbl_name_t)]; // This is a new section or paragraph; we need to create its values: retval = (struct cbl_proc_t *)xmalloc(sizeof(struct cbl_proc_t)); @@ -2681,8 +2663,9 @
[gcc r15-8056] Prevent use of ASM_EXPR for optimized COBOL compilations [PR119214]
https://gcc.gnu.org/g:b673d7b593f63a526a85d56204f1217bc4fbf6a1 commit r15-8056-gb673d7b593f63a526a85d56204f1217bc4fbf6a1 Author: Robert Dubner Date: Thu Mar 13 21:03:46 2025 -0400 Prevent use of ASM_EXPR for optimized COBOL compilations [PR119214] The creation of assembler labels using ASM_EXPR causes name collisions in the assembly language because some optimizations repeat code, and those labels can get repeated. Use of "if( !optimize )" prevents (at least) that problem when it cropped up with "-O -ftrace" gcc/cobol: PR cobol/119214 * gengen.cc: applies if( !optimize ) test Diff: --- gcc/cobol/gengen.cc | 55 + 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/gcc/cobol/gengen.cc b/gcc/cobol/gengen.cc index 4fc0a830c1ed..e4331204d0ad 100644 --- a/gcc/cobol/gengen.cc +++ b/gcc/cobol/gengen.cc @@ -3429,30 +3429,35 @@ gg_trans_unit_var_decl(const char *var_name) void gg_insert_into_assembler(const char *format, ...) { - // This routine inserts text directly into the assembly language stream. - - // Note that if for some reason your text has to have a '%' character, it - // needs to be doubled in the GENERIC tag. And that means if it is in the - // 'format' variable, it needs to be quadrupled. + // Temporarily defeat all ASM_EXPR for optimized code per PR119214 + // The correct solution using LABEL_DECL is forthcoming + if( !optimize ) +{ +// This routine inserts text directly into the assembly language stream. + +// Note that if for some reason your text has to have a '%' character, it +// needs to be doubled in the GENERIC tag. And that means if it is in the +// 'format' variable, it needs to be quadrupled. + +// Create the string to be inserted: +char ach[256]; +va_list ap; +va_start(ap, format); +vsnprintf(ach, sizeof(ach), format, ap); +va_end(ap); + +// Create the required generic tag +tree asm_expr = build5_loc( location_from_lineno(), +ASM_EXPR, +VOID, +build_string(strlen(ach), ach), +NULL_TREE, +NULL_TREE, +NULL_TREE, +NULL_TREE); +//SET_EXPR_LOCATION (asm_expr, UNKNOWN_LOCATION); - // Create the string to be inserted: - char ach[256]; - va_list ap; - va_start(ap, format); - vsnprintf(ach, sizeof(ach), format, ap); - va_end(ap); - - // Create the required generic tag - tree asm_expr = build5_loc( location_from_lineno(), - ASM_EXPR, - VOID, - build_string(strlen(ach), ach), - NULL_TREE, - NULL_TREE, - NULL_TREE, - NULL_TREE); - //SET_EXPR_LOCATION (asm_expr, UNKNOWN_LOCATION); - - // And insert it as a statement - gg_append_statement(asm_expr); +// And insert it as a statement +gg_append_statement(asm_expr); +} }
[gcc r15-9392] cobol: Eliminate many getenv() calls. [PR119694]
https://gcc.gnu.org/g:711c10383f494b316c5919aa0141f6fa609578b4 commit r15-9392-g711c10383f494b316c5919aa0141f6fa609578b4 Author: Bob Dubner Date: Fri Apr 11 16:00:42 2025 -0400 cobol: Eliminate many getenv() calls. [PR119694] Many debugging calls to getenv() are eliminated. The debugging calls that remain use gcobol_getenv(...) ). Environment variables available to the user are mostly prefixed "GCOBOL_". gcc/cobol PR cobol/119694 * cbldiag.h: Eliminate getenv() calls. * cdf.y: Likewise. * cobol1.cc: Likewise. * except.cc: Likewise. * genapi.cc: Likewise. * lexio.cc: Likewise. * parse.y: Likewise. * scan_ante.h: Likewise. * show_parse.h: Likewise. * symbols.cc: Likewise. * symfind.cc: Likewise. * util.cc: Likewise. gcc/testsuite PR cobol/119694 * cobol.dg/group2/ACCEPT_DATE___DAY_and_intrinsic_functions__2_.cob: GCOBOL_CURRENT_DATE. * cobol.dg/group2/ACCEPT_FROM_TIME___DATE___DAY___DAY-OF-WEEK__2_.cob: Likewise * cobol.dg/group2/FUNCTION_DATE___TIME_OMNIBUS.cob: Likewise libgcobol PR cobol/119694 * gfileio.cc: Eliminate getenv() calls. * libgcobol.cc: Likewise. Diff: --- gcc/cobol/cbldiag.h| 8 +- gcc/cobol/cdf.y| 2 +- gcc/cobol/cobol1.cc| 2 +- gcc/cobol/except.cc| 4 +- gcc/cobol/genapi.cc| 52 +- gcc/cobol/lexio.cc | 6 +- gcc/cobol/parse.y | 136 gcc/cobol/scan_ante.h | 3 - gcc/cobol/show_parse.h | 3 - gcc/cobol/symbols.cc | 177 + gcc/cobol/symfind.cc | 27 gcc/cobol/util.cc | 35 +--- ...CEPT_DATE___DAY_and_intrinsic_functions__2_.cob | 2 +- ...PT_FROM_TIME___DATE___DAY___DAY-OF-WEEK__2_.cob | 2 +- .../group2/FUNCTION_DATE___TIME_OMNIBUS.cob| 2 +- libgcobol/gfileio.cc | 31 libgcobol/libgcobol.cc | 50 +- 17 files changed, 31 insertions(+), 511 deletions(-) diff --git a/gcc/cobol/cbldiag.h b/gcc/cobol/cbldiag.h index ed754f1203e4..d7ee98f6f25d 100644 --- a/gcc/cobol/cbldiag.h +++ b/gcc/cobol/cbldiag.h @@ -33,6 +33,12 @@ #else #define _CBLDIAG_H +#if 0 +#define gcobol_getenv(x) getenv(x) +#else +#define gcobol_getenv(x) ((char *)nullptr) +#endif + const char * cobol_filename(); /* @@ -101,7 +107,7 @@ template static void location_dump( const char func[], int line, const char tag[], const LOC& loc) { extern int yy_flex_debug; - if( yy_flex_debug && getenv("update_location") ) + if( yy_flex_debug && gcobol_getenv("update_location") ) fprintf(stderr, "%s:%d: %s location (%d,%d) to (%d,%d)\n", func, line, tag, loc.first_line, loc.first_column, loc.last_line, loc.last_column); diff --git a/gcc/cobol/cdf.y b/gcc/cobol/cdf.y index 6392f89d3b13..e06ccf371e9d 100644 --- a/gcc/cobol/cdf.y +++ b/gcc/cobol/cdf.y @@ -226,7 +226,7 @@ apply_cdf_turn( exception_turns_t& turns ) { turns.location, elem.first, files); } - if( getenv("SHOW_PARSE") ) enabled_exceptions.dump(); + if( getenv("GCOBOL_SHOW") ) enabled_exceptions.dump(); return true; } %} diff --git a/gcc/cobol/cobol1.cc b/gcc/cobol/cobol1.cc index 1e690ff4ba54..98d15a8d1eda 100644 --- a/gcc/cobol/cobol1.cc +++ b/gcc/cobol/cobol1.cc @@ -294,7 +294,7 @@ cobol_langhook_init_options_struct (struct gcc_options *opts) { cobol_set_debugging( false, false, false ); - copybook_directory_add( getenv("GCOB_COPYBOOK") ); + copybook_directory_add( getenv("GCOBOL_COPYBOOK") ); } static unsigned int diff --git a/gcc/cobol/except.cc b/gcc/cobol/except.cc index 1485a337ab93..7a6a92225607 100644 --- a/gcc/cobol/except.cc +++ b/gcc/cobol/except.cc @@ -312,11 +312,11 @@ file_status_t current_file_handled_status(); void declarative_runtime_match( cbl_field_t *declaratives, cbl_label_t *lave ) { - if( getenv("SHOW_PARSE") ) + if( getenv("GCOBOL_SHOW") ) { fprintf(stderr, "( %d ) %s: \n", cobol_location().first_line, __func__); } - if( getenv("TRACE1") ) + if( getenv("GCOBOL_TRACE") ) { gg_printf(">>( %d )(%s) declaratives:%s lave:%s\n", build_int_cst_type(INT, cobol_location().first_line), diff --git a/gcc/cobol/genapi.cc b/gcc/cobol/genapi.cc index fdf76aad7b14..622387f01a5f 100644 --- a/gcc/cobol/genapi.cc +++ b/gcc/cobol/genapi.cc @@ -75,7 +75,7 @@ static in
[gcc r15-9537] cobol: Eliminate gcc/cobol/LICENSE. [PR119759]
https://gcc.gnu.org/g:c3e721f489ebed71fccb4a2ebb5add92e8ddc206 commit r15-9537-gc3e721f489ebed71fccb4a2ebb5add92e8ddc206 Author: Bob Dubner Date: Wed Apr 16 14:41:06 2025 -0400 cobol: Eliminate gcc/cobol/LICENSE. [PR119759] gcc/cobol PR cobol/119759 * LICENSE: Deleted. Diff: --- gcc/cobol/LICENSE | 29 - 1 file changed, 29 deletions(-) diff --git a/gcc/cobol/LICENSE b/gcc/cobol/LICENSE deleted file mode 100644 index aa5ba6024cca.. --- a/gcc/cobol/LICENSE +++ /dev/null @@ -1,29 +0,0 @@ -# -# -# Copyright (c) 2021-2025 Symas Corporation -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are -# met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above -# copyright notice, this list of conditions and the following disclaimer -# in the documentation and/or other materials provided with the -# distribution. -# * Neither the name of the Symas Corporation nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
[gcc r16-118] cobol: Repair some exception processing logic.
https://gcc.gnu.org/g:05b6fc1eb55f30d28c3a23d8a6c2ef0a10856f46 commit r16-118-g05b6fc1eb55f30d28c3a23d8a6c2ef0a10856f46 Author: Robert Dubner Date: Thu Apr 24 16:26:58 2025 -0400 cobol: Repair some exception processing logic. This patch changes the exception processing logic for the calculation of reference modifications and table subscripts to be more in accordance with ISO specifications. It also adjusts the processing of RETURN-CODE when calling routines that have no CALL ... RETURNING phrase. gcc/cobol * genapi.cc: (initialize_variable_internal): Change TRACE1 formatting. (create_and_call): Repair RETURN-CODE processing. (mh_source_is_group): Repair run-time IF type comparison. (psa_FldLiteralA): Change TRACE1 formatting. (parser_symbol_add): Eliminate unnecessary code. * genutil.cc: Eliminate SET_EXCEPTION_CODE macro. (get_data_offset_dest): Repair set_exception_code logic. (get_data_offset_source): Likewise. (get_binary_value): Likewise. (refer_refmod_length): Likewise. (refer_fill_depends): Likewise. (refer_offset_dest): Likewise. (refer_size_dest): Likewise. (refer_offset_source): Likewise. gcc/testsuite * cobol.dg/group1/declarative_1.cob: Adjust for repaired exception logic. Diff: --- gcc/cobol/genapi.cc | 99 +-- gcc/cobol/genutil.cc| 779 gcc/testsuite/cobol.dg/group1/declarative_1.cob | 6 +- 3 files changed, 295 insertions(+), 589 deletions(-) diff --git a/gcc/cobol/genapi.cc b/gcc/cobol/genapi.cc index c8911f964d59..e44364a1b482 100644 --- a/gcc/cobol/genapi.cc +++ b/gcc/cobol/genapi.cc @@ -1229,7 +1229,40 @@ initialize_variable_internal( cbl_refer_t refer, } else { - TRACE1_FIELD_VALUE("", parsed_var, "") + // Convert strings of spaces to "" + tree spaces = gg_define_int(0); + if( parsed_var->type == FldGroup + || parsed_var->type == FldAlphanumeric + || parsed_var->type == FldAlphaEdited + || parsed_var->type == FldLiteralA ) +{ +gg_assign(spaces, integer_one_node); +tree counter = gg_define_int(parsed_var->data.capacity); +WHILE(counter, gt_op, integer_zero_node) + { + gg_decrement(counter); + IF( gg_indirect(member(parsed_var->var_decl_node, "data"), counter), + ne_op, + build_int_cst_type(UCHAR, ' ') ) + { + gg_assign(spaces, integer_zero_node); + } + ELSE +{ +} + ENDIF + } + WEND +} + IF(spaces, eq_op, integer_one_node) +{ +TRACE1_TEXT(" ") +} + ELSE +{ +TRACE1_FIELD_VALUE("", parsed_var, "") +} + ENDIF } TRACE1_END } @@ -12341,7 +12374,7 @@ create_and_call(size_t narg, // Because the CALL had a RETURNING clause, RETURN-CODE doesn't return a // value. So, we make sure it is zero -gg_assign(var_decl_return_code, build_int_cst_type(SHORT, 0)); +gg_assign(var_decl_return_code, build_int_cst_type(SHORT, 0)); if( returned_value_type == CHAR_P ) { @@ -12352,7 +12385,7 @@ create_and_call(size_t narg, gg_add( member(returned.field->var_decl_node, "data"), refer_offset_dest(returned))); gg_assign(returned_length, -refer_size_dest(returned)); +gg_cast(TREE_TYPE(returned_length), refer_size_dest(returned))); // The returned value is a string of nbytes, which by specification // has to be at least as long as the returned_length of the target: @@ -12442,28 +12475,9 @@ create_and_call(size_t narg, } else { -// Because no explicit returning value is expected, we switch to -// the IBM default behavior, where the returned INT value is assigned -// to our RETURN-CODE: -returned_value = gg_define_variable(SHORT); - -// Before doing the call, we save the COBOL program_state: -push_program_state(); -gg_assign(returned_value, gg_cast(SHORT, call_expr)); -// And after the call, we restore it: -pop_program_state(); - -// We know that the returned value is a 2-byte little-endian INT: -gg_assign( var_decl_return_code, -returned_value); -TRACE1 - { - TRACE1_HEADER - gg_printf("returned value: %d", -gg_cast(INT, var_decl_return_code), -NULL_TREE); - TRACE1_END - } +// Because no explicit returning value is expected, we just call it. We +// expect COBOL routines to set RETURN-CODE when they think it necessary. +gg_append_statement(call_expr); } for( size_t i=0; iva
[gcc r15-7972] MAINTAINERS: Add myself
https://gcc.gnu.org/g:bc6bbdb2cbc3ace1fbc8db6cc8976f5d8680809b commit r15-7972-gbc6bbdb2cbc3ace1fbc8db6cc8976f5d8680809b Author: Bob Dubner Date: Tue Mar 11 14:59:30 2025 -0400 MAINTAINERS: Add myself ChangeLog: * MAINTAINERS: Add myself. Diff: --- MAINTAINERS | 3 +++ 1 file changed, 3 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 84c0a6b892bb..34e2f9f53b74 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -162,6 +162,7 @@ Ada front end Arnaud Charlet Ada front end Eric Botcazou Ada front end Marc Poulhiès Ada front end Pierre-Marie de Rodat +COBOL front end Robert Dubner c++ Jason Merrill c++ Nathan Sidwell D front end Iain Buclaw @@ -276,6 +277,7 @@ check in changes outside of the parts of the compiler they maintain. arm port (MVE) Christophe Lyon callgraph Martin Jambor C front end Marek Polacek +COBOL front end Robert Dubner CTF, BTFIndu Bhagat CTF, BTF, bpf port David Faust dataflowPaolo Bonzini @@ -445,6 +447,7 @@ Dimitar Dimitrovdimitar Benoit Dupont de Dinechin bd3 Lehua Ding - Ulrich Drepper drepper +Robert Dubner rdubner François Dumont fdumont Zdenek Dvorak rakdver Michael Eager eager
[gcc/rdubner/heads/bobdev] (33 commits) aarch64: xfail pr109072_1.c's s16x4_2 [PR117092]
The branch 'rdubner/heads/bobdev' was updated to point to: e5d54c33a257... aarch64: xfail pr109072_1.c's s16x4_2 [PR117092] It previously pointed to: 52e297a3aa91... MAINTAINERS: Remove extraneous "Robert Dubner" entries Diff: Summary of changes (added commits): --- e5d54c3... aarch64: xfail pr109072_1.c's s16x4_2 [PR117092] (*) 6888a4b... Move 'find-dg-do-what' from 'gcc/testsuite/lib/gcc-dg.exp' (*) 5967fe0... libstdc++: Allow 'configure.host' to pre-set 'EXTRA_CFLAGS' (*) feb75e4... match.pd: Extend pointer alignment folds (*) 7dae3f6... match.pd: Fold ((X >> C1) & C2) * (1 << C1) (*) a68e32b... testsuite: Remove sve/pre_cond_share_1.c [PR115248] (*) 22847ef... libstdc++: Hide 128-bit int and float types behind handle f (*) 77ef91d... RISC-V: Do not delete fused vsetvl if it has uses [PR119115 (*) f043ef2... RISC-V: Adjust LMUL when using maximum SEW [PR117955]. (*) d109ad5... cobol/119229 - fix external variable declaration (*) 6fe63cc... Remove extra argument from subst macro (*) f1baee3... Allow to build libgccjit with a soname bound to the GCC maj (*) 4e6967a... LoongArch: Don't use C++17 feature [PR119238] (*) 8015a72... analyzer: support RAW_DATA_CST [PR117262] (*) 0385556... Daily bump. (*) ebf6e62... c++: Evaluate immediate invocation call arguments with mce_ (*) 2eb3d74... c++/modules: Better handle no-linkage decls in unnamed name (*) 4cd99e4... c++/modules: Handle gnu_inline attribute, cleanup linkage d (*) 3dd7b59... c++: ICE with aligned member and trivial assign op [PR11751 (*) cfb20f1... libstdc++: Implement P3137R3 views::to_input for C++26 (*) 90e53ec... c++: Look through capture proxy from outer lambda instead o (*) 9ee6c26... arm: testsuite: remove gcc.target/arm/lp1243022.c [PR117931 (*) d8a3944... libstdc++: Use new header in (*) fdcff3f... Remove bogus dg-error statements from binding_label_tests_2 (*) 0e47062... c++: ICE with lambda in fold expression in requires [PR1191 (*) 2560603... libstdc++: Optimize basic_format_parse_context::check_dynam (*) 4d2683b... libstdc++: Add static_assert to std::packaged_task::package (*) 0ce4c1c... libstdc++: Update tzdata to 2025a (*) 90f5dab... contrib: relpath.sh /lib /include [PR119081] (*) 758e617... df: Treat partial defs as uses in df_simulate_defs [PR11656 (*) d63b52e... libphobos: Merge upstream phobos 0faae92d6 (*) 6e40455... arm: allow type-punning subregs in vpr_register_operand [PR (*) baa9b2b... Fortran: Add F2018 TEAM_NUMBER to coindexed expressions [PR (*) (*) This commit already exists in another branch. Because the reference `refs/users/rdubner/heads/bobdev' matches your hooks.email-new-commits-only configuration, no separate email is sent for this commit.
[gcc] Created branch 'rdubner/heads/bobdev' in namespace 'refs/users'
The branch 'rdubner/heads/bobdev' was created in namespace 'refs/users' pointing to: 52e297a3aa91... MAINTAINERS: Remove extraneous "Robert Dubner" entries
[gcc r15-7996] MAINTAINERS: Remove extraneous "Robert Dubner" entries
https://gcc.gnu.org/g:52e297a3aa91ade5ee248fb728cf3b2f0ef320e7 commit r15-7996-g52e297a3aa91ade5ee248fb728cf3b2f0ef320e7 Author: Robert Dubner Date: Wed Mar 12 08:38:57 2025 -0400 MAINTAINERS: Remove extraneous "Robert Dubner" entries ChangeLog: * MAINTAINERS: Remove extraneous entries for "Robert Dubner" Diff: --- MAINTAINERS | 2 -- 1 file changed, 2 deletions(-) diff --git a/MAINTAINERS b/MAINTAINERS index 34e2f9f53b74..5b3fe407860f 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -277,7 +277,6 @@ check in changes outside of the parts of the compiler they maintain. arm port (MVE) Christophe Lyon callgraph Martin Jambor C front end Marek Polacek -COBOL front end Robert Dubner CTF, BTFIndu Bhagat CTF, BTF, bpf port David Faust dataflowPaolo Bonzini @@ -447,7 +446,6 @@ Dimitar Dimitrovdimitar Benoit Dupont de Dinechin bd3 Lehua Ding - Ulrich Drepper drepper -Robert Dubner rdubner François Dumont fdumont Zdenek Dvorak rakdver Michael Eager eager
[gcc r15-9005] cobol: Eliminate check-cobol -Os failure in EVALUATE testcase
https://gcc.gnu.org/g:ae2f951cc22ba9b0b1c8650d4de553344fc4fb95 commit r15-9005-gae2f951cc22ba9b0b1c8650d4de553344fc4fb95 Author: Bob Dubner Date: Fri Mar 28 08:57:24 2025 -0400 cobol: Eliminate check-cobol -Os failure in EVALUATE testcase The coding error was the lack of a necessary cast from unsigned char to int. gcc/cobol * genapi.cc: (create_and_call): cast unsigned char to int gcc/testsuite * cobol.dg/group2/Complex_EVALUATE__1_.cob: New EVALUTE testcase. * cobol.dg/group2/Complex_EVALUATE__2_.cob: Likewise. * cobol.dg/group2/EVALUATE_WHEN_NEGATIVE.cob: Likewise. * cobol.dg/group2/EVALUATE_condition__2_.cob: Likewise. * cobol.dg/group2/EVALUATE_doubled_WHEN.cob: Likewise. * cobol.dg/group2/EVALUATE_with_WHEN_using_condition-1.cob: Likewise. * cobol.dg/group2/Complex_EVALUATE__1_.out: Known-good data for testcase. * cobol.dg/group2/Complex_EVALUATE__2_.out: Likewise. * cobol.dg/group2/EVALUATE_WHEN_NEGATIVE.out: Likewise. * cobol.dg/group2/EVALUATE_condition__2_.out: Likewise. * cobol.dg/group2/EVALUATE_doubled_WHEN.out: Likewise. * cobol.dg/group2/EVALUATE_with_WHEN_using_condition-1.out: Likewise. Diff: --- gcc/cobol/genapi.cc| 3 +- .../cobol.dg/group2/Complex_EVALUATE__1_.cob | 46 +++ .../cobol.dg/group2/Complex_EVALUATE__1_.out | 5 +++ .../cobol.dg/group2/Complex_EVALUATE__2_.cob | 52 ++ .../cobol.dg/group2/Complex_EVALUATE__2_.out | 15 +++ .../cobol.dg/group2/EVALUATE_WHEN_NEGATIVE.cob | 16 +++ .../cobol.dg/group2/EVALUATE_WHEN_NEGATIVE.out | 2 + .../cobol.dg/group2/EVALUATE_condition__2_.cob | 38 .../cobol.dg/group2/EVALUATE_condition__2_.out | 5 +++ .../cobol.dg/group2/EVALUATE_doubled_WHEN.cob | 30 + .../cobol.dg/group2/EVALUATE_doubled_WHEN.out | 5 +++ .../EVALUATE_with_WHEN_using_condition-1.cob | 18 .../EVALUATE_with_WHEN_using_condition-1.out | 2 + 13 files changed, 236 insertions(+), 1 deletion(-) diff --git a/gcc/cobol/genapi.cc b/gcc/cobol/genapi.cc index bc9153381588..8adc07ec57fa 100644 --- a/gcc/cobol/genapi.cc +++ b/gcc/cobol/genapi.cc @@ -12395,13 +12395,14 @@ create_and_call(size_t narg, // We got back a 64-bit or 128-bit integer. The called and calling // programs have to agree on size, but other than that, integer numeric // types are converted one to the other. + gg_call(VOID, "__gg__int128_to_qualified_field", gg_get_address_of(returned.field->var_decl_node), refer_offset_dest(returned), refer_size_dest(returned), gg_cast(INT128, returned_value), - member(returned.field->var_decl_node, "rdigits"), + gg_cast(INT, member(returned.field->var_decl_node, "rdigits")), build_int_cst_type(INT, truncation_e), null_pointer_node, NULL_TREE ); diff --git a/gcc/testsuite/cobol.dg/group2/Complex_EVALUATE__1_.cob b/gcc/testsuite/cobol.dg/group2/Complex_EVALUATE__1_.cob new file mode 100644 index ..a070d16108e9 --- /dev/null +++ b/gcc/testsuite/cobol.dg/group2/Complex_EVALUATE__1_.cob @@ -0,0 +1,46 @@ + *> { dg-do run } + *> { dg-output-file "group2/Complex_EVALUATE__1_.out" } + +identification division. +function-id.bumper. +datadivision. +working-storage section. +77 bump pic value zero. +linkage section. +77 bumped pic . +procedure division returning bumped. +add 1 to bump. +move bump to bumped. +goback. +end functionbumper. + +identification division. +program-id. prog. +environment division. +configuration section. +repository. +function bumper. +data division. +working-storage section. +77 bump pic value zero. +77 bump1pic value zero. +77 bump2pic value zero. +77 bump3pic value zero. +procedure division. +move function bumper to bump +display bump +move function bumper to bump +display bump +move function bumper to bump +display bump +evaluate function bumper also function bumper also function bumper +when 4 also 5 also 6 +display "properly 4 also 5 also 6" +when 7 also 8 also 9 +display "IMPROPERLY 6 then 7 then 8" +when othe
[gcc r15-9205] cobol: Eliminate cobolworx UAT errors when compiling with -Os
https://gcc.gnu.org/g:e70fe5ed46ab129a8b1da961c47d3fb75b11b988 commit r15-9205-ge70fe5ed46ab129a8b1da961c47d3fb75b11b988 Author: Bob Dubner Date: Fri Apr 4 13:48:58 2025 -0400 cobol: Eliminate cobolworx UAT errors when compiling with -Os Testcases compiled with -Os were failing because static functions and static variables were being optimized away, because of improper data type casts, and because strict aliasing (whatever that is) was resulting in some loss of data. These changes eliminate those known problems. gcc/cobol * cobol1.cc: (cobol_langhook_post_options): Implemented in order to set flag_strict_aliasing to zero. * genapi.cc: (set_user_status): Add comment. (parser_intrinsic_subst): Expand SHOW_PARSE information. (psa_global): Change names of return-code and upsi globals, (psa_FldLiteralA): Set DECL_PRESERVE_P for FldLiteralA. * gengen.cc: (show_type): Add POINTER type. (gg_define_function_with_no_parameters): Set DECL_PRESERVE_P for COBOL- style nested programs. (gg_array_of_bytes): Fix bad cast. libgcobol * charmaps.h: Change __gg__data_return_code to 'short' type. * constants.cc: Likewise. Diff: --- gcc/cobol/cobol1.cc| 19 +++ gcc/cobol/genapi.cc| 19 +-- gcc/cobol/gengen.cc| 12 ++-- libgcobol/charmaps.h | 2 +- libgcobol/constants.cc | 10 +- 5 files changed, 52 insertions(+), 10 deletions(-) diff --git a/gcc/cobol/cobol1.cc b/gcc/cobol/cobol1.cc index 0d07c460d416..d175ab11e3f2 100644 --- a/gcc/cobol/cobol1.cc +++ b/gcc/cobol/cobol1.cc @@ -646,6 +646,22 @@ cobol_get_sarif_source_language(const char *) return "cobol"; } +bool +cobol_langhook_post_options(const char**) + { + // This flag, when set to 0, results in calls to gg_exit working properly. + // I don't know why it is necessary. There is something going on with the + // definition of __gg__data_return_code in constants.cc, and with how it + // is used through var_decl_return_code in genapi.cc. Without it, the value + // delivered to exit@PLT is zero, and not __gg__data_return_code + // Dubner, 2025-04-04. + flag_strict_aliasing = 0; + + /* Returning false means that the backend should be used. */ + return false; + } + + #undef LANG_HOOKS_BUILTIN_FUNCTION #undef LANG_HOOKS_GETDECLS #undef LANG_HOOKS_GLOBAL_BINDINGS_P @@ -660,6 +676,7 @@ cobol_get_sarif_source_language(const char *) #undef LANG_HOOKS_TYPE_FOR_SIZE #undef LANG_HOOKS_SET_DECL_ASSEMBLER_NAME #undef LANG_HOOKS_GET_SARIF_SOURCE_LANGUAGE +#undef LANG_HOOKS_POST_OPTIONS // We use GCC in the name, not GNU, as others do, // because "GnuCOBOL" refers to a different GNU project. @@ -685,6 +702,8 @@ cobol_get_sarif_source_language(const char *) #define LANG_HOOKS_GET_SARIF_SOURCE_LANGUAGE cobol_get_sarif_source_language +#define LANG_HOOKS_POST_OPTIONS cobol_langhook_post_options + struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER; #include "gt-cobol-cobol1.h" diff --git a/gcc/cobol/genapi.cc b/gcc/cobol/genapi.cc index a0da6476e2a8..fbe0bbc75dc8 100644 --- a/gcc/cobol/genapi.cc +++ b/gcc/cobol/genapi.cc @@ -8806,6 +8806,10 @@ static void set_user_status(struct cbl_file_t *file) { // This routine sets the user_status, if any, to the cblc_file_t::status + + // We have to do it this way, because in the case where the file->user_status + // is in linkage, the memory addresses can end up pointing to the wrong + // places if(file->user_status) { cbl_field_t *user_status = cbl_field_of(symbol_at(file->user_status)); @@ -10111,6 +10115,13 @@ parser_intrinsic_subst( cbl_field_t *f, SHOW_PARSE { SHOW_PARSE_HEADER +SHOW_PARSE_FIELD(" TO ", f) +for(size_t i=0; iname, "RETURN-CODE") == 0 ) { -strcpy(ach, "__gg___11_return_code6"); +strcpy(ach, "__gg__return_code"); } if( strcmp(new_var->name, "UPSI-0") == 0 ) { -strcpy(ach, "__gg___6_upsi_04"); +strcpy(ach, "__gg__upsi"); } new_var->var_decl_node = gg_declare_variable(cblc_field_type_node, ach, NULL, vs_external_reference); @@ -16156,6 +16167,10 @@ psa_FldLiteralA(struct cbl_field_t *field ) field->data.initial, NULL_TREE, field->var_decl_node); +TREE_READONLY(field->var_decl_node) = 1; +TREE_USED(field->var_decl_node) = 1; +TREE_STATIC(field->var_decl_node) = 1; +DECL_PRESERVE_P (field->var_decl_node) = 1; nvar += 1; } TRACE1 diff --git a/gcc/cobol/gengen.cc b/gcc/cobol/gengen.cc index ffb64c8993d9..e7a4e3c51653 100644 --- a/gcc/cobol/gengen.cc +++ b/gcc/cobol/gengen.cc @@ -375,6 +375,10 @@ show_type(tree type) static char ach[1024]; switch( TREE_CODE(type) ) { +case POINTER_TYPE: + sprintf(ach, "POINTER"); + break; + case VOID_TYPE:
[gcc r15-8679] cobol: Make CXXFLAGS_FOR_TARGET available to the libgcobol build.
https://gcc.gnu.org/g:438e82b8aa3cf14e08c70ea8a7f669621a897eae commit r15-8679-g438e82b8aa3cf14e08c70ea8a7f669621a897eae Author: Bob Dubner Date: Fri Mar 21 17:22:31 2025 -0400 cobol: Make CXXFLAGS_FOR_TARGET available to the libgcobol build. By setting "CXXFLAGS_FOR_TARGET=-ggdb -O0", a debuggable version of libgcobol.so is created. libgcobol * Makefile.am: Incorporate AM_CXXFLAGS = $(CXXFLAGS_FOR_TARGET). * Makefile.in: Regenerated. Diff: --- libgcobol/Makefile.am | 2 ++ libgcobol/Makefile.in | 1 + 2 files changed, 3 insertions(+) diff --git a/libgcobol/Makefile.am b/libgcobol/Makefile.am index 888cbf2b0b04..cafb733dde1d 100644 --- a/libgcobol/Makefile.am +++ b/libgcobol/Makefile.am @@ -52,6 +52,8 @@ libgcobol_la_LINK = $(LIBTOOL) --mode=link --tag=CXX $(CXX) \ WARN_CFLAGS = -W -Wall -Wwrite-strings +AM_CXXFLAGS = $(CXXFLAGS_FOR_TARGET) + # not defined: DEFS, MAX_ERRORS, LTLDFLAGS ALL_CXXFLAGS = -I. -I$(srcdir) $(AM_CPPFLAGS) $(DEFS) \ $(XCFLAGS) $(AM_CXXFLAGS) $(WARN_CFLAGS) $(MAX_ERRORS) \ diff --git a/libgcobol/Makefile.in b/libgcobol/Makefile.in index 1a1e2ee39eb0..c4a562a80585 100644 --- a/libgcobol/Makefile.in +++ b/libgcobol/Makefile.in @@ -431,6 +431,7 @@ libgcobol_la_LINK = $(LIBTOOL) --mode=link --tag=CXX $(CXX) \ $(LTLDFLAGS) $(LTLIBICONV) WARN_CFLAGS = -W -Wall -Wwrite-strings +AM_CXXFLAGS = $(CXXFLAGS_FOR_TARGET) # not defined: DEFS, MAX_ERRORS, LTLDFLAGS ALL_CXXFLAGS = -I. -I$(srcdir) $(AM_CPPFLAGS) $(DEFS) \
[gcc r15-9180] cobol: New testcases for INSPECT statement.
https://gcc.gnu.org/g:9b9b0ccffaf6185f5f44734755ebb7ae085ed745 commit r15-9180-g9b9b0ccffaf6185f5f44734755ebb7ae085ed745 Author: Bob Dubner Date: Wed Apr 2 18:01:08 2025 -0400 cobol: New testcases for INSPECT statement. gcc/testsuite * cobol.dg/group2/INSPECT_BACKWARD_REPLACING_LEADING.cob: New testcase. * cobol.dg/group2/INSPECT_BACKWARD_REPLACING_TRAILING.cob: Likewise. * cobol.dg/group2/INSPECT_BACKWARD_simple_CONVERTING.cob: Likewise. * cobol.dg/group2/INSPECT_BACKWARD_simple_REPLACING.cob: Likewise. * cobol.dg/group2/INSPECT_BACKWARD_simple_TALLYING.cob: Likewise. * cobol.dg/group2/INSPECT_CONVERTING_NULL.cob: Likewise. * cobol.dg/group2/INSPECT_CONVERTING_TO_figurative_constant.cob: Likewise. * cobol.dg/group2/INSPECT_CONVERTING_TO_figurative_constants.cob: Likewise. * cobol.dg/group2/INSPECT_ISO_Example_1.cob: Likewise. * cobol.dg/group2/INSPECT_ISO_Example_2.cob: Likewise. * cobol.dg/group2/INSPECT_ISO_Example_3.cob: Likewise. * cobol.dg/group2/INSPECT_ISO_Example_4.cob: Likewise. * cobol.dg/group2/INSPECT_ISO_Example_5.cob: Likewise. * cobol.dg/group2/INSPECT_ISO_Example_5-f.cob: Likewise. * cobol.dg/group2/INSPECT_ISO_Example_5-r.cob: Likewise. * cobol.dg/group2/INSPECT_ISO_Example_6.cob: Likewise. * cobol.dg/group2/INSPECT_ISO_Example_7.cob: Likewise. * cobol.dg/group2/INSPECT_No_repeat_conversion_check.cob: Likewise. * cobol.dg/group2/INSPECT_REPLACING_figurative_constant.cob: Likewise. * cobol.dg/group2/INSPECT_REPLACING_LEADING_ZEROS_BY_SPACES.cob: Likewise. * cobol.dg/group2/INSPECT_TALLYING_AFTER.cob: Likewise. * cobol.dg/group2/INSPECT_TALLYING_BEFORE.cob: Likewise. * cobol.dg/group2/INSPECT_TALLYING_REPLACING_ISO_Example.cob: Likewise. * cobol.dg/group2/INSPECT_TRAILING.cob: Likewise. * cobol.dg/group2/INSPECT_BACKWARD_REPLACING_LEADING.out: New known-good result. * cobol.dg/group2/INSPECT_BACKWARD_REPLACING_TRAILING.out: Likewise. * cobol.dg/group2/INSPECT_BACKWARD_simple_CONVERTING.out: Likewise. * cobol.dg/group2/INSPECT_BACKWARD_simple_REPLACING.out: Likewise. * cobol.dg/group2/INSPECT_BACKWARD_simple_TALLYING.out: Likewise. * cobol.dg/group2/INSPECT_CONVERTING_TO_figurative_constants.out: Likewise. * cobol.dg/group2/INSPECT_ISO_Example_1.out: Likewise. * cobol.dg/group2/INSPECT_ISO_Example_2.out: Likewise. * cobol.dg/group2/INSPECT_ISO_Example_3.out: Likewise. * cobol.dg/group2/INSPECT_ISO_Example_4.out: Likewise. * cobol.dg/group2/INSPECT_ISO_Example_5-f.out: Likewise. * cobol.dg/group2/INSPECT_ISO_Example_5.out: Likewise. * cobol.dg/group2/INSPECT_ISO_Example_5-r.out: Likewise. * cobol.dg/group2/INSPECT_ISO_Example_6.out: Likewise. * cobol.dg/group2/INSPECT_ISO_Example_7.out: Likewise. * cobol.dg/group2/INSPECT_TALLYING_REPLACING_ISO_Example.out: Likewise. * cobol.dg/group2/INSPECT_TRAILING.out: Likewise. Diff: --- .../group2/INSPECT_BACKWARD_REPLACING_LEADING.cob | 43 +++ .../group2/INSPECT_BACKWARD_REPLACING_LEADING.out | 10 ++ .../group2/INSPECT_BACKWARD_REPLACING_TRAILING.cob | 44 +++ .../group2/INSPECT_BACKWARD_REPLACING_TRAILING.out | 10 ++ .../group2/INSPECT_BACKWARD_simple_CONVERTING.cob | 105 +++ .../group2/INSPECT_BACKWARD_simple_CONVERTING.out | 15 +++ .../group2/INSPECT_BACKWARD_simple_REPLACING.cob | 29 + .../group2/INSPECT_BACKWARD_simple_REPLACING.out | 7 + .../group2/INSPECT_BACKWARD_simple_TALLYING.cob| 78 +++ .../group2/INSPECT_BACKWARD_simple_TALLYING.out| 14 ++ .../cobol.dg/group2/INSPECT_CONVERTING_NULL.cob| 15 +++ .../INSPECT_CONVERTING_TO_figurative_constant.cob | 15 +++ .../INSPECT_CONVERTING_TO_figurative_constants.cob | 27 .../INSPECT_CONVERTING_TO_figurative_constants.out | 6 + .../cobol.dg/group2/INSPECT_ISO_Example_1.cob | 83 .../cobol.dg/group2/INSPECT_ISO_Example_1.out | 9 ++ .../cobol.dg/group2/INSPECT_ISO_Example_2.cob | 75 +++ .../cobol.dg/group2/INSPECT_ISO_Example_2.out | 7 + .../cobol.dg/group2/INSPECT_ISO_Example_3.cob | 68 ++ .../cobol.dg/group2/INSPECT_ISO_Example_3.out | 13 ++ .../cobol.dg/group2/INSPECT_ISO_Example_4.cob | 71 +++ .../cobol.dg/group2/INSPECT_ISO_Example_4.out | 5 + .../cobol.dg/group2/INSPECT_ISO_Example_5-f.cob| 81 .../cobol.dg/group2/INSPECT_ISO_Example_5-f.out| 9 ++ .../cobol.dg/group2/INSPECT_ISO_Example_5-r.cob| 77 +++ .../cobol.dg/group2/INSPECT_ISO_Example_5-r.out| 9 ++ .../co
[gcc r15-9156] cobol: Plug memory leak caused by intermediate_e stack-frame variables. [PR119521]
https://gcc.gnu.org/g:29ac3adb8f72ecbe734d535b1015fe8b411316cb commit r15-9156-g29ac3adb8f72ecbe734d535b1015fe8b411316cb Author: Bob Dubner Date: Wed Apr 2 12:18:08 2025 -0400 cobol: Plug memory leak caused by intermediate_e stack-frame variables. [PR119521] COBOL variables with attribute intermediate_e are being allocated on the stack frame, but their data was assigned using malloc(), without a corresponding call to free(). For numerics, the problem is solved with a fixed allocation of sixteen bytes for the cblc_field_t::data member (sixteen is big enough for all data types) and with a fixed allocation of 8,192 bytes for the alphanumeric type. In use, the intermediate numeric data types are "shrunk" to the minimum applicable size. The intermediate alphanumerics, generally used as destination targets for functions, are trimmed as well. gcc/cobol PR cobol/119521 * genapi.cc: (parser_division): Change comment. (parser_symbol_add): Change intermediate_t handling. * parse.y: Multiple changes to new_alphanumeric() calls. * parse_ante.h: Establish named constant for date function calls. Change declaration of new_alphanumeric() function. * symbols.cc: (new_temporary_impl): Use named constant for default size of temporary alphanumerics. * symbols.h: Establish MAXIMUM_ALPHA_LENGTH constant. libgcobol PR cobol/119521 * intrinsic.cc: (__gg__reverse): Trim final result for intermediate_e. * libgcobol.cc: (__gg__adjust_dest_size): Abort on attempt to increase the size of a result. (__gg__module_name): Formatting. __gg__reverse(): Resize only intermediates Diff: --- gcc/cobol/genapi.cc| 85 -- gcc/cobol/parse.y | 73 +-- gcc/cobol/parse_ante.h | 3 +- gcc/cobol/symbols.cc | 3 +- gcc/cobol/symbols.h| 6 libgcobol/intrinsic.cc | 4 +++ libgcobol/libgcobol.cc | 8 +++-- 7 files changed, 94 insertions(+), 88 deletions(-) diff --git a/gcc/cobol/genapi.cc b/gcc/cobol/genapi.cc index 92ab460e2c0b..4d958cfc0d4b 100644 --- a/gcc/cobol/genapi.cc +++ b/gcc/cobol/genapi.cc @@ -6647,7 +6647,10 @@ parser_division(cbl_division_t division, if( args[i].refer.field->attr & any_length_e ) { -//gg_printf("side channel 0x%lx\n", gg_array_value(var_decl_call_parameter_lengths, rt_i), NULL_TREE); +// gg_printf("side channel: Length of \"%s\" is %ld\n", + // member(args[i].refer.field->var_decl_node, "name"), + // gg_array_value(var_decl_call_parameter_lengths, rt_i), + // NULL_TREE); // Get the length from the global lengths[] side channel. Don't // forget to use the length mask on the table value. @@ -16753,55 +16756,47 @@ parser_symbol_add(struct cbl_field_t *new_var ) if( bytes_to_allocate ) { - if(new_var->attr & (intermediate_e) - && new_var->type != FldLiteralN - && new_var->type != FldLiteralA ) + // We need a unique name for the allocated data for this COBOL variable: + char achDataName[256]; + if( new_var->attr & external_e ) { -// We'll malloc() data in initialize_variable -data_area = null_pointer_node; +sprintf(achDataName, "%s", new_var->name); +} + else if( new_var->name[0] == '_' ) +{ +// Avoid doubling up on leading underscore +sprintf(achDataName, +"%s_data_%lu", +new_var->name, +sv_data_name_counter++); } else { -// We need a unique name for the allocated data for this COBOL variable: -char achDataName[256]; -if( new_var->attr & external_e ) - { - sprintf(achDataName, "%s", new_var->name); - } -else if( new_var->name[0] == '_' ) - { - // Avoid doubling up on leading underscore - sprintf(achDataName, - "%s_data_%lu", - new_var->name, - sv_data_name_counter++); - } -else - { - sprintf(achDataName, - "_%s_data_%lu", - new_var->name, - sv_data_name_counter++); - } +sprintf(achDataName, +"_%s_data_%lu", +new_var->name, +sv_data_name_counter++); +} -if( new_var->attr & external_e ) - { - tree array_ty
[gcc r16-528] cobol: Eliminate padding bytes from cbl_declarative_t. [PR119377]
https://gcc.gnu.org/g:d7d24f9cc55d5cf0a70a984d4e63e8a307710d9e commit r16-528-gd7d24f9cc55d5cf0a70a984d4e63e8a307710d9e Author: Robert Dubner Date: Sun May 11 13:43:32 2025 -0400 cobol: Eliminate padding bytes from cbl_declarative_t. [PR119377] By changing the type of a variable in the cbl_declarative_t structure from "bool" to "uint32_t", three uninitialized padding bytes were turned into initialized bytes. This eliminates the valgrind error caused by those uninitialized values. This is an interim fix, which expediently eliminates the valgrind problem. The underlying design flaw, which involves turning a host-side C++ structure into a run-time data block, is slated for complete replacement in the next few weeks. libgcobol/ChangeLog: PR cobol/119377 * common-defs.h: (struct cbl_declaratives_t): Change "bool global" to "uint32_t global". Diff: --- libgcobol/common-defs.h | 16 +++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/libgcobol/common-defs.h b/libgcobol/common-defs.h index 026f377e74b2..e3471c5ccc3d 100644 --- a/libgcobol/common-defs.h +++ b/libgcobol/common-defs.h @@ -458,11 +458,25 @@ struct cbl_enabled_exception_t { struct cbl_declarative_t { enum { files_max = 16 }; size_t section; // implies program - bool global; + uint32_t global; // See the note below ec_type_t type; uint32_t nfile, files[files_max]; cbl_file_mode_t mode; +/* The ::global member originally was "bool global". A bool, however, occupies +only one byte of storage. The structure, in turn, is constructed on +four-byte boundaries for members, so there were three padding bytes between +the single byte of global and the ::type member. + +When used to create a "blob", where the structure was treated as a stream +of bytes that were used to create a constructor for an array of bytes, +valgrind noticed that those three padding bytes were not initialized, and +generated the appropriate error message. This made it hard to find other +problems. + +Changing the declaration from "bool" to "uint32_t" seems to have eliminated +the valgrind error without affecting overall performance. */ + cbl_declarative_t( cbl_file_mode_t mode = file_mode_none_e ) : section(0), global(false) , type(ec_none_e)
[gcc r16-1765] cobol: Normalize generating and using function_decls.
https://gcc.gnu.org/g:dd92d6acb416e138b21f00f34df54cb740e40e4c commit r16-1765-gdd92d6acb416e138b21f00f34df54cb740e40e4c Author: Robert Dubner Date: Sun Jun 29 10:54:36 2025 -0400 cobol: Normalize generating and using function_decls. Because COBOL doesn't require function prototypes, it is possible to, for example, CALL "getcwd" USING and then later CALL "getcwd" USING RETURNING The second call "knows" that the return value is a char*, but the first one does not. So, the first one gets a default return value type of SSIZE_t, which later needs to be replaced with CHAR_P. These [all too] extensive changes ensure that all references to a particular function use the same function_decl, and take measures to make sure that one function_decl is back-modified, if necessary, with the best return value type. gcc/cobol/ChangeLog: * Make-lang.in: Incorporate gcobol.clean. * except.cc (cbl_enabled_exceptions_t::dump): Update debug message. * genapi.cc (gg_attribute_bit_get): Formatting. (file_static_variable): Formatting. (trace1_init): Formatting. (build_main_that_calls_something): Normalize function_decl use. (parser_call_target): Likewise. (set_call_convention): Likewise. (parser_call_target_convention): Likewise. (parser_call_targets_dump): Likewise. (function_handle_from_name): Likewise. (function_pointer_from_name): Likewise. (parser_initialize_programs): Likewise. (parser_statement_begin): Formatting. (parser_leave_file): Use function_decl FIFO. (enter_program_common): Normalize function_decl use. (parser_enter_program): Normalize function_decl use. (tree_type_from_field_type): Normalize function_decl use. (is_valuable): Comment. (pe_stuff): Change name to program_end_stuff. (program_end_stuff): Likewise. (parser_exit): Likewise. (parser_division): Normalize function_decl use. (create_and_call): Normalize function_decl use. (parser_call): Normalize function_decl use. (parser_set_pointers): Normalize function_decl use. (parser_program_hierarchy): Normalize function_decl use. (psa_FldLiteralA): Defeat attempt to re-use literals. (Fails on some aarch64). (parser_symbol_add): Error message formatting. * genapi.h: Formatting. * gengen.cc (struct cbl_translation_unit_t): Add function_decl FIFO. (show_type): Rename to gg_show_type. (gg_show_type): Correct an error message. (gg_assign): Formatting; change error handling. (gg_modify_function_type): Normalize function_decl use. (gg_define_function_with_no_parameters): Fold into gg_defint_function(). (function_decl_key): Normalize function_decl use. (gg_peek_fn_decl): Normalize function_decl use. (gg_build_fn_decl): Normalize function_decl use. (gg_define_function): Normalize function_decl use. (gg_tack_on_function_parameters): Remove. (gg_finalize_function): Normalize function_decl use. (gg_leaving_the_source_code_file): Normalize function_decl use. (gg_call_expr_list): Normalize function_decl use. (gg_trans_unit_var_decl): Normalize function_decl use. (gg_insert_into_assemblerf): New function; formatting. * gengen.h (struct gg_function_t): Eliminate "is_truly_nested" flag. (gg_assign): Incorporate return value. (gg_define_function): Normalize function_decl use. (gg_define_function_with_no_parameters): Eliminate. (gg_build_fn_decl): Normalize function_decl use. (gg_peek_fn_decl): Normalize function_decl use. (gg_modify_function_type): Normalize function_decl use. (gg_call_expr_list): Normalize function_decl use. (gg_get_function_decl): Normalize function_decl use. (location_from_lineno): Prefix with "extern". (gg_open): Likewise. (gg_close): Likewise. (gg_get_indirect_reference): Likewise. (gg_insert_into_assembler): Likewise. (gg_insert_into_assemblerf): Likewise. (gg_show_type): New declaration. (gg_leaving_the_source_code_file): New declaration. * parse.y: Format debugging message. * parse_ante.h: Normalize function_decl use. Diff: --- gcc/cobol/Make-lang.in | 7 + gcc/cobol/except.cc| 4 +- gcc/cobol/genapi.cc| 431 +++ gcc/cobol/genapi.h | 2 +- gcc/cobol/gengen.cc| 484 + gcc/cobo
[gcc r16-2219] cobol: Minor changes to genapi.cc to eliminate CPPCHECK warnings.
https://gcc.gnu.org/g:9b9753718e202073a3343d196a2eae13df80f408 commit r16-2219-g9b9753718e202073a3343d196a2eae13df80f408 Author: Robert Dubner Date: Fri Jul 11 17:11:21 2025 -0400 cobol: Minor changes to genapi.cc to eliminate CPPCHECK warnings. Several hundred cppcheck warnings were eliminated. Most of these changes were replacing C-style casts, checking for NULL pointers, establishing some variables and formal parameters as const, and moving some variables around to tidy up their scopes. One memory leak was found and eliminated as a result of the cppcheck. gcc/cobol/ChangeLog: * Make-lang.in: Eliminate the .cc.o override. * genapi.cc (level_88_helper): Eliminate cppcheck warning. (get_level_88_domain): Likewise. (get_class_condition_string): Likewise. (parser_call_targets_dump): Likewise. (parser_compile_ecs): Likewise. (initialize_variable_internal): Likewise. (move_tree): Likewise. (combined_name): Likewise. (assembler_label): Likewise. (find_procedure): Likewise. (parser_perform): Likewise. (parser_perform_times): Likewise. (internal_perform_through): Likewise. (internal_perform_through_times): Likewise. (psa_FldLiteralN): Likewise. (psa_FldBlob): Likewise. (parser_accept): Likewise. (parser_accept_exception): Likewise. (parser_accept_exception_end): Likewise. (parser_accept_command_line): Likewise. (parser_accept_envar): Likewise. (parser_display_internal): Likewise. (parser_display): Likewise. (parser_assign): Likewise. (parser_initialize_table): Likewise. (parser_arith_error): Likewise. (parser_arith_error_end): Likewise. (parser_division): Likewise. (label_fetch): Likewise. (parser_label_label): Likewise. (parser_label_goto): Likewise. (parser_perform_start): Likewise. (parser_perform_conditional): Likewise. (parser_perform_conditional_end): Likewise. (parser_perform_until): Likewise. (parser_file_delete): Likewise. (parser_intrinsic_subst): Likewise. (create_lsearch_address_pairs): Likewise. (parser_bsearch_start): Likewise. (is_ascending_key): Likewise. (parser_sort): Likewise. (parser_file_sort): Likewise. (parser_return_start): Likewise. (parser_file_merge): Likewise. (parser_string_overflow): Likewise. (parser_unstring): Likewise. (parser_string): Likewise. (parser_call_exception): Likewise. (create_and_call): Likewise. (mh_identical): Likewise. (move_helper): Likewise. (binary_initial_from_float128): Likewise. (initial_from_initial): Likewise. (psa_FldLiteralA): Likewise. (parser_local_add): Likewise. (parser_symbol_add): Likewise. * genapi.h (parser_display): Likewise. * gengen.cc (gg_call_expr): Explict check for NULL_TREE. (gg_call): Likewise. * show_parse.h (SHOW_PARSE_LABEL_OK): Likewise. (TRACE1_FIELD_VALUE): Likewise. (CHECK_FIELD): Likewise. (CHECK_FIELD2): Likewise. (CHECK_LABEL): Likewise. * util.cc (cbl_internal_error): Apply [[noreturn]] attribute. * util.h (cbl_internal_error): Likewise. libgcobol/ChangeLog: * common-defs.h (PTRCAST): Moved here from libgcobol.h. * libgcobol.h (PTRCAST): Deleted. Diff: --- gcc/cobol/Make-lang.in | 28 +--- gcc/cobol/genapi.cc | 433 +--- gcc/cobol/genapi.h | 4 +- gcc/cobol/gengen.cc | 4 +- gcc/cobol/show_parse.h | 49 +- gcc/cobol/util.cc | 2 + gcc/cobol/util.h| 2 +- libgcobol/common-defs.h | 8 + libgcobol/libgcobol.h | 7 - 9 files changed, 334 insertions(+), 203 deletions(-) diff --git a/gcc/cobol/Make-lang.in b/gcc/cobol/Make-lang.in index ee494b86f0cc..22de3b15bdea 100644 --- a/gcc/cobol/Make-lang.in +++ b/gcc/cobol/Make-lang.in @@ -385,22 +385,12 @@ selftest-cobol: lang_checks += check-cobol -# -# Front-end specific flags: Originally done for the COBOL front end, this -# scripting applies CXXFLAGS_FOR_COBOL only to compilations of source code in the -# gcc/cobol source code tree. Both forms can be used: -# -# CXXFLAGS_FOR_COBOL=xxx ../configure --enable-languages= -# and -# make CXXFLAGS_FOR_COBOL=yyy -# -# The second form overrides the first. -# -# To apply this feature to other front ends, look for and clone lines -# containing
[gcc r16-1894] cobol: Update test case for intrinsic function syntax.
https://gcc.gnu.org/g:63f44b398f5938503cbd1e168bcc723697c9e9ad commit r16-1894-g63f44b398f5938503cbd1e168bcc723697c9e9ad Author: Robert Dubner Date: Tue Jul 1 11:07:18 2025 -0400 cobol: Update test case for intrinsic function syntax. gcc/testsuite/ChangeLog: * cobol.dg/group2/Intrinsics_without_FUNCTION_keyword__2_.cob: Append INTRINSIC keyword. Diff: --- .../cobol.dg/group2/Intrinsics_without_FUNCTION_keyword__2_.cob | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gcc/testsuite/cobol.dg/group2/Intrinsics_without_FUNCTION_keyword__2_.cob b/gcc/testsuite/cobol.dg/group2/Intrinsics_without_FUNCTION_keyword__2_.cob index b94adf580264..39a0c5b33da2 100644 --- a/gcc/testsuite/cobol.dg/group2/Intrinsics_without_FUNCTION_keyword__2_.cob +++ b/gcc/testsuite/cobol.dg/group2/Intrinsics_without_FUNCTION_keyword__2_.cob @@ -5,8 +5,8 @@ ENVIRONMENT DIVISION. CONFIGURATIONSECTION. REPOSITORY. - FUNCTION PI - FUNCTION E. + FUNCTION PI INTRINSIC + FUNCTION E INTRINSIC. DATA DIVISION. WORKING-STORAGE SECTION. 01 ZPIC 99V99.
[gcc r16-1896] cobol: Repair printf format of size_t.
https://gcc.gnu.org/g:f471ed487ab36651d48c6c31fb28d36a42a30829 commit r16-1896-gf471ed487ab36651d48c6c31fb28d36a42a30829 Author: Robert Dubner Date: Tue Jul 1 12:02:21 2025 -0400 cobol: Repair printf format of size_t. gcc/cobol/ChangeLog: * parse.y: printf() of size_t is %zu, not %ld. Diff: --- gcc/cobol/parse.y | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/cobol/parse.y b/gcc/cobol/parse.y index 57a41bbca718..74637c9641f5 100644 --- a/gcc/cobol/parse.y +++ b/gcc/cobol/parse.y @@ -12404,7 +12404,7 @@ numstr2i( const char input[], radix_t radix ) { return output; } if( erc == -1 ) { -yywarn("'%s' was accepted as %ld", input, integer); +yywarn("'%s' was accepted as %zu", input, integer); } return output; }
[gcc r16-2243] cobol: Eliminate cppcheck warnings in gcc/cobol .cc files.
https://gcc.gnu.org/g:c1be1d75126c8e946943b6dd94a3a0dea392888a commit r16-2243-gc1be1d75126c8e946943b6dd94a3a0dea392888a Author: Robert Dubner Date: Mon Jul 14 16:41:35 2025 -0400 cobol: Eliminate cppcheck warnings in gcc/cobol .cc files. These changes eliminate various cppcheck warnings, mostly involving C-Style casting and applying "const" to various variables and formal parameters. Some tab characters were eliminated, and some lines were trimmed to seventy-nine characters. gcc/cobol/ChangeLog: * cobol1.cc (cobol_langhook_handle_option): Eliminate cppcheck warnings. * dts.h: Likewise. * except.cc (cbl_enabled_exceptions_t::dump): Likewise. * gcobolspec.cc (lang_specific_driver): Likewise. * genapi.cc (parser_file_merge): Likewise. * gengen.cc (gg_unique_in_function): Likewise. (gg_declare_variable): Likewise. (gg_peek_fn_decl): Likewise. (gg_define_function): Likewise. * genmath.cc (set_up_on_exception_label): Likewise. (set_up_compute_error_label): Likewise. (arithmetic_operation): Likewise. (fast_divide): Likewise. * genutil.cc (get_and_check_refstart_and_reflen): Likewise. (get_depending_on_value_from_odo): Likewise. (get_data_offset): Likewise. (get_binary_value): Likewise. (process_this_exception): Likewise. (copy_little_endian_into_place): Likewise. (refer_is_clean): Likewise. (refer_fill_depends): Likewise. * genutil.h (process_this_exception): Likewise. (copy_little_endian_into_place): Likewise. (refer_is_clean): Likewise. * lexio.cc (check_push_pop_directive): Likewise. (check_source_format_directive): Likewise. (location_in): Likewise. (lexer_input): Likewise. (cdftext::lex_open): Likewise. (lexio_dialect_mf): Likewise. (valid_sequence_area): Likewise. (cdftext::free_form_reference_format): Likewise. (cdftext::segment_line): Likewise. * lexio.h (struct span_t): Likewise. * scan_ante.h (trim_location): Likewise. * symbols.cc (symbol_elem_cmp): Likewise. (symbol_alphabet): Likewise. (end_of_group): Likewise. (cbl_field_t::attr_str): Likewise. (symbols_update): Likewise. (symbol_typedef_add): Likewise. (symbol_field_add): Likewise. (new_temporary_impl): Likewise. (symbol_label_section_exists): Likewise. (symbol_program_callables): Likewise. (file_status_status_of): Likewise. * symfind.cc (is_data_field): Likewise. (finalize_symbol_map2): Likewise. (class in_scope): Likewise. (symbol_match2): Likewise. * util.cc (get_current_dir_name): Likewise. (gb4): Likewise. (class cdf_directives_t): Likewise. (cbl_field_t::report_invalid_initial_value): Likewise. (literal_subscript_oob): Likewise. (cbl_refer_t::str): Likewise. (date_time_fmt): Likewise. (class unique_stack): Likewise. (cobol_set_pp_option): Likewise. (cobol_filename): Likewise. (cobol_filename_restore): Likewise. (gcc_location_set_impl): Likewise. (ydferror): Likewise. (error_msg_direct): Likewise. (yyerror): Likewise. (cbl_unimplemented_at): Likewise. Diff: --- gcc/cobol/cobol1.cc | 8 +++-- gcc/cobol/dts.h | 2 +- gcc/cobol/except.cc | 2 +- gcc/cobol/gcobolspec.cc | 5 ++-- gcc/cobol/genapi.cc | 3 +- gcc/cobol/gengen.cc | 15 -- gcc/cobol/genmath.cc| 25 gcc/cobol/genutil.cc| 80 +++-- gcc/cobol/genutil.h | 6 ++-- gcc/cobol/lexio.cc | 31 ++- gcc/cobol/lexio.h | 4 +-- gcc/cobol/scan_ante.h | 3 +- gcc/cobol/symbols.cc| 50 ++- gcc/cobol/symfind.cc| 14 - gcc/cobol/util.cc | 79 +--- 15 files changed, 177 insertions(+), 150 deletions(-) diff --git a/gcc/cobol/cobol1.cc b/gcc/cobol/cobol1.cc index 4bd79f1f6057..3146da578998 100644 --- a/gcc/cobol/cobol1.cc +++ b/gcc/cobol/cobol1.cc @@ -357,7 +357,7 @@ cobol_langhook_handle_option (size_t scode, return true; case OPT_M: - cobol_set_pp_option('M'); +cobol_set_pp_option('M'); return true; case OPT_fstatic_call: @@ -368,16 +368,18 @@ cobol_langhook_handle_option (size_t scode, wsclear(cobol_default_byte); return true; -case OPT_fflex_
[gcc r16-660] cobol: Don't display 0xFF HIGH-VALUE characters in testcases. [PR120251]
https://gcc.gnu.org/g:022d8e25e49021b378a4e6c24c2f0c380a066690 commit r16-660-g022d8e25e49021b378a4e6c24c2f0c380a066690 Author: Robert Dubner Date: Thu May 15 12:01:12 2025 -0400 cobol: Don't display 0xFF HIGH-VALUE characters in testcases. [PR120251] The tests were displaying 0xFF characters, and the resulting generated output changed with the system locale. The check_88 test was modified so that the regex comparisons ignore those character positions. Two of the other tests were changed to output hexadecimal rather than character strings. There is one new test, and the other inspect testcases were edited to remove an unimportant back-apostrophe that had found its way into the source code sequence number area. gcc/testsuite/ChangeLog: PR cobol/120251 * cobol.dg/group1/check_88.cob: Ignore characters above 0x80. * cobol.dg/group2/ALLOCATE_Rule_8_OPTION_INITIALIZE_with_figconst.cob: Output HIGH-VALUE as hex, rather than as characters. * cobol.dg/group2/ALLOCATE_Rule_8_OPTION_INITIALIZE_with_figconst.out: Likewise. * cobol.dg/group2/INSPECT_CONVERTING_TO_figurative_constants.cob: Typo. * cobol.dg/group2/INSPECT_CONVERTING_TO_figurative_constants.out: Likewise. * cobol.dg/group2/INSPECT_ISO_Example_1.cob: Likewise. * cobol.dg/group2/INSPECT_ISO_Example_2.cob: Likewise. * cobol.dg/group2/INSPECT_ISO_Example_3.cob: Likewise. * cobol.dg/group2/INSPECT_ISO_Example_4.cob: Likewise. * cobol.dg/group2/INSPECT_ISO_Example_5-f.cob: Likewise. * cobol.dg/group2/INSPECT_ISO_Example_6.cob: Likewise. * cobol.dg/group2/INSPECT_ISO_Example_7.cob: Likewise. * cobol.dg/group2/Multiple_INDEXED_BY_variables_with_the_same_name.cob: New test. * cobol.dg/group2/Multiple_INDEXED_BY_variables_with_the_same_name.out: New test. Diff: --- gcc/testsuite/cobol.dg/group1/check_88.cob | 12 +-- ...CATE_Rule_8_OPTION_INITIALIZE_with_figconst.cob | 3 ++- ...CATE_Rule_8_OPTION_INITIALIZE_with_figconst.out | 3 +-- .../INSPECT_CONVERTING_TO_figurative_constants.cob | 12 +-- .../INSPECT_CONVERTING_TO_figurative_constants.out | 10 - .../cobol.dg/group2/INSPECT_ISO_Example_1.cob | 2 +- .../cobol.dg/group2/INSPECT_ISO_Example_2.cob | 2 +- .../cobol.dg/group2/INSPECT_ISO_Example_3.cob | 2 +- .../cobol.dg/group2/INSPECT_ISO_Example_4.cob | 2 +- .../cobol.dg/group2/INSPECT_ISO_Example_5-f.cob| 2 +- .../cobol.dg/group2/INSPECT_ISO_Example_6.cob | 2 +- .../cobol.dg/group2/INSPECT_ISO_Example_7.cob | 2 +- ...ple_INDEXED_BY_variables_with_the_same_name.cob | 24 ++ ...ple_INDEXED_BY_variables_with_the_same_name.out | 3 +++ 14 files changed, 54 insertions(+), 27 deletions(-) diff --git a/gcc/testsuite/cobol.dg/group1/check_88.cob b/gcc/testsuite/cobol.dg/group1/check_88.cob index 4a7723eb92a3..18a299fc282b 100644 --- a/gcc/testsuite/cobol.dg/group1/check_88.cob +++ b/gcc/testsuite/cobol.dg/group1/check_88.cob @@ -3,25 +3,25 @@ *> { dg-output {\-> <\-(\n|\r\n|\r)} } *> { dg-output {\->"""<\-(\n|\r\n|\r)} } *> { dg-output {\->000<\-(\n|\r\n|\r)} } -*> { dg-output {\->ÿÿÿ<\-(\n|\r\n|\r)} } +*> { dg-output {\->.*<\-(\n|\r\n|\r)} } *> { dg-output { (\n|\r\n|\r)} } *> { dg-output {\-><\-(\n|\r\n|\r)} } *> { dg-output {\-><\-(\n|\r\n|\r)} } *> { dg-output {\-><\-(\n|\r\n|\r)} } *> { dg-output {\-><\-(\n|\r\n|\r)} } -*> { dg-output {\-><\-(\n|\r\n|\r)} } +*> { dg-output {\->.*<\-(\n|\r\n|\r)} } *> { dg-output { (\n|\r\n|\r)} } *> { dg-output {There should be no garbage after character 32(\n|\r\n|\r)} } *> { dg-output {\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\*\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-(\n|\r\n|\r)} } -*> { dg-output {üüü Bundesstraße (\n|\r\n|\r)} } -*> { dg-output {üüü Bundesstraße (\n|\r\n|\r)} } +*> { dg-output {.* Bundesstra.e(\n|\r\n|\r)} } +*> { dg-output {.* Bundesstra.e(\n|\r\n|\r)} } *> { dg-output { (\n|\r\n|\r)} } *> { dg-output {There should be no spaces before the final quote(\n|\r\n|\r)} } -*> { dg-output {"üüü Bundesstraße"(\n|\r\n|\r)} } +*> { dg-output {".* Bundesstraße"(\n|\r\n|\r)} } *> { dg-output { (\n|\r\n|\r)} } *> { dg-output { IsLow ""(\n|\r\n|\r)} } *> { dg-output { IsZero "000"(\n|\r\n|\r)} } -*> { dg-output { IsHi"ÿÿÿ"(\n|\r\n|\r)} } +*> { dg-output { IsHi".*"(\n|\r\n|\r)} } *> { dg-output { IsBob "bob"(\n|\r\n|\r)} } *> { dg-output { IsQuote "(\n|\r\n|\r)} } *> { dg-output { IsSpace " "(\n|\r\n|\r)} } diff --git a/gcc/testsuite/cobol.dg/group2/ALLOCATE_R
[gcc r16-1064] cobol: Honor HAVE_CLOCK_GETTIME and HAVE_GETTIMEOFDAY. [PR119975]
https://gcc.gnu.org/g:8fc9e03a70fd08b54449b05833b00e7f8ad01c25 commit r16-1064-g8fc9e03a70fd08b54449b05833b00e7f8ad01c25 Author: Robert Dubner Date: Mon Jun 2 15:55:20 2025 -0400 cobol: Honor HAVE_CLOCK_GETTIME and HAVE_GETTIMEOFDAY. [PR119975] These changes cause genapi.cc to use whichever of clock_gettime() or gettimeofday() are available. This prevents compilation errors on systems where clock_gettime() is not available. gcc/cobol/ChangeLog: PR cobol/119975 * genapi.cc (parser_intrinsic_call_0): Use get_time_64() function. * genutil.cc (get_time_64): Definition created. * genutil.h (get_time_64): Declaration created. Diff: --- gcc/cobol/genapi.cc | 4 +++- gcc/cobol/genutil.cc | 23 +++ gcc/cobol/genutil.h | 3 +++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/gcc/cobol/genapi.cc b/gcc/cobol/genapi.cc index 2ce9cad5c0d6..5e983ab503c2 100644 --- a/gcc/cobol/genapi.cc +++ b/gcc/cobol/genapi.cc @@ -10491,7 +10491,9 @@ parser_intrinsic_call_0(cbl_field_t *tgt, { // Pass __gg__when_compiled() the time from right now. struct timespec tp; -clock_gettime(CLOCK_REALTIME, &tp); // time_t tv_sec; long tv_nsec +uint64_t now = get_time_64(); +tp.tv_sec = now / 10; +tp.tv_nsec = now % 10; store_location_stuff(function_name); gg_call(VOID, diff --git a/gcc/cobol/genutil.cc b/gcc/cobol/genutil.cc index d0aaf2b3215f..e971043164c7 100644 --- a/gcc/cobol/genutil.cc +++ b/gcc/cobol/genutil.cc @@ -2119,3 +2119,26 @@ qualified_data_location(cbl_refer_t &refer) return gg_add(member(refer.field->var_decl_node, "data"), refer_offset(refer)); } + +uint64_t +get_time_64() +{ + // This code was unabashedly stolen from gcc/timevar.cc. + // It returns the Unix epoch with nine decimal places. + + uint64_t retval = 0; + +#ifdef HAVE_CLOCK_GETTIME + struct timespec ts; + clock_gettime (CLOCK_REALTIME, &ts); + retval = ts.tv_sec * 10 + ts.tv_nsec; + return retval; +#endif +#ifdef HAVE_GETTIMEOFDAY + struct timeval tv; + gettimeofday (&tv, NULL); + retval = tv.tv_sec * 10 + tv.tv_usec * 1000; + return retval; +#endif + return retval; +} \ No newline at end of file diff --git a/gcc/cobol/genutil.h b/gcc/cobol/genutil.h index 2f4bc36eace7..43102d7cc544 100644 --- a/gcc/cobol/genutil.h +++ b/gcc/cobol/genutil.h @@ -155,4 +155,7 @@ void build_array_of_fourplets( int ngroup, size_t N, cbl_refer_t *refers); void get_depending_on_value_from_odo(tree retval, cbl_field_t *odo); +uint64_t get_time_64(); + + #endif
[gcc r16-1038] cobol: Wrap the call to fprintf in a libgcobol routine. [PR119524]
https://gcc.gnu.org/g:213cb633e7ec9b291768a4da0cd6d67679221aeb commit r16-1038-g213cb633e7ec9b291768a4da0cd6d67679221aeb Author: Robert Dubner Date: Sun Jun 1 12:32:37 2025 -0400 cobol: Wrap the call to fprintf in a libgcobol routine. [PR119524] gcc/cobol/ChangeLog: PR cobol/119524 * gengen.cc (gg_printf): Use the new __gg__fprintf_stderr() function instead of generating a call to fprintf(). libgcobol/ChangeLog: PR cobol/119524 * libgcobol.cc (__gg__fprintf_stderr): New function. Diff: --- gcc/cobol/gengen.cc| 16 +--- libgcobol/libgcobol.cc | 14 ++ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/gcc/cobol/gengen.cc b/gcc/cobol/gengen.cc index 91f67d534f6e..a5f143cf2342 100644 --- a/gcc/cobol/gengen.cc +++ b/gcc/cobol/gengen.cc @@ -2152,18 +2152,6 @@ gg_printf(const char *format_string, ...) int nargs = 0; tree args[ARG_LIMIT]; - // Because this routine is intended for debugging, we are sending the - // text to STDERR - - // Because we don't actually use stderr ourselves, we just pick it up as a - // VOID_P and pass it along to fprintf() - tree t_stderr = gg_declare_variable(VOID_P, "stderr", - NULL_TREE, - vs_external_reference); - - gg_push_context(); - - args[nargs++] = t_stderr; args[nargs++] = build_string_literal(strlen(format_string)+1, format_string); va_list ap; @@ -2197,7 +2185,7 @@ gg_printf(const char *format_string, ...) static tree function = NULL_TREE; if( !function ) { -function = gg_get_function_address(INT, "fprintf"); +function = gg_get_function_address(INT, "__gg__fprintf_stderr"); } tree stmt = build_call_array_loc (location_from_lineno(), @@ -2206,8 +2194,6 @@ gg_printf(const char *format_string, ...) nargs, args); gg_append_statement(stmt); - - gg_pop_context(); } tree diff --git a/libgcobol/libgcobol.cc b/libgcobol/libgcobol.cc index 66405baf99b1..3ab74636601b 100644 --- a/libgcobol/libgcobol.cc +++ b/libgcobol/libgcobol.cc @@ -49,6 +49,7 @@ #include #include #include +#include #if __has_include() # include // for program_invocation_short_name #endif @@ -13151,3 +13152,16 @@ __gg__set_env_value(cblc_field_t *value, // And now, anticlimactically, set the variable: setenv(trimmed_env, trimmed_val, 1); } + +extern "C" +void +__gg__fprintf_stderr(const char *format_string, ...) + { + /* This routine allows the compiler to send stuff to stderr in a way + that is straightforward to use.. */ + va_list ap; + va_start(ap, format_string); + vfprintf(stderr, format_string, ap); + va_end(ap); + } +
[gcc r16-1193] cobol: Guard clock_gettime(). [PR119975]
https://gcc.gnu.org/g:2e334900f4ddcd804e3b324402544a572d306ab6 commit r16-1193-g2e334900f4ddcd804e3b324402544a572d306ab6 Author: Robert Dubner Date: Thu Jun 5 10:53:02 2025 -0400 cobol: Guard clock_gettime(). [PR119975] This attempts to eliminate "'clock_gettime' not declared..." when building on x86_64-apple-darwin15.6.0. Calls to clock_gettime have been reduced to two locations. Both have been guarded with gcc/cobol/ChangeLog: PR cobol/119975 * genapi.cc (parser_intrinsic_call_0): Use get_time_nanoseconds(). * genutil.cc (get_time_64): Rename to get_time_nanoseconds(). (get_time_nanoseconds): Likewise. * genutil.h (get_time_64): Likewise. (get_time_nanoseconds): Likewise. * util.cc (class cbl_timespec): Timing routine uses get_time_nanoseconds(). (operator-): Likewise. (parse_file): Likewise. libgcobol/ChangeLog: PR cobol/119975 * configure.ac: AC_CHECK_LIB(rt, clock_gettime). * config.h.in: Likewise. * configure: Likewise. * gfileio.cc: Remove in-line cppcheck-suppress. * intrinsic.cc (timespec_to_string): Use guarded clock_gettime(). (__gg__current_date): Likewise. (__gg__seconds_past_midnight): Likewise. (__gg__formatted_current_date): Likewise. (__gg__random): Likewise. (__gg__random_next): Likewise. (__gg__when_compiled): Likewise. * libgcobol.cc (cobol_time): Likewise. (get_time_nanoseconds): Likewise. (__gg__clock_gettime): Likewise. (__gg__get_date_hhmmssff): Likewise. * libgcobol.h (__gg__clock_gettime): Likewise. (struct cbl_timespec): Likewise. Diff: --- gcc/cobol/genapi.cc| 2 +- gcc/cobol/genutil.cc | 2 +- gcc/cobol/genutil.h| 2 +- gcc/cobol/util.cc | 19 +- libgcobol/config.h.in | 3 +++ libgcobol/configure| 53 ++ libgcobol/configure.ac | 11 +++ libgcobol/gfileio.cc | 2 -- libgcobol/intrinsic.cc | 14 ++--- libgcobol/libgcobol.cc | 34 libgcobol/libgcobol.h | 10 +- 11 files changed, 130 insertions(+), 22 deletions(-) diff --git a/gcc/cobol/genapi.cc b/gcc/cobol/genapi.cc index 5e983ab503c2..bde8151ece79 100644 --- a/gcc/cobol/genapi.cc +++ b/gcc/cobol/genapi.cc @@ -10491,7 +10491,7 @@ parser_intrinsic_call_0(cbl_field_t *tgt, { // Pass __gg__when_compiled() the time from right now. struct timespec tp; -uint64_t now = get_time_64(); +uint64_t now = get_time_nanoseconds(); tp.tv_sec = now / 10; tp.tv_nsec = now % 10; diff --git a/gcc/cobol/genutil.cc b/gcc/cobol/genutil.cc index e971043164c7..f1098f02768e 100644 --- a/gcc/cobol/genutil.cc +++ b/gcc/cobol/genutil.cc @@ -2121,7 +2121,7 @@ qualified_data_location(cbl_refer_t &refer) } uint64_t -get_time_64() +get_time_nanoseconds() { // This code was unabashedly stolen from gcc/timevar.cc. // It returns the Unix epoch with nine decimal places. diff --git a/gcc/cobol/genutil.h b/gcc/cobol/genutil.h index 43102d7cc544..fb582e5a493f 100644 --- a/gcc/cobol/genutil.h +++ b/gcc/cobol/genutil.h @@ -155,7 +155,7 @@ void build_array_of_fourplets( int ngroup, size_t N, cbl_refer_t *refers); void get_depending_on_value_from_odo(tree retval, cbl_field_t *odo); -uint64_t get_time_64(); +uint64_t get_time_nanoseconds(); #endif diff --git a/gcc/cobol/util.cc b/gcc/cobol/util.cc index 75a0b26c0a91..e92f069bee1b 100644 --- a/gcc/cobol/util.cc +++ b/gcc/cobol/util.cc @@ -65,6 +65,7 @@ #include "inspect.h" #include "../../libgcobol/io.h" #include "genapi.h" +#include "genutil.h" #pragma GCC diagnostic ignored "-Wunused-result" #pragma GCC diagnostic ignored "-Wmissing-field-initializers" @@ -2141,22 +2142,25 @@ cobol_fileline_set( const char line[] ) { return file.name; } +//#define TIMING_PARSE +#ifdef TIMING_PARSE class cbl_timespec { - struct timespec now; + uint64_t now; // Nanoseconds public: cbl_timespec() { -clock_gettime(CLOCK_MONOTONIC, &now); +now = get_time_nanoseconds(); } double ns() const { -return now.tv_sec * 10 + now.tv_nsec; +return now; } friend double operator-( const cbl_timespec& now, const cbl_timespec& then ); }; double -operator-( const cbl_timespec& then, const cbl_timespec& now ) { +operator-( const cbl_timespec& now, const cbl_timespec& then ) { return (now.ns() - then.ns()) / 10; } +#endif static int parse_file( const char filename[] ) @@ -2172,15 +2176,20 @@ parse_file( const char filename[] ) return 0; } +#ifdef TIMING_PARSE cbl_timespec start; +#endif
[gcc r16-2449] cobol: Tweak adjustments to location_t of GENERIC nodes for PERFORM.
https://gcc.gnu.org/g:3cc2116fe6694b0e52855427fc1fd1335c6d00b6 commit r16-2449-g3cc2116fe6694b0e52855427fc1fd1335c6d00b6 Author: Robert Dubner Date: Wed Jul 23 08:44:54 2025 -0400 cobol: Tweak adjustments to location_t of GENERIC nodes for PERFORM. COBOL has a group of PERFORM statements that require careful adjustments to the location_t elements of the GENERIC nodes so that the COBOL-aware version of GDB behaves properly. These changes are in service of that goal. gcc/cobol/ChangeLog: * genapi.cc (leave_procedure): Adjust location_t for PERFORM. (parser_perform_times): Likewise. (internal_perform_through_times): Likewise. (perform_outofline_before_until): Likewise. (perform_outofline_after_until): Likewise. (perform_outofline_testafter_varying): Likewise. (perform_outofline_before_varying): Likewise. Diff: --- gcc/cobol/genapi.cc | 7 +++ 1 file changed, 7 insertions(+) diff --git a/gcc/cobol/genapi.cc b/gcc/cobol/genapi.cc index 52e75e583556..666802ea137e 100644 --- a/gcc/cobol/genapi.cc +++ b/gcc/cobol/genapi.cc @@ -2858,6 +2858,7 @@ leave_procedure(struct cbl_proc_t *procedure, bool /*section*/) char *psz; psz = xasprintf("_procret." HOST_SIZE_T_PRINT_DEC ":", (fmt_size_t)symbol_label_id(procedure->label)); +token_location_override(current_location_minus_one()); gg_insert_into_assembler(psz); free(psz); pseudo_return_pop(procedure); @@ -3445,6 +3446,7 @@ parser_perform_times( cbl_label_t *proc_1, cbl_refer_t count ) sprintf(ach, "_procretb." HOST_SIZE_T_PRINT_DEC ":", (fmt_size_t)our_pseudo_label); + token_location_override(current_location_minus_one()); gg_insert_into_assembler(ach); } @@ -3598,6 +3600,7 @@ internal_perform_through_times( cbl_label_t *proc_1, sprintf(ach, "_procretb." HOST_SIZE_T_PRINT_DEC ":", (fmt_size_t)our_pseudo_label); + token_location_override(current_location_minus_one()); gg_insert_into_assembler( ach ); } @@ -8440,6 +8443,7 @@ perform_outofline_before_until(struct cbl_perform_tgt_t *tgt, sprintf(ach, "_procretb." HOST_SIZE_T_PRINT_DEC ":", (fmt_size_t)our_pseudo_label); + token_location_override(current_location_minus_one()); gg_insert_into_assembler( ach ); } @@ -8503,6 +8507,7 @@ perform_outofline_after_until(struct cbl_perform_tgt_t *tgt, sprintf(ach, "_procretb." HOST_SIZE_T_PRINT_DEC ":", (fmt_size_t)our_pseudo_label); + token_location_override(current_location_minus_one()); gg_insert_into_assembler( ach ); } @@ -8623,6 +8628,7 @@ perform_outofline_testafter_varying(struct cbl_perform_tgt_t *tgt, sprintf(ach, "_procretb." HOST_SIZE_T_PRINT_DEC ":", (fmt_size_t)our_pseudo_label); + token_location_override(current_location_minus_one()); gg_insert_into_assembler( ach ); } @@ -8766,6 +8772,7 @@ perform_outofline_before_varying( struct cbl_perform_tgt_t *tgt, sprintf(ach, "_procretb." HOST_SIZE_T_PRINT_DEC ":", (fmt_size_t)our_pseudo_label); + token_location_override(current_location_minus_one()); gg_insert_into_assembler( ach ); }
[gcc r16-2393] cobol: Improved linemap and diagnostic handling; PIC validation. [PR120402]
https://gcc.gnu.org/g:7c1d08860796d4c1ff6fc8c5e8e8462e9ee8f7fc commit r16-2393-g7c1d08860796d4c1ff6fc8c5e8e8462e9ee8f7fc Author: Robert Dubner Date: Mon Jul 21 12:58:47 2025 -0400 cobol: Improved linemap and diagnostic handling; PIC validation. [PR120402] Implementation of PICTURE string validation for PR120402. Expanded some printf format attributes. Improved debugging and diagnostic messages. Improved linemap and line location tracking in support of diagnostic messages and location_t tagging of GENERIC nodes for improved GDB-COBOL performance. Assorted changes to eliminate cppcheck warnings. Co-Authored-By: James K. Lowden Co-Authored-By: Robert Dubner gcc/cobol/ChangeLog: PR cobol/120402 * Make-lang.in: Elminate commented-out scripting. * cbldiag.h (_CBLDIAG_H): Change #if 0 to #if GCOBOL_GETENV (warn_msg): Add printf attributes. (location_dump): Add debugging message. * cdf.y: Improved linemap tracking. * genapi.cc (treeplet_fill_source): const attribute for formal parameter. (insert_nop): Created to consolidate var_decl_nop writes. (build_main_that_calls_something): Move generation to the end of executable. (level_88_helper): Formatting. (parser_call_targets_dump): Formatting. (function_pointer_from_name): const attribute for formal parameter. (parser_initialize_programs): const attribute for formal parameter. (parser_statement_begin): Improved linemap handling. (section_label): Improved linemap handling. (paragraph_label): Improved linemap handling. (pseudo_return_pop): Improved linemap handling. (leave_procedure): Formatting. (parser_enter_section): Improved linemap handling. (parser_enter_paragraph): Improved linemap handling. (parser_perform): Formatting. (parser_leave_file): Move creation of main() to this routine. (parser_enter_program): Move creation of main from here to leave_file. (parser_accept): Formatting. const attribute for formal parameter. (parser_accept_command_line): const attribute for formal parameter. (parser_accept_command_line_count): const attribute for formal parameter. (parser_accept_envar): Likewise. (parser_set_envar): Likewise. (parser_display): Likewise. (get_exhibit_name): Implement EXHIBIT verb. (parser_exhibit): Likewise. (parser_sleep): const attribute for formal parameter. (parser_division): Improved linemap handling. (parser_classify): const attribute for formal parameter. (create_iline_address_pairs): Improved linemap handling. (parser_perform_start): Likewise. (perform_inline_until): Likewise. (perform_inline_testbefore_varying): Likewise. (parser_perform_until): Likewise. (parser_perform_inline_times): Likewise. (parser_intrinsic_subst): const attribute for formal parameter. (parser_file_merge): Formatting. (create_and_call): Improved linemap handling. (mh_identical): const attribute for formal parameter. (mh_numeric_display): const attribute for formal parameter. (mh_little_endian): Likewise. (mh_source_is_group): Likewise. (psa_FldLiteralA): Formatting. * genapi.h (parser_accept): const attribute for formal parameter. (parser_accept_envar): Likewise. (parser_set_envar): Likewise. (parser_accept_command_line): Likewise. (parser_accept_command_line_count): Likewise. (parser_add): Likewise. (parser_classify): Likewise. (parser_sleep): Likewise. (parser_exhibit): Likewise. (parser_display): Likewise. (parser_initialize_programs): Likewise. (parser_intrinsic_subst): Likewise. * gengen.cc (gg_assign): Improved linemap handling. (gg_add_field_to_structure): Likewise. (gg_define_from_declaration): Likewise. (gg_build_relational_expression): Likewise. (gg_goto_label_decl): Likewise. (gg_goto): Likewise. (gg_printf): Likewise. (gg_fprintf): Likewise. (gg_memset): Likewise. (gg_memchr): Likewise. (gg_memcpy): Likewise. (gg_memmove): Likewise. (gg_strcpy): Likewise. (gg_strcmp): Likewise. (gg_strncmp): Likewise. (gg_return): Likewise. (chain_parameter_to_function): Likewise. (gg_define_function): Likewise. (gg_get_function_decl): Likewise. (gg_call_expr): Like
[gcc r15-10110] cobol: Repair some exception processing logic.
https://gcc.gnu.org/g:5915b1a3538dd1dc92863b2e1e6d9817c04a9291 commit r15-10110-g5915b1a3538dd1dc92863b2e1e6d9817c04a9291 Author: Robert Dubner Date: Thu Apr 24 16:26:58 2025 -0400 cobol: Repair some exception processing logic. This patch changes the exception processing logic for the calculation of reference modifications and table subscripts to be more in accordance with ISO specifications. It also adjusts the processing of RETURN-CODE when calling routines that have no CALL ... RETURNING phrase. gcc/cobol * genapi.cc: (initialize_variable_internal): Change TRACE1 formatting. (create_and_call): Repair RETURN-CODE processing. (mh_source_is_group): Repair run-time IF type comparison. (psa_FldLiteralA): Change TRACE1 formatting. (parser_symbol_add): Eliminate unnecessary code. * genutil.cc: Eliminate SET_EXCEPTION_CODE macro. (get_data_offset_dest): Repair set_exception_code logic. (get_data_offset_source): Likewise. (get_binary_value): Likewise. (refer_refmod_length): Likewise. (refer_fill_depends): Likewise. (refer_offset_dest): Likewise. (refer_size_dest): Likewise. (refer_offset_source): Likewise. gcc/testsuite * cobol.dg/group1/declarative_1.cob: Adjust for repaired exception logic. (cherry picked from commit 05b6fc1eb55f30d28c3a23d8a6c2ef0a10856f46) Diff: --- gcc/cobol/genapi.cc | 99 +-- gcc/cobol/genutil.cc| 779 gcc/testsuite/cobol.dg/group1/declarative_1.cob | 6 +- 3 files changed, 295 insertions(+), 589 deletions(-) diff --git a/gcc/cobol/genapi.cc b/gcc/cobol/genapi.cc index c8911f964d59..e44364a1b482 100644 --- a/gcc/cobol/genapi.cc +++ b/gcc/cobol/genapi.cc @@ -1229,7 +1229,40 @@ initialize_variable_internal( cbl_refer_t refer, } else { - TRACE1_FIELD_VALUE("", parsed_var, "") + // Convert strings of spaces to "" + tree spaces = gg_define_int(0); + if( parsed_var->type == FldGroup + || parsed_var->type == FldAlphanumeric + || parsed_var->type == FldAlphaEdited + || parsed_var->type == FldLiteralA ) +{ +gg_assign(spaces, integer_one_node); +tree counter = gg_define_int(parsed_var->data.capacity); +WHILE(counter, gt_op, integer_zero_node) + { + gg_decrement(counter); + IF( gg_indirect(member(parsed_var->var_decl_node, "data"), counter), + ne_op, + build_int_cst_type(UCHAR, ' ') ) + { + gg_assign(spaces, integer_zero_node); + } + ELSE +{ +} + ENDIF + } + WEND +} + IF(spaces, eq_op, integer_one_node) +{ +TRACE1_TEXT(" ") +} + ELSE +{ +TRACE1_FIELD_VALUE("", parsed_var, "") +} + ENDIF } TRACE1_END } @@ -12341,7 +12374,7 @@ create_and_call(size_t narg, // Because the CALL had a RETURNING clause, RETURN-CODE doesn't return a // value. So, we make sure it is zero -gg_assign(var_decl_return_code, build_int_cst_type(SHORT, 0)); +gg_assign(var_decl_return_code, build_int_cst_type(SHORT, 0)); if( returned_value_type == CHAR_P ) { @@ -12352,7 +12385,7 @@ create_and_call(size_t narg, gg_add( member(returned.field->var_decl_node, "data"), refer_offset_dest(returned))); gg_assign(returned_length, -refer_size_dest(returned)); +gg_cast(TREE_TYPE(returned_length), refer_size_dest(returned))); // The returned value is a string of nbytes, which by specification // has to be at least as long as the returned_length of the target: @@ -12442,28 +12475,9 @@ create_and_call(size_t narg, } else { -// Because no explicit returning value is expected, we switch to -// the IBM default behavior, where the returned INT value is assigned -// to our RETURN-CODE: -returned_value = gg_define_variable(SHORT); - -// Before doing the call, we save the COBOL program_state: -push_program_state(); -gg_assign(returned_value, gg_cast(SHORT, call_expr)); -// And after the call, we restore it: -pop_program_state(); - -// We know that the returned value is a 2-byte little-endian INT: -gg_assign( var_decl_return_code, -returned_value); -TRACE1 - { - TRACE1_HEADER - gg_printf("returned value: %d", -gg_cast(INT, var_decl_return_code), -NULL_TREE); - TRACE1_END - } +// Because no explicit returning value is expected, we just call it. We +// expect COBOL routines to set RETURN-CODE when they think it
[gcc r15-10109] libgcobol: Check for struct tm tm_zone
https://gcc.gnu.org/g:636c0d50988472fa5a5bee2b22ed413ea39d842a commit r15-10109-g636c0d50988472fa5a5bee2b22ed413ea39d842a Author: Rainer Orth Date: Mon Apr 21 15:59:14 2025 +0200 libgcobol: Check for struct tm tm_zone intrinsic.cc doesn't compile on Solaris: /vol/gcc/src/hg/master/cobol/libgcobol/intrinsic.cc: In function ‘void __gg__formatted_current_date(cblc_field_t*, cblc_field_t*, std::size_t, std::size_t)’: /vol/gcc/src/hg/master/cobol/libgcobol/intrinsic.cc:1480:6: error: ‘struct std::tm’ has no member named ‘tm_zone’; did you mean ‘tm_mon’? 1480 | tm.tm_zone = "GMT"; | ^~~ | tm_mon struct tm.tm_zone is new in POSIX.1-2024, thus cannot be assumed to be present universally. This patch checks for its presence and guards the use accordingly. Bootstrapped without regressions on amd64-pc-solaris2.11, sparcv9-sun-solaris2.11, and x86_64-pc-solaris2.11. 2025-04-08 Rainer Orth libgcobol: * configure.ac: Check for struct tm.tm_zone. * configure, config.h.in: Regenerate. * intrinsic.cc (__gg__formatted_current_date): Guard tm.tm_zone use with HAVE_STRUCT_TM_TM_ZONE. (cherry picked from commit a619a128c992b2121a862b8470960ae751d25db6) Diff: --- libgcobol/config.h.in | 3 ++ libgcobol/configure| 74 -- libgcobol/configure.ac | 3 ++ libgcobol/intrinsic.cc | 2 ++ 4 files changed, 80 insertions(+), 2 deletions(-) diff --git a/libgcobol/config.h.in b/libgcobol/config.h.in index 6a5327996167..fdf5e3e7dc1c 100644 --- a/libgcobol/config.h.in +++ b/libgcobol/config.h.in @@ -72,6 +72,9 @@ /* Define to 1 if you have the `strtof128' function. */ #undef HAVE_STRTOF128 +/* Define to 1 if `tm_zone' is a member of `struct tm'. */ +#undef HAVE_STRUCT_TM_TM_ZONE + /* Define to 1 if you have the header file. */ #undef HAVE_SYS_STAT_H diff --git a/libgcobol/configure b/libgcobol/configure index e83119d48f62..6821591852af 100755 --- a/libgcobol/configure +++ b/libgcobol/configure @@ -2449,6 +2449,63 @@ $as_echo "$ac_res" >&6; } eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_cxx_check_func + +# ac_fn_cxx_check_member LINENO AGGR MEMBER VAR INCLUDES +# -- +# Tries to find if the field MEMBER exists in type AGGR, after including +# INCLUDES, setting cache variable VAR accordingly. +ac_fn_cxx_check_member () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2.$3" >&5 +$as_echo_n "checking for $2.$3... " >&6; } +if eval \${$4+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$5 +int +main () +{ +static $2 ac_aggr; +if (ac_aggr.$3) +return 0; + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_compile "$LINENO"; then : + eval "$4=yes" +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$5 +int +main () +{ +static $2 ac_aggr; +if (sizeof ac_aggr.$3) +return 0; + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_compile "$LINENO"; then : + eval "$4=yes" +else + eval "$4=no" +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +eval ac_res=\$$4 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + +} # ac_fn_cxx_check_member cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. @@ -11693,7 +11750,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 11696 "configure" +#line 11753 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -11799,7 +11856,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 11802 "configure" +#line 11859 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -17434,6 +17491,19 @@ $as_echo "#define USE_IEC_60559 1" >>confdefs.h +# struct tm tm_zone is a POSIX.1-2024 addition. +ac_fn_cxx_check_member "$LINENO" "struct tm" "tm_zone" "ac_cv_member_struct_tm_tm_zone" "#include +" +if test "x$ac_cv_member_struct_tm_tm_zone" = xyes; then : + +cat >>confdefs.h <<_ACEOF +#define HAVE_STRUCT_TM_TM_ZONE 1 +_ACEOF + + +fi + + if test "${multilib}" = "yes"; then multilib_arg="--enable-multilib" else diff --git a/libgcobol/configure.ac b/libgcobol/configure.ac index a1e95139299e..4bb690559ad9 100644 --- a/libgcobol/configure.ac +++ b/libgcobol/configure.ac @@ -231,6 +231,9 @@ elif test "${ENABLE_LIBQUADMATH_SUPPORT}" = "
[gcc r15-10112] cobol, v2: Fix up cobol cross-compilation from 32-bit arches [PR119364]
https://gcc.gnu.org/g:adffa5342315cc642e3c0a35304f7d27f7c4f987 commit r15-10112-gadffa5342315cc642e3c0a35304f7d27f7c4f987 Author: Jakub Jelinek Date: Fri May 2 19:09:34 2025 +0200 cobol, v2: Fix up cobol cross-compilation from 32-bit arches [PR119364] Right now it is not possible to even build cross-compilers from 32-bit architectures to e.g. x86_64-linux or aarch64-linux, even from little-endian ones. The following patch attempts to fix that. There were various issues seen e.g. trying to build i686-linux -> x86_64-linux cross-compiler (so still 64-bit libgcobol, but the compiler is 32-bit). 1) warning about >> 32 shift of size_t, on 32-bit arches size_t is 32-bit and so the shift is UB; fixed by doing (new_size>>16)>>16 so that it ors in >> 32 when new_size is 64-bit and 0 when it is 32-bit 2) enum cbl_field_attr_t was using size_t as underlying type, but has various bitmasks which require full 64-bit type; changed this to uint64_t underlying type and using unsigned long long in the structure; various routines which operate with those attributes had to be changed also to work with uint64_t instead of size_t 3) on i686-linux, config.h can #define _FILE_OFFSET_BITS 64 or similar macros; as documented, those macros have to be defined before including first C library header, but some sources included cobol-system.h which includes config.h only after various other headers; this resulted in link failures, as ino_t was sometimes unsigned long and sometines unsigned long long, depending on whether config.h was included first or not, and e.g. cobol_filename uses ino_t argument 4) lots of places used %ld or %lx *printf format specifers with size_t arguments; that works only if size_t is unsigned long, but not when it is unsigned int or unsigned long long or some other type; now while ISO C99 has %zd or %zx to print size_t and C++14 includes C99 (or C11?), while for the C++ headers the C++ compilers typically have full control over it and so support everything in C++14 (e.g. libstdc++ in GCC 5.1+ or libc++ if not too old), for C library we are dependent on the system C library (note, on the host for the compiler side). And not all hosts support C99 in their C libraries; so instead of just changing it to %zd or %zx, I'm changing it to what we use elsewhere in GCC, HOST_SIZE_T_PRINT_{DEC,UNSIGNED,HEX_PURE} or GCC_PRISZ macros in the *printf family format string and casts of the size_t arguments to fmt_size_t. Note, if not using the C library *printf family (e.g. in dbgmsg, sprintf, snprintf, fprintf, etc.) but the GCC diagnostic code (e.g. err_msg, error, warning, yywarn, ...), then %zd/%zu is supported and on the other side HOST_SIZE_T_PRINT_{DEC,UNSIGNED,HEX_PURE} etc. macros shouldn't be used (for two reasons, because it is unnecessary when %zd/%zu is guaranteed to be supported there because GCC has control over that and more importantly because it breaks translations, both extraction of the to be translated strings and we don't want to have different messages, once with %lld, once with %ld, once with just %d or %I64d depending on host, translators couldn't translate it all). 5) see above, there were already tons of %zd/%zu or %3zu etc. format specifers in *printf format strings, this patch changes those too 6) I've noticed dbgmsg wasn't declared with printf attribute, which resulted in bugs where format specifiers didn't match actually passed types of arguments 2025-05-02 Jakub Jelinek PR cobol/119364 libgcobol/ * valconv.cc (__gg__realloc_if_necessary): Use (new_size>>16)>>16; instead of new_size>>32; to avoid warnings on 32-bit hosts. * common-defs.h (enum cbl_field_attr_t): Use uint64_t as underlying type rather than size_t. * gcobolio.h (cblc_field_t): Change attr member type from size_t to unsigned long long. gcc/cobol/ * util.cc (is_numeric_edited): Use HOST_SIZE_T_PRINT_UNSIGNED instead of "%zu" and cast corresponding argument to fmt_size_t. (normalize_picture): Use GCC_PRISZ instead of "z" and pass address of fmt_size_t var to sscanf and copy afterwards. (cbl_refer_t::str): Use HOST_SIZE_T_PRINT_UNSIGNED instead of "%zu" or GCC_PRISZ instead of "z" and cast corresponding argument to fmt_size_t. (struct move_corresponding_field): Likewise. (valid_move): Likewise. (ambiguous_reference): Likewise. (parent_names): Likewise. (find_corresponding::find_corresponding): Likewise. (corresponding_fields): Likewise. (uniqu
[gcc r15-10119] libgcobol: Heed --enable-libgcobol
https://gcc.gnu.org/g:7fdeb675872349d016a344b5f801e90344267dac commit r15-10119-g7fdeb675872349d016a344b5f801e90344267dac Author: Rainer Orth Date: Thu May 8 09:42:42 2025 +0200 libgcobol: Heed --enable-libgcobol If some target isn't listed as supported in configure.tgt, --enable-libgcobol cannot override that. However, that's what should happen just like an explicit --enable-languages=cobol forces the frontend to be built. This patch, shamelessly adapted from libphobos, does just that. Tested on amd64-pc-solaris2.11, sparcv9-sun-solaris2.11, and x86_64-pc-linux-gnu. 2025-04-08 Rainer Orth libgcobol: * configure.ac: Handle --enable-libgcobol. Let it override LIBGCOBOL_SUPPORTED. * configure: Regenerate. (cherry picked from commit fdd2374b87bd9d7f4c201c81875d77acaebb38cd) Diff: --- libgcobol/configure| 26 +++--- libgcobol/configure.ac | 15 ++- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/libgcobol/configure b/libgcobol/configure index 06e7544822cb..5f319eedf538 100755 --- a/libgcobol/configure +++ b/libgcobol/configure @@ -788,6 +788,7 @@ enable_option_checking enable_multilib enable_maintainer_mode enable_silent_rules +enable_libgcobol enable_version_specific_runtime_libs enable_dependency_tracking enable_shared @@ -1438,6 +1439,7 @@ Optional Features: sometimes confusing) to the casual installer --enable-silent-rules less verbose build output (undo: "make V=1") --disable-silent-rules verbose build output (undo: "make V=0") + --enable-libgcobol Enable libgcobol --enable-version-specific-runtime-libs Specify that runtime libraries should be installed in a compiler-specific directory @@ -3723,6 +3725,16 @@ END fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --enable-libgcobol" >&5 +$as_echo_n "checking for --enable-libgcobol... " >&6; } +# Check whether --enable-libgcobol was given. +if test "${enable_libgcobol+set}" = set; then : + enableval=$enable_libgcobol; +fi + +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_libgcobol" >&5 +$as_echo "$enable_libgcobol" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for --enable-version-specific-runtime-libs" >&5 $as_echo_n "checking for --enable-version-specific-runtime-libs... " >&6; } # Check whether --enable-version-specific-runtime-libs was given. @@ -11798,7 +11810,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 11801 "configure" +#line 11813 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -11904,7 +11916,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 11907 "configure" +#line 11919 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -16795,6 +16807,14 @@ _ACEOF unset LIBGCOBOL_SUPPORTED . ${srcdir}/configure.tgt +# Decide if it's usable. +case $LIBGCOBOL_SUPPORTED:$enable_libgcobol in +*:no) use_libgcobol=no ;; +*:yes) use_libgcobol=yes ;; +yes:*) use_libgcobol=yes ;; +*:*) use_libgcobol=no ;; +esac + # - # __int128 support # - @@ -16887,7 +16907,7 @@ fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $libgcobol_cv_have_int128" >&5 $as_echo "$libgcobol_cv_have_int128" >&6; } - if test "x$LIBGCOBOL_SUPPORTED" = xyes && test "x$libgcobol_cv_have_int128" = xyes; then + if test "x$use_libgcobol" = xyes && test "x$libgcobol_cv_have_int128" = xyes; then BUILD_LIBGCOBOL_TRUE= BUILD_LIBGCOBOL_FALSE='#' else diff --git a/libgcobol/configure.ac b/libgcobol/configure.ac index e2547637209c..13326960515a 100644 --- a/libgcobol/configure.ac +++ b/libgcobol/configure.ac @@ -40,6 +40,11 @@ AM_MAINTAINER_MODE AM_INIT_AUTOMAKE([1.15.1 no-define foreign no-dist -Wall -Wno-portability]) +AC_MSG_CHECKING([for --enable-libgcobol]) +AC_ARG_ENABLE(libgcobol, + [AS_HELP_STRING([--enable-libgcobol], [Enable libgcobol])]) +AC_MSG_RESULT($enable_libgcobol) + AC_MSG_CHECKING([for --enable-version-specific-runtime-libs]) AC_ARG_ENABLE(version-specific-runtime-libs, AS_HELP_STRING([--enable-version-specific-runtime-libs], @@ -138,6 +143,14 @@ AC_CHECK_SIZEOF([void *]) unset LIBGCOBOL_SUPPORTED . ${srcdir}/configure.tgt +# Decide if it's usable. +case $LIBGCOBOL_SUPPORTED:$enable_libgcobol in +*:no) use_libgcobol=no ;; +*:yes) use_libgcobol=yes ;; +yes:*) use_libgcobol=yes ;; +*:*) use_libgcobol=no ;; +esac + # - # __int128 support # - @@ -164,7 +177,7 @@ AC_CACHE_CHECK([whether __int128 is supported], [libgcobol_cv_have_int128], libgcobol_cv_have_int128=no ])]) -AM_CONDITIONAL(BUILD_LIBGCOBOL, [test "x$LIBGCOBOL_SUPPORTED" = xyes && test "x$libgcobol_cv_have_i
[gcc r15-10115] libgcobol: Fix bootstrap for targets without program_invocation_short_name
https://gcc.gnu.org/g:b61e85f3eb34e3b6403eb02e4004b30e8bd170ae commit r15-10115-gb61e85f3eb34e3b6403eb02e4004b30e8bd170ae Author: Iain Sandoe Date: Tue May 6 09:42:40 2025 +0100 libgcobol: Fix bootstrap for targets without program_invocation_short_name program_invocation_short_name is not widely available, however getprogname() appears to be a suitable replacement. Amend the library configuration to look for both. Use program_invocation_short_name in preference to getprogname() when it is available. If neither is found fall back to a constant string. libgcobol/ChangeLog: * config.h.in: Regenerate. * configure: Regenerate. * configure.ac: Check for program_invocation_short_name and and getprogname(). * libgcobol.cc (default_exception_handler): When the platform has program_invocation_short_name, use it otherwise fall back to using getprogname() or a constant string (if neither interface is available). Signed-off-by: Iain Sandoe (cherry picked from commit 67e79da5a3c0deb93cd6df1557affb6994440357) Diff: --- libgcobol/config.h.in | 10 +++ libgcobol/configure| 81 -- libgcobol/configure.ac | 14 - libgcobol/libgcobol.cc | 15 -- 4 files changed, 114 insertions(+), 6 deletions(-) diff --git a/libgcobol/config.h.in b/libgcobol/config.h.in index fdf5e3e7dc1c..ee3dd6b21514 100644 --- a/libgcobol/config.h.in +++ b/libgcobol/config.h.in @@ -6,9 +6,16 @@ /* Define to 1 if you have the header file. */ #undef HAVE_COMPLEX_H +/* Define to 1 if you have the declaration of `program_invocation_short_name', + and to 0 if you don't. */ +#undef HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME + /* Define to 1 if you have the header file. */ #undef HAVE_DLFCN_H +/* Define to 1 if you have the header file. */ +#undef HAVE_ERRNO_H + /* Define to 1 if you have the header file. */ #undef HAVE_FENV_H @@ -21,6 +28,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_FPTRAP_H +/* Define to 1 if you have the `getprogname' function. */ +#undef HAVE_GETPROGNAME + /* Define if you have the iconv() function and it works. */ #undef HAVE_ICONV diff --git a/libgcobol/configure b/libgcobol/configure index 6821591852af..06e7544822cb 100755 --- a/libgcobol/configure +++ b/libgcobol/configure @@ -2380,6 +2380,52 @@ $as_echo "$ac_res" >&6; } } # ac_fn_cxx_check_header_compile +# ac_fn_cxx_check_decl LINENO SYMBOL VAR INCLUDES +# --- +# Tests whether SYMBOL is declared in INCLUDES, setting cache variable VAR +# accordingly. +ac_fn_cxx_check_decl () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + as_decl_name=`echo $2|sed 's/ *(.*//'` + as_decl_use=`echo $2|sed -e 's/(/((/' -e 's/)/) 0&/' -e 's/,/) 0& (/g'` + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $as_decl_name is declared" >&5 +$as_echo_n "checking whether $as_decl_name is declared... " >&6; } +if eval \${$3+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$4 +int +main () +{ +#ifndef $as_decl_name +#ifdef __cplusplus + (void) $as_decl_use; +#else + (void) $as_decl_name; +#endif +#endif + + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_compile "$LINENO"; then : + eval "$3=yes" +else + eval "$3=no" +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +eval ac_res=\$$3 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + +} # ac_fn_cxx_check_decl + # ac_fn_cxx_check_func LINENO FUNC VAR # # Tests whether FUNC exists, setting the cache variable VAR accordingly @@ -2796,6 +2842,8 @@ as_fn_append ac_header_list " fenv.h" as_fn_append ac_header_list " fptrap.h" as_fn_append ac_header_list " complex.h" as_fn_append ac_header_list " stdlib.h" +as_fn_append ac_header_list " errno.h" +as_fn_append ac_func_list " getprogname" as_fn_append ac_func_list " random_r" as_fn_append ac_func_list " srandom_r" as_fn_append ac_func_list " initstate_r" @@ -11750,7 +11798,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 11753 "configure" +#line 11801 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -11856,7 +11904,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 11859 "configure" +#line 11907 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -17016,7 +17064,29 @@ done -# These are GLIBC + + +# Look for a way to represent the program name +# First, check the GLIBC case +ac_fn_cxx_check_decl "$LINENO"
[gcc r15-10118] cobol: Allow for undefined NAME_MAX [PR119217]
https://gcc.gnu.org/g:1066f31c3d2f28a85f8c89446166120a45eba8dc commit r15-10118-g1066f31c3d2f28a85f8c89446166120a45eba8dc Author: Rainer Orth Date: Thu May 8 09:39:26 2025 +0200 cobol: Allow for undefined NAME_MAX [PR119217] All users of symbols.h fail to compile on Solaris: /vol/gcc/src/hg/master/local/gcc/cobol/symbols.h: At global scope: /vol/gcc/src/hg/master/local/gcc/cobol/symbols.h:1365:13: error: ‘NAME_MAX’ was not declared in this scope 1365 | char name[NAME_MAX]; | ^~~~ NAME_MAX being undefined is allowed by POSIX.1, actually: it's listed for under "Pathname Variable Values": A definition of one of the symbolic constants in the following list shall be omitted from the header on specific implementations where the corresponding value is equal to or greater than the stated minimum, but where the value can vary depending on the file to which it is applied. The actual value supported for a specific pathname shall be provided by the pathconf() function. As a hack, this patch provides a fallback definition to allow the build to finish. In fact it turned out that cbl_funtion_t.name isn't filename related and never set at all, so this patch serves as a mere stopgap fix to unbreak the build until a real solution can be figured out. Bootstrapped without regressions on amd64-pc-solaris2.11, sparcv9-sun-solaris2.11, and x86_64-pc-linux-gnu. 2025-04-08 Rainer Orth gcc/cobol: PR cobol/119217 * symbols.h (NAME_MAX): Define fallback. (cherry picked from commit 1df8fffba30bf4022dda762bf61acf16ac704c67) Diff: --- gcc/cobol/symbols.h | 5 + 1 file changed, 5 insertions(+) diff --git a/gcc/cobol/symbols.h b/gcc/cobol/symbols.h index adfa8d979b2f..50c5d48ff9f5 100644 --- a/gcc/cobol/symbols.h +++ b/gcc/cobol/symbols.h @@ -46,6 +46,11 @@ #include #include +// Provide fallback definition. +#ifndef NAME_MAX +#define NAME_MAX 255 +#endif + #define PICTURE_MAX 64 extern const char *numed_message;
[gcc r15-10113] cobol: Fix up exception handling [PR119364]
https://gcc.gnu.org/g:167f3663ccc7d0a5cf2a83e0c29461ca79841e99 commit r15-10113-g167f3663ccc7d0a5cf2a83e0c29461ca79841e99 Author: Jakub Jelinek Date: Fri May 2 19:10:59 2025 +0200 cobol: Fix up exception handling [PR119364] The following patch on top of the https://gcc.gnu.org/pipermail/gcc-patches/2025-May/682500.html fixes most of the remaining make check-cobol FAILs in the i686-linux -> x86_64-linux cross-compiler. Using the testing environment detailed in https://gcc.gnu.org/pipermail/gcc-patches/2025-April/680403.html with this patch I get just cobol.dg/group1/declarative_1.cob FAILs in i686-linux -> x86_64-linux cross and no FAILs in x86_64-linux native one. The patch isn't needed just for cross-compilation with different hosts, but also on x86_64-linux/aarch64-linux native, because without it the FE is hashing padding bits which contain random garbage and making code generation decisions based on that. That is very much against the reproduceability requirements. 2025-05-02 Jakub Jelinek PR cobol/119364 * structs.h (cbl_enabled_exception_type_node): New variable declaration. * structs.cc (cbl_enabled_exception_type_node): New variable. (create_cbl_enabled_exception_t): New function. (create_our_type_nodes): Initialize cbl_enabled_exception_type_node using it. * genapi.cc (stash_exceptions): Don't compare padding bits to determine if the exceptions are the same as last time. Use cbl_enabled_exception_type_node for target size and field offsets and native_encode_expr to write each field into byte sequence. (cherry picked from commit c77d04506e6abdc45969d0ff146204be7485244a) Diff: --- gcc/cobol/genapi.cc | 66 +--- gcc/cobol/structs.cc | 25 gcc/cobol/structs.h | 1 + 3 files changed, 73 insertions(+), 19 deletions(-) diff --git a/gcc/cobol/genapi.cc b/gcc/cobol/genapi.cc index eba10b0bdfe3..dca52ce080d5 100644 --- a/gcc/cobol/genapi.cc +++ b/gcc/cobol/genapi.cc @@ -13301,24 +13301,29 @@ static void stash_exceptions( const cbl_enabled_exceptions_array_t *enabled ) { // We need to create a static array of bytes - size_t narg = enabled->nbytes(); - unsigned char *p = (unsigned char *)(enabled->ecs); + size_t nec = enabled->nec; + size_t sz = int_size_in_bytes(cbl_enabled_exception_type_node); + size_t narg = nec * sz; + cbl_enabled_exception_t *p = enabled->ecs; - static size_t prior_narg = 0; - static size_t max_narg = 128; - static unsigned char *prior_p = (unsigned char *)xmalloc(max_narg); + static size_t prior_nec = 0; + static size_t max_nec = 0; + static cbl_enabled_exception_t *prior_p; bool we_got_new_data = false; - if( prior_narg != narg ) + if( prior_nec != nec ) { we_got_new_data = true; } else { -// The narg counts are the same. -for(size_t i=0; i max_narg ) + if( nec > max_nec ) { -max_narg = narg; -prior_p = (unsigned char *)xrealloc(prior_p, max_narg); +max_nec = nec; +prior_p = (cbl_enabled_exception_t *) + xrealloc(prior_p, max_nec * sizeof(cbl_enabled_exception_t)); } - memcpy(prior_p, p, narg); + memcpy((unsigned char *)prior_p, (unsigned char *)p, + nec * sizeof(cbl_enabled_exception_t)); static int count = 1; @@ -13355,12 +13362,33 @@ stash_exceptions( const cbl_enabled_exceptions_array_t *enabled ) TREE_TYPE(constr) = array_of_chars_type; TREE_STATIC(constr)= 1; TREE_CONSTANT(constr) = 1; - -for(size_t i=0; i
[gcc r15-10126] cobol: Eliminate exception "blob"; streamline some code generation.
https://gcc.gnu.org/g:08e58db367d94e6abc8b3d00cebc2db88c0aa828 commit r15-10126-g08e58db367d94e6abc8b3d00cebc2db88c0aa828 Author: Robert Dubner Date: Fri May 16 11:12:04 2025 -0400 cobol: Eliminate exception "blob"; streamline some code generation. This eliminates some of the last vestiges of creating a structure at host-time that is intended for use at target-time. It removes some unnecessary processing when exceptions are not enabled. It improves the creation of code that handles table subscripts and refmod parameters. gcc/cobol/ChangeLog: * cobol1.cc (cobol_langhook_handle_option): Eliminate OPT_M. * except.cc (cbl_enabled_exception_t::dump): Formatting. (symbol_declaratives_add): Remove. (declarative_runtime_match): Change to no-blob processing. * exceptg.h (declarative_runtime_match): Change declaration. (symbol_declaratives_add): Remove declaration. * gcobc: Dialect handling. * genapi.cc (parser_compile_ecs): Formatting; add SHOW_IF_PARSE. (parser_compile_dcls): Likewise. (parser_statement_begin): Avoid unnecessary store_location_stuff() call. (gg_get_depending_on_value): Streamline get_depending_on_value_from_odo(). (depending_on_value): Likewise. (parser_display_field): Formatting. (parser_display): Handle case ENV_NAME_e. (parser_file_open): Avoid unnecessary store_location_stuff. (parser_file_close): Likewise. (parser_file_read): Likewise. (parser_file_write): Likewise. (parser_file_delete): Likewise. (parser_file_rewrite): Likewise. (parser_file_start): Likewise. (parser_intrinsic_subst): Streamline get_depending_on_value_from_odo(). (parser_intrinsic_call_1): Likewise. (parser_lsearch_start): Likewise. (parser_bsearch_start): Likewise. (parser_sort): Likewise. (store_location_stuff): Avoid unnecessary assignments. (parser_pop_exception): Formatting. * genmath.cc (parser_add): Avoid var_decl_default_compute_error assignment when doing fast_add(). (parser_subtract): Likewise. * genutil.cc (REFER): Macro for analyzing code generation. (get_integer_value): Use data_decl_node for integer value from FldLiteralN. (get_data_offset): Streamline exception code processing. (get_and_check_refstart_and_reflen): Likewise. (get_depending_on_value_from_odo): Likewise. (get_depending_on_value): Likewise. (refer_is_clean): Formatting. (refer_refmod_length): Streamline exception code processing. (refer_fill_depends): Likewise. (refer_offset): Likewise. (refer_size_dest): Likewise. (refer_size_source): Likewise. * genutil.h (get_depending_on_value_from_odo): Likewise. * lang-specs.h: Options definition. * lang.opt: -M as in c.opt. * lexio.h: Formatting. * parse.y: Expand -dialect suggestions; SECTION SEGMENT messages. * parse_ante.h (declarative_runtime_match): Dialect handling. (labels_dump): Likewise. (class current_tokens_t): Likewise. (class prog_descr_t): Make program_index size_t to prevent padding bytes. * scan.l: POP_FILE directive. * scan_ante.h (class enter_leave_t): Better handle line number when processing COPY statements. * symbols.cc (symbol_elem_cmp): Eliminate SymFunction. (symbols_dump): Likewise. (symbol_label_section_exists): Likewise. * symbols.h (NAME_MAX): Eliminate. (Was part of SymFunction). (dialect_is): Improve dialect handling. (dialect_gcc): Likewise. (dialect_ibm): Likewise. (dialect_gnu): Likewise. (enum symbol_type_t): Eliminate SymFunction. * util.cc (symbol_type_str): Likewise. (class unique_stack): Option -M handling. (cobol_set_pp_option): Likewise. (parse_file): Likewise. * util.h (cobol_set_pp_option): Likewise. libgcobol/ChangeLog: * common-defs.h (struct cbl_declarative_t): Eliminate blobl. * libgcobol.cc (__gg__set_env_name): Code for ENVIRONMENT-NAME/VALUE. (__gg__set_env_value): Likewise. gcc/testsuite/ChangeLog: * cobol.dg/group1/declarative_1.cob: Handle modified exception handling. (cherry picked from commit 92b6485a75cabaf64f1f74ba7ab73a5204c9d0aa) Diff: --- gcc/cobol/cobol1.cc | 23 +- gcc/cobol/except.cc | 111 ++--- gcc/cobol/exceptg.h
[gcc r15-10123] libgcobol: Allow for lack of LOG_PERROR
https://gcc.gnu.org/g:5ce4d3e211d43d069d60fea8d53dab7115a235db commit r15-10123-g5ce4d3e211d43d069d60fea8d53dab7115a235db Author: Rainer Orth Date: Tue May 13 09:43:48 2025 +0200 libgcobol: Allow for lack of LOG_PERROR The libgcobol build is broken again on Solaris: /vol/gcc/src/hg/master/local/libgcobol/libgcobol.cc: In function ‘void default_exception_handler(ec_type_t)’: /vol/gcc/src/hg/master/local/libgcobol/libgcobol.cc:11196:44: error: ‘LOG_PERROR’ was not declared in this scope; did you mean ‘LOG_ERR’? 11196 | static int priority = LOG_INFO, option = LOG_PERROR, facility = LOG_USER; |^~ |LOG_ERR /vol/gcc/src/hg/master/local/libgcobol/libgcobol.cc:11202:28: error: ‘facility’ was not declared in this scope 11202 | openlog(ident, option, facility); |^~~~ LOG_PERROR is a BSD extension not present on Solaris due to its System V heritage, and Linux syslog(3) documents: LOG_PERROR (Not in POSIX.1-2001 or POSIX.1-2008.) Also log the message to stderr. This patch provides a fallback definition, just the minimum to unbreak the build. Tested on amd64-pc-solaris2.11, sparcv9-sun-solaris2.11, and x86_64-pc-linux-gnu. 2025-05-12 Rainer Orth libgcobol: * libgcobol.cc [!LOG_PERROR] (LOG_PERROR): Provide fallback. (cherry picked from commit 90fee97d528e8447648c37f9df1daa3445e598bc) Diff: --- libgcobol/libgcobol.cc | 5 + 1 file changed, 5 insertions(+) diff --git a/libgcobol/libgcobol.cc b/libgcobol/libgcobol.cc index 2de87cbfc487..56b1a7bf5876 100644 --- a/libgcobol/libgcobol.cc +++ b/libgcobol/libgcobol.cc @@ -75,6 +75,11 @@ #include "exceptl.h" +/* BSD extension. */ +#if !defined(LOG_PERROR) +#define LOG_PERROR 0 +#endif + #if !defined (HAVE_STRFROMF32) # if __FLT_MANT_DIG__ == 24 && __FLT_MAX_EXP__ == 128 static int
[gcc r15-10129] cobol: Multiple PRs; formatting; exception processing.
https://gcc.gnu.org/g:907e343138c9e4eee09c7e263418a45c67fbd116 commit r15-10129-g907e343138c9e4eee09c7e263418a45c67fbd116 Author: Robert Dubner Date: Tue May 20 13:35:15 2025 -0400 cobol: Multiple PRs; formatting; exception processing. The PRs mentined here have either been previously fixed, or are fixed by this commit. gcc/cobol/ChangeLog: PR cobol/119770 PR cobol/119772 PR cobol/119790 PR cobol/119771 PR cobol/119810 PR cobol/119335 PR cobol/119632 * cdf-copy.cc (GLOB_BRACE): Eliminate . * cdfval.h (_CDF_VAL_H_): Switch to C++ headers. * copybook.h (class copybook_elem_t): Eliminate . (class copybook_t): Likewise. * gcobc: Numerous changes to improve utility. * gcobol.1: Correct names in the list of functions. * genapi.cc (compare_binary_binary): Use has_attr() function. * lexio.cc (cdftext::lex_open): Typo; filename logic. (cdftext::process_file): Filename logic. * parse.y: Numerous parsing changes. * parse_ante.h (new_alphanumeric): C++ includes; changes to temporaries. (new_tempnumeric): Likewise. (new_tempnumeric_float): Likewise. (set_real_from_capacity): Created. * scan.l: Use yy_pop_state(). * scan_ante.h (typed_name): Find figconst from data.initial. * symbols.cc (symbol_valid_udf_args): Eliminate. (symbols_update): figconst processing. (new_temporary_impl): For functions, set .initial to function name. (temporaries_t::acquire): Likewise. (new_alphanumeric): Likewise. (new_temporary): Likewise. * symbols.h (_SYMBOLS_H_): Use C++ includes. (cbl_figconst_tok): Change handling of figconst. (cbl_figconst_field_of): Change handling of figconst. (symbol_valid_udf_args): Eliminate. * symfind.cc (symbol_match2): Change declaration. (symbol_match): Change declaration. libgcobol/ChangeLog: * charmaps.cc: Switch to C++ includes. * common-defs.h: Likewise. * constants.cc: Likewise. * ec.h: Remove #include . * gcobolio.h (GCOBOLIO_H_): Switch to C++ includes. * gfileio.cc: Likewise. * gmath.cc: Likewise. * intrinsic.cc: Comment formatting; C++ includes. * io.cc: C++ includes. * libgcobol.cc: (__gg__stash_exceptions): Eliminate. * valconv.cc: Switch to C++ includes. Co-Authored-By: James K. Lowden (cherry picked from commit fba34a0cc55488ad89becf81cf2c9ac517d244d4) Diff: --- gcc/cobol/cdf-copy.cc | 88 +++ gcc/cobol/cdfval.h | 6 +- gcc/cobol/copybook.h| 13 +-- gcc/cobol/gcobc | 141 ++-- gcc/cobol/gcobol.1 | 54 - gcc/cobol/genapi.cc | 4 +- gcc/cobol/lexio.cc | 7 +- gcc/cobol/parse.y | 283 +++- gcc/cobol/parse_ante.h | 35 -- gcc/cobol/scan.l| 2 +- gcc/cobol/scan_ante.h | 4 + gcc/cobol/symbols.cc| 63 +++ gcc/cobol/symbols.h | 19 ++-- gcc/cobol/symfind.cc| 4 +- libgcobol/charmaps.cc | 14 ++- libgcobol/common-defs.h | 5 +- libgcobol/constants.cc | 19 ++-- libgcobol/ec.h | 1 - libgcobol/gcobolio.h| 3 +- libgcobol/gfileio.cc| 18 +-- libgcobol/gmath.cc | 19 ++-- libgcobol/intrinsic.cc | 22 ++-- libgcobol/io.cc | 11 +- libgcobol/libgcobol.cc | 14 +-- libgcobol/valconv.cc| 7 +- 25 files changed, 456 insertions(+), 400 deletions(-) diff --git a/gcc/cobol/cdf-copy.cc b/gcc/cobol/cdf-copy.cc index 059596c08f41..99f5866ae86f 100644 --- a/gcc/cobol/cdf-copy.cc +++ b/gcc/cobol/cdf-copy.cc @@ -35,23 +35,12 @@ // We regret any confusion engendered. #include "config.h" -#include #include "cobol-system.h" #include "cbldiag.h" #include "util.h" #include "copybook.h" -// GLOB_BRACE and GLOB_TILDE are BSD extensions. Provide fallback definitions -// if necessary. -#ifndef GLOB_BRACE -#define GLOB_BRACE 0 -#endif - -#ifndef GLOB_TILDE -#define GLOB_TILDE 0 -#endif - #define COUNT_OF(X) (sizeof(X) / sizeof(X[0])) /* @@ -86,7 +75,6 @@ * space. This function only applies them. */ -extern int yydebug; const char * cobol_filename(); bool is_fixed_format(); bool is_reference_format(); @@ -190,12 +178,6 @@ esc( size_t len, const char input[] ) { return buffer; // caller must strdup static buffer } -static int -glob_error(const char *epath, int eerrno) { - dbgmsg("%s: COPY file search: '%s': %s", __func__, epath, xstrerror(eerrno)); - return 0; -} - void copybook_directory_add( const char gcob_copybook[] ) { if( !gcob_copybook ) return; @@ -242
[gcc r15-10128] cobol: sqrt(0) is not an ec-argument error. [PR119885]
https://gcc.gnu.org/g:e7f1334ad02d4913346238aba58b0025ab7f455c commit r15-10128-ge7f1334ad02d4913346238aba58b0025ab7f455c Author: Robert Dubner Date: Tue May 20 11:49:43 2025 -0400 cobol: sqrt(0) is not an ec-argument error. [PR119885] libgcobol PR cobol/119885 * intrinsic.cc: (__gg__sqrt): Change test from <= zero to < zero. gcc/testsuite * cobol.dg/group2/FUNCTION_SQRT__2_.cob: Testcase. * cobol.dg/group2/FUNCTION_SQRT__2_.out: Known-good for the testcase. (cherry picked from commit d44beb132850a8ced1b0614e2724f18465b4a737) Diff: --- gcc/testsuite/cobol.dg/group2/FUNCTION_SQRT__2_.cob | 13 + gcc/testsuite/cobol.dg/group2/FUNCTION_SQRT__2_.out | 5 + libgcobol/intrinsic.cc | 2 +- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/gcc/testsuite/cobol.dg/group2/FUNCTION_SQRT__2_.cob b/gcc/testsuite/cobol.dg/group2/FUNCTION_SQRT__2_.cob new file mode 100644 index ..c1f4ba8684a6 --- /dev/null +++ b/gcc/testsuite/cobol.dg/group2/FUNCTION_SQRT__2_.cob @@ -0,0 +1,13 @@ + *> { dg-do run } + *> { dg-output-file "group2/FUNCTION_SQRT__2_.out" } +program-id. sqbug. +procedure division. +if function sqrt (0) = 0*>if4034.2 +display 'ok' else display 'bad'. +display "sqrt(0) " function trim (function exception-status) +set last exception to off +if function sqrt (-0.1) = 0*>if4034.2 +display 'ok' else display 'bad'. +display "sqrt(-0.1) " function trim (function exception-status) +goback. + diff --git a/gcc/testsuite/cobol.dg/group2/FUNCTION_SQRT__2_.out b/gcc/testsuite/cobol.dg/group2/FUNCTION_SQRT__2_.out new file mode 100644 index ..0783ac5abb17 --- /dev/null +++ b/gcc/testsuite/cobol.dg/group2/FUNCTION_SQRT__2_.out @@ -0,0 +1,5 @@ +ok +sqrt(0) "" +bad +sqrt(-0.1) "EC-ARGUMENT-FUNCTION" + diff --git a/libgcobol/intrinsic.cc b/libgcobol/intrinsic.cc index 37ae13e262fe..d6dfcb981a5e 100644 --- a/libgcobol/intrinsic.cc +++ b/libgcobol/intrinsic.cc @@ -3565,7 +3565,7 @@ __gg__sqrt( cblc_field_t *dest, source_offset, source_size); - if( value <= GCOB_FP128_LITERAL(0.0) ) + if( value < GCOB_FP128_LITERAL(0.0) ) { exception_raise(ec_argument_function_e); }
[gcc r15-10116] cobol: Don't require GLOB_BRACE etc. [PR119217]
https://gcc.gnu.org/g:320f24a3b26aa8dc0640aa56b63bc9ef30ca043b commit r15-10116-g320f24a3b26aa8dc0640aa56b63bc9ef30ca043b Author: Rainer Orth Date: Thu May 8 09:21:45 2025 +0200 cobol: Don't require GLOB_BRACE etc. [PR119217] cdf-copy.cc doesn't compile on Solaris: /vol/gcc/src/hg/master/local/gcc/cobol/cdf-copy.cc: In member function ‘int copybook_elem_t::open_file(const char*, bool)’: /vol/gcc/src/hg/master/local/gcc/cobol/cdf-copy.cc:317:34: error: ‘GLOB_BRACE’ was not declared in this scope; did you mean ‘GLOB_ERR’? 317 | static int flags = GLOB_MARK | GLOB_BRACE | GLOB_TILDE; | ^~ | GLOB_ERR /vol/gcc/src/hg/master/local/gcc/cobol/cdf-copy.cc:317:47: error: ‘GLOB_TILDE’ was not declared in this scope 317 | static int flags = GLOB_MARK | GLOB_BRACE | GLOB_TILDE; | ^~ GLOB_BRACE and GLOB_TILDE are BSD extensions not in POSIX.1, thus missing on Solaris probably due to its System V heritage. This patch introduces fallback definitions to avoid this. Bootstrapped without regressions on amd64-pc-solaris2.11, sparcv9-sun-solaris2.11, and x86_64-pc-linux-gnu. 2025-04-08 Rainer Orth gcc/cobol: PR cobol/119217 * cdf-copy.cc (GLOB_BRACE): Define fallback. (GLOB_TILDE): Likewise. (cherry picked from commit aacaa3b13bca508cb6cb803d11cb942b2de8c0db) Diff: --- gcc/cobol/cdf-copy.cc | 10 ++ 1 file changed, 10 insertions(+) diff --git a/gcc/cobol/cdf-copy.cc b/gcc/cobol/cdf-copy.cc index 2e4bfb623d1e..059596c08f41 100644 --- a/gcc/cobol/cdf-copy.cc +++ b/gcc/cobol/cdf-copy.cc @@ -42,6 +42,16 @@ #include "util.h" #include "copybook.h" +// GLOB_BRACE and GLOB_TILDE are BSD extensions. Provide fallback definitions +// if necessary. +#ifndef GLOB_BRACE +#define GLOB_BRACE 0 +#endif + +#ifndef GLOB_TILDE +#define GLOB_TILDE 0 +#endif + #define COUNT_OF(X) (sizeof(X) / sizeof(X[0])) /*
[gcc r15-10125] cobol: One additional edit to testsuite/cobol.dg/group1/check_88.cob [PR120251]
https://gcc.gnu.org/g:aa66c628206d10d101f9d3528b3b641189fc280e commit r15-10125-gaa66c628206d10d101f9d3528b3b641189fc280e Author: Robert Dubner Date: Thu May 15 13:33:16 2025 -0400 cobol: One additional edit to testsuite/cobol.dg/group1/check_88.cob [PR120251] Missed one edit. This fixes that. gcc/testsuite/ChangeLog: PR cobol/120251 * cobol.dg/group1/check_88.cob: One final regex "." instead of "ß" (cherry picked from commit fae53928595341981f08ded4edcbba07ee1d5d04) Diff: --- gcc/testsuite/cobol.dg/group1/check_88.cob | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/testsuite/cobol.dg/group1/check_88.cob b/gcc/testsuite/cobol.dg/group1/check_88.cob index 18a299fc282b..f1d0685e478a 100644 --- a/gcc/testsuite/cobol.dg/group1/check_88.cob +++ b/gcc/testsuite/cobol.dg/group1/check_88.cob @@ -17,7 +17,7 @@ *> { dg-output {.* Bundesstra.e(\n|\r\n|\r)} } *> { dg-output { (\n|\r\n|\r)} } *> { dg-output {There should be no spaces before the final quote(\n|\r\n|\r)} } -*> { dg-output {".* Bundesstraße"(\n|\r\n|\r)} } +*> { dg-output {".* Bundesstra.e"(\n|\r\n|\r)} } *> { dg-output { (\n|\r\n|\r)} } *> { dg-output { IsLow ""(\n|\r\n|\r)} } *> { dg-output { IsZero "000"(\n|\r\n|\r)} }
[gcc r15-10124] cobol: Don't display 0xFF HIGH-VALUE characters in testcases. [PR120251]
https://gcc.gnu.org/g:412994e3d304229f60ef3bc597c87bae4bfb4e22 commit r15-10124-g412994e3d304229f60ef3bc597c87bae4bfb4e22 Author: Robert Dubner Date: Thu May 15 12:01:12 2025 -0400 cobol: Don't display 0xFF HIGH-VALUE characters in testcases. [PR120251] The tests were displaying 0xFF characters, and the resulting generated output changed with the system locale. The check_88 test was modified so that the regex comparisons ignore those character positions. Two of the other tests were changed to output hexadecimal rather than character strings. There is one new test, and the other inspect testcases were edited to remove an unimportant back-apostrophe that had found its way into the source code sequence number area. gcc/testsuite/ChangeLog: PR cobol/120251 * cobol.dg/group1/check_88.cob: Ignore characters above 0x80. * cobol.dg/group2/ALLOCATE_Rule_8_OPTION_INITIALIZE_with_figconst.cob: Output HIGH-VALUE as hex, rather than as characters. * cobol.dg/group2/ALLOCATE_Rule_8_OPTION_INITIALIZE_with_figconst.out: Likewise. * cobol.dg/group2/INSPECT_CONVERTING_TO_figurative_constants.cob: Typo. * cobol.dg/group2/INSPECT_CONVERTING_TO_figurative_constants.out: Likewise. * cobol.dg/group2/INSPECT_ISO_Example_1.cob: Likewise. * cobol.dg/group2/INSPECT_ISO_Example_2.cob: Likewise. * cobol.dg/group2/INSPECT_ISO_Example_3.cob: Likewise. * cobol.dg/group2/INSPECT_ISO_Example_4.cob: Likewise. * cobol.dg/group2/INSPECT_ISO_Example_5-f.cob: Likewise. * cobol.dg/group2/INSPECT_ISO_Example_6.cob: Likewise. * cobol.dg/group2/INSPECT_ISO_Example_7.cob: Likewise. * cobol.dg/group2/Multiple_INDEXED_BY_variables_with_the_same_name.cob: New test. * cobol.dg/group2/Multiple_INDEXED_BY_variables_with_the_same_name.out: New test. (cherry picked from commit 022d8e25e49021b378a4e6c24c2f0c380a066690) Diff: --- gcc/testsuite/cobol.dg/group1/check_88.cob | 12 +-- ...CATE_Rule_8_OPTION_INITIALIZE_with_figconst.cob | 3 ++- ...CATE_Rule_8_OPTION_INITIALIZE_with_figconst.out | 3 +-- .../INSPECT_CONVERTING_TO_figurative_constants.cob | 12 +-- .../INSPECT_CONVERTING_TO_figurative_constants.out | 10 - .../cobol.dg/group2/INSPECT_ISO_Example_1.cob | 2 +- .../cobol.dg/group2/INSPECT_ISO_Example_2.cob | 2 +- .../cobol.dg/group2/INSPECT_ISO_Example_3.cob | 2 +- .../cobol.dg/group2/INSPECT_ISO_Example_4.cob | 2 +- .../cobol.dg/group2/INSPECT_ISO_Example_5-f.cob| 2 +- .../cobol.dg/group2/INSPECT_ISO_Example_6.cob | 2 +- .../cobol.dg/group2/INSPECT_ISO_Example_7.cob | 2 +- ...ple_INDEXED_BY_variables_with_the_same_name.cob | 24 ++ ...ple_INDEXED_BY_variables_with_the_same_name.out | 3 +++ 14 files changed, 54 insertions(+), 27 deletions(-) diff --git a/gcc/testsuite/cobol.dg/group1/check_88.cob b/gcc/testsuite/cobol.dg/group1/check_88.cob index 4a7723eb92a3..18a299fc282b 100644 --- a/gcc/testsuite/cobol.dg/group1/check_88.cob +++ b/gcc/testsuite/cobol.dg/group1/check_88.cob @@ -3,25 +3,25 @@ *> { dg-output {\-> <\-(\n|\r\n|\r)} } *> { dg-output {\->"""<\-(\n|\r\n|\r)} } *> { dg-output {\->000<\-(\n|\r\n|\r)} } -*> { dg-output {\->ÿÿÿ<\-(\n|\r\n|\r)} } +*> { dg-output {\->.*<\-(\n|\r\n|\r)} } *> { dg-output { (\n|\r\n|\r)} } *> { dg-output {\-><\-(\n|\r\n|\r)} } *> { dg-output {\-><\-(\n|\r\n|\r)} } *> { dg-output {\-><\-(\n|\r\n|\r)} } *> { dg-output {\-><\-(\n|\r\n|\r)} } -*> { dg-output {\-><\-(\n|\r\n|\r)} } +*> { dg-output {\->.*<\-(\n|\r\n|\r)} } *> { dg-output { (\n|\r\n|\r)} } *> { dg-output {There should be no garbage after character 32(\n|\r\n|\r)} } *> { dg-output {\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\*\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-(\n|\r\n|\r)} } -*> { dg-output {üüü Bundesstraße (\n|\r\n|\r)} } -*> { dg-output {üüü Bundesstraße (\n|\r\n|\r)} } +*> { dg-output {.* Bundesstra.e(\n|\r\n|\r)} } +*> { dg-output {.* Bundesstra.e(\n|\r\n|\r)} } *> { dg-output { (\n|\r\n|\r)} } *> { dg-output {There should be no spaces before the final quote(\n|\r\n|\r)} } -*> { dg-output {"üüü Bundesstraße"(\n|\r\n|\r)} } +*> { dg-output {".* Bundesstraße"(\n|\r\n|\r)} } *> { dg-output { (\n|\r\n|\r)} } *> { dg-output { IsLow ""(\n|\r\n|\r)} } *> { dg-output { IsZero "000"(\n|\r\n|\r)} } -*> { dg-output { IsHi"ÿÿÿ"(\n|\r\n|\r)} } +*> { dg-output { IsHi".*"(\n|\r\n|\r)} } *> { dg-output { IsBob "bob"(\n|\r\n|\r)} } *> { dg-output { IsQuote "(\n|\r\n|\r)} } *> { dg-output { IsS
[gcc r15-10130] cobol: Wrap the call to fprintf in a libgcobol routine. [PR119524]
https://gcc.gnu.org/g:7305d78ab9478422ac03d17399e2384859a73c81 commit r15-10130-g7305d78ab9478422ac03d17399e2384859a73c81 Author: Robert Dubner Date: Sun Jun 1 12:32:37 2025 -0400 cobol: Wrap the call to fprintf in a libgcobol routine. [PR119524] gcc/cobol/ChangeLog: PR cobol/119524 * gengen.cc (gg_printf): Use the new __gg__fprintf_stderr() function instead of generating a call to fprintf(). libgcobol/ChangeLog: PR cobol/119524 * libgcobol.cc (__gg__fprintf_stderr): New function. (cherry picked from commit 213cb633e7ec9b291768a4da0cd6d67679221aeb) Diff: --- gcc/cobol/gengen.cc| 16 +--- libgcobol/libgcobol.cc | 14 ++ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/gcc/cobol/gengen.cc b/gcc/cobol/gengen.cc index 91f67d534f6e..a5f143cf2342 100644 --- a/gcc/cobol/gengen.cc +++ b/gcc/cobol/gengen.cc @@ -2152,18 +2152,6 @@ gg_printf(const char *format_string, ...) int nargs = 0; tree args[ARG_LIMIT]; - // Because this routine is intended for debugging, we are sending the - // text to STDERR - - // Because we don't actually use stderr ourselves, we just pick it up as a - // VOID_P and pass it along to fprintf() - tree t_stderr = gg_declare_variable(VOID_P, "stderr", - NULL_TREE, - vs_external_reference); - - gg_push_context(); - - args[nargs++] = t_stderr; args[nargs++] = build_string_literal(strlen(format_string)+1, format_string); va_list ap; @@ -2197,7 +2185,7 @@ gg_printf(const char *format_string, ...) static tree function = NULL_TREE; if( !function ) { -function = gg_get_function_address(INT, "fprintf"); +function = gg_get_function_address(INT, "__gg__fprintf_stderr"); } tree stmt = build_call_array_loc (location_from_lineno(), @@ -2206,8 +2194,6 @@ gg_printf(const char *format_string, ...) nargs, args); gg_append_statement(stmt); - - gg_pop_context(); } tree diff --git a/libgcobol/libgcobol.cc b/libgcobol/libgcobol.cc index 66405baf99b1..3ab74636601b 100644 --- a/libgcobol/libgcobol.cc +++ b/libgcobol/libgcobol.cc @@ -49,6 +49,7 @@ #include #include #include +#include #if __has_include() # include // for program_invocation_short_name #endif @@ -13151,3 +13152,16 @@ __gg__set_env_value(cblc_field_t *value, // And now, anticlimactically, set the variable: setenv(trimmed_env, trimmed_val, 1); } + +extern "C" +void +__gg__fprintf_stderr(const char *format_string, ...) + { + /* This routine allows the compiler to send stuff to stderr in a way + that is straightforward to use.. */ + va_list ap; + va_start(ap, format_string); + vfprintf(stderr, format_string, ap); + va_end(ap); + } +
[gcc r15-10117] cobol: Initialize regmatch_t portably [PR119217]
https://gcc.gnu.org/g:43bf1b391b4b34a9e0be07770aeec2e8c6b08b25 commit r15-10117-g43bf1b391b4b34a9e0be07770aeec2e8c6b08b25 Author: Rainer Orth Date: Thu May 8 09:29:56 2025 +0200 cobol: Initialize regmatch_t portably [PR119217] The dts.h initialization of regmatch_t currently breaks Solaris compilation: In file included from /vol/gcc/src/hg/master/local/gcc/cobol/lexio.h:208, from /vol/gcc/src/hg/master/local/gcc/cobol/lexio.cc:36: /vol/gcc/src/hg/master/local/gcc/cobol/dts.h: In constructor ‘dts::csub_match::csub_match(const char*)’: /vol/gcc/src/hg/master/local/gcc/cobol/dts.h:36:35: error: invalid conversion from ‘int’ to ‘const char*’ [-fpermissive] 36 | static regmatch_t empty = { -1, -1 }; | ^~ | | | int The problem is that Solaris regmatch_t has additional members before rm_so and rm_eo, as is always allowed by POSIX.1 typedef struct { const char *rm_sp, *rm_ep; /* Start pointer, end pointer */ regoff_trm_so, rm_eo; /* Start offset, end offset */ int rm_ss, rm_es; /* Used internally */ } regmatch_t; so the initialization doesn't do what it's supposed to do. Fixed by initializing the rm_so and rm_eo members explicitly. Bootstrapped without regressions on amd64-pc-solaris2.11, sparcv9-sun-solaris2.11, and x86_64-pc-linux-gnu. 2025-04-08 Rainer Orth gcc/cobol: PR cobol/119217 * dts.h (csub_match): Initialize rm_so, rm_eo fields explicitly. (cherry picked from commit 12d6fa2a21140166181ae3be7711d60e62c569d7) Diff: --- gcc/cobol/dts.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gcc/cobol/dts.h b/gcc/cobol/dts.h index c345dc7e64ab..dfd7c4c24f71 100644 --- a/gcc/cobol/dts.h +++ b/gcc/cobol/dts.h @@ -33,7 +33,8 @@ namespace dts { : input(input) , first(NULL), second(NULL), matched(false) { - static regmatch_t empty = { -1, -1 }; + static regmatch_t empty; + empty.rm_so = empty.rm_eo = -1; regmatch_t& self(*this); self = empty; }
[gcc r15-10139] libgcobol: Add license.
https://gcc.gnu.org/g:fd735329ee8bddd34be4a341aa04132c9503dadf commit r15-10139-gfd735329ee8bddd34be4a341aa04132c9503dadf Author: James K. Lowden Date: Fri Jun 20 10:16:26 2025 -0400 libgcobol: Add license. libgcobol/ChangeLog: * LICENSE: New file. (cherry picked from commit 632a50abc3a99cace8abc6ed3817f7eb1312c9d2) Diff: --- libgcobol/LICENSE | 27 +++ 1 file changed, 27 insertions(+) diff --git a/libgcobol/LICENSE b/libgcobol/LICENSE new file mode 100644 index ..3937993c56a2 --- /dev/null +++ b/libgcobol/LICENSE @@ -0,0 +1,27 @@ +Copyright (c) 2021-2025 Symas Corporation + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + +* Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following disclaimer + in the documentation and/or other materials provided with the + distribution. +* Neither the name of the Symas Corporation nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
[gcc r15-10148] cobol: Fix build on 32-bit Darwin [PR120621]
https://gcc.gnu.org/g:79c7ed9d45d1862fb1ac4e6f3653bf8892c3afe6 commit r15-10148-g79c7ed9d45d1862fb1ac4e6f3653bf8892c3afe6 Author: Rainer Orth Date: Fri Jul 11 09:56:18 2025 +0200 cobol: Fix build on 32-bit Darwin [PR120621] Bootstrapping trunk with 32-bit-default on Mac OS X 10.11 (i386-apple-darwin15) fails: /vol/gcc/src/hg/master/local/gcc/cobol/lexio.cc: In static member function 'static void cdftext::process_file(filespan_t, int, bool)': /vol/gcc/src/hg/master/local/gcc/cobol/lexio.cc:1859:14: error: format '%u' expects argument of type 'unsigned int', but argument 4 has type 'size_t' {aka 'long unsigned int'} [-Werror=format=] 1859 | dbgmsg("%s:%d: line " HOST_SIZE_T_PRINT_UNSIGNED ", opening %s on fd %d", | ^ 1860 | __func__, __LINE__,mfile.lineno(), | ~~ | | | size_t {aka long unsigned int} In file included from /vol/gcc/src/hg/master/local/gcc/system.h:1244, from /vol/gcc/src/hg/master/local/gcc/cobol/cobol-system.h:61, from /vol/gcc/src/hg/master/local/gcc/cobol/lexio.cc:33: /vol/gcc/src/hg/master/local/gcc/hwint.h:135:51: note: format string is defined here 135 | #define HOST_SIZE_T_PRINT_UNSIGNED "%" GCC_PRISZ "u" | ~~^ | | | unsigned int | %" GCC_PRISZ "lu On Darwin, size_t is always long unsigned int. However, unsigned int and long unsigned int are both 32-bit, so hwint.h selects %u for the format. As documented there, the arg needs to be cast to fmt_size_t to avoid the error. This isn't an issue on other 32-bit platforms like Solaris/i386 or Linux/i686 since they use unsigned int for size_t. /vol/gcc/src/hg/master/local/gcc/cobol/parse.y: In function 'int yyparse()': /vol/gcc/src/hg/master/local/gcc/cobol/parse.y:10215:36: error: format '%zu' expects argument of type 'size_t', but argument 4 has type 'int' [-Werror=format=] 10215 | error_msg(loc, "FUNCTION %qs has " |^~~ 10216 | "inconsistent parameter type %zu (%qs)", | ~~~ 10217 | keyword_str($1), p - args.data(), name_of(p->field) ); | ~~~ | | | int The arg (p - args.data())) is ptrdiff_t (int on 32-bit Darwin), while the %zu format expect size_t (long unsigned int). The patch therefore casts the ptrdiff_t arg to long and prints it as such. There are two more instances of the same problem: /vol/gcc/src/hg/master/local/gcc/cobol/util.cc: In member function 'void cbl_field_t::report_invalid_initial_value(const YYLTYPE&) const': /vol/gcc/src/hg/master/local/gcc/cobol/util.cc:905:80: error: format '%zu' expects argument of type 'size_t', but argument 6 has type 'int' [-Werror=format=] 905 | error_msg(loc, "%s cannot represent VALUE %qs exactly (max %c%zu)", | ~~^ | | | long unsigned int | %u 906 | name, data.initial, '.', pend - p); | | | | int In file included from /vol/gcc/src/hg/master/local/gcc/cobol/scan.l:48: /vol/gcc/src/hg/master/local/gcc/cobol/scan_ante.h: In function 'int numstr_of(const char*, radix_t)': /vol/gcc/src/hg/master/local/gcc/cobol/scan_ante.h:152:25: error: format '%zu' expects argument of type 'size_t', but argument 4 has type 'int' [-Werror=format=] 152 | error_msg(yylloc, "significand of %s has more than 36 digits (%zu)", input, nx); | ^ ~~ |
[gcc r15-10141] cobol: Normalize generating and using function_decls.
https://gcc.gnu.org/g:3f8dfda16b836e20eb898202943dee647232cace commit r15-10141-g3f8dfda16b836e20eb898202943dee647232cace Author: Robert Dubner Date: Sun Jun 29 10:54:36 2025 -0400 cobol: Normalize generating and using function_decls. Because COBOL doesn't require function prototypes, it is possible to, for example, CALL "getcwd" USING and then later CALL "getcwd" USING RETURNING The second call "knows" that the return value is a char*, but the first one does not. So, the first one gets a default return value type of SSIZE_t, which later needs to be replaced with CHAR_P. These [all too] extensive changes ensure that all references to a particular function use the same function_decl, and take measures to make sure that one function_decl is back-modified, if necessary, with the best return value type. gcc/cobol/ChangeLog: * Make-lang.in: Incorporate gcobol.clean. * except.cc (cbl_enabled_exceptions_t::dump): Update debug message. * genapi.cc (gg_attribute_bit_get): Formatting. (file_static_variable): Formatting. (trace1_init): Formatting. (build_main_that_calls_something): Normalize function_decl use. (parser_call_target): Likewise. (set_call_convention): Likewise. (parser_call_target_convention): Likewise. (parser_call_targets_dump): Likewise. (function_handle_from_name): Likewise. (function_pointer_from_name): Likewise. (parser_initialize_programs): Likewise. (parser_statement_begin): Formatting. (parser_leave_file): Use function_decl FIFO. (enter_program_common): Normalize function_decl use. (parser_enter_program): Normalize function_decl use. (tree_type_from_field_type): Normalize function_decl use. (is_valuable): Comment. (pe_stuff): Change name to program_end_stuff. (program_end_stuff): Likewise. (parser_exit): Likewise. (parser_division): Normalize function_decl use. (create_and_call): Normalize function_decl use. (parser_call): Normalize function_decl use. (parser_set_pointers): Normalize function_decl use. (parser_program_hierarchy): Normalize function_decl use. (psa_FldLiteralA): Defeat attempt to re-use literals. (Fails on some aarch64). (parser_symbol_add): Error message formatting. * genapi.h: Formatting. * gengen.cc (struct cbl_translation_unit_t): Add function_decl FIFO. (show_type): Rename to gg_show_type. (gg_show_type): Correct an error message. (gg_assign): Formatting; change error handling. (gg_modify_function_type): Normalize function_decl use. (gg_define_function_with_no_parameters): Fold into gg_defint_function(). (function_decl_key): Normalize function_decl use. (gg_peek_fn_decl): Normalize function_decl use. (gg_build_fn_decl): Normalize function_decl use. (gg_define_function): Normalize function_decl use. (gg_tack_on_function_parameters): Remove. (gg_finalize_function): Normalize function_decl use. (gg_leaving_the_source_code_file): Normalize function_decl use. (gg_call_expr_list): Normalize function_decl use. (gg_trans_unit_var_decl): Normalize function_decl use. (gg_insert_into_assemblerf): New function; formatting. * gengen.h (struct gg_function_t): Eliminate "is_truly_nested" flag. (gg_assign): Incorporate return value. (gg_define_function): Normalize function_decl use. (gg_define_function_with_no_parameters): Eliminate. (gg_build_fn_decl): Normalize function_decl use. (gg_peek_fn_decl): Normalize function_decl use. (gg_modify_function_type): Normalize function_decl use. (gg_call_expr_list): Normalize function_decl use. (gg_get_function_decl): Normalize function_decl use. (location_from_lineno): Prefix with "extern". (gg_open): Likewise. (gg_close): Likewise. (gg_get_indirect_reference): Likewise. (gg_insert_into_assembler): Likewise. (gg_insert_into_assemblerf): Likewise. (gg_show_type): New declaration. (gg_leaving_the_source_code_file): New declaration. * parse.y: Format debugging message. * parse_ante.h: Normalize function_decl use. (cherry picked from commit dd92d6acb416e138b21f00f34df54cb740e40e4c) Diff: --- gcc/cobol/Make-lang.in | 7 + gcc/cobol/except.cc| 4 +- gcc/cobol/genapi.cc| 431 +++ gcc/cobol/genapi.h | 2 +- gcc/cobol
[gcc r15-10142] cobol: Revise diagnostic linemap management.
https://gcc.gnu.org/g:d6115f773e868b94a5195b73ba249cf86b22deb2 commit r15-10142-gd6115f773e868b94a5195b73ba249cf86b22deb2 Author: James K. Lowden Date: Mon Jun 30 16:51:49 2025 -0400 cobol: Revise diagnostic linemap management. Update linemap filename before location in both parsers. Rely on parser to update linemap. Lexer maintains location. Various small syntax corrections and extensions. PR cobol/120772 PR cobol/120779 PR cobol/120790 PR cobol/120791 PR cobol/120794 gcc/cobol/ChangeLog: * gcobc: Supply -fPIC for shared objects. * genapi.cc (linemap_add): Delete empty macro. (parser_enter_file): Do not call linemap_add. (parser_leave_file): Same. * gengen.cc (location_from_lineno): Remove function. * lexio.cc (parse_replacing_term): Allow empty term. (cdftext::process_file): Always append to output. (cdftext::segment_line): Output #line directives. * lexio.h (struct span_t): Count lines in span. * parse.y: Revamp REPOSITORY, and minor syntax extensions. * parse_ante.h (input_file_status_notify): Update linemap filename before location. (intrinsic_token_of): Declare. (parser_move_carefully): Support MOVE pointer. * parse_util.h (intrinsic_token_of): New function. * scan.l: New EOF logic, accept NOT=, own yylloc and yylineno. * scan_ante.h (class enter_leave_t): Do not store newline count. (cdf_location_set): Remove declaration. (ydfltype_of): New function. (update_location): Accept location parameter. (reset_location): New function. (YY_USER_ACTION): Use update_location(). (YY_USER_INIT): Update CDF location. (verify_ws): New function. (wait_for_the_child): Removed. * symbols.h (cobol_fileline_set): return line number. * util.cc (valid_move): Use range-based for loop. (struct input_file_t): Remove line_map pointer. (class unique_stack): New peek() member function. (cobol_lineno_save): Rename to overload cobol_lineno(). (cobol_lineno): Replaces cobol_lineno_save(). (cobol_filename): Return void. (location_from_lineno): New function used by genapi.cc. (cdf_location_set): Remove. (matched_length): No change. (cobol_fileline_set): Return line number. (fisspace): Remove extra semicolon. (fisprint): Same. * util.h (cobol_filename_restore): Return void. (cobol_lineno_save): Remove declaration. (cobol_lineno): Declare. (cherry picked from commit 612c4c104ac0c2726d2de27f350040ad5f8d5776) Diff: --- gcc/cobol/gcobc| 7 +- gcc/cobol/genapi.cc| 9 -- gcc/cobol/gengen.cc| 8 - gcc/cobol/lexio.cc | 26 +++- gcc/cobol/lexio.h | 9 ++ gcc/cobol/parse.y | 109 ++ gcc/cobol/parse_ante.h | 11 +- gcc/cobol/parse_util.h | 9 ++ gcc/cobol/scan.l | 389 + gcc/cobol/scan_ante.h | 113 +++--- gcc/cobol/symbols.h| 2 +- gcc/cobol/util.cc | 83 ++- gcc/cobol/util.h | 5 +- 13 files changed, 439 insertions(+), 341 deletions(-) diff --git a/gcc/cobol/gcobc b/gcc/cobol/gcobc index 8c2245f5f82c..01c75dd191e4 100755 --- a/gcc/cobol/gcobc +++ b/gcc/cobol/gcobc @@ -35,6 +35,10 @@ ##output set the mode variable. Everything else is appended to the ##opts variable. ## +## - -fPIC is added to the command line if $mode is "-shared". That +##option applies only to "certain machines", per the gcc info +##manual. For this script to be portable across machines, -fPIC +##would have to be set more judiciously. if [ "$COBCPY" ] then @@ -478,12 +482,13 @@ do *) if [ -z "$output_name" ] # first non-option argument is source file name then - output_name=$(basename ${opt%.*}) + output_name=$(basename "${opt%.*}") case $mode in -c) output_name="$output_name".o ;; -shared) output_name="$output_name".so + opts="$opts -fPIC" ;; esac opts="$opts -o $output_name" diff --git a/gcc/cobol/genapi.cc b/gcc/cobol/genapi.cc index d73601cd9d07..80177886dbc6 100644 --- a/gcc/cobol/genapi.cc +++ b/gcc/cobol/genapi.cc @@ -3635,8 +3635,6 @@ parser_first_statement( int lineno ) } } -#define linemap_add(...) - void parser_enter_file(const char *filename) { @@ -3668,9 +3666,6 @@ parser_enter_file(const char *filename) } } - // Let the linemap routine know
[gcc r15-10136] cobol: Eliminate unguarded clock_gettime dependencies. [PR119975]
https://gcc.gnu.org/g:8df603ce1c0f69eb4ffe01d044096dbd082d406d commit r15-10136-g8df603ce1c0f69eb4ffe01d044096dbd082d406d Author: Robert Dubner Date: Wed Jun 11 15:49:41 2025 -0400 cobol: Eliminate unguarded clock_gettime dependencies. [PR119975] These changes are help make it possible to compile on MacOS. In addition to guarding clock_settime() calls, it removes the use of structures and constants needed for clock_settime(). libgcobol/ChangeLog: PR cobol/119975 * intrinsic.cc (__gg__current_date): Eliminate CLOCK_REALTIME. (__gg__seconds_past_midnight): Likewise. (__gg__formatted_current_date): Likewise. (__gg__random): Likewise. (__gg__random_next): Likewise. * libgcobol.cc: include . (__gg__abort): Eliminate CLOCK_REALTIME. (cobol_time): Likewise. (get_time_nanoseconds): Rename. (get_time_nanoseconds_local): Comment; Eliminate CLOCK_REALTIME. (__gg__clock_gettime): Likewise. (__gg__get_date_hhmmssff): Likewise. * libgcobol.h (__gg__clock_gettime): Eliminate clockid_t from declaration. (cherry picked from commit 582dda08eabc8f7dc9c504c0010d778bd6ff09b2) Diff: --- libgcobol/intrinsic.cc | 12 ++-- libgcobol/libgcobol.cc | 44 ++-- libgcobol/libgcobol.h | 2 +- 3 files changed, 37 insertions(+), 21 deletions(-) diff --git a/libgcobol/intrinsic.cc b/libgcobol/intrinsic.cc index 2d8d79c1c7c7..81ae638630f1 100644 --- a/libgcobol/intrinsic.cc +++ b/libgcobol/intrinsic.cc @@ -1219,7 +1219,7 @@ __gg__current_date(cblc_field_t *dest) { // FUNCTION CURRENT-DATE struct cbl_timespec tp = {}; - __gg__clock_gettime(CLOCK_REALTIME, &tp); // time_t tv_sec; long tv_nsec + __gg__clock_gettime(&tp); // time_t tv_sec; long tv_nsec char retval[DATE_STRING_BUFFER_SIZE]; timespec_to_string(retval, tp); @@ -1236,7 +1236,7 @@ __gg__seconds_past_midnight(cblc_field_t *dest) struct tm tm; __int128 retval=0; - __gg__clock_gettime(CLOCK_REALTIME, &tp); // time_t tv_sec; long tv_nsec + __gg__clock_gettime(&tp); // time_t tv_sec; long tv_nsec localtime_r(&tp.tv_sec, &tm); retval += tm.tm_hour; @@ -1460,7 +1460,7 @@ __gg__formatted_current_date( cblc_field_t *dest, // Destination string size_t input_offset, size_t input_size) { - // FUNCTION CURRENT-DATE + // FUNCTION FORMATTED-CURRENT-DATE // Establish the destination, and set it to spaces char *d= PTRCAST(char, dest->data); @@ -1485,7 +1485,7 @@ __gg__formatted_current_date( cblc_field_t *dest, // Destination string } struct cbl_timespec ts = {}; - __gg__clock_gettime(CLOCK_REALTIME, &ts); + __gg__clock_gettime(&ts); struct tm tm = {}; #ifdef HAVE_STRUCT_TM_TM_ZONE @@ -3433,7 +3433,7 @@ __gg__random( cblc_field_t *dest, state = (char *)malloc(state_len); struct cbl_timespec ts; -__gg__clock_gettime(CLOCK_REALTIME, &ts); +__gg__clock_gettime(&ts); initstate_r( ts.tv_nsec, state, state_len, buf); } int seed = (int)__gg__binary_value_from_qualified_field(&rdigits, @@ -3473,7 +3473,7 @@ __gg__random_next(cblc_field_t *dest) buf->state = NULL; state = (char *)malloc(state_len); struct cbl_timespec ts; -__gg__clock_gettime(CLOCK_REALTIME, &ts); +__gg__clock_gettime(&ts); initstate_r( ts.tv_nsec, state, state_len, buf); } random_r(buf, &retval_31); diff --git a/libgcobol/libgcobol.cc b/libgcobol/libgcobol.cc index f8697afd59cb..81b5b7af8121 100644 --- a/libgcobol/libgcobol.cc +++ b/libgcobol/libgcobol.cc @@ -69,6 +69,7 @@ #include #include #include +#include #include #include "exceptl.h" @@ -264,7 +265,7 @@ class ec_status_t { , operation(file_op_none) , mode(file_mode_none_e) , user_status(nullptr) -, filename(nullptr) +, filename(nullptr) {} explicit file_status_t( const cblc_file_t *file ) : ifile(file->symbol_table_index) @@ -558,7 +559,7 @@ __gg__abort(const char *msg) abort(); } -void +void __gg__mabort() { __gg__abort("Memory allocation error\n"); @@ -2290,7 +2291,7 @@ static time_t cobol_time() { struct cbl_timespec tp; - __gg__clock_gettime(CLOCK_REALTIME, &tp); + __gg__clock_gettime(&tp); return tp.tv_sec; } @@ -2402,12 +2403,28 @@ int_from_digits(const char * &p, int ndigits) return retval; } -uint64_t -get_time_nanoseconds() +// For testing purposes, this undef causes the use of gettimeofday(). +// #undef HAVE_CLOCK_GETTIME + +static uint64_t +get_time_nanoseconds_local() { // This code was unabashedly stolen from gcc/timevar.cc. // It returns the Unix epoch with nine decimal places. + /* No
[gcc r15-10145] cobol: Respect error in cobol.install-common.
https://gcc.gnu.org/g:2e508448cfad64aae20a259b6fa5a7e5fd0e2eb6 commit r15-10145-g2e508448cfad64aae20a259b6fa5a7e5fd0e2eb6 Author: James K. Lowden Date: Tue Jul 1 13:51:44 2025 -0400 cobol: Respect error in cobol.install-common. If GCOBOL_INSTALL_NAME fails to install, do not install GCOBC_INSTALL_NAME. gcc/cobol/ChangeLog: * Make-lang.in: Use && instead of semicolon between commands. (cherry picked from commit ffe49d47a8452cee7865c96bd58565b9c2153b0e) Diff: --- gcc/cobol/Make-lang.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/cobol/Make-lang.in b/gcc/cobol/Make-lang.in index 18eb3b0f1e54..e884212eb769 100644 --- a/gcc/cobol/Make-lang.in +++ b/gcc/cobol/Make-lang.in @@ -287,7 +287,7 @@ cobol.install-common: installdirs rm -f $(DESTDIR)$(bindir)/$(GCOBOL_TARGET_INSTALL_NAME)$(exeext); \ rm -f $(DESTDIR)$(bindir)/$(GCOBC_TARGET_INSTALL_NAME)$(exeext); \ ( cd $(DESTDIR)$(bindir) && \ - $(LN) $(GCOBOL_INSTALL_NAME)$(exeext) $(GCOBOL_TARGET_INSTALL_NAME)$(exeext) ); \ + $(LN) $(GCOBOL_INSTALL_NAME)$(exeext) $(GCOBOL_TARGET_INSTALL_NAME)$(exeext) && \ $(LN) $(GCOBC_INSTALL_NAME)$(exeext) $(GCOBC_TARGET_INSTALL_NAME)$(exeext) ); \ fi; \ fi
[gcc r15-10144] cobol: Repair printf format of size_t.
https://gcc.gnu.org/g:8536d47f4bbd98476778199728f54f4074ca90ed commit r15-10144-g8536d47f4bbd98476778199728f54f4074ca90ed Author: Robert Dubner Date: Tue Jul 1 12:02:21 2025 -0400 cobol: Repair printf format of size_t. gcc/cobol/ChangeLog: * parse.y: printf() of size_t is %zu, not %ld. (cherry picked from commit f471ed487ab36651d48c6c31fb28d36a42a30829) Diff: --- gcc/cobol/parse.y | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/cobol/parse.y b/gcc/cobol/parse.y index 57a41bbca718..74637c9641f5 100644 --- a/gcc/cobol/parse.y +++ b/gcc/cobol/parse.y @@ -12404,7 +12404,7 @@ numstr2i( const char input[], radix_t radix ) { return output; } if( erc == -1 ) { -yywarn("'%s' was accepted as %ld", input, integer); +yywarn("'%s' was accepted as %zu", input, integer); } return output; }
[gcc r15-10147] cobol: Add PUSH and POP to CDF.
https://gcc.gnu.org/g:d780100c63ffd3b96c4be218edc60627dba1fcc1 commit r15-10147-gd780100c63ffd3b96c4be218edc60627dba1fcc1 Author: James K. Lowden Date: Wed Jul 9 18:14:40 2025 -0400 cobol: Add PUSH and POP to CDF. Introduce cdf_directives_t class to centralize management of CDF state. Move existing CDF state variables and functions into the new class. gcc/cobol/ChangeLog: PR cobol/120765 * cdf.y: Extend grammar for new CDF syntax, relocate dictionary. * cdfval.h (cdf_dictionary): Use new CDF dictionary. * dts.h: Remove useless assignment, note incorrect behavior. * except.cc: Remove obsolete EC state. * gcobol.1: Document CDF in its own section. * genapi.cc (parser_statement_begin): Use new EC state function. (parser_file_merge): Same. (parser_check_fatal_exception): Same. * genutil.cc (get_and_check_refstart_and_reflen): Same. (get_depending_on_value_from_odo): Same. (get_data_offset): Same. (process_this_exception): Same. * lexio.cc (check_push_pop_directive): New function. (check_source_format_directive): Restrict regex search to 1 line. (cdftext::free_form_reference_format): Use new function. * parse.y: Define new CDF tokens, use new CDF state. * parse_ante.h (cdf_tokens): Use new CDF state. (redefined_token): Same. (class prog_descr_t): Remove obsolete CDF state. (class program_stack_t): Same. (current_call_convention): Same. * scan.l: Recognize new CDF tokens. * scan_post.h (is_cdf_token): Same. * symbols.h (cdf_current_tokens): Change current_call_convention to return void. * token_names.h: Regenerate. * udf/stored-char-length.cbl: Use new PUSH/POP CDF functionality. * util.cc (class cdf_directives_t): Define cdf_directives_t. (current_call_convention): Same. (cdf_current_tokens): Same. (cdf_dictionary): Same. (cdf_enabled_exceptions): Same. (cdf_push): Same. (cdf_push_call_convention): Same. (cdf_push_current_tokens): Same. (cdf_push_dictionary): Same. (cdf_push_enabled_exceptions): Same. (cdf_push_source_format): Same. (cdf_pop): Same. (cdf_pop_call_convention): Same. (cdf_pop_current_tokens): Same. (cdf_pop_dictionary): Same. (cdf_pop_enabled_exceptions): Same. (cdf_pop_source_format): Same. * util.h (cdf_push): Declare cdf_directives_t. (cdf_push_call_convention): Same. (cdf_push_current_tokens): Same. (cdf_push_dictionary): Same. (cdf_push_enabled_exceptions): Same. (cdf_push_source_format): Same. (cdf_pop): Same. (cdf_pop_call_convention): Same. (cdf_pop_current_tokens): Same. (cdf_pop_dictionary): Same. (cdf_pop_source_format): Same. (cdf_pop_enabled_exceptions): Same. libgcobol/ChangeLog: * common-defs.h (cdf_enabled_exceptions): Use new CDF state. (cherry picked from commit 3f59a1cac717f8af84e884e9ec0f6ef14e102e6e) Diff: --- gcc/cobol/cdf.y | 94 +- gcc/cobol/cdfval.h |4 + gcc/cobol/dts.h | 14 +- gcc/cobol/except.cc |2 - gcc/cobol/gcobol.1 | 192 +-- gcc/cobol/genapi.cc |6 +- gcc/cobol/genutil.cc |7 + gcc/cobol/lexio.cc | 72 +- gcc/cobol/parse.y| 21 +- gcc/cobol/parse_ante.h | 48 +- gcc/cobol/scan.l | 13 + gcc/cobol/scan_post.h|2 + gcc/cobol/symbols.h |3 +- gcc/cobol/token_names.h | 2228 +- gcc/cobol/udf/stored-char-length.cbl |4 + gcc/cobol/util.cc| 90 +- gcc/cobol/util.h | 15 + libgcobol/common-defs.h |2 +- 18 files changed, 1541 insertions(+), 1276 deletions(-) diff --git a/gcc/cobol/cdf.y b/gcc/cobol/cdf.y index f1a791245854..840eb5033151 100644 --- a/gcc/cobol/cdf.y +++ b/gcc/cobol/cdf.y @@ -105,14 +105,14 @@ void input_file_status_notify(); using std::map; - static map dictionary; - #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-function" static bool cdfval_add( const char name[], const cdfval_t& value, bool override = false ) { +cdf_values_t& dictionary( cdf_dictionary() ); + if( scanner_parsing() ) { if( ! override ) { if( dictionary.find(name) != dictionary.end() ) return fa
[gcc r15-10150] cobol: Eliminate cppcheck warnings in gcc/cobol .cc files.
https://gcc.gnu.org/g:f27c6d83f9dcb0189ba8a5fe7e0094160b797091 commit r15-10150-gf27c6d83f9dcb0189ba8a5fe7e0094160b797091 Author: Robert Dubner Date: Mon Jul 14 16:41:35 2025 -0400 cobol: Eliminate cppcheck warnings in gcc/cobol .cc files. These changes eliminate various cppcheck warnings, mostly involving C-Style casting and applying "const" to various variables and formal parameters. Some tab characters were eliminated, and some lines were trimmed to seventy-nine characters. gcc/cobol/ChangeLog: * cobol1.cc (cobol_langhook_handle_option): Eliminate cppcheck warnings. * dts.h: Likewise. * except.cc (cbl_enabled_exceptions_t::dump): Likewise. * gcobolspec.cc (lang_specific_driver): Likewise. * genapi.cc (parser_file_merge): Likewise. * gengen.cc (gg_unique_in_function): Likewise. (gg_declare_variable): Likewise. (gg_peek_fn_decl): Likewise. (gg_define_function): Likewise. * genmath.cc (set_up_on_exception_label): Likewise. (set_up_compute_error_label): Likewise. (arithmetic_operation): Likewise. (fast_divide): Likewise. * genutil.cc (get_and_check_refstart_and_reflen): Likewise. (get_depending_on_value_from_odo): Likewise. (get_data_offset): Likewise. (get_binary_value): Likewise. (process_this_exception): Likewise. (copy_little_endian_into_place): Likewise. (refer_is_clean): Likewise. (refer_fill_depends): Likewise. * genutil.h (process_this_exception): Likewise. (copy_little_endian_into_place): Likewise. (refer_is_clean): Likewise. * lexio.cc (check_push_pop_directive): Likewise. (check_source_format_directive): Likewise. (location_in): Likewise. (lexer_input): Likewise. (cdftext::lex_open): Likewise. (lexio_dialect_mf): Likewise. (valid_sequence_area): Likewise. (cdftext::free_form_reference_format): Likewise. (cdftext::segment_line): Likewise. * lexio.h (struct span_t): Likewise. * scan_ante.h (trim_location): Likewise. * symbols.cc (symbol_elem_cmp): Likewise. (symbol_alphabet): Likewise. (end_of_group): Likewise. (cbl_field_t::attr_str): Likewise. (symbols_update): Likewise. (symbol_typedef_add): Likewise. (symbol_field_add): Likewise. (new_temporary_impl): Likewise. (symbol_label_section_exists): Likewise. (symbol_program_callables): Likewise. (file_status_status_of): Likewise. * symfind.cc (is_data_field): Likewise. (finalize_symbol_map2): Likewise. (class in_scope): Likewise. (symbol_match2): Likewise. * util.cc (get_current_dir_name): Likewise. (gb4): Likewise. (class cdf_directives_t): Likewise. (cbl_field_t::report_invalid_initial_value): Likewise. (literal_subscript_oob): Likewise. (cbl_refer_t::str): Likewise. (date_time_fmt): Likewise. (class unique_stack): Likewise. (cobol_set_pp_option): Likewise. (cobol_filename): Likewise. (cobol_filename_restore): Likewise. (gcc_location_set_impl): Likewise. (ydferror): Likewise. (error_msg_direct): Likewise. (yyerror): Likewise. (cbl_unimplemented_at): Likewise. (cherry picked from commit c1be1d75126c8e946943b6dd94a3a0dea392888a) Diff: --- gcc/cobol/cobol1.cc | 8 +++-- gcc/cobol/dts.h | 2 +- gcc/cobol/except.cc | 2 +- gcc/cobol/gcobolspec.cc | 5 ++-- gcc/cobol/genapi.cc | 3 +- gcc/cobol/gengen.cc | 15 -- gcc/cobol/genmath.cc| 25 gcc/cobol/genutil.cc| 80 +++-- gcc/cobol/genutil.h | 6 ++-- gcc/cobol/lexio.cc | 31 ++- gcc/cobol/lexio.h | 4 +-- gcc/cobol/scan_ante.h | 3 +- gcc/cobol/symbols.cc| 50 ++- gcc/cobol/symfind.cc| 14 - gcc/cobol/util.cc | 79 +--- 15 files changed, 177 insertions(+), 150 deletions(-) diff --git a/gcc/cobol/cobol1.cc b/gcc/cobol/cobol1.cc index 4bd79f1f6057..3146da578998 100644 --- a/gcc/cobol/cobol1.cc +++ b/gcc/cobol/cobol1.cc @@ -357,7 +357,7 @@ cobol_langhook_handle_option (size_t scode, return true; case OPT_M: - cobol_set_pp_option('M'); +cobol_set_pp_option('M'); return true; case OPT_fstatic_call: @@ -368,16 +368,18 @@ cobol_langhook_handle_option (size_t scode, ws
[gcc r15-10122] cobol: Eliminate padding bytes from cbl_declarative_t. [PR119377]
https://gcc.gnu.org/g:d6da95bc4ce45e57ec47016275a2a9a12c8ef0ce commit r15-10122-gd6da95bc4ce45e57ec47016275a2a9a12c8ef0ce Author: Robert Dubner Date: Sun May 11 13:43:32 2025 -0400 cobol: Eliminate padding bytes from cbl_declarative_t. [PR119377] By changing the type of a variable in the cbl_declarative_t structure from "bool" to "uint32_t", three uninitialized padding bytes were turned into initialized bytes. This eliminates the valgrind error caused by those uninitialized values. This is an interim fix, which expediently eliminates the valgrind problem. The underlying design flaw, which involves turning a host-side C++ structure into a run-time data block, is slated for complete replacement in the next few weeks. libgcobol/ChangeLog: PR cobol/119377 * common-defs.h: (struct cbl_declaratives_t): Change "bool global" to "uint32_t global". (cherry picked from commit d7d24f9cc55d5cf0a70a984d4e63e8a307710d9e) Diff: --- libgcobol/common-defs.h | 16 +++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/libgcobol/common-defs.h b/libgcobol/common-defs.h index 026f377e74b2..e3471c5ccc3d 100644 --- a/libgcobol/common-defs.h +++ b/libgcobol/common-defs.h @@ -458,11 +458,25 @@ struct cbl_enabled_exception_t { struct cbl_declarative_t { enum { files_max = 16 }; size_t section; // implies program - bool global; + uint32_t global; // See the note below ec_type_t type; uint32_t nfile, files[files_max]; cbl_file_mode_t mode; +/* The ::global member originally was "bool global". A bool, however, occupies +only one byte of storage. The structure, in turn, is constructed on +four-byte boundaries for members, so there were three padding bytes between +the single byte of global and the ::type member. + +When used to create a "blob", where the structure was treated as a stream +of bytes that were used to create a constructor for an array of bytes, +valgrind noticed that those three padding bytes were not initialized, and +generated the appropriate error message. This made it hard to find other +problems. + +Changing the declaration from "bool" to "uint32_t" seems to have eliminated +the valgrind error without affecting overall performance. */ + cbl_declarative_t( cbl_file_mode_t mode = file_mode_none_e ) : section(0), global(false) , type(ec_none_e)
[gcc r15-10127] Regenerate cobol/lang.opt.urls
https://gcc.gnu.org/g:d33eb8356da0b419ca57185b0b746db7a5f43862 commit r15-10127-gd33eb8356da0b419ca57185b0b746db7a5f43862 Author: Mark Wielaard Date: Sun May 18 16:20:10 2025 +0200 Regenerate cobol/lang.opt.urls The Cobol frontend lang.opt got -M added, but lang.opt.urls wasn't regenerated. Fixes: 92b6485a75ca ("cobol: Eliminate exception "blob"; streamline some code generation.") gcc/cobol/ChangeLog: * lang.opt.urls: Regenerated. (cherry picked from commit f32946cc54a7de59498b42e3450ff124dffeb2d7) Diff: --- gcc/cobol/lang.opt.urls | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gcc/cobol/lang.opt.urls b/gcc/cobol/lang.opt.urls index 69f52973c025..78fc491fa67f 100644 --- a/gcc/cobol/lang.opt.urls +++ b/gcc/cobol/lang.opt.urls @@ -10,6 +10,9 @@ UrlSuffix(gcc/Preprocessor-Options.html#index-D-1) I UrlSuffix(gcc/Directory-Options.html#index-I) LangUrlSuffix_D(gdc/Directory-Options.html#index-I) +M +UrlSuffix(gcc/Preprocessor-Options.html#index-M) LangUrlSuffix_D(gdc/Code-Generation.html#index-M) + ffixed-form LangUrlSuffix_Fortran(gfortran/Fortran-Dialect-Options.html#index-ffixed-form)
[gcc r15-10143] cobol: Update test case for intrinsic function syntax.
https://gcc.gnu.org/g:1951807f10b7d5122c6f8c9817af7bd90682454a commit r15-10143-g1951807f10b7d5122c6f8c9817af7bd90682454a Author: Robert Dubner Date: Tue Jul 1 11:07:18 2025 -0400 cobol: Update test case for intrinsic function syntax. gcc/testsuite/ChangeLog: * cobol.dg/group2/Intrinsics_without_FUNCTION_keyword__2_.cob: Append INTRINSIC keyword. (cherry picked from commit 63f44b398f5938503cbd1e168bcc723697c9e9ad) Diff: --- .../cobol.dg/group2/Intrinsics_without_FUNCTION_keyword__2_.cob | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gcc/testsuite/cobol.dg/group2/Intrinsics_without_FUNCTION_keyword__2_.cob b/gcc/testsuite/cobol.dg/group2/Intrinsics_without_FUNCTION_keyword__2_.cob index b94adf580264..39a0c5b33da2 100644 --- a/gcc/testsuite/cobol.dg/group2/Intrinsics_without_FUNCTION_keyword__2_.cob +++ b/gcc/testsuite/cobol.dg/group2/Intrinsics_without_FUNCTION_keyword__2_.cob @@ -5,8 +5,8 @@ ENVIRONMENT DIVISION. CONFIGURATIONSECTION. REPOSITORY. - FUNCTION PI - FUNCTION E. + FUNCTION PI INTRINSIC + FUNCTION E INTRINSIC. DATA DIVISION. WORKING-STORAGE SECTION. 01 ZPIC 99V99.
[gcc r15-10134] cobol: Diagnostic messages, Flex build, and some cppcheck reports. [PR120328, PR119695]
https://gcc.gnu.org/g:cd1fd184020d319d117768f2de1500569b3b1e67 commit r15-10134-gcd1fd184020d319d117768f2de1500569b3b1e67 Author: Robert Dubner Date: Fri Jun 6 16:32:22 2025 -0400 cobol: Diagnostic messages, Flex build, and some cppcheck reports. [PR120328, PR119695] Remove %0x and similar from diagnostic framework messages. Remove %zu from printf messages because it is not supported on some platforms. Corrections in response to cppcheck. Sundry small fixes. gcc/cobol/ChangeLog: PR cobol/120328 * Make-lang.in: Success with non-English locale. PR cobol/119695 * cbldiag.h (cbl_unimplemented_at): Comment: * cdf-copy.cc (copybook_elem_t::open_file): Indentation. * cdf.y: YYABORT on certain errors. * cdfval.h (cdf_value): Const parameter. * copybook.h (class copybook_elem_t): Initialization. (class uppername_t): Explicit constructor. * except.cc (ec_type_descr): Remove %04s. (cbl_enabled_exceptions_t::dump): Remove %zu. * exceptg.h (class exception_turn_t): Explicit constructor. * genapi.cc (parser_perform_conditional): Remove %zu. (set_exception_environment): Formatting. (parser_statement_begin): Exception overhead. (parser_perform_conditional): Formatting: (parser_perform_conditional_end): Eliminate size_t. (parser_check_fatal_exception): Exception overhead. (parser_perform_conditional_end): Remove %zu. * inspect.h (struct cbx_inspect_match_t): Const reference. (struct cbx_inspect_t): Const parameter. * lexio.cc (cdftext::process_file): Remove %zu. * lexio.h (struct YYLTYPE): Remove unneeded struct. (YYLTYPE_IS_DECLARED): Likewise. (YYLTYPE_IS_TRIVIAL): Likewise. * parse.y: Comment; change DOT. * scan.l: Scan function names without swallowing whitespace. * scan_ante.h (scanner_parsing): Remove %zu. (scanner_parsing_pop): Remove %zu. (binary_integer_usage): Remove %zu. * scan_post.h (prelex): Correct post-CDF resumption. (yylex): Clearer message. * symbols.cc (symbol_table_extend): Explicit constructor. (elementize): Const parameter. (is_variable_length): Correct always-false. (symbols_update): Remove unnecessary shadow variable. (struct symbol_elem_t): Const parameter. (symbol_alphabet_add): Const parameter. (new_literal_add): Initialization. * symbols.h (class cbl_domain_elem_t): Correct assignment. (struct cbl_span_t): Improve constructor. (struct cbl_refer_t): Initialization. (struct cbl_alphabet_t): Rename shadow variable. (struct cbl_file_key_t): Remove unused constructor. (struct symbol_elem_t): Initialization. (struct cbl_until_addresses_t): Use unsigned int, for messages. (struct cbl_prog_hier_t): Initialization. (struct cbl_perform_tgt_t): Repair constructor. (struct cbl_label_t): Const parameter. (symbol_typedef_add): Const parameter. (symbol_field_add): Explicit constructor. (symbol_label_add): Explicit constructor. (symbol_program_add): Remove C-style "struct" use. (symbol_special_add): Remove C-style "struct" use. (symbol_alphabet_add): Const parameter. (symbol_file_add): Remove C-style "struct" use. (symbol_section_add): Remove C-style "struct" use. * symfind.cc: Const parameter. * util.cc (gb4): New function. * util.h (gb4): New function. * TODO: New file. libgcobol/ChangeLog: * common-defs.h (enum cbl_file_mode_t): Whitespace. (enum file_stmt_t): Likewise. (ec_cmp): Likewise. (struct cbl_declarative_t): Add "explicit" keyword. (class cbl_enabled_exceptions_t): Whitespace. * gfileio.cc: Remove cppcheck comment. * libgcobol.cc (class ec_status_t): Add "explicit" keyword. (match_declarative): Remove %zu. (default_exception_handler): Likwise. (__gg__check_fatal_exception): Exception overhead. (__gg__exception_push): Remove %zu. (__gg__exception_pop): Likewise. (cbl_enabled_exception_t::dump): Likewise. (__gg__match_exception): Exception overhead; remove %zu. (cbl_enabled_exceptions_t::dump): Remove %zu. (__gg__set_exception_environment): Likewise. Co-authored-by: James K. Lowden Co-authored-by: Robert Dubner (cherry picked from commit 37f5fdd008399c239e0689f2e864519505c78c7e) Diff: --- gcc/cobol/Make-lang.in | 3
[gcc r15-10151] cobol: Improved linemap and diagnostic handling; PIC validation. [PR120402]
https://gcc.gnu.org/g:84296ba2a410193f795456392ca96718af7166b6 commit r15-10151-g84296ba2a410193f795456392ca96718af7166b6 Author: Robert Dubner Date: Mon Jul 21 12:58:47 2025 -0400 cobol: Improved linemap and diagnostic handling; PIC validation. [PR120402] Implementation of PICTURE string validation for PR120402. Expanded some printf format attributes. Improved debugging and diagnostic messages. Improved linemap and line location tracking in support of diagnostic messages and location_t tagging of GENERIC nodes for improved GDB-COBOL performance. Assorted changes to eliminate cppcheck warnings. Co-Authored-By: James K. Lowden Co-Authored-By: Robert Dubner gcc/cobol/ChangeLog: PR cobol/120402 * Make-lang.in: Elminate commented-out scripting. * cbldiag.h (_CBLDIAG_H): Change #if 0 to #if GCOBOL_GETENV (warn_msg): Add printf attributes. (location_dump): Add debugging message. * cdf.y: Improved linemap tracking. * genapi.cc (treeplet_fill_source): const attribute for formal parameter. (insert_nop): Created to consolidate var_decl_nop writes. (build_main_that_calls_something): Move generation to the end of executable. (level_88_helper): Formatting. (parser_call_targets_dump): Formatting. (function_pointer_from_name): const attribute for formal parameter. (parser_initialize_programs): const attribute for formal parameter. (parser_statement_begin): Improved linemap handling. (section_label): Improved linemap handling. (paragraph_label): Improved linemap handling. (pseudo_return_pop): Improved linemap handling. (leave_procedure): Formatting. (parser_enter_section): Improved linemap handling. (parser_enter_paragraph): Improved linemap handling. (parser_perform): Formatting. (parser_leave_file): Move creation of main() to this routine. (parser_enter_program): Move creation of main from here to leave_file. (parser_accept): Formatting. const attribute for formal parameter. (parser_accept_command_line): const attribute for formal parameter. (parser_accept_command_line_count): const attribute for formal parameter. (parser_accept_envar): Likewise. (parser_set_envar): Likewise. (parser_display): Likewise. (get_exhibit_name): Implement EXHIBIT verb. (parser_exhibit): Likewise. (parser_sleep): const attribute for formal parameter. (parser_division): Improved linemap handling. (parser_classify): const attribute for formal parameter. (create_iline_address_pairs): Improved linemap handling. (parser_perform_start): Likewise. (perform_inline_until): Likewise. (perform_inline_testbefore_varying): Likewise. (parser_perform_until): Likewise. (parser_perform_inline_times): Likewise. (parser_intrinsic_subst): const attribute for formal parameter. (parser_file_merge): Formatting. (create_and_call): Improved linemap handling. (mh_identical): const attribute for formal parameter. (mh_numeric_display): const attribute for formal parameter. (mh_little_endian): Likewise. (mh_source_is_group): Likewise. (psa_FldLiteralA): Formatting. * genapi.h (parser_accept): const attribute for formal parameter. (parser_accept_envar): Likewise. (parser_set_envar): Likewise. (parser_accept_command_line): Likewise. (parser_accept_command_line_count): Likewise. (parser_add): Likewise. (parser_classify): Likewise. (parser_sleep): Likewise. (parser_exhibit): Likewise. (parser_display): Likewise. (parser_initialize_programs): Likewise. (parser_intrinsic_subst): Likewise. * gengen.cc (gg_assign): Improved linemap handling. (gg_add_field_to_structure): Likewise. (gg_define_from_declaration): Likewise. (gg_build_relational_expression): Likewise. (gg_goto_label_decl): Likewise. (gg_goto): Likewise. (gg_printf): Likewise. (gg_fprintf): Likewise. (gg_memset): Likewise. (gg_memchr): Likewise. (gg_memcpy): Likewise. (gg_memmove): Likewise. (gg_strcpy): Likewise. (gg_strcmp): Likewise. (gg_strncmp): Likewise. (gg_return): Likewise. (chain_parameter_to_function): Likewise. (gg_define_function): Likewise. (gg_get_function_decl): Likewise. (gg_call_expr): Lik
[gcc r15-10149] cobol: Minor changes to genapi.cc to eliminate CPPCHECK warnings.
https://gcc.gnu.org/g:7dc3a3720cdf1b467f9a8ed92d4cbb7cf657ef54 commit r15-10149-g7dc3a3720cdf1b467f9a8ed92d4cbb7cf657ef54 Author: Robert Dubner Date: Fri Jul 11 17:11:21 2025 -0400 cobol: Minor changes to genapi.cc to eliminate CPPCHECK warnings. Several hundred cppcheck warnings were eliminated. Most of these changes were replacing C-style casts, checking for NULL pointers, establishing some variables and formal parameters as const, and moving some variables around to tidy up their scopes. One memory leak was found and eliminated as a result of the cppcheck. gcc/cobol/ChangeLog: * Make-lang.in: Eliminate the .cc.o override. * genapi.cc (level_88_helper): Eliminate cppcheck warning. (get_level_88_domain): Likewise. (get_class_condition_string): Likewise. (parser_call_targets_dump): Likewise. (parser_compile_ecs): Likewise. (initialize_variable_internal): Likewise. (move_tree): Likewise. (combined_name): Likewise. (assembler_label): Likewise. (find_procedure): Likewise. (parser_perform): Likewise. (parser_perform_times): Likewise. (internal_perform_through): Likewise. (internal_perform_through_times): Likewise. (psa_FldLiteralN): Likewise. (psa_FldBlob): Likewise. (parser_accept): Likewise. (parser_accept_exception): Likewise. (parser_accept_exception_end): Likewise. (parser_accept_command_line): Likewise. (parser_accept_envar): Likewise. (parser_display_internal): Likewise. (parser_display): Likewise. (parser_assign): Likewise. (parser_initialize_table): Likewise. (parser_arith_error): Likewise. (parser_arith_error_end): Likewise. (parser_division): Likewise. (label_fetch): Likewise. (parser_label_label): Likewise. (parser_label_goto): Likewise. (parser_perform_start): Likewise. (parser_perform_conditional): Likewise. (parser_perform_conditional_end): Likewise. (parser_perform_until): Likewise. (parser_file_delete): Likewise. (parser_intrinsic_subst): Likewise. (create_lsearch_address_pairs): Likewise. (parser_bsearch_start): Likewise. (is_ascending_key): Likewise. (parser_sort): Likewise. (parser_file_sort): Likewise. (parser_return_start): Likewise. (parser_file_merge): Likewise. (parser_string_overflow): Likewise. (parser_unstring): Likewise. (parser_string): Likewise. (parser_call_exception): Likewise. (create_and_call): Likewise. (mh_identical): Likewise. (move_helper): Likewise. (binary_initial_from_float128): Likewise. (initial_from_initial): Likewise. (psa_FldLiteralA): Likewise. (parser_local_add): Likewise. (parser_symbol_add): Likewise. * genapi.h (parser_display): Likewise. * gengen.cc (gg_call_expr): Explict check for NULL_TREE. (gg_call): Likewise. * show_parse.h (SHOW_PARSE_LABEL_OK): Likewise. (TRACE1_FIELD_VALUE): Likewise. (CHECK_FIELD): Likewise. (CHECK_FIELD2): Likewise. (CHECK_LABEL): Likewise. * util.cc (cbl_internal_error): Apply [[noreturn]] attribute. * util.h (cbl_internal_error): Likewise. libgcobol/ChangeLog: * common-defs.h (PTRCAST): Moved here from libgcobol.h. * libgcobol.h (PTRCAST): Deleted. (cherry picked from commit 9b9753718e202073a3343d196a2eae13df80f408) Diff: --- gcc/cobol/Make-lang.in | 28 +--- gcc/cobol/genapi.cc | 433 +--- gcc/cobol/genapi.h | 4 +- gcc/cobol/gengen.cc | 4 +- gcc/cobol/show_parse.h | 49 +- gcc/cobol/util.cc | 2 + gcc/cobol/util.h| 2 +- libgcobol/common-defs.h | 8 + libgcobol/libgcobol.h | 7 - 9 files changed, 334 insertions(+), 203 deletions(-) diff --git a/gcc/cobol/Make-lang.in b/gcc/cobol/Make-lang.in index ee494b86f0cc..22de3b15bdea 100644 --- a/gcc/cobol/Make-lang.in +++ b/gcc/cobol/Make-lang.in @@ -385,22 +385,12 @@ selftest-cobol: lang_checks += check-cobol -# -# Front-end specific flags: Originally done for the COBOL front end, this -# scripting applies CXXFLAGS_FOR_COBOL only to compilations of source code in the -# gcc/cobol source code tree. Both forms can be used: -# -# CXXFLAGS_FOR_COBOL=xxx ../configure --enable-languages= -# and -# make CXXFLAGS_FOR_COBOL=yyy -# -# The second form overrides the first. -# -# To
[gcc r15-10140] cobol: Correct diagnostic strings for 32-bit builds.
https://gcc.gnu.org/g:9717324b7e867460f0e4023b12ad4a9d3633d889 commit r15-10140-g9717324b7e867460f0e4023b12ad4a9d3633d889 Author: James K. Lowden Date: Fri Jun 20 12:43:51 2025 -0400 cobol: Correct diagnostic strings for 32-bit builds. Avoid %z for printf-family. Cast pid_t to long. Avoid use of YYUNDEF for old Bison versions. PR cobol/120621 gcc/cobol/ChangeLog: * genapi.cc (parser_compile_ecs): Cast argument to unsigned long. (parser_compile_dcls): Same. (parser_division): RAII. (inspect_tally): Cast argument to unsigned long. * lexio.cc (cdftext::lex_open): Cast pid_t to long. * parse.y: hard-code values for old versions of Bison, and message format. * scan_ante.h (wait_for_the_child): Cast pid_t to long. (cherry picked from commit 007392c0f93cf46b9e87aebdd04e123e3381fc07) Diff: --- gcc/cobol/genapi.cc | 25 + gcc/cobol/lexio.cc| 6 +++--- gcc/cobol/parse.y | 8 gcc/cobol/scan_ante.h | 9 ++--- 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/gcc/cobol/genapi.cc b/gcc/cobol/genapi.cc index 0ea41f167afa..42f1599a87f6 100644 --- a/gcc/cobol/genapi.cc +++ b/gcc/cobol/genapi.cc @@ -957,8 +957,8 @@ parser_compile_ecs( const std::vector& ecs ) { SHOW_PARSE_HEADER char ach[64]; -snprintf(ach, sizeof(ach), " Size is %ld; retval is %p", - ecs.size(), as_voidp(retval)); +snprintf(ach, sizeof(ach), " Size is %lu; retval is %p", + gb4(ecs.size()), as_voidp(retval)); SHOW_PARSE_TEXT(ach) SHOW_PARSE_END } @@ -966,8 +966,8 @@ parser_compile_ecs( const std::vector& ecs ) { TRACE1_HEADER char ach[64]; -snprintf(ach, sizeof(ach), " Size is %ld; retval is %p", - ecs.size(), as_voidp(retval)); +snprintf(ach, sizeof(ach), " Size is %lu; retval is %p", + gb4(ecs.size()), as_voidp(retval)); TRACE1_TEXT_ABC("", ach, ""); TRACE1_END } @@ -1006,8 +1006,8 @@ parser_compile_dcls( const std::vector& dcls ) { SHOW_PARSE_HEADER char ach[64]; -snprintf(ach, sizeof(ach), " Size is %ld; retval is %p", - dcls.size(), as_voidp(retval)); +snprintf(ach, sizeof(ach), " Size is %lu; retval is %p", + gb4(dcls.size()), as_voidp(retval)); SHOW_PARSE_TEXT(ach); SHOW_PARSE_END } @@ -1015,8 +1015,8 @@ parser_compile_dcls( const std::vector& dcls ) { TRACE1_HEADER char ach[64]; -snprintf(ach, sizeof(ach), " Size is %ld; retval is %p", - dcls.size(), as_voidp(retval)); +snprintf(ach, sizeof(ach), " Size is %lu; retval is %p", + gb4(dcls.size()), as_voidp(retval)); TRACE1_TEXT_ABC("", ach, ""); TRACE1_END } @@ -6898,7 +6898,7 @@ parser_division(cbl_division_t division, // There are 'nusing' elements in the PROCEDURE DIVISION USING list. - tree parameter; + tree parameter = NULL_TREE; tree rt_i = gg_define_int(); for(size_t i=0; i(pid)); if( WIFSIGNALED(status) ) { - cbl_errx( "%s pid %d terminated by %s", - filter, kid, strsignal(WTERMSIG(status)) ); + cbl_errx( "%s pid %ld terminated by %s", +filter, static_cast(kid), strsignal(WTERMSIG(status)) ); } if( WIFEXITED(status) ) { if( (status = WEXITSTATUS(status)) != 0 ) { diff --git a/gcc/cobol/parse.y b/gcc/cobol/parse.y index 99295e8db3e3..f0faaa415776 100644 --- a/gcc/cobol/parse.y +++ b/gcc/cobol/parse.y @@ -11409,8 +11409,8 @@ keyword_str( int token ) { switch( token ) { case YYEOF: return "YYEOF"; case YYEMPTY: return "YYEMPTY"; - case YYerror: return "YYerror"; - case YYUNDEF: return "invalid token"; + case 256: return "YYerror"; + case 257: return "invalid token"; // YYUNDEF } if( token < 256 ) { @@ -12359,7 +12359,7 @@ numstr2i( const char input[], radix_t radix ) { return output; } if( erc == -1 ) { -yywarn("'%s' was accepted as %wd", input, integer); +yywarn("'%s' was accepted as %zu", input, integer); } return output; } @@ -13141,7 +13141,7 @@ literal_subscripts_valid( YYLTYPE loc, const cbl_refer_t& name ) { // X(0): subscript 1 of for out of range for 02 X OCCURS 4 to 6 error_msg(loc, "%s(%s): subscript %zu out of range " - "for %s %s OCCURS %lu%s", + "for %s %s OCCURS %zu%s", oob->name, subscript_names.c_str(), 1 + isub, oob->level_str(), oob->name, oob->occurs.bounds.lower, upper_phrase ); diff --git a/gcc/cobol/scan_ante.h b/gcc/cobol/scan_ante.h index 037c929aff33..96b688e75128 100644 --- a/gcc/cobol/scan_ante.h +++ b/gcc/cobol/scan_ante.h @@ -824,17 +824,20 @@ wait_for_the_child(void) { } if( WIFSIGNALED(status) ) { -yywarn( "process %d terminated by %s", pid, strsignal(WTERMS
[gcc r15-10131] cobol: Honor HAVE_CLOCK_GETTIME and HAVE_GETTIMEOFDAY. [PR119975]
https://gcc.gnu.org/g:c48cce8872c3b66f28727b8dee8349ec72e1f234 commit r15-10131-gc48cce8872c3b66f28727b8dee8349ec72e1f234 Author: Robert Dubner Date: Mon Jun 2 15:55:20 2025 -0400 cobol: Honor HAVE_CLOCK_GETTIME and HAVE_GETTIMEOFDAY. [PR119975] These changes cause genapi.cc to use whichever of clock_gettime() or gettimeofday() are available. This prevents compilation errors on systems where clock_gettime() is not available. gcc/cobol/ChangeLog: PR cobol/119975 * genapi.cc (parser_intrinsic_call_0): Use get_time_64() function. * genutil.cc (get_time_64): Definition created. * genutil.h (get_time_64): Declaration created. (cherry picked from commit 8fc9e03a70fd08b54449b05833b00e7f8ad01c25) Diff: --- gcc/cobol/genapi.cc | 4 +++- gcc/cobol/genutil.cc | 23 +++ gcc/cobol/genutil.h | 3 +++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/gcc/cobol/genapi.cc b/gcc/cobol/genapi.cc index 2ce9cad5c0d6..5e983ab503c2 100644 --- a/gcc/cobol/genapi.cc +++ b/gcc/cobol/genapi.cc @@ -10491,7 +10491,9 @@ parser_intrinsic_call_0(cbl_field_t *tgt, { // Pass __gg__when_compiled() the time from right now. struct timespec tp; -clock_gettime(CLOCK_REALTIME, &tp); // time_t tv_sec; long tv_nsec +uint64_t now = get_time_64(); +tp.tv_sec = now / 10; +tp.tv_nsec = now % 10; store_location_stuff(function_name); gg_call(VOID, diff --git a/gcc/cobol/genutil.cc b/gcc/cobol/genutil.cc index d0aaf2b3215f..e971043164c7 100644 --- a/gcc/cobol/genutil.cc +++ b/gcc/cobol/genutil.cc @@ -2119,3 +2119,26 @@ qualified_data_location(cbl_refer_t &refer) return gg_add(member(refer.field->var_decl_node, "data"), refer_offset(refer)); } + +uint64_t +get_time_64() +{ + // This code was unabashedly stolen from gcc/timevar.cc. + // It returns the Unix epoch with nine decimal places. + + uint64_t retval = 0; + +#ifdef HAVE_CLOCK_GETTIME + struct timespec ts; + clock_gettime (CLOCK_REALTIME, &ts); + retval = ts.tv_sec * 10 + ts.tv_nsec; + return retval; +#endif +#ifdef HAVE_GETTIMEOFDAY + struct timeval tv; + gettimeofday (&tv, NULL); + retval = tv.tv_sec * 10 + tv.tv_usec * 1000; + return retval; +#endif + return retval; +} \ No newline at end of file diff --git a/gcc/cobol/genutil.h b/gcc/cobol/genutil.h index 2f4bc36eace7..43102d7cc544 100644 --- a/gcc/cobol/genutil.h +++ b/gcc/cobol/genutil.h @@ -155,4 +155,7 @@ void build_array_of_fourplets( int ngroup, size_t N, cbl_refer_t *refers); void get_depending_on_value_from_odo(tree retval, cbl_field_t *odo); +uint64_t get_time_64(); + + #endif
[gcc r15-10152] cobol: Tweak adjustments to location_t of GENERIC nodes for PERFORM.
https://gcc.gnu.org/g:0879a2a840c9209b3bf54e2dc40355c263f28924 commit r15-10152-g0879a2a840c9209b3bf54e2dc40355c263f28924 Author: Robert Dubner Date: Wed Jul 23 08:44:54 2025 -0400 cobol: Tweak adjustments to location_t of GENERIC nodes for PERFORM. COBOL has a group of PERFORM statements that require careful adjustments to the location_t elements of the GENERIC nodes so that the COBOL-aware version of GDB behaves properly. These changes are in service of that goal. gcc/cobol/ChangeLog: * genapi.cc (leave_procedure): Adjust location_t for PERFORM. (parser_perform_times): Likewise. (internal_perform_through_times): Likewise. (perform_outofline_before_until): Likewise. (perform_outofline_after_until): Likewise. (perform_outofline_testafter_varying): Likewise. (perform_outofline_before_varying): Likewise. (cherry picked from commit 3cc2116fe6694b0e52855427fc1fd1335c6d00b6) Diff: --- gcc/cobol/genapi.cc | 7 +++ 1 file changed, 7 insertions(+) diff --git a/gcc/cobol/genapi.cc b/gcc/cobol/genapi.cc index 52e75e583556..666802ea137e 100644 --- a/gcc/cobol/genapi.cc +++ b/gcc/cobol/genapi.cc @@ -2858,6 +2858,7 @@ leave_procedure(struct cbl_proc_t *procedure, bool /*section*/) char *psz; psz = xasprintf("_procret." HOST_SIZE_T_PRINT_DEC ":", (fmt_size_t)symbol_label_id(procedure->label)); +token_location_override(current_location_minus_one()); gg_insert_into_assembler(psz); free(psz); pseudo_return_pop(procedure); @@ -3445,6 +3446,7 @@ parser_perform_times( cbl_label_t *proc_1, cbl_refer_t count ) sprintf(ach, "_procretb." HOST_SIZE_T_PRINT_DEC ":", (fmt_size_t)our_pseudo_label); + token_location_override(current_location_minus_one()); gg_insert_into_assembler(ach); } @@ -3598,6 +3600,7 @@ internal_perform_through_times( cbl_label_t *proc_1, sprintf(ach, "_procretb." HOST_SIZE_T_PRINT_DEC ":", (fmt_size_t)our_pseudo_label); + token_location_override(current_location_minus_one()); gg_insert_into_assembler( ach ); } @@ -8440,6 +8443,7 @@ perform_outofline_before_until(struct cbl_perform_tgt_t *tgt, sprintf(ach, "_procretb." HOST_SIZE_T_PRINT_DEC ":", (fmt_size_t)our_pseudo_label); + token_location_override(current_location_minus_one()); gg_insert_into_assembler( ach ); } @@ -8503,6 +8507,7 @@ perform_outofline_after_until(struct cbl_perform_tgt_t *tgt, sprintf(ach, "_procretb." HOST_SIZE_T_PRINT_DEC ":", (fmt_size_t)our_pseudo_label); + token_location_override(current_location_minus_one()); gg_insert_into_assembler( ach ); } @@ -8623,6 +8628,7 @@ perform_outofline_testafter_varying(struct cbl_perform_tgt_t *tgt, sprintf(ach, "_procretb." HOST_SIZE_T_PRINT_DEC ":", (fmt_size_t)our_pseudo_label); + token_location_override(current_location_minus_one()); gg_insert_into_assembler( ach ); } @@ -8766,6 +8772,7 @@ perform_outofline_before_varying( struct cbl_perform_tgt_t *tgt, sprintf(ach, "_procretb." HOST_SIZE_T_PRINT_DEC ":", (fmt_size_t)our_pseudo_label); + token_location_override(current_location_minus_one()); gg_insert_into_assembler( ach ); }
[gcc r15-10138] cobol: Correct diagnostic strings to rectify bootstrap build
https://gcc.gnu.org/g:efc75cbe390a83dbf7bfe9d90dd16dfc030cead4 commit r15-10138-gefc75cbe390a83dbf7bfe9d90dd16dfc030cead4 Author: James K. Lowden Date: Tue Jun 17 18:31:33 2025 -0400 cobol: Correct diagnostic strings to rectify bootstrap build Apply patch from Jakub to enable diagnostics. Use %<%> and %qs liberally. PR cobol/120621 gcc/cobol/ChangeLog: * cbldiag.h (yyerror): Add diagnostic attributes. (yywarn): Same. (error_msg): Same. (yyerrorvl): Same. (cbl_unimplementedw): Same. (cbl_unimplemented): Same. (cbl_unimplemented_at): Same. * cdf-copy.cc (copybook_elem_t::open_file): Supply string argument. * cdf.y: Use %<%>. * cobol-system.h (if): Check GCC_VERSION. (ATTRIBUTE_GCOBOL_DIAG): Define. * except.cc (cbl_enabled_exception_t::dump): Remove extra %s. * genapi.cc (get_class_condition_string): Use acceptable message. (get_bytes_needed): Same. (move_tree): Same. (get_string_from): Same. (internal_perform_through): Same. (tree_type_from_field_type): Same. (is_valuable): Same. (parser_logop): Same. (parser_relop): Same. (parser_relop_long): Same. (parser_if): Same. (parser_setop): Same. (parser_perform_conditional): Same. (parser_file_add): Same. (parser_file_open): Same. (parser_file_close): Same. (parser_file_read): Same. (parser_file_write): Same. (inspect_replacing): Same. (parser_sort): Same. (parser_file_sort): Same. (parser_file_merge): Same. (create_and_call): Same. (parser_bitop): Same. (parser_bitwise_op): Same. (hijack_for_development): Same. (mh_source_is_literalN): Same. (mh_dest_is_float): Same. (parser_symbol_add): Same. * gengen.cc (show_type): Use acceptable message. (gg_find_field_in_struct): Same. (gg_declare_variable): Same. (gg_printf): Same. (gg_fprintf): Same. (gg_tack_on_function_parameters): Same. (gg_define_function): Same. (gg_get_function_decl): Same. (gg_finalize_function): Same. (gg_call_expr): Same. (gg_call): Same. (gg_insert_into_assembler): Define new function. (gg_insert_into_assemblerf): Use gg_insert_into_assembler(). * gengen.h (gg_insert_into_assembler): Simpler function declaration. (gg_insert_into_assemblerf): Declare new function. * genmath.cc (parser_op): Use acceptable message. * genutil.cc (get_binary_value): Use acceptable message. * lexio.cc (parse_replacing_pair): Correct diagnostic arguments. (preprocess_filter_add): Same. (cdftext::open_input): Same. * parse.y: Use acceptable messages. * parse_ante.h (struct evaluate_elem_t): Use %<%>. (is_callable): Same. * parse_util.h (intrinsic_invalid_parameter): Use %qs. * scan.l: Use dialect_error(). * scan_ante.h (numstr_of): Use %qs. (scanner_token): Quote COBOL tokens in messages. (scanner_parsing): Correct diagnostic message. (scanner_parsing_toggle): Quote COBOL tokens in messages. (scanner_parsing_pop): Same. (typed_name): Use %qs. * scan_post.h (prelex): Quote COBOL tokens in message. * show_parse.h (CHECK_FIELD): Use acceptable message format. (CHECK_LABEL): Same. * symbols.cc (symbol_field_same_as): Remove extra spaces. (cbl_alphabet_t::assign): Use %<%>. (cbl_field_t::internalize): Quote library name in message. * symbols.h (struct os_locale_t): Constify codeset. (class temporaries_t): Add copy constructor. (struct cbl_alphabet_t): Use acceptable message. * util.cc (symbol_type_str): Use cbl_internal_error. (cbl_field_type_str): Same. (is_elementary): Same. (cbl_field_t::report_invalid_initial_value): Use %qs. (class unique_stack): Avoid %m. (ydferror): Declare function with attributes. (error_msg): Same. (cobol_fileline_set): Use %<%>. (os_locale_t): Remove use of xstrdup. (cobol_parse_files): Quote C names in message. (dialect_error): Use %<%>. * util.h (cbl_message): Add attributes. (cbl_internal_error): Same. (cbl_err): Same. (cbl_errx): Same. (cherry picked from commit 14b8f077e4409ca0d188f0ed55891a18ba2ecd7d) Di
[gcc r15-10133] cobol: Guard clock_gettime(). [PR119975]
https://gcc.gnu.org/g:6c214d4e458afd628c6e511df8a6cc1e5f4ab776 commit r15-10133-g6c214d4e458afd628c6e511df8a6cc1e5f4ab776 Author: Robert Dubner Date: Thu Jun 5 10:53:02 2025 -0400 cobol: Guard clock_gettime(). [PR119975] This attempts to eliminate "'clock_gettime' not declared..." when building on x86_64-apple-darwin15.6.0. Calls to clock_gettime have been reduced to two locations. Both have been guarded with gcc/cobol/ChangeLog: PR cobol/119975 * genapi.cc (parser_intrinsic_call_0): Use get_time_nanoseconds(). * genutil.cc (get_time_64): Rename to get_time_nanoseconds(). (get_time_nanoseconds): Likewise. * genutil.h (get_time_64): Likewise. (get_time_nanoseconds): Likewise. * util.cc (class cbl_timespec): Timing routine uses get_time_nanoseconds(). (operator-): Likewise. (parse_file): Likewise. libgcobol/ChangeLog: PR cobol/119975 * configure.ac: AC_CHECK_LIB(rt, clock_gettime). * config.h.in: Likewise. * configure: Likewise. * gfileio.cc: Remove in-line cppcheck-suppress. * intrinsic.cc (timespec_to_string): Use guarded clock_gettime(). (__gg__current_date): Likewise. (__gg__seconds_past_midnight): Likewise. (__gg__formatted_current_date): Likewise. (__gg__random): Likewise. (__gg__random_next): Likewise. (__gg__when_compiled): Likewise. * libgcobol.cc (cobol_time): Likewise. (get_time_nanoseconds): Likewise. (__gg__clock_gettime): Likewise. (__gg__get_date_hhmmssff): Likewise. * libgcobol.h (__gg__clock_gettime): Likewise. (struct cbl_timespec): Likewise. (cherry picked from commit 2e334900f4ddcd804e3b324402544a572d306ab6) Diff: --- gcc/cobol/genapi.cc| 2 +- gcc/cobol/genutil.cc | 2 +- gcc/cobol/genutil.h| 2 +- gcc/cobol/util.cc | 19 +- libgcobol/config.h.in | 3 +++ libgcobol/configure| 53 ++ libgcobol/configure.ac | 11 +++ libgcobol/gfileio.cc | 2 -- libgcobol/intrinsic.cc | 14 ++--- libgcobol/libgcobol.cc | 34 libgcobol/libgcobol.h | 10 +- 11 files changed, 130 insertions(+), 22 deletions(-) diff --git a/gcc/cobol/genapi.cc b/gcc/cobol/genapi.cc index 5e983ab503c2..bde8151ece79 100644 --- a/gcc/cobol/genapi.cc +++ b/gcc/cobol/genapi.cc @@ -10491,7 +10491,7 @@ parser_intrinsic_call_0(cbl_field_t *tgt, { // Pass __gg__when_compiled() the time from right now. struct timespec tp; -uint64_t now = get_time_64(); +uint64_t now = get_time_nanoseconds(); tp.tv_sec = now / 10; tp.tv_nsec = now % 10; diff --git a/gcc/cobol/genutil.cc b/gcc/cobol/genutil.cc index e971043164c7..f1098f02768e 100644 --- a/gcc/cobol/genutil.cc +++ b/gcc/cobol/genutil.cc @@ -2121,7 +2121,7 @@ qualified_data_location(cbl_refer_t &refer) } uint64_t -get_time_64() +get_time_nanoseconds() { // This code was unabashedly stolen from gcc/timevar.cc. // It returns the Unix epoch with nine decimal places. diff --git a/gcc/cobol/genutil.h b/gcc/cobol/genutil.h index 43102d7cc544..fb582e5a493f 100644 --- a/gcc/cobol/genutil.h +++ b/gcc/cobol/genutil.h @@ -155,7 +155,7 @@ void build_array_of_fourplets( int ngroup, size_t N, cbl_refer_t *refers); void get_depending_on_value_from_odo(tree retval, cbl_field_t *odo); -uint64_t get_time_64(); +uint64_t get_time_nanoseconds(); #endif diff --git a/gcc/cobol/util.cc b/gcc/cobol/util.cc index 75a0b26c0a91..e92f069bee1b 100644 --- a/gcc/cobol/util.cc +++ b/gcc/cobol/util.cc @@ -65,6 +65,7 @@ #include "inspect.h" #include "../../libgcobol/io.h" #include "genapi.h" +#include "genutil.h" #pragma GCC diagnostic ignored "-Wunused-result" #pragma GCC diagnostic ignored "-Wmissing-field-initializers" @@ -2141,22 +2142,25 @@ cobol_fileline_set( const char line[] ) { return file.name; } +//#define TIMING_PARSE +#ifdef TIMING_PARSE class cbl_timespec { - struct timespec now; + uint64_t now; // Nanoseconds public: cbl_timespec() { -clock_gettime(CLOCK_MONOTONIC, &now); +now = get_time_nanoseconds(); } double ns() const { -return now.tv_sec * 10 + now.tv_nsec; +return now; } friend double operator-( const cbl_timespec& now, const cbl_timespec& then ); }; double -operator-( const cbl_timespec& then, const cbl_timespec& now ) { +operator-( const cbl_timespec& now, const cbl_timespec& then ) { return (now.ns() - then.ns()) / 10; } +#endif static int parse_file( const char filename[] ) @@ -2172,15 +2176,20 @@ parse_file( const char filenam
[gcc r15-10153] cobol: Honor the "-static" command-line option. [PR119231]
https://gcc.gnu.org/g:4e568451bface5d15fc0bb28bc6794612f32677c commit r15-10153-g4e568451bface5d15fc0bb28bc6794612f32677c Author: Robert Dubner Date: Thu Jul 24 12:09:36 2025 -0400 cobol: Honor the "-static" command-line option. [PR119231] gcc/cobol/ChangeLog: PR cobol/119231 * gcobolspec.cc: (lang_specific_driver): Pass OPT_static through. Handle -static and -static-libgcobol properly. gcc/testsuite/ChangeLog: * cobol.dg/group2/_-static__compilation.cob: Modify for -static warning. * cobol.dg/group2/_-static__compilation.out: Removed. (cherry picked from commit 44e32178031e89399710c3ee7444891631a9c8ec) Diff: --- gcc/cobol/gcobolspec.cc | 13 +++-- gcc/testsuite/cobol.dg/group2/_-static__compilation.cob | 4 ++-- gcc/testsuite/cobol.dg/group2/_-static__compilation.out | 2 -- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/gcc/cobol/gcobolspec.cc b/gcc/cobol/gcobolspec.cc index 9532d4256b22..2f3092da5d85 100644 --- a/gcc/cobol/gcobolspec.cc +++ b/gcc/cobol/gcobolspec.cc @@ -478,7 +478,10 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, break; #endif case OPT_static: +#if defined (HAVE_LD_STATIC_DYNAMIC) +append_arg(decoded_options[i]); static_in_general = true; +#endif break; default: @@ -506,17 +509,23 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, need_libgcobol = false; } + if( static_in_general ) +{ +// These two options interfere with each other. +static_libgcobol = false; +} + if( need_libgcobol ) { add_arg_lib(COBOL_LIBRARY, static_libgcobol); } if( need_libdl ) { -add_arg_lib(DL_LIBRARY, static_in_general); +add_arg_lib(DL_LIBRARY, false); } if( need_libstdc ) { -add_arg_lib(STDCPP_LIBRARY, static_in_general); +add_arg_lib(STDCPP_LIBRARY, false); } if( prior_main ) diff --git a/gcc/testsuite/cobol.dg/group2/_-static__compilation.cob b/gcc/testsuite/cobol.dg/group2/_-static__compilation.cob index 7843d3d27aac..f344a84c3988 100644 --- a/gcc/testsuite/cobol.dg/group2/_-static__compilation.cob +++ b/gcc/testsuite/cobol.dg/group2/_-static__compilation.cob @@ -1,7 +1,7 @@ *> { dg-do run } *> { dg-options "-static" } - *> { dg-output-file "group2/_-static__compilation.out" } - + *> { dg-prune-output {warning} } + *> { dg-output {hello, world} } IDENTIFICATION DIVISION. PROGRAM-ID. prog. PROCEDURE DIVISION. diff --git a/gcc/testsuite/cobol.dg/group2/_-static__compilation.out b/gcc/testsuite/cobol.dg/group2/_-static__compilation.out deleted file mode 100644 index ae0e5111caef.. --- a/gcc/testsuite/cobol.dg/group2/_-static__compilation.out +++ /dev/null @@ -1,2 +0,0 @@ -hello, world -
[gcc r15-10135] cobol: Variety of small changes in answer to cppcheck diagnostics.
https://gcc.gnu.org/g:f79a7d0f7b3f79c8e234ca870c0abf5b3101368e commit r15-10135-gf79a7d0f7b3f79c8e234ca870c0abf5b3101368e Author: James K. Lowden Date: Tue Jun 10 10:34:28 2025 -0400 cobol: Variety of small changes in answer to cppcheck diagnostics. Remove non-ASCII input and blank lines from gcobol.1. Restrict cobol.clean target to compiler object files. gcc/cobol/ChangeLog: * Make-lang.in: cobol.clean does not remove libgcobol files. * cdf.y: Suppress 1 cppcheck false positive. * cdfval.h (scanner_parsing): Partial via cppcheck for PR119324. * gcobol.1: Fix groff errors. * gcobolspec.cc (append_arg): Const parameter. * parse_ante.h (intrinsic_call_2): Avoid NULL dereference. (cherry picked from commit 70c3dd9a81cdefcaf24a66ec0c1ceddf5d3984dd) Diff: --- gcc/cobol/Make-lang.in | 3 +-- gcc/cobol/cdf.y | 1 + gcc/cobol/cdfval.h | 8 gcc/cobol/gcobol.1 | 12 +--- gcc/cobol/gcobolspec.cc | 2 +- gcc/cobol/parse_ante.h | 2 +- 6 files changed, 17 insertions(+), 11 deletions(-) diff --git a/gcc/cobol/Make-lang.in b/gcc/cobol/Make-lang.in index 993e4c6ffb02..5f293e1f9874 100644 --- a/gcc/cobol/Make-lang.in +++ b/gcc/cobol/Make-lang.in @@ -351,8 +351,7 @@ cobol.srcman: cobol.mostlyclean: cobol.clean: - rm -fr gcobol cobol1 cobol/*\ - ../*/libgcobol/* + rm -fr gcobol cobol1 cobol/* cobol.distclean: diff --git a/gcc/cobol/cdf.y b/gcc/cobol/cdf.y index 0440d0216af9..e4d2feaaf52e 100644 --- a/gcc/cobol/cdf.y +++ b/gcc/cobol/cdf.y @@ -891,6 +891,7 @@ verify_integer( const YDFLTYPE& loc, const cdfval_base_t& val ) { return true; } +// cppcheck-suppress returnTempReference const cdfval_base_t& cdfval_base_t::operator()( const YDFLTYPE& loc ) { static cdfval_t zero(0); diff --git a/gcc/cobol/cdfval.h b/gcc/cobol/cdfval.h index 09c21ab08e50..c4387b080661 100644 --- a/gcc/cobol/cdfval.h +++ b/gcc/cobol/cdfval.h @@ -38,6 +38,14 @@ bool scanner_parsing(); +/* cdfval_base_t has no constructor because otherwise: + * cobol/cdf.h:172:7: note: ‘YDFSTYPE::YDFSTYPE()’ is implicitly deleted + * because the default definition would be ill-formed: + * 172 | union YDFSTYPE + * + * We use the derived type cdfval_t, which can be properly constructed and + * operated on, but tell Bison only about its POD base class. + */ struct YDFLTYPE; struct cdfval_base_t { bool off; diff --git a/gcc/cobol/gcobol.1 b/gcc/cobol/gcobol.1 index 0ce890e97229..6db54009fcf7 100644 --- a/gcc/cobol/gcobol.1 +++ b/gcc/cobol/gcobol.1 @@ -39,7 +39,7 @@ compiles \*[lang] source code to object code, and optionally produces an executable binary or shared object. As a GCC component, it accepts all options that affect code-generation and linking. Options specific to \*[lang] are listed below. -.Bl -tag -width \0\0debug +.Bl -tag -width "\0\0debug" .It Fl main Ar filename .Nm will generate a @@ -197,14 +197,12 @@ Otherwise, columns 1-6 are examined. If those characters are all digits or blanks, the file is assumed to be in .Em "fixed-form reference format", also with the indicator in column 7. - If not auto-detected as .Em "fixed-form reference format" or .Em "extended source format", the file is assumed to be in .Em "free-form reference format". - .Pp . .It Fl fcobol-exceptions Ar exception Op Ns , Ns Ar exception Ns ... @@ -1088,7 +1086,7 @@ the directive must appear before .Pp To test a feature-set variable, use .Dl >>IF Ar feature Li DEFINED -.. +. .Ss Copybooks .Nm supports the CDF @@ -1294,7 +1292,7 @@ stores and converts numbers. Converting the floating-point value to the numeric display value 0055110 is done by multiplying 55.10...\& by 1,000 and then truncating the result to an integer. And it turns out that even -though 55.11 can’t be represented in floating-point as an exact value, +though 55.11 can't be represented in floating-point as an exact value, the product of the multiplication, 55110, is an exact value. .Pp In cases where it is important for conversions to have predictable @@ -1325,7 +1323,7 @@ specified for a calculation, then the intermediate result becomes a . .Ss A warning about binary floating point comparison The cardinal rule when doing comparisons involving floating-point -values: Never, ever, test for equality. It’s just not worth the hassle. +values: Never, ever, test for equality. It's just not worth the hassle. .Pp For example: .Bd -literal @@ -1361,7 +1359,7 @@ and you really test the code. And then avoid it anyway. .Pp Finally, it is observably the case that the .Nm -implementations of floating-point conversions and comparisons don’t +implementations of floating-point conversions and comparisons don't precisely match the behavior of other \*[lang] compilers. .Pp You have been warned. diff --git a/gcc/cobol/gcobolspec.cc b/gcc/cobol/gcobolspec.cc index d
[gcc r16-2676] cobol: Eliminate various errors. [PR120244]
https://gcc.gnu.org/g:0f93b290938d2a78adb7183104a86ce05ccd21de commit r16-2676-g0f93b290938d2a78adb7183104a86ce05ccd21de Author: Robert Dubner Date: Wed Jul 30 09:54:13 2025 -0400 cobol: Eliminate various errors. [PR120244] The following coding errors were located by running extended tests through valgrind. These changes repair the errors. gcc/cobol/ChangeLog: PR cobol/120244 * genapi.cc (get_level_88_domain): Increase array size for final byte. (psa_FldLiteralA): Use correct length in build_string_literal call. * scan.l: Use a loop instead of std:transform to avoid EOF overrun. * scan_ante.h (binary_integer_usage): Use a variable-length buffer. Diff: --- gcc/cobol/genapi.cc | 12 ++-- gcc/cobol/scan.l | 21 +++-- gcc/cobol/scan_ante.h | 5 - 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/gcc/cobol/genapi.cc b/gcc/cobol/genapi.cc index 666802ea137e..20341643182e 100644 --- a/gcc/cobol/genapi.cc +++ b/gcc/cobol/genapi.cc @@ -531,6 +531,14 @@ get_level_88_domain(size_t parent_capacity, cbl_field_t *var, size_t &returned_s free(stream); domain += 1; } + + if( returned_size >= retval_capacity) +{ +retval_capacity *= 2; +retval = static_cast(xrealloc(retval, retval_capacity)); +} + + gcc_assert(returned_size < retval_capacity); retval[returned_size++] = '\0'; return retval; } @@ -16765,9 +16773,9 @@ psa_FldLiteralA(struct cbl_field_t *field ) vs_file_static); actually_create_the_static_field( field, -build_string_literal(field->data.capacity+1, +build_string_literal(field->data.capacity, buffer), -field->data.capacity+1, +field->data.capacity, field->data.initial, NULL_TREE, field->var_decl_node); diff --git a/gcc/cobol/scan.l b/gcc/cobol/scan.l index 2da38d82a2e7..ba4c044e15e3 100644 --- a/gcc/cobol/scan.l +++ b/gcc/cobol/scan.l @@ -1673,16 +1673,17 @@ B-SHIFT-RC p += 2; while( ISSPACE(*p) ) p++; cbl_name_t name2; - std::transform( p, p + sizeof(name2), name2, - []( char ch ) { - switch(ch) { - case '-': - case '_': return ch; - default: - if( ISALNUM(ch) ) return ch; - } - return '\0'; - } ); +const char *pend = p + sizeof(name2); +char *pout = name2; +while( p < pend ) { + char ch = *p++; + if( ISALNUM(ch) || ch == '-' || ch == '_' ) { +*pout++ = ch; + } else { +*pout++ = '\0'; +break; + } +} symbol_elem_t *e = symbol_file(PROGRAM, name2); /* * For NAME IN FILENAME, we want the parser to handle it. diff --git a/gcc/cobol/scan_ante.h b/gcc/cobol/scan_ante.h index 19ceb2b4a08b..c00826d652fd 100644 --- a/gcc/cobol/scan_ante.h +++ b/gcc/cobol/scan_ante.h @@ -609,7 +609,9 @@ static const std::map binary_integers { static int binary_integer_usage( const char name[]) { - cbl_name_t uname = {}; + // uname can't be cbl_name_t, because at this point name[] might have more + // than sizeof(cbl_name_t) characters. The length check comes later. + char *uname = xstrdup(name); std::transform(name, name + strlen(name), uname, ftoupper); dbgmsg("%s:%d: checking %s in %zu keyword_aliases", @@ -628,6 +630,7 @@ binary_integer_usage( const char name[]) { yylval.computational.signable = p->second.signable; dbgmsg("%s:%d: %s has type %d", __func__, __LINE__, uname, p->second.type ); + free(uname); return p->second.token; }
[gcc r16-2713] cobol: Minor changes to quiet cppcheck warnings. [PR119324]
https://gcc.gnu.org/g:8b06c58c4ae83d4007510f2d2c74ee979bc2b86a commit r16-2713-g8b06c58c4ae83d4007510f2d2c74ee979bc2b86a Author: Robert Dubner Date: Fri Aug 1 10:37:38 2025 -0400 cobol: Minor changes to quiet cppcheck warnings. [PR119324] gcc/cobol/ChangeLog: PR cobol/119324 * cbldiag.h (location_dump): Inline suppression of knownConditionTrueFalse. * genapi.cc (parser_statement_begin): Combine two if() statements. * genutil.cc (get_binary_value): File-level suppression of duplicateBreak. * symbols.cc (symbol_elem_cmp): File-level suppression of duplicateBreak. Diff: --- gcc/cobol/cbldiag.h | 2 +- gcc/cobol/genapi.cc | 5 + gcc/cobol/genutil.cc | 5 - gcc/cobol/symbols.cc | 10 ++ 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/gcc/cobol/cbldiag.h b/gcc/cobol/cbldiag.h index 39f13690bec9..dd16190fbd87 100644 --- a/gcc/cobol/cbldiag.h +++ b/gcc/cobol/cbldiag.h @@ -122,7 +122,7 @@ static void location_dump( const char func[], int line, const char tag[], const LOC& loc) { extern int yy_flex_debug; // cppcheck-suppress shadowVariable if( yy_flex_debug ) { -const char *detail = gcobol_getenv("update_location"); +const char *detail = gcobol_getenv("update_location"); // cppcheck-suppress knownConditionTrueFalse if( detail ) { fprintf(stderr, "%s:%d: %s location (%d,%d) to (%d,%d)\n", func, line, tag, diff --git a/gcc/cobol/genapi.cc b/gcc/cobol/genapi.cc index 20341643182e..c9d2da481ab9 100644 --- a/gcc/cobol/genapi.cc +++ b/gcc/cobol/genapi.cc @@ -1198,12 +1198,9 @@ parser_statement_begin( const cbl_name_t statement_name, if( exception_processing ) { store_location_stuff(statement_name); -} - - if( exception_processing ) -{ set_exception_environment(ecs, dcls); } + sv_is_i_o = false; } diff --git a/gcc/cobol/genutil.cc b/gcc/cobol/genutil.cc index 7895ea8d71ec..a5f69a09eec9 100644 --- a/gcc/cobol/genutil.cc +++ b/gcc/cobol/genutil.cc @@ -27,6 +27,9 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + +// cppcheck-suppress-file duplicateBreak + #include "cobol-system.h" #include "coretypes.h" #include "tree.h" @@ -1267,7 +1270,7 @@ get_binary_value( tree value, cbl_field_type_str(field->type) ); cbl_internal_error("%s", err); abort(); - // break; // break not needed after abort(); + break; } } diff --git a/gcc/cobol/symbols.cc b/gcc/cobol/symbols.cc index 7d6a9554bdde..f2cd1b55f802 100644 --- a/gcc/cobol/symbols.cc +++ b/gcc/cobol/symbols.cc @@ -28,6 +28,8 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +// cppcheck-suppress-file duplicateBreak + #include "config.h" #include // Before cobol-system because it uses poisoned functions #include "cobol-system.h" @@ -500,13 +502,13 @@ symbol_elem_cmp( const void *K, const void *E ) } return strcasecmp(key.name, elem.name); } -// break; // This break not needed if all options do a return. +break; case SymSpecial: return special_pair_cmp(k->elem.special, e->elem.special)? 0 : 1; -// break; // This break not needed after return. +break; case SymAlphabet: return strcasecmp(k->elem.alphabet.name, e->elem.alphabet.name); -// break; // This break not needed after return. +break; case SymFile: // If the key is global, so must be the found element. if( (cbl_file_of(k)->attr & global_e) == global_e && @@ -514,7 +516,7 @@ symbol_elem_cmp( const void *K, const void *E ) return 1; } return strcasecmp(k->elem.file.name, e->elem.file.name); -// break; // This break not needed after return. +break; } assert(k->type == SymField);
[gcc r16-2489] cobol: Honor the "-static" command-line option. [PR119231]
https://gcc.gnu.org/g:44e32178031e89399710c3ee7444891631a9c8ec commit r16-2489-g44e32178031e89399710c3ee7444891631a9c8ec Author: Robert Dubner Date: Thu Jul 24 12:09:36 2025 -0400 cobol: Honor the "-static" command-line option. [PR119231] gcc/cobol/ChangeLog: PR cobol/119231 * gcobolspec.cc: (lang_specific_driver): Pass OPT_static through. Handle -static and -static-libgcobol properly. gcc/testsuite/ChangeLog: * cobol.dg/group2/_-static__compilation.cob: Modify for -static warning. * cobol.dg/group2/_-static__compilation.out: Removed. Diff: --- gcc/cobol/gcobolspec.cc | 13 +++-- gcc/testsuite/cobol.dg/group2/_-static__compilation.cob | 4 ++-- gcc/testsuite/cobol.dg/group2/_-static__compilation.out | 2 -- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/gcc/cobol/gcobolspec.cc b/gcc/cobol/gcobolspec.cc index 038aaec13469..1f1b4631d8f3 100644 --- a/gcc/cobol/gcobolspec.cc +++ b/gcc/cobol/gcobolspec.cc @@ -470,7 +470,10 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, break; #endif case OPT_static: +#if defined (HAVE_LD_STATIC_DYNAMIC) +append_arg(decoded_options[i]); static_in_general = true; +#endif break; default: @@ -498,17 +501,23 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, need_libgcobol = false; } + if( static_in_general ) +{ +// These two options interfere with each other. +static_libgcobol = false; +} + if( need_libgcobol ) { add_arg_lib(COBOL_LIBRARY, static_libgcobol); } if( need_libdl ) { -add_arg_lib(DL_LIBRARY, static_in_general); +add_arg_lib(DL_LIBRARY, false); } if( need_libstdc ) { -add_arg_lib(STDCPP_LIBRARY, static_in_general); +add_arg_lib(STDCPP_LIBRARY, false); } if( prior_main ) diff --git a/gcc/testsuite/cobol.dg/group2/_-static__compilation.cob b/gcc/testsuite/cobol.dg/group2/_-static__compilation.cob index 7843d3d27aac..f344a84c3988 100644 --- a/gcc/testsuite/cobol.dg/group2/_-static__compilation.cob +++ b/gcc/testsuite/cobol.dg/group2/_-static__compilation.cob @@ -1,7 +1,7 @@ *> { dg-do run } *> { dg-options "-static" } - *> { dg-output-file "group2/_-static__compilation.out" } - + *> { dg-prune-output {warning} } + *> { dg-output {hello, world} } IDENTIFICATION DIVISION. PROGRAM-ID. prog. PROCEDURE DIVISION. diff --git a/gcc/testsuite/cobol.dg/group2/_-static__compilation.out b/gcc/testsuite/cobol.dg/group2/_-static__compilation.out deleted file mode 100644 index ae0e5111caef.. --- a/gcc/testsuite/cobol.dg/group2/_-static__compilation.out +++ /dev/null @@ -1,2 +0,0 @@ -hello, world -
[gcc r16-667] cobol: One additional edit to testsuite/cobol.dg/group1/check_88.cob [PR120251]
https://gcc.gnu.org/g:fae53928595341981f08ded4edcbba07ee1d5d04 commit r16-667-gfae53928595341981f08ded4edcbba07ee1d5d04 Author: Robert Dubner Date: Thu May 15 13:33:16 2025 -0400 cobol: One additional edit to testsuite/cobol.dg/group1/check_88.cob [PR120251] Missed one edit. This fixes that. gcc/testsuite/ChangeLog: PR cobol/120251 * cobol.dg/group1/check_88.cob: One final regex "." instead of "ß" Diff: --- gcc/testsuite/cobol.dg/group1/check_88.cob | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/testsuite/cobol.dg/group1/check_88.cob b/gcc/testsuite/cobol.dg/group1/check_88.cob index 18a299fc282b..f1d0685e478a 100644 --- a/gcc/testsuite/cobol.dg/group1/check_88.cob +++ b/gcc/testsuite/cobol.dg/group1/check_88.cob @@ -17,7 +17,7 @@ *> { dg-output {.* Bundesstra.e(\n|\r\n|\r)} } *> { dg-output { (\n|\r\n|\r)} } *> { dg-output {There should be no spaces before the final quote(\n|\r\n|\r)} } -*> { dg-output {".* Bundesstraße"(\n|\r\n|\r)} } +*> { dg-output {".* Bundesstra.e"(\n|\r\n|\r)} } *> { dg-output { (\n|\r\n|\r)} } *> { dg-output { IsLow ""(\n|\r\n|\r)} } *> { dg-output { IsZero "000"(\n|\r\n|\r)} }
[gcc r16-698] cobol: Eliminate exception "blob"; streamline some code generation.
https://gcc.gnu.org/g:92b6485a75cabaf64f1f74ba7ab73a5204c9d0aa commit r16-698-g92b6485a75cabaf64f1f74ba7ab73a5204c9d0aa Author: Robert Dubner Date: Fri May 16 11:12:04 2025 -0400 cobol: Eliminate exception "blob"; streamline some code generation. This eliminates some of the last vestiges of creating a structure at host-time that is intended for use at target-time. It removes some unnecessary processing when exceptions are not enabled. It improves the creation of code that handles table subscripts and refmod parameters. gcc/cobol/ChangeLog: * cobol1.cc (cobol_langhook_handle_option): Eliminate OPT_M. * except.cc (cbl_enabled_exception_t::dump): Formatting. (symbol_declaratives_add): Remove. (declarative_runtime_match): Change to no-blob processing. * exceptg.h (declarative_runtime_match): Change declaration. (symbol_declaratives_add): Remove declaration. * gcobc: Dialect handling. * genapi.cc (parser_compile_ecs): Formatting; add SHOW_IF_PARSE. (parser_compile_dcls): Likewise. (parser_statement_begin): Avoid unnecessary store_location_stuff() call. (gg_get_depending_on_value): Streamline get_depending_on_value_from_odo(). (depending_on_value): Likewise. (parser_display_field): Formatting. (parser_display): Handle case ENV_NAME_e. (parser_file_open): Avoid unnecessary store_location_stuff. (parser_file_close): Likewise. (parser_file_read): Likewise. (parser_file_write): Likewise. (parser_file_delete): Likewise. (parser_file_rewrite): Likewise. (parser_file_start): Likewise. (parser_intrinsic_subst): Streamline get_depending_on_value_from_odo(). (parser_intrinsic_call_1): Likewise. (parser_lsearch_start): Likewise. (parser_bsearch_start): Likewise. (parser_sort): Likewise. (store_location_stuff): Avoid unnecessary assignments. (parser_pop_exception): Formatting. * genmath.cc (parser_add): Avoid var_decl_default_compute_error assignment when doing fast_add(). (parser_subtract): Likewise. * genutil.cc (REFER): Macro for analyzing code generation. (get_integer_value): Use data_decl_node for integer value from FldLiteralN. (get_data_offset): Streamline exception code processing. (get_and_check_refstart_and_reflen): Likewise. (get_depending_on_value_from_odo): Likewise. (get_depending_on_value): Likewise. (refer_is_clean): Formatting. (refer_refmod_length): Streamline exception code processing. (refer_fill_depends): Likewise. (refer_offset): Likewise. (refer_size_dest): Likewise. (refer_size_source): Likewise. * genutil.h (get_depending_on_value_from_odo): Likewise. * lang-specs.h: Options definition. * lang.opt: -M as in c.opt. * lexio.h: Formatting. * parse.y: Expand -dialect suggestions; SECTION SEGMENT messages. * parse_ante.h (declarative_runtime_match): Dialect handling. (labels_dump): Likewise. (class current_tokens_t): Likewise. (class prog_descr_t): Make program_index size_t to prevent padding bytes. * scan.l: POP_FILE directive. * scan_ante.h (class enter_leave_t): Better handle line number when processing COPY statements. * symbols.cc (symbol_elem_cmp): Eliminate SymFunction. (symbols_dump): Likewise. (symbol_label_section_exists): Likewise. * symbols.h (NAME_MAX): Eliminate. (Was part of SymFunction). (dialect_is): Improve dialect handling. (dialect_gcc): Likewise. (dialect_ibm): Likewise. (dialect_gnu): Likewise. (enum symbol_type_t): Eliminate SymFunction. * util.cc (symbol_type_str): Likewise. (class unique_stack): Option -M handling. (cobol_set_pp_option): Likewise. (parse_file): Likewise. * util.h (cobol_set_pp_option): Likewise. libgcobol/ChangeLog: * common-defs.h (struct cbl_declarative_t): Eliminate blobl. * libgcobol.cc (__gg__set_env_name): Code for ENVIRONMENT-NAME/VALUE. (__gg__set_env_value): Likewise. gcc/testsuite/ChangeLog: * cobol.dg/group1/declarative_1.cob: Handle modified exception handling. Diff: --- gcc/cobol/cobol1.cc | 23 +- gcc/cobol/except.cc | 111 ++--- gcc/cobol/exceptg.h | 7 +- gcc/cobol/gcobc |
[gcc r16-761] cobol: sqrt(0) is not an ec-argument error. [PR119885]
https://gcc.gnu.org/g:d44beb132850a8ced1b0614e2724f18465b4a737 commit r16-761-gd44beb132850a8ced1b0614e2724f18465b4a737 Author: Robert Dubner Date: Tue May 20 11:49:43 2025 -0400 cobol: sqrt(0) is not an ec-argument error. [PR119885] libgcobol PR cobol/119885 * intrinsic.cc: (__gg__sqrt): Change test from <= zero to < zero. gcc/testsuite * cobol.dg/group2/FUNCTION_SQRT__2_.cob: Testcase. * cobol.dg/group2/FUNCTION_SQRT__2_.out: Known-good for the testcase. Diff: --- gcc/testsuite/cobol.dg/group2/FUNCTION_SQRT__2_.cob | 13 + gcc/testsuite/cobol.dg/group2/FUNCTION_SQRT__2_.out | 5 + libgcobol/intrinsic.cc | 2 +- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/gcc/testsuite/cobol.dg/group2/FUNCTION_SQRT__2_.cob b/gcc/testsuite/cobol.dg/group2/FUNCTION_SQRT__2_.cob new file mode 100644 index ..c1f4ba8684a6 --- /dev/null +++ b/gcc/testsuite/cobol.dg/group2/FUNCTION_SQRT__2_.cob @@ -0,0 +1,13 @@ + *> { dg-do run } + *> { dg-output-file "group2/FUNCTION_SQRT__2_.out" } +program-id. sqbug. +procedure division. +if function sqrt (0) = 0*>if4034.2 +display 'ok' else display 'bad'. +display "sqrt(0) " function trim (function exception-status) +set last exception to off +if function sqrt (-0.1) = 0*>if4034.2 +display 'ok' else display 'bad'. +display "sqrt(-0.1) " function trim (function exception-status) +goback. + diff --git a/gcc/testsuite/cobol.dg/group2/FUNCTION_SQRT__2_.out b/gcc/testsuite/cobol.dg/group2/FUNCTION_SQRT__2_.out new file mode 100644 index ..0783ac5abb17 --- /dev/null +++ b/gcc/testsuite/cobol.dg/group2/FUNCTION_SQRT__2_.out @@ -0,0 +1,5 @@ +ok +sqrt(0) "" +bad +sqrt(-0.1) "EC-ARGUMENT-FUNCTION" + diff --git a/libgcobol/intrinsic.cc b/libgcobol/intrinsic.cc index 37ae13e262fe..d6dfcb981a5e 100644 --- a/libgcobol/intrinsic.cc +++ b/libgcobol/intrinsic.cc @@ -3565,7 +3565,7 @@ __gg__sqrt( cblc_field_t *dest, source_offset, source_size); - if( value <= GCOB_FP128_LITERAL(0.0) ) + if( value < GCOB_FP128_LITERAL(0.0) ) { exception_raise(ec_argument_function_e); }
[gcc r16-764] cobol: Multiple PRs; formatting; exception processing.
https://gcc.gnu.org/g:fba34a0cc55488ad89becf81cf2c9ac517d244d4 commit r16-764-gfba34a0cc55488ad89becf81cf2c9ac517d244d4 Author: Robert Dubner Date: Tue May 20 13:35:15 2025 -0400 cobol: Multiple PRs; formatting; exception processing. The PRs mentined here have either been previously fixed, or are fixed by this commit. gcc/cobol/ChangeLog: PR cobol/119770 PR cobol/119772 PR cobol/119790 PR cobol/119771 PR cobol/119810 PR cobol/119335 PR cobol/119632 * cdf-copy.cc (GLOB_BRACE): Eliminate . * cdfval.h (_CDF_VAL_H_): Switch to C++ headers. * copybook.h (class copybook_elem_t): Eliminate . (class copybook_t): Likewise. * gcobc: Numerous changes to improve utility. * gcobol.1: Correct names in the list of functions. * genapi.cc (compare_binary_binary): Use has_attr() function. * lexio.cc (cdftext::lex_open): Typo; filename logic. (cdftext::process_file): Filename logic. * parse.y: Numerous parsing changes. * parse_ante.h (new_alphanumeric): C++ includes; changes to temporaries. (new_tempnumeric): Likewise. (new_tempnumeric_float): Likewise. (set_real_from_capacity): Created. * scan.l: Use yy_pop_state(). * scan_ante.h (typed_name): Find figconst from data.initial. * symbols.cc (symbol_valid_udf_args): Eliminate. (symbols_update): figconst processing. (new_temporary_impl): For functions, set .initial to function name. (temporaries_t::acquire): Likewise. (new_alphanumeric): Likewise. (new_temporary): Likewise. * symbols.h (_SYMBOLS_H_): Use C++ includes. (cbl_figconst_tok): Change handling of figconst. (cbl_figconst_field_of): Change handling of figconst. (symbol_valid_udf_args): Eliminate. * symfind.cc (symbol_match2): Change declaration. (symbol_match): Change declaration. libgcobol/ChangeLog: * charmaps.cc: Switch to C++ includes. * common-defs.h: Likewise. * constants.cc: Likewise. * ec.h: Remove #include . * gcobolio.h (GCOBOLIO_H_): Switch to C++ includes. * gfileio.cc: Likewise. * gmath.cc: Likewise. * intrinsic.cc: Comment formatting; C++ includes. * io.cc: C++ includes. * libgcobol.cc: (__gg__stash_exceptions): Eliminate. * valconv.cc: Switch to C++ includes. Co-Authored-By: James K. Lowden Diff: --- gcc/cobol/cdf-copy.cc | 88 +++ gcc/cobol/cdfval.h | 6 +- gcc/cobol/copybook.h| 13 +-- gcc/cobol/gcobc | 141 ++-- gcc/cobol/gcobol.1 | 54 - gcc/cobol/genapi.cc | 4 +- gcc/cobol/lexio.cc | 7 +- gcc/cobol/parse.y | 283 +++- gcc/cobol/parse_ante.h | 35 -- gcc/cobol/scan.l| 2 +- gcc/cobol/scan_ante.h | 4 + gcc/cobol/symbols.cc| 63 +++ gcc/cobol/symbols.h | 19 ++-- gcc/cobol/symfind.cc| 4 +- libgcobol/charmaps.cc | 14 ++- libgcobol/common-defs.h | 5 +- libgcobol/constants.cc | 19 ++-- libgcobol/ec.h | 1 - libgcobol/gcobolio.h| 3 +- libgcobol/gfileio.cc| 18 +-- libgcobol/gmath.cc | 19 ++-- libgcobol/intrinsic.cc | 22 ++-- libgcobol/io.cc | 11 +- libgcobol/libgcobol.cc | 14 +-- libgcobol/valconv.cc| 7 +- 25 files changed, 456 insertions(+), 400 deletions(-) diff --git a/gcc/cobol/cdf-copy.cc b/gcc/cobol/cdf-copy.cc index 059596c08f41..99f5866ae86f 100644 --- a/gcc/cobol/cdf-copy.cc +++ b/gcc/cobol/cdf-copy.cc @@ -35,23 +35,12 @@ // We regret any confusion engendered. #include "config.h" -#include #include "cobol-system.h" #include "cbldiag.h" #include "util.h" #include "copybook.h" -// GLOB_BRACE and GLOB_TILDE are BSD extensions. Provide fallback definitions -// if necessary. -#ifndef GLOB_BRACE -#define GLOB_BRACE 0 -#endif - -#ifndef GLOB_TILDE -#define GLOB_TILDE 0 -#endif - #define COUNT_OF(X) (sizeof(X) / sizeof(X[0])) /* @@ -86,7 +75,6 @@ * space. This function only applies them. */ -extern int yydebug; const char * cobol_filename(); bool is_fixed_format(); bool is_reference_format(); @@ -190,12 +178,6 @@ esc( size_t len, const char input[] ) { return buffer; // caller must strdup static buffer } -static int -glob_error(const char *epath, int eerrno) { - dbgmsg("%s: COPY file search: '%s': %s", __func__, epath, xstrerror(eerrno)); - return 0; -} - void copybook_directory_add( const char gcob_copybook[] ) { if( !gcob_copybook ) return; @@ -242,27 +224,15 @@ copybook_extension_add( const char ext[] ) { copybook.ext
[gcc r16-1273] cobol: Diagnostic messages, Flex build, and some cppcheck reports. [PR120328, PR119695]
https://gcc.gnu.org/g:37f5fdd008399c239e0689f2e864519505c78c7e commit r16-1273-g37f5fdd008399c239e0689f2e864519505c78c7e Author: Robert Dubner Date: Fri Jun 6 16:32:22 2025 -0400 cobol: Diagnostic messages, Flex build, and some cppcheck reports. [PR120328, PR119695] Remove %0x and similar from diagnostic framework messages. Remove %zu from printf messages because it is not supported on some platforms. Corrections in response to cppcheck. Sundry small fixes. gcc/cobol/ChangeLog: PR cobol/120328 * Make-lang.in: Success with non-English locale. PR cobol/119695 * cbldiag.h (cbl_unimplemented_at): Comment: * cdf-copy.cc (copybook_elem_t::open_file): Indentation. * cdf.y: YYABORT on certain errors. * cdfval.h (cdf_value): Const parameter. * copybook.h (class copybook_elem_t): Initialization. (class uppername_t): Explicit constructor. * except.cc (ec_type_descr): Remove %04s. (cbl_enabled_exceptions_t::dump): Remove %zu. * exceptg.h (class exception_turn_t): Explicit constructor. * genapi.cc (parser_perform_conditional): Remove %zu. (set_exception_environment): Formatting. (parser_statement_begin): Exception overhead. (parser_perform_conditional): Formatting: (parser_perform_conditional_end): Eliminate size_t. (parser_check_fatal_exception): Exception overhead. (parser_perform_conditional_end): Remove %zu. * inspect.h (struct cbx_inspect_match_t): Const reference. (struct cbx_inspect_t): Const parameter. * lexio.cc (cdftext::process_file): Remove %zu. * lexio.h (struct YYLTYPE): Remove unneeded struct. (YYLTYPE_IS_DECLARED): Likewise. (YYLTYPE_IS_TRIVIAL): Likewise. * parse.y: Comment; change DOT. * scan.l: Scan function names without swallowing whitespace. * scan_ante.h (scanner_parsing): Remove %zu. (scanner_parsing_pop): Remove %zu. (binary_integer_usage): Remove %zu. * scan_post.h (prelex): Correct post-CDF resumption. (yylex): Clearer message. * symbols.cc (symbol_table_extend): Explicit constructor. (elementize): Const parameter. (is_variable_length): Correct always-false. (symbols_update): Remove unnecessary shadow variable. (struct symbol_elem_t): Const parameter. (symbol_alphabet_add): Const parameter. (new_literal_add): Initialization. * symbols.h (class cbl_domain_elem_t): Correct assignment. (struct cbl_span_t): Improve constructor. (struct cbl_refer_t): Initialization. (struct cbl_alphabet_t): Rename shadow variable. (struct cbl_file_key_t): Remove unused constructor. (struct symbol_elem_t): Initialization. (struct cbl_until_addresses_t): Use unsigned int, for messages. (struct cbl_prog_hier_t): Initialization. (struct cbl_perform_tgt_t): Repair constructor. (struct cbl_label_t): Const parameter. (symbol_typedef_add): Const parameter. (symbol_field_add): Explicit constructor. (symbol_label_add): Explicit constructor. (symbol_program_add): Remove C-style "struct" use. (symbol_special_add): Remove C-style "struct" use. (symbol_alphabet_add): Const parameter. (symbol_file_add): Remove C-style "struct" use. (symbol_section_add): Remove C-style "struct" use. * symfind.cc: Const parameter. * util.cc (gb4): New function. * util.h (gb4): New function. * TODO: New file. libgcobol/ChangeLog: * common-defs.h (enum cbl_file_mode_t): Whitespace. (enum file_stmt_t): Likewise. (ec_cmp): Likewise. (struct cbl_declarative_t): Add "explicit" keyword. (class cbl_enabled_exceptions_t): Whitespace. * gfileio.cc: Remove cppcheck comment. * libgcobol.cc (class ec_status_t): Add "explicit" keyword. (match_declarative): Remove %zu. (default_exception_handler): Likwise. (__gg__check_fatal_exception): Exception overhead. (__gg__exception_push): Remove %zu. (__gg__exception_pop): Likewise. (cbl_enabled_exception_t::dump): Likewise. (__gg__match_exception): Exception overhead; remove %zu. (cbl_enabled_exceptions_t::dump): Remove %zu. (__gg__set_exception_environment): Likewise. Co-authored-by: James K. Lowden Co-authored-by: Robert Dubner Diff: --- gcc/cobol/Make-lang.in | 3 +- gcc/cobol/TODO | 33 +++ gcc/cobol/cbldiag.h | 6
[gcc r16-1424] cobol: Eliminate unguarded clock_gettime dependencies. [PR119975]
https://gcc.gnu.org/g:582dda08eabc8f7dc9c504c0010d778bd6ff09b2 commit r16-1424-g582dda08eabc8f7dc9c504c0010d778bd6ff09b2 Author: Robert Dubner Date: Wed Jun 11 15:49:41 2025 -0400 cobol: Eliminate unguarded clock_gettime dependencies. [PR119975] These changes are help make it possible to compile on MacOS. In addition to guarding clock_settime() calls, it removes the use of structures and constants needed for clock_settime(). libgcobol/ChangeLog: PR cobol/119975 * intrinsic.cc (__gg__current_date): Eliminate CLOCK_REALTIME. (__gg__seconds_past_midnight): Likewise. (__gg__formatted_current_date): Likewise. (__gg__random): Likewise. (__gg__random_next): Likewise. * libgcobol.cc: include . (__gg__abort): Eliminate CLOCK_REALTIME. (cobol_time): Likewise. (get_time_nanoseconds): Rename. (get_time_nanoseconds_local): Comment; Eliminate CLOCK_REALTIME. (__gg__clock_gettime): Likewise. (__gg__get_date_hhmmssff): Likewise. * libgcobol.h (__gg__clock_gettime): Eliminate clockid_t from declaration. Diff: --- libgcobol/intrinsic.cc | 12 ++-- libgcobol/libgcobol.cc | 44 ++-- libgcobol/libgcobol.h | 2 +- 3 files changed, 37 insertions(+), 21 deletions(-) diff --git a/libgcobol/intrinsic.cc b/libgcobol/intrinsic.cc index 2d8d79c1c7c7..81ae638630f1 100644 --- a/libgcobol/intrinsic.cc +++ b/libgcobol/intrinsic.cc @@ -1219,7 +1219,7 @@ __gg__current_date(cblc_field_t *dest) { // FUNCTION CURRENT-DATE struct cbl_timespec tp = {}; - __gg__clock_gettime(CLOCK_REALTIME, &tp); // time_t tv_sec; long tv_nsec + __gg__clock_gettime(&tp); // time_t tv_sec; long tv_nsec char retval[DATE_STRING_BUFFER_SIZE]; timespec_to_string(retval, tp); @@ -1236,7 +1236,7 @@ __gg__seconds_past_midnight(cblc_field_t *dest) struct tm tm; __int128 retval=0; - __gg__clock_gettime(CLOCK_REALTIME, &tp); // time_t tv_sec; long tv_nsec + __gg__clock_gettime(&tp); // time_t tv_sec; long tv_nsec localtime_r(&tp.tv_sec, &tm); retval += tm.tm_hour; @@ -1460,7 +1460,7 @@ __gg__formatted_current_date( cblc_field_t *dest, // Destination string size_t input_offset, size_t input_size) { - // FUNCTION CURRENT-DATE + // FUNCTION FORMATTED-CURRENT-DATE // Establish the destination, and set it to spaces char *d= PTRCAST(char, dest->data); @@ -1485,7 +1485,7 @@ __gg__formatted_current_date( cblc_field_t *dest, // Destination string } struct cbl_timespec ts = {}; - __gg__clock_gettime(CLOCK_REALTIME, &ts); + __gg__clock_gettime(&ts); struct tm tm = {}; #ifdef HAVE_STRUCT_TM_TM_ZONE @@ -3433,7 +3433,7 @@ __gg__random( cblc_field_t *dest, state = (char *)malloc(state_len); struct cbl_timespec ts; -__gg__clock_gettime(CLOCK_REALTIME, &ts); +__gg__clock_gettime(&ts); initstate_r( ts.tv_nsec, state, state_len, buf); } int seed = (int)__gg__binary_value_from_qualified_field(&rdigits, @@ -3473,7 +3473,7 @@ __gg__random_next(cblc_field_t *dest) buf->state = NULL; state = (char *)malloc(state_len); struct cbl_timespec ts; -__gg__clock_gettime(CLOCK_REALTIME, &ts); +__gg__clock_gettime(&ts); initstate_r( ts.tv_nsec, state, state_len, buf); } random_r(buf, &retval_31); diff --git a/libgcobol/libgcobol.cc b/libgcobol/libgcobol.cc index f8697afd59cb..81b5b7af8121 100644 --- a/libgcobol/libgcobol.cc +++ b/libgcobol/libgcobol.cc @@ -69,6 +69,7 @@ #include #include #include +#include #include #include "exceptl.h" @@ -264,7 +265,7 @@ class ec_status_t { , operation(file_op_none) , mode(file_mode_none_e) , user_status(nullptr) -, filename(nullptr) +, filename(nullptr) {} explicit file_status_t( const cblc_file_t *file ) : ifile(file->symbol_table_index) @@ -558,7 +559,7 @@ __gg__abort(const char *msg) abort(); } -void +void __gg__mabort() { __gg__abort("Memory allocation error\n"); @@ -2290,7 +2291,7 @@ static time_t cobol_time() { struct cbl_timespec tp; - __gg__clock_gettime(CLOCK_REALTIME, &tp); + __gg__clock_gettime(&tp); return tp.tv_sec; } @@ -2402,12 +2403,28 @@ int_from_digits(const char * &p, int ndigits) return retval; } -uint64_t -get_time_nanoseconds() +// For testing purposes, this undef causes the use of gettimeofday(). +// #undef HAVE_CLOCK_GETTIME + +static uint64_t +get_time_nanoseconds_local() { // This code was unabashedly stolen from gcc/timevar.cc. // It returns the Unix epoch with nine decimal places. + /* Note: I am perplexed. I have been examining the gcc Makefiles and + config
[gcc r16-3152] cobol: Bring EBCDIC NumericDisplay variables into IBM compliance.
https://gcc.gnu.org/g:9992c0a0e1b455ad5c68d7261b4bc9bfc2461f70 commit r16-3152-g9992c0a0e1b455ad5c68d7261b4bc9bfc2461f70 Author: Robert Dubner Date: Mon Aug 11 20:56:38 2025 -0400 cobol: Bring EBCDIC NumericDisplay variables into IBM compliance. The internal representation of Numeric Display (ND) zoned decimal variables when operating in EBCDIC mode has been brought into compliance with IBM conventions. This requires changes to data input, data output, internal conversion of zoned decimal to binary, and variable assignment. gcc/cobol/ChangeLog: * genapi.cc (compare_binary_binary): Formatting. (cobol_compare): Formatting. (mh_numeric_display): Rewrite "move ND to ND" algorithm. (initial_from_initial): Proper initialization of EBCDIC ND variables. * genmath.cc (fast_add): Delete comment. * genutil.cc (get_binary_value): Modify for updated EBCDIC. libgcobol/ChangeLog: * common-defs.h (NUMERIC_DISPLAY_SIGN_BIT): New comment; new constant. (EBCDIC_MINUS): New constant. (EBCDIC_PLUS): Likewise. (EBCDIC_ZERO): Likewise. (EBCDIC_NINE): Likewise. (PACKED_NYBBLE_PLUS): Likewise. (PACKED_NYBBLE_MINUS): Likewise. (PACKED_NYBBLE_UNSIGNED): Likewise. (NUMERIC_DISPLAY_SIGN_BIT_ASCII): Likewise. (NUMERIC_DISPLAY_SIGN_BIT_EBCDIC): Likewise. (SEPARATE_PLUS): Likewise. (SEPARATE_MINUS): Likewise. (ZONED_ZERO): Likewise. (ZONE_SIGNED_EBCDIC): Likewise. * configure: Regenerate. * libgcobol.cc (turn_sign_bit_on): Handle new EBCDIC sign convention. (turn_sign_bit_off): Likewise. (is_sign_bit_on): Likewise. (int128_to_field): EBCDIC NumericDisplay conversion. (get_binary_value_local): Likewise. (format_for_display_internal): Likewise. (normalize_id): Likewise. (__gg__inspect_format_1): Convert EBCDIC negative numbers to positive. * stringbin.cc (packed_from_combined): Quell cppcheck warning. gcc/testsuite/ChangeLog: * cobol.dg/group2/ALLOCATE_Rule_8_OPTION_INITIALIZE_with_figconst.out: Change test for updated handling of Numeric Display variables. Diff: --- gcc/cobol/genapi.cc| 462 - gcc/cobol/genmath.cc | 1 - gcc/cobol/genutil.cc | 104 ++--- ...CATE_Rule_8_OPTION_INITIALIZE_with_figconst.out | 6 +- libgcobol/common-defs.h| 53 ++- libgcobol/configure| 1 - libgcobol/libgcobol.cc | 360 +++- libgcobol/stringbin.cc | 2 +- 8 files changed, 527 insertions(+), 462 deletions(-) diff --git a/gcc/cobol/genapi.cc b/gcc/cobol/genapi.cc index c9d2da481ab9..40b79ba5ce6c 100644 --- a/gcc/cobol/genapi.cc +++ b/gcc/cobol/genapi.cc @@ -2102,6 +2102,7 @@ compare_binary_binary(tree return_int, right_side_ref->field, refer_offset(*right_side_ref), hilo_right); + IF( hilo_left, eq_op, integer_one_node ) { // left side is hi-value @@ -2358,8 +2359,6 @@ cobol_compare( tree return_int, NULL_TREE)); // compared = true; // Commented out to quiet cppcheck } - -// gg_printf(" result is %d\n", return_int, NULL_TREE); } static void @@ -14852,7 +14851,7 @@ static bool mh_numeric_display( const cbl_refer_t &destref, const cbl_refer_t &sourceref, const TREEPLET&tsource, - tree size_error) + tree size_error) { bool moved = false; @@ -14862,98 +14861,106 @@ mh_numeric_display( const cbl_refer_t &destref, && !(sourceref.field->attr & scaled_e) ) { Analyze(); -// I believe that there are 225 pathways through the following code. That's -// because there are five different valid combination of signable_e, +// I believe that there are 450 pathways through the following code. +// That's because there are five different valid combination of signable_e, // separate_e, and leading_e. There are three possibilities for -// sender/receiver rdigits (too many, too few, and just right), and the same -// for ldigits. 5 * 5 * 3 * 3 = 225. +// sender/receiver rdigits (too many, too few, and just right), and the +// same for ldigits. 5 * 5 * 3 * 3 * 2 = 450. // Fasten your seat belts. -// In order to simplify processing of a signable internal sender, we are -// going to pick up the sign byte and temporarily turn off the sign bit in -// the source data. At the end, we will re
[gcc r16-3173] cobol: Implement faster zoned decimal to binary conversion.
https://gcc.gnu.org/g:67e0490922691305699fb17922e44bce304e0505 commit r16-3173-g67e0490922691305699fb17922e44bce304e0505 Author: Robert Dubner Date: Tue Aug 12 22:13:59 2025 -0400 cobol: Implement faster zoned decimal to binary conversion. Replace " value *= 10; value += digit" routines with a new one that does two digits at a time and avoids __int128 calculations until they are necessary. These changes also clean up the conversion behavior when a digit is not valid. gcc/cobol/ChangeLog: * genutil.cc (get_binary_value): Use the new routine. libgcobol/ChangeLog: * libgcobol.cc (int128_to_field): Use the new routine. (get_binary_value_local): Use the new routine. (format_for_display_internal): Formatting. (__gg__get_file_descriptor): Likewise. * stringbin.cc (string_from_combined): Formatting. (packed_from_combined): Likewise. (int_from_string): New routine. (__gg__numeric_display_to_binary): Likewise. * stringbin.h (__gg__numeric_display_to_binary): Likewise. Diff: --- gcc/cobol/genutil.cc | 256 +++ libgcobol/libgcobol.cc | 149 +--- libgcobol/stringbin.cc | 358 +++-- libgcobol/stringbin.h | 5 + 4 files changed, 436 insertions(+), 332 deletions(-) diff --git a/gcc/cobol/genutil.cc b/gcc/cobol/genutil.cc index 1c39ff19f338..e131d15d5361 100644 --- a/gcc/cobol/genutil.cc +++ b/gcc/cobol/genutil.cc @@ -752,8 +752,12 @@ get_binary_value( tree value, return; } - static tree pointer = gg_define_variable(UCHAR_P, "..gbv_pointer", vs_file_static); - static tree pend = gg_define_variable(UCHAR_P, "..gbv_pend", vs_file_static); + static tree pointer = gg_define_variable( UCHAR_P, +"..gbv_pointer", +vs_file_static); + static tree pend = gg_define_variable(UCHAR_P, +"..gbv_pend", +vs_file_static); switch(field->type) { @@ -791,8 +795,9 @@ get_binary_value( tree value, // We need to check early on for HIGH-VALUE and LOW-VALUE // Pick up the byte tree digit = gg_get_indirect_reference(source_address, NULL_TREE); - IF( digit, eq_op, build_int_cst(UCHAR, 0xFF) ) + IF( digit, eq_op, build_int_cst(UCHAR, DEGENERATE_HIGH_VALUE) ) { +// We are dealing with HIGH-VALUE if( hilo ) { gg_assign(hilo, integer_one_node); @@ -803,12 +808,14 @@ get_binary_value( tree value, build_int_cst_type( TREE_TYPE(rdigits), get_scaled_rdigits(field))); } -gg_assign(value, build_int_cst_type(TREE_TYPE(value), 0xFFFUL)); +gg_assign(value, build_int_cst_type(TREE_TYPE(value), +0x7FFFUL)); } ELSE { -IF( digit, eq_op, build_int_cst(UCHAR, 0x00) ) +IF( digit, eq_op, build_int_cst(UCHAR, DEGENERATE_LOW_VALUE) ) { + // We are dealing with LOW-VALUE if( hilo ) { gg_assign(hilo, integer_minus_one_node); @@ -816,26 +823,25 @@ get_binary_value( tree value, } ELSE { - // Establish rdigits: + // We are dealing with an ordinary NumericEdited value + gg_assign(pointer, source_address); + if( rdigits ) { gg_assign(rdigits, -build_int_cst_type( TREE_TYPE(rdigits), -get_scaled_rdigits(field))); + build_int_cst_type(TREE_TYPE(rdigits), + get_scaled_rdigits(field))); } - // Zero out the destination - gg_assign(value, gg_cast(TREE_TYPE(value), integer_zero_node)); - // Pick up a pointer to the source bytes: - - gg_assign(pointer, source_address); - - // This is the we-are-done pointer - gg_assign(pend, gg_add( pointer, - get_any_capacity(field))); - - static tree signbyte = gg_define_variable(UCHAR, "..gbv_signbyte", vs_file_static); - - // The big decision is whether or not the variable is signed: + // This will be the 128-bit value of the character sequence + static tree val128 = gg_define_variable(INT128, + "..gbv_val128", + vs_file_static); + // This is a pointer to the sign byte + static tree signp = gg_define_variable(UCHAR_P, + "..gbv_signp", +
[gcc r16-3184] cobol: Implement and use faster __gg__packed_to_binary() routine.
https://gcc.gnu.org/g:33e26a071f9daea57cb0d170d75d9fdf406040f1 commit r16-3184-g33e26a071f9daea57cb0d170d75d9fdf406040f1 Author: Robert Dubner Date: Wed Aug 13 11:17:05 2025 -0400 cobol: Implement and use faster __gg__packed_to_binary() routine. The new routine uses table lookups more effectively, and avoids __int128 arithmetic until necessary. gcc/cobol/ChangeLog: * genutil.cc (get_binary_value): Use the new routine. libgcobol/ChangeLog: * libgcobol.cc (get_binary_value_local): Use the new routine. * stringbin.cc (int_from_string): Removed. (__gg__packed_to_binary): Implement new routine. * stringbin.h (__gg__packed_to_binary): Likewise. Diff: --- gcc/cobol/genutil.cc | 60 - libgcobol/libgcobol.cc | 49 +-- libgcobol/stringbin.cc | 223 - libgcobol/stringbin.h | 5 ++ 4 files changed, 134 insertions(+), 203 deletions(-) diff --git a/gcc/cobol/genutil.cc b/gcc/cobol/genutil.cc index e131d15d5361..3682b107c5ad 100644 --- a/gcc/cobol/genutil.cc +++ b/gcc/cobol/genutil.cc @@ -755,10 +755,6 @@ get_binary_value( tree value, static tree pointer = gg_define_variable( UCHAR_P, "..gbv_pointer", vs_file_static); - static tree pend = gg_define_variable(UCHAR_P, -"..gbv_pend", -vs_file_static); - switch(field->type) { case FldLiteralN: @@ -945,7 +941,9 @@ get_binary_value( tree value, vs_file_static); if( field->attr & signable_e ) { - IF( gg_array_value(gg_cast(build_pointer_type(SCHAR), source)), lt_op, gg_cast(SCHAR, integer_zero_node) ) + IF( gg_array_value(gg_cast(build_pointer_type(SCHAR), source)), + lt_op, + gg_cast(SCHAR, integer_zero_node) ) { gg_assign(extension, build_int_cst_type(UCHAR, 0xFF)); } @@ -1028,45 +1026,23 @@ get_binary_value( tree value, case FldPacked: { - // Zero out the destination: - gg_assign(value, gg_cast(TREE_TYPE(value), integer_zero_node)); - gg_assign(pointer, get_data_address(field, field_offset)); - gg_assign(pend, -gg_add(pointer, - build_int_cst_type(SIZE_T, field->data.capacity-1))); - - // Convert all but the last byte of the packed decimal sequence - WHILE( pointer, lt_op, pend ) -{ -// Convert the first nybble -gg_assign(value, gg_multiply(value, build_int_cst_type(TREE_TYPE(value), 10))); -gg_assign(value, gg_add(value, gg_cast(TREE_TYPE(value), gg_rshift(gg_get_indirect_reference(pointer, NULL_TREE), build_int_cst(UINT, 4); - -// Convert the second nybble -gg_assign(value, gg_multiply(value, build_int_cst_type(TREE_TYPE(value), 10))); -gg_assign(value, gg_add(value, gg_cast(TREE_TYPE(value), gg_bitwise_and(gg_get_indirect_reference(pointer, NULL_TREE), build_int_cst_type(UCHAR, 0xF); -gg_increment(pointer); -} -WEND - - // This is the final byte: - gg_assign(value, gg_multiply(value, build_int_cst_type(TREE_TYPE(value), 10))); - gg_assign(value, gg_add(value, gg_cast(TREE_TYPE(value), gg_rshift(gg_get_indirect_reference(pointer, NULL_TREE), build_int_cst(UINT, 4); - - IF( gg_bitwise_and(gg_get_indirect_reference(pointer, NULL_TREE), build_int_cst_type(UCHAR, 0xF)), eq_op, build_int_cst_type(UCHAR, 0x0D) ) -{ -gg_assign(value, gg_negate(value)); -} - ELSE + if( rdigits ) { -IF( gg_bitwise_and(gg_get_indirect_reference(pointer, NULL_TREE), build_int_cst_type(UCHAR, 0xF)), eq_op, build_int_cst_type(UCHAR, 0x0B) ) - { - gg_assign(value, gg_negate(value)); - } -ELSE - ENDIF +gg_assign(rdigits, + build_int_cst_type( TREE_TYPE(rdigits), + get_scaled_rdigits(field))); } -ENDIF + tree dest_type = TREE_TYPE(value); + + gg_assign(value, +gg_cast(dest_type, +gg_call_expr(INT128, +"__gg__packed_to_binary", +get_data_address( field, + field_offset), +build_int_cst_type(INT, + field->data.capacity), +NULL_TREE))); break; } diff --git a/libgcobol/libgcobol.cc b/libgcobol/libgcobol.cc index f41434f9f3a0..427625366810 100644 --- a/libgcobol/libgcobol.cc +++ b/libgcobol/libgcob
[gcc r16-3087] cobol: Divide-and-conquer conversion from binary to packed-decimal.
https://gcc.gnu.org/g:435e09e05c3750cad153c3c6e83134803c22c7f6 commit r16-3087-g435e09e05c3750cad153c3c6e83134803c22c7f6 Author: Robert Dubner Date: Fri Aug 8 13:04:53 2025 -0400 cobol: Divide-and-conquer conversion from binary to packed-decimal. The legacy routine for converting a binary integer to a packed-decimal representaion peeled two digits at a time from the bottom of an _int128 value. These changes replace that routine with a divide-and-conquer algorithm that runs about ten times faster. libgcobol/ChangeLog: * libgcobol.cc (int128_to_field): Switch to the new routine. * stringbin.cc (packed_from_combined): Implement the new routine. (__gg__binary_to_packed): Likewise. * stringbin.h (__gg__binary_to_packed): Likewise. Diff: --- libgcobol/libgcobol.cc | 70 --- libgcobol/stringbin.cc | 147 + libgcobol/stringbin.h | 5 ++ 3 files changed, 175 insertions(+), 47 deletions(-) diff --git a/libgcobol/libgcobol.cc b/libgcobol/libgcobol.cc index a7b4b5599908..eac6e3164198 100644 --- a/libgcobol/libgcobol.cc +++ b/libgcobol/libgcobol.cc @@ -1719,34 +1719,27 @@ int128_to_field(cblc_field_t *var, case FldPacked: { -static const unsigned char bin2pd[100] = - { - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, - 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, - 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, - 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, - 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, - 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, - } ; - // Convert the binary value to packed decimal. +int digits = var->digits; -// Set the destination bytes to zero -memset(location, 0, length); +// Assume for the moment that the res unsigned char sign_nybble = 0; -if( !(var->attr & packed_no_sign_e) ) +if( var->attr & packed_no_sign_e ) + { + // This is COMP-6 packed decimal, with no sign nybble + sign_nybble = 0; + } +else { // This is COMP-3 packed decimal, so we need to make room to the // right of the final decimal digit for the sign nybble: value *= 10; + digits += 1; // Figure out what the sign nybble is going to be, and make the // the value positive: if(var->attr & signable_e) { +// It is signable, so 0xD for negative, and 0xC for positive if(value < 0) { sign_nybble = 0x0D; @@ -1759,6 +1752,7 @@ int128_to_field(cblc_field_t *var, } else { +// The value is not signable, so the sign nybble is 0xF sign_nybble = 0x0F; if(value < 0) { @@ -1766,43 +1760,25 @@ int128_to_field(cblc_field_t *var, } } } -// ploc points to the current rightmost byte of the location: -unsigned char *ploc = location + length -1 ; -// Build the target from right to left, so that the result is -// big-endian: -while( value && ploc >= location ) - { - *ploc-- = bin2pd[value%100]; - value /= 100; - } +/* We need to check if the value is too big, in case our caller +wants to check for the error condition. In any event, we need +to make sure the value actually fits, because otherwise the +result might have a bad high-place digit for a value with an +odd number of places. */ +__int128 mask = __gg__power_of_ten(digits); +size_error = !!(value / mask); +value %= mask; + +// We are now set up to do the conversion: +__gg__binary_to_packed(location, digits, value); + // We can put the sign nybble into place at this point. Note that // for COMP-6 numbers the sign_nybble value is zero, so the next // operation is harmless. location[length -1] |= sign_nybble; -// If we still have value left, we have a size
[gcc r16-3222] cobol: Eliminate a run-time structure type that is no longer used.
https://gcc.gnu.org/g:87f354ca75361faa2f40b826d632fbc49a082553 commit r16-3222-g87f354ca75361faa2f40b826d632fbc49a082553 Author: Robert Dubner Date: Thu Aug 14 09:49:46 2025 -0400 cobol: Eliminate a run-time structure type that is no longer used. gcc/cobol/ChangeLog: * genapi.h (parser_call_exception_end): Remove obsolete comment. * structs.cc (create_cbl_enabled_exception_t): Remove cbl_enabled_exception_type_node; remove create_cbl_enabled_exception_t(). (create_our_type_nodes): Likewise. * structs.h (GTY): Likewise. Diff: --- gcc/cobol/genapi.h | 2 -- gcc/cobol/structs.cc | 25 - gcc/cobol/structs.h | 1 - 3 files changed, 28 deletions(-) diff --git a/gcc/cobol/genapi.h b/gcc/cobol/genapi.h index b41b906aa697..b86be8e97909 100644 --- a/gcc/cobol/genapi.h +++ b/gcc/cobol/genapi.h @@ -536,8 +536,6 @@ void parser_exception_raise(ec_type_t ec); void parser_call_exception( cbl_label_t *name ); void parser_call_exception_end( cbl_label_t *name ); -//void parser_stash_exceptions(const cbl_enabled_exceptions_array_t *enabled); - void parser_match_exception(cbl_field_t *index); void parser_check_fatal_exception(); void parser_clear_exception(); diff --git a/gcc/cobol/structs.cc b/gcc/cobol/structs.cc index 7a4db97ea483..2393dfbe5b92 100644 --- a/gcc/cobol/structs.cc +++ b/gcc/cobol/structs.cc @@ -156,7 +156,6 @@ tree cblc_field_p_type_node; tree cblc_field_pp_type_node; tree cblc_file_type_node; tree cblc_file_p_type_node; -tree cbl_enabled_exception_type_node; tree cblc_goto_type_node; // The following functions return type_decl nodes for the various structures @@ -288,29 +287,6 @@ typedef struct cblc_file_t return retval; } -static tree -create_cbl_enabled_exception_t() -{ -/* -struct cbl_enabled_exception_t -{ -bool enabled, location; -ec_type_t ec; -size_t file; -}; -*/ -tree retval = NULL_TREE; -retval = gg_get_filelevel_struct_type_decl( "cbl_enabled_exception_t", -4, -BOOL, "enabled", -BOOL, "location", -UINT, "ec", -SIZE_T, "file"); -retval = TREE_TYPE(retval); - -return retval; -} - void create_our_type_nodes() { @@ -323,7 +299,6 @@ create_our_type_nodes() cblc_field_pp_type_node = build_pointer_type(cblc_field_p_type_node); cblc_file_type_node = create_cblc_file_t(); cblc_file_p_type_node = build_pointer_type(cblc_file_type_node); -cbl_enabled_exception_type_node = create_cbl_enabled_exception_t(); } } diff --git a/gcc/cobol/structs.h b/gcc/cobol/structs.h index 1a16523dcb6b..47a78b45e9a8 100644 --- a/gcc/cobol/structs.h +++ b/gcc/cobol/structs.h @@ -54,7 +54,6 @@ extern GTY(()) tree cblc_field_p_type_node; extern GTY(()) tree cblc_field_pp_type_node; extern GTY(()) tree cblc_file_type_node; extern GTY(()) tree cblc_file_p_type_node; -extern GTY(()) tree cbl_enabled_exception_type_node; extern GTY(()) tree cblc_goto_type_node; extern void create_our_type_nodes();
[gcc r16-3221] real: Eliminate access to uninitialized memory.
https://gcc.gnu.org/g:810340f9fed56dc2a0e7e1db3f19b383f6e4cb95 commit r16-3221-g810340f9fed56dc2a0e7e1db3f19b383f6e4cb95 Author: Robert Dubner Date: Thu Jul 31 07:45:26 2025 -0400 real: Eliminate access to uninitialized memory. When compiling this program with gcobol: identification division. program-id. prog. data division. working-storage section. 01 val pic v9(5) value .001. procedure division. display val goback. the rounding up of .9... to 1.000... causes a read of the first byte of the output buffer. Although harmless, it generates a valgrind warning. The following change clears that warning. gcc/ChangeLog: * real.cc (real_to_decimal_for_mode): Set str[0] to known value. Diff: --- gcc/real.cc | 5 + 1 file changed, 5 insertions(+) diff --git a/gcc/real.cc b/gcc/real.cc index 1f987d48889f..43d25246ed7c 100644 --- a/gcc/real.cc +++ b/gcc/real.cc @@ -1629,6 +1629,11 @@ real_to_decimal_for_mode (char *str, const REAL_VALUE_TYPE *r_orig, strcpy (str, (r.sign ? "-0.0" : "0.0")); return; case rvc_normal: + /* When r_orig is a positive value that converts to all nines and is + rounded up to 1.0, str[0] is harmlessly accessed before being set to + '1'. That read access triggers a valgrind warning. Setting str[0] + to any value quiets the warning. */ + str[0] = ' '; break; case rvc_inf: strcpy (str, (r.sign ? "-Inf" : "+Inf"));
[gcc r16-3072] cobol: Improve binary-to-string conversion.
https://gcc.gnu.org/g:c684053fc0f0a159f4ddbc7d023fdcc61752b58d commit r16-3072-gc684053fc0f0a159f4ddbc7d023fdcc61752b58d Author: Robert Dubner Date: Thu Aug 7 15:52:02 2025 -0400 cobol: Improve binary-to-string conversion. COBOL often requires the conversion of binary integers to string of characters. These changes replace a naive routine that peels decimal digits from a binary value one digit at a time, with a divide-and-conquer algorithm that is twice as fast even for a couple of digits, and is about eight times faster past ten digits. Included here are some minor fixes to the lexer and parser. gcc/cobol/ChangeLog: * cbldiag.h (location_dump): Source code formatting. * parse.y: error_msg formatting. * scan.l: Remove UTF-8 character from regex pattern. * scan_ante.h (numstr_of): error_msg formatting. * show_parse.h (class ANALYZE): Suppress cppcheck error. * util.cc (cbl_field_t::report_invalid_initial_value): error_msg formatting. libgcobol/ChangeLog: * Makefile.am: Include new stringbin.cc file. * Makefile.in: Regenerated. * libgcobol.cc (__gg__power_of_ten): Improve error message. (__gg__binary_to_string): Deleted. (__gg__binary_to_string_internal): Deleted. (int128_to_field): Use new conversion routine. (__gg__move): Use new conversion routine. * stringbin.cc: New file. Implements new conversion routine. * stringbin.h: New file. Likewise. Diff: --- gcc/cobol/cbldiag.h| 4 +- gcc/cobol/parse.y | 4 +- gcc/cobol/scan.l | 2 +- gcc/cobol/scan_ante.h | 2 +- gcc/cobol/show_parse.h | 2 +- gcc/cobol/util.cc | 4 +- libgcobol/Makefile.am | 1 + libgcobol/Makefile.in | 4 +- libgcobol/libgcobol.cc | 68 ++ libgcobol/stringbin.cc | 330 + libgcobol/stringbin.h | 42 +++ 11 files changed, 397 insertions(+), 66 deletions(-) diff --git a/gcc/cobol/cbldiag.h b/gcc/cobol/cbldiag.h index dd16190fbd87..2554deb96447 100644 --- a/gcc/cobol/cbldiag.h +++ b/gcc/cobol/cbldiag.h @@ -122,8 +122,8 @@ static void location_dump( const char func[], int line, const char tag[], const LOC& loc) { extern int yy_flex_debug; // cppcheck-suppress shadowVariable if( yy_flex_debug ) { -const char *detail = gcobol_getenv("update_location"); // cppcheck-suppress knownConditionTrueFalse -if( detail ) { +const char *detail = gcobol_getenv("update_location"); +if( detail ) { // cppcheck-suppress knownConditionTrueFalse fprintf(stderr, "%s:%d: %s location (%d,%d) to (%d,%d)\n", func, line, tag, loc.first_line, loc.first_column, loc.last_line, loc.last_column); diff --git a/gcc/cobol/parse.y b/gcc/cobol/parse.y index fae96ed5c718..59cc64ddeca4 100644 --- a/gcc/cobol/parse.y +++ b/gcc/cobol/parse.y @@ -10336,8 +10336,8 @@ intrinsic: function_udf if( p != NULL ) { auto loc = symbol_field_location(field_index(p->field)); error_msg(loc, "FUNCTION %qs has " - "inconsistent parameter type %td (%qs)", - keyword_str($1), p - args.data(), name_of(p->field) ); + "inconsistent parameter type %ld (%qs)", + keyword_str($1), (long)(p - args.data()), name_of(p->field) ); YYERROR; } $$ = is_numeric(args[0].field)? diff --git a/gcc/cobol/scan.l b/gcc/cobol/scan.l index ba4c044e15e3..5773f09a9704 100644 --- a/gcc/cobol/scan.l +++ b/gcc/cobol/scan.l @@ -123,7 +123,7 @@ NUMEDCHAR [BPVZ90/,]+{COUNT}? NUMEDCHARS {NUMEDCHAR}([.]?{NUMEDCHAR})* NUMED ([+-]{NUMEDCHARS}+)|({NUMEDCHARS}+[+-]) CURRENCY [A-Zfhijklmoqtuwy\x80-\xFF]{-}[ABCDEGNPRSVXZ] -NUMEDCUR (([.]?[-$0B/Z*+,P9()V+–]|{CURRENCY}+|{COUNT})+([.][$0B/Z*+P9()V+\–])*)+ +NUMEDCUR (([.]?[$0B/Z*+,P9()V+-]|{CURRENCY}+|{COUNT})+([.][$0B/Z*+P9()V+-])*)+ NUMEDITED {NUMED}|{NUMEDCUR} EDITED {ALPHED}|{NUMED}|{NUMEDCUR} diff --git a/gcc/cobol/scan_ante.h b/gcc/cobol/scan_ante.h index 31093a68350f..c00826d652fd 100644 --- a/gcc/cobol/scan_ante.h +++ b/gcc/cobol/scan_ante.h @@ -149,7 +149,7 @@ numstr_of( const char string[], radix_t radix = decimal_e ) { } auto nx = std::count_if(input, p, fisdigit); if( 36 < nx ) { - error_msg(yylloc, "significand of %s has more than 36 digits (%td)", input, nx); + error_msg(yylloc, "significand of %s has more than 36 digits (%ld)", input, (long)nx); return NO_CONDITION; } diff --git a/gcc/cobol/show_parse.h b/gcc/cobol/show_parse.h index bd0e16fe8332..e1a8cb21b6f7 100644 --- a/gcc/cobol/show_parse.h +++ b/gcc/cobol/show_parse.h @@ -500,7 +500,7 @@ class ANALYZE
[gcc r16-3603] cobol: Improved handling of COBOL Special Registers.
https://gcc.gnu.org/g:dc20fa683d8cd46cc73407de1a24f1a2875102c5 commit r16-3603-gdc20fa683d8cd46cc73407de1a24f1a2875102c5 Author: Robert Dubner Date: Fri Sep 5 10:41:08 2025 -0400 cobol: Improved handling of COBOL Special Registers. COBOL Special Registers (e.g., RETURN-CODE; DEBUG-ITEM) are implemented as global variables. These changes define them with the prefix "__ggsr__" in their variable names so that the GDB-COBOL debugger can identify them. The creation and handling of such variables has been streamlined with the introduction of the "register_e" cbl_field_t::attr bit. gcc/cobol/ChangeLog: * genapi.cc (trace1_init): Prepend two internal variables with underscore. (initialize_variable_internal): Use new register_e attribute. (psa_global): Use "__ggsr__" prefix to identify special registers (parser_symbol_add): Use new register_e attribute. * symbols.cc (cbl_field_attr_str): Likewise. (symbol_table_init): Likewise. (is_register_field): Eliminated in favor of (attr & register_e). * symbols.h (is_register_field): Likewise. libgcobol/ChangeLog: * common-defs.h (enum cbl_field_attr_t): Define register_e. * constants.cc (struct cblc_field_t): Define special registers with "__ggsr__" prefix. Diff: --- gcc/cobol/genapi.cc | 38 +++--- gcc/cobol/symbols.cc| 85 + gcc/cobol/symbols.h | 2 - libgcobol/common-defs.h | 2 +- libgcobol/constants.cc | 330 +--- 5 files changed, 364 insertions(+), 93 deletions(-) diff --git a/gcc/cobol/genapi.cc b/gcc/cobol/genapi.cc index 40b79ba5ce6c..11242c19285d 100644 --- a/gcc/cobol/genapi.cc +++ b/gcc/cobol/genapi.cc @@ -203,8 +203,8 @@ trace1_init() if( first_time ) { first_time = false; -trace_handle = gg_define_variable(INT, "trace_handle", vs_static); -trace_indent = gg_define_variable(INT, "trace_indent", vs_static); +trace_handle = gg_define_variable(INT, "_trace_handle", vs_static); +trace_indent = gg_define_variable(INT, "_trace_indent", vs_static); bTRACE1 = getenv("GCOBOL_TRACE") ? getenv("GCOBOL_TRACE") :gv_trace_switch; @@ -1227,7 +1227,7 @@ initialize_variable_internal( cbl_refer_t refer, return; } - if( is_register_field( parsed_var) ) + if( parsed_var->attr & register_e ) { return; } @@ -16374,10 +16374,6 @@ actually_create_the_static_field( cbl_field_t *new_var, static void psa_global(cbl_field_t *new_var) { - char *mname = cobol_name_mangler(new_var->name); - char ach[2*sizeof(cbl_name_t)]; - sprintf(ach, "__gg__%s", mname); - free(mname); if( strcmp(new_var->name, "_VERY_TRUE") == 0 ) { @@ -16390,10 +16386,20 @@ psa_global(cbl_field_t *new_var) return; } - // global variables already have a cblc_field_t defined in constants.cc + // global variables already have a cblc_field_t defined in constants.cc. - strcpy(ach, "__gg__"); - strcat(ach, new_var->name); + // Finding their name is done by converting to lowercase, dashes become + // underscores, and "__ggsr__" is prepended. "filler" gets ignored. + + // To feed GDB-COBOL's requirements, we tack on this variable's index and + // this program's index number: + + char ach[2*sizeof(cbl_name_t)]; + + snprintf( ach, +sizeof(ach), +"__ggsr__%s", +new_var->name); for(size_t i=0; iname, "RETURN-CODE") == 0 ) -{ -strcpy(ach, "__gg__return_code"); -} - - if( strcmp(new_var->name, "UPSI-0") == 0 ) -{ -strcpy(ach, "__gg__upsi"); -} - new_var->var_decl_node = gg_declare_variable(cblc_field_type_node, ach, NULL, vs_external_reference); // global variables already have a .data area defined. We can find that @@ -16857,7 +16853,7 @@ parser_symbol_add(struct cbl_field_t *new_var ) { cbl_field_type_t incoming_type = new_var->type; -if( is_register_field(new_var) ) +if( new_var->attr & register_e ) { psa_global(new_var); goto done; diff --git a/gcc/cobol/symbols.cc b/gcc/cobol/symbols.cc index bbe99b6801f6..205465b2c64d 100644 --- a/gcc/cobol/symbols.cc +++ b/gcc/cobol/symbols.cc @@ -741,7 +741,7 @@ cbl_field_attr_str( cbl_field_attr_t attr ) { case function_e: return "function"; case quoted_e: return "quoted"; case filler_e: return "filler"; - case _spare_e: return "temporary"; + case register_e: return "register"; case intermediate_e: return "intermediate"; case embiggened_e: return "embiggened"; case all_alpha_e: return "all_alpha"; @@ -2153,34 +2153,34 @@ symbol_table_init(void) { // These should match the definitions in libgcobol/constants.cc static cbl_field_t constants[] = { -{ 0, FldAlphanumeric, FldInvalid, space_value_e | constq, 0, 0, 0, nonarray, 0, +{ 0, FldAlphanumeric, FldI
[gcc r16-3292] cobol: Eliminate errors that cause valgrind messages.
https://gcc.gnu.org/g:e78eb2f85b9b61cf193dfc721bbd58966bea76df commit r16-3292-ge78eb2f85b9b61cf193dfc721bbd58966bea76df Author: Robert Dubner Date: Tue Aug 19 23:08:48 2025 -0400 cobol: Eliminate errors that cause valgrind messages. gcc/cobol/ChangeLog: * genutil.cc (get_binary_value): Fix a comment. * parse.y: udf_args_valid(): Fix loc calculation. * symbols.cc (assert): extend_66_capacity(): Avoid assert(e < e2) in -O0 build until symbol_table expansion is fixed. libgcobol/ChangeLog: * libgcobol.cc (format_for_display_internal): Handle NumericDisplay properly. (compare_88): Fix memory access error. (__gg__unstring): Likewise. Diff: --- gcc/cobol/genutil.cc | 2 +- gcc/cobol/parse.y | 5 - gcc/cobol/symbols.cc | 10 + libgcobol/libgcobol.cc | 61 ++ 4 files changed, 47 insertions(+), 31 deletions(-) diff --git a/gcc/cobol/genutil.cc b/gcc/cobol/genutil.cc index 3682b107c5ad..4b296e46e877 100644 --- a/gcc/cobol/genutil.cc +++ b/gcc/cobol/genutil.cc @@ -819,7 +819,7 @@ get_binary_value( tree value, } ELSE { - // We are dealing with an ordinary NumericEdited value + // We are dealing with an ordinary NumericDisplay value gg_assign(pointer, source_address); if( rdigits ) diff --git a/gcc/cobol/parse.y b/gcc/cobol/parse.y index 59cc64ddeca4..039cb957de0c 100644 --- a/gcc/cobol/parse.y +++ b/gcc/cobol/parse.y @@ -11959,7 +11959,10 @@ current_t::udf_args_valid( const cbl_label_t *L, if( arg.field ) { // else omitted auto tgt = cbl_field_of(symbol_at(udf.linkage_fields.at(i).isym)); if( ! valid_move(tgt, arg.field) ) { - auto loc = symbol_field_location(field_index(arg.field)); + auto loc = current_location; +if( ! is_temporary(arg.field) ) { + loc = symbol_field_location(field_index(arg.field)); +} error_msg(loc, "FUNCTION %s argument %zu, '%s' cannot be passed to %s, type %s", L->name, i, arg.field->pretty_name(), tgt->pretty_name(), 3 + cbl_field_type_str(tgt->type) ); diff --git a/gcc/cobol/symbols.cc b/gcc/cobol/symbols.cc index f2cd1b55f802..bbe99b6801f6 100644 --- a/gcc/cobol/symbols.cc +++ b/gcc/cobol/symbols.cc @@ -1598,7 +1598,17 @@ extend_66_capacity( cbl_field_t *alias ) { symbol_elem_t *e = symbol_at(alias->parent); symbol_elem_t *e2 = reinterpret_cast(const_cast(alias->data.picture)); +#ifndef __OPTIMIZE__ +#pragma message "The assert(e < e2) needs fixing" + // The following assert fails when valgrind is involved. This is the known + // problem of expecting mmap() to put new memory maps after older memory + // maps; that assumption fails when valgrind is involved. + + // For now I am defeating the assert when using -O0 so that I can run the + // NIST "make valgrind" tests. But this should be fixed so that the + // symbol table index is used, not the entry locations. assert(e < e2); +#endif alias->data.picture = NULL; capacity_of cap; diff --git a/libgcobol/libgcobol.cc b/libgcobol/libgcobol.cc index 427625366810..1b54cfdc3894 100644 --- a/libgcobol/libgcobol.cc +++ b/libgcobol/libgcobol.cc @@ -2990,6 +2990,9 @@ format_for_display_internal(char **dest, { // Because a NumericDisplay can have any damned thing as a character, // we are going force things that aren't digits to display as '0' + + // 0xFF is an exception, so that a HIGH-VALUE in a numeric display shows + // up in a unique way. static const uint8_t ascii_chars[256] = { '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', // 0x00 @@ -3007,7 +3010,7 @@ format_for_display_internal(char **dest, '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', // 0xc0 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', // 0xd0 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', // 0xe0 -'0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', // 0xf0 +'0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 0xFF, // 0xf0 }; static const uint8_t ebcdic_chars[256] = { @@ -3026,7 +3029,7 @@ format_for_display_internal(char **dest, 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0, // 0xc0 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0, // 0xd0 0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0, // 0xe0 - 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0, // 0xf0 + 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9