Commit Graph

197781 Commits

Author SHA1 Message Date
GCC Administrator
d901bf8a44 Daily bump. 2023-01-08 00:16:59 +00:00
Takayuki 'January June' Suwa
b095a1db48 xtensa: Optimize stack frame adjustment more
This patch introduces a convenient helper function for integer immediate
addition with scratch register as needed, that splits and emits either
up to two ADDI/ADDMI machine instructions or an addition by register
following an integer immediate load (which may later be transformed by
constantsynth).

By using the helper function, it makes stack frame adjustment logic
simplified and instruction count less in some cases.

gcc/ChangeLog:

	* config/xtensa/xtensa.cc
	(xtensa_split_imm_two_addends, xtensa_emit_add_imm):
	New helper functions.
	(xtensa_set_return_address, xtensa_output_mi_thunk):
	Change to use the helper function.
	(xtensa_emit_adjust_stack_ptr): Ditto.
	And also change to try reusing the content of scratch register
	A9 if the register is not modified in the function body.
2023-01-07 12:21:55 -08:00
Iain Sandoe
2d2edf1080 modula-2, libm2min: Declare abort and exit as expected.
The build is currently emitting a warning that abort() is declared differently
from the built-in.  This updates the declaration to match expectations.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>

gcc/m2/ChangeLog:

	* gm2-libs-min/libc.c (abort): Update declaration to match the
	expected form, add no-return attribute.
	(exit): Add no-return attribute.
2023-01-07 19:39:59 +00:00
John David Anglin
727bd5d478 Fix compilation of gcc.dg/atomic/c11-atomic-exec-[45].c on hpux.
_HPUX_SOURCE needs to be defined to provide various types needed
for pthreads.

2023-01-07  John David Anglin  <danglin@gcc.gnu.org>

gcc/testsuite/ChangeLog:

	* gcc.dg/atomic/c11-atomic-exec-4.c: Add "-D_HPUX_SOURCE" option
	on *-*-hpux*.
	* gcc.dg/atomic/c11-atomic-exec-5.c: Likewise.
2023-01-07 18:40:04 +00:00
LIU Hao
902c755930 Always define WIN32_LEAN_AND_MEAN before <windows.h>
Recently, mingw-w64 has got updated <msxml.h> from Wine which is included
indirectly by <windows.h> if `WIN32_LEAN_AND_MEAN` is not defined. The
`IXMLDOMDocument` class has a member function named `abort()`, which gets
affected by our `abort()` macro in "system.h".

`WIN32_LEAN_AND_MEAN` should, nevertheless, always be defined. This
can exclude 'APIs such as Cryptography, DDE, RPC, Shell, and Windows
Sockets' [1], and speed up compilation of these files a bit.

[1] https://learn.microsoft.com/en-us/windows/win32/winprog/using-the-windows-headers

gcc/

	PR middle-end/108300
	* config/xtensa/xtensa-dynconfig.c: Define `WIN32_LEAN_AND_MEAN`
	before <windows.h>.
	* diagnostic-color.cc: Likewise.
	* plugin.cc: Likewise.
	* prefix.cc: Likewise.

gcc/ada/

	PR middle-end/108300
	* adaint.c: Define `WIN32_LEAN_AND_MEAN` before `#include
	<windows.h>`.
	* cio.c: Likewise.
	* ctrl_c.c: Likewise.
	* expect.c: Likewise.
	* gsocket.h: Likewise.
	* mingw32.h: Likewise.
	* mkdir.c: Likewise.
	* rtfinal.c: Likewise.
	* rtinit.c: Likewise.
	* seh_init.c: Likewise.
	* sysdep.c: Likewise.
	* terminals.c: Likewise.
	* tracebak.c: Likewise.

gcc/jit/

	PR middle-end/108300
	* jit-w32.h: Define `WIN32_LEAN_AND_MEAN` before <windows.h>.

libatomic/

	PR middle-end/108300
	* config/mingw/lock.c: Define `WIN32_LEAN_AND_MEAN` before
	<windows.h>.

libffi/

	PR middle-end/108300
	* src/aarch64/ffi.c: Define `WIN32_LEAN_AND_MEAN` before
	<windows.h>.

libgcc/

	PR middle-end/108300
	* config/i386/enable-execute-stack-mingw32.c: Define
	`WIN32_LEAN_AND_MEAN` before <windows.h>.
	* libgcc2.c: Likewise.
	* unwind-generic.h: Likewise.

libgfortran/

	PR middle-end/108300
	* intrinsics/sleep.c: Define `WIN32_LEAN_AND_MEAN` before
	<windows.h>.

libgomp/

	PR middle-end/108300
	* config/mingw32/proc.c: Define `WIN32_LEAN_AND_MEAN` before
	<windows.h>.

