Commit graph

209175 commits

Author SHA1 Message Date
GCC Administrator
b05f474c8f Daily bump. 2024-03-01 00:16:41 +00:00
David Malcolm
c0d8a64e72 analyzer: fix ICE in call summarization [PR114159]
PR analyzer/114159 reports an ICE inside playback of call summaries
for very low values of --param=analyzer-max-svalue-depth=VAL.

Root cause is that call_summary_edge_info's ctor tries to evaluate
the function ptr of a gimple call stmt and assumes it gets a function *,
but with low values of --param=analyzer-max-svalue-depth=VAL we get
back an UNKNOWN svalue, rather than a pointer to a specific function.

Fix by adding a new call_info ctor that passes a specific
const function & from the call_summary_edge_info, rather than trying
to compute the function.

In doing so, I noticed that the analyzer was using "function *" despite
not modifying functions, and was sloppy about can-be-null versus
must-be-non-null function pointers, so I "constified" the function, and
converted the many places where the function must be non-null to be
"const function &".

gcc/analyzer/ChangeLog:
	PR analyzer/114159
	* analyzer.cc: Include "tree-dfa.h".
	(get_ssa_default_def): New decl.
	* analyzer.h (get_ssa_default_def): New.
	* call-info.cc (call_info::call_info): New ctor taking an explicit
	called_fn.
	* call-info.h (call_info::call_info): Likewise.
	* call-summary.cc (call_summary_replay::call_summary_replay):
	Convert param from function * to const function &.
	* call-summary.h (call_summary_replay::call_summary_replay):
	Likewise.
	* checker-event.h (state_change_event::get_dest_function):
	Constify return value.
	* engine.cc (point_and_state::validate): Update for conversion to
	const function &.
	(exploded_node::on_stmt): Likewise.
	(call_summary_edge_info::call_summary_edge_info): Likewise.
	Pass in called_fn to call_info ctor.
	(exploded_node::replay_call_summaries): Update for conversion to
	const function &.  Convert per_function_data from * to &.
	(exploded_node::replay_call_summary): Update for conversion to
	const function &.
	(exploded_graph::add_function_entry): Likewise.
	(toplevel_function_p): Likewise.
	(add_tainted_args_callback): Likewise.
	(exploded_graph::build_initial_worklist): Likewise.
	(exploded_graph::maybe_create_dynamic_call): Likewise.
	(maybe_update_for_edge): Likewise.
	(exploded_graph::on_escaped_function): Likewise.
	* exploded-graph.h (exploded_node::replay_call_summaries):
	Likewise.
	(exploded_node::replay_call_summary): Likewise.
	(exploded_graph::add_function_entry): Likewise.
	* program-point.cc (function_point::from_function_entry):
	Likewise.
	(program_point::from_function_entry): Likewise.
	* program-point.h (function_point::from_function_entry): Likewise.
	(program_point::from_function_entry): Likewise.
	* program-state.cc (program_state::push_frame): Likewise.
	(program_state::get_current_function): Constify return type.
	* program-state.h (program_state::push_frame): Update for
	conversion to const function &.
	(program_state::get_current_function): Likewise.
	* region-model-manager.cc
	(region_model_manager::get_frame_region): Likewise.
	* region-model-manager.h
	(region_model_manager::get_frame_region): Likewise.
	* region-model.cc (region_model::called_from_main_p): Likewise.
	(region_model::update_for_gcall): Likewise.
	(region_model::push_frame): Likewise.
	(region_model::get_current_function): Constify return type.
	(region_model::pop_frame): Update for conversion to
	const function &.
	(selftest::test_stack_frames): Likewise.
	(selftest::test_get_representative_path_var): Likewise.
	(selftest::test_state_merging): Likewise.
	(selftest::test_alloca): Likewise.
	* region-model.h (region_model::push_frame): Likewise.
	(region_model::get_current_function): Likewise.
	* region.cc (frame_region::dump_to_pp): Likewise.
	(frame_region::get_region_for_local): Likewise.
	* region.h (class frame_region): Likewise.
	* sm-signal.cc (signal_unsafe_call::describe_state_change):
	Likewise.
	(update_model_for_signal_handler): Likewise.
	(signal_delivery_edge_info_t::update_model): Likewise.
	(register_signal_handler::impl_transition): Likewise.
	* state-purge.cc (class gimple_op_visitor): Likewise.
	(state_purge_map::state_purge_map): Likewise.
	(state_purge_map::get_or_create_data_for_decl): Likewise.
	(state_purge_per_ssa_name::state_purge_per_ssa_name): Likewise.
	(state_purge_per_ssa_name::add_to_worklist): Likewise.
	(state_purge_per_ssa_name::process_point): Likewise.
	(state_purge_per_decl::add_to_worklist): Likewise.
	(state_purge_annotator::print_needed): Likewise.
	* state-purge.h
	(state_purge_map::get_or_create_data_for_decl): Likewise.
	(class state_purge_per_tree): Likewise.
	(class state_purge_per_ssa_name): Likewise.
	(class state_purge_per_decl): Likewise.
	* supergraph.cc (supergraph::dump_dot_to_pp): Likewise.
	* supergraph.h
	(supergraph::get_node_for_function_entry): Likewise.
	(supergraph::get_node_for_function_exit): Likewise.

gcc/ChangeLog:
	PR analyzer/114159
	* function.cc (function_name): Make param const.
	* function.h (function_name): Likewise.

gcc/testsuite/ChangeLog:
	PR analyzer/114159
	* c-c++-common/analyzer/call-summaries-pr114159.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2024-02-29 17:57:08 -05:00
Georg-Johann Lay
cda3836161 AVR: target/114100 - Better indirect accesses for reduced Tiny
The Reduced Tiny core does not support indirect addressing with offset,
which basically means that every indirect memory access with a size
of more than one byte is effectively POST_INC or PRE_DEC.  The lack of
that addressing mode is currently handled by pretending to support it,
and then let the insn printers add and subtract again offsets as needed.
For example, the following C code

   int vars[10];

   void inc_var2 (void) {
      ++vars[2];
   }

is compiled to:

   ldi r30,lo8(vars)     ;  14   [c=4 l=2]  *movhi/4
   ldi r31,hi8(vars)
   subi r30,lo8(-(4))    ;  15   [c=8 l=6]  *movhi/2
   sbci r31,hi8(-(4))
   ld r20,Z+
   ld r21,Z
   subi r30,lo8((4+1))
   sbci r31,hi8((4+1))
   subi r20,-1             ;  16   [c=4 l=2]  *addhi3_clobber/1
   sbci r21,-1
   subi r30,lo8(-(4+1))    ;  17   [c=4 l=4]  *movhi/3
   sbci r31,hi8(-(4+1))
   st Z,r21
   st -Z,r20

