Commit Graph

220975 Commits

Author SHA1 Message Date
Kugan Vivekanandarajah
79091220da [AutoFDO] Fix profile bootstrap for x86_64
This patch fixes profile bootstrap for x86_64 by special
caseing cpu_type for x86_64 as it shares AUTO_PROFILE
from i386.

ChangeLog:

	* configure.ac: Special case cpu_type for x86_64.
	* configure: Regenerate.

Signed-off-by: Kugan Vivekanandarajah <kvivekananda@nvidia.com>
2025-06-10 09:19:37 +10:00
Martin Uecker
ef62600244 c: Add remove_qualifier helper function [PR120510]
Add a helper function to replace repeated code for removing
qualifiers but not atomic.  Make sure to also remove qualifiers
but not atomic from the element type of arrays.

	PR c/120510

gcc/c/ChangeLog:
	* c-typeck.cc (remove_qualifiers): New function.
	(composite_type_internal): Use it.
	(comp_target_types): Use it.
	(type_lists_compatible_p): Use it.
	(find_anonymous_field_with_type): Use it.
	(convert_to_anonymous_field): Use it.
	(convert_for_assignment): Use it.
2025-06-10 01:14:25 +02:00
Martin Uecker
aea870e953 c: partial fix for qualifier inconsistency II [PR120510]
This fixes a case where we invoke composite_type with types
that do not have matching qualifiers.  With this change, we can
activate the checking assertion that makes sure the composite
type is compatible with the two original types also for arrays.

	PR c/120510

gcc/c/ChangeLog:
	* c-typeck.cc (composite_type_internal): Activate checking
	assertion for arrays.
	(common_pointer_type): Remove qualifiers also from arrays.
2025-06-10 01:14:24 +02:00
Martin Uecker
c1904cd27b c: partial fix for qualifier inconsistency [PR120510]
Checking assertions revealed that we sometimes produce
composite types with incorrect qualifiers, e.g. the example

int f(int [_Atomic]);
int f(int [_Atomic]);
int f(int [_Atomic]);

was rejected because atomic was lost in the second declaration.

	PR c/120510

gcc/c/ChangeLog:
	* c-typeck.cc (composite_types_internal): Handle arrays
	declared with atomic for function arguments.

gcc/testsuite/ChangeLog:
	* gcc.dg/pr120510.c
2025-06-10 01:14:17 +02:00
Iain Sandoe
cf588f1a8e 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>
2025-06-09 23:08:04 +01:00
Peter Bergner
e825ec7fcd MAINTAINERS: Update my email address
2025-06-09  Peter Bergner  <bergner@tenstorrent.com>

	* MAINTAINERS: Update my email address and add myself to DCO.

Signed-off-by: Peter Bergner <bergner@tenstorrent.com>
2025-06-09 16:03:34 -05:00
David Malcolm
bf0c6e1d34 diagnostics: convert enum logical_location_kind to enum class
No functional change intended.

gcc/ChangeLog:
	* diagnostic-format-sarif.cc (maybe_get_sarif_kind): Update for
	conversion of enum logical_location_kind to enum class.
	* diagnostic.cc (logical_location_manager::function_p): Likewise.
	* libgdiagnostics.cc (html-output/missing-semicolon.py::get_kind):
	Likewise.
	* logical-location.h (enum logical_location_kind): Convert to...
	(enum class logical_location_kind): ...this.
	* selftest-logical-location.cc
	(test_logical_location_manager::item_from_funcname): Update for
	conversion of enum logical_location_kind to enum class.
	* tree-logical-location.cc
	(tree_logical_location_manager::get_kind): Likewise.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-06-09 14:15:25 -04:00
Gaius Mulley
639a147414 PR modula2/120606: FOR loop ICE if the last expression uses an array
This patch fixes the ICE which occurs if the last expression is an array.
It ensures that the start and end values of the for loop expressions are
dereferenced.

gcc/m2/ChangeLog:

	PR modula2/120606
	* gm2-compiler/M2Quads.mod (ForLoopLastIterator): Dereference
	start and end expressions e1 and e2 respectively.

gcc/testsuite/ChangeLog:

	PR modula2/120606
	* gm2/pim/pass/forarray.mod: New test.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
