Commit Graph

194398 Commits

Author SHA1 Message Date
Eric Botcazou
298bbf3c9b [Ada] Use actual types instead of formal types consistently in debug info
This makes sure that the objects present in instantiations always have the
actual type instead of a local variant of the formal type in the debugging
information generated by the compiler (this was already the case when the
actual type is a record, a protected or a task type).

gcc/ada/

	* gcc-interface/decl.cc (Gigi_Cloned_Subtype): New function.
	(gnat_to_gnu_entity) <E_Signed_Integer_Subtype>: Call it to get the
	cloned subtype, if any.
	<E_Floating_Point_Subtype>: Likewise.
	<E_Array_Subtype>: Likewise.
	<E_Record_Subtype>: Likewise.
	<E_Access_Subtype>: Likewise.
	Deal with all cloned subtypes on the main path.
2022-07-13 10:01:20 +00:00
Eric Botcazou
45808a572b [Ada] Generate debug info entry for user-defined access subtype
This is consistent with the other kinds of subtypes.

gcc/ada/

	* gcc-interface/decl.cc (gnat_to_gnu_entity) <E_Access_Subtype>: Do
	not reuse the TYPE_DECL of the base type.
2022-07-13 10:01:20 +00:00
Eric Botcazou
589163e18a [Ada] Do not generate DW_TAG_typedef for constrained array types
It no longer serves any useful purpose at this point.

gcc/ada/

	* gcc-interface/utils.cc (gnat_pushdecl): Build DECL_ORIGINAL_TYPE
	only for pointer types.
2022-07-13 10:01:20 +00:00
Eric Botcazou
d927cb527c [Ada] Fix internal error on comparison with access function parameter
It comes from an overzealous assertion.

gcc/ada/

	* gcc-interface/utils2.cc (build_binary_op) <EQ_EXPR>: Also accept
	pointer-to-function types that are not variant of each other.
2022-07-13 10:01:19 +00:00
Eric Botcazou
2b8c12348d [Ada] Fix internal error on instance of Ada.Task_Attributes at -O
This happens when there is a size mismatch, but this must be accepted.

gcc/ada/

	* gcc-interface/utils.cc (unchecked_convert): Also pad in most cases
	if the source is not a scalar type but the destination is.
2022-07-13 10:01:19 +00:00
Eric Botcazou
6071ef0bed [Ada] Fix wrong access check with access-to-unconstrained-array
The current implementation may create dangling references from a superset
of the alias set of the dummy pointer-to-array type when it exists.

gcc/ada/

	* gcc-interface/decl.cc (gnat_to_gnu_entity) <E_Array_Type>: Save
	and restore the alias set of the dummy pointer-to-array type.
2022-07-13 10:01:19 +00:00
Eric Botcazou
84d3047b14 [Ada] Extend No_Dependence restriction to code generation (continued)
gcc/ada/

	* snames.ads-tmpl (Name_Memory_Compare): New package name.
	(Name_Memory_Copy): Likewise.
	(Name_Memory_Move): Likewise.
	(Name_Memory_Set): Likewise.
2022-07-13 10:01:18 +00:00
Gary Dismukes
d60f61f6a4 [Ada] Fix for bootstrap problem with calling function System.Case_Util.To_Mixed
gcc/ada/

	* sem_ch13.adb (Check_And_Resolve_Storage_Model_Type_Argument):
	Call the System.Case_Util.To_Mixed procedure rather than the
	function, to avoid bootstrap problems.
2022-07-13 10:01:18 +00:00
Gary Dismukes
9f857be34d [Ada] Add support for defaulted Storage_Model_Type aspect and subaspects
The compiler currently rejects a Storage_Model_Type aspect that is not
specified with an aggregate, or that has an aggregate that does not
specify all defined "subaspects" (Address_Type, Null_Address, Allocate,
etc.). The RFC for this feature defines the aspect to fully default to
the native memory model when no aggregate is given, and also allows any
subaspects to be specified and others to default in the case where the
address type is the native address type (System.Address), whether that
address type is explicitly specified or defaulted. This set of changes
now supports that defaulting semantics. Note that the subaspect
retrieval functions in Sem_Util.Storage_Model_Support (which are called
by the compiler back ends) will now return Empty for any subprogram
subaspects (Allocate, Deallocate, etc.) that are defaulted in the aspect
(that is, in the native model case where the address type is
System.Address).  Also in the native case, retrieval of defaulted
subaspects Address_Type and Null_Address will return the entities for
System.Address and System.Null_Address, respectively. Additionally,
error checks for multiple associations given for the same subaspect are
now done.