where the code could be -- and with this patch actually is -- like

   ldi r30,lo8(vars+4)    ;  28   [c=4 l=2]  *movhi/4
   ldi r31,hi8(vars+4)
   ld r20,Z+              ;  17   [c=8 l=2]  *movhi/2
   ld r21,Z+
   subi r20,-1            ;  19   [c=4 l=2]  *addhi3_clobber/1
   sbci r21,-1
   st -Z,r21              ;  30   [c=4 l=2]  *movhi/3
   st -Z,r20

This is achieved in two steps:

- A post-reload split into "real" instructions during .split2.
- A new avr-specific mini pass .avr-fuse-add that runs before
  RTL peephole and that tries to combine the generated pointer
  additions into memory accesses to form POST_INC or PRE_DEC.

gcc/
	PR target/114100
	* doc/invoke.texi (AVR Options) <-mfuse-add>: Document.
	* config/avr/avr.opt (-mfuse-add=): New target option.
	* common/config/avr/avr-common.cc (avr_option_optimization_table)
	[OPT_LEVELS_1_PLUS]: Set -mfuse-add=1.
	[OPT_LEVELS_2_PLUS]: Set -mfuse-add=2.
	* config/avr/avr-passes.def (avr_pass_fuse_add): Insert new pass.
	* config/avr/avr-protos.h (avr_split_tiny_move)
	(make_avr_pass_fuse_add): New protos.
	* config/avr/avr.md [AVR_TINY]: New post-reload splitter uses
	avr_split_tiny_move to split indirect memory accesses.
	(gen_move_clobbercc): New define_expand helper.
	* config/avr/avr.cc (avr_pass_data_fuse_add): New pass data.
	(avr_pass_fuse_add): New class from rtl_opt_pass.
	(make_avr_pass_fuse_add, avr_split_tiny_move): New functions.
	(reg_seen_between_p, emit_move_ccc, emit_move_ccc_after): New functions.
	(avr_legitimate_address_p) [AVR_TINY]: Don't restrict offsets
	of PLUS addressing for AVR_TINY.
	(avr_regno_mode_code_ok_for_base_p) [AVR_TINY]: Ignore -mstrict-X.
	(avr_out_plus_1) [AVR_TINY]: Tweak ++Y and --Y.
	(avr_mode_code_base_reg_class) [AVR_TINY]: Always return POINTER_REGS.
2024-02-29 20:39:58 +01:00
Jonathan Wakely
02ca9d3f0c libstdc++: Fix std::basic_format_arg::handle for BasicFormatters
std::basic_format_arg::handle is supposed to format its value as const
if that is valid, to reduce the number of instantiations of the
formatter's format function. I made a silly typo so that it checks
formattable_with<TD, Context> not formattable_with<const TD, Context>,
which breaks support for BasicFormatters i.e. ones that can only format
non-const types.

There's a static_assert in the handle constructor which is supposed to
improve diagnostics for trying to format a const argument with a
formatter that doesn't support it. That condition can't fail, because
the std::basic_format_arg constructor is already constrained to check
that the argument type is formattable. The static_assert can be removed.

libstdc++-v3/ChangeLog:

	* include/std/format (basic_format_arg::handle::__maybe_const_t):
	Fix condition to check if const type is formattable.
	(basic_format_arg::handle::handle(T&)): Remove redundant
	static_assert.
	* testsuite/std/format/formatter/basic.cc: New test.
2024-02-29 17:49:43 +00:00
Jonathan Wakely
f5cdda8acb libstdc++: Fix conditions for using memcmp in std::lexicographical_compare_three_way [PR113960]
The change in r11-2981-g2f983fa69005b6 meant that
std::lexicographical_compare_three_way started to use memcmp for
unsigned integers on big endian targets, but for that to be valid we
need the two value types to have the same size and we need to use that
size to compute the length passed to memcmp.

I already defined a __is_memcmp_ordered_with trait that does the right
checks, std::lexicographical_compare_three_way just needs to use it.

libstdc++-v3/ChangeLog:

	PR libstdc++/113960
	* include/bits/stl_algobase.h (__is_byte_iter): Replace with ...
	(__memcmp_ordered_with): New concept.
	(lexicographical_compare_three_way): Use __memcmp_ordered_with
	instead of __is_byte_iter. Use correct length for memcmp.
	* testsuite/25_algorithms/lexicographical_compare_three_way/113960.cc:
	New test.
2024-02-29 17:49:43 +00:00
Georg-Johann Lay
2f43ad6a60 AVR: target/114132 - Code sets up a frame pointer without need.
The condition CUMULATIVE_ARGS.nregs == 0 in avr_frame_pointer_required_p()
means that no more argument registers are left, but that's not the same
condition that tells whether an argument pointer is required.

	PR target/114132
gcc/
	* config/avr/avr.h (CUMULATIVE_ARGS) <has_stack_args>: New field.
	* config/avr/avr.cc (avr_init_cumulative_args): Initialize it.
	(avr_function_arg): Set it.
	(avr_frame_pointer_required_p): Use it instead of .nregs.

gcc/testsuite/
	* gcc.target/avr/pr114132-1.c: New test.
	* gcc.target/avr/torture/pr114132-2.c: New test.
2024-02-29 18:46:19 +01:00
Marek Polacek
b83f3cd3ff c++: -Wuninitialized when binding a ref to uninit DM [PR113987]
This PR asks that our -Wuninitialized for mem-initializers does
not warn when binding a reference to an uninitialized data member.
We already check !INDIRECT_TYPE_P in find_uninit_fields_r, but
that won't catch binding a parameter of a reference type to an
uninitialized field, as in:

  struct S { S (int&); };
  struct T {
      T() : s(i) {}
      S s;
      int i;
  };

This patch adds a new function to handle this case.

	PR c++/113987

gcc/cp/ChangeLog:

	* call.cc (conv_binds_to_reference_parm_p): New.
	* cp-tree.h (conv_binds_to_reference_parm_p): Declare.
	* init.cc (find_uninit_fields_r): Call it.

gcc/testsuite/ChangeLog:

	* g++.dg/warn/Wuninitialized-15.C: Turn dg-warning into dg-bogus.
	* g++.dg/warn/Wuninitialized-34.C: New test.
