Commit graph

193350 commits

Author SHA1 Message Date
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
Etienne Servais
7cff43618e [Ada] Check token to be "access", reject it if not
The parser skips the token without verifying it is indeed "access".  So
any token is accepted.

gcc/ada/

	* par-ch3.adb (P_Access_Type_Definition): Outputs an error if
	token is not "access".
2022-05-17 08:25:40 +00:00
Piotr Trojanek
bc17882341 [Ada] Enable current value propagation within pragma expressions
This patch fixes an odd incomplete optimization within pragma
expressions. For example, in this code:

   X := True;
   pragma Assert (X = True);
   pragma Assert (X);

the first assertion was eliminated by the frontend (regardless of the
optimization switches), while the second assertion was only eliminated
by the backend and only with switch -O1 or similar.

The problem was that the current value propagation was disabled for
references immediately within pragma argument associations. This was
meant to avoid a crash when such a reference appears in pragma
Inspection_Point, but this wasn't a proper fix. The proper solution is
rather to not expand references in pragma Inspection_Point at all.

Actually, this expansion was enabled to avoid a yet another crash, when
the parameter of pragma Inspection_Point is a prival (i.e. a renaming of
private protected component). It turns out that none of these suspicious
problematic fixes is no longer necessary.

Cleanup related to fixes of current value propagation in expansion of
attribute Loop_Entry.

gcc/ada/

	* exp_ch2.adb (Expand_Current_Value): Remove special case for
	references immediately within pragma argument associations.
	* exp_prag.adb (Expand_Pragma_Inspection_Point): Remove special
	case for privals.
2022-05-17 08:25:40 +00:00
Jakub Jelinek
bc9aa450eb forwprop: Fix a typo and comment formatting
When looking around the spot of the PR105591 fix, I've noticed a typo
and incorrectly formatted comment.

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

	* tree-ssa-forwprop.cc (simplify_bitfield_ref): Spelling fix:
	hanlde -> handle.  Fix up comment formatting.
2022-05-17 09:06:55 +02:00
liuhongt
105c56a8cf Optimize vpermtiw/b to vpunpcklqdq for certain cases.
Assembly Optimization like:
-       vmovq   %xmm0, %xmm2
-       vmovdqa .LC0(%rip), %xmm0
        vmovq   %xmm1, %xmm1
-       vpermi2w        %xmm1, %xmm2, %xmm0
+       vmovq   %xmm0, %xmm0
+       vpunpcklqdq     %xmm1, %xmm0, %xmm0

...

-.LC0:
-       .value  0
-       .value  1
-       .value  2
-       .value  3
-       .value  8
-       .value  9
-       .value  10
-       .value  11

gcc/ChangeLog:

	PR target/105033
	* config/i386/sse.md (*vec_concatv4si): Extend to ..
	(*vec_concat<mode>): .. V16QI and V8HImode.
	(*vec_concatv16qi_permt2): New pre_reload define_insn_and_split.
	(*vec_concatv8hi_permt2): Ditto.

gcc/testsuite/ChangeLog:

	* gcc.target/i386/pr105033.c: New test.
2022-05-17 09:30:22 +08:00
liuhongt
1fba0608d1 Clamp vec_perm_expr index in simplify_bitfield_ref to avoid ICE.
gcc/ChangeLog:

	PR tree-optimization/105591
	* tree-ssa-forwprop.cc (simplify_bitfield_ref): Clamp
	vec_perm_expr index.

gcc/testsuite/ChangeLog:

	* gcc.dg/pr105591.c: New test.
2022-05-17 08:59:42 +08:00
GCC Administrator
702bd11fa7 Daily bump. 2022-05-17 00:16:28 +00:00
Jason Merrill
ed12749a3c attribs: fix typedefs in generic code [PR105492]
In my patch for PR100545 I added an assert to check for broken typedefs in
set_underlying_type, and it found one in this case:
rs6000_handle_altivec_attribute had the same problem as
handle_mode_attribute.  So let's move the fixup into decl_attributes.

	PR c/105492

gcc/ChangeLog:

	* attribs.cc (decl_attributes): Fix broken typedefs here.

gcc/c-family/ChangeLog:

	* c-attribs.cc (handle_mode_attribute): Don't fix broken typedefs
	here.
2022-05-16 17:32:46 -04:00
David Malcolm
2402dc6b98 analyzer: implement four new warnings for <stdarg.h> misuses [PR105103]
This patch adds support to the analyzer for checking usage of <stdarg.h>,
with four new warnings.

It adds:
(a) a state-machine for tracking "started" and "ended" states on va_list
instances, implementing two new warnings:
  -Wanalyzer-va-list-leak
    for complaining about missing va_end after a va_start or va_copy
  -Wanalyzer-va-list-use-after-va-end:
    for complaining about va_arg or va_copy used on a va_list that's had
    va_end called on it

