]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
6 months agoor1k: add .note.GNU-stack section on linux
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.

6 months agoRespect -fprofile-prefix-map for getcwd in .gcno files
Fangrui Song [Wed, 1 Jan 2025 00:32:07 +0000 (16:32 -0800)] 
Respect -fprofile-prefix-map for getcwd in .gcno files

so that
`gcc -c a.cc --coverage -fprofile-prefix-map=$PWD=.`
does not emit $PWD in the generated a.gcno file.

gcc/ChangeLog:

PR gcov-profile/96092
* coverage.cc (coverage_init): Remap getpwd().

6 months agoSVE intrinsics: Fold svmul by -1 to svneg for unsigned types
Jennifer Schmitz [Thu, 7 Nov 2024 16:44:30 +0000 (08:44 -0800)] 
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;

  D.12920 = VIEW_CONVERT_EXPR<svint64_t>(x);
  D.12921 = svneg_s64_x (pg, D.12920);
  D.12919 = VIEW_CONVERT_EXPR<svuint64_t>(D.12921);
  goto <D.12922>;
  <D.12922>:
  return 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.

6 months agoAda: fix spurious relinking of gnatbind for cross compilers
Eric Botcazou [Mon, 6 Jan 2025 11:20:00 +0000 (12:20 +0100)] 
Ada: fix spurious relinking of gnatbind for cross compilers

The problem has been introduced by r15-1881.

gcc/ada
PR ada/118247
* gcc-interface/Make-lang.in (GNATTOOLS_CROSS_MV): Copy gnatbind
instead of moving it.

6 months agoipa-cp: Make dumping of bit masks representing -1 nicer
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.

6 months agotree-switch-conversion: don't apply switch size limit on jump tables
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.

gcc/ChangeLog:

PR tree-optimization/118032
* tree-switch-conversion.cc (jump_table_cluster::find_jump_tables):
Remove param_switch_lower_slow_alg_max_cases check.

6 months agoAArch64: Implement four and eight chunk VLA concats [PR118272]
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.

6 months agoada: Fix small thinko in previous change to two-pass aggregate expansion
Eric Botcazou [Fri, 13 Dec 2024 19:50:44 +0000 (20:50 +0100)] 
ada: Fix small thinko in previous change to two-pass aggregate expansion

We need a type tailored to the base index type to compute the length.

gcc/ada/ChangeLog:

* exp_aggr.adb (Two_Pass_Aggregate_Expansion): Use the base type of
the index type to find the type used to compute the length.

6 months agoada: Streamline runtime support of finalization collections
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.

6 months agoada: Fix predicate involving array indexing rejected in generic package
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.

6 months agoada: Fix incorrect RM reference in s-imagef.adb
Bob Duff [Fri, 13 Dec 2024 13:58:08 +0000 (08:58 -0500)] 
ada: Fix incorrect RM reference in s-imagef.adb

gcc/ada/ChangeLog:

* libgnat/s-imagef.adb (Set_Image_Integer):
Change "RM A.3.10" to be "RM A.10.9".

6 months agoada: Reduce footprint of C++ exception interoperation support
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.

6 months agoada: Support new SPARK aspect Exit_Cases
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.

6 months agoada: Correct xref of operator expression function body
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).

6 months agoada: Small housekeeping work in Exp_Aggr
Eric Botcazou [Thu, 12 Dec 2024 12:00:14 +0000 (13:00 +0100)] 
ada: Small housekeeping work in Exp_Aggr

This moves a few declarations around and tweaks a few comments.

gcc/ada/ChangeLog:

* exp_aggr.adb (Case_Table_Type): Fix reference in comment.
(In_Place_Assign_OK): Move declaration around.
(Is_Build_In_Place_Aggregate_Return): Likewise and adjust.
(Expand_Array_Aggregate): Streamline for the sake of consistency.
(Aggr_Assignment_OK_For_Backend): Remove reference to Gigi/gcc.
(Backend_Processing_Possible): Likewise.
(Expand_Array_Aggregate): Add comment.

6 months agoada: cleanup documentation for shift and rotate
Bob Duff [Tue, 10 Dec 2024 13:56:45 +0000 (08:56 -0500)] 
ada: cleanup documentation for shift and rotate

Documentation updated.

gcc/ada/ChangeLog:

* sinfo.ads (Shift_Count_OK): Update comments.
(Is_Power_Of_2_For_Shift): Likewise.

6 months agoada: Fix memory leak when failing to initialize newly allocated memory
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.

6 months agoada: Fix assertion failure on 'Old in post-condition with -gnat2022
Eric Botcazou [Wed, 11 Dec 2024 12:06:07 +0000 (13:06 +0100)] 
ada: Fix assertion failure on 'Old in post-condition with -gnat2022

It comes from a small oversight in the updated implementation for Ada 2022.

gcc/ada/ChangeLog:

PR ada/117956
* sem_util.adb (Is_Known_On_Entry): Be prepared for constants coming
from a renaming declaration.

6 months agoada: Declare that the new argument may not be used
Tonu Naks [Tue, 10 Dec 2024 10:41:16 +0000 (10:41 +0000)] 
ada: Declare that the new argument may not be used

gcc/ada/ChangeLog:

* adaint.c (__gnat_locate_exec_on_path): modify function signature

6 months agoada: Fix crash on Depends contract with homonym functions
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.

gcc/ada/ChangeLog:

* sem_prag.adb (Resolve_State): Continue ordinary processing.

6 months agoada: Crash in prefix notation with access to class-wide object
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.

