platform/upstream/gcc.git
2 years agoDaily bump.
GCC Administrator [Thu, 17 Nov 2022 00:16:52 +0000 (00:16 +0000)]
Daily bump.

2 years agoanalyzer: more test coverage for named constants
David Malcolm [Wed, 16 Nov 2022 22:38:28 +0000 (17:38 -0500)]
analyzer: more test coverage for named constants

gcc/testsuite/ChangeLog:
* gcc.dg/analyzer/named-constants-via-command-line.c: New test.
* gcc.dg/analyzer/named-constants-via-macros-3.c: New test.
* gcc.dg/analyzer/named-constants-via-macros-4.c: New test.
* gcc.dg/analyzer/named-constants-via-macros-empty.c: New test.
* gcc.dg/analyzer/named-constants-via-macros-gc.c: New test.
* gcc.dg/analyzer/named-constants-via-macros-traditional.c: New test.
* gcc.dg/analyzer/named-constants-via-macros-undef.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2 years agoanalyzer: log the stashing of named constants [PR107711]
David Malcolm [Wed, 16 Nov 2022 22:38:24 +0000 (17:38 -0500)]
analyzer: log the stashing of named constants [PR107711]

PR analyzer/107711 seems to be a bug in how named constants are looked up
by the analyzer in the C frontend.

To help debug this, this patch extends -fdump-analyzer and
-fdump-analyzer-stderr so that they dump this part of the analyzer's
startup.

gcc/analyzer/ChangeLog:
PR analyzer/107711
* analyzer-language.cc: Include "diagnostic.h".
(maybe_stash_named_constant): Add logger param and use it to log
the name being looked up, and the result.
(stash_named_constants): New, splitting out from...
(on_finish_translation_unit): ...this function.  Call
get_or_create_logfile and use the result to create a logger
instance, passing it to stash_named_constants.
* analyzer.h (get_or_create_any_logfile): New decl.
* engine.cc (dump_fout, owns_dump_fout): New globals, split out
from run_checkers.
(get_or_create_any_logfile): New function, split out from...
(run_checkers): ...here, so that the logfile can be opened by
on_finish_translation_unit.  Clear the globals when closing the
dump file.

gcc/testsuite/ChangeLog:
PR analyzer/107711
* gcc.dg/analyzer/fdump-analyzer-1.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2 years agoFortran: ICE on procedure arguments with non-integer length [PR107707]
Steve Kargl [Wed, 16 Nov 2022 21:46:55 +0000 (22:46 +0100)]
Fortran: ICE on procedure arguments with non-integer length [PR107707]

gcc/fortran/ChangeLog:

PR fortran/107707
* interface.cc (gfc_compare_actual_formal): Check that we actually
have integer values before asking gmp_* to use them.

gcc/testsuite/ChangeLog:

PR fortran/107707
* gfortran.dg/pr107707.f90: New test.

2 years agoc++: P2448 - Relaxing some constexpr restrictions [PR106649]
Marek Polacek [Wed, 2 Nov 2022 17:11:02 +0000 (13:11 -0400)]
c++: P2448 - Relaxing some constexpr restrictions [PR106649]

This patch implements C++23 P2448, which lifts more restrictions on the
constexpr keyword.  It's effectively going the way of being just a hint
(hello, inline!).

This gist is relatively simple: in C++23, a constexpr function's return
type/parameter type doesn't have to be a literal type; and you can have
a constexpr function for which no invocation satisfies the requirements
of a core constant expression.  For example,

  void f(int& i); // not constexpr

  constexpr void g(int& i) {
    f(i); // unconditionally calls a non-constexpr function
  }

is now OK, even though there isn't an invocation of 'g' that would be
a constant expression.  Maybe 'f' will be made constexpr soon, or maybe
this depends on the version of C++ used, and similar.  The patch is
unfortunately not that trivial.  The important bit is to use the new
require_potential_rvalue_constant_expression_fncheck in
maybe_save_constexpr_fundef (and where appropriate).  It has a new flag
that says that we're checking the body of a constexpr function, and in
that case it's OK to find constructs that aren't a constant expression.

Since it's useful to be able to check for problematic constructs even
in C++23, this patch implements a new warning, -Winvalid-constexpr,
which is a pedwarn turned on by default in C++20 and earlier, and which
can be turned on in C++23 as well, in which case it's an ordinary warning.
This I implemented by using the new function constexpr_error, used in
p_c_e_1 and friends.  (In some cases I believe fundef_p will be always
false (= hard error), but it made sense to me to be consistent and use
constexpr_error throughout p_c_e_1.)

While working on this I think I found a bug, see constexpr-nonlit15.C
and <https://gcc.gnu.org/PR107598>.  This patch doesn't address that.

This patch includes changes to diagnose the problem if the user doesn't
use -Winvalid-constexpr and calls a constexpr function that in fact isn't
constexpr-ready yet: maybe_save_constexpr_fundef registers the function
if warn_invalid_constexpr is 0 and explain_invalid_constexpr_fn then
gives the diagnostic.

PR c++/106649

gcc/c-family/ChangeLog:

* c-cppbuiltin.cc (c_cpp_builtins): Update value of __cpp_constexpr for
C++23.
* c-opts.cc (c_common_post_options): Set warn_invalid_constexpr
depending on cxx_dialect.
* c.opt (Winvalid-constexpr): New option.

gcc/cp/ChangeLog:

* constexpr.cc (constexpr_error): New function.
(is_valid_constexpr_fn): Use constexpr_error.
(maybe_save_constexpr_fundef): Call
require_potential_rvalue_constant_expression_fncheck rather than
require_potential_rvalue_constant_expression.  Register the
function if -Wno-invalid-constexpr was specified.
(explain_invalid_constexpr_fn): Don't return early if a function marked
'constexpr' that isn't actually a constant expression was called.
(non_const_var_error): Add a bool parameter.  Use constexpr_error.
(inline_asm_in_constexpr_error): Likewise.
(cxx_eval_constant_expression): Adjust calls to non_const_var_error
and inline_asm_in_constexpr_error.
(potential_constant_expression_1): Add a bool parameter.  Use
constexpr_error.
(require_potential_rvalue_constant_expression_fncheck): New function.
* cp-tree.h (require_potential_rvalue_constant_expression_fncheck):
Declare.
* method.cc (struct comp_info): Call
require_potential_rvalue_constant_expression_fncheck rather than
require_potential_rvalue_constant_expression.

gcc/ChangeLog:

* doc/invoke.texi: Document -Winvalid-constexpr.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/constexpr-ctor2.C: Expect an error in c++20_down only.
* g++.dg/cpp0x/constexpr-default-ctor.C: Likewise.
* g++.dg/cpp0x/constexpr-diag3.C: Likewise.
* g++.dg/cpp0x/constexpr-ex1.C: Likewise.
* g++.dg/cpp0x/constexpr-friend.C: Likewise.
* g++.dg/cpp0x/constexpr-generated1.C: Likewise.
* g++.dg/cpp0x/constexpr-ice5.C: Likewise.
* g++.dg/cpp0x/constexpr-ice6.C: Likewise.
* g++.dg/cpp0x/constexpr-memfn1.C: Likewise.
* g++.dg/cpp0x/constexpr-neg2.C: Likewise.
* g++.dg/cpp0x/constexpr-non-const-arg.C: Likewise.
* g++.dg/cpp0x/constexpr-reinterpret1.C: Likewise.
* g++.dg/cpp0x/pr65327.C: Likewise.
* g++.dg/cpp1y/constexpr-105050.C: Likewise.
* g++.dg/cpp1y/constexpr-89285-2.C: Likewise.
* g++.dg/cpp1y/constexpr-89285.C: Likewise.
* g++.dg/cpp1y/constexpr-89785-2.C: Likewise.
* g++.dg/cpp1y/constexpr-neg1.C: Likewise.
* g++.dg/cpp1y/constexpr-nsdmi7b.C: Likewise.
* g++.dg/cpp1y/constexpr-throw.C: Likewise.
* g++.dg/cpp23/constexpr-nonlit3.C: Remove dg-error.
* g++.dg/cpp23/constexpr-nonlit6.C: Call the test functions.
* g++.dg/cpp23/feat-cxx2b.C: Adjust the expected value of
__cpp_constexpr.
* g++.dg/cpp2a/consteval3.C: Remove dg-error.
* g++.dg/cpp2a/constexpr-new7.C: Expect an error in c++20_down only.
* g++.dg/cpp2a/constexpr-try5.C: Remove dg-error.
* g++.dg/cpp2a/spaceship-constexpr1.C: Expect an error in c++20_down
only.
* g++.dg/cpp2a/spaceship-eq3.C: Likewise.
* g++.dg/diagnostic/constexpr1.C: Remove dg-error.
* g++.dg/gomp/pr79664.C: Use -Winvalid-constexpr -pedantic-errors.
* g++.dg/ubsan/vptr-4.C: Likewise.
* g++.dg/cpp23/constexpr-nonlit10.C: New test.
* g++.dg/cpp23/constexpr-nonlit11.C: New test.
* g++.dg/cpp23/constexpr-nonlit12.C: New test.
* g++.dg/cpp23/constexpr-nonlit13.C: New test.
* g++.dg/cpp23/constexpr-nonlit14.C: New test.
* g++.dg/cpp23/constexpr-nonlit15.C: New test.
* g++.dg/cpp23/constexpr-nonlit16.C: New test.
* g++.dg/cpp23/constexpr-nonlit8.C: New test.
* g++.dg/cpp23/constexpr-nonlit9.C: New test.

2 years agolibstdc++: Fix dumb typos in ALT128 support in <format> [PR107720]
Jonathan Wakely [Wed, 16 Nov 2022 20:47:39 +0000 (20:47 +0000)]
libstdc++: Fix dumb typos in ALT128 support in <format> [PR107720]

This is only a partial fix for the PR.

libstdc++-v3/ChangeLog:

PR libstdc++/107720
* include/std/format (__format::_Arg_t): Fix typo in enumerator
name.
(_Arg_value::_S_get): Fix missing semi-colons.

2 years agolibstdc++: Improve performance of chrono::utc_clock::now()
Jonathan Wakely [Wed, 16 Nov 2022 15:35:23 +0000 (15:35 +0000)]
libstdc++: Improve performance of chrono::utc_clock::now()

We can use an array instead of a std::vector, and we can avoid the
binary search for the common case of a time point after the most recent
leap second. On one system where I tested this, utc_clock::now() now
takes about 16ns instead of 31ns.

libstdc++-v3/ChangeLog:

* include/std/chrono (get_leap_second_info): Optimize.

2 years agolibstdc++: Adjust <format> for Clang compatibility [PR107712]
Jonathan Wakely [Wed, 16 Nov 2022 13:48:39 +0000 (13:48 +0000)]
libstdc++: Adjust <format> for Clang compatibility [PR107712]

Clang doesn't define __builtin_toupper, so use std::toupper.

Also add some (not actually required since C++20) typename keywords to
help Clang versions up to and including 15.

libstdc++-v3/ChangeLog:

PR libstdc++/107712
* include/std/format (__format::__formatter_int::format): Use
std::toupper when __builtin_toupper isn't available.
(basic_format_arg::handle): Add 'typename'.
* include/std/complex (complex<T>): Add 'typename'.

2 years agolibstdc++: Disable std::format of _Float128 if std::to_chars is innaccurate
Jonathan Wakely [Tue, 15 Nov 2022 15:31:17 +0000 (15:31 +0000)]
libstdc++: Disable std::format of _Float128 if std::to_chars is innaccurate

This restricts std::format support for _Float128 (and __float128) to
targets where glibc provides __strfromf128 and so can give correct
output.

libstdc++-v3/ChangeLog:

* include/std/format [__FLT128_DIG__] (_GLIBCXX_FORMAT_F128):
Only support formatting _Float128 when glibc provides the
functionality needed for accurate std::to_chars.

2 years agoFortran: error recovery after reference to bad CLASS variable [PR107681]
Harald Anlauf [Wed, 16 Nov 2022 20:41:19 +0000 (21:41 +0100)]
Fortran: error recovery after reference to bad CLASS variable [PR107681]

gcc/fortran/ChangeLog:

PR fortran/107681
* resolve.cc (resolve_fl_var_and_proc): Prevent NULL pointer
dereference with reference to bad CLASS variable.

gcc/testsuite/ChangeLog:

PR fortran/107681
* gfortran.dg/pr107681.f90: New test.

2 years agoFortran: ICE in simplification of array expression involving power [PR107680]
Harald Anlauf [Tue, 15 Nov 2022 20:20:20 +0000 (21:20 +0100)]
Fortran: ICE in simplification of array expression involving power [PR107680]

gcc/fortran/ChangeLog:

PR fortran/107680
* arith.cc (arith_power): Check that operands are properly converted
before attempting to simplify.

gcc/testsuite/ChangeLog:

PR fortran/107680
* gfortran.dg/pr107680.f90: New test.

2 years agoRISC-V: Split "(a & (1UL << bitno)) ? 0 : 1" to bext + xori
Philipp Tomsich [Thu, 12 May 2022 13:11:20 +0000 (15:11 +0200)]
RISC-V: Split "(a & (1UL << bitno)) ? 0 : 1" to bext + xori

We avoid reassociating "(~(a >> BIT_NO)) & 1" into "((~a) >> BIT_NO) & 1"
by splitting it into a zero-extraction (bext) and an xori.  This both
avoids burning a register on a temporary and generates a sequence that
clearly captures 'extract bit, then invert bit'.

This change improves the previously generated
    srl   a0,a0,a1
    not   a0,a0
    andi  a0,a0,1