libiberty/

	PR middle-end/108300
	* make-temp-file.c: Define `WIN32_LEAN_AND_MEAN` before <windows.h>.
	* pex-win32.c: Likewise.

libssp/

	PR middle-end/108300
	* ssp.c: Define `WIN32_LEAN_AND_MEAN` before <windows.h>.

libstdc++-v3/

	PR middle-end/108300
	* src/c++11/system_error.cc: Define `WIN32_LEAN_AND_MEAN` before
	<windows.h>.
	* src/c++11/thread.cc: Likewise.
	* src/c++17/fs_ops.cc: Likewise.
	* src/filesystem/ops.cc: Likewise.

libvtv/

	PR middle-end/108300
	* vtv_malloc.cc: Define `WIN32_LEAN_AND_MEAN` before <windows.h>.
	* vtv_rts.cc: Likewise.
	* vtv_utils.cc: Likewise.
2023-01-07 06:51:06 +00:00
GCC Administrator
d808db1f7b Daily bump. 2023-01-07 00:17:28 +00:00
Jonathan Wakely
74852a3a2c libstdc++: Suppress -Waddress warning in tzdb.cc [PR108228]
For some tarets the weak symbol is always defined, so we get a warning
that its address is never null. The warning isn't useful in this case,
so suppress it.

libstdc++-v3/ChangeLog:

	PR libstdc++/108228
	* src/c++20/tzdb.cc (zoneinfo_dir): Add diagnostic pragma.
2023-01-06 21:06:28 +00:00
Jonathan Wakely
61da01772a libstdc++: Refactor time_zone::_Impl::rules_counter [PR108235]
Abstract the atomic counter used to synchronize access to time_zone
infos behind a Lockable class API, and use atomic_signed_lock_free
instead of atomic<int_least32_t>, as that should be the most efficient
type. (For futex-supporting targets it makes no difference, but might
benefit other targets in future.)

The new API allows the calling code to be simpler, without needing to
repeat the same error prone preprocessor conditions in multiple places.
It also allows using template metaprogramming to decide whether to use
the atomic or a mutex, which gives us more flexibility than only using
preprocessor conditions. That allows us to choose the mutex
implementation for targets such as hppa-hp-hpux11.11 where 32-bit
atomics are not lock-free and so would introduce an unwanted dependency
on libatomic.

libstdc++-v3/ChangeLog:

	PR libstdc++/108235
	* src/c++20/tzdb.cc (time_zone::_Impl::RulesCounter): New class
	template and partial specialization for synchronizing access to
	time_zone::_Impl::infos.
	(time_zone::_M_get_sys_info, reload_tzdb): Adjust uses of
	rules_counter.
2023-01-06 20:56:43 +00:00
Joseph Myers
5b68fb47bd c: C2x semantics for __builtin_tgmath
__builtin_tgmath implements <tgmath.h> semantics for integer generic
arguments that handle cases involving _FloatN / _FloatNx types as
specified in TS 18661-3 plus some defect fixes.

C2x has further changes to the semantics for <tgmath.h> macros with
such types, which should also be considered defect fixes (although
handled through the integration of TS 18661-3 in C2x rather than
through an issue tracking process).  Specifically, the rules were
changed because of problems raised with using the macros with the
evaluation format types such as float_t and _Float32_t: the older
version of the rules didn't allow passing _FloatN / _FloatNx types to
the narrowing macros returning float or double, or passing float /
double / long double to the narrowing macros returning _FloatN /
_FloatNx, which was a problem with the evaluation format types which
could be either kind of type depending on the value of
FLT_EVAL_METHOD.

Thus the new rules allow cases of mixing types which were not allowed
before - which is not itself a problem for __builtin_tgmath - and, as
part of the changes, the handling of integer arguments was also
changed: if there is any _FloatNx generic argument, integer generic
arguments are treated as _Float32x (not double), while the rule about
treating integer arguments to narrowing macros returning _FloatN or
_FloatNx as _Float64 not double was removed (no longer needed now
double is a valid argument to such macros).

Implement the changes for __builtin_tgmath.  (The changes also added a
rule that if any argument is _DecimalNx, integer arguments are treated
as _Decimal64x, but GCC doesn't support _DecimalNx types so nothing is
done about that.)