2025-06-09 18:26:36 +01:00
Jan Hubicka
b0d50cbb42 Fix profile updating in ipa-cp
Bootstrapping with autoprofiledbootstrap, LTO and checking enables ICEs in WPA
because we end up mixing local and IPA count in
ipa-cp.cc:update_specialized_profile.  This is because of missing call to
profile_count::adjust_for_ipa_scaling.  While looking into that I however
noticed that the function forgets to update indirect call edges. This made me
to commonize same logic which currently exists in clone_inlined_nodes,
update_specialized_profile, update_profiling_info and
update_counts_for_self_gen_clones.

While testing it I noticed that we also ICE when linking with
-fdump-ipa-all-details-blocks since IPA and local counts are temporarily mixed
during IPA transformation stage, so I also added check to profile_count::dump
to not crash and added verifier to gimple_verify_flow_info.

Other problem I also noticed is that while profile updates done by inliner (via
cgraph_node::clone) are correctly using global0 profiles instead of erasing
profile completely when IPA counts drops to 0, the scaling in ipa-cp is not
doing that, so we lose info and possibly some code quality.  I will fix that
incrementally. Similarly ipa-split, when offlining region with 0 entry count
may re-do frequency propagation to get something useful.

gcc/ChangeLog:

	* cgraph.cc (cgraph_node::apply_scale): New member function.
	* cgraph.h (struct cgraph_node): declare.
	* ipa-cp.cc (update_counts_for_self_gen_clones):
	Use cgraph_node::apply_scale.
	(update_profiling_info): Do not overwrite local
	profile when dropping to 0 global profile.
	(update_specialized_profile): Likewise.
	* ipa-inline-transform.cc (update_noncloned_counts): Remove.
	(can_remove_node_now_p_1): Fix formating.
	(clone_inlined_nodes): Use cgraph_node::apply_scale.
	* profile-count.cc (profile_count::dump): Do not ICE
	when count is not compatible with entry block count.
	* tree-cfg.cc (gimple_verify_flow_info): Check
	compatibility of count and entry block count.
2025-06-09 16:47:54 +02:00
Gaius Mulley
0adb415d12 PR modula2/119779: ASM examples no longer work
This patch introduces a regression test using the example in the
documentation and tests it using -masm=intel on x86_64-*-gnu systems.

gcc/testsuite/ChangeLog:

	PR modula2/119779
	* gm2.dg/doc/examples/run/pass/doc-examples-run-pass.exp: New test.
	* gm2.dg/doc/examples/run/pass/exampleadd2.mod: New test.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
2025-06-09 15:26:35 +01:00
David Malcolm
82de4cada8 diagnostics: fix <title> of experimental-html output [PR116792]
Add a new vfunc diagnostic_output_format::set_main_input_filename
so that we can separate setting the <title> of HTML output and
the diagnostic_artifact_role::analysis_target of SARIF output from
creation of the sinks.  Calling it is done by the various creators
of the sinks.