into
    bext  a0,a0,a1
    xori  a0,a0,1

Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu>
gcc/ChangeLog:

* config/riscv/bitmanip.md: Add split covering
"(a & (1 << BIT_NO)) ? 0 : 1".

gcc/testsuite/ChangeLog:

* gcc.target/riscv/zbs-bext.c: Add testcases.
* gcc.target/riscv/zbs-bexti.c: Add testcases.

2 years agoRISC-V: Split "(a & (1UL << bitno)) ? 0 : -1" to bext + addi
Philipp Tomsich [Wed, 11 May 2022 11:50:11 +0000 (13:50 +0200)]
RISC-V: Split "(a & (1UL << bitno)) ? 0 : -1" to bext + addi

For a straightforward application of bext for the following function
  long bext64(long a, char bitno)
  {
    return (a & (1UL << bitno)) ? 0 : -1;
  }
we generate
srl a0,a0,a1 # 7 [c=4 l=4]  lshrdi3
andi a0,a0,1 # 8 [c=4 l=4]  anddi3/1
addi a0,a0,-1 # 14 [c=4 l=4]  adddi3/1
due to the following failed match at combine time:
  (set (reg:DI 82)
       (zero_extract:DI (reg:DI 83)
            (const_int 1 [0x1])
            (reg:DI 84)))

The existing pattern for bext requires the 3rd argument to
zero_extract to be a QImode register wrapped in a zero_extension.
This adds an additional pattern that allows an Xmode argument.

With this change, the testcase compiles to
bext a0,a0,a1 # 8 [c=4 l=4]  *bextdi
addi a0,a0,-1 # 14 [c=4 l=4]  adddi3/1

gcc/ChangeLog:

* config/riscv/bitmanip.md (*bext<mode>): Add an additional
pattern that allows the 3rd argument to zero_extract to be
an Xmode register operand.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/zbs-bext.c: Add testcases.
* gcc.target/riscv/zbs-bexti.c: Add testcases.

2 years agotestsuite: Fix mistransformed gcov
Hans-Peter Nilsson [Tue, 15 Nov 2022 20:11:54 +0000 (21:11 +0100)]
testsuite: Fix mistransformed gcov

In commit r13-2619-g34b9a03353d3fd, [transform] was applied to all
invocations of gcov, for both out-of-tree and in-tree testing.
For in-tree cross builds, this means gcov was called as
"/path/to/gccobj/gcc/target-tuple-gcov" gcov-pr94029.c which is
incorrect, as it's there "/path/to/gccobj/gcc/gcov" until it's
installed.  This caused a testsuite failure, like:

Running /x/gcc/gcc/testsuite/gcc.misc-tests/gcov.exp ...
FAIL: gcc.misc-tests/gcov-pr94029.c gcov failed: spawn failed

To avoid cumbersome conditionals, use a dedicated new helper function.

gcc/testsuite:
* lib/gcc-dg.exp (gcc-transform-out-of-tree): New proc.
* g++.dg/gcov/gcov.exp, gcc.misc-tests/gcov.exp: Call
gcc-transform-out-of-tree instead of transform.

2 years agotree-optimization/107686 - fix bitfield ref through vec_unpack optimization
Richard Biener [Wed, 16 Nov 2022 14:27:13 +0000 (15:27 +0100)]
tree-optimization/107686 - fix bitfield ref through vec_unpack optimization

The following propely restricts the bitfield access to integral types
when we look through VEC_UNPACK with the intent to emit a widening
conversion.

PR tree-optimization/107686
* tree-ssa-forwprop.cc (optimize_vector_load): Restrict
VEC_UNPACK support to integral typed bitfield refs.

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

2 years agomiddle-end/107679 - fix SSA rewrite of clobber of parameter
Richard Biener [Wed, 16 Nov 2022 12:57:14 +0000 (13:57 +0100)]
middle-end/107679 - fix SSA rewrite of clobber of parameter

When the frontend clobbers a parameter and that parameter gets
rewritten into SSA then we ICE because we didn't expect this.  Avoid
using the parameter decl to create a SSA default def in this case.

PR middle-end/107679
* tree-into-ssa.cc (maybe_register_def): Use new temporary if
we require an uninitialized value for a parameter decl.

* gfortran.dg/pr107679.f90: New testcase.

2 years agolibstdc++: Add test for chrono::utc_clock leap second offset
Jonathan Wakely [Wed, 16 Nov 2022 15:04:32 +0000 (15:04 +0000)]
libstdc++: Add test for chrono::utc_clock leap second offset

This test of leap second handling is taken from the C++20 standard.

libstdc++-v3/ChangeLog:

* testsuite/std/time/clock/utc/1.cc: Check handling across leap
second insertion.

2 years agolibatomic: regenerate Makefile.in
Martin Liska [Wed, 16 Nov 2022 14:13:41 +0000 (15:13 +0100)]
libatomic: regenerate Makefile.in

libatomic/ChangeLog:

* Makefile.in: Re-generate.

2 years agolibstdc++: Fix stream initialization with static library [PR107701]
Patrick Palka [Wed, 16 Nov 2022 13:53:51 +0000 (08:53 -0500)]
libstdc++: Fix stream initialization with static library [PR107701]

When linking with a static library, the linker seems to discard a
constituent .o object (including its global initializers) if nothing
defined in the object is referenced by the program (unless e.g.
--whole-archive is used).  This behavior breaks iostream with static
libstdc++.a (on systems that support init priorities) because we define
the global initializer for the standard stream objects in a separate TU
(ios_init.cc) from the stream object definitions (globals_io.cc).

This patch fixes this by moving the stream initialization object into
the same TU that defines the stream objects, so that any use of the
streams prevents the linker from discarding this global initializer.

PR libstdc++/107701

libstdc++-v3/ChangeLog:

* include/std/iostream (__ioinit): Adjust comment.
* src/c++98/globals_io.cc: Include "io_base_init.h" here
instead of ...
* src/c++98/ios_init.cc: ... here.
* src/c++98/ios_base_init.h (__ioinit): More comments.
* testsuite/17_intro/static.cc: dg-do run instead of just link.

2 years agoc++: Alignment changes to layout compatibility/common initial sequence - DR2583
Jakub Jelinek [Wed, 16 Nov 2022 13:49:47 +0000 (14:49 +0100)]
c++: Alignment changes to layout compatibility/common initial sequence - DR2583

When trying to figure out what to do about alignment,
layout_compatible_type_p returns false if TYPE_ALIGN on
ENUMERAL_TYPE/CLASS_TYPE_P (but not scalar types?) differ, or if members
don't have the same positions.

What is in DR2583 doesn't say anything like that though, on the other side
it says that if the corresponding entities don't have the same alignment
requirements, they aren't part of the common initial sequence.

So, my understanding of this is we shouldn't check TYPE_ALIGN in
layout_compatible_type_p, but instead DECL_ALIGN in
next_common_initial_seqence.

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

* typeck.cc (next_common_initial_sequence): Return false members have
different DECL_ALIGN.
(layout_compatible_type_p): Don't test TYPE_ALIGN of ENUMERAL_TYPE
or CLASS_TYPE_P.

* g++.dg/cpp2a/is-layout-compatible3.C: Expect enums with different
alignas to be layout compatible, while classes with different
alignas on members layout incompatible.
* g++.dg/DRs/dr2583.C: New test.

2 years agolibstdc++: Fix up <complex> for extended floating point types [PR107649]
Jakub Jelinek [Wed, 16 Nov 2022 13:45:40 +0000 (14:45 +0100)]
libstdc++: Fix up <complex> for extended floating point types [PR107649]

As filed by Jonathan in the PR, I've screwed up the requires syntax
in the extended floating point specialization:
-    requires(__complex_type<_Tp>::type)
+    requires requires { typename __complex_type<_Tp>::type; }
and doing this change resulted in lots of errors because __complex_whatever
overfloads from extended floating point types were declared after the
templates which used them.

The following patch fixes that.

Bootstrapped/regtested on x86_64-linux and i686-linux, additionally
I've tested that with _GLIBCXX_HAVE_FLOAT128_MATH not being defined
while __STDCPP_FLOAT128_T__ defined one can still use
std::complex<std::float128_t> for basic arithmetic etc., just one can't
expect std::sin etc. to work in that case (because we don't have any
implementation).

2022-11-16  Jakub Jelinek  <jakub@redhat.com>
    Jonathan Wakely  <jwakely@redhat.com>

PR libstdc++/107649
* include/std/complex (__complex_abs, __complex_arg, __complex_cos,
__complex_cosh, __complex_exp, __complex_log, __complex_sin,
__complex_sinh, __complex_sqrt, __complex_tan, __complex_tanh,
__complex_pow): Move __complex__ _Float{16,32,64,128} and
__complex__ decltype(0.0bf16) overloads earlier in the file.
(complex): Fix up requires on the partial specialization for extended
float types.
(__complex_acos, __complex_asin, __complex_atan, __complex_acosh,
__complex_asinh, __complex_atanh): Move
__complex__ _Float{16,32,64,128} and __complex__ decltype(0.0bf16)
overloads earlier in the file.

2 years agoc++: Fix up calls to static operator() or operator[] [PR107624]
Jakub Jelinek [Wed, 16 Nov 2022 13:42:54 +0000 (14:42 +0100)]
c++: Fix up calls to static operator() or operator[] [PR107624]

One thing that doesn't work properly is the same problem as I've filed
yesterday for static operator() - PR107624 - that side-effects of
the postfix-expression on which the call or subscript operator are
applied are thrown away, I assume we have to add them into COMPOUND_EXPR
somewhere after we find out that the we've chosen a static member function
operator.

On Mon, Nov 14, 2022 at 06:29:44PM -0500, Jason Merrill wrote:
> Indeed.  The code in build_new_method_call for this case has the comment
>
>               /* In an expression of the form `a->f()' where `f' turns
>                  out to be a static member function, `a' is
>                  none-the-less evaluated.  */

Had to tweak 3 spots for this.  Furthermore, found that if in non-pedantic
C++20 compilation static operator[] is accepted, we required that it has 2
arguments, I think it is better to require exactly one because that case
is the only one that will actually work in C++20 and older.

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

PR c++/107624
* call.cc (keep_unused_object_arg): New function.
(build_op_call): Use it.
(build_op_subscript): Likewise.
(build_new_op): Similarly for ARRAY_REF.
(build_new_method_call): Use it.
* decl.cc (grok_op_properties): For C++20 and earlier, if operator[]
is static member function, require exactly one parameter rather than
exactly two parameters.

* g++.dg/cpp23/static-operator-call4.C: New test.
* g++.dg/cpp23/subscript10.C: New test.
* g++.dg/cpp23/subscript11.C: New test.

2 years agodoc: fix description of -mrelax-cmpxchg-loop [PR 107676]
Alexander Monakov [Wed, 16 Nov 2022 13:33:11 +0000 (16:33 +0300)]
doc: fix description of -mrelax-cmpxchg-loop [PR 107676]

gcc/ChangeLog:

PR target/107676
* doc/invoke.texi (-mrelax-cmpxchg-loop): Reword description.

2 years agoi386: correct x87&SSE multiplication modeling in znver.md
Alexander Monakov [Tue, 1 Nov 2022 14:53:13 +0000 (17:53 +0300)]
i386: correct x87&SSE multiplication modeling in znver.md

All multiplication instructions are fully pipelined, except AVX256
instructions on Zen 1, which issue over two cycles on a 128-bit unit.
Correct the model accordingly to reduce combinatorial explosion in
automaton tables.

Top znver table sizes in insn-automata.o:

Before:

30056 r znver1_fp_min_issue_delay
120224 r znver1_fp_transitions

After:

6720 r znver1_fp_min_issue_delay
53760 r znver1_fp_transitions

gcc/ChangeLog:

PR target/87832
* config/i386/znver.md: (znver1_fp_op_mul): Correct cycles in
the reservation.
(znver1_fp_op_mul_load): Ditto.
(znver1_mmx_mul): Ditto.
(znver1_mmx_load): Ditto.
(znver1_ssemul_ss_ps): Ditto.
(znver1_ssemul_ss_ps_load): Ditto.
(znver1_ssemul_avx256_ps): Ditto.
(znver1_ssemul_avx256_ps_load): Ditto.
(znver1_ssemul_sd_pd): Ditto.
(znver1_ssemul_sd_pd_load): Ditto.
(znver2_ssemul_sd_pd): Ditto.
(znver2_ssemul_sd_pd_load): Ditto.
(znver1_ssemul_avx256_pd): Ditto.
(znver1_ssemul_avx256_pd_load): Ditto.
(znver1_sseimul): Ditto.
(znver1_sseimul_avx256): Ditto.
(znver1_sseimul_load): Ditto.
(znver1_sseimul_avx256_load): Ditto.
(znver1_sseimul_di): Ditto.
(znver1_sseimul_load_di): Ditto.

2 years agoi386: correct x87&SSE division modeling in znver.md
Alexander Monakov [Tue, 1 Nov 2022 14:04:25 +0000 (17:04 +0300)]
i386: correct x87&SSE division modeling in znver.md

Correct modeling of division instructions in the SIMD/FP domain for
AMD Zen architectures and avoid combinatorial explosion of automaton
tables by modeling the separate floating-point division unit and
correcting reservations to reflect reciprocal throughput of the
corresponding instructions, similar to earlier commit
5cee5f94000 ("i386: correct integer division modeling in znver.md").