I have a corresponding glibc patch to update glibc test expectations
for C2x and also ensure that appropriate semantics are followed when
GCC 7 through 12 are used with <tgmath.h> (avoiding __builtin_tgmath
in cases where it doesn't match the C2x semantics).

Bootstrapped with no regressions for x86_64-pc-linux-gnu.

gcc/
	* doc/extend.texi (__builtin_tgmath): Do not restate standard rule
	for handling real integer types.

gcc/c/
	* c-parser.cc (c_parser_postfix_expression): Handle integer
	generic arguments to functions passed to __builtin_tgmath as
	_Float32x if any argument has _FloatNx or _Complex _FloatNx type.
	Do not handle integer arguments to some narrowing functions as
	_Float64.

gcc/testsuite/
	* gcc.dg/builtin-tgmath-3.c: Update expectations and add more
	tests.
2023-01-06 19:31:26 +00:00
Ian Lance Taylor
f3707a55ac libbacktrace: don't run --build-id tests if it is not supported
PR libbacktrace/108297
	* configure.ac: Test whether linker supports --build-id.
	* Makefile.am: Only run --build-id tests if supported.
	* configure, Makefile.in: Regenerate.
2023-01-06 09:41:57 -08:00
Patrick Palka
f7bd48c6bb libstdc++: Add feature-test macros for implemented C++23 views [PR108260]
PR libstdc++/108260

libstdc++-v3/ChangeLog:

	* include/bits/utility.h (__cpp_lib_ranges_zip): Define for C++23.
	* include/std/ranges (__cpp_lib_ranges_zip): Likewise.
	(__cpp_lib_ranges_chunk): Likewise.
	(__cpp_lib_ranges_slide): Likewise.
	(__cpp_lib_ranges_chunk_by): Likewise.
	(__cpp_lib_ranges_join_with): Likewise.
	(__cpp_lib_ranges_repeat): Likewise.
	(__cpp_lib_ranges_stride): Likewise.
	(__cpp_lib_ranges_cartesian_product): Likewise.
	(__cpp_lib_ranges_as_rvalue): Likewise.
	* include/std/version: Ditto.
	* testsuite/20_util/tuple/p2321r2.cc: Verify value of
	feature-test macro.
	* testsuite/std/ranges/adaptors/as_rvalue/1.cc: Likewise.
	* testsuite/std/ranges/adaptors/chunk/1.cc: Likewise.
	* testsuite/std/ranges/adaptors/chunk_by/1.cc: Likewise.
	* testsuite/std/ranges/adaptors/join_with/1.cc: Likewise.
	* testsuite/std/ranges/adaptors/slide/1.cc: Likewise.
	* testsuite/std/ranges/adaptors/stride/1.cc: Likewise.
	* testsuite/std/ranges/cartesian_product/1.cc: Likewise.
	* testsuite/std/ranges/repeat/1.cc: Likewise.
	* testsuite/std/ranges/zip/1.cc: Likewise.
	* testsuite/std/ranges/version_c++23.cc: New test.
2023-01-06 10:32:10 -05:00
Jonathan Wakely
553332c19a libstdc++: Fix misuse of alloca in std::bitset [PR108214]
The use of alloca in a constructor is wrong, because the memory is gone
after the constructor returns, and will be overwritten by a subsequent
function call. This didn't show up in testing because function inlining
alters the stack usage.

libstdc++-v3/ChangeLog:

	PR libstdc++/108214
	* include/std/bitset (operator>>): Use alloca in the right
	scope, not in a constructor.
	* testsuite/20_util/bitset/io/input.cc: Check case from PR.
2023-01-06 13:50:36 +00:00
Jonathan Wakely
8c330fd494 libstdc++: Disable broken std::format for floating-point types [PR108221]
If we don't have std::to_chars for floating-point types (either because
float and double are not IEEE format, or size_t is 16-bit) then we can't
use them with std::format. This causes a bootstrap failure since
std/c++20/tzdb.cc was added to the library, because <chrono> now
includes <format>.

This change just disables formatting support for those types. This is
not a proper fix, but solves the bootstrap failure for now.

libstdc++-v3/ChangeLog:

	PR libstdc++/108221
	* include/std/format (basic_format_arg) [!__cpp_lib_to_chars]:
	Disable visiting floating-point types.
2023-01-06 13:24:57 +00:00
Tamar Christina
a40c22c377 Revert "aarch64: Make existing V2HF be usable."
This reverts commit 2cba118e53.
2023-01-06 12:57:50 +00:00
Martin Liska
17176326de docs: fix Var documentation for .opt files
The Var documentation was somehow wrongly split into 2 pieces.

	PR middle-end/107966

gcc/ChangeLog:

	* doc/options.texi: Fix Var documentation in internal manual.
2023-01-06 13:05:26 +01:00
Jonathan Wakely
b9479ddc7a libstdc++: Fix deadlock in debug iterator increment [PR108288]
With -fno-elide-constructors the debug iterator post-increment and
post-decrement operators are susceptible to deadlock. They take a mutex
lock and then return a temporary, which also attempts to take a lock to
attach itself to the sequence. If the return value and *this happen to
collide and use the same mutex from the pool, then you get a deadlock
trying to lock a mutex that is already held by the current thread.

The solution is to construct the return value before taking the lock.
The copy constructor and pre-inc/pre-dec operators already manage locks
correctly, without deadlock, so just implement post-inc/post-dec in the
conventional way, taking a copy then modifying *this, then returning the
copy.