gcc/ada/

	* aspects.ads (Aspect_Argument): Change the association for
	Aspect_Storage_Model_Type from Expression to
	Optional_Expression.
	* exp_util.ads (Find_Storage_Op): Update comment to indicate
	that Empty can be returned in the case where a storage-model
	operation is defaulted.
	* exp_util.adb (Find_Storage_Op): Allow the function to return
	Empty in Storage_Model_Type case rather than raising
	Program_Error, so that Procedure_To_Call fields in N_Allocator
	and N_Free_Statement nodes will be set to Empty in the defaulted
	native storage-model case.
	* sem_ch13.adb: Add with and use of System.Case_Util (and
	reformat context_clause).
	(Check_Aspect_At_Freeze_Point): Return with no action for a
	Storage_Model_Type aspect with no expression (fully-defaulted
	native memory-model case).
	(Resolve_Storage_Model_Type_Argument): If an Address_Type has
	not been explicitly specified, then set Addr_Type to denote type
	System.Address.
	(Validate_Storage_Model_Type_Aspect): Return immediately in the
	case where the aspect has no Expression (fully-defaulted native
	memory-model case).  No longer issue an error when Address_Type
	isn't specified, and instead use type System.Address as the
	default address type. When the address type is
	System.Address (whether specified or defaulted), no longer issue
	errors for any other "subaspects" that aren't specified, since
	in that case those are allowed to default as well. Remove ???
	comment about needing to check for duplicates, which is now
	addressed.
	(Check_And_Resolve_Storage_Model_Type_Argument): New procedure
	to check that an association for a storage-model subaspect in
	the aggregate has not been specified earlier in the aggregate,
	and to then resolve the expression of the association and save
	the resolved entity. Called by
	Validate_Storage_Model_Type_Aspect.
	* sem_util.ads (Storage_Model_Support): Update comments on specs
	of the functions Get_Storage_Model_Type_Entity,
	Storage_Model_Address_Type, and Storage_Model_Null_Address to
	indicate the behavior when the address type is System.Address
	(the native memory-model case).
	* sem_util.adb
	(Storage_Model_Support.Get_Storage_Model_Type_Entity): Suppress
	the search for the given subaspect name (Nam) when the
	Storage_Model_Type aspect is fully defaulted (i.e., no
	Expression is present) and simply return. In cases where the
	search is done, but no association that matches Nam is found,
	return System.Address for the Name_Address_Type case, return
	System.Null_Address for the Name_Null_Address case, and return
	Empty for all other cases.
2022-07-13 10:01:18 +00:00
Piotr Trojanek
6beeff028f [Ada] Fix for visibility of aspect expressions inside generic units
When a generic unit contains references to global entities (i.e.
entities declared outside of this generic unit), those references are
saved: from the analyzed copy of a generic unit (which is then
discarded) into a generic template (which is then instantiated, possibly
many times). To save those references we maintain an association from
nodes in the generic template to nodes in the analyzed copy. However,
this association breaks when analysis of the generic copy calls
Relocate_Node, which conceptually only moves the node, while in fact it
creates a copy with a new Node_Id.

In particular, this association was broken by calls to Relocate_Node
that happen when transforming various aspects into corresponding pragmas
or attribute definition clases. For the most common Pre and Post aspects
this was fixed years ago by not using Relocate_Node and simply sharing
the tree.  This patch extends this fix to other aspects, in particular
those that allow non-static expressions.

gcc/ada/

	* sem_ch13.adb (Relocate_Expression): New routine with code that
	previously was only applied to Pre and Post aspects.
	(Analyze_Aspect_Specifications): Apply the above routine to
	other aspects, in particular to aspects Address, Attach_Handler,
	Predicate and Interrupt_Priority.
2022-07-13 10:01:17 +00:00
Piotr Trojanek
a714ca803c [Ada] Handle bodies-to-inline just like generic templates
Originally bodies-to-inline created for the frontend inlining were
analyzed with expansion disabled. Then, to facilitate inlining in
GNATprove mode, the analysis was changed to preanalysis.

However, preanalysis in this context works badly for calls in prefix
notation, because preanalysis assigns entities and types to nodes but
doesn't convert calls from prefix to ordinary notation. When the
body-to-inline is actually inlined, the (re)analysis of calls in prefix
notation fails.

The proper solution is rather to handle bodies-to-inline just like
generic templates.

From the user point of view, this patch fixes spurious errors both in
GNATprove (which uses frontend inlining by default) and in GNAT (where
frontend inlining is typically explicitly requested with -gnatN and
pragma Inline_Always).

gcc/ada/

	* inline.adb (Build_Body_To_Inline): Instead of manipulating the
	Full_Analysis flag, use the Inside_A_Generic flag (which is
	conveniently manipulated by Start_Generic/End_Generic, together
	with Expander_Active).
	* sem_attr.adb (Analyze_Attribute_Old_Result): Adapt comment and
	assertion to different flag that is set while building
	body-to-inline.