Division is partially pipelined and some instructions have fractional
throughput (e.g. Zen 3 can issue divss and divsd each 3.5 and 4.5
cycles on average, respectively). Considering these CPUs implement
out-of-order execution, the model doesn't need to be exact to the last
cycle, so simplify it by using 4/5 cycles for SF/DF modes, and not
modeling the fact that FP3 pipe is occupied for one cycle.

Top znver table sizes in insn-automata.o:

Before:

428108 r znver1_fp_min_issue_delay
856216 r znver1_fp_transitions

After:

30056 r znver1_fp_min_issue_delay
120224 r znver1_fp_transitions

gcc/ChangeLog:

PR target/87832
* config/i386/znver.md (znver1_fdiv): New automaton.
(znver1-fdiv): New unit.
(znver1_fp_op_div): Correct unit and cycles in the reservation.
(znver1_fp_op_div_load): Ditto.
(znver1_fp_op_idiv_load): Ditto.
(znver2_fp_op_idiv_load): Ditto.
(znver1_ssediv_ss_ps): Ditto.
(znver1_ssediv_ss_ps_load): Ditto.
(znver1_ssediv_sd_pd): Ditto.
(znver1_ssediv_sd_pd_load): Ditto.
(znver1_ssediv_avx256_ps): Ditto.
(znver1_ssediv_avx256_ps_load): Ditto.
(znver1_ssediv_avx256_pd): Ditto.
(znver1_ssediv_avx256_pd_load): Ditto.

2 years agolibstdc++: Fix std::any pretty printer
Jonathan Wakely [Wed, 16 Nov 2022 12:22:04 +0000 (12:22 +0000)]
libstdc++: Fix std::any pretty printer

The recent changes to FilteringTypePrinter affect the result of
gdb.lookup_type('std::string') in StdExpAnyPrinter, causing it to always
return the std::__cxx11::basic_string specialization. This then causes a
gdb.error exception when trying to lookup the std::any manager type for
a specliaization using that string, but that manager was never
instantiated in the program. This causes FAILs when running the tests
with -D_GLIBCXX_USE_CXX11_ABI=0:

FAIL: libstdc++-prettyprinters/libfundts.cc print as
FAIL: libstdc++-prettyprinters/libfundts.cc print as

The ugly solution used in this patch is to repeat the lookup for every
type that std::string could be a typedef for, and hope it only works for
one of them.

libstdc++-v3/ChangeLog:

* python/libstdcxx/v6/printers.py (StdExpAnyPrinter): Make
expansion of std::string in manager name more robust.

2 years agolibstdc++: Improve comments on pretty printer code
Jonathan Wakely [Wed, 16 Nov 2022 11:02:42 +0000 (11:02 +0000)]
libstdc++: Improve comments on pretty printer code

libstdc++-v3/ChangeLog:

* python/libstdcxx/v6/printers.py (is_specialization_of): Fix
incorrect terminology in docstring and describe arguments.
(FilteringTypePrinter): Add default argument for new parameter,
enhance docstring.

2 years agogcn: Add __builtin_gcn_kernarg_ptr
Tobias Burnus [Wed, 16 Nov 2022 13:24:01 +0000 (14:24 +0100)]
gcn: Add __builtin_gcn_kernarg_ptr

Add __builtin_gcn_kernarg_ptr to avoid using hard-coded register values
and permit future ABI changes while keeping the API.

gcc/ChangeLog:

* config/gcn/gcn-builtins.def (KERNARG_PTR): Add.
* config/gcn/gcn.cc (gcn_init_builtin_types): Change siptr_type_node,
sfptr_type_node and voidptr_type_node from FLAT to ADDR_SPACE_DEFAULT.
(gcn_expand_builtin_1): Handle GCN_BUILTIN_KERNARG_PTR.
(gcn_oacc_dim_size): Return in ADDR_SPACE_FLAT.

libgomp/ChangeLog:

* config/gcn/team.c (gomp_gcn_enter_kernel): Use
__builtin_gcn_kernarg_ptr instead of asm ("s8").

Co-Authored-By: Andrew Stubbs <ams@codesourcery.com>
2 years agoanalyzer: use known_function to simplify region_model::on_call_{pre,post}
David Malcolm [Wed, 16 Nov 2022 13:23:02 +0000 (08:23 -0500)]
analyzer: use known_function to simplify region_model::on_call_{pre,post}

Replace lots of repeated checks against strings with a hash_map lookup.
Add some missing type-checking for handling known functions (e.g. checks
for pointer types).

gcc/analyzer/ChangeLog:
* analyzer.h (known_function::matches_call_types_p): New vfunc.
(known_function::impl_call_pre): Provide base implementation.
(known_function::impl_call_post): New vfunc.
(register_known_functions): New.
* engine.cc (impl_run_checkers): Call register_known_functions.
* region-model-impl-calls.cc (region_model::impl_call_accept):
Convert to...
(class known_function_accept): ...this.
(region_model::impl_call_bind): Convert to...
(class known_function_bind): ...this.
(region_model::impl_call_connect): Convert to...
(class known_function_connect): ...this.
(region_model::impl_call_listen): Convert to...
(class known_function_listen): ...this.
(region_model::impl_call_socket): Convert to...
(class known_function_socket): ...this.
(register_known_functions): New.
* region-model.cc (region_model::on_call_pre): Remove special
case for "bind" in favor of the known_function-handling dispatch.
Add call to known_function::matches_call_types_p to latter.
(region_model::on_call_post): Remove special cases for "accept",
"bind", "connect", "listen", and "socket" in favor of dispatch
to known_function::impl_call_post.
* region-model.h (region_model::impl_call_accept): Delete decl.
(region_model::impl_call_bind): Delete decl.
(region_model::impl_call_connect): Delete decl.
(region_model::impl_call_listen): Delete decl.
(region_model::impl_call_socket): Delete decl.
* sm-fd.cc: Update comments.

gcc/testsuite/ChangeLog:
* gcc.dg/plugin/analyzer_kernel_plugin.c
(copy_across_boundary_fn::matches_call_types_p): New.
* gcc.dg/plugin/analyzer_known_fns_plugin.c
(known_function_returns_42::matches_call_types_p): New.
(known_function_attempt_to_copy::matches_call_types_p): New.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2 years agoanalyzer: split out checker-path.cc into a new checker-event.cc
David Malcolm [Wed, 16 Nov 2022 13:21:17 +0000 (08:21 -0500)]
analyzer: split out checker-path.cc into a new checker-event.cc

gcc/ChangeLog:
* Makefile.in (ANALYZER_OBJS): Add analyzer/checker-event.o.

gcc/analyzer/ChangeLog:
* checker-event.cc: New file, split out from...
* checker-path.cc: ...this file.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2 years agogcc: m68k: fix PR target/107645
Max Filippov [Wed, 9 Nov 2022 08:39:50 +0000 (00:39 -0800)]
gcc: m68k: fix PR target/107645

gcc/
PR target/107645
* config/m68k/predicates.md (symbolic_operand): Return false
when UNSPEC is under the CONST node.

2 years agodoc: invoke: pru/riscv: Fix option list formatting
Christoph Müllner [Tue, 15 Nov 2022 22:29:24 +0000 (23:29 +0100)]
doc: invoke: pru/riscv: Fix option list formatting

This patch fixes a wrong placed closing bracket in the RISC-V option
list and an unneeded @gol in the PRU option list in invoke.texi.

gcc/ChangeLog:

* doc/invoke.texi: Fix PRU/RISC-V option list formatting.

2 years agoc++: Implement CWG 2654 - Un-deprecation of compound volatile assignments
Jakub Jelinek [Wed, 16 Nov 2022 09:23:22 +0000 (10:23 +0100)]
c++: Implement CWG 2654 - Un-deprecation of compound volatile assignments

The following patch implements CWG 2654.

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

* typeck.cc (cp_build_modify_expr): Implement CWG 2654
- Un-deprecation of compound volatile assignments.  Remove
-Wvolatile warning about compound volatile assignments.

* g++.dg/cpp2a/volatile1.C (fn2, fn3, racoon): Adjust expected
diagnostics.
* g++.dg/cpp2a/volatile3.C (fn2, fn3, racoon): Likewise.
* g++.dg/cpp2a/volatile5.C (f): Likewise.
* g++.dg/ext/vector25.C (foo): Don't expect a warning.
* g++.dg/cpp1y/new1.C (test_unused): Likewise.

2 years agonvptx/mkoffload.cc: Fix "$nohost" check
Tobias Burnus [Wed, 16 Nov 2022 07:58:44 +0000 (08:58 +0100)]
nvptx/mkoffload.cc: Fix "$nohost" check

If lhd_set_decl_assembler_name is invoked - in particular if
!TREE_PUBLIC (decl) && !DECL_FILE_SCOPE_P (decl) - the '.nohost' suffix
might change to '.nohost.2'. This happens for the existing reverse offload
testcases via cgraph_node::analyze and is a side effect of
r13-3455-g178ac530fe67e4f2fc439cc4ce89bc19d571ca31 for some reason.

The solution is to not only check for a tailing '$nohost' but also for
'$nohost$' in nvptx/mkoffload.cc.

gcc/ChangeLog:

* config/nvptx/mkoffload.cc (process): Recognize '$nohost$...'
besides tailing '$nohost' as being for reverse offload.

2 years agoc++: Allow attributes on concepts - DR 2428
Jakub Jelinek [Wed, 16 Nov 2022 06:37:05 +0000 (07:37 +0100)]
c++: Allow attributes on concepts - DR 2428