gcc/ChangeLog:
	PR other/116792
	* diagnostic-format-html.cc (html_builder::m_title_element): New
	field.
	(html_builder::html_builder): Initialize it.  Don't add
	placeholder text.
	(html_builder::set_main_input_filename): New.
	(html_output_format::set_main_input_filename): New.
	(test_html_diagnostic_context::test_html_diagnostic_context): Call
	set_main_input_filename on the new sink.
	(seldtest::test_simple_log): Update expected <title> text.
	* diagnostic-format-json.cc (diagnostic_output_format_init_json):
	Return a reference to the new sink.
	(diagnostic_output_format_init_json_stderr): Likewise.
	(diagnostic_output_format_init_json_file): Likewise.
	* diagnostic-format-sarif.cc (sarif_builder::sarif_builder): Drop
	"main_input_filename_" param, and move adding an artifact for it
	with diagnostic_artifact_role::analysis_target to...
	(sarif_builder::set_main_input_filename): ...this new function.
	(sarif_output_format::set_main_input_filename): New.
	(sarif_output_format::sarif_output_format): Drop
	"main_input_filename_" param.
	(sarif_stream_output_format::sarif_stream_output_format):
	Likewise.
	(sarif_file_output_format::sarif_file_output_format): Likewise.
	(diagnostic_output_format_init_sarif): Return a reference to *FMT.
	(diagnostic_output_format_init_sarif_stderr): Return a refererence
	to the new sink.  Drop "main_input_filename_" param.
	(diagnostic_output_format_init_sarif_file): Likewise.
	(diagnostic_output_format_init_sarif_stream): Likewise.
	(make_sarif_sink): Drop "main_input_filename_" param.
	(selftest::test_sarif_diagnostic_context::test_sarif_diagnostic_context):
	Likewise.  Call set_main_input_filename on the new format.
	(selftest::test_sarif_diagnostic_context::buffered_output_format::buffered_output_format):
	Drop "main_input_filename_" param.
	(selftest::test_make_location_object): Likewise.
	* diagnostic-format-sarif.h
	(diagnostic_output_format_init_sarif_stderr): Return a refererence
	to the new sink.  Drop "main_input_filename_" param.
	(diagnostic_output_format_init_sarif_file): Likewise.
	(diagnostic_output_format_init_sarif_stream): Likewise.
	(make_sarif_sink): Drop "main_input_filename_" param.
	* diagnostic-format.h
	(diagnostic_output_format::set_main_input_filename): New vfunc.
	(diagnostic_output_format_init_json_stderr): Return a refererence
	to the new sink.
	(diagnostic_output_format_init_json_file): Likewise.
	* diagnostic.cc (diagnostic_output_format_init): Likewise.  Call
	set_main_input_filename on the new sink.
	* libgdiagnostics.cc (sarif_sink::sarif_sink): Update for above
	changes.
	* opts-diagnostic.cc (sarif_scheme_handler::make_sink): Likewise.
	(handle_OPT_fdiagnostics_add_output_): Likewise.
	(handle_OPT_fdiagnostics_set_output_): Likewise.

gcc/testsuite/ChangeLog:
	PR other/116792
	* gcc.dg/html-output/missing-semicolon.py: Update expected <title>
	text.  Drop out-of-date comment.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-06-09 09:43:11 -04:00
Jeff Law
af3de9e209 [RISC-V] Enable more if-conversion on RISC-V
Another czero related adjustment.  This time in costing of conditional move
sequences.  Essentially a copy from a promoted subreg can and should be ignored
from a costing standpoint.  We had some code to do this, but its conditions
were too strict.

No real surprises evaluating spec.  This should be a minor, but probably not
measurable improvement in x264 and xz.   It is if-converting more in some
particular harm to hot routines, but not necessarily in the hot parts of those
routines.

It's been tested on riscv32-elf and riscv64-elf.  Versions of this have
bootstrapped and regression tested as well, though perhaps not this exact
version.

Waiting on pre-commit testing.

gcc/
	* config/riscv/riscv.cc (riscv_noce_conversion_profitable_p): Relax
	condition for adjustments due to copies from promoted SUBREGs.
2025-06-09 06:56:10 -06:00
Alfie Richards
ef938108b8 powerpc: testsuite: Fix powerpc FMV symbol tests [PR 120519]
As discussed on the BZ page, this removes the overly specific resolver tests
which proved overly specific, and modifies the jump instructions.

gcc/testsuite/ChangeLog:

	PR testsuite/120519
	* g++.target/powerpc/mvc-symbols1.C: Modify tests.
	* g++.target/powerpc/mvc-symbols2.C: Ditto.
	* g++.target/powerpc/mvc-symbols3.C: Ditto.
	* g++.target/powerpc/mvc-symbols4.C: Ditto.
2025-06-09 10:35:44 +00:00
Gary Dismukes
4e96f7fc8e ada: Support fixed-lower-bound array types as generic actual parameters
Attempting to use a fixed-lower-bound array type (or subtype) as
an actual parameter for a formal unconstrained array type was being
rejected by the compiler (complaining about the index type of the
actual not matching the index type of the formal type).  The compiler
was improperly testing the actual's FLB range and finding that it didn't
statically match the index type of the formal array type; it should
instead test the underlying index type of the FLB type or subtype.

gcc/ada/ChangeLog:

	* sem_ch3.adb (Constrain_Index): In the case of a fixed-lower-bound index,
	set Etype of the newly created itype's Scalar_Range from the index's Etype.
	* sem_ch12.adb (Validate_Array_Type_Instance): If the actual subtype is
	a fixed-lower-bound type, then check again the Etype of its Scalar_Range.
2025-06-09 08:32:14 +02:00
Piotr Trojanek
4631b74b97 ada: Reject component-related aspects on formal non-array types
In Ada 2022 aspects Atomic_Components and Volatile_Components can be specified
for a formal array type, but they were wrongly accepted on any formal type.