(b) interprocedural tracking of variadic parameters, tracking symbolic
values, implementing two new warnings:
  -Wanalyzer-va-arg-type-mismatch
     for type-checking va_arg usage against the types of the parameters
     that were actually passed to the variadic call
  -Wanalyzer-va-list-exhausted
     for complaining if va_arg is used too many times on a va_list

Here's an LTO example of a type mismatch in a variadic call that
straddles two source files:

stdarg-lto-1-a.c: In function 'called_by_test_type_mismatch_1':
stdarg-lto-1-a.c:19:7: warning: 'va_arg' expected 'const char *' but
 received 'int' for variadic argument 1 of 'ap' [-Wanalyzer-va-arg-type-mismatch]
   19 |   str = va_arg (ap, const char *);
      |       ^
  'test_type_mismatch_1': events 1-2
    |
    |stdarg-lto-1-b.c:3:6:
    |    3 | void test_type_mismatch_1 (void)
    |      |      ^
    |      |      |
    |      |      (1) entry to 'test_type_mismatch_1'
    |    4 | {
    |    5 |   called_by_test_type_mismatch_1 (42, 1066);
    |      |   ~
    |      |   |
    |      |   (2) calling 'called_by_test_type_mismatch_1' from 'test_type_mismatch_1' with 1 variadic argument
    |
    +--> 'called_by_test_type_mismatch_1': events 3-4
           |
           |stdarg-lto-1-a.c:12:1:
           |   12 | called_by_test_type_mismatch_1 (int placeholder, ...)
           |      | ^
           |      | |
           |      | (3) entry to 'called_by_test_type_mismatch_1'
           |......
           |   19 |   str = va_arg (ap, const char *);
           |      |       ~
           |      |       |
           |      |       (4) 'va_arg' expected 'const char *' but received 'int' for variadic argument 1 of 'ap'
           |

gcc/ChangeLog:
	PR analyzer/105103
	* Makefile.in (ANALYZER_OBJS): Add analyzer/varargs.o.
	* doc/invoke.texi: Add -Wanalyzer-va-arg-type-mismatch,
	-Wanalyzer-va-list-exhausted, -Wanalyzer-va-list-leak, and
	-Wanalyzer-va-list-use-after-va-end.

gcc/analyzer/ChangeLog:
	PR analyzer/105103
	* analyzer.cc (make_label_text_n): New.
	* analyzer.h (class var_arg_region): New forward decl.
	(make_label_text_n): New decl.
	* analyzer.opt (Wanalyzer-va-arg-type-mismatch): New option.
	(Wanalyzer-va-list-exhausted): New option.
	(Wanalyzer-va-list-leak): New option.
	(Wanalyzer-va-list-use-after-va-end): New option.
	* checker-path.cc (call_event::get_desc): Split out decl access
	into..
	(call_event::get_caller_fndecl): ...this new function and...
	(call_event::get_callee_fndecl): ...this new function.
	* checker-path.h (call_event::get_desc): Drop "FINAL".
	(call_event::get_caller_fndecl): New decl.
	(call_event::get_callee_fndecl): New decl.
	(class call_event): Make fields protected.
	* diagnostic-manager.cc (null_assignment_sm_context::warn): New
	overload.
	(null_assignment_sm_context::get_new_program_state): New.
	(diagnostic_manager::add_events_for_superedge): Move case
	SUPEREDGE_CALL to a new pending_diagnostic::add_call_event vfunc.
	* engine.cc (impl_sm_context::warn): Implement new override.
	(impl_sm_context::get_new_program_state): New.
	* pending-diagnostic.cc: Include "analyzer/diagnostic-manager.h",
	"cpplib.h", "digraph.h", "ordered-hash-map.h", "cfg.h",
	"basic-block.h", "gimple.h", "gimple-iterator.h", "cgraph.h"
	"analyzer/supergraph.h", "analyzer/program-state.h",
	"alloc-pool.h", "fibonacci_heap.h", "shortest-paths.h",
	"sbitmap.h", "analyzer/exploded-graph.h", "diagnostic-path.h",
	and "analyzer/checker-path.h".
	(ht_ident_eq): New.
	(fixup_location_in_macro_p): New.
	(pending_diagnostic::fixup_location): New.
	(pending_diagnostic::add_call_event): New.
	* pending-diagnostic.h (pending_diagnostic::fixup_location): Drop
	no-op inline implementation in favor of the more complex
	implementation above.
	(pending_diagnostic::add_call_event): New vfunc.
	* region-model-impl-calls.cc: Include "analyzer/sm.h",
	"diagnostic-path.h", and "analyzer/pending-diagnostic.h".
	* region-model-manager.cc
	(region_model_manager::get_var_arg_region): New.
	(region_model_manager::log_stats): Log m_var_arg_regions.
	* region-model.cc (region_model::on_call_pre): Handle IFN_VA_ARG,
	BUILT_IN_VA_START, and BUILT_IN_VA_COPY.
	(region_model::on_call_post): Handle BUILT_IN_VA_END.
	(region_model::get_representative_path_var_1): Handle RK_VAR_ARG.
	(region_model::push_frame): Push variadic arguments.
	* region-model.h (region_model_manager::get_var_arg_region): New
	decl.
	(region_model_manager::m_var_arg_regions): New field.
	(region_model::impl_call_va_start): New decl.
	(region_model::impl_call_va_copy): New decl.
	(region_model::impl_call_va_arg): New decl.
	(region_model::impl_call_va_end): New decl.
	* region.cc (alloca_region::dump_to_pp): Dump the id.
	(var_arg_region::dump_to_pp): New.
	(var_arg_region::get_frame_region): New.
	* region.h (enum region_kind): Add RK_VAR_ARG.
	(region::dyn_cast_var_arg_region): New.
	(class var_arg_region): New.
	(is_a_helper <const var_arg_region *>::test): New.
	(struct default_hash_traits<var_arg_region::key_t>): New.
	* sm.cc (make_checkers): Call make_va_list_state_machine.
	* sm.h (sm_context::warn): New vfunc.
	(sm_context::get_old_svalue): Drop unused decl.
	(sm_context::get_new_program_state): New vfunc.
	(make_va_list_state_machine): New decl.
	* varargs.cc: New file.

gcc/testsuite/ChangeLog:
	PR analyzer/105103
	* gcc.dg/analyzer/stdarg-1.c: New test.
	* gcc.dg/analyzer/stdarg-2.c: New test.
	* gcc.dg/analyzer/stdarg-fmtstring-1.c: New test.
	* gcc.dg/analyzer/stdarg-lto-1-a.c: New test.
	* gcc.dg/analyzer/stdarg-lto-1-b.c: New test.
	* gcc.dg/analyzer/stdarg-lto-1.h: New test.
	* gcc.dg/analyzer/stdarg-sentinel-1.c: New test.
	* gcc.dg/analyzer/stdarg-types-1.c: New test.
	* gcc.dg/analyzer/stdarg-types-2.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2022-05-16 15:34:09 -04:00
Iain Buclaw
5eb9927aae d: Merge upstream dmd 60bfa0ee7, druntime 94bd5bcb, phobos 3a1cd9a01.
D front-end changes:

    - Import dmd v2.100.0.
    - Add bit fields to D, enabled via the -fpreview=bitfields switch.
    - Removed the -ftransition=markdown and -frevert=markdown switches.
    - Added new trait `__traits(classInstanceAlignment)' to provide the
      required data alignment for classes.
    - The check for `pragma(crt_constructor)' and `pragma(crt_destructor)'
      linkage has been relaxed to allow all `void()' signatures.
    - ImportC parser now recognizes the `typeof(...)' operator.

D runtime changes:

    - Import druntime v2.100.0.

Phobos changes:

    - Import phobos v2.100.0.
    - To comply with dip1000, `std.socket.Socket` methods now accept only
      `scope' arrays.
    - The `fill', `alignSize', `align2', and `align4' methods of
      `std.outbuffer.OutBuffer' have been extended to allow specifying a custom
      value when pre-filling or padding the buffer.

gcc/d/ChangeLog:

	* dmd/MERGE: Merge upstream dmd 60bfa0ee7.
	* dmd/VERSION: Update version to v2.100.0.
	* d-builtins.cc (d_init_versions): Update for new front-end interface.
	* d-codegen.cc (d_decl_context): Use resolvedLinkage to get
	declaration linkage.
	(build_struct_literal): Track offset in bits.
	* d-gimplify.cc (d_gimplify_modify_expr): Check both operands for a
	bit-field reference.
	* d-lang.cc (d_handle_option): Handle -fpreview=bitfields, remove
	-frevert=markdown and -ftransition=vmarkdown.
	(d_post_options): Set flag_rtti and flag_exceptions if -fno-druntime
	was seen on command-line.
	(d_parse_file): Update for new front-end interface.
	(d_type_promotes_to): Use resolvedLinkage to get declaration linkage.
	* decl.cc (make_thunk): Likewise.
	* expr.cc (ExprVisitor::visit (CatAssignExp *)): Remove lowering for
	appending of an element or array to another array.
	* lang.opt (fpreview=bitfields): New option.
	(frevert=markdown): Remove.
	(ftransition=vmarkdown): Remove.
	* types.cc (layout_aggregate_members): Ignore anonymous fields in
	total count.

libphobos/ChangeLog:

	* libdruntime/MERGE: Merge upstream druntime 94bd5bcb.
	* libdruntime/Makefile.am (ALL_DRUNTIME_INSTALL_DSOURCES): Add
	$(DRUNTIME_DSOURCES_ELF).
	(ALL_DRUNTIME_SOURCES): Likewise.
	(DRUNTIME_DSOURCES_ELF): New variable.
	* libdruntime/Makefile.in: Regenerate.
	* src/MERGE: Merge upstream phobos 3a1cd9a01.
	* testsuite/libphobos.init_fini/custom_gc.d: Update test.
2022-05-16 19:07:45 +02:00
Jonathan Wakely
682e587f10 libstdc++: Fix hyperlink in docs
libstdc++-v3/ChangeLog:

	* doc/xml/manual/prerequisites.xml: Fix attributes for external
	hyperlink.
	* doc/html/manual/setup.html: Regenerate.
2022-05-16 14:54:07 +01:00
Jonathan Wakely
8414dad54a libstdc++: Update C++23 status docs
These are the C++23 proposals supported in the gcc-12 branch.

libstdc++-v3/ChangeLog:

	* doc/xml/manual/status_cxx2023.xml: Update with gcc-12 support.
	* doc/html/*: Regenerate.
2022-05-16 14:53:16 +01:00
Jonathan Wakely
4361867344 libstdc++: Add C++23 status docs
These are the C++23 proposals already supported in the gcc-11 branch.

libstdc++-v3/ChangeLog:

	* doc/xml/manual/intro.xml: Include new chapter.
	* doc/xml/manual/status_cxx2020.xml: Tweak release numbers.
	* doc/xml/manual/status_cxx2023.xml: New file.
	* doc/html/*: Regenerate.
2022-05-16 14:47:34 +01:00
Jonathan Wakely
64648821f1 libstdc++: Fix status docs for <bit> support
libstdc++-v3/ChangeLog:

	* doc/html/manual/status.html: Regenerate.
	* doc/xml/manual/status_cxx2020.xml: Fix supported version for
	C++20 bit operations.
2022-05-16 14:47:34 +01:00
Richard Biener
6f5b06032e Finish gimple_build API enhancement
This finishes the remaining parts of the gimple_build API enhancement,
converting the remaining workers to receive a gimple_stmt_iterator,
direction and update argument.  It also moves the code_helper
receiving functions from gimple-match.h to gimple-fold.h.

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

	* gimple-match.h (gimple_build): Move code_helper overloads ...
	* gimple-fold.h (gimple_build): ... here.
	(gimple_build): Transition to new worker API.  Provide
	overloads from sequence-based API.
	(gimple_convert): Likewise.
	(gimple_convert_to_ptrofftype): Likewise.
	(gimple_build_vector_from_val): Likewise.
	(gimple_build_vector): Likewise.
	(gimple_build_round_up): Likewise.
	* gimple-fold.cc (gimple_build_insert_seq): New helper.
	(gimple_build): Use it.  Transition combined_fn and code_helper
	API parts.
	(gimple_convert): Transition to new worker API.
	(gimple_convert_to_ptrofftype): Likewise.
	(gimple_build_vector_from_val): Likewise.
	(gimple_build_vector): Likewise.
	(gimple_build_round_up): Likewise.
2022-05-16 13:39:26 +02:00
Richard Biener
adace78911 Move code_helper to tree.h
tree.h already contains combined_fn handling at the top and moving
code_helper away from gimple-match.h makes improving the gimple_build
API easier.

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

	* gimple-match.h (code_helper): Move class ...
	* tree.h (code_helper): ... here.
2022-05-16 13:39:26 +02:00
Richard Biener
ef7b8976b9 rtl-optimization/105577 - testcase for the PR
2022-05-16  Richard Biener  <rguenther@suse.de>

	PR rtl-optimization/105577
	* g++.dg/torture/pr105577.C: New testcase.
2022-05-16 12:08:40 +02:00
Richard Biener
6230911cb9 ipa/105598 - testcase for PR105598
2022-05-16  Richard Biener  <rguenther@suse.de>

gcc/testsuite/
	* gcc.dg/torture/pr105598.c: New testcase.
2022-05-16 12:03:33 +02:00
Martin Liska
8ab53e65a6 opts-global.cc: document last change
gcc/ChangeLog:

	* opts-global.cc (write_langs): Add comment.
2022-05-16 11:07:57 +02:00
Eric Botcazou
cc7cd8d57c Do not use DW_OP_not for TRUTH_NOT_EXPR in conditional expressions
DW_OP_not is a bitwise, not a logical NOT, so it computes the wrong result
in a DWARF conditional expression.

gcc/
	* dwarf2out.cc (loc_list_from_tree_1) <TRUTH_NOT_EXPR>: Do a logical
	instead of a bitwise negation.
	<COND_EXPR>: Swap the operands if the condition is TRUTH_NOT_EXPR.
2022-05-16 11:04:51 +02:00
Eric Botcazou
b90e43dbbb [Ada] Fix fallout of change in equality for untagged record types
The problem is that the resolution of expanded names implicitly assumes
that the visible and private homonyms in a given scope are segregated on
the homonym chain, and this was no longer the case for equality operators
in the specific case at stake.

gcc/ada/

	* sem_ch7.adb (Inspect_Untagged_Record_Completion): Also move the
	equality operator on the homonym chain if there is another equality
	operator in the private part.
2022-05-16 08:42:06 +00:00
Piotr Trojanek
7e0c853c6f [Ada] Fix expansion of attribute Loop_Entry wrt value propagation
When expanding attribute Loop_Entry we create constant object
declarations and put them just before the loop. The current values of
variables at the point of Loop_Entry attribute must not be used when
analysing the initialization expressions of these constants, because
they might be different from the values at the loop entry itself.

gcc/ada/

	* exp_attr.adb (Expand_Loop_Entry_Attribute): Disable value
	propagation when analysing the constant that holds the
	Loop_Entry prefix value.
2022-05-16 08:42:06 +00:00
Piotr Trojanek
20652c7f22 [Ada] Remove useless code related to current value propagation
The current value propagation applies only to assignable objects and
doesn't make sense for subprogram entities. This was a mistake
introduced when extending the current value propagation years ago.

Cleanup related to fixing interference between expansion of attribute
Loop_Entry and current value propagation.

gcc/ada/

	* sem_attr.adb (Address_Checks): Remove call to
	Kill_Current_Values for subprogram entities, because this
	routine only does something for object entities.
2022-05-16 08:42:06 +00:00
Justin Squirek
b32b51902c [Ada] Type invariant or postcondition may cause uninitialized memory reads
This patch corrects an error in the compiler whereby a function
requiring the generation of a postconditions procedure may cause an
uninitialized memory read when the return type
Has_Unconstrained_Elements or is an unconstrained array.

The error occurs because evaluation of postconditions happens within the
"at end" handler when the temporary result object may go out of scope.
The patch modifies expansion in the above cases to evaluate
postconditions at the point of return instead - in order to guarantee
the result object is valid.

Note that these changes have the side effect of introducing a semantic
bug such that functions returning types with unconstrained elements will
have their postconditions/return type invariants evaluated before
finalization. Work is currently being done to introduce wrappers which
will solve this problem and remove technical debt in this area.

gcc/ada/

	* exp_ch7.adb (Build_Finalizer): Disable late evaluation of
	postconditions for functions returning types which where
	Has_Unconstrained_Elements is true or are unconstrained arrays.
2022-05-16 08:42:06 +00:00
Etienne Servais
26bbf0e5da [Ada] Freeze target type on qualified expression expansion
An object declaration (other than a deferred constant declaration)
causes freezing where it occurs (13.14(6)), which means every name
occurring within it causes freezing (13.14(4/1)), and when the name in a
subtype_mark causes freezing, the denoted subtype is frozen (13.14(11)).
Hence, one needs to freeze the target type when expanding a qualified
expression.

gcc/ada/

	* exp_ch4.adb (Expand_N_Qualified_Expression): Freeze
	Target_Type.
2022-05-16 08:42:06 +00:00
Yannick Moy
c1e007985f [Ada] Fix proof of double arithmetic units
Proof of an assertion is not automatic anymore. Add two assertions
before it to guide the prover.

gcc/ada/

	* libgnat/s-aridou.adb (Double_Divide): Add intermediate
	assertions.
2022-05-16 08:42:05 +00:00
Ghjuvan Lacambre
9eb55045f8 [Ada] Don't crash on ghost packages when emitting CUDA symbols in ALI files
Before this commit, a GNAT compiled with assertions would crash when
attempting to emit CUDA symbols in ALI files for spark_mode/ghost
packages, whose content is a single null statement.

gcc/ada/

	* lib-writ.adb (Output_CUDA_Symbols): Check for null packages.
2022-05-16 08:42:05 +00:00
Joel Brobecker
f29e9e8896 [Ada] GNAT.Debug_Pools: Improve documentation of the Stack_Trace_Depth parameter
Setting this parameter to zero when calling the Configure procedure has
the effect of disabling completely the tracking of the biggest memory
users, which wasn't clear from the current documentation.  So this patch
enhances the documentation of both the Configure procedure as well as
the Dump procedure to make that explicit.

gcc/ada/

	* libgnat/g-debpoo.ads: Improve documentation of the
	Stack_Trace_Depth parameter.
2022-05-16 08:42:05 +00:00
Joel Brobecker
1bdf9fa390 [Ada] sigaction result not properly checked in __gnat_install_handler (QNX)
The QNX version of __gnat_install_handler calls sigaction for a number
of signals, and then prints an error message when the the call failed.
But unfortunately, except for the first call, we forgot to store
sigaction's return value, so the check that ensues uses a potentially
uninitialized variable, which the compiler does detect (this is how we
found this issue).

This change fixes this by make sure we store the result of each
sigaction call before checking it.

While at it, we noticed a thinko in the error messages all alerting
about the SIGFPE signal, rather than the signal it just tested.  Most
likely a copy/paste thinko. Fixed by this change as well.

gcc/ada/

	* init.c (__gnat_install_handler) [__QNX__]: Save sigaction's
	return value in err before checking err's value.  Fix incorrect
	signal names in perror messages.
2022-05-16 08:42:05 +00:00
Joel Brobecker
839e7f16ab [Ada] Fix thinko in QNX's implementation of __gnat_install_handler
On QNX, the sigaction handler is incorrectly installed via the
sa_handler field of struct sigaction, rather than the sa_sigaction
field. This triggers a compilation warning due to a mismatch between the
function's signature and the field's type.

    | init.c:2614:18: warning: assignment to 'void (*)(int)'
    | from incompatible pointer type 'void (*)(int,  siginfo_t *, void *)'
    | {aka 'void (*)(int,  struct _siginfo *, void *)'}
    | [-Wincompatible-pointer-types]

In practice, using the sa_handler field actually works, but only because
those two fields are inside a union:

    From target/qnx7/usr/include/signal.h:
    | union { \
    |     __handler_type  _sa_handler; \
    |     __action_type   _sa_sigaction; \
    |     } __sa_un; \

This commit fixes this.

gcc/ada/

	* init.c (__gnat_install_handler) [__QNX__]: Set
	act.sa_sigaction rather than act.sa_handler.
2022-05-16 08:42:05 +00:00
Joel Brobecker
9abb17d9fa [Ada] Add <stdlib.h> #include in cstreams.c
When building the GNAT runtime for QNX, we get the following warning:

| cstreams.c: In function '__gnat_full_name':
| cstreams.c:209:5: warning: implicit declaration of function 'realpath'
|                   [-Wimplicit-function-declaration]
|   209 |     realpath (nam, buffer);
|       |     ^~~~~~~~

This commit fixes the warning by adding the corresponding #include
of <stdlib.h>

gcc/ada/

	* cstreams.c: Add <stdlib.h> #include.
2022-05-16 08:42:05 +00:00
Joel Brobecker
dec636b831 [Ada] replace call to bzero in terminals.c by call to memset
bzero is marked as legacy in POSIX.1-2001, and using it triggers a
deprecation warnings on some systems such as QNX. This change adjusts
the one place where we use it in terminals.c to use memset instead.
This, in turns, allows us to get rid of a hack for HP/UX and Solaris.

gcc/ada/

	* terminals.c: Remove bzero #define on HP/UX or Solaris
	platforms.
	(child_setup_tty): Replace bzero call by equivalent call to
	memset.
2022-05-16 08:42:05 +00:00
Gary Dismukes
21f8b41051 [Ada] Revise Storage_Model_Support operations to do checks and take objects and types
The functions in subpackage Storage_Model_Support (apart from the
Has_*_Aspect functions) are revised to have assertions that will fail
when passed a parameter that doesn't specify the appropriate aspect
(either aspect Storage_Model_Type or Designated_Storage_Model), instead
of returning Empty for bad arguments. Also, various of the functions now
allow either a type with aspect Storage_Model_Type or an object of such
a type.

gcc/ada/

	* sem_util.ads (Storage_Model_Support): Revise comments on most
	operations within this nested package to reflect that they can
	now be passed either a type that has aspect Storage_Model_Type
	or an object of such a type.  Change the names of the relevant
	formals to SM_Obj_Or_Type. Also, add more precise semantic
	descriptions in some cases, and declare the subprograms in a
	more logical order.
	* sem_util.adb (Storage_Model_Support.Storage_Model_Object): Add
	an assertion that the type must specify aspect
	Designated_Storage_Model, rather than returning Empty when it
	doesn't specify that aspect.
	(Storage_Model_Support.Storage_Model_Type): Add an assertion
	that formal must be an object whose type specifies aspect
	Storage_Model_Type, rather than returning Empty for when it
	doesn't have such a type (and test Has_Storage_Model_Type_Aspect
	rather than Find_Value_Of_Aspect).
	(Storage_Model_Support.Get_Storage_Model_Type_Entity): Allow
	both objects and types, and add an assertion that the type (or
	the type of the object) has a value for aspect
	Storage_Model_Type.
2022-05-16 08:42:04 +00:00
Etienne Servais
ae745a0de3 [Ada] Handle case-expression inside if-expression in -gnato2
gcc/ada/

	* checks.adb (Apply_Arithmetic_Overflow_Minimized_Eliminated):
	Fix condition to return.
2022-05-16 08:42:04 +00:00
Yannick Moy
7d8e3f5298 [Ada] Update comment justifying non-inlining for proof inside generics
gcc/ada/

	* inline.adb (Can_Be_Inlined_In_GNATprove_Mode): Update comment.
2022-05-16 08:42:04 +00:00
Marc Poulhiès
aacbf3761c [Ada] Fix iterated element association loop var escaping loop scope
Fix the escaping of the loop variable from the loop scope in both forms
of iterated element associations (i.e. "for J in ..." and "for J of
..."). Create a dedicated scope around the analyses of both loops. Also
create a copy of the Loop_Parameter_Specification instead of analyzing
(and modifying) the original Tree as it will be reanalyzed later.

gcc/ada/

	* sem_aggr.adb (Resolve_Iterated_Association): Create scope
	around N_Iterated_Element_Association handling. Analyze a copy
	of the Loop_Parameter_Specification. Call Analyze instead
	Analyze_* to be more homogeneous.
	(Sem_Ch5): Remove now unused package.
2022-05-16 08:42:04 +00:00
Eric Botcazou
e4acb82e97 [Ada] Fix internal error on iterated array aggregate
The front-end drops the declaration of a temporary on the floor because
Insert_Actions fails to climb up out of an N_Iterated_Component_Association
when the temporary is created during the analysis of its Discrete_Choices.

gcc/ada/

	* exp_util.adb (Insert_Actions) <N_Iterated_Component_Association>:
	Climb up out of the node if the actions come from Discrete_Choices.
2022-05-16 08:42:04 +00:00
Javier Miranda
e6bdaa0299 [Ada] Accept calls to abstract subprograms in class-wide pre/post-conditions
Fix a regression in the support for Ada 2022's treatment of calls to
abstract subprograms in pre/post-conditions (thanks to Javier Miranda
for producing this patch).

gcc/ada/

	* sem_disp.adb (Check_Dispatching_Context): When checking to see
	whether an expression occurs in a class-wide pre/post-condition,
	also check for the possibility that it occurs in a class-wide
	preconditions subprogram that was introduced as part of
	expansion. Without this fix, some legal calls occuring in
	class-wide preconditions may be incorrectly flagged as violating
	the "a call to an abstract subprogram must be dispatching" rule.
2022-05-16 08:42:04 +00:00
Eric Botcazou
146ea83af9 [Ada] Fix internal error on mix of controlled and protected types
The key is that the protected type is a (limited) private type, which
fools a test in Cleanup_Scopes.

gcc/ada/

	* inline.adb (Cleanup_Scopes): Test the underlying type.
2022-05-16 08:42:03 +00:00
Eric Botcazou
861b78a946 [Ada] Fix internal error on predicate aspect with iterator
The semantic analysis of predicates involves a fair amount of tree
copying because of both semantic and implementation considerations, and
there is a difficulty with quantified expressions since they declare a
new entity that cannot be shared between the various copies of the tree.

This change implements a specific processing for it in New_Copy_Tree
that subsumes a couple of fixes made earlier for variants of the issue.

gcc/ada/

	* sem_util.ads (Is_Entity_Of_Quantified_Expression): Declare.
	* sem_util.adb (Is_Entity_Of_Quantified_Expression): New
	predicate.
	(New_Copy_Tree): Deal with all entities of quantified
	expressions.
	* sem_ch13.adb (Build_Predicate_Functions): Get rid of
	superfluous tree copying and remove obsolete code.
	* sem_ch6.adb (Fully_Conformant_Expressions): Deal with all
	entities of quantified expressions.
2022-05-16 08:42:03 +00:00
Steve Baird
7c88e46a27 [Ada] Implement component finalization ordering rules for type extensions
Finalization of a record object is required to finalize any components
that have an access discriminant constrained by a per-object expression
before other components. This includes the case of a type extension;
"early finalization" components of the parent type are required to be
finalized before non-early-finalization extension components. This is
implemented in the extension type's finalization procedure by placing
the call to the parent type's finalization procedure between the
finalization of the "early finalization" extension components and the
finalization of the other extension components. Previously that call was
executed after finalizing all of the extension conponents.

gcc/ada/

	* exp_ch7.adb (Build_Finalize_Statements): Add Last_POC_Call
	variable to keep track of the last "early finalization" call
	generated for type extension's finalization procedure. If
	non-empty, then this will indicate the point at which to insert
	the call to the parent type's finalization procedure. Modify
	nested function Process_Component_List_For_Finalize to set this
	variable (and avoid setting it during a recursive call).  If
	Last_POC_Call is empty, then insert the parent finalization call
	before, rather than after, the finalization code for the
	extension components.
2022-05-16 08:42:03 +00:00
Eric Botcazou
909ce3528c [Ada] Fix implementation issues with equality for untagged record types
This moves the implementation of AI12-0101 + AI05-0123 from the expander
to the semantic analyzer and completes the implementation of AI12-0413,
which are both binding interpretations in Ada 2012, fixing a few bugs in
the process and removing a fair amount of duplicated code throughout.

gcc/ada/

	* einfo-utils.adb (Remove_Entity): Fix couple of oversights.
	* exp_ch3.adb (Is_User_Defined_Equality): Delete.
	(User_Defined_Eq): Call Get_User_Defined_Equality.
	(Make_Eq_Body): Likewise.
	(Predefined_Primitive_Eq_Body): Call Is_User_Defined_Equality.
	* exp_ch4.adb (Build_Eq_Call): Call Get_User_Defined_Equality.
	(Is_Equality): Delete.
	(User_Defined_Primitive_Equality_Op): Likewise.
	(Find_Aliased_Equality): Call Is_User_Defined_Equality.
	(Expand_N_Op_Eq): Call Underlying_Type unconditionally.
	Do not implement AI12-0101 + AI05-0123 here.
	(Expand_Set_Membership): Call Resolve_Membership_Equality.
	* exp_ch6.adb (Expand_Call_Helper): Remove obsolete code.
	* sem_aux.ads (Is_Record_Or_Limited_Type): Delete.
	* sem_aux.adb (Is_Record_Or_Limited_Type): Likewise.
	* sem_ch4.ads (Nondispatching_Call_To_Abstract_Operation): Declare.
	* sem_ch4.adb (Analyze_Call): Call Call_Abstract_Operation.
	(Analyze_Membership_Op): Call Resolve_Membership_Equality.
	(Nondispatching_Call_To_Abstract_Operation): New procedure.
	(Remove_Abstract_Operations): Call it.
	* sem_ch6.adb (Check_Untagged_Equality): Remove obsolete error and
	call Is_User_Defined_Equality.
	* sem_ch7.adb (Inspect_Untagged_Record_Completion): New procedure
	implementing AI12-0101 + AI05-0123.
	(Analyze_Package_Specification): Call it.
	(Declare_Inherited_Private_Subprograms): Minor tweak.
	(Uninstall_Declarations): Likewise.
	* sem_disp.adb (Check_Direct_Call): Adjust to new implementation
	of Is_User_Defined_Equality.
	* sem_res.ads (Resolve_Membership_Equality): Declare.
	* sem_res.adb (Resolve): Replace direct error handling with call to
	Nondispatching_Call_To_Abstract_Operation
	(Resolve_Call): Likewise.
	(Resolve_Equality_Op): Likewise.  mplement AI12-0413.
	(Resolve_Membership_Equality): New procedure.
	(Resolve_Membership_Op): Call Get_User_Defined_Equality.
	* sem_util.ads (Get_User_Defined_Eq): Rename into...
	(Get_User_Defined_Equality): ...this.
	* sem_util.adb (Get_User_Defined_Eq): Rename into...
	(Get_User_Defined_Equality): ...this. Call Is_User_Defined_Equality.
	(Is_User_Defined_Equality): Also check the profile but remove tests
	on Comes_From_Source and Parent.
	* sinfo.ads (Generic_Parent_Type): Adjust field description.
	* uintp.ads (Ubool): Invoke user-defined equality in predicate.
2022-05-16 08:42:03 +00:00
Piotr Trojanek
9a39b25f6f [Ada] Remove duplicated detection of user-defined equality
Cleanup related to handling of user-defined equality in GNATprove.

gcc/ada/

	* exp_ch3.adb (User_Defined_Eq): Replace duplicated code with a
	call to Get_User_Defined_Eq.
2022-05-16 08:42:03 +00:00
Piotr Trojanek
90fadb50df [Ada] Improve building of untagged equality
When checking components of a record type for their own user-defined
equality function it is enough to find just one such a component.

Cleanup related to handling of user-defined equality in GNATprove.

gcc/ada/

	* exp_ch3.adb (Build_Untagged_Equality): Exit early when the
	outcome of a loop is already known.
2022-05-16 08:42:03 +00:00