Gaius Mulley [Tue, 7 Jan 2025 11:20:45 +0000 (11:20 +0000)]
[PR modula2/118010, modula2/118183] Unable to rebuild the bootstrap tools and Wtypemismatch
This patch combines fixes for both PR-118010 (Wtypemismatch) and PR-118183
(unable to rebuild the bootstrap tools). PR-118010 required a new data
type (COFF_T) to be exported from SYSTEM and used in all return
types for libc.lseek. The patch also includes COFF_T implemented in mc
and this data type has been propagated though the translated versions
of pge and mc. Finally the patch adjusts the modula-2 declaration of
location_t to reflect the new gcc 64 bit type.
A new command line option -fm2-file-offset-bits= has been implemented to
override the default 64 bit declaration of COFF_T.
gcc/ChangeLog:
PR modula2/118010
* doc/gm2.texi (Compiler options): New option
-fm2-file-offset-bits=.
Fortran: Extend cylic type detection for deallocate [PR116669]
Using cycles in derived/class types lead to the compiler doing a endless
recursion in several locations, when the cycle was not immediate.
An immediate cyclic dependency is present in, for example T T::comp.
Cylcic dependencies of the form T T2::comp; T2 T::comp2; are now
detected and the recursive bit in the derived type's attr is set.
gcc/fortran/ChangeLog:
PR fortran/116669
* class.cc (gfc_find_derived_vtab): Use attr to determine cyclic
type dependendies.
* expr.cc (gfc_has_default_initializer): Prevent endless
recursion by storing already visited derived types.
* resolve.cc (resolve_cyclic_derived_type): Determine if a type
is used in its hierarchy in a cyclic way.
(resolve_fl_derived0): Call resolve_cyclic_derived_type.
(resolve_fl_derived): Ensure vtab is generated when cyclic
derived types have allocatable components.
* trans-array.cc (structure_alloc_comps): Prevent endless loop
for derived type cycles.
* trans-expr.cc (gfc_get_ultimate_alloc_ptr_comps_caf_token):
Off topic, just prevent memory leaks.
gcc/testsuite/ChangeLog:
* gfortran.dg/class_array_15.f03: Freeing more memory.
* gfortran.dg/recursive_alloc_comp_6.f90: New test.
This patch removes the AARCH64_EXTRA_TUNE_USE_NEW_VECTOR_COSTS tunable and
use_new_vector_costs entry in aarch64-tuning-flags.def and makes the
AARCH64_EXTRA_TUNE_USE_NEW_VECTOR_COSTS paths in the backend the
default. To that end, the function aarch64_use_new_vector_costs_p and its uses
were removed. To prevent costing vec_to_scalar operations with 0, as
described in
https://gcc.gnu.org/pipermail/gcc-patches/2024-October/665481.html,
we adjusted vectorizable_store such that the variable n_adjacent_stores
also covers vec_to_scalar operations. This way vec_to_scalar operations
are not costed individually, but as a group.
As suggested by Richard Sandiford, the "known_ne" in the multilane-check
was replaced by "maybe_ne" in order to treat nunits==1+1X as a vector
rather than a scalar.
Two tests were adjusted due to changes in codegen. In both cases, the
old code performed loop unrolling once, but the new code does not:
Example from gcc.target/aarch64/sve/strided_load_2.c (compiled with
-O2 -ftree-vectorize -march=armv8.2-a+sve -mtune=generic -moverride=tune=none):
f_int64_t_32:
cbz w3, .L92
mov x4, 0
uxtw x3, w3
+ cntd x5
+ whilelo p7.d, xzr, x3
+ mov z29.s, w5
mov z31.s, w2
- whilelo p6.d, xzr, x3
- mov x2, x3
- index z30.s, #0, #1
- uqdecd x2
- ptrue p5.b, all
- whilelo p7.d, xzr, x2
+ index z30.d, #0, #1
+ ptrue p6.b, all
.p2align 3,,7
.L94:
- ld1d z27.d, p7/z, [x0, #1, mul vl]
- ld1d z28.d, p6/z, [x0]
- movprfx z29, z31
- mul z29.s, p5/m, z29.s, z30.s
- incw x4
- uunpklo z0.d, z29.s
- uunpkhi z29.d, z29.s
- ld1d z25.d, p6/z, [x1, z0.d, lsl 3]
- ld1d z26.d, p7/z, [x1, z29.d, lsl 3]
- add z25.d, z28.d, z25.d
+ ld1d z27.d, p7/z, [x0, x4, lsl 3]
+ movprfx z28, z31
+ mul z28.s, p6/m, z28.s, z30.s
+ ld1d z26.d, p7/z, [x1, z28.d, uxtw 3]
add z26.d, z27.d, z26.d
- st1d z26.d, p7, [x0, #1, mul vl]
- whilelo p7.d, x4, x2
- st1d z25.d, p6, [x0]
- incw z30.s
- incb x0, all, mul #2
- whilelo p6.d, x4, x3
+ st1d z26.d, p7, [x0, x4, lsl 3]
+ add z30.s, z30.s, z29.s
+ incd x4
+ whilelo p7.d, x4, x3
b.any .L94
.L92:
ret
Alexandre Oliva [Fri, 20 Dec 2024 21:02:08 +0000 (18:02 -0300)]
expand: drop stack adjustments after barrier [PR118006]
A gimple block with __builtin_unreachable () can't have code after it,
and gimple optimizers ensure there isn't any, even without
optimization. But if the block requires stack adjustments,
e.g. because of a call that passes arguments on the stack, expand will
emit that after the barrier, and then rtl checkers rightfully
complain. Arrange to discard adjustments after a barrier.
Strub expanders seem to be necessary to bring about the exact
conditions that require stack adjustments after the block that ends
with a __builtin_unreachable call.
for gcc/ChangeLog
PR middle-end/118006
* cfgexpand.cc (expand_gimple_basic_block): Do not emit
pending stack adjustments after a barrier.
Akram Ahmad [Mon, 6 Jan 2025 20:09:30 +0000 (20:09 +0000)]
aarch64: remove extra XTN in vector concatenation
GIMPLE code which performs a narrowing truncation on the result of a
vector concatenation currently results in an unnecessary XTN being
emitted following a UZP1 to concate the operands. In cases such as this,
UZP1 should instead use a smaller arrangement specifier to replace the
XTN instruction. This is seen in cases such as in this GIMPLE example:
int32x2_t foo (svint64_t a, svint64_t b)
{
vector(2) int vect__2.8;
long int _1;
long int _3;
vector(2) long int _12;
bar:
ptrue p3.b, all
uaddv d0, p3, z0.d
uaddv d1, p3, z1.d
uzp1 v0.2d, v0.2d, v1.2d
xtn v0.2s, v0.2d
ret
This patch therefore defines the *aarch64_trunc_concat<mode> insn which
truncates the concatenation result, rather than concatenating the
truncated operands (such as in *aarch64_narrow_trunc<mode>), resulting
in the following optimised assembly being emitted:
bar:
ptrue p3.b, all
uaddv d0, p3, z0.d
uaddv d1, p3, z1.d
uzp1 v0.2s, v0.2s, v1.2s
ret
This patch passes all regression tests on aarch64 with no new failures.
A supporting test for this optimisation is also written and passes.
OK for master? I do not have commit rights so I cannot push the patch
myself.
gcc/ChangeLog:
* config/aarch64/aarch64-simd.md: (*aarch64_trunc_concat)
new insn definition.
gcc/testsuite/ChangeLog:
* gcc.target/aarch64/sve/truncated_concatenation_1.c: new test
for the above example and other modes covered by insn
definitions.
```
In file included from /gcc/src/libsanitizer/interception/interception.h:18,
from /gcc/src/libsanitizer/interception/interception_type_test.cpp:14:
/gcc/src/libsanitizer/interception/interception_type_test.cpp:30:61: error: static assertion failed
30 | COMPILER_CHECK((__sanitizer::is_same<::SSIZE_T, ::ssize_t>::value));
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
/gcc/src/libsanitizer/sanitizer_common/sanitizer_internal_defs.h:363:44: note: in definition of macro 'COMPILER_CHECK'
363 | #define COMPILER_CHECK(pred) static_assert(pred, "")
| ^~~~
make[8]: *** [Makefile:469: interception_type_test.lo] Error 1
```
The culprit seems to be that we don't check for equality of type sizes
anymore but rather whether the types are indeed the same. On s390 -m31
we have that `sizeof(int)==sizeof(long)` holds which is why previously
the checks succeeded. They fail now because
```
size_t => unsigned long
ssize_t => long
ptrdiff_t => int
::SSIZE_T => __sanitizer::sptr => int
::PTRDIFF_T => __sanitizer::sptr => int
```
This is fixed by mapping `SSIZE_T` to `long` in the end.
For some targets uptr is mapped to unsigned int and size_t to unsigned
long and sizeof(int)==sizeof(long) holds. Still, these are distinct
types and type checking may fail. Therefore, replace uptr by
usize/SIZE_T wherever a size_t is expected.
Stafford Horne [Mon, 6 Jan 2025 12:12:40 +0000 (12:12 +0000)]
or1k: add .note.GNU-stack section on linux
In the OpenRISC build we get the following warning:
ld: warning: __modsi3_s.o: missing .note.GNU-stack section implies executable stack
ld: NOTE: This behaviour is deprecated and will be removed in a future version of the linker
Fix this by adding a .note.GNU-stack to indicate the stack does not need to be
executable for the lib1funcs.
Note, this is also needed for the upcoming glibc 2.41.
libgcc/
* config/or1k/lib1funcs.S: Add .note.GNU-stack section on linux.
SVE intrinsics: Fold svmul by -1 to svneg for unsigned types
As follow-up to
https://gcc.gnu.org/pipermail/gcc-patches/2024-October/665472.html,
this patch implements folding of svmul by -1 to svneg for
unsigned SVE vector types. The key idea is to reuse the existing code that
does this fold for signed types and feed it as callback to a helper function
that adds the necessary type conversions.
For example, for the test case
svuint64_t foo (svuint64_t x, svbool_t pg)
{
return svmul_n_u64_x (pg, x, -1);
}
the following gimple sequence is emitted (-O2 -mcpu=grace):
svuint64_t foo (svuint64_t x, svbool_t pg)
{
svint64_t D.12921;
svint64_t D.12920;
svuint64_t D.12919;
In general, the new helper gimple_folder::convert_and_fold
- takes a target type and a function pointer,
- converts the lhs and all non-boolean vector types to the target type,
- passes the converted lhs and arguments to the callback,
- receives the new gimple statement from the callback function,
- adds the necessary view converts to the gimple sequence,
- and returns the new call.
Because all arguments are converted to the same target types, the helper
function is only suitable for folding calls whose arguments are all of
the same type. If necessary, this could be extended to convert the
arguments to different types differentially.
The patch was bootstrapped and tested on aarch64-linux-gnu, no regression.
OK for mainline?
Signed-off-by: Jennifer Schmitz <jschmitz@nvidia.com>
gcc/ChangeLog:
* config/aarch64/aarch64-sve-builtins-base.cc
(svmul_impl::fold): Wrap code for folding to svneg in lambda
function and pass to gimple_folder::convert_and_fold to enable
the transform for unsigned types.
* config/aarch64/aarch64-sve-builtins.cc
(gimple_folder::convert_and_fold): New function that converts
operands to target type before calling callback function, adding the
necessary conversion statements.
(gimple_folder::redirect_call): Set fntype of redirected call.
(get_vector_type): Move from here to aarch64-sve-builtins.h.
* config/aarch64/aarch64-sve-builtins.h
(gimple_folder::convert_and_fold): Declare function.
(get_vector_type): Move here as inline function.
gcc/testsuite/ChangeLog:
* gcc.target/aarch64/sve/acle/asm/mul_u8.c: Adjust expected outcome.
* gcc.target/aarch64/sve/acle/asm/mul_u16.c: Likewise.
* gcc.target/aarch64/sve/acle/asm/mul_u32.c: Likewise.
* gcc.target/aarch64/sve/acle/asm/mul_u64.c: New test and adjust
expected outcome.
Martin Jambor [Mon, 6 Jan 2025 10:58:29 +0000 (11:58 +0100)]
ipa-cp: Make dumping of bit masks representing -1 nicer
Dumps of the lattices representing bit-values and of propagation
results of bit-values can print a really long hexadecimal value when
the bit-value represents -1 (all bits set). This patch simply detect
that situation and prints the string "-1" in that case, making the
dumps somewhat nicer.
gcc/ChangeLog:
2025-01-03 Martin Jambor <mjambor@suse.cz>
* ipa-cp.cc (ipcp_print_widest_int): New function.
(ipcp_store_vr_results): Use it.
(ipcp_bits_lattice::print): Likewise. Fix formatting.
Mark Wielaard [Sun, 5 Jan 2025 17:00:36 +0000 (18:00 +0100)]
tree-switch-conversion: don't apply switch size limit on jump tables
commit 56946c801a7c ("gimple: Add limit after which slower switchlower
algs are used [PR117091] [PR117352]") introduced a limit on the number
of cases of a switch. It also bails out on finding jump tables if the
switch is too large. This introduces a compile time regression during
bootstrap. A riscv bootstrap takes hours longer. Particularly
insn-attrtab.cc will take hours instead of minutes. Fix this by not
applying the switch size limit on jump tables.
An alternative would be to implement greedy switch clustering for jump
tables as is done for switch bitmap clustering.
Tamar Christina [Mon, 6 Jan 2025 09:24:36 +0000 (09:24 +0000)]
AArch64: Implement four and eight chunk VLA concats [PR118272]
The following testcase
#pragma GCC target ("+sve")
extern char __attribute__ ((simd, const)) fn3 (int, short);
void test_fn3 (float *a, float *b, double *c, int n)
{
for (int i = 0; i < n; ++i)
a[i] = fn3 (b[i], c[i]);
}
at -Ofast ICEs because my previous patch only added support for combining 2
partial SVE vectors into a bigger vector. However There can also 4 and 8
piece subvectors.
This patch fixes this by implementing the missing expansions.
gcc/ChangeLog:
PR target/96342
PR target/118272
* config/aarch64/aarch64-sve.md (vec_init<mode><Vquad>,
vec_initvnx16qivnx2qi): New.
* config/aarch64/aarch64.cc (aarch64_sve_expand_vector_init_subvector):
Rewrite to support any arbitrary combinations.
* config/aarch64/iterators.md (SVE_NO2E): Update to use SVE_NO4E
(SVE_NO2E, Vquad): New.
gcc/testsuite/ChangeLog:
PR target/96342
PR target/118272
* gcc.target/aarch64/vect-simd-clone-3.c: New test.
Eric Botcazou [Fri, 13 Dec 2024 18:17:00 +0000 (19:17 +0100)]
ada: Streamline runtime support of finalization collections
Finalization collections are declared as (limited) controlled types so that
they can be naturally attached to a finalization master, but the same result
can be achieved by means of (limited) finalizable types, which need not be
tagged and thus avoid dragging the runtime support of tagged types.
gcc/ada/ChangeLog:
* libgnat/s-finpri.ads: Remove clause for Ada.Finalization.
(Finalization_Collection): Change to limited private type with the
Finalizable aspect.
(Initialize): Remove "overriding" keyword.
(Finalize): Likewise.
* libgnat/s-finpri.adb (Initialize): Likewise.
(Finalize): Likewise.
Eric Botcazou [Thu, 12 Dec 2024 22:08:30 +0000 (23:08 +0100)]
ada: Fix predicate involving array indexing rejected in generic package
The indexing is rejected with the message:
error: reference to current instance of type does not denote a type
when it is applied to a prefix which is the current instance of the type
to which the predicate is applied.
There is already a specific handling of component selection for this case
present in Find_Selected_Component, so this adds an equivalent specific
handling of indexing for this case to Analyze_Indexed_Component_Form.
gcc/ada/ChangeLog:
PR ada/117569
* sem_ch4.adb (Analyze_Indexed_Component_Form): Do not rewrite the
node as a type conversion if it is the current instance of a type
in a generic unit.
* sem_ch8.adb (Find_Selected_Component): Restrict the special case
of the current instance of a type to a generic unit.
Alexandre Oliva [Tue, 10 Dec 2024 12:06:57 +0000 (09:06 -0300)]
ada: Reduce footprint of C++ exception interoperation support
The initial C++ base-type exception interoperation support change
brought all of GNAT.CPP* along with raise-gcc, because of
[__gnat_]Convert_Caught_Object. Move that private but pragma-exported
function to GNAT.CPP.Std.Type_Info, so that it can rely on the C++
virtual/dispatch calls that justified the introduction of the Ada
wrapper type, to avoid emulating virtual calls in C or bringing in a
dependency on the C++ compiler and runtime.
Drop the CharPtr package instantiation, that brought a huge amount of
unnecessary code, and use string and storage primitives instead, using
the strcmp builtin directly for the C string compares.
Move the conversion to Ada String in Name to the wrapper interface in
GNAT.CPP.Std, adjusting the private internal type to shave off a few
more bytes from the only unit that raise-gcc will still need.
Finally, disable heap finalization for Type_Info_Ptr, to avoid
dragging in all of the finalization code. Thank to Eric Botcazou for
the suggestion.
gcc/ada/ChangeLog:
* libgnat/g-cppexc.adb (Convert_Caught_Object): Move...
* libgnat/g-cstyin.adb (Convert_Caught_Object): ... here.
Use object call notation.
(strcmp): New.
(Char_Arr, CharPtr, Char_Pointer, To_chars_ptr): Drop. Do not
import Interfaces.C.Pointers.
(To_Pointer): Convert from System.Address.
(Name_Starts_With_Asterisk): Rename local variable.
(Name_Past_Asterisk): Rewrite with System.Address and strcmp.
Import System.Storage_Elements.
(Equals): Use strcmp.
(Before): Fix logic error. Use strcmp.
(Name): Move conversion to String...
* libgnat/g-cppstd.adb (Name): ... here. Import
Interfaces.C.Strings.
* libgnat/g-cppstd.ads (Type_Info_Ptr): Disable heap
finalization.
* libgnat/g-cstyin.ads (Name): Change return type.
Claire Dross [Mon, 2 Dec 2024 16:14:47 +0000 (17:14 +0100)]
ada: Support new SPARK aspect Exit_Cases
The aspect Exit_Cases allows annotating a subprogram with a list of
cases specifying, for all input which satisfy a guard, how the
subprogram is allowed to terminate. For now, it can only be either
returning normally or propagating an exception. This contract is not
checked at runtime, it is only meant for static verification in SPARK.
gcc/ada/ChangeLog:
* aspects.ads: Add aspect Aspect_Exit_Cases.
* contracts.adb (Analyze_Entry_Or_Subprogram_Contract): Handle Exit_Cases.
(Expand_Subprogram_Contract): Idem.
* einfo-utils.adb (Get_Pragma): Allow Pragma_Exit_Cases.
* einfo-utils.ads (Get_Pragma): Idem.
* exp_prag.adb (Expand_Pragma_Exit_Cases): Ignore the pragma, currently we don't expand it.
* exp_prag.ads (Expand_Pragma_Exit_Cases): Idem.
* inline.adb (Remove_Aspects_And_Pragmas): Add Exit_Cases to the list.
(Remove_Items): Idem.
* par-prag.adb (Last_Arg_Is_Reason): Idem.
* sem_ch12.adb: Idem.
* sem_ch13.adb: Idem.
* sem_util.adb: Idem.
* sem_util.ads: Idem.
* sinfo.ads: Idem.
* snames.ads-tmpl: Add names Name_Exit_Cases, Name_Exception_Raised, and Name_Normal_Return
as well as pragma Pragma_Exit_Cases.
* sem_prag.adb (Analyze_Exit_Cases_In_Decl_Part): Make sure that a
pragma or aspect Exit_Cases is well formed.
(Analyze_Pragma): Make sure that a pragma or aspect Exit_Cases is at the right place.
* sem_prag.ads (Analyze_Exit_Cases_In_Decl_Part): Declaration.
* doc/gnat_rm/implementation_defined_pragmas.rst: Document the Exit_Cases pragma.
* doc/gnat_rm/implementation_defined_aspects.rst: Document the Exit_Cases aspect.
* gnat_rm.texi: Regenerate.
Bob Duff [Thu, 12 Dec 2024 14:13:16 +0000 (09:13 -0500)]
ada: Correct xref of operator expression function body
For an expression function body that is an operator,
make sure the xref entry in the ALI file points one past the
double quote mark. For example, if the name is ">", point
to the greater-than symbol, not the double quote.
This was already the case for proper bodies.
gcc/ada/ChangeLog:
* sem_util.adb (Copy_Subprogram_Spec): When copying
an N_Defining_Operator_Symbol, create an
N_Defining_Operator_Symbol rather than an N_Defining_Identifier.
This will cause Lib.Xref to "skip the initial quote for
navigation purposes" (as per comments in Lib.Xref body).
Eric Botcazou [Tue, 10 Dec 2024 18:43:14 +0000 (19:43 +0100)]
ada: Fix memory leak when failing to initialize newly allocated memory
This makes the compiler generate cleanup code to deallocate the memory when
the evaluation of the expression of an allocator raises an exception, if the
expression is a call to a function that may raise, i.e. is not declared with
the No_Raise aspect/pragma. This can also be disabled by means of -gnatdQ.
gcc/ada/ChangeLog:
* debug.adb (dQ): Document usage.
* exp_ch4.ads (Build_Cleanup_For_Allocator): New declaration.
* exp_ch4.adb (Build_Cleanup_For_Allocator): New procedure.
(Expand_Allocator_Expression): Build a cleanup to deallocate the
memory when the evaluation of the expression raises an exception.
* exp_ch6.adb (Make_Build_In_Place_Call_In_Allocator): Likewise.
* exp_util.adb (Build_Allocate_Deallocate_Proc): Do not generate the
detachment if the deallocation is for the cleanup of an allocator.
* gen_il-fields.ads (Opt_Field_Enum): Add For_Allocator.
* gen_il-gen-gen_nodes.adb (N_Free_Statement): Likewise.
* sinfo.ads (For_Allocator): Document usage on N_Free_Statement.
Piotr Trojanek [Tue, 10 Dec 2024 15:42:46 +0000 (16:42 +0100)]
ada: Fix crash on Depends contract with homonym functions
When resolving names in flow contracts, we refine the ordinary analysis by
knowing that an overloaded name must refer to an abstract state and not a
function. However, when all overloadings refer to function, we shouldn't
crash, but instead let the error to be diagnosed later.
Javier Miranda [Tue, 10 Dec 2024 19:49:15 +0000 (19:49 +0000)]
ada: Crash in prefix notation with access to class-wide object
The compiler crashes analyzing a prefix notation call when its
prefix is an access to a class-wide object, an actual parameter
is missing, and the sources are compiled with language extensions
(-gnatX) and full errors (-gnatf).
gcc/ada/ChangeLog:
* sem_ch4.adb (Try_Object_Operation): if no candidate interpretation
matches the context, redo the same analysis with Report_Error True
to report the error.
Eric Botcazou [Tue, 10 Dec 2024 16:53:34 +0000 (17:53 +0100)]
ada: Plug small loophole in previous change
The initial change only deals with the controlled record case for assignment
statements, but the controlled array case needs the same treatment.
gcc/ada/ChangeLog:
* exp_ch5.adb (Expand_Assign_Array): Bail out for controlled
components if the RHS is a function call and the assignment has
the No_Ctrl_Actions flag set.
Viljar Indus [Tue, 26 Nov 2024 12:10:46 +0000 (14:10 +0200)]
ada: Fix printing boolean attributes in the SARIF report
Boolean attributes should have the value true or false
without any quotes.
gcc/ada/ChangeLog:
* diagnostics-json_utils.adb: Add new method
Write_Boolean_Attribute.
* diagnostics-json_utils.ads: Likewise.
* diagnostics-sarif_emitter.adb (Print_Invocations): print
the executionSuccesful property value without extra quotes.
Viljar Indus [Thu, 28 Nov 2024 10:44:37 +0000 (12:44 +0200)]
ada: Remove level attribute from Rules in the SARIF report
A Rule object in the SARIF report does not have a level
attribute. Result objects are the elements in the SARIF
reprot that have a level attribute that ultimately determines
the level of each diagnostic object.
Rules can have a defaultConfiguration attribute which has a level
attribute that can be overridden in multiple ways. This can make
the overall report more complex than it needs to be. It is simpler
to remove the attribute from rules where it does not really matter
and add it back in under the defaultConfiguration when there is an
explicit need for it.
gcc/ada/ChangeLog:
* diagnostics-sarif_emitter.adb (Print_Rule): Remove printing
of the level attribute since it does not match the SARIF schema.
Piotr Trojanek [Wed, 27 Sep 2023 10:19:53 +0000 (12:19 +0200)]
ada: Avoid null-exclusion checks for Node_Field_Table
By generating the type of Node_Field_Table with a "not null" qualifier
we check the null exclusion of its elements only once, at the object
declaration.
Tiny performance improvement for the debug builds (because in production
builds checks are disabled anyway); semantics is unaffected.
gcc/ada/ChangeLog:
* gen_il-gen.adb (Put_Tables): Add "not null" to the generated code.
* rtsfind.adb (Cstring_Ptr): Same for table with predefined RE_Id
error messages.
* impunit.adb (Aunit_Record): Same for array of alternative unit names.
Bob Duff [Mon, 9 Dec 2024 17:20:34 +0000 (12:20 -0500)]
ada: null procedure cannot be used as compilation unit
This patch gives a syntax error if a null procedure is used as
a compilation unit. The error was already given during semantic
analysis; now it is given in the parser, which is more convenient
for other tools like gprbuild, because the -gnats switch now
gives the error.
Note that the old message "null procedure cannot be declared at library
level" was wrong; "library level" is not the same thing as "is a library
unit".
gcc/ada/ChangeLog:
* par-ch10.adb (P_Compilation_Unit): Give an error for "is null".
* sem_ch10.adb (Analyze_Subunit): Remove check for "is null"
as a subunit.
* sem_ch6.adb (Analyze_Subprogram_Declaration):
Remove check for "is null" as a library unit.
Javier Miranda [Wed, 4 Dec 2024 17:49:01 +0000 (17:49 +0000)]
ada: Cleanup preanalysis of static expressions
Complete previous patch; required to avoid regressions in GNATProve.
gcc/ada/ChangeLog:
* sem_ch6.adb (Analyze_Expression_Function): Set the parent of
the new node to be the parent of the original to get the proper
context, which is needed for complete error reporting and for
semantic analysis. Patch suggested by Eric Botcazou.
* Makefile.rtl (LLVM_BUILD): Define based on LLVM_CONFIG.
(GNATRTL_NONTASKING_OBJS): Make g-cpp, g-cppstd, and g-cstyin
conditional on -gcc or -arm EH, and on no LLVM_BUILD.
* raise-gcc.c (GXX_EH_INTEROP): Define as 0 on gnat-llvm or
CERT, and 1 otherwise.
(__gnat_get_cxx_dependent_exception) Omit on !GXX_EH_INTEROP.
(__gnat_maybe_get_cxx_dependent_exception): Likewise.
(__gnat_get_cxx_exception_type_info): Likewise.
(__gnat_obtain_caught_object): Likewise.
(is_handled_by): Omit eid parameter and G++ interop on
!GXX_EH_INTEROP. Adjust callers.
Eric Botcazou [Mon, 9 Dec 2024 09:01:11 +0000 (10:01 +0100)]
ada: Elide copy for calls as default values of nonlimited by-reference components
This prevents a temporary from being created on the primary stack to hold
the result of the function calls before it is copied to the object being
elaborated in the nonlimited by-reference case.
That's already not done in the nonlimited non-by-reference case and there is
no reason to do it in the former case either. The main issue are the calls
to Remove_Side_Effects in Expand_Ctrl_Function_Call (controlled case only)
and in Expand_N_Assignment_Statement, which serve various purposes including
very technical ones beside removing side effects.
The change is therefore very conservative and only removes the copy in the
case of a naked function call for the time being.
gcc/ada/ChangeLog:
* einfo.ads (Returns_By_Ref): Fix description.
* exp_ch3.adb (Build_Record_Init_Proc.Build_Assignment): Do not
adjust the component manually (if need be), set No_Finalize_Actions
instead of No_Ctrl_Actions for this purpose. Do not adjust when
the expression is a naked function call.
* exp_ch5.adb (Make_Tag_Ctrl_Assignment): Document the quirks of
the function. Assert that the LHS of the assignment does not have
side effects and replace calls to Duplicate_Subexpr_No_Checks with
calls to New_Copy_Tree. Rename local variable Asn to New_N.
(Expand_N_Assignment_Statement): In the tagged or controlled record
case, do remove side effects from both operands on entry. Remove
them in the controlled record case, except if the RHS is a function
call and the assignment has the No_Ctrl_Actions flag set.
* exp_ch6.adb (Expand_Ctrl_Function_Call): Bail out when the parent
node is an assignment statement with the No_Ctrl_Actions flag set.
* sem_util.adb (Statically_Different): Return True for a function
call that does not return its result by reference.
* sinfo.ads (No_Ctrl_Actions): Adjust description and add a note for
the code generator.
(No_Finalize_Actions): Likewise.
Tonu Naks [Thu, 5 Dec 2024 11:34:24 +0000 (11:34 +0000)]
ada: Silence unused parameter warning on linux
In __gnat_locate_exec_on_path (char *exec_name, int current_dir_on_windows)
the recently added second parameter is for windows only. On non-windows
platforms its usage is removed by the preprocessor and the compiler
reports unused parameter.
gcc/ada/ChangeLog:
* adaint.c: void parameter on non-windows platforms
Bob Duff [Mon, 9 Dec 2024 13:47:05 +0000 (08:47 -0500)]
ada: Use inheritance in Gen_IL
In Gen_IL, detect cases where fields could be inherited from
an abstract type instead of being defined in each of two or more
descendants of that type. Raise Illegal when that is the case,
except in specific cases called out as exceptions to this rule.
For every such case, either update the types declared in
Gen_Nodes and Gen_Entities to use inheritance, or add the case
to the list of exceptions where we do not want to use inheritance.
gcc/ada/ChangeLog:
* gen_il-internals.ads: Split Fields field into two fields
Imm_Fields and Fields.
* gen_il-gen.adb: Modify the field-inheritance
algorithm to inherit at each level of the type hierarchy,
rather than just inheriting into concrete types.
For example, if C is a concrete type derived from B,
which is in turn derived from A, we now set the Fields
of B to include those of A. (We had always set the Fields
of C to include those of A and B, and we still do that.)
(Compute_Fields_For_One_Type): Detect cases where a given
field is declared for all descendants of a given abstract
type, in which case we should consider declaring it in
the abstract type, and inheriting it in those descendants.
(Exception_To_Inheritance_Rule): These are the cases where
we could inherit, but we don't want to.
* gen_il-gen-gen_nodes.adb: Move fields up the type hierarchy,
so they are inherited instead of being defined separately.
* gen_il-gen-gen_entities.adb: Likewise.
Eric Botcazou [Fri, 6 Dec 2024 14:30:49 +0000 (15:30 +0100)]
ada: Fix finalization issue introduced by previous change
When detecting calls to subprograms specified for aspects of a type, the
entity denoted by the aspects must go through Ultimate_Alias, since that
of the name of the calls did the same.
gcc/ada/ChangeLog:
* exp_ch6.adb (Expand_Call_Helper): Call Ultimate_Alias for the
detection of calls to subprograms specified for Constant_Indexing.
* exp_util.adb (Is_Indexed_Container): Likewise.
(Is_Iterated_Container): Likewise for Default_Iterator.
Piotr Trojanek [Fri, 6 Dec 2024 08:33:28 +0000 (09:33 +0100)]
ada: Remove workaround for RM_Size being unable to represent unknown size
When validating instances of Ada.Unchecked_Conversion, we explicitly detected
null arrays, because a size of 0 was used to indicate both an unknown size and
an actual size of 0. This limitation has been lifted, so we can remove
detection of null arrays.
Code cleanup; behavior is unaffected.
gcc/ada/ChangeLog:
* sem_ch13.adb (Validate_Unchecked_Conversions): Remove detection of
null arrays; remove tests for sizes being present, which are redundant
after calling Known_Static_RM_Size.
Jakub Jelinek [Mon, 6 Jan 2025 09:12:00 +0000 (10:12 +0100)]
tree-ssa-dce: Punt on allocations with too large constant sizes [PR118224]
As suggested by Richi in the PR, the following patch will fail to DCE
allocation calls if they have constant size which is too large (over
PTRDIFF_MAX), or for the case of calloc, if either of the arguments
is too large (in that case in theory the call could succeed if the other
argument is variable zero but who cares) or if both are constant and
their product overflows or is above PTRDIFF_MAX.
This will make some pedantic conformance tests happy, though if one
hides the size one will still need to use -fno-malloc-dce or obfuscate even
the malloc etc. uses. If the size is constant and too large, it isn't worth
trying to optimize it.
2025-01-06 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/118224
* tree-ssa-dce.cc (is_removable_allocation_p): Don't return true
for allocations with constant size argument larger than PTRDIFF_MAX
or for calloc with one of the arguments constant larger than
PTRDIFF_MAX or their product known constant above PTRDIFF_MAX.
Fix comment typos, furhter -> further and then -> than.
* lto-section-in.cc (lto_free_function_in_decl_state_for_node):
Fix comment typo, furhter -> further.
* gcc.dg/pr118224.c: New test.
* c-c++-common/ubsan/vla-1.c (bar): Use noipa attribute instead
of noinline, noclone.
Synchronizing with the upstream release of v2.109.1.
D front-end changes:
- Import dmd v2.109.1.
- Copying from `const(void)[]' to `void[]' is now disallowed
with `-fpreview=fiximmutableconv'.
- Import expressions are now treated as hex strings.
- Using boolean values other than 0 or 1 in `@safe' code is now
deprecated.
Synchronizing with the upstream release of v2.109.0.
D front-end changes:
- Import dmd v2.109.0.
D runtime changes:
- Import druntime v2.109.0.
Phobos changes:
- Import phobos v2.109.0.
gcc/d/ChangeLog:
* decl.cc (DeclVisitor::finish_vtable): Update for new front-end
interface.
* dmd/MERGE: Merge upstream dmd 07bc5b9b3c.
* dmd/VERSION: Bump version to v2.109.0.
Synchronizing the library with the upstream release of v2.108.1.
D runtime changes:
- Import druntime v2.108.1.
- Removed all `collectNoStack' functions and API from the
garbage collector.
- The static method `core.thread.Thread.sleep' is now marked as
`@trusted'.
Synchronizing the compiler with the upstream release of v2.108.1.
D front-end changes:
- Import dmd v2.108.1.
- Add experimental support for language editions, enabled by
adding the UDA `@__edition_latest_do_not_use' before module
declarations.
- [Next Edition] Aliasing a member of a type instance is now an
error.
- Added `__ctfeWrite' to write messages from CTFE.
- `-fdump-c++-spec' generates signatures for `extern(Windows)'
and `extern(System)' functions.
- `foreach_reverse' on a delegate is now an error.
- ImportC has improved Unicode support.
D runtime changes:
- Mark unsafe unittest @trusted.
Phobos changes:
- Mark unsafe functions @trusted.
gcc/d/ChangeLog:
* Make-lang.in (D_FRONTEND_OBJS): Add d/attribsem.o,
d/common-charactertables.o, d/common-identifiertables.o.
* d-attribs.cc (apply_user_attributes): Update for new front-end
interface.
* d-builtins.cc (d_init_versions): Predefine CppRuntime_GNU.
* d-incpath.cc (add_globalpaths): Update for new front-end interface.
(add_filepaths): Likewise.
(add_import_paths): Likewise.
* d-lang.cc (d_post_options): Likewise.
* dmd/MERGE: Merge upstream dmd c11e1d1708.
* dmd/VERSION: Bump version to v2.108.1.
testsuite: Replace MMIX-specific adjustments with TARGET_CALLEE_COPIES-adjustments
With the dump now emitting "privatized symbols" in the default
"%s.%lu" format also for MMIX, there's still a difference for MMIX.
This time it's because numbers have changed (copies introduced before
this point) because it has TARGET_CALLEE_COPIES yielding true.
Redundant copies may have been elided at this point, but the change
in name remains.
Since that's true for other targets too, an obvious change is to
generalize the tested patterns to include TARGET_CALLEE_COPIES-true
targets, as a brief inspection of the history of these tests shows
that the point of these tests lie not in whether copies have been done
but in the part of the pattern that match a constant.
Also fixed up a "." where there should have been a "\\.".
* gcc.dg/tree-ssa/vector-4.c: Replace MMIX adjustments with
TARGET_CALLEE_COPIES-agnostic adjustments.
* gcc.dg/tree-ssa/forwprop-36.c: Ditto. Correct pattern to match a
literal ".".
MMIX: Replace format for private symbol output by output-time adjustment
All this started with belated MMIX regression patrol in observance of
the holidays, looking at gcc.dg/Wstringop-overflow-27.c as a
regression for target mmix. That's because of a single message not
matched, where there is "note: destination object 'vla::22'" instead
of the expected "note: destination object 'vla'" due to r11-5523-geafe8ee7af13c3 in which the message format and the match
changed.
That ::22 is because some identifiers that are SSA_NAME-versions and
other clones are "privatized" by ASM_FORMAT_PRIVATE_NAME and its
companion macro by default, ASM_PN_FORMAT; see the patch. I found
that these "private names" were "unprivatized" for the purpose of
warnings and error messages *in code that only handles the default
format*, "%s.%lu".
I went ahead and wrote and tested a patch-set to hookize that
unprivatizing code, but found that it would only affect errors and
warnings; dumps still had the "target format". While having bad
thoughts about being hit by yet another structural testism because of
the choice of outputting yet another target-specific format instead of
a canonical "versioned" format, I realized it *already was handling a
canonical format*: only the default "%s.%lu" is properly handled.
To wit, targets are better off with the default "%s.%lu" and adjusting
it (if needed, including not allowing "." or "$"), *at time of
assembly code output*. IOW, outputs, both references and definitions,
pass a single label-output target code point: ASM_OUTPUT_LABELREF,
which is that time of output. Some older testsuite adjustments need
to be unadjusted, but is another rabbit-hole, so I've kept that change
separate. Other tests checking dumps, now started to pass for the
first time, some 20+.
* config/mmix/mmix.cc (mmix_asm_output_labelref): Replace '.'
with '::'.
* config/mmix/mmix.h (ASM_PN_FORMAT): Define to actual default.
OpenMP: Robustify C front end handling of attribute-syntax pragmas
Presently, the code to handle OpenMP attribute-syntax pragmas in the C
front end assumes nothing else is messing with redirecting
parser->tokens, and makes no provision for restoring it from anything
other than parser->tokens_buf when the buffer allocated for the pragma
is exhausted. Adding support for metadirectives will change that,
since it also needs to buffer tokens for the metadirective
alternatives, and an attribute-syntax directive can appear inside a
metadirective.
This patch adds a more general save/restore mechanism attached to the
parser via a pointer to a new struct omp_attribute_pragma_state.
gcc/c/ChangeLog
* c-parser.cc (struct c_parser): Change in_omp_attribute_pragma
field to be of type struct omp_attribute_pragma_state.
(struct omp_attribute_pragma_state): New.
(c_parser_skip_until_found): Use the new way to restore state
on EOF.
(c_parser_skip_to_pragma_eol): Likewise.
(c_parser_handle_statement_omp_attributes): Create an
omp_attribute_pragma_state to hold the restore state. Do not
store state in tok.flags.
(omp_maybe_parse_omp_decl): Likewise.
rtlanal: Treat writes to sp as also writing to memory [PR117938]
This PR was about a case in which late-combine moved a stack
deallocation across an earlier stack access. This was possible
because the deallocation was missing the RTL-SSA equivalent of
a vop, which in turn was because rtl_properties didn't treat
the deallocation as writing to memory. I think the bug was
ultimately there.
gcc/
PR rtl-optimization/117938
* rtlanal.cc (rtx_properties::try_to_add_dest): Treat writes
to the stack pointer as also writing to memory.
gcc/testsuite/
PR rtl-optimization/117938
* gcc.dg/torture/pr117938.c: New test.
Jakub Jelinek [Fri, 3 Jan 2025 16:59:57 +0000 (17:59 +0100)]
varasm: Fix up array_size_for_constructor RAW_DATA_CST handling once again [PR118275]
As the following testcases show (the latter only if I revert the
temporary reversion of the C++ large array speedup), the FEs aren't
really consistent in the type of array CONSTRUCTOR_ELTS indexes,
it can be bitsizetype, but can be sizetype as well.
Given that everything else is able to cope with it just fine,
I'm using build_int_cst which also doesn't care what type it is,
instead of bitsize_int, which I've used in PR117190 fix (previously
it was size_int).
2025-01-03 Jakub Jelinek <jakub@redhat.com>
PR c++/118275
* varasm.cc (array_size_for_constructor): Use build_int_cst
with TREE_TYPE (index) as first argument, instead of bitsize_int.
* g++.dg/cpp/embed-18.C: New test.
* g++.dg/ext/flexary41.C: New test.
Jakub Jelinek [Fri, 3 Jan 2025 16:55:04 +0000 (17:55 +0100)]
forwprop: Use tree_fits_shwi_p in check_ctz_array
When touching the function yesterday, I was surprised to see just
TREE_CODE (something) != INTEGER_CST checks followed by tree_to_shwi.
That would ICE if the INTEGER_CST doesn't fit.
I have actually not been able to reproduce an ICE for the elt case
as the caller gives up if the precision of the array type is larger than 32
bits (but I think it is still cleaner to use it), the idx case can actually
ICE e.g. on
static const unsigned long long magic = 0x03f08c5392f756cdULL;
static const char table[] = {
0, [0x8000000000000000ULL] = 1, 12, 2, 13, 22, 17, 3, 14, 33, 23, 36, 18, 58, 28, 4,
62, 15, 34, 26, 24, 48, 50, 37, 19, 55, 59, 52, 29, 44, 39, 5,
63, 11, 21, 16, 32, 35, 57, 27, 61, 25, 47, 49, 54, 51, 43, 38,
10, 20, 31, 56, 60, 46, 53, 42, 9, 30, 45, 41, 8, 40, 7, 6,
};
int ctz (unsigned long x)
{
unsigned long lsb = x & -x;
return table[(lsb * magic) >> 58];
}
~/src/gcc/obj20/gcc/cc1 -quiet /tmp/1.c -O2 -mbmi
/tmp/1.c:2:19: warning: size of ‘table’ 9223372036854775871 bytes exceeds maximum object size 9223372036854775807 [-Wlarger-than=]
2 | static const char table[] = {
| ^~~~~
during GIMPLE pass: forwprop
/tmp/1.c: In function ‘ctz’:
/tmp/1.c:13:1: internal compiler error: in tree_to_shwi, at tree.cc:6518
13 | }
| ^
0x2efa51f internal_error(char const*, ...)
../../gcc/diagnostic-global-context.cc:517
0xf3c617 fancy_abort(char const*, int, char const*)
../../gcc/diagnostic.cc:1722
0x949a36 tree_to_shwi(tree_node const*)
../../gcc/tree.cc:6518
0x949a36 tree_to_shwi(tree_node const*)
../../gcc/tree.cc:6516
0x18472d5 check_ctz_array
../../gcc/tree-ssa-forwprop.cc:2286
but given the 9223372036854775871 bytes long array
I'm not sure it is appropriate for the testsuite.
2025-01-03 Jakub Jelinek <jakub@redhat.com>
* tree-ssa-forwprop.cc (check_ctz_array): Use tree_fits_shwi_p instead
of just TREE_CODE tests for INTEGER_CST.
Sam James [Fri, 13 Dec 2024 04:42:29 +0000 (04:42 +0000)]
testsuite: torture: add LLVM testcase for DSE vs. -ftrivial-auto-var-init=
This testcase came up in a recent LLVM bug report [0] for DSE vs
-ftrivial-auto-var-init=. Add it to our testsuite given that area
could do with better coverage.
Piotr Trojanek [Thu, 5 Dec 2024 17:03:26 +0000 (18:03 +0100)]
ada: Rely on default parameter when making non-null nodes
When calling Make_Access_To_Object_Definition and Make_Parameter_Specification
we can rely on the default value of parameter Null_Exclusion_Present being
False. This makes code cleaner and consistent with relying on the default value
of other parameters of this routine.
Piotr Trojanek [Thu, 5 Dec 2024 16:55:09 +0000 (17:55 +0100)]
ada: Rely on default parameter when making non-constant nodes
When calling Make_Access_To_Object_Definition and Make_Object_Declaration we
can rely on the default value of parameter Constant_Present being False. This
makes code cleaner and consistent with relying on the default value of other
parameters of this routine, like Null_Exclusion_Present.
Piotr Trojanek [Thu, 5 Dec 2024 16:38:43 +0000 (17:38 +0100)]
ada: Rely on default parameter when making component definition nodes
When calling Make_Component_Definition we can rely on the default value of
parameter Aliased_Present being False. This makes code cleaner and consistent
with relying on the default value of other parameters of this routine, e.g.
Null_Exclusion_Present.
Code cleanup; semantics is unaffected.
gcc/ada/ChangeLog:
* exp_ch3.adb, exp_ch9.adb, exp_dist.adb, exp_imgv.adb, exp_util.adb,
sem_dist.adb: Remove explicit actual parameter Aliased_Present equal
False; tune comments and whitespace.
Piotr Trojanek [Thu, 5 Dec 2024 15:59:36 +0000 (16:59 +0100)]
ada: Remove extra checks for raising a constraint error
Routine Is_OK_Static_Expression itself calls Raises_Constraint_Error, so there
is no need to call both of these routines in a row. Code cleanup; semantics is
unaffected.
gcc/ada/ChangeLog:
* sem_attr.adb (Check_Array_Type): Remove extra call.
* sem_util.adb (Static_Boolean): Likewise.
Piotr Trojanek [Thu, 5 Dec 2024 14:14:58 +0000 (15:14 +0100)]
ada: Remove guards against empty lists
There is no need to guard against calling First on a No_List, in which case
the call intentionally returns Empty. Code cleanup; semantics is unaffected.
Tucker Taft [Thu, 5 Dec 2024 14:47:37 +0000 (14:47 +0000)]
ada: Fix comments and change subtype name in response to review
gcc/ada/ChangeLog:
* pprint.adb (Expression_Image): Adjust and improve comments
to match style recommendations, and change name of subtype
from Not_Associative to Non_Associative, in response to
code review.
Tucker Taft [Wed, 4 Dec 2024 16:22:10 +0000 (16:22 +0000)]
ada: Add parentheses in expressions involving combinations of and & or
In the Expression_Image function, we were not inserting
parentheses properly when there was a sequence of
and and or operators, even though Ada requires such
parentheses to show the correct order of association.
gcc/ada/ChangeLog:
* pprint.adb (Expression_Image): In local function Expr_Name
add a No_Parens flag and define a subtype Not_Associative
to represent the short-circuit operations and And/Or/Xor.
Insert parentheses to separate the subexpressions when
different "Not_Associative" operations occur in a
sequence.
Eric Botcazou [Thu, 5 Dec 2024 10:15:10 +0000 (11:15 +0100)]
ada: Fix latent issue exposed by latest change
The finalization machinery needs to precisely locate the point where the
initialization of objects is complete in order to generate the attachment
to the finalization master. For objects initialized with a built-in-place
function call, this is achieved by means of the BIP_Initialization_Call
field present in their entity node, but this field is only set in the case
where the enclosing scope is transient, which is not guaranteed.
gcc/ada/ChangeLog:
* einfo.ads (BIP_Initialization_Call): Adjust description.
* exp_ch4.adb (Expand_N_Case_Expression): Adjust commentary.
(Expand_N_If_Expression): Likewise.
* exp_ch6.adb (Make_Build_In_Place_Call_In_Object_Declaration):
Set BIP_Initialization_Call unconditionally in the definite case.
Piotr Trojanek [Wed, 31 Jan 2024 12:44:19 +0000 (13:44 +0100)]
ada: Simplify traversal procedures into traversal functions
Instead of using the generic routine Traverse_Proc to set a global flag when a
particular node is found, we can use its underlying routine Traverse_Func and
check if traversal has been abandoned. We already used this pattern in a number
of places; this patch merely applies it the remaining uses of Traverse_Proc.
Code cleanup; semantics is unaffected.
gcc/ada/ChangeLog:
* exp_ch3.adb (Search_Access_Discriminant, Search_Current_Instance,
Search_Internal_Call): Use traversal function instead of traversal
procedure and remove associated global variables.
* exp_util.adb (Search_Calls): Likewise.
* sem_prag.adb (Contains_Loop_Entry): Likewise.
* sem_util.adb (Mentions_Post_State): Likewise.
Alexandre Oliva [Wed, 13 Nov 2024 22:21:56 +0000 (19:21 -0300)]
ada: Handle C++ exception hierarchies
This patch introduces support for defining exceptions in Ada with
C++'s notion of exception type compatibility, such as handling
occurrences of derived types, and obtaining class-wide access to the
thrown/raised objects. As a bonus, it adds support for C++ dependent
(wrapped) exceptions, and introduces types and interfaces to match
C++'s std::type_info and std::exception.
Support for C++ exceptions with base-type matching, added to raise-gcc
by calling subprograms in Ada units, requires these units and their
dependencies to be linked into programs that link with raise-gcc.
Gary Dismukes [Mon, 4 Nov 2024 06:06:21 +0000 (06:06 +0000)]
ada: Improve and correct support for inheritance of nonoverriding aspects
This set of changes fixes various issues with the handling of inheritance
of nonoverridable aspects (such as for Aggregate, and the indexing and
iterator aspects, among others), plus improves some of the error reporting
related to those. The prior implementation incorrectly handled types
derived from container types with respect to such aspect inheritance,
not properly inheriting the parent type's aspects, leading to rejection
of legal constructs (such as container aggregates for the derived type).
Also, various errors were incorrect (such as stating the wrong aspect)
or unclear.
In the case of types with indexing aspects, the resolution of indexed
names for such types involved locating the eligible indexing functions
anew with the analysis of each indexed name, which was both inefficient
and wrong in some cases. That is addressed by locating the functions once,
when the aspects are resolved, rather doing the location of those in two
places, which is a maintenance hazard and could result in inconsistent
resolution.
Note that this completes work originally undertaken by Ed Schonberg
that was also worked on by Steve Baird.
gcc/ada/ChangeLog:
* diagnostics-constructors.adb (Make_Default_Iterator_Not_Primitive_Error):
Revise message to match message change made in sem_ch13.adb.
* freeze.adb (Freeze_Record_Type): Output appropriate aspect name in
error message, using Get_Name_String.
(Freeze_Entity): For derived types, call Analyze_Aspects_At_Freeze_Point
on the parent type, and call Inherit_Nonoverridable_Aspects on the type
(for both parent type and any progenitor types). Add with_clause for
System.Case_Util.
* gen_il-fields.ads: Add Aspect_Subprograms to type Opt_Field_Enum.
* gen_il-gen-gen_nodes.adb: Add field Aspect_Subprograms to
N_Aspect_Specification nodes.
* sem_ch4.adb (Try_Container_Indexing): Remove Find_Indexing_Operations
and the code calling it. Add new function Indexing_Interpretations for
retrieving the eligible indexing functions from the appropriate aspect's
Aspect_Subprograms list and call that instead of Find_Value_Of_Aspect.
* sem_ch7.adb (Analyze_Package_Specification): In loop over entities,
call Analyze_Aspects_At_Freeze_Point for types that have delayed
aspects.
* sem_ch13.ads (Analyze_Aspects_At_Freeze_Point): Add Nonoverridable_Only
formal to restrict processing to nonoverridable aspects.
(Check_Function_For_Indexing_Aspect): New exported procedure renamed
from Check_One_Function and moved to library level.
* sem_ch13.adb (Analyze_Aspects_At_Freeze_Point): Test new formal
Nonoverridable_Only formal to skip processing of aspects that are not
nonoverridable when the formal is True. Skip the processing for
Aspect_Full_Access_Only when Nonoverridable_Only is True. Call
Check_Indexing_Functions in the case of indexing aspects (procedure
moved from Analyze_Attribute_Definition_Clause to top level).
(Analyze_Aspect_Specifications): Locate closest ancestor type with an
explicit matching aspect to determine the aspect spec to reference in
the error about a nonoverridable aspect not confirming an inherited
aspect (skipping intermediate derived parents). Ensures that we retain
existing errors flagged on explicit ancestor aspects rather than
implicit inherited ones. Change names of variables Parent_Type and
Inherited_Aspect to Ancestor_Type and Ancestor_Aspect respectively
for clarity.
(Analyze_Attribute_Definition_Clause): Move nested subprograms
Check_Iterator_Functions and Check_Primitive_Function to top level
of package. Move Check_Indexing_Functions (and its nested subprograms)
from here to within Analyze_Aspects_At_Freeze_Point (adding some
formal parameters and adjusting the code appropriately, and no longer
call it from this procedure).
(Is_CW_Or_Access_To_CW): Add test for the parent type having the
indexing aspect for proper setting of Aspect_Specification_Is_Inherited.
Delete "???" comment.
(Look_Through_Anon_Access): Remove unneeded tests of Is_Access_Constant
and Name_Constant_Indexing, which lead to wrong messages in some cases.
(Check_Function_For_Indexing_Aspect): Procedure renamed from
Check_One_Function and moved to library level (was nested within
Check_Indexing_Functions), plus added formals (including Valid, to
check result). Move scope test to beginning, to immediately exclude
subprograms not declared immediately within the same scope as the type.
Improve several error messages. Add error checking for Constant_Indexing
functions. Append the function entity to the Aspect_Subprograms list of
the aspect specification. Move code for checking for nonconfirming
index aspects and for checking for illegal indexing aspects on full
views to Check_Indexing_Functions.
(Check_Indexing_Functions): Move procedure Illegal_Indexing from
here to within Check_Function_For_Indexing_Aspect. Add a comment
to the loop over interpretations about the checking being done as
legality rules rather than resolution rules, plus a note referencing
AI22-0084. Check for nonconfirming indexing aspects and illegal
indexing aspects on full views here rather than in Check_One_Function
(now named Check_Function_For_Indexing_Aspect). Remove function
Check_One_Function (moved to library level and renamed), and call
Check_Function_For_Indexing_Aspect instead.
(Check_Inherited_Indexing): Improve spec comment. Remove nested function
Same_Chars, and replace call Same_Chars with call to Sem_Util.Same_Name.
Replace call to Illegal_Indexing with call to Error_Msg_NE.
(Check_One_Function): Unnested from Check_Indexing_Functions, rename
to Check_Function_For_Indexing_Aspect, move body to library level,
and move declaration to Sem_Ch13 spec.
(Analyze_Attribute_Definition_Clause, case Attribute_Default_Iterator):
Improve error message related to tagged-type requirement. Suppress call
to Check_Iterator_Functions for attribute definition clauses associated
with inherited aspects. Remove error checking that is redundant with
checking done in Check_Iterator_Functions.
(Check_Aspect_At_Freeze_Point, case Attribute_Default_Iterator): Call
Check_Iterator_Functions (only if the aspect is not Comes_From_Source).
(Check_Iterator_Functions): Procedure unnested from
Analyze_Attribute_Definition_Clause. Add formals Typ and Expr.
Error messages corrected to say "aspect Default_Iterator" instead of
"aspect Iterator".
(Valid_Default_Iterator): Improve error message to say "must be
a local primitive or class-wide function" instead of "must be
a primitive function".
(Check_Primitive_Function): Unnested from Analyze_Attribute_Definition_Clause.
Add formal Ent.
(Rep_Item_Too_Late): Return False when an attribute_definition_clause
is not Comes_From_Source, since it was generated by the compiler (such
as for an inherited aspect).
(Resolve_Aspect_Aggregate): Capture implementation base type.
(Valid_Empty): Use implementation base types for result type comparison.
(Valid_Add_Named): Use impl base types for comparison of formal's type.
(Valid_Add_Unnamed): Use impl base types for comparison of formal's type.
(Valid_New_Indexed): Use impl base types for result type comparison.
(Validate_Literal_Aspect): Return immediately when aspect does not have
Comes_From_Source True (no point in validating inherited aspects).
* sem_res.adb (Has_Applicable_User_Defined_Literal): Remove Base_Type
comparison and always call Corresponding_Op_Of_Derived_Type for derived
types. Add "???" comment about issue with wrapper functions (and
indicate that it would be nice to eliminate the call to
Corresponding_Primitive_Op).
* sem_util.ads (Inherit_Nonoverridable_Aspects): New procedure.
(Corresponding_Op_Of_Derived_Type): Update spec comment to indicate
return of Ancestor_Op and name changed from Corresponding_Primitive_Op.
* sem_util.adb (Check_Inherited_Nonoverridable_Aspects): Fix name in
header comment.
(Corresponding_Op_Of_Derived_Type): Move declaration of Typ down with
other local variables. Remove Assert that doesn't apply in some cases.
Simply return Ancestor_Op when it isn't a primitive (it can be a
class-wide op). Function name changed from Corresponding_Primitive_Op.
(Find_Untagged_Type_Of): Add test of Is_Type (E) as a guard for checking
Direct_Primitive_Operations. Remove Assert (False), and return Empty
when the primitive is not found.
(Profile_Matches_Ancestor): Change comparisons to use implementation
base types of the operations' formal and result types. Add tests for
interface ancestors. Revise "???" comment.
(Is_Confirming): Simplify name-matching test to use the names associated
with the aspects rather than going to the N_Attribute_Definition_Clause
nodes (may facilitate elimination of those clauses at some point).
(Inherit_Nonoverridable_Aspects): New procedure to traverse the
aspects of a derived type's parent type and create inherited versions
of the parent type's nonoverridable aspects, identifying the appropriate
subprograms for each such inherited aspect.
(Inherit_Nonoverridable_Aspect): New procedure nested in
Inherit_Nonoverridable_Aspects to inherit individual nonoverridable
aspects. Identifies the corresponding subprogram(s) associated with
an inherited nonoverridable aspect. In the case of indexing aspects,
new eligible indexing functions of the type are also identified here,
and the entities of all of the identified subprograms are appended to
the aspect's Aspect_Subprograms Elist. Add a "???" comment about this.
* sinfo.ads: Add documentation for the new Aspect_Subprograms field.
Eric Botcazou [Wed, 4 Dec 2024 11:35:29 +0000 (12:35 +0100)]
ada: Fix small thinko in previous change
Even if the declaration of the conditional object is turned into a renaming
during expansion, the conditional object must be finalized when the original
object would have been.
gcc/ada/ChangeLog:
* exp_ch4.adb (Insert_Conditional_Object_Declaration): Create the
Master_Node even if the declaration is turned into a renaming.
Piotr Trojanek [Wed, 4 Dec 2024 12:45:24 +0000 (13:45 +0100)]
ada: Leave empty parent in an array component of an anonymous access type
An itype created for a record component with an anonymous access type has empty
parent. However, a similar itype created for an array component has its parent
copied from the parent of the array type.
The above discrepancy appears to be not needed for the frontend. Also, it is
confusing for the GNATprove backend, because it looks like the itype entity
of the array component comes from a declaration of the array itself.
gcc/ada/ChangeLog:
* sem_ch3.adb (Array_Type_Declaration): Don't copy parent for an itype
created by an array component declaration.
Douglas B Rupp [Mon, 5 Aug 2024 20:17:38 +0000 (13:17 -0700)]
ada: Incompatible conversion on vxworks in socket.c
In the vxworks section, a conversion between char* and int is
attempted, which results in a warning with gcc. However with clang
with is an error. Note also on 64bit targets, there's a size
mismatch.
gcc/ada/ChangeLog:
* socket.c [__vxworks]: Change vxw_h_addr type to long from
int, and cast the conversion of char* to vxw_h_addr to avoid
warning/error.
Eric Botcazou [Tue, 3 Dec 2024 21:36:15 +0000 (22:36 +0100)]
ada: Fix double free at run time for class-wide allocation
The previous change was too aggressive and overlooked a specific case.
gcc/ada/ChangeLog:
* exp_ch4.adb (Expand_Allocator_Expression): Put back the call to
Remove_Side_Effects in the case of a function call, a class-wide
designated type and a regular storage pool.
Bob Duff [Tue, 3 Dec 2024 22:49:15 +0000 (17:49 -0500)]
ada: Warn on unmodified parameters of expression functions
If an 'out' or 'in out' parameter is not modified in a function body,
we warn. However, the warning was missing when we have an expression
function instead of a proper body. This patch enables the warning
on expression functions.
gcc/ada/ChangeLog:
* sem_ch6.adb (Analyze_Expression_Function): Mark the implicit
spec for an expression function as Comes_From_Source.
(Analyze_Null_Procedure): Minor cleanup.
* sem_warn.adb (Source_E1): New function to compute whether
to give warnings. In particular, return True for [in] out
parameters of expression functions.
Steve Baird [Tue, 3 Dec 2024 00:45:37 +0000 (16:45 -0800)]
ada: Avoid failing reanalysis of aggregate bounds
An expression like Some_Package."+" (Arg1, Arg2) is sometimes transformed
during expansion into an unqualified call of the form "+" (Arg1, Arg2).
This is normally ok, but it means that reanalysis of the expression is likely
to fail and must therefore be avoided. Remove code that was forcing such
reanalysis (the original reason for the now-removed code is unknown).
gcc/ada/ChangeLog:
* exp_aggr.adb (Check_Bounds): Remove calls that were setting the
Analyzed flag to False for two aggregate bound expressions.
Eric Botcazou [Mon, 2 Dec 2024 20:58:29 +0000 (21:58 +0100)]
ada: Improve expansion of conditional expressions in object declarations
This arranges for conditional expressions in objects declarations to have
their expansion delayed when they have a type that cannot be easily copied
or copied at all, including limited and controlled types.
The ultimate goal is to replace the declaration with a renaming declaration
of the dereference of an access value designating an object initialized with
the dependent expression chosen by the condition.
gcc/ada/ChangeLog:
* einfo.ads (Is_Independent): Document usage on Master_Node objects.
* exp_aggr.adb (In_Place_Assign_OK): Remove Parent_Kind variable.
(Convert_To_Assignments): Call Unconditional_Parent and remove the
restriction on the known size for the in-place expansion of the
aggregate in the context of an object declaration.
(Expand_Array_Aggregate): Remove Parent_Kind variable and call
Unconditional_Parent and Delay_Conditional_Expressions_Between
* exp_ch3.adb: Remove clauses for Exp_Dbug.
(Expand_N_Object_Declaration): Factor out the code rewriting the
declaration as a renaming in Rewrite_Object_Declaration_As_Renaming
and call the procedure.
* exp_ch4.adb (Insert_Conditional_Object_Declaration): Declare.
(Expand_N_Case_Expression): Delay expanding the expression if it is
in the context of an optimizable object declaration. If the parent
node is this object declaration, then replace it with a renaming of
the dereference of an access value designating an object initialized
with the dependent expression chosen by the condition.
(Expand_N_If_Expression): Likewise.
(Insert_Conditional_Object_Declaration): New procedure.
* exp_ch6.adb (Expand_Ctrl_Function_Call): Test the unconditional
parent in the case of an object declaration too.
* exp_ch7.adb (Build_Finalizer.Process_Declarations): Pass Strict to
Processing_Actions from the Is_Independent flag on a Master_Node.
* exp_util.ads (Rewrite_Object_Declaration_As_Renaming): Declare.
* exp_util.adb: Add clauses for Exp_Dbug.
(Rewrite_Object_Declaration_As_Renaming): New procedure extracted
from Expand_N_Object_Declaration.
* sem_ch3.adb (Analyze_Object_Declaration): Also leave the analysis
if the declaration has been replaced with a renaming in the case of
an initialization expression that is a conditional expression.
Eric Botcazou [Sun, 1 Dec 2024 10:46:46 +0000 (11:46 +0100)]
ada: Preliminary work in analysis and expansion of initialized allocators
This makes the expansion of the various cases of initialized allocators more
uniform by factoring out common processing as much as possible. This also
avoids giving the warning or error for a default-initialized allocator when
it is marked with No_Initialization. No functional changes.
gcc/ada/ChangeLog:
* checks.adb (Apply_Predicate_Check): Preserve Comes_From_Source.
* exp_ch4.adb (Expand_Allocator_Expression): Factor out common code
for the various cases. Also delay applying the 2nd predicate check.
In the default case, defer to Make_Build_In_Place_Call_In_Allocator
entirely in the build-in-place case.
* sem_ch4.adb (Analyze_Allocator): Do not give the warning or error
for a default-initialized allocator with No_Initialization.