Also, we don't need to check if the corresponding pragmas appear in Ada 2022
mode, because generic formal parameters can't have explicit representation
pragmas in any Ada version and can only have aspects since Ada 2022.

gcc/ada/ChangeLog:

	* sem_prag.adb (Analyze_Pragma): Fix conditions for legality checks on
	formal type declarations.
2025-06-09 08:32:14 +02:00
Piotr Trojanek
eedc248542 ada: Fix glitch in handling of Atomic_Components on generic formal type
In Ada 2022 aspects Atomic_Components and Volatile_Components can be specified
for a formal array type, but then they need to be set on the base type entity.
Otherwise we get an assertion failure in debug build and wrong legality errors
in production builds.

gcc/ada/ChangeLog:

	* sem_prag.adb (Analyze_Pragma): If pragmas apply to a formal array
	type, then set the flags on the base type.
2025-06-09 08:32:13 +02:00
Ronan Desplanques
3280bce431 ada: Clarify code in Process_Subtype
This patch factorizes two if statements together in the body of
Process_Subtype, to improve readability.

gcc/ada/ChangeLog:

	* sem_ch3.adb (Process_Subtype): Clarify code.
2025-06-09 08:32:13 +02:00
Ronan Desplanques
83578594c5 ada: Add null exclusion formal to Process_Subtype
Before this patch, Process_Subtype looked at the parent of its argument
to determine whether it was called in a context that excluded null. This
patch replaces this lookup with a new formal parameter to
Process_Subtype, and updates the calls to it accordingly.

gcc/ada/ChangeLog:

	* sem_ch3.ads (Process_Subtype): Add formal.
	* sem_ch3.adb (Process_Subtype): Use new formal.
	(Analyze_Subtype_Declaration, Array_Type_Declaration,
	Build_Derived_Access_Type): Pass new actual.
	* sem_ch4.adb (Find_Type_Of_Object): Likewise.
2025-06-09 08:32:13 +02:00
Ronan Desplanques
51e01fb40a ada: Call Mutate_Ekind earlier for formal entities
This patch migrates the handling of "premature usage" type of error to
the Is_Self_Hidden mechanism.

gcc/ada/ChangeLog:

	* sem_ch6.adb (Set_Formal_Mode): Extend profile. Move parts of the
	body…
	(Process_Formals): … here. Move call to Set_Formal_Mode earlier. Call
	Set_Is_Not_Self_Hidden in second traversal.
2025-06-09 08:32:12 +02:00
Gary Dismukes
ff89e55497 ada: Missing discriminant check on assignment of Bounded_Vector aggregate
When a container aggregate for a Bounded_Vector type involves an iterated
association that is assigned to a vector object whose capacity (as defined
by the Capacity discriminant) is less than the number of elements of the
aggregate, Constraint_Error should be raised due to failing a discriminant
check on the assignment. But the compiler fails to do proper expansion,
plus omits the check, and instead creates a temporary whose capacity is
bounded by that of the target vector of the assignment. It attempts to
assign all elements of the aggregate to the temporary, resulting in
a failure on a call to the Replace_Element operation that assigns past
the length of the temporary vector (which can result in a Storage_Error
due to a segment violation).

This is fixed by ensuring that the temporary object is declared with
an unconstrained base subtype rather than the assignment target's
constrained subtype.

gcc/ada/ChangeLog:

	* exp_aggr.adb (Expand_Container_Aggregate): Use the Base_Type of the
	subtype provided by the context as the subtype of the temporary object
	initialized by the aggregate.
2025-06-09 08:32:12 +02:00
Eric Botcazou
7e94851346 ada: Remove duplicated code in parser for Chapter 4 (continued)
P_Qualified_Simple_Name and P_Function_Name contain essentially the same
code, except that P_Function_Name does not error out on an operator symbol
that is followed by something else than a dot.

This deletes P_Function_Name and changes P_Qualified_Simple_Name[_Resync]
to not error out either in this case, with the only consequence that the
error message given for:

  generic
    type T is private;
  function "&" (A, B : String) return String;

  procedure Proc is new "&" (Integer);

is now identical to the one given for:

  generic
    type T is private;
  function "&" (A, B : String) return String;

  function Func is new "&" (Integer);

