platform/upstream/gcc.git
2 years agolibstdc++: Implement ranges::cartesian_product_view from P2374R4
Patrick Palka [Mon, 7 Nov 2022 18:29:30 +0000 (13:29 -0500)]
libstdc++: Implement ranges::cartesian_product_view from P2374R4

This also implements the proposed resolutions of the tentatively ready
LWG issues 3760, 3761 and 3801 for cartesian_product_view.

I'm not sure how/if we should implement the recommended practice of:

  iterator::difference_type should be the smallest signed-integer-like
  type that is sufficiently wide to store the product of the maximum
  sizes of all underlying ranges if such a type exists

because for e.g.

  extern std::vector<int> x, y;
  auto v = views::cartesian_product(x, y);

IIUC it'd mean difference_type should be __int128 (on 64-bit systems),
which seems quite wasteful: in practice the size of any cartesian product
probably won't exceed the precision of say ptrdiff_t, and using anything
larger will just incur unnecessary space/time overhead.  It's also
probably not worth the complexity to use less precision than ptrdiff_t
(when possible) either.  So this patch defines difference_type as

  common_type_t<ptrdiff_t, range_difference_t<_First>, range_difference_t<_Vs>...>

which should mean it's least as large as the difference_type of each
underlying range, and at least as large as ptrdiff_t.  This patch also
adds assertions to catch any overflow that occurs due to this choice of
difference_type.

libstdc++-v3/ChangeLog:

* include/std/ranges (__maybe_const_t): New alias for
__detail::__maybe_const_t.
(__detail::__cartesian_product_is_random_access): Define.
(__detail::__cartesian_product_common_arg): Define.
(__detail::__cartesian_product_is_bidirectional): Define.
(__detail::__cartesian_product_is_common): Define.
(__detail::__cartesian_product_is_sized): Define.
(__detail::__cartesian_is_sized_sentinel): Define.
(__detail::__cartesian_common_arg_end): Define.
(cartesian_product_view): Define.
(cartesian_product_view::_Iterator): Define.
(views::__detail::__can_cartesian_product_view): Define.
(views::_CartesianProduct, views::cartesian_product): Define.
* testsuite/std/ranges/cartesian_product/1.cc: New test.

2 years agoC++: Template lambda mangling testcases
Nathan Sidwell [Mon, 7 Nov 2022 16:08:21 +0000 (11:08 -0500)]
C++: Template lambda mangling testcases

I found some additional cases when working on the demangler.  May as
well check their mangling.

gcc/testsuite/
* g++.dg/abi/lambda-tpl1.h: Add more cases.
* g++.dg/abi/lambda-tpl1-17.C: Add checks.
* g++.dg/abi/lambda-tpl1-18.C: Likewise.
* g++.dg/abi/lambda-tpl1-18vs17.C: Likewise.

2 years agoFix NULL filename handling
Richard Purdie [Mon, 7 Nov 2022 16:26:44 +0000 (17:26 +0100)]
Fix NULL filename handling

The previous commit introduced a regression as some Ada tests end up passing
NULL as the filename to remap_filename.  Handle this as before to fix them.

gcc/
* file-prefix-map.cc (remap_filename): Handle NULL filenames.

2 years agolibstdc++: Update from latest fast_float [PR107468]
Jakub Jelinek [Mon, 7 Nov 2022 14:17:21 +0000 (15:17 +0100)]
libstdc++: Update from latest fast_float [PR107468]

The following patch updates from fast_float trunk.  That way
it grabs two of the 4 LOCAL_PATCHES, some smaller tweaks, to_extended
cleanups and most importantly fix for the incorrect rounding case,
PR107468 aka https://github.com/fastfloat/fast_float/issues/149
Using std::fegetround showed in benchmarks too slow, so instead of
doing that the patch limits the fast path where it uses floating
point multiplication rather than integral to cases where we can
prove there will be no rounding (the multiplication will be exact, not
just that the two multiplication or division operation arguments are
exactly representable).

2022-11-07  Jakub Jelinek  <jakub@redhat.com>

PR libstdc++/107468
* src/c++17/fast_float/MERGE: Adjust for merge from upstream.
* src/c++17/fast_float/LOCAL_PATCHES: Remove commits that were
upstreamed.
* src/c++17/fast_float/README.md: Merge from fast_float
662497742fea7055f0e0ee27e5a7ddc382c2c38e commit.
* src/c++17/fast_float/fast_float.h: Likewise.
* testsuite/20_util/from_chars/pr107468.cc: New test.

2 years agolibstdc++: Add _Float128 to_chars/from_chars support for x86, ia64 and ppc64le with...
Jakub Jelinek [Mon, 7 Nov 2022 14:15:50 +0000 (15:15 +0100)]
libstdc++: Add _Float128 to_chars/from_chars support for x86, ia64 and ppc64le with glibc

The following patch adds std::{to,from}_chars support for std::float128_t
on glibc 2.26+ for {i?86,x86_64,ia64,powerpc64le}-linux.
When long double is already IEEE quad, previous changes already handle
it by using long double overloads in _Float128 overloads.
The powerpc64le case (with explicit or implicit -mabi=ibmlongdouble)
is handled by using the __float128/__ieee128 entrypoints which are
already in the library and used for -mabi=ieeelongdouble.
For i?86, x86_64 and ia64 this patch adds new library entrypoints,
mostly by enabling the code that was already there for powerpc64le-linux.
Those use __float128 or __ieee128, the patch uses _Float128 for the
exported overloads and internally as template parameter.  While
powerpc64le-linux uses __sprintfieee128 and __strtoieee128,
for _Float128 the patch uses the glibc 2.26 strfromf128 and strtof128
APIs.  So that one can build gcc against older glibc and then compile
user programs on newer glibc, the patch uses weak references unless
gcc is compiled against glibc 2.26+.  strfromf128 unfortunately can't
handle %.0Lf and %.*Le, %.*Lf, %.*Lg format strings sprintf/__sprintfieee128
use, we need to remove the L from those and replace * with actually
directly printing the precision into the format string (i.e. it can
handle %.0f and %.27f (floating point type is implied from the function
name)).
Unlike the std::{,b}float16_t support, this one actually exports APIs
with std::float128_t aka _Float128 in the mangled name, because no
standard format is superset of it.  On the other side, e.g. on i?86/x86_64
it doesn't have restrictions like for _Float16/__bf16 which ISAs need
to be enabled in order to use it.

The denorm_min case in the testcase is temporarily commented out because
of the ERANGE subnormal issue Patrick posted patch for.

2022-11-07  Jakub Jelinek  <jakub@redhat.com>

* include/std/charconv (from_chars, to_chars): Add _Float128
overfloads if _GLIBCXX_HAVE_FLOAT128_MATH is defined.
* config/abi/pre/gnu.ver (GLIBCXX_3.4.31): Export
_ZSt8to_charsPcS_DF128_, _ZSt8to_charsPcS_DF128_St12chars_format,
_ZSt8to_charsPcS_DF128_St12chars_formati and
_ZSt10from_charsPKcS0_RDF128_St12chars_format.
* src/c++17/floating_from_chars.cc (USE_STRTOF128_FOR_FROM_CHARS):
Define if needed.
(__strtof128): Declare.
(from_chars_impl): Handle _Float128.
(from_chars): New _Float128 overload if USE_STRTOF128_FOR_FROM_CHARS
is define.
* src/c++17/floating_to_chars.cc (__strfromf128): Declare.
(FLOAT128_TO_CHARS): Define even when _Float128 is supported and
wider than long double.
(F128_type): Use _Float128 for that case.
(floating_type_traits): Specialize for F128_type rather than
__float128.
(sprintf_ld): Add length argument.  Handle _Float128.
(__floating_to_chars_shortest, __floating_to_chars_precision):
Pass length to sprintf_ld.
(to_chars): Add _Float128 overloads for the F128_type being
_Float128 cases.
* testsuite/20_util/to_chars/float128_c++23.cc: New test.

2 years agotree-ssa-sink: do not touch calls that return twice
Alexander Monakov [Mon, 7 Nov 2022 12:33:01 +0000 (15:33 +0300)]
tree-ssa-sink: do not touch calls that return twice

Avoid moving pure/const calls that may return twice in tree-ssa-sink:
properly redirecting the associated abnormal edge is non-trivial.

gcc/ChangeLog:

PR tree-optimization/107505
* tree-ssa-sink.cc (statement_sink_location): Additionally
reject ECF_RETURNS_TWICE calls.

gcc/testsuite/ChangeLog:

PR tree-optimization/107505
* gcc.dg/pr107505.c: New test.

2 years ago[range-op] Restrict division by power of 2 optimization to positive numbers.
Aldy Hernandez [Mon, 7 Nov 2022 07:40:12 +0000 (08:40 +0100)]
[range-op] Restrict division by power of 2 optimization to positive numbers.

The problem here is that we are transforming a division by a power of
2 into a right shift, and using this to shift the maybe nonzero bits.
This gives the wrong result when the number being divided is negative.

In the testcase we are dividing this by 8:

[irange] int [-256, -255] NONZERO 0xffffff01

and coming up with:

[irange] int [-32, -31] NONZERO 0xffffffe0

The maybe nonzero bits are wrong as -31 has the LSB set (0xffffffe1)
whereas the bitmask says the lower 4 bits are off.

PR tree-optimization/107541

gcc/ChangeLog:

* range-op.cc (operator_div::fold_range): Restrict power of 2
optimization to positive numbers.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/pr107541.c: New test.

2 years agoFortran: Fix reallocation on assignment for kind=4 strings [PR107508]
Tobias Burnus [Mon, 7 Nov 2022 10:32:33 +0000 (11:32 +0100)]
Fortran: Fix reallocation on assignment for kind=4 strings [PR107508]

The check whether reallocation on assignment was required did not handle
kind=4 characters correctly such that there was always a reallocation,
implying issues with pointer addresses and lower bounds.  Additionally,
with all deferred strings, the old memory was not freed on reallocation.
And, finally, inside the block which was only executed if string lengths
or bounds or dynamic types changed, was a subcheck of the same, which
was effectively a no op but still confusing and at least added with -O0
extra instructions to the binary.

PR fortran/107508

gcc/fortran/ChangeLog:

* trans-array.cc (gfc_alloc_allocatable_for_assignment): Fix
string-length check, plug memory leak, and avoid generation of
effectively no-op code.
* trans-expr.cc (alloc_scalar_allocatable_for_assignment): Extend
comment; minor cleanup.

gcc/testsuite/ChangeLog:

* gfortran.dg/widechar_11.f90: New test.

2 years agoi386: Fix typo in sse-22.c pragma
konglin1 [Mon, 7 Nov 2022 09:34:50 +0000 (17:34 +0800)]
i386: Fix typo in sse-22.c pragma

gcc/testsuite/ChangeLog:

* gcc.target/i386/sse-22.c: Fix typo in pragma GCC target.

2 years agounswitch most profitable condition first
Richard Biener [Tue, 27 Sep 2022 08:16:52 +0000 (10:16 +0200)]
unswitch most profitable condition first

When doing the loop unswitching re-org we promised to followup
with improvements on the cost modeling.  The following makes sure we
try to unswitch on the most profitable condition first.  As most profitable
we pick the condition leading to the edge with the highest profile count.

Note the profile is only applied when picking the first unswitching
opportunity since the profile counts are not updated with earlier
unswitchings in mind.  Further opportunities are picked in DFS order.

* tree-ssa-loop-unswitch.cc (unswitch_predicate::count): New.
(unswitch_predicate::unswitch_predicate): Initialize count.
(init_loop_unswitch_info): First collect candidates and
determine the outermost loop to unswitch.
(tree_ssa_unswitch_loops): First perform all guard hoisting,
then perform unswitching on innermost loop predicates.
(find_unswitching_predicates_for_bb): Keep track of the
most profitable predicate to unswitch on.
(tree_unswitch_single_loop): Unswitch given predicate if
not NULL.

2 years agodocs: update: document sanitizers can trigger warnings
Martin Liska [Mon, 7 Nov 2022 08:54:09 +0000 (09:54 +0100)]
docs: update: document sanitizers can trigger warnings

gcc/ChangeLog:

* doc/invoke.texi: Improve wording.

Co-Authored-By: Gerald Pfeifer <gerald@pfeifer.com>
2 years agoMitigate clang warnings:
Martin Liska [Mon, 7 Nov 2022 08:50:21 +0000 (09:50 +0100)]
Mitigate clang warnings:

gcc/range-op.cc:1752:16: warning: 'wi_fold' overrides a member function but is not marked 'override' [-Winconsistent-missing-override]
gcc/range-op.cc:1757:16: warning: 'wi_op_overflows' overrides a member function but is not marked 'override' [-Winconsistent-missing-override]
gcc/range-op.cc:1759:16: warning: 'op1_range' overrides a member function but is not marked 'override' [-Winconsistent-missing-override]
gcc/range-op.cc:1763:16: warning: 'op2_range' overrides a member function but is not marked 'override' [-Winconsistent-missing-override]
gcc/range-op.cc:1928:16: warning: 'wi_fold' overrides a member function but is not marked 'override' [-Winconsistent-missing-override]
gcc/range-op.cc:1933:16: warning: 'wi_op_overflows' overrides a member function but is not marked 'override' [-Winconsistent-missing-override]

gcc/ChangeLog:

* range-op.cc: Add final override keywords.

2 years agoada: Document that gprof won't work on windows with PIE.
Cedric Landet [Tue, 18 Oct 2022 07:58:46 +0000 (09:58 +0200)]
ada: Document that gprof won't work on windows with PIE.

Document that gprof won't work on windows with PIE and -no-pie must be
used.

gcc/ada/

* doc/gnat_ugn/gnat_and_program_execution.rst: Mention the needed
-no-pie for windows to use gprof.
* gnat_ugn.texi: Regenerate.

2 years agoada: Tune hash function for cross-reference entries
Piotr Trojanek [Tue, 18 Oct 2022 07:33:38 +0000 (09:33 +0200)]
ada: Tune hash function for cross-reference entries

Tune the hash function that combines entity identifiers with source
locations of where those entities are referenced. Previously the source
location was multiplied by 2 ** 7 (i.e. shifted left by 7 bits), then
added to the entity identifier, and finally divided modulo 2 ** 16 (i.e.
masked to only use the lowest 16 bits). This hash routine caused
collisions that could make some tests up to twice slower.

With a large entity number the source location was only contributing few
bits to the hash value. This large entity number might correspond to
entity like Ada.Characters.Latin_1.NUL that occurs thousands of times in
generated code.

gcc/ada/

* lib-xref.adb (Hash): Tune hash function.

2 years agoada: Fix performance regression related to references in Refined_State
Piotr Trojanek [Mon, 17 Oct 2022 20:08:37 +0000 (22:08 +0200)]
ada: Fix performance regression related to references in Refined_State

Recently added call to In_Pragma_Expression caused a performance
regression. It might require climbing syntax trees of arbitrarily deep
expressions, while previously references within pragmas were detected in
bounded time.

This patch restores the previous efficiency. However, while the original
code only detected references directly within pragma argument
associations, now we also detect references inside aggregates, e.g.
like those in pragma Refined_State.

gcc/ada/

* sem_prag.adb (Non_Significant_Pragma_Reference): Detect
references with aggregates; only assign local variables Id and C
when necessary.

2 years agoada: Use named notation in calls to Expand_Composite_Equality
Bob Duff [Mon, 17 Oct 2022 19:49:22 +0000 (15:49 -0400)]
ada: Use named notation in calls to Expand_Composite_Equality

Use named notation in calls to Expand_Composite_Equality.

gcc/ada/

* exp_ch4.adb
(Component_Equality, Expand_Array_Equality)
(Expand_Record_Equality): Use named notation.

2 years agoada: New warning about noncomposing user-defined "="
Bob Duff [Mon, 17 Oct 2022 15:56:27 +0000 (11:56 -0400)]
ada: New warning about noncomposing user-defined "="

Print warning for a user-defined "=" that does not compose
as might be expected (i.e. is ignored for predefined "=" of
a containing record or array type). This warning is enabled by
-gnatw_q; we don't enable it by default because it generates
too many false positives. We also don't enable it via -gnatwa.

gcc/ada/

* exp_ch4.adb
(Expand_Array_Equality): Do not test Ltyp = Rtyp here, because
that is necessarily true. Move assertion thereof to more general
place.
(Expand_Composite_Equality): Pass in Outer_Type, for use in
warnings. Rename Typ to be Comp_Type, to more clearly distinguish
it from Outer_Type. Print warning when appropriate.
* exp_ch4.ads: Minor comment fix.
* errout.ads: There is no such pragma as Warning_As_Pragma --
Warning_As_Error must have been intended. Improve comment for ?x?.
* exp_ch3.adb
(Build_Untagged_Equality): Update comment to be accurate for more
recent versions of Ada.
* sem_case.adb
(Choice_Analysis): Declare user-defined "=" functions as abstract.
* sem_util.ads
(Is_Bounded_String): Give RM reference in comment.
* warnsw.ads, warnsw.adb
(Warn_On_Ignored_Equality): Implement new warning switch -gnatw_q.
* doc/gnat_ugn/building_executable_programs_with_gnat.rst:
Document new warning switch.
* gnat_ugn.texi: Regenerate.

2 years agoada: Inline composite node kind AST queries
Piotr Trojanek [Mon, 17 Oct 2022 14:28:20 +0000 (16:28 +0200)]
ada: Inline composite node kind AST queries

Queries that ultimately examine the same field of an AST
node (e.g. Nkind) are visibly more efficient when inlined.

In particular, routines Is_Body_Or_Package_Declaration and Is_Body can
apparently be inlined into a single Nkind membership test.

This patch fixes some of the performance lost with the recent changes,
which increased the number of calls to Is_Body_Or_Package_Declaration
(as it is typically used to prevent AST search from climbing too far).
However, it should be generally beneficial to inline routines like this.

gcc/ada/

* sem_aux.ads (Is_Body): Annotate with Inline.
* sem_util.ads (Is_Body_Or_Package_Declaration): Likewise.

2 years agoada: Fix inherited postconditions in inlined subprograms
Bob Duff [Thu, 13 Oct 2022 21:12:18 +0000 (17:12 -0400)]
ada: Fix inherited postconditions in inlined subprograms

Protect the building of postcondition pragmas in case the
postcondition is not present due to inlining.

gcc/ada/

* freeze.adb
(Build_Inherited_Condition_Pragmas): Do nothing if A_Post is
empty.

2 years agoada: Fixed elaboration of CUDA programs.
Quentin Ochem [Fri, 14 Oct 2022 10:30:04 +0000 (06:30 -0400)]
ada: Fixed elaboration of CUDA programs.

The names of imported / exported symbols were not consistent
between the device and the host when compiling for CUDA.

Remove the function Device_Ada_Final_Link_Name as it is no
longer referenced.

gcc/ada/

* bindgen.adb: fixed the way the device init and final symbols are
computed, re-using the normal way these symbols would be computed
with a __device_ prefix. Also fixed the "is null;" procedure on
the host side which are not Ada 95, replaced with a procedure
raising an exception as it should never be called. Remove the
unused function Device_Ada_Final_Link_Name.

Co-authored-by: Steve Baird <baird@adacore.com>
2 years agoada: Rework CUDA host-side invocation of device-side elaboration code
Steve Baird [Fri, 14 Oct 2022 00:07:31 +0000 (17:07 -0700)]
ada: Rework CUDA host-side invocation of device-side elaboration code

When the binder is invoked with a "-d_c" switch, add an argument to that
switch which is the library name on the device side; so "-d_c" becomes
"-d_c=some_library_name". This does not effect the case where "-d_c" is
specified as a switch for compilation (as opposed to binding). Use this
new piece of information in the code generated by the binder to invoke
elaboration code on the device side from the host side.

gcc/ada/

* opt.ads: Declare new string pointer variable, CUDA_Device_Library_Name.
Modify comments for existing Boolean variable Enable_CUDA_Device_Expansion.
* switch-b.adb: When "-d_c" switch is encountered, check that the next
character is an "'='; use the remaining characters to initialize
Opt.CUDA_Device_Library_Name.
* bindgen.adb: Remove (for now) most support for host-side invocation of
device-side finalization. Make use of the new CUDA_Device_Library_Name
in determining the string used to refer (on the host side) to the
device-side initialization procedure. Declare the placeholder routine
that is named in the CUDA_Execute pragma (and the CUDA_Register_Function
call) as an exported null procedure, rather than as an imported procedure.
It is not clear whether it is really necessary to specify the link-name
for this should-never-be-called subprogram on the host side, but for now it
shouldn't hurt to do so.

2 years agoada: Fix detection of external calls to protected objects in instances
Piotr Trojanek [Fri, 14 Oct 2022 18:22:34 +0000 (20:22 +0200)]
ada: Fix detection of external calls to protected objects in instances

