Commit graph

193293 commits

Author SHA1 Message Date
Jonathan Wakely
5c2d703e6d libstdc++: Add attributes to functions in <memory_resource>
Add attributes to the accessors for the global memory resource objects,
to allow the compiler to eliminate redundant calls to them. For example,
multiple calls to std::pmr::new_delete_resource() will always return the
same object, and so the compiler can replace them with a single call.

Ideally we would like adjacent calls to std::pmr::get_default_resource()
to be combined into a single call by the CSE pass. The 'pure' attribute
would permit that. However, the standard requires that calls to
std::pmr::set_default_resource() synchronize with subsequent calls to
std::pmr::get_default_resource().  With 'pure' the DCE pass might
eliminate seemingly redundant calls to std::pmr::get_default_resource().
That might be unsafe, because the caller might be relying on the
associated synchronization. We could use a hypothetical attribute that
allows CSE but not DCE, but we don't have one. So it can't be 'pure'.

Also add [[nodiscard]] to equality operators.

libstdc++-v3/ChangeLog:

	* include/std/memory_resource (new_delete_resource): Add
	nodiscard, returns_nonnull and const attributes.
	(null_memory_resource): Likewise.
	(set_default_resource, get_default_resource): Add returns_nonnull
	attribute.
	(memory_resource::is_equal): Add nodiscard attribute.
	(operator==, operator!=): Likewise.
2022-05-17 20:51:04 +01:00
Jonathan Wakely
5f1ce85135 libstdc++: Add attributes to <system_error> and related
Add the const attribute to std::future_category() and
std::iostream_category(), to match the existing attributes on
std::generic_category() and std::system_category().

Also add [[nodiscard]] to those functions and to the comparison
operators for std::error_code and std::error_condition, and to
std::make_error_code and std::make_error_condition overloads.

libstdc++-v3/ChangeLog:

	* include/bits/ios_base.h (io_category): Add const and nodiscard
	attributes.
	(make_error_code, make_error_condition): Add nodiscard.
	* include/std/future (future_category): Add const and nodiscard.
	(make_error_code, make_error_condition): Add nodiscard.
	* include/std/system_error (generic_category system_category):
	Add nodiscard. Replace _GLIBCXX_CONST with C++11 attribute.
	(error_code::value, error_code::category, error_code::operator bool)
	(error_condition::value, error_condition::category)
	(error_condition::operator bool, make_error_code)
	(make_error_condition, operator==, operator!=, operator<=>): Add
	nodiscard.
2022-05-17 20:50:31 +01:00
Tobias Burnus
c9852156dd Revert 'Use more ARRAY_SIZE.' for mkoffload
Revert commit r13-472-gca32b29ec3e92dcf8dda5c2501d0baf9dd1cb09d partially;
namely for {gcn,nvptx}/mkoffload.cc, only.

The patch changed 'sizeof(...)/sizeof(...[0])' to the 'ARRAY_SIZE' macro,
which is in principle a good idea – except that in the two mkoffload.cc,
the change happened inside a string that is used to generate plain C code.

With offlading to nvptx or gcn, the mkoffload genenates then the C file
and compilation of the latter fails with
"warning: implicit declaration of function 'ARRAY_SIZE'" followed by
"error: initializer element is not constant"

gcc/
	* config/gcn/mkoffload.cc (process_obj): Revert: Use ARRAY_SIZE.
	* config/nvptx/mkoffload.cc (process): Likewise.
2022-05-17 20:54:32 +02:00
Andrew MacLeod
b7501739f3 Add side effect infrastructure.
Replace the non-null procesing with a generic side effect implementation that
can handle arbitrary side effects.

	* Makefile.in (OBJS): Add gimple-range-side-effect.o.
	* gimple-range-cache.cc (non_null_ref::non_null_ref): Delete.
	(non_null_ref::~non_null_ref): Delete.
	(non_null_ref::set_nonnull): Delete.
	(non_null_ref::non_null_deref_p): Delete.
	(non_null_ref::process_name): Delete.
	(ranger_cache::ranger_cache): Initialize m_exit object.
	(ranger_cache::fill_block_cache): Use m_exit object intead of nonnull.
	(ranger_cache::range_from_dom): Use side_effect class and m_exit object.
	(ranger_cache::update_to_nonnull): Delete.
	(non_null_loadstore): Delete.
	(ranger_cache::block_apply_nonnull): Delete.
	(ranger_cache::apply_side_effects): New.
	* gimple-range-cache.h (class non_null_ref): Delete.
	(non_null_ref::adjust_range): Delete.
	(class ranger_cache): Adjust prototypes, add side effect manager.
	* gimple-range-path.cc (path_range_query::range_defined_in_block): Use
	side effect manager for queries.
	(path_range_query::adjust_for_non_null_uses): Ditto.
	* gimple-range-path.h (class path_range_query): Delete non_null_ref.
	* gimple-range-side-effect.cc: New.
	* gimple-range-side-effect.h: New.
	* gimple-range.cc (gimple_ranger::gimple_ranger): Update contructor.
	(gimple_ranger::range_of_expr): Check def block for override value.
	(gimple_ranger::range_on_entry): Don't scan dominators for non-null.
	(gimple_ranger::range_on_edge): Check for outgoing side-effects.
	(gimple_ranger::register_side_effects): Call apply_side_effects.
	(enable_ranger): Update contructor.
	* gimple-range.h (class gimple_ranger): Update prototype.
	(enable_ranger): Update prototype.
	* tree-vrp.cc (execute_ranger_vrp): Invoke without immediate-use flag.