namely:

q.ads:7:12: error: operator symbol not allowed for generic subprogram

gcc/ada/ChangeLog:

	* par-ch4.adb (P_Function_Name): Delete body.
	(P_Qualified_Simple_Name_Resync): Do not raise Error_Resync on an
	operator symbol followed by something else than a dot.
	* par-ch6.adb (P_Subprogram): Do not call P_Function_Name.
	* par.adb (P_Function_Name): Delete declaration.
2025-06-09 08:32:12 +02:00
Ronan Desplanques
025f6caa60 ada: Set Ekind of components earlier
Before this patch, the calls to set the proper Ekind of component
entities were delayed in order to catch "premature usage" type of
errors. This patch moves those calls to the natural place, at the
beginning of Analyze_Component_Declaration, and makes premature usage
error dectection use the newer Is_Self_Hidden mechanism.

The motivation for this patch is to accomodate future removals of
operations on E_Void entities.

gcc/ada/ChangeLog:

	* sem.adb (Analyze): Adapt to new Ekinds.
	* sem_ch3.adb (Analyze_Component_Declaration): Set Ekind early.
	(Is_Visible_Component, Record_Type_Definition): Adjust.
2025-06-09 08:32:11 +02:00
Ronan Desplanques
aaac06d086 ada: Fix comment
gcc/ada/ChangeLog:

	* sem.adb (Analyze): Fix comment.
2025-06-09 08:32:11 +02:00
Eric Botcazou
5ed1891054 ada: Remove duplicated code in parser for Chapter 4
P_Qualified_Simple_Name and P_Qualified_Simple_Name_Resync contain exactly
the same code, so this change makes the former call the latter.

gcc/ada/ChangeLog:

	* par-ch4.adb (P_Name): Remove obsolete references in comments.
	(P_Qualified_Simple_Name): Call P_Qualified_Simple_Name_Resync.
	(P_Qualified_Simple_Name_Resync): Adjust a couple of comments.
2025-06-09 08:32:11 +02:00
Gary Dismukes
bb9cd860cb ada: Fix SPARK test failures caused by new handling of inherited class-wide pre/post
The revised handling of inherited class-wide pre/postconditions (for
properly implementing the rules of RM 6.1.1(7/5)) broke two SPARK tests
(N709-001__contracts and V516-041__private_ownership). This change fixes
that, by refining the test for detecting formal parameters used as actuals
in calls to primitive functions, as well as adding handling for 'Result
attributes given as actuals in such calls.

gcc/ada/ChangeLog:

	* exp_util.adb (Call_To_Parent_Dispatching_Op_Must_Be_Mapped): Replace
	test of Covers with test of Is_Controlling_Formal. Add handling for
	'Result actuals. Remove Actual_Type and its uses.
2025-06-09 08:32:10 +02:00
Piotr Trojanek
0ab32e590f ada: Simplify handling of selected components as name references
The selector_name of a selected_component always points to an identifier than
is an object name, i.e. specifically, name of a component or discriminant.
There is no need to examine this.

Code cleanup; behavior is unaffected.

gcc/ada/ChangeLog:

	* sem_util.adb (Is_Name_Reference): Remove check for selector_name of a
	selected_component; reuse existing code for indexed components and
	slices.
	(Statically_Names_Object): Remove dead code.
2025-06-09 08:32:10 +02:00
Eric Botcazou
4413a63126 ada: Restrict Overlays_Constant flag to selected entities
Namely E_Constant and E_Variable entities.

gcc/ada/ChangeLog:

	* einfo.ads (Overlays_Constant): Define in constants and variables.
	* gen_il-gen-gen_entities.adb (Entity_Kind): Move Overlays_Constant
	semantic flag to...
	(Constant_Or_Variable_Kind): ...here.
	* sem_util.adb (Note_Possible_Modification): Add guard.
2025-06-09 08:32:10 +02:00
Bob Duff
027457ded6 ada: Back out removal of renaming tranformation
A previous change (commit 33eebd96d27fa2b29cec79f55167a11aaf7f4802)
removed code in Analyze_Object_Renaming that tranformed renamings
into object declarations. This reinstates that code.

Removing the code causes failures in
gnatbugs-large/2023/gnat-435_deep_blue_capital.
Ideally, we SHOULD remove that transformation at some point,
but that will require further changes.