libstdc++-v3/ChangeLog:

	PR libstdc++/108288
	* include/debug/safe_iterator.h (_Safe_iterator::operator++(int))
	(_Safe_iterator::operator--(int)): Do not hold lock around
	construction of return value.
2023-01-06 11:52:01 +00:00
Jakub Jelinek
b990e80e39 testsuite: Add testcases from PR108292 and PR108308
These PRs were for now fixed by reversion of the r13-4977
patch, but so that the problems don't reappear during stage 1,
I'm adding testcase coverage from those PRs.

2023-01-06  Jakub Jelinek  <jakub@redhat.com>

	PR target/108292
	PR target/108308
	* gcc.c-torture/execute/pr108292.c: New test.
	* gcc.target/i386/pr108292.c: New test.
	* gcc.dg/pr108308.c: New test.
2023-01-06 10:52:34 +01:00
Clément Chigot
5977d14a60 configure: remove dependencies on gmp and mpfr when gdb is disabled
Since 91e0d22025, the configure checks
about GMP and MPFR for gdb builds have been moved to the toplevel
configure.
However, it doesn't take into account the --disable-gdb option. Meaning
that a build without gdb will require these libraries even if not
needed.

ChangeLog:

	* configure.ac: Skip GMP and MPFR when --disable-gdb is
	provided.
	* configure: Regenerate.
2023-01-06 09:36:52 +01:00
Martin Liska
55f813f5cd contrib: add 'contrib' to default dirs in update-copyright.py
contrib/ChangeLog:

	* update-copyright.py: Add contrib as a default dir.
2023-01-06 08:45:24 +01:00
v
53add16251 PR-108294 soname bump for modula2 runtime libraries.
The soname for the Modula-2 runtime libraries for the compiler based on
GCC 12 is 17 and didn't change for GCC 13.  This patch bumps the version
to 18.

libgm2/ChangeLog:

	* configure: Regenerate.
	* configure.ac (libtool_VERSION): Bump to 18:0:0.

Signed-off-by:  <gaiusmod2@gmail.com>
2023-01-06 04:50:09 +00:00
GCC Administrator
53ef7c1d9a Daily bump. 2023-01-06 00:17:35 +00:00
Roger Sayle
9e6ac747ac [Committed] PR rtl-optimization/108292: Revert "Improve ix86_expand_int_movcc to allow condition (mask) sharing"
This reverts commit d0558f420b.

2023-01-05  Roger Sayle  <roger@nextmovesoftware.com>

gcc/ChangeLog
	PR rtl-optimization/108292
	* config/i386/i386-expand.cc (ix86_expand_int_movcc): Revert
	previous changes.

gcc/testsuite/ChangeLog
	PR rtl-optimization/108292
	* gcc.target/i386/cmov10.c: Remove test case.
2023-01-05 19:49:45 +00:00
Patrick Palka
12b0d35ec5 c++: class-head parsing and CPP_TEMPLATE_ID access [PR108275]
When tentatively parsing what is really an elaborated-type-specifier
containing a template-id first as a class-specifier, we may form a
CPP_TEMPLATE_ID token that later gets reused by the fallback parse if
the tentative parse fails.  These special tokens also capture the access
checks that have been deferred while parsing the template-id.  But here
we form such a token when the access check state is dk_no_check, and so
the token captures no access checks.  This effectively bypasses access
checking for the template-id during the subsequent parse as an
elaborated-type-specifier.

This patch fixes this by using dk_deferred instead of dk_no_check when
parsing the class name of a class-head.

	PR c++/108275

gcc/cp/ChangeLog:

	* parser.cc (cp_parser_class_head): Use dk_deferred instead of
	dk_no_check when parsing the class name.

gcc/testsuite/ChangeLog:

	* g++.dg/parse/access14.C: New test.
2023-01-05 14:21:34 -05:00
John David Anglin
9807c31af9 Fix atomic operations on PA-RISC 2.0 processors.
PA-RISC 2.0 supports out-of-order execution for loads and stores.
Thus, we need to synchonize memory accesses.

This change revises the lock releases in __exchange_and_add and
__atomic_add to use an ordered store with release semantics.  We
also use an ordered load in the inner spin loop.

We use the "ldcw,co" instruction instead of "ldcw" when compiled
for PA 2.0.  Most PA 2.0 processors are coherent and can execute
the ldcw instruction in cache for improved performance.

Finally, the inner spin loop is revised to immediately branch to
the ldcw instruction when it detects the lock is free.

2023-01-05  John David Anglin  <danglin@gcc.gnu.org>

libstdc++-v3/ChangeLog:

	* config/cpu/hppa/atomicity.h (_PA_LDCW_INSN): Define.
	(__exchange_and_add): Use _PA_LDCW_INSN.  Use ordered store for
	lock release.  Revise loop.
	(__atomic_add): Likewise.