2022-07-13 10:01:17 +00:00
Alexandre Oliva
4621bae835 [Ada] Clarify hardening command-line options that require explicit choices
Prefixes -fzero-call-used-regs and -fstrub could be mistaken for full
command-line options with the references to them in the GNAT RM.  Make
it clearer that they require explicit choices.

gcc/ada/

	* doc/gnat_rm/security_hardening_features.rst: Clarify the need
	for choices after -fzero-call-used-regs and -fstrub.
	* gnat_rm.texi: Regenerate.
2022-07-13 10:01:17 +00:00
Yannick Moy
8e3030ea9a [Ada] Fix incorrect handling of Ghost aspect
When a formal generic type is marked as Ghost, the instantiation of that
generic will contain a generic subtype for the actual with the Ghost
pragma. Recognize this case.

gcc/ada/

	* sem_prag.adb (Analyze_Pragma): Recognize a generated subtype
	with Ghost pragma for generic instantiations.
2022-07-13 10:01:16 +00:00
Yannick Moy
4709037646 [Ada] Fix proof of runtime unit System.Arith_64
After changes in provers and Why3, changes are needed to recover
automatic proof of System.Arith_64. This is the first part of it.

gcc/ada/

	* libgnat/s-aridou.adb (Lemma_Mult_Div, Lemma_Powers): New
	lemmas.
	(Prove_Sign_Quotient): New local lemma.
	(Prove_Signs): Expand definition of Big_R and Big_Q in the
	postcondition. Add intermediate assertions.
	(Double_Divide): Call new lemma.
	(Lemma_Div_Eq): Provide body for proving lemma.
	(Lemma_Powers_Of_2, Lemma_Shift_Without_Drop,
	Prove_Dividend_Scaling, Prove_Multiplication, Prove_Z_Low): Call
	lemmas, add intermediate assertions.
2022-07-13 10:01:16 +00:00
Piotr Trojanek
d03a7f8c24 [Ada] Fix crash on frontend inlining of functions with single returns
When examining expression of the first declaration of the inlined body
make sure that this declaration is in fact an object declaration.

gcc/ada/

	* inline.adb (Has_Single_Return): Add guard for the subsequent
	call to Expression.
2022-07-13 10:01:16 +00:00
Eric Botcazou
05e91ac1f8 [Ada] Plug legality loophole for equality operator of untagged record types
In Ada 2012, the RM 4.5.2(9.8) clause prevents an equality operator for an
untagged record type from being declared after the type is frozen.  While
the clause is implemented in GNAT, the implementation has a loophole which
lets subprogram bodies that are not the completion of a declaration pass
the check without being flagged.

gcc/ada/

	* sem_ch6.adb (Analyze_Subprogram_Body_Helper): Set Acts_As_Spec
	earlier if the body is not the completion of a declaration.
	(Check_Untagged_Equality): Deal with subprogram bodies that are
	not the completion of a declaration and make sure that they are
	not flagged when they cause the freezing of the type themselves.
	Give a warning on the freezing point of the type in more cases.
	* sem_res.adb (Resolve_Equality_Op): Revert latest change.
2022-07-13 10:01:15 +00:00
Yannick Moy
b872d3fe67 [Ada] Fix automatic proof on System.Arith_32
gcc/ada/

	* libgnat/s-arit32.adb (Scaled_Divide32): Add an assertion, move
	the call of Prove_Sign_R around.
2022-07-13 10:01:15 +00:00
Marc Poulhiès
7a03001cd2 [Ada] Fix if expression returning slice
The compiler incorrectly assumed the prefix for a slice returned in one
branch of an if expression has its bounds known at compile time and would
crash when this is not true.

gcc/ada/

	* exp_ch4.adb (Expand_N_If_Expression): Test for compile time
	known bounds when handling slices.
2022-07-13 10:01:15 +00:00
Eric Botcazou
94425248c7 [Ada] Add cross-references between Integer_Type_For and Small_Integer_Type_For
gcc/ada/

	* exp_util.ads (Integer_Type_For): Mention Small_Integer_Type_For.
	(Small_Integer_Type_For): Mention Integer_Type_For.
2022-07-13 10:01:14 +00:00
Eric Botcazou
6faa271f09 [Ada] Fix internal error on untagged record type with equality operator
After the binding interpretation issued under AI12-0413, a user-defined
primitive equality operator of an untagged record type hides the predefined
equality operator in an instantiation, but this does not apply if the
instantiation appears in the same declarative region as the type and
before the declaration of this user-defined operator.

gcc/ada/

	* sem_res.adb (Resolve_Equality_Op): Make sure that the user-defined
	operator of an untagged record type is declared ahead of an instance
	before using it to resolve the equality operator in the instance.
2022-07-13 10:01:14 +00:00
Justin Squirek
730814edc8 [Ada] Fix CodePeer warnings in GNAT sources
This patch fixes various redundant constructs or uninitialized variables
identified by CodePeer in the GNAT frontend and runtime sources.