2024-02-29 12:39:21 -05:00
Tom Tromey
bc0e18a960 Fix PR libcc1/113977
PR libcc1/113977 points out a case where a simple expression is
rejected with a compiler error message.  The bug here is that gdb does
not inform the plugin of the correct alignment -- in fact, there is no
way to do that.

This patch adds a new method to allow the alignment to be set, and
bumps the C front end protocol version.

It also includes some updates to various comments in 'include', done
here to simplify the merge to binutils-gdb.

include

	* gcc-cp-interface.h (gcc_cp_fe_context_function): Update
	comment.
	* gcc-c-interface.h (enum gcc_c_api_version) <GCC_C_FE_VERSION_2>:
	New constant.
	(gcc_c_fe_context_function): Update comment.
	* gcc-c-fe.def (finish_record_with_alignment): New method.
	Update documentation.

libcc1

	PR libcc1/113977
	* libcc1plugin.cc (plugin_finish_record_or_union): New function.
	(plugin_finish_record_or_union): Rewrite.
	(plugin_init): Use GCC_C_FE_VERSION_2.
	* libcc1.cc (c_vtable): Use GCC_C_FE_VERSION_2.
	(gcc_c_fe_context): Check for GCC_C_FE_VERSION_2.
2024-02-29 08:50:06 -07:00
Tom Tromey
54137725cf Fix version negotiation in libcc1 plugins
This fixes version negotiation in the libcc1 plugins.  It's done in a
simple way: the version number from the context object is now passed
to base_gdb_plugin.

The idea behind this is that when the client (gdb) requests version N,
the plugin should respond with the newest version that it knows of
that is backward compatible to N.  That is, the connection can be
upgraded.  Note that the protocol does not change much, and no
backward incompatibilities have ever been needed.

The C plugin is also changed to advertise GCC_C_FE_VERSION_1.

The version negotiation approach should of course be documented, but I
did that in a subsequent patch, in order to only have one patch
touching the 'include' directory and thus needing a merge to
binutils-gdb.

libcc1

	* libcp1.cc (libcp1::libcp1): Use FE version number from context.
	* libcc1.cc (libcc1::libcc1): Use FE version number from context.
	(c_vtable): Use GCC_C_FE_VERSION_1.
2024-02-29 08:50:06 -07:00
Tom Tromey
fd846abc2d Change 'v1' float and int code to fall back to v0
While working on another patch, I discovered that the libcc1 plugin
code never did version negotiation correctly.  So, the patches to
introduce v1 never did anything -- the new code, as far as I know, has
never been run.

Making version negotiation work shows that the existing code causes
crashes.  For example, safe_lookup_builtin_type might return
error_mark_node in some cases, which the callers aren't prepared to
accept.

Looking into it some more, I couldn't find any justification for this
v1 code for the C compiler plugin.  Since it's not run at all, it's
also clear that removing it doesn't cause any regressions in gdb.

However, rather than remove it, this patch changes it to handle
ERROR_MARK better, and then to fall back to the v0 code if the new
code fails to find the type it's looking for.

libcc1

	* libcc1plugin.cc (safe_lookup_builtin_type): Handle ERROR_MARK.
	(plugin_int_type): Fall back to plugin_int_type_v0.
	(plugin_float_type): Fall back to plugin_float_type_v0.
2024-02-29 08:50:06 -07:00
Gaius Mulley
46666b9bde PR modula2/102344 TestLong4.mod FAILs
This is a testsuite fix for TestLong4.mod so that it
succeeds on 32 bit systems.  The original TestLong4.mod has
been rewritten as testing MAX(LONGCARD) into the variable l.
The new testlong4.mod has been added to cpp/pass.  The new
testcode uses the C preprocessor to select the appropriate
constant literal depending upon __SIZEOF_LONG__.

gcc/testsuite/ChangeLog:

	PR modula2/102344
	* gm2/pim/pass/TestLong4.mod: Rewrite.
	* gm2/cpp/pass/testlong4.mod: New test.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
2024-02-29 13:42:30 +00:00
Andrew Pinski
5ec7740496 aarch64: Fix memtag builtins vs GC [PR108174]
The memtag builtins were being GC'ed away so we end up
with a crash sometimes (maybe even wrong code).
This fixes that issue by adding GTY on the variable/struct
aarch64_memtag_builtin_data.

Committed as obvious after a build/test for aarch64-linux-gnu.

	PR target/108174

gcc/ChangeLog:

	* config/aarch64/aarch64-builtins.cc (aarch64_memtag_builtin_data): Make
	static and mark with GTY.

gcc/testsuite/ChangeLog:

	* gcc.target/aarch64/acle/memtag_4.c: New test.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
2024-02-28 23:14:12 -08:00
Xi Ruoyao
aab1c5dcd2
LoongArch: Remove unneeded sign extension after crc/crcc instructions
The specification of crc/crcc instructions is clear that the output is
sign-extended to GRLEN.  Add a define_insn to tell the compiler this
fact and allow it to remove the unneeded sign extension on crc/crcc
output.  As crc/crcc instructions are usually used in a tight loop,
this should produce a significant performance gain.

gcc/ChangeLog:

	* config/loongarch/loongarch.md
	(loongarch_<crc>_w_<size>_w_extended): New define_insn.

gcc/testsuite/ChangeLog:

	* gcc.target/loongarch/crc-sext.c: New test;
2024-02-29 14:48:18 +08:00
Xi Ruoyao
c556ea076d
LoongArch: NFC: Deduplicate crc instruction defines
Introduce an iterator for UNSPEC_CRC and UNSPEC_CRCC to make the next
change easier.

gcc/ChangeLog:

	* config/loongarch/loongarch.md (CRC): New define_int_iterator.
	(crc): New define_int_attr.
	(loongarch_crc_w_<size>_w, loongarch_crcc_w_<size>_w): Unify
	into ...
	(loongarch_<crc>_w_<size>_w): ... here.
2024-02-29 14:48:18 +08:00
Nathaniel Shead
3685fae23b c++: Support lambdas attached to more places in modules [PR111710]
The fix for PR107398 weakened the restrictions that lambdas must belong
to namespace scope. However this was not sufficient: we also need to
allow lambdas attached to FIELD_DECLs, PARM_DECLs, and TYPE_DECLs.

For field decls we key the lambda to its class rather than the field
itself. Otherwise we can run into issues when deduplicating the lambda's
TYPE_DECL, because when loading its context we load the containing field
before we've deduplicated the keyed lambda, causing mismatches; by
keying to the class instead we defer checking keyed declarations until
deduplication has completed.