2023-01-05 18:15:18 +00:00
Iain Sandoe
4413365616 modula-2: Remove uses of scalb*() and significand*() [PR107631]
The scalb*() functions are obsolete in Posix from 2004 and removed in
2008.

The significand*() functions are glibc-only and considered there to be
obsolescent (not supported for types such as _Float128).

We can remove them from Modula-2 since they are not required for ISO
support, but we need to provide an implementation of significand* for
the "fraction()" functions.

	PR modula2/107631

gcc/m2/ChangeLog:

	* gm2-gcc/m2builtins.cc: Remove scalb, scalbf, scalbl,
	significand, significandf, significandl.
	* gm2-libs/Builtins.def (significand): Likewise.
	* gm2-libs/Builtins.mod: Likewise.
	* target-independent/Builtins.texi: Likewise.
	* gm2-libs-iso/LowLong.mod: Implement fraction with scalbn*() and
	ilogb*().
	* gm2-libs-iso/LowReal.mod: Likewise.
	* gm2-libs-iso/LowShort.mod: Likewise.
2023-01-05 16:55:30 +00:00
Jonathan Wakely
80ff207da6 libstdc++: Fix <chrono> printers for Python 2 [PR108212]
The datetime.timezone.utc singleton doesn't exist in Python 2, but we
can create it ourselves by deriving from datetime.tzinfo.

libstdc++-v3/ChangeLog:

	PR libstdc++/108212
	* python/libstdcxx/v6/printers.py (_utc_timezone): New global
	variable.
	(StdChronoTimePointPrinter::to_string): Use it.
2023-01-05 16:28:43 +00:00
Jonathan Wakely
e2eab3c4ed libstdc++: Reduce size of std::bind_front(empty_type) result [PR108290]
libstdc++-v3/ChangeLog:

	PR libstdc++/108290
	* include/std/functional (_Bind_front): Add no_unique_address
	attribute to data members.
	* testsuite/20_util/function_objects/bind_front/107784.cc: Check
	size of call wrappers with empty types for targets and bound
	arguments.
2023-01-05 16:28:43 +00:00
David Malcolm
efce0caf2d gccrs: avoid printing to stderr in selftest::rust_flatten_list
gcc/rust/ChangeLog:
	* resolve/rust-ast-resolve-item.cc (selftest::rust_flatten_list):
	Remove output to stderr.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2023-01-05 10:01:38 -05:00
David Malcolm
b0edfa0ef0 gccrs: add selftest-rust-gdb and selftest-rust-valgrind "make" targets
Add "make" targets to make it easy to run the rust selftests under gdb
and under valgrind via:
  make selftest-rust-gdb
and
  make selftest-rust-valgrind
respectively.

gcc/rust/ChangeLog:
	* Make-lang.in (selftest-rust-gdb): New.
	(selftest-rust-valgrind): New.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2023-01-05 10:01:37 -05:00
Eric Botcazou
bd96a6a8a6 ada: Minor tweak to test added in previous change
This changes the test to use the common idion of the codebase.

gcc/ada/

	* exp_util.adb (Make_CW_Equivalent_Type) <Has_Tag_Of_Type>: Tweak.
2023-01-05 15:30:02 +01:00
Eric Botcazou
09e0175327 ada: Clean up interface handling in Expand_N_Object_Declaration
The code performing the expansion of objects with (class-wide) interface
type in Expand_N_Object_Declaration is fairly low-level, fiddling with the
homonym and entity chains, which is unnecessary.

gcc/ada/

	* exp_ch3.adb (Expand_N_Object_Declaration): Rewrite the end of the
	handling of objects with (class-wide) interface type by using the
	same idiom as the other cases generating a renaming.
	* exp_util.adb (Is_Displacement_Of_Object_Or_Function_Result): Tweak
	pattern matching code and exclude special return objects.
	(Requires_Cleanup_Actions): Adjust comment.
	* exp_ch7.adb (Build_Finalizer): Likewise.
2023-01-05 15:30:02 +01:00
Piotr Trojanek
9ff806899b ada: Flag renaming-as-spec as a body to inline
For GNAT the frontend is only inlining subprograms with explicit specs,
including specs completed with renaming-as-body. For GNATprove the
frontend must also inline renamings acting as specs. Otherwise, we will
try to build a body-to-inline with code that is can't handle unusual
subprogram renamings, e.g. those of the form "object.call".

gcc/ada/

	* freeze.adb (Build_Renamed_Body): Rewrite subprogram renaming to
	subprogram declaration early and then set the Body_To_Inling flag.