gcc/ada/

	* exp_ch6.adb (Expand_N_Extended_Return_Statement): Add default
	initialization for Stmts.
	* sem_ch12.adb (Analyze_Associations): Add default
	initialization for Match.
	* libgnat/a-ztenau.adb (Scan_Enum_Lit): Remove duplicated
	boolean test.
	* libgnat/g-spipat.adb (XMatch): Combine duplicated cases.
2022-07-13 10:01:14 +00:00
Piotr Trojanek
1d73dfb5e6 [Ada] Refine type for checking number of pragma arguments
Code cleanup.

gcc/ada/

	* par-prag.adb (Check_Arg_Count): Change parameter type from Int
	to Nat, because this parameter is compared to Arg_Count variable
	which is of type Nat. Also, it wouldn't make sense to check for
	negative number of pragma arguments.
2022-07-13 10:01:13 +00:00
Andrew Carlotti
e9cad1e582 aarch64: Don't return invalid GIMPLE assign statements
aarch64_general_gimple_fold_builtin doesn't check whether the LHS of a
function call is null before converting it to an assign statement. To avoid
returning an invalid GIMPLE statement in this case, we instead assign the
expression result to a new (unused) variable.

This change only affects code that:
1) Calls an intrinsic function that has no side effects;
2) Does not use or store the value returned by the intrinsic;
3) Uses parameters that prevent the front-end eliminating the call prior to
gimplification.

The ICE is unlikely to have occurred in the wild, as it relies on the presence
of a redundant intrinsic call.

gcc/ChangeLog:

	* config/aarch64/aarch64-builtins.cc
	(aarch64_general_gimple_fold_builtin): Add fixup for invalid GIMPLE.

gcc/testsuite/ChangeLog:

	* gcc.target/aarch64/advsimd-intrinsics/ignored_return_1.c: New test.
2022-07-13 09:01:51 +01:00
Richard Biener
c479c40f8c tree-optimization/106249 - unroll-and-jam and LC SSA upate
When I delayed the LC SSA update in unroll-and-jam this exposed
an issue that tree_transform_and_unroll_loop does a full function
LC SSA verification when new_loop is NULL (when it doesn't need to
do versioning).  That wasn't intended.  I also took the chance
to make the versioning in tree_transform_and_unroll_loop use
TODO_update_ssa_nophi for the loop versioning SSA update which
I somehow missed earlier.

	PR tree-optimization/106249
	* tree-ssa-loop-manip.cc (tree_transform_and_unroll_loop):
	Only verify LC SSA of the new_loop if we created it.
	Use TODO_update_ssa_nophi for the SSA update after versioning
	the loop.

	* gcc.dg/pr106249.c: New testcase.
2022-07-13 08:30:44 +02:00
GCC Administrator
43997608a0 Daily bump. 2022-07-13 00:16:33 +00:00
Jonathan Wakely
5ae74944af libstdc++: Check for EOF if extraction avoids buffer overflow [PR106248]
In r11-2581-g17abcc77341584 (for LWG 2499) I added overflow checks to
the pre-C++20 operator>>(istream&, char*) overload.  Those checks can
cause extraction to stop after filling the buffer, where previously it
would have tried to extract another character and stopped at EOF. When
that happens we no longer set eofbit in the stream state, which is
consistent with the behaviour of the new C++20 overload, but is an
observable and unexpected change in the C++17 behaviour. What makes it
worse is that the behaviour change is dependent on optimization, because
__builtin_object_size is used to detect the buffer size and that only
works when optimizing.

To avoid the unexpected and optimization-dependent change in behaviour,
set eofbit manually if we stopped extracting because of the buffer size
check, but had reached EOF anyway. If the stream's rdstate() != goodbit
or width() is non-zero and smaller than the buffer, there's nothing to
do. Otherwise, we filled the buffer and need to check for EOF, and maybe
set eofbit.

The new check is guarded by #ifdef __OPTIMIZE__ because otherwise
__builtin_object_size is useless. There's no point compiling and
emitting dead code that can't be eliminated because we're not
optimizing.

We could add extra checks that the next character in the buffer is not
whitespace, to detect the case where we stopped early and prevented a
buffer overflow that would have happened otherwise. That would allow us
to assert or set badbit in the stream state when undefined behaviour was
prevented. However, those extra checks would increase the size of the
function, potentially reducing the likelihood of it being inlined, and
so making the buffer size detection less reliable. It seems preferable
to prevent UB and silently truncate, rather than miss the UB and allow
the overflow to happen.

libstdc++-v3/ChangeLog:

	PR libstdc++/106248
	* include/std/istream [C++17] (operator>>(istream&, char*)):
	Set eofbit if we stopped extracting at EOF.
	* testsuite/27_io/basic_istream/extractors_character/char/pr106248.cc:
	New test.
	* testsuite/27_io/basic_istream/extractors_character/wchar_t/pr106248.cc:
	New test.
