]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
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.

13 days agoada: Fix assertion failure on aggregate with controlled component
Eric Botcazou [Tue, 8 Jul 2025 09:05:19 +0000 (11:05 +0200)] 
ada: Fix assertion failure on aggregate with controlled component

The assertion is:

      pragma Assert (Side_Effect_Free (L));

in Make_Tag_Ctrl_Assignment and demonstrates that the sequence:

  Remove_Side_Effects (L);
  pragma Assert (Side_Effect_Free (L));

does not hold in this case.

What happens is that Remove_Side_Effects uses a renaming to remove the side
effects of L but, at the end, the renamed object is substituted back for the
renamed object in the node by Expand_Renaming, which is invoked because the
Is_Renaming_Of_Object flag is set on the renaming after Evaluate_Name has
been invoked on its Name.

This is a general discrepancy between Evaluate_Name and Side_Effect_Free of
Exp_Util, coming from the call to Safe_Unchecked_Type_Conversion present in
Side_Effect_Free in this case.  The long term goal is probably to remove the
call but, in the meantime, this change is sufficient to fix the failure.

gcc/ada/ChangeLog:

* exp_util.adb (Safe_Unchecked_Type_Conversion): Always return True
if the expression is the prefix of an N_Selected_Component.

13 days agoada: Tune recent change for bit-packed arrays to help GNATprove backend
Piotr Trojanek [Fri, 4 Jul 2025 09:52:46 +0000 (11:52 +0200)] 
ada: Tune recent change for bit-packed arrays to help GNATprove backend

When GNAT is operating in GNATprove_Mode the Expander_Active flag is disabled,
but we still must do things that ordinary backends expect.

gcc/ada/ChangeLog:

* sem_util.adb (Get_Actual_Subtype): Do the same for GCC and GNATprove
backends.

13 days agoada: Fix wrong indirect access to bit-packed array in iterated loop
Eric Botcazou [Wed, 2 Jul 2025 13:25:55 +0000 (15:25 +0200)] 
ada: Fix wrong indirect access to bit-packed array in iterated loop

This comes from a missing expansion of the bit-packed array reference in
the loop, because the actual subtype created for the dereference lacks a
Packed_Array_Impl_Type as it is ultimately created by the Preanalyze_Range
call present in Analyze_Loop_Statement.

gcc/ada/ChangeLog:

* sem_util.adb (Get_Actual_Subtype): Only create a new subtype when
the expander is active.  Remove a useless test of type inequality,
as well as a useless call to Set_Has_Delayed_Freeze on the subtype.

13 days agoada: exp_util.adb: prevent infinite loop in case of broken code
Ghjuvan Lacambre [Wed, 2 Jul 2025 07:11:03 +0000 (09:11 +0200)] 
ada: exp_util.adb: prevent infinite loop in case of broken code

A recent commit modified exp_util.adb in order to fix the selection of
Finalize subprograms in the case of untagged objects.
This introduced regressions for GNATSAS in fixedbugs by causing
GNAT2SCIL to loop over the same type over and over in case of broken
code.
We fix this by simply checking that the loop is making progress, and if
it doesn't, assume that we're done.

gcc/ada/ChangeLog:

* exp_util.adb (Finalize_Address): Prevent infinite loop

13 days agoOpenMP: Fix implicit 'declare target' for <ostream>
Tobias Burnus [Tue, 17 Jun 2025 09:33:09 +0000 (11:33 +0200)] 
OpenMP: Fix implicit 'declare target' for <ostream>