2022-05-17 14:38:03 -04:00
Nathan Sidwell
451894cadc demangler: Structured Bindings
C++ Structured bindings have a mangling that has yet to be formally
documented.  However, it's been around for a while and shows up for
module support.

	include/
	* demangle.h (enum demangle_component_type): Add
	DEMANGLE_COMPONENT_STRUCTURED_BINDING.
	libiberty/
	* cp-demangle.c (d_make_comp): Adjust.
	(d_unqualified_name): Add 'DC' support.
	(d_count_template_scopes): Adjust.
	(d_print_comp_inner): Add structured binding.
	* testsuite/demangle-expected: Add testcases.
2022-05-17 11:10:03 -07:00
Giuliano Belinassi
7a3f38a966 PR105169 Fix references to discarded sections
When -fpatchable-function-entry= is enabled, certain C++ codes fails to
link because of generated references to discarded sections in
__patchable_function_entry section. This commit fixes this problem by
puting those references in a COMDAT section.

2022-05-06  Giuliano Belinassi  <gbelinassi@suse.de>

gcc/ChangeLog
	PR c++/105169
	* targhooks.cc (default_print_patchable_function_entry_1): Handle COMDAT case.
	* varasm.cc (switch_to_comdat_section): New
	(handle_vtv_comdat_section): Call switch_to_comdat_section.
	* varasm.h: Declare switch_to_comdat_section.

gcc/testsuite/ChangeLog
2022-05-06  Giuliano Belinassi  <gbelinassi@suse.de>

	PR c++/105169
	* g++.dg/modules/pr105169.h: New file.
	* g++.dg/modules/pr105169_a.C: New test.
	* g++.dg/modules/pr105169_b.C: New file.
2022-05-17 14:34:21 -03:00
Richard Biener
941efd87e2 Do not clear bb->aux in duplicate_loop_body_to_header_edge
duplicate_loop_body_to_header_edge clears bb->aux which is not wanted
by a new use in loop unswitching.  The clearing was introduced with
r0-69110-g6580ee7781f903 and it seems accidentially so.

2022-05-17  Richard Biener  <rguenther@suse.de>

	* cfgloopmanip.cc (duplicate_loop_body_to_header_edge): Do
	not clear bb->aux of the copied blocks.
2022-05-17 17:53:46 +02:00
Andrew MacLeod
6101a276c3 Check for equivalence after merging relations.
When registering a relation, we need to merge with any existing relation
before checking if it was an equivalence... otherwise it was not being
handled properly.

	gcc/
	PR tree-optimization/105458
	* value-relation.cc (path_oracle::register_relation): Merge, then check
	for equivalence.

	gcc/testsuite/
	* gcc.dg/pr105458.c: New.
2022-05-17 11:43:32 -04:00
Uros Bizjak
61a6923e89 i386: Fix ICE in final_scan_insn_1 [PR105624]
Apparently const_int_operand and other const*_operand predicates
do need constraints.  Revert the offending patch that caused ICE.

2022-05-17  Uroš Bizjak  <ubizjak@gmail.com>

gcc/ChangeLog:

	PR target/105624
	Revert:

	* config/i386/i386.md: Remove constraints when used with
	const_int_operand, const0_operand, const_1_operand, constm1_operand,
	const8_operand, const128_operand, const248_operand, const123_operand,
	const2367_operand, const1248_operand, const359_operand,
	const_4_or_8_to_11_operand, const48_operand, const_0_to_1_operand,
	const_0_to_3_operand, const_0_to_4_operand, const_0_to_5_operand,
	const_0_to_7_operand, const_0_to_15_operand, const_0_to_31_operand,
	const_0_to_63_operand, const_0_to_127_operand, const_0_to_255_operand,
	const_0_to_255_mul_8_operand, const_1_to_31_operand,
	const_1_to_63_operand, const_2_to_3_operand, const_4_to_5_operand,
	const_4_to_7_operand, const_6_to_7_operand, const_8_to_9_operand,
	const_8_to_11_operand, const_8_to_15_operand, const_10_to_11_operand,
	const_12_to_13_operand, const_12_to_15_operand, const_14_to_15_operand,
	const_16_to_19_operand, const_16_to_31_operand, const_20_to_23_operand,
	const_24_to_27_operand and const_28_to_31_operand.
	* config/i386/mmx.md: Ditto.
	* config/i386/sse.md: Ditto.
	* config/i386/subst.md: Ditto.
	* config/i386/sync.md: Ditto.

gcc/testsuite/ChangeLog:

	PR target/105624
	* gcc.target/i386/pr105624.c: New test.