2022-07-12 23:35:28 +01:00
Harald Anlauf
6e9d5dfc29 Fortran: error recovery simplifying PACK with invalid arguments [PR106049]
gcc/fortran/ChangeLog:

	PR fortran/106049
	* simplify.cc (is_constant_array_expr): A non-zero-sized constant
	array shall have a non-empty constructor.  When the constructor is
	empty or missing, treat as non-constant.

gcc/testsuite/ChangeLog:

	PR fortran/106049
	* gfortran.dg/pack_simplify_1.f90: New test.
2022-07-12 19:18:19 +02:00
Aldy Hernandez
cab411a2b4 Set nonzero bits from bitwise and operator in range-ops.
Now that nonzero bits are first class citizens in the range, we can
keep better track of them in range-ops, especially the bitwise and
operator.

This patch sets the nonzero mask for the trivial case.  In doing so,
I've removed some old dead code that was an attempt to keep better
track of masks.

I'm sure there are tons of optimizations throughout range-ops that
could be implemented, especially the op1_range methods, but those
always make my head hurt.  I'll leave them to the smarter hackers
out there.

I've removed the restriction that nonzero bits can't be queried from
legacy.  This was causing special casing all over the place, and
it's not like we can generate incorrect code.  We just silently
drop nonzero bits to -1 in some of the legacy code.  The end result
is that VRP1, and other users of legacy, may not benefit from these
improvements.

Tested and benchmarked on x86-64 Linux.

gcc/ChangeLog:

	* range-op.cc (unsigned_singleton_p): Remove.
	(operator_bitwise_and::remove_impossible_ranges): Remove.
	(operator_bitwise_and::fold_range): Set nonzero bits.  *
	* value-range.cc (irange::get_nonzero_bits): Remove
	legacy_mode_p assert.
	(irange::dump_bitmasks): Remove legacy_mode_p check.
2022-07-12 16:40:51 +02:00
Martin Liska
32a753506b lto-plugin: implement LDPT_GET_API_VERSION
include/ChangeLog:

	* plugin-api.h (enum linker_api_version): New enum.
	(ld_plugin_get_api_version): New.
	(enum ld_plugin_tag): Add LDPT_GET_API_VERSION.
	(struct ld_plugin_tv): Add tv_get_api_version.

lto-plugin/ChangeLog:

	* lto-plugin.c (negotiate_api_version): New.
	(onload): Negotiate API version.
	* Makefile.am: Add -DBASE_VERSION.
	* Makefile.in: Regenerate.
2022-07-12 15:26:57 +02:00
Richard Sandiford
00eab0c654 Add internal functions for iround etc. [PR106253]
The PR is about the aarch64 port using an ACLE built-in function
to vectorise a scalar function call, even though the ECF_* flags for
the ACLE function didn't match the ECF_* flags for the scalar call.

To some extent that kind of difference is inevitable, since the
ACLE intrinsics are supposed to follow the behaviour of the
underlying instruction as closely as possible.  Also, using
target-specific builtins has the drawback of limiting further
gimple optimisation, since the gimple optimisers won't know what
the function does.

We handle several other maths functions, including round, floor
and ceil, by defining directly-mapped internal functions that
are linked to the associated built-in functions.  This has two
main advantages:

- it means that, internally, we are not restricted to the set of
  scalar types that happen to have associated C/C++ functions

- the functions (and thus the underlying optabs) extend naturally
  to vectors

This patch takes the same approach for the remaining functions
handled by aarch64_builtin_vectorized_function.

gcc/
	PR target/106253
	* predict.h (insn_optimization_type): Declare.
	* predict.cc (insn_optimization_type): New function.
	* internal-fn.def (IFN_ICEIL, IFN_IFLOOR, IFN_IRINT, IFN_IROUND)
	(IFN_LCEIL, IFN_LFLOOR, IFN_LRINT, IFN_LROUND, IFN_LLCEIL)
	(IFN_LLFLOOR, IFN_LLRINT, IFN_LLROUND): New internal functions.
	* internal-fn.cc (unary_convert_direct): New macro.
	(expand_convert_optab_fn): New function.
	(expand_unary_convert_optab_fn): New macro.
	(direct_unary_convert_optab_supported_p): Likewise.
	* optabs.cc (expand_sfix_optab): Pass insn_optimization_type to
	convert_optab_handler.
	* config/aarch64/aarch64-protos.h
	(aarch64_builtin_vectorized_function): Delete.
	* config/aarch64/aarch64-builtins.cc
	(aarch64_builtin_vectorized_function): Delete.
	* config/aarch64/aarch64.cc
	(TARGET_VECTORIZE_BUILTIN_VECTORIZED_FUNCTION): Delete.
	* config/i386/i386.cc (ix86_optab_supported_p): Handle lround_optab.
	* config/i386/i386.md (lround<X87MODEF:mode><SWI248x:mode>2): Remove
	optimize_insn_for_size_p test.