Additionally, by [basic.link] p15.2 a lambda defined anywhere in a
class-specifier should not be TU-local, which includes base-class
declarations, so ensure that lambdas declared there are keyed
appropriately as well.

Because this now requires 'DECL_MODULE_KEYED_DECLS_P' to be checked on a
fairly large number of different kinds of DECLs, and that in general
it's safe to just get 'false' as a result of a check on an unexpected
DECL type, this patch also removes the tree checking from the accessor.

Finally, to handle deduplicating templated lambda fields, we need to
ensure that we can determine that two lambdas from different field decls
match, so we ensure that we also deduplicate LAMBDA_EXPRs on stream in.

	PR c++/111710

gcc/cp/ChangeLog:

	* cp-tree.h (DECL_MODULE_KEYED_DECLS_P): Remove tree checking.
	(struct lang_decl_base): Update comments and fix whitespace.
	* module.cc (trees_out::lang_decl_bools): Always write
	module_keyed_decls_p flag...
	(trees_in::lang_decl_bools): ...and always read it.
	(trees_out::decl_value): Handle all kinds of keyed decls.
	(trees_in::decl_value): Likewise.
	(trees_in::tree_value): Deduplicate LAMBDA_EXPRs.
	(maybe_key_decl): Also support lambdas attached to fields,
	parameters, and types. Key lambdas attached to fields to their
	class.
	(trees_out::get_merge_kind): Likewise.
	(trees_out::key_mergeable): Likewise.
	(trees_in::key_mergeable): Support keyed decls in a TYPE_DECL
	container.
	* parser.cc (cp_parser_class_head): Start a lambda scope when
	parsing base classes.

gcc/testsuite/ChangeLog:

	* g++.dg/modules/lambda-7.h: New test.
	* g++.dg/modules/lambda-7_a.H: New test.
	* g++.dg/modules/lambda-7_b.C: New test.
	* g++.dg/modules/lambda-7_c.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Patrick Palka <ppalka@redhat.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
2024-02-29 16:04:03 +11:00
Kito Cheng
fd07a29e39 RISC-V: Fix __atomic_compare_exchange with 32 bit value on RV64
atomic_compare_and_swapsi will use lr.w to do obtain the original value,
which sign extends to DI.  RV64 only has DI comparisons, so we also need
to sign extend the expected value to DI as otherwise the comparison will
fail when the expected value has the 32nd bit set.

gcc/ChangeLog:

	PR target/114130
	* config/riscv/sync.md (atomic_compare_and_swap<mode>): Sign
	extend the expected value if needed.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/pr114130.c: New.

Reviewed-by: Palmer Dabbelt <palmer@rivosinc.com>
2024-02-29 11:05:21 +08:00
Andrew Pinski
5ff49272bf Add libcc1 to bug components
As found by Tom Tromey in https://gcc.gnu.org/pipermail/gcc-patches/2024-February/646807.html
libcc1 is not listed as bug component even though it is there in bugzilla.
This fixes that oversight.

Committed as obvious after testing using git gcc-verify on a patch.

contrib/ChangeLog:

	* gcc-changelog/git_commit.py (bug_components): Add libcc1.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
2024-02-29 02:36:12 +00:00
Alexander Westbrooks
edfe198084 Fortran - Error compiling PDT Type-bound Procedures [PR82943/86148/86268]
This patch allows parameterized derived types to compile successfully
when typebound procedures are specified in the type specification.
Furthermore, it allows function calls for PDTs by setting the
f2k_derived space of PDT instances to reference their original template,
thereby giving it referential access to the typebound procedures of the
template. Lastly, it adds a check for deferred length parameters of
PDTs in CLASS declaration statements, and correctly throws an error if
such declarations are missing POINTER or ALLOCATABLE attributes.

2024-02-25  Alexander Westbrooks  <alexanderw@gcc.gnu.org>

gcc/fortran/ChangeLog:
	PR fortran/82943
	PR fortran/86148
	PR fortran/86268
	* decl.cc (gfc_get_pdt_instance): Set the PDT instance field
	'f2k_derived', if not set already, to point to the given
	PDT template 'f2k_derived' namespace in order to give the
	PDT instance referential access to the typebound procedures
	of the template.
	* gfortran.h (gfc_pdt_is_instance_of): Add prototype.
	* resolve.cc (resolve_typebound_procedure): If the derived type
	does not have the attribute 'pdt_template' set, compare the
	dummy argument to the 'resolve_bindings_derived' type like usual.
	If the derived type is a 'pdt_template', then check if the
	dummy argument is an instance of the PDT template. If the derived
	type is a PDT template, and the dummy argument is an instance of
	that template, but the dummy argument 'param_list' is not
	SPEC_ASSUMED, check if there are any LEN parameters in the
	dummy argument. If there are no LEN parameters, then this implies
	that there are only KIND parameters in the dummy argument.
	If there are LEN parameters, this would be an error, for all
	LEN parameters for the dummy argument MUST be assumed for
	typebound procedures of PDTs.
	(resolve_pdt): Add a check for ALLOCATABLE and POINTER attributes for
	SPEC_DEFERRED parameters of PDT class symbols.  ALLOCATABLE and
	POINTER attributes for a PDT class symbol are stored in the
	'class_pointer' and 'allocatable' attributes of the '_data'
	component respectively.
	* symbol.cc (gfc_pdt_is_instance_of): New function.

gcc/testsuite/ChangeLog:
	PR fortran/82943
	PR fortran/86148
	PR fortran/86268
	* gfortran.dg/pdt_4.f03: Update modified error message.
	* gfortran.dg/pdt_34.f03: New test.
	* gfortran.dg/pdt_35.f03: New test.
	* gfortran.dg/pdt_36.f03: New test.
	* gfortran.dg/pdt_37.f03: New test.

Signed-off-by: Alexander Westbrooks <alexanderw@gcc.gnu.org>
2024-02-28 20:09:58 -06:00
GCC Administrator
fd52355aa5 Daily bump. 2024-02-29 00:16:43 +00:00
Jakub Jelinek
29ac92436a c++: Fix explicit instantiation of const variable templates after earlier implicit instantation [PR113976]
Already previously instantiated const variable templates had
cp_apply_type_quals_to_decl called when they were instantiated,
but if they need runtime initialization, their TREE_READONLY flag
has been subsequently cleared.
Explicit variable template instantiation calls grokdeclarator which
calls cp_apply_type_quals_to_decl on them again, setting TREE_READONLY
flag again, but nothing clears it afterwards, so we emit such
instantiations into rodata sections and segfault when the dynamic
initialization attempts to initialize them.

