]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
6 days agocobol: Honor the "-static" command-line option. [PR119231]
Robert Dubner [Thu, 24 Jul 2025 16:09:36 +0000 (12:09 -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)

6 days agocobol: Tweak adjustments to location_t of GENERIC nodes for PERFORM.
Robert Dubner [Wed, 23 Jul 2025 12:44:54 +0000 (08:44 -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)

6 days agocobol: Improved linemap and diagnostic handling; PIC validation. [PR120402]
Robert Dubner [Mon, 21 Jul 2025 16:58:47 +0000 (12:58 -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 <jklowden@cobolworx.com>
Co-Authored-By: Robert Dubner <rdubner@symas.com>
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): Likewise.
(gg_call): Likewise.
(gg_call_expr_list): Likewise.
(gg_exit): Likewise.
(gg_abort): Likewise.
(gg_strlen): Likewise.
(gg_strdup): Likewise.
(gg_malloc): Likewise.
(gg_realloc): Likewise.
(gg_free): Likewise.
(gg_set_current_line_number): Likewise.
(gg_get_current_line_number): Likewise.
(gg_insert_into_assembler): Likewise.
(token_location_override): Likewise.
(gg_token_location): Likewise.
* gengen.h (location_from_lineno): Likewise.
(gg_set_current_line_number): Likewise.
(gg_get_current_line_number): Likewise.
(gg_token_location): Likewise.
(current_token_location): Likewise.
(current_location_minus_one): Likewise.
(current_location_minus_one_clear): Likewise.
(token_location_override): Likewise.
* genmath.cc (fast_divide):  const attribute for formal parameter.
* genutil.cc (get_and_check_refstart_and_reflen): Likewise.
(get_data_offset): Likewise.
(refer_refmod_length): Likewise.
(refer_offset): Likewise.
(refer_size): Likewise.
(refer_size_dest): Likewise.
(refer_size_source): Likewise.
(qualified_data_location): Likewise.
* genutil.h (refer_offset): Likewise.
(refer_size_source): Likewise.
(refer_size_dest): Likewise.
(qualified_data_location): Likewise.
* parse.y: EVALUATE token; Implement EXHIBIT verb;
Improved linemap handling.
* parse_ante.h (input_file_status_notify): Improved linemap handling.
(location_set): Likewise.
* scan.l: PICTURE string validation.
* scan_ante.h (class picture_t): PICTURE string validation.
(validate_picture): Likewise.
* symbols.cc (symbol_currency): Revised default currency handling.
* symbols.h (symbol_currency): Likewise.
* util.cc (location_from_lineno): Improved linemap handling.
(current_token_location): Improved linemap handling.
(current_location_minus_one): Improved linemap handling.
(current_location_minus_one_clear): Improved linemap handling.
(gcc_location_set_impl): Improved linemap handling.
(warn_msg): Improved linemap handling.
* util.h (cobol_lineno): Improved linemap handling.

(cherry picked from commit 7c1d08860796d4c1ff6fc8c5e8e8462e9ee8f7fc)

6 days agocobol: Eliminate cppcheck warnings in gcc/cobol .cc files.
Robert Dubner [Mon, 14 Jul 2025 20:41:35 +0000 (16:41 -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)

6 days agocobol: Minor changes to genapi.cc to eliminate CPPCHECK warnings.
Robert Dubner [Fri, 11 Jul 2025 21:11:21 +0000 (17:11 -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)

6 days agocobol: Fix build on 32-bit Darwin [PR120621]
Rainer Orth [Fri, 11 Jul 2025 07:56:18 +0000 (09:56 +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);
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~         ~~
      |                                                                                   |
      |                                                                                   int

Fixed in the same way.

Bootstrapped without regressions on i386-apple-darwin15,
x86_64-apple-darwin, i386-pc-solaris2.11, amd64-pc-solaris2.11,
i686-pc-linux-gnu, and x86_64-pc-linux-gnu.

2025-06-23  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

gcc/cobol:
PR cobol/120621
* lexio.cc (parse_replace_pairs): Cast mfile.lineno() to fmt_size_t.
* parse.y (intrinsic): Print ptrdiff_t using %ld, cast arg to long.
* scan_ante.h (numstr_of): Print nx using %ld, cast arg to long.
* util.cc (cbl_field_t::report_invalid_initial_value): Print
ptrdiff_t using %ld, cast arg to long.

(cherry picked from commit 3e7dd06860bf0589bc743e458b16bd1d33d73835)

6 days agocobol: Add PUSH and POP to CDF.
James K. Lowden [Wed, 9 Jul 2025 22:14:40 +0000 (18:14 -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)

6 days agocobol: Development round-up. [PR120765, PR119337, PR120794]
Robert Dubner [Wed, 9 Jul 2025 16:24:38 +0000 (12:24 -0400)] 
cobol: Development round-up. [PR120765, PR119337, PR120794]

This collection of changes reflects development by both Jim Lowden and Bob
Dubner.  It includes fixes to the cobcd script; refinements to the multiple-
period syntax; changes to the parser; implementation of DISPLAY/ACCEPT to and
from ENVIRONMENT-NAME, ENVIRONMENT-VALUE, ARGUMENT-NUMBER, ARGUMENT-VALUE and
minor changes to genapi.cc to cut down on the number of cppcheck warnings.

Co-authored-by: James K. Lowden <jklowden@cobolworx.com>
Co-authored-by: Robert Dubner <rdubner@symas.com>
gcc/cobol/ChangeLog:

PR cobol/120765
PR cobol/119337
PR cobol/120794
* Make-lang.in: Take control of the .cc.o rule.
* cbldiag.h (error_msg_direct): New declaration.
(gcc_location_dump): Forward declaration.
(location_dump): Use gcc_location_dump.
* cdf.y: Change some tokens.
* gcobc: Change dialect handling.
* genapi.cc (parser_call_targets_dump): Temporarily remove from service.
(parser_compile_dcls): Combine temporary arrays.
(get_binary_value_from_float): Apply const to one parameter.
(depending_on_value): Localize a boolean variable.
(normal_normal_compare): Likewise.
(cobol_compare): Eliminate cppcheck warning.
(combined_name): Apply const to an input parameter.
(parser_perform): Apply const to a variable.
(parser_accept): Improve handling of special_name_t parameter and
the exception conditions.
(parser_display): Improve handling of speciat_name_t parameter; use the
os_filename[] string when appropriate.
(program_end_stuff): Rename shadowing variable.
(parser_division): Consolidate temporary char[] arrays.
(parser_file_start): Apply const to a parameter.
(inspect_replacing): Likewise.
(parser_program_hierarchy): Rename shadowing variable.
(mh_identical): Apply const to parameters.
(float_type_of): Likewise.
(picky_memcpy): Likewise.
(mh_numeric_display): Likewise.
(mh_little_endian): Likewise.
(mh_source_is_group): Apply static to a variable it.
(move_helper): Quiet a cppcheck warning.
* genapi.h (parser_accept): Add exceptions to declaration.
(parser_accept_under_discussion): Add declaration.
(parser_display): Change to std::vector; add exceptions to declaration.
* lexio.cc (cdf_source_format): Improve source code location handling.
(source_format_t::infer): Likewise.
(is_fixed_format): Likewise.
(is_reference_format): Likewise.
(left_margin): Likewise.
(right_margin): Likewise.
(cobol_set_indicator_column): Likewise.
(include_debug): Likewise.
(continues_at): Likewise.
(indicated): Likewise.
(check_source_format_directive): Likewise.
(cdftext::free_form_reference_format): Likewise.
* parse.y: Tokens; program and function names; DISPLAY and ACCEPT
handling.
* parse_ante.h (class tokenset_t): Removed.
(class current_tokens_t): Removed.
(field_of): Removed.
* scan.l: Token handling.
* scan_ante.h (level_found): Comment.
* scan_post.h (start_condition_str): Remove cast author_state:.
* symbols.cc (symbols_update): Change error message.
(symbol_table_init): Correct and reorder entries.
(symbol_unresolved_file_key): New function definition.
(cbl_file_key_t::deforward): Change error message.
* symbols.h (symbol_unresolved_file_key): New declaration.
(keyword_tok): New function.
(redefined_token): New function.
(class current_tokens_t): New class.
* symfind.cc (symbol_match): Revise error message.
* token_names.h: Reorder and change numbers in comments.
* util.cc (class cdf_directives_t): New class.
(cobol_set_indicator_column): New function.
(cdf_source_format): New function.
(gcc_location_set_impl): Improve column handling in token_location.
(gcc_location_dump): New function.
(class temp_loc_t): Modify constructor.
(error_msg_direct): New function.
* util.h (class source_format_t): New class.

libgcobol/ChangeLog:

* libgcobol.cc (__gg__accept_envar): ACCEPT/DISPLAY environment variables.
(accept_envar): Likewise.
(default_exception_handler): Refine system log entries.
(open_syslog): Likewise.
(__gg__set_env_name): ACCEPT/DISPLAY environment variables.
(__gg__get_env_name): ACCEPT/DISPLAY environment variables.
(__gg__get_env_value): ACCEPT/DISPLAY environment variables.
(__gg__set_env_value): ACCEPT/DISPLAY environment variables.
(__gg__fprintf_stderr): Adjust __attribute__ for printf.
(__gg__set_arg_num): ACCEPT/DISPLAY command-line arguments.
(__gg__accept_arg_value): ACCEPT/DISPLAY command-line arguments.
(__gg__get_file_descriptor): DISPLAY on os_filename[] /dev device.

(cherry picked from commit 069bf2fe31e99f0415ddb6acaf76cfb6eee8bb6a)

6 days agocobol: Respect error in cobol.install-common.
James K. Lowden [Tue, 1 Jul 2025 17:51:44 +0000 (13:51 -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)

6 days agocobol: Repair printf format of size_t.
Robert Dubner [Tue, 1 Jul 2025 16:02:21 +0000 (12:02 -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)

6 days agocobol: Update test case for intrinsic function syntax.
Robert Dubner [Tue, 1 Jul 2025 15:07:18 +0000 (11:07 -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)

6 days agocobol: Revise diagnostic linemap management.
James K. Lowden [Mon, 30 Jun 2025 20:51:49 +0000 (16:51 -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)

6 days agocobol: Normalize generating and using function_decls.
Robert Dubner [Sun, 29 Jun 2025 14:54:36 +0000 (10:54 -0400)] 
cobol: Normalize generating and using function_decls.

Because COBOL doesn't require function prototypes, it is possible to, for
example,

    CALL "getcwd" USING <parameters>

and then later

    CALL "getcwd" USING <parameters> RETURNING <alphanumeric>

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)

6 days agocobol: Correct diagnostic strings for 32-bit builds.
James K. Lowden [Fri, 20 Jun 2025 16:43:51 +0000 (12:43 -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)

6 days agolibgcobol: Add license.
James K. Lowden [Fri, 20 Jun 2025 14:16:26 +0000 (10:16 -0400)] 
libgcobol: Add license.

libgcobol/ChangeLog:

* LICENSE: New file.

(cherry picked from commit 632a50abc3a99cace8abc6ed3817f7eb1312c9d2)

6 days agocobol: Correct diagnostic strings to rectify bootstrap build
James K. Lowden [Tue, 17 Jun 2025 22:31:33 +0000 (18:31 -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)

6 days agocobol: Some 1000 small changes in answer to cppcheck diagnostics.
James K. Lowden [Mon, 16 Jun 2025 15:43:35 +0000 (11:43 -0400)] 
cobol: Some 1000 small changes in answer to cppcheck diagnostics.

constification per cppcheck. Use STRICT_WARN and fix reported
diagnostics.  Ignore [shadowVariable] in general. Use std::vector to
avoid exposing arrays as raw pointers.

PR cobol/120621

gcc/cobol/ChangeLog:

* Make-lang.in: Use STRICT_WARN.
* cbldiag.h (location_dump): suppress shadowVariable.
* cdf-copy.cc (esc): Fix shadowVariable.
(copybook_elem_t::open_file): Do not use %m.
* cdf.y: suppress invalidPrintfArgType for target format.
* cdfval.h (struct cdfval_t): Suppress noExplicitConstructor.
* cobol1.cc (cobol_name_mangler): Use C++ cast.
* copybook.h (class copybook_elem_t): Same.
* dts.h: Fixes and suppressions due to cppcheck.
* except.cc (cbl_enabled_exceptions_t::status): Suppress useStlAlgorithm.
(cbl_enabled_exceptions_t::turn_on_off): Const parameter.
(class choose_declarative): Removed.
* genapi.cc (struct called_tree_t): Explicit constructor.
(parser_compile_ecs): Cast to void * for %p.
(parser_compile_dcls): Same.
(parser_statement_begin): Same.
(initialize_variable_internal): Use std::vector for subscripts.
(parser_initialize): Constification.
(get_string_from): Same.
(combined_name): Same.
(parser_perform): Same.
(psa_FldLiteralN): Same.
(is_figconst): Const parameter.
(is_figconst_t): Same.
(parser_exit): Same.
(parser_division): Const pointer.
(parser_perform_conditional): Whitespace.
(parser_set_conditional88): Const parameter.
(inspect_tally): Use std::vector.
(inspect_replacing): Same.
(parser_inspect): Same.
(parser_intrinsic_subst): Use std::vector (constuct elements).
(parser_intrinsic_call_1): Use std::vector for subscripts.
(is_ascending_key): Const pointer.
(parser_sort): Use std::vector.
(parser_file_sort): Same.
(parser_file_merge): Same.
(parser_unstring): Same.
(parser_string): Same.
(parser_call): Const pointer.
(parser_program_hierarchy): Use std::vector.
(conditional_abs): Const paraemeter.
(float_type_of): Same.
(initial_from_initial): Set value, quoted or not.
(parser_symbol_add): Remove redundant nested test.
* genapi.h (parser_add): Const parameters.
(parser_subtract): Same.
(parser_multiply): Same.
(parser_divide): Same.
(parser_perform): Same.
(parser_exit): Same.
(parser_initialize): Same.
(parser_set_conditional88): Same.
(parser_sort): Same.
(parser_file_sort): Same.
(parser_file_merge): Same.
(parser_string): Same.
(is_ascending_key): Same.
* genmath.cc (arithmetic_operation): Use std::vector.
(is_somebody_float): Const parameter.
(all_results_binary): Const parameter.
(fast_multiply): Remove redundant nested test.
(parser_add): Const parameter.
(parser_multiply): Remove redundant nested test.
(parser_divide): Const parameter.
(parser_subtract): Same.
* genutil.cc (get_depending_on_value): Use std::vector.
(get_data_offset): Same.
(tree_type_from_field): Const parameter.
(refer_has_depends): Const pointers.
(get_literal_string): RAII.
(refer_is_clean): Use std::vector.
(get_time_nanoseconds): Newline at EOF.
* genutil.h (tree_type_from_field): Remove declaration.
* inspect.h (struct cbx_inspect_qual_t): Use std::vector.
(struct cbl_inspect_qual_t): Same.
(struct cbx_inspect_match_t): Same.
(class cbl_inspect_match_t): Same.
(struct cbx_inspect_replace_t): Same.
(struct cbl_inspect_replace_t): Same.
(struct cbx_inspect_oper_t): Same.
(struct cbl_inspect_oper_t): Same.
(struct cbx_inspect_t): Same.
(struct cbl_inspect_t): Same.
(parser_inspect): Same.
* lexio.cc (indicated): Const pointer.
(remove_inline_comment): Scope reduction.
(maybe_add_space): Const pointer.
(recognize_replacements): C++ cast.
(check_source_format_directive): Same.
(struct replacing_term_t): Explicit constructor.
(parse_replace_pairs): Const reference.
(location_in): Const reference.
(parse_copy_directive): C++ cast.
(parse_replace_last_off): Const parameter.
(parse_replace_text): Const reference.
(parse_replace_directive): C++ cast.
(cdftext::lex_open): Const reference.
(cdftext::open_output): Scope reduction.
(cdftext::free_form_reference_format): Remove unused variable.
(cdftext::process_file): Simplify.
* lexio.h (struct bytespan_t): Use nullptr.
(struct filespan_t): Initialize icol in constructor.
(struct span_t): Suppress confused operatorEqRetRefThis.
(struct replace_t): Eliminate single-value constructor.
* parse.y: Many const cppcheck reports, and portable bit-shift.
* parse_ante.h (reject_refmod): Const parameter.
(require_pointer): Same.
(require_integer): Same.
(struct evaluate_elem_t): Explicit constructor.
(struct arith_t): Use std::vector.
(class eval_subject_t): Const parameter.
(dump_inspect_match): Declare.
(struct perform_t): Explicit constructor.
(list_add):  Const parameter.
(class tokenset_t): Avoid negative array index.
(struct file_list_t): Explicit constructor.
(struct field_list_t): Same.
(struct refer_list_t): Same.
(struct refer_marked_list_t): Const parameter.
(struct refer_collection_t): Explicit constructor.
(struct ast_inspect_oper_t): Remove class.
(ast_inspect_oper_t): Same.
(struct ast_inspect_t): Same.
(struct ast_inspect_list_t): Same.
(ast_inspect): Add location.
(struct elem_list_t): Explicit constructor.
(struct unstring_tgt_t): Same.
(struct unstring_tgt_list_t): Same.
(struct unstring_into_t): Same.
(struct ffi_args_t): Same.
(struct file_sort_io_t): Same.
(merge_t): Same.
(struct vargs_t): Same.
(class prog_descr_t): Eliminate single-value constructor.
(class program_stack_t): Suppress useStlAlgorithm.
(struct rel_part_t): Eliminate single-value constructor.
(class log_expr_t): Explicit constructor.
(add_debugging_declarative): Rename local variable.
(intrinsic_call_2): Const parameter.
(invalid_key): Use std::find_if.
(parser_add2): Const parameter.
(parser_subtract2): Same.
(stringify): Same.
(unstringify): Same.
(anybody_redefines): Same.
(ast_call): Same.
* parse_util.h (class cname_cmp): Explicit constructor.
(intrinsic_inconsistent_parameter): Same.
* scan_ante.h (struct cdf_status_t): Eliminate single-value constructor.
(class enter_leave_t): Explicit constructor.
(update_location): Const pointer, explicit constructor.
(symbol_function_token): Const pointer.
(typed_name): Same.
* scan_post.h (datetime_format_of): Scope reduction.
* show_parse.h (class ANALYZE): Use std::vector, explicit consstructor.
* symbols.cc (symbol_table_extend): Scope reduction.
(cbl_ffi_arg_t::cbl_ffi_arg_t): Define default constructor.
(end_of_group): Const pointer.
(symbol_find_odo): Const parameter.
(rename_not_ok): Same.
(field_str): Use %u instead of %d.
(struct capacity_of): Const pointer.
(symbols_update): Same.
(symbol_field_parent_set): Same.
(symbol_file_add): Same.
(symbol_typedef_add): Same.
(symbol_field_add): Use new operator=().
(symbol_field): Suppress CastIntegerToAddressAtReturn.
(symbol_register): Same.
(symbol_file): Suppress knownConditionTrueFalse.
(next_program): Const parameter.
(symbol_file_record): Same.
(class is_section): Explicit constructor.
(cbl_file_t::no_key): Remove.
(cbl_prog_hier_t::cbl_prog_hier_t): Use std::vector.
(symbol_label_add): Assert pointer is not NULL.
(symbol_label_section_exists): Const reference in lambda.
(expand_picture): Use C++ cast.
(symbol_program_callables): Const pointer.
(symbol_currency_add): Suppress nullPointerRedundantCheck.
(cbl_key_t): Use std::vector.
(cbl_occurs_t::field_add): Const parameter.
(cbl_occurs_t::index_add): Explicit constructor.
(class is_field_at): Same.
(cbl_file_key_t::deforward): Scope reduction.
(cbl_file_t::keys_str): Use allocated memory only.
(file_status_status_of): Const pointer.
(is_register_field): Const parameter.
* symbols.h (struct cbl_field_data_t): Eliminate single-value constructor.
(struct cbl_occurs_bounds_t): Same.
(struct cbl_refer_t): Use std::vector.
(valid_move): Const parameter.
(is_register_field): Same.
(struct cbl_key_t): Use std::vector.
(struct cbl_substitute_t): Eliminate single-value constructor.
(refer_of): Return const reference
(struct cbl_ffi_arg_t): Eliminate single-value constructor.
(class temporaries_t): Same.
(struct cbl_file_key_t): Define default constructor.
(struct cbl_file_lock_t): Define copy constructor and operator=().
(struct cbl_file_t): Complete default constructor.
(struct symbol_elem_t): Explicit constructor.
(symbol_elem_of): Suppress cstyleCast.
(symbol_redefines): Const parameter.
(struct cbl_field_t): Same.
(cbl_section_of): Test for NULL pointer.
(cbl_field_of): Same.
(cbl_label_of): Same.
(cbl_special_name_of): Same.
(cbl_alphabet_of): Same.
(cbl_file_of): Same.
(is_figconst): Delete extra "struct" keyword.
(is_figconst_low): Same.
(is_figconst_zero): Same.
(is_figconst_space): Same.
(is_figconst_quote): Same.
(is_figconst_high): Same.
(is_space_value): Same.
(is_quoted): Same.
(symbol_index): Const parameter.
(struct cbl_prog_hier_t): Suppress noExplicitConstructor.
(struct cbl_perform_vary_t): Eliminate single-value constructor.
(is_signable): Const parameter.
(is_temporary): Same.
(rename_not_ok): Same.
(field_at): Test for NULL pointer.
(class procref_base_t): Eliminate single-value constructor.
* symfind.cc (is_data_field): Const pointer.
(finalize_symbol_map2): Same.
(class in_scope): Same.
(symbol_match2): Same.
* token_names.h: Suppress useInitializationList.
* util.cc (normalize_picture): Whitespace and remove extra "continue".
(redefine_field): Const pointer.
(cbl_field_t::report_invalid_initial_value): Same.
(literal_subscript_oob): Rename shadow variable.
(cbl_refer_t::subscripts_set): Use std::vector.
(cbl_refer_t::str): Same.
(cbl_refer_t::deref_str): Same.
(locally_unique): Use explicit constructor.
(ambiguous_reference): Same.
(class unique_stack): Use const reference.
(cobol_filename): Const pointer.
(verify_format): Scope reduction.
(class temp_loc_t): Do not derive from YYLTYPE.
(cobol_parse_files): Const pointer.
* util.h (as_voidp): Define convenient converter.

libgcobol/ChangeLog:

* common-defs.h (class cbl_enabled_exceptions_t): Const parameter.

(cherry picked from commit f298fabf3f10bcc426b41c23f90a5b90d694730d)

6 days agocobol: Eliminate unguarded clock_gettime dependencies. [PR119975]
Robert Dubner [Wed, 11 Jun 2025 19:49:41 +0000 (15:49 -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 <sys/time.h>.
(__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)

6 days agocobol: Variety of small changes in answer to cppcheck diagnostics.
James K. Lowden [Tue, 10 Jun 2025 14:34:28 +0000 (10:34 -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)

6 days agocobol: Diagnostic messages, Flex build, and some cppcheck reports. [PR120328, PR119695]
Robert Dubner [Fri, 6 Jun 2025 20:32:22 +0000 (16:32 -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 <jklowden@cobolworx.com>
Co-authored-by: Robert Dubner <rdubner@symas.com>
(cherry picked from commit 37f5fdd008399c239e0689f2e864519505c78c7e)

6 days agocobol: Guard clock_gettime(). [PR119975]
Robert Dubner [Thu, 5 Jun 2025 14:53:02 +0000 (10:53 -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)

6 days agocobol: Eliminate cppcheck warnings for libgcobol [PR119323]
Robert Dubner [Mon, 2 Jun 2025 22:40:28 +0000 (18:40 -0400)] 
cobol: Eliminate cppcheck warnings for libgcobol [PR119323]

I configured and ran cppcheck-2.17.0 with this config file:

<?xml version="1.0"?>
<def format="2">
  <define name="HOST_SIZE_T_PRINT_UNSIGNED" value="&quot;%ld&quot;"/>
  <define name="GCC_PRISZ" value="&quot;z&quot;"/>
  <define name="YYLTYPE" value="struct {int first_line; int first_column; int last_line; int last_column;}"/>
  <define name="__FLT128_MANT_DIG__" value="113"/>
  <define name="__FLT128_MIN_EXP__" value="-16381"/>
</def>

and this command line

cppcheck --inline-suppr --enable=all --force --language=c++ --library=$CFG \
--check-level=exhaustive \
--disable=unusedFunction \
--disable=missingInclude \
$(cat $FILES) > $RESULT 2>&1

$FILES was all of the .cc files in libgcobol.

The result was many hundreds of warnings.  The vast bulk of them were
recommendations for declaring variables as const, recommendations for
changing C-style casts to C++ casts, cheery notes about shadowed
variables, and complaints that malloc() results weren't being checked
for errors.

Two and a half days of applied OCD on my part has reduced the number of
warnings down to zero.

libgcobol/ChangeLog:

PR cobol/119323
* charmaps.cc (__gg__raw_to_ascii):  Eliminate cppcheck warnings.
(__gg__raw_to_ebcdic): Likewise.
(__gg__ebcdic_to_console): Likewise.
(__gg__console_to_ascii): Likewise.
(__gg__console_to_ebcdic): Likewise.
* common-defs.h (struct cbl_declarative_t): Likewise.
* gfileio.cc (get_filename): Likewise.
(max_value): Likewise.
(relative_file_delete_varying): Likewise.
(relative_file_delete): Likewise.
(read_an_indexed_record): Likewise.
(position_state_restore): Likewise.
(indexed_file_delete): Likewise.
(indexed_file_start): Likewise.
(sequential_file_rewrite): Likewise.
(relative_file_write_varying): Likewise.
(relative_file_write): Likewise.
(sequential_file_write): Likewise.
(indexed_file_write): Likewise.
(__io__file_write): Likewise.
(line_sequential_file_read): Likewise.
(indexed_file_read): Likewise.
(file_indexed_open): Likewise.
(__gg__file_reopen): Likewise.
* gmath.cc (conditional_stash): Likewise.
(__gg__pow): Likewise.
(multiply_int256_by_int64): Likewise.
(add_int256_to_int256): Likewise.
(divide_int256_by_int64): Likewise.
(squeeze_int256): Likewise.
(get_int256_from_qualified_field): Likewise.
(__gg__add_fixed_phase1): Likewise.
(__gg__addf1_fixed_phase2): Likewise.
(__gg__fixed_phase2_assign_to_c): Likewise.
(__gg__add_float_phase1): Likewise.
(__gg__addf1_float_phase2): Likewise.
(__gg__float_phase2_assign_to_c): Likewise.
(__gg__addf3): Likewise.
(__gg__subtractf1_fixed_phase2): Likewise.
(__gg__subtractf2_fixed_phase1): Likewise.
(__gg__subtractf1_float_phase2): Likewise.
(__gg__subtractf2_float_phase1): Likewise.
(__gg__subtractf3): Likewise.
(__gg__multiplyf1_phase1): Likewise.
(multiply_int128_by_int128): Likewise.
(__gg__multiplyf1_phase2): Likewise.
(__gg__multiplyf2): Likewise.
(shift_in_place128): Likewise.
(divide_int128_by_int128): Likewise.
(__gg__dividef1_phase2): Likewise.
(__gg__dividef23): Likewise.
(__gg__dividef45): Likewise.
* intrinsic.cc (struct input_state): Likewise.
(get_value_as_double_from_qualified_field): Likewise.
(kahan_summation): Likewise.
(variance): Likewise.
(get_all_time): Likewise.
(populate_ctm_from_date): Likewise.
(populate_ctm_from_time): Likewise.
(ftime_replace): Likewise.
(__gg__abs): Likewise.
(__gg__acos): Likewise.
(__gg__annuity): Likewise.
(__gg__asin): Likewise.
(__gg__atan): Likewise.
(__gg__byte_length): Likewise.
(__gg__char): Likewise.
(__gg__combined_datetime): Likewise.
(__gg__cos): Likewise.
(__gg__date_of_integer): Likewise.
(__gg__date_to_yyyymmdd): Likewise.
(__gg__day_of_integer): Likewise.
(__gg__day_to_yyyyddd): Likewise.
(__gg__exp): Likewise.
(__gg__exp10): Likewise.
(__gg__factorial): Likewise.
(__gg__formatted_current_date): Likewise.
(__gg__formatted_date): Likewise.
(__gg__formatted_datetime): Likewise.
(__gg__formatted_time): Likewise.
(__gg__integer): Likewise.
(__gg__integer_of_date): Likewise.
(__gg__integer_of_day): Likewise.
(__gg__integer_part): Likewise.
(__gg__fraction_part): Likewise.
(__gg__log): Likewise.
(__gg__log10): Likewise.
(__gg__max): Likewise.
(__gg__lower_case): Likewise.
(__gg__median): Likewise.
(__gg__min): Likewise.
(numval): Likewise.
(numval_c): Likewise.
(__gg__numval): Likewise.
(__gg__test_numval): Likewise.
(__gg__numval_c): Likewise.
(__gg__test_numval_c): Likewise.
(__gg__ord): Likewise.
(__gg__rem): Likewise.
(__gg__trim): Likewise.
(__gg__random): Likewise.
(__gg__reverse): Likewise.
(__gg__sign): Likewise.
(__gg__sin): Likewise.
(__gg__sqrt): Likewise.
(__gg__tan): Likewise.
(__gg__test_date_yyyymmdd): Likewise.
(__gg__test_day_yyyyddd): Likewise.
(__gg__upper_case): Likewise.
(__gg__year_to_yyyy): Likewise.
(gets_int): Likewise.
(gets_year): Likewise.
(gets_month): Likewise.
(gets_day): Likewise.
(gets_day_of_week): Likewise.
(gets_day_of_year): Likewise.
(gets_week): Likewise.
(gets_hours): Likewise.
(gets_minutes): Likewise.
(gets_seconds): Likewise.
(gets_nanoseconds): Likewise.
(fill_cobol_tm): Likewise.
(__gg__test_formatted_datetime): Likewise.
(__gg__integer_of_formatted_date): Likewise.
(__gg__seconds_from_formatted_time): Likewise.
(__gg__hex_of): Likewise.
(__gg__highest_algebraic): Likewise.
(__gg__lowest_algebraic): Likewise.
(floating_format_tester): Likewise.
(__gg__numval_f): Likewise.
(__gg__test_numval_f): Likewise.
(ismatch): Likewise.
(iscasematch): Likewise.
(strstr): Likewise.
(strcasestr): Likewise.
(strlaststr): Likewise.
(strcaselaststr): Likewise.
(__gg__substitute): Likewise.
(__gg__locale_compare): Likewise.
(__gg__locale_date): Likewise.
(__gg__locale_time): Likewise.
(__gg__locale_time_from_seconds): Likewise.
* libgcobol.cc (class ec_status_t): Likewise.
(__gg__set_truncation_mode): Likewise.
(malloc): Likewise.
(__gg__mabort): Likewise.
(__gg__resize_int_p): Likewise.
(__gg__resize_treeplet): Likewise.
(var_is_refmod): Likewise.
(value_is_too_big): Likewise.
(__gg__string_to_alpha_edited_ascii): Likewise.
(int128_to_field): Likewise.
(edited_to_binary): Likewise.
(get_binary_value_local): Likewise.
(__gg__get_date_yymmdd): Likewise.
(__gg__get_date_yyyymmdd): Likewise.
(__gg__get_date_yyddd): Likewise.
(__gg__get_yyyyddd): Likewise.
(__gg__get_date_dow): Likewise.
(get_scaled_rdigits): Likewise.
(format_for_display_internal): Likewise.
(compare_88): Likewise.
(get_float128): Likewise.
(compare_field_class): Likewise.
(compare_strings): Likewise.
(__gg__compare_2): Likewise.
(__gg__sort_table): Likewise.
(init_var_both): Likewise.
(alpha_to_alpha_move_from_location): Likewise.
(alpha_to_alpha_move): Likewise.
(__gg__move): Likewise.
(__gg__move_literala): Likewise.
(__gg__sort_workfile): Likewise.
(__gg__merge_files): Likewise.
(normalize_id): Likewise.
(inspect_backward_format_1): Likewise.
(__gg__inspect_format_1): Likewise.
(inspect_backward_format_2): Likewise.
(__gg__inspect_format_2): Likewise.
(__gg__inspect_format_4): Likewise.
(move_string): Likewise.
(__gg__string): Likewise.
(display_both): Likewise.
(__gg__display_string): Likewise.
(__gg__accept): Likewise.
(__gg__binary_value_from_qualified_field): Likewise.
(__gg__float128_from_qualified_field): Likewise.
(float128_to_int128): Likewise.
(float128_to_location): Likewise.
(__gg__set_initial_switch_value): Likewise.
(is_numeric_display_numeric): Likewise.
(is_packed_numeric): Likewise.
(is_alpha_a_number): Likewise.
(__gg__classify): Likewise.
(__gg__accept_envar): Likewise.
(__gg__set_envar): Likewise.
(command_line_plan_b): Likewise.
(__gg__get_command_line): Likewise.
(__gg__set_pointer): Likewise.
(__gg__ascii_to_internal_field): Likewise.
(__gg__internal_to_console_in_place): Likewise.
(__gg__routine_to_call): Likewise.
(__gg__fetch_call_by_value_value): Likewise.
(__gg__assign_value_from_stack): Likewise.
(__gg__literaln_alpha_compare): Likewise.
(string_in): Likewise.
(__gg__unstring): Likewise.
(local_ec_type_of): Likewise.
(struct exception_descr_t): Likewise.
(struct cbl_exception_t): Likewise.
(cbl_enabled_exception_t: Likewise.: Likewise.dump): Likewise.
(__gg__match_exception): Likewise.
(__gg__float128_from_location): Likewise.
(__gg__integer_from_float128): Likewise.
(__gg__set_exception_file): Likewise.
(__gg__func_exception_file): Likewise.
(__gg__set_exception_code): Likewise.
(__gg__is_float_infinite): Likewise.
(__gg__float32_from_128): Likewise.
(__gg__float32_from_64): Likewise.
(__gg__float64_from_128): Likewise.
(__gg__copy_as_big_endian): Likewise.
(__gg__get_figconst_data): Likewise.
(find_in_dirs): Likewise.
(__gg__function_handle_from_cobpath): Likewise.
(__gg__just_mangle_name): Likewise.
(__gg__function_handle_from_literal): Likewise.
(__gg__function_handle_from_name): Likewise.
(__gg__mirror_range): Likewise.
(__gg__deallocate): Likewise.
(__gg__allocate): Likewise.
(__gg__module_name): Likewise.
(__gg__set_env_name): Likewise.
(__gg__set_env_value): Likewise.
* libgcobol.h (__gg__mabort): Likewise.
(massert): Likewise.
(PTRCAST): Likewise.
(__gg__float128_from_location): Likewise.
(__gg__set_exception_file): Likewise.
(__gg__binary_value_from_qualified_field): Likewise.
(__gg__float128_from_qualified_field): Likewise.
* valconv.cc (__gg__realloc_if_necessary): Likewise.
(__gg__alphabet_create): Likewise.
(__gg__string_to_numeric_edited): Likewise.
(__gg__string_to_alpha_edited): Likewise.
* valconv.h: Likewise.

(cherry picked from commit 54e4f75b7d57e02bba79cd67332bbfdc37d1b321)

6 days agocobol: Honor HAVE_CLOCK_GETTIME and HAVE_GETTIMEOFDAY. [PR119975]
Robert Dubner [Mon, 2 Jun 2025 19:55:20 +0000 (15:55 -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)

6 days agocobol: Wrap the call to fprintf in a libgcobol routine. [PR119524]
Robert Dubner [Sun, 1 Jun 2025 16:32:37 +0000 (12:32 -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)

6 days agocobol: Multiple PRs; formatting; exception processing.
Robert Dubner [Tue, 20 May 2025 17:35:15 +0000 (13:35 -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 <glob.h>.
* cdfval.h (_CDF_VAL_H_): Switch to C++ headers.
* copybook.h (class copybook_elem_t): Eliminate <glob.h>.
(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 <assert.h>.
* 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 <jklowden@cobolworx.com>
(cherry picked from commit fba34a0cc55488ad89becf81cf2c9ac517d244d4)

6 days agocobol: sqrt(0) is not an ec-argument error. [PR119885]
Robert Dubner [Tue, 20 May 2025 15:49:43 +0000 (11:49 -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)

6 days agoRegenerate cobol/lang.opt.urls
Mark Wielaard [Sun, 18 May 2025 14:20:10 +0000 (16:20 +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)

6 days agocobol: Eliminate exception "blob"; streamline some code generation.
Robert Dubner [Fri, 16 May 2025 15:12:04 +0000 (11:12 -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)

6 days agocobol: One additional edit to testsuite/cobol.dg/group1/check_88.cob [PR120251]
Robert Dubner [Thu, 15 May 2025 17:33:16 +0000 (13:33 -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)

6 days agocobol: Don't display 0xFF HIGH-VALUE characters in testcases. [PR120251]
Robert Dubner [Thu, 15 May 2025 16:01:12 +0000 (12:01 -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)

6 days agolibgcobol: Allow for lack of LOG_PERROR
Rainer Orth [Tue, 13 May 2025 07:43:48 +0000 (09:43 +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  <ro@CeBiTec.Uni-Bielefeld.DE>

libgcobol:
* libgcobol.cc [!LOG_PERROR] (LOG_PERROR): Provide fallback.

(cherry picked from commit 90fee97d528e8447648c37f9df1daa3445e598bc)

6 days agocobol: Eliminate padding bytes from cbl_declarative_t. [PR119377]
Robert Dubner [Sun, 11 May 2025 17:43:32 +0000 (13:43 -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)

6 days agocobol: New testcases.
Robert Dubner [Sun, 11 May 2025 13:40:41 +0000 (09:40 -0400)] 
cobol: New testcases.

Eighty-six testcases extracted from the run_move and run_misc COBOLworx
testsuite.

gcc/testsuite/ChangeLog:

* cobol.dg/group2/258_Nested_PERFORM.cob: New testcase.
* cobol.dg/group2/259_PERFORM_VARYING_BY_-0.2.cob: Likewise.
* cobol.dg/group2/338_Default_Arithmetic__1_.cob: Likewise.
* cobol.dg/group2/access_to_OPTIONAL_LINKAGE_item_not_passed.cob: Likewise.
* cobol.dg/group2/ALLOCATE___FREE_basic_default_versions.cob: Likewise.
* cobol.dg/group2/ALLOCATE___FREE_with_BASED_item__1_.cob: Likewise.
* cobol.dg/group2/ALLOCATE___FREE_with_BASED_item__2_.cob: Likewise.
* cobol.dg/group2/ALLOCATE_Rule_8_OPTION_INITIALIZE_with_figconst.cob: Likewise.
* cobol.dg/group2/Alphanumeric_and_binary_numeric.cob: Likewise.
* cobol.dg/group2/Alphanumeric_MOVE_with_truncation.cob: Likewise.
* cobol.dg/group2/ANY_LENGTH__1_.cob: Likewise.
* cobol.dg/group2/ANY_LENGTH__2_.cob: Likewise.
* cobol.dg/group2/ANY_LENGTH__3_.cob: Likewise.
* cobol.dg/group2/ANY_LENGTH__4_.cob: Likewise.
* cobol.dg/group2/ANY_LENGTH__5_.cob: Likewise.
* cobol.dg/group2/CALL_with_OMITTED_parameter.cob: Likewise.
* cobol.dg/group2/Class_check_with_reference_modification.cob: Likewise.
* cobol.dg/group2/Complex_HEX__VALUE_and_MOVE.cob: Likewise.
* cobol.dg/group2/Complex_IF.cob: Likewise.
* cobol.dg/group2/Concatenation_operator.cob: Likewise.
* cobol.dg/group2/CONTINUE_AFTER_1_SECONDS.cob: Likewise.
* cobol.dg/group2/CURRENCY_SIGN.cob: Likewise.
* cobol.dg/group2/CURRENCY_SIGN_WITH_PICTURE_SYMBOL.cob: Likewise.
* cobol.dg/group2/DECIMAL-POINT_is_COMMA__1_.cob: Likewise.
* cobol.dg/group2/DECIMAL-POINT_is_COMMA__2_.cob: Likewise.
* cobol.dg/group2/DECIMAL-POINT_is_COMMA__3_.cob: Likewise.
* cobol.dg/group2/DECIMAL-POINT_is_COMMA__4_.cob: Likewise.
* cobol.dg/group2/DECIMAL-POINT_is_COMMA__5_.cob: Likewise.
* cobol.dg/group2/EC-SIZE-TRUNCATION_EC-SIZE-OVERFLOW.cob: Likewise.
* cobol.dg/group2/EC-SIZE-ZERO-DIVIDE__fixed_and_float.cob: Likewise.
* cobol.dg/group2/EXIT_PARAGRAPH.cob: Likewise.
* cobol.dg/group2/EXIT_PERFORM.cob: Likewise.
* cobol.dg/group2/EXIT_PERFORM_CYCLE.cob: Likewise.
* cobol.dg/group2/EXIT_SECTION.cob: Likewise.
* cobol.dg/group2/Fixed_continuation_indicator.cob: Likewise.
* cobol.dg/group2/FLOAT-LONG_with_SIZE_ERROR.cob: Likewise.
* cobol.dg/group2/FLOAT-SHORT___FLOAT-LONG_w_o_SIZE_ERROR.cob: Likewise.
* cobol.dg/group2/FLOAT-SHORT_with_SIZE_ERROR.cob: Likewise.
* cobol.dg/group2/Index_and_parenthesized_expression.cob: Likewise.
* cobol.dg/group2/LENGTH_OF_omnibus.cob: Likewise.
* cobol.dg/group2/LOCAL-STORAGE__3__with_recursive_PROGRAM-ID.cob: Likewise.
* cobol.dg/group2/LOCAL-STORAGE__4__with_recursive_PROGRAM-ID_..._USING.cob: Likewise.
* cobol.dg/group2/MOVE_indexes.cob: Likewise.
* cobol.dg/group2/MOVE_integer_literal_to_alphanumeric.cob: Likewise.
* cobol.dg/group2/MOVE_to_edited_item__1_.cob: Likewise.
* cobol.dg/group2/MOVE_to_edited_item__2_.cob: Likewise.
* cobol.dg/group2/MOVE_to_item_with_simple_and_floating_insertion.cob: Likewise.
* cobol.dg/group2/MOVE_to_itself.cob: Likewise.
* cobol.dg/group2/MOVE_to_JUSTIFIED_item.cob: Likewise.
* cobol.dg/group2/MOVE_with_group_refmod.cob: Likewise.
* cobol.dg/group2/MOVE_with_refmod.cob: Likewise.
* cobol.dg/group2/MOVE_with_refmod__variable_.cob: Likewise.
* cobol.dg/group2/MOVE_Z_literal_.cob: Likewise.
* cobol.dg/group2/Multi-target_MOVE_with_subscript_re-evaluation.cob: Likewise.
* cobol.dg/group2/Non-numeric_data_in_numeric_items__1_.cob: Likewise.
* cobol.dg/group2/Non-numeric_data_in_numeric_items__2_.cob: Likewise.
* cobol.dg/group2/Non-overflow_after_overflow.cob: Likewise.
* cobol.dg/group2/OCCURS_clause_with_1_entry.cob: Likewise.
* cobol.dg/group2/OSVS_Arithmetic_Test__2_.cob: Likewise.
* cobol.dg/group2/PERFORM_..._CONTINUE.cob: Likewise.
* cobol.dg/group2/PERFORM_inline__1_.cob: Likewise.
* cobol.dg/group2/PERFORM_inline__2_.cob: Likewise.
* cobol.dg/group2/PERFORM_type_OSVS.cob: Likewise.
* cobol.dg/group2/PIC_ZZZ-__ZZZ_.cob: Likewise.
* cobol.dg/group2/Quick_check_of_PIC_XX_COMP-5.cob: Likewise.
* cobol.dg/group2/Quote_marks_in_comment_paragraphs.cob: Likewise.
* cobol.dg/group2/Recursive_PERFORM_paragraph.cob: Likewise.
* cobol.dg/group2/REDEFINES_values_on_FILLER_and_INITIALIZE.cob: Likewise.
* cobol.dg/group2/SORT__EBCDIC_table_sort__1_.cob: Likewise.
* cobol.dg/group2/SORT__EBCDIC_table_sort__2_.cob: Likewise.
* cobol.dg/group2/SORT__table_sort__2_.cob: Likewise.
* cobol.dg/group2/SORT__table_sort__3A_.cob: Likewise.
* cobol.dg/group2/SORT__table_sort__3B_.cob: Likewise.
* cobol.dg/group2/SORT__table_sort.cob: Likewise.
* cobol.dg/group2/SOURCE_FIXED_FREE_directives.cob: Likewise.
* cobol.dg/group2/Static_CALL_with_ON_EXCEPTION__with_-fno-static-call_.cob: Likewise.
* cobol.dg/group2/_-static__compilation.cob: Likewise.
* cobol.dg/group2/STOP_RUN_WITH_ERROR_STATUS.cob: Likewise.
* cobol.dg/group2/STOP_RUN_WITH_NORMAL_STATUS.cob: Likewise.
* cobol.dg/group2/STRING___UNSTRING__NOT__ON_OVERFLOW.cob: Likewise.
* cobol.dg/group2/STRING_with_subscript_reference.cob: Likewise.
* cobol.dg/group2/UNSTRING_DELIMITED_ALL_LOW-VALUE.cob: Likewise.
* cobol.dg/group2/UNSTRING_DELIMITED_ALL_SPACE-2.cob: Likewise.
* cobol.dg/group2/UNSTRING_DELIMITED_POINTER.cob: Likewise.
* cobol.dg/group2/UNSTRING_DELIMITER_IN.cob: Likewise.
* cobol.dg/group2/UNSTRING_with_FUNCTION___literal.cob: Likewise.
* cobol.dg/group2/258_Nested_PERFORM.out: Known-good results file.
* cobol.dg/group2/259_PERFORM_VARYING_BY_-0.2.out: Likewise.
* cobol.dg/group2/338_Default_Arithmetic__1_.out: Likewise.
* cobol.dg/group2/access_to_OPTIONAL_LINKAGE_item_not_passed.out: Likewise.
* cobol.dg/group2/ALLOCATE___FREE_basic_default_versions.out: Likewise.
* cobol.dg/group2/ALLOCATE_Rule_8_OPTION_INITIALIZE_with_figconst.out: Likewise.
* cobol.dg/group2/Alphanumeric_MOVE_with_truncation.out: Likewise.
* cobol.dg/group2/ANY_LENGTH__1_.out: Likewise.
* cobol.dg/group2/ANY_LENGTH__2_.out: Likewise.
* cobol.dg/group2/ANY_LENGTH__3_.out: Likewise.
* cobol.dg/group2/ANY_LENGTH__5_.out: Likewise.
* cobol.dg/group2/CALL_with_OMITTED_parameter.out: Likewise.
* cobol.dg/group2/Complex_HEX__VALUE_and_MOVE.out: Likewise.
* cobol.dg/group2/Complex_IF.out: Likewise.
* cobol.dg/group2/Concatenation_operator.out: Likewise.
* cobol.dg/group2/CONTINUE_AFTER_1_SECONDS.out: Likewise.
* cobol.dg/group2/CURRENCY_SIGN.out: Likewise.
* cobol.dg/group2/CURRENCY_SIGN_WITH_PICTURE_SYMBOL.out: Likewise.
* cobol.dg/group2/DECIMAL-POINT_is_COMMA__1_.out: Likewise.
* cobol.dg/group2/DECIMAL-POINT_is_COMMA__2_.out: Likewise.
* cobol.dg/group2/DECIMAL-POINT_is_COMMA__3_.out: Likewise.
* cobol.dg/group2/DECIMAL-POINT_is_COMMA__4_.out: Likewise.
* cobol.dg/group2/DECIMAL-POINT_is_COMMA__5_.out: Likewise.
* cobol.dg/group2/EC-SIZE-TRUNCATION_EC-SIZE-OVERFLOW.out: Likewise.
* cobol.dg/group2/EC-SIZE-ZERO-DIVIDE__fixed_and_float.out: Likewise.
* cobol.dg/group2/EXIT_PERFORM_CYCLE.out: Likewise.
* cobol.dg/group2/EXIT_PERFORM.out: Likewise.
* cobol.dg/group2/Fixed_continuation_indicator.out: Likewise.
* cobol.dg/group2/FLOAT-LONG_with_SIZE_ERROR.out: Likewise.
* cobol.dg/group2/FLOAT-SHORT___FLOAT-LONG_w_o_SIZE_ERROR.out: Likewise.
* cobol.dg/group2/FLOAT-SHORT_with_SIZE_ERROR.out: Likewise.
* cobol.dg/group2/Index_and_parenthesized_expression.out: Likewise.
* cobol.dg/group2/LENGTH_OF_omnibus.out: Likewise.
* cobol.dg/group2/LOCAL-STORAGE__3__with_recursive_PROGRAM-ID.out: Likewise.
* cobol.dg/group2/LOCAL-STORAGE__4__with_recursive_PROGRAM-ID_..._USING.out: Likewise.
* cobol.dg/group2/MOVE_integer_literal_to_alphanumeric.out: Likewise.
* cobol.dg/group2/MOVE_to_edited_item__1_.out: Likewise.
* cobol.dg/group2/MOVE_to_edited_item__2_.out: Likewise.
* cobol.dg/group2/MOVE_to_item_with_simple_and_floating_insertion.out: Likewise.
* cobol.dg/group2/MOVE_to_JUSTIFIED_item.out: Likewise.
* cobol.dg/group2/MOVE_Z_literal_.out: Likewise.
* cobol.dg/group2/Multi-target_MOVE_with_subscript_re-evaluation.out: Likewise.
* cobol.dg/group2/Non-numeric_data_in_numeric_items__1_.out: Likewise.
* cobol.dg/group2/Non-numeric_data_in_numeric_items__2_.out: Likewise.
* cobol.dg/group2/OSVS_Arithmetic_Test__2_.out: Likewise.
* cobol.dg/group2/Quick_check_of_PIC_XX_COMP-5.out: Likewise.
* cobol.dg/group2/Quote_marks_in_comment_paragraphs.out: Likewise.
* cobol.dg/group2/Recursive_PERFORM_paragraph.out: Likewise.
* cobol.dg/group2/REDEFINES_values_on_FILLER_and_INITIALIZE.out: Likewise.
* cobol.dg/group2/SORT__table_sort__2_.out: Likewise.
* cobol.dg/group2/SORT__table_sort__3A_.out: Likewise.
* cobol.dg/group2/SORT__table_sort__3B_.out: Likewise.
* cobol.dg/group2/SOURCE_FIXED_FREE_directives.out: Likewise.
* cobol.dg/group2/Static_CALL_with_ON_EXCEPTION__with_-fno-static-call_.out: Likewise.
* cobol.dg/group2/_-static__compilation.out: Likewise.
* cobol.dg/group2/STRING___UNSTRING__NOT__ON_OVERFLOW.out: Likewise.
* cobol.dg/group2/UNSTRING_with_FUNCTION___literal.out: Likewise.

(cherry picked from commit 40cecd49fba1db0cb98b81016d0742398ce3c861)

6 days agocobol: Auto-detect source format; some FldLiteralN; infer gcobc name. [PR119337]
Robert Dubner [Sat, 10 May 2025 22:05:29 +0000 (18:05 -0400)] 
cobol: Auto-detect source format; some FldLiteralN; infer gcobc name. [PR119337]

This commit includes changes to the parser's auto-detection heuristic for source
code formatting.  The heuristic now examines the line containing "program-id" to
determine whether the code is in ISO "fixed-form reference format", or ISO
"free-form reference format", or the IBM "extended source format".

Changes to the parser also changes to token processing.

On the code generation side, there are some changes that begin to process
numeric literals in order generate more efficient code using information known
at compilation time.

gcc/cobol/ChangeLog:

PR cobol/119337

* Make-lang.in: Change how $(FLEX) is invoked.
* cdf.y: Change parser tokens.
* gcobc: Changed how name is inferred for PR119337
* gcobol.1: Documentation for SOURCE format heuristic
* genapi.cc: Eliminate __gg__odo_violation.
(parser_display_field): Change comment.
* genutil.cc:Eliminate __gg__odo_violation.
(REFER): New macro for analyzing subscript/refmod calculations.
(get_integer_value): Likewise.
(get_data_offset): Eliminate __gg__odo_violation.
(scale_by_power_of_ten_N): Eliminate unnecessary var_decl_rdigits operation.
(refer_is_clean): Check for FldLiteralN.
(REFER_CHECK): Eliminate.
(refer_refmod_length): Streamline var_decl_rdigits processing.
(refer_fill_depends): Likewise.
(refer_offset): Streamline processing when FldLiteralN.
(refer_size): Tag with REFER macro.
(refer_size_dest): Likewise.
(refer_size_source): Likewise.
* genutil.h (get_integer_value): Delete declaration for odo_violation;
change comment for get_integer_value
(REFER_CHECK): Delete declaration.
(refer_check): Delete #define.
* lexio.cc (is_fixed_format): Changes for source format auto-detect.
(is_reference_format): Likewise.
(check_source_format_directive): Likewise.
(valid_sequence_area): Likewise.
(is_p): Likewise.
(is_program_id): Likewise.
(likely_nist_file): Likewise.
(infer_reference_format): Likewise.
(cdftext::free_form_reference_format): Likewise.
* parse.y: Token changes.
* parse_ante.h (class tokenset_t):  Likewise.
(class current_tokens_t):  Likewise.
(cmd_or_env_special_of): Likewise.
* scan.l:  Likewise.
* scan_ante.h (bcomputable): Likewise.
(keyword_alias_add): Likewise.
(struct bint_t): Likewise.
(binary_integer_usage): Likewise.
(binary_integer_usage_of): Likewise.
* scan_post.h (start_condition_str): Likewise.
* symbols.cc (symbol_table_init): Formatting.
* symbols.h (struct cbl_field_data_t): Add "input" method to field_data_t.
(keyword_alias_add): Add forward declaration.
(binary_integer_usage_of): Likewise.
* token_names.h: Change list of tokens.
* util.cc (iso_cobol_word): Change list of COBOL reserved words.

libgcobol/ChangeLog:

* common-defs.h (ec_cmp): Delete "getenv("match_declarative")" calls.
(enabled_exception_match): Delete "getenv("match_declarative")" calls.
* libgcobol.cc: Eliminate __gg__odo_violation.

gcc/testsuite/ChangeLog:

* cobol.dg/group1/simple-if.cob: Make explicitly >>SOURCE FREE

(cherry picked from commit a3f5aac402a7ef721e1e832f96ed77ec21f5a25c)

6 days agolibgcobol: Heed --enable-libgcobol
Rainer Orth [Thu, 8 May 2025 07:42:42 +0000 (09:42 +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  <ro@CeBiTec.Uni-Bielefeld.DE>

libgcobol:
* configure.ac: Handle --enable-libgcobol.
Let it override LIBGCOBOL_SUPPORTED.
* configure: Regenerate.

(cherry picked from commit fdd2374b87bd9d7f4c201c81875d77acaebb38cd)

6 days agocobol: Allow for undefined NAME_MAX [PR119217]
Rainer Orth [Thu, 8 May 2025 07:39:26 +0000 (09:39 +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 <limits.h> under "Pathname Variable Values":

A definition of one of the symbolic constants in the following list
shall be omitted from the <limits.h> 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  <ro@CeBiTec.Uni-Bielefeld.DE>

gcc/cobol:
PR cobol/119217
* symbols.h (NAME_MAX): Define fallback.

(cherry picked from commit 1df8fffba30bf4022dda762bf61acf16ac704c67)

6 days agocobol: Initialize regmatch_t portably [PR119217]
Rainer Orth [Thu, 8 May 2025 07:29:56 +0000 (09:29 +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_t        rm_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  <ro@CeBiTec.Uni-Bielefeld.DE>

gcc/cobol:
PR cobol/119217
* dts.h (csub_match): Initialize rm_so, rm_eo fields explicitly.

(cherry picked from commit 12d6fa2a21140166181ae3be7711d60e62c569d7)

6 days agocobol: Don't require GLOB_BRACE etc. [PR119217]
Rainer Orth [Thu, 8 May 2025 07:21:45 +0000 (09:21 +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  <ro@CeBiTec.Uni-Bielefeld.DE>

gcc/cobol:
PR cobol/119217
* cdf-copy.cc (GLOB_BRACE): Define fallback.
(GLOB_TILDE): Likewise.

(cherry picked from commit aacaa3b13bca508cb6cb803d11cb942b2de8c0db)

6 days agolibgcobol: Fix bootstrap for targets without program_invocation_short_name
Iain Sandoe [Tue, 6 May 2025 08:42:40 +0000 (09:42 +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 <iain@sandoe.co.uk>
(cherry picked from commit 67e79da5a3c0deb93cd6df1557affb6994440357)

6 days agocobol: Rewrite exception handling. Partially refactor subscript/refmod calculations.
Robert Dubner [Fri, 2 May 2025 20:56:52 +0000 (16:56 -0400)] 
cobol: Rewrite exception handling.  Partially refactor subscript/refmod calculations.

This commit includes changes to exception handling, and changes to the
calculations for offsets and lengths when processing subscripted table entries
and variables with (from:length) reference modifications.

Exception handling in COBOL requires significant amounts of information to be
built at compile time and sent to libgcobol.so at run time.  The changes here
reduce some problems caused by creating structures by the host that are
processed by the target, mainly by creating arrays of simple integers rather
than by turning a structure into a stream of bytes.

Significant changes to the logic of exception handling brings the run-time
performance more in line with the ISO specification.

The handling of COBOL variables that include tables defined with DEPENDING ON
clauses is subtly different when used as sending variables versus when they are
receiving variables.  This commit folds the very similar refer_offset_source
and refer_offset_dest routines into a single refer_offset routine.  It also
streamlines the refer_length_source and refer_length_dest routines by moving
common code into a static refer_length() routine, and having
refer_length_source() and refer_length_dest() each call refer_length() with a
a type flag.

Co-Authored by: James K. Lowden <jklowden@cobolworx.com>
Co-Authored by: Robert Dubner <rdubner@symas.com>

gcc/cobol/ChangeLog:

* cdf.y: Exceptions.
* except.cc (cbl_enabled_exception_t::dump): Likewise.
(cbl_enabled_exceptions_t::dump): Likewise.
(cbl_enabled_exceptions_t::status): Likewise.
(cbl_enabled_exceptions_t::encode): Likewise.
(cbl_enabled_exceptions_t::turn_on_off): Likewise.
(cbl_enabled_exceptions_t::match): Likewise.
(declarative_runtime_match): Likewise. Likewise.
* exceptg.h (struct cbl_exception_files_t): Likewise.
(class exception_turn_t): Likewise.
(apply_cdf_turn): Likewise.
* genapi.cc (treeplet_fill_source): Use refer_offset().
(function_handle_from_name): Likewise.
(parser_initialize_programs): Likewise.
(parser_statement_begin): Likewise.
(array_of_long_long): Exceptions.
(parser_compile_ecs): Exceptions.
(parser_compile_dcls): Exceptions.
(store_location_stuff): Exceptions.
(initialize_variable_internal): Use refer_offset().
(compare_binary_binary): Use refer_offset().
(cobol_compare): Use refer_offset().
(paragraph_label): Formatting.
(parser_goto): Use refer_offset().
(parser_perform_times): Likewise.
(internal_perform_through_times): Likewise.
(parser_enter_file): Exceptions.
(psa_FldLiteralN): Add comment.
(parser_accept): Use refer_offset().
(parser_accept_command_line): Likewise.
(parser_accept_command_line_count): Likewise.
(parser_accept_envar): Likewise.
(parser_set_envar): Likewise.
(parser_display_internal): Likewise.
(parser_initialize_table): Likewise.
(parser_sleep): Likewise.
(parser_allocate): Likewise.
(parser_free): Likewise.
(parser_division): Likewise.
(parser_relop_long): Likewise.
(parser_see_stop_run): Likewise.
(parser_classify): Likewise.
(parser_file_add): Include symbol_table_index in __gg__file_init().
(parser_file_open): Use refer_offset().
(parser_file_write): Move forward declaration of store_location_stuff().
(parser_file_start): Use refer_offset().
(parser_inspect_conv): Likewise:
(parser_intrinsic_numval_c): Likewise:
(parser_intrinsic_subst): Likewise:
(parser_intrinsic_call_1): Likewise:
(parser_intrinsic_call_2): Likewise:
(parser_intrinsic_call_3): Likewise:
(parser_intrinsic_call_4): Likewise:
(parser_sort): Likewise:
(parser_return_start): Exceptions.
(parser_unstring): Use refer_offset().
(create_and_call): Likewise.
(parser_set_pointers): Use refer_offset().
(parser_program_hierarchy): Comment.
(parser_set_handled): Exceptions; removed.
(parser_set_file_number): Exceptions; removed.
(stash_exceptions): Exceptions; removed.
(parser_exception_prepare): Exceptions; removed.
(parser_match_exception): Exceptions; eliminate blob.
(parser_check_fatal_exception): Exceptions.
(parser_push_exception): Create.
(parser_pop_exception): Create.
(mh_identical): Use refer_offset().
(mh_source_is_literalN): Likewise.
(mh_dest_is_float): Likewise.
(mh_numeric_display): Likewise.
(mh_little_endian): Likewise.
(mh_source_is_group): Likewise.
(move_helper): Likewise.
(binary_initial_from_float128): Formatting; change error message.
(initial_from_float128): Change name to "initial_from_initial"
(initial_from_initial): Add one byte to allocation for figconsts.
(parser_symbol_add): Use initial_from_initial().
(parser_symbol_add): Eliminate unneeded logic around actually_create...
* genapi.h: Exceptions.
* genmath.cc (fast_add): Use refer_offset().
(fast_subtract): Likewise.
(fast_multiply): Likewise.
(fast_divide): Likewise.
* genutil.cc: Exceptions; various global definitions.
(get_integer_value): Comment.
(get_data_offset_dest): Eliminate.
(get_data_offset_source): Rename to get_data_offset().
(get_data_offset): Use refer_offset().
(get_binary_value): Likewise; eliminate use of literal_decl_node.
(build_array_of_treeplets): Likewise.
(build_array_of_fourplets): Likewise.
(REFER_CHECK): Comment:
(refer_refmod_length): Use get_any_capacity(); use refer_offset;
set reflen to integer_one_node.
(refer_offset_dest): Change name to refer_offset.
(refer_offset): Use get_data_offset().
(refer_size_dest): Change name to refer_size().
(refer_size): Use get_any_capacity().
(refer_offset_source): Use refer_offset().
(refer_size_source): Likewise.
(qualified_data_source): Likewise.
(qualified_data_dest): Likewise.
(qualified_data_location): Likewise.
* genutil.h: Exceptions; changes to global declarations.
* lexio.cc (likely_nist_file): Added to detect NIST file format.
(cdftext::free_form_reference_format): Handle NIST file format.
* parse.y: (strip_trailing_zeroes): Added.
Changes for exceptions.
* parse_ante.h (parse_error_inc): Likewise.
(YYLLOC_DEFAULT): Likewise.
(static_cast): Likewise.
(is_cobol_word): Change to is_cobol_charset.
(is_cobol_charset): Refine allowed characters.
(require_numeric): Change to require integer.
(require_integer): Likewise.
(current_enabled_ecs): Exceptions.
(is_integer_literal): Change interpretation.
(procedure_division_ready): Exceptions.
(statement_epilog): Likewise.
(statement_begin): Likewise.
* show_parse.h: Changes to GCOBOL_SHOW handling.
* structs.cc: Add symbol_index to cblc_file_t structure.
* symbols.cc (field_str): Repair .initial handling in FldLiteralN.
* symbols.h (struct cbl_field_t): Eliminate literal_decl_node.
(current_enabled_ecs): Exceptions.
* util.cc (cbl_message): Add final newline to error message.
(ftoupper): Added.
(iso_cobol_word): Add list of ISO reserved words.
* util.h (ftoupper): Added.

libgcobol/ChangeLog:

* charmaps.cc: Add #include <vector>.
* common-defs.h (COMMON_DEFS_H_): Add #include <stdio.h>.
(enum cbl_file_mode_t): Add file_mode_any_e.
(enum file_stmt_t): Created.
(cbl_file_mode_str): Add case for file_mode_any_e.
(ec_cmp): Exceptions.
(struct cbl_enabled_exception_t): Likewise.
(struct cbl_declarative_t): Likewise.
(class cbl_enabled_exceptions_array_t): Likewise.
(class cbl_enabled_exceptions_t): Likewise.
(struct cbl_enabled_exceptions_array_t): Likewise.
(enabled_exception_match): Likewise.
* constants.cc: Add #include <vector>.
* exceptl.h (struct cbl_exception_t): Removed.
(struct cbl_declarative_t): Removed.
(class ec_status_t): Removed.
* gcobolio.h: Add symbol_table_index to cblc_file_t.
* gfileio.cc: Add #include <vector>
(establish_status): Comment.
(__io__file_init): Handle symbol_table_index.
(__io__file_delete): Set file->prior_op.
(__io__file_rewrite): Likewise.
(__io__file_read): Likewise.
(__io__file_open): Likewise.
(__io__file_close): Likewise.
* gmath.cc: Include #include <vector>.
* intrinsic.cc: Include #include <vector>.
* libgcobol.cc: Multiple modifications for exceptions.
* valconv.cc: #include <vector>.

(cherry picked from commit c4d0f4c499c400f9f12068c721fbeac501223743)

6 days agocobol: Fix up exception handling [PR119364]
Jakub Jelinek [Fri, 2 May 2025 17:10:59 +0000 (19:10 +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  <jakub@redhat.com>

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)

6 days agocobol, v2: Fix up cobol cross-compilation from 32-bit arches [PR119364]
Jakub Jelinek [Fri, 2 May 2025 17:09:34 +0000 (19:09 +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  <jakub@redhat.com>

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.
(unique_stack::push): Likewise.
(cobol_filename): Likewise.
* lexio.cc: Include config.h first.
(recognize_replacements): Use HOST_SIZE_T_PRINT_UNSIGNED instead of
"%zu" or GCC_PRISZ instead of "z" and cast corresponding argument
to fmt_size_t.
(check_source_format_directive): Likewise.
(parse_replacing_pair): Use size_t(0) instead of 0UL in span_t
construction.
(parse_replace_pairs): Use HOST_SIZE_T_PRINT_UNSIGNED instead of
"%zu" or GCC_PRISZ instead of "z" or HOST_SIZE_T_PRINT_DEC instead
of "%zd" and cast corresponding argument to fmt_size_t.
(parse_copy_directive): Likewise.
(parse_replace_last_off): Likewise.
(parse_replace_text): Likewise.
(bytespan_t::append): Likewise.
(cdftext::map_file): Likewise.
(cdftext::process_file): Likewise.
* symfind.cc (dump_symbol_map2): Likewise.
(dump_symbol_map_value): Likewise.
(build_symbol_map): Likewise.
(is_name::dump_key): Likewise.
(symbol_match2): Likewise.
(symbol_find): Likewise.
(symbol_find_of): Likewise.
* cdf.y: Likewise.
* symbols.cc: Include config.h first.
(cbl_field_t::set_attr): Return uint64_t rather than size_t
and replace size_t(attr) with uint64_t(attr).
(cbl_field_t::clear_attr): Likewise.
(symbol_field_capacity): Use HOST_SIZE_T_PRINT_UNSIGNED instead of
"%zu" or GCC_PRISZ instead of "z" or HOST_SIZE_T_PRINT_DEC instead
of "%zd" and cast corresponding argument to fmt_size_t.
(symbol_find_odo_debug): Likewise.
(symbols_dump): Likewise.
(calculate_capacity): Likewise.
(field_str): Likewise.
(symbols_update): Likewise.
(symbol_field_forward): Likewise.
(numeric_group_attrs): Return uint64_t rather than size_t and
change inherit variable to from size_t to uint64_t.
(new_literal_add): Use HOST_SIZE_T_PRINT_UNSIGNED instead of
"%zu" or GCC_PRISZ instead of "z" or HOST_SIZE_T_PRINT_DEC instead
of "%zd" and cast corresponding argument to fmt_size_t.
(temporaries_t::dump): Likewise.
(cbl_label_t::str): Likewise.
(symbol_label_add): Likewise.
(symbol_program_add): Likewise.
(symbol_forward_names): Likewise.
(symbol_forward_to): Likewise.
(cbl_file_key_t::deforward): Likewise.
(cbl_file_key_t::str): Likewise.
* gengen.cc (show_type): Use PRId64 instead of "ld".
(gg_unique_in_function): Use HOST_SIZE_T_PRINT_DEC instead of
%ld and cast corresponding argument to fmt_size_t.
* scan.l: Add %top section with #include "config.h".
* genmath.cc (parser_add): Use HOST_SIZE_T_PRINT_DEC instead of
%ld and cast corresponding argument to fmt_size_t.
(parser_subtract): Likewise.
* parse.y: Include "config.h" before <fstream>.  Use
HOST_SIZE_T_PRINT_UNSIGNED instead of "%zu" and cast corresponding
argument to fmt_size_t.  Change type of sign_attrs, group_sign and
type_implies from size_t to uint64_t.
(perform_t::ec_labels_t::new_label): Use HOST_SIZE_T_PRINT_UNSIGNED
instead of "%zu" or GCC_PRISZ instead of "z" or HOST_SIZE_T_PRINT_DEC
instead of "%zd" and cast corresponding argument to fmt_size_t.
(stringify_src_t::dump): Likewise.
(lang_check_failed): Likewise.
(numstr2i): Use GCC_PRISZ instead of "z" and pass address of temporary
with fmt_size_t type to sscanf and then copy it over.
(initialize_statement): Use HOST_SIZE_T_PRINT_UNSIGNED instead of
"%zu" or GCC_PRISZ instead of "z" or HOST_SIZE_T_PRINT_DEC instead
of "%zd" and cast corresponding argument to fmt_size_t.
(dump_inspect_oper): Likewise.
(new_literal): Likewise.
(literal_subscripts_valid): Likewise.
(eval_subject_t::label): Likewise.
* genapi.cc (level_88_helper): Likewise.
(parser_call_targets_dump): Likewise.
(combined_name): Use HOST_SIZE_T_PRINT_DEC instead of "%ld"
and cast corresponding argument to fmt_size_t.
(section_label): Likewise.
(paragraph_label): Likewise.
(leave_procedure): Likewise.
(parser_perform): Likewise.
(parser_perform_times): Likewise.
(internal_perform_through): Likewise.
(internal_perform_through_times): Likewise.
(parser_enter_program): Likewise.
(parser_init_list_size): Likewise.
(parser_init_list): Likewise.
(psa_FldLiteralN): Likewise.
(psa_FldBlob): Likewise.
(parser_assign): Likewise.
(parser_free): Pass p->field->name to dbgmsg.
(parser_division): Use HOST_SIZE_T_PRINT_DEC instead of "%ld"
and cast corresponding argument to fmt_size_t.
(perform_outofline_before_until): Likewise.
(perform_outofline_after_until): Likewise.
(perform_outofline_testafter_varying): Likewise.
(perform_outofline_before_varying): Likewise.
(perform_inline_testbefore_varying): Likewise.
(parser_inspect): Change n_operations parameter type from
unsigned long to size_t.
(parser_intrinsic_callv): Use HOST_SIZE_T_PRINT_DEC instead
of "%zd" and cast corresponding argument to fmt_size_t.
(parser_bitop): Use HOST_SIZE_T_PRINT_HEX_PURE instead of
"%lx" and cast corresponding argument to fmt_size_t.
(parser_bitwise_op): Likewise.
(parser_program_hierarchy): Use HOST_SIZE_T_PRINT_DEC instead of "%ld"
and cast corresponding argument to fmt_size_t.
(parser_set_handled): Use HOST_SIZE_T_PRINT_HEX_PURE instead of
"%lx" and cast corresponding argument to fmt_size_t.
(parser_set_numeric): Use HOST_SIZE_T_PRINT_DEC instead of "%ld"
and cast corresponding argument to fmt_size_t.
(psa_new_var_decl): Use HOST_SIZE_T_PRINT_DEC instead of "%ld"
and cast corresponding argument to fmt_size_t.
(parser_symbol_add): Use HOST_SIZE_T_PRINT_DEC instead of "%zd"
or HOST_SIZE_T_PRINT_HEX_PURE instead of "%lx" and cast corresponding
argument to fmt_size_t.
* cdf-copy.cc: Include "config.h" first.
* scan_ante.h (trim_location): Use HOST_SIZE_T_PRINT_UNSIGNED instead
of "%zu" or "%d" and cast corresponding argument to fmt_size_t.
* structs.cc (create_cblc_field_t): Use ULONGLONG instead of SIZE
for "attr".
* cbldiag.h (dbgmsg): Add ATTRIBUTE_PRINTF_1.
* gcobolspec.cc (lang_specific_driver): Use HOST_SIZE_T_PRINT_DEC
instead of "%ld" and cast corresponding argument to fmt_size_t.
* parse_ante.h (literal_of): Use HOST_SIZE_T_PRINT_UNSIGNED instead of
"%zu" or GCC_PRISZ instead of "z" or HOST_SIZE_T_PRINT_DEC instead
of "%zd" and cast corresponding argument to fmt_size_t.
(evaluate_elem_t::dump): Likewise.
(arith_t::another_pair): Likewise.
(current_t::end_program): Likewise.
(file_add): Likewise.
(implicit_paragraph): Likewise.
(implicit_section): Likewise.
(data_division_ready): Use HOST_SIZE_T_PRINT_DEC instead of "%d"
and cast corresponding argument to fmt_size_t.
* symbols.h (struct cbl_field_t): Change attr member type from size_t
to uint64_t.
(cbl_field_t::set_attr): Change return type from size_t to uint64_t.
(cbl_field_t::clear_attr): Likewise.
(function_descr_t::init): Use HOST_SIZE_T_PRINT_UNSIGNED instead of
"%zu" or GCC_PRISZ instead of "z" or HOST_SIZE_T_PRINT_DEC instead
of "%zd" and cast corresponding argument to fmt_size_t.
(cbl_perform_tgt_t::dump): Likewise.
(numeric_group_attrs): Change return type from size_t to uint64_t.

(cherry picked from commit 4704b94fc76b51e79e6fcf63344f70da4d89d75c)

6 days agocobol: New testcases.
Robert Dubner [Fri, 25 Apr 2025 14:19:35 +0000 (10:19 -0400)] 
cobol: New testcases.

These testcases are derived from the cobolworx run_fundamental.at file.

gcc/testsuite

* cobol.dg/group2/88_level_with_FALSE_IS_clause.cob: New testcase.
* cobol.dg/group2/88_level_with_FILLER.cob: Likewise.
* cobol.dg/group2/88_level_with_THRU.cob: Likewise.
* cobol.dg/group2/ADD_CORRESPONDING.cob: Likewise.
* cobol.dg/group2/ADD_SUBTRACT_CORR_mixed_fix___float.cob: Likewise.
* cobol.dg/group2/ALPHABETIC-LOWER_test.cob: Likewise.
* cobol.dg/group2/ALPHABETIC_test.cob: Likewise.
* cobol.dg/group2/ALPHABETIC-UPPER_test.cob: Likewise.
* cobol.dg/group2/BLANK_WHEN_ZERO.cob: Likewise.
* cobol.dg/group2/Check_for_equality_of_COMP-1___COMP-2.cob: Likewise.
* cobol.dg/group2/Compare_COMP-2_with_floating-point_literal.cob: Likewise.
* cobol.dg/group2/Contained_program_visibility__3_.cob: Likewise.
* cobol.dg/group2/Contained_program_visibility__4_.cob: Likewise.
* cobol.dg/group2/Context_sensitive_words__1_.cob: Likewise.
* cobol.dg/group2/Context_sensitive_words__2_.cob: Likewise.
* cobol.dg/group2/Context_sensitive_words__3_.cob: Likewise.
* cobol.dg/group2/Context_sensitive_words__4_.cob: Likewise.
* cobol.dg/group2/Context_sensitive_words__5_.cob: Likewise.
* cobol.dg/group2/Context_sensitive_words__6_.cob: Likewise.
* cobol.dg/group2/Context_sensitive_words__7_.cob: Likewise.
* cobol.dg/group2/Context_sensitive_words__8_.cob: Likewise.
* cobol.dg/group2/debugging_lines__not_active_.cob: Likewise.
* cobol.dg/group2/debugging_lines__WITH_DEBUGGING_MODE_.cob: Likewise.
* cobol.dg/group2/DEBUG_Line.cob: Likewise.
* cobol.dg/group2/DISPLAY_and_assignment_NumericDisplay.cob: Likewise.
* cobol.dg/group2/DISPLAY_data_items_with_MOVE_statement.cob: Likewise.
* cobol.dg/group2/DISPLAY_data_items_with_VALUE_clause.cob: Likewise.
* cobol.dg/group2/DISPLAY_literals__DECIMAL-POINT_is_COMMA.cob: Likewise.
* cobol.dg/group2/GLOBAL_at_lower_level.cob: Likewise.
* cobol.dg/group2/GLOBAL_at_same_level.cob: Likewise.
* cobol.dg/group2/GLOBAL_FD__1_.cob: Likewise.
* cobol.dg/group2/GLOBAL_FD__2_.cob: Likewise.
* cobol.dg/group2/GLOBAL_FD__3_.cob: Likewise.
* cobol.dg/group2/GLOBAL_FD__4_.cob: Likewise.
* cobol.dg/group2/Hexadecimal_literal.cob: Likewise.
* cobol.dg/group2/integer_arithmetic_on_floating-point_var.cob: Likewise.
* cobol.dg/group2/MULTIPLY_BY_literal_in_INITIAL_program.cob: Likewise.
* cobol.dg/group2/Named_conditionals_-_fixed__float__and_alphabetic.cob: Likewise.
* cobol.dg/group2/Numeric_operations__1_.cob: Likewise.
* cobol.dg/group2/Numeric_operations__2_.cob: Likewise.
* cobol.dg/group2/Numeric_operations__3_.cob: Likewise.
* cobol.dg/group2/Numeric_operations__4_.cob: Likewise.
* cobol.dg/group2/Numeric_operations__5_.cob: Likewise.
* cobol.dg/group2/Numeric_operations__7_.cob: Likewise.
* cobol.dg/group2/Numeric_operations__8_.cob: Likewise.
* cobol.dg/group2/ROUNDED_AWAY-FROM-ZERO.cob: Likewise.
* cobol.dg/group2/ROUNDED_NEAREST-AWAY-FROM-ZERO.cob: Likewise.
* cobol.dg/group2/ROUNDED_NEAREST-EVEN.cob: Likewise.
* cobol.dg/group2/ROUNDED_NEAREST-TOWARD-ZERO.cob: Likewise.
* cobol.dg/group2/ROUNDED_TOWARD-GREATER.cob: Likewise.
* cobol.dg/group2/ROUNDED_TOWARD-LESSER.cob: Likewise.
* cobol.dg/group2/ROUNDED_TRUNCATION.cob: Likewise.
* cobol.dg/group2/ROUNDING_omnibus_Floating-Point_from_COMPUTE.cob: Likewise.
* cobol.dg/group2/ROUNDING_omnibus_NumericDisplay_from_COMPUTE.cob: Likewise.
* cobol.dg/group2/Separate_sign_positions__1_.cob: Likewise.
* cobol.dg/group2/Separate_sign_positions__2_.cob: Likewise.
* cobol.dg/group2/Simple_p-scaling.cob: Likewise.
* cobol.dg/group2/Simple_TYPEDEF.cob: Likewise.
* cobol.dg/group2/ADD_SUBTRACT_CORR_mixed_fix___float.out: New known-good result.
* cobol.dg/group2/BLANK_WHEN_ZERO.out: Likewise.
* cobol.dg/group2/Contained_program_visibility__4_.out: Likewise.
* cobol.dg/group2/Context_sensitive_words__1_.out: Likewise.
* cobol.dg/group2/Context_sensitive_words__2_.out: Likewise.
* cobol.dg/group2/Context_sensitive_words__3_.out: Likewise.
* cobol.dg/group2/Context_sensitive_words__4_.out: Likewise.
* cobol.dg/group2/Context_sensitive_words__5_.out: Likewise.
* cobol.dg/group2/Context_sensitive_words__6_.out: Likewise.
* cobol.dg/group2/Context_sensitive_words__7_.out: Likewise.
* cobol.dg/group2/Context_sensitive_words__8_.out: Likewise.
* cobol.dg/group2/debugging_lines__not_active_.out: Likewise.
* cobol.dg/group2/debugging_lines__WITH_DEBUGGING_MODE_.out: Likewise.
* cobol.dg/group2/DEBUG_Line.out: Likewise.
* cobol.dg/group2/DISPLAY_and_assignment_NumericDisplay.out: Likewise.
* cobol.dg/group2/DISPLAY_data_items_with_MOVE_statement.out: Likewise.
* cobol.dg/group2/DISPLAY_data_items_with_VALUE_clause.out: Likewise.
* cobol.dg/group2/DISPLAY_literals__DECIMAL-POINT_is_COMMA.out: Likewise.
* cobol.dg/group2/GLOBAL_at_lower_level.out: Likewise.
* cobol.dg/group2/GLOBAL_at_same_level.out: Likewise.
* cobol.dg/group2/Hexadecimal_literal.out: Likewise.
* cobol.dg/group2/Named_conditionals_-_fixed__float__and_alphabetic.out: Likewise.
* cobol.dg/group2/ROUNDED_AWAY-FROM-ZERO.out: Likewise.
* cobol.dg/group2/ROUNDED_NEAREST-AWAY-FROM-ZERO.out: Likewise.
* cobol.dg/group2/ROUNDED_NEAREST-EVEN.out: Likewise.
* cobol.dg/group2/ROUNDED_NEAREST-TOWARD-ZERO.out: Likewise.
* cobol.dg/group2/ROUNDED_TOWARD-GREATER.out: Likewise.
* cobol.dg/group2/ROUNDED_TOWARD-LESSER.out: Likewise.
* cobol.dg/group2/ROUNDED_TRUNCATION.out: Likewise.
* cobol.dg/group2/ROUNDING_omnibus_Floating-Point_from_COMPUTE.out: Likewise.
* cobol.dg/group2/ROUNDING_omnibus_NumericDisplay_from_COMPUTE.out: Likewise.
* cobol.dg/group2/Separate_sign_positions__1_.out: Likewise.
* cobol.dg/group2/Separate_sign_positions__2_.out: Likewise.
* cobol.dg/group2/Simple_p-scaling.out: Likewise.

(cherry picked from commit 591831dcd4bc9cb9c089d952e73ec8bfcb6cb3fb)

6 days agocobol: Repair some exception processing logic.
Robert Dubner [Thu, 24 Apr 2025 20:26:58 +0000 (16:26 -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)

6 days agolibgcobol: Check for struct tm tm_zone
Rainer Orth [Mon, 21 Apr 2025 13:59:14 +0000 (15:59 +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  <ro@CeBiTec.Uni-Bielefeld.DE>

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)

6 days agotestsuite: Adjust s390x params for vector tests.
Juergen Christ [Tue, 29 Jul 2025 14:23:24 +0000 (16:23 +0200)] 
testsuite: Adjust s390x params for vector tests.

Loop peeling and minimal loop vectorization threshold prevented loop
vectorization in these examples.  Adjust parameters in the test to
make the test pass.

Signed-off-by: Juergen Christ <jchrist@linux.ibm.com>
PR testsuite/121286
PR testsuite/121288

gcc/testsuite/ChangeLog:

* gcc.dg/vect/pr112325.c: Adjust parameters for s390.
* gcc.dg/vect/pr117888-1.c: Ditto.

6 days agoDarwin: account for macOS 26
Francois-Xavier Coudert [Mon, 14 Jul 2025 10:14:00 +0000 (12:14 +0200)] 
Darwin: account for macOS 26

darwin25 will be named macOS 26 (codename Tahoe). This is a change from
darwin24, which was macOS 15. We need to adapt the driver to this new
numbering scheme.

2025-07-14  François-Xavier Coudert  <fxcoudert@gcc.gnu.org>

gcc/ChangeLog:

PR target/120645
* config/darwin-driver.cc: Account for latest macOS numbering
scheme.

gcc/testsuite/ChangeLog:

* gcc.dg/darwin-minversion-link.c: Account for macOS 26.

(cherry picked from commit cc4f3397331f6ecd5e775cf963c65face0145f3f)

6 days agoc++, coroutines: Handle allocation fail returns [PR121219].
Iain Sandoe [Wed, 23 Jul 2025 15:22:32 +0000 (16:22 +0100)] 
c++, coroutines: Handle allocation fail returns [PR121219].

The current implementation was returning the result of the g_r_o_o_a_f
call independently of the return expressions for 'normal' cases.

This prevents the NVRO that we need to guarantee copy elision for the
ramp return values - when these are initialised from a temporary of the
same type.

The solution here reorders the code so that the regular return expression
appears before the allocation-failed case.  Ensure that the g_r_o and
associated code appears in a distinct scope.  These steps are to meet the
constaints of NRV.

PR c++/121219

gcc/cp/ChangeLog:

* coroutines.cc
(cp_coroutine_transform::build_ramp_function): Reorder the return
expressions for the 'normal' and 'allocation failed' cases so that
NRV constraints are met.

gcc/testsuite/ChangeLog:

* g++.dg/coroutines/torture/pr121219.C: New test.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
(cherry picked from commit a2775feb7c7de9f21f79052e2b6a752a3eb08f07)

6 days agoc++: add passing testcases [PR120243]
Jason Merrill [Wed, 9 Jul 2025 15:13:19 +0000 (11:13 -0400)] 
c++: add passing testcases [PR120243]

These pass now; the first was fixed by r16-1507.

PR c++/120243

gcc/testsuite/ChangeLog:

* g++.dg/coroutines/torture/pr120243-unhandled-1.C: New test.
* g++.dg/coroutines/torture/pr120243-unhandled-2.C: New test.

(cherry picked from commit 2492bab503f57f2cf6e08e5c104f7a1d31d34047)

6 days agoc++, coroutines: CWG2563 promise lifetime extension [PR115908].
Iain Sandoe [Sat, 31 May 2025 18:59:04 +0000 (19:59 +0100)] 
c++, coroutines: CWG2563 promise lifetime extension [PR115908].

This implements the final piece of the revised CWG2563 wording;
"It exits the scope of promise only if the coroutine completed
 without suspending."

Considering the coroutine to be made up of two components; a
'ramp' and a 'body' where the body represents the user's original
code and the ramp is responsible for setup of that and for
returning some object to the original caller.

Coroutine state, and responsibility for its release.

A coroutine has some state that persists across suspensions.

The state has two components:
  * State that is specified by the standard and persists for the entire
    life of the coroutine.
  * Local state that is constructed/destructed as scopes in the original
    function body are entered/exited.  The destruction of local state is
    always the responsibility of the body code.

The persistent state (and the overall storage for the state) must be
managed in two places:
  * The ramp function (which allocates and builds this - and can, in some
    cases, be responsible for destroying it)
  * The re-written function body which can destroy it when that body
    completes its final suspend - or when the handle.destroy () is called.

In all cases the ramp holds responsibility for constructing the standard-
mandated persistent state.

There are four ways in which the ramp might be re-entered after starting
the function body:
  A The body could suspend (one might expect that to be the 'normal' case
    for most coroutines).
  B The body might complete either synchronously or via continuations.
  C An exception might be thrown during the setup of the initial await
    expression, before the initial awaiter resumes.
  D An exception might be processed by promise.unhandled_exception () and
    that, in turn, might re-throw it (or throw something else).  In this
    case, the coroutine is considered suspended at the final suspension
    point.

Once the coroutine has passed initial suspend (i.e. the initial awaiter
await_resume() has been called) the body is considered to have a use of
the state.

Until the ramp return value has been constructed, the ramp is considered
to have a use of the state.

To manage these interacting conditions we allocate a reference counter
for the frame state.  This is initialised to 1 by the ramp as part of its
startup (note that failures/exceptions in the startup code are handled
locally to the ramp).

When the body returns (either normally, or by exception) the ramp releases
its use.

Once the rewritten coroutine body is started, the body is considered to
have a use of the frame.  This use (potentially) needs to be released if
an exception is thrown from the body.  We implement this using an eh-only
cleanup around the initial await.  If we have the case D above, then we
do not release the body use.

In case:

  A, typically the ramp would be re-entered with the body holding a use,
  and therefore the ramp should not destroy the state.

  B, both the body and ramp will have released their uses, and the ramp
  should destroy the state.

  C, we must arrange for the body to release its use, because we require
  the ramp to cleanup in this circumstance.

  D is an outlier, since the responsibility for destruction of the state
  now rests with the user's code (via a handle.destroy() call).

  NOTE: In the case that the body has never suspended before such an
  exception occurs, the only reasonable way for the user code to obtain the
  necessary handle is if unhandled_exception() throws the handle or some
  object that contains the handle.  That is outside of the designs here -
  if the user code might need this corner-case, then such provision will
  have to be made.

In the ramp, we implement destruction for the persistent frame state by
means of cleanups.  These are run conditionally when the reference count
is 0 signalling that both the body and the ramp have completed.

In the body, once we pass the final suspend, then we test the use and
delete the state if the use is 0.

PR c++/115908
PR c++/118074
PR c++/95615

gcc/cp/ChangeLog:

* coroutines.cc (coro_frame_refcount_id): New.
(coro_init_identifiers): Initialise coro_frame_refcount_id.
(build_actor_fn): Set up initial_await_resume_called.  Handle
decrementing of the frame reference count.  Return directly to
the caller if that is non-zero.
(cp_coroutine_transform::wrap_original_function_body): Use a
conditional eh-only cleanup around the initial await expression
to release the body use on exception before initial await
resume.
(cp_coroutine_transform::build_ramp_function): Wrap the called
body in a cleanup that releases a use of the frame when we
return to the ramp.  Implement frame, promise and argument copy
destruction via conditional cleanups when the frame use count
is zero.

gcc/testsuite/ChangeLog:

* g++.dg/coroutines/pr115908.C: Move to...
* g++.dg/coroutines/torture/pr115908.C: ...here.
* g++.dg/coroutines/torture/pr95615-02.C: Move to...
* g++.dg/coroutines/torture/pr95615-01-promise-ctor-throws.C: ...here.
* g++.dg/coroutines/torture/pr95615-03.C: Move to...
* g++.dg/coroutines/torture/pr95615-02-get-return-object-throws.C: ...here.
* g++.dg/coroutines/torture/pr95615-01.C: Move to...
* g++.dg/coroutines/torture/pr95615-03-initial-suspend-throws.C: ...here.
* g++.dg/coroutines/torture/pr95615-04.C: Move to...
* g++.dg/coroutines/torture/pr95615-04-initial-await-ready-throws.C: ...here.
* g++.dg/coroutines/torture/pr95615-05.C: Move to...
* g++.dg/coroutines/torture/pr95615-05-initial-await-suspend-throws.C: ...here.
* g++.dg/coroutines/torture/pr95615.inc: Add more cases and ensure that the
code completes properly when no exceptions are thrown.
* g++.dg/coroutines/torture/pr95615-00-nothing-throws.C: New test.
* g++.dg/coroutines/torture/pr95615-06-initial-await-resume-throws.C: New test.
* g++.dg/coroutines/torture/pr95615-07-body-throws.C: New test.
* g++.dg/coroutines/torture/pr95615-08-initial-suspend-throws-uhe-throws.C: New test.
* g++.dg/coroutines/torture/pr95615-09-body-throws-uhe-throws.C: New test.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
(cherry picked from commit 43e408f675f8e998c94462346f4306cd4716e138)

6 days agoc++, coroutines: Remove use of coroutine handle in the frame.
Iain Sandoe [Mon, 16 Jun 2025 06:12:29 +0000 (09:12 +0300)] 
c++, coroutines: Remove use of coroutine handle in the frame.

We have been keeping a copy of coroutine_handle<promise> in the state
frame, as it was expected to be efficient to use this to initialize the
argument to await_suspend.  This does not turn out to be the case and
intializing the value is obstructive to CGW2563 fixes.  This removes
the use.

gcc/cp/ChangeLog:

* coroutines.cc (struct coroutine_info): Update comments.
(struct coro_aw_data): Remove self_handle and add in
information to create the handle in lowering.
(expand_one_await_expression): Build a temporary coroutine
handle.
(build_actor_fn): Remove reference to the frame copy of the
coroutine handle.
(cp_coroutine_transform::wrap_original_function_body): Remove
reference to the frame copy of the coroutine handle.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
(cherry picked from commit 8a3acd8cf449636079acb3d1dfcbcabb074b75af)

6 days agoc++,coroutines: Handle await expressions in assume attributes.
Iain Sandoe [Mon, 9 Jun 2025 10:26:01 +0000 (11:26 +0100)] 
c++,coroutines: Handle await expressions in assume attributes.

Here we have an expression that is not evaluated but is still seen
as potentially-evaluated.  We handle this by determining if the
operand has side-effects, producing a warning that the assume has
been ignored and eliding it.

gcc/cp/ChangeLog:

* coroutines.cc (analyze_expression_awaits): Elide assume
attributes containing await expressions, since these have
side effects.  Emit a diagnostic that this has been done.

gcc/testsuite/ChangeLog:

* g++.dg/coroutines/assume.C: New test.

(cherry picked from commit 4ff09eb3422c525d514c869c7e0366fd5b40b561)

6 days agoc++, coroutines: Handle unevaluated contexts.
Iain Sandoe [Sun, 8 Jun 2025 13:28:01 +0000 (14:28 +0100)] 
c++, coroutines: Handle unevaluated contexts.

From [expr.await]/2
We should not accept co_await, co_yield in unevaluated contexts.

Currently (see PR68604) we do not mark typeid expressions as unevaluated
since the standard rules mean that this depends on the value type.

gcc/cp/ChangeLog:

* coroutines.cc (finish_co_await_expr): Do not allow in an
unevaluated context.
(finish_co_yield_expr): Likewise.

gcc/testsuite/ChangeLog:

* g++.dg/coroutines/unevaluated.C: New test.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
(cherry picked from commit e2bff264e8b92426b13aacec3087cb97971ec9b9)

6 days agoc++, coroutines: Avoid UNKNOWN_LOCATION synthesizing code [PR120273].
Iain Sandoe [Tue, 3 Jun 2025 12:07:27 +0000 (13:07 +0100)] 
c++, coroutines: Avoid UNKNOWN_LOCATION synthesizing code [PR120273].

Some of the lookup code is expecting to find a valid (not UNKNOWN)
location, which triggers in the reported case.  To avoid this, we are
reverting the change to use UNKNOWN_LOCATION for synthesizing the
wrapper, and instead using the start and end locations of the original
function.

PR c++/120273

gcc/cp/ChangeLog:

* coroutines.cc
(cp_coroutine_transform::wrap_original_function_body): Use
function start and end locations when synthesizing code.
(cp_coroutine_transform::cp_coroutine_transform): Set the
function end location.

gcc/testsuite/ChangeLog:

* g++.dg/coroutines/pr120273.C: New test.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
(cherry picked from commit 3b95be7bd1882add4b1e22f6b70bc130cd465eca)

6 days agoc++, coroutines: Improve diagnostics for awaiter/promise.
Iain Sandoe [Thu, 29 May 2025 15:50:44 +0000 (16:50 +0100)] 
c++, coroutines: Improve diagnostics for awaiter/promise.

At present, we can issue diagnostics about missing or malformed
awaiter or promise methods when we encounter their uses in the
body of a user's function.  We might then re-issue the same
diagnostics when processing the initial or final await expressions.

This change avoids such duplication, and also attempts to
identify issues with the initial or final expressions specifically
since diagnostics for those do not have any useful line number.

gcc/cp/ChangeLog:

* coroutines.cc (build_co_await): Identify diagnostics
for initial and final await expressions.
(cp_coroutine_transform::wrap_original_function_body): Do
not handle initial and final await expressions here ...
(cp_coroutine_transform::apply_transforms): ... handle them
here and avoid duplicate diagnostics.
* coroutines.h: Declare inital and final await expressions
in the transform class.  Save the function closing brace
location.

gcc/testsuite/ChangeLog:

* g++.dg/coroutines/coro1-missing-await-method.C: Adjust for
improved diagnostics.
* g++.dg/coroutines/coro-missing-final-suspend.C: Likewise.
* g++.dg/coroutines/pr104051.C: Move to...
* g++.dg/coroutines/pr104051-0.C: ...here.
* g++.dg/coroutines/pr104051-1.C: New test.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
(cherry picked from commit 4c014a9db521b24bd900eb9a6ac70988322a57da)

6 days agoc++, coroutines: Handle builtin_constant_p [PR116775].
Iain Sandoe [Mon, 9 Jun 2025 10:00:47 +0000 (11:00 +0100)] 
c++, coroutines: Handle builtin_constant_p [PR116775].

Since the folding of this builtin happens after the main coroutine FE
lowering, we need to account for await expressions in that lowering.

Since these expressions have a property of being not evaluated, but do
not have the full constraints of an unevaluatated context, we want to
apply the checks and then remove the await expressions so that they no
longer participate in the analysis and lowering.

When a builtin_constant_p call is encountered, and the operand contains
any await expression, we check to see if the operand can be a constant
and replace the call with its result.

PR c++/116775

gcc/cp/ChangeLog:

* coroutines.cc (analyze_expression_awaits): When we see
a builtin_constant_p call, and that contains one or more
await expressions, then replace the call with its result
and discard the unevaluated operand.

gcc/testsuite/ChangeLog:

* g++.dg/coroutines/pr116775.C: New test.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
(cherry picked from commit ab3f04b73e5a1dd734d3bab64b4878d2d0cc29ad)

6 days agoc++, coroutines: Ensure that the resumer is marked as can_throw.
Iain Sandoe [Sat, 7 Jun 2025 16:01:15 +0000 (17:01 +0100)] 
c++, coroutines: Ensure that the resumer is marked as can_throw.

We must flag that the resumer might throw (since the wrapping of the
original function body unconditionally adds a try-catch/rethrow). We
also add code that might throw - even when the original function body
would not.

TODO: We could improve code-gen by recognising cases where the combined
body + initial await expressions cannot throw and omitting the unneeded
try/catch/rethrow wrapper.

gcc/cp/ChangeLog:

* coroutines.cc (build_actor_fn): Set can_throw.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
(cherry picked from commit e83c4bfc338fad0c87b2debb37ccfe98d148c7ac)

6 days agoc++: Fix template class lookup [PR120495, PR115605].
Iain Sandoe [Mon, 2 Jun 2025 08:42:23 +0000 (09:42 +0100)] 
c++: Fix template class lookup [PR120495, PR115605].

In the reported issues, using lookup_template_class () directly on (for example)
the coroutine_handle identifier fails because a class-local  TYPE_DECL is found.
This is because, in the existing code, lookup is called with default parameters
which means that class contexts are examined first.

Fix this, when a context is provided by the caller, by doing lookup in namespace
provided.

PR c++/120495
PR c++/115605

gcc/cp/ChangeLog:

* pt.cc (lookup_template_class): Honour provided namespace contexts
when looking up class templates.

gcc/testsuite/ChangeLog:

* g++.dg/coroutines/pr120495.C: New test.
* g++.dg/pr115605.C: New test.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
(cherry picked from commit cf588f1a8e7406ced5b08f32f9d23f015a240a31)

6 days agoc++, coroutines: Make analyze_fn_params into a class method.
Iain Sandoe [Thu, 29 May 2025 15:45:44 +0000 (16:45 +0100)] 
c++, coroutines: Make analyze_fn_params into a class method.

This continues code cleanups and migration to encapsulation of the
whole coroutine transform.

gcc/cp/ChangeLog:

* coroutines.cc (analyze_fn_parms): Move from free function..
(cp_coroutine_transform::analyze_fn_parms):... to method.
(cp_coroutine_transform::apply_transforms): Adjust call to
analyze_fn_parms.
* coroutines.h: Declare analyze_fn_parms.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
(cherry picked from commit 2a8af97e3528f812201687334f64b27b94d01271)

6 days agoc++, coroutines: Simplify initial_await_resume_called.
Iain Sandoe [Thu, 29 May 2025 12:43:37 +0000 (13:43 +0100)] 
c++, coroutines: Simplify initial_await_resume_called.

We do not need to generate this code early, since it does not affect
any of the analysis.  Lowering it later takes less code, and avoids
modifying the initial await expresssion which will simplify changes
to analysis to deal with open PRs.

gcc/cp/ChangeLog:

* coroutines.cc (expand_one_await_expression): Set the
initial_await_resume_called flag here.
(build_actor_fn): Populate the frame accessor for the
initial_await_resume_called flag.
(cp_coroutine_transform::wrap_original_function_body): Do
not modify the initial_await expression to include the
initial_await_resume_called flag here.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
(cherry picked from commit bfd4aae0a999375cf008b75c14607c7b94daced3)

6 days agoc++, coroutines: Some cleanups in build_actor.
Iain Sandoe [Sat, 31 May 2025 15:13:40 +0000 (16:13 +0100)] 
c++, coroutines: Some cleanups in build_actor.

We were incorrectly guarding all the frame cleanups on the
basis of frame_needs_free (which is always set for the present
code-gen since we have no allocation elision).  The net result
being that the (incorrect) code was behaving as expected.

We built, but never used, a label for the frame destruction;
in practice it is never triggered independently of the promise
and argument copy destruction.

Finally there are a few instances where we had been building
expressions manually rather than using higher-level APIs.

gcc/cp/ChangeLog:

* coroutines.cc (build_actor_fn): Remove an unused
label, guard the frame deallocation correctly, use
simpler APIs to build if and return statements.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
(cherry picked from commit 7037c72a8bb41ed07da64b23e14857a066a91baa)

6 days agoc++: Emit an error for attempted constexpr co_await [PR118903].
Iain Sandoe [Fri, 30 May 2025 19:09:40 +0000 (20:09 +0100)] 
c++: Emit an error for attempted constexpr co_await [PR118903].

We checked that the coroutine expressions were not suitable for
constexpr, but did not emit and error when needed.

PR c++/118903

gcc/cp/ChangeLog:

* constexpr.cc (potential_constant_expression_1): Emit
an error when co_await et. al. are used in constexpr
contexts.

gcc/testsuite/ChangeLog:

* g++.dg/coroutines/pr118903.C: New test.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
(cherry picked from commit 0ae77a05c416c9f750cb87f1bef0800651168b7e)

6 days agoc++: Add co_await, co_yield and co_return to dump_expr.
Iain Sandoe [Fri, 30 May 2025 19:06:26 +0000 (20:06 +0100)] 
c++: Add co_await, co_yield and co_return to dump_expr.

These were omitted there as an oversight, most of the error handling
for the coroutines code is specific rather than using generic %qE etc.

gcc/cp/ChangeLog:

* error.cc (dump_expr): Add co_await, co_yield and co_return.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
(cherry picked from commit 09cac2a833689f2535d6c2c88a67b2169df4e4d7)

6 days agoc++, coroutines: Make a check more specific [PR109283].
Iain Sandoe [Thu, 29 May 2025 14:45:29 +0000 (15:45 +0100)] 
c++, coroutines: Make a check more specific [PR109283].

The check was intended to assert that we had visited contained
ternary expressions with embedded co_awaits, but had been made
too general - and therefore was ICEing on code that was actually
OK.  Fixed by checking specifically that no co_awaits embedded.

PR c++/109283

gcc/cp/ChangeLog:

* coroutines.cc (find_any_await): Only save the statement
pointer if the caller passes a place for it.
(flatten_await_stmt): When checking that ternary expressions
have been handled, also check that they contain a co_await.

gcc/testsuite/ChangeLog:

* g++.dg/coroutines/pr109283.C: New test.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
(cherry picked from commit 977fadd69776e2a8a6daca43e1c898bc4f87154d)

6 days agoc++, coroutines: Clean up the ramp cleanups.
Iain Sandoe [Mon, 12 May 2025 19:38:48 +0000 (20:38 +0100)] 
c++, coroutines: Clean up the ramp cleanups.

This replaces the cleanup try-catch block in the ramp with a series of
eh-only cleanup statements.

Includes
 typo fixes from 83aa09e90487b52c1772eeffc4af577ee70536f1
 dead code removal from 7bba8d48ea556a03bdc4e9076740b83d3db6599e

gcc/cp/ChangeLog:

* coroutines.cc (analyze_fn_parms): No longer
create a parameter copy guard var.
(cp_coroutine_transform::build_ramp_function): Replace ramp
cleanup try-catch block with eh-only cleanup statements.
* coroutines.h (struct param_info): Remove the
entry for the parameter copy destructor guard.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
(cherry picked from commit 18df4a10bc96946401218019ec566d867238b3e4)

6 days agoc++, coroutines: Use decltype(auto) for the g_r_o.
Iain Sandoe [Sun, 11 May 2025 19:36:58 +0000 (20:36 +0100)] 
c++, coroutines: Use decltype(auto) for the g_r_o.

The revised wording for coroutines, uses decltype(auto) for the
type of the get return object, which preserves references.

It is quite reasonable for a  coroutine body implementation to
complete before control is returned to the ramp - and in that
case we would be creating the ramp return object from an already-
deleted promise object.

Jason observes that this is a terrible situation and we should
seek a resolution to it via core.

Since the test added here explicitly performs the unsafe action
dscribed above we expect it to fail (until a resolution is found).

gcc/cp/ChangeLog:

* coroutines.cc
(cp_coroutine_transform::build_ramp_function): Use
decltype(auto) to determine the type of the temporary
get_return_object.

gcc/testsuite/ChangeLog:

* g++.dg/coroutines/pr115908.C: Count promise construction
and destruction. Run the test and XFAIL it.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
(cherry picked from commit e71a6e002c6650a7a7be99277120d3e59ecb78a3)

6 days agoc++, coroutines: Address CWG2563 return value init [PR119916].
Iain Sandoe [Mon, 12 May 2025 18:47:42 +0000 (19:47 +0100)] 
c++, coroutines: Address CWG2563 return value init [PR119916].

This addresses the clarification that, when the get_return_object is of a
different type from the ramp return, any necessary conversions should be
performed on the return expression (so that they typically occur after the
function body has started execution).

PR c++/119916

gcc/cp/ChangeLog:

* coroutines.cc
(cp_coroutine_transform::wrap_original_function_body): Do not
initialise initial_await_resume_called here...
(cp_coroutine_transform::build_ramp_function): ... but here.
When the coroutine is not void, initialize a GRO object from
promise.get_return_object().  Use this as the argument to the
return expression.  Use a regular cleanup for the GRO, since
it is ramp-local.

gcc/testsuite/ChangeLog:

* g++.dg/coroutines/torture/special-termination-00-sync-completion.C:
Amend for CWG2563 expected behaviour.
* g++.dg/coroutines/torture/special-termination-01-self-destruct.C:
Likewise.
* g++.dg/coroutines/torture/pr119916.C: New test.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
(cherry picked from commit e06555a40c051d5062405b02f93b89b01a397f97)

6 days agoc++, coroutines: Fix identification of coroutine ramps [PR120453].
Iain Sandoe [Thu, 29 May 2025 10:00:18 +0000 (11:00 +0100)] 
c++, coroutines: Fix identification of coroutine ramps [PR120453].

The existing implementation, incorrectly, tried to use DECL_RAMP_FN
in check_return_expr to determine if we are handling a ramp func.
However, that query is only set for the resume/destroy functions.

Replace the use of DECL_RAMP_FN with a new query.

PR c++/120453

gcc/cp/ChangeLog:

* cp-tree.h (DECL_RAMP_P): New.
* typeck.cc (check_return_expr): Use DECL_RAMP_P instead
of DECL_RAMP_FN.

gcc/testsuite/ChangeLog:

* g++.dg/coroutines/pr120453.C: New test.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
(cherry picked from commit 217b7f655227a52e5fe26729baa09dc6083ed577)

6 days agoc++, coroutines: Allow NVRO in more cases for ramp functions.
Iain Sandoe [Sat, 10 May 2025 16:22:55 +0000 (17:22 +0100)] 
c++, coroutines: Allow NVRO in more cases for ramp functions.

The constraints of the c++ coroutines specification require the ramp
to construct a return object early in the function.  This will be returned
at some later time.  This is implemented as NVRO but requires that copying
be well-formed even though it will be elided.  Special-case ramp functions
to allow this.

gcc/cp/ChangeLog:

* typeck.cc (check_return_expr): Suppress conversions for NVRO
in coroutine ramp functions.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
(cherry picked from commit d87caa9d3595ca845c9282cef8b0c9a656d8def0)

6 days agoc++: Set the outer brace marker for missed cases.
Iain Sandoe [Sat, 10 May 2025 16:12:44 +0000 (17:12 +0100)] 
c++: Set the outer brace marker for missed cases.

In some cases, a function might be declared as FUNCTION_NEEDS_BODY_BLOCK
but all the content is contained within that block.  However, poplevel
is currently assuming that such cases would always contain subblocks.

In the case that we do have a body block, but there are no subblocks
then st the outer brace marker on the body block.  This situation occurs
for at least coroutine lambda ramp functions and empty constructors.

gcc/cp/ChangeLog:

* decl.cc (poplevel): Set BLOCK_OUTER_CURLY_BRACE_P on the
body block for functions with no subblocks.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
(cherry picked from commit 689bc394efe9e042acb37799deec6568c0f63a45)

6 days agotree-sra: Avoid total SRA if there are incompat. aggregate accesses (PR119085)
Martin Jambor [Wed, 23 Jul 2025 09:22:33 +0000 (11:22 +0200)] 
tree-sra: Avoid total SRA if there are incompat. aggregate accesses  (PR119085)

We currently use the types encountered in the function body and not in
type declaration to perform total scalarization.  Bug PR 119085
uncovered that we miss a check that when the same data is accessed
with aggregate types that those are actually compatible.  Without it,
we can base total scalarization on a type that does not "cover" all
live data in a different part of the function.  This patch adds the
check.

gcc/ChangeLog:

2025-07-21  Martin Jambor  <mjambor@suse.cz>

PR tree-optimization/119085
* tree-sra.cc (sort_and_splice_var_accesses): Prevent total
scalarization if two incompatible aggregates access the same place.

gcc/testsuite/ChangeLog:

2025-07-21  Martin Jambor  <mjambor@suse.cz>

PR tree-optimization/119085
* gcc.dg/tree-ssa/pr119085.c: New test.

(cherry picked from commit 171fcc80ede596442712e559c4fc787aa4636694)

6 days agocalls: Allow musttail calls to noreturn [PR121159]
Jakub Jelinek [Tue, 29 Jul 2025 07:49:55 +0000 (09:49 +0200)] 
calls: Allow musttail calls to noreturn [PR121159]

In the PR119483 r15-9003 change we've allowed musttail calls to noreturn
functions, after all the decision not to normally tail call noreturn
functions is not because it is not possible to tail call those, but because
it screws up backtraces.  As the following testcase shows, we've done that
only for functions not declared [[noreturn]]/_Noreturn but later on
discovered through IPA as noreturn.  Functions explicitly declared
[[noreturn]] have (for historical reasons) volatile FUNCTION_TYPE and
the FUNCTION_DECLs are volatile as well, so in order to support those
we shouldn't complain on ECF_NORETURN (we've stopped doing so for musttail
in PR119483) but also shouldn't complain about TYPE_VOLATILE on their
FUNCTION_TYPE (something that IPA doesn't change, I think it only sets
TREE_THIS_VOLATILE on the FUNCTION_DECL).  volatile on function type
really means noreturn as well, it has no other meaning.

2025-07-29  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/121159
* calls.cc (can_implement_as_sibling_call_p): Don't reject declared
noreturn functions in musttail calls.

* c-c++-common/pr121159.c: New test.
* gcc.dg/plugin/must-tail-call-2.c (test_5): Don't expect an error.

(cherry picked from commit f4abe216199930adfa110059c3c8e642c585388b)

6 days agox86: Enable *mov<mode>_(and|or) only for -Oz
H.J. Lu [Sat, 24 May 2025 23:40:29 +0000 (07:40 +0800)] 
x86: Enable *mov<mode>_(and|or) only for -Oz

commit ef26c151c14a87177d46fd3d725e7f82e040e89f
Author: Roger Sayle <roger@nextmovesoftware.com>
Date:   Thu Dec 23 12:33:07 2021 +0000

    x86: PR target/103773: Fix wrong-code with -Oz from pop to memory.

added "*mov<mode>_and" and extended "*mov<mode>_or" to transform
"mov $0,mem" to the shorter "and $0,mem" and "mov $-1,mem" to the shorter
"or $-1,mem" for -Oz.  But the new pattern:

(define_insn "*mov<mode>_and"
  [(set (match_operand:SWI248 0 "memory_operand" "=m")
    (match_operand:SWI248 1 "const0_operand"))
   (clobber (reg:CC FLAGS_REG))]
  "reload_completed"
  "and{<imodesuffix>}\t{%1, %0|%0, %1}"
  [(set_attr "type" "alu1")
   (set_attr "mode" "<MODE>")
   (set_attr "length_immediate" "1")])

and the extended pattern:

(define_insn "*mov<mode>_or"
  [(set (match_operand:SWI248 0 "nonimmediate_operand" "=rm")
    (match_operand:SWI248 1 "constm1_operand"))
   (clobber (reg:CC FLAGS_REG))]
  "reload_completed"
  "or{<imodesuffix>}\t{%1, %0|%0, %1}"
  [(set_attr "type" "alu1")
   (set_attr "mode" "<MODE>")
   (set_attr "length_immediate" "1")])

aren't guarded for -Oz.  As a result, "and $0,mem" and "or $-1,mem" are
generated without -Oz.

1. Change *mov<mode>_and" to define_insn_and_split and split it to
"mov $0,mem" if not -Oz.
2. Change "*mov<mode>_or" to define_insn_and_split and split it to
"mov $-1,mem" if not -Oz.
3. Don't transform "mov $-1,reg" to "push $-1; pop reg" for -Oz since it
should be transformed to "or $-1,reg".

gcc/

PR target/120427
* config/i386/i386.md (*mov<mode>_and): Changed to
define_insn_and_split.  Split it to "mov $0,mem" if not -Oz.
(*mov<mode>_or): Changed to define_insn_and_split.  Split it
to "mov $-1,mem" if not -Oz.
(peephole2): Don't transform "mov $-1,reg" to "push $-1; pop reg"
for -Oz since it will be transformed to "or $-1,reg".

gcc/testsuite/

PR target/120427
* gcc.target/i386/cold-attribute-4.c: Compile with -Oz.
* gcc.target/i386/pr120427-1.c: New test.
* gcc.target/i386/pr120427-2.c: Likewise.
* gcc.target/i386/pr120427-3.c: Likewise.
* gcc.target/i386/pr120427-4.c: Likewise.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
(cherry picked from commit 4c80062d7b8c272e2e193b8074a8440dbb4fe588)

6 days agoDaily bump.
GCC Administrator [Tue, 29 Jul 2025 00:24:17 +0000 (00:24 +0000)] 
Daily bump.

7 days agoAVR: target/121277 - Don't load 0x800000 with const __flashx *x = NULL.
Georg-Johann Lay [Mon, 28 Jul 2025 19:44:06 +0000 (21:44 +0200)] 
AVR: target/121277 - Don't load 0x800000 with const __flashx *x = NULL.

Converting from generic AS to __flashx used the same rule like
for __memx, which tags RAM (generic AS) locations by setting bit 23.
The justification was that generic isn't a subset of __flashx, though
that lead to surprises with code like const __flashx *x = NULL.

The natural thing to do is to just load 0x000000 in that case,
so that the null pointer works in __flashx as expected.

Apart from that, converting NULL to __flashx (or __flash) no more
raises a -Waddr-space-convert diagnostic.

gcc/
PR target/121277
* config/avr/avr.cc (avr_addr_space_convert): When converting
from generic AS to __flashx, don't set bit 23.
(avr_convert_to_type): Don't -Waddr-space-convert when NULL
is converted to __flashx or to __flash.

(cherry picked from commit 089faf54fa96565784ebdd8dfcf9c350c4c3bee5)

7 days agoFortran: Allow for iterator substitution in array constructors [PR119106]
Andre Vehreschild [Fri, 27 Jun 2025 09:42:54 +0000 (11:42 +0200)] 
Fortran: Allow for iterator substitution in array constructors [PR119106]

PR fortran/119106

gcc/fortran/ChangeLog:

* expr.cc (simplify_constructor): Do not simplify constants.
(gfc_simplify_expr): Continue to simplify expression when an
iterator is present.

gcc/testsuite/ChangeLog:

* gfortran.dg/array_constructor_58.f90: New test.

(cherry picked from commit 3a7fcf4f54ecffdbad03787d4f734c1fb2291ef5)

7 days agoLoongArch: Fix wrong code generated by TARGET_VECTORIZE_VEC_PERM_CONST [PR121064]
Xi Ruoyao [Mon, 14 Jul 2025 19:01:12 +0000 (03:01 +0800)] 
LoongArch: Fix wrong code generated by TARGET_VECTORIZE_VEC_PERM_CONST [PR121064]

When TARGET_VECTORIZE_VEC_PERM_CONST is called, target may be the
same pseudo as op0 and/or op1.  Loading the selector into target
would clobber the input, producing wrong code like

    vld     $vr0, $t0
    vshuf.w $vr0, $vr0, $vr1

So don't load the selector into d->target, use a new pseudo to hold the
selector instead.  The reload pass will load the pseudo for selector and
the pseudo for target into the same hard register (following our
constraint '0' on the shuf instructions) anyway.

gcc/ChangeLog:

PR target/121064
* config/loongarch/lsx.md (lsx_vshuf_<lsxfmt_f>): Add '@' to
generate a mode-aware helper.  Use <VIMODE> as the mode of the
operand 1 (selector).
* config/loongarch/lasx.md (lasx_xvshuf_<lasxfmt_f>): Likewise.
* config/loongarch/loongarch.cc
(loongarch_try_expand_lsx_vshuf_const): Create a new pseudo for
the selector.  Use the mode-aware helper to simplify the code.
(loongarch_expand_vec_perm_const): Likewise.

gcc/testsuite/ChangeLog:

PR target/121064
* gcc.target/loongarch/pr121064.c: New test.

(cherry picked from commit d626debcb3717f18bf2ee88f4281b109b13e1181)

7 days agoDaily bump.
GCC Administrator [Mon, 28 Jul 2025 00:22:05 +0000 (00:22 +0000)] 
Daily bump.

8 days ago[RISC-V] Correct CFA notes for stack-clash protection [PR120714]
Alexey Merzlyakov [Mon, 30 Jun 2025 19:58:29 +0000 (13:58 -0600)] 
[RISC-V] Correct CFA notes for stack-clash protection [PR120714]

Fixes incorrect SP-addresses used in CFA notes for the stack probes
unrelative to the frame's top. It applied to the RISC-V targets code
generation when the stack-clash protection is enabled.

PR target/120714
gcc/ChangeLog:

* config/riscv/riscv.cc (riscv_allocate_and_probe_stack_space):
Fix SP-addresses in REG_CFA_DEF_CFA notes for stack-clash case.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/pr120714.c: New test.

(cherry picked from commit 45a17e3081120f51f8e8b1d7cda73c7d89453e85)

8 days agoDaily bump.
GCC Administrator [Sun, 27 Jul 2025 00:22:27 +0000 (00:22 +0000)] 
Daily bump.

9 days agogcse: Skip hardreg pre when the hardreg is never live [PR121095]
Andrew Pinski [Wed, 16 Jul 2025 16:31:35 +0000 (09:31 -0700)] 
gcse: Skip hardreg pre when the hardreg is never live [PR121095]

r15-6789-ge7f98d9603808b added a new RTL pass for hardreg PRE for the hard register
of FPM_REGNUM, this pass could get expensive if you have a large number of basic blocks
and the hard register was never live so it does nothing in the end.
In the aarch64 case, FPM_REGNUM is only used for FP8 related code so it has a high probability
of not being used. So skipping the pass for that register can improve both compile time and memory
usage.

Build and tested for aarch64-linux-gnu.

PR middle-end/121095
gcc/ChangeLog:

* gcse.cc (execute_hardreg_pre): Skip if the hardreg which is never live.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
(cherry picked from commit 6916639b48357334579cf94717a3e51dd003e940)

9 days agoaarch64: Fix fma steering when rename fails [PR120119]
Andrew Pinski [Tue, 22 Jul 2025 17:26:54 +0000 (10:26 -0700)] 
aarch64: Fix fma steering when rename fails [PR120119]

Regrename can fail in some case and `insn_rr[INSN_UID (insn)].op_info`
will be null. The FMA steering code was not expecting the failure to happen.
This started to happen after early RA was added but it has been a latent bug
before that.

Build and tested for aarch64-linux-gnu.

PR target/120119

gcc/ChangeLog:

* config/aarch64/cortex-a57-fma-steering.cc (func_fma_steering::analyze):
Skip if renaming fails.

gcc/testsuite/ChangeLog:

* g++.dg/torture/pr120119-1.C: New test.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
(cherry picked from commit 66c879571ab1fbdb4b119b8b0a1a30ebc7160057)

9 days agoFortran: fix passing of character length of function to procedure [PR121203]
Harald Anlauf [Tue, 22 Jul 2025 18:16:16 +0000 (20:16 +0200)] 
Fortran: fix passing of character length of function to procedure [PR121203]

PR fortran/121203

gcc/fortran/ChangeLog:

* trans-expr.cc (gfc_conv_procedure_call): Obtain the character
length of an assumed character length procedure from the typespec
of the actual argument even if there is no explicit interface.

gcc/testsuite/ChangeLog:

* gfortran.dg/function_charlen_4.f90: New test.

(cherry picked from commit 53b64337ef325c4e47ae96ea8dea86031a3a0602)

9 days ago[PATCH] [modula2] Add return to remove build warning
Gaius Mulley [Sat, 26 Jul 2025 13:08:21 +0000 (14:08 +0100)] 
[PATCH] [modula2] Add return to remove build warning

This patch adds a return statement to M2Exception which removes a
build warning.

gcc/m2/ChangeLog:

* gm2-libs/M2EXCEPTION.mod (M2Exception): Add return
exException in case Raise completes.

(cherry picked from commit db8b92d8d61de408e14a4aebf5a777734936699d)

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
9 days ago[PATCH] PR modula2/121164: Modula 2 build failure followup
Gaius Mulley [Sat, 26 Jul 2025 12:19:29 +0000 (13:19 +0100)] 
[PATCH] PR modula2/121164: Modula 2 build failure followup

This is a followup patch for PR modula2/121164 to
fix the location for the error message attributed to cc1gm2.
The Patch has been cherry picked, but without the forced -Wall option
in libgm2.

gcc/m2/ChangeLog:

PR modula2/121164
* gm2-compiler/P1SymBuild.mod: Remove PutProcTypeParam.
Remove PutProcTypeParam.
(CheckFileName): Remove.
(P1EndBuildDefinitionModule): Correct spelling.
(P1EndBuildImplementationModule): Ditto.
(P1EndBuildProgramModule): Ditto.
(EndBuildInnerModule): Ditto.
* gm2-compiler/P2SymBuild.mod (P2EndBuildDefModule): Correct
spelling.
(P2EndBuildImplementationModule): Ditto.
(P2EndBuildProgramModule): Ditto.
(EndBuildInnerModule): Ditto.
(CheckFormalParameterSection): Ditto.
* gm2-compiler/P3SymBuild.mod (P3EndBuildDefModule): Ditto.
* gm2-compiler/PCSymBuild.mod (PCEndBuildDefModule): Ditto.
(fixupProcedureType): Pass tok to PutProcTypeVarParam.
Pass tok to PutProcTypeParam.
* gm2-compiler/SymbolTable.def (PutProcTypeParam): Add tok
parameter.
(PutProcTypeVarParam): Ditto.
* gm2-compiler/SymbolTable.mod (SymParam): At change type to
CARDINAL.
New field FullTok.
New field Scope.
(SymVarParam): At change type to CARDINAL.
New field FullTok.
New field Scope.
(GetVarDeclTok): Check ShadowVar for NulSym and return At.
(PutParam): Initialize FullTok.
Initialize At.
Initialize Scope.
(PutVarParam): Initialize FullTok.
Assign At.
Initialize Scope.
(AddProcedureProcTypeParam): Add tok parameter.
(GetScope): Add ParamSym and VarParamSym clause.
(PutProcTypeVarParam): Add tok parameter.
Initialize At.
Initialize FullTok.
(GetDeclaredDefinition): Clause ParamSym return At.
Clause VarParamSym return At.
(GetDeclaredModule): Ditto.
(PutDeclaredDefinition): Remove clause ParamSym.
Remove clause VarParamSym.
(PutDeclaredModule): Remove clause ParamSym.
Remove clause VarParamSym.

gcc/testsuite/ChangeLog:

PR modula2/121164
* gm2/switches/pedantic-params/fail/arrayofchar.def: New test.
* gm2/switches/pedantic-params/fail/arrayofchar.mod: New test.

(cherry picked from commit ab5a89c0b4f1ead202dee072e16690607b810111)

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
9 days agoDaily bump.
GCC Administrator [Sat, 26 Jul 2025 00:23:58 +0000 (00:23 +0000)] 
Daily bump.

10 days agoc++: constexpr uninitialized union [PR120577]
Jason Merrill [Fri, 25 Jul 2025 19:57:26 +0000 (15:57 -0400)] 
c++: constexpr uninitialized union [PR120577]

This was failing for two reasons:

1) We were wrongly treating the basic_string constructor as
zero-initializing the object, which it doesn't.
2) Given that, when we went to look for a value for the anonymous union,
we concluded that it was value-initialized, and trying to evaluate that
broke because we weren't setting ctx->ctor for it.

This patch fixes both issues, #1 by setting CONSTRUCTOR_NO_CLEARING and #2
by inserting a new CONSTRUCTOR for the member rather than evaluate it out of
context, which is consistent with cxx_eval_store_expression.

PR c++/120577

gcc/cp/ChangeLog:

* constexpr.cc (cxx_eval_call_expression): Set
CONSTRUCTOR_NO_CLEARING on initial value for ctor.
(cxx_eval_component_reference): Make value-initialization
of an aggregate member explicit.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/constexpr-union9.C: New test.

(cherry picked from commit f23b5df56e237df9f66b615ca4babc564d5f75de)

10 days agoada: Bug in Indefinite_Holders instance passed to formal package
Bob Duff [Wed, 16 Jul 2025 14:29:01 +0000 (10:29 -0400)] 
ada: Bug in Indefinite_Holders instance passed to formal package

Fix bug when an instance of Indefinite_Holders with a class-wide type is
passed as a generic formal package; Program_Error was raised when
dealing with the implicit "=" function.

The fix is to disable legality checks in formal packages when the
entity is an E_Subprogram_Body, because these are implicitly generated
for class-wide predefined functions when passed to generics.

gcc/ada/ChangeLog:

* sem_ch12.adb (Check_Formal_Package_Instance):
Do nothing in case of E_Subprogram_Body.

10 days agoada: Fix regression of finalization primitive selection
Ronan Desplanques [Fri, 11 Jul 2025 09:28:35 +0000 (11:28 +0200)] 
ada: Fix regression of finalization primitive selection

A recent patch introduced a new flag to mark the types for which looking
up finalization primitives needs special handling. But there was one
place in Build_Derived_Record_Type where the flag was not set when it
should, which introduced a regression in some cases.

This patch adds the missing setting of the flag.

gcc/ada/ChangeLog:

* sem_ch3.adb (Build_Derived_Record_Type): Set flag appropriately.

10 days agoDaily bump.
GCC Administrator [Fri, 25 Jul 2025 00:25:22 +0000 (00:25 +0000)] 
Daily bump.

11 days agoc++: fix __is_invocable for std::reference_wrapper [PR121055]
Patrick Palka [Wed, 23 Jul 2025 12:31:46 +0000 (08:31 -0400)] 
c++: fix __is_invocable for std::reference_wrapper [PR121055]

Our implementation of the INVOKE spec ([func.require]) was incorrectly
treating reference_wrapper<T>::get() as returning T instead of T&, which
notably makes a difference when invoking a ref-qualified memfn pointer.

PR c++/121055

gcc/cp/ChangeLog:

* method.cc (build_invoke): Correct reference_wrapper handling.

gcc/testsuite/ChangeLog:

* g++.dg/ext/is_invocable5.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
(cherry picked from commit 04a176a1d84a84c630cfd4d232736c12b105957a)

11 days agolibstdc++: Add missing initializers for __maybe_present_t members [PR119962]
Patrick Palka [Tue, 15 Jul 2025 19:17:23 +0000 (15:17 -0400)] 
libstdc++: Add missing initializers for __maybe_present_t members [PR119962]

Data members of type __maybe_present_t where the conditionally present
type might be an aggregate or fundamental type need to be explicitly
value-initialized (rather than implicitly default-initialized), so that
default-initialization of the containing class always results in an
completely initialized object.

PR libstdc++/119962

libstdc++-v3/ChangeLog:

* include/std/ranges (join_view::_Iterator::_M_outer): Initialize.
(lazy_split_view::_OuterIter::_M_current): Initialize.
(join_with_view::_Iterator::_M_outer_it): Initialize.
* testsuite/std/ranges/adaptors/join.cc (test15): New test.
* testsuite/std/ranges/adaptors/join_with/1.cc (test05): New test.
* testsuite/std/ranges/adaptors/lazy_split.cc (test13): New test.

Reviewed-by: Tomasz KamiƄski <tkaminsk@redhat.com>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
(cherry picked from commit 0828600f586e75a2056a4fc7eb0a340c363d6c66)

11 days agotree-optimization/121202 - fix vector stmt placement
Richard Biener [Tue, 22 Jul 2025 11:02:03 +0000 (13:02 +0200)] 
tree-optimization/121202 - fix vector stmt placement

When we have a vector shift with a scalar the shift operand can be
external - in that case we should not use the shift operand def
as hint where to place the vector shift instruction.  The ICE
in the PR is because stmt dominance queries only work inside of
the vector region.  But we should also never place stmts outside
of it.

PR tree-optimization/121202
* tree-vect-slp.cc (vect_schedule_slp_node): Do not take
an out-of-region stmt as "last".

* gcc.dg/pr121202.c: New testcase.

(cherry picked from commit bdfb5cc5aa6959a6959fc0cf98da08db89c81032)

11 days agoc++/modules: Support re-streaming TU_LOCAL_ENTITYs [PR120412]
Nathaniel Shead [Sat, 24 May 2025 00:56:22 +0000 (10:56 +1000)] 
c++/modules: Support re-streaming TU_LOCAL_ENTITYs [PR120412]

When emitting a primary module interface, we must re-stream any TU-local
entities that we saw in a partition.  This patch adds the missing
members from core_vals.

As a drive-by fix, in some cases we might have a typedef referring to a
TU-local entity; we need to handle that case as well.

PR c++/120412

gcc/cp/ChangeLog:

* module.cc (trees_out::core_vals): Write TU_LOCAL_ENTITY bits.
(trees_in::core_vals): Read it.
(trees_in::tree_node): Handle TU_LOCAL_ENTITY typedefs.

gcc/testsuite/ChangeLog:

* g++.dg/modules/internal-14_a.C: New test.
* g++.dg/modules/internal-14_b.C: New test.
* g++.dg/modules/internal-14_c.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
(cherry picked from commit be81c5c01c243013c4bac0718e63e0fdc132d384)

11 days agoDaily bump.
GCC Administrator [Thu, 24 Jul 2025 00:27:18 +0000 (00:27 +0000)] 
Daily bump.

12 days agotree-sra: Fix grp_covered flag computation when totally scalarizing (PR117423)
Martin Jambor [Fri, 18 Jul 2025 10:42:11 +0000 (12:42 +0200)] 
tree-sra: Fix grp_covered flag computation when totally scalarizing (PR117423)

Testcase of PR 117423 shows a flaw in the fancy way we do "total
scalarization" in SRA now.  We use the types encountered in the
function body and not in type declaration (allowing us to totally
scalarize when only one union field is ever used, since we effectively
"skip" the union then) and can accommodate pre-existing accesses that
happen to fall into padding.

In this case, we skipped the union (bypassing the
totally_scalarizable_type_p check) and the access falling into the
"padding" is an aggregate and so not a candidate for SRA but actually
containing data.  Arguably total scalarization should just bail out
when it encounters this situation (but I decided not to depend on this
mainly because we'd need to detect all cases when we eventually cannot
scalarize, such as when a scalar access has children accesses) but the
actual bug is that the detection if all data in an aggregate is indeed
covered by replacements just assumes that is always the case if total
scalarization triggers which however may not be the case in cases like
this - and perhaps more.

This patch fixes the bug by just assuming that all padding is taken
care of when total scalarization triggered, not that every access was
actually scalarized.

gcc/ChangeLog:

2025-07-17  Martin Jambor  <mjambor@suse.cz>

PR tree-optimization/117423
* tree-sra.cc (analyze_access_subtree): Fix computation of grp_covered
flag.

gcc/testsuite/ChangeLog:

2025-07-17  Martin Jambor  <mjambor@suse.cz>

PR tree-optimization/117423
* gcc.dg/tree-ssa/pr117423.c: New test.

(cherry picked from commit 7375909e9d9e7de23acb4b1e0a965d8faf1943c4)

12 days agotestsuite: Fix overflow in gcc.dg/vect/pr116125.c
Siddhesh Poyarekar [Mon, 21 Jul 2025 01:13:20 +0000 (06:43 +0530)] 
testsuite: Fix overflow in gcc.dg/vect/pr116125.c

The test ends up writing a byte beyond bounds of the buffer, which gets
trapped on some targets when the test is run with
-fstack-protector-strong.

gcc/testsuite/ChangeLog:

* gcc.dg/vect/pr116125.c (mem_overlap): Expand A to 10 members.

Signed-off-by: Siddhesh Poyarekar <siddhesh@gotplt.org>
(cherry picked from commit 96d5aef307025a771ae4ef47a9b382ef20eb06c4)

12 days agoDaily bump.
GCC Administrator [Wed, 23 Jul 2025 00:26:52 +0000 (00:26 +0000)] 
Daily bump.

13 days agoada: Fix generation of Initialize and Adjust calls
Ronan Desplanques [Wed, 9 Jul 2025 08:19:00 +0000 (10:19 +0200)] 
ada: Fix generation of Initialize and Adjust calls

Before this patch, Make_Init_Call and Make_Adjust_Call made the
assumption that if the type they were called with was untagged and a
derived type, it was the untagged private view of a tagged type. That
assumption made it possible to inspect the root type's primitives to
handle the case where the underlying type was implicitly generated by
the compiler without all inherited primitives.

The introduction of the Finalizable aspect broke that assumption, so
this patch adds a new field to type entities that make the generated
full view stand out, and updates Make_Init_Call and Make_Adjust_Call to
only jump to the root type when they're passed one of those generated
types.

Make_Final_Call and Finalize_Address are two other subprograms that
perform the same test on the types they're passed. They did not suffer
from the same bug as Make_Init_Call and Make_Adjust_Call because of an
earlier, more ad hoc fix, but this patch switches them over to the newly
introduced mechanism for the sake of consistency.

gcc/ada/ChangeLog:

* gen_il-fields.ads (Is_Implicit_Full_View): New field.
* gen_il-gen-gen_entities.adb (Type_Kind): Use new field.
* einfo.ads (Is_Implicit_Full_View): Document new field.
* exp_ch7.adb (Make_Adjust_Call, Make_Init_Call, Make_Final_Call): Use
new field.
* exp_util.adb (Finalize_Address): Likewise.
* sem_ch3.adb (Copy_And_Build): Set new field.

13 days agoada: Remove obsolete code from Safe_Unchecked_Type_Conversion
Eric Botcazou [Tue, 8 Jul 2025 19:40:44 +0000 (21:40 +0200)] 
ada: Remove obsolete code from Safe_Unchecked_Type_Conversion

That's a kludge added to work around the limitations of the stack checking
mechanism used in the early days.

gcc/ada/ChangeLog:

* exp_util.ads (May_Generate_Large_Temp): Delete.
* exp_util.adb (May_Generate_Large_Temp): Likewise.
(Safe_Unchecked_Type_Conversion): Do not take stack checking into
account to compute the result.