gcc/testsuite/
	PR target/106253
	* gcc.target/aarch64/vect_unary_1.c: Add tests for iroundf,
	llround, iceilf, llceil, ifloorf, llfloor, irintf and llrint.
	* gfortran.dg/vect/pr106253.f: New test.
2022-07-12 14:09:44 +01:00
Richard Biener
9b06b9d237 Remove create_lcssa_for_virtual_phi and uses
The following expands the comment in vect_do_peeling as to why we
do not need create_lcssa_for_virtual_phi and removes that function.

That's the last bit I have queued for the vectorizer virtual LCSSA
cleanup.

	* tree-vect-loop-manip.cc (create_lcssa_for_virtual_phi):
	Remove.
	(vect_do_peeling): Do not call it, adjust comment.
2022-07-12 14:40:39 +02:00
Piotr Trojanek
7005b5e57e [Ada] Fix inconsistent comment about expansion of exception declarations
Code cleanup.

gcc/ada/

	* exp_ch11.adb (Expand_N_Exception_Declaration): Sync comment
	with declaration in System.Standard_Library.
2022-07-12 12:24:15 +00:00
Marc Poulhiès
6e3c2ee1d1 [Ada] Fix 0-sized secondary stack allocations
The Has_Enough_Free_Memory was not correctly reporting a completely full
chunk in the case of a 0-sized allocation.

gcc/ada/

	* libgnat/s-secsta.adb (Has_Enough_Free_Memory): Check for full
	chunk before computing the available size.
2022-07-12 12:24:15 +00:00
Steve Baird
33338e7289 [Ada] Use right implementation type for nonbinary-modulus ops
If the flag Opt.Expand_Nonbinary_Modular_Ops is set (which occurs if
-gnateg is specified) then we implement predefined operations for a
modular type whose modulus is not a power of two by converting the
operands to some other type (either a signed integer type or a modular
type with a power-of-two modulus), doing the operation in that
representation, and converting back.  If the bounds of the chosen type
are too narrow, then problems with intermediate overflow can result. But
there are performance advantages to choosing narrower bounds (and to
prefering an unsigned choice over a signed choice of the same size) when
multiple safe choices are available.

gcc/ada/

	* exp_ch4.adb (Expand_Nonbinary_Modular_Op.Expand_Modular_Op):
	Reimplement choice of which predefined type to use for the
	implementation of a predefined operation of a modular type with
	a non-power-of-two modulus.
2022-07-12 12:24:14 +00:00
Justin Squirek
729d2e2a80 [Ada] Spurious use_type clause warning
This patch corrects an error in the compiler whereby a spurious
redundant use_type_clause warning gets issued when the clause appears in
the context_clause of a package preceding a with_clause for a package
with an identical use_clause in its specification.

gcc/ada/

	* einfo.ads: Modify documentation for In_Use flag to include
	scope stack manipulation.
	* sem_ch8.adb (Use_One_Type): Add condition to return when
	attempting to detect redundant use_type_clauses in child units
	in certain cases.
2022-07-12 12:24:14 +00:00
Eric Botcazou
433cefcd02 [Ada] Extend No_Dependence restriction to code generation
This makes it possible to report violations of the No_Dependence restriction
during code generation, in other words outside of the Ada front-end proper.
These violations are supposed to be only for child units of System, so the
implementation is restricted to these cases.

gcc/ada/

	* restrict.ads (type ND_Entry): Add System_Child component.
	(Check_Restriction_No_Dependence_On_System): Declare.
	* restrict.adb (Global_Restriction_No_Tasking): Move around.
	(Violation_Of_No_Dependence): New procedure.
	(Check_Restriction_No_Dependence): Call Violation_Of_No_Dependence
	to report a violation.
	(Check_Restriction_No_Dependence_On_System): New procedure.
	(Set_Restriction_No_Dependenc): Set System_Child component if the
	unit is a child of System.
	* snames.ads-tmpl (Name_Arith_64): New package name.
	(Name_Arith_128): Likewise.
	(Name_Memory): Likewise.
	(Name_Stack_Checking): Likewise.
	* fe.h (Check_Restriction_No_Dependence_On_System): Declare.
2022-07-12 12:24:14 +00:00
Bob Duff
0ff936fe86 [Ada] Ada 2020: Allow declarative items mixed with statements
This patch implements a syntactic language extension that allows
declarative items to appear in a sequence of statements.  For example:

    for X in S'Range loop
        Item : Character renames S (X);
        Item := Transform (Item);
    end loop;

Previously, declare/begin/end was required, which is just noise.