The following patch fixes that by not calling cp_apply_type_quals_to_decl
on already instantiated variable declarations.

2024-02-28  Jakub Jelinek  <jakub@redhat.com>
	    Patrick Palka  <ppalka@redhat.com>

	PR c++/113976
	* decl.cc (grokdeclarator): Don't call cp_apply_type_quals_to_decl
	on DECL_TEMPLATE_INSTANTIATED VAR_DECLs.

	* g++.dg/cpp1y/var-templ87.C: New test.
2024-02-28 23:20:13 +01:00
Fangrui Song
bfecc90737 Add myself to write after approval and DCO
ChangeLog:

	* MAINTAINERS: Add myself.

Signed-off-by: Fangrui Song <maskray@gcc.gnu.org>
2024-02-28 12:57:20 -08:00
Cupertino Miranda
13914f4be9 bpf: renames coreout.* files to btfext-out.*.
gcc/ChangeLog:

	* config.gcc (target_gtfiles): Change coreout to btfext-out.
	(extra_objs): Change coreout to btfext-out.
	* config/bpf/coreout.cc: Rename to btfext-out.cc.
	* config/bpf/btfext-out.cc: Add.
	* config/bpf/coreout.h: Rename to btfext-out.h.
	* config/bpf/btfext-out.h: Add.
	* config/bpf/core-builtins.cc: Change include.
	* config/bpf/core-builtins.h: Change include.
	* config/bpf/t-bpf: Accomodate renamed files.
2024-02-28 19:20:21 +00:00
Cupertino Miranda
77142bdba4 bpf: implementation of func_info in .BTF.ext.
Kernel verifier complains in some particular cases for missing func_info
implementation in .BTF.ext. This patch implements it.

Strings are cached locally in coreout.cc to avoid adding duplicated
strings in the string list. This string deduplication should eventually
be moved to the CTFC functions such that this happens widely.

With this implementation, the CO-RE relocations information was also
simplified and integrated with the FuncInfo structures.

gcc/Changelog:

	PR target/113453
	* config/bpf/bpf.cc (bpf_function_prologue): Define target
	hook.
	* config/bpf/coreout.cc (brf_ext_info_section)
	(btf_ext_info): Move from coreout.h
	(btf_ext_funcinfo, btf_ext_lineinfo): Add struct.
	(bpf_core_reloc): Rename to btf_ext_core_reloc.
	(btf_ext): Add static variable.
	(btfext_info_sec_find_or_add, SEARCH_NODE_AND_RETURN)
	(bpf_create_or_find_funcinfo, bpt_create_core_reloc)
	(btf_ext_add_string, btf_funcinfo_type_callback)
	(btf_add_func_info_for, btf_validate_funcinfo)
	(btf_ext_info_len, output_btfext_func_info): Add function.
	(output_btfext_header, bpf_core_reloc_add)
	(output_btfext_core_relocs, btf_ext_init, btf_ext_output):
	Change to support new structs.
	* config/bpf/coreout.h (btf_ext_funcinfo, btf_ext_lineinfo):
	Move and change in coreout.cc.
	(btf_add_func_info_for, btf_ext_add_string): Add prototypes.

gcc/testsuite/ChangeLog:
	PR target/113453
	* gcc.target/bpf/btfext-funcinfo-nocore.c: Add.
	* gcc.target/bpf/btfext-funcinfo.c: Add.
	* gcc.target/bpf/core-attr-5.c: Fix regexp.
	* gcc.target/bpf/core-attr-6.c: Fix regexp.
	* gcc.target/bpf/core-builtin-fieldinfo-offset-1.c: Fix regexp.
	* gcc.target/bpf/core-section-1.c: Fix regexp.
2024-02-28 19:20:21 +00:00
Cupertino Miranda
38d2eb337b bpf: Always emit .BTF.ext section if generating BTF
BPF applications, when generating BTF information should always create a
.BTF.ext section.
Current implementation was only creating it when -mco-re option was used.
This patch makes .BTF.ext always be generated for BPF target objects.
The patch also adds conditions around btf_finalize function call
such that BTF deallocation happens later for BPF target.
For BPF, btf_finalize is only called after .BTF.ext is generated.

gcc/ChangeLog:

	* config/bpf/bpf.cc (bpf_option_override): Make .BTF.ext
	enabled by default for BPF.
	(bpf_file_end): Call BTF deallocation.
	(bpf_asm_init_sections): Correct condition.
	* dwarf2ctf.cc (ctf_debug_finalize): Conditionally execute BTF
	deallocation.
	(ctf_debuf_finish): Correct condition for calling
	ctf_debug_finalize.
2024-02-28 19:20:20 +00:00
Cupertino Miranda
69a3ce49bd btf: add BTF_KIND_FUNC traversal function.
The patch adds a traversal function to traverse all BTF_KIND_FUNC nodes
with a callback function. Used for .BTF.ext section content creation.

gcc/ChangeLog:

	* btfout.cc (output_btf_func_types): Use FOR_EACH_VEC_ELT.
	(traverse_btf_func_types): Define function.
	* ctfc.h (funcs_traverse_callback): Typedef for function
	prototype.
	(traverse_btf_func_types): Add prototype.
2024-02-28 19:20:20 +00:00
Cupertino Miranda
0198cade5a btf: fix type id in BTF_KIND_FUNC struct data.
This patch corrects the addition of +1 on the type id, which originally
was done in the wrong location and led to func_dtd->dtd_type for
BTF_KIND_FUNC struct data to contain the type id of the previous entry.

gcc/ChangeLog:

	* btfout.cc (btf_collect_dataset): Corrects BTF type id.
2024-02-28 19:20:20 +00:00
Harald Anlauf
95f012ef4a Fortran testsuite: fix invalid Fortran in testcase
gcc/testsuite/ChangeLog:

	* gfortran.dg/pr101026.f: Let variables used in specification
	expression be passed as dummy arguments
2024-02-28 19:19:14 +01:00
Jonathan Wakely
80c386cb20 libstdc++: Fix noexcept on dtors in <experimental/scope> [PR114152]
The PR points out that the destructors all have incorrect
noexcept-specifiers.

libstdc++-v3/ChangeLog:

	PR libstdc++/114152
	* include/experimental/scope (scope_exit scope_fail): Make
	destructor unconditionally noexcept.
	(scope_sucess): Fix noexcept-specifier.
	* testsuite/experimental/scopeguard/114152.cc: New test.
