platform/upstream/gcc.git
2 years agoc: Do not use *_IS_IEC_60559 == 2
Joseph Myers [Thu, 13 Oct 2022 01:13:36 +0000 (01:13 +0000)]
c: Do not use *_IS_IEC_60559 == 2

A late change for C2x (addressing comments from the second round of
editorial review before the CD ballot, postdating the most recent
public working draft) removed the value 2 for *_IS_IEC_60559 (a new
<float.h> macro added in C2x).  Adjust the implementation accordingly
not to use this value.

Bootstrapped with no regressions for x86_64-pc-linux-gnu.

gcc/
* ginclude/float.h (FLT_IS_IEC_60559, DBL_IS_IEC_60559)
(LDBL_IS_IEC_60559): Update comment.

gcc/c-family/
* c-cppbuiltin.cc (builtin_define_float_constants): Do not use
value 2 for *_IS_IEC_60559.

gcc/testsuite/
* gcc.dg/c2x-float-10.c: Do not expect value 2 for *_IS_IEC_60559.

2 years agoDaily bump.
GCC Administrator [Thu, 13 Oct 2022 00:17:37 +0000 (00:17 +0000)]
Daily bump.

2 years agopreprocessor: Fix tracking of system header state [PR60014,PR60723]
Lewis Hyatt [Thu, 6 Oct 2022 22:05:02 +0000 (18:05 -0400)]
preprocessor: Fix tracking of system header state [PR60014,PR60723]

The token_streamer class (which implements gcc mode -E and
-save-temps/-no-integrated-cpp) needs to keep track whether the last tokens
output were in a system header, so that it can generate line marker
annotations as necessary for a downstream consumer to reconstruct the
state. The logic for tracking it, which was added by r5-1863 to resolve
PR60723, has some edge case issues as revealed by the three new test
cases. The first, coming from the original PR60014, was incidentally fixed by
r9-1926 for unrelated reasons. The other two were still failing on master
prior to this commit. Such code paths were not realizable prior to r13-1544,
which made it possible for the token streamer to see CPP_PRAGMA tokens in more
contexts.

The two main issues being corrected here are:

1) print.prev_was_system_token needs to indicate whether the previous token
output was in a system location. However, it was not being set on every token,
only on those that triggered the main code path; specifically it was not
triggered on a CPP_PRAGMA token. Testcase 2 covers this case.

2) The token_streamer uses a variable "line_marker_emitted" to remember
whether a line marker has been emitted while processing a given token, so that
it wouldn't be done more than once in case multiple conditions requiring a
line marker are true. There was no reason for this to be a member variable
that retains its value from token to token, since it is just needed for
tracking the state locally while processing a single given token. The fact
that it could retain its value for a subsequent token is rather difficult to
observe, but testcase 3 demonstrates incorrect behavior resulting from
that. Moving this to a local variable also simplifies understanding the
control flow going forward.

gcc/c-family/ChangeLog:

PR preprocessor/60014
PR preprocessor/60723
* c-ppoutput.cc (class token_streamer): Remove member
line_marker_emitted to...
(token_streamer::stream): ...a local variable here. Set
print.prev_was_system_token on all code paths.

gcc/testsuite/ChangeLog:

PR preprocessor/60014
PR preprocessor/60723
* gcc.dg/cpp/pr60014-1.c: New test.
* gcc.dg/cpp/pr60014-1.h: New test.
* gcc.dg/cpp/pr60014-2.c: New test.
* gcc.dg/cpp/pr60014-2.h: New test.
* gcc.dg/cpp/pr60014-3.c: New test.
* gcc.dg/cpp/pr60014-3.h: New test.

2 years agolibstdc++: Add __gnu_debug::basic_string<>::compare overloads
François Dumont [Wed, 10 Aug 2022 17:35:41 +0000 (19:35 +0200)]
libstdc++: Add __gnu_debug::basic_string<>::compare overloads

Rather than adding those implementations we are adding a:
using _Base::compare;

so that any compare method not implemented at __gnu_debug::basic_string
level are injected from the base class.

Also review how __gnu_debug::basic_string is tested. Now require to define
_GLIBCXX_TEST_DEBUG_STRING when running 'make check-debug'.

libstdc++-v3/ChangeLog

* include/debug/string: Add using _Base::compare.
(__gnu_debug::basic_string<>::compare(const basic_string<>&)): Remove.
(__gnu_debug::basic_string<>::compare(size_type, size_type, const basic_string<>&)):
Remove.
(__gnu_debug::basic_string<>::compare(size_type, size_type, const basic_string<>&,
size_type, size_type)): Remove.
* testsuite/util/testsuite_string.h [_GLIBCXX_TEST_DEBUG_STRING]: Include <debug/string>.
* testsuite/21_strings/basic_string/operations/compare/char/1.cc: Include testsuite_string.h
and use __gnu_test::string.
* testsuite/21_strings/basic_string/operations/compare/char/13650.cc: Likewise.
* testsuite/21_strings/basic_string/operations/compare/char/2.cc: Likewise.
* testsuite/21_strings/basic_string/operations/rfind/char/1.cc: Likewise.
* testsuite/21_strings/basic_string/operations/rfind/char/2.cc: Likewise.
* testsuite/21_strings/basic_string/operations/rfind/char/3.cc: Likewise.
* testsuite/21_strings/basic_string/operations/compare/wchar_t/1.cc:
Include testsuite_string.h
and use __gnu_test::wstring.
* testsuite/21_strings/basic_string/operations/compare/wchar_t/13650.cc: Likewise.
* testsuite/21_strings/basic_string/operations/compare/wchar_t/2.cc: Likewise.

2 years agoc++: Remove maybe-rvalue OR in implicit move
Marek Polacek [Wed, 28 Sep 2022 14:37:34 +0000 (10:37 -0400)]
c++: Remove maybe-rvalue OR in implicit move

This patch removes the two-stage overload resolution when performing
implicit move, whereby the compiler does two separate overload resolutions:
one treating the operand as an rvalue, and then (if that resolution fails)
another one treating the operand as an lvalue.  In the standard this was
introduced via CWG 1579 and implemented in gcc in r251035.  In r11-2412,
we disabled the fallback OR in C++20 (but not in C++17).  Then C++23 P2266
removed the fallback overload resolution, and changed the implicit move rules
once again.  So we wound up with three different behaviors.

The two overload resolutions approach was complicated and quirky, so
users should transition to the newer model.  Removing the maybe-rvalue
OR also allows us to simplify our code, for instance, now we can get
rid of LOOKUP_PREFER_RVALUE altogether.

This change means that code that previously didn't compile in C++17 will
now compile, for example:

  struct S1 { S1(S1 &&); };
  struct S2 : S1 {};

  S1
  f (S2 s)
  {
    return s; // OK, derived-to-base, use S1::S1(S1&&)
  }

And conversely, code that used to work in C++17 may not compile anymore:

  struct W {
    W();
  };

  struct F {
    F(W&);
    F(W&&) = delete;
  };

  F fn ()
  {
    W w;
    return w; // use w as rvalue -> use of deleted function F::F(W&&)
  }

I plan to add a note to porting_to.html.

gcc/cp/ChangeLog:

* call.cc (standard_conversion): Remove LOOKUP_PREFER_RVALUE code.
(reference_binding): Honor clk_implicit_rval even pre-C++20.
(implicit_conversion_1): Remove LOOKUP_PREFER_RVALUE code.
(build_user_type_conversion_1): Likewise.
(convert_like_internal): Likewise.
(build_over_call): Likewise.
* cp-tree.h (LOOKUP_PREFER_RVALUE): Remove.
(LOOKUP_NO_NARROWING): Adjust definition.
* except.cc (build_throw): Don't perform two overload resolutions.
* typeck.cc (maybe_warn_pessimizing_move): Don't use
LOOKUP_PREFER_RVALUE.
(check_return_expr): Don't perform two overload resolutions.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/Wredundant-move10.C: Adjust dg-warning.
* g++.dg/cpp0x/Wredundant-move7.C: Likewise.
* g++.dg/cpp0x/move-return2.C: Remove dg-error.
* g++.dg/cpp0x/move-return4.C: Likewise.
* g++.dg/cpp0x/ref-qual20.C: Adjust expected return value.
* g++.dg/cpp0x/move-return5.C: New test.

2 years agoAdd range-op entry for floating point NEGATE_EXPR.
Aldy Hernandez [Tue, 11 Oct 2022 15:23:42 +0000 (17:23 +0200)]
Add range-op entry for floating point NEGATE_EXPR.

gcc/ChangeLog:

* range-op-float.cc (class foperator_negate): New.
(floating_op_table::floating_op_table): Add NEGATE_EXPR
(range_op_float_tests): Add negate tests.

2 years agoFortran: check types of operands of arithmetic binary operations [PR107217]
Harald Anlauf [Tue, 11 Oct 2022 20:08:48 +0000 (22:08 +0200)]
Fortran: check types of operands of arithmetic binary operations [PR107217]

gcc/fortran/ChangeLog:

PR fortran/107217
* arith.cc (gfc_arith_plus): Compare consistency of types of operands.
(gfc_arith_minus): Likewise.
(gfc_arith_times): Likewise.
(gfc_arith_divide): Likewise.
(arith_power): Check that both operands are of numeric type.

gcc/testsuite/ChangeLog:

PR fortran/107217
* gfortran.dg/pr107217.f90: New test.

2 years agolibgomp: Fix up OpenMP 5.2 feature bullet
Jakub Jelinek [Wed, 12 Oct 2022 16:43:58 +0000 (18:43 +0200)]
libgomp: Fix up OpenMP 5.2 feature bullet

The previous bullet correctly mentions 5.2 added for Fortran
allocators directive which is a replacement of allocate directive
associated with ALLOCATE statement to differentiate it at parse time
from allocate directive as declarative one not associated with ALLOCATE
statement, but the deprecation bullet talks about non-existing allocator
directive.

2022-10-12  Jakub Jelinek  <jakub@redhat.com>

* libgomp.texi (OpenMP 5.2): Fix up allocator -> allocate directive
in deprecation bullet.

2 years agolibgomp: Add omp_in_explicit_task support
Jakub Jelinek [Wed, 12 Oct 2022 16:39:20 +0000 (18:39 +0200)]
libgomp: Add omp_in_explicit_task support

This is pretty straightforward, if gomp_thread ()->task is NULL,
it can't be explicit task, otherwise if
gomp_thread ()->task->kind == GOMP_TASK_IMPLICIT, it is an implicit
task, otherwise explicit task.

2022-10-12  Jakub Jelinek  <jakub@redhat.com>

* omp.h.in (omp_in_explicit_task): Declare.
* omp_lib.h.in (omp_in_explicit_task): Likewise.
* omp_lib.f90.in (omp_in_explicit_task): New interface.
* libgomp.map (OMP_5.2): New symbol version, export
omp_in_explicit_task and omp_in_explicit_task_.
* task.c (omp_in_explicit_task): New function.
* fortran.c (omp_in_explicit_task): Add ialias_redirect.
(omp_in_explicit_task_): New function.
* libgomp.texi (OpenMP 5.2): Mark omp_in_explicit_task as implemented.
* testsuite/libgomp.c-c++-common/task-in-explicit-1.c: New test.
* testsuite/libgomp.c-c++-common/task-in-explicit-2.c: New test.
* testsuite/libgomp.c-c++-common/task-in-explicit-3.c: New test.

2 years agolibgomp: Fix up creation of artificial teams
Jakub Jelinek [Wed, 12 Oct 2022 15:54:08 +0000 (17:54 +0200)]
libgomp: Fix up creation of artificial teams

When not in explicit parallel/target/teams construct, we in some cases create
an artificial parallel with a single thread (either to handle target nowait
or for task reduction purposes).  In those cases, it handled again artificially
created implicit task (created by gomp_new_icv for cases where we needed to write
to some ICVs), but as the testcases show, didn't take into account possibility
of this being done from explicit task(s).  The code would destroy/free the previous
task and replace it with the new implicit task.  If task is an explicit task
(when teams is NULL, all explicit tasks behave like if (0)), it is a pointer to
a local stack variable, so freeing it doesn't work, and additionally we shouldn't
lose the explicit tasks - the new implicit task should instead replace the
ancestor task which is the first implicit one.

