platform/upstream/gcc.git
2 years agoc: Implement new -Wenum-int-mismatch warning [PR105131]
Marek Polacek [Fri, 1 Apr 2022 20:55:58 +0000 (16:55 -0400)]
c: Implement new -Wenum-int-mismatch warning [PR105131]

In C, an enumerated type is compatible with char, a signed integer type,
or an unsigned integer type (6.7.2.2/5).  Therefore this code compiles:

  enum E { l = -1, z = 0, g = 1 };
  int foo(void);
  enum E foo(void) { return z; }

if the underlying type of 'enum E' is 'int' (if not, we emit an error).
This is different for typedefs, where C11 permits typedefs to be
redeclared to the same type, but not to compatible types.  In C++, the
code above is invalid.

It seems desirable to emit a warning in the C case, because it is
probably a mistake and definitely a portability error, given that the
choice of the underlying type is implementation-defined.

To that end, this patch implements a new -Wenum-int-mismatch warning.
Conveniently, we already have comptypes_check_enum_int to detect such
mismatches.  This warning is enabled by either -Wall or -Wc++-compat.

PR c/105131

gcc/c-family/ChangeLog:

* c.opt (Wenum-int-mismatch): New.

gcc/c/ChangeLog:

* c-decl.cc (diagnose_mismatched_decls): Warn about enum/integer type
mismatches.
* c-tree.h (comptypes_check_enum_int): Declare.
* c-typeck.cc (comptypes): No longer static.

gcc/ChangeLog:

* doc/invoke.texi: Document -Wenum-int-mismatch.

gcc/testsuite/ChangeLog:

* gcc.dg/Wenum-int-mismatch-1.c: New test.
* gcc.dg/Wenum-int-mismatch-2.c: New test.
* gcc.dg/Wenum-int-mismatch-3.c: New test.
* gcc.dg/Wenum-int-mismatch-4.c: New test.
* gcc.dg/Wenum-int-mismatch-5.c: New test.

2 years agoRevert move of g++.dg/pr69667.C
Paul A. Clarke [Wed, 18 May 2022 20:45:56 +0000 (15:45 -0500)]
Revert move of g++.dg/pr69667.C

Commit eccbd7fcee5bbfc47731e8de83c44eee2e3dcc4b moved the subject file to
g++.target/powerpc.  Unfortunately, test g++.dg/tsan/pr88018.C includes
"../pr69667.C".

Revert the move of this file.

Commit 14e678a2c4a76433fd4029568d28530c921e11ee relaxed some DejaGnu
directives in g++.dg/tsan/pr88018.C, given its more restrictive environment
within g++.target/powerpc.  Revert these changes in that file as well.

2022-05-18  Paul A. Clarke  <pc@us.ibm.com>

gcc/testsuite
PR target/105620
* g++.target/powerpc/pr69667.C: Move to ...
* g++.dg/pr69667.C: here. Also, revert recent dg directives changes.

2 years agox86: Fix -fsplit-stack feature detection via TARGET_CAN_SPLIT_STACK
Uros Bizjak [Wed, 18 May 2022 18:03:26 +0000 (20:03 +0200)]
x86: Fix -fsplit-stack feature detection via  TARGET_CAN_SPLIT_STACK

Since commit c163647ffbc9a20c8feb6e079dbecccfe016c82e -fsplit-stack
is only supported on glibc targets. However, this original commit
required some fixups. As part of the fixup, the changes to the
gnu-user-common.h and gnu.h were partially reverted in commit
60953a23d57b13a672f751bec0c6eefc059eb1ab thus causing TARGET_CAN_SPLIT_STACK
to be defined for non-glibc targets even though -fsplit-stack is
actually not supported and attempting to use it causes a runtime error.

This causes gcc internal code, such as ./gcc/go/gospec.c to not
correctly detect that -fsplit-stack is not supported and thus causes
gccgo to fail compilation on non-glibc targets.

This commit ensures that TARGET_CAN_SPLIT_STACK is only set if the
default libc is glibc. It is presently unclear to me if there is a
better way to detect glibc at pre-processor time.

The proposed changes have been tested on x86 and x86_64 Alpine Linux
(which uses musl libc) and fix compilation of gccgo for this target.

Signed-off-by: Sören Tempel <soeren@soeren-tempel.net>
gcc/ChangeLog:

* config/i386/gnu-user-common.h (defined): Only define
TARGET_CAN_SPLIT_STACK for glibc targets.
* config/i386/gnu.h (defined): Ditto.

2 years agoCorrect ix86_rtx_cost for multi-word multiplication.
Roger Sayle [Wed, 18 May 2022 15:23:01 +0000 (16:23 +0100)]
Correct ix86_rtx_cost for multi-word multiplication.

This is the i386 backend specific piece of my revised patch for
PR middle-end/98865, where Richard Biener has suggested that I perform
the desired transformation during RTL expansion where the backend can
control whether it is profitable to convert a multiplication into a
bit-wise AND and a negation.  This works well for x86_64, but alas
exposes a latent bug with -m32, where a DImode multiplication incorrectly
appears to be cheaper than negdi2+anddi3(!?).  The fix to ix86_rtx_costs
is to report that a DImode (multi-word) multiplication actually requires
three SImode multiplications and two SImode additions.  This also corrects
the cost of TImode multiplication on TARGET_64BIT.

2022-05-18  Roger Sayle  <roger@nextmovesoftware.com>

gcc/ChangeLog
* config/i386/i386.cc (ix86_rtx_costs) [MULT]: When mode size
is wider than word_mode, a multiplication costs three word_mode
multiplications and two word_mode additions.

2 years agoAvoid andn and generate shorter not;and with -Oz on x86.
Roger Sayle [Wed, 18 May 2022 15:13:17 +0000 (16:13 +0100)]
Avoid andn and generate shorter not;and with -Oz on x86.

The x86 instruction encoding for SImode andn is longer than the
equivalent notl/andl sequence when the source for the not operand
is the same register as the destination.  This patch adds post_reload
splitters to i386.md to avoid "-mbmi" (which enables andn) increasing
code size with "-Oz".

One minor subtlety with this patch is that the splitter for
*andn_si_ccno swaps the order of operands (match_dup 2 and match_dup 3)
as memory operands need to appear first in *test<mode>_1 patterns.

2022-05-18  Roger Sayle  <roger@nextmovesoftware.com>

gcc/ChangeLog
* config/i386/i386.md (define_split):  Split *andsi_1
and *andn_si_ccno after reload with -Oz.

gcc/testsuite/ChangeLog
* gcc.target/i386/bmi-andn-3.c: New test case.

2 years agoc, c++: -Wswitch warning on [[maybe_unused]] enumerator [PR105497]
Marek Polacek [Sat, 7 May 2022 20:15:49 +0000 (16:15 -0400)]
c, c++: -Wswitch warning on [[maybe_unused]] enumerator [PR105497]

This PR complains that we emit the "enumeration value not handled in
switch" warning even though the enumerator was marked with the
[[maybe_unused]] attribute.

I couldn't just check TREE_USED, because the enumerator could have been
used earlier in the function, which doesn't play well with the
c_do_switch_warnings warning.  Instead, I had to check the attributes on
the CONST_DECL.  This is easy since the TYPE_VALUES of an enum type are
now consistent between C and C++, both of which store the CONST_DECL in
its TREE_VALUE.

PR c++/105497

gcc/c-family/ChangeLog:

* c-warn.cc (c_do_switch_warnings): Don't warn about unhandled
enumerator when it was marked with attribute unused.

gcc/testsuite/ChangeLog:

* c-c++-common/Wswitch-1.c: New test.
* g++.dg/warn/Wswitch-4.C: New test.

2 years agoc++: fix SIGFPE with -Wclass-memaccess [PR105634]
Marek Polacek [Tue, 17 May 2022 19:13:58 +0000 (15:13 -0400)]
c++: fix SIGFPE with -Wclass-memaccess [PR105634]

Here we crash because we attempt to % by 0.  Thus fixed.
While at it, I've moved the -Wclass-memaccess tests into warn/.
I've checked that the # of expected passes is the same before/after
the move.

PR c++/105634

gcc/cp/ChangeLog:

* call.cc (maybe_warn_class_memaccess): Avoid % by zero.

gcc/testsuite/ChangeLog:

* g++.dg/Wclass-memaccess-2.C: Moved to...
* g++.dg/warn/Wclass-memaccess-2.C: ...here.
* g++.dg/Wclass-memaccess-3.C: Moved to...
* g++.dg/warn/Wclass-memaccess-3.C: ...here.
* g++.dg/Wclass-memaccess-4.C: Moved to...
* g++.dg/warn/Wclass-memaccess-4.C: ...here.
* g++.dg/Wclass-memaccess-5.C: Moved to...
* g++.dg/warn/Wclass-memaccess-5.C: ...here.
* g++.dg/Wclass-memaccess-6.C: Moved to...
* g++.dg/warn/Wclass-memaccess-6.C: ...here.
* g++.dg/Wclass-memaccess.C: Moved to...
* g++.dg/warn/Wclass-memaccess.C: ...here.
* g++.dg/warn/Wclass-memaccess-7.C: New test.

2 years agoReduce usage of limited_with clauses with -fdump-ada-spec
Eric Botcazou [Wed, 18 May 2022 14:27:55 +0000 (16:27 +0200)]
Reduce usage of limited_with clauses with -fdump-ada-spec

The problem is that subtypes are not part of the limited view of a package
so we need to use types in conjunction with limited_with clauses, which is
not always desirable as this yields less portable Ada bindings.  The patch
also contains a small enhancement for complex floating-point types.

gcc/c-family/
* c-ada-spec.cc (dump_ada_node) <COMPLEX_TYPE>: Deal with usual
floating-point complex types.
<POINTER_TYPE>: Do not use limited_with clause if the designated
type is a scalar type.

2 years agotestsuite/rs6000: Move pr83660.C to g++.target
Kewen Lin [Wed, 18 May 2022 14:08:10 +0000 (09:08 -0500)]
testsuite/rs6000: Move pr83660.C to g++.target

Move pr83660.C to g++.target.  As comment #3 of PR83660,
rename it to c isn't one option.

gcc/testsuite/ChangeLog:

* gcc.target/powerpc/pr83660.C: Moved to...
* g++.target/powerpc/pr83660.C: ...here.

2 years agographite: Extend SCoP detection dump output
Frederik Harwath [Wed, 18 May 2022 05:59:42 +0000 (07:59 +0200)]
graphite: Extend SCoP detection dump output

Extend dump output to make understanding why Graphite rejects to
include a loop in a SCoP easier (for GCC developers).

gcc/ChangeLog:

* graphite-scop-detection.cc (scop_detection::can_represent_loop):
Output reason for failure to dump file.
(scop_detection::harmful_loop_in_region): Likewise.
(scop_detection::graphite_can_represent_expr): Likewise.
(scop_detection::stmt_has_simple_data_refs_p): Likewise.
(scop_detection::stmt_simple_for_scop_p): Likewise.
(print_sese_loop_numbers): New function.
(scop_detection::add_scop): Use from here.

gcc/testsuite/ChangeLog:

* gcc.dg/graphite/scop-22a.c: New test.

2 years agodemangler: Reorganize for module demangling
Nathan Sidwell [Tue, 8 Mar 2022 18:53:39 +0000 (10:53 -0800)]
demangler: Reorganize for module demangling

Module demangling requires some changes in how substitutions are
handled.  This adjusts things to make that possible.

libiberty/
* cp-demangle.c (d_name): Add SUBSTABLE parameter,
push substitution if requested. Adjust unscoped name handling.
(d_prefix): Reorder main loop. Adjust all calls.
(d_unqualified_name): Add SCOPE parameter, create qualified
name here. Adjust all calls.
(cplus_demangle_type): Do not handle 'S' here, leave all
to d_class_enum_type.
(d_class_enum_type): Add SUBSTABLE parameter.

2 years ago'include/cuda/cuda.h': Add parts necessary for nvptx-tools 'nvptx-run'
Thomas Schwinge [Fri, 29 Apr 2022 08:44:12 +0000 (10:44 +0200)]
'include/cuda/cuda.h': Add parts necessary for nvptx-tools 'nvptx-run'

include/
* cuda/cuda.h (enum CUjit_option): Add
'CU_JIT_GENERATE_DEBUG_INFO', 'CU_JIT_GENERATE_LINE_INFO'.
(enum CUlimit): Add 'CU_LIMIT_STACK_SIZE',
'CU_LIMIT_MALLOC_HEAP_SIZE'.
(cuCtxSetLimit, cuGetErrorName): Add.

2 years ago'include/cuda/cuda.h': For C++, wrap in 'extern "C"'
Thomas Schwinge [Fri, 29 Apr 2022 08:33:15 +0000 (10:33 +0200)]
'include/cuda/cuda.h': For C++, wrap in 'extern "C"'

include/
* cuda/cuda.h: For C++, wrap in 'extern "C"'.

2 years agoOpenMP: Add Fortran support for inoutset depend-kind
Tobias Burnus [Wed, 18 May 2022 10:04:21 +0000 (12:04 +0200)]
OpenMP: Add Fortran support for inoutset depend-kind

Fortran additions to the C/C++ + ME/libgomp commit
r13-556-g2c16eb3157f86ae561468c540caf8eb326106b5f

gcc/fortran/ChangeLog:

* gfortran.h (enum gfc_omp_depend_op): Add OMP_DEPEND_INOUTSET.
(gfc_omp_clauses): Enlarge ENUM_BITFIELD.
* dump-parse-tree.cc (show_omp_namelist, show_omp_clauses): Handle
'inoutset' depend modifier.
* openmp.cc (gfc_match_omp_clauses, gfc_match_omp_depobj): Likewise.
* trans-openmp.cc (gfc_trans_omp_clauses, gfc_trans_omp_depobj):
Likewise.

libgomp/ChangeLog:

* libgomp.texi (OpenMP 5.1): Set 'inoutset' to Y.
(OpenMP Context Selectors): Add missing comma.
* testsuite/libgomp.fortran/depend-5.f90: Add inoutset test.
* testsuite/libgomp.fortran/depend-6.f90: Likewise.
* testsuite/libgomp.fortran/depend-7.f90: Likewise.
* testsuite/libgomp.fortran/depend-inoutset-1.f90: New test.

gcc/testsuite/ChangeLog:

* gfortran.dg/gomp/all-memory-1.f90: Add inoutset test.
* gfortran.dg/gomp/all-memory-2.f90: Likewise.
* gfortran.dg/gomp/depobj-1.f90: Likewise.
* gfortran.dg/gomp/depobj-2.f90: Likewise.

2 years ago[Ada] Fix proof of runtime unit s-imageu
Claire Dross [Mon, 11 Apr 2022 12:10:49 +0000 (14:10 +0200)]
[Ada] Fix proof of runtime unit s-imageu

Update to provers caused some proof regressions.  Fix the proof by
adding an assertion.

gcc/ada/

* libgnat/s-imageu.adb (Set_Image_Unsigned): Change assertion.

2 years ago[Ada] qnx-7.1: warning in sigtramp-qnx.c __gnat_sigtramp
Doug Rupp [Fri, 8 Apr 2022 21:12:24 +0000 (14:12 -0700)]
[Ada] qnx-7.1: warning in sigtramp-qnx.c __gnat_sigtramp

Fix compilation warning. The code was using a cast to struct sigcontext
*, which doesn't exist. It worked by accident.

gcc/ada/

* sigtramp-qnx.c: Change struct sigcontext * to mcontext_t *.

2 years ago[Ada] arm-qnx-7.1: stack-checking and sigtramp implementation
Doug Rupp [Fri, 8 Apr 2022 18:28:48 +0000 (11:28 -0700)]
[Ada] arm-qnx-7.1: stack-checking and sigtramp implementation

Rewrite and base on VxWorks RTP implementation.

gcc/ada/

* sigtramp-arm-qnx.c: Rewrite.

2 years ago[Ada] Adapt proof of double arithmetic runtime unit
Yannick Moy [Fri, 8 Apr 2022 15:24:49 +0000 (15:24 +0000)]
[Ada] Adapt proof of double arithmetic runtime unit

After changes in Why3 and generation of VCs, ghost code needs to be
adapted for proofs to remain automatic.

gcc/ada/

* libgnat/s-aridou.adb (Big3): Change return type.
(Lemma_Mult_Non_Negative, Lemma_Mult_Non_Positive): Reorder
alphabetically.
(Lemma_Concat_Definition, Lemma_Double_Big_2xxsingle): New
lemmas.
(Double_Divide, Scaled_Divide): Add assertions.

2 years ago[Ada] Fix proof of runtime unit s-valeu
Claire Dross [Fri, 8 Apr 2022 14:38:47 +0000 (16:38 +0200)]
[Ada] Fix proof of runtime unit s-valeu

Update to provers caused some proof regressions.  Fix the proof by
changing ghost code.

gcc/ada/

* libgnat/s-valueu.adb (Scan_Raw_Unsigned): Add assertions.

2 years ago[Ada] Make sure output variable is always initialized
Kévin Le Gouguec [Thu, 7 Apr 2022 15:43:34 +0000 (17:43 +0200)]
[Ada] Make sure output variable is always initialized

gcc/ada/

* libgnat/s-dwalin.adb (Read_Aranges_Header): Initialize output
parameter in case we return early.

2 years ago[Ada] Disable Vet calls when container checks are disabled
Bob Duff [Thu, 7 Apr 2022 16:58:56 +0000 (12:58 -0400)]
[Ada] Disable Vet calls when container checks are disabled

Calls to various Vet functions are used throughout the containers
packages to check internal consistency. This patch improves efficiency
by disabling these calls when Container_Checks are suppressed.

gcc/ada/

* libgnat/a-crbtgo.ads, libgnat/a-rbtgbo.ads,
libgnat/a-cbdlli.adb, libgnat/a-cbhama.adb,
libgnat/a-cbhase.adb, libgnat/a-cdlili.adb,
libgnat/a-cfdlli.adb, libgnat/a-cfhama.adb,
libgnat/a-cfhase.adb, libgnat/a-cidlli.adb,
libgnat/a-cihama.adb, libgnat/a-cihase.adb,
libgnat/a-cohama.adb, libgnat/a-cohase.adb,
libgnat/a-crbtgo.adb, libgnat/a-crdlli.adb, libgnat/a-rbtgbo.adb
(Vet): Make the Vet functions do nothing when
Container_Checks'Enabled is False, and inline them, so the calls
disappear when optimizing.

2 years ago[Ada] arm-qnx-7.1: undefined reference to fma* symbols
Doug Rupp [Thu, 7 Apr 2022 18:08:56 +0000 (11:08 -0700)]
[Ada] arm-qnx-7.1: undefined reference to fma* symbols

Configure the arm-qnx runtime packages to avoid generating these
symbols.

gcc/ada/

* Makefile.rtl (arm-qnx): Use default (non-fma) target pair.

2 years ago[Ada] Fix DWARF parsing for 32-bit targets on 64-bit hosts
Kévin Le Gouguec [Thu, 7 Apr 2022 08:51:51 +0000 (10:51 +0200)]
[Ada] Fix DWARF parsing for 32-bit targets on 64-bit hosts

Currently, a 64-bit gnatsymbolize fails to output line numbers and
accurate symbol names when run on 32-bit executables (and vice-versa).
This is because a couple of spots in System.Dwarf_Lines expect the
Address_Size found in the DWARF data to match the host Address'Size.

This patch corrects that assumption.

gcc/ada/

* libgnat/s-dwalin.adb (Aranges_Lookup, Enable_Cache): Adapt to
changes in the signature of Read_Aranges_*.
(Debug_Info_Lookup): Do not control address size read from
DWARF.
(Read_Aranges_Header): Do not control address size read from
DWARF; return this size.
(Read_Aranges_Entry): Use the size returned by
Read_Aranges_Header.

2 years ago[Ada] Improve error messages for occurrence of GNAT extensions without -gnatX
Gary Dismukes [Wed, 6 Apr 2022 00:20:10 +0000 (20:20 -0400)]
[Ada] Improve error messages for occurrence of GNAT extensions without -gnatX