2023-01-05 15:30:02 +01:00
Piotr Trojanek
6147feb54c ada: Remove unhelpful special case for renamed bodies in GNATprove mode
This patch reverts a special-case related to inlining of renamed bodies
in GNATprove mode. Its idea was that inlining is decided in routine
Cannot_Inline, which is called much later. This didn't quite work,
because in the meantime the renamed body was prepared to inlining in
Build_Body_To_Inline, which was not designed to handle renamed bodies.

gcc/ada/

	* freeze.adb (Build_Renamed_Body): Revert a special case for
	GNATprove; remove unnecessary initialization of a local variable.
2023-01-05 15:30:02 +01:00
Marc Poulhiès
07facb98ed ada: Fix nested generic instantiation
Previous fix for generic instantiation was not precise enough and could
wrongly assume the instantiation node to be an N_Expanded_Name.

gcc/ada/

	* sem_ch12.adb (Instantiate_Package_Body): Better filtering when
	installing parent on the scope stack.
2023-01-05 15:30:01 +01:00
Eric Botcazou
3f7776ea33 ada: Do not use decimal approximation in -gnatRj output
This avoids an unnecessary loss of precision for real values.

gcc/ada/

	* repinfo.ads (The JSON output format): Document change.
	* urealp.adb (UR_Write_To_JSON): Output a fraction instead of a
	decimal approximation.
2023-01-05 15:30:01 +01:00
Eric Botcazou
133a8e6339 ada: Optimize class-wide objects initialized with function calls
This optimizes the implementation of class-wide objects initialized with
function calls in the non-interface case, by avoiding an unnecessary copy
operation and/or a dispatching call to the _Size primitive when possible.

gcc/ada/

	* exp_ch3.adb (Expand_N_Object_Declaration): New local variable
	Func_Id holding the function for a special return object.
	Use a direct renaming in the class-wide case when the initializing
	expression is a captured function call, except for a special return
	object when the two functions do not return on the same stack.
	Apply the accessibility check for class-wide special return objects.
	* exp_util.adb (Make_CW_Equivalent_Type) <Has_Tag_Of_Type>: New.
	Do not force a dispatching call to the primitive operation _Size if
	the expression is known to statically have the tag of its type.
2023-01-05 15:30:01 +01:00
Eric Botcazou
229f5150ad ada: Fix pasto in comment
gcc/ada/

	* exp_ch3.adb (Expand_N_Object_Declaration): Fix pasto in comment.
2023-01-05 15:30:01 +01:00
Ronan Desplanques
a124b52631 ada: Fix spurious emissions of -gnatwj warning
Before this patch, the compiler would erroneously emit a warning
about the use of parentheses for array aggregates being discouraged
in some situations. Those situations were the ones where array
aggregates were used as generic actuals when instantiating generic
packages defined in the runtime library.

This patch fixes this issue by looking at the Ada version explicitly
specified by the user instead of the Ada_Version flag which is
always set to the latest Ada version when compiling code from the
runtime library.

gcc/ada/

	* sem_aggr.adb (Resolve_Array_Aggregate): Tweak conditions for
	warning about use of parentheses for array aggregates.
2023-01-05 15:30:00 +01:00
Javier Miranda
9ef547a7a9 ada: INOX: prototype RFC on String Interpolation
This patch incorporates a prototype for a new string literal syntax
which supports the use of "string interpolation," where the names
of variables or expressions can be used directly within the string
literal, such that the value of the variable or the expression is
"interpolated" directly into the value of the enclosing string
upon use at run-time.