Detection of external-vs-internal calls to protected objects relied on
the scope stack. This didn't work when the call appeared in an instance
of generic unit, because instances are analyzed in different context to
where they appear.

gcc/ada/

* exp_ch6.adb (Expand_Protected_Subprogram_Call): Examine scope
tree and not the scope stack.

2 years agoada: Clean up unnecessary nesting in code for DLL libraries
Piotr Trojanek [Fri, 14 Oct 2022 10:17:30 +0000 (12:17 +0200)]
ada: Clean up unnecessary nesting in code for DLL libraries

Code cleanup; issue spotted while examining routines with No_ prefix.

gcc/ada/

* mdll.ads (Build_Import_Library): Fix grammar in comment.
* mdll.adb (Build_Import_Library): Directly execute code of a
nested routine; rename No_Lib_Prefix to Strip_Lib_Prefix.

2 years agoada: Suppress warnings on derived True/False
Bob Duff [Thu, 13 Oct 2022 20:51:08 +0000 (16:51 -0400)]
ada: Suppress warnings on derived True/False

GNAT normally warns on "return ...;" if the "..." is known to be True or
False, but not when it is a Boolean literal True or False. This patch
also suppresses the warning when the type is derived from Boolean, and
has convention C or Fortran (and therefore True is represented as
"nonzero").

Without this fix, GNAT would give warnings like "False is always False".

gcc/ada/

* sem_warn.adb
(Check_For_Warnings): Remove unnecessary exception handler.
(Warn_On_Known_Condition): Suppress warning when we detect a True
or False that has been turned into a more complex expression
because True is represented as "nonzero". (Note that the complex
expression will subsequently be constant-folded to a Boolean True
or False). Also simplify to always print "condition is always ..."
instead of special-casing object names. The special case was
unhelpful, and indeed wrong when the expression is a literal.

2 years agoada: Deconstruct Safe_To_Capture_In_Parameter_Value
Piotr Trojanek [Tue, 19 May 2020 19:07:07 +0000 (21:07 +0200)]
ada: Deconstruct Safe_To_Capture_In_Parameter_Value

Recently routine Safe_To_Capture_Value was adapted, so that various data
properties like validity/nullness/values are tracked also for
in-parameters. Now a similar routine Safe_To_Capture_In_Parameter_Value,
which was only used to track data nullness, is redundant, so this patch
deconstructs it.

Also the removed routine had at least few problems and limitations, for
example:

1) it only worked for functions and procedures, but not for protected
entries and task types (whose discriminants work very much like
in-parameters)

2) it only worked for subprogram bodies with no spec, because of this
dubious check (here simplified):

   if Nkind (Parent (Parent (Current_Scope))) /= N_Subprogram_Body then
       return False;

3) it only recognized references within short-circuit operators as
certainly evaluated if they were directly their left hand expression,
e.g.:

   X.all and then ...

but not when they were certainly evaluated as part of a bigger
expression on the left hand side, e.g.:

   (X.all > 0) and then ...

4) it categorizes parameters with 'Unrestricted_Access attribute as safe
to capture, which is not necessarily wrong, but risky (because the
object becomes aliased).

Routine Safe_To_Capture_Value, which is kept by this patch, seems to
behave better in all those situations, though it has its own problems as
well and ideally should be further scrutinized.

gcc/ada/

* checks.adb (Safe_To_Capture_In_Parameter_Value): Remove.
* sem_util.adb (Safe_To_Capture_Value): Stop search at the current
body.

2 years agoada: Flip warning suppression routine to positive meaning
Piotr Trojanek [Wed, 7 Sep 2022 15:22:47 +0000 (17:22 +0200)]
ada: Flip warning suppression routine to positive meaning

Subprogram names starting with No_ seem unnecessarily confusing.

Cleanup related to improved detection of references to uninitialized
objects; semantics is unaffected.

gcc/ada/

* sem_warn.adb (Warn_On_In_Out): Remove No_ prefix; flip return
values between True and False; adapt caller.

2 years agoada: Cleanup detection of code within generic instances
Piotr Trojanek [Wed, 7 Sep 2022 15:24:40 +0000 (17:24 +0200)]
ada: Cleanup detection of code within generic instances

To check if a node is located in a generic instance we can either look
at Instantiation_Location or at the Instantiation_Depth, but just
looking at the location is simpler and more efficient.

Cleanup related to improved detection of references to uninitialized
objects; semantics is unaffected.

gcc/ada/

* sem_ch13.adb (Add_Call): Just look at Instantiation_Depth.
* sem_ch3.adb (Derive_Subprograms): Likewise.
* sem_warn.adb (Check_References): Remove redundant filtering with
Instantiation_Depth that follows filtering with
Instantiation_Location.
* sinput.adb (Instantiation_Depth): Reuse Instantiation_Location.

2 years agoada: Remove redundant suppression for non-modified IN OUT parameters
Piotr Trojanek [Mon, 5 Sep 2022 22:24:17 +0000 (00:24 +0200)]
ada: Remove redundant suppression for non-modified IN OUT parameters

Non-modified IN OUT parameters are first collected and then filtered by
examining uses of their enclosing subprograms. In this filtering we
don't need to look again at properties of the formal parameters
themselves.

Cleanup related to improved detection of references to uninitialized
objects; semantics is unaffected.

gcc/ada/

* sem_warn.adb
(No_Warn_On_In_Out): For subprograms we can simply call
Warnings_Off.
(Output_Non_Modified_In_Out_Warnings): Remove repeated
suppression.

2 years agoada: Reject boxes in delta array aggregates
Piotr Trojanek [Thu, 14 Oct 2021 15:50:43 +0000 (17:50 +0200)]
ada: Reject boxes in delta array aggregates

Implement Ada 2022 4.3.4(11/5), which rejects box compound delimiter <>
in delta record aggregates, just like another rule rejects it in delta
array aggregates.

gcc/ada/

* sem_aggr.adb (Resolve_Delta_Array_Aggregate): Reject boxes in
delta array aggregates.

2 years agoada: Allow reuse of Enclosing_Declaration_Or_Statement by GNATprove
Piotr Trojanek [Fri, 25 Sep 2020 08:43:27 +0000 (10:43 +0200)]
ada: Allow reuse of Enclosing_Declaration_Or_Statement by GNATprove

Move routine Enclosing_Declaration_Or_Statement from body of Sem_Res to spec
of Sem_Util, so it can be reused. In particular, GNATprove needs this
functionality to climb from an arbitrary subexpression with target_name (@)
to the enclosing assignment statement. Behaviour of the compiler is
unaffected.

gcc/ada/

* sem_res.adb (Enclosing_Declaration_Or_Statement): Moved to
Sem_Util.
* sem_util.ads (Enclosing_Declaration_Or_Statement): Moved from
Sem_Res.
* sem_util.adb (Enclosing_Declaration_Or_Statement): Likewise.

2 years agoada: Clean up unnecesary call in resolution of overloaded expressions
Piotr Trojanek [Fri, 12 Aug 2022 10:04:35 +0000 (12:04 +0200)]
ada: Clean up unnecesary call in resolution of overloaded expressions

When experimentally enabling frontend inlining by default, the
unnecessary call to Comes_From_Predefined_Lib_Unit in Resolve appears to
be a performance bottleneck (most likely this call is expensive because
it involves a loop over the currently inlined subprograms).

Code cleanup; semantics is unaffected.

gcc/ada/

* sem_res.adb (Resolve): Only call Comes_From_Predefined_Lib_Unit
when its result might be needed.

2 years agoada: Clean up code for visibility of generic actuals
Piotr Trojanek [Fri, 12 Aug 2022 09:55:35 +0000 (11:55 +0200)]
ada: Clean up code for visibility of generic actuals

Code cleanup related to fixing visibility of actual parameters in
inlining-for-proof in GNATprove mode; semantics is unaffected.

gcc/ada/

* sem_ch12.adb (Check_Generic_Actuals): Remove redundant parens;
refactor an excessive if-statement; remove repeated call to Node.

2 years agoada: Cleanup comment about mapping parameters when inlining
Piotr Trojanek [Fri, 12 Aug 2022 09:51:30 +0000 (11:51 +0200)]
ada: Cleanup comment about mapping parameters when inlining

Improve location of the comment about a special case for GNATprove mode.

gcc/ada/

* inline.adb (Establish_Actual_Mapping_For_Inlined_Call): Move
comment next to a condition that it describes.

2 years agoada: Put_Image aspect spec incorrectly not inherited
Steve Baird [Tue, 11 Oct 2022 22:21:39 +0000 (15:21 -0700)]
ada: Put_Image aspect spec incorrectly not inherited

In some cases, a Put_Image aspect specification for a scalar type was not
correctly inherited by a descendant of that type.

gcc/ada/

* exp_put_image.adb
(Image_Should_Call_Put_Image): Correctly handle the case of an
inherited Put_Image aspect specification for a scalar type.

2 years agoada: Tune layout after switching to Ada 2022 aggregate syntax
Piotr Trojanek [Fri, 9 Sep 2022 15:48:45 +0000 (17:48 +0200)]
ada: Tune layout after switching to Ada 2022 aggregate syntax

Whitespace cleanup only.

gcc/ada/

* libgnarl/s-interr.adb: Tune whitespace.

2 years agoada: Cleanup WITH clauses after switching from obsolescent Ada 83 unit
Piotr Trojanek [Fri, 9 Sep 2022 15:46:22 +0000 (17:46 +0200)]
ada: Cleanup WITH clauses after switching from obsolescent Ada 83 unit

Cleanup after replacing Unchecked_Conversion with
Ada.Unchecked_Conversion.

gcc/ada/

* libgnarl/s-interr.adb: Reorder context items and pragmas.

2 years agoada: Create operator nodes in functional style
Piotr Trojanek [Fri, 2 Sep 2022 11:32:27 +0000 (13:32 +0200)]
ada: Create operator nodes in functional style

A recent patch removed two rewritings, where we kept the operator node
but replaced its operands. This patch removes explicit setting of the
operands; instead, the operator is already created together with its
operands, which seems a bit safer and more consistent with how we
typically create operator nodes.

It is a cleanup only; semantics is unaffected.

gcc/ada/

* exp_ch4.adb
(Expand_Modular_Addition): Rewrite using Make_XXX calls.
(Expand_Modular_Op): Likewise.
(Expand_Modular_Subtraction): Likewise.
* exp_imgv.adb
(Expand_User_Defined_Enumeration_Image): Likewise.