2024-02-28 14:50:13 +00:00
Jonathan Wakely
06866bc368 libstdc++: Change some URLs in the manual to use https
libstdc++-v3/ChangeLog:

	* doc/xml/manual/appendix_contributing.xml: Change URLs to use
	https.
	* doc/html/manual/*: Regenerate.
2024-02-28 14:37:12 +00:00
Jonathan Wakely
7c7c937b5e libstdc++: Update outdated docs on contributing
We don't want a separate ChangeLog submission now.

libstdc++-v3/ChangeLog:

	* doc/xml/manual/appendix_contributing.xml: Replace outdated
	info on ChangeLog entries.
	* doc/html/manual/appendix_contributing.html: Regenerate.
2024-02-28 14:32:38 +00:00
Richard Biener
5c01ede02a tree-optimization/113831 - revert original fix
This reverts the original fix for PR113831 which is better fixed by
the PR114121 fix.  I've XFAILed instead of removing the PR108355
testcase again.

	PR tree-optimization/113831
	PR tree-optimization/108355
	* tree-ssa-sccvn.cc (copy_reference_ops_from_ref): Revert
	PR113831 fix.

	* gcc.dg/tree-ssa/ssa-fre-104.c: XFAIL.
2024-02-28 15:03:17 +01:00
Richard Biener
c841144a94 tree-optimization/114121 - wrong VN with context sensitive range info
When VN ends up exploiting range-info specifying the ao_ref offset
and max_size we have to make sure to reflect this in the hashtable
entry for the recorded expression.  The PR113831 fix handled the
case where we can encode this in the operands themselves but this
bug shows the issue is more widespread.

So instead of altering the operands the following instead records
this extra info that's possibly used, only throwing it away when
the value-numbering didn't come up with a non-VARYING value which
is an important detail to preserve CSE as opposed to constant
folding which is where all cases currently known popped up.

With this the original PR113831 fix can be reverted.

	PR tree-optimization/114121
	* tree-ssa-sccvn.h (vn_reference_s::offset,
	vn_reference_s::max_size): New fields.
	(vn_reference_insert_pieces): Adjust prototype.
	* tree-ssa-pre.cc (phi_translate_1): Preserve offset/max_size.
	* tree-ssa-sccvn.cc (vn_reference_eq): Compare offset and
	size, allow using "don't know" state.
	(vn_walk_cb_data::finish): Pass along offset/max_size.
	(vn_reference_lookup_or_insert_for_pieces): Take offset and
	max_size as argument and use it.
	(vn_reference_lookup_3): Properly adjust offset and max_size
	according to the adjusted ao_ref.
	(vn_reference_lookup_pieces): Initialize offset and max_size.
	(vn_reference_lookup): Likewise.
	(vn_reference_lookup_call): Likewise.
	(vn_reference_insert): Likewise.
	(visit_reference_op_call): Likewise.
	(vn_reference_insert_pieces): Take offset and max_size
	as argument and use it.

	* gcc.dg/torture/pr114121.c: New testcase.
2024-02-28 15:03:17 +01:00
Jonathan Wakely
2d8cd712b1 libstdc++: Add more nodiscard uses in <vector>
Add [[nodiscard]] to vector::at and to comparison operators.

libstdc++-v3/ChangeLog:

	* include/bits/stl_bvector.h (vector<bool, A>::at): Add
	nodiscard.
	* include/bits/stl_vector.h (vector<T, A>::at): Likewise.
	(operator==, operator<=>, operator<, operator!=, operator>)
	(operator<=, operator>=): Likewise.
	* include/debug/vector (operator==, operator<=>, operator<)
	(operator!=, operator>, operator<=, operator>=): Likewise.
	* testsuite/23_containers/vector/nodiscard.cc: New test.
2024-02-28 11:27:46 +00:00
Jonathan Wakely
cf918498ab libstdc++: Consistently use noexcept, constexpr, nodiscard on bitmask ops
The bitwise operators for combining bitmask types such as std::launch
are not consistently annotated with noexcept, constexpr, and nodiscard.

This is the subject of LWG 3977, although the proposed resolution
doesn't work. We can make the changes in libstdc++ anyway though.

libstdc++-v3/ChangeLog:

	* include/bits/atomic_base.h (operator|, operator&): Add
	noexcept.
	* include/bits/fs_fwd.h (operator&, operator|, operator^)
	(operator~): Add nodiscard to overloads for copy_options, perms,
	perm_options, and directory_options.
	* include/bits/ios_base.h (operator&, operator|, operator^)
	(operator~): Add nodiscard and noexcept to overloads for
	_Ios_Fmtflags, _Ios_Openmode, and _Ios_Iostate.
	(operator|=, operator&=, operator^=): Add constexpr for C++14.
	* include/bits/regex_constants.h (operator&, operator|, operator^)
	(operator~): Add nodiscard and noexcept to overloads for
	syntax_option_type and match_flag_type.
	(operator|=, operator&=, operator^=): Add noexcept.
	* include/std/charconv (operator&, operator|, operator^)
	(operator~): Add nodiscard to overloads for chars_format.
	* include/std/future (operator&, operator|, operator^)
	(operator~): Add nodiscard for overloads for launch.
	(operator&=, operator|=, operator^=): Add constexpr for C++14.
	* include/experimental/bits/fs_fwd.h  (operator&, operator|)
	(operator^, operator~): Add nodiscard to overloads for
	copy_options, perms, and directory_options.
	* testsuite/27_io/ios_base/types/fmtflags/bitmask_operators.cc:
	Add dg-warning for nodiscard warnings.
	* testsuite/27_io/ios_base/types/iostate/bitmask_operators.cc:
	Likewise.
	* testsuite/27_io/ios_base/types/openmode/bitmask_operators.cc:
	Likewise.
	* testsuite/27_io/filesystem/operations/bitmask_types.cc:
	New test.
2024-02-28 11:27:46 +00:00
Jonathan Wakely
5c22de3fec libstdc++: Test error handling in std::print
The standard requires an exception if std::print fails to write to a
FILE*. When writing to a std::ostream, failure to format the arguments
doesn't affect the stream state, but failure to write to the streadm
sets badbit.

libstdc++-v3/ChangeLog:

	* testsuite/27_io/basic_ostream/print/1.cc: Check error
	handling.
	* testsuite/27_io/print/1.cc: Likewise.
2024-02-28 11:27:46 +00:00
Jonathan Wakely
4da67f63b9 libstdc++: Fix std::print for Cygwin
Cygwin should use std::fwrite, not WriteConsoleW. And the -lstdc++exp
library is only needed when running the tests on *-*-mingw*.

libstdc++-v3/ChangeLog:

	* include/std/ostream (vprint_unicode) [__CYGWIN__]: Use POSIX
	code path for Cygwin instead of Windows.
	* include/std/print (vprint_unicode) [__CYGWIN__]: Likewise.
	* testsuite/27_io/basic_ostream/print/1.cc: Only add -lstdc++exp
	for *-*-mingw* targets.
	* testsuite/27_io/print/1.cc: Likewise.
2024-02-28 11:27:46 +00:00
Jonathan Wakely
3c1e624a92 libstdc++: Include <bits/stl_iterator.h> in <bits/alloc_traits.h>
libstdc++-v3/ChangeLog:

	* include/bits/alloc_traits.h: Include <bits/stl_iterator.h> for
	__make_move_if_noexcept_iterator.
2024-02-28 11:27:46 +00:00
Jonathan Wakely
d59175ef8a libstdc++: Add more [[nodiscard]] to <stacktrace>
libstdc++-v3/ChangeLog:

	* include/std/stacktrace: Add nodiscard attribute to all
	functions without side effects.
2024-02-28 11:27:45 +00:00
Jakub Jelinek
92f07eb406 testsuite: XFAIL ssa-sink-18.c also on powerpc64 [PR111462]
powerpc64-linux apparently (not very surprisingly) behaves the same
way as powerpc64le-linux and has 4 sunk statements rather than 5,
so we should xfail it on powerpc64*-*-* rather than just powerpc64le-*-*.
powerpc-linux has 3 sunk statements, but the scan pattern is done for
lp64 only as the comment explains.

2024-02-28  Jakub Jelinek  <jakub@redhat.com>

	PR testsuite/111462
	* gcc.dg/tree-ssa/ssa-sink-18.c: XFAIL also on powerpc64.
2024-02-28 12:11:54 +01:00
Rainer Orth
6864a2aa78 testsuite: Fix gcc.dg/tree-ssa/builtin-snprintf-6.c XPASS on i?86 -m64 [PR91567]
gcc.dg/tree-ssa/builtin-snprintf-6.c currently XPASSes on i?86-*-*
configurations with -m64:

XPASS: gcc.dg/tree-ssa/builtin-snprintf-6.c scan-tree-dump-times optimized "Function test_assign_aggregate" 1

(seen e.g. on i386-pc-solaris2.11, i686-pc-linux-gnu, or i386-apple-darwin*).

The problem is that the xfail only handles x86_64, ignoring that i?86
configurations can also be multilibbed.

This patch fixes the by handling both forms alike.

Tested on i386-pc-solaris2.11, amd64-pc-solaris2.11,
sparc-sun-solaris2.11, and sparcv9-sun-solaris2.11.

2024-02-28  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

	gcc/testsuite:
	PR tree-optimization/91567
	* gcc.dg/tree-ssa/builtin-snprintf-6.c (scan-tree-dump-times):
	Treat i?86-*-* like x86_64-*-*.
2024-02-28 11:55:47 +01:00
Jakub Jelinek
db465230cc testsuite: Add testcase for recently fixed PR [PR114075]
This adds testcase from PR114075 which has been fixed by the r14-9205
change on s390x-linux with -march=z13.

2024-02-28  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/114075
	* gcc.dg/gomp/pr114075.c: New test.
2024-02-28 11:49:29 +01:00
Juergen Christ
82ebfd35da Only emulate integral vectors.
The emulation via word mode tries to perform integer arithmetic on floating
point values instead of floating point arithmetic.  This leads to
mis-compilations.

Failure occured on s390x on these existing test cases:
gcc.dg/vect/tsvc/vect-tsvc-s112.c
gcc.dg/vect/tsvc/vect-tsvc-s113.c
gcc.dg/vect/tsvc/vect-tsvc-s119.c
gcc.dg/vect/tsvc/vect-tsvc-s121.c
gcc.dg/vect/tsvc/vect-tsvc-s131.c
gcc.dg/vect/tsvc/vect-tsvc-s132.c
gcc.dg/vect/tsvc/vect-tsvc-s2233.c
gcc.dg/vect/tsvc/vect-tsvc-s421.c
gcc.dg/vect/vect-alias-check-14.c
gcc.target/s390/vector/partial/s390-vec-length-epil-run-1.c
gcc.target/s390/vector/partial/s390-vec-length-epil-run-3.c
gcc.target/s390/vector/partial/s390-vec-length-full-run-3.c

gcc/ChangeLog:

	PR tree-optimization/114075

	* tree-vect-stmts.cc (vectorizable_operation): Don't emulate floating
	point vectors

Signed-off-by: Juergen Christ <jchrist@linux.ibm.com>
2024-02-28 11:17:30 +01:00
Jakub Jelinek
d6479050ec graphite: Fix non-INTEGER_TYPE integral comparison handling [PR114041]
The following testcases are miscompiled, because graphite ignores boolean,
enumerated or _BitInt comparisons, rewrites the code as if the comparisons
were always true or always false.

The INTEGER_TYPE checks were initially added in r6-2239 but at that point
it was both in add_conditions_to_domain and in parameter_index_in_region.
Later on the check was also added to stmt_simple_for_scop_p, and finally
r8-3931 changed the stmt_simple_for_scop_p check to INTEGRAL_TYPE_P
and turned the parameter_index_in_region -> assign_parameter_index_in_region
into INTEGRAL_TYPE_P assertion, but the add_conditions_to_domain check
for INTEGER_TYPE remained.

The following patch uses INTEGRAL_TYPE_P to complete the change.

2024-02-28  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/114041
	* graphite-sese-to-poly.cc (add_conditions_to_domain): Check for
	INTEGRAL_TYPE_P check rather than INTEGER_TYPE.

	* gcc.dg/graphite/run-id-pr114041-1.c: New test.
	* gcc.dg/graphite/run-id-pr114041-2.c: New test.
2024-02-28 09:59:45 +01:00
Jakub Jelinek
cc383e9702 gimple-fold: Use bitwise vector types rather than barely supported huge integral types in memcpy etc. folding [PR113988]
The following patch changes the memcpy etc. folding to use bitwise vector
types rather  than huge INTEGER_TYPEs for copying of > MAX_FIXED_MODE_SIZE
lengths.  The problem with the huge INTEGER_TYPEs is that they aren't
supported very much, usually there are just optabs to handle moves of them,
perhaps misaligned moves and that is it, so they pose problems e.g. to
BITINT_TYPE lowering.

2024-02-28  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/113988
	* stor-layout.h (bitwise_mode_for_size): Declare.
	* stor-layout.cc (bitwise_mode_for_size): New function.
	* gimple-fold.cc (gimple_fold_builtin_memory_op): Use it.
	Use bitwise_type_for_mode instead of build_nonstandard_integer_type.
	Use BITS_PER_UNIT instead of 8.

	* gcc.dg/bitint-91.c: New test.
2024-02-28 09:40:15 +01:00
Jakub Jelinek
dc30e24b76 testsuite: Add c23-stdarg-4.c test variant where all functions return large struct
I think we have no coverage for the case where structure_value_addr_parm and
TYPE_NO_NAMED_ARGS_STDARG_P are both true.  The
  if (type_arg_types != 0)
    n_named_args
      = (list_length (type_arg_types)
         /* Count the struct value address, if it is passed as a parm.  */
         + structure_value_addr_parm);
  else if (TYPE_NO_NAMED_ARGS_STDARG_P (funtype))
    n_named_args = 0;
  else
    /* If we know nothing, treat all args as named.  */
    n_named_args = num_actuals;