2022-05-17 17:37:59 +02:00
Jakub Jelinek
741478ed3e libgomp: Clarify that omp_display_env is fully implemented
OpenMP 5.2 added
"When called from within a target region the effect is unspecified."
restriction to omp_display_env, so it is ok not to support it in
target regions (worst case we could add an empty implementation
or one with __builtin_trap in there).

2022-05-17  Jakub Jelinek  <jakub@redhat.com>

	* libgomp.texi (OpenMP 5.1): Remove "Not inside target regions"
	comment for omp_display_env feature.
2022-05-17 16:58:26 +02:00
Thomas Schwinge
cd4a0ddc12 Advise to call 'internal_error' instead of 'abort' or 'fancy_abort'
gcc/
	* diagnostic.cc: Don't advise to call 'abort' instead of
	'internal_error'.
	* system.h: Advise to call 'internal_error' instead of 'abort' or
	'fancy_abort'.

Suggested-by: Richard Biener <richard.guenther@gmail.com>
2022-05-17 16:27:32 +02:00
Frederik Harwath
0f00ebf0d6 graphite: Fix minor mistakes in comments
gcc/ChangeLog:

	* graphite-sese-to-poly.cc (build_poly_sr_1): Fix a typo and
	a reference to a variable which does not exist.
	* graphite-isl-ast-to-gimple.cc (gsi_insert_earliest): Fix typo
	in comment.
2022-05-17 16:02:01 +02:00
Frederik Harwath
0cca1c22b0 graphite: Rename isl_id_for_ssa_name
The SSA names for which this function gets used are always SCoP
parameters and hence "isl_id_for_parameter" is a better name.  It also
explains the prefix "P_" for those names in the ISL representation.

gcc/ChangeLog:

	* graphite-sese-to-poly.cc (isl_id_for_ssa_name): Rename to ...
	(isl_id_for_parameter): ... this new function name.
	(build_scop_context): Adjust function use.
2022-05-17 16:00:57 +02:00
Tobias Burnus
61fe7b7d46 libgomp.texi: Document OpenMP context selectors
libgomp/
	* libgomp.texi (Offload-Target Specifics): New chapter; add section
	to document OpenMP context selectors.
2022-05-17 15:54:24 +02:00
Tobias Burnus
ebe5dace8c gcn/t-omp-device: Add 'amdgcn' as 'arch' [PR105602]
Improve cross-compiler handling.

gcc/ChangeLog:

	PR target/105602
	* config/gcn/t-omp-device (arch): Add 'amdgcn' besides existing 'gcn'.
	* config/gcn/gcn.cc (gcn_omp_device_kind_arch_isa): Likewise.
2022-05-17 15:54:23 +02:00
Jakub Jelinek
2c16eb3157 openmp: Add support for inoutset depend-kind
This patch adds support for inoutset depend-kind in depend
clauses.  It is very similar to the in depend-kind in that
a task with a dependency with that depend-kind is dependent
on all previously created sibling tasks with matching address
unless they have the same depend-kind.
In the in depend-kind case everything is dependent except
for in -> in dependency, for inoutset everything is
dependent except for inoutset -> inoutset dependency.
mutexinoutset is also similar (everything is dependent except
for mutexinoutset -> mutexinoutset dependency), but there is
also the additional restriction that only one task with
mutexinoutset for each address can be scheduled at once (i.e.
mutual exclusitivty).  For now we support mutexinoutset
the same as inout/out, but the inoutset support is full.

In order not to bump the ABI for dependencies each time
(we've bumped it already once, the old ABI supports only
inout/out and in depend-kind, the new ABI supports
inout/out, mutexinoutset, in and depobj), this patch arranges
for inoutset to be at least for the time being always handled
as if it was specified through depobj even when it is not.
So it uses the new ABI for that and inoutset are represented
like depobj - pointer to a pair of pointers where the first one
will be the actual address of the object mentioned in depend
clause and second pointer will be (void *) GOMP_DEPEND_INOUTSET.

2022-05-17  Jakub Jelinek  <jakub@redhat.com>

gcc/
	* tree-core.h (enum omp_clause_depend_kind): Add
	OMP_CLAUSE_DEPEND_INOUTSET.
	* tree-pretty-print.cc (dump_omp_clause): Handle
	OMP_CLAUSE_DEPEND_INOUTSET.
	* gimplify.cc (gimplify_omp_depend): Likewise.
	* omp-low.cc (lower_depend_clauses): Likewise.
gcc/c-family/
	* c-omp.cc (c_finish_omp_depobj): Handle
	OMP_CLAUSE_DEPEND_INOUTSET.
gcc/c/
	* c-parser.cc (c_parser_omp_clause_depend): Parse
	inoutset depend-kind.
	(c_parser_omp_depobj): Likewise.
gcc/cp/
	* parser.cc (cp_parser_omp_clause_depend): Parse
	inoutset depend-kind.
	(cp_parser_omp_depobj): Likewise.
	* cxx-pretty-print.cc (cxx_pretty_printer::statement): Handle
	OMP_CLAUSE_DEPEND_INOUTSET.
