https://gcc.gnu.org/g:8280b3ff920fc6b1c72fdbe44e6f388eb0955865
commit r17-5675-g8280b3ff920fc6b1c72fdbe44e6f388eb0955865 Author: Robert Dubner <[email protected]> Date: Wed Oct 28 12:40:40 2026 -0400 cobol: Initialize WHEN-COMPILED; make check-cobol is now parallelizable. gcc/cobol/ChangeLog: * Make-lang.in: Enable parallel computing for "make check-cobol"/ * genapi.cc (parser_enter_file): Initialize WHEN-COMPILED. (parser_intrinsic_call_0): Likewise. (parser_symbol_add): Likewise. Diff: --- gcc/cobol/Make-lang.in | 3 +++ gcc/cobol/genapi.cc | 42 ++++++++++++++++++++++++++++++++++-------- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/gcc/cobol/Make-lang.in b/gcc/cobol/Make-lang.in index 76505b07af9e..e22418dd4ca2 100644 --- a/gcc/cobol/Make-lang.in +++ b/gcc/cobol/Make-lang.in @@ -396,4 +396,7 @@ cobol.stagefeedback: stagefeedback-start selftest-cobol: lang_checks += check-cobol +lang_checks_parallelized += check-cobol +# For description see the check_$lang_parallelize comment in gcc/Makefile.in. +check_cobol_parallelize = 10000 diff --git a/gcc/cobol/genapi.cc b/gcc/cobol/genapi.cc index f4350c0833fe..09e89c6d2bf9 100644 --- a/gcc/cobol/genapi.cc +++ b/gcc/cobol/genapi.cc @@ -65,6 +65,10 @@ extern int yylineno; +// This timespec, established just once in parser_enter_file, is used by +// both the WHEN_COMPILED variable, and the intrinsic FUNCITON WHEN-COMPILED. +static struct timespec compilation_tp; + #define TSI_BACK (tsi_last(current_function->statement_list_stack.back())) extern char *cobol_name_mangler(const char *cobol_name); @@ -2849,6 +2853,17 @@ parser_enter_file(const char *filename) SHOW_PARSE_END } + static bool first_time = true; + if( first_time ) + { + first_time = false; + // Here is where we calculate a common WHEN-COMPILED string to be used + // both by the WHEN-COMPILED variable and the FUNCTION WHEN-COMPILED + uint64_t now = get_time_nanoseconds(); + compilation_tp.tv_sec = now / 1000000000; + compilation_tp.tv_nsec = now % 1000000000; + } + current_filename.push_back(filename); std::unordered_map<std::string, std::string>::const_iterator it @@ -10933,18 +10948,13 @@ parser_intrinsic_call_0(cbl_field_t *tgt, } else if( strcmp(function_name, "__gg__when_compiled") == 0 ) { - // Pass __gg__when_compiled() the time from right now. - struct timespec tp; - uint64_t now = get_time_nanoseconds(); - tp.tv_sec = now / 1000000000; - tp.tv_nsec = now % 1000000000; - + // Pass __gg__when_compiled() the time from parser_enter_file store_location_stuff(function_name); gg_call(VOID, function_name, gg_get_address_of(tgt->var_decl_node), - build_int_cst(SIZE_T, tp.tv_sec), - build_int_cst(LONG, tp.tv_nsec), + build_int_cst(SIZE_T, compilation_tp.tv_sec), + build_int_cst(LONG, compilation_tp.tv_nsec), NULL_TREE); } else @@ -15410,6 +15420,22 @@ parser_symbol_add(struct cbl_field_t *new_var ) trap_here = false; } + if( strcmp(new_var->name, "WHEN-COMPILED") == 0 ) + { + // Convert the epoch seconds + struct tm tm = {}; + localtime_r(&compilation_tp.tv_sec, &tm); + snprintf(const_cast<char *>(new_var->data.initial), + 17, + "%2.2d/%2.2d/%2.2d%2.2d.%2.2d.%2.2d", + static_cast<unsigned int>(tm.tm_mon + 1), + static_cast<unsigned int>(tm.tm_mday), + static_cast<unsigned int>(tm.tm_year % 100), + static_cast<unsigned int>(tm.tm_hour), + static_cast<unsigned int>(tm.tm_min), + static_cast<unsigned int>(tm.tm_sec)); + } + switch( new_var->type ) { static int counter=1;