gcc/ada/

	* par.adb (P_Declarative_Items): New function to parse a
	sequence of declarative items.
	(P_Sequence_Of_Statements): Add Handled flag, to indicate
	whether to wrap the result in a block statement.
	* par-ch3.adb (P_Declarative_Item): Rename P_Declarative_Items
	to be P_Declarative_Item, because it really only parses a single
	declarative item, and to avoid conflict with the new
	P_Declarative_Items. Add In_Statements.  We keep the old
	error-recovery mechanisms in place when In_Statements is False.
	When True, we don't want to complain about statements, because
	we are parsing a sequence of statements.
	(P_Identifier_Declarations): If In_Statements, and we see what
	looks like a statement, we no longer give an error. We return to
	P_Sequence_Of_Statements with Done = True, so it can parse the
	statement.
	* par-ch5.adb (P_Sequence_Of_Statements): Call
	P_Declarative_Items to parse declarative items that appear in
	the statement list.  Remove error handling code that complained
	about such items.  Check some errors conservatively.  Wrap the
	result in a block statement when necessary.
	* par-ch11.adb (P_Handled_Sequence_Of_Statements): Pass
	Handled => True to P_Sequence_Of_Statements.
	* types.ads (No, Present): New functions for querying
	Source_Ptrs (equal, not equal No_Location).
2022-07-12 12:24:14 +00:00
Piotr Trojanek
2b98bb583f [Ada] Don't check for misspelling of Not_A_Restriction_Id
When looking for a misspelling of a restriction identifier we should
ignore the Not_A_Restriction_Id literal, because it doesn't represent
any restriction.

gcc/ada/

	* sem_prag.adb (Process_Restrictions_Or_Restriction_Warnings):
	Fix range of iteration.
2022-07-12 12:24:14 +00:00
Piotr Trojanek
7e5a0317ad [Ada] Fix confusing error expression on an unknown restriction
When pragma Restriction is used with an unknown restriction identifier,
it is better to not process the restriction expression, as it will
likely produce confusing error message.

In particular, an odd message appeared when there was a typo in the
restriction identifier whose expression requires special processing
(e.g.  No_Dependence_On instead of No_Dependence).

gcc/ada/

	* sem_prag.adb (Process_Restrictions_Or_Restriction_Warnings):
	Do not process expression of unknown restrictions.
2022-07-12 12:24:14 +00:00
Vasiliy Fofanov
3a7a02f435 [Ada] Make it clear that gnatmake passes the ball to gprbuild if -P is set
Also move -P switch description to the top of the switches list.

gcc/ada/

	* makeusg.adb,
	doc/gnat_ugn/building_executable_programs_with_gnat.rst: Move -P
	to the top of switches list and make it clear that gnatmake
	passes the ball to gprbuild if -P is set.
	* gnat_ugn.texi: Regenerate.
2022-07-12 12:24:13 +00:00
Bob Duff
fa7ea64706 [Ada] Suppress warning in g-socthi__vxworks.adb
Follow-on to previous change, which missed the vxworks version of this
package.

gcc/ada/

	* libgnat/g-socthi__vxworks.adb (C_Connect): Suppress new warning.
2022-07-12 12:24:13 +00:00
Piotr Trojanek
a24614ec49 [Ada] Simplify rewriting of attributes into Boolean literals
Code cleanup; semantics is unaffected.

gcc/ada/

	* sem_attr.adb (Set_Boolean_Result): Simplify using
	Boolean_Literals.
2022-07-12 12:24:13 +00:00
Yannick Moy
f40948963b [Ada] Ignore switches for controlling frontend warnings in GNATprove mode
In the special mode for GNATprove, ignore switches controlling frontend
warnings, like already done for the control of style checks warnings.
Also remove special handling of warning mode in Errout to make up for
the previous division of control between -gnatw (GNAT) and --warnings
(GNATprove).

gcc/ada/

	* errout.adb (Record_Compilation_Errors): Remove global
	variable.
	(Compilation_Errors): Simplify.
	(Initialize): Inline Reset_Warnings.
	(Reset_Warnings): Remove.
	* errout.ads (Reset_Warnings): Remove.
	(Compilation_Errors): Update comment.
	* gnat1drv.adb (Adjust_Global_Switches): Ignore all frontend
	warnings in GNATprove mode, except regarding elaboration and
	suspicious contracts.
2022-07-12 12:24:13 +00:00
Eric Botcazou
570f43b823 [Ada] Do not create large objects for indefinite protected types
This plugs a small loophole in the Needs_Secondary_Stack predicate for
some protected types and record types containing protected components.

gcc/ada/

	* sem_util.adb (Caller_Known_Size_Record): Make entry assertion
	more robust and add guard for null argument.  For protected
	types, invoke Caller_Known_Size_Record on
	Corresponding_Record_Type.
	(Needs_Secondary_Stack): Likewise.