2022-10-12  Jakub Jelinek  <jakub@redhat.com>

* task.c (gomp_create_artificial_team): Fix up handling of invocations
from within explicit task.
* target.c (GOMP_target_ext): Likewise.
* testsuite/libgomp.c/task-7.c: New test.
* testsuite/libgomp.c/task-8.c: New test.
* testsuite/libgomp.c-c++-common/task-reduction-17.c: New test.
* testsuite/libgomp.c-c++-common/task-reduction-18.c: New test.

2 years agoc++: defer all consteval in default args [DR2631]
Jason Merrill [Sat, 8 Oct 2022 00:34:53 +0000 (20:34 -0400)]
c++: defer all consteval in default args [DR2631]

The proposed resolution of CWG2631 extends our current handling of
source_location::current to all consteval functions: default arguments
are not evaluated until they're used in a call, the same should apply to
evaluation of immediate invocations.  And similarly for default member
initializers.

Previously we folded source_location::current in cp_fold_r; now we fold all
consteval calls in default arguments/member initializers in bot_replace.

DR 2631

gcc/cp/ChangeLog:

* cp-tree.h (source_location_current_p): Remove.
* name-lookup.h (struct cp_binding_level): Remove
immediate_fn_ctx_p.
* call.cc (in_immediate_context): All default args
and DMI are potentially immediate context.
(immediate_invocation_p): Don't treat source_location specially.
(struct in_consteval_if_p_temp_override): Move to cp-tree.h.
* constexpr.cc (get_nth_callarg): Move to cp-tree.h.
* cp-gimplify.cc (cp_fold_r): Don't fold consteval.
* name-lookup.cc (begin_scope): Don't set immediate_fn_ctx_p.
* parser.cc (cp_parser_lambda_declarator_opt): Likewise.
(cp_parser_direct_declarator): Likewise.
* pt.cc (tsubst_default_argument): Open sk_function_parms level.
* tree.cc (source_location_current_p): Remove.
(bot_replace): Fold consteval here.
(break_out_target_exprs): Handle errors.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/consteval-defarg3.C: New test.

2 years agolibstdc++: Implement ranges::repeat_view from P2474R2
Patrick Palka [Wed, 12 Oct 2022 15:14:11 +0000 (11:14 -0400)]
libstdc++: Implement ranges::repeat_view from P2474R2

libstdc++-v3/ChangeLog:

* include/std/ranges (repeat_view): Define.
(repeat_view::_Iterator): Define.
(views::__detail::__can_repeat_view): Define.
(views::__detail::__can_bounded_repeat_view): Define.
(views::_Repeat, views::repeat): Define.
* testsuite/std/ranges/repeat/1.cc: New test.

2 years agoRISC-V: Remove TUPLE size macro define. [NFC]
Ju-Zhe Zhong [Tue, 11 Oct 2022 06:23:33 +0000 (14:23 +0800)]
RISC-V: Remove TUPLE size macro define. [NFC]

gcc/ChangeLog:

* config/riscv/riscv-vector-builtins.h: Remove unused macro.

2 years agoRISC-V: Apply clang-format for riscv-vector-builtins.* [NFC]
Ju-Zhe Zhong [Tue, 11 Oct 2022 06:21:59 +0000 (14:21 +0800)]
RISC-V: Apply clang-format for riscv-vector-builtins.* [NFC]

gcc/ChangeLog:

* config/riscv/riscv-vector-builtins.cc (DEF_RVV_TYPE): Apply
clang-format.
(add_vector_type_attribute): Ditto.
* config/riscv/riscv-vector-builtins.def (DEF_RVV_TYPE): Apply
clang-format.
* config/riscv/riscv-vector-builtins.h (DEF_RVV_TYPE): Apply
clang-format.

2 years agoRISC-V: Refine register_builtin_types function. [NFC]
Ju-Zhe Zhong [Tue, 11 Oct 2022 06:15:21 +0000 (14:15 +0800)]
RISC-V: Refine register_builtin_types function. [NFC]

gcc/ChangeLog:

* config/riscv/riscv-vector-builtins.cc (builtin_types): Redefine
vector types.
(build_const_pointer): New function.
(register_builtin_type): Ditto.
(DEF_RVV_TYPE): Simplify macro.
(register_vector_type): Refine implementation.
* config/riscv/riscv-vector-builtins.h (rvv_builtin_types_t): New.

2 years agoRISC-V: Move function place to make it looks better. [NFC]
Ju-Zhe Zhong [Tue, 11 Oct 2022 04:48:20 +0000 (12:48 +0800)]
RISC-V: Move function place to make it looks better. [NFC]

gcc/ChangeLog:

* config/riscv/riscv-vector-builtins.h (class rvv_switcher): Move to
this to ....
* config/riscv/riscv-vector-builtins.cc (class rvv_switcher):
here.

2 years agoRemove AVX512_VP2INTERSECT from PTA_SAPPHIRERAPIDS
Cui,Lili [Thu, 29 Sep 2022 06:28:06 +0000 (14:28 +0800)]
Remove AVX512_VP2INTERSECT from PTA_SAPPHIRERAPIDS

gcc/ChangeLog:

* config/i386/driver-i386.cc (host_detect_local_cpu):
Move sapphirerapids out of AVX512_VP2INTERSECT.
* config/i386/i386.h: Remove AVX512_VP2INTERSECT from PTA_SAPPHIRERAPIDS
* doc/invoke.texi: Remove AVX512_VP2INTERSECT from SAPPHIRERAPIDS

2 years agoMAINTAINERS: Add myself for write after approval
Cui,Lili [Wed, 12 Oct 2022 07:43:28 +0000 (15:43 +0800)]
MAINTAINERS: Add myself for write after approval

ChangeLog:
* MAINTAINERS (Write After Approval): Add myself.

2 years agogcov: rename gcov_write_summary
Martin Liska [Tue, 11 Oct 2022 18:45:21 +0000 (20:45 +0200)]
gcov: rename gcov_write_summary

gcc/ChangeLog:

* gcov-io.cc (gcov_write_summary): Rename to ...
(gcov_write_object_summary): ... this.
* gcov-io.h (GCOV_TAG_OBJECT_SUMMARY_LENGTH): Rename from ...
(GCOV_TAG_SUMMARY_LENGTH): ... this.

libgcc/ChangeLog:

* libgcov-driver.c: Use new function.
* libgcov.h (gcov_write_summary): Rename to ...
(gcov_write_object_summary): ... this.

2 years agoregenerate configure files
Martin Liska [Wed, 12 Oct 2022 07:31:32 +0000 (09:31 +0200)]
regenerate configure files

Needed after a recent change.

gcc/ChangeLog:

* configure: Regenerate.

libatomic/ChangeLog:

* configure: Regenerate.

libbacktrace/ChangeLog:

* configure: Regenerate.

libcc1/ChangeLog:

* configure: Regenerate.

libffi/ChangeLog:

* configure: Regenerate.

libgfortran/ChangeLog:

* configure: Regenerate.

libgomp/ChangeLog:

* configure: Regenerate.

libitm/ChangeLog:

* configure: Regenerate.

libobjc/ChangeLog:

* configure: Regenerate.

liboffloadmic/ChangeLog:

* configure: Regenerate.
* plugin/configure: Regenerate.

libphobos/ChangeLog:

* configure: Regenerate.

libquadmath/ChangeLog:

* configure: Regenerate.

libsanitizer/ChangeLog:

* configure: Regenerate.

libssp/ChangeLog:

* configure: Regenerate.

libstdc++-v3/ChangeLog:

* configure: Regenerate.

libvtv/ChangeLog:

* configure: Regenerate.

lto-plugin/ChangeLog:

* configure: Regenerate.

zlib/ChangeLog:

* configure: Regenerate.

2 years agoAdd stubs for floating point range-op tests.
Aldy Hernandez [Tue, 11 Oct 2022 15:23:33 +0000 (17:23 +0200)]
Add stubs for floating point range-op tests.

gcc/ChangeLog:

* range-op-float.cc (frange_float): New.
(range_op_float_tests): New.
* range-op.cc (range_op_tests): Call range_op_float_tests.

2 years agoAdd method to query the sign of a NAN.
Aldy Hernandez [Tue, 11 Oct 2022 17:21:14 +0000 (19:21 +0200)]
Add method to query the sign of a NAN.

In writing some range-op entries I noticed we don't have a way to
query the sign of the NAN in a range, unless the range only contains
NAN, in which case you can just use frange::signbit_p.  This patch
adds a method that returns TRUE if there exists the possiblity of a
NAN and we know its sign.

gcc/ChangeLog:

* value-range.h (frange::nan_signbit_p): New.

2 years agoDisable tree to bool conversion in frange::update_nan.
Aldy Hernandez [Tue, 11 Oct 2022 17:20:47 +0000 (19:20 +0200)]
Disable tree to bool conversion in frange::update_nan.

We have a set_nan(type) method which can be confused with
update_nan(bool) because of the silent conversion of pointers to bool.
Currently, if you call update_nan(tree), you'll set the possibility of
NAN with a sign of true if tree is non-null.  This is prone to error
and this patch disallows this behavior.

gcc/ChangeLog:

* value-range.cc (frange::set_nonnegative): Pass bool to
update_nan.
* value-range.h: Disallow conversion to bool in update_nan().

2 years agoAdd an frange(type) constructor analogous to the irange version.
Aldy Hernandez [Tue, 11 Oct 2022 15:22:40 +0000 (17:22 +0200)]
Add an frange(type) constructor analogous to the irange version.

gcc/ChangeLog:

* value-range.h (frange::frange): Add constructor taking type.

2 years agoAdd default relation_kind to floating point range-op entries.
Aldy Hernandez [Tue, 11 Oct 2022 15:22:23 +0000 (17:22 +0200)]
Add default relation_kind to floating point range-op entries.

The methods from which these derive all have a default relation_kind.
This patch just adds the default, to make it easier to write unit
tests later.

gcc/ChangeLog:

* range-op-float.cc: Add relation_kind = VREL_VARYING to all
methods.

2 years agoLibvtv-test: Fix bug that scansarif.exp cannot be found in libvtv regression test.
Lulu Cheng [Tue, 27 Sep 2022 02:47:06 +0000 (10:47 +0800)]
Libvtv-test: Fix bug that scansarif.exp cannot be found in libvtv regression test.

SARIF support was added in r13-967 but libvtv wasn't updated.

libvtv/ChangeLog:

* testsuite/lib/libvtv-dg.exp: Add load_gcc_lib of scansarif.exp.

2 years agoDaily bump.
GCC Administrator [Wed, 12 Oct 2022 00:17:24 +0000 (00:17 +0000)]
Daily bump.

2 years agoEnable support for atomic primitives on SPARC/Linux
Eric Botcazou [Tue, 11 Oct 2022 22:38:04 +0000 (00:38 +0200)]
Enable support for atomic primitives on SPARC/Linux

The SPARC/Linux port is very similar to the SPARC/Solaris port nowadays so
it makes sense to copy the setting of the support for atomic primitives.

This fixes the single regression in the gnat.dg testsuite:
FAIL: gnat.dg/prot7.adb (test for excess errors)

gcc/ada/
* libgnat/system-linux-sparc.ads (Support_Atomic_Primitives): New
constant set to True.

2 years agoFortran: check types of source expressions before conversion [PR107215]
Harald Anlauf [Tue, 11 Oct 2022 18:37:42 +0000 (20:37 +0200)]
Fortran: check types of source expressions before conversion [PR107215]

gcc/fortran/ChangeLog:

PR fortran/107215
* arith.cc (gfc_int2int): Check validity of type of source expr.
(gfc_int2real): Likewise.
(gfc_int2complex): Likewise.
(gfc_real2int): Likewise.
(gfc_real2real): Likewise.
(gfc_complex2int): Likewise.
(gfc_complex2real): Likewise.
(gfc_complex2complex): Likewise.
(gfc_log2log): Likewise.
(gfc_log2int): Likewise.
(gfc_int2log): Likewise.

gcc/testsuite/ChangeLog:

PR fortran/107215
* gfortran.dg/pr107215.f90: New test.

2 years agolibstdc++: Fix bootstrap for --disable-threads build [PR107221]
Jonathan Wakely [Tue, 11 Oct 2022 19:19:08 +0000 (20:19 +0100)]
libstdc++: Fix bootstrap for --disable-threads build [PR107221]

