platform/upstream/gcc.git
23 months agoc++: Tweaks for -Wredundant-move [PR107363]
Marek Polacek [Fri, 28 Oct 2022 17:39:40 +0000 (13:39 -0400)]
c++: Tweaks for -Wredundant-move [PR107363]

Two things here:

1) when we're pointing out that std::move on a constant object is
   redundant, don't say "in return statement" when we aren't in a
   return statement;
2) suppress the warning when the std::move call was dependent, because
   removing the std::move may not be correct for a different
   instantiation of the original template.

PR c++/107363

gcc/cp/ChangeLog:

* semantics.cc (finish_call_expr): Suppress OPT_Wpessimizing_move.
* typeck.cc (maybe_warn_pessimizing_move): Check warn_redundant_move
and warning_suppressed_p.  Adjust a message depending on return_p.
(check_return_expr): Don't suppress OPT_Wpessimizing_move here.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/Wredundant-move13.C: New test.

23 months agoFix incorrect insn type to avoid ICE in memory attr auto-detection.
liuhongt [Mon, 7 Nov 2022 01:55:25 +0000 (09:55 +0800)]
Fix incorrect insn type to avoid ICE in memory attr auto-detection.

Memory attribute auto detection will check operand 2 for type sselog,
and check operand 1 for type sselog1. For below 2 insns, there's no
operand 2. Change type to sselog1.

gcc/ChangeLog:

PR target/107540
* config/i386/sse.md (avx512f_movddup512<mask_name>): Change
type from sselog to sselog1.
(avx_movddup256<mask_name>): Ditto.

gcc/testsuite/ChangeLog:

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

23 months agoDaily bump.
GCC Administrator [Wed, 9 Nov 2022 00:19:55 +0000 (00:19 +0000)]
Daily bump.

23 months agoanalyzer: eliminate region_model::eval_condition_without_cm [PR101962]
David Malcolm [Tue, 8 Nov 2022 22:49:07 +0000 (17:49 -0500)]
analyzer: eliminate region_model::eval_condition_without_cm [PR101962]

In r12-3094-ge82e0f149b0aba I added the assumption that
POINTER_PLUS_EXPR of non-NULL is non-NULL (for PR analyzer/101962).

Whilst working on another bug, I noticed that this only works
when the LHS is known to be non-NULL via
region_model::eval_condition_without_cm, but not when it's known through
a constraint.

This distinction predates the original commit of the analyzer in GCC 10,
but I believe it became irrelevant in the GCC 11 rewrite of the region
model code (r11-2694-g808f4dfeb3a95f).

Hence this patch eliminates region_model::eval_condition_without_cm in
favor of all users simply calling region_model::eval_condition.  Doing
so enables the "POINTER_PLUS_EXPR of non-NULL is non-NULL" assumption to
also be made when the LHS is known through a constraint (e.g. a
conditional).

gcc/analyzer/ChangeLog:
PR analyzer/101962
* region-model-impl-calls.cc: Update comment.
* region-model.cc (region_model::check_symbolic_bounds): Fix
layout of "void" return.  Replace usage of
eval_condition_without_cm with eval_condition.
(region_model::eval_condition): Take over body of...
(region_model::eval_condition_without_cm): ...this subroutine,
dropping the latter.  Eliminating this distinction avoids issues
where constraints were not considered when recursing.
(region_model::compare_initial_and_pointer): Update comment.
(region_model::symbolic_greater_than): Replace usage of
eval_condition_without_cm with eval_condition.
* region-model.h
(region_model::eval_condition_without_cm): Delete decl.

gcc/testsuite/ChangeLog:
PR analyzer/101962
* gcc.dg/analyzer/data-model-23.c (test_3): New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
23 months agolibstdc++: Fix -Wsystem-headers warnings in tests
Jonathan Wakely [Mon, 7 Nov 2022 15:00:34 +0000 (15:00 +0000)]
libstdc++: Fix -Wsystem-headers warnings in tests

libstdc++-v3/ChangeLog:

* testsuite/18_support/new_nothrow.cc: Add missing noexcept
to operator delete replacements.
* testsuite/20_util/any/cons/92156.cc: Disable
-Winit-list-lifetime warnings from instantiating invalid
specialization of manager function.
* testsuite/20_util/any/modifiers/92156.cc: Likewise.
* testsuite/20_util/default_delete/void_neg.cc: Prune additional
diagnostics.
* testsuite/20_util/headers/memory/synopsis.cc: Add missing
noexcept.
* testsuite/20_util/shared_ptr/cons/void_neg.cc: Prune
additional diagnostic.
* testsuite/20_util/unique_ptr/creation/for_overwrite.cc: Add
missing noexcept to operator delete replacements.
* testsuite/21_strings/basic_string/cons/char/103919.cc:
Likewise.
* testsuite/23_containers/map/modifiers/emplace/92300.cc:
Likewise.
* testsuite/23_containers/map/modifiers/insert/92300.cc:
Likewise.
* testsuite/24_iterators/headers/iterator/range_access_c++11.cc:
Add missing noexcept to synopsis declarations.
* testsuite/24_iterators/headers/iterator/range_access_c++14.cc:
Likewise.
* testsuite/24_iterators/headers/iterator/range_access_c++17.cc:
Likewise.

23 months agolibstdc++: Fix -Wsystem-headers warnings
Jonathan Wakely [Sat, 5 Nov 2022 12:35:55 +0000 (12:35 +0000)]
libstdc++: Fix -Wsystem-headers warnings

Fix some problems noticed with -Wsystem-headers.

libstdc++-v3/ChangeLog:

* include/bits/stl_tempbuf.h (_Temporary_buffer): Disable
warnings about get_temporary_buffer being deprecated.
* include/ext/functional (mem_fun1, mem_fun1_ref): Disable
warnings about mem_fun1_t, const_mem_fun1_t, mem_fun1_ref_t and
const_mem_fun1_ref_t being deprecated.
* include/std/array (__array_traits<T, 0>): Remove artificial
attributes which give warnings about being ignored.
* include/std/spanstream (basic_spanbuf::setbuf): Add assertion
and adjust to avoid narrowing warning.
* libsupc++/exception_ptr.h [!__cpp_rtti && !__cpp_exceptions]
(make_exception_ptr): Add missing inline specifier.

23 months agolibstdc++: Add always_inline to most allocator functions
Jonathan Wakely [Fri, 16 Sep 2022 15:30:02 +0000 (16:30 +0100)]
libstdc++: Add always_inline to most allocator functions

This reduces the abstraction penalty for allocator support in
unoptimized code. Constructing and using allocators in containers calls
many one-line (or completely empty) inline functions. Those can all be
inlined to reduce code size and function call overhead for -O0.

libstdc++-v3/ChangeLog:

* include/bits/alloc_traits.h (allocator_traits): Add
always_inline attribute to all member functions.
(__do_alloc_on_copy, __alloc_on_copy, __do_alloc_on_move)
(__alloc_on_move, __do_alloc_on_swap, __alloc_on_swap)
(_Destroy(FwdIter, FwdIter, allocator<T>&)): : Add
always_inline attribute.
* include/bits/allocator.h (allocator): Add always_inline
attribute to all member functions and equality operators.
* include/bits/new_allocator.h (__new_allocator): Likewise.
* include/ext/alloc_traits.h (__gnu_cxx::__alloc_traits):
Likewise.

23 months agolibstdc++: basic_filebuf: don't flush more often than necessary [PR63746]
Charles-François Natali [Thu, 6 Oct 2022 19:02:56 +0000 (20:02 +0100)]
libstdc++: basic_filebuf: don't flush more often than necessary [PR63746]

`basic_filebuf::xsputn` would bypass the buffer when passed a chunk of
size 1024 and above, seemingly as an optimisation.