gcc/testsuite/
	* c-c++-common/gomp/all-memory-1.c (boo): Add test with
	inoutset depend-kind.
	* c-c++-common/gomp/all-memory-2.c (boo): Likewise.
	* c-c++-common/gomp/depobj-1.c (f1): Likewise.
	(f2): Adjusted expected diagnostics.
	* g++.dg/gomp/depobj-1.C (f4): Adjust expected diagnostics.
include/
	* gomp-constants.h (GOMP_DEPEND_INOUTSET): Define.
libgomp/
	* libgomp.h (struct gomp_task_depend_entry): Change is_in type
	from bool to unsigned char.
	* task.c (gomp_task_handle_depend): Handle GOMP_DEPEND_INOUTSET.
	Ignore dependencies where
	task->depend[i].is_in && task->depend[i].is_in == ent->is_in
	rather than just task->depend[i].is_in && ent->is_in.  Remember
	whether GOMP_DEPEND_IN loop is needed and guard the loop with that
	conditional.
	(gomp_task_maybe_wait_for_dependencies): Handle GOMP_DEPEND_INOUTSET.
	Ignore dependencies where elem.is_in && elem.is_in == ent->is_in
	rather than just elem.is_in && ent->is_in.
	* testsuite/libgomp.c-c++-common/depend-1.c (test): Add task with
	inoutset depend-kind.
	* testsuite/libgomp.c-c++-common/depend-2.c (test): Likewise.
	* testsuite/libgomp.c-c++-common/depend-3.c (test): Likewise.
	* testsuite/libgomp.c-c++-common/depend-inoutset-1.c: New test.
2022-05-17 15:40:27 +02:00
Jonathan Wakely
1815462a6e libstdc++: Skip tests that fail for the versioned namespace
Most tests for the contents of header synopses need to be supressed for
the versioned namespace build, because redeclaring the entities in std
fails when they were originally declared in std::__8.

I added these tests recently without the suppression, so they fail.

libstdc++-v3/ChangeLog:

	* testsuite/20_util/expected/synopsis.cc: Skip for versioned
	namespace.
	* testsuite/27_io/headers/iosfwd/synopsis.cc: Likewise.
2022-05-17 11:42:34 +01:00
Jonathan Wakely
357d6fcd41 libstdc++: Stop defining C++0x compat symbols for versioned namespace
The src/c++11/compatibility*-c++0x.cc files define symbols that need to
be exported for ancient versions of libstdc++.so.6 due to changes
between C++0x and the final C++11 standard. Those symbols are not needed
in the libstdc++.so.8 library, and we can skip building them entirely.

This also fixes the build failure I introduced last week when making the
versioned namespace config not use the _V2 namespace for compat symbols.

libstdc++-v3/ChangeLog:

	* src/Makefile.am [ENABLE_SYMVERS_GNU_NAMESPACE] (cxx11_sources):
	Do not build the compatibility*-c++0x.cc objects.
	* src/Makefile.in: Regenerate.
	* src/c++11/compatibility-c++0x.cc [_GLIBCXX_INLINE_VERSION]:
	Refuse to build for the versioned namespace.
	* src/c++11/compatibility-chrono.cc: Likewise.
	* src/c++11/compatibility-condvar.cc: Likewise.
	* src/c++11/compatibility-thread-c++0x.cc: Likewise.
	* src/c++11/chrono.cc (system_clock, steady_clock):
	Use macros to define in inline namespace _V2, matching the
	declarations in <system_error>.
	* src/c++11/system_error.cc (system_category, generic_category):
	Likewise.
2022-05-17 11:42:34 +01:00
Tobias Burnus
472aecb789 libgomp.texi: Add OpenMP 5.2 implementation status
libgomp/
	* libgomp.texi (OpenMP Implementation Status): Add 5.2 table.
2022-05-17 12:31:35 +02:00
Jakub Jelinek
254cbf7266 i386: Fix up V2DI and V1TI inequality comparisons [PR105613]
The recent r13-458 change to introduce vec_cmpeqv1tiv1ti and
add TARGET_SSE2 support to vec_cmpeqv2div2di works nicely for
equality comparisons, but as the testcase shows doesn't work
for inequality comparisons.
For EQ if we perform comparison with twice as many half-sized elemenets,
the result should be ~0 when both halves are ~0 only (both halves need
to be equal for the whole to be equal), otherwise 0, so AND is the
correct operation for it.
But for NE, the result should be ~0 when either of the halves is ~0
(if either half is not equal, the whole is not equal) and so the right
operation for NE is IOR, not AND.

2022-05-17  Jakub Jelinek  <jakub@redhat.com>

	PR target/105613
	* config/i386/sse.md (vec_cmpeqv2div2di, vec_cmpeqv1tiv1ti): Use
	andv4si3 only for EQ, for NE use iorv4si3 instead.

	* gcc.c-torture/execute/pr105613.c: New test.
2022-05-17 12:10:30 +02:00
Tobias Burnus
4f94c38a92 OpenMP: Add omp_all_memory support to Fortran
Fortran part to the C/C++/backend implementation
r13-337-g7f78783dbedca0183d193e475262ca3c489fd365