6 months agoada: Plug small loophole in previous change
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.

6 months agoada: Fix printing boolean attributes in the SARIF report
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.

6 months agoada: Remove level attribute from Rules in the SARIF report
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.

6 months agoada: Avoid null-exclusion checks for Node_Field_Table
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.

6 months agoada: Ada version used to compile runtime is constant
Piotr Trojanek [Sun, 14 Jan 2024 20:15:37 +0000 (21:15 +0100)] 
ada: Ada version used to compile runtime is constant

Code cleanup.

gcc/ada/ChangeLog:

* opt.ads (Ada_Version_Runtime): Now a constant, since it cannot
and should never be modified.

6 months agoada: null procedure cannot be used as compilation unit
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.

6 months agoada: Cleanup preanalysis of static expressions
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.

6 months agoada: C++ exception hierarchies: adjust for gnat-llvm
Alexandre Oliva [Mon, 9 Dec 2024 10:56:06 +0000 (07:56 -0300)] 
ada: C++ exception hierarchies: adjust for gnat-llvm

gnat-llvm doesn't support C++ imports, so arrange for the GNAT.CPP*
units to be omitted from gnat-llvm builds.

Drop G++ exception interoperability support from raise-gcc.c, so as to
not require the GNAT.CPP* units that define some of the required
symbols.

Co-Authored-By: Olivier Hainque <hainque@adacore.com>
gcc/ada/ChangeLog:

* 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.

6 months agoada: Elide copy for calls as default values of nonlimited by-reference components
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.

6 months agoada: Follow-on to Use inheritance in Gen_IL
Bob Duff [Mon, 9 Dec 2024 22:45:17 +0000 (17:45 -0500)] 
ada: Follow-on to Use inheritance in Gen_IL

Fix too-long line.

gcc/ada/ChangeLog:

* gen_il-gen.adb: Fix too-long line.

6 months agoada: Silence unused parameter warning on linux
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

6 months agoada: Use inheritance in Gen_IL
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.

6 months agoada: Fix incorrect incomplete type error
Viljar Indus [Thu, 5 Dec 2024 09:47:05 +0000 (11:47 +0200)] 
ada: Fix incorrect incomplete type error

In Ada 2005 even if the formal is using a tagged limited type
then the type should not be considered incomplete.

gcc/ada/ChangeLog:

* sem_ch6.adb (Analyze_Subprogram_Body_Helper):
Exchange_Limited_Views also in Ada 2005.

6 months agoada: Fix finalization issue introduced by previous change
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.

6 months agoada: Fix markup in user's guide
Ronan Desplanques [Fri, 6 Dec 2024 14:26:33 +0000 (15:26 +0100)] 
ada: Fix markup in user's guide

gcc/ada/ChangeLog:

* doc/gnat_ugn/building_executable_programs_with_gnat.rst: Fix markup.
* gnat_ugn.texi: Regenerate.

6 months agoada: Remove workaround for RM_Size being unable to represent unknown size
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.

6 months agotree-ssa-dce: Punt on allocations with too large constant sizes [PR118224]
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.

6 months agoAda: fix documentation of pragma Unimplemented_Unit
Eric Botcazou [Mon, 6 Jan 2025 07:46:06 +0000 (08:46 +0100)] 
Ada: fix documentation of pragma Unimplemented_Unit

gcc/ada
PR ada/117936
* doc/gnat_rm/implementation_defined_pragmas.rst
(Unimplemented_Unit): Adjust the description of the error message.
* gnat_rm.texi: Regenerate.

6 months agoRISC-V: Move fortran testcase to gfortran.target
Kito Cheng [Mon, 23 Dec 2024 13:27:46 +0000 (21:27 +0800)] 
RISC-V: Move fortran testcase to gfortran.target

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/fortran/pr111395.f90: Move this file to...
* gfortran.target/riscv/rvv/pr111395.f90: ...here.
* gcc.target/riscv/rvv/fortran/pr111566.f90: Move this file to...
* gfortran.target/riscv/rvv/pr111566.f90: ...here.
* gcc.target/riscv/rvv/rvv-fortran.exp: Move this file to...
* gfortran.target/riscv/rvv/rvv.exp: ...here.

6 months agoDaily bump.
GCC Administrator [Mon, 6 Jan 2025 00:16:54 +0000 (00:16 +0000)] 
Daily bump.

6 months agod: Merge upstream dmd, druntime 66b93fc24a, phobos 0c28620c3
Iain Buclaw [Sun, 5 Jan 2025 13:40:13 +0000 (14:40 +0100)] 
d: Merge upstream dmd, druntime 66b93fc24a, phobos 0c28620c3

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.

D runtime changes:

- Import dmd v2.109.1.

Phobos changes:

- Import dmd v2.109.1.

gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd 66b93fc24a.
* dmd/VERSION: Bump version to v2.109.1.
* d-builtins.cc (build_frontend_type): Update for new front-end
interface.
(matches_builtin_type): Likewise.
* d-codegen.cc (identity_compare_p): Likewise.
(call_side_effect_free_p): Likewise.
* d-convert.cc (convert_expr): Likewise.
(check_valist_conversion): Likewise.
* d-lang.cc (d_types_compatible_p): Likewise.
* d-target.cc (Target::isVectorTypeSupported): Likewise.
(Target::isReturnOnStack): Likewise.
(Target::preferPassByRef): Likewise.
* decl.cc (class DeclVisitor): Likewise.
* expr.cc (class ExprVisitor): Likewise.
* typeinfo.cc (class TypeInfoVisitor): Likewise.
* types.cc (class TypeVisitor): Likewise.