The error message issued for use of GNAT extension features without
specifying -gnatX (or pragma Extensions_Allowed) was confusing in the
presence of a pragma specifying a language version (such as "pragma
Ada_2022;"), because the pragma supersedes the switch.  The message is
improved by testing for use of such a pragma, plus use of pragma
Extensions_Allowed is now suggested, and several cases are changed to
call the common error procedure for flagging uses of extension features.

gcc/ada/

* errout.ads (Error_Msg_GNAT_Extension): Add formal Loc and
revise comment.
* errout.adb (Error_Msg_GNAT_Extension): Condition message on
the flag Ada_Version_Pragma, and add suggestion to use of pragma
Extensions_Allowed in messages.
* par-ch3.adb, par-ch5.adb, par-ch6.adb, par-ch11.adb,
par-ch12.adb: Add actual Token_Ptr on calls to
Error_Msg_GNAT_Extension.
* par-ch4.adb: Change Error_Msg to Error_Msg_GNAT_Extension for
error calls related to use of extension features.
* sem_ch13.adb: Likewise.

2 years ago[Ada] Fix Ada-QNX task priority conversion
Johannes Kliemann [Tue, 5 Apr 2022 16:25:43 +0000 (16:25 +0000)]
[Ada] Fix Ada-QNX task priority conversion

The conversion between OS and Ada priorties should be done in the wider
Interfaces.C.int type rather than Any_Priority otherwise
Constraint_Error will be raised when coverting Any_Priority'Last to int.

gcc/ada/

* libgnarl/s-osinte__qnx.adb (To_Target_Priority): Perform
arithmetic in int.

2 years ago[Ada] Use specific predicate before manipulating BIP_Alloc_Form
Eric Botcazou [Mon, 28 Mar 2022 19:16:24 +0000 (21:16 +0200)]
[Ada] Use specific predicate before manipulating BIP_Alloc_Form

For the sake of consistency with other similar manipulations.

gcc/ada/

* exp_ch7.adb (Build_BIP_Cleanup_Stmts): Use Needs_BIP_Alloc_Form.

2 years ago[Ada] Crash building VSS with compiler built with assertions
Javier Miranda [Fri, 1 Apr 2022 22:12:05 +0000 (22:12 +0000)]
[Ada] Crash building VSS with compiler built with assertions

When a tagged type T has aspect String_Literal, a derived type defines a
null extension T2, and the context to resolve the use of an object of
type T2 where the string literal is applicable is a class-wide type the
frontend crashes trying to evaluate if the object is a null extension.
This problem does not reproduce when the compiler is built with
assertions disabled.

gcc/ada/

* sem_ch6.adb (Find_Corresponding_Spec): Avoid calling
Is_Null_Extension with a class-wide type entity.
(Overrides_Visible_Function): Handle alias entities.
* sem_res.adb (Has_Applicable_User_Defined_Literal): Conversion
not needed if the result type of the call is class-wide or if
the result type matches the context type.
* sem_util.ads (Is_Null_Extension): Adding documentation.
(Is_Null_Extension_Of): Adding documentation.
* sem_util.adb (Is_Null_Extension): Adding assertion.
(Is_Null_Extension_Of): Adding assertions.

2 years ago[Ada] Ada2022: AI12-0143 Index attribute for entry families
Javier Miranda [Fri, 1 Apr 2022 20:06:27 +0000 (20:06 +0000)]
[Ada] Ada2022: AI12-0143 Index attribute for entry families

gcc/ada/

* snames.ads-tmpl (Name_Index): New attribute name.
(Attribute_Id): Adding Attribute_Index as regular attribute.
* sem_attr.adb (Attribute_22): Adding Attribute_Index as Ada
2022 attribute.
(Analyze_Index_Attribute): Check that 'Index appears in a
pre-/postcondition aspect or pragma associated with an entry
family.
(Analyze_Attribute): Adding semantic analysis for 'Index.
(Eval_Attribute): Register 'Index as can never be folded.
(Resolve_Attribute): Resolve attribute 'Index.
* sem_ch9.adb (Check_Wrong_Attribute_In_Postconditions): New
subprogram.
(Analyze_Requeue): Check that the requeue target shall not have
an applicable specific or class-wide postcondition which
includes an Index attribute reference.
* exp_attr.adb (Expand_N_Attribute_Reference): Transform
attribute Index into a renaming of the second formal of the
wrapper built for an entry family that has contract cases.
* einfo.ads (Is_Entry_Wrapper): Complete documentation.

2 years ago[Ada] Fix proof of runtime units
Yannick Moy [Mon, 4 Apr 2022 15:38:57 +0000 (17:38 +0200)]
[Ada] Fix proof of runtime units

Update to latest version of Why3 caused some proof regressions.
Fix the proof by changing ghost code.

gcc/ada/

* libgnat/s-imagei.adb (Set_Digits): Add assertion.
* libgnat/s-imgboo.adb (Image_Boolean): Add assertions.
* libgnat/s-valueu.adb (Scan_Raw_Unsigned): Add assertion.

2 years ago[Ada] Errors missed on ACATS test B650007
Arnaud Charlet [Sat, 2 Apr 2022 17:29:09 +0000 (17:29 +0000)]
[Ada] Errors missed on ACATS test B650007

This ACATS test shows that we need to call Is_Immutably_Limited_Type
in Analyze_Function_Return and also that we have a latent bug in
Is_Immutably_Limited_Type which shouldn't look through private types.

gcc/ada/

* sem_aux.adb (Is_Immutably_Limited_Type): Do not look through
private types as per RM 7.5(8.1).
* sem_ch6.adb (Analyze_Function_Return): Use
Is_Immutably_Limited_Type as per RM 6.5(5.10).

2 years ago[Ada] Fix the parsing for delta aggregate
Marc Poulhiès [Mon, 4 Apr 2022 12:09:45 +0000 (14:09 +0200)]
[Ada] Fix the parsing for delta aggregate

In Ada 2022, delta aggregate must use parentheses not square brackets
except array delta aggregates.

gcc/ada/

* gen_il-gen-gen_nodes.adb (Gen_IL.Gen.Gen_Nodes): Add
Is_Homogeneous_Aggregate field for N_Delta_Aggregate nodes.
* par-ch4.adb (P_Aggregate_Or_Paren_Expr): Minor reformatting.
* sem_aggr.adb (Resolve_Delta_Aggregate): Reject square brackets
for record aggregate.
(Resolve_Record_Aggregate): Uniformise error message.

2 years ago[Ada] Secondary stack and a-tags
Arnaud Charlet [Sun, 3 Apr 2022 08:08:48 +0000 (08:08 +0000)]
[Ada] Secondary stack and a-tags

The simple use of Ada.Tags triggers a dependency on the secondary stack
mechanism, which is unwanted on small embedded targets. To avoid this
dependency, we special case a-tags.ali in ALI.Scan_ALI to not set
Sec_Stack_Used. If some other code calls one of the functions returning
a string, this code will also be marked as requiring the secondary
stack. We also remove the need to import and set __gnat_binder_ss_count
in this case by ensuring this variable defaults to 0.

gcc/ada/

* ali.adb (Scan_ALI): Special case a-tags.ali when setting
Sec_Stack_Used.
* bindgen.adb (Gen_Adainit): Simplify handling of secondary
stack related code, and only import __gnat_binder_ss_count when
needed.
* libgnat/s-secsta.adb (Binder_SS_Count): Default initialize to
0.

2 years ago[Ada] Fix problematic underflow for Float_Type'Value
Eric Botcazou [Mon, 4 Apr 2022 21:16:53 +0000 (23:16 +0200)]
[Ada] Fix problematic underflow for Float_Type'Value

We need a couple of guards for boundary conditions in the support code.

gcc/ada/

* libgnat/s-dourea.adb ("/"): Add guard for zero and infinite
divisor.
* libgnat/s-valuer.adb (Scan_Raw_Real): Add guard for very large
exponent values.

2 years ago[Ada] Spurious error on freezing of tagged types in SPARK
Yannick Moy [Fri, 1 Apr 2022 14:58:19 +0000 (16:58 +0200)]
[Ada] Spurious error on freezing of tagged types in SPARK

SPARK RM 7.7(8) mandates that the freezing point of a tagged type must
occur within the so-called early call region of all its primitives.
This check may lead to spurious errors due to generated constructs being
considered in the search for the start of the early call region.

gcc/ada/

* sem_elab.adb (Is_Suitable_Construct): Fix for generated
constructs.

2 years ago[Ada] Rework optimization skipping pragma check in object declaration
Marc Poulhiès [Fri, 18 Mar 2022 09:32:41 +0000 (10:32 +0100)]
[Ada] Rework optimization skipping pragma check in object declaration

When an object declaration is initialized with a type conversion:

 Var : Typ := Typ (Value);

we skip the check for Typ's predicate as it is already checked
during the type conversion.

This is not correct when Var's subtype and the target subtype of the
conversion do not statically match:

 Var : Typ := OtherTyp (Value);

In such case, we can't skip the check of Typ's predicate.

Fix minor typos in comment.

gcc/ada/

* sem_ch3.adb (Analyze_Object_Declaration): Skip predicate check
for type conversion if object's subtype and expression's subtype
statically match.
* exp_prag.adb (Expand_Pragma_Check): Typo fix in comment.

2 years ago[Ada] Fix internal error on subprogram instantiation
Eric Botcazou [Fri, 1 Apr 2022 23:21:36 +0000 (01:21 +0200)]
[Ada] Fix internal error on subprogram instantiation

The compiler builds renamings for actuals of formal objects for debugging
purposes in this case, but it must not generate them for temporaries.

gcc/ada/

* exp_dbug.ads (Build_Subprogram_Instance_Renamings): Fix typo.
* exp_dbug.adb (Build_Subprogram_Instance_Renamings): Build the
renaming only for actuals of formal objects.

2 years ago[Ada] Overriding error on type derived from discriminated untagged private type
Gary Dismukes [Thu, 31 Mar 2022 20:33:01 +0000 (16:33 -0400)]
[Ada] Overriding error on type derived from discriminated untagged private type

When a derived type DT has an untagged private parent type PT with a
discriminant, where the full type of PT is tagged, and DT inherits a
function F with an anonymous access result that designates the type, the
compiler wrongly reports an error saying that DT must be declared
abstract or F overridden. A test is added to exclude checking the
abstract overriding rules that should only apply to inherited
subprograms of tagged derived types.

gcc/ada/

* sem_ch3.adb (Check_Abstract_Overriding): If the type is
derived from an untagged type, then don't perform any of the
abstract overriding error checks.

2 years ago[Ada] Prevent overflow in computation of aggregate size
Piotr Trojanek [Thu, 31 Mar 2022 18:56:58 +0000 (20:56 +0200)]
[Ada] Prevent overflow in computation of aggregate size

When computing size of a static aggregate to decide if it should be
transformed into assignments and loops we could have an overflow check.
This is mostly harmless, because colossal aggregates will likely crash
the application anyway, no matter how we transform them.

This was not detected because compiler was built with -gnatg switch that
suppresses overflow checks (they are only enabled by an explicit -gnato
switch).

gcc/ada/

* exp_aggr.adb (Component_Count): Calculate size as an Uint and
only then check if it is in the range of Int, as otherwise the
multiplication of Int values can overflow.

2 years ago[Ada] Fast implementation of floating-point mathematical functions
Eric Botcazou [Mon, 28 Mar 2022 07:30:16 +0000 (09:30 +0200)]
[Ada] Fast implementation of floating-point mathematical functions

This adds a package renaming unit to the GNAT hierarchy so as to expose
the underlying implementation of floating-point mathematical functions,
thus also making it possible to use their vector implementation, if any.

The change also contains a small improvement to the Hide_Public_Entities
mechanism in Sem_Ch7 that makes it possible to clear the Is_Public flag
within instances of generic packages that do not have a body.

gcc/ada/

* Makefile.rtl (GNATRTL_NONTASKING_OBJS): Add g-gfmafu$(objext).
(SIMD_PATH_TARGET_PAIRS): New variable.
(TRASYM_DWARF_COMMON_OBJS): Minor tweak.
(x86-64/Linux): Use SIMD_PATH_TARGET_PAIRS.
(x32/Linux): Likewise.
* doc/gnat_rm/the_gnat_library.rst (Generic_Fast_Math_Functions):
New entry.
* gnat_rm.texi: Regenerate.
* impunit.adb (Non_Imp_File_Names_95): Add g-gfmafu.
* sem_ch7.adb (Has_Referencer): Do not set In_Nested_Instance for
instances of generic packages that do not have a body.
* libgnat/a-nalofl__simd.ads: New SIMD-enabled version.
* libgnat/a-nuaufl__simd.ads: Likewise.
* libgnat/g-gfmafu.ads: New package renaming unit.

2 years ago[Ada] Freezing too strict in instances
Arnaud Charlet [Wed, 30 Mar 2022 19:00:27 +0000 (19:00 +0000)]
[Ada] Freezing too strict in instances

Should_Freeze_Type is relaxed to only take the relevant case into
account (entities denoted by generic actual parameters as per
13.14(5/3), as well as profile of any subprograms named as per
13.14(10.2/4)), instead of being overly conservative wrt instances and
as a result, wrongly rejecting some legal code.

In practice this means we only need to worry about profile of
subprograms named as part of instances.

gcc/ada/

* freeze.adb (Should_Freeze_Type): Fix handling of freezing in
instances.

2 years ago[Ada] Fix incorrect freezing with generic child unit
Marc Poulhiès [Mon, 28 Mar 2022 14:03:48 +0000 (16:03 +0200)]
[Ada] Fix incorrect freezing with generic child unit

The Analyze_Associations.Check_Generic_Parent function was using an
incorrect node as the instanciation node for the actual, possibly
leading to incorrect freeze node being created (and later crashing in
gigi). Using Get_Unit_Instantiation_Node fixes the issue.

gcc/ada/

* sem_ch12.adb (Check_Generic_Parent): Use
Get_Unit_Instantiation_Node instead of Next.

2 years ago[Ada] Ada.Numerics.Aux.*: Mention more Intrinsic and less C Math Library
Alexandre Oliva [Wed, 30 Mar 2022 08:45:17 +0000 (05:45 -0300)]
[Ada] Ada.Numerics.Aux.*: Mention more Intrinsic and less C Math Library

Since we import the elemental math functions as intrinsics, it's not
accurate to state we're drawing them in from the C math library.

gcc/ada/

* libgnat/a-nagefl.ads: Replace mentions of C/unix math library
with intrinsics.
* libgnat/a-nallfl.ads: Likewise.  State compatibility
requirements.
* libgnat/a-nalofl.ads: Likewise.
* libgnat/a-nuaufl.ads: Likewise.

2 years ago[Ada] Small performance tweak in recent change
Eric Botcazou [Wed, 30 Mar 2022 10:59:23 +0000 (12:59 +0200)]
[Ada] Small performance tweak in recent change

This avoids a useless walk of the prefix chain in instances.

gcc/ada/

* sem_ch8.adb (Analyze_Subprogram_Renaming): Move final test on
In_Instance to outer condition.

2 years ago[Ada] New port arm-qnx
Doug Rupp [Tue, 29 Mar 2022 16:22:31 +0000 (09:22 -0700)]
[Ada] New port arm-qnx

The QNX system specs for ARM and AARCH64 are identical. It makes more
sense to have it named for the base architecture.

gcc/ada/

* Makefile.rtl: Rename system-qnx-aarch64.ads to
system-qnx-arm.ads.
(AARCH64 QNX section): Modify to handle both arm and arch64.
* tracebak.c (__QNX__): Add new __ARMEL__ section.
* sigtramp-arm-qnx.c: New file.
* libgnat/system-qnx-aarch64.ads: Renamed to ...
* libgnat/system-qnx-arm.ads: this.

2 years agoEnhance final_value_replacement_loop to handle bitwise induction.
liuhongt [Tue, 7 Dec 2021 07:41:52 +0000 (15:41 +0800)]
Enhance final_value_replacement_loop to handle bitwise induction.

This patch will enable below optimization:

 {
-  int bit;
-  long long unsigned int _1;
-  long long unsigned int _2;
-
   <bb 2> [local count: 46707768]:
-
-  <bb 3> [local count: 1027034057]:
-  # tmp_11 = PHI <tmp_8(3), tmp_6(D)(2)>
-  # bit_13 = PHI <bit_9(3), 63(2)>
-  _1 = 1 << bit_13;
-  _2 = ~_1;
-  tmp_8 = _2 & tmp_11;
-  bit_9 = bit_13 + -3;
-  if (bit_9 != -3(OVF))
-    goto <bb 3>; [95.65%]
-  else
-    goto <bb 4>; [4.35%]
-
-  <bb 4> [local count: 46707768]:
-  return tmp_8;
+  tmp_12 = tmp_6(D) & 7905747460161236406;
+  return tmp_12;

 }

gcc/ChangeLog:

PR middle-end/103462
* match.pd (bitwise_induction_p): New match.
* tree-scalar-evolution.cc (gimple_bitwise_induction_p):
Declare.
(analyze_and_compute_bitwise_induction_effect): New function.
(enum bit_op_kind): New enum.
(final_value_replacement_loop): Enhanced to handle bitwise
induction.

gcc/testsuite/ChangeLog:

* gcc.target/i386/pr103462-1.c: New test.
* gcc.target/i386/pr103462-2.c: New test.
* gcc.target/i386/pr103462-3.c: New test.
* gcc.target/i386/pr103462-4.c: New test.
* gcc.target/i386/pr103462-5.c: New test.
* gcc.target/i386/pr103462-6.c: New test.

2 years agoThis patch adds a combine pattern for "CA minus one". The SImode "CA minus one" can...
Haochen Gui [Wed, 11 May 2022 01:19:52 +0000 (09:19 +0800)]
This patch adds a combine pattern for "CA minus one". The SImode "CA minus one" can be converted to DImode as CA only has two values (0 or 1).

gcc/
PR target/95737
* config/rs6000/rs6000.md (*subfsi3_carry_in_xx_64): New.

gcc/testsuite/
PR target/95737
* gcc.target/powerpc/pr95737.c: New.

2 years agorecognize bzhi pattern when there's zero_extendsidi.
liuhongt [Thu, 28 Apr 2022 07:30:06 +0000 (15:30 +0800)]
recognize bzhi pattern when there's zero_extendsidi.

backend has

16550(define_insn "*bmi2_bzhi_<mode>3_2"
16551  [(set (match_operand:SWI48 0 "register_operand" "=r")
16552        (and:SWI48
16553          (plus:SWI48
16554            (ashift:SWI48 (const_int 1)
16555                          (match_operand:QI 2 "register_operand" "r"))
16556            (const_int -1))
16557          (match_operand:SWI48 1 "nonimmediate_operand" "rm")))
16558   (clobber (reg:CC FLAGS_REG))]
16559  "TARGET_BMI2"
16560  "bzhi\t{%<k>2, %1, %0|%0, %1, %<k>2}"
16561  [(set_attr "type" "bitmanip")
16562   (set_attr "prefix" "vex")
16563   (set_attr "mode" "<MODE>")])

But there's extra zero_extend in pattern match.

424Failed to match this instruction:
425(parallel [
426        (set (reg:DI 90)
427            (zero_extend:DI (and:SI (plus:SI (ashift:SI (const_int 1 [0x1])
428                            (subreg:QI (reg:SI 98) 0))
429                        (const_int -1 [0xffffffffffffffff]))
430                    (subreg:SI (reg:DI 95) 0))))
431        (clobber (reg:CC 17 flags))
432    ])

Add new define_insn for it.

gcc/ChangeLog:

PR target/104375
* config/i386/i386.md (*bmi2_bzhi_zero_extendsidi_4): New
define_insn.

gcc/testsuite/ChangeLog:

* gcc.target/i386/pr104375.c: New test.

2 years agoExpand __builtin_memcmp_eq with ptest for OImode.
liuhongt [Tue, 1 Mar 2022 05:41:52 +0000 (13:41 +0800)]
Expand __builtin_memcmp_eq with ptest for OImode.

gcc/ChangeLog:

PR target/104610
* config/i386/i386-expand.cc (ix86_expand_branch): Use ptest
for QImode when code is EQ or NE.
* config/i386/i386.md (cbranchoi4): New expander.

gcc/testsuite/ChangeLog:

* gcc.target/i386/pr104610.c: New test.

2 years agors6000: Prefer assigning the MMA vector operands to altivec registers [PR105556]
Peter Bergner [Wed, 18 May 2022 02:09:29 +0000 (21:09 -0500)]
rs6000: Prefer assigning the MMA vector operands to altivec registers [PR105556]

When optimizing the DGEMM kernel in OpenBLAS to use MMA, the MMA code
uses all 8 accumulators, which overlap all vs0-vs31 vector registers.
Current trunk assigns one of the normal vector inputs to one of the MMA
instructions, which forces us to spill one of the accumulators to memory,
leading to poor performance.  The solution here is to replace the "wa"
constraints for the vector input operands in the MMA instruction patterns
with "v,?wa" so that we prefer using the altivec registers vs32-vs63
over the vs0-vs31 registers.

2022-05-17  Peter Bergner  <bergner@linux.ibm.com>
    Segher Boessenkool  <segher@kernel.crashing.org>

gcc/
PR target/105556
* config/rs6000/mma.md (mma_<vv>, mma_<avv>, mma_<pv>, mma_<apv>,
mma_<vvi4i4i8>, mma_<avvi4i4i8>, mma_<vvi4i4i2>, mma_<avvi4i4i2>,
mma_<vvi4i4>, mma_<avvi4i4>, mma_<pvi4i2>, mma_<apvi4i2>,
mma_<vvi4i4i4>, mma_<avvi4i4i4>): Replace "wa" constraints with "v,?wa".
Update other operands accordingly.

2 years agoDaily bump.
GCC Administrator [Wed, 18 May 2022 00:16:36 +0000 (00:16 +0000)]
Daily bump.

2 years agocompiler: load LHS subexpressions of op= assignment only once
Ian Lance Taylor [Wed, 11 May 2022 00:05:08 +0000 (17:05 -0700)]
compiler: load LHS subexpressions of op= assignment only once

Fixes golang/go#52811

Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/405617

2 years agoc++: constexpr ref to array of array [PR102307]
Jason Merrill [Tue, 26 Apr 2022 15:15:04 +0000 (11:15 -0400)]
c++: constexpr ref to array of array [PR102307]

The problem here is that first check_initializer calls
build_aggr_init_full_exprs, which does overload resolution, but then in the
case of failed constexpr throws away the result and does it again in
build_functional_cast.  But in the first overload resolution,
reshape_init_array_1 decided to reuse the inner CONSTRUCTORs because
tf_error is set, so we know we're committed.  But the second pass gets
confused by the CONSTRUCTORs with non-init-list types.

Fixed by avoiding a second pass: instead, pass the call from build_aggr_init
to build_cplus_new, which will turn it into a TARGET_EXPR.  I don't bother
to change the object argument because it will be replaced later in
simplify_aggr_init_expr.

PR c++/102307

gcc/cp/ChangeLog:

* decl.cc (check_initializer): Use build_cplus_new in case of
constexpr failure.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1z/constexpr-array2.C: New test.

2 years agoc: use CONST_DECL for enumerators in TYPE_VALUES
Marek Polacek [Tue, 17 May 2022 17:41:56 +0000 (13:41 -0400)]
c: use CONST_DECL for enumerators in TYPE_VALUES

The C and C++ FEs differ in TYPE_VALUES for an enum type: an entry in
the list in the C++ FE has a CONST_DECL in the TREE_VALUE, but the C FE
has only the numerical value of the CONST_DECL there.  This has caused
me some trouble in my PR105497 patch.  Using a CONST_DECL is preferable
because a CONST_DECL can track more information (e.g., attributes), and
you can always get the value simply by looking at its DECL_INITIAL.

This turned out to be a trivial change.  One place in godump.cc had to be
adjusted.  I'm not changing the CONST_DECL check in c_do_switch_warnings
because I'll be changing it soon in my next patch.  I didn't see any other
checks that this patch makes redundant.

gcc/c/ChangeLog:

* c-decl.cc (finish_enum): Store the CONST_DECL into TREE_VALUE, not
its value.

gcc/ChangeLog:

* godump.cc (go_output_typedef): Use the DECL_INITIAL of the TREE_VALUE.

2 years agoFix register count when not splitting Complex IEEE 128-bit args.
Pat Haugen [Tue, 17 May 2022 20:53:24 +0000 (15:53 -0500)]
Fix register count when not splitting Complex IEEE 128-bit args.

For ABI_V4, we do not split complex args. This created a problem because
even though an arg would be passed in two VSX regs, we were only advancing the
function arg counter by one VSX register. Fixed with this patch.

PR target/99685

gcc/
* config/rs6000/rs6000-call.cc (rs6000_function_arg_advance_1): Bump
register count when not splitting IEEE 128-bit Complex.

2 years agoOpenMP: Skip target-nesting warning for reverse offload
Tobias Burnus [Tue, 17 May 2022 20:09:16 +0000 (22:09 +0200)]
OpenMP: Skip target-nesting warning for reverse offload

gcc/ChangeLog:

* omp-low.cc (check_omp_nesting_restrictions): Skip warning for
target inside target if inner is reverse offload.

gcc/testsuite/ChangeLog:

* c-c++-common/gomp/target-device-ancestor-5.c: New test.

2 years agolibstdc++: Relax memory ordering for default memory resource object
Jonathan Wakely [Tue, 17 May 2022 15:17:21 +0000 (16:17 +0100)]
libstdc++: Relax memory ordering for default memory resource object

Currently pmr::set_default_resource and pmr::get_default_resource both
use sequentially consistent memory ordering. This is overkill. The
standard only requires that a call to set_default_resource synchronizes
with subsequent calls to set_default_resource and get_default_resource.

Using acquire-release for the setter and acquire for the getter is
sufficient to meet the requirement.

Reviewed-by: Thomas Rodgers <trodgers@redhat.com>
libstdc++-v3/ChangeLog:

* src/c++17/memory_resource.cc (set_default_resource): Use
memory_order_acq_rel.
(get_default_resource): Use memory_order_acquire.

2 years agolibstdc++: Add attributes to functions in <memory_resource>
Jonathan Wakely [Tue, 17 May 2022 14:14:39 +0000 (15:14 +0100)]
libstdc++: Add attributes to functions in <memory_resource>

Add attributes to the accessors for the global memory resource objects,
to allow the compiler to eliminate redundant calls to them. For example,
multiple calls to std::pmr::new_delete_resource() will always return the
same object, and so the compiler can replace them with a single call.

Ideally we would like adjacent calls to std::pmr::get_default_resource()
to be combined into a single call by the CSE pass. The 'pure' attribute
would permit that. However, the standard requires that calls to
std::pmr::set_default_resource() synchronize with subsequent calls to
std::pmr::get_default_resource().  With 'pure' the DCE pass might
eliminate seemingly redundant calls to std::pmr::get_default_resource().
That might be unsafe, because the caller might be relying on the
associated synchronization. We could use a hypothetical attribute that
allows CSE but not DCE, but we don't have one. So it can't be 'pure'.

Also add [[nodiscard]] to equality operators.

libstdc++-v3/ChangeLog:

* include/std/memory_resource (new_delete_resource): Add
nodiscard, returns_nonnull and const attributes.
(null_memory_resource): Likewise.
(set_default_resource, get_default_resource): Add returns_nonnull
attribute.
(memory_resource::is_equal): Add nodiscard attribute.
(operator==, operator!=): Likewise.

2 years agolibstdc++: Add attributes to <system_error> and related
Jonathan Wakely [Tue, 17 May 2022 13:50:32 +0000 (14:50 +0100)]
libstdc++: Add attributes to <system_error> and related

Add the const attribute to std::future_category() and
std::iostream_category(), to match the existing attributes on
std::generic_category() and std::system_category().

Also add [[nodiscard]] to those functions and to the comparison
operators for std::error_code and std::error_condition, and to
std::make_error_code and std::make_error_condition overloads.

libstdc++-v3/ChangeLog:

* include/bits/ios_base.h (io_category): Add const and nodiscard
attributes.
(make_error_code, make_error_condition): Add nodiscard.
* include/std/future (future_category): Add const and nodiscard.
(make_error_code, make_error_condition): Add nodiscard.
* include/std/system_error (generic_category system_category):
Add nodiscard. Replace _GLIBCXX_CONST with C++11 attribute.
(error_code::value, error_code::category, error_code::operator bool)
(error_condition::value, error_condition::category)
(error_condition::operator bool, make_error_code)
(make_error_condition, operator==, operator!=, operator<=>): Add
nodiscard.

2 years agoRevert 'Use more ARRAY_SIZE.' for mkoffload
Tobias Burnus [Tue, 17 May 2022 18:46:29 +0000 (20:46 +0200)]
Revert 'Use more ARRAY_SIZE.' for mkoffload

Revert commit r13-472-gca32b29ec3e92dcf8dda5c2501d0baf9dd1cb09d partially;
namely for {gcn,nvptx}/mkoffload.cc, only.

The patch changed 'sizeof(...)/sizeof(...[0])' to the 'ARRAY_SIZE' macro,
which is in principle a good idea – except that in the two mkoffload.cc,
the change happened inside a string that is used to generate plain C code.

With offlading to nvptx or gcn, the mkoffload genenates then the C file
and compilation of the latter fails with
"warning: implicit declaration of function 'ARRAY_SIZE'" followed by
"error: initializer element is not constant"

gcc/
* config/gcn/mkoffload.cc (process_obj): Revert: Use ARRAY_SIZE.
* config/nvptx/mkoffload.cc (process): Likewise.

2 years agoAdd side effect infrastructure.
Andrew MacLeod [Mon, 9 May 2022 19:35:14 +0000 (15:35 -0400)]
Add side effect infrastructure.

Replace the non-null procesing with a generic side effect implementation that
can handle arbitrary side effects.

* Makefile.in (OBJS): Add gimple-range-side-effect.o.
* gimple-range-cache.cc (non_null_ref::non_null_ref): Delete.
(non_null_ref::~non_null_ref): Delete.
(non_null_ref::set_nonnull): Delete.
(non_null_ref::non_null_deref_p): Delete.
(non_null_ref::process_name): Delete.
(ranger_cache::ranger_cache): Initialize m_exit object.
(ranger_cache::fill_block_cache): Use m_exit object intead of nonnull.
(ranger_cache::range_from_dom): Use side_effect class and m_exit object.
(ranger_cache::update_to_nonnull): Delete.
(non_null_loadstore): Delete.
(ranger_cache::block_apply_nonnull): Delete.
(ranger_cache::apply_side_effects): New.
* gimple-range-cache.h (class non_null_ref): Delete.
(non_null_ref::adjust_range): Delete.
(class ranger_cache): Adjust prototypes, add side effect manager.
* gimple-range-path.cc (path_range_query::range_defined_in_block): Use
side effect manager for queries.
(path_range_query::adjust_for_non_null_uses): Ditto.
* gimple-range-path.h (class path_range_query): Delete non_null_ref.
* gimple-range-side-effect.cc: New.
* gimple-range-side-effect.h: New.
* gimple-range.cc (gimple_ranger::gimple_ranger): Update contructor.
(gimple_ranger::range_of_expr): Check def block for override value.
(gimple_ranger::range_on_entry): Don't scan dominators for non-null.
(gimple_ranger::range_on_edge): Check for outgoing side-effects.
(gimple_ranger::register_side_effects): Call apply_side_effects.
(enable_ranger): Update contructor.
* gimple-range.h (class gimple_ranger): Update prototype.
(enable_ranger): Update prototype.
* tree-vrp.cc (execute_ranger_vrp): Invoke without immediate-use flag.

2 years agodemangler: Structured Bindings
Nathan Sidwell [Tue, 8 Mar 2022 21:00:35 +0000 (13:00 -0800)]
demangler: Structured Bindings

C++ Structured bindings have a mangling that has yet to be formally
documented.  However, it's been around for a while and shows up for
module support.

include/
* demangle.h (enum demangle_component_type): Add
DEMANGLE_COMPONENT_STRUCTURED_BINDING.
libiberty/
* cp-demangle.c (d_make_comp): Adjust.
(d_unqualified_name): Add 'DC' support.
(d_count_template_scopes): Adjust.
(d_print_comp_inner): Add structured binding.
* testsuite/demangle-expected: Add testcases.

2 years agoPR105169 Fix references to discarded sections
Giuliano Belinassi [Sat, 7 May 2022 02:37:52 +0000 (23:37 -0300)]
PR105169 Fix references to discarded sections

When -fpatchable-function-entry= is enabled, certain C++ codes fails to
link because of generated references to discarded sections in
__patchable_function_entry section. This commit fixes this problem by
puting those references in a COMDAT section.

2022-05-06  Giuliano Belinassi  <gbelinassi@suse.de>

gcc/ChangeLog
PR c++/105169
* targhooks.cc (default_print_patchable_function_entry_1): Handle COMDAT case.
* varasm.cc (switch_to_comdat_section): New
(handle_vtv_comdat_section): Call switch_to_comdat_section.
* varasm.h: Declare switch_to_comdat_section.

gcc/testsuite/ChangeLog
2022-05-06  Giuliano Belinassi  <gbelinassi@suse.de>

PR c++/105169
* g++.dg/modules/pr105169.h: New file.
* g++.dg/modules/pr105169_a.C: New test.
* g++.dg/modules/pr105169_b.C: New file.

2 years agoDo not clear bb->aux in duplicate_loop_body_to_header_edge
Richard Biener [Tue, 17 May 2022 15:18:06 +0000 (17:18 +0200)]
Do not clear bb->aux in duplicate_loop_body_to_header_edge

duplicate_loop_body_to_header_edge clears bb->aux which is not wanted
by a new use in loop unswitching.  The clearing was introduced with
r0-69110-g6580ee7781f903 and it seems accidentially so.

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

* cfgloopmanip.cc (duplicate_loop_body_to_header_edge): Do
not clear bb->aux of the copied blocks.

2 years agoCheck for equivalence after merging relations.
Andrew MacLeod [Tue, 17 May 2022 01:39:30 +0000 (21:39 -0400)]
Check for equivalence after merging relations.

When registering a relation, we need to merge with any existing relation
before checking if it was an equivalence... otherwise it was not being
handled properly.

gcc/
PR tree-optimization/105458
* value-relation.cc (path_oracle::register_relation): Merge, then check
for equivalence.

gcc/testsuite/
* gcc.dg/pr105458.c: New.

2 years agoi386: Fix ICE in final_scan_insn_1 [PR105624]
Uros Bizjak [Tue, 17 May 2022 15:22:26 +0000 (17:22 +0200)]
i386: Fix ICE in final_scan_insn_1 [PR105624]

Apparently const_int_operand and other const*_operand predicates
do need constraints.  Revert the offending patch that caused ICE.

2022-05-17  Uroš Bizjak  <ubizjak@gmail.com>

gcc/ChangeLog:

PR target/105624
Revert:

* config/i386/i386.md: Remove constraints when used with
const_int_operand, const0_operand, const_1_operand, constm1_operand,
const8_operand, const128_operand, const248_operand, const123_operand,
const2367_operand, const1248_operand, const359_operand,
const_4_or_8_to_11_operand, const48_operand, const_0_to_1_operand,
const_0_to_3_operand, const_0_to_4_operand, const_0_to_5_operand,
const_0_to_7_operand, const_0_to_15_operand, const_0_to_31_operand,
const_0_to_63_operand, const_0_to_127_operand, const_0_to_255_operand,
const_0_to_255_mul_8_operand, const_1_to_31_operand,
const_1_to_63_operand, const_2_to_3_operand, const_4_to_5_operand,
const_4_to_7_operand, const_6_to_7_operand, const_8_to_9_operand,
const_8_to_11_operand, const_8_to_15_operand, const_10_to_11_operand,
const_12_to_13_operand, const_12_to_15_operand, const_14_to_15_operand,
const_16_to_19_operand, const_16_to_31_operand, const_20_to_23_operand,
const_24_to_27_operand and const_28_to_31_operand.
* config/i386/mmx.md: Ditto.
* config/i386/sse.md: Ditto.
* config/i386/subst.md: Ditto.
* config/i386/sync.md: Ditto.

gcc/testsuite/ChangeLog:

PR target/105624
* gcc.target/i386/pr105624.c: New test.

2 years agolibgomp: Clarify that omp_display_env is fully implemented
Jakub Jelinek [Tue, 17 May 2022 14:58:26 +0000 (16:58 +0200)]
libgomp: Clarify that omp_display_env is fully implemented

OpenMP 5.2 added
"When called from within a target region the effect is unspecified."
restriction to omp_display_env, so it is ok not to support it in
target regions (worst case we could add an empty implementation
or one with __builtin_trap in there).

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

* libgomp.texi (OpenMP 5.1): Remove "Not inside target regions"
comment for omp_display_env feature.

2 years agoAdvise to call 'internal_error' instead of 'abort' or 'fancy_abort'
Thomas Schwinge [Tue, 10 May 2022 13:56:08 +0000 (15:56 +0200)]
Advise to call 'internal_error' instead of 'abort' or 'fancy_abort'

gcc/
* diagnostic.cc: Don't advise to call 'abort' instead of
'internal_error'.
* system.h: Advise to call 'internal_error' instead of 'abort' or
'fancy_abort'.

Suggested-by: Richard Biener <richard.guenther@gmail.com>
2 years agographite: Fix minor mistakes in comments
Frederik Harwath [Tue, 17 May 2022 14:02:01 +0000 (16:02 +0200)]
graphite: Fix minor mistakes in comments

gcc/ChangeLog:

* graphite-sese-to-poly.cc (build_poly_sr_1): Fix a typo and
a reference to a variable which does not exist.
* graphite-isl-ast-to-gimple.cc (gsi_insert_earliest): Fix typo
in comment.

2 years agographite: Rename isl_id_for_ssa_name
Frederik Harwath [Tue, 17 May 2022 14:00:57 +0000 (16:00 +0200)]
graphite: Rename isl_id_for_ssa_name

The SSA names for which this function gets used are always SCoP
parameters and hence "isl_id_for_parameter" is a better name.  It also
explains the prefix "P_" for those names in the ISL representation.

gcc/ChangeLog:

* graphite-sese-to-poly.cc (isl_id_for_ssa_name): Rename to ...
(isl_id_for_parameter): ... this new function name.
(build_scop_context): Adjust function use.

2 years agolibgomp.texi: Document OpenMP context selectors
Tobias Burnus [Tue, 17 May 2022 13:52:24 +0000 (15:52 +0200)]
libgomp.texi: Document OpenMP context selectors

libgomp/
* libgomp.texi (Offload-Target Specifics): New chapter; add section
to document OpenMP context selectors.

2 years agogcn/t-omp-device: Add 'amdgcn' as 'arch' [PR105602]
Tobias Burnus [Tue, 17 May 2022 13:48:40 +0000 (15:48 +0200)]
gcn/t-omp-device: Add 'amdgcn' as 'arch' [PR105602]

Improve cross-compiler handling.

gcc/ChangeLog:

PR target/105602
* config/gcn/t-omp-device (arch): Add 'amdgcn' besides existing 'gcn'.
* config/gcn/gcn.cc (gcn_omp_device_kind_arch_isa): Likewise.

2 years agoopenmp: Add support for inoutset depend-kind
Jakub Jelinek [Tue, 17 May 2022 13:40:27 +0000 (15:40 +0200)]
openmp: Add support for inoutset depend-kind

This patch adds support for inoutset depend-kind in depend
clauses.  It is very similar to the in depend-kind in that
a task with a dependency with that depend-kind is dependent
on all previously created sibling tasks with matching address
unless they have the same depend-kind.
In the in depend-kind case everything is dependent except
for in -> in dependency, for inoutset everything is
dependent except for inoutset -> inoutset dependency.
mutexinoutset is also similar (everything is dependent except
for mutexinoutset -> mutexinoutset dependency), but there is
also the additional restriction that only one task with
mutexinoutset for each address can be scheduled at once (i.e.
mutual exclusitivty).  For now we support mutexinoutset
the same as inout/out, but the inoutset support is full.

In order not to bump the ABI for dependencies each time
(we've bumped it already once, the old ABI supports only
inout/out and in depend-kind, the new ABI supports
inout/out, mutexinoutset, in and depobj), this patch arranges
for inoutset to be at least for the time being always handled
as if it was specified through depobj even when it is not.
So it uses the new ABI for that and inoutset are represented
like depobj - pointer to a pair of pointers where the first one
will be the actual address of the object mentioned in depend
clause and second pointer will be (void *) GOMP_DEPEND_INOUTSET.

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

gcc/
* tree-core.h (enum omp_clause_depend_kind): Add
OMP_CLAUSE_DEPEND_INOUTSET.
* tree-pretty-print.cc (dump_omp_clause): Handle
OMP_CLAUSE_DEPEND_INOUTSET.
* gimplify.cc (gimplify_omp_depend): Likewise.
* omp-low.cc (lower_depend_clauses): Likewise.
gcc/c-family/
* c-omp.cc (c_finish_omp_depobj): Handle
OMP_CLAUSE_DEPEND_INOUTSET.
gcc/c/
* c-parser.cc (c_parser_omp_clause_depend): Parse
inoutset depend-kind.
(c_parser_omp_depobj): Likewise.
gcc/cp/
* parser.cc (cp_parser_omp_clause_depend): Parse
inoutset depend-kind.
(cp_parser_omp_depobj): Likewise.
* cxx-pretty-print.cc (cxx_pretty_printer::statement): Handle
OMP_CLAUSE_DEPEND_INOUTSET.
gcc/testsuite/
* c-c++-common/gomp/all-memory-1.c (boo): Add test with
inoutset depend-kind.
* c-c++-common/gomp/all-memory-2.c (boo): Likewise.
* c-c++-common/gomp/depobj-1.c (f1): Likewise.
(f2): Adjusted expected diagnostics.
* g++.dg/gomp/depobj-1.C (f4): Adjust expected diagnostics.
include/
* gomp-constants.h (GOMP_DEPEND_INOUTSET): Define.
libgomp/
* libgomp.h (struct gomp_task_depend_entry): Change is_in type
from bool to unsigned char.
* task.c (gomp_task_handle_depend): Handle GOMP_DEPEND_INOUTSET.
Ignore dependencies where
task->depend[i].is_in && task->depend[i].is_in == ent->is_in
rather than just task->depend[i].is_in && ent->is_in.  Remember
whether GOMP_DEPEND_IN loop is needed and guard the loop with that
conditional.
(gomp_task_maybe_wait_for_dependencies): Handle GOMP_DEPEND_INOUTSET.
Ignore dependencies where elem.is_in && elem.is_in == ent->is_in
rather than just elem.is_in && ent->is_in.
* testsuite/libgomp.c-c++-common/depend-1.c (test): Add task with
inoutset depend-kind.
* testsuite/libgomp.c-c++-common/depend-2.c (test): Likewise.
* testsuite/libgomp.c-c++-common/depend-3.c (test): Likewise.
* testsuite/libgomp.c-c++-common/depend-inoutset-1.c: New test.

2 years agolibstdc++: Skip tests that fail for the versioned namespace
Jonathan Wakely [Tue, 17 May 2022 08:32:36 +0000 (09:32 +0100)]
libstdc++: Skip tests that fail for the versioned namespace

Most tests for the contents of header synopses need to be supressed for
the versioned namespace build, because redeclaring the entities in std
fails when they were originally declared in std::__8.

I added these tests recently without the suppression, so they fail.

libstdc++-v3/ChangeLog:

* testsuite/20_util/expected/synopsis.cc: Skip for versioned
namespace.
* testsuite/27_io/headers/iosfwd/synopsis.cc: Likewise.

2 years agolibstdc++: Stop defining C++0x compat symbols for versioned namespace
Jonathan Wakely [Mon, 16 May 2022 15:54:52 +0000 (16:54 +0100)]
libstdc++: Stop defining C++0x compat symbols for versioned namespace

The src/c++11/compatibility*-c++0x.cc files define symbols that need to
be exported for ancient versions of libstdc++.so.6 due to changes
between C++0x and the final C++11 standard. Those symbols are not needed
in the libstdc++.so.8 library, and we can skip building them entirely.

This also fixes the build failure I introduced last week when making the
versioned namespace config not use the _V2 namespace for compat symbols.

libstdc++-v3/ChangeLog:

* src/Makefile.am [ENABLE_SYMVERS_GNU_NAMESPACE] (cxx11_sources):
Do not build the compatibility*-c++0x.cc objects.
* src/Makefile.in: Regenerate.
* src/c++11/compatibility-c++0x.cc [_GLIBCXX_INLINE_VERSION]:
Refuse to build for the versioned namespace.
* src/c++11/compatibility-chrono.cc: Likewise.
* src/c++11/compatibility-condvar.cc: Likewise.
* src/c++11/compatibility-thread-c++0x.cc: Likewise.
* src/c++11/chrono.cc (system_clock, steady_clock):
Use macros to define in inline namespace _V2, matching the
declarations in <system_error>.
* src/c++11/system_error.cc (system_category, generic_category):
Likewise.

2 years agolibgomp.texi: Add OpenMP 5.2 implementation status
Tobias Burnus [Tue, 17 May 2022 10:02:37 +0000 (12:02 +0200)]
libgomp.texi: Add OpenMP 5.2 implementation status

libgomp/
* libgomp.texi (OpenMP Implementation Status): Add 5.2 table.

2 years agoi386: Fix up V2DI and V1TI inequality comparisons [PR105613]
Jakub Jelinek [Tue, 17 May 2022 10:10:30 +0000 (12:10 +0200)]
i386: Fix up V2DI and V1TI inequality comparisons [PR105613]

The recent r13-458 change to introduce vec_cmpeqv1tiv1ti and
add TARGET_SSE2 support to vec_cmpeqv2div2di works nicely for
equality comparisons, but as the testcase shows doesn't work
for inequality comparisons.
For EQ if we perform comparison with twice as many half-sized elemenets,
the result should be ~0 when both halves are ~0 only (both halves need
to be equal for the whole to be equal), otherwise 0, so AND is the
correct operation for it.
But for NE, the result should be ~0 when either of the halves is ~0
(if either half is not equal, the whole is not equal) and so the right
operation for NE is IOR, not AND.

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

PR target/105613
* config/i386/sse.md (vec_cmpeqv2div2di, vec_cmpeqv1tiv1ti): Use
andv4si3 only for EQ, for NE use iorv4si3 instead.

* gcc.c-torture/execute/pr105613.c: New test.

2 years agoOpenMP: Add omp_all_memory support to Fortran
Tobias Burnus [Tue, 17 May 2022 09:01:04 +0000 (11:01 +0200)]
OpenMP: Add omp_all_memory support to Fortran

Fortran part to the C/C++/backend implementation
r13-337-g7f78783dbedca0183d193e475262ca3c489fd365

gcc/fortran/ChangeLog:

* dump-parse-tree.cc (show_omp_namelist): Handle omp_all_memory.
* openmp.cc (gfc_match_omp_variable_list, gfc_match_omp_depend_sink,
gfc_match_omp_clauses, resolve_omp_clauses): Likewise.
* trans-openmp.cc (gfc_trans_omp_clauses, gfc_trans_omp_depobj):
Likewise.
* resolve.cc (resolve_symbol): Reject it as symbol.

libgomp/ChangeLog:

* libgomp.texi (OpenMP 5.1): Set omp_all_memory to 'Y'.
* testsuite/libgomp.fortran/depend-5.f90: New test.
* testsuite/libgomp.fortran/depend-6.f90: New test.
* testsuite/libgomp.fortran/depend-7.f90: New test.

gcc/testsuite/ChangeLog:

* gfortran.dg/gomp/all-memory-1.f90: New test.
* gfortran.dg/gomp/all-memory-2.f90: New test.
* gfortran.dg/gomp/all-memory-3.f90: New test.

2 years agotree-optimization/105618 - restore load sinking
Richard Biener [Tue, 17 May 2022 07:45:02 +0000 (09:45 +0200)]
tree-optimization/105618 - restore load sinking

The PR97330 fix caused some missed sinking of loads out of loops
the following patch re-instantiates.

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

PR tree-optimization/105618
* tree-ssa-sink.cc (statement_sink_location): For virtual
PHI uses ignore those defining the used virtual operand.

* gcc.dg/tree-ssa/ssa-sink-19.c: New testcase.

2 years ago[Ada] Restore defensive guard in checks for volatile actuals
Piotr Trojanek [Wed, 30 Mar 2022 10:00:20 +0000 (12:00 +0200)]
[Ada] Restore defensive guard in checks for volatile actuals

When flagging names of volatile objects occurring in actual parameters
it is safer to guard against identifiers without entity. This is
redundant (because earlier in the resolution of actual parameters we
already guard against actuals with Any_Type), but perhaps such
identifiers will become allowed in constructs like:

   Subprogram_Call
     (Actual =>
        (declare
           X : Boolean := ...
             with Annotate (GNATprove, ...)));
                            ^^^^^^^^^

which include an identifier that does not denote any entity.

Code cleanup related to handling of volatile components; behaviour is
unaffected.

gcc/ada/

* sem_res.adb (Flag_Effectively_Volatile_Objects): Restore
redundant guard.

2 years ago[Ada] Subprogram renaming fails to hide homograph
Gary Dismukes [Mon, 28 Mar 2022 23:15:30 +0000 (19:15 -0400)]
[Ada] Subprogram renaming fails to hide homograph

The compiler failed to detect an error where the first prefix of an
expanded name given as the renamed subprogram in a subprogram renaming
declaration denotes a unit with the same name as the name given for the
subprogram renaming. Such a unit must be hidden by the renaming itself.
An error check is added to catch this case.

gcc/ada/

* sem_ch8.adb (Analyze_Subprogram_Renaming): Add error check for
the case of a renamed subprogram given by an expanded name whose
outermost prefix names a unit that is hidden by the name of the
renaming.
(Ult_Expanded_Prefix): New local expression function to return
the ultimate prefix of an expanded name.

2 years ago[Ada] CUDA: remove code performing kernel registration
Ghjuvan Lacambre [Mon, 28 Mar 2022 14:40:46 +0000 (16:40 +0200)]
[Ada] CUDA: remove code performing kernel registration

A previous commit implemented a new kernel registration scheme, using
the binder to generate registration code rather than inserting
registration code in packages.  Now that this new approach has had time
to be thoroughly tested, it is time to remove the old approach.

gcc/ada/

* gnat_cuda.ads: Update package-level comments.
(Build_And_Insert_CUDA_Initialization): Remove function.
* gnat_cuda.adb (Build_And_Insert_CUDA_Initialization): Remove
function.
(Expand_CUDA_Package): Remove call to
Build_And_Insert_CUDA_Initialization.

2 years ago[Ada] Enhance the warning on C enum with size clause for size /= 32
Etienne Servais [Tue, 15 Feb 2022 16:59:10 +0000 (17:59 +0100)]
[Ada] Enhance the warning on C enum with size clause for size /= 32

Improve the warning message and silence warning when size > 32, this is
likely intentional and does not warrant a warning.

gcc/ada/

* freeze.adb (Freeze_Enumeration_Type): Fix comment, enhance
message and silence warning for size > 32.

2 years ago[Ada] Allow inlining for proof inside generics
Yannick Moy [Fri, 11 Mar 2022 10:19:37 +0000 (11:19 +0100)]
[Ada] Allow inlining for proof inside generics

For local subprograms without contracts inside generics, allow their
inlining for proof in GNATprove mode. This requires forbidding the
inlining of subprograms which contain references to object renamings,
which would be replaced in the SPARK expansion and violate assumptions
of the inlining code.

gcc/ada/

* exp_spark.adb (Expand_SPARK_Potential_Renaming): Deal with no
entity case.
* inline.ads (Check_Object_Renaming_In_GNATprove_Mode): New
procedure.
* inline.adb (Check_Object_Renaming_In_GNATprove_Mode): New
procedure.
(Can_Be_Inlined_In_GNATprove_Mode): Remove case forbidding
inlining for subprograms inside generics.
* sem_ch12.adb (Copy_Generic_Node): Preserve global entities
when inlining in GNATprove mode.
* sem_ch6.adb (Analyse_Subprogram_Body_Helper): Remove body to
inline if renaming is detected in GNATprove mode.

2 years ago[Ada] Provide allocation subtype for allocators of a Designated_Storage_Model type
Gary Dismukes [Fri, 25 Mar 2022 16:56:24 +0000 (12:56 -0400)]
[Ada] Provide allocation subtype for allocators of a Designated_Storage_Model type

When an allocator is for an access type that has a
Designated_Storage_Model aspect, and the designated type is an
unconstrained record type with discriminants, and the subtype associated
with the allocator is constrained, a dereference of the new access value
can be passed to the designated type's initialization procedure. The
post-front-end phase of the compiler needs to be able to create a
temporary object in the host memory space to pass to the init proc,
which requires creating such an object, but the subtype needed for the
allocation isn't readily available at the point of the dereference.  To
make the subtype easily accessible, we set the Actual_Designated_Subtype
of such a dereference to the subtype of the allocated object.

gcc/ada/

* exp_ch4.adb (Expand_N_Allocator): For an allocator with an
unconstrained discriminated designated type, and whose
allocation subtype is constrained, set the
Actual_Designated_Subtype of the dereference passed to the init
proc of the designated type to be the allocation subtype.
* sinfo.ads: Add documentation of new setting of
Actual_Designated_Subtype on a dereference used as an actual
parameter of call to an init proc associated with an allocator.
Also add missing syntax and documentation for the GNAT language
extension that allows an expression as a default for a concrete
generic formal function.

2 years ago[Ada] Cleanups related to front-end SJLJ
Bob Duff [Fri, 25 Mar 2022 14:23:08 +0000 (10:23 -0400)]
[Ada] Cleanups related to front-end SJLJ

This patch cleans up some code that is left over from the front-end SJLJ
exception handling mechanism, which has been removed.
This is in preparation for fixing a finalization-related bug.

Most importantly:

    The documentation is changed: a Handled_Sequence_Of_Statements node
    CAN contain both Exception_Handlers and an At_End_Proc.

    The assertion contradicting that is removed from
    Expand_At_End_Handler.

    The From_At_End field is removed.

gcc/ada/

* sinfo.ads: Remove From_At_End.  Update comments.
* gen_il-fields.ads, gen_il-gen-gen_nodes.adb, sem_ch11.adb:
Remove From_At_End.
* exp_ch11.adb (Expand_At_End_Handler): Remove assertion.
* fe.h (Exception_Mechanism, Exception_Mechanism_Type, Has_DIC,
Has_Invariants, Is_List_Member, List_Containing): Remove
declarations that are not used in gigi.
* opt.ads (Exception_Mechanism): This is not used in gigi.
* exp_util.ads: Minor comment fix.

2 years ago[Ada] GNAT.Binary_Search is not internal
Dmitriy Anisimkov [Thu, 24 Mar 2022 06:49:56 +0000 (12:49 +0600)]
[Ada] GNAT.Binary_Search is not internal

Put package GNAT.Binary_Search to predefined units list.

gcc/ada/

* impunit.adb: Add "g-binsea" to Non_Imp_File_Names_95 list.

2 years ago[Ada] Fix insertion of declaration inside quantified expression
Yannick Moy [Fri, 18 Mar 2022 16:33:25 +0000 (17:33 +0100)]
[Ada] Fix insertion of declaration inside quantified expression

When the evaluation of the subtype_indication for the
iterator_specification of a quantified_expression leads to the insertion
of a type declaration, this should be done with Insert_Action instead of
Insert_Before.

gcc/ada/

* sem_ch5.adb (Analyze_Iterator_Specification): Use
Insert_Action when possibly inside an expression.

2 years ago[Ada] Fix Forced sign flag in formatted string
Marc Poulhiès [Tue, 22 Mar 2022 09:08:46 +0000 (10:08 +0100)]
[Ada] Fix Forced sign flag in formatted string

Fix the Forced sign flag that is incorrectly ignored for scientific
notation and shortest representation.

gcc/ada/

* libgnat/g-forstr.adb (Is_Number): Add scientific notation and
shortest representation.

2 years ago[Ada] Fix small glitch in Expand_N_Full_Type_Declaration
Eric Botcazou [Wed, 23 Mar 2022 22:47:06 +0000 (23:47 +0100)]
[Ada] Fix small glitch in Expand_N_Full_Type_Declaration

The original node is not guaranteed to also be an
N_Full_Type_Declaration, so the code needs to look into the node itself.

gcc/ada/

* exp_ch3.adb (Expand_N_Full_Type_Declaration): Look into N.

2 years ago[Ada] Requires_Cleanup_Actions and N_Protected_Body
Bob Duff [Wed, 23 Mar 2022 18:04:22 +0000 (14:04 -0400)]
[Ada] Requires_Cleanup_Actions and N_Protected_Body

This patch disallows N_Protected_Body from being passed to
Requires_Cleanup_Actions. Protected bodies never need cleanup, and are
never passed to Requires_Cleanup_Actions, which is a good thing, because
it would blow up on Handled_Statement_Sequence, which doesn't exist for
N_Protected_Body.

gcc/ada/

* exp_util.adb (Requires_Cleanup_Actions): Remove
N_Protected_Body from the case statement, so that case will be
covered by "raise Program_Error".

2 years ago[Ada] Output.w always writes to stderr
Bob Duff [Wed, 23 Mar 2022 14:27:44 +0000 (10:27 -0400)]
[Ada] Output.w always writes to stderr

There are several debugging procedures called Output.w, and some
output-redirection features. This patch modifies Output.w so their
output is not redirected; it always goes to standard error. Otherwise,
debugging output can get mixed in with some "real" output (perhaps to a
file), which causes confusion and in some cases failure to build.

gcc/ada/

* output.adb (Pop_Output, Set_Output): Unconditionally flush
output when switching from one output destination to another.
Otherwise buffering can cause garbled output.
(w): Push/pop the current settings, and temporarily
Set_Standard_Error during these procedures.

2 years ago[Ada] Generic binary search implementation
Dmitriy Anisimkov [Wed, 9 Mar 2022 04:31:48 +0000 (10:31 +0600)]
[Ada] Generic binary search implementation

Allows binary search in sorted anonymous array (or array-like
container).

gcc/ada/

* libgnat/g-binsea.ads, libgnat/g-binsea.adb
(GNAT.Binary_Search): New package.
* Makefile.rtl (GNATRTL_NONTASKING_OBJS): New item in list.
* doc/gnat_rm/the_gnat_library.rst (GNAT.Binary_Search): New
package record.
* gnat_rm.texi: Regenerate.

2 years ago[Ada] Fix bogus visibility error with partially parameterized formal package
Eric Botcazou [Thu, 17 Mar 2022 18:05:10 +0000 (19:05 +0100)]
[Ada] Fix bogus visibility error with partially parameterized formal package

The problem comes from the special instantiation (abbreviated instantiation
in GNAT parlance) done to check conformance between a formal package and its
corresponding actual in a generic instantiation: the compiler instantiates
the formal package, in the context of the generic instantiation, so that it
can check the conformance of the actual with the result.

More precisely, it occurs with formal packages that are only partially
parameterized, i.e. that have at least one parameter association and an
(others => <>) choice. In this case, RM 12.7(10/2) says that the visible
part of the formal package contains a copy of the formal parameters that
are not explicitly associated.

The analysis of these copies for the abbreviated instantiation is not done
in the correct context when the generic unit is a child generic unit.

gcc/ada/

* sem_ch12.ads (Is_Abbreviated_Instance): Declare.
* sem_ch12.adb (Check_Abbreviated_Instance): Declare.
(Requires_Conformance_Checking): Declare.
(Analyze_Association.Process_Default): Fix subtype of parameter.
(Analyze_Formal_Object_Declaration): Check whether it is in the
visible part of abbreviated instance.
(Analyze_Formal_Subprogram_Declaration): Likewise.
(Analyze_Formal_Type_Declaration): Likewise.
(Analyze_Package_Instantiation): Do not check for a generic child
unit in the case of an abbreviated instance.
(Check_Abbreviated_Instance): New procedure.
(Check_Formal_Packages): Tidy up.
(Copy_Generic_Elist): Fix comment.
(Instantiate_Formal_Package): Tidy up.  If the generic unit is a
child unit, copy the qualified name onto the abbreviated instance.
(Is_Abbreviated_Instance): New function.
(Collect_Previous_Instances): Call Is_Abbreviated_Instance.
(Requires_Conformance_Checking): New function.
* sem_ch7.adb (Analyze_Package_Specification): Do not install the
private declarations of the parent for an abbreviated instance.

2 years ago[Ada] Take full view of private type
Etienne Servais [Mon, 21 Feb 2022 15:32:46 +0000 (16:32 +0100)]
[Ada] Take full view of private type

This allows to resolve the following:

      type Rec (<>) is private;
      type Arr (<>) is private;
   private
      type Arr is array (Positive range <>) of Natural;
      type Rec (L : Natural) is record
         F1 : Integer;
         F2 : Arr (1 .. L);
      end record;

gcc/ada/

* sem_ch3.adb (Analyze_Subtype_Declaration): Use underlying type
of Indic_Typ.
(Constrain_Array): Ditto for T.

2 years ago[Ada] Allow 'Reduce with -gnat2022
Arnaud Charlet [Sun, 20 Mar 2022 09:12:32 +0000 (09:12 +0000)]
[Ada] Allow 'Reduce with -gnat2022

After a period of experimentation, allow 'Reduce in Ada 2022 mode.

gcc/ada/

* sem_attr.adb (Analyze_Attribute [Attribute_Reduce]): Allow
'Reduce for Ada 2022 and above.
* sem_attr.ads (Attribute_Impl_Def): 'Reduce is no longer
implementation defined.

2 years ago[Ada] Don't create calls to Abort_Undefer when not Abort_Allowed
Ghjuvan Lacambre [Tue, 15 Mar 2022 09:57:45 +0000 (10:57 +0100)]
[Ada] Don't create calls to Abort_Undefer when not Abort_Allowed

Prevent creation of references to Abort_Undefer when aborts aren't
allowed. Another solution could have been an early return at
Expand_N_Asynchronous_Select's beginning, but this would break backends
that currently expect trees that do not contain any
N_Asynchronous_Selects in their AST (e.g. CodePeer).

gcc/ada/

* exp_ch9.adb (Expand_N_Asynchronous_Select): Don't generate
Abort_Undefers when not Abort_Allowed.

2 years ago[Ada] Typo fix in finalization comment
Marc Poulhiès [Fri, 18 Mar 2022 15:11:41 +0000 (16:11 +0100)]
[Ada] Typo fix in finalization comment

Add missing 's' and reformat the comment block.

gcc/ada/

* exp_ch7.adb: Fix typo.

2 years ago[Ada] Initialize Compiler_State to avoid Constraint_Error
Etienne Servais [Tue, 26 Oct 2021 15:00:24 +0000 (17:00 +0200)]
[Ada] Initialize Compiler_State to avoid Constraint_Error

When building gnat1 with `-gnatVa` as we do locally, rules like: `gcc -c
-gnatyM79 <any adb file with lines longer than 79>` will throw a
constraint error as `lib.compiler_state` is initialized by par.adb, ie
after scanning. Therefore any error_msg thrown during scanning will
perform this uninitialized read (which raises a Constraint_Error when
the compiler was compiled with `-gnatVa`).

Initialize this flag to `Parsing`.

gcc/ada/

* lib.ads: initialize `Compiler_State` to `Parsing`.

2 years ago[Ada] Deal with derived record types in Has_Compatible_Representation
Eric Botcazou [Mon, 21 Mar 2022 07:35:53 +0000 (08:35 +0100)]
[Ada] Deal with derived record types in Has_Compatible_Representation

More precisely, untagged record types, as tagged record types are already
handled by the predicate.  If the derived type has not been given its own
representation clause, then the representations are the same.

gcc/ada/

* sem_ch13.adb (Has_Compatible_Representation): Return true for
derived untagged record types without representation clause.

2 years ago[Ada] Streamline implementation of Has_Compatible_Representation
Eric Botcazou [Sun, 20 Mar 2022 17:01:04 +0000 (18:01 +0100)]
[Ada] Streamline implementation of Has_Compatible_Representation

The predicate is only concerned with the internal representation of types
and this representation is shared by the subtypes of a given type, so the
implementation can directly look into the (implementation) base types.

No functional changes.

gcc/ada/

* sem_ch13.ads (Has_Compatible_Representation): Minor tweaks.
* sem_ch13.adb (Has_Compatible_Representation): Look directly into
the (implementation) base types and simplifiy accordingly.
* exp_ch5.adb (Change_Of_Representation): Adjust.
* exp_ch6.adb (Expand_Actuals): Likewise.