gcc/fortran/ChangeLog:

	* dump-parse-tree.cc (show_omp_namelist): Handle omp_all_memory.
	* openmp.cc (gfc_match_omp_variable_list, gfc_match_omp_depend_sink,
	gfc_match_omp_clauses, resolve_omp_clauses): Likewise.
	* trans-openmp.cc (gfc_trans_omp_clauses, gfc_trans_omp_depobj):
	Likewise.
	* resolve.cc (resolve_symbol): Reject it as symbol.

libgomp/ChangeLog:

	* libgomp.texi (OpenMP 5.1): Set omp_all_memory to 'Y'.
	* testsuite/libgomp.fortran/depend-5.f90: New test.
	* testsuite/libgomp.fortran/depend-6.f90: New test.
	* testsuite/libgomp.fortran/depend-7.f90: New test.

gcc/testsuite/ChangeLog:

	* gfortran.dg/gomp/all-memory-1.f90: New test.
	* gfortran.dg/gomp/all-memory-2.f90: New test.
	* gfortran.dg/gomp/all-memory-3.f90: New test.
2022-05-17 11:01:04 +02:00
Richard Biener
ebce0e9bd8 tree-optimization/105618 - restore load sinking
The PR97330 fix caused some missed sinking of loads out of loops
the following patch re-instantiates.

2022-05-17  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/105618
	* tree-ssa-sink.cc (statement_sink_location): For virtual
	PHI uses ignore those defining the used virtual operand.

	* gcc.dg/tree-ssa/ssa-sink-19.c: New testcase.
2022-05-17 10:45:45 +02:00
Piotr Trojanek
33400df641 [Ada] Restore defensive guard in checks for volatile actuals
When flagging names of volatile objects occurring in actual parameters
it is safer to guard against identifiers without entity. This is
redundant (because earlier in the resolution of actual parameters we
already guard against actuals with Any_Type), but perhaps such
identifiers will become allowed in constructs like:

   Subprogram_Call
     (Actual =>
        (declare
           X : Boolean := ...
             with Annotate (GNATprove, ...)));
                            ^^^^^^^^^

which include an identifier that does not denote any entity.

Code cleanup related to handling of volatile components; behaviour is
unaffected.

gcc/ada/

	* sem_res.adb (Flag_Effectively_Volatile_Objects): Restore
	redundant guard.
2022-05-17 08:25:50 +00:00
Gary Dismukes
de0665fc7f [Ada] Subprogram renaming fails to hide homograph
The compiler failed to detect an error where the first prefix of an
expanded name given as the renamed subprogram in a subprogram renaming
declaration denotes a unit with the same name as the name given for the
subprogram renaming. Such a unit must be hidden by the renaming itself.
An error check is added to catch this case.

gcc/ada/

	* sem_ch8.adb (Analyze_Subprogram_Renaming): Add error check for
	the case of a renamed subprogram given by an expanded name whose
	outermost prefix names a unit that is hidden by the name of the
	renaming.
	(Ult_Expanded_Prefix): New local expression function to return
	the ultimate prefix of an expanded name.
2022-05-17 08:25:49 +00:00
Ghjuvan Lacambre
a51b6016c9 [Ada] CUDA: remove code performing kernel registration
A previous commit implemented a new kernel registration scheme, using
the binder to generate registration code rather than inserting
registration code in packages.  Now that this new approach has had time
to be thoroughly tested, it is time to remove the old approach.

gcc/ada/

	* gnat_cuda.ads: Update package-level comments.
	(Build_And_Insert_CUDA_Initialization): Remove function.
	* gnat_cuda.adb (Build_And_Insert_CUDA_Initialization): Remove
	function.
	(Expand_CUDA_Package): Remove call to
	Build_And_Insert_CUDA_Initialization.
2022-05-17 08:25:49 +00:00
Etienne Servais
5ab656c5e9 [Ada] Enhance the warning on C enum with size clause for size /= 32
Improve the warning message and silence warning when size > 32, this is
likely intentional and does not warrant a warning.

gcc/ada/

	* freeze.adb (Freeze_Enumeration_Type): Fix comment, enhance
	message and silence warning for size > 32.
2022-05-17 08:25:49 +00:00
Yannick Moy
3c802e9749 [Ada] Allow inlining for proof inside generics
For local subprograms without contracts inside generics, allow their
inlining for proof in GNATprove mode. This requires forbidding the
inlining of subprograms which contain references to object renamings,
which would be replaced in the SPARK expansion and violate assumptions
of the inlining code.

gcc/ada/

	* exp_spark.adb (Expand_SPARK_Potential_Renaming): Deal with no
	entity case.
	* inline.ads (Check_Object_Renaming_In_GNATprove_Mode): New
	procedure.
	* inline.adb (Check_Object_Renaming_In_GNATprove_Mode): New
	procedure.
	(Can_Be_Inlined_In_GNATprove_Mode): Remove case forbidding
	inlining for subprograms inside generics.
	* sem_ch12.adb (Copy_Generic_Node): Preserve global entities
	when inlining in GNATprove mode.
	* sem_ch6.adb (Analyse_Subprogram_Body_Helper): Remove body to
	inline if renaming is detected in GNATprove mode.