gcc/ada/ChangeLog:

	* exp_ch6.adb: (Make_Build_In_Place_Call_In_Object_Declaration):
	Deal with renamings transformed into object declarations.
	* sem_ch8.adb (Analyze_Object_Renaming):
	Reinstate transformation of a renaming into
	an object declaration.
2025-06-09 08:32:09 +02:00
Ronan Desplanques
af68e74167 ada: Set Ekind early in object declarations
Setting the proper Ekind on object entities was once needed to catch
cases of premature usages. The introduction of Is_Self_Hidden changed
that, so this patch replaces the Mutate_Ekind calls in the natural
place.

gcc/ada/ChangeLog:

	* sem_ch3.adb (Analyze_Object_Declaration): Call Mutate_Ekind earlier.
2025-06-09 08:32:09 +02:00
Ronan Desplanques
e9066cf788 ada: Tweak error recovery path
Before this patch, the constant mark of object declarations was stripped
in some error situations. This behavior is currently not useful so this
patch removes it.

gcc/ada/ChangeLog:

	* sem_ch3.adb (Analyze_Object_Declaration): Tweak error handling.
2025-06-09 08:32:09 +02:00
Piotr Trojanek
fd98d3b9b1 ada: Specialize syntax error on malformed Abstract_State contract
Syntax for the Abstract_State contract is the same as for extended aggregates,
but conceptually they are completely different. This patch specializes error
messages emitted on syntax errors for these constructs.

gcc/ada/ChangeLog:

	* par-ch13.adb (Get_Aspect_Specifications): Save and restore flag while
	parsing aspect Abstract_State.
	* par-ch2.adb (P_Pragma): Same while parsing pragma Abstract_State.
	* par-ch4.adb (P_Aggregate_Or_Paren_Expr): Specialize error message
	for contract Abstract_State and extended aggregate.
	* par.adb (Inside_Abstract_State): Add new context flag.
2025-06-09 08:32:08 +02:00
Ronan Desplanques
31b7b7518e ada: Do not build dispatch tables for generics
Before this patch, Build_Static_Dispatch_Tables was called on generic
package bodies. While this has not been proved to cause any actual bug,
it was clearly inappropriate and also useless, so this patch removes
those calls.

gcc/ada/ChangeLog:

	* sem_ch10.adb (Analyze_Compilation_Unit): Check for generic bodies.
	* exp_disp.adb (Build_Dispatch_Tables): Likewise.
2025-06-09 08:32:08 +02:00
Piotr Trojanek
7f31b28fe1 ada: Tune recent change for warning about unsupported overlays
Fix crash occurring when overlay applies to protected component and expansion
is disabled, e.g. because of semantic checking mode (switch -gnatc) or because
the compiler is running in GNATprove mode.

Also, simply pick the type of overlaid object from the attribute prefix itself.

gcc/ada/ChangeLog:

	* sem_util.adb (Find_Overlaid_Entity): Don't call Etype on empty Ent;
	tune style; move computation of Overl_Typ out of the loop.
2025-06-09 08:32:08 +02:00
Javier Miranda
108e346ced ada: Pragma Ada_XX not propagated from library level spec to body
Add documentation to pragmas Ada_83, Ada_95, Ada_05, Ada_12,
and Ada_2022: when placed before a library level package
specification they are not propagated to the corresponding
package body; they must be added explicitly to the package
body.

gcc/ada/ChangeLog:

	* doc/gnat_rm/implementation_defined_pragmas.rst: Adding
	documentation.
	* doc/gnat_ugn/the_gnat_compilation_model.rst: ditto.
	* gnat_rm.texi: Regenerate.
	* gnat_ugn.texi: Regenerate.
2025-06-09 08:32:07 +02:00
Ronan Desplanques
fefac68641 ada: Remove redundant error checking
This patch removes a test for a condition that can never be false.

gcc/ada/ChangeLog:

	* sem_attr.adb (Analyze_Attribute): Remove test.
2025-06-09 08:32:07 +02:00
Ronan Desplanques
6ad0d51d4e ada: Remove unnecessary special handling
This patch removes a special exemption in Enter_Name. That exemption was
preceded by a comment which described what situations it was supposed to
be required for, but it was unnecessary even in those situations.

gcc/ada/ChangeLog:

	* sem_util.adb (Enter_Name): Remove special handling.