code should probably have n_named_args = structure_value_addr_parm;
instead of n_named_args = 0;, this testcase is an attempt to see if
it is broken on any target.

2024-02-28  Jakub Jelinek  <jakub@redhat.com>

	* gcc.dg/c23-stdarg-6.c: New test.
2024-02-28 09:26:51 +01:00
Nathaniel Shead
615b62aada c++: Revert deferring emission of inline variables [PR114013]
This is a (partial) reversion of r14-8987-gdd9d14f7d53 to return to
eagerly emitting inline variables to the middle-end when they are
declared. 'import_export_decl' will still continue to accept them, as
allowing this is a pure extension and doesn't seem to cause issues with
modules, but otherwise deferring the emission of inline variables
appears to cause issues on some targets and prevents some code using
inline variable templates from correctly linking.

There might be a more targetted way to support this, but due to the
complexity of handling linkage and emission I'd prefer to wait till
GCC 15 to explore our options.

	PR c++/113970
	PR c++/114013

gcc/cp/ChangeLog:

	* decl.cc (make_rtl_for_nonlocal_decl): Don't defer inline
	variables.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp1z/inline-var10.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
2024-02-28 11:25:21 +11:00
GCC Administrator
6309ad25c6 Daily bump. 2024-02-28 00:16:42 +00:00
David Malcolm
939439a90f analyzer: use correct format code for string literal indices [PR110483,PR111802]
On e.g. gcc211 the use of "%li" with unsigned HOST_WIDE_INT led to this warning:
../../src/gcc/analyzer/access-diagram.cc: In member function ‘void ana::string_literal_spatial_item::add_column_for_byte(text_art::table&, const ana::bit_to_table_map&, text_art::style_manager&, ana::byte_offset_t, ana::byte_offset_t, int, int) const’:
../../src/gcc/analyzer/access-diagram.cc:1909:40: warning: format ‘%li’ expects argument of type ‘long int’, but argument 3 has type ‘long long unsigned int’ [-Wformat=]
          byte_idx_within_string.ulow ()));
                                        ^