2022-05-17 08:25:48 +00:00
Gary Dismukes
867bf6f087 [Ada] Provide allocation subtype for allocators of a Designated_Storage_Model type
When an allocator is for an access type that has a
Designated_Storage_Model aspect, and the designated type is an
unconstrained record type with discriminants, and the subtype associated
with the allocator is constrained, a dereference of the new access value
can be passed to the designated type's initialization procedure. The
post-front-end phase of the compiler needs to be able to create a
temporary object in the host memory space to pass to the init proc,
which requires creating such an object, but the subtype needed for the
allocation isn't readily available at the point of the dereference.  To
make the subtype easily accessible, we set the Actual_Designated_Subtype
of such a dereference to the subtype of the allocated object.

gcc/ada/

	* exp_ch4.adb (Expand_N_Allocator): For an allocator with an
	unconstrained discriminated designated type, and whose
	allocation subtype is constrained, set the
	Actual_Designated_Subtype of the dereference passed to the init
	proc of the designated type to be the allocation subtype.
	* sinfo.ads: Add documentation of new setting of
	Actual_Designated_Subtype on a dereference used as an actual
	parameter of call to an init proc associated with an allocator.
	Also add missing syntax and documentation for the GNAT language
	extension that allows an expression as a default for a concrete
	generic formal function.
2022-05-17 08:25:48 +00:00
Bob Duff
f2ef7a0545 [Ada] Cleanups related to front-end SJLJ
This patch cleans up some code that is left over from the front-end SJLJ
exception handling mechanism, which has been removed.
This is in preparation for fixing a finalization-related bug.

Most importantly:

    The documentation is changed: a Handled_Sequence_Of_Statements node
    CAN contain both Exception_Handlers and an At_End_Proc.

    The assertion contradicting that is removed from
    Expand_At_End_Handler.

    The From_At_End field is removed.

gcc/ada/

	* sinfo.ads: Remove From_At_End.  Update comments.
	* gen_il-fields.ads, gen_il-gen-gen_nodes.adb, sem_ch11.adb:
	Remove From_At_End.
	* exp_ch11.adb (Expand_At_End_Handler): Remove assertion.
	* fe.h (Exception_Mechanism, Exception_Mechanism_Type, Has_DIC,
	Has_Invariants, Is_List_Member, List_Containing): Remove
	declarations that are not used in gigi.
	* opt.ads (Exception_Mechanism): This is not used in gigi.
	* exp_util.ads: Minor comment fix.
2022-05-17 08:25:48 +00:00
Dmitriy Anisimkov
26b0b2ddf4 [Ada] GNAT.Binary_Search is not internal
Put package GNAT.Binary_Search to predefined units list.

gcc/ada/

	* impunit.adb: Add "g-binsea" to Non_Imp_File_Names_95 list.
2022-05-17 08:25:47 +00:00
Yannick Moy
5c44da007b [Ada] Fix insertion of declaration inside quantified expression
When the evaluation of the subtype_indication for the
iterator_specification of a quantified_expression leads to the insertion
of a type declaration, this should be done with Insert_Action instead of
Insert_Before.

gcc/ada/

	* sem_ch5.adb (Analyze_Iterator_Specification): Use
	Insert_Action when possibly inside an expression.
2022-05-17 08:25:47 +00:00
Marc Poulhiès
5dbb65676f [Ada] Fix Forced sign flag in formatted string
Fix the Forced sign flag that is incorrectly ignored for scientific
notation and shortest representation.

gcc/ada/

	* libgnat/g-forstr.adb (Is_Number): Add scientific notation and
	shortest representation.
2022-05-17 08:25:46 +00:00
Eric Botcazou
42fe7c9a80 [Ada] Fix small glitch in Expand_N_Full_Type_Declaration
The original node is not guaranteed to also be an
N_Full_Type_Declaration, so the code needs to look into the node itself.

gcc/ada/

	* exp_ch3.adb (Expand_N_Full_Type_Declaration): Look into N.
2022-05-17 08:25:46 +00:00
Bob Duff
80d1067508 [Ada] Requires_Cleanup_Actions and N_Protected_Body
This patch disallows N_Protected_Body from being passed to
Requires_Cleanup_Actions. Protected bodies never need cleanup, and are
never passed to Requires_Cleanup_Actions, which is a good thing, because
it would blow up on Handled_Statement_Sequence, which doesn't exist for
N_Protected_Body.

gcc/ada/

	* exp_util.adb (Requires_Cleanup_Actions): Remove
	N_Protected_Body from the case statement, so that case will be
	covered by "raise Program_Error".
2022-05-17 08:25:46 +00:00
Bob Duff
b81c9e4f9f [Ada] Output.w always writes to stderr
There are several debugging procedures called Output.w, and some
output-redirection features. This patch modifies Output.w so their
output is not redirected; it always goes to standard error. Otherwise,
debugging output can get mixed in with some "real" output (perhaps to a
file), which causes confusion and in some cases failure to build.