2 years agoada: Don't reuse operator nodes in expansion
Piotr Trojanek [Fri, 2 Sep 2022 20:42:57 +0000 (22:42 +0200)]
ada: Don't reuse operator nodes in expansion

This patch removes handling of references to unset objects that relied
on Original_Node. This handling was only needed because of rewriting
that reused operator nodes, for example, when an array inequality like:

  A < B

was rewritten into:

  System.Compare_Array_Unsigned_8.Compare_Array_U8
    (A'Address, B'Address, A'Length, B'Length) < 0

by keeping the node for operator "<" and only substituting its operands.
It seems safer to simply create an new operator node when rewriting and
not rely on Original_Node afterwards.

Cleanup related to improved detection uninitialized objects.

gcc/ada/

* checks.adb (Apply_Arithmetic_Overflow_Strict): Rewrite using a
newly created operator node.
* exp_ch4.adb (Expand_Array_Comparison): Likewise.
* exp_ch6.adb (Add_Call_By_Copy_Code): Rewriting actual parameter
using its own location and not the location of the subprogram
call.
* sem_warn.adb (Check_References): Looping with Original_Node is
no longer needed.

2 years agoada: Simplify detection of pragmas in the context items
Piotr Trojanek [Wed, 7 Sep 2022 14:02:42 +0000 (16:02 +0200)]
ada: Simplify detection of pragmas in the context items

Code cleanup; semantics is unaffected.

gcc/ada/

* sem_prag.adb (Is_In_Context_Clause): Rewrite without negations
and inequalities.

2 years agoada: Reject misplaced pragma Obsolescent
Piotr Trojanek [Wed, 7 Sep 2022 13:02:04 +0000 (15:02 +0200)]
ada: Reject misplaced pragma Obsolescent

Pragma Obsolescent appearing before declaration was putting the
Obsolescent flag on the Standard package, which is certainly wrong. The
problem was that we relied on the Find_Lib_Unit_Name routine without
sanitizing the pragma placement with Check_Valid_Library_Unit_Pragma.

Part of cleaning up the warnings machinery to better handle references
to unset objects.

gcc/ada/

* sem_prag.adb (Analyze_Pragma [Pragma_Obsolescent]): Reject
misplaced pragma.

2 years agoada: Fix missing tag for with of an obsolescent function
Piotr Trojanek [Wed, 7 Sep 2022 13:01:16 +0000 (15:01 +0200)]
ada: Fix missing tag for with of an obsolescent function

Fix minor inconsistency in tags of warnings about obsolescent entities.

Part of cleaning up the warnings machinery to better handle references
to unset objects.

gcc/ada/

* sem_warn.adb (Output_Obsolescent_Entity_Warnings): Tag warnings
about obsolescent functions just like we tag similar warnings for
packages and procedures.

2 years agoada: Remove useless validity suppression for attribute Input
Piotr Trojanek [Wed, 12 Oct 2022 10:17:34 +0000 (12:17 +0200)]
ada: Remove useless validity suppression for attribute Input

Attributes 'Input and 'Read are similar, but only the 'Read denotes a
subprogram with parameter of mode OUT where operand validity checks need
to be suppressed.

Cleanup related to fix for attributes 'Has_Same_Storage and
'Overlaps_Storage.

gcc/ada/

* exp_attr.adb (Expand_N_Attribute_Reference): Remove useless
skipping for attribute Input.

2 years agovect: Fold LEN_{LOAD,STORE} if it's for the whole vector [PR107412]
Kewen Lin [Mon, 7 Nov 2022 08:07:27 +0000 (02:07 -0600)]
vect: Fold LEN_{LOAD,STORE} if it's for the whole vector [PR107412]

As the test case in PR107412 shows, we can fold IFN .LEN_{LOAD,
STORE} into normal vector load/store if the given length is known
to be equal to the length of the whole vector.  It would help to
improve overall cycles as normally the latency of vector access
with length in bytes is bigger than normal vector access, and it
also saves the preparation for length if constant length can not
be encoded into instruction (such as on power).

PR tree-optimization/107412

gcc/ChangeLog:

* gimple-fold.cc (gimple_fold_mask_load_store_mem_ref): Rename to ...
(gimple_fold_partial_load_store_mem_ref): ... this, add one parameter
mask_p indicating it's for mask or length, and add some handlings for
IFN LEN_{LOAD,STORE}.
(gimple_fold_mask_load): Rename to ...
(gimple_fold_partial_load): ... this, add one parameter mask_p.
(gimple_fold_mask_store): Rename to ...
(gimple_fold_partial_store): ... this, add one parameter mask_p.
(gimple_fold_call): Add the handlings for IFN LEN_{LOAD,STORE},
and adjust calls on gimple_fold_mask_load_store_mem_ref to
gimple_fold_partial_load_store_mem_ref.

gcc/testsuite/ChangeLog:

* gcc.target/powerpc/pr107412.c: New test.
* gcc.target/powerpc/p9-vec-length-epil-8.c: Adjust scan times for
folded LEN_LOAD.

2 years agoInitial Grand Ridge support
Hu, Lin1 [Mon, 7 Nov 2022 03:31:15 +0000 (11:31 +0800)]
Initial Grand Ridge support

gcc/ChangeLog:

* common/config/i386/cpuinfo.h
(get_intel_cpu): Handle Grand Ridge.
* common/config/i386/i386-common.cc
(processor_names): Add grandridge.
(processor_alias_table): Ditto.
* common/config/i386/i386-cpuinfo.h:
(enum processor_types): Add INTEL_GRANDRIDGE.
* config.gcc: Add -march=grandridge.
* config/i386/driver-i386.cc (host_detect_local_cpu):
Handle grandridge.
* config/i386/i386-c.cc (ix86_target_macros_internal):
Ditto.
* config/i386/i386-options.cc (m_GRANDRIDGE): New define.
(processor_cost_table): Add grandridge.
* config/i386/i386.h (enum processor_type):
Add PROCESSOR_GRANDRIDGE.
(PTA_GRANDRIDGE): Ditto.
* doc/extend.texi: Add grandridge.
* doc/invoke.texi: Ditto.

gcc/testsuite/ChangeLog:

* g++.target/i386/mv16.C: Add grandridge.
* gcc.target/i386/funcspec-56.inc: Handle new march.

2 years agoi386: Prefer remote atomic insn for atomic_fetch{add, and, or, xor}
konglin1 [Mon, 7 Nov 2022 03:21:14 +0000 (11:21 +0800)]
i386: Prefer remote atomic insn for atomic_fetch{add, and, or, xor}

Add flag -mprefer-remote-atomic to control whether to generate raoint
insn for atomic operations.

gcc/ChangeLog:

* config/i386/i386.opt:Add -mprefer-remote-atomic.
* config/i386/sync.md (atomic_<plus_logic><mode>):
New define_expand.
(atomic_add<mode>): Rename to below one.
(atomic_add<mode>_1): To this.
(atomic_<logic><mode>): Ditto.
(atomic_<logic><mode>_1): Ditto.
* doc/invoke.texi: Add -mprefer-remote-atomic.

gcc/testsuite/ChangeLog:

* gcc.target/i386/raoint-atomic-fetch.c: New test.

2 years agoSupport Intel RAO-INT
konglin1 [Mon, 7 Nov 2022 02:33:45 +0000 (10:33 +0800)]
Support Intel RAO-INT

gcc/ChangeLog:

* common/config/i386/cpuinfo.h (get_available_features):
Detect raoint.
* common/config/i386/i386-common.cc (OPTION_MASK_ISA2_RAOINT_SET,
OPTION_MASK_ISA2_RAOINT_UNSET): New.
(ix86_handle_option): Handle -mraoint.
* common/config/i386/i386-cpuinfo.h (enum processor_features):
Add FEATURE_RAOINT.
* common/config/i386/i386-isas.h: Add ISA_NAME_TABLE_ENTRY for
raoint.
* config.gcc: Add raointintrin.h
* config/i386/cpuid.h (bit_RAOINT): New.
* config/i386/i386-builtin.def (BDESC): Add new builtins.
* config/i386/i386-c.cc (ix86_target_macros_internal): Define
__RAOINT__.
* config/i386/i386-isa.def (RAOINT): Add DEF_PTA(RAOINT).
* config/i386/i386-options.cc (ix86_valid_target_attribute_inner_p):
Add -mraoint.
* config/i386/sync.md (rao_a<raointop><mode>): New define insn.
* config/i386/i386.opt: Add option -mraoint.
* config/i386/x86gprintrin.h: Include raointintrin.h.
* doc/extend.texi: Document raoint.
* doc/invoke.texi: Document -mraoint.
* doc/sourcebuild.texi: Document target raoint.
* config/i386/raointintrin.h: New file.

gcc/testsuite/ChangeLog:

* g++.dg/other/i386-2.C: Add -mraoint.
* g++.dg/other/i386-3.C: Ditto.
* gcc.target/i386/funcspec-56.inc: Add new target attribute.
* gcc.target/i386/sse-12.c: Add -mraoint.
* gcc.target/i386/sse-13.c: Ditto.
* gcc.target/i386/sse-14.c: Ditto.
* gcc.target/i386/sse-22.c: Add raoint target.
* gcc.target/i386/sse-23.c: Ditto.
* lib/target-supports.exp: Add check_effective_target_raoint.
* gcc.target/i386/rao-helper.h: New test.
* gcc.target/i386/raoint-1.c: Ditto.
* gcc.target/i386/raoint-aadd-2.c: Ditto.
* gcc.target/i386/raoint-aand-2.c: Ditto.
* gcc.target/i386/raoint-aor-2.c: Ditto.
* gcc.target/i386/raoint-axor-2.c: Ditto.
* gcc.target/i386/x86gprintrin-1.c: Ditto.
* gcc.target/i386/x86gprintrin-2.c: Ditto.
* gcc.target/i386/x86gprintrin-3.c: Ditto.
* gcc.target/i386/x86gprintrin-4.c: Ditto.
* gcc.target/i386/x86gprintrin-5.c: Ditto.

2 years agoInitial Granite Rapids Support
Haochen Jiang [Mon, 7 Nov 2022 03:04:57 +0000 (11:04 +0800)]
Initial Granite Rapids Support

gcc/ChangeLog:

* common/config/i386/cpuinfo.h
(get_intel_cpu): Handle Granite Rapids.
* common/config/i386/i386-common.cc:
(processor_names): Add graniterapids.
(processor_alias_table): Ditto.
* common/config/i386/i386-cpuinfo.h
(enum processor_subtypes): Add INTEL_GRANTIERAPIDS.
* config.gcc: Add -march=graniterapids.
* config/i386/driver-i386.cc (host_detect_local_cpu):
Handle graniterapids.
* config/i386/i386-c.cc (ix86_target_macros_internal):
Ditto.
* config/i386/i386-options.cc (m_GRANITERAPIDS): New.
(processor_cost_table): Add graniterapids.
* config/i386/i386.h (enum processor_type):
Add PROCESSOR_GRANITERAPIDS.
(PTA_GRANITERAPIDS): Ditto.
* doc/extend.texi: Add graniterapids.
* doc/invoke.texi: Ditto.

gcc/testsuite/ChangeLog:

* g++.target/i386/mv16.C: Add graniterapids.
* gcc.target/i386/funcspec-56.inc: Handle new march.

2 years agoSupport Intel prefetchit0/t1
Haochen Jiang [Fri, 4 Nov 2022 07:01:05 +0000 (15:01 +0800)]
Support Intel prefetchit0/t1

gcc/ChangeLog:

* common/config/i386/cpuinfo.h (get_available_features):
Detect PREFETCHI.
* common/config/i386/i386-common.cc
(OPTION_MASK_ISA2_PREFETCHI_SET,
OPTION_MASK_ISA2_PREFETCHI_UNSET): New.
(ix86_handle_option): Handle -mprefetchi.
* common/config/i386/i386-cpuinfo.h
(enum processor_features): Add FEATURE_PREFETCHI.
* common/config/i386/i386-isas.h: Add ISA_NAME_TABLE_ENTRY
for prefetchi.
* config.gcc: Add prfchiintrin.h.
* config/i386/cpuid.h (bit_PREFETCHI): New.
* config/i386/i386-builtin-types.def:
Add DEF_FUNCTION_TYPE (VOID, PCVOID, INT)
and DEF_FUNCTION_TYPE (VOID, PCVOID, INT, INT, INT).
* config/i386/i386-builtin.def (BDESC): Add new builtins.
* config/i386/i386-c.cc (ix86_target_macros_internal):
Define __PREFETCHI__.
* config/i386/i386-expand.cc: Handle new builtins.
* config/i386/i386-isa.def (PREFETCHI):
Add DEF_PTA(PREFETCHI).
* config/i386/i386-options.cc
(ix86_valid_target_attribute_inner_p): Handle prefetchi.
* config/i386/i386.md (prefetchi): New define_insn.
* config/i386/i386.opt: Add option -mprefetchi.
* config/i386/predicates.md (local_func_symbolic_operand):
New predicates.
* config/i386/x86gprintrin.h: Include prfchiintrin.h.
* config/i386/xmmintrin.h (enum _mm_hint): New enum for
prefetchi.
(_mm_prefetch): Handle the highest bit of enum.
* doc/extend.texi: Document prefetchi.
* doc/invoke.texi: Document -mprefetchi.
* doc/sourcebuild.texi: Document target prefetchi.
* config/i386/prfchiintrin.h: New file.

gcc/testsuite/ChangeLog:

* g++.dg/other/i386-2.C: Add -mprefetchi.
* g++.dg/other/i386-3.C: Ditto.
* gcc.target/i386/avx-1.c: Ditto.
* gcc.target/i386/funcspec-56.inc: Add new target attribute.
* gcc.target/i386/sse-13.c: Add -mprefetchi.
* gcc.target/i386/sse-23.c: Ditto.
* gcc.target/i386/x86gprintrin-1.c: Ditto.
* gcc.target/i386/x86gprintrin-2.c: Ditto.
* gcc.target/i386/x86gprintrin-3.c: Ditto.
* gcc.target/i386/x86gprintrin-4.c: Ditto.
* gcc.target/i386/x86gprintrin-5.c: Ditto.
* gcc.target/i386/prefetchi-1.c: New test.
* gcc.target/i386/prefetchi-2.c: Ditto.
* gcc.target/i386/prefetchi-3.c: Ditto.
* gcc.target/i386/prefetchi-4.c: Ditto.

Co-authored-by: Hongtao Liu <hongtao.liu@intel.com>
2 years agoDaily bump.
GCC Administrator [Mon, 7 Nov 2022 00:16:42 +0000 (00:16 +0000)]
Daily bump.

2 years agooptabs: Use operand[2] mode in can_vec_set_var_idx_p
Uros Bizjak [Sun, 6 Nov 2022 19:51:01 +0000 (20:51 +0100)]
optabs: Use operand[2] mode in can_vec_set_var_idx_p

Use operand[2] mode in can_vec_set_var_idx_p when checking vec_set_optab.

This change allows non-VOID index operand in vec_set_optab.

2022-11-06  UroÅ¡ Bizjak  <ubizjak@gmail.com>

gcc/ChangeLog:

* optabs.cc (can_vec_set_var_idx_p): Use operand[2]
mode when checking vec_set_optab.

2 years agolibstdc++: Declare const global variables inline
Patrick Palka [Sun, 6 Nov 2022 16:30:47 +0000 (11:30 -0500)]
libstdc++: Declare const global variables inline

The changes inside the regex_constants and execution namespaces seem to
be (the only) unimplemented parts of P0607R0 "Inline Variable for the
Standard Library"; the rest of the changes are to implementation details.

libstdc++-v3/ChangeLog:

* include/bits/atomic_wait.h (_detail::__platform_wait_alignment):
Declare inline.  Remove redundant static specifier.
(__detail::__atomic_spin_count_relax): Declare inline.
(__detail::__atomic_spin_count): Likewise.
* include/bits/regex_automaton.h (__detail::_S_invalid_state_id):
Declare inline for C++17.  Declare constexpr.  Remove
redundant const and static specifiers.
* include/bits/regex_error.h (regex_constants::error_collate):
Declare inline for C++17 as per P0607R0.
(regex_constants::error_ctype): Likewise.
(regex_constants::error_escape): Likewise.
(regex_constants::error_backref): Likewise.
(regex_constants::error_brack): Likewise.
(regex_constants::error_paren): Likewise.
(regex_constants::error_brace): Likewise.
(regex_constants::error_badbrace): Likewise.
(regex_constants::error_range): Likewise.
(regex_constants::error_space): Likewise.
(regex_constants::error_badrepeat): Likewise.
(regex_constants::error_complexity): Likewise.
(regex_constants::error_stack): Likewise.
* include/ext/concurrence.h (__gnu_cxx::__default_lock_policy):
Likewise.  Remove redundant static specifier.
* include/pstl/execution_defs.h (execution::seq): Declare inline
for C++17 as per P0607R0.
(execution::par): Likewise.
(execution::par_unseq): Likewise.
(execution::unseq): Likewise.

2 years agolibstdc++: Move stream initialization into compiled library [PR44952]
Patrick Palka [Sun, 6 Nov 2022 16:16:00 +0000 (11:16 -0500)]
libstdc++: Move stream initialization into compiled library [PR44952]

This patch moves the static object for constructing the standard streams
out from <iostream> and into the compiled library on systems that support
init priorities.  This'll mean <iostream> no longer introduces a separate
global constructor in each TU that includes it.

We can do this only if the init_priority attribute is supported because
we need a way to ensure the stream initialization runs first before any
user global initializer, particularly when linking with a static
libstdc++.a.

PR libstdc++/44952
PR libstdc++/39796
PR libstdc++/98108

libstdc++-v3/ChangeLog:

* include/std/iostream (__ioinit): No longer define here if
the init_priority attribute is usable.
* src/c++98/ios_init.cc (__ioinit): Define here instead if
init_priority is usable, via ...
* src/c++98/ios_base_init.h: ... this new file.

2 years agoc++: correct __has_attribute(init_priority)
Patrick Palka [Sun, 6 Nov 2022 16:09:26 +0000 (11:09 -0500)]
c++: correct __has_attribute(init_priority)

Currently __has_attribute(init_priority) always returns true, even on
targets that don't actually support init priorities, and when using the
attribute on such targets we just get a hard error about them being
unsupported.  This makes it impossible to conditionally use the attribute
by querying __has_attribute.

This patch fixes this by including init_priority in the attribute table
only if the target supports init priorities.  Thus on such targets
__has_attribute(init_priority) will now return false and we'll treat it
as just another unrecognized attribute (e.g. using it gives a -Wattribute
warning instead of a hard error).

gcc/cp/ChangeLog:

* tree.cc (cxx_attribute_table): Include init_priority entry
only if SUPPORTS_INIT_PRIORITY.
(handle_init_priority_attribute): Add ATTRIBUTE_UNUSED.  Assert
SUPPORTS_INIT_PRIORITY is true.

gcc/testsuite/ChangeLog:

* g++.dg/special/initpri3.C: New test.

2 years agoManually add ChangeLog entries from r13-3652-ge4cba49413ca429dc82f6aa2e88129ecb3fdd943
Jakub Jelinek [Sun, 6 Nov 2022 11:12:47 +0000 (12:12 +0100)]
Manually add ChangeLog entries from r13-3652-ge4cba49413ca429dc82f6aa2e88129ecb3fdd943

This commit caused failure of update_version_git due to the removal of
liboffloadmic with ChangeLog in it, so I had to blacklist that commit
and here I'm adding ChangeLog entries manually.

2 years agoDaily bump.
GCC Administrator [Sun, 6 Nov 2022 11:05:22 +0000 (11:05 +0000)]
Daily bump.

2 years agoAdd another commit to ignore
Jakub Jelinek [Sun, 6 Nov 2022 10:59:44 +0000 (11:59 +0100)]
Add another commit to ignore

We can't handle r13-3652-ge4cba49413ca429dc82f6aa2e88129ecb3fdd943

* gcc-changelog/git_update_version.py: Add
e4cba49413ca429dc82f6aa2e88129ecb3fdd943 to ignored commits.

2 years agoLoongArch: Add fcopysign instructions
Xi Ruoyao [Fri, 4 Nov 2022 07:12:22 +0000 (15:12 +0800)]
LoongArch: Add fcopysign instructions

Add fcopysign.{s,d} with the names copysign{sf,df}3 so GCC will expand
__builtin_copysign{f,} to a single instruction.

Link: https://sourceware.org/pipermail/libc-alpha/2022-November/143177.html
gcc/ChangeLog:

* config/loongarch/loongarch.md (UNSPEC_FCOPYSIGN): New unspec.
(type): Add fcopysign.
(copysign<mode>3): New instruction template.

gcc/testsuite/ChangeLog:

* gcc.target/loongarch/fcopysign.c: New test.