and to all values being erroneously printed as "0".

Fixed thusly.

gcc/analyzer/ChangeLog:
	PR analyzer/110483
	PR analyzer/111802
	* access-diagram.cc
	(string_literal_spatial_item::add_column_for_byte): Use %wu for
	printing unsigned HOST_WIDE_INT.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2024-02-27 17:17:12 -05:00
Uros Bizjak
15d1dae0d4 i386: psrlq is not used for PERM<a,{0},1,2,3,4> [PR113871]
Also handle V2BF mode.

	PR target/113871

gcc/ChangeLog:

	* config/i386/mmx.md (V248FI): Add V2BF mode.
	(V24FI_32): Ditto.

gcc/testsuite/ChangeLog:

	* gcc.target/i386/pr113871-5a.c: New test.
	* gcc.target/i386/pr113871-5b.c: New test.
2024-02-27 18:41:24 +01:00
Eric Botcazou
27534e793e Fix internal error on non-byte-aligned reference in GIMPLE DSE
This is a regression present on the mainline, 13 and 12 branches.  For the
attached Ada case, it's a tree checking failure on the mainline at -O:

+===========================GNAT BUG DETECTED==============================+
| 14.0.1 20240226 (experimental) [master r14-9171-g4972f97a265]  GCC error:|
| tree check: expected tree that contains 'decl common' structure,         |
| have 'component_ref' in tree_could_trap_p, at tree-eh.cc:2733        |
| Error detected around /home/eric/cvs/gcc/gcc/testsuite/gnat.dg/opt104.adb:

Time is a 10-byte record and Packed_Rec.T is placed at bit-offset 65 because
of the packing. so tree-ssa-dse.cc:setup_live_bytes_from_ref has computed a
const_size of 88 from ref->offset of 65 and ref->max_size of 80.

Then in tree-ssa-dse.cc:compute_trims:

411       int last_live = bitmap_last_set_bit (live);
(gdb) next
412       if (ref->size.is_constant (&const_size))
(gdb)
414           int last_orig = (const_size / BITS_PER_UNIT) - 1;
(gdb)
418           *trim_tail = last_orig - last_live;

(gdb) call debug_bitmap (live)
n_bits = 256, set = {0 1 2 3 4 5 6 7 8 9 10 }
(gdb) p last_live
$33 = 10
(gdb) p const_size
$34 = 80
(gdb) p last_orig
$35 = 9
(gdb) p *trim_tail
$36 = -1

In other words, compute_trims is overlooking the alignment adjustments that
setup_live_bytes_from_ref applied earlier.  Moveover it reads:

  /* We use sbitmaps biased such that ref->offset is bit zero and the bitmap
     extends through ref->size.  So we know that in the original bitmap
     bits 0..ref->size were true.  We don't actually need the bitmap, just
     the REF to compute the trims.  */

but setup_live_bytes_from_ref used ref->max_size instead of ref->size.

It appears that all the callers of compute_trims assume that ref->offset is
byte aligned and that the trimmed bytes are relative to ref->size, so the
patch simply adds an early return if either condition is not fulfilled.

gcc/
	* tree-ssa-dse.cc (compute_trims): Fix description.  Return early
	if either ref->offset is not byte aligned or ref->size is not known
	to be equal to ref->max_size.
	(maybe_trim_complex_store): Fix description.
	(maybe_trim_constructor_store): Likewise.
	(maybe_trim_partially_dead_store): Likewise.

gcc/testsuite/
	* gnat.dg/opt104.ads, gnat.dg/opt104.adb: New test.
2024-02-27 18:08:56 +01:00