gcc/ada/

	* scans.ads (Tok_Left_Curly_Bracket, Tok_Right_Curly_Bracket)
	(Tok_Left_Interpolated_String): Placed in no category since they
	don't fit well in the existing categories. Fix typo in comment.
	(Inside_Interpolated_String_Literal): New scan state variable.
	* scng.adb (Slit): Scan interpolated string literals,
	continuations of interpolated string literals and escaped
	characters found in interpolated string literals.
	(Scan): Handle consecutive interpolated expressions. Handle ending
	delimiter placed immediately after an interpolated expression.
	Handle string literal placed after interpolated expression. Handle
	left and right curly brackets; when extensions are not allowed
	they are treated as left and right paren; when extensions are
	allowed they are handled as delimiters of interpolated string
	literals.
	* sinfo.ads (N_Interpolated_String_Literal): New node.
	* gen_il-gen-gen_nodes.adb (N_Interpolated_String_Literal): Define
	N_String_Literal node.
	* gen_il-types.ads (Opt_Type_Enum): Define N_String_Literal as
	concrete node type.
	* par-ch2.adb (P_Interpolated_String_Literal): New subprogram.
	* par-ch4.adb (P_Simple_Expression): Handle '}' as expression
	terminator when scanning an interpolated expression; disable error
	recovery machinery for binary operator when we are processing an
	interpolated string literal and reach the expression terminator
	'}'.
	(P_Primary): Call P_Interpolated_String_Literal when the opening
	interpolated-string-literal delimiter is found (that is, the left
	curly bracket '{').
	* par-tchk.adb (T_Right_Curly_Bracket): New subprogram.
	* par.adb (P_Interpolated_String_Literal): New declaration.
	(T_Right_Curly_Bracket): New declaration.
	* sem.adb (Analyze): Call Analyze_Interpolated_String_Literal.
	* sem_ch2.ads (Analyze_Interpolated_String_Literal): New
	subprogram
	* sem_ch2.adb (Analyze_Interpolated_String_Literal): Likewise.
	* sem_util.adb (Is_User_Defined_Literal): Complete mapping of
	literal aspects adding that interpolated string literals have no
	correspondence with any aspect.
	* sem_res.adb (Resolve_Interpolated_String_Literal): New
	subprogram.
	(Has_Applicable_User_Defined_Literal): Complete mapping of literal
	aspects adding that interpolated string literals have no
	correspondency with any aspect.
	* expander.adb (Expand): Add call to
	Expand_N_Interpolated_String_Literal.
	* exp_util.adb (Insert_Actions): Handle
	N_Interpolated_String_Literal nodes; that is, continue climbing.
	* exp_ch2.ads (Expand_N_Interpolated_String_Literal): New
	subprogram.
	* exp_ch2.adb (Expand_N_Interpolated_String_Literal): Likewise.
	* exp_put_image.adb (Build_Elementary_Put_Image_Call): Add missing
	conversion to force dispatching call. Required to handle calls to
	descendants.
	(Build_String_Put_Image_Call): Do not output string delimiters
	when the put_image call is part of an interpolated string literal.
	* rtsfind.ads (RTU_Id): Add RE_Set_Trim_Leading_Spaces.
	* sprint.adb (Sprint_Node): Output interpolated string contents.
	* libgnat/a-stbubo.adb (Get_UTF_8): Add default value for
	Trim_Leading_White_Spaces component in aggregate.
	(Buffer_Type_Implementation): Update Trim_Leading_White_Spaces.
	* libgnat/a-stbuun.adb (Get_UTF_8): Likewise.
	(Buffer_Type_Implementation): Likewise.
	* libgnat/a-sttebu.ads (Set_Trim_Leading_Spaces): New subprogram.
	(Trim_Leading_Spaces): New subprogram.
	(Root_Buffer_Type): Adding Trim_Leading_While_Spaces component.
	* libgnat/a-sttebu.adb (procedure Set_Trim_Leading_Spaces): New
	subprogram.
	(Trim_Leading_Space): New subprogram.
	(Put_UTF_8): Handle Trim_Leading_White_Spaces.
	(New_Line): Likewise.
	* libgnat/s-putima.ads (Put_Image_String): Adding formal
	(with_delimiters).
	(Put_Image_Wide_String): Likewise.
	(Put_Image_Wide_Wide_String): Likewise.
	* libgnat/s-putima.adb (Put_Image_String): Adding support for new
	formal.
	(Put_Image_Wide_String): Likewise.
	(Put_Image_Wide_Wide_String): Likewise.
2023-01-05 15:30:00 +01:00
Joao Azevedo
e45bef1ec6 ada: Update gnatpp documentation with --layout switch
Update legacy switches.

gcc/ada/

	* doc/gnat_ugn/gnat_utility_programs.rst: add gnatpp --layout
	switch and update legacy switches.
2023-01-05 15:30:00 +01:00
Eric Botcazou
59d1681bf3 ada: Further adjust freezing for expansion of contracts
This further adjusts a test deciding whether to freeze an entity coming from
an outer scope in an inner scope based on language rules, to the presence of
the new internal subprogram generated because of post-conditions.

gcc/ada/

	* freeze.adb (Freeze_Entity): For the purpose of deciding whether to
	freeze an entity coming from an outer scope in an inner scope, treat
	the internal subprogram generated because of post-conditions as also
	coming from source if the original subprogram itself does.
2023-01-05 15:30:00 +01:00
Eric Botcazou
f0bed52ec9 ada: Simplify new expansion of contracts
We can now use an extended return statement in all cases since it no longer
generates an extra copy for nonlimited by-reference types.

gcc/ada/

	* contracts.adb (Build_Subprogram_Contract_Wrapper): Generate an
	extended return statement in all cases.
	(Expand_Subprogram_Contract): Adjust comment.
2023-01-05 15:29:59 +01:00
Ronan Desplanques
90d3cd03b3 ada: Adjust handling of "%g" in GNAT.Formatted_String
The way the "%g" specifier was handled by GNAT.Formatted_String
before this patch was very different from the behavior of C's printf.
This patch makes the handling of "%g" in GNAT.Formatted_String closer
to the behavior described in the specification of the C language.