libstdc++-v3/include/std/ostream contains:

  namespace std _GLIBCXX_VISIBILITY(default)
  {
    ...
    template<typename _CharT, typename _Traits>
      inline basic_ostream<_CharT, _Traits>&
      endl(basic_ostream<_CharT, _Traits>& __os)
      { return flush(__os.put(__os.widen('\n'))); }
  ...
  #include <bits/ostream.tcc>

and the latter, libstdc++-v3/include/bits/ostream.tcc, has:
    // Inhibit implicit instantiations for required instantiations,
    // which are defined via explicit instantiations elsewhere.
  #if _GLIBCXX_EXTERN_TEMPLATE
    extern template class basic_ostream<char>;
    extern template ostream& endl(ostream&);

Before this commit, omp_discover_declare_target_tgt_fn_r marked 'endl'
as (implicitly) declare target - but not the calls in it due to the
'extern' (DECL_EXTERNAL).

Thanks to inlining and as 'endl' is (therefore) not used and, hence,
discarded by the linker; hencet, it works with -O0 and -O1. However,
as the (unused) function still exits, IPA CP (enabled by -O2) will try
to do constant-value propagation and fails as the definition of 'widen'
is not available.

Solution is to still walk 'endl' despite being an 'extern(al)' decl;
this has been restricted for now to DECL_DECLARED_INLINE_P.

gcc/ChangeLog:

* omp-offload.cc (omp_discover_declare_target_tgt_fn_r): Also
walk external functions that are declare inline (and have a
DECL_SAVED_TREE).

libgomp/ChangeLog:

* testsuite/libgomp.c++/declare_target-2.C: New test.

(cherry picked from commit ea43b99537591b1103da3961c61f1cbfae968859)

13 days agoAvoid SIGSEGV in nvptx 'mkoffload' for voluminous PTX code
Thomas Schwinge [Mon, 26 May 2025 11:31:54 +0000 (13:31 +0200)] 
Avoid SIGSEGV in nvptx 'mkoffload' for voluminous PTX code

In commit 50be486dff4ea2676ed022e9524ef190b92ae2b1
"nvptx: libgomp+mkoffload.cc: Prepare for reverse offload fn lookup", some
additional tracking of the PTX code was added, and this assumes that
potentially every single character of PTX code needs to be tracked as a new
chunk of PTX code.  That's problematic if we're dealing with voluminous PTX
code (for example, non-trivial C++ code), and the 'file_idx' 'alloca'tion then
causes stack overflow.  For example:

    FAIL: libgomp.c++/target-std__valarray-1.C (test for excess errors)
    UNRESOLVED: libgomp.c++/target-std__valarray-1.C compilation failed to produce executable

    lto-wrapper: fatal error: [...]/build-gcc/gcc//accel/nvptx-none/mkoffload terminated with signal 11 [Segmentation fault], core dumped

gcc/
* config/nvptx/mkoffload.cc (process): Use an 'auto_vec' for
'file_idx'.

(cherry picked from commit 01044e0ee27093a3990996578b15f6ab69ed3395)

13 days agoAdd 'libgomp.c++/target-valarray-1.C'
Thomas Schwinge [Wed, 30 Apr 2025 09:29:08 +0000 (11:29 +0200)] 
Add 'libgomp.c++/target-valarray-1.C'

libgomp/
* testsuite/libgomp.c++/target-std__valarray-1.C: New.
* testsuite/libgomp.c++/target-std__valarray-1.output: Likewise.

(cherry picked from commit 2ffada0296c95898a68bdb67ced738fe788df93a)

13 days agolibgomp: Add testcases for concurrent access to standard C++ containers on offload...
Thomas Schwinge [Fri, 30 May 2025 09:37:46 +0000 (11:37 +0200)] 
libgomp: Add testcases for concurrent access to standard C++ containers on offload targets, a number of USM variants

libgomp/
* testsuite/libgomp.c++/target-std__array-concurrent-usm.C: New.
* testsuite/libgomp.c++/target-std__array-concurrent.C: Adjust.
* testsuite/libgomp.c++/target-std__bitset-concurrent-usm.C: New.
* testsuite/libgomp.c++/target-std__bitset-concurrent.C: Adjust.
* testsuite/libgomp.c++/target-std__deque-concurrent-usm.C: New.
* testsuite/libgomp.c++/target-std__deque-concurrent.C: Adjust.
* testsuite/libgomp.c++/target-std__forward_list-concurrent-usm.C: New.
* testsuite/libgomp.c++/target-std__forward_list-concurrent.C: Adjust.
* testsuite/libgomp.c++/target-std__list-concurrent-usm.C: New.
* testsuite/libgomp.c++/target-std__list-concurrent.C: Adjust.
* testsuite/libgomp.c++/target-std__map-concurrent-usm.C: New.
* testsuite/libgomp.c++/target-std__map-concurrent.C: Adjust.
* testsuite/libgomp.c++/target-std__multimap-concurrent-usm.C: New.
* testsuite/libgomp.c++/target-std__multimap-concurrent.C: Adjust.
* testsuite/libgomp.c++/target-std__multiset-concurrent-usm.C: New.
* testsuite/libgomp.c++/target-std__multiset-concurrent.C: Adjust.
* testsuite/libgomp.c++/target-std__set-concurrent-usm.C: New.
* testsuite/libgomp.c++/target-std__set-concurrent.C: Adjust.
* testsuite/libgomp.c++/target-std__span-concurrent-usm.C: New.
* testsuite/libgomp.c++/target-std__span-concurrent.C: Adjust.
* testsuite/libgomp.c++/target-std__valarray-concurrent-usm.C: New.
* testsuite/libgomp.c++/target-std__valarray-concurrent.C: Adjust.
* testsuite/libgomp.c++/target-std__vector-concurrent-usm.C: New.
* testsuite/libgomp.c++/target-std__vector-concurrent.C: Adjust.

(cherry picked from commit 83ca283853f195a08d2f758580a369bc6a076122)

13 days agolibgomp: Add testcases for concurrent access to standard C++ containers on offload...
Kwok Cheung Yeung [Thu, 8 May 2025 19:41:16 +0000 (20:41 +0100)] 
libgomp: Add testcases for concurrent access to standard C++ containers on offload targets

libgomp/

* testsuite/libgomp.c++/target-std__array-concurrent.C: New.
* testsuite/libgomp.c++/target-std__bitset-concurrent.C: Likewise.
* testsuite/libgomp.c++/target-std__deque-concurrent.C: Likewise.
* testsuite/libgomp.c++/target-std__flat_map-concurrent.C: Likewise.
* testsuite/libgomp.c++/target-std__flat_multimap-concurrent.C: Likewise.
* testsuite/libgomp.c++/target-std__flat_multiset-concurrent.C: Likewise.
* testsuite/libgomp.c++/target-std__flat_set-concurrent.C: Likewise.
* testsuite/libgomp.c++/target-std__forward_list-concurrent.C: Likewise.
* testsuite/libgomp.c++/target-std__list-concurrent.C: Likewise.
* testsuite/libgomp.c++/target-std__map-concurrent.C: Likewise.
* testsuite/libgomp.c++/target-std__multimap-concurrent.C: Likewise.
* testsuite/libgomp.c++/target-std__multiset-concurrent.C: Likewise.
* testsuite/libgomp.c++/target-std__set-concurrent.C: Likewise.
* testsuite/libgomp.c++/target-std__span-concurrent.C: Likewise.
* testsuite/libgomp.c++/target-std__unordered_map-concurrent.C: Likewise.
* testsuite/libgomp.c++/target-std__unordered_multimap-concurrent.C: Likewise.
* testsuite/libgomp.c++/target-std__unordered_multiset-concurrent.C: Likewise.
* testsuite/libgomp.c++/target-std__unordered_set-concurrent.C: Likewise.
* testsuite/libgomp.c++/target-std__valarray-concurrent.C: Likewise.
* testsuite/libgomp.c++/target-std__vector-concurrent.C: Likewise.

Co-authored-by: Thomas Schwinge <tschwinge@baylibre.com>
(cherry picked from commit a811d1d72261da58196ccec253fd2bdb10e999db)

13 days agolibgomp: Add testcases for the standard C++ math library on offload targets
Kwok Cheung Yeung [Wed, 21 May 2025 11:59:58 +0000 (12:59 +0100)] 
libgomp: Add testcases for the standard C++ math library on offload targets

libgomp/

* testsuite/libgomp.c++/target-std__cmath.C: New.
* testsuite/libgomp.c++/target-std__complex.C: Likewise.
* testsuite/libgomp.c++/target-std__numbers.C: Likewise.

(cherry picked from commit fbcd0ad41f7cc801664da1e583f6bcad1eb02a08)

13 days agoAdd 'libgomp.c++/target-flex-[...].C' test cases
Waffl3x [Mon, 26 May 2025 08:38:27 +0000 (02:38 -0600)] 
Add 'libgomp.c++/target-flex-[...].C' test cases

libgomp/ChangeLog:

* testsuite/libgomp.c++/target-flex-10.C: New test.
* testsuite/libgomp.c++/target-flex-100.C: New test.
* testsuite/libgomp.c++/target-flex-101.C: New test.
* testsuite/libgomp.c++/target-flex-11.C: New test.
* testsuite/libgomp.c++/target-flex-12.C: New test.
* testsuite/libgomp.c++/target-flex-2000.C: New test.
* testsuite/libgomp.c++/target-flex-2001.C: New test.
* testsuite/libgomp.c++/target-flex-2002.C: New test.
* testsuite/libgomp.c++/target-flex-2003.C: New test.
* testsuite/libgomp.c++/target-flex-30.C: New test.
* testsuite/libgomp.c++/target-flex-300.C: New test.
* testsuite/libgomp.c++/target-flex-31.C: New test.
* testsuite/libgomp.c++/target-flex-32.C: New test.
* testsuite/libgomp.c++/target-flex-33.C: New test.
* testsuite/libgomp.c++/target-flex-41.C: New test.
* testsuite/libgomp.c++/target-flex-60.C: New test.
* testsuite/libgomp.c++/target-flex-61.C: New test.
* testsuite/libgomp.c++/target-flex-62.C: New test.
* testsuite/libgomp.c++/target-flex-70.C: New test.
* testsuite/libgomp.c++/target-flex-80.C: New test.
* testsuite/libgomp.c++/target-flex-81.C: New test.
* testsuite/libgomp.c++/target-flex-90.C: New test.
* testsuite/libgomp.c++/target-flex-common.h: New test.

Co-authored-by: Thomas Schwinge <tschwinge@baylibre.com>
(cherry picked from commit 28a5bc2d4f7ae345234a15e22fd65cfad851cf04)

13 days agoDefuse 'RESULT_DECL' check in 'pass_nrv' (for offloading compilation) [PR119835]
Thomas Schwinge [Wed, 28 May 2025 16:40:31 +0000 (18:40 +0200)] 
Defuse 'RESULT_DECL' check in 'pass_nrv' (for offloading compilation) [PR119835]

... to avoid running into ICEs per PR119835, until that's resolved properly.

PR middle-end/119835
gcc/
* tree-nrv.cc (pass_nrv::execute): Defuse 'RESULT_DECL' check.
libgomp/
* testsuite/libgomp.oacc-c-c++-common/abi-struct-1.c:
'#pragma GCC optimize "-fno-inline"'.
* testsuite/libgomp.c-c++-common/target-abi-struct-1.c: New.
* testsuite/libgomp.c-c++-common/target-abi-struct-1-O0.c: Adjust.

Co-authored-by: Richard Biener <rguenther@suse.de>
(cherry picked from commit 543f7e1d59f0b6628e0de6610ad5e1cf7150090b)

13 days ago'TYPE_EMPTY_P' vs. code offloading [PR120308]
Thomas Schwinge [Thu, 15 May 2025 16:11:16 +0000 (18:11 +0200)] 
'TYPE_EMPTY_P' vs. code offloading [PR120308]

We've got 'gcc/stor-layout.cc:finalize_type_size':

    /* Handle empty records as per the x86-64 psABI.  */
    TYPE_EMPTY_P (type) = targetm.calls.empty_record_p (type);

(Indeed x86_64 is still the only target to define 'TARGET_EMPTY_RECORD_P',
calling 'gcc/tree.cc-default_is_empty_record'.)

And so it happens that for an empty struct used in code offloaded from x86_64
host (but not powerpc64le host, for example), we get to see 'TYPE_EMPTY_P' in
offloading compilation (where the offload targets (currently?) don't use it
themselves, and therefore aren't prepared to handle it).

For nvptx offloading compilation, this causes wrong code generation:
'ptxas [...] error : Call has wrong number of parameters', as nvptx code
generation for function definition doesn't pay attention to this flag (say, in
'gcc/config/nvptx/nvptx.cc:pass_in_memory', or whereever else would be
appropriate to handle that), but the generic code 'gcc/calls.cc:expand_call'
via 'gcc/function.cc:aggregate_value_p' does pay attention to it, and we thus
get mismatching function definition vs. function call.

This issue apparently isn't a problem for GCN offloading, but I don't know if
that's by design or by accident.

Richard Biener:
> It looks like TYPE_EMPTY_P is only used during RTL expansion for ABI
> purposes, so computing it during layout_type is premature as shown here.
>
> I would suggest to simply re-compute it at offload stream-in time.

(For avoidance of doubt, the additions to 'gcc.target/nvptx/abi-struct-arg.c',
'gcc.target/nvptx/abi-struct-ret.c' are not dependent on the offload streaming
code changes, but are just to mirror the changes to
'libgomp.oacc-c-c++-common/abi-struct-1.c'.)

PR lto/120308
gcc/
* lto-streamer-out.cc (hash_tree): Don't handle 'TYPE_EMPTY_P' for
'lto_stream_offload_p'.
* tree-streamer-in.cc (unpack_ts_type_common_value_fields):
Likewise.
* tree-streamer-out.cc (pack_ts_type_common_value_fields):
Likewise.
libgomp/
* testsuite/libgomp.oacc-c-c++-common/abi-struct-1.c: Add empty
structure testing.
gcc/testsuite/
* gcc.target/nvptx/abi-struct-arg.c: Add empty structure testing.
* gcc.target/nvptx/abi-struct-ret.c: Likewise.

(cherry picked from commit 9063810c86beee6274d745b91d8fb43a81c9683e)

13 days agoAdd 'libgomp.c-c++-common/target-abi-struct-1-O0.c', 'libgomp.oacc-c-c++-common/abi...
Thomas Schwinge [Thu, 15 May 2025 16:10:05 +0000 (18:10 +0200)] 
Add 'libgomp.c-c++-common/target-abi-struct-1-O0.c', 'libgomp.oacc-c-c++-common/abi-struct-1.c'

libgomp/
* testsuite/libgomp.c-c++-common/target-abi-struct-1-O0.c: New.
* testsuite/libgomp.oacc-c-c++-common/abi-struct-1.c: Likewise.

(cherry picked from commit 45efda05c47f770a617b44cf85713a696bcf0384)

13 days agolibgomp.c/target-map-zero-sized-3.c: Fix code for non-USM offload [PR120530]
Tobias Burnus [Fri, 6 Jun 2025 13:15:03 +0000 (15:15 +0200)] 
libgomp.c/target-map-zero-sized-3.c: Fix code for non-USM offload [PR120530]

A mapping clause was missing, causing the code to fail with offloading
when a host pointer was not device accessible.

libgomp/ChangeLog:

PR target/120530
* testsuite/libgomp.c/target-map-zero-sized-3.c (main): Add missing
map clause; remove unused variable.

(cherry picked from commit 16c742e1079e838b920a1b215af17828da7c6365)

13 days agoGCN, nvptx offloading: Restrain 'WARNING: program timed out.' while in 'dynamic_cast...
Thomas Schwinge [Wed, 16 Jul 2025 20:13:46 +0000 (22:13 +0200)] 
GCN, nvptx offloading: Restrain 'WARNING: program timed out.' while in 'dynamic_cast' only for effective-target 'offload_device' [PR119692]

In PR119692 "C++ 'typeinfo', 'vtable' vs. OpenACC, OpenMP 'target' offloading":

> --- Comment #8 from Rainer Orth <ro at gcc dot gnu.org> ---
> The last commit made things worse on sparc-sun-solaris2.11: since that one
> (dg-timeout 10) I regularly get
>
> WARNING: libgomp.c++/target-exceptions-bad_cast-1.C (test for excess errors)
> program timed out.
> FAIL: libgomp.c++/target-exceptions-bad_cast-1.C (test for excess errors)
> UNRESOLVED: libgomp.c++/target-exceptions-bad_cast-1.C compilation failed to produce executable
> UNRESOLVED: libgomp.c++/target-exceptions-bad_cast-1.C scan-tree-dump-times optimized "gimple_call <__cxa_bad_cast, " 1
>
> Before that, the test had no issue.  Compiling the test on an unloaded system
> usually takes less than 1 sec, but when fully loaded, times can go up.

To keep things simple, let's restrict this temporary (yeah...) workaround to
apply only for effective-target 'offload_device', just like the
'dg-xfail-run-if' itself.

PR target/119692
libgomp/
* testsuite/libgomp.c++/pr119692-1-4.C: '{ dg-timeout 10 { target offload_device } }'.
* testsuite/libgomp.c++/pr119692-1-5.C: Likewise.
* testsuite/libgomp.c++/target-exceptions-bad_cast-1.C: Likewise.
* testsuite/libgomp.c++/target-exceptions-bad_cast-2.C: Likewise.
* testsuite/libgomp.oacc-c++/exceptions-bad_cast-1.C: Likewise.
* testsuite/libgomp.oacc-c++/exceptions-bad_cast-2.C: Likewise.

(cherry picked from commit aa143261bdf6db4334b3fcad7768b53e231f998e)

13 days agoGCN, nvptx offloading: Restrain 'WARNING: program timed out.' while in 'dynamic_cast...
Thomas Schwinge [Fri, 9 May 2025 12:49:03 +0000 (14:49 +0200)] 
GCN, nvptx offloading: Restrain 'WARNING: program timed out.' while in 'dynamic_cast'" [PR119692]

PR target/119692
libgomp/
* testsuite/libgomp.c++/pr119692-1-4.C: '{ dg-timeout 10 }'.
* testsuite/libgomp.c++/pr119692-1-5.C: Likewise.
* testsuite/libgomp.c++/target-exceptions-bad_cast-1.C: Likewise.
* testsuite/libgomp.c++/target-exceptions-bad_cast-2.C: Likewise.
* testsuite/libgomp.oacc-c++/exceptions-bad_cast-1.C: Likewise.
* testsuite/libgomp.oacc-c++/exceptions-bad_cast-2.C: Likewise.

(cherry picked from commit b5f48e7872db30b8f174cb2c497868a358bf75d6)

13 days agonvptx: Support '-march=sm_61'
Thomas Schwinge [Wed, 7 May 2025 14:02:16 +0000 (16:02 +0200)] 
nvptx: Support '-march=sm_61'

gcc/
* config/nvptx/nvptx-sm.def: Add '61'.
* config/nvptx/nvptx-gen.h: Regenerate.
* config/nvptx/nvptx-gen.opt: Likewise.
* config/nvptx/nvptx.cc (first_ptx_version_supporting_sm): Adjust.
* config/nvptx/nvptx.opt (-march-map=sm_61, -march-map=sm_62):
Likewise.
* config.gcc: Likewise.
* doc/invoke.texi (Nvidia PTX Options): Document '-march=sm_61'.
* config/nvptx/gen-multilib-matches-tests: Extend.
gcc/testsuite/
* gcc.target/nvptx/march-map=sm_61.c: Adjust.
* gcc.target/nvptx/march-map=sm_62.c: Likewise.
* gcc.target/nvptx/march=sm_61.c: New.
libgomp/
* testsuite/libgomp.c/declare-variant-3-sm61.c: New.
* testsuite/libgomp.c/declare-variant-3.h: Adjust.

(cherry picked from commit 7b53b88381179c5c8152bcb890460f66d9c88fac)

13 days agonvptx: Support '-mptx=5.0'
Thomas Schwinge [Wed, 7 May 2025 13:37:17 +0000 (15:37 +0200)] 
nvptx: Support '-mptx=5.0'

gcc/
* config/nvptx/nvptx-opts.h (enum ptx_version): Add
'PTX_VERSION_5_0'.
* config/nvptx/nvptx.cc (ptx_version_to_string)
(ptx_version_to_number): Adjust.
* config/nvptx/nvptx.h (TARGET_PTX_5_0): New.
* config/nvptx/nvptx.opt (Enum(ptx_version)): Add 'EnumValue'
'5.0' for 'PTX_VERSION_5_0'.
* doc/invoke.texi (Nvidia PTX Options): Document '-mptx=5.0'.
gcc/testsuite/
* gcc.target/nvptx/mptx=5.0.c: New.

(cherry picked from commit 97616687149f115e0ab946b9a05a9f8c1e47429e)

13 days agoAdjust 'libgomp.c++/target-cdtor-{1,2}.C' for 'targetm.cxx.use_aeabi_atexit' [PR11985...
Thomas Schwinge [Fri, 18 Jul 2025 10:56:13 +0000 (12:56 +0200)] 
Adjust 'libgomp.c++/target-cdtor-{1,2}.C' for 'targetm.cxx.use_aeabi_atexit' [PR119853, PR119854]

Fix-up for commit aafe942227baf8c2bcd4cac2cb150e49a4b895a9
"GCN, nvptx offloading: Host/device compatibility: Itanium C++ ABI, DSO Object Destruction API [PR119853, PR119854]":
we need to adjust for 'targetm.cxx.use_aeabi_atexit':

    gcc/config/arm/arm.cc:#define TARGET_CXX_USE_AEABI_ATEXIT arm_cxx_use_aeabi_atexit

    gcc/config/arm/arm.cc:/* The EABI says __aeabi_atexit should be used to register static
    gcc/config/arm/arm.cc-   destructors.  */
    gcc/config/arm/arm.cc-
    gcc/config/arm/arm.cc-static bool
    gcc/config/arm/arm.cc:arm_cxx_use_aeabi_atexit (void)
    gcc/config/arm/arm.cc-{
    gcc/config/arm/arm.cc-  return TARGET_AAPCS_BASED;
    gcc/config/arm/arm.cc-}

..., which 'gcc/cp/decl.cc:get_atexit_node' then acts on: call '__aeabi_atexit'
instead of '__cxa_atexit', and swap two arguments.

PR target/119853
PR target/119854
libgomp/
* testsuite/libgomp.c++/target-cdtor-1.C: Adjust for
'targetm.cxx.use_aeabi_atexit'.
* testsuite/libgomp.c++/target-cdtor-2.C: Likewise.

(cherry picked from commit 04b42c4245d85f77aa54ec002ebd7bbe6fde5f11)

13 days agoGCN, nvptx offloading: Host/device compatibility: Itanium C++ ABI, DSO Object Destruc...
Thomas Schwinge [Wed, 23 Apr 2025 08:51:48 +0000 (10:51 +0200)] 
GCN, nvptx offloading: Host/device compatibility: Itanium C++ ABI, DSO Object Destruction API [PR119853, PR119854]

'__dso_handle' for '__cxa_atexit', '__cxa_finalize'.  See
<https://itanium-cxx-abi.github.io/cxx-abi/abi.html#dso-dtor>.

PR target/119853
PR target/119854
libgcc/
* config/gcn/crt0.c (_fini_array): Call
'__GCC_offload___cxa_finalize'.
* config/nvptx/gbl-ctors.c (__static_do_global_dtors): Likewise.
libgomp/
* target-cxa-dso-dtor.c: New.
* config/accel/target-cxa-dso-dtor.c: Likewise.
* Makefile.am (libgomp_la_SOURCES): Add it.
* Makefile.in: Regenerate.
* testsuite/libgomp.c++/target-cdtor-1.C: New.
* testsuite/libgomp.c++/target-cdtor-2.C: Likewise.

(cherry picked from commit aafe942227baf8c2bcd4cac2cb150e49a4b895a9)