gcc/ada/

	* output.adb (Pop_Output, Set_Output): Unconditionally flush
	output when switching from one output destination to another.
	Otherwise buffering can cause garbled output.
	(w): Push/pop the current settings, and temporarily
	Set_Standard_Error during these procedures.
2022-05-17 08:25:46 +00:00
Dmitriy Anisimkov
a2bcadcef0 [Ada] Generic binary search implementation
Allows binary search in sorted anonymous array (or array-like
container).

gcc/ada/

	* libgnat/g-binsea.ads, libgnat/g-binsea.adb
	(GNAT.Binary_Search): New package.
	* Makefile.rtl (GNATRTL_NONTASKING_OBJS): New item in list.
	* doc/gnat_rm/the_gnat_library.rst (GNAT.Binary_Search): New
	package record.
	* gnat_rm.texi: Regenerate.
2022-05-17 08:25:45 +00:00
Eric Botcazou
ca3e565395 [Ada] Fix bogus visibility error with partially parameterized formal package
The problem comes from the special instantiation (abbreviated instantiation
in GNAT parlance) done to check conformance between a formal package and its
corresponding actual in a generic instantiation: the compiler instantiates
the formal package, in the context of the generic instantiation, so that it
can check the conformance of the actual with the result.

More precisely, it occurs with formal packages that are only partially
parameterized, i.e. that have at least one parameter association and an
(others => <>) choice. In this case, RM 12.7(10/2) says that the visible
part of the formal package contains a copy of the formal parameters that
are not explicitly associated.

The analysis of these copies for the abbreviated instantiation is not done
in the correct context when the generic unit is a child generic unit.

gcc/ada/

	* sem_ch12.ads (Is_Abbreviated_Instance): Declare.
	* sem_ch12.adb (Check_Abbreviated_Instance): Declare.
	(Requires_Conformance_Checking): Declare.
	(Analyze_Association.Process_Default): Fix subtype of parameter.
	(Analyze_Formal_Object_Declaration): Check whether it is in the
	visible part of abbreviated instance.
	(Analyze_Formal_Subprogram_Declaration): Likewise.
	(Analyze_Formal_Type_Declaration): Likewise.
	(Analyze_Package_Instantiation): Do not check for a generic child
	unit in the case of an abbreviated instance.
	(Check_Abbreviated_Instance): New procedure.
	(Check_Formal_Packages): Tidy up.
	(Copy_Generic_Elist): Fix comment.
	(Instantiate_Formal_Package): Tidy up.  If the generic unit is a
	child unit, copy the qualified name onto the abbreviated instance.
	(Is_Abbreviated_Instance): New function.
	(Collect_Previous_Instances): Call Is_Abbreviated_Instance.
	(Requires_Conformance_Checking): New function.
	* sem_ch7.adb (Analyze_Package_Specification): Do not install the
	private declarations of the parent for an abbreviated instance.
2022-05-17 08:25:45 +00:00
Etienne Servais
27b2b83bd7 [Ada] Take full view of private type
This allows to resolve the following:

      type Rec (<>) is private;
      type Arr (<>) is private;
   private
      type Arr is array (Positive range <>) of Natural;
      type Rec (L : Natural) is record
         F1 : Integer;
         F2 : Arr (1 .. L);
      end record;

gcc/ada/

	* sem_ch3.adb (Analyze_Subtype_Declaration): Use underlying type
	of Indic_Typ.
	(Constrain_Array): Ditto for T.
2022-05-17 08:25:44 +00:00
Arnaud Charlet
c21a0097b6 [Ada] Allow 'Reduce with -gnat2022
After a period of experimentation, allow 'Reduce in Ada 2022 mode.

gcc/ada/

	* sem_attr.adb (Analyze_Attribute [Attribute_Reduce]): Allow
	'Reduce for Ada 2022 and above.
	* sem_attr.ads (Attribute_Impl_Def): 'Reduce is no longer
	implementation defined.
2022-05-17 08:25:44 +00:00
Ghjuvan Lacambre
6e2d6b8e8e [Ada] Don't create calls to Abort_Undefer when not Abort_Allowed
Prevent creation of references to Abort_Undefer when aborts aren't
allowed. Another solution could have been an early return at
Expand_N_Asynchronous_Select's beginning, but this would break backends
that currently expect trees that do not contain any
N_Asynchronous_Selects in their AST (e.g. CodePeer).

gcc/ada/

	* exp_ch9.adb (Expand_N_Asynchronous_Select): Don't generate
	Abort_Undefers when not Abort_Allowed.
2022-05-17 08:25:44 +00:00
Marc Poulhiès
98208e364c [Ada] Typo fix in finalization comment
Add missing 's' and reformat the comment block.

gcc/ada/

	* exp_ch7.adb: Fix typo.