The __scoped_lock type should be used unqualified so that we always
refer to pool::__scoped_lock, which might be the dummy fallback
implementation.

The __mutex and __scoped_lock types in <ext/concurrence.h> already work
fine without __GTHREADS being defined, but that header isn't included at
all unless _GLIBCXX_HOSTED != 0. The fallback implementation should be
used for ! _GLIBCXX_HOSTED instead of for !defined __GTHREADS.

libstdc++-v3/ChangeLog:

PR bootstrap/107221
* libsupc++/eh_alloc.cc (pool): Change preprocessor condition
for using __mutex from __GTHREADS to _GLIBCXX_HOSTED.
(pool::allocate): Remove namespace qualification to use
pool::__scoped_lock instead of __gnu_cxx::__scoped_lock.

2 years agoc++ modules: ICE with templated friend and std namespace [PR100134]
Patrick Palka [Tue, 11 Oct 2022 19:02:23 +0000 (15:02 -0400)]
c++ modules: ICE with templated friend and std namespace [PR100134]

The function depset::hash::add_binding_entity has an assert verifying
that if a namespace contains an exported entity, then the namespace must
have been opened in the module purview:

  if (data->hash->add_namespace_entities (decl, data->partitions))
    {
      /* It contains an exported thing, so it is exported.  */
      gcc_checking_assert (DECL_MODULE_PURVIEW_P (decl));
      DECL_MODULE_EXPORT_P (decl) = true;
    }

We're tripping over this assert in the below testcase because by
instantiating and exporting std::A<int>, we in turn define and export the
hidden friend std::f(A<int>) without ever having opened the enclosing
namespace std within the module purview, and thus DECL_MODULE_PURVIEW_P
for std is false.

It's important that the enclosing namespace is std here: if we use
a different namespace then the ICE disappears.  This probably has
something to do with us predefining std via push_namespace from
cxx_init_decl_processing (which makes it look like we've opened it
within the TU), whereas with another namespace we would instead lazily
create its NAMESPACE_DECL from add_imported_namespace.

Since templated friend functions are special in that they give us a way
to introduce a namespace-scope function without having to explicitly
open the namespace, this patch proposes to fix this ICE by propagating
DECL_MODULE_PURVIEW_P from the introduced function to the enclosing
namespace during tsubst_friend_function.

PR c++/100134

gcc/cp/ChangeLog:

* pt.cc (tsubst_friend_function): Propagate DECL_MODULE_PURVIEW_P
from the introduced namespace-scope function to the namespace.

gcc/testsuite/ChangeLog:

* g++.dg/modules/tpl-friend-8_a.H: New test.
* g++.dg/modules/tpl-friend-8_b.C: New test.

2 years agoc++ modules: lazy loading from within template [PR99377]
Patrick Palka [Tue, 11 Oct 2022 19:02:01 +0000 (15:02 -0400)]
c++ modules: lazy loading from within template [PR99377]

Here when lazily loading the binding for f due to its first use from the
template g, processing_template_decl is set which causes the call to
note_vague_linkage_fn from module_state::read_cluster to have no effect,
and thus we never push f onto deferred_fns and end up never emitting its
definition despite needing it.

The behavior of the lazy loading machinery shouldn't be sensitive to
whether we're inside a template, so to that end this patch makes us
clear processing_template_decl in the entrypoints lazy_load_binding and
lazy_load_pendings.

PR c++/99377

gcc/cp/ChangeLog:

* module.cc (lazy_load_binding): Clear processing_template_decl.
(lazy_load_pendings): Likewise.

gcc/testsuite/ChangeLog:

* g++.dg/modules/pr99377-2_a.C: New test.
* g++.dg/modules/pr99377-2_b.C: New test.

2 years agolibstdc++: Allow emergency EH alloc pool size to be tuned [PR68606]
Jonathan Wakely [Wed, 5 Oct 2022 20:21:54 +0000 (21:21 +0100)]
libstdc++: Allow emergency EH alloc pool size to be tuned [PR68606]

Implement a long-standing request to support tuning the size of the
emergency buffer for allocating exceptions after malloc fails, or to
disable that buffer entirely.

It's now possible to disable the dynamic allocation of the buffer and
use a fixed-size static buffer, via --enable-libstdcxx-static-eh-pool.
This is a built-time choice that is baked into libstdc++ and so affects
all code linked against that build of libstdc++.

The size of the pool can be set by --with-libstdcxx-eh-pool-obj-count=N
which is measured in units of sizeof(void*) not bytes. A given exception
type such as std::system_error depends on the target, so giving a size
in bytes wouldn't be portable across 16/32/64-bit targets.

When libstdc++ is configured to use a dynamic buffer, the size of that
buffer can now be tuned at runtime by setting the GLIBCXX_TUNABLES
environment variable (c.f. PR libstdc++/88264). The number of exceptions
to reserve space for is controlled by the "glibcxx.eh_pool.obj_count"
and "glibcxx.eh_pool.obj_size" tunables. The pool will be sized to be
able to allocate obj_count exceptions of size obj_size*sizeof(void*) and
obj_count "dependent" exceptions rethrown by std::rethrow_exception.

With the ability to tune the buffer size, we can reduce the default pool
size on 32-bit and 16-bit targets. Most users never need to throw 1kB
exceptions in parallel from hundreds of threads after malloc is OOM. The
users who do need that can use the tunables to select larger sizes.

The old defaults can be chosen at runtime by setting GLIBCXX_TUNABLES
to:
64-bit: glibcxx.eh_pool.obj_count=64:glibcxx.eh_pool.obj_size=112
32-bit: glibcxx.eh_pool.obj_count=32:glibcxx.eh_pool.obj_size=104

Or approximated by configuring with:
64-bit: --with-libstdcxx-eh-pool-obj-count=252
32-bit: --with-libstdcxx-eh-pool-obj-count=94

libstdc++-v3/ChangeLog:

PR libstdc++/68606
* Makefile.in: Regenerate.
* acinclude.m4 (GLIBCXX_EMERGENCY_EH_ALLOC): New macro.
* configure: Regenerate.
* configure.ac: Use GLIBCXX_EMERGENCY_EH_ALLOC.
* crossconfig.m4: Check for secure_getenv.
* doc/Makefile.in: Regenerate.
* doc/xml/manual/configure.xml: Document new configure options.
* doc/xml/manual/evolution.xml: Document addition of tunables.
* doc/xml/manual/using_exceptions.xml: Document emergency
buffer and tunables.
* doc/html/*: Regenerate.
* include/Makefile.in: Regenerate.
* libsupc++/Makefile.am: Use EH_POOL_FLAGS.
* libsupc++/Makefile.in: Regenerate.
* libsupc++/eh_alloc.cc (EMERGENCY_OBJ_SIZE): Define in units
of sizeof(void*) not including the ABI's exception header.
(EMERGENCY_OBJ_COUNT): Define as target-independent calculation
based on word size.
(MAX_OBJ_COUNT): Define macro for upper limit on pool size.
(pool) [_GLIBCXX_EH_POOL_STATIC]: Use fixed-size buffer.
(pool::buffer_size_in_bytes): New static member function.
(pool::pool): Parse GLIBCXX_TUNABLES environment variable to set
pool size at runtime.
(pool::in_pool): Use std::less<void*> for total order.
(__freeres) [_GLIBCXX_EH_POOL_STATIC]: Do nothing.
(__cxa_free_exception, __cxa_free_dependent_exception): Add
[[unlikely]] attributes.
* po/Makefile.in: Regenerate.
* python/Makefile.in: Regenerate.
* src/Makefile.in: Regenerate.
* src/c++11/Makefile.in: Regenerate.
* src/c++17/Makefile.in: Regenerate.
* src/c++20/Makefile.in: Regenerate.
* src/c++98/Makefile.in: Regenerate.
* src/filesystem/Makefile.in: Regenerate.
* src/libbacktrace/Makefile.in: Regenerate.
* testsuite/Makefile.in: Regenerate.

2 years agoAvoid calling tracer.trailer() twice.
Aldy Hernandez [Tue, 11 Oct 2022 14:00:33 +0000 (16:00 +0200)]
Avoid calling tracer.trailer() twice.

gcc/ChangeLog:

* gimple-range-gori.cc (gori_compute::logical_combine): Avoid
calling tracer.trailer().

2 years agoi386: Fix up RTL checking ICE [PR107185]
Jakub Jelinek [Tue, 11 Oct 2022 13:57:09 +0000 (15:57 +0200)]
i386: Fix up RTL checking ICE [PR107185]

On Tue, Oct 11, 2022 at 04:03:16PM +0800, liuhongt via Gcc-patches wrote:
> gcc/ChangeLog:
>
>       * config/i386/i386.md (*notxor<mode>_1): New post_reload
>       define_insn_and_split.
>       (*notxorqi_1): Ditto.

> --- a/gcc/config/i386/i386.md
> +++ b/gcc/config/i386/i386.md
> @@ -10826,6 +10826,39 @@ (define_insn "*<code><mode>_1"
>     (set_attr "type" "alu, alu, msklog")
>     (set_attr "mode" "<MODE>")])
>
> +(define_insn_and_split "*notxor<mode>_1"
> +  [(set (match_operand:SWI248 0 "nonimmediate_operand" "=rm,r,?k")
> +     (not:SWI248
> +       (xor:SWI248
> +         (match_operand:SWI248 1 "nonimmediate_operand" "%0,0,k")
> +         (match_operand:SWI248 2 "<general_operand>" "r<i>,<m>,k"))))
> +   (clobber (reg:CC FLAGS_REG))]
> +  "ix86_binary_operator_ok (XOR, <MODE>mode, operands)"
> +  "#"
> +  "&& reload_completed"
> +  [(parallel
> +    [(set (match_dup 0)
> +       (xor:SWI248 (match_dup 1) (match_dup 2)))
> +     (clobber (reg:CC FLAGS_REG))])
> +   (set (match_dup 0)
> +     (not:SWI248 (match_dup 1)))]
> +{
> +  if (MASK_REGNO_P (REGNO (operands[0])))

This causes --enable-checking=yes,rtl,extra regression on
gcc.dg/store_merging_13.c test on x86_64-linux:
.../gcc/testsuite/gcc.dg/store_merging_13.c: In function 'f13':
.../gcc/testsuite/gcc.dg/store_merging_13.c:189:1: internal compiler error: RTL check: expected code 'reg', have 'mem' in rhs_regno, at rtl.h:1932
0x7b0c8f rtl_check_failed_code1(rtx_def const*, rtx_code, char const*, int, char const*)
        ../../gcc/rtl.cc:916
0x8e74be rhs_regno
        ../../gcc/rtl.h:1932
0x9785fd rhs_regno
        ./genrtl.h:120
0x9785fd gen_split_260(rtx_insn*, rtx_def**)
        ../../gcc/config/i386/i386.md:10846
0x23596dc split_insns(rtx_def*, rtx_insn*)
        ../../gcc/config/i386/i386.md:16392
0xfccd5a try_split(rtx_def*, rtx_insn*, int)
        ../../gcc/emit-rtl.cc:3799
0x132e9d8 split_insn
        ../../gcc/recog.cc:3384
0x13359d5 split_all_insns()
        ../../gcc/recog.cc:3488
0x1335ae8 execute
        ../../gcc/recog.cc:4412
Please submit a full bug report, with preprocessed source (by using -freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

Fixed thusly.

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

PR target/107185
* config/i386/i386.md (*notxor<mode>_1): Use MASK_REG_P (x) instead of
MASK_REGNO_P (REGNO (x)).

2 years agoImplement ABS_EXPR operator for frange.
Aldy Hernandez [Mon, 10 Oct 2022 12:56:42 +0000 (14:56 +0200)]
Implement ABS_EXPR operator for frange.

Implementing ABS_EXPR allows us to fold certain __builtin_inf calls
since they are expanded into calls to involving ABS_EXPR.

This is an adaptation of the integer version.

gcc/ChangeLog:

* range-op-float.cc (class foperator_abs): New.
(floating_op_table::floating_op_table): Add ABS_EXPR entry.

gcc/testsuite/ChangeLog:

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

2 years agoImplement op1_range operators for unordered comparisons.
Aldy Hernandez [Mon, 10 Oct 2022 14:58:29 +0000 (16:58 +0200)]
Implement op1_range operators for unordered comparisons.

gcc/ChangeLog:

* range-op-float.cc (foperator_unordered_le::op1_range): New.
(foperator_unordered_le::op2_range): New.
(foperator_unordered_gt::op1_range): New.
(foperator_unordered_gt::op2_range): New.
(foperator_unordered_ge::op1_range): New.
(foperator_unordered_ge::op2_range): New.
(foperator_unordered_equal::op1_range): New.

2 years agoShare common ordered comparison code with UN*_EXPR.
Aldy Hernandez [Mon, 10 Oct 2022 12:56:01 +0000 (14:56 +0200)]
Share common ordered comparison code with UN*_EXPR.

Most unordered comparisons can use the result from the ordered
version, if the operands are known not to be NAN or if the result is
true.

gcc/ChangeLog:

* range-op-float.cc (class foperator_unordered_lt): New.
(class foperator_relop_unknown): Remove
(class foperator_unordered_le): New.
(class foperator_unordered_gt): New.
(class foperator_unordered_ge): New.
(class foperator_unordered_equal): New.
(floating_op_table::floating_op_table): Replace all UN_EXPR
entries with their appropriate fop_unordered_* counterpart.

2 years agoMove TRUE case first in range-op.cc.
Aldy Hernandez [Tue, 11 Oct 2022 09:20:25 +0000 (11:20 +0200)]
Move TRUE case first in range-op.cc.

It's incredibly annoying that some of the BRS_TRUE cases come after
BRS_FALSE, if only because we're not consistent.  Having random
ordering increases the changes of thinkos when adapting the irange
code to floats.

gcc/ChangeLog:

* range-op.cc (operator_equal::op1_range): Move BRS_TRUE case up.
(operator_lt::op2_range): Same.
(operator_le::op2_range): Same.
(operator_gt::op2_range): Same.
(operator_ge::op2_range): Same.

2 years agolibiberty: Demangling 'M' prefixes
Nathan Sidwell [Fri, 30 Sep 2022 16:43:30 +0000 (09:43 -0700)]
libiberty: Demangling 'M' prefixes

The grammar for a lambda context can include <source-name> 'M', and we
were adding the component that generated to the substitution table
twice.  Just ignore the 'M' completely -- we'll already have done the
checks we need when we saw its predecessor.  A prefix cannot be the
last component of a nested name, so we do not need to check for that
case (although we could if we wanted to be more lenient).

libiberty/
* cp-demangle.c (d_prefix): 'M' components are not
(re-)added to the substitution table.
* testsuite/demangle-expected: Add tests.

2 years agotree-optimization/107212 - SLP reduction of reduction paths
Richard Biener [Tue, 11 Oct 2022 09:34:55 +0000 (11:34 +0200)]
tree-optimization/107212 - SLP reduction of reduction paths

The following fixes an issue with how we handle epilogue generation
for SLP reductions of reduction paths where the actual live lanes
are not "canonical".  We need to make sure to identify all live
lanes as reductions and thus have to iterate over all participating
SLP lanes when walking the reduction SSA use-def chain.  Also the
previous attempt likely to mitigate such issue in
vectorizable_live_operation is misguided and has to be removed.

PR tree-optimization/107212
* tree-vect-loop.cc (vectorizable_reduction): Make sure to
set STMT_VINFO_REDUC_DEF for all live lanes in a SLP
reduction.
(vectorizable_live_operation): Do not pun to the SLP
node representative for reduction epilogue generation.

* gcc.dg/vect/pr107212-1.c: New testcase.
* gcc.dg/vect/pr107212-2.c: Likewise.

2 years agoamdgcn: vector testsuite tweaks
Andrew Stubbs [Sat, 10 Sep 2022 22:47:19 +0000 (23:47 +0100)]
amdgcn: vector testsuite tweaks

The testsuite needs a few tweaks following my patches to add multiple vector
sizes for amdgcn.

gcc/testsuite/ChangeLog:

* gcc.dg/pr104464.c: Xfail on amdgcn.
* gcc.dg/signbit-2.c: Likewise.
* gcc.dg/signbit-5.c: Likewise.
* gcc.dg/vect/bb-slp-68.c: Likewise.
* gcc.dg/vect/bb-slp-cond-1.c: Change expectations on amdgcn.
* gcc.dg/vect/bb-slp-subgroups-3.c: Likewise.
* gcc.dg/vect/no-vfa-vect-depend-2.c: Change expectations for multiple
vector sizes.
* gcc.dg/vect/pr33953.c: Likewise.
* gcc.dg/vect/pr65947-12.c: Likewise.
* gcc.dg/vect/pr65947-13.c: Likewise.
* gcc.dg/vect/pr80631-2.c: Likewise.
* gcc.dg/vect/slp-reduc-4.c: Likewise.
* gcc.dg/vect/trapv-vect-reduc-4.c: Likewise.
* lib/target-supports.exp (available_vector_sizes): Add more sizes
for amdgcn.

2 years agoamdgcn: Add vector integer negate insn
Andrew Stubbs [Thu, 22 Sep 2022 11:48:30 +0000 (12:48 +0100)]
amdgcn: Add vector integer negate insn

Another example of the vectorizer needing explicit insns where the scalar
expander just works.

gcc/ChangeLog:

* config/gcn/gcn-valu.md (neg<mode>2): New define_expand.

2 years agoamdgcn: vec_init for multiple vector sizes
Andrew Stubbs [Wed, 11 Mar 2020 16:39:54 +0000 (16:39 +0000)]
amdgcn: vec_init for multiple vector sizes

Implements vec_init when the input is a vector of smaller vectors, or of
vector MEM types, or a smaller vector duplicated several times.

gcc/ChangeLog:

* config/gcn/gcn-valu.md (vec_init<V_ALL:mode><V_ALL_ALT:mode>): New.
* config/gcn/gcn.cc (GEN_VN): Add andvNsi3, subvNsi3.
(GEN_VNM): Add gathervNm_expr.
(GEN_VN_NOEXEC): Add vec_seriesvNsi.
(gcn_expand_vector_init): Add initialization of vectors from smaller
vectors.

2 years agoamdgcn: Add vec_extract for partial vectors
Andrew Stubbs [Mon, 29 Jun 2020 14:20:09 +0000 (15:20 +0100)]
amdgcn: Add vec_extract for partial vectors

Add vec_extract expanders for all valid pairs of vector types.

gcc/ChangeLog:

* config/gcn/gcn-protos.h (get_exec): Add prototypes for two variants.
* config/gcn/gcn-valu.md
(vec_extract<V_ALL:mode><V_ALL_ALT:mode>): New define_expand.
* config/gcn/gcn.cc (get_exec): Export the existing function. Add a
new overload variant.

2 years agoamdgcn: Resolve insn conditions at compile time
Andrew Stubbs [Thu, 26 Mar 2020 21:22:45 +0000 (21:22 +0000)]
amdgcn: Resolve insn conditions at compile time

GET_MODE_NUNITS isn't a compile time constant, so we end up with many
impossible insns in the machine description.  Adding MODE_VF allows the insns
to be eliminated completely.

gcc/ChangeLog:

* config/gcn/gcn-valu.md
(<cvt_name><VCVT_MODE:mode><VCVT_FMODE:mode>2<exec>): Use MODE_VF.
(<cvt_name><VCVT_FMODE:mode><VCVT_IMODE:mode>2<exec>): Likewise.
* config/gcn/gcn.h (MODE_VF): New macro.

2 years agoamdgcn: add multiple vector sizes
Andrew Stubbs [Mon, 3 Aug 2020 20:09:36 +0000 (21:09 +0100)]
amdgcn: add multiple vector sizes

The vectors sizes are simulated using implicit masking, but they make life
easier for the autovectorizer and SLP passes.

gcc/ChangeLog:

* config/gcn/gcn-modes.def (VECTOR_MODE): Add new modes
V32QI, V32HI, V32SI, V32DI, V32TI, V32HF, V32SF, V32DF,
V16QI, V16HI, V16SI, V16DI, V16TI, V16HF, V16SF, V16DF,
V8QI, V8HI, V8SI, V8DI, V8TI, V8HF, V8SF, V8DF,
V4QI, V4HI, V4SI, V4DI, V4TI, V4HF, V4SF, V4DF,
V2QI, V2HI, V2SI, V2DI, V2TI, V2HF, V2SF, V2DF.
(ADJUST_ALIGNMENT): Likewise.
* config/gcn/gcn-protos.h (gcn_full_exec): Delete.
(gcn_full_exec_reg): Delete.
(gcn_scalar_exec): Delete.
(gcn_scalar_exec_reg): Delete.
(vgpr_1reg_mode_p): Use inner mode to identify vector registers.
(vgpr_2reg_mode_p): Likewise.
(vgpr_vector_mode_p): Use VECTOR_MODE_P.
* config/gcn/gcn-valu.md (V_QI, V_HI, V_HF, V_SI, V_SF, V_DI, V_DF,
V_QIHI, V_1REG, V_INT_1REG, V_INT_1REG_ALT, V_FP_1REG, V_2REG, V_noQI,
V_noHI, V_INT_noQI, V_INT_noHI, V_ALL, V_ALL_ALT, V_INT, V_FP):
Add additional vector modes.
(V64_SI, V64_DI, V64_ALL, V64_FP): New iterators.
(scalar_mode, SCALAR_MODE, vnsi, VnSI, vndi, VnDI, sdwa):
Add additional vector mode mappings.
(mov<mode>): Implement vector length conversions.
(ldexp<mode>3<exec>): Use VnSI.
(frexp<mode>_exp2<exec>): Likewise.
(VCVT_MODE, VCVT_FMODE, VCVT_IMODE): Add additional vector modes.
(reduc_<reduc_op>_scal_<mode>): Use V64_ALL.
(fold_left_plus_<mode>): Use V64_FP.
(*<reduc_op>_dpp_shr_<mode>): Use V64_1REG.
(*<reduc_op>_dpp_shr_<mode>): Use V64_DI.
(*plus_carry_dpp_shr_<mode>): Use V64_INT_1REG.
(*plus_carry_in_dpp_shr_<mode>): Use V64_SI.
(*plus_carry_dpp_shr_<mode>): Use V64_DI.
(mov_from_lane63_<mode>): Use V64_2REG.
* config/gcn/gcn.cc (VnMODE): New function.
(gcn_can_change_mode_class): Support multiple vector sizes.
(gcn_modes_tieable_p): Likewise.
(gcn_operand_part): Likewise.
(gcn_scalar_exec): Delete function.
(gcn_scalar_exec_reg): Delete function.
(gcn_full_exec): Delete function.
(gcn_full_exec_reg): Delete function.
(gcn_inline_fp_constant_p): Support multiple vector sizes.
(gcn_fp_constant_p): Likewise.
(A): New macro.
(GEN_VN_NOEXEC): New macro.
(GEN_VNM_NOEXEC): New macro.
(GEN_VN): New macro.
(GEN_VNM): New macro.
(GET_VN_FN): New macro.
(CODE_FOR): New macro.
(CODE_FOR_OP): New macro.
(gen_mov_with_exec): Delete function.
(gen_duplicate_load): Delete function.
(gcn_expand_vector_init): Support multiple vector sizes.
(strided_constant): Likewise.
(gcn_addr_space_legitimize_address): Likewise.
(gcn_expand_scalar_to_vector_address): Likewise.
(gcn_expand_scaled_offsets): Likewise.
(gcn_secondary_reload): Likewise.
(gcn_valid_cvt_p): Likewise.
(gcn_expand_builtin_1): Likewise.
(gcn_make_vec_perm_address): Likewise.
(gcn_vectorize_vec_perm_const): Likewise.
(gcn_vector_mode_supported_p): Likewise.
(gcn_autovectorize_vector_modes): New hook.
(gcn_related_vector_mode): Support multiple vector sizes.
(gcn_expand_dpp_shr_insn): Add FIXME comment.
(gcn_md_reorg): Support multiple vector sizes.
(print_reg): Likewise.
(print_operand): Likewise.
(TARGET_VECTORIZE_AUTOVECTORIZE_VECTOR_MODES): New hook.

2 years agovect: Teach vectorizer how to handle bitfield accesses
Andre Vieira [Tue, 11 Oct 2022 09:49:27 +0000 (10:49 +0100)]
vect: Teach vectorizer how to handle bitfield accesses

gcc/ChangeLog:

* tree-if-conv.cc (if_convertible_loop_p_1): Move ordering of loop bb's from
here...
(tree_if_conversion): ... to here.  Also call bitfield lowering when
appropriate.
(version_loop_for_if_conversion): Adapt to enable loop versioning when we only
need to lower bitfields.
(ifcvt_split_critical_edges): Relax condition of expected loop form as this is
checked earlier.
(get_bitfield_rep): New function.
(lower_bitfield): Likewise.
(bitfields_to_lower_p): Likewise.
(need_to_lower_bitfields): New global boolean.
(need_to_ifcvt): Likewise.
* tree-vect-data-refs.cc (vect_find_stmt_data_reference): Improve diagnostic
message.
* tree-vect-patterns.cc (vect_recog_temp_ssa_var): Add default value for last
parameter.
(vect_recog_bitfield_ref_pattern): New.
(vect_recog_bit_insert_pattern): New.

gcc/testsuite/ChangeLog:

* gcc.dg/vect/vect-bitfield-read-1.c: New test.
* gcc.dg/vect/vect-bitfield-read-2.c: New test.
* gcc.dg/vect/vect-bitfield-read-3.c: New test.
* gcc.dg/vect/vect-bitfield-read-4.c: New test.
* gcc.dg/vect/vect-bitfield-read-5.c: New test.
* gcc.dg/vect/vect-bitfield-read-6.c: New test.
* gcc.dg/vect/vect-bitfield-write-1.c: New test.
* gcc.dg/vect/vect-bitfield-write-2.c: New test.
* gcc.dg/vect/vect-bitfield-write-3.c: New test.
* gcc.dg/vect/vect-bitfield-write-4.c: New test.
* gcc.dg/vect/vect-bitfield-write-5.c: New test.

2 years agoAdd define_insn_and_split to support general version of "kxnor".
liuhongt [Mon, 10 Oct 2022 03:31:48 +0000 (11:31 +0800)]
Add define_insn_and_split to support general version of "kxnor".

For genereal_reg_operand, it will be splitted into xor + not.
For mask_reg_operand, it will be splitted with UNSPEC_MASK_OP just
like what we did for other logic operations.

The patch will optimize xor+not to kxnor when possible.

gcc/ChangeLog:

PR target/107093
* config/i386/i386.md (*notxor<mode>_1): New post_reload
define_insn_and_split.
(*notxorqi_1): Ditto.

gcc/testsuite/ChangeLog:

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

2 years ago[PR107195] Set range to zero when nonzero mask is 0.
Aldy Hernandez [Mon, 10 Oct 2022 18:42:10 +0000 (20:42 +0200)]
[PR107195] Set range to zero when nonzero mask is 0.

When solving 0 = _15 & 1, we calculate _15 as:

[irange] int [-INF, -2][0, +INF] NONZERO 0xfffffffe

The known value of _15 is [0, 1] NONZERO 0x1 which is intersected with
the above, yielding:

[0, 1] NONZERO 0x0

This eventually gets copied to a _Bool [0, 1] NONZERO 0x0.

This is problematic because here we have a bool which is zero, but
returns false for irange::zero_p, since the latter does not look at
nonzero bits.  This causes logical_combine to assume the range is
not-zero, and all hell breaks loose.

I think we should just normalize a nonzero mask of 0 to [0, 0] at
creation, thus avoiding all this.

PR tree-optimization/107195

gcc/ChangeLog:

* value-range.cc (irange::set_range_from_nonzero_bits): Set range
to [0,0] when nonzero mask is 0.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/pr107195-1.c: New test.
* gcc.dg/tree-ssa/pr107195-2.c: New test.

2 years agoGeneric configury support for shared libs on VxWorks
Olivier Hainque [Fri, 3 Dec 2021 17:50:56 +0000 (17:50 +0000)]
Generic configury support for shared libs on VxWorks

This change adds the configury bits to activate the build of
shared libs on VxWorks ports configured with --enable-shared,
for libraries variants where this is generally supported (rtp,
code model !large - currently not compatible with -fPIC).

Set lt_cv_deplibs_check_method in libtool.m4, so the build of
libraries know how to establish dependencies.  This is useful in
configurations such as aarch64 where proper support of LSE relies
on accurate dependency information between libstdc++ and libgcc_s
to begin with.

Regenerate configure scripts to reflect libtool.m4 change.

2022-10-09  Olivier Hainque  <hainque@adacore.com>

* libtool.m4 (*vxworks*): When enable_shared, set dynamic_linker
and friends for rtp !large. Assume the linker has the required
abilities and set lt_cv_deplibs_check_method.

gcc/
* config.gcc (*vxworks*): Add t-slibgcc fragment
if enable_shared.

libgcc/
* config.host (*vxworks*): When enable_shared, add
libgcc and crtstuff "shared" fragments for rtp except
large code model.
(aarch64*-wrs-vxworks7*): Remove t-slibgcc-libgcc from
the list of fragments.

2022-10-09  Olivier Hainque  <hainque@adacore.com>

gcc/
* configure: Regenerate.

libatomic/
* configure: Regenerate.

libbacktrace/
* configure: Regenerate.

libcc1/
* configure: Regenerate.

libffi/
* configure: Regenerate.

libgfortran/
* configure: Regenerate.

libgomp/
* configure: Regenerate.

libitm/
* configure: Regenerate.

libobjc/
* configure: Regenerate.

liboffloadmic/
* configure: Regenerate.

liboffloadmic/
* plugin/configure: Regenerate.

libphobos/
* configure: Regenerate.

libquadmath/
* configure: Regenerate.

libsanitizer/
* configure: Regenerate.

libssp/
* configure: Regenerate.

libstdc++-v3/
* configure: Regenerate.

libvtv/
* configure: Regenerate.

lto-plugin/
* configure: Regenerate.

zlib/
* configure: Regenerate.

2 years agoTigthen the addition of -lgcc_eh to vxworks_libgcc_spec
Olivier Hainque [Fri, 18 Feb 2022 22:44:53 +0000 (22:44 +0000)]
Tigthen the addition of -lgcc_eh to vxworks_libgcc_spec

This change refines VXWORKS_LIBGCC_SPEC wrt the inclusion
of -lgcc_eh.

Unless the compiler features support for dual sjlj and
table based eh, libgcc_eh.a is available only with multilib
variants for which we build a shared lib (mrtp on VxWorks).

Rework logic to handle absence of libgcc_s
for -mrtp -mcmodel=large, using a conditional expr kind of
spec.

The gthread support in libgcc_eh might resort to libgcc
functions on some targets, e.g. cas synchronisation routines
on aarch64. Arrange to append -lgcc also after -lgcc_eh
in VXWORKS_LIBGCC_SPEC.

2022-10-09  Olivier Hainque  <hainque@adacore.com>

gcc/
* config/vxworks.h (VX_LGCC_EH_SO0, VX_LGCC_EH_SO1): New
internal macros.
(VXWORKS_LIBGCC_SPEC): Use them and document.

2 years agoranger: add override keyword
Martin Liska [Tue, 11 Oct 2022 06:52:28 +0000 (08:52 +0200)]
ranger: add override keyword

Fixes the following clang warning:
gcc/gimple-range-op.cc:310:16: warning: 'fold_range' overrides a member function but is not marked 'override' [-Winconsistent-missing-override]

gcc/ChangeLog:

* gimple-range-op.cc: Add override keyword.

2 years agoFix PR107193.
Eugene Rozenfeld [Mon, 10 Oct 2022 21:10:31 +0000 (14:10 -0700)]
Fix PR107193.

The bug was introduced in f30e9fd33e56a5a721346ea6140722e1b193db42.
A variable (cur_locus_e) was incorrectly declared inside a loop.
I also moved two other declarations (last and locus) down to make
the code more clear.

Tested on x86_64-pc-linux-gnu.

gcc/ChangeLog:
PR debug/107193
* tree-cfg.cc (assign_discriminators): Move declaration of cur_locus_e
out of the loop.

2 years agoOptimize nested permutation to single VEC_PERM_EXPR [PR54346]
Liwei Xu [Fri, 23 Sep 2022 05:46:02 +0000 (13:46 +0800)]
Optimize nested permutation to single VEC_PERM_EXPR [PR54346]

        This patch implemented the optimization in PR 54346, which Merges

c = VEC_PERM_EXPR <a, b, VCST0>;
        d = VEC_PERM_EXPR <c, c, VCST1>;
                to
        d = VEC_PERM_EXPR <a, b, NEW_VCST>;

Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,}
        tree-ssa/forwprop-19.c fail to pass but I'm not sure whether it
        is ok to removed it.

gcc/ChangeLog:

PR tree-optimization/54346
* match.pd: Merge the index of VCST then generates the new vec_perm.

gcc/testsuite/ChangeLog:

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

Co-authored-by: liuhongt <hongtao.liu@intel.com>
2 years ago[PR rtl-optimization/107182] Clear EDGE_CROSSING for jump->ret optimization
Jeff Law [Tue, 11 Oct 2022 04:44:26 +0000 (00:44 -0400)]
[PR rtl-optimization/107182] Clear EDGE_CROSSING for jump->ret optimization

When turning a jump to a return into a return, we need to clear EDGE_CROSSING
of the fallthru edge to prevent a checking failure.

I considered not applying the transformation when the edge has EDGE_CROSSING
set, but it still seems like we ought to eliminate the unnecessary jump in
that case.

gcc/
PR rtl-optimization/107182
* cfgrtl.cc (fixup_reorder_chain): When optimizing a jump to a
return, clear EDGE_CROSSING on the appropriate edge.

2 years agoRISC-V: move struct vector_type_info from *.h to *.cc and change "user_name" into...
Ju-Zhe Zhong [Mon, 10 Oct 2022 13:57:21 +0000 (21:57 +0800)]
RISC-V: move struct vector_type_info from *.h to *.cc and change "user_name" into "name".

gcc/ChangeLog:

* config/riscv/riscv-vector-builtins.cc (struct vector_type_info): Move
from config/riscv/riscv-vector-builtins.h.
(DEF_RVV_TYPE): Change USER_NAME to NAME.
(register_vector_type): Change user_name to name.
* config/riscv/riscv-vector-builtins.def (DEF_RVV_TYPE): Change
USER_NAME to NAME.
* config/riscv/riscv-vector-builtins.h (struct vector_type_info): Move
to riscv-vector-builtins.cc.
(DEF_RVV_TYPE): Change USER_NAME to NAME.

Reviewed-by: Kito Cheng <kito.cheng@sifive.com>
2 years agoRISC-V: Add missing vsetvl instruction type.
Ju-Zhe Zhong [Mon, 10 Oct 2022 13:43:22 +0000 (21:43 +0800)]
RISC-V: Add missing vsetvl instruction type.

When implementing built-in framework, I notice I missed
vsetvl instruction type, so add it in a single patch
preparing for the following patches.

gcc/ChangeLog:

* config/riscv/riscv.md: Add vsetvl instruction type.

Reviewed-by: Kito Cheng <kito.cheng@sifive.com>
2 years agoDaily bump.
GCC Administrator [Tue, 11 Oct 2022 00:17:00 +0000 (00:17 +0000)]
Daily bump.

2 years agoAdd cpplib ro.po
Joseph Myers [Mon, 10 Oct 2022 22:58:34 +0000 (22:58 +0000)]
Add cpplib ro.po

* ro.po: New.

2 years agoc++: Lambda context mangling
Nathan Sidwell [Mon, 10 Oct 2022 21:55:04 +0000 (17:55 -0400)]
c++: Lambda context mangling

VAR and FIELD decls can become part of a lambda context, when the
lambda is 'attached' to that entity (It's a C++20 ODR thing that was
discovered with modules, but is actually separate.)  We were not
marking those decls as substitution candidates, leading to demangling
failures and variance from other compilers.

This patch bumps the ABI, and adds the contexts them to the
substitution table.  This is the intent of the ABI.

gcc/
* common.opt (-fabi-version=): Document 18.
* doc/invoke.texi (-fabi-version): Document 18.
gcc/c-family/
* c-opts.cc (c_common_post_options): Bump abi to 18.
gcc/cp/
* mangle.cc (write_prefix): Add VAR_DECL & FIELD_DECL to
substitution table under abi=18.  Note possible mismatch.
gcc/testsuite/
* g++.dg/abi/lambda-ctx1-17.C: New.
* g++.dg/abi/lambda-ctx1-18.C: New.
* g++.dg/abi/lambda-ctx1-18vs17.C: New.
* g++.dg/abi/lambda-ctx1.h: New.
* g++.dg/abi/lambda-vis.C: Adjust expected mangles.
* g++.dg/abi/macro0.C: Adjust.

2 years agocompiler: treat S("") as a string constant
Ian Lance Taylor [Sun, 9 Oct 2022 19:52:17 +0000 (12:52 -0700)]
compiler: treat S("") as a string constant

The compiler neglected to notice that a conversion from a string
constant to a string type was a valid string constant.

No test case because this only caused a compiler failure when compiling
without optimization, which is not the normal case, and is not a case
that we test.

Fixes golang/go#56113

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

2 years agocompiler: only build thunk struct type when it is needed
Ian Lance Taylor [Sat, 8 Oct 2022 18:47:56 +0000 (11:47 -0700)]
compiler: only build thunk struct type when it is needed

Instead of building the thunk struct type in the determine_types pass,
build it when we need it.  That ensures that we are consistent in
determining whether an argument is constant.

We no longer need to add a field for a call to recover, as the
simplify_thunk_statements pass runs after the build_recover_thunks pass,
so the additional argument will already have been added to the call.

The test case is https://go.dev/cl/440297.

Fixes golang/go#56109

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

2 years agolibstdc++: Revert addition of constraints to make_signed/make_unsigned
Jonathan Wakely [Mon, 10 Oct 2022 14:06:53 +0000 (15:06 +0100)]
libstdc++: Revert addition of constraints to make_signed/make_unsigned

Constraining the primary template makes it unusable in uninstantiated
contexts.

libstdc++-v3/ChangeLog:

* include/std/type_traits (make_signed, make_unsigned): Remove
constraints on primary template.
* testsuite/20_util/make_signed/requirements/typedefs_neg.cc:
Undo changes to expected error in C++20 mode.
* testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc:
Likewise.
* testsuite/24_iterators/range_access/range_access_cpp20_neg.cc:
Likewise.
* testsuite/20_util/make_signed/requirements/uninstantiated.cc:
New test.
* testsuite/20_util/make_unsigned/requirements/uninstantiated.cc:
New test.

2 years agoc-family: ICE with [[gnu::nocf_check]] [PR106937]
Marek Polacek [Thu, 29 Sep 2022 21:49:32 +0000 (17:49 -0400)]
c-family: ICE with [[gnu::nocf_check]] [PR106937]

When getting the name of an attribute, we ought to use
get_attribute_name, which handles both [[]] and __attribute__(())
forms.  Failure to do so may result in an ICE, like here.

pp_c_attributes_display wasn't able to print the [[]] form of
attributes, so this patch teaches it to.

When printing a pointer to function with a standard attribute, the attribute
should be printed after the parameter-list.  With this patch we print:

  aka 'void (*)(int) [[gnu::nocf_check]]'

or, in C++ with noexcept:

  aka 'void (*)(int) noexcept [[gnu::nocf_check]]'

pp_c_attributes has been unused since its introduction in r56273 so
this patch removes it.

PR c++/106937

gcc/c-family/ChangeLog:

* c-pretty-print.cc (pp_c_specifier_qualifier_list): Print only GNU
attributes here.
(c_pretty_printer::direct_abstract_declarator): Print the standard [[]]
attributes here.
(pp_c_attributes): Remove.
(pp_c_attributes_display): Print the [[]] form if appropriate.  Use
get_attribute_name.  Don't print a trailing space when printing the
[[]] form.
* c-pretty-print.h (pp_c_attributes): Remove.

gcc/cp/ChangeLog:

* error.cc: Include "attribs.h".
(dump_type_prefix): Print only GNU attributes here.
(dump_type_suffix): Print standard attributes here.

gcc/testsuite/ChangeLog:

* c-c++-common/pointer-to-fn1.c: New test.

2 years agoDon't ICE running selftests if errors were raised [PR99723]
Andrea Corallo [Tue, 27 Sep 2022 14:20:28 +0000 (16:20 +0200)]
Don't ICE running selftests if errors were raised [PR99723]

Hi all

this is to address PR 99723.

In the PR GCC crashes as the initialization of common trees is not
performed as no compilation is happening, this is because we raise an
error earlier while processing the arch flags.

This patch changes the code to execute selftests only if no errors
where raised before.

Bootstrapped on aarch64, okay for trunk?

Best Regards

  Andrea

2022-09-27  Andrea Corallo  <andrea.corallo@arm.com>

PR other/99723
* toplev.cc (toplev::main): Don't run self tests in case of
previous error.

2 years agoRISC-V: Add riscv_vector.h wrapper in testsuite to prevent pull in stdint.h from...
Kito Cheng [Fri, 7 Oct 2022 08:55:14 +0000 (16:55 +0800)]
RISC-V: Add riscv_vector.h wrapper in testsuite to prevent pull in stdint.h from C library

For RISC-V linux/glibc toolchain will got header file not found when including
stdint.h if multilib is not enabled, it because some header file will
try to include gnu/stubs-<ABI-NAME>.h from the system, however it only
generated when multilib enabled.

In order to prevent that, we introduce a wrapper for riscv_vector.h,
include stdint-gcc.h rather than the default stdint.h.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/base/riscv_vector.h: New.

Reported-by: Christoph Müllner <christoph.muellner@vrull.eu>
Tested-by: Christoph Müllner <christoph.muellner@vrull.eu>
Reviewed-by: Ju-Zhe Zhong <juzhe.zhong@rivai.ai>
2 years agoRISC-V: Adjust testcase for rvv/base/user-1.c
Kito Cheng [Fri, 7 Oct 2022 08:54:05 +0000 (16:54 +0800)]
RISC-V: Adjust testcase for rvv/base/user-1.c

The -march option check isn't precise enough, -march=rv*v* also mach any
zve extensions.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/base/user-1.c: Add dg-options and drop
dg-skip-if.

Reported-by: Christoph Müllner <christoph.muellner@vrull.eu>
Tested-by: Christoph Müllner <christoph.muellner@vrull.eu>
Reviewed-by: Ju-Zhe Zhong <juzhe.zhong@rivai.ai>
2 years agoRISC-V: Add newline to the end of file [NFC]
Kito Cheng [Mon, 10 Oct 2022 13:05:50 +0000 (21:05 +0800)]
RISC-V: Add newline to the end of file [NFC]

gcc/ChangeLog:

* config/riscv/riscv-c.cc: Add newline to the end of file.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/base/pragma-1.c: Add newline to the end of file.
* gcc.target/riscv/rvv/base/pragma-2.c: Ditto.
* gcc.target/riscv/rvv/base/pragma-3.c: Ditto.
* gcc.target/riscv/rvv/base/user-1.c: Ditto.
* gcc.target/riscv/rvv/base/user-2.c: Ditto.
* gcc.target/riscv/rvv/base/user-3.c: Ditto.
* gcc.target/riscv/rvv/base/user-4.c: Ditto.
* gcc.target/riscv/rvv/base/user-5.c: Ditto.
* gcc.target/riscv/rvv/base/user-6.c: Ditto.
* gcc.target/riscv/rvv/base/vread_csr.c: Ditto.
* gcc.target/riscv/rvv/base/vwrite_csr.c: Ditto.

2 years agoMake range-op-float entries public.
Aldy Hernandez [Mon, 10 Oct 2022 11:46:32 +0000 (13:46 +0200)]
Make range-op-float entries public.

gcc/ChangeLog:

* range-op-float.cc (class foperator_identity): Make members public.
(class foperator_equal): Same.
(class foperator_not_equal): Same.
(class foperator_lt): Same.
(class foperator_le): Same.
(class foperator_gt): Same.
(class foperator_ge): Same.
(class foperator_unordered): Same.
(class foperator_ordered): Same.

2 years agoAdd frange::maybe_isnan (bool sign).
Aldy Hernandez [Mon, 10 Oct 2022 11:43:16 +0000 (13:43 +0200)]
Add frange::maybe_isnan (bool sign).

It is useful to know if there's the possiblity of a NAN with a given
sign.  This is to complement maybe_isnan(void) which returns TRUE for a
NAN of any sign.

A follow-up patch implementing ABS will make use of this.

gcc/ChangeLog:

* value-range.h (frange::maybe_isnan): New.

2 years agoThe true side of x != x should set NAN.
Aldy Hernandez [Mon, 10 Oct 2022 09:15:43 +0000 (11:15 +0200)]
The true side of x != x should set NAN.

gcc/ChangeLog:

* range-op-float.cc (foperator_not_equal::op1_range): Set NAN on
TRUE side for x != x.

2 years agox UNORD x should set NAN on the TRUE side (and !NAN on the FALSE side).
Aldy Hernandez [Mon, 10 Oct 2022 09:01:48 +0000 (11:01 +0200)]
x UNORD x should set NAN on the TRUE side (and !NAN on the FALSE side).

gcc/ChangeLog:

* range-op-float.cc (foperator_unordered::op1_range): Set NAN when
operands are equal and result is TRUE.

2 years agoReturn non-legacy ranges in range.h.
Aldy Hernandez [Mon, 10 Oct 2022 11:43:56 +0000 (13:43 +0200)]
Return non-legacy ranges in range.h.

int_range<1> is a legacy range (think anti ranges, legacy VRP, etc).
There is a penalty for converting anything built with <1> to
non-legacy.  Since most of the uses of these functions are now ranger,
we can save a miniscule amount of time by converting them to
non-legacy.

gcc/ChangeLog:

* range.h (range_true): Return int_range<2>.
(range_false): Same.
(range_true_and_false): Same.

2 years agolibstdc++: std::make_signed_t<cv bool> should be ill-formed
Jonathan Wakely [Fri, 7 Oct 2022 11:18:57 +0000 (12:18 +0100)]
libstdc++: std::make_signed_t<cv bool> should be ill-formed

Currently we only reject std::make_signed_t<bool> but not cv bool.
Similarly for std::make_unsigned_t<cv bool>.

As well as making those ill-formed, this adds a requires-clause to the
make_signed and make_unsigned primary templates. This makes
non-integral, non-enum cases fail immediately with a clear error, rather
than giving an error about __make_signed_selector<T, false, false> being
incomplete.

libstdc++-v3/ChangeLog:

* include/std/type_traits (make_signed, make_unsigned): Add
specializations for cv bool. Add requires-clause for C++20 to
improve diagnostics for non-integral, non-enum cases.
* testsuite/20_util/make_signed/requirements/typedefs_neg.cc:
Check cv bool.
* testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc:
Likewise.
* testsuite/24_iterators/range_access/range_access_cpp20_neg.cc:
Adjust expected errors for C++20 and later.
* testsuite/lib/prune.exp: Prune "in requirements  [with ...]"
lines from diagnostics.

2 years agoRequire fgraphite effective target for pr107153.c test [PR107153]
Jakub Jelinek [Mon, 10 Oct 2022 10:04:56 +0000 (12:04 +0200)]
Require fgraphite effective target for pr107153.c test [PR107153]

The test uses -floop-parallelize-all which emits a sorry when graphite
isn't configured in.

2022-10-10  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/107153
* gcc.dg/autopar/pr107153.c: Require fgraphite effective target.

2 years agoAdd op1_range for __builtin_signbit.
Aldy Hernandez [Wed, 5 Oct 2022 18:23:15 +0000 (20:23 +0200)]
Add op1_range for __builtin_signbit.

This is the op1_range range-op entry for __builtin_signbit.  It allows
us to wind back through a call to signbit.

For example, on the true side of if (__builtin_signbit(x_5) != 0) we
can crop down the range of x_5 to:

[frange] float [-Inf, -0.0 (-0x0.0p+0)] -NAN

Similarly on the false side, we can crop to:

[frange] float [0.0 (0x0.0p+0), +Inf] +NAN

Tested on x86-64 Linux.

gcc/ChangeLog:

* gimple-range-op.cc: Add op1_range entry for __builtin_signbit.

gcc/testsuite/ChangeLog:

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

2 years agoFix unrecognizable insn of cvtss2si.
liuhongt [Sun, 9 Oct 2022 07:30:10 +0000 (15:30 +0800)]
Fix unrecognizable insn of cvtss2si.

Adjust lrintmn2 operand preidcates according to real instructions.

gcc/ChangeLog:

PR target/107185
* config/i386/i386.md (lrint<MODEF:mode><SWI48:mode>2): Swap
predicate of operands[0] and operands[1].

gcc/testsuite/ChangeLog:

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

2 years agoopenmp, fortran: Fix up IFN_ASSUME call
Jakub Jelinek [Mon, 10 Oct 2022 07:34:35 +0000 (09:34 +0200)]
openmp, fortran: Fix up IFN_ASSUME call

Like in other spots in trans-openmp.cc that create a TARGET_EXPR, the
slot has to be created with create_tmp_var_raw, because gfc_create_var
adds the var to BLOCK_VARS and that ICEs during expansion because
gimple_add_tmp_var_fn has:
  gcc_assert (!DECL_CHAIN (tmp) && !DECL_SEEN_IN_BIND_EXPR_P (tmp));
assertion.  Also, both C/C++ ensure the argument to IFN_ASSUME has
boolean_type_node, it is easier if Fortran does that too.

2022-10-10  Jakub Jelinek  <jakub@redhat.com>

* trans-openmp.cc (gfc_trans_omp_assume): Use create_tmp_var_raw
instead of gfc_create_var for TARGET_EXPR slot creation.  Create it
with boolean_type_node and convert.

2 years agoarc: Remove obsolete mRcq and mRcw options.
Claudiu Zissulescu [Mon, 10 Oct 2022 07:27:12 +0000 (10:27 +0300)]
arc: Remove obsolete mRcq and mRcw options.

gcc/

* common/config/arc/arc-common.cc (arc_option_optimization_table):
Remove Rcq and Rcw options.
* config/arc/arc.opt (mRcq): Ignore option, preserve it for
backwards compatibility.
(mRcw): Likewise.
* doc/invoke.texi (mRcw, mRcq): Update document.

Signed-off-by: Claudiu Zissulescu <claziss@gmail.com>
2 years agoarc: Remove Rcq constraint.
Claudiu Zissulescu [Mon, 10 Oct 2022 07:27:12 +0000 (10:27 +0300)]
arc: Remove Rcq constraint.

gcc/
* config/arc/arc.cc (arc_check_short_reg_p): New function.
(arc_address_cost): Replace satisfies_constraint_Rcq with the
above new function.
(arc_output_addsi): Likewise.
(split_addsi): Likewise.
(split_subsi): Likewise.
* config/arc/arc.md (movqi_insn): Remove Rcq constraint.
(movhi_insn): Likewise.
(movsi_insn): Likewise.
(tst_movb): Likewise.
(tst): Likewise.
(tst_bitfield): Likewise.
(abssi2): Likewise.
(addsi3_mixed): Likewise.
(mulhisi3_reg): Likewise.
(umulhisi3_reg): Likewise.
(mulsi_600): Likewise.
(mul64): Likewise.
(subsi3_insn): Likewise.
(bicsi3_insn): Likewise.
(xorsi3): Likewise.
(negsi2): Likewise.
(one_cmplsi2): Likewise.
(lshrsi3_insn): Likewise.
(cmpsi_cc_insn_mixed): Likewise.
(cmpsi_cc_zn_insn): Likewise.
(btst): Likewise.
(cmpsi_cc_z_insn): Likewise.
(cmpsi_cc_c_insn): Likewise.
(indirect_jump): Likewise.
(casesi_jump): Likewise.
(call_i): Likewise.
(call_value_i): Likewise.
(bbit): Likewise.
(abssf2): Likewise.
(ashlsi2_cnt1): Likewise.
(lshrsi3_cnt1): Likewise.
(ashrsi3_cnt1): Likewise.
* config/arc/constraints.md (Rcq): Remove.

Signed-off-by: Claudiu Zissulescu <claziss@gmail.com>
2 years agoarc: Remove Rcw constraint
Claudiu Zissulescu [Mon, 10 Oct 2022 07:27:12 +0000 (10:27 +0300)]
arc: Remove Rcw constraint

gcc/Changelog:

* config/arc/arc.md (smaxsi3): Remove Rcw.
(sminsi3): Likewise.
(addsi3_mixed): Likewise.
(add_f_2): Likewise.
(subsi3_insn): Likewise.
(sub_f): Likewise.
(sub_n): Likewise.
(bset): Likewise.
(bxor): Likewise.
(bclr): Likewise.
(bset_insn): Likewise.
(bxor_insn): Likewise.
(bclr_insn): Likewise.
(bmsk_insn): Likewise.
(bicsi3_insn): Likewise.
(xorsi3): Likewise.
(negsi2): Likewise.
(lshrsi3_insn): Likewise.
(abssf2): Likewise.
(negsf2): Likewise.
* config/arc/constraints.md(Rcw): Remove it.

Signed-off-by: Claudiu Zissulescu <claziss@gmail.com>
2 years agoarc: Remove Rcr constraint
Claudiu Zissulescu [Mon, 10 Oct 2022 07:27:12 +0000 (10:27 +0300)]
arc: Remove Rcr constraint

gcc/ChangeLog:

* config/arc/arc.md(mulsi3_700): Remove Rcr.
(mulsi3_highpart): Likewise.
(umulsi3_highpart_i): Likewise.
(umulsi3_highpart_int): Likewise.
(macd): Likewise.
(macdu): Likewise.
* config/arc/constraints.md (Rcr): Remove it.

gcc/testsuite/ChangeLog:
* gcc.target/arc/tmac-2.c: Update test.

Signed-off-by: Claudiu Zissulescu <claziss@gmail.com>
2 years agoarc: Use negative enter pattern instruction's offsets
Claudiu Zissulescu [Mon, 10 Oct 2022 07:27:12 +0000 (10:27 +0300)]
arc: Use negative enter pattern instruction's offsets

The enter pattern instruction contains the necessary information for
the dwarf machinery to generate the appropriate dwarf code.  This
patch is fixing the register offsets related to CFA, and adds a test.

gcc/
* config/arc/arc.cc (arc_save_callee_enter): Use negative offsets.

gcc/testsuite
* gcc.target/arc/enter-dw2-1.c: New file.

Signed-off-by: Claudiu Zissulescu <claziss@gmail.com>
2 years agolibgfortran: Use `__gthread_t` instead of `pthread_t`
LIU Hao [Fri, 27 May 2022 15:12:48 +0000 (23:12 +0800)]
libgfortran: Use `__gthread_t` instead of `pthread_t`

It used to cause errors if a thread model other than `posix` was selected,
which looks like a leftover from a79878585a1c5e32bafbc6d1e73f91fd6e4293bf.

libgfortran/
* io/async.h (struct async_unit): Use `__gthread_t` instead
of `pthread_t`.

Signed-off-by: LIU Hao <lh_mouse@126.com>
Signed-off-by: Jonathan Yong <10walls@gmail.com>
2 years agoDaily bump.
GCC Administrator [Mon, 10 Oct 2022 00:16:29 +0000 (00:16 +0000)]
Daily bump.

2 years agopru: Add cbranchdi4 pattern
Dimitar Dimitrov [Sun, 18 Sep 2022 13:27:18 +0000 (16:27 +0300)]
pru: Add cbranchdi4 pattern

Manually expanding into 32-bit comparisons is much more efficient than
the default expansion into word-size comparisons.  Note that word for PRU
is 8-bit.

PR target/106562

gcc/ChangeLog:

* config/pru/pru-protos.h (pru_noteq_condition): New
function declaration.
* config/pru/pru.cc (pru_noteq_condition): New function.
* config/pru/pru.md (cbranchdi4): Define new pattern.

gcc/testsuite/ChangeLog:

* gcc.target/pru/pr106562-1.c: New test.
* gcc.target/pru/pr106562-2.c: New test.
* gcc.target/pru/pr106562-3.c: New test.
* gcc.target/pru/pr106562-4.c: New test.

Signed-off-by: Dimitar Dimitrov <dimitar@dinux.eu>
2 years agopru: Optimize DI shifts
Dimitar Dimitrov [Thu, 22 Sep 2022 20:08:43 +0000 (23:08 +0300)]
pru: Optimize DI shifts

If the number of shift positions is a constant, then the DI shift
operation is expanded to a sequence of 2 to 4 machine instructions.
That is more efficient than the default action to call libgcc.

gcc/ChangeLog:

* config/pru/pru.md (lshrdi3): New expand pattern.
(ashldi3): Ditto.

gcc/testsuite/ChangeLog:

* gcc.target/pru/ashiftdi-1.c: New test.
* gcc.target/pru/lshiftrtdi-1.c: New test.

Signed-off-by: Dimitar Dimitrov <dimitar@dinux.eu>
2 years agoMIPS: improve -march=native arch detection
YunQiang Su [Tue, 2 Aug 2022 10:57:18 +0000 (10:57 +0000)]
MIPS: improve -march=native arch detection

If we cannot get info from options and cpuinfo, we try to get from:
  1. getauxval(AT_BASE_PLATFORM), introduced since Linux 5.7
  2. _MIPS_ARCH from host compiler.

mnan=2008 option is also used if __mips_nan2008__ is used.
This can fix the wrong loader usage on r5/r6 platform with
 -march=native.

gcc/ChangeLog:
* config.gcc: set with_arch to default_mips_arch if no defined.
* config/mips/driver-native.cc (host_detect_local_cpu):
  try getauxval(AT_BASE_PLATFORM) and _MIPS_ARCH, too.
  pass -mnan=2008 if __mips_nan2008__ is defined.
* config.in: define HAVE_SYS_AUXV_H and HAVE_GETAUXVAL.
* configure.ac: detect sys/auxv.h and getauxval.
* configure: regenerated.

2 years agoDaily bump.
GCC Administrator [Sun, 9 Oct 2022 00:17:55 +0000 (00:17 +0000)]
Daily bump.

2 years agoFortran: error recovery for invalid types in array constructors [PR107000]
Harald Anlauf [Tue, 4 Oct 2022 21:04:06 +0000 (23:04 +0200)]
Fortran: error recovery for invalid types in array constructors [PR107000]

gcc/fortran/ChangeLog:

PR fortran/107000
* arith.cc (gfc_arith_error): Define error message for
ARITH_INVALID_TYPE.
(reduce_unary): Catch arithmetic expressions with invalid type.
(reduce_binary_ac): Likewise.
(reduce_binary_ca): Likewise.
(reduce_binary_aa): Likewise.
(eval_intrinsic): Likewise.
(gfc_real2complex): Source expression must be of type REAL.
* gfortran.h (enum arith): Add ARITH_INVALID_TYPE.

gcc/testsuite/ChangeLog:

PR fortran/107000
* gfortran.dg/pr107000.f90: New test.

Co-authored-by: Mikael Morin <mikael@gcc.gnu.org>
2 years agoc++: track whether we expect a TARGET_EXPR to be elided
Jason Merrill [Sat, 17 Sep 2022 10:04:05 +0000 (12:04 +0200)]
c++: track whether we expect a TARGET_EXPR to be elided

A discussion at Cauldron made me think that with the formalization of copy
elision in C++17, we should be able to determine before optimization which
TARGET_EXPRs will become temporaries and which are initializers.  This patch
implements that: we set TARGET_EXPR_ELIDING_P if it's used as an
initializer, and later check that we were right.

There's an exception in the cp_gimplify_expr check to allow extra
temporaries of non-addressable type: this is used by
gimplify_init_ctor_preeval to materialize subobjects of a CONSTRUCTOR on the
rhs of a MODIFY_EXPR rather than materializing the whole object.  If the
type isn't addressable, there's no way for a program to tell the difference,
so this is a valid optimization.

I considered changing replace_placeholders_for_class_temp_r to check
TARGET_EXPR_ELIDING_P instead of potential_prvalue_result_of, but decided
that would be wrong: if we have an eliding TARGET_EXPR inside a non-eliding
one, we would miss replacing its placeholders.

gcc/cp/ChangeLog:

* cp-tree.h (TARGET_EXPR_ELIDING_P): New.
(unsafe_copy_elision_p, set_target_expr_eliding)
(cp_build_init_expr): Declare.
* call.cc (unsafe_copy_elision_p): No longer static.
(build_over_call, build_special_member_call)
(build_new_method_call): Use cp_build_init_expr.
* coroutines.cc (expand_one_await_expression)
(build_actor_fn, flatten_await_stmt, handle_nested_conditionals)
(await_statement_walker, morph_fn_to_coro): Use cp_build_init_expr.
* cp-gimplify.cc (cp_gimplify_init_expr)
(cp_gimplify_expr): Check TARGET_EXPR_ELIDING_P.
(cp_fold_r): Propagate it.
(cp_fold): Use cp_build_init_expr.
* decl.cc (check_initializer): Use cp_build_init_expr.
* except.cc (build_throw): Use cp_build_init_expr.
* init.cc (get_nsdmi): Call set_target_expr_eliding.
(perform_member_init, expand_default_init, expand_aggr_init_1)
(build_new_1, build_vec_init): Use cp_build_init_expr.
* method.cc (do_build_copy_constructor): Use cp_build_init_expr.
* semantics.cc (simplify_aggr_init_expr, finalize_nrv_r)
(finish_omp_reduction_clause): Use cp_build_init_expr.
* tree.cc (build_target_expr): Call set_target_expr_eliding.
(bot_manip): Copy TARGET_EXPR_ELIDING_P.
* typeck.cc (cp_build_modify_expr): Call set_target_expr_eliding.
(check_return_expr): Use cp_build_modify_expr.
* typeck2.cc (split_nonconstant_init_1)
(split_nonconstant_init): Use cp_build_init_expr.
(massage_init_elt): Call set_target_expr_eliding.
(process_init_constructor_record): Clear TARGET_EXPR_ELIDING_P on
unsafe copy elision.
(set_target_expr_eliding, cp_build_init_expr): New.

2 years agoDaily bump.
GCC Administrator [Sat, 8 Oct 2022 00:17:29 +0000 (00:17 +0000)]
Daily bump.

2 years agoc++: fixes for derived-to-base reference binding [PR107085]
Marek Polacek [Wed, 5 Oct 2022 19:51:30 +0000 (15:51 -0400)]
c++: fixes for derived-to-base reference binding [PR107085]

This PR reports that

  struct Base {};
  struct Derived : Base {};
  static_assert(__reference_constructs_from_temporary(Base const&, Derived));

doesn't pass, which it should: it's just like

  const Base& b(Derived{});

where we bind 'b' to the Base subobject of a temporary object of type
Derived.  The ck_base conversion didn't have ->need_temporary_p set because
we didn't need to create a temporary object just for the base, but the whole
object is a temporary so we're still binding to a temporary.  Since the
Base subobject is an xvalue, a new function is introduced.

PR c++/107085

gcc/cp/ChangeLog:

* call.cc (conv_binds_ref_to_temporary): New.
(ref_conv_binds_directly): Rename to...
(ref_conv_binds_to_temporary): ...this.  Use
conv_binds_ref_to_temporary.
* cp-tree.h (ref_conv_binds_directly): Rename to...
(ref_conv_binds_to_temporary): ...this.
* method.cc (ref_xes_from_temporary): Use ref_conv_binds_to_temporary.
* parser.cc (warn_for_range_copy): Likewise.

gcc/testsuite/ChangeLog:

* g++.dg/ext/reference_constructs_from_temporary1.C: Adjust expected
result.
* g++.dg/ext/reference_converts_from_temporary1.C: Likewise.
* g++.dg/cpp0x/elision4.C: New test.

2 years agoSet discriminators for call stmts on the same line within the same basic block.
Eugene Rozenfeld [Thu, 21 Apr 2022 23:43:24 +0000 (16:43 -0700)]
Set discriminators for call stmts on the same line within the same basic block.

Call statements are possible split points of a basic block so they may end up
in different basic blocks by the time pass_ipa_auto_profile executes.

This change will also simplify call site lookups since now location with discriminator
will uniquely identify the call site (no callee function name is needed).

This change is based on commit 1e6c4a7a8fb8e20545bb9f9032d3854f3f794c18
by Dehao Chen in vendors/google/heads/gcc-4_8.

Tested on x86_64-pc-linux-gnu.

gcc/ChangeLog:
* tree-cfg.cc (assign_discriminators): Set discriminators for call stmts
on the same line within the same basic block.

2 years agoUse array_at_struct_end_p in __builtin_object_size [PR101836]
Qing Zhao [Fri, 7 Oct 2022 14:59:01 +0000 (14:59 +0000)]
Use array_at_struct_end_p in __builtin_object_size [PR101836]

Use array_at_struct_end_p to determine whether the trailing array
of a structure is flexible array member in __builtin_object_size.

gcc/ChangeLog:

PR tree-optimization/101836
* tree-object-size.cc (addr_object_size): Use array_at_struct_end_p
to determine a flexible array member reference.

gcc/testsuite/ChangeLog:

PR tree-optimization/101836
* gcc.dg/pr101836.c: New test.
* gcc.dg/pr101836_1.c: New test.
* gcc.dg/pr101836_2.c: New test.
* gcc.dg/pr101836_3.c: New test.
* gcc.dg/pr101836_4.c: New test.
* gcc.dg/pr101836_5.c: New test.
* gcc.dg/strict-flex-array-2.c: New test.
* gcc.dg/strict-flex-array-3.c: New test.

2 years agoAdd a new option -fstrict-flex-arrays[=n] and new attribute strict_flex_array
Qing Zhao [Fri, 7 Oct 2022 14:58:20 +0000 (14:58 +0000)]
Add a new option -fstrict-flex-arrays[=n] and new attribute strict_flex_array

Add the following new option -fstrict-flex-arrays[=n] and a corresponding
attribute strict_flex_array to GCC:

'-fstrict-flex-arrays'
     Control when to treat the trailing array of a structure as a flexible array
     member for the purpose of accessing the elements of such an array.
     The positive form is equivalent to '-fstrict-flex-arrays=3', which is the
     strictest.  A trailing array is treated as a flexible array member only when
     it declared as a flexible array member per C99 standard onwards.
     The negative form is equivalent to '-fstrict-flex-arrays=0', which is the
     least strict.  All trailing arrays of structures are treated as flexible
     array members.

'-fstrict-flex-arrays=LEVEL'
     Control when to treat the trailing array of a structure as a flexible array
     member for the purpose of accessing the elements of such an array.  The value
     of LEVEL controls the level of strictness

     The possible values of LEVEL are the same as for the
     'strict_flex_array' attribute (*note Variable Attributes::).

     You can control this behavior for a specific trailing array field
     of a structure by using the variable attribute 'strict_flex_array'
     attribute (*note Variable Attributes::).

'strict_flex_array (LEVEL)'
     The 'strict_flex_array' attribute should be attached to the trailing
     array field of a structure. It controls when to treat the trailing array
     field of a structure as a flexible array member for the purposes of accessing
     the elements of such an array. LEVEL must be an integer betwen 0 to 3.

     LEVEL=0 is the least strict level, all trailing arrays of
     structures are treated as flexible array members.  LEVEL=3 is the
     strictest level, only when the trailing array is declared as a
     flexible array member per C99 standard onwards ('[]'), it is
     treated as a flexible array member.

     There are two more levels in between 0 and 3, which are provided to
     support older codes that use GCC zero-length array extension
     ('[0]') or one-element array as flexible array members('[1]'): When
     LEVEL is 1, the trailing array is treated as a flexible array member
     when it is declared as either '[]', '[0]', or '[1]'; When
     LEVEL is 2, the trailing array is treated as a flexible array member
     when it is declared as either '[]', or '[0]'.

     This attribute can be used with or without the
     '-fstrict-flex-arrays'.  When both the attribute and the option
     present at the same time, the level of the strictness for the
     specific trailing array field is determined by the attribute.

gcc/c-family/ChangeLog:

* c-attribs.cc (handle_strict_flex_array_attribute): New function.
(c_common_attribute_table): New item for strict_flex_array.
* c.opt: (fstrict-flex-arrays): New option.
(fstrict-flex-arrays=): New option.

gcc/c/ChangeLog:

* c-decl.cc (flexible_array_member_type_p): New function.
(one_element_array_type_p): Likewise.
(zero_length_array_type_p): Likewise.
(add_flexible_array_elts_to_size): Call new utility
routine flexible_array_member_type_p.
(is_flexible_array_member_p): New function.
(finish_struct): Set the new DECL_NOT_FLEXARRAY flag.

gcc/cp/ChangeLog:

* module.cc (trees_out::core_bools): Stream out new bit
decl_not_flexarray.
(trees_in::core_bools): Stream in new bit decl_not_flexarray.

gcc/ChangeLog:

* doc/extend.texi: Document strict_flex_array attribute.
* doc/invoke.texi: Document -fstrict-flex-arrays[=n] option.
* print-tree.cc (print_node): Print new bit decl_not_flexarray.
* tree-core.h (struct tree_decl_common): New bit field
decl_not_flexarray.
* tree-streamer-in.cc (unpack_ts_decl_common_value_fields): Stream
in new bit decl_not_flexarray.
* tree-streamer-out.cc (pack_ts_decl_common_value_fields): Stream
out new bit decl_not_flexarray.
* tree.cc (array_at_struct_end_p): Update it with the new bit field
decl_not_flexarray.
* tree.h (DECL_NOT_FLEXARRAY): New flag.

gcc/testsuite/ChangeLog:

* g++.dg/strict-flex-array-1.C: New test.
* gcc.dg/strict-flex-array-1.c: New test.

2 years agoSpecialize paths to version.h in _vxworks-versions.h
Olivier Hainque [Fri, 7 Oct 2022 10:12:26 +0000 (10:12 +0000)]
Specialize paths to version.h in _vxworks-versions.h

The _vxworks-versions.h runtime file helps us control
the compilation of some library components depending on
the OS version extracted out of a system header.

The system header name is "version.h", and gcc has a
"version.h" file of its own.

gcc's version.h is now generated and the current
instance instead of the OS one, resulting in build failures
from

  #if !defined(_WRS_VXWORKS_MAJOR)
  #error "_WRS_VXWORKS_MAJOR undefined"
  #endif

This change introduces a twist in the way
_vxworks-versions.h #includes version.h, using a relative
path with components that will match in the OS include
dirs only.

The actual relative path is conditioned on _VSB_CONFIG_FILE
to accommodate a change in the include dirs organisation between
VxWorks 6 and 7.

2022-10-07  Olivier Hainque  <hainque@adacore.com>

gcc/
* config/vxworks/_vxworks-versions.h: Use OS specific
paths in #include of version.h.

2 years agoanalyzer: extract bits from integer constants [PR105783]
David Malcolm [Fri, 7 Oct 2022 16:41:59 +0000 (12:41 -0400)]
analyzer: extract bits from integer constants [PR105783]

Fix a false positive from -Wanalyzer-null-dereference due to -fanalyzer
failing to grok the value of a particular boolean field initialized to a
constant.

gcc/analyzer/ChangeLog:
PR analyzer/105783
* region-model.cc (selftest::get_bit): New function.
(selftest::test_bits_within_svalue_folding): New.
(selfftest::analyzer_region_model_cc_tests): Call it.
* svalue.cc (constant_svalue::maybe_fold_bits_within): Handle the
case of extracting a single bit.

gcc/testsuite/ChangeLog:
PR analyzer/105783
* gcc.dg/analyzer/pr105783.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2 years agolibiberty: Demangle variadic template lambdas
Nathan Sidwell [Fri, 30 Sep 2022 19:11:42 +0000 (12:11 -0700)]
libiberty: Demangle variadic template lambdas

Now we have templated lambdas, we can have variadic template lambdas,
and this leads to lambda signatures containing parameter packs.  But
just like 'auto' inside such a signature, we don't have a containing
template, and thus fail.  The fix is to check is_lambda_arg, just as
for a template parameter.  This allows us to demangle g++'s manglings
of such lambdas.

It's not a totally accurate demangling, because we don't mangle the
template head (that's a separate issue), but it is better than failing
to demangle.

Due to the way we print subexprs, we add an unnecessary parens around
the argument of the pack.  That's an orthogonal problem, for which the
solution is to have better knowledge of operator precedence.

libiberty/
* cp-demangle.c (d_print_comp_inner): Allow parameter packs
in a lambda signature.
* testsuite/demangle-expected: Add tests.