This can have a significant performance impact if the overhead of a
`write` syscall is non-negligible, e.g. on a slow disk, on network
filesystems, or simply during IO contention because instead of flushing
every `BUFSIZ` (by default), we can flush every 1024 char.
The impact is even greater with custom larger buffers, e.g. for network
filesystems, because the code could issue `write` for example 1000X more
often than necessary with respect to the buffer size.
It also introduces a significant discontinuity in performance when
writing chunks of size 1024 and above.

Instead, it makes sense to only bypass the buffer if the amount of data
to be written is larger than the buffer capacity.

Signed-off-by: Charles-Francois Natali <cf.natali@gmail.com>
libstdc++-v3/ChangeLog:

PR libstdc++/63746
* include/bits/fstream.tcc (basic_filbuf::xsputn): Remove
1024-byte chunking that bypasses the buffer for large writes.
* testsuite/27_io/basic_filebuf/sputn/char/63746.cc: New test.

23 months agolibstdc++: Refactor implementation of operator+ for std::string
Will Hawkins [Thu, 20 Oct 2022 00:05:59 +0000 (20:05 -0400)]
libstdc++: Refactor implementation of operator+ for std::string

Until now operator+(char*, string) and operator+(string, char*) had
different performance characteristics. The former required a single
memory allocation and the latter required two. This patch makes the
performance equal.

After consultation with Jonathan, it seemed like a good idea to create a
single function that performed one-allocation string concatenation that
could be used by various different version of operator+. This patch adds
such a function and calls it from the relevant implementations.

Co-authored-by: Jonathan Wakely <jwakely@redhat.com>
libstdc++-v3/ChangeLog:

* include/bits/basic_string.h (__str_cat): Add common function
that performs single-allocation string concatenation.
(operator+): Use __str_cat.
* include/bits/basic_string.tcc (operator+): Move to .h and
define inline using __str_cat.

Signed-off-by: Will Hawkins <whh8b@obs.cr>
23 months agobpf: Use enum for resolved overloaded builtins
David Faust [Mon, 7 Nov 2022 18:40:01 +0000 (10:40 -0800)]
bpf: Use enum for resolved overloaded builtins

Change several places in the eBPF backend dealing with overloaded
built-in functions to consistently use the enum bpf_builtins type,
rather than variously using integer constants or booleans. The result is
eaiser to read and extend.

gcc/