2022-05-17 08:25:43 +00:00
Etienne Servais
83bfddac6f [Ada] Initialize Compiler_State to avoid Constraint_Error
When building gnat1 with `-gnatVa` as we do locally, rules like: `gcc -c
-gnatyM79 <any adb file with lines longer than 79>` will throw a
constraint error as `lib.compiler_state` is initialized by par.adb, ie
after scanning. Therefore any error_msg thrown during scanning will
perform this uninitialized read (which raises a Constraint_Error when
the compiler was compiled with `-gnatVa`).

Initialize this flag to `Parsing`.

gcc/ada/

	* lib.ads: initialize `Compiler_State` to `Parsing`.
2022-05-17 08:25:43 +00:00
Eric Botcazou
d678717ab2 [Ada] Deal with derived record types in Has_Compatible_Representation
More precisely, untagged record types, as tagged record types are already
handled by the predicate.  If the derived type has not been given its own
representation clause, then the representations are the same.

gcc/ada/

	* sem_ch13.adb (Has_Compatible_Representation): Return true for
	derived untagged record types without representation clause.
2022-05-17 08:25:43 +00:00
Eric Botcazou
e2f7d58cda [Ada] Streamline implementation of Has_Compatible_Representation
The predicate is only concerned with the internal representation of types
and this representation is shared by the subtypes of a given type, so the
implementation can directly look into the (implementation) base types.

No functional changes.

gcc/ada/

	* sem_ch13.ads (Has_Compatible_Representation): Minor tweaks.
	* sem_ch13.adb (Has_Compatible_Representation): Look directly into
	the (implementation) base types and simplifiy accordingly.
	* exp_ch5.adb (Change_Of_Representation): Adjust.
	* exp_ch6.adb (Expand_Actuals): Likewise.
2022-05-17 08:25:42 +00:00
Etienne Servais
87a6558424 [Ada] Remove superfluous call to Original_Node
The function Same_Object starts by taking the Original_Node of its
arguments.

gcc/ada/

	* sem_ch5.adb (Analyze_Assignment): Remove superfluous call to
	Original_Node.
2022-05-17 08:25:42 +00:00
Javier Miranda
6c72dc7d60 [Ada] Crash freezing declaration that will raise constraint error
When the compiler is built with assertions enabled and processes the
following declarations:

   type Vector_Boolean_Array is array (1 .. 10) of Boolean;
   O2 : constant Vector_Boolean_Array := [for J in 2 => True];

The expression is rewritten by the frontend with an N_Raise_CE node,
which leads to an assertion error at the freezing point of the object
declaration.

gcc/ada/

	* freeze.adb (Freeze_Entity): Protect the call to
	Declaration_Node against entities of expressions replaced by the
	frontend with an N_Raise_CE node.
2022-05-17 08:25:42 +00:00
Javier Miranda
c30e5ab027 [Ada] Spurious error on subprogram with class-wide preconditions
gcc/ada/

	* freeze.adb (Build_DTW_Spec): Do not inherit the not-overriding
	indicator because the DTW wrapper overrides its wrapped
	subprogram.
	* contracts.ads (Make_Class_Precondition_Subps): Adding
	documentation.
2022-05-17 08:25:41 +00:00
Eric Botcazou
d409061404 [Ada] Use Actions field of freeze nodes for subprograms
This has a couple of advantages: 1) the actions are analyzed with checks
disabled and 2) they are considered elaboration code by Sem_Elab.

gcc/ada/

	* exp_ch13.adb (Expand_N_Freeze_Entity): Delete freeze nodes for
	subprograms only if they have no actions.
	* exp_ch6.adb (Freeze_Subprogram): Put the actions into the Actions
	field of the freeze node instead of inserting them after it.
	* sem_elab.adb (Is_SPARK_Semantic_Target): Fix typo in comment.
	* gcc-interface/trans.cc (process_freeze_entity): Return early for
	freeze nodes of subprograms with Interface_Alias set.
2022-05-17 08:25:41 +00:00
Javier Miranda
a08f366ae8 [Ada] Implement calls to abstract subprograms in class-wide pre/post-conditions
In some special cases involving class-wide pre/post conditions, Ada
allows a non-dispatching call to an abstract function (which is usually
illegal).  Fix a bug in the implementation of Ada's rules about the
run-time behavior of such a call. Thanks to Javier Miranda for producing
this patch.

gcc/ada/

	* contracts.adb (Build_Call_Helper_Body): Improve handling of
	the case of a (legal) non-dispatching call to an abstract
	subprogram.
2022-05-17 08:25:41 +00:00
Piotr Trojanek
8fc021c098 [Ada] Fix documentation of using attribute Loop_Entry in pragmas
Attribute Loop_Entry was initially only allowed to appear in pragmas
Loop_Variant and Loop_Invariant. Then it was also allowed to appear in
pragmas Assert, Assert_And_Cut and Assume, but this change was not
reflected in the GNAT RM.

gcc/ada/

	* doc/gnat_rm/implementation_defined_attributes.rst
	(Loop_Entry): Mention pragmas Assert, Assert_And_Cut and Assume;
	refill.
	* gnat_rm.texi: Regenerate.
2022-05-17 08:25:40 +00:00