gcc/ada/

	* libgnat/g-forstr.adb (F_Kind): Rename enumeration literal.
	(P_Flt_Format): Adjust handling of "%g".
	(Determine_Notation_And_Aft): New procedure.
	(Decimal_Exponent): New function.
	(Increment_Integral_Part): New procedure.
	(Remove_Extraneous_Decimal_Digit): New procedure.
	(Trim_Fractional_Part): New procedure.
	* libgnat/g-forstr.ads: Change description of "%g" specifier.
2023-01-05 15:29:59 +01:00
Marc Poulhiès
912d1e184a ada: Fix generic instantiation of sibling package
The compiler would crash because it is failing at setting up the scope
stack correctly for a generic instantiation of a sibling package within
a child package instance. In this case, the parent instance isn't
explicitly referenced and it must be found differently.

gcc/ada/

	* sem_ch12.adb (Instantiate_Package_Body): Correctly find the
	parent instance to place on the scope stack.
2023-01-05 15:29:59 +01:00
Justin Squirek
2aa5f94243 ada: Spurious error on Lock_Free protected type with discriminants
This patch corrects an issue in the compiler whereby unprefixed discriminants
appearing in protected subprograms were unable to be properly resolved -
leading to spurious resolution errors.

gcc/ada/

	* sem_ch8.adb (Set_Entity_Or_Discriminal): Verify we are actually
	resetting the entity field of a non-prefixed discriminant
	reference.
2023-01-05 15:29:59 +01:00
Eric Botcazou
8313c5f600 ada: Revert to constrained allocation for string concatenation
Using an unconstrained allocation is less efficient in the general case.

gcc/ada/

	* exp_ch3.adb (Expand_N_Object_Declaration): New local variable used
	throughout instead of testing Is_Special_Return_Object every time.
	Do not rename an OK_To_Rename object for a special return object.
	* exp_ch4.adb (Expand_Concatenate): Revert to constrained allocation
	if the result is allocated on the secondary stack.
2023-01-05 15:29:58 +01:00
Steve Baird
0776fec155 ada: Better error message for bad Discard_Names configuration pragma
When a pragma Discard_Names is used as a configuration pragma, it does not
take an argument. If an argument is given, the resulting error message was
incorrect and confusing.

gcc/ada/

	* sem_prag.adb (Analyze_Pragma): Fix Is_Configuration_Pragma
	function to handle case where the pragma's parent is an
	N_Aspect_Specification node. In analyzing a Discard_Names pragma,
	do not assume that a nonzero number of arguments implies that the
	pragma is not a configuration pragma; that assumption only holds
	for legal programs.
2023-01-05 15:29:58 +01:00
Bob Duff
0a8824f702 ada: Update doc for -gnatw_q
The -gnatw_q switch turns on warnings for noncomposing "="
operators. This patch updates the doc to refer to relevant
RM paragraphs.

gcc/ada/

	* doc/gnat_ugn/building_executable_programs_with_gnat.rst:
	Add RM references.
	* gnat_ugn.texi: Regenerate.
2023-01-05 15:29:58 +01:00
Eric Botcazou
d990f34e93 ada: Fix finalization issues in extended return statements
The first issue pertains to return objects of (class-wide) interface types,
which need to be adjusted if the type is not inherently limited.  The second
issue is for return objects of non-class-wide types that are initialized by
a function call, which can use a direct renaming only if the object doing
the capture of the function call is flagged by Is_Related_To_Func_Return.
The third one is that, in the second case, we may need to reassign the tag.

gcc/ada/

	* exp_ch3.adb (Expand_N_Object_Declaration): For a special return
	object of an interface type that is not inherently limited, make
	a call to the Adjust primitive after doing the copy.  For a special
	return object of a non-class-wide type initialized by a function
	call, use a direct renaming only if the object doing the capture
	is flagged by Is_Related_To_Func_Return.  For a special return
	object using a direct renaming, reassign the tag, if need be.
	* exp_ch6.adb (Expand_Simple_Function_Return): Fix comment.
	* exp_util.adb (Is_Related_To_Func_Return): Accept both regular and
	renaming object declarations for return objects.
2023-01-05 15:29:57 +01:00
Bob Duff
46924ad780 ada: Fix incorrect warning about unreferenced packed arrays
This patch fixes a bug in which a reference to a renaming of a
component of a packed array was not counted as a reference,
and thus caused incorrect warnings about unreferenced objects.

gcc/ada/

	* sem_ch5.adb (Analyze_Assignment): Fix the bug by checking
	Original_Node. The renaming might be elsewhere, but the (original)
	reference is right here.
	* errout.adb: Remove pragma Unreferenced which was added because
	of the above bug.
	* einfo.ads: Misc cleanup.
	* lib.adb: Likewise.
	* lib.ads: Likewise.
2023-01-05 15:29:57 +01:00