* config/bpf/bpf.cc (struct core_walk_data): Add field `which'...
(bpf_resolve_overloaded_builtin): ... set it here. Use values of enum
bpf_builtins for error checks.
(bpf_core_walk): Use values of enum bpf_builtins.
(bpf_core_newdecl): Likewise.
(bpf_expand_builtin): Likewise.

23 months ago[PR24021] Implement PLUS_EXPR range-op entry for floats.
Aldy Hernandez [Thu, 13 Oct 2022 06:14:16 +0000 (08:14 +0200)]
[PR24021] Implement PLUS_EXPR range-op entry for floats.

This is the range-op entry for floating point PLUS_EXPR.  It's the
most intricate range entry we have so far, because we need to keep
track of rounding and target FP formats.  This will be the last FP
entry I commit, mostly to avoid disturbing the tree any further, and
also because what we have so far is enough for a solid VRP.

So far we track NANs and signs correctly.  We also handle relationals
(symbolics and numeric), both ordered and unordered, ABS_EXPR and
NEGATE_EXPR which are used to fold __builtin_isinf, and __builtin_sign
(__builtin_copysign is coming up).  All in all, I think this provide
more than enough for basic VRP on floats, as well as provide a basis
to flesh out the rest if there's interest.

My goal with this entry is to provide a template for additional binary
operators, as they tend to follow a similar pattern: handle NANs, do
the arithmetic while keeping track of rounding, and adjust for NAN.  I
may abstract the general parts as we do for irange's fold_range and
wi_fold.

PR tree-optimization/24021

gcc/ChangeLog:

* range-op-float.cc (propagate_nans): New.
(frange_nextafter): New.
(frange_arithmetic): New.
(class foperator_plus): New.
(floating_op_table::floating_op_table): Add PLUS_EXPR entry.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/vrp-float-plus.c: New test.

23 months agoProvide normalized and denormal format version of real_isdenormal.
Aldy Hernandez [Mon, 7 Nov 2022 13:18:57 +0000 (14:18 +0100)]
Provide normalized and denormal format version of real_isdenormal.

Implement a variant of real_isdenormal() to be used within real.cc
where the argument is known to be in denormal format.  Rewrite
real_isdenormal() for use outside of real.cc where the argument is
known to be normalized.

gcc/ChangeLog:

* real.cc (real_isdenormal): New.
(encode_ieee_single): Call real_isdenormal.
(encode_ieee_double): Same.
(encode_ieee_extended): Same.
(encode_ieee_quad): Same.
(encode_ieee_half): Same.
(encode_arm_bfloat_half): Same.
* real.h (real_isdenormal): Add mode argument.  Rewrite for
normalized values.
* value-range.cc (frange::flush_denormals_to_zero): Pass mode to
real_isdenormal.

23 months agotree-optimization/107389 - honor __builtin_assume_alignment at -O0
Richard Biener [Tue, 8 Nov 2022 12:49:16 +0000 (13:49 +0100)]
tree-optimization/107389 - honor __builtin_assume_alignment at -O0

The following makes sure to set alignment information on the LHS
of __builtin_assume_alignment calls even when not optimizing so
uses as arguments to builtin functions like memcpy or __atomic_load_n
can be reflected at RTL expansion time.

PR tree-optimization/107389
* gimple-low.cc (lower_builtin_assume_aligned): New.
(lower_stmt): Call it.

* gcc.dg/pr107389.c: New testcase.

23 months agoCCP: handle division by a power of 2 as a right shift.
Aldy Hernandez [Sun, 6 Nov 2022 19:38:42 +0000 (20:38 +0100)]
CCP: handle division by a power of 2 as a right shift.

We have some code in range-ops that sets better maybe nonzero bits for
TRUNC_DIV_EXPR by a power of 2 than CCP does, by just shifting the
mask.  I'd like to offload this functionality into the CCP mask
tracking code, which already does the right thing for right shifts.

The testcase for this change is gcc.dg/tree-ssa/vrp123.c and
gcc.dg/tree-ssa/pr107541.c.

gcc/ChangeLog:

* range-op.cc (operator_div::fold_range): Call
update_known_bitmask.
* tree-ssa-ccp.cc (bit_value_binop): Handle divisions by powers of
2 as a right shift.

23 months agoamdgcn: Fix expansion of GCN_BUILTIN_LDEXPV builtin
Kwok Cheung Yeung [Tue, 8 Nov 2022 14:38:23 +0000 (14:38 +0000)]
amdgcn: Fix expansion of GCN_BUILTIN_LDEXPV builtin

2022-11-08  Kwok Cheung Yeung  <kcy@codesourcery.com>

gcc/
* config/gcn/gcn.cc (gcn_expand_builtin_1): Expand first argument
of GCN_BUILTIN_LDEXPV to V64DFmode.

23 months agoamdgcn: Add builtins for vectorized native versions of abs, floorf and floor
Kwok Cheung Yeung [Tue, 8 Nov 2022 11:59:58 +0000 (11:59 +0000)]
amdgcn: Add builtins for vectorized native versions of abs, floorf and floor

2022-11-08  Kwok Cheung Yeung  <kcy@codesourcery.com>

gcc/
* config/gcn/gcn-builtins.def (FABSV, FLOORVF, FLOORV): New builtins.
* config/gcn/gcn.cc (gcn_expand_builtin_1): Expand GCN_BUILTIN_FABSV,
GCN_BUILTIN_FLOORVF and GCN_BUILTIN_FLOORV.

gcc/testsuite/
* gcc.target/gcn/math-builtins-1.c: New test.

23 months agoUse bit-CCP in range-ops.
Aldy Hernandez [Sun, 6 Nov 2022 12:05:39 +0000 (13:05 +0100)]
Use bit-CCP in range-ops.

After Jakub and Richi's suggestion of using the same representation
for tracking known bits as we do in CCP, I took a peek at the code and
realized there's a plethora of bit-tracking code there that we could
be sharing with range-ops.  For example, the multiplication
optimizations are way better than what I had cobbled together.  For
that matter, our maybe nonzero tracking as a whole has a lot of room
for improvement.  Being the lazy ass that I am, I think we should just
use one code base (CCP's).

This patch provides a thin wrapper for converting the irange maybe
nonzero bits to what CCP requires, and uses that to call into
bit_value_binop().  I have so far converted the MULT_EXPR range-op
entry to use it, as the DIV_EXPR entry we have gets a case CCP doesn't
get so I'd like to contribute the enhancement to CCP before converting
over.

I'd like to use this approach with the dozen or so tree_code's that
are handled in CCP, thus saving us from having to implement any of
them :).

Early next season I'd like to change irange's internal representation
to a pair of value / mask, and start tracking all known bits.  This
ties in nicely with our plan for tracking known set bits.

Perhaps if the stars align, we could merge the bit twiddling in CCP
into range-ops and have a central repository for it.  That is, once we
make the switch to wide-ints, and assuming there are no performance
issues.  Note that range-ops is our lowest level abstraction.
i.e. it's just the math, there's no GORI or ranger, or even the
concept of a symbolic or SSA.

gcc/ChangeLog:

* range-op.cc (irange_to_masked_value): New.
(update_known_bitmask): New.
(operator_mult::fold_range): Call update_known_bitmask.

23 months agotestsuite: Fix failure in test pr105586.c [PR107171]
Surya Kumari Jangala [Thu, 13 Oct 2022 14:18:15 +0000 (09:18 -0500)]
testsuite: Fix failure in test pr105586.c [PR107171]

The test pr105586.c fails on a big endian system when run in 32bit
mode. The failure occurs as the test case does not guard against
unsupported __int128.

2022-10-13  Surya Kumari Jangala  <jskumari@linux.ibm.com>

gcc/testsuite/
PR testsuite/107171
* gcc.target/powerpc/pr105586.c: Guard against unsupported
__int128.

23 months agocdce: Fix up get_no_error_domain for new f{16,32,64,128} builtins [PR107547]
Jakub Jelinek [Tue, 8 Nov 2022 12:24:02 +0000 (13:24 +0100)]
cdce: Fix up get_no_error_domain for new f{16,32,64,128} builtins [PR107547]

I've missed that this function needs to handle all the builtins that
are handled in can_test_argument_range.
The following patch does that.  For many of the builtins (like acos, or
log) it is the same range regardless of the floating point type, but for
some (cosh, sinh, exp{,m1,2}) it is different for each format,
so I had to compute those ranges.

Note, seems the existing ranges were in some cases (e.g. for exp2)
the smallest in absolute value which results infinite result, in others
the largest which still results in finite result (but consistently so
for the IEEE single vs. double).  I've followed that for IEEE half and
quad cases too, just am not sure why it was like that.  I think
get_domain with true, false is open interval rather than closed
and the comments indicate that too, conservatively that is certainly
correct.

OT, with frange, perhaps we could DCE the calls unconditionally if
frange can prove we are in the domain range.

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

PR tree-optimization/107547
* tree-call-cdce.cc (get_no_error_domain): Handle CASE_FLT_FN_FLOATN_NX
of BUILT_IN_{ACOS,ASIN,ACOSH,ATANH,LOG,LOG2,LOG10,LOG1P}.  Handle
BUILT_IN_{COSH,SINH,EXP,EXPM1,EXP2}F{16,32,64,128}.

* gcc.dg/pr107547.c: New test.

23 months agoi386: Improve vector [GL]E{,U} comparison against vector constants [PR107546]
Jakub Jelinek [Tue, 8 Nov 2022 11:21:55 +0000 (12:21 +0100)]
i386: Improve vector [GL]E{,U} comparison against vector constants [PR107546]

For integer vector comparisons without XOP before AVX512{F,VL} we are
constrained by only GT and EQ being supported in HW.
For GTU we play tricks to implement it using GT or unsigned saturating
subtraction, for LT/LTU we swap the operands and thus turn it into
GT/GTU.  For LE/LEU we handle it by using GT/GTU and negating the
result and for GE/GEU by using GT/GTU on swapped operands and negating
the result.
If the second operand is a CONST_VECTOR, we can usually do better though,
we can avoid the negation.  For LE/LEU cst by doing LT/LTU cst+1 (and
then cst+1 GT/GTU x) and for GE/GEU cst by doing GT/GTU cst-1, provided
there is no wrap-around on those cst+1 or cst-1.
GIMPLE canonicalizes x < cst to x <= cst-1 etc. (the rule is smaller
absolute value on constant), but only for scalars or uniform vectors,
so in some cases this undoes that canonicalization in order to avoid
the extra negation, but it handles also non-uniform constants.
E.g. with -mavx2 the testcase assembly difference is:
-       movl    $47, %eax
+       movl    $48, %eax
        vmovdqa %xmm0, %xmm1
        vmovd   %eax, %xmm0
        vpbroadcastb    %xmm0, %xmm0
-       vpminsb %xmm0, %xmm1, %xmm0
-       vpcmpeqb        %xmm1, %xmm0, %xmm0
+       vpcmpgtb        %xmm1, %xmm0, %xmm0
and
-       vmovdqa %xmm0, %xmm1
-       vmovdqa .LC1(%rip), %xmm0
-       vpminsb %xmm1, %xmm0, %xmm1
-       vpcmpeqb        %xmm1, %xmm0, %xmm0
+       vpcmpgtb        .LC1(%rip), %xmm0, %xmm0
while with just SSE2:
-       pcmpgtb .LC0(%rip), %xmm0
-       pxor    %xmm1, %xmm1
-       pcmpeqb %xmm1, %xmm0
+       movdqa  %xmm0, %xmm1
+       movdqa  .LC0(%rip), %xmm0
+       pcmpgtb %xmm1, %xmm0
and
-       movdqa  %xmm0, %xmm1
-       movdqa  .LC1(%rip), %xmm0
-       pcmpgtb %xmm1, %xmm0
-       pxor    %xmm1, %xmm1
-       pcmpeqb %xmm1, %xmm0
+       pcmpgtb .LC1(%rip), %xmm0

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

PR target/107546
* config/i386/predicates.md (vector_or_const_vector_operand): New
predicate.
* config/i386/sse.md (vec_cmp<mode><sseintvecmodelower>,
vec_cmpv2div2di, vec_cmpu<mode><sseintvecmodelower>,
vec_cmpuv2div2di): Use nonimmediate_or_const_vector_operand
predicate instead of nonimmediate_operand and
vector_or_const_vector_operand instead of vector_operand.
* config/i386/i386-expand.cc (ix86_expand_int_sse_cmp): For
LE/LEU or GE/GEU with CONST_VECTOR cop1 try to transform those
into LE/LEU or GT/GTU with larger or smaller by one cop1 if
there is no wrap-around.  Force CONST_VECTOR cop0 or cop1 into
REG.  Formatting fix.

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

23 months agolibstdc++: Uncomment denorm_min test
Jakub Jelinek [Tue, 8 Nov 2022 10:19:25 +0000 (11:19 +0100)]
libstdc++: Uncomment denorm_min test

As r13-3609-g6d9dbdf51f9afe8 has been committed, we can now enable
even the denorm_min test.

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

* testsuite/20_util/to_chars/float128_c++23.cc (test): Uncomment
denorm_min test.

23 months agogcc: fix PR rtl-optimization/107482
Max Filippov [Mon, 7 Nov 2022 21:58:49 +0000 (13:58 -0800)]
gcc: fix PR rtl-optimization/107482

gcc/
PR rtl-optimization/107482
* ira-color.cc (assign_hard_reg): Only call
update_costs_from_copies when retry_p is false.

23 months agoada: Fix oversight in implementation of allocators for storage models
Eric Botcazou [Tue, 18 Oct 2022 09:32:02 +0000 (11:32 +0200)]
ada: Fix oversight in implementation of allocators for storage models

When the allocator is of an unconstrained array type and has an initializing
expression, the copy of the initializing expression must be done separately
from that of the bounds.

gcc/ada/

* gcc-interface/utils2.cc (build_allocator): For unconstrained
array types with a storage model and an initializing expression,
copy the initialization expression separately from the bounds. In
all cases with a storage model, pass the locally computed size for
the store.

23 months agoada: Compile-time simplification of 'Image incorrectly ignores Put_Image
Steve Baird [Tue, 25 Oct 2022 23:59:29 +0000 (16:59 -0700)]
ada: Compile-time simplification of 'Image incorrectly ignores Put_Image

In the case of Some_Enumeration_Type'Image (<some static value>),
the compiler will replace this expression in its internal program
representation with a corresponding string literal. This is incorrect
if the Put_Image aspect has been specified (directly or via inheritance)
for the enumeration type.

gcc/ada/

* sem_attr.adb
(Eval_Attribute): Don't simplify 'Image call if Put_Image has been
specified.

23 months agoada: Clean up call to check if aspects are present
Piotr Trojanek [Wed, 26 Oct 2022 07:58:47 +0000 (09:58 +0200)]
ada: Clean up call to check if aspects are present

Code cleanup; semantics is unaffected.

gcc/ada/

* exp_ch6.adb, exp_put_image.adb, sem_aggr.adb, sem_attr.adb,
sem_ch5.adb, sem_type.adb, sem_util.adb: Replace
"Present (Find_Aspect (...))" with "Has_Aspect".

23 months agoada: Adjust classwide contract expression preanalysis
Ronan Desplanques [Mon, 24 Oct 2022 09:50:06 +0000 (11:50 +0200)]
ada: Adjust classwide contract expression preanalysis

Before this patch, a classwide contract expression was preanalyzed
only when its primitive operation's type was frozen. It caused name
resolution to be off in the cases where the freezing took place
after the end of the declaration list the primitive operation was
declared in.

This patch makes it so that if the compiler gets to the end of
the declaration list before the type is frozen, it preanalyzes the
classwide contract expression, so that the names are resolved in the
right context.

gcc/ada/

* contracts.adb
(Preanalyze_Class_Conditions): New procedure.
(Preanalyze_Condition): Moved out from Merge_Class_Conditions in
order to be spec-visible.
* contracts.ads
(Preanalyze_Class_Conditions): New procedure.
* sem_prag.adb
(Analyze_Pre_Post_Condition_In_Decl_Part): Call
Preanalyze_Class_Conditions when necessary.

23 months agoada: Set Support_Atomic_Primitives for VxWorks 7 runtimes
Johannes Kliemann [Fri, 21 Oct 2022 13:21:04 +0000 (13:21 +0000)]
ada: Set Support_Atomic_Primitives for VxWorks 7 runtimes

gcc/ada/

* libgnat/system-vxworks7-aarch64-rtp-smp.ads: Set
Support_Atomic_Primitives to True.
* libgnat/system-vxworks7-aarch64.ads: Set
Support_Atomic_Primitives to True.
* libgnat/system-vxworks7-arm-rtp-smp.ads: Set
Support_Atomic_Primitives to True.
* libgnat/system-vxworks7-arm.ads: Set Support_Atomic_Primitives
to True.
* libgnat/system-vxworks7-ppc-kernel.ads: Set
Support_Atomic_Primitives to False.
* libgnat/system-vxworks7-ppc-rtp-smp.ads: Set
Support_Atomic_Primitives to False.
* libgnat/system-vxworks7-ppc64-kernel.ads: Set
Support_Atomic_Primitives to True.
* libgnat/system-vxworks7-ppc64-rtp-smp.ads: Set
Support_Atomic_Primitives to True.
* libgnat/system-vxworks7-x86-kernel.ads: Set
Support_Atomic_Primitives to True.
* libgnat/system-vxworks7-x86-rtp-smp.ads: Set
Support_Atomic_Primitives to True.
* libgnat/system-vxworks7-x86_64-kernel.ads: Set
Support_Atomic_Primitives to True.
* libgnat/system-vxworks7-x86_64-rtp-smp.ads: Set
Support_Atomic_Primitives to True.

23 months agoada: Small consistency fix
Eric Botcazou [Sat, 22 Oct 2022 10:48:13 +0000 (12:48 +0200)]
ada: Small consistency fix

gcc/ada/

* fe.h (Get_Warn_On_Questionable_Layout): Add void parameter.

23 months agoada: Propagate aspect Ghost when instantiating null formal procedures
Piotr Trojanek [Fri, 21 Oct 2022 18:12:15 +0000 (20:12 +0200)]
ada: Propagate aspect Ghost when instantiating null formal procedures

When instantiating generic package that includes a formal subprogram
declaration with Ghost aspect and a subprogram_default of null, e.g.:

   generic
     with procedure Proc is null with Ghost;
   package P is ...

the Ghost aspect should be propagated to the internally generated null
subprogram, so this null subprogram can be used in contexts that require
ghost entities.

gcc/ada/

* sem_ch12.adb (Instantiate_Formal_Subprogram): Copy aspect Ghost
from formal subprogram declaration to the internally generated
procedure.

23 months agoada: Implement RM 4.5.7(10/3) name resolution rule
Eric Botcazou [Thu, 20 Oct 2022 18:41:08 +0000 (20:41 +0200)]
ada: Implement RM 4.5.7(10/3) name resolution rule

This rule deals with the specific case of a conditional expression that is
the operand of a type conversion and effectively distributes the conversion
to the dependent expressions with the help of the dynamic semantics.

gcc/ada/

* sem_ch4.adb (Analyze_Case_Expression): Compute the
interpretations of the expression only at the end of the analysis,
but skip doing it if it is the operand of a type conversion.
(Analyze_If_Expression): Likewise.
* sem_res.adb (Resolve): Deal specially with conditional
expression that is the operand of a type conversion.
(Resolve_Dependent_Expression): New procedure.
(Resolve_Case_Expression): Call Resolve_Dependent_Expression.
(Resolve_If_Expression): Likewise.
(Resolve_If_Expression.Apply_Check): Take result type as
parameter.
(Resolve_Type_Conversion): Do not warn about a redundant
conversion when the operand is a conditional expression.

23 months agoada: Enforce matching of extra formals
Javier Miranda [Sun, 16 Oct 2022 19:48:53 +0000 (19:48 +0000)]
ada: Enforce matching of extra formals

This patch enforces matching of extra formals in overridden subprograms,
subprogram renamings, and subprograms to which attributes 'Access,
'Unchecked_Access, or 'Unrestricted_Access is applied (for these access
cases the subprogram is checked against its corresponding subprogram
type). This enforcement is an internal consistency check, not an
implementation of some language legality rule.

gcc/ada/

* debug.adb
(Debug_Flag_Underscore_XX): Switch -gnatd_X used temporarily to allow
disabling extra formal checks.
* exp_attr.adb
(Expand_N_Attribute_Reference [access types]): Add extra formals
to the subprogram referenced in the prefix of 'Unchecked_Access,
'Unrestricted_Access or 'Access; required to check that its extra
formals match the extra formals of the corresponding subprogram type.
* exp_ch3.adb
(Stream_Operation_OK): Declaration moved to the public part of the
package.
(Validate_Tagged_Type_Extra_Formals): New subprogram.
(Expand_Freeze_Record_Type): Improve the code that takes care of
adding the extra formals of dispatching primitives; extended to
add also the extra formals to renamings of dispatching primitives.
* exp_ch3.ads
(Stream_Operation_OK): Declaration moved from the package body.
* exp_ch6.adb
(Check_BIP_Actuals): Complete documentation.
(Has_BIP_Extra_Formal): Subprogram declaration moved to the public
part of the package. In addition, a parameter has been added to
disable an assertion that requires its use with frozen entities.
(Duplicate_Params_Without_Extra_Actuals): New subprogram.
(Check_Subprogram_Variant): Emit the call without duplicating the
extra formals since they will be added when the call is analyzed.
(Expand_Call_Helper): Ensure that the called subprogram has all its
extra formals, enforce assertion checking extra formals on thunks,
and mark calls from thunks as processed-BIP-calls to avoid adding
their extra formals twice.
(Is_Build_In_Place_Function): Return False for entities with foreign
convention.
(Is_Build_In_Place_Function_Call): Return True also for not BIP functions
that have BIP formals since the extra actuals are required.
(Make_Build_In_Place_Call_In_Object_Declaration): Occurrences of
Is_Return_Object replaced by the local variable Is_OK_Return_Object
that evaluates to False for scopes with foreign convention.
(Might_Have_Tasks): Fix check of class-wide limited record types.
(Needs_BIP_Task_Actuals): Remove assertion to allow calling this
function in more contexts; in addition it returns False for functions
returning objects with foreign convention.
(Needs_BIP_Finalization_Master): Likewise.
(Needs_BIP_Alloc_Form): Likewise.
(Validate_Subprogram_Calls): Check that the number of actuals (including
extra actuals) of calls in the subtree N match their corresponding
formals.
* exp_ch6.ads
(Has_BIP_Extra_Formal): Subprogram declaration moved to the public
part of the package. In addition, a parameter has been added to
disable an assertion that requires its use with frozen entities.
(Is_Build_In_Place_Function_Call): Complete documentation.
(Validate_Subprogram_Calls): Check that the number of actuals (including
extra actuals) of calls in the subtree N match their corresponding
formals.
* freeze.adb
(Check_Itype): Add extra formals to anonymous access subprogram itypes.
(Freeze_Expression): Improve code that disables the addition of extra
formals to functions with foreign convention.
(Check_Extra_Formals): Moved to package Sem_Ch6 as Extra_Formals_OK.
(Freeze_Subprogram): Add extra formals to non-dispatching subprograms.
* frontend.adb
(Frontend): Validate all the subprogram calls; it can be disabled using
switch -gnatd_X
* sem_ch3.adb
(Access_Subprogram_Declaration): Defer the addition of extra formals to
the freezing point so that we know the convention.
(Check_Anonymous_Access_Component): Likewise.
(Derive_Subprogram): Fix documentation.
* sem_ch6.adb
(Has_Reliable_Extra_Formals): New subprogram.
(Check_Anonymous_Return): Fix check of access to class-wide limited
record types.
(Check_Untagged_Equality): Placed in alphabetical order.
(Extra_Formals_OK): Subprogram moved from freeze.adb.
(Extra_Formals_Match_OK): New subprogram.
(Has_BIP_Formals): New subprogram.
(Has_Extra_Formals): New subprograms.
(Needs_Accessibility_Check_Extra): New subprogram.
(Parent_Subprogram): New subprogram.
(Add_Extra_Formal): Minor code cleanup.
(Create_Extra_Formals): Enforce matching extra formals on overridden
and aliased entities.
* sem_ch6.ads
(Extra_Formals_Match_OK): New subprogram.
(Extra_Formals_OK): Subprogram moved from freeze.adb.
* sem_eval.adb
(Compile_Time_Known_Value): Improve predicate to avoid assertion
failure; found working on this ticket; this change does not
affect the behavior of the compiler because this subprogram
has an exception handler that returns False when the assertion
fails.
* sem_util.adb
(Needs_Result_Accessibility_Level): Do not return False for dispatching
operations compiled with Ada_Version < 2012 since they they may be
overridden by primitives compiled with Ada_Version >= Ada_2012.

23 months agoada: Move warnings switches -- initial work
Bob Duff [Fri, 21 Oct 2022 15:09:49 +0000 (11:09 -0400)]
ada: Move warnings switches -- initial work

This patch prepares to move warning switches from Opt into Warnsw.

gcc/ada/

* warnsw.ads, warnsw.adb, fe.h, err_vars.ads, errout.ads: Move
Warning_Doc_Switch from Err_Vars to Warnsw. Access
Warn_On_Questionable_Layout on the C side via a function rather
than a variable, because we plan to turn the variables into
renamings, and you can't Export renamings.
* erroutc.adb, switch-c.adb, errout.adb: Likewise.
* gcc-interface/decl.cc: Use Get_Warn_On_Questionable_Layout
instead of Warn_On_Questionable_Layout.
* gcc-interface/Makefile.in (GNATMAKE_OBJS): Add warnsw.o, because
it is indirectly imported via Errout.
* gcc-interface/Make-lang.in (GNATBIND_OBJS): Likewise and remove
restrict.o (not needed).

23 months agoada: Align -gnatwc's documentation with its behavior
Ronan Desplanques [Fri, 14 Oct 2022 14:28:58 +0000 (16:28 +0200)]
ada: Align -gnatwc's documentation with its behavior

Shortly after the -gnatwc flag was introduced, its behavior was
tweaked, but its documentation was not updated accordingly.

gcc/ada/

* doc/gnat_ugn/building_executable_programs_with_gnat.rst
(-gnatwc): Fix flag documentation.
* gnat_ugn.texi: Regenerate.

23 months agoada: Improve handling of declare expressions in deferred-freezing contexts
Steve Baird [Wed, 19 Oct 2022 19:42:55 +0000 (12:42 -0700)]
ada: Improve handling of declare expressions in deferred-freezing contexts

In some cases where a declare expression occurs in a deferred-freezing
context (e.g., within the default value for a discriminant or for a formal
parameter, or within the expression of an expression function), the compiler
generates a bugbox.

gcc/ada/

* sem_ch3.adb
(Analyze_Object_Declaration): Do not perform expansion actions if
In_Spec_Expression is true.

23 months agoada: Minor consistency tweaks in Sem_Ch4
Eric Botcazou [Thu, 20 Oct 2022 09:05:16 +0000 (11:05 +0200)]
ada: Minor consistency tweaks in Sem_Ch4

This ensures that, during the analysis of the qualified expressions, type
conversions and unchecked type conversions, the determination of the type
of the node and the analysis of its expression are done in the same order.

No functional changes.

gcc/ada/

* sem_ch4.adb (Analyze_Qualified_Expression): Analyze the
expression only after setting the type.
(Analyze_Unchecked_Type_Conversion): Likewise.
(Analyze_Short_Circuit): Likewise for the operands.
(Analyze_Type_Conversion): Minor tweaks.
(Analyze_Unchecked_Expression): Likewise.

23 months agoada: Remove redundant line in Analyze_Qualified_Expression
Eric Botcazou [Wed, 19 Oct 2022 10:39:42 +0000 (12:39 +0200)]
ada: Remove redundant line in Analyze_Qualified_Expression

The same statement is present a few lines above.

gcc/ada/

* sem_ch4.adb (Analyze_Qualified_Expression): Remove redundant
line.

23 months agoada: Preanalyze classwide contracts as spec expressions
Ronan Desplanques [Mon, 17 Oct 2022 10:00:09 +0000 (12:00 +0200)]
ada: Preanalyze classwide contracts as spec expressions

Classwide contracts are "spec expressions" as defined in the
documentation in sem.ads. Before this patch, the instances of
classwide contracts that are destined to class conditions merging
were not preanalyzed as spec expressions. That caused preanalysis to
emit spurious errors in some cases.

gcc/ada/

* contracts.adb (Preanalyze_Condition): Use
Preanalyze_Spec_Expression.

23 months agoada: Fix expansion of 'Wide_Image and 'Wide_Wide_Image on composite types
Piotr Trojanek [Thu, 17 Jun 2021 17:44:40 +0000 (19:44 +0200)]
ada: Fix expansion of 'Wide_Image and 'Wide_Wide_Image on composite types

Attributes Wide_Image and Wide_Wide_Image applied to composite types are
now expanded just like attribute Image.

gcc/ada/

* exp_imgv.adb
(Expand_Wide_Image_Attribute): Handle just like attribute Image.
(Expand_Wide_Wide_Image_Attribute): Likewise.
* exp_put_image.adb
(Build_Image_Call): Adapt to also work for Wide and Wide_Wide
attributes.
* exp_put_image.ads
(Build_Image_Call): Update comment.
* rtsfind.ads
(RE_Id): Support wide variants of Get.
(RE_Unit_Table): Likewise.

23 months agoada: Fix inconsistent whitespace in Ada.Numerics.Generic_Complex_Arrays
Piotr Trojanek [Wed, 7 Sep 2022 19:36:04 +0000 (21:36 +0200)]
ada: Fix inconsistent whitespace in Ada.Numerics.Generic_Complex_Arrays

Cleanup only.

gcc/ada/

* libgnat/a-ngcoar.ads, libgnat/a-ngcoar.adb: Remove extra spaces.

23 months agoada: Remove unneeded code in handling formal type defaults
Piotr Trojanek [Tue, 6 Sep 2022 21:20:47 +0000 (23:20 +0200)]
ada: Remove unneeded code in handling formal type defaults

Unneeded code found while experimenting with improved detection of
unreferenced objects.

gcc/ada/

* sem_ch12.adb (Validate_Formal_Type_Default): Remove call to
Collect_Interfaces, which had no effect apart from populating a
list that was not used; fix style.

23 months agoada: Cleanup local variable that is only set as an out parameter
Piotr Trojanek [Tue, 6 Sep 2022 21:28:26 +0000 (23:28 +0200)]
ada: Cleanup local variable that is only set as an out parameter

Minor improvements; found experimenting with improved detection of
unreferenced objects.

gcc/ada/

* exp_spark.adb (SPARK_Freeze_Type): Refine type of a local
object.
* sem_ch3.adb (Derive_Subprograms): Remove initial value for
New_Subp, which is in only written as an out parameter and never
read.

23 months agoada: Remove obsolete code in Resolve_If_Expression
Eric Botcazou [Tue, 18 Oct 2022 22:04:31 +0000 (00:04 +0200)]
ada: Remove obsolete code in Resolve_If_Expression

gcc/ada/

* sem_res.adb (Resolve_If_Expression): Remove obsolete special
case.

23 months agoada: Reject limited objects in array and record delta aggregates
Piotr Trojanek [Thu, 14 Oct 2021 21:31:21 +0000 (23:31 +0200)]
ada: Reject limited objects in array and record delta aggregates

For array delta aggregates the base expression cannot be limited; for
record delta aggregates the base expression can only be limited if it is
a newly constructed object.

gcc/ada/

* sem_aggr.adb (Resolve_Delta_Aggregate): Implement rules related
to limited objects appearing as the base expression.

23 months agoada: Allow initialization of limited objects with delta aggregates
Piotr Trojanek [Thu, 14 Oct 2021 21:24:54 +0000 (23:24 +0200)]
ada: Allow initialization of limited objects with delta aggregates

Objects of a limited type can be initialized with "aggregates", which is
a collective term for ordinary aggregates (i.e. record aggregates and
array aggregates), extension aggregates and finally for delta
aggregates (introduced by Ada 2022).

gcc/ada/

* sem_ch3.adb (OK_For_Limited_Init_In_05): Handle delta aggregates
just like other aggregates.

23 months agoada: Reject record delta aggregates with limited expressions
Piotr Trojanek [Thu, 14 Oct 2021 10:48:12 +0000 (12:48 +0200)]
ada: Reject record delta aggregates with limited expressions

Implement a missing check related to record delta aggregates.

gcc/ada/

* sem_aggr.adb (Resolve_Delta_Record_Aggregate): Reject
expressions of a limited types.

23 months agoada: Missing master of task causing assertion failure
Javier Miranda [Sat, 15 Oct 2022 16:29:38 +0000 (16:29 +0000)]
ada: Missing master of task causing assertion failure

gcc/ada/

* exp_ch9.adb
(Build_Master_Entity): Handle missing case: when the context of
the master is a BIP function whose result type has tasks.

23 months agoada: Raise Tag_Error when Ada.Tags operations are called with No_Tag
Piotr Trojanek [Tue, 18 Oct 2022 12:31:00 +0000 (14:31 +0200)]
ada: Raise Tag_Error when Ada.Tags operations are called with No_Tag

Implement missing behavior of RM 13.9 (25.1/3): Tag_Error is raised by a
call of Interface_Ancestor_Tags and Is_Descendant_At_Same_Level, if any
tag passed is No_Tag. This change also fixes Descendant_Tag, which
relies on Is_Descendant_At_Same_Level. The remaining operations already
worked properly.

gcc/ada/

* libgnat/a-tags.adb
(Interface_Ancestor_Tags): Raise Tag_Error on No_Tag.
(Is_Descendant_At_Same_Level): Likewise.

23 months agoada: Add new -gnatw_q switch to usage message
Bob Duff [Tue, 18 Oct 2022 12:33:47 +0000 (08:33 -0400)]
ada: Add new -gnatw_q switch to usage message

...along with -gnatw_Q.

gcc/ada/

* usage.adb: Add -gnatw_q and -gnatw_Q.

23 months agolibstdc++: Update my author blurb in the manual
Jonathan Wakely [Mon, 7 Nov 2022 22:52:31 +0000 (22:52 +0000)]
libstdc++: Update my author blurb in the manual

libstdc++-v3/ChangeLog:

* doc/xml/authors.xml: Update the blurb listing my doc
contributions.

23 months agolibstdc++: Remove empty <author> elements in manual
Jonathan Wakely [Mon, 7 Nov 2022 22:27:08 +0000 (22:27 +0000)]
libstdc++: Remove empty <author> elements in manual

This fixes a spurious comma before the list of authors in the PDF
version of the libstdc++ manual.

Also fix the commented-out examples which should show <personblurb> not
<authorblurb>.

libstdc++-v3/ChangeLog:

* doc/xml/authors.xml: Remove empty author element.
* doc/xml/manual/spine.xml: Likewise.
* doc/html/manual/index.html: Regenerate.

23 months agoRevert "i386: Prefer remote atomic insn for atomic_fetch{add, and, or, xor}"
konglin1 [Tue, 8 Nov 2022 02:58:36 +0000 (10:58 +0800)]
Revert "i386: Prefer remote atomic insn for atomic_fetch{add, and, or, xor}"

This reverts commit 48fa4131e419942efc9dd762694fdc7e819de392.

23 months agoAdd m_CORE_ATOM for atom cores
Haochen Jiang [Tue, 8 Nov 2022 02:58:36 +0000 (10:58 +0800)]
Add m_CORE_ATOM for atom cores

gcc/ChangeLog:

* config/i386/i386-options.cc (m_CORE_ATOM): New.
* config/i386/x86-tune.def
(X86_TUNE_SCHEDULE): Initial tune for CORE_ATOM.
(X86_TUNE_PARTIAL_REG_DEPENDENCY): Ditto.
(X86_TUNE_SSE_PARTIAL_REG_DEPENDENCY): Ditto.
(X86_TUNE_SSE_PARTIAL_REG_FP_CONVERTS_DEPENDENCY): Ditto.
(X86_TUNE_SSE_PARTIAL_REG_CONVERTS_DEPENDENCY): Ditto.
(X86_TUNE_DEST_FALSE_DEP_FOR_GLC): Ditto.
(X86_TUNE_MEMORY_MISMATCH_STALL): Ditto.
(X86_TUNE_USE_LEAVE): Ditto.
(X86_TUNE_PUSH_MEMORY): Ditto.
(X86_TUNE_USE_INCDEC): Ditto.
(X86_TUNE_INTEGER_DFMODE_MOVES): Ditto.
(X86_TUNE_PREFER_KNOWN_REP_MOVSB_STOSB): Ditto.
(X86_TUNE_MISALIGNED_MOVE_STRING_PRO_EPILOGUES): Ditto.
(X86_TUNE_USE_SAHF): Ditto.
(X86_TUNE_USE_BT): Ditto.
(X86_TUNE_AVOID_FALSE_DEP_FOR_BMI): Ditto.
(X86_TUNE_ONE_IF_CONV_INSN): Ditto.
(X86_TUNE_AVOID_MFENCE): Ditto.
(X86_TUNE_USE_SIMODE_FIOP): Ditto.
(X86_TUNE_EXT_80387_CONSTANTS): Ditto.
(X86_TUNE_SSE_UNALIGNED_LOAD_OPTIMAL): Ditto.
(X86_TUNE_SSE_UNALIGNED_STORE_OPTIMAL): Ditto.
(X86_TUNE_SSE_TYPELESS_STORES): Ditto.
(X86_TUNE_SSE_LOAD0_BY_PXOR): Ditto.
(X86_TUNE_AVOID_4BYTE_PREFIXES): Ditto.
(X86_TUNE_USE_GATHER_2PARTS): Ditto.
(X86_TUNE_USE_GATHER_4PARTS): Ditto.
(X86_TUNE_USE_GATHER): Ditto.

23 months agoanalyzer: start adding support for errno
David Malcolm [Tue, 8 Nov 2022 02:52:46 +0000 (21:52 -0500)]
analyzer: start adding support for errno

gcc/analyzer/ChangeLog:
* region-model-impl-calls.cc
(region_model::impl_call_errno_location): New.
* region-model-manager.cc
(region_model_manager::region_model_manager): Initialize
m_thread_local_region and m_errno_region.
* region-model-manager.h (region_model_manager::get_errno_region):
New accessor.
(region_model_manager::m_thread_local_region): New.
(region_model_manager::m_errno_region): New.
* region-model.cc (region_model::on_call_pre): Special-case
"__errno_location".
(region_model::set_errno): New.
* region-model.h (impl_call_errno_location): New decl.
(region_model::set_errno): New decl.
* region.cc (thread_local_region::dump_to_pp): New.
(errno_region::dump_to_pp): New.
* region.h (enum memory_space): Add MEMSPACE_THREAD_LOCAL.
(enum region_kind): Add RK_THREAD_LOCAL and RK_ERRNO.
(class thread_local_region): New.
(is_a_helper <const thread_local_region *>::test): New.
(class errno_region): New.
(is_a_helper <const errno_region *>::test): New.
* store.cc (binding_cluster::escaped_p): New.
(store::escaped_p): Treat errno as always having escaped.
(store::replay_call_summary_cluster): Handle RK_THREAD_LOCAL and
RK_ERRNO.
* store.h (binding_cluster::escaped_p): Remove definition.

gcc/testsuite/ChangeLog:
* gcc.dg/analyzer/errno-1.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
23 months agoanalyzer: introduce succeed_or_fail_call_info
David Malcolm [Tue, 8 Nov 2022 02:52:40 +0000 (21:52 -0500)]
analyzer: introduce succeed_or_fail_call_info

This makes some followup code much cleaner.

gcc/analyzer/ChangeLog:
* call-info.cc (success_call_info::get_desc): Delete.
(failed_call_info::get_desc): Likewise.
(succeed_or_fail_call_info::get_desc): New.
* call-info.h (class succeed_or_fail_call_info): New.
(class success_call_info): Convert to a subclass of
succeed_or_fail_call_info.
(class failed_call_info): Likewise.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
23 months agoanalyzer: fix "when 'strchr' returns non-NULL" message
David Malcolm [Tue, 8 Nov 2022 02:52:30 +0000 (21:52 -0500)]
analyzer: fix "when 'strchr' returns non-NULL" message

Tweak analyzer handling of strchr, so that we show the
  when 'strchr' returns non-NULL
message for that execution path.

gcc/analyzer/ChangeLog:
* region-model-impl-calls.cc (region_model::impl_call_strchr):
Move to on_call_post.  Handle both outcomes using bifurcation,
rather than just the "not found" case.
* region-model.cc (region_model::on_call_pre): Move
BUILT_IN_STRCHR and "strchr" to...
(region_model::on_call_post): ...here.

gcc/testsuite/ChangeLog:
* gcc.dg/analyzer/strchr-1.c (test_literal): Detect writing to a
string literal.  Verify that we emit the "when '__builtin_strchr'
returns non-NULL" message.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
23 months agolibstdc++: Fix syntax error in old-glibc case in floating_from_chars.cc [PR107562]
Joseph Myers [Tue, 8 Nov 2022 01:39:52 +0000 (01:39 +0000)]
libstdc++: Fix syntax error in old-glibc case in floating_from_chars.cc [PR107562]

PR libstdc++/107562
* src/c++17/floating_from_chars.cc (from_chars_impl): Fix syntax
error.

23 months agoc++: implement P2468R2, the equality operator you are looking for
Jason Merrill [Fri, 4 Nov 2022 19:22:45 +0000 (15:22 -0400)]
c++: implement P2468R2, the equality operator you are looking for

This paper is resolving the problem of well-formed C++17 code becoming
ambiguous in C++20 due to asymmetrical operator== being compared with itself
in reverse.  I had previously implemented a tiebreaker such that if the two
candidates were functions with the same parameter types, we would prefer the
non-reversed candidate.  But the committee went with a different approach:
if there's an operator!= with the same parameter types as the operator==,
don't consider the reversed form of the ==.

So this patch implements that, and changes my old tiebreaker to give a
pedwarn if it is used.  I also noticed that we were giving duplicate errors
for some testcases, and fixed the tourney logic to avoid that.

As a result, a lot of tests of the form

  struct A { bool operator==(const A&); };

need to be fixed to add a const function-cv-qualifier, e.g.

  struct A { bool operator==(const A&) const; };

The committee thought such code ought to be fixed, so breaking it was fine.

18_support/comparisons/algorithms/fallback.cc also breaks with this patch,
because of the similarly asymmetrical

  bool operator==(const S&, S&) { return true; }

As a result, some of the asserts need to be reversed.

The H test in spaceship-eq15.C is specified in the standard to be
well-formed because the op!= in the inline namespace is not found by the
search, but that seems wrong to me.  I've implemented that behavior, but
disabled it for now; if we decide that is the way we want to go, we can just
remove the "0 &&" in add_candidates to enable it.

Co-authored-by: Jakub Jelinek <jakub@redhat.com>
gcc/cp/ChangeLog:

* cp-tree.h (fns_correspond): Declare.
* decl.cc (fns_correspond): New.
* call.cc (add_candidates): Look for op!= matching op==.
(joust): Complain about non-standard reversed tiebreaker.
(tourney): Fix champ_compared_to_predecessor logic.
(build_new_op): Don't complain about error_mark_node not having
'bool' type.
* pt.cc (tsubst_copy_and_build): Don't try to be permissive
when seen_error().

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/spaceship-eq15.C: New test.
* g++.dg/cpp0x/defaulted3.C: Add const.
* g++.dg/cpp2a/bit-cast7.C: Add const.
* g++.dg/cpp2a/spaceship-rewrite1.C: Expect error.
* g++.dg/cpp2a/spaceship-rewrite5.C: Expect error.
* g++.old-deja/g++.jason/byval2.C: Expect error.
* g++.old-deja/g++.other/overload13.C: Add const.

libstdc++-v3/ChangeLog:

* testsuite/18_support/comparisons/algorithms/fallback.cc: Adjust
asserts.

23 months agoAdd transitive inferred range processing.
Andrew MacLeod [Mon, 7 Nov 2022 20:07:35 +0000 (15:07 -0500)]
Add transitive inferred range processing.

Rewalk statements at the end of a block to see if any inferred ranges
affect earlier calculations and register those as inferred ranges.

gcc/
PR tree-optimization/104530
* gimple-range-cache.cc (ranger_cache::register_inferred_value):
New.  Split from:
(ranger_cache::apply_inferred_ranges): Move setting cache to
separate function.
* gimple-range-cache.h (register_inferred_value): New prototype.
* gimple-range-infer.cc (infer_range_manager::has_range_p): New.
* gimple-range-infer.h (has_range_p): New prototype.
* gimple-range.cc (register_transitive_inferred_ranges): New.
* gimple-range.h (register_transitive_inferred_ranges): New proto.
* tree-vrp.cc (rvrp_folder::fold_stmt): Check for transitive inferred
ranges at the end of the block before folding final stmt.

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

23 months agoDaily bump.
GCC Administrator [Tue, 8 Nov 2022 00:17:53 +0000 (00:17 +0000)]
Daily bump.

23 months agolibstdc++: Fix up libstdc++ build against glibc 2.25 or older [PR107562]
Jakub Jelinek [Mon, 7 Nov 2022 23:35:09 +0000 (00:35 +0100)]
libstdc++: Fix up libstdc++ build against glibc 2.25 or older [PR107562]

On Mon, Nov 07, 2022 at 05:48:42PM +0000, Jonathan Wakely wrote:
> On Mon, 7 Nov 2022 at 16:11, Joseph Myers <joseph@codesourcery.com> wrote:
> >
> > On Wed, 2 Nov 2022, Jakub Jelinek via Gcc-patches wrote:
> >
> > > APIs.  So that one can build gcc against older glibc and then compile
> > > user programs on newer glibc, the patch uses weak references unless
> > > gcc is compiled against glibc 2.26+.  strfromf128 unfortunately can't
> >
> > This support for older glibc doesn't actually seem to be working, on an
> > older system with glibc 2.19 I'm seeing
> >
> > /scratch/jmyers/fsf/gcc-mainline/libstdc++-v3/src/c++17/floating_to_chars.cc:52:3: error: expected initializer before '__asm'
> >    52 |   __asm ("strfromf128");
> >       |   ^~~~~
> >
> > and a series of subsequent errors.
>
> This seems to "fix" it (not sure if it's right though):
>
> #ifndef _GLIBCXX_HAVE_FLOAT128_MATH
> extern "C" _Float128 __strtof128(const char*, char**)
>  __attribute__((__weak__));
> #endif
> extern "C" _Float128 __strtof128(const char*, char**)
>  __asm ("strtof128");

It is, but floating_from_chars.cc has the same problem,
and I think we can avoid the duplication, like this:

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

PR libstdc++/107562
* src/c++17/floating_from_chars.cc (__strtof128): Put __asm before
__attribute__.
* src/c++17/floating_to_chars.cc (__strfromf128): Likewise.

23 months agobpf: cleanup missed refactor
David Faust [Mon, 7 Nov 2022 18:30:52 +0000 (10:30 -0800)]
bpf: cleanup missed refactor

Commit 068baae1864 "bpf: add preserve_field_info builtin" factored out
some repeated code to a new function maybe_make_core_relo (), but missed
using it in one place. Clean that up.

gcc/

* config/bpf/bpf.cc (handle_attr_preserve): Use maybe_make_core_relo().

23 months agoImprove multiplication by powers of 2 in range-ops.
Aldy Hernandez [Fri, 4 Nov 2022 21:24:42 +0000 (22:24 +0100)]
Improve multiplication by powers of 2 in range-ops.

For unsigned numbers, multiplication by X, where X is a power of 2 is
[0,0][X,+INF].

This patch causes a regression to g++.dg/pr71488.C where
-Wstringop-overflow gets the same IL as before, but better ranges
cause it to issue a bogus warning.  I will create a PR with some
notes.

No discernible changes in performance.

Tested on x86-64 Linux.

PR tree-optimization/55157

gcc/ChangeLog:

* range-op.cc (operator_mult::wi_fold): Optimize multiplications
by powers of 2.

gcc/testsuite/ChangeLog:

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

23 months agoExtend optimization for integer bit test on __atomic_fetch_[or|and]_*
H.J. Lu [Tue, 1 Nov 2022 16:49:18 +0000 (09:49 -0700)]
Extend optimization for integer bit test on __atomic_fetch_[or|and]_*

Extend optimization for

_1 = __atomic_fetch_or_4 (ptr_6, 0x80000000, _3);
_5 = (signed int) _1;
_4 = _5 >= 0;

to

_1 = __atomic_fetch_or_4 (ptr_6, 0x80000000, _3);
_5 = (signed int) _1;
if (_5 >= 0)

gcc/

PR middle-end/102566
* tree-ssa-ccp.cc (optimize_atomic_bit_test_and): Also handle
if (_5 < 0) and if (_5 >= 0).

gcc/testsuite/

PR middle-end/102566
* g++.target/i386/pr102566-7.C

23 months agolibstdc++: Implement ranges::as_rvalue_view from P2446R2
Patrick Palka [Mon, 7 Nov 2022 18:29:42 +0000 (13:29 -0500)]
libstdc++: Implement ranges::as_rvalue_view from P2446R2

libstdc++-v3/ChangeLog:

* include/std/ranges (as_rvalue_view): Define.
(enable_borrowed_range<as_rvalue_view>): Define.
(views::__detail::__can_as_rvalue_view): Define.
(views::_AsRvalue, views::as_rvalue): Define.
* testsuite/std/ranges/adaptors/as_rvalue/1.cc: New test.

23 months agolibstdc++: Implement ranges::cartesian_product_view from P2374R4
Patrick Palka [Mon, 7 Nov 2022 18:29:30 +0000 (13:29 -0500)]
libstdc++: Implement ranges::cartesian_product_view from P2374R4

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

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

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

because for e.g.

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

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

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

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

libstdc++-v3/ChangeLog:

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

gcc/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

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

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

In the testcase we are dividing this by 8:

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

and coming up with:

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

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

PR tree-optimization/107541

gcc/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

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

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

PR fortran/107508

gcc/fortran/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

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

gcc/testsuite/ChangeLog:

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

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

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

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

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

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

gcc/ChangeLog:

* doc/invoke.texi: Improve wording.

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

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

gcc/ChangeLog:

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

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

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

gcc/ada/

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

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

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

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

gcc/ada/

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

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

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

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

gcc/ada/

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

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

Use named notation in calls to Expand_Composite_Equality.

gcc/ada/

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

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

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

gcc/ada/

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

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

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

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

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

gcc/ada/

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

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

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

gcc/ada/

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

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

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

Remove the function Device_Ada_Final_Link_Name as it is no
longer referenced.

gcc/ada/

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

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

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

gcc/ada/

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

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

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

gcc/ada/

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

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

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

gcc/ada/

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

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

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

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

gcc/ada/

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

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

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

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

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

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

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

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

   X.all and then ...

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

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

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

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

gcc/ada/

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

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

Subprogram names starting with No_ seem unnecessarily confusing.

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

gcc/ada/

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

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

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

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

gcc/ada/

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

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

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

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

gcc/ada/

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

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

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

gcc/ada/

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

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

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

gcc/ada/

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

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

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

Code cleanup; semantics is unaffected.

gcc/ada/

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

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

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

gcc/ada/

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

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

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

gcc/ada/

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

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

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

gcc/ada/

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

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

Whitespace cleanup only.

gcc/ada/

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

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

Cleanup after replacing Unchecked_Conversion with
Ada.Unchecked_Conversion.

gcc/ada/

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