2025-06-09 08:32:07 +02:00
Ronan Desplanques
ff9781d1dc ada: Remove misleading comment
This patch removes a comment that misleadingly presented a condition as
being met only in rare situations, while it's in fact satisfied in very
basic cases such as simple object declarations.

gcc/ada/ChangeLog:

	* sem_util.adb (Enter_Name): Remove comment.
2025-06-09 08:32:06 +02:00
Bob Duff
a23938b3a7 ada: Constraint check on tagged build-in-place object decls
In the case of "X : T := F (...);", where T is a constrained
discriminated tagged subtype, perform a constraint check
after F returns. The result of F is allocated by the callee
on the secondary stack in this case.
Note that there are still missing checks for some build-in-place
calls.

gcc/ada/ChangeLog:

	* exp_ch6.adb: Remove a couple of "???" suggesting something that
	we will likely never do.
	(Make_Build_In_Place_Call_In_Object_Declaration):
	When a constraint check is needed, do the check.
	Do it at the call site for now.
	The check is still missing in the untagged case,
	because the caller allocates in that case.
	* sem_ch8.adb (Analyze_Object_Renaming):
	Remove obsolete transformation of a renaming into
	an object declaration. Given that we also (sometimes) tranform
	object declarations into renamings, this transformation was
	adding complexity; the new code in
	Make_Build_In_Place_Call_In_Object_Declaration above
	would need to explicitly avoid the run-time check in the case of
	renamings, because renamings are supposed to ignore the nominal
	subtype. Anyway, it is no longer needed.
	* exp_ch3.adb (Expand_N_Object_Declaration): Rewrite comment;
	it IS clear how to do it, but we haven't done it right yet.
2025-06-09 08:32:06 +02:00
Ronan Desplanques
95da1ec42b ada: Remove incorrect bits in Copy_Node documentation
This patch removes a leftover reference to the concept of node extension
and a note about aspect specification that's been incorrect since at
least the latest rework of aspect specification representation.

gcc/ada/ChangeLog:

	* atree.ads (Copy_Node): Fix comment.
2025-06-09 08:32:06 +02:00
Piotr Trojanek
bba4596132 ada: Check validity using signedness from the type and not its base type
When attribute Valid is applied to a private type, we used the signedness of
its implementation base type which wrongly included negative values.

gcc/ada/ChangeLog:

	* exp_attr.adb (Expand_N_Attribute_Reference): When expanding attribute
	Valid, use signedness from the validated view, not from its base type.
2025-06-09 08:32:05 +02:00
Marc Poulhiès
5069485475 ada: Emit more warnings on unsupported overlay
In the case where the overlaid object is nested in a record or is an
array element as in:

    for Foo'Address use Item.Nested_Item'Address;
or  for Foo'Address use Item (Bar)'Address;

the compiler was not emitting a warning in case of differing
Scalar_Storage_Order values.

gcc/ada/ChangeLog:

	* sem_util.adb (Find_Overlaid_Entity): Add extra parameter to
	extract the type being overlaid.
	(Note_Possible_Modification): Adjust call to Find_Overlaid_Entity.
	(Ultimate_Overlaid_Entity): Likewise.
	* sem_ch13.adb (Analyze_Attribute_Definition_Clause): Likewise.
	* sem_util.ads (Find_Overlaid_Entity): Add extra parameter to
	extract the type being overlaid.
	* freeze.adb (Check_Address_Clause): Likewise.
2025-06-09 08:32:05 +02:00
Gary Dismukes
250392311d ada: Incorrect creation of corresponding expression of class-wide contracts
GNAT was incorrectly implementing the Ada rules for resolving calls to
primitive functions within inherited class-wide pre- and postconditions,
as specified in RM22 6.1.1 (relating to AI12-0113).  Only function calls
that involve formals of the associated primitive subprogram should be
treated using the "(notional) formal derived type" rules.  In particular,
calls that are tag-indeterminate (for example, "F(G)") should not be mapped
to call the corresponding primitives of the derived type (they should still
call the primitives of the ancestor type).  The fix for this involves a new
predicate function that recursively traverses calls to determine the calls
that satisfy the criteria for mapping.  These changes also completely remove
the mapping of formals that was done in Contracts.Merge_Class_Conditions
(in Inherit_Condition), since the mapping will be done later anyway by
Build_Class_Wide_Expression, and the earlier mapping interferes with that.