2022-07-12 12:24:13 +00:00
Doug Rupp
70c3959a8a [Ada] Vxworks7* - Makefile.rtl rtp vs rtp-smp cleanup - remove unused files
Only smp runtimes are built for vxworks7*, even though the -smp suffix
is removed during install. This change removes unused system packages
for rtp runtimes.

gcc/ada/

	* libgnat/system-vxworks7-ppc-rtp.ads: Remove
	* libgnat/system-vxworks7-x86-rtp.ads: Likewise.
2022-07-12 12:24:13 +00:00
Piotr Trojanek
4fc09105aa [Ada] Fix spurious warning on unreferenced internal generic instance
This patch removes a spurious warning, saying that an internal entity of
a generic formal package is unreferenced. The immediate cause of this
warning is that the internal entity is explicitly flagged as coming from
source.

The explicit flagging was added decades ago to fix a missing
cross-reference in the ALI file. Apparently these days the
cross-references work fine without this flag.

gcc/ada/

	* sem_ch12.adb (Analyze_Package_Instantiation): Remove dubious
	call to Set_Comes_From_Source.
2022-07-12 12:24:12 +00:00
Bob Duff
e124352c0a [Ada] Refine heuristics for unreachable-code warnings
This patch refines the heuristics for when we warn about unreachable
code, to avoid common false alarms.

gcc/ada/

	* sem_ch5.adb (Check_Unreachable_Code): Refine heuristics.
	* sem_util.ads, sem_util.adb (Is_Static_Constant_Name): Remove
	this; instead we have a new function Is_Simple_Case in
	Sem_Ch5.Check_Unreachable_Code.
2022-07-12 12:24:12 +00:00
Bob Duff
6a64ee3903 [Ada] Remove out-of-range warning in unreachable code
This patch removes a warning in examples like this:

    if cond then
       return; -- or other jump
    end if;
    X := ...; -- where the value is out of range

where cond is known at compile time. It could, for example, be a generic
formal parameter that is known to be True in some instances.

As a side effect, this patch adds new warnings about unreachable code.

gcc/ada/

	* gnatls.adb (Output_License_Information): Remove pragma
	No_Return; call sites deal with Exit_Program.
	* libgnat/g-socthi.adb (C_Connect): Suppress warning about
	unreachable code.
	* sem_ch5.adb (Check_Unreachable_Code): Special-case if
	statements with static conditions.  If we remove unreachable
	code (including the return statement) from a function, add
	"raise Program_Error", so we won't warn about missing returns.
	Remove Original_Node in test for N_Raise_Statement; it's not
	needed.  Remove test for CodePeer_Mode; if Operating_Mode =
	Generate_Code, then CodePeer_Mode can't be True.  Misc cleanup.
	Do not reuse Nxt variable for unrelated purpose (the usage in
	the Kill_Dead_Code loop is entirely local to the loop).
	* sem_ch6.adb: Add check for Is_Transfer. Misc cleanup.
	* sem_prag.adb: Minor.
	* sem_res.adb: Minor.
	* sem_util.adb: Minor cleanup.
	(Is_Trivial_Boolean): Move to nonnested place, so it can be
	called from elsewhere.
	(Is_Static_Constant_Boolean): New function.
	* sem_util.ads (Is_Trivial_Boolean): Export.
	(Is_Static_Constant_Boolean): New function.
2022-07-12 12:24:12 +00:00
Eric Botcazou
6882d60a10 [Ada] Add one more leading underscore to couple of exported symbols
For the sake of consistency with other runtime units.

gcc/ada/

	* libgnat/s-stchop.ads: Use a double underscore prefix for symbols.
2022-07-12 12:24:12 +00:00
Ed Schonberg
be4ab2ae01 [Ada] Proper freezing for dispatching expression functions.
In the case of an expression function that is a primitive function of a
tagged type, freezing the tagged type needs to freeze the function (and
its return expression). A bug in this area could result in incorrect
behavior both at compile time and at run time. At compile time, freezing
rule violations could go undetected so that an illegal program could be
incorrectly accepted. At run time, a dispatching call to the primitive
function could end up dispatching through a not-yet-initialized slot in
the dispatch table, typically (although not always) resulting in a
segmentation fault.

gcc/ada/

	* freeze.adb (Check_Expression_Function.Find_Constant): Add a
	check that a type that is referenced as the prefix of an
	attribute is fully declared.
	(Freeze_And_Append): Do not freeze the profile when freezing an
	expression function.
	(Freeze_Entity): When a tagged type is frozen, also freeze any
	primitive operations of the type that are expression functions.
	* sem_ch6.adb (Analyze_Subprogram_Body_Helper): Do not prevent
	freezing associated with an expression function body if the
	function is a dispatching op.
2022-07-12 12:24:12 +00:00