2 years agoPlug memory leak in attribute target_clones
Bernhard Reutner-Fischer [Thu, 3 Nov 2022 20:52:51 +0000 (21:52 +0100)]
Plug memory leak in attribute target_clones

It looks like there was some memory leak in the handling
of attribute target_clones.

Ok for trunk if testing passes?

gcc/ChangeLog:

* multiple_target.cc (expand_target_clones): Free memory.

Signed-off-by: Bernhard Reutner-Fischer <aldot@gcc.gnu.org>
2 years agocgraph_node: Remove redundant section clearing
Bernhard Reutner-Fischer [Thu, 3 Nov 2022 20:20:57 +0000 (21:20 +0100)]
cgraph_node: Remove redundant section clearing

Ok for trunk if testing passes?

gcc/ChangeLog:

* cgraph.cc (cgraph_node::make_local): Remove redundant set_section.
* multiple_target.cc (create_dispatcher_calls): Likewise.

Signed-off-by: Bernhard Reutner-Fischer <aldot@gcc.gnu.org>
2 years agod: Adjust test to pass when compiling with -m32
Iain Buclaw [Sat, 5 Nov 2022 18:45:05 +0000 (19:45 +0100)]
d: Adjust test to pass when compiling with -m32

Noticed when running on x86_64-linux-gnu with `-m32', this test
triggered other errors.  Adjusted the test to use a different register
that is common between x86 and x86_64.

gcc/testsuite/ChangeLog:

* gdc.dg/attr_register2.d: Adjust test.

2 years agod: Add support for vector comparison operators
Iain Buclaw [Sat, 5 Nov 2022 18:32:17 +0000 (19:32 +0100)]
d: Add support for vector comparison operators

The front-end added semantic support to permit comparing two vector
expressions.  This removes the restriction in the code generator, as
well as the intrisics that previously exposed the same operation.

gcc/d/ChangeLog:

* d-target.cc (Target::isVectorOpSupported): Remove cases for
comparison operators.
* intrinsics.cc (maybe_set_intrinsic): Remove cases for vector
comparison intrinsics.
(maybe_warn_intrinsic_mismatch): Likewise.
(expand_intrinsic_vec_cond): Remove.
(maybe_expand_intrinsic): Remove cases for vector comparison
intrinsics.
* intrinsics.def (INTRINSIC_EQUALMASK): Remove.
(INTRINSIC_NOTEQUALMASK): Remove.
(INTRINSIC_GREATERMASK): Remove.
(INTRINSIC_GREATEREQUALMASK): Remove.

libphobos/ChangeLog:

* libdruntime/gcc/simd.d (equalMask): Implement using generics.
(notEqualMask): Likewise.
(greaterMask): Likewise.
(greaterOrEqualMask): Likewise.
(notMask): Likewise.
(andAndMask): Likewise.
(orOrMask): Likewise.

gcc/testsuite/ChangeLog:

* gdc.dg/Wbuiltin_declaration_mismatch2.d: Remove comparision tests.
* gdc.dg/simd2a.d: Update comparison tests.
* gdc.dg/simd2b.d: Likewise.
* gdc.dg/simd2c.d: Likewise.
* gdc.dg/simd2d.d: Likewise.
* gdc.dg/simd2e.d: Likewise.
* gdc.dg/simd2f.d: Likewise.
* gdc.dg/simd2g.d: Likewise.
* gdc.dg/simd2h.d: Likewise.
* gdc.dg/simd2i.d: Likewise.
* gdc.dg/simd2j.d: Likewise.

2 years agoc++: libcpp: Support raw strings with newlines in directives [PR55971]
Lewis Hyatt [Wed, 15 Jun 2022 22:06:53 +0000 (18:06 -0400)]
c++: libcpp: Support raw strings with newlines in directives [PR55971]

It's not currently possible to use a C++11 raw string containing a newline as
part of the definition of a macro, or in any other preprocessing directive,
such as:

 #define X R"(two
lines)"

 #error R"(this error has
two lines)"

Add support for that by relaxing the conditions under which
_cpp_get_fresh_line() refuses to get a new line. For the case of lexing a raw
string, it's OK to do so as long as there is another line within the current
buffer. The code in cpp_get_fresh_line() was refactored into a new function
get_fresh_line_impl(), so that the new logic is applied only when processing a
raw string and not any other times.

libcpp/ChangeLog:

PR preprocessor/55971
* lex.cc (get_fresh_line_impl): New function refactoring the code
from...
(_cpp_get_fresh_line): ...here.
(lex_raw_string): Use the new version of get_fresh_line_impl() to
support raw strings containing new lines when processing a directive.

gcc/testsuite/ChangeLog:

PR preprocessor/55971
* c-c++-common/raw-string-directive-1.c: New test.
* c-c++-common/raw-string-directive-2.c: New test.

gcc/c-family/ChangeLog:

PR preprocessor/55971
* c-ppoutput.cc (adjust_for_newlines): Update comment.

2 years agolibstdc++: fix pointer type exception catch (no RTTI) [PR105387]
Jakob Hasse [Tue, 26 Apr 2022 04:03:47 +0000 (12:03 +0800)]
libstdc++: fix pointer type exception catch (no RTTI) [PR105387]

__pbase_type_info::__do_catch(), used to catch pointer type exceptions,
did not check if the type info object to compare against is a pointer
type info object before doing a static down-cast to a pointer type info
object. If RTTI is disabled, this leads to the following situation:
Since a pointer type info object has additional fields, they would
end up being undefined if the actual type info object was not a pointer
type info object.

A simple check has been added before the down-cast happens.

Note that a consequence of this check is that exceptions of type
pointer-to-member cannot be caught anymore.

In case RTTI is enabled, this does not seem to be a problem because
RTTI-based checks would run before and prevent running into the bad
down-cast. Hence, the fix is disabled if RTTI is enabled and exceptions
of type pointer-to-member can still be caught.

libstdc++-v3/ChangeLog:

PR libstdc++/105387
* libsupc++/pbase_type_info.cc (__do_catch) [!__cpp_rtti]: Add
check that the thrown type is actually a pointer.
* testsuite/18_support/105387.cc: New test.
* testsuite/18_support/105387_memptr.cc: New test.

Signed-off-by: Jakob Hasse <jakob.hasse@espressif.com>
2 years agolibstdc++: Do not use SFINAE for propagate_const conversions [PR107525]
Jonathan Wakely [Fri, 4 Nov 2022 15:05:41 +0000 (15:05 +0000)]
libstdc++: Do not use SFINAE for propagate_const conversions [PR107525]

As the PR notes, the current conversion operators are defined as
function templates so that we can use SFINAE. But this changes how they
are considered for overload resolution. This moves those operators into
base classes that can be specialized so the operators are obsent unless
the constraints are satisfied.

libstdc++-v3/ChangeLog:

PR libstdc++/107525
* include/experimental/propagate_const (operator element_type*()):
Move into base class that can be partially specilized to iompose
constraints.
(operator const element_type*()): Likewise.
* testsuite/experimental/propagate_const/observers/107525.cc: New test.

2 years agodoc: Document correct -fwide-exec-charset defaults [PR41041]
Jonathan Wakely [Fri, 4 Nov 2022 12:10:32 +0000 (12:10 +0000)]
doc: Document correct -fwide-exec-charset defaults [PR41041]

As shown in the PR, the default is not UTF-32 but rather UTF-32BE or
UTF-32LE, avoiding the need for a byte order mark in literals.

gcc/ChangeLog:

PR c/41041
* doc/cppopts.texi: Document -fwide-exec-charset defaults
correctly.

2 years agoSupport multilib-aware target lib flags self-specs overriding
Alexandre Oliva [Sat, 5 Nov 2022 06:14:33 +0000 (03:14 -0300)]
Support multilib-aware target lib flags self-specs overriding

This patch introduces -fmultiflags, short for multilib TFLAGS, as an
option that does nothing by default, but that can be added to TFLAGS
and mapped to useful options by driver self-specs.

for  gcc/ChangeLog

* common.opt (fmultiflags): New.
* doc/invoke.texi: Document it.
* gcc.cc (driver_self_specs): Discard it.
* opts.cc (common_handle_option): Ignore it in the driver.

2 years agotestsuite: Add testcase from C++23 P2314R4 - Character sets and encodings
Jakub Jelinek [Fri, 4 Nov 2022 17:20:36 +0000 (18:20 +0100)]
testsuite: Add testcase from C++23 P2314R4 - Character sets and encodings

I've read the paper and I believe we just implement it with no changes
needed (at least since PR67224 and similar libcpp changes in GCC 10),
but I could be wrong.

The following patch at least adds a testcase from the start of the paper.

2022-11-04  Jakub Jelinek  <jakub@redhat.com>

* g++.dg/cpp23/charset1.C: New testcase from C++23 P2314R4.

2 years agolibcpp: Update to Unicode 15
Jakub Jelinek [Fri, 4 Nov 2022 17:18:42 +0000 (18:18 +0100)]
libcpp: Update to Unicode 15

The following pseudo-patch regenerates the libcpp tables with Unicode 15.0.0
which added 4489 new characters.

As mentioned previously, this isn't just a matter of running the
two libcpp/make*.cc programs on the new Unicode files, but one needs
to manually update a table inside of makeuname2c.cc according to
a table in Unicode text (which is partially reflected in the text
files, but e.g. in Unicode 14.0.0 not 100% accurately, in 15.0.0
actually accurately).
I've also added some randomly chosen subset of those 4489 new
characters to a testcase.

2022-11-04  Jakub Jelinek  <jakub@redhat.com>

gcc/testsuite/
* c-c++-common/cpp/named-universal-char-escape-1.c: Add tests for some
characters newly added in Unicode 15.0.0.
libcpp/
* makeuname2c.cc (struct generated): Update from Unicode 15.0.0
table 4-8.
* ucnid.h: Regenerated for Unicode 15.0.0.
* uname2c.h: Likewise.

2 years agoAArch64: Fix testcase
Wilco Dijkstra [Thu, 27 Oct 2022 15:40:17 +0000 (16:40 +0100)]
AArch64: Fix testcase

gcc/testsuite/
* gcc.target/aarch64/mgeneral-regs_3.c: Fix testcase.

2 years agoinput: add get_source_text_between
Jeff Chapman II [Thu, 3 Nov 2022 19:47:47 +0000 (15:47 -0400)]
input: add get_source_text_between

The c++-contracts branch uses this to retrieve the source form of the
contract predicate, to be returned by contract_violation::comment().

Co-authored-by: Jason Merrill <jason@redhat.com>
gcc/ChangeLog:

* input.cc (get_source_text_between): New fn.
* input.h (get_source_text_between): Declare.

2 years agoSet nonzero bits for multiplication and divisions by a power of 2.
Aldy Hernandez [Fri, 4 Nov 2022 09:20:46 +0000 (10:20 +0100)]
Set nonzero bits for multiplication and divisions by a power of 2.

We're missing a lot of TLC in keeping track of nonzero bits across
range-ops.  It isn't an oversight, but just limited amount of hours to
implement stuff.

This patch keeps better track of the nonzero mask (really
maybe_nonzero bits as discussed) across multiplication and division
when the RHS is a power of 2.

It fixes PR107342 and also touches on PR55157.  In the latter, the
nonzero mask is being set quite late (CCP2) but could be set by evrp
time if we enhanced range-ops.  I have added tests from both PRs.

Tested

PR tree-optimization/107342

gcc/ChangeLog:

* range-op.cc (operator_mult::fold_range): New.
(operator_div::fold_range): New.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/vrp122.c: New test.
* gcc.dg/tree-ssa/vrp123.c: New test.

2 years agoFix recent thinko in operand_equal_p
Eric Botcazou [Fri, 4 Nov 2022 10:23:12 +0000 (11:23 +0100)]
Fix recent thinko in operand_equal_p

There is a thinko in a recent improvement made to operand_equal_p where
the code just looks at operand 2 of COMPONENT_REF, if it is present, to
compare addresses.  That's wrong because operand 2 contains the number of
DECL_OFFSET_ALIGN-bit-sized words so, when DECL_OFFSET_ALIGN > 8, not all
the  bytes are included and some of them are in DECL_FIELD_BIT_OFFSET, see
get_inner_reference for the model computation.

In other words, you would need to compare operand 2 and DECL_OFFSET_ALIGN
and DECL_FIELD_BIT_OFFSET in this situation, but I'm not sure this is worth
the hassle in practice so the fix just removes this alternate handling.

gcc/
* fold-const.cc (operand_compare::operand_equal_p) <COMPONENT_REF>:
Do not take into account operand 2.
(operand_compare::hash_operand) <COMPONENT_REF>: Likewise.

gcc/testsuite/
* gnat.dg/opt99.adb: New test.
* gnat.dg/opt99_pkg1.ads, gnat.dg/opt99_pkg1.adb: New helper.
* gnat.dg/opt99_pkg2.ads: Likewise.

2 years agoDo not use subword paradoxical subregs in emit_group_store
Eric Botcazou [Fri, 4 Nov 2022 10:15:57 +0000 (11:15 +0100)]
Do not use subword paradoxical subregs in emit_group_store

The goal of the trick is to make life easier for the combiner, but subword
paradoxical subregs make it harder for the register allocator instead.

gcc/
* expr.cc (emit_group_store): Do not use subword paradoxical subregs

2 years agolibstdc++: Simplify lifetime of eh_globals variable [PR107500]
Jonathan Wakely [Thu, 3 Nov 2022 11:48:57 +0000 (11:48 +0000)]
libstdc++: Simplify lifetime of eh_globals variable [PR107500]

Since this is a trivial type, we probably don't need to do anything to
ensure it's still accessible after other static dtors.

libstdc++-v3/ChangeLog:

PR libstdc++/107500
* libsupc++/eh_globals.cc (eh_globals): Remove immortalizing
wrapper.
(__cxxabiv1::__cxa_get_globals_fast): Adjust.
(__cxxabiv1::__cxa_get_globals): Adjust.

2 years agolibstdc++: Define _GNU_SOURCE for secure_getenv on Cygwin [PR107511]
Jonathan Wakely [Thu, 3 Nov 2022 11:44:47 +0000 (11:44 +0000)]
libstdc++: Define _GNU_SOURCE for secure_getenv on Cygwin [PR107511]

As in r12-6867-ge20486d508afdf we need to define _GNU_SOURCE explicitly
for Cygwin, because configure finds it in libc but it isn't declared
unless we request it.

libstdc++-v3/ChangeLog:

PR libstdc++/107511
* libsupc++/eh_alloc.cc (_GNU_SOURCE): Define.

2 years agoada: Fix for validity checks combined with aliasing checks
Justin Squirek [Wed, 12 Oct 2022 09:53:04 +0000 (11:53 +0200)]
ada: Fix for validity checks combined with aliasing checks

Attribute Overlaps_Storage, which can appear implicitly in expansion of
aliasing checks, is now excluded from operand validity checks. Likewise
for attribute Has_Same_Storage.

gcc/ada/

* exp_attr.adb (Expand_N_Attribute_Reference): Skip operand
validity checks for attributes Has_Same_Storage and
Overlaps_Storage.

2 years agoada: Fix couple of issues with arrays indexed by enumeration type
Eric Botcazou [Wed, 12 Oct 2022 10:41:49 +0000 (12:41 +0200)]
ada: Fix couple of issues with arrays indexed by enumeration type

The first one is that Remove_Warning_Messages reinstates the Original_Node
of an N_Raise_Constraint_Error node in the tree for no clear reasons, and
the Original_Node may contain constructs whose expansion has been stopped
when the Constraint_Error was asserted, eventually causing gigi to stop.

The second one is that a path in Build_Array_Aggr_Code.Gen_Loop does not
copy the loop bounds, unlike other paths, thus triggering a sharing issue.

gcc/ada/

* errout.adb (Remove_Warning_Messages.Check_For_Warning): Do not
reinstate the Original_Node in the tree.
* exp_aggr.adb (Build_Array_Aggr_Code.Gen_Loop): Copy the bounds
on all paths.

2 years agoada: Fix typo in comment referring to pragma Restrictions
Piotr Trojanek [Thu, 1 Sep 2022 08:16:23 +0000 (10:16 +0200)]
ada: Fix typo in comment referring to pragma Restrictions

Comment cleanup only.

gcc/ada/

* libgnat/g-excact.ads
(Register_Global_Action): Refill comment.
(Name_To_Id): Change pragma Restriction from singular to plural.

2 years agoada: Cleanup code for warnings about unreferenced formal parameters
Piotr Trojanek [Wed, 24 Aug 2022 11:27:49 +0000 (13:27 +0200)]
ada: Cleanup code for warnings about unreferenced formal parameters

Cleanup related to new checks for unset references.

gcc/ada/

* sem_warn.adb (Check_References): Remove redundant guard, as it
is implied by a preceding call to Referenced_Check_Spec.

2 years agoada: Cleanup code for unreferenced variables
Piotr Trojanek [Tue, 23 Aug 2022 13:59:32 +0000 (15:59 +0200)]
ada: Cleanup code for unreferenced variables

Further cleanups related to warnings about unreferenced objects.

gcc/ada/

* sem_warn.adb (Check_References): Remove useless query for "spec"
of a variable; refactor nested if-statements into a single
condition.

2 years agoada: Cleanup code for warnings about unset references
Piotr Trojanek [Tue, 23 Aug 2022 10:57:35 +0000 (12:57 +0200)]
ada: Cleanup code for warnings about unset references

Cleanup related to new checks for unset references.

gcc/ada/

* sem_util.adb
(In_Pragma_Expression): Add standard guard against searching too
far.
(In_Quantified_Expression): Likewise.
* sem_warn.adb
(May_Need_Initialized_Actual): Remove redundant parens.
(Check_References): Remove guard that duplicates a condition from
the enclosing if-statement; only assign E1T variable when
necessary.
(Within_Postcondition): Fix layout.
(No_Warn_On_In_Out): Balance parens in comment.

2 years agoada: Static intrinsic functions are a core language extension.
Steve Baird [Sat, 8 Oct 2022 00:20:31 +0000 (17:20 -0700)]
ada: Static intrinsic functions are a core language extension.

GNAT-defined Ada extensions are divided into two categories: those that are
enabled by either -gnatX or -gnatX0 and those which require -gnatX0.
Move static intrinsic functions from the second category into the first.

gcc/ada/

* doc/gnat_rm/implementation_defined_pragmas.rst: Add the standard
'... "On" enables this extension.' sentence to the description of
static intrinsic functions.
* sem_ch13.adb
(Analyze_Aspect_Spec): In the call to Error_Msg_GNAT_Extension for
a Static aspect specification for an intrinsic function, specify
Is_Core_Extension => True.
* sem_eval.adb
(Eval_Intrinsic_Call): Test Core_Extensions_Allowed instead of
testing All_Extensions_Allowed.
* gnat_rm.texi: Regenerate.

2 years agoada: Remove redundant calls in handling of aspect specifications
Piotr Trojanek [Fri, 26 Aug 2022 13:27:31 +0000 (15:27 +0200)]
ada: Remove redundant calls in handling of aspect specifications

Routine Set_Aspect_Specifications sets the Has_Aspect flag, so there is
no need to set this flag again afterwards.

Code cleanup; semantics is unaffected.

gcc/ada/

* aspects.adb (Relocate_Aspect): Remove call to Set_Has_Aspects.
* sem_ch12.adb (Analyze_Formal_Package_Declaration): Likewise.
* sem_util.adb (Copy_Ghost_Aspect, Copy_SPARK_Mode_Aspect):
Likewise.

2 years agoada: Flag unsupported dispatching constructor calls
Javier Miranda [Fri, 7 Oct 2022 18:43:46 +0000 (18:43 +0000)]
ada: Flag unsupported dispatching constructor calls

gcc/ada/

* exp_intr.adb
(Expand_Dispatching_Constructor_Call): Report an error on
unsupported dispatching constructor calls and report a warning on
calls that may fail at run time.

gcc/testsuite/

* gnat.dg/abstract1.ads: Cleanup whitespaces.
* gnat.dg/abstract1.adb: Likewise and add -gnatws to silence new
warning.

2 years agoada: Avoid repeated iteration over private protected components
Piotr Trojanek [Thu, 1 Sep 2022 08:19:09 +0000 (10:19 +0200)]
ada: Avoid repeated iteration over private protected components

The First_Entity/Next_Entity chain includes private entities, so there
it no need to iterate starting both from First_Entity and
First_Private_Entity.

Code cleanup related to improved detection of references to
uninitialized objects; behavior is unaffected.

gcc/ada/

* sem_util.adb
(Check_Components): Iterate using
First/Next_Component_Or_Discriminant.
(Has_Preelaborable_Initialization): Avoid repeated iteration with
calls to Check_Components with First_Entity and
First_Private_Entity.
(Is_Independent_Object_Entity): Tune indentation.

2 years agoada: Cleanup clearing flags on package variables
Piotr Trojanek [Tue, 23 Aug 2022 15:16:44 +0000 (17:16 +0200)]
ada: Cleanup clearing flags on package variables

When killing flags on assignable entities we iterated from First_Entity
and then again from First_Private_Entity. This second iteration was
unnecessary, because the entity chain that starts with First_Entity
contains all entities, including the private ones.

This is just a performance improvement; the behavior is unchanged.

gcc/ada/

* sem_ch7.adb (Clear_Constants): Only iterate from First_Entity
through Next_Entity; only examine variables because packages have
no assignable formal parameters.

2 years agoada: Fix various typos in GNAT User's Guide
Piotr Trojanek [Sun, 9 Oct 2022 20:01:51 +0000 (22:01 +0200)]
ada: Fix various typos in GNAT User's Guide

Fix uncontroversial typos.

gcc/ada/

* doc/gnat_ugn/building_executable_programs_with_gnat.rst: Fix
typos.
* doc/gnat_ugn/elaboration_order_handling_in_gnat.rst: Fix typos
and refill as necessary; remove trailing whitespace.
* doc/gnat_ugn/gnat_and_program_execution.rst: Fix typos.
* gnat_ugn.texi: Regenerate.

2 years agoada: Fix loop unnesting issue.
Marc Poulhiès [Thu, 22 Sep 2022 08:59:42 +0000 (10:59 +0200)]
ada: Fix loop unnesting issue.

During loop unnesting, when the loop statements are wrapped in a code
block, the newly created block's scope must be set to the loop
scope (instead of the previous 'Current_Scope' that would point to an
upper scope).

gcc/ada/

* sem_util.ads (Add_Block_Identifier): Add new extra Scope
argument.
* sem_util.adb (Add_Block_Identifier): Likewise and use this scope
variable instead of Current_Scope.
* exp_util.adb (Wrap_Statements_In_Block): Add new scope argument
to Add_Block_Identifier call.

2 years agoada: Fix repeated killing of private entity values
Piotr Trojanek [Fri, 7 Oct 2022 10:55:14 +0000 (12:55 +0200)]
ada: Fix repeated killing of private entity values

When killing known values of assignable entities we iterated from
First_Entity and then again from First_Private_Entity. This second
iteration was unnecessary, because the entity chain that starts with
First_Entity contains all entities, including the private ones.

This is just a performance improvement; the behavior is unchanged.

gcc/ada/

* sem_util.adb (Kill_Current_Values): Only iterate from
First_Entity through Next_Entity.

2 years agoada: Simplify detection of controlling formals
Piotr Trojanek [Fri, 7 Oct 2022 19:58:58 +0000 (21:58 +0200)]
ada: Simplify detection of controlling formals

When detecting controlling formals we are only interested in formal
parameters and not in other entities.

gcc/ada/

* sem_ch6.adb (Controlling_Formal): Iterate with First/Next_Formal
and not with First/Next_Entity.

2 years agoada: Skip dynamic interface conversion under configurable runtime
Javier Miranda [Fri, 7 Oct 2022 16:02:02 +0000 (16:02 +0000)]
ada: Skip dynamic interface conversion under configurable runtime

gcc/ada/

* exp_disp.adb
(Expand_Interface_Conversion): Fix typo in comment.

2 years agoada: Skip dynamic interface conversion under configurable runtime
Javier Miranda [Thu, 6 Oct 2022 21:44:43 +0000 (21:44 +0000)]
ada: Skip dynamic interface conversion under configurable runtime

gcc/ada/

* exp_disp.adb
(Expand_Interface_Conversion): Under configurable runtime, when
the target type is an interface that is an ancestor of the operand
type, skip generating code to displace the pointer to reference
the target dispatch table.
* sem_disp.adb
(Propagate_Tag): Handle class-wide types when checking for the
addition of an implicit interface conversion.

2 years agoada: Fix typo
Ronan Desplanques [Thu, 6 Oct 2022 12:34:17 +0000 (14:34 +0200)]
ada: Fix typo

Fix typo in documentation.

gcc/ada/

* doc/gnat_rm/standard_library_routines.rst: Fix typo.
* gnat_rm.texi: Regenerate.

2 years agoada: Remove sa_messages
Ghjuvan Lacambre [Fri, 30 Sep 2022 13:44:49 +0000 (15:44 +0200)]
ada: Remove sa_messages

Spark and CodePeer do not depend on this unit anymore.

gcc/ada/

* sa_messages.ads, sa_messages.adb: Remove files.

2 years agoada: Refactor: replace uses of `not Present(X)` with `No (X)`
Ghjuvan Lacambre [Sat, 17 Sep 2022 17:35:48 +0000 (19:35 +0200)]
ada: Refactor: replace uses of `not Present(X)` with `No (X)`

`No (X)` is essentially `not Present (X)`, there's no reason for not
using this shorter form.

gcc/ada/

* checks.adb, exp_atag.adb, exp_attr.adb, exp_ch4.adb, exp_ch6.adb,
exp_ch7.adb, exp_dbug.adb, exp_disp.adb, exp_unst.adb, exp_util.adb,
freeze.adb, layout.adb, pprint.adb, rtsfind.adb, sem_aggr.adb,
sem_attr.adb, sem_case.adb, sem_ch12.adb, sem_ch13.adb, sem_ch3.adb,
sem_ch5.adb, sem_ch6.adb, sem_ch8.adb, sem_dim.adb, sem_prag.adb,
sem_util.adb, sem_warn.adb:
Replace uses of `not Present (X)` with `No (X)`.

2 years agoada: Fix various typos in node and entity description comments
Piotr Trojanek [Fri, 7 Oct 2022 10:42:34 +0000 (12:42 +0200)]
ada: Fix various typos in node and entity description comments

Fix typos in units that describe GNAT abstract syntax tree.

gcc/ada/

* einfo.ads: Fix typos in comments; refill as necessary.
* sinfo.ads: Likewise.

2 years agoada: Fix various typos in GNAT RM
Piotr Trojanek [Fri, 7 Oct 2022 10:20:55 +0000 (12:20 +0200)]
ada: Fix various typos in GNAT RM

List of unknown words in files can be produced with:

  $ cat *.rst | ispell -l |
    tr '[:upper:]' '[:lower:]' | sort | uniq | less

and can be easily filtered with eyes.

gcc/ada/

* doc/gnat_rm/implementation_defined_aspects.rst: Fix typos.
* doc/gnat_rm/implementation_defined_attributes.rst: Likewise
* doc/gnat_rm/implementation_defined_characteristics.rst: Likewise
* doc/gnat_rm/implementation_defined_pragmas.rst: Likewise
* doc/gnat_rm/standard_library_routines.rst: Likewise.
* gnat_rm.texi: Regenerate.

2 years agoada: Improve efficiency of scope stack restoration
Piotr Trojanek [Thu, 6 Oct 2022 21:42:46 +0000 (23:42 +0200)]
ada: Improve efficiency of scope stack restoration

We save/restore visibility by setting the Is_Immediately_Visible flag
and appending entities to / removing them from the tail of an element
list.

However, the Is_Immediately_Visible flag can be restored in any order,
while the element list is singly-linked and removal from the tail is
inefficient. This change removes a performance hot spot, which accounted
for up to 10% of compilation time of complex applications (e.g. QGen),
at least as measured on GNAT built with profiling support.

gcc/ada/

* sem_ch8.adb (Restore_Scope_Stack): Remove elements from the head
and not the tail of an element list.

2 years agoada: Small editorial changes to documentation comments
Ronan Desplanques [Mon, 3 Oct 2022 08:34:57 +0000 (10:34 +0200)]
ada: Small editorial changes to documentation comments

gcc/ada/

* sinfo.ads: Small editorial changes.

2 years agoada: Allow enabling a restricted set of language extensions.
Steve Baird [Fri, 30 Sep 2022 22:27:00 +0000 (15:27 -0700)]
ada: Allow enabling a restricted set of language extensions.

The -gnatX switch (and the related Extensions_Allowed pragma) is currently a
two-valued all-or-nothing option. Add support for enabling a curated subset
of language extensions without enabling others via the -gnatX switch
and for enabling all language extensions via the new -gnatX0 switch.
Similarly, the existing "ON" argument for the Extensions_Allowed pragma
now only enables the curated subset; the new argument "ALL" enables all
language extensions. The subset of language extensions currently includes
prefixed-view notation with an untagged prefix, fixed-low-bound array
subtypes, and casing on composite values.

gcc/ada/

* opt.ads: Replace Ada_Version_Type enumeration literal
Ada_With_Extensions with two literals, Ada_With_Core_Extensions
and Ada_With_All_Extensions. Update uses of the deleted literal.
Replace Extensions_Allowed function with two functions:
All_Extensions_Allowed and Core_Extensions_Allowed.
* errout.ads, errout.adb: Add Boolean parameter to
Error_Msg_GNAT_Extension to indicate whether the construct in
question belongs to the curated subset.
* exp_ch5.adb, par-ch4.adb, sem_case.adb, sem_ch3.adb:
* sem_ch4.adb, sem_ch5.adb, sem_ch8.adb: Replace calls to
Extensions_Allowed with calls to Core_Extensions_Allowed for
constructs that are in the curated subset.
* sem_attr.adb, sem_ch13.adb, sem_eval.adb, sem_util.adb: Replace
calls to Extensions_Allowed with calls to All_Extensions_Allowed
for constructs that are not in the curated subset.
* par-ch3.adb: Override default for new parameter in calls to
Error_Msg_GNAT_Extension for constructs in the curated subset.
* par-prag.adb: Add Boolean parameter to Check_Arg_Is_On_Or_Off to
also allow ALL. Set Opt.Ada_Version appropriately for ALL or ON
arguments.
* sem_prag.adb: Allowed ALL argument for an Extensions_Allowed
pragma. Set Opt.Ada_Version appropriately for ALL or ON arguments.
* switch-c.adb: The -gnatX switch now enables only the curated
subset of language extensions (formerly it enabled all of them);
the new -gnatX0 switch enables all of them.
* doc/gnat_ugn/building_executable_programs_with_gnat.rst:
Document new "-gnatX0" switch and update documentation for
"-gnatX" switch.
* doc/gnat_rm/implementation_defined_pragmas.rst: Document new ALL
argument for pragma Extensions_Allowed and update documentation
for the ON argument. Delete mention of Ada 2022 Reduce attribute
as an extension.
* gnat_rm.texi, gnat_ugn.texi: Regenerate.