Note: The utility function Sem_Util.Check_Parents is no longer called
after removal of the single call to it from contracts.adb, but it's being
retained (along with the generic subprograms in Atree that it depends on)
for possible use in VAST.

gcc/ada/ChangeLog:

	* contracts.adb (Inherit_Condition): Remove Assoc_List and its uses
	along with function Check_Condition, since mapping of formals will
	effectively be done in Build_Class_Wide_Expression (by Replace_Entity).
	* exp_util.adb (Replace_Entity): Only rewrite entity references in
	function calls that qualify according to the result of calling the
	new function Call_To_Parent_Dispatching_Op_Must_Be_Mapped.
	(Call_To_Parent_Dispatching_Op_Must_Be_Mapped): New function that
	determines whether a function call to a primitive of Par_Subp
	associated tagged type needs to be mapped (according to whether
	it has any actuals that reference controlling formals of the
	primitive).
2025-06-09 08:32:05 +02:00
Ronan Desplanques
5fba1c986d ada: Remove outdated comment
This patch removes a comment that was made incorrect by the introduction
of Is_Self_Hidden.

gcc/ada/ChangeLog:

	* sem_ch3.adb (Analyze_Object_Declaration): Remove comment.
2025-06-09 08:32:04 +02:00
Ronan Desplanques
7ab63499ac ada: Add example in Current_Entity_In_Scope comment
gcc/ada/ChangeLog:

	* sem_util.ads (Current_Entity_In_Scope): Add example in comment.
2025-06-09 08:32:04 +02:00
Ronan Desplanques
8577f2ebef ada: Clarify warning in Atree.Rewrite documentation
The documentation of Atree.Rewrite warns about a potential misuse of
that subprogram. This patch makes the text of that warning more specific.
The documentation of Atree.Replace had the same note but this patch
replaces it with a mention of the one in Rewrite's documentation.

gcc/ada/ChangeLog:

	* atree.ads (Rewrite, Replace): Clarify comments.
2025-06-09 08:32:04 +02:00
Ronan Desplanques
9334a4a2c5 ada: Remove incorrect comment
This patchs removes a comment that was incorrect, as noted by a ???
comment that was right after and that this patch also removes.

gcc/ada/ChangeLog:

	* atree.ads (Rewrite): Remove comment.
2025-06-09 08:32:03 +02:00
Ronan Desplanques
880e6752ad ada: Improve readability in Atree.Rewrite body
This patch visually packs together the statements that implement the
exceptions in Rewrite that a few fields are not actually overwritten, in
order to improve the readability of the code.

gcc/ada/ChangeLog:

	* atree.adb (Rewrite): Improve readability.
2025-06-09 08:32:03 +02:00
Ronan Desplanques
acc54e0cf0 ada: Tweak Kill_Current_Values
Is_Object returns True for "record field" entities, which might make
sense in some contexts but not when Kill_Current_Values is called in a
default expression of a record component. This patch refines the choice
of considered entities in Kill_Current_Values accordingly.

gcc/ada/ChangeLog:

	* sem_util.adb (Kill_Current_Values): Tweak condition.
2025-06-09 08:32:03 +02:00
Eric Botcazou
109ea2d288 ada: Fix spurious error on anonymous array initialized by conditional expression
Even though the actual subtype of the anonymous array is not yet set on the
object itself by the time Insert_Conditional_Object_Declaration is called,
it is set on its initialization expression, so it can simply be forwarded
to Insert_Conditional_Object_Declaration from there, which avoids creating
a new one for each new object and triggering a subtype mismatch later.

gcc/ada/ChangeLog:

	* exp_ch4.adb (Insert_Conditional_Object_Declaration): Remove Decl
	formal parameter, add Typ and Const formal parameters.
	(Expand_N_Case_Expression): Fix pasto in comment.  Adjust call to
	Insert_Conditional_Object_Declaration and tidy up surrounding code.
	(Expand_N_If_Expression): Adjust couple of calls to
	Insert_Conditional_Object_Declaration.
2025-06-09 08:32:03 +02:00
Ronan Desplanques
2e0e76ca8e ada: Fix assertion failure on error path
gcc/ada/ChangeLog:

	* sem_ch8.adb (Find_Selected_Component): Fix error path.
2025-06-09 08:32:02 +02:00