The following patch adds parsing of attributes to concept definition,
allows deprecated attribute to be specified (as CONCEPT_DECL now needs
to be checked in c-family/c-attribs.cc, I had to move its declaration
from cp/*.def to c-family/*.def) and checks TREE_DEPRECATED in
build_standard_check (not sure if that is the right spot, or whether
it shouldn't be checked also for variable and function concepts and
how to write testcase coverage for that).

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

gcc/c-family/
* c-common.def (CONCEPT_DECL): New tree, moved here from
cp-tree.def.
* c-common.cc (c_common_init_ts): Handle CONCEPT_DECL.
* c-attribs.cc (handle_deprecated_attribute): Allow deprecated
attribute on CONCEPT_DECL.
gcc/cp/
* cp-tree.def (CONCEPT_DECL): Move to c-common.def.
* cp-objcp-common.cc (cp_common_init_ts): Don't handle CONCEPT_DECL
here.
* cp-tree.h (finish_concept_definition): Add ATTRS parameter.
* parser.cc (cp_parser_concept_definition): Parse attributes in
between identifier and =.  Adjust finish_concept_definition
caller.
* pt.cc (finish_concept_definition): Add ATTRS parameter.  Call
cplus_decl_attributes.
* constraint.cc (build_standard_check): If CONCEPT_DECL is
TREE_DEPRECATED, emit -Wdeprecated-declaration warnings.
gcc/testsuite/
* g++.dg/cpp2a/concepts-dr2428.C: New test.

2 years agoragen-op-float: Fix up float_binary_op_range_finish [PR107668]
Jakub Jelinek [Wed, 16 Nov 2022 06:30:07 +0000 (07:30 +0100)]
ragen-op-float: Fix up float_binary_op_range_finish [PR107668]

The following testcase ICEs, because when !HONOR_NANS but
HONOR_SIGNED_ZEROS, if we see
lhs = op1 * op2;
and know that lhs is [-0.0, 0.0] and op2 is [0.0, 0.0], the
division of these two yields UNDEFINED and clear_nan () on it
fails an assert.  With HONOR_NANS it would actually result in
a known NAN, but when NANs aren't honored, we clear the NAN bits.
Now, for the above case we actually don't know anything about
the op1 range (except that it isn't a NAN/INF because of
!HONOR_NANS !HONOR_INFINITIES), so I think the best is just
to return VARYING for the case we get UNDEFINED as well.

If we want, the op[12]_range methods perhaps can handle the
corner cases earlier separately, say for
lhs [0.0, 0.0] and op2 [0.0, 0.0] when HONOR_SIGNED_ZEROS this
would be just [0.0, MAX].

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

PR tree-optimization/107668
* range-op-float.cc (float_binary_op_range_finish): Set VARYING
also when r is UNDEFINED.

* gcc.dg/ubsan/pr107668.c: New test.

2 years agolibstdc++: Fix gdb FilteringTypePrinter
François Dumont [Wed, 5 Oct 2022 17:24:55 +0000 (19:24 +0200)]
libstdc++: Fix gdb FilteringTypePrinter

Once we found a matching FilteringTypePrinter instance we look for the associated
typedef and check that the returned Python Type is equal to the Type to recognize.
But gdb Python Type includes properties to distinguish a typedef from the actual
type. So use gdb.types.get_basic_type to check if we are indeed on the same type.

Additionnaly enhance FilteringTypePrinter matching mecanism by introducing targ1 that,
if not None, will be used as the 1st template parameter.

libstdc++-v3/ChangeLog:

* python/libstdcxx/v6/printers.py (FilteringTypePrinter): Rename 'match' field
'template'. Add self.targ1 to specify the first template parameter of the instantiation
to match.
(add_one_type_printer): Add targ1 optional parameter, default to None.
Use gdb.types.get_basic_type to compare the type to recognize and the type
returned from the typedef lookup.
(register_type_printers): Adapt calls to add_one_type_printers.

2 years agortl: Try to remove EH edges after {pro,epi}logue generation [PR90259]
Kewen Lin [Wed, 16 Nov 2022 02:26:07 +0000 (20:26 -0600)]
rtl: Try to remove EH edges after {pro,epi}logue generation [PR90259]

After prologue and epilogue generation, the judgement on whether
one memory access onto stack frame may trap or not could change,
since we get more exact stack information by now.

As PR90259 shows, some memory access becomes impossible to trap
any more after prologue and epilogue generation, it can make
subsequent optimization be able to remove it if safe, but it
results in unexpected control flow status due to REG_EH_REGION
note missing.

This patch proposes to try to remove EH edges with function
purge_all_dead_edges after prologue and epilogue generation,
it simplifies CFG as early as we can and don't need any fixup
in downstream passes.

CFG simplification result with PR90259's case as example:

*before*

   18: %1:TF=call [`__gcc_qdiv'] argc:0
      REG_EH_REGION 0x2
   77: NOTE_INSN_BASIC_BLOCK 3
   19: NOTE_INSN_DELETED
   20: NOTE_INSN_DELETED
  110: [%31:SI+0x20]=%1:DF
      REG_EH_REGION 0x2
  116: NOTE_INSN_BASIC_BLOCK 4
  111: [%31:SI+0x28]=%2:DF
      REG_EH_REGION 0x2
   22: NOTE_INSN_BASIC_BLOCK 5
  108: %0:DF=[%31:SI+0x20]
      REG_EH_REGION 0x2
  117: NOTE_INSN_BASIC_BLOCK 6
  109: %1:DF=[%31:SI+0x28]
      REG_EH_REGION 0x2
   79: NOTE_INSN_BASIC_BLOCK 7
   26: [%31:SI+0x18]=%0:DF
  104: pc=L69
  105: barrier

*after*

   18: %1:TF=call [`__gcc_qdiv'] argc:0
      REG_EH_REGION 0x2
   77: NOTE_INSN_BASIC_BLOCK 3
   19: NOTE_INSN_DELETED
   20: NOTE_INSN_DELETED
  110: [%31:SI+0x20]=%1:DF
  111: [%31:SI+0x28]=%2:DF
  108: %0:DF=[%31:SI+0x20]
  109: %1:DF=[%31:SI+0x28]
   26: [%31:SI+0x18]=%0:DF
  104: pc=L69
  105: barrier

PR rtl-optimization/90259

gcc/ChangeLog:

* function.cc (rest_of_handle_thread_prologue_and_epilogue): Add
parameter fun, and call function purge_all_dead_edges.
(pass_thread_prologue_and_epilogue::execute): Name unamed parameter
as fun, and use it for rest_of_handle_thread_prologue_and_epilogue.

gcc/testsuite/ChangeLog:

* g++.target/powerpc/pr90259.C: New.

2 years agoDaily bump.
GCC Administrator [Wed, 16 Nov 2022 00:17:09 +0000 (00:17 +0000)]
Daily bump.

2 years agoc++: Disable -Wignored-qualifiers for template args [PR107492]
Marek Polacek [Tue, 1 Nov 2022 15:49:03 +0000 (11:49 -0400)]
c++: Disable -Wignored-qualifiers for template args [PR107492]

It seems wrong to issue a -Wignored-qualifiers warning for code like:

  static_assert(!is_same_v<void(*)(), const void(*)()>);

because there the qualifier matters.  Likewise in template
specialization:

  template<typename T> struct S { };
  template<> struct S<void(*)()> { };
  template<> struct S<const void(*)()> { }; // OK, not a redefinition

And likewise in other type-id contexts such as trailing-return-type:

  auto g() -> const void (*)();

This patch limits the warning to the function declaration context only.

PR c++/107492

gcc/cp/ChangeLog:

* decl.cc (grokdeclarator): Only emit a -Wignored-qualifiers warning
when funcdecl_p.

gcc/testsuite/ChangeLog:

* g++.dg/warn/Wignored-qualifiers3.C: New test.

2 years agoRISC-V: Zihintpause: add __builtin_riscv_pause
Philipp Tomsich [Wed, 16 Dec 2020 23:44:11 +0000 (00:44 +0100)]
RISC-V: Zihintpause: add __builtin_riscv_pause

The Zihintpause extension uses an opcode from the 'fence' opcode range
to add a true hint instruction (i.e. if it is not supported on any
given platform, the 'fence' that is encoded will not enforce any
specific ordering on memory accesses) for entering a low-power state
(e.g. in an idle thread).  We expose this new instruction through a
machine-dependent builtin to allow generating it without a requirement
for any inline assembly.

Given that the encoding of 'pause' is valid (as a 'fence' encoding)
even for processors that do not (yet) support Zihintpause, we make
this builtin available without any further TARGET_* constraints.

gcc/ChangeLog:

* config/riscv/riscv-builtins.cc (struct riscv_builtin_description):
add the pause machine-dependent builtin with no result and no
arguments; mark it as always present (pause is a true hint
that encodes into a fence-insn, if not supported with the new
pause semantics).
* config/riscv/riscv-ftypes.def: Add type for void -> void.
* config/riscv/riscv.md (riscv_pause): Add risc_pause and
UNSPECV_PAUSE
* doc/extend.texi: Document __builtin_riscv_pause.
* optabs.cc (maybe_gen_insn): Allow nops == 0 (void -> void).

gcc/testsuite/ChangeLog:

* gcc.target/riscv/builtin_pause.c: New test.

2 years agobpf: avoid possible use of uninitialized variable
David Faust [Tue, 15 Nov 2022 17:21:51 +0000 (09:21 -0800)]
bpf: avoid possible use of uninitialized variable

Fix a maybe-uninitialized warning introduced in commit:
068baae1864 bpf: add preserve_field_info builtin

gcc/

* config/bpf/bpf.cc (bpf_expand_builtin): Avoid use of uninitialized
variable in error case.

2 years agoanalyzer: add warnings relating to sockets [PR106140]
David Malcolm [Tue, 15 Nov 2022 18:53:42 +0000 (13:53 -0500)]
analyzer: add warnings relating to sockets [PR106140]

This patch generalizes the analyzer's file descriptor state machine
so that it tracks the states of sockets.

It adds two new warnings relating to misuses of socket APIs:
* -Wanalyzer-fd-phase-mismatch (e.g. calling 'accept' on a socket
before calling 'listen' on it)
* -Wanalyzer-fd-type-mismatch (e.g. using a stream socket operation
on a datagram socket)

gcc/analyzer/ChangeLog:
PR analyzer/106140
* analyzer-language.cc (on_finish_translation_unit): Stash named
constants "SOCK_STREAM" and "SOCK_DGRAM".
* analyzer.opt (Wanalyzer-fd-phase-mismatch): New.
(Wanalyzer-fd-type-mismatch): New.
* engine.cc (impl_region_model_context::get_state_map_by_name):
Add "out_sm_context" param.  Allow out_sm_idx to be NULL.
* exploded-graph.h
(impl_region_model_context::get_state_map_by_name):
Add "out_sm_context" param.
* region-model-impl-calls.cc (region_model::impl_call_accept): New.
(region_model::impl_call_bind): New.
(region_model::impl_call_connect): New.
(region_model::impl_call_listen): New.
(region_model::impl_call_socket): New.
* region-model.cc (region_model::on_call_pre): Special-case
"bind".
(region_model::on_call_post): Special-case "accept", "bind",
"connect", "listen", and "socket".
* region-model.h (region_model::impl_call_accept): New decl.
(region_model::impl_call_bind): New decl.
(region_model::impl_call_connect): New decl.
(region_model::impl_call_listen): New decl.
(region_model::impl_call_socket): New decl.
(region_model::on_socket): New decl.
(region_model::on_bind): New decl.
(region_model::on_listen): New decl.
(region_model::on_accept): New decl.
(region_model::on_connect): New decl.
(region_model::add_constraint): Make public.
(region_model::check_for_poison): Make public.
(region_model_context::get_state_map_by_name): Add out_sm_context param.
(region_model_context::get_fd_map): Likewise.
(region_model_context::get_malloc_map): Likewise.
(region_model_context::get_taint_map): Likewise.
(noop_region_model_context::get_state_map_by_name): Likewise.
(region_model_context_decorator::get_state_map_by_name): Likewise.
* sm-fd.cc: Include "analyzer/supergraph.h" and
"analyzer/analyzer-language.h".
(enum expected_phase): New enum.
(fd_state_machine::m_new_datagram_socket): New.
(fd_state_machine::m_new_stream_socket): New.
(fd_state_machine::m_new_unknown_socket): New.
(fd_state_machine::m_bound_datagram_socket): New.
(fd_state_machine::m_bound_stream_socket): New.
(fd_state_machine::m_bound_unknown_socket): New.
(fd_state_machine::m_listening_stream_socket): New.
(fd_state_machine::m_m_connected_stream_socket): New.
(fd_state_machine::m_SOCK_STREAM): New.
(fd_state_machine::m_SOCK_DGRAM): New.
(fd_diagnostic::describe_state_change): Handle socket states.
(fd_diagnostic::get_meaning_for_state_change): Likewise.
(class fd_phase_mismatch): New.
(enum expected_type): New enum.
(class fd_type_mismatch): New.
(fd_state_machine::fd_state_machine): Initialize new states and
stashed named constants.
(fd_state_machine::is_socket_fd_p): New.
(fd_state_machine::is_datagram_socket_fd_p): New.
(fd_state_machine::is_stream_socket_fd_p): New.
(fd_state_machine::on_close): Handle the socket states.
(fd_state_machine::check_for_open_fd): Complain about fncalls on
sockets in the wrong phase.  Support socket FDs.
(add_constraint_ge_zero): New.
(fd_state_machine::get_state_for_socket_type): New.
(fd_state_machine::on_socket): New.
(fd_state_machine::check_for_socket_fd): New.
(fd_state_machine::check_for_new_socket_fd): New.
(fd_state_machine::on_bind): New.
(fd_state_machine::on_listen): New.
(fd_state_machine::on_accept): New.
(fd_state_machine::on_connect): New.
(fd_state_machine::can_purge_p): Don't purge socket values.
(get_fd_state): New.
(region_model::mark_as_valid_fd): Use get_fd_state.
(region_model::on_socket): New.
(region_model::on_bind): New.
(region_model::on_listen): New.
(region_model::on_accept): New.
(region_model::on_connect): New.
* sm-fd.dot: Update to reflect sm-fd.cc changes.

gcc/ChangeLog:
PR analyzer/106140
* doc/invoke.texi (Static Analyzer Options): Add
-Wanalyzer-fd-phase-mismatch and -Wanalyzer-fd-type-mismatch.  Add
"socket", "bind", "listen", "accept", and "connect" to the list of
functions known to the analyzer.

gcc/testsuite/ChangeLog:
PR analyzer/106140
* gcc.dg/analyzer/fd-accept.c: New test.
* gcc.dg/analyzer/fd-bind.c: New test.
* gcc.dg/analyzer/fd-connect.c: New test.
* gcc.dg/analyzer/fd-datagram-socket.c: New test.
* gcc.dg/analyzer/fd-glibc-byte-stream-connection-server.c: New test.
* gcc.dg/analyzer/fd-glibc-byte-stream-socket.c: New test.
* gcc.dg/analyzer/fd-glibc-datagram-client.c: New test.
* gcc.dg/analyzer/fd-glibc-datagram-socket.c: New test.
* gcc.dg/analyzer/fd-glibc-make_named_socket.h: New test.
* gcc.dg/analyzer/fd-listen.c: New test.
* gcc.dg/analyzer/fd-manpage-getaddrinfo-client.c: New test.
* gcc.dg/analyzer/fd-mappage-getaddrinfo-server.c: New test.
* gcc.dg/analyzer/fd-socket-meaning.c: New test.
* gcc.dg/analyzer/fd-socket-misuse.c: New test.
* gcc.dg/analyzer/fd-stream-socket-active-open.c: New test.
* gcc.dg/analyzer/fd-stream-socket-passive-open.c: New test.
* gcc.dg/analyzer/fd-stream-socket.c: New test.
* gcc.dg/analyzer/fd-symbolic-socket.c: New test.
* gcc.dg/analyzer/pr104369-1.c: Add -Wno-analyzer-too-complex and
-Wno-analyzer-fd-leak to options.
* gcc.dg/analyzer/pr104369-2.c: Add -Wno-analyzer-fd-leak to
options.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2 years agoc, analyzer: support named constants in analyzer [PR106302]
David Malcolm [Tue, 15 Nov 2022 18:53:42 +0000 (13:53 -0500)]
c, analyzer: support named constants in analyzer [PR106302]

The analyzer's file-descriptor state machine tracks the access mode of
opened files, so that it can emit -Wanalyzer-fd-access-mode-mismatch.

To do this, its symbolic execution needs to "know" the values of the
constants "O_RDONLY", "O_WRONLY", and "O_ACCMODE".  Currently
analyzer/sm-fd.cc simply uses these values directly from the build-time
header files, but these are the values on the host, not those from the
target, which could be different (PR analyzer/106302).

In an earlier discussion of this issue:
  https://gcc.gnu.org/pipermail/gcc/2022-June/238954.html
we talked about adding a target hook for this.

However, I've also been experimenting with extending the fd state
machine to track sockets (PR analyzer/106140).  For this, it's useful to
"know" the values of the constants "SOCK_STREAM" and "SOCK_DGRAM".
Unfortunately, these seem to have many arbitrary differences from target
to target.

For example: Linux/glibc general has SOCK_STREAM == 1, SOCK_DGRAM == 2,
as does AIX, but annoyingly, e.g. Linux on MIPS has them the other way
around.

It seems to me that as the analyzer grows more ambitious modeling of the
behavior of APIs (perhaps via plugins) it's more likely that the
analyzer will need to know the values of named constants, which might
not even exist on the host.

For example, at LPC it was suggested to me that -fanalyzer could check
rules about memory management inside the Linux kernel (probably via a
plugin), but doing so involves a bunch of GFP_* flags (see PR 107472).

So rather than trying to capture all this knowledge in a target hook,
this patch attempts to get at named constant values from the user's
source code.

The patch adds an interface for frontends to call into the analyzer as
the translation unit finishes.  The analyzer can then call back into the
frontend to ask about the values of the named constants it cares about
whilst the frontend's data structures are still around.

The patch implements this for the C frontend, which looks up the names
by looking for named CONST_DECLs (which handles enum values).  Failing
that, it attempts to look up the values of macros but only the simplest
cases are supported (a non-traditional macro with a single CPP_NUMBER
token).  It does this by building a buffer containing the macro
definition and rerunning a lexer on it.

The analyzer gracefully handles the cases where named values aren't
found (such as anything more complicated than described above).

The patch ports the analyzer to use this mechanism for "O_RDONLY",
"O_WRONLY", and "O_ACCMODE".  I have successfully tested my socket patch
to also use this for "SOCK_STREAM" and "SOCK_DGRAM", so the technique
seems to work.

gcc/ChangeLog:
PR analyzer/106302
* Makefile.in (ANALYZER_OBJS): Add analyzer/analyzer-language.o.
(GTFILES): Add analyzer/analyzer-language.cc.
* doc/analyzer.texi: Document __analyzer_dump_named_constant.

gcc/analyzer/ChangeLog:
PR analyzer/106302
* analyzer-language.cc: New file.
* analyzer-language.h: New file.
* analyzer.h (get_stashed_constant_by_name): New decl.
(log_stashed_constants): New decl.
* engine.cc (impl_run_checkers): Call log_stashed_constants.
* region-model-impl-calls.cc
(region_model::impl_call_analyzer_dump_named_constant): New.
* region-model.cc (region_model::on_stmt_pre): Handle
__analyzer_dump_named_constant.
* region-model.h
(region_model::impl_call_analyzer_dump_named_constant): New decl.
* sm-fd.cc (fd_state_machine::m_O_ACCMODE): New.
(fd_state_machine::m_O_RDONLY): New.
(fd_state_machine::m_O_WRONLY): New.
(fd_state_machine::fd_state_machine): Initialize the new fields.
(fd_state_machine::get_access_mode_from_flag): Use the new fields,
rather than using the host values.

gcc/c/ChangeLog:
PR analyzer/106302
* c-parser.cc: Include "analyzer/analyzer-language.h" and "toplev.h".
(class ana::c_translation_unit): New.
(c_parser_translation_unit): Call ana::on_finish_translation_unit.

gcc/testsuite/ChangeLog:
* gcc.dg/analyzer/analyzer-decls.h
(__analyzer_dump_named_constant): New decl.
* gcc.dg/analyzer/fd-4.c (void): Likewise.
(O_ACCMODE): Define.
* gcc.dg/analyzer/fd-access-mode-enum.c: New test, based on .
* gcc.dg/analyzer/fd-5.c: ...this.  Rename to...
* gcc.dg/analyzer/fd-access-mode-macros.c: ...this.
(O_ACCMODE): Define.
* gcc.dg/analyzer/fd-access-mode-target-headers.c: New test, also
based on fd-5.c.
(test_sm_fd_constants): New.
* gcc.dg/analyzer/fd-dup-1.c (O_ACCMODE): Define.
* gcc.dg/analyzer/named-constants-via-enum.c: New test.
* gcc.dg/analyzer/named-constants-via-enum-and-macro.c: New test.
* gcc.dg/analyzer/named-constants-via-macros-2.c: New test.
* gcc.dg/analyzer/named-constants-via-macros.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2 years agodemangler: Templated lambda demangling
Nathan Sidwell [Mon, 7 Nov 2022 16:24:14 +0000 (11:24 -0500)]
demangler: Templated lambda demangling

Templated lambdas have a template-head, which is part of their
signature.  GCC ABI 18 mangles that into the lambda name.  This adds
support to the demangler.  We have to introduce artificial template
parameter names, as we need to refer to them from later components of
the lambda signature. We use $T:n, $N:n and $TT:n for type, non-type
and template parameters.  Non-type parameter names are not shown in
the strictly correct location -- for instance 'int (&NT) ()' would be
shown as 'int (&) $N:n'.  That's unfortunate, but an orthogonal issue.
The 'is_lambda_arg' field is now repurposed as indicating the number
of explicit template parameters (1-based).

include/
* demangle.h (enum demangle_component_type): Add
DEMANGLE_COMPONENT_TEMPLATE_HEAD,
DEMANGLE_COMPONENT_TEMPLATE_TYPE_PARM,
DEMANGLE_COMPONENT_TEMPLATE_NON_TYPE_PARM,
DEMANGLE_COMPONENT_TEMPLATE_TEMPLATE_PARM,
DEMANGLE_COMPONENT_TEMPLATE_PACK_PARM.
libiberty/
* cp-demangle.c (struct d_print_info): Rename is_lambda_arg to
lambda_tpl_parms.  Augment semantics.
(d_make_comp): Add checks for new components.
(d_template_parm, d_template_head): New.
(d_lambda): Add templated lambda support.
(d_print_init): Adjust.
(d_print_lambda_parm_name): New.
(d_print_comp_inner): Support templated lambdas,
* testsuite/demangle-expected: Add testcases.

2 years agodiagnostics: Remove null-termination requirement for json::string
Lewis Hyatt [Fri, 4 Nov 2022 16:50:06 +0000 (12:50 -0400)]
diagnostics: Remove null-termination requirement for json::string

json::string currently handles null-terminated data and so can't work with
data that may contain embedded null bytes or that is not null-terminated.
Supporting such data will make json::string more robust in some contexts, such
as SARIF output, which uses it to output user source code that may contain
embedded null bytes.

gcc/ChangeLog:

* json.h (class string): Add M_LEN member to store the length of
the data.  Add constructor taking an explicit length.
* json.cc (string::string):  Implement the new constructor.
(string::print): Support printing strings that are not
null-terminated.  Escape embdedded null bytes on output.
(test_writing_strings): Test the new null-byte-related features of
json::string.

2 years agodiagnostics: Use an inline function rather than hardcoding <built-in> string
Lewis Hyatt [Tue, 1 Nov 2022 22:43:10 +0000 (18:43 -0400)]
diagnostics: Use an inline function rather than hardcoding <built-in> string

The string "<built-in>" is hard-coded in several places throughout the
diagnostics code, and in some of those places, it is used incorrectly with
respect to internationalization. (Comparing a translated string to an
untranslated string.) The error is not currently observable in any output GCC
actually produces, hence no testcase added here, but it's worth fixing, and
also, I am shortly going to add a new such string and want to avoid hardcoding
that one in similar places.

gcc/c-family/ChangeLog:

* c-opts.cc (c_finish_options): Use special_fname_builtin () rather
than a hard-coded string.

gcc/ChangeLog:

* diagnostic.cc (diagnostic_get_location_text): Use
special_fname_builtin () rather than a hardcoded string (which was
also incorrectly left untranslated previously.)
* input.cc (special_fname_builtin): New function.
(expand_location_1): Use special_fname_builtin () rather than a
hard-coded string.
(test_builtins): Likewise.
* input.h (special_fname_builtin): Declare.

gcc/fortran/ChangeLog:

* cpp.cc (gfc_cpp_init): Use special_fname_builtin () rather than a
hardcoded string (which was also incorrectly left untranslated
previously.)
* error.cc (gfc_diagnostic_build_locus_prefix): Likewise.
* f95-lang.cc (gfc_init): Likewise.

2 years agodiagnostics: Fix macro tracking for ad-hoc locations
Lewis Hyatt [Tue, 1 Nov 2022 21:50:27 +0000 (17:50 -0400)]
diagnostics: Fix macro tracking for ad-hoc locations

The result of linemap_resolve_location() can be an ad-hoc location, if that is
what was stored in a relevant macro map.  maybe_unwind_expanded_macro_loc()
did not previously handle this case, causing it to print the wrong tracking
information for an example such as the new testcase macro-trace-1.c.  Fix that
by checking for ad-hoc locations where needed.

gcc/ChangeLog:

* tree-diagnostic.cc (maybe_unwind_expanded_macro_loc): Handle ad-hoc
location in return value of linemap_resolve_location().

gcc/testsuite/ChangeLog:

* c-c++-common/cpp/macro-trace-1.c: New test.

2 years agolibsanitizer: update LOCAL_PATCHES
Martin Liska [Tue, 15 Nov 2022 15:45:21 +0000 (16:45 +0100)]
libsanitizer: update LOCAL_PATCHES

libsanitizer/ChangeLog:

* LOCAL_PATCHES: Update local patches.

2 years agoasan: update expected format based on ASAN
Martin Liska [Tue, 15 Nov 2022 11:02:36 +0000 (12:02 +0100)]
asan: update expected format based on ASAN

gcc/testsuite/ChangeLog:

* c-c++-common/asan/global-overflow-1.c: Update
expected format.
* c-c++-common/asan/heap-overflow-1.c: Likewise.
* c-c++-common/asan/strlen-overflow-1.c: Likewise.
* c-c++-common/asan/strncpy-overflow-1.c: Likewise.
* c-c++-common/hwasan/heap-overflow.c: Likewise.
* g++.dg/asan/asan_mem_test.cc: Likewise.
* g++.dg/asan/asan_oob_test.cc: Likewise.
* g++.dg/asan/asan_str_test.cc: Likewise.
* g++.dg/asan/asan_test.cc: Likewise.
* g++.dg/asan/large-func-test-1.C: Likewise.

2 years agolibsanitizer: Apply local patches
Martin Liska [Thu, 5 May 2022 10:52:44 +0000 (12:52 +0200)]
libsanitizer: Apply local patches

2 years agolibsanitizer: merge from upstream ae59131d3ef311fb4b1e50627c6457be00e60dc9
Martin Liska [Tue, 15 Nov 2022 10:11:41 +0000 (11:11 +0100)]
libsanitizer: merge from upstream ae59131d3ef311fb4b1e50627c6457be00e60dc9

2 years agolibatomic: Add support for LSE and LSE2
Wilco Dijkstra [Tue, 15 Nov 2022 14:38:55 +0000 (14:38 +0000)]
libatomic: Add support for LSE and LSE2

Add support for AArch64 LSE and LSE2 to libatomic.  Disable outline atomics,
and use LSE ifuncs for 1-8 byte atomics and LSE2 ifuncs for 16-byte atomics.
On Neoverse V1, 16-byte atomics are ~4x faster due to avoiding locks.

Note this is safe since we swap all 16-byte atomics using the same ifunc,
so they either use locks or LSE2 atomics, but never a mix. This also improves
ABI compatibility with LLVM: its inlined 16-byte atomics are compatible with
the new libatomic if LSE2 is supported.

libatomic/
* Makefile.in: Regenerated with automake 1.15.1.
* Makefile.am: Add atomic_16.S for AArch64.
* configure.tgt: Disable outline atomics in AArch64 build.
* config/linux/aarch64/atomic_16.S: New file - implementation of
ifuncs for 16-byte atomics.
* config/linux/aarch64/host-config.h: Enable ifuncs, use LSE
(HWCAP_ATOMICS) for 1-8-byte atomics and LSE2 (HWCAP_USCAT) for
16-byte atomics.

2 years agoc++: remove i_c_e_p parm from tsubst_copy_and_build
Patrick Palka [Tue, 15 Nov 2022 14:32:21 +0000 (09:32 -0500)]
c++: remove i_c_e_p parm from tsubst_copy_and_build

It seems the only and original purpose of tsubst_copy_and_build's
integral_constant_expression_p boolean parameter (added in r116276, which
predates the constexpr machinery) is to diagnose certain constructs that
aren't allowed to appear in a C++98 integral constant expression
context, specifically casts to a non-integral type (diagnosed from the
*_CAST_EXPR case of tsubst_copy_and_build) or dependent names that
resolve to a non-constant decl (diagnosed from the IDENTIFIER_NODE case
of tsubst_copy_and_build).  The parameter has no effect outside of C++98
AFAICT.

But diagnosing such constructs should arguably be the job of the constexpr
machinery (e.g. is_constant_expression) after substitution, and doing it
during substitution by way of an additional parameter complicates the
API of this workhorse function for what amounts to a couple of archaic
C++98 restrictions.  And it seems is_constant_expression already does a
good job of diagnosing the aforementioned two constructs in C++98 mode,
at least as far as our testsuite is concerned.

So this patch removes this parameter from tsubst_copy_and_build,
tsubst_expr and tsubst_copy_and_build_call_args.  The only interesting
changes are to potential_constant_expression_1 and the IDENTIFIER_NODE
and *_CAST_EXPR cases of tsubst_copy_and_build; the rest are mechanical
adjustments to the functions' signatures and their call sites.

gcc/cp/ChangeLog:

* constexpr.cc (potential_constant_expression_1)
<case *_CAST_EXPR>: Use
cast_valid_in_integral_constant_expression_p instead of
open coding it.
* constraint.cc (tsubst_valid_expression_requirement): Adjust
calls to tsubst_copy_and_build and tsubst_expr.
(tsubst_constraint): Likewise.
(satisfy_atom): Likewise.
(diagnose_trait_expr): Likewise.
* cp-tree.h (tsubst_copy_and_build): Remove i_c_e_p parameter.
(tsubst_expr): Likewise.
* init.cc (get_nsdmi): Adjust calls to tsubst_copy_and_build
and tsubst_expr.
* pt.cc (expand_integer_pack): Likewise.
(instantiate_non_dependent_expr_internal): Likewise.
(tsubst_friend_function): Likewise.
(tsubst_attribute): Likewise.
(instantiate_class_template): Likewise.
(tsubst_template_arg): Likewise.
(gen_elem_of_pack_expansion_instantiation): Likewise.
(tsubst_fold_expr_init): Likewise.
(tsubst_pack_expansion): Likewise.
(tsubst_default_argument): Likewise.
(tsubst_function_decl): Likewise.
(tsubst_decl): Likewise.
(tsubst_arg_types): Likewise.
(tsubst_exception_specification): Likewise.
(tsubst): Likewise.
(tsubst_init): Likewise.
(tsubst_copy): Likewise.
(tsubst_omp_clause_decl): Likewise.
(tsubst_omp_clauses): Likewise.
(tsubst_copy_asm_operands): Likewise.
(tsubst_omp_for_iterator): Likewise.
(tsubst_expr): Likewise.  Remove i_c_e_p parameter.
(tsubst_omp_udr): Likewise.
(tsubst_non_call_postfix_expression): Likewise.  Remove i_c_e_p parameter.
(tsubst_lambda_expr): Likewise.
(tsubst_copy_and_build_call_args): Likewise.
(tsubst_copy_and_build): Likewise.  Remove i_c_e_p parameter.
<case IDENTIFIER_NODE>: Adjust call to finish_id_expression
following removal of i_c_e_p.
<case *_CAST_EXPR>: Remove C++98-specific cast validity check
guarded by i_c_e_p.
(maybe_instantiate_noexcept): Adjust calls to
tsubst_copy_and_build and tsubst_expr.
(instantiate_body): Likewise.
(instantiate_decl): Likewise.
(tsubst_initializer_list): Likewise.
(tsubst_enum): Likewise.

gcc/objcp/ChangeLog:

* objcp-lang.cc (objcp_tsubst_copy_and_build): Adjust calls to
tsubst_copy_and_build and tsubst_expr.

gcc/testsuite/ChangeLog:

* g++.dg/template/crash55.C: Don't expect additional
C++98-specific diagnostics.
* g++.dg/template/ref3.C: Remove C++98-specific xfail.

2 years agoc++: remove function_p parm from tsubst_copy_and_build
Patrick Palka [Tue, 15 Nov 2022 14:31:54 +0000 (09:31 -0500)]
c++: remove function_p parm from tsubst_copy_and_build

The function_p parameter of tsubst_copy_and_build (added in r69316) is
inspected only in its IDENTIFIER_NODE case, where it controls whether we
diagnose unqualified name lookup failure for the given identifier.  But
I think ever since r173965, we never substitute an IDENTIFIER_NODE with
function_p=true for which the lookup can possibly fail, and therefore
the flag is effectively unneeded.

Before that commit, we would incorrectly repeat unqualified lookup for
an ADL-enabled CALL_EXPR at instantiation time, which naturally could
fail and thus motivated the flag.  Afterwards, we no longer substitute
an IDENTIFIER_NODE callee when koenig_p is true, so the flag isn't needed
for its original purpose.  What about when koenig_p=false?  Apparently
we still may have an IDENTIFIER_NODE callee in this case, namely when
unqualified name lookup found a dependent local function declaration,
but repeating that lookup can't fail (ditto for USING_DECL callees).

So this patch removes this effectively unneeded parameter from
tsubst_copy_and_build.  It also updates an outdated comment in the
CALL_EXPR case about when we may see an IDENTIFIER_NODE callee with
koenig_p=false.

gcc/cp/ChangeLog:

* cp-lang.cc (objcp_tsubst_copy_and_build): Remove
function_p parameter.
* cp-objcp-common.h (objcp_tsubst_copy_and_build):
Likewise.
* cp-tree.h (tsubst_copy_and_build): Likewise.
* init.cc (get_nsdmi): Adjust calls to tsubst_copy_and_build.
* pt.cc (expand_integer_pack): Likewise.
(instantiate_non_dependent_expr_internal): Likewise.
(tsubst_function_decl): Likewise.
(tsubst_arg_types): Likewise.
(tsubst_exception_specification): Likewise.
(tsubst): Likewise.
(tsubst_copy_asm_operands): Likewise.
(tsubst_expr): Likewise.
(tsubst_non_call_postfix_expression): Likewise.
(tsubst_lambda_expr): Likewise.
(tsubst_copy_and_build_call_args): Likewise.
(tsubst_copy_and_build): Remove function_p parameter
and adjust function comment.  Adjust recursive calls.
<case CALL_EXPR>: Update outdated comment about when
we can see an IDENTIFIER_NODE callee with koenig_p=false.
(maybe_instantiate_noexcept): Adjust calls to
tsubst_copy_and_build.

gcc/objcp/ChangeLog:

* objcp-lang.cc (objcp_tsubst_copy_and_build): Remove
function_p parameter.

2 years agolibstdc++: Fix std::format test for strict -std=c++20 mode
Jonathan Wakely [Tue, 15 Nov 2022 14:24:57 +0000 (14:24 +0000)]
libstdc++: Fix std::format test for strict -std=c++20 mode

Adjust a test to avoid using std::make_unsigned_t<__int128>. That's
ill-formed in strict modes because std::is_integral_v<__int128> is
false.

libstdc++-v3/ChangeLog:

* testsuite/std/format/functions/format.cc: Do not use
std::make_unsigned_t<__int128>.

2 years agolibstc++: std::formattable concept should not be defined for C++20
Jonathan Wakely [Tue, 15 Nov 2022 13:59:51 +0000 (13:59 +0000)]
libstc++: std::formattable concept should not be defined for C++20

This concept was added by a C++23 proposal, so don't define it for
C++20.

Split the format/formatter/formatter.cc test into two parts, one that
tests the C++20 requirements and one that tests the C++23 concept.

libstdc++-v3/ChangeLog:

* include/std/format (formattable): Only define for C++23/
* testsuite/std/format/formatter.cc: Moved to...
* testsuite/std/format/formatter/requirements.cc: ...here.
* testsuite/std/format/formatter/concept.cc: New test.
* testsuite/std/format/functions/format.cc: Replace use of
std::formattable in C++20.

2 years agolibstdc++: Fix detection of std::format support for __float128 [PR107693]
Jonathan Wakely [Tue, 15 Nov 2022 13:44:38 +0000 (13:44 +0000)]
libstdc++: Fix detection of std::format support for __float128 [PR107693]

std::format gives linker errors on targets that define __float128 but
do not support using it with std::to_chars. This improves the handling
of 128-bit flaoting-point types so they are disabled if unsupportable.

libstdc++-v3/ChangeLog:

PR libstdc++/107693
* include/std/format (_GLIBCXX_FORMAT_F128): Define to 2 when
basic_format_arg needs to use its _M_f128 member.
(__extended_floating_point, __floating_point): Replace with ...
(__formattable_floating_point): New concept.
* testsuite/std/format/functions/format.cc: Check whether
__float128 is supported. Also test _Float128.

2 years agolibsanitizer: use git clone --depth 1
Martin Liska [Tue, 15 Nov 2022 13:18:27 +0000 (14:18 +0100)]
libsanitizer: use git clone --depth 1

Using depth == 1 it makes the cloning much faster.

libsanitizer/ChangeLog:

* merge.sh: Use git clone --depth 1.

2 years agoRevert "docs: Fix expected diagnostics URL [PR107599]"
Martin Liska [Tue, 15 Nov 2022 12:51:25 +0000 (13:51 +0100)]
Revert "docs: Fix expected diagnostics URL [PR107599]"

This reverts commit f94c2eff6b0e000ee2feadedf354590958308760.

2 years agolibstdc++: Document use of Markdown for Doxygen comments
Jonathan Wakely [Tue, 15 Nov 2022 11:34:46 +0000 (11:34 +0000)]
libstdc++: Document use of Markdown for Doxygen comments

libstdc++-v3/ChangeLog:

* doc/xml/manual/documentation_hacking.xml: Document use of
Markdown for Doxygen comments. Tweak formatting.
* doc/html/manual/documentation_hacking.html: Regenerate.

2 years agodoc: Format region pragmas as separate items
Jonathan Wakely [Mon, 14 Nov 2022 09:19:13 +0000 (09:19 +0000)]
doc: Format region pragmas as separate items

This seems consistent with how other paired pragmas are documented in
texinfo, e.g. push_options and pop_options.

gcc/ChangeLog:

* doc/cpp.texi (Pragmas): Use @item and @itemx for region
pragmas.

2 years agoira: Remove duplicate `memset' over `full_costs' from `assign_hard_reg'
Maciej W. Rozycki [Tue, 15 Nov 2022 11:23:02 +0000 (11:23 +0000)]
ira: Remove duplicate `memset' over `full_costs' from `assign_hard_reg'

Remove duplicate clearing of `full_costs' made in `assign_hard_reg',
which has been there since the beginning, i.e. commit 058e97ecf33a
("IRA has been merged into trunk"),
<https://gcc.gnu.org/ml/gcc-patches/2008-08/msg01932.html>.

gcc/
* ira-color.cc (assign_hard_reg): Remove duplicate `memset' over
`full_costs'.

2 years agoaarch64: Add support for widening LDAPR instructions
Andre Vieira [Tue, 15 Nov 2022 09:50:46 +0000 (09:50 +0000)]
aarch64: Add support for widening LDAPR instructions

gcc/ChangeLog:

* config/aarch64/atomics.md
(*aarch64_atomic_load<ALLX:mode>_rcpc_zext): New pattern.
(*aarch64_atomic_load<ALLX:mode>_rcpc_sext): New pattern.

gcc/testsuite/ChangeLog:
* gcc.target/aarch64/ldapr-ext.c: New test.

2 years agoaarch64: Enable the use of LDAPR for load-acquire semantics
Andre Vieira [Tue, 15 Nov 2022 09:50:39 +0000 (09:50 +0000)]
aarch64: Enable the use of LDAPR for load-acquire semantics

This patch enables the use of LDAPR for load-acquire semantics.

2022-11-15  Andre Vieira  <andre.simoesdiasvieira@arm.com>
    Kyrylo Tkachov  <kyrylo.tkachov@arm.com>

gcc/ChangeLog:

* config/aarch64/aarch64.h (AARCH64_ISA_RCPC): New Macro.
(TARGET_RCPC): New Macro.
* config/aarch64/atomics.md (atomic_load<mode>): Change into an expand.
(aarch64_atomic_load<mode>_rcpc): New define_insn for ldapr.
(aarch64_atomic_load<mode>): Rename of old define_insn for ldar.
* config/aarch64/iterators.md (UNSPEC_LDAP): New unspec enum value.
* doc/invoke.texi (rcpc): Ammend documentation to mention the effects
on code generation.

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/ldapr.c: New test.

2 years agogcc-changelog: revert temporary rule relaxation
Martin Liska [Tue, 15 Nov 2022 08:34:50 +0000 (09:34 +0100)]
gcc-changelog: revert temporary rule relaxation

contrib/ChangeLog:

* gcc-changelog/git_commit.py: Revert temporary rule
relaxation.

2 years agoDaily bump.
GCC Administrator [Tue, 15 Nov 2022 08:32:29 +0000 (08:32 +0000)]
Daily bump.

2 years agoc++: Fix a typo in function name
Jakub Jelinek [Tue, 15 Nov 2022 07:17:11 +0000 (08:17 +0100)]
c++: Fix a typo in function name

I've noticed I've made a typo in the name of the function.
Fixed thusly.

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

* cp-tree.h (next_common_initial_seqence): Rename to ...
(next_common_initial_sequence): ... this.
* typeck.cc (next_common_initial_seqence): Rename to ...
(next_common_initial_sequence): ... this.
(layout_compatible_type_p): Call next_common_initial_sequence
rather than next_common_initial_seqence.
* semantics.cc (is_corresponding_member_aggr): Likewise.

2 years agolibatomic: Handle AVX+CX16 AMD like Intel for 16b atomics [PR104688]
Jakub Jelinek [Tue, 15 Nov 2022 07:14:45 +0000 (08:14 +0100)]
libatomic: Handle AVX+CX16 AMD like Intel for 16b atomics [PR104688]

We got a response from AMD in
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104688#c10
so the following patch starts treating AMD with AVX and CMPXCHG16B
ISAs like Intel by using vmovdqa for atomic load/store in libatomic.
We still don't have confirmation from Zhaoxin and VIA (anything else
with CPUs featuring AVX and CX16?).

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

PR target/104688
* config/x86/init.c (__libat_feat1_init): Don't clear
bit_AVX on AMD CPUs.

2 years agoc++: Add testcase for DR 2392
Jakub Jelinek [Tue, 15 Nov 2022 07:13:06 +0000 (08:13 +0100)]
c++: Add testcase for DR 2392

The testcase from DR 2392 passes, so I assume we don't need to do
anything further for the DR.

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

* g++.dg/DRs/dr2392.C: Add testcase for DR 2392.

2 years agoc++: Implement C++23 P2589R1 - - static operator[]
Jakub Jelinek [Tue, 15 Nov 2022 07:00:21 +0000 (08:00 +0100)]
c++: Implement C++23 P2589R1 - - static operator[]

Here is a patch that implements the static operator[] paper.
One thing that doesn't work properly is the same problem as I've filed
yesterday for static operator() - PR107624 - that side-effects of
the postfix-expression on which the call or subscript operator are
applied are thrown away, I assume we have to add them into COMPOUND_EXPR
somewhere after we find out that the we've chosen a static member function
operator.

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

gcc/c-family/
* c-cppbuiltin.cc (c_cpp_builtins): Bump C++23
__cpp_multidimensional_subscript macro value to 202211L.
gcc/cp/
* decl.cc (grok_op_properties): Implement C++23 P2589R1
- static operator[].  Handle operator[] similarly to operator()
- allow static member functions, but pedwarn on it for C++20 and
older.  Unlike operator(), perform rest of checks on it though for
C++20.
* call.cc (add_operator_candidates): For operator[] with class
typed first parameter, pass that parameter as first_arg and
an adjusted arglist without that parameter.
gcc/testsuite/
* g++.dg/cpp23/subscript9.C: New test.
* g++.dg/cpp23/feat-cxx2b.C: Expect a newer
__cpp_multidimensional_subscript value.
* g++.old-deja/g++.bugs/900210_10.C: Don't expect an error
for C++23 or later.

2 years agoc++: Add testcase for DR 2604
Jakub Jelinek [Tue, 15 Nov 2022 06:57:42 +0000 (07:57 +0100)]
c++: Add testcase for DR 2604

As the following testcase shows, I think we don't inherit template's
attributes into specializations.

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

* g++.dg/DRs/dr2604.C: New test.

2 years agoOptimize VEC_PERM_EXPR with same permutation index and operation
Hongyu Wang [Mon, 17 Jan 2022 05:01:51 +0000 (13:01 +0800)]
Optimize VEC_PERM_EXPR with same permutation index and operation

The sequence
     c1 = VEC_PERM_EXPR (a, a, mask)
     c2 = VEC_PERM_EXPR (b, b, mask)
     c3 = c1 op c2
can be optimized to
     c = a op b
     c3 = VEC_PERM_EXPR (c, c, mask)
for all integer vector operation, and float operation with
full permutation.

gcc/ChangeLog:

PR target/98167
* match.pd: New perm + vector op patterns for int and fp vector.

gcc/testsuite/ChangeLog:

PR target/98167
* gcc.target/i386/pr98167.c: New test.

2 years agoRemove Score documentation
Andrew Pinski [Tue, 15 Nov 2022 04:59:51 +0000 (04:59 +0000)]
Remove Score documentation

Score target support was removed in r5-3909-g3daa7bbf791203
but it looks like some of the documentation was missed.
This removes it.

Committed as obvious after a "make html".

Thanks,
Andrew

gcc/ChangeLog:

* doc/invoke.texi: Remove Score option section.

2 years agoRemove the picoChip documentation
Andrew Pinski [Tue, 15 Nov 2022 04:42:20 +0000 (04:42 +0000)]
Remove the picoChip documentation

PicoChip support was removed in r5-3431-g157e859ffe3b5d but the
documentation was missed it seems.

Committed as obvious after running "make html" to make sure the
building of the documentation still works.

Thanks,
Andrew Pinski

gcc/ChangeLog:

* doc/extend.texi: Remove picoChip builtin section.
* doc/invoke.texi: Remove picoChip option section.

2 years agoRemove documentation for MeP
Andrew Pinski [Tue, 15 Nov 2022 04:35:57 +0000 (04:35 +0000)]
Remove documentation for MeP

MeP support was removed in r7-1614-g0609abdad81e26
but it looks like the documentation for the target
was missed.

Committed as obvious after doing "make html" to
make sure the documentation is fine.

Thanks,
Andrew Pinski

gcc/ChangeLog:

* doc/extend.texi: Remove MeP documentation.
* doc/invoke.texi: Remove MeP Options documentation.

2 years agoFix @opindex for mcall-aixdesc and mcall-openbsd
Andrew Pinski [Tue, 15 Nov 2022 04:16:57 +0000 (04:16 +0000)]
Fix @opindex for mcall-aixdesc and mcall-openbsd

For mcall-aixdesc, the opindex was just m which was wrong.
For mcall-openbsd, the opindex was mcall-netbsd which was wrong.
This two have been broken since the options were added to the documentation
back in r0-92913-g244609a618b094 .

Committed as obvious after a "make html" and checking the options index.

Thanks,
Andrew

gcc/ChangeLog:

* doc/invoke.texi: Fix opindex for mcall-aixdesc and mcall-openbsd.

2 years agoc++: init_priority and SUPPORTS_INIT_PRIORITY [PR107638]
Patrick Palka [Tue, 15 Nov 2022 02:28:58 +0000 (21:28 -0500)]
c++: init_priority and SUPPORTS_INIT_PRIORITY [PR107638]

The commit r13-3706-gd0a492faa6478c for fixing the result of
__has_attribute(init_priority) causes a bootstrap failure on hppa64-hpux
due to assuming the macro SUPPORTS_INIT_PRIORITY expands to a simple
constant, but on this target the macro is defined as

  #define SUPPORTS_INIT_PRIORITY (TARGET_GNU_LD ? 1 : 0)

(where TARGET_GNU_LD expands to something in terms of global_options)
which means we can't use the macro to conditionally exclude the entry
for init_priority when defining the cxx_attribute_table.

So instead of trying to exclude init_priority from the attribute table,
this patch just makes __has_attribute handle init_priority specially.

PR c++/107638

gcc/c-family/ChangeLog:

* c-lex.cc (c_common_has_attribute): Return 1 for init_priority
iff SUPPORTS_INIT_PRIORITY.

gcc/cp/ChangeLog:

* tree.cc (cxx_attribute_table): Don't conditionally exclude
the init_priority entry.
(handle_init_priority_attribute): Remove ATTRIBUTE_UNUSED.
Return error_mark_node if !SUPPORTS_INIT_PRIORITY.

2 years agoc++: Disable -Wdangling-reference when initing T&
Marek Polacek [Fri, 11 Nov 2022 17:01:54 +0000 (12:01 -0500)]
c++: Disable -Wdangling-reference when initing T&

Non-const lvalue references can't bind to a temporary, so the
warning should not be emitted if we're initializing something of that
type.  I'm not disabling the warning when the function itself returns
a non-const lvalue reference, that would regress at least

  const int &r = std::any_cast<int&>(std::any());

in Wdangling-reference2.C where the any_cast returns an int&.

Unfortunately, this patch means we'll stop diagnosing

  int& fn(int&& x) { return static_cast<int&>(x); }
  void test ()
  {
    int &r = fn(4);
  }

where there's a genuine dangling reference.  OTOH, the patch
should suppress false positives with iterators, like:

  auto &candidate = *candidates.begin ();

and arguably that's more important than detecting some relatively
obscure cases.  It's probably not worth it making the warning more
complicated by, for instance, not warning when a fn returns 'int&'
but takes 'const int&' (because then it can't return its argument).

gcc/cp/ChangeLog:

* call.cc (maybe_warn_dangling_reference): Don't warn when initializing
a non-const lvalue reference.

gcc/testsuite/ChangeLog:

* g++.dg/cpp23/elision4.C: Remove dg-warning.
* g++.dg/warn/Wdangling-reference1.C: Turn dg-warning into dg-bogus.
* g++.dg/warn/Wdangling-reference7.C: New test.

2 years agoRevert "RISC-V: Add basic support for the Ventana-VT1 core"
Philipp Tomsich [Mon, 14 Nov 2022 23:50:49 +0000 (00:50 +0100)]
Revert "RISC-V: Add basic support for the Ventana-VT1 core"

This reverts commit b4fca4fc70dc76cf18406fd2b046c834d976aa90.

2 years agoRevert "RISC-V: Add instruction fusion (for ventana-vt1)"
Philipp Tomsich [Mon, 14 Nov 2022 23:50:44 +0000 (00:50 +0100)]
Revert "RISC-V: Add instruction fusion (for ventana-vt1)"

This reverts commit 991cfe5b30cb06611aa03d8c67860552785faba8.

2 years agoc++: only declare satisfied friends
Jason Merrill [Fri, 11 Nov 2022 10:45:02 +0000 (00:45 -1000)]
c++: only declare satisfied friends

A friend declaration can only have constraints if it is defined.  If
multiple instantiations of a class template define the same friend function
signature, it's an error, but that shouldn't happen if it's constrained to
only be declared in one instantiation.

Currently we don't mangle requirements, so the foos all mangle the same and
actually instantiating #1 will break, but for now we can test that they're
considered distinct.

gcc/cp/ChangeLog:

* pt.cc (tsubst_friend_function): Check satisfaction.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/concepts-friend11.C: New test.

2 years agoira: Fix `create_insn_allocnos' `outer' parameter documentation
Maciej W. Rozycki [Mon, 14 Nov 2022 22:02:11 +0000 (22:02 +0000)]
ira: Fix `create_insn_allocnos' `outer' parameter documentation

The parameter of `create_insn_allocnos' for any parent expression of `x'
has always been called `outer' rather than `parent', just as added by
commit d1bb282efbf9 ("Fix for "FAIL: tmpdir-gcc.dg-struct-layout-1/t028
c_compat_x_tst.o compile, (internal compiler error)""),
<https://gcc.gnu.org/ml/gcc-patches/2014-09/msg02611.html>.  Correct
inline documentation accordingly.

gcc/
* ira-build.cc (create_insn_allocnos): Fix documentation.

2 years agomiddle-end: Fix addsub patch removing return statements
Tamar Christina [Mon, 14 Nov 2022 20:09:07 +0000 (20:09 +0000)]
middle-end: Fix addsub patch removing return statements

My recent patch had return statements in the match.pd expressions
which were recently outlawed.. Unfornately I didn't rebase this
patch before committing so this broke the build.

I've just reflowed the conditions to avoid the returns.

gcc/ChangeLog:

* match.pd: Remove returns.

2 years agoriscv: bitmanip: add orc.b as an unspec
Philipp Tomsich [Thu, 27 May 2021 15:20:05 +0000 (17:20 +0200)]
riscv: bitmanip: add orc.b as an unspec

As a basis for optimized string functions (e.g., the by-pieces
implementations), we need orc.b available.  This adds orc.b as an
unspec, so we can expand to it.

gcc/ChangeLog:

* config/riscv/bitmanip.md (orcb<mode>2): Add orc.b as an
  unspec.
* config/riscv/riscv.md: Add UNSPEC_ORC_B.

Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu>
2 years agomiddle-end: Fix can_special_div_by_const doc.
Tamar Christina [Mon, 14 Nov 2022 18:50:39 +0000 (18:50 +0000)]
middle-end: Fix can_special_div_by_const doc.

This commits the typo fix so it matches the tm.texi file and fix the bootstrap.

gcc/ChangeLog:

* target.def: Fix typo.

2 years agoRISC-V: Add instruction fusion (for ventana-vt1)
Philipp Tomsich [Sun, 14 Nov 2021 21:56:19 +0000 (22:56 +0100)]
RISC-V: Add instruction fusion (for ventana-vt1)

The Ventana VT1 core supports quad-issue and instruction fusion.
This implemented TARGET_SCHED_MACRO_FUSION_P to keep fusible sequences
together and adds idiom matcheing for the supported fusion cases.

gcc/ChangeLog:

* config/riscv/riscv.cc (enum riscv_fusion_pairs): Add symbolic
constants to identify supported fusion patterns.
(struct riscv_tune_param): Add fusible_op field.
(riscv_macro_fusion_p): Implement.
(riscv_fusion_enabled_p): Implement.
(riscv_macro_fusion_pair_p): Implement and recognize fusible
idioms for Ventana VT1.
(TARGET_SCHED_MACRO_FUSION_P): Point to riscv_macro_fusion_p.
(TARGET_SCHED_MACRO_FUSION_PAIR_P): Point to
riscv_macro_fusion_pair_p.

2 years agoRISC-V: Add basic support for the Ventana-VT1 core
Philipp Tomsich [Sun, 14 Nov 2021 21:56:11 +0000 (22:56 +0100)]
RISC-V: Add basic support for the Ventana-VT1 core

The Ventana-VT1 core is compatible with rv64gc, Zb[abcs], Zifenci and
XVentanaCondOps.
This introduces a placeholder -mcpu=ventana-vt1, so tooling and
scripts don't need to change once full support (pipeline, tuning,
etc.) will become public later.

gcc/ChangeLog:

* config/riscv/riscv-cores.def (RISCV_TUNE): Add ventana-vt1.
(RISCV_CORE): Ditto.
* config/riscv/riscv-opts.h (enum riscv_microarchitecture_type): Ditto.
* config/riscv/riscv.cc: Add tune_info for ventana-vt1.
* doc/invoke.texi: Document -mcpu= and -mtune with ventana-vt1.

2 years agoaarch64: Add support for +cssc
Kyrylo Tkachov [Mon, 14 Nov 2022 18:05:26 +0000 (18:05 +0000)]
aarch64: Add support for +cssc

This patch adds codegen for FEAT_CSSC from the 2022 Architecture extensions.
It fits various existing optabs in GCC quite well.
There are instructions for scalar signed/unsigned min/max, abs, ctz, popcount.
We have expanders for these already, so they are wired up to emit single-insn
patterns for the new TARGET_CSSC.

These instructions are enabled by the +cssc command-line extension.
Bootstrapped and tested on aarch64-none-linux-gnu.

gcc/ChangeLog:

* config/aarch64/aarch64-option-extensions.def (cssc): Define.
* config/aarch64/aarch64.h (AARCH64_ISA_CSSC): Define.
(TARGET_CSSC): Likewise.
* config/aarch64/aarch64.md (*aarch64_abs<mode>2_cssc_ins): New define_insn.
(abs<mode>2): Adjust for the above.
(aarch64_umax<mode>3_insn): New define_insn.
(umax<mode>3): Adjust for the above.
(*aarch64_popcount<mode>2_cssc_insn): New define_insn.
(popcount<mode>2): Adjust for the above.
(<optab><mode>3): New define_insn.
* config/aarch64/constraints.md (Usm): Define.
(Uum): Likewise.
* doc/invoke.texi (AArch64 options): Document +cssc.
* config/aarch64/iterators.md (MAXMIN_NOUMAX): New code iterator.
* config/aarch64/predicates.md (aarch64_sminmax_immediate): Define.
(aarch64_sminmax_operand): Likewise.
(aarch64_uminmax_immediate): Likewise.
(aarch64_uminmax_operand): Likewise.

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/cssc_1.c: New test.
* gcc.target/aarch64/cssc_2.c: New test.
* gcc.target/aarch64/cssc_3.c: New test.
* gcc.target/aarch64/cssc_4.c: New test.
* gcc.target/aarch64/cssc_5.c: New test.

2 years agoAArch64: Add SVE2 implementation for pow2 bitmask division
Tamar Christina [Mon, 14 Nov 2022 15:53:42 +0000 (15:53 +0000)]
AArch64: Add SVE2 implementation for pow2 bitmask division

In plenty of image and video processing code it's common to modify pixel values
by a widening operation and then scale them back into range by dividing by 255.

This patch adds an named function to allow us to emit an optimized sequence
when doing an unsigned division that is equivalent to:

   x = y / (2 ^ (bitsize (y)/2)-1)

For SVE2 this means we generate for:

void draw_bitmap1(uint8_t* restrict pixel, uint8_t level, int n)
{
  for (int i = 0; i < (n & -16); i+=1)
    pixel[i] = (pixel[i] * level) / 0xff;
}

the following:

        mov     z3.b, #1
.L3:
        ld1b    z0.h, p0/z, [x0, x3]
        mul     z0.h, p1/m, z0.h, z2.h
        addhnb  z1.b, z0.h, z3.h
        addhnb  z0.b, z0.h, z1.h
        st1b    z0.h, p0, [x0, x3]
        inch    x3
        whilelo p0.h, w3, w2
        b.any   .L3

instead of:

.L3:
        ld1b    z0.h, p1/z, [x0, x3]
        mul     z0.h, p0/m, z0.h, z1.h
        umulh   z0.h, p0/m, z0.h, z2.h
        lsr     z0.h, z0.h, #7
        st1b    z0.h, p1, [x0, x3]
        inch    x3
        whilelo p1.h, w3, w2
        b.any   .L3

Which results in significantly faster code.

gcc/ChangeLog:

* config/aarch64/aarch64-sve2.md (@aarch64_bitmask_udiv<mode>3): New.

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/sve2/div-by-bitmask_1.c: New test.

2 years agoAArch64: Add implementation for pow2 bitmask division.
Tamar Christina [Mon, 14 Nov 2022 15:52:26 +0000 (15:52 +0000)]
AArch64: Add implementation for pow2 bitmask division.

This adds an implementation for the new optab for unsigned pow2 bitmask for
AArch64.

The implementation rewrites:

   x = y / (2 ^ (sizeof (y)/2)-1

into e.g. (for bytes)

   (x + ((x + 257) >> 8)) >> 8

where it's required that the additions be done in double the precision of x
such that we don't lose any bits during an overflow.

Essentially the sequence decomposes the division into doing two smaller
divisions, one for the top and bottom parts of the number and adding the results
back together.

To account for the fact that shift by 8 would be division by 256 we add 1 to
both parts of x such that when 255 we still get 1 as the answer.

Because the amount we shift are half the original datatype we can use the
halfing instructions the ISA provides to do the operation instead of using
actual shifts.

For AArch64 this means we generate for:

void draw_bitmap1(uint8_t* restrict pixel, uint8_t level, int n)
{
  for (int i = 0; i < (n & -16); i+=1)
    pixel[i] = (pixel[i] * level) / 0xff;
}

the following:

movi    v3.16b, 0x1
umull2  v1.8h, v0.16b, v2.16b
umull   v0.8h, v0.8b, v2.8b
addhn   v5.8b, v1.8h, v3.8h
addhn   v4.8b, v0.8h, v3.8h
uaddw   v1.8h, v1.8h, v5.8b
uaddw   v0.8h, v0.8h, v4.8b
uzp2    v0.16b, v0.16b, v1.16b

instead of:

umull   v2.8h, v1.8b, v5.8b
umull2  v1.8h, v1.16b, v5.16b
umull   v0.4s, v2.4h, v3.4h
umull2  v2.4s, v2.8h, v3.8h
umull   v4.4s, v1.4h, v3.4h
umull2  v1.4s, v1.8h, v3.8h
uzp2    v0.8h, v0.8h, v2.8h
uzp2    v1.8h, v4.8h, v1.8h
shrn    v0.8b, v0.8h, 7
shrn2   v0.16b, v1.8h, 7

Which results in significantly faster code.

Thanks for Wilco for the concept.

gcc/ChangeLog:

* config/aarch64/aarch64-simd.md (@aarch64_bitmask_udiv<mode>3): New.
* config/aarch64/aarch64.cc (aarch64_vectorize_can_special_div_by_constant): New.

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/div-by-bitmask.c: New test.

2 years agomiddle-end: Support not decomposing specific divisions during vectorization.
Tamar Christina [Mon, 14 Nov 2022 15:43:48 +0000 (15:43 +0000)]
middle-end: Support not decomposing specific divisions during vectorization.

In plenty of image and video processing code it's common to modify pixel values
by a widening operation and then scale them back into range by dividing by 255.

e.g.:

   x = y / (2 ^ (bitsize (y)/2)-1

This patch adds a new target hook can_special_div_by_const, similar to
can_vec_perm which can be called to check if a target will handle a particular
division in a special way in the back-end.

The vectorizer will then vectorize the division using the standard tree code
and at expansion time the hook is called again to generate the code for the
division.

Alot of the changes in the patch are to pass down the tree operands in all paths
that can lead to the divmod expansion so that the target hook always has the
type of the expression you're expanding since the types can change the
expansion.

gcc/ChangeLog:

* expmed.h (expand_divmod): Pass tree operands down in addition to RTX.
* expmed.cc (expand_divmod): Likewise.
* explow.cc (round_push, align_dynamic_address): Likewise.
* expr.cc (force_operand, expand_expr_divmod): Likewise.
* optabs.cc (expand_doubleword_mod, expand_doubleword_divmod):
Likewise.
* target.h: Include tree-core.
* target.def (can_special_div_by_const): New.
* targhooks.cc (default_can_special_div_by_const): New.
* targhooks.h (default_can_special_div_by_const): New.
* tree-vect-generic.cc (expand_vector_operation): Use it.
* doc/tm.texi.in: Document it.
* doc/tm.texi: Regenerate.
* tree-vect-patterns.cc (vect_recog_divmod_pattern): Check for support.
* tree-vect-stmts.cc (vectorizable_operation): Likewise.

gcc/testsuite/ChangeLog:

* gcc.dg/vect/vect-div-bitmask-1.c: New test.
* gcc.dg/vect/vect-div-bitmask-2.c: New test.
* gcc.dg/vect/vect-div-bitmask-3.c: New test.
* gcc.dg/vect/vect-div-bitmask.h: New file.

2 years agomiddle-end: Add optimized float addsub without needing VEC_PERM_EXPR.
Tamar Christina [Mon, 14 Nov 2022 15:42:42 +0000 (15:42 +0000)]
middle-end: Add optimized float addsub without needing VEC_PERM_EXPR.

For IEEE 754 floating point formats we can replace a sequence of alternative
+/- with fneg of a wider type followed by an fadd.  This eliminated the need for
using a permutation.  This patch adds a math.pd rule to recognize and do this
rewriting.

For

void f (float *restrict a, float *restrict b, float *res, int n)
{
   for (int i = 0; i < (n & -4); i+=2)
    {
      res[i+0] = a[i+0] + b[i+0];
      res[i+1] = a[i+1] - b[i+1];
    }
}

we generate:

.L3:
        ldr     q1, [x1, x3]
        ldr     q0, [x0, x3]
        fneg    v1.2d, v1.2d
        fadd    v0.4s, v0.4s, v1.4s
        str     q0, [x2, x3]
        add     x3, x3, 16
        cmp     x3, x4
        bne     .L3

now instead of:

.L3:
        ldr     q1, [x0, x3]
        ldr     q2, [x1, x3]
        fadd    v0.4s, v1.4s, v2.4s
        fsub    v1.4s, v1.4s, v2.4s
        tbl     v0.16b, {v0.16b - v1.16b}, v3.16b
        str     q0, [x2, x3]
        add     x3, x3, 16
        cmp     x3, x4
        bne     .L3

Thanks to George Steed for the idea.

gcc/ChangeLog:

* generic-match-head.cc: Include langooks.
* gimple-match-head.cc: Likewise.
* match.pd: Add fneg/fadd rule.

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/simd/addsub_1.c: New test.
* gcc.target/aarch64/sve/addsub_1.c: New test.

2 years agolibstdc++: Fix installation of python files for debug lib
Jonathan Wakely [Mon, 14 Nov 2022 10:37:58 +0000 (10:37 +0000)]
libstdc++: Fix installation of python files for debug lib

libstdc++-v3/ChangeLog:

* python/Makefile.am (install-data-local): Use mkdirs_p for debug
libdir.
* python/Makefile.in: Regenerate.

2 years agoarm: Add support for Cortex-X1C CPU.
Srinath Parvathaneni [Mon, 14 Nov 2022 15:45:59 +0000 (15:45 +0000)]
arm: Add support for Cortex-X1C CPU.

This patch adds the -mcpu support for the Arm Cortex-X1C CPU.

gcc/ChangeLog:

2022-11-09  Srinath Parvathaneni  <srinath.parvathaneni@arm.com>

* config/arm/arm-cpus.in (cortex-x1c): Define new CPU.
* config/arm/arm-tables.opt: Regenerate.
* config/arm/arm-tune.md: Likewise.
* doc/invoke.texi: Document Cortex-X1C CPU.

gcc/testsuite/ChangeLog:

2022-11-09  Srinath Parvathaneni  <srinath.parvathaneni@arm.com>

* gcc.target/arm/multilib.exp: Add tests for Cortex-X1C.

2 years agoaarch64: Add support for Cortex-X3 CPU.
Srinath Parvathaneni [Mon, 14 Nov 2022 15:18:26 +0000 (15:18 +0000)]
aarch64: Add support for Cortex-X3 CPU.

This patch adds support for Cortex-X3 CPU.

gcc/ChangeLog:

2022-11-09  Srinath Parvathaneni  <srinath.parvathaneni@arm.com>

* config/aarch64/aarch64-cores.def (AARCH64_CORE): Add Cortex-X3
CPU.
* config/aarch64/aarch64-tune.md: Regenerate.
* doc/invoke.texi: Document Cortex-X3 CPU.

2 years agoFix @opindex for m80387
Andrew Pinski [Mon, 14 Nov 2022 15:21:36 +0000 (15:21 +0000)]
Fix @opindex for m80387

I noticed that the opindex for -m80387
option was wrong. It was just 80387 which
was not consistent with the rest of the options.
This fixes that and uses "@opindex m80387".

Committed as obvious after  "make html" and checking
the option index page.

gcc/ChangeLog:

* doc/invoke.texi: Fix @opindex
for m80387 option.

2 years agoFix some @opindex with - in the front
Andrew Pinski [Mon, 14 Nov 2022 15:02:10 +0000 (15:02 +0000)]
Fix some @opindex with - in the front

I noticed this during the conversion of the docs
to sphinx that some options in the option index had a -
in the front of it for the texinfo docs. When the sphinx
conversion was reverted, I thought I would fix the texinfo
documentation for these options.

Committed as obvious after doing "make html" to check
the resulting option index page.

gcc/ChangeLog:

* doc/invoke.texi: Remove the front - from
some @opindex.

2 years agoaarch64: Add support for Ampere-1A (-mcpu=ampere1a) CPU
Philipp Tomsich [Mon, 7 Nov 2022 13:22:21 +0000 (14:22 +0100)]
aarch64: Add support for Ampere-1A (-mcpu=ampere1a) CPU

This patch adds support for Ampere-1A CPU:
 - recognize the name of the core and provide detection for -mcpu=native,
 - updated extra_costs,
 - adds a new fusion pair for (A+B+1 and A-B-1).

Ampere-1A and Ampere-1 have more timing difference than the extra
costs indicate, but these don't propagate through to the headline
items in our extra costs (e.g. the change in latency for scalar sqrt
doesn't have a corresponding table entry).

gcc/ChangeLog:

* config/aarch64/aarch64-cores.def (AARCH64_CORE): Add ampere1a.
* config/aarch64/aarch64-cost-tables.h: Add ampere1a_extra_costs.
* config/aarch64/aarch64-fusion-pairs.def (AARCH64_FUSION_PAIR):
Define a new fusion pair for A+B+1/A-B-1 (i.e., add/subtract two
registers and then +1/-1).
* config/aarch64/aarch64-tune.md: Regenerate.
* config/aarch64/aarch64.cc (aarch_macro_fusion_pair_p): Implement
idiom-matcher for the new fusion pair.
* doc/invoke.texi: Add ampere1a.

2 years agoada: Silence CodePeer false positive
Boris Yakobowski [Wed, 9 Nov 2022 13:02:00 +0000 (14:02 +0100)]
ada: Silence CodePeer false positive

gcc/ada/

* sem_case.adb: silence false positive warning emitted by CodePeer
on predefined equality for type Choice_Range_Info.