libphobos/ChangeLog:

* libdruntime/MERGE: Merge upstream druntime 66b93fc24a.
* src/MERGE: Merge upstream phobos 0c28620c3.
* src/Makefile.am (PHOBOS_DSOURCES): Add
std/internal/test/sumtype_example_overloads.d.
* src/Makefile.in: Regenerate.

6 months agod: Merge upstream dmd, druntime 07bc5b9b3c, phobos de1dea109
Iain Buclaw [Sun, 5 Jan 2025 13:24:49 +0000 (14:24 +0100)] 
d: Merge upstream dmd, druntime 07bc5b9b3c, phobos de1dea109

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.

libphobos/ChangeLog:

* libdruntime/MERGE: Merge upstream druntime 07bc5b9b3c.
* src/MERGE: Merge upstream phobos de1dea109.

6 months agolibphobos: Merge upstream druntime c11e1d1708, phobos 303b9c9f7
Iain Buclaw [Sun, 5 Jan 2025 12:51:59 +0000 (13:51 +0100)] 
libphobos: Merge upstream druntime c11e1d1708, phobos 303b9c9f7

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'.

Phobos changes:

        - Import phobos v2.108.1.
- Add `std.process.Config.preExecDelegate'.

libphobos/ChangeLog:

* libdruntime/MERGE: Merge upstream druntime c11e1d1708.
* libdruntime/Makefile.am (DRUNTIME_DSOURCES_FREEBSD): Add
core/sys/freebsd/mqueue.d.
(DRUNTIME_DSOURCES_LINUX): Add core/sys/linux/sys/mount.d.
* libdruntime/Makefile.in: Regenerate.
* src/MERGE: Merge upstream phobos 303b9c9f7.
* testsuite/libphobos.exceptions/invalid_memory_operation.d: Adjust
test.

6 months agod: Merge upstream dmd c11e1d1708, druntime e60bfd11bd, phobos 8729740e3
Iain Buclaw [Sun, 29 Dec 2024 05:40:04 +0000 (06:40 +0100)] 
d: Merge upstream dmd c11e1d1708, druntime e60bfd11bd, phobos 8729740e3

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.

libphobos/ChangeLog:

* libdruntime/MERGE: Merge upstream druntime e60bfd11bd.
* src/MERGE: Merge upstream phobos 8729740e3.

gcc/testsuite/ChangeLog:

* gdc.dg/torture/pr96435.d: Add dg-warning.

6 months agoAda: Fix build for dummy s-taprop
Estevan Castilho (Tevo) [Sat, 28 Dec 2024 20:37:37 +0000 (20:37 +0000)] 
Ada: Fix build for dummy s-taprop

gcc/ada
* libgnarl/s-taprop__dummy.adb: Remove use clause for
System.Parameters.
(Unlock): Remove Global_Lock formal parameter.
(Write_Lock): Likewise.

6 months agotestsuite, d: Fix failing pr110406.d test
Iain Buclaw [Sun, 5 Jan 2025 10:19:31 +0000 (11:19 +0100)] 
testsuite, d: Fix failing pr110406.d test

At some point during GCC 15 development, the compiler-generated code for
D ModuleInfo support now gets transformed into the following on x86:

    _12 = (uint) &__stop_minfo;
    _13 = (uint) &__start_minfo;
    _14 = (uint) &gdc.dso_slot;
    _15 = {1, _14, _13, _12};
    gdc.dso_initialized = 0;
    MEM <unsigned char[8]> [(void *)&D.1974 + 16B] = {};
    MEM <vector(4) uint> [(void *)&D.1974] = _15;
    _d_dso_registry (&D.1974);

This causes the scan-tree-dump-not test to fail. As ModuleInfo is not
what's being checked for in PR110406, remove its generation altogether.

gcc/testsuite/ChangeLog:

* gdc.dg/torture/pr110406.d: Add -fno-moduleinfo to dg-options.

6 months agoDaily bump.
GCC Administrator [Sun, 5 Jan 2025 00:16:24 +0000 (00:16 +0000)] 
Daily bump.

6 months agotestsuite: Replace MMIX-specific adjustments with TARGET_CALLEE_COPIES-adjustments
Hans-Peter Nilsson [Fri, 3 Jan 2025 17:34:14 +0000 (18:34 +0100)] 
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 ".".

6 months agoMMIX: Replace format for private symbol output by output-time adjustment
Hans-Peter Nilsson [Fri, 3 Jan 2025 17:25:36 +0000 (18:25 +0100)] 
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.

6 months agoDaily bump.
GCC Administrator [Sat, 4 Jan 2025 00:17:49 +0000 (00:17 +0000)] 
Daily bump.

6 months agoOpenMP: Robustify C front end handling of attribute-syntax pragmas
Sandra Loosemore [Fri, 3 Jan 2025 17:35:03 +0000 (17:35 +0000)] 
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.

6 months agortlanal: Treat writes to sp as also writing to memory [PR117938]
Richard Sandiford [Fri, 3 Jan 2025 18:12:07 +0000 (18:12 +0000)] 
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.

6 months agoMention generating C prototypes in the C interop documentation.
Thomas Koenig [Fri, 3 Jan 2025 17:31:07 +0000 (18:31 +0100)] 
Mention generating C prototypes in the C interop documentation.

gcc/fortran/ChangeLog:

* gfortran.texi: New subsection "Generating C prototypes from
Fortran".

6 months agolibgomp: Regenerate configure after copyright year bump
Jakub Jelinek [Fri, 3 Jan 2025 17:06:19 +0000 (18:06 +0100)] 
libgomp: Regenerate configure after copyright year bump

2025-01-03  Jakub Jelinek  <jakub@redhat.com>

* configure: Regenerate.

6 months agovarasm: Fix up array_size_for_constructor RAW_DATA_CST handling once again [PR118275]
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.

6 months agoforwprop: Use tree_fits_shwi_p in check_ctz_array
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.

6 months agotestsuite: torture: add LLVM testcase for DSE vs. -ftrivial-auto-var-init=
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.

[0] https://github.com/llvm/llvm-project/issues/119646

gcc/testsuite/ChangeLog:

* gcc.dg/torture/dse-trivial-auto-var-init.c: New test.

Co-authored-by: Andrew Pinski <pinskia@gmail.com>
6 months agoFortran: Cray pointer comparison wrongly optimized away [PR106692]
Harald Anlauf [Thu, 2 Jan 2025 19:22:23 +0000 (20:22 +0100)] 
Fortran: Cray pointer comparison wrongly optimized away [PR106692]

PR fortran/106692

gcc/fortran/ChangeLog:

* trans-expr.cc (gfc_conv_expr_op): Inhibit excessive optimization
of Cray pointers by treating them as volatile in comparisons.

gcc/testsuite/ChangeLog:

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

6 months agoada: Rely on default parameter when making non-null nodes
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.

Code cleanup; semantics is unaffected.

gcc/ada/ChangeLog:

* exp_ch3.adb, exp_ch4.adb, exp_disp.adb, inline.adb: Remove explicit
actual parameter Null_Exclusion_Present equal False.

6 months agoada: Rely on default parameter when making non-constant nodes
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.

Code cleanup; semantics is unaffected.

gcc/ada/ChangeLog:

* exp_ch3.adb, exp_disp.adb: Remove explicit actual parameter
Constant_Present equal False; tune comments.

6 months agoada: Rely on default parameter when making component definition nodes
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.

6 months agoada: Simplify code for obtaining function entity from a function call
Piotr Trojanek [Thu, 5 Dec 2024 16:12:55 +0000 (17:12 +0100)] 
ada: Simplify code for obtaining function entity from a function call

Code cleanup; behavior is unaffected.

gcc/ada/ChangeLog:

* sem_ch5.adb (Check_Call): Reuse Get_Called_Entity.

6 months agoada: Remove extra checks for raising a constraint error
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.

6 months agoada: Reuse and simplify counting the length of various lists
Piotr Trojanek [Thu, 5 Dec 2024 13:12:25 +0000 (14:12 +0100)] 
ada: Reuse and simplify counting the length of various lists

Use utility routines to compute number of elements in lists of nodes and chains
of formal parameters. Code cleanup; semantics is unaffected.

gcc/ada/ChangeLog:

* exp_aggr.adb (Others_Check): Reuse List_Length; tune whitespace.
* exp_ch3.adb (Constrain_Array): Remove counting of constraints.
* exp_disp.adb (Make_DT): Use Elist utility routines; tune whitespace.
* sem_ch12.adb (Formal_Dimensions): Reuse List_Length.
(Valid_Default_Attribute): Reuse Number_Formals.
* sem_prag.adb (Process_Convention): Likewise.
* sem_util.adb (Normalize_Actuals): Likewise.
(Check_Function_Writable_Actuals): Reuse List_Length.

6 months agoada: Remove guards against empty lists
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.

gcc/ada/ChangeLog:

* contracts.adb (Create_Generic_Contract): Remove calls to Present.
* sem_util.adb (Normalize_Actuals): Likewise.

6 months agoada: Enclosing_Entity of specless subprogram bodies
Bob Duff [Wed, 4 Dec 2024 23:30:03 +0000 (18:30 -0500)] 
ada: Enclosing_Entity of specless subprogram bodies

Correct Enclosing_Entity of specless subprogram bodies;
these are marked as Comes_From_Source = False,
so the simple name was missing.

gcc/ada/ChangeLog:

* sem_util.adb (Append_Entity_Name): Do not skip the
simple name for a compilation unit (which includes
the case of specless subprogram bodies).

6 months agoada: Fix comments and change subtype name in response to review
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.

6 months agoada: Add parentheses in expressions involving combinations of and & or
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.

6 months agoada: Fix latent issue exposed by latest change
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.

6 months agoada: Refine subtype of a universal arithmetic utility routine
Piotr Trojanek [Wed, 4 Dec 2024 18:23:08 +0000 (19:23 +0100)] 
ada: Refine subtype of a universal arithmetic utility routine

Code cleanup; semantics is unaffected.

gcc/ada/ChangeLog:

* uintp.adb (N_Digits): Refine return subtype, since this routine
always returns a positive number of digits.

6 months agoada: Reuse existing utility routine to detect attribute Loop_Entry
Piotr Trojanek [Wed, 4 Dec 2024 18:20:31 +0000 (19:20 +0100)] 
ada: Reuse existing utility routine to detect attribute Loop_Entry

Code cleanup; semantics is unaffected.

gcc/ada/ChangeLog:

* checks.adb (Generate_Index_Checks): Reuse existing utility routine.
* sem_ch4.adb (Analyze_Indexed_Component_Form): Likewise.
* sem_prag.adb (Analyze_Pragma): Likewise.

6 months agoada: Simplify uses of the global name buffer
Piotr Trojanek [Wed, 4 Dec 2024 15:42:29 +0000 (16:42 +0100)] 
ada: Simplify uses of the global name buffer

Code cleanup; semantics is unaffected.

gcc/ada/ChangeLog:

* exp_dist.adb (Assign_Subprogram_Identifier,
Reserve_NamingContext_Methods): Simplify.
* osint.adb (Append_Suffix_To_File_Name, Find_File, Get_Directory,
Object_File_Name, Strip_Directory): Likewise.

6 months agoada: Simplify check for No_Coextensions restriction
Piotr Trojanek [Wed, 4 Dec 2024 15:26:45 +0000 (16:26 +0100)] 
ada: Simplify check for No_Coextensions restriction

Code cleanup; semantics is unaffected.

gcc/ada/ChangeLog:

* sem_res.adb (Resolve_Alocator): Move unrelated code out of a declare
block.

6 months agoada: Simplify traversal procedures into traversal functions
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.

6 months agoada: Assorted style cleanups
Piotr Trojanek [Wed, 4 Dec 2024 15:22:05 +0000 (16:22 +0100)] 
ada: Assorted style cleanups

Whitespace and comment cleanups.

gcc/ada/ChangeLog:

* sem_attr.adb (Eval_Attribute): Fix comment for attribute Image.
* tbuild.adb (Make_SC): Remove extra whitespace.

6 months agoada: Handle C++ exception hierarchies
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.

gcc/ada/ChangeLog:

* Makefile.rtl (GNATRTL_NONTASKING_OBJS): Add g-cpp, g-cppstd,
and g-cstyin.
* doc/gnat_rm/interfacing_to_other_languages.rst (Interfacing to C++):
Document class-wide matching and new interfaces.
* exp_prag.adb (Expand_Pragma_Import_Or_Interface): Add class-wide
exception matching support with 'B' as language identifier.
* libgnat/a-exexpr.adb (Setup_Current_Excep): Add Id formal.
(Set_Foreign_Occurrence): Likewise.
(Propagate_GCC_Exception): Adjust.
(Set_Exception_Parameter): Likewise.
(Unhandled_Except_Handler): Likewise.
* libgnat/g-cpp.ads: New.
* libgnat/g-cppexc.adb (Raise_Cpp_Exception): Match 'B' lang id.
(Get_Object_Address): New.
(Get_Object): Rewrite.
(Get_Access_To_Object): New.
(Get_Access_To_Tagged_Object): New.
(Get_Type_Info): New.
(Convert_Caught_Object): New.
* libgnat/g-cppexc.ads (Get_Object_Address): New.
(Get_Object): Note the Cpp Convention requirement.
(Get_Access_To_Object): New.
(Get_Access_To_Tagged_Object): New.
(Get_Type_Info): New.
* libgnat/g-cppstd.adb: New.
* libgnat/g-cppstd.ads: New.
* libgnat/g-csclex.ads: New, unused.
* libgnat/g-cstyin.adb: New.
* libgnat/g-cstyin.ads: New.
* libgnat/g-excact.adb (Exception_Language): New.
(Is_Foreign_Exception): Rewrite.
* libgnat/g-excact.ads (Exception_Languages): New.
(Exception_Language): New.
* libgnat/s-stalib.ads (Lang): Document 'B'.
* raise-gcc.c (__gnat_setup_current_excep): Add Exception_Id formal.
(CXX_DEPENDENT_EXCEPTION_CLASS): New.
(cxx_type_info): New.
(__cxa_exception): Rename exceptionType to encompass PrimaryException.
(_GNAT_Exception): Drop wrapper.
(EID_For): Adjust.
(exception_class_eq): Likewise.
(__gnat_exception_language_is_cplusplus): New.
(__gnat_exception_language_is_ada): New.
(__gnat_convert_caught_object): Declare.
(__gnat_get_cxx_dependent_exception): New.
(__gnat_maybe_get_cxx_dependent_exception): New.
(__gnat_get_cxx_exception_type_info): New.
(__gnat_obtain_caught_object): New.
(is_handled_by): Adjust.   [!CERT] Add eid formal, handle dependent
exceptions and base-type matches.
(get_action_description_for) [!CERT]: Add eid formal.  Adjust.
(personality_body): Adjust.
* gcc-interface/Make-lang.in (GNAT_ADA_OBJS, GNATBIND_OBJS) [!STAGE1]:
Add new g-cpp, g-cppstd, g-cstyin + preexisting g-cppexc
and i-cstrin.
* gnat-style.texi: Regenerate.
* gnat_rm.texi: Regenerate.

6 months agoada: Improve and correct support for inheritance of nonoverriding aspects
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.

6 months agoada: Fix small thinko in previous change
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.

6 months agoada: Leave empty parent in an array component of an anonymous access type
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.

6 months agoada: Incompatible conversion on vxworks in socket.c
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.

6 months agoada: Do not search executables in current dir by default
Tonu Naks [Tue, 3 Dec 2024 12:50:45 +0000 (12:50 +0000)] 
ada: Do not search executables in current dir by default

gcc/ada/ChangeLog:

* adaint.c: change default behaviour of __gnat_locate_exec_on_path
* adaint.h: change prototype of __gnat_locate_exec_on_path
* libgnat/s-os_lib.adb: pass optional argument in Locate_Exec_On_Path
* libgnat/s-os_lib.ads: change spec of Locate_Exec_On_Path
* libgnat/s-trasym__dwarf.adb: update import of __gnat_locate_exec_on_path

6 months agoada: Fix double free at run time for class-wide allocation
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.

6 months agoada: Warn on unmodified parameters of expression functions
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.

6 months agoada: Avoid failing reanalysis of aggregate bounds
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.

6 months agoada: Improve expansion of conditional expressions in object declarations
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.

6 months agoada: Preliminary work in analysis and expansion of initialized allocators
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.

6 months agoada: Remove useless space in ALI P lines
Ronan Desplanques [Thu, 28 Nov 2024 10:45:25 +0000 (11:45 +0100)] 
ada: Remove useless space in ALI P lines

The generated ALI files are syntactically unchanged.

gcc/ada/ChangeLog:

* lib-writ.adb (Write_ALI): Remove useless space.

6 months agoada: Fix omissions of ALI P line parameters
Ronan Desplanques [Thu, 28 Nov 2024 10:08:46 +0000 (11:08 +0100)] 
ada: Fix omissions of ALI P line parameters

Before this patch, the compiler would not report various tasking
settings specified in library units when these library units did not use
tasking, or when they were predefined. While this behavior was
implemented deliberately, that was a long time ago and it proved to be
a pitfall that could cause configuration pragmas to be silently ignored.

This patch makes the compiler report the aforementioned tasking settings
in ALI files unconditionally.

Also, this patch fixes an incorrect statement and a couple of typos in
the spec of Lib.Writ.

gcc/ada/ChangeLog:

* lib-writ.adb (Write_ALI): Remove condition for writing P line
parameters.
* lib-writ.ads: Fix typos. Clarify comment.

6 months agobpf: install a wrapping stdint.h for bpf-none-unknown targets
Jose E. Marchesi [Fri, 3 Jan 2025 12:42:26 +0000 (13:42 +0100)] 
bpf: install a wrapping stdint.h for bpf-none-unknown targets

This patch makes GCC to wrap the host's stdint.h header when operating
in the default hosted/non-freestanding mode.  It is thus up to the
user to provide a suitable standard header unless -ffreestanding gets
explicitly passed in the compilation line.

A few tests that use stdint.h are adapted to explicitly pass
-ffreestanding.

Tested in a x86_64-linux-gnu host with target bpf-unknown-none.

gcc/ChangeLog:

* config.gcc: install a wrapping stdint.h in bpf targets.

gcc/testsuite/ChangeLog:

* gcc.target/bpf/diag-funargs-2.c: Use -ffreestanding.
* gcc.target/bpf/helper-skb-ancestor-cgroup-id.c: Likewise.
* gcc.target/bpf/helper-bind.c: Likewise.
* gcc.target/bpf/diag-funargs-3.c: Likewise.

6 months agoOpenMP: update documentation for dispatch and adjust_args
Paul-Antoine Arras [Mon, 27 May 2024 09:48:34 +0000 (11:48 +0200)] 
OpenMP: update documentation for dispatch and adjust_args

libgomp/ChangeLog:

* libgomp.texi:

6 months agoOpenMP/C++: Store location in cp_parser_omp_var_list for kind=0
Tobias Burnus [Fri, 3 Jan 2025 09:12:32 +0000 (10:12 +0100)] 
OpenMP/C++: Store location in cp_parser_omp_var_list for kind=0

cp_parser_omp_var_list and cp_parser_omp_var_list_no_open have a special
modus: kind = 0 alias kind = OMP_CLAUSE_ERROR, which returns a simple tree
list; however, for a decl, no location is associated with that variable,
yielding to confusing error locations. With this patch, also for kind=0,
a reasonable error location is stored, albeit with creating a tree node
(build_empty_stmt), which is otherwise not used.

gcc/cp/ChangeLog:

* parser.cc (cp_parser_omp_var_list_no_open,
cp_parser_omp_var_list): For kind=0 (= OMP_CLAUSE_ERROR),
store also the expression location in the tree list.
(cp_parser_oacc_data_clause_deviceptr,
cp_finish_omp_declare_variant): Use that location instead or
input_location/the before-parsing location.
* semantics.cc (finish_omp_threadprivate): Likewise.

6 months agoFortran: Fix typo in ATAN documentation.
Sandra Loosemore [Fri, 3 Jan 2025 04:02:44 +0000 (04:02 +0000)] 
Fortran: Fix typo in ATAN documentation.

gcc/fortran/ChangeLog
* intrinsic.texi (ATAN): Add missing verb.

6 months agoDaily bump.
GCC Administrator [Fri, 3 Jan 2025 00:17:15 +0000 (00:17 +0000)] 
Daily bump.

6 months agoOpenMP: Enable has_device_addr clause for 'dispatch' in Fortran
Tobias Burnus [Thu, 2 Jan 2025 21:41:03 +0000 (22:41 +0100)] 
OpenMP: Enable has_device_addr clause for 'dispatch' in Fortran

Fortran version of commit r15-6178-g2cbb2408a830a6 for C/C++.
However, the has_device_addr clause on dispatch only becomes really
useful (for C++ and Fortran) once the 'need_device_addr' modifier
to declare variant's 'adjust_args' clause is supported (i.e. with
a future commit).

gcc/fortran/ChangeLog:

* openmp.cc (OMP_DISPATCH_CLAUSES): Add OMP_CLAUSE_HAS_DEVICE_ADDR.

gcc/testsuite/ChangeLog:

* gfortran.dg/gomp/adjust-args-10.f90: New test.

6 months agoOpenMP: Fortran front-end support for dispatch + adjust_args
Paul-Antoine Arras [Fri, 24 May 2024 17:13:50 +0000 (19:13 +0200)] 
OpenMP: Fortran front-end support for dispatch + adjust_args

This patch adds support for the `dispatch` construct and the `adjust_args`
clause to the Fortran front-end.

Handling of `adjust_args` across translation units is missing due to PR115271.

Minor modifications to the C++ FE and the ME are also folded into this patch as
a side effect of the Fortran work.

gcc/c-family/ChangeLog:

* c-attribs.cc: (c_common_gnu_attributes): Rename "omp declare variant
variant adjust_args" into "omp declare variant variant args" to also
accommodate append_args.

gcc/cp/ChangeLog:

* parser.cc (cp_parser_omp_dispatch): Handle INDIRECT_REF.

gcc/fortran/ChangeLog:

* dump-parse-tree.cc (show_omp_clauses): Handle novariants and nocontext
clauses.
(show_omp_node): Handle EXEC_OMP_DISPATCH.
(show_code_node): Likewise.
* frontend-passes.cc (gfc_code_walker): Handle novariants and nocontext.
* gfortran.h (enum gfc_statement): Add ST_OMP_DISPATCH.
(symbol_attribute): Add omp_declare_variant_need_device_ptr.
(gfc_omp_clauses): Add novariants and nocontext.
(gfc_omp_declare_variant): Add need_device_ptr_arg_list.
(enum gfc_exec_op): Add EXEC_OMP_DISPATCH.
* match.h (gfc_match_omp_dispatch): Declare.
* openmp.cc (gfc_free_omp_clauses): Free novariants and nocontext
clauses.
(gfc_free_omp_declare_variant_list): Free need_device_ptr_arg_list
namelist.
(enum omp_mask2): Add OMP_CLAUSE_NOVARIANTS and OMP_CLAUSE_NOCONTEXT.
(gfc_match_omp_clauses): Handle OMP_CLAUSE_NOVARIANTS and
OMP_CLAUSE_NOCONTEXT.
(OMP_DISPATCH_CLAUSES): Define.
(gfc_match_omp_dispatch): New function.
(gfc_match_omp_declare_variant): Parse adjust_args.
(resolve_omp_clauses): Handle adjust_args, novariants and nocontext.
Adjust handling of OMP_LIST_IS_DEVICE_PTR.
(icode_code_error_callback): Handle EXEC_OMP_DISPATCH.
(omp_code_to_statement): Likewise.
(resolve_omp_dispatch): New function.
(gfc_resolve_omp_directive): Handle EXEC_OMP_DISPATCH.
* parse.cc (decode_omp_directive): Match dispatch.
(next_statement): Handle ST_OMP_DISPATCH.
(gfc_ascii_statement): Likewise.
(parse_omp_dispatch): New function.
(parse_executable): Handle ST_OMP_DISPATCH.
* resolve.cc (gfc_resolve_blocks): Handle EXEC_OMP_DISPATCH.
* st.cc (gfc_free_statement): Likewise.
* trans-decl.cc (create_function_arglist): Declare.
(gfc_get_extern_function_decl): Call it.
* trans-openmp.cc (gfc_trans_omp_clauses): Handle novariants and
nocontext.
(replace_omp_dispatch_call): New function.
(gfc_trans_omp_dispatch): New function.
(gfc_trans_omp_directive): Handle EXEC_OMP_DISPATCH.
(gfc_trans_omp_declare_variant): Handle adjust_args.
* trans.cc (trans_code): Handle EXEC_OMP_DISPATCH:.

gcc/ChangeLog:

* gimplify.cc (gimplify_call_expr): Fix handling of need_device_ptr for
type(c_ptr). Fix handling of nested function calls in a dispatch region.
(find_ifn_gomp_dispatch): Return the IFN without stripping it.
(gimplify_omp_dispatch): Keep IFN_GOMP_DISPATCH until
gimplify_call_expr.

libgomp/ChangeLog:
* testsuite/libgomp.fortran/declare-variant-2-aux.f90: New test.
* testsuite/libgomp.fortran/declare-variant-2.f90: New test (xfail).
* testsuite/libgomp.fortran/dispatch-1.f90: New test.
* testsuite/libgomp.fortran/dispatch-2.f90: New test.
* testsuite/libgomp.fortran/dispatch-3.f90: New test.

gcc/testsuite/ChangeLog:

* g++.dg/gomp/dispatch-3.C: Update scan dumps.
* gfortran.dg/gomp/declare-variant-2.f90: Update dg-error.
* gfortran.dg/gomp/adjust-args-1.f90: New test.
* gfortran.dg/gomp/adjust-args-2.f90: New test.
* gfortran.dg/gomp/adjust-args-2a.f90: New test.
* gfortran.dg/gomp/adjust-args-3.f90: New test.
* gfortran.dg/gomp/adjust-args-4.f90: New test.
* gfortran.dg/gomp/adjust-args-5.f90: New test.
* gfortran.dg/gomp/adjust-args-6.f90: New test.
* gfortran.dg/gomp/adjust-args-7.f90: New test.
* gfortran.dg/gomp/adjust-args-8.f90: New test.
* gfortran.dg/gomp/adjust-args-9.f90: New test.
* gfortran.dg/gomp/dispatch-1.f90: New test.
* gfortran.dg/gomp/dispatch-2.f90: New test.
* gfortran.dg/gomp/dispatch-3.f90: New test.
* gfortran.dg/gomp/dispatch-4.f90: New test.
* gfortran.dg/gomp/dispatch-5.f90: New test.
* gfortran.dg/gomp/dispatch-6.f90: New test.
* gfortran.dg/gomp/dispatch-7.f90: New test.
* gfortran.dg/gomp/dispatch-8.f90: New test.
* gfortran.dg/gomp/dispatch-9.f90: New test.
* gfortran.dg/gomp/dispatch-9a.f90: New test.
* gfortran.dg/gomp/dispatch-10.f90: New test.

6 months agoc: special-case some "bool" errors with C23 (v2) [PR117629]
David Malcolm [Thu, 2 Jan 2025 20:10:15 +0000 (15:10 -0500)] 
c: special-case some "bool" errors with C23 (v2) [PR117629]

Changed in v2:
- distinguish between "bool" and "_Bool" when determining
  standard version

This patch attempts to provide better error messages for
code compiled with C23 that hasn't been updated for
"bool", "true", and "false" becoming keywords.

Specifically:

(1) with "typedef int bool;" previously we emitted:

t1.c:7:13: error: two or more data types in declaration specifiers
    7 | typedef int bool;
      |             ^~~~
t1.c:7:1: warning: useless type name in empty declaration
    7 | typedef int bool;
      | ^~~~~~~

whereas with this patch we emit:

t1.c:7:13: error: 'bool' cannot be defined via 'typedef'
    7 | typedef int bool;
      |             ^~~~
t1.c:7:13: note: 'bool' is a keyword with '-std=c23' onwards
t1.c:7:1: warning: useless type name in empty declaration
    7 | typedef int bool;
      | ^~~~~~~

(2) with "int bool;" previously we emitted:

t2.c:7:5: error: two or more data types in declaration specifiers
    7 | int bool;
      |     ^~~~
t2.c:7:1: warning: useless type name in empty declaration
    7 | int bool;
      | ^~~

whereas with this patch we emit:

t2.c:7:5: error: 'bool' cannot be used here
    7 | int bool;
      |     ^~~~
t2.c:7:5: note: 'bool' is a keyword with '-std=c23' onwards
t2.c:7:1: warning: useless type name in empty declaration
    7 | int bool;
      | ^~~

(3) with "typedef enum { false = 0, true = 1 } _Bool;" previously we
emitted:

t3.c:7:16: error: expected identifier before 'false'
    7 | typedef enum { false = 0, true = 1 } _Bool;
      |                ^~~~~
t3.c:7:38: error: expected ';', identifier or '(' before '_Bool'
    7 | typedef enum { false = 0, true = 1 } _Bool;
      |                                      ^~~~~
t3.c:7:38: warning: useless type name in empty declaration

whereas with this patch we emit:

t3.c:7:16: error: cannot use keyword 'false' as enumeration constant
    7 | typedef enum { false = 0, true = 1 } _Bool;
      |                ^~~~~
t3.c:7:16: note: 'false' is a keyword with '-std=c23' onwards
t3.c:7:38: error: expected ';', identifier or '(' before '_Bool'
    7 | typedef enum { false = 0, true = 1 } _Bool;
      |                                      ^~~~~
t3.c:7:38: warning: useless type name in empty declaration

gcc/c/ChangeLog:
PR c/117629
* c-decl.cc (declspecs_add_type): Special-case attempts to use
bool as a typedef name or declaration name.
* c-errors.cc (get_std_for_keyword): New.
(add_note_about_new_keyword): New.
* c-parser.cc (report_bad_enum_name): New, split out from...
(c_parser_enum_specifier): ...here, adding handling for RID_FALSE
and RID_TRUE.
* c-tree.h (add_note_about_new_keyword): New decl.

gcc/testsuite/ChangeLog:
PR c/117629
* gcc.dg/auto-type-2.c: Update expected output with _Bool.
* gcc.dg/c23-bool-errors-1.c: New test.
* gcc.dg/c23-bool-errors-2.c: New test.
* gcc.dg/c23-bool-errors-3.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
6 months agoUse _Float128 in test for PR118184
Richard Sandiford [Thu, 2 Jan 2025 17:33:49 +0000 (17:33 +0000)] 
Use _Float128 in test for PR118184

The test was failing on x86 because longdouble128 only checks sizeof,
rather than a full 128-bit payload.  Using _Float128 is more portable
and still exposes the original bug.

gcc/testsuite/
PR target/118184
* gcc.dg/torture/pr118184.c: Use _Float128 instead of long double.

6 months ago[GCN] install.texi: Refer to Newlib 4.5.0 instead to certain git commits
Tobias Burnus [Thu, 2 Jan 2025 14:43:30 +0000 (15:43 +0100)] 
[GCN] install.texi: Refer to Newlib 4.5.0 instead to certain git commits

gcc/ChangeLog:

* doc/install.texi (amdgcn-x-amdhsa): Refer to Newlib 4.5.0 for
the I/O locking fixes.

6 months agotree-optimization/118171 - GENERIC folding in PRE results in invalid GIMPLE
Richard Biener [Wed, 1 Jan 2025 15:07:03 +0000 (16:07 +0100)] 
tree-optimization/118171 - GENERIC folding in PRE results in invalid GIMPLE

PRE applies GENERIC folding to some component ref components which
might result in invalid GIMPLE, like a VIEW_CONVERT_EXPR wrapping
a REALPART_EXPR as in the PR.  The following removes all GENERIC
folding in the code re-constructing a GENERIC component-ref from
the PRE VN IL.

PR tree-optimization/118171
* tree-ssa-pre.cc (create_component_ref_by_pieces_1): Do not
fold any component ref parts.

* gcc.dg/torture/pr118171.c: New testcase.