]> gcc.gnu.org Git - gcc.git/log
gcc.git
2 years agotestsuite: Backport testsuite changes from GCC 12 to GCC 11
Tamar Christina [Thu, 28 Apr 2022 11:32:26 +0000 (12:32 +0100)]
testsuite: Backport testsuite changes from GCC 12 to GCC 11

This backports the testsuite changes from mainline to GCC 11.
This enables some tests that were not running and fix some
unresolved cases. The test output are adjusted to what GCC 11 could detect.

gcc/testsuite/ChangeLog:

PR testsuite/105095
* gcc.dg/vect/complex/fast-math-bb-slp-complex-mul-float.c: Update for
codegen.
* gcc.dg/vect/complex/fast-math-complex-add-double.c: Likewise.
* gcc.dg/vect/complex/fast-math-complex-add-float.c: Likewise.
* gcc.dg/vect/complex/fast-math-complex-add-half-float.c: Likewise.
* gcc.dg/vect/complex/fast-math-complex-add-pattern-double.c: Likewise.
* gcc.dg/vect/complex/fast-math-complex-add-pattern-float.c: Likewise.
* gcc.dg/vect/complex/fast-math-complex-add-pattern-half-float.c:
Likewise.
* gcc.dg/vect/complex/fast-math-complex-mla-half-float.c: Likewise.
* gcc.dg/vect/complex/fast-math-complex-mls-double.c: Likewise.
* gcc.dg/vect/complex/fast-math-complex-mls-float.c: Likewise.
* gcc.dg/vect/complex/fast-math-complex-mls-half-float.c: Likewise.
* gcc.dg/vect/complex/fast-math-complex-mul-double.c: Likewise.
* gcc.dg/vect/complex/fast-math-complex-mul-float.c: Likewise.
* gcc.dg/vect/complex/fast-math-complex-mul-half-float.c: Likewise.
* gcc.dg/vect/vect.exp: Add extra letter to filter.

2 years agoDaily bump.
GCC Administrator [Thu, 28 Apr 2022 00:18:29 +0000 (00:18 +0000)]
Daily bump.

2 years agoc++: enum in generic lambda at global scope [PR105398]
Marek Polacek [Tue, 26 Apr 2022 20:12:58 +0000 (16:12 -0400)]
c++: enum in generic lambda at global scope [PR105398]

We crash compiling this test since r11-7993 which changed
lookup_template_class_1 so that we only call tsubst_enum when

  !uses_template_parms (current_nonlambda_scope ())

But here current_nonlambda_scope () is the global NAMESPACE_DECL ::, which
doesn't have a type, therefore is considered type-dependent.  So we don't
call tsubst_enum, and crash in tsubst_copy/CONST_DECL because we didn't
find the e1 enumerator.

I don't think any namespace can depend on any template parameter, so
this patch tweaks uses_template_parms.

PR c++/105398

gcc/cp/ChangeLog:

* pt.c (uses_template_parms): Return false for any NAMESPACE_DECL.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1y/lambda-generic-enum2.C: New test.

(cherry picked from commit 409edcca331296b53842c50d3b789e1b1ccc05e5)

2 years agoAVX512F: Add missing macro for mask(z?)_scalf_s[sd] [PR 105339]
Hongyu Wang [Fri, 22 Apr 2022 06:42:30 +0000 (14:42 +0800)]
AVX512F: Add missing macro for mask(z?)_scalf_s[sd] [PR 105339]

Add missing macro under O0 and adjust macro format for scalf
intrinsics.

gcc/ChangeLog:

PR target/105339
* config/i386/avx512fintrin.h (_mm512_scalef_round_pd):
Add parentheses for parameters and djust format.
(_mm512_mask_scalef_round_pd): Ditto.
(_mm512_maskz_scalef_round_pd): Ditto.
(_mm512_scalef_round_ps): Ditto.
(_mm512_mask_scalef_round_ps): Ditto.
(_mm512_maskz_scalef_round_ps): Ditto.
(_mm_scalef_round_sd): Use _mm_undefined_pd.
(_mm_scalef_round_ss): Use _mm_undefined_ps.
(_mm_mask_scalef_round_sd): New macro.
(_mm_mask_scalef_round_ss): Ditto.
(_mm_maskz_scalef_round_sd): Ditto.
(_mm_maskz_scalef_round_ss): Ditto.

gcc/testsuite/ChangeLog:

PR target/105339
* gcc.target/i386/sse-14.c: Add tests for new macro.

(cherry picked from commit 3c940d42701707559fabe49be99296f60fbc43e7)

2 years agoDaily bump.
GCC Administrator [Wed, 27 Apr 2022 00:18:38 +0000 (00:18 +0000)]
Daily bump.

2 years agolibphobos: Give _Unwind_Exception an alignment that best resembles __attribute__...
Iain Buclaw [Sat, 25 Sep 2021 17:50:52 +0000 (19:50 +0200)]
libphobos: Give _Unwind_Exception an alignment that best resembles __attribute__((aligned))

For interoperability with C++ EH, the alignment should match, otherwise
D may not be able to intercept exceptions thrown from C++.

libphobos/ChangeLog:

* libdruntime/gcc/unwind/generic.d (__aligned__): Define.
(_Unwind_Exception): Align struct to __aligned__.

(cherry picked from commit efa5449a094d3887e124d400ff0410af2c745b2d)

2 years agolibphobos: Don't call free on the TLS array in the emutls destroy function.
Iain Buclaw [Tue, 26 Apr 2022 13:10:09 +0000 (14:10 +0100)]
libphobos: Don't call free on the TLS array in the emutls destroy function.

Fixes a segfault seen on Darwin when a GC scan is ran after a thread has
been destroyed.  As the global emutlsArrays hash still has a reference
to the array itself, and tries to iterate all elements.

Setting the length to zero frees all allocated elements in the array,
and ensures that it is skipped when the _d_emutls_scan is called.

libphobos/ChangeLog:

* libdruntime/gcc/emutls.d (emutlsDestroyThread): Clear the per-thread
TLS array, don't call free().

(cherry picked from commit 796b7cbac3d553a91d37c3961b9391fb7e19d0c6)

2 years agolibstdc++: Add deduction guides for std::packaged_task [PR105375]
Jonathan Wakely [Mon, 25 Apr 2022 13:22:41 +0000 (14:22 +0100)]
libstdc++: Add deduction guides for std::packaged_task [PR105375]

This change was LWG 3117.

The test is copied from 20_util/function/cons/deduction.cc

libstdc++-v3/ChangeLog:

PR libstdc++/105375
* include/std/future (packaged_task): Add deduction guides.
* testsuite/30_threads/packaged_task/cons/deduction.cc: New test.

(cherry picked from commit a5cee0480c10bafa8ed65d49e5cedca23d98d7b7)

2 years agoDaily bump.
GCC Administrator [Tue, 26 Apr 2022 00:18:39 +0000 (00:18 +0000)]
Daily bump.

2 years agoDaily bump.
GCC Administrator [Mon, 25 Apr 2022 00:18:30 +0000 (00:18 +0000)]
Daily bump.

2 years agoDaily bump.
GCC Administrator [Sun, 24 Apr 2022 00:18:18 +0000 (00:18 +0000)]
Daily bump.

2 years agoDaily bump.
GCC Administrator [Sat, 23 Apr 2022 00:18:34 +0000 (00:18 +0000)]
Daily bump.

2 years agolibstdc++: Make atomic notify_one and notify_all non-const
Thomas W Rodgers [Fri, 22 Apr 2022 22:46:19 +0000 (15:46 -0700)]
libstdc++: Make atomic notify_one and notify_all non-const

<recording this here for future reference>
PR102994 "atomics: std::atomic<ptr>::wait is not marked const" raises the
issue that the current libstdc++ implementation marks the notify members
const, the implementation strategy used by libstdc++, as well as libc++
and the Microsoft STL, do not require the atomic to be mutable (it is hard
to conceive of a desirable implementation approach that would require it).
The original paper proposing the wait/notify functionality for atomics
(p1185) also had these members marked const for the first three revisions,
but that was changed without explanation in r3 and subsequent revisions of
the paper.

After raising the issue to the authors of p1185 and the author of the
libc++ implementation, the consensus seems to be "meh, it's harmless" so
there seems little appetite for an LWG issue to revisit the subject.

This patch changes the libstdc++ implementation to be in agreement with
the standard by removing const from those notify_one/notify_all members.

libstdc++-v3/ChangeLog:

PR libstdc++/102994
* include/bits/atomic_base.h (atomic_flag::notify_one,
notify_all): Remove const qualification.
(__atomic_base::notify_one, notify_all): Likewise.
* include/std/atomic (atomic<bool>::notify_one, notify_all):
Likewise.
(atomic::notify_one, notify_all): Likewise.
(atomic<T*>::notify_one, notify_all): Likewise.
(atomic_notify_one, atomic_notify_all): Likewise.
* testsuite/29_atomics/atomic/wait_notify/102994.cc: Adjust test
to account for change in notify_one/notify_all signature.

(cherry picked from commit 7c21556daf385fe9ece37319f574776dd7d8ab1c)

2 years agoc++: wrong error with constexpr COMPOUND_EXPR [PR105321]
Marek Polacek [Wed, 20 Apr 2022 20:02:52 +0000 (16:02 -0400)]
c++: wrong error with constexpr COMPOUND_EXPR [PR105321]

Here we issue a bogus error for the first assert in the test.  Therein
we have

<retval> = (void) (VIEW_CONVERT_EXPR<bool>(yes) || handle_error ());, VIEW_CONVERT_EXPR<int>(value);

which has a COMPOUND_EXPR, so we get to cxx_eval_constant_expression
<case COMPOUND_EXPR>.  The problem here is that we call

7044             /* Check that the LHS is constant and then discard it.  */
7045             cxx_eval_constant_expression (ctx, op0,
7046                                           true, non_constant_p, overflow_p,
7047                                           jump_target);

where lval is always true, so the PARM_DECL 'yes' is not evaluated into
its value.

Fixed by always passing false for 'lval' in cxx_eval_logical_expression;
there's no case where we actually expect an lvalue from a TRUTH_*.

PR c++/105321

gcc/cp/ChangeLog:

* constexpr.c (cxx_eval_logical_expression): Always pass false for lval
to cxx_eval_constant_expression.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/constexpr-105321.C: New test.

(cherry picked from commit 93b65ed9706e2ceb4be7b28c9ff9be759e68a614)

2 years agoc++: ambiguous call not diagnosed after DR2352 [PR97296]
Marek Polacek [Tue, 12 Apr 2022 21:30:30 +0000 (17:30 -0400)]
c++: ambiguous call not diagnosed after DR2352 [PR97296]

DR 2352 changed the definitions of reference-related (so that it uses
"similar type" instead of "same type") and of reference-compatible (use
a standard conversion sequence).  That means that reference-related is
now more broad, which means that we will be binding more things directly.

The original patch for DR 2352 caused some problems, which were fixed in
r276251 by creating a "fake" ck_qual in direct_reference_binding, so
that in

  void f(int *); // #1
  void f(const int * const &); // #2
  int *x;
  int main()
  {
    f(x); // call #1
  }

we call #1.  The extra ck_qual in #2 causes compare_ics to select #1,
which is a better match for "int *" because then we don't have to do
a qualification conversion.

Let's turn to the problem in this PR.  We have

  void f(const int * const &); // #1
  void f(const int *); // #2
  int *x;
  int main()
  {
    f(x);
  }

We arrive in compare_ics to decide which one is better. The ICS for #1
looks like

    ck_ref_bind      <-    ck_qual         <-   ck_identity
  const int *const &     const int *const         int *

and the ICS for #2 is

    ck_qual     <-  ck_rvalue   <-  ck_identity
  const int *          int *           int *

We strip the reference and then comp_cv_qual_signature when comparing two
ck_quals sees that "const int *" is a proper subset of "const int *const"
and we return -1.  But that's wrong; presumably the top-level "const"
should be ignored and the call should be ambiguous.  This patch adjust
the type of the "fake" ck_qual so that this problem doesn't arise.

PR c++/97296

gcc/cp/ChangeLog:

* call.c (direct_reference_binding): strip_top_quals when creating
a ck_qual.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/ref-bind4.C: Add dg-error.
* g++.dg/cpp0x/ref-bind8.C: New test.

(cherry picked from commit 85ae54e18b9a3cbe4feda921ecd77cf275177edf)

2 years agoDaily bump.
GCC Administrator [Fri, 22 Apr 2022 00:18:50 +0000 (00:18 +0000)]
Daily bump.

2 years agolibstdc++: Remove workaround for FE bug in std::tuple [PR96592]
Jonathan Wakely [Fri, 26 Nov 2021 17:46:47 +0000 (17:46 +0000)]
libstdc++: Remove workaround for FE bug in std::tuple [PR96592]

The FE bug was fixed, so we don't need this workaround now.

libstdc++-v3/ChangeLog:

PR libstdc++/96592
* include/std/tuple (tuple::is_constructible): Remove.

(cherry picked from commit 76c6be48b7841524974754f8ea7533b82c7de77e)

2 years agolibstdc++: Remove "no stronger" assertion in compare exchange [PR102177]
Jonathan Wakely [Thu, 2 Sep 2021 14:29:22 +0000 (15:29 +0100)]
libstdc++: Remove "no stronger" assertion in compare exchange [PR102177]

P0418R2 removed some preconditions from std::atomic::compare_exchange_*
but we still enforce them via __glibcxx_assert. This removes those
assertions.

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

PR c++/102177
* include/bits/atomic_base.h (__is_valid_cmpexch_failure_order):
New function to check if a memory order is valid for the failure
case of compare exchange operations.
(__atomic_base<I>::compare_exchange_weak): Simplify assertions
by using __is_valid_cmpexch_failure_order.
(__atomic_base<I>::compare_exchange_strong): Likewise.
(__atomic_base<P*>::compare_exchange_weak): Likewise.
(__atomic_base<P*>::compare_exchange_strong): Likewise.
(__atomic_impl::compare_exchange_weak): Add assertion.
(__atomic_impl::compare_exchange_strong): Likewise.
* include/std/atomic (atomic::compare_exchange_weak): Likewise.
(atomic::compare_exchange_strong): Likewise.

(cherry picked from commit dba1ab212292839572fda60df00965e094a11252)

2 years agolibstdc++: Fix test failures at -O0
Jonathan Wakely [Fri, 11 Feb 2022 21:17:05 +0000 (21:17 +0000)]
libstdc++: Fix test failures at -O0

libstdc++-v3/ChangeLog:

* testsuite/20_util/monotonic_buffer_resource/allocate.cc:
Ignore -Walloc-larger-than warning.
* testsuite/20_util/unsynchronized_pool_resource/allocate.cc:
Likewise.
* testsuite/29_atomics/atomic/cons/user_pod.cc: Compile with -O1
to avoid linker error for __atomic_is_lock_free.

(cherry picked from commit b02247346ea7e403d706b9ccabf9078c060adb9e)

2 years agolibstdc++: Fix ambiguous comparisons for iterators in C++20
Jonathan Wakely [Thu, 9 Dec 2021 22:22:42 +0000 (22:22 +0000)]
libstdc++: Fix ambiguous comparisons for iterators in C++20

Since r11-1571 (c++: Refinements to "more constrained") was changed in
the front end, the following comment from stl_iterator.h stopped being
true:

  // These extra overloads are not needed in C++20, because the ones above
  // are constrained with a requires-clause and so overload resolution will
  // prefer them to greedy unconstrained function templates.

The requires-clause is no longer considered when comparing unrelated
function templates. That means that the constrained operator== specified
in the standard is no longer more constrained than the pathological
comparison operators defined in the testsuite_greedy_ops.h header. This
was causing several tests to FAIL in C++20 mode:

FAIL: 23_containers/deque/types/1.cc (test for excess errors)
FAIL: 23_containers/vector/types/1.cc (test for excess errors)
FAIL: 24_iterators/move_iterator/greedy_ops.cc (test for excess errors)
FAIL: 24_iterators/normal_iterator/greedy_ops.cc (test for excess errors)
FAIL: 24_iterators/reverse_iterator/greedy_ops.cc (test for excess errors)

The solution is to restore some of the non-standard comparison operators
that are more specialized than the greedy operators in the testsuite.

libstdc++-v3/ChangeLog:

* include/bits/stl_iterator.h (operator==, operator<=>): Define
overloads for homogeneous specializations of reverse_iterator,
__normal_iterator and move_iterator.

(cherry picked from commit 2c7fb16b5283cf90c4a7f7470e91e1010ee80fcc)

2 years agolibstdc++: Fix test that fails in C++20 mode
Jonathan Wakely [Fri, 26 Nov 2021 22:53:02 +0000 (22:53 +0000)]
libstdc++: Fix test that fails in C++20 mode

This test was written to verify that the LWG 3265 changes work. But
those changes were superseded by LWG 3435, and the test is now incorrect
according to the current draft. The assignment operator is now
constrained to also require convertibility, which makes the test fail.

Change the Iter type to be convertible from int*, but make it throw an
exception if that conversion is used. Change the test from compile-only
to run, so we verify that the exception isn't thrown.

libstdc++-v3/ChangeLog:

* testsuite/24_iterators/move_iterator/dr3265.cc: Fix test to
account for LWG 3435 resolution.

(cherry picked from commit 52b769437a4d1ca50f4ef5bdad65b12115ded845)

2 years agofortran: Fix conv of UNION constructors [PR105310]
Fritz Reese [Tue, 19 Apr 2022 20:45:46 +0000 (16:45 -0400)]
fortran: Fix conv of UNION constructors [PR105310]

This fixes an ICE when a UNION is the (1+8*2^n)-th field in a DEC
STRUCTURE when compiled with -finit-derived -finit-local-zero.
The problem was CONSTRUCTOR_APPEND_ELT from within gfc_conv_union_initializer
modified the vector pointer, but the pointer was passed by-value,
so the old pointer from the caller (gfc_conv_structure) pointed to freed
memory.

PR fortran/105310

gcc/fortran/ChangeLog:

* trans-expr.c (gfc_conv_union_initializer): Pass vec* by reference.

gcc/testsuite/ChangeLog:

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

(cherry picked from commit c049f638da4f7b32b11e4d895184e0960bae5291)

2 years agolibstdc++: Fix filesystem::temp_directory_path [PR101709]
Jonathan Wakely [Mon, 2 Aug 2021 14:52:41 +0000 (15:52 +0100)]
libstdc++: Fix filesystem::temp_directory_path [PR101709]

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

PR libstdc++/101709
* src/filesystem/ops-common.h (get_temp_directory_from_env):
Add error_code parameter.
* src/c++17/fs_ops.cc (fs::temp_directory_path): Pass error_code
argument to get_temp_directory_from_env and check it.
* src/filesystem/ops.cc (fs::temp_directory_path): Likewise.

(cherry picked from commit 38fb24ba4d67254cea78731fc8d961903dad9646)

2 years agolibstdc++: Remove bogus assertion in std::from_chars [PR105324]
Jonathan Wakely [Thu, 21 Apr 2022 10:26:49 +0000 (11:26 +0100)]
libstdc++: Remove bogus assertion in std::from_chars [PR105324]

I'm not sure what I was thinking when I added this assertion, maybe it
was supposed to be alignment == 1 (which is what the pmr::string actually
uses). The simplest fix is to just remove the assertion.

The assertion is no longer enabled by default on trunk, but it's still
there for the --enablke-libstdcxx-debug build, and is still wrong. The
fix is needed on the gcc-11 branch.

libstdc++-v3/ChangeLog:

PR libstdc++/105324
* src/c++17/floating_from_chars.cc (buffer_resource::do_allocate):
Remove assertion.
* testsuite/20_util/from_chars/pr105324.cc: New test.

(cherry picked from commit cf37107522f465d9e12af01ba68d2d1df0f18d46)

2 years agolibstdc++: Use secure_getenv for filesystem::temp_directory_path() [PR65018]
Jonathan Wakely [Fri, 30 Jul 2021 12:56:14 +0000 (13:56 +0100)]
libstdc++: Use secure_getenv for filesystem::temp_directory_path() [PR65018]

This adds a configure check for the GNU extension secure_getenv and then
uses it for looking up TMPDIR and similar variables.

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

PR libstdc++/65018
* configure.ac: Check for secure_getenv.
* config.h.in: Regenerate.
* configure: Regenerate.
* src/filesystem/ops-common.h (get_temp_directory_from_env): New
helper function to obtain path from the environment.
* src/c++17/fs_ops.cc (fs::temp_directory_path): Use new helper.
* src/filesystem/ops.cc (fs::temp_directory_path): Likewise.
* testsuite/27_io/filesystem/operations/temp_directory_path.cc:
Print messages if test cannot be run.
* testsuite/experimental/filesystem/operations/temp_directory_path.cc:
Likewise. Fix incorrect condition. Use "TMP" to work with
Windows as well as POSIX.

(cherry picked from commit 3dbd4d94bf380f3efa8bba9b203ce7d4c8f47fbb)

2 years agolibstdc++: Ensure C++20 std::stringstream definitions use correct ABI
Jonathan Wakely [Tue, 30 Nov 2021 22:04:49 +0000 (22:04 +0000)]
libstdc++: Ensure C++20 std::stringstream definitions use correct ABI

The definitions of the new C++20 members of std::stringstream etc are
missing when --with-default-libstdcxx-abi=gcc4-compatible is used,
because all the explicit instantiations in src/c++20/sstream-inst.cc are
skipped.

This ensures the contents of that file are compiled with the new ABI, so
the same set of symbols are exported regardless of which ABI is active
by default.

libstdc++-v3/ChangeLog:

* src/c++20/sstream-inst.cc (_GLIBCXX_USE_CXX11_ABI): Define to
select new ABI.

(cherry picked from commit 56b07badf052fb140c4636f6d77cfc02d1ac357c)

2 years agolibstdc++: Fix tests that fail with fully-dynamic-string
Jonathan Wakely [Tue, 30 Nov 2021 16:07:21 +0000 (16:07 +0000)]
libstdc++: Fix tests that fail with fully-dynamic-string

Fix some tests that assume that a moved-from string is empty, or that
default constructing a string doesn't allocate.

libstdc++-v3/ChangeLog:

* testsuite/21_strings/basic_string/cons/char/moveable.cc: Allow
moved-from string to be non-empty.
* testsuite/21_strings/basic_string/cons/char/moveable2.cc:
Likewise.
* testsuite/21_strings/basic_string/cons/char/moveable2_c++17.cc:
Likewise.
* testsuite/21_strings/basic_string/cons/wchar_t/moveable.cc:
Likewise.
* testsuite/21_strings/basic_string/cons/wchar_t/moveable2.cc:
Likewise.
* testsuite/21_strings/basic_string/cons/wchar_t/moveable2_c++17.cc:
Likewise.
* testsuite/21_strings/basic_string/modifiers/assign/char/87749.cc:
Construct empty string before setting oom flag.
* testsuite/21_strings/basic_string/modifiers/assign/wchar_t/87749.cc:
Likewise.

(cherry picked from commit be30fc4ce085ef786f104c6a407ccd44e554cd54)

2 years agolibstdc++: Fix non-reserved name in <regex> header
Jonathan Wakely [Mon, 13 Dec 2021 13:36:33 +0000 (13:36 +0000)]
libstdc++: Fix non-reserved name in <regex> header

libstdc++-v3/ChangeLog:

* include/bits/regex_compiler.tcc (_Compiler::_M_match_token):
Use reserved name for parameter.
* testsuite/17_intro/names.cc: Check "token".

(cherry picked from commit b0e6a257f1862e217cdf19332ea0f7bad56dcddc)

2 years agolibstdc++: Add another non-reserved name to tests
Jonathan Wakely [Wed, 25 Aug 2021 22:19:25 +0000 (23:19 +0100)]
libstdc++: Add another non-reserved name to tests

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

* testsuite/17_intro/names.cc: Check 'sz'.

(cherry picked from commit ea5674687ac45fe7242c57220b699337899881f0)

2 years agolibstdc++: Add missing noexcept to lazy_split_view iterator (LWG 3593)
Jonathan Wakely [Tue, 11 Jan 2022 14:22:47 +0000 (14:22 +0000)]
libstdc++: Add missing noexcept to lazy_split_view iterator (LWG 3593)

This was approved at the October 2021 plenary. We already have noexcept
in the other places the issue adds it in the spec.

libstdc++-v3/ChangeLog:

* include/std/ranges (ranges::lazy_split_view::_InnerIter::end()):
Add neoxcept (LWG 3593).

(cherry picked from commit 46de918f9892e637845bd97b4ca95011d46d3733)

2 years agolibstdc++: Use std::construct_at in net::ip::address
Jonathan Wakely [Wed, 17 Nov 2021 15:05:43 +0000 (15:05 +0000)]
libstdc++: Use std::construct_at in net::ip::address

Using placement-new isn't valid in constant expressions, so this
replaces it with std::construct_at (via the std::_Construct function
that is usable before C++20).

libstdc++-v3/ChangeLog:

* include/experimental/internet (address): Use std::_Construct
to initialize union members.

(cherry picked from commit 5ea8803e65eb546f58d3dccf5aff94a1638ba8b2)

2 years agolibstdc++: Improvements to standard error category objects (part deux)
Jonathan Wakely [Wed, 22 Sep 2021 12:56:21 +0000 (13:56 +0100)]
libstdc++: Improvements to standard error category objects (part deux)

In r12-3860 the error categories in <system_error> were made final and
immortal, but I missed the categories for <future> and <ios>. This makes
the same changes to those.

libstdc++-v3/ChangeLog:

* src/c++11/cxx11-ios_failure.cc (io_error_category): Define
class and virtual functions as 'final'.
(io_category_instance): Use constinit union to make the object
immortal.
* src/c++11/future.cc (future_error_category): Define class and
virtual functions as 'final'.
(future_category_instance): Use constinit union.

(cherry picked from commit 096228d84e9238d97fe115623126373f5b67bdc1)

2 years agolibstdc++: Reorder constraints on std::span::span(Range&&) constructor.
Jonathan Wakely [Mon, 1 Nov 2021 11:32:39 +0000 (11:32 +0000)]
libstdc++: Reorder constraints on std::span::span(Range&&) constructor.

In PR libstdc++/103013 Tim Song pointed out that we could reorder the
constraints of this constructor. That's worth doing just to reduce the
work the compiler has to do during overload resolution, even if it isn't
needed to make the code in the PR work.

libstdc++-v3/ChangeLog:

* include/std/span (span(Range&&)): Reorder constraints.

(cherry picked from commit 09bc98098e4ad474d2ba9da52457b29bbd08874b)

2 years agolibstdc++: Avoid unwanted allocations in filesystem::path
Jonathan Wakely [Tue, 30 Nov 2021 16:18:23 +0000 (16:18 +0000)]
libstdc++: Avoid unwanted allocations in filesystem::path

When using COW strings, accessing _M_pathname[0] and similar non-const
accessors can cause the string to "leak", meaning it reallocates itself
if it shares ownership with another string object.

This causes test failures for --enable-fully-dynamic-string builds:
/home/jwakely/src/gcc/libstdc++-v3/testsuite/experimental/filesystem/path/construct/90634.cc:62: void test01(): Assertion 'bytes_allocated == 0' failed.
FAIL: experimental/filesystem/path/construct/90634.cc execution test

This FAIL happens because the fully-dynamic move constructor results in
shared ownership, so for path(std::move(std::string("foo"))) the
_M_pathname member shares ownership with the temporary, and the
non-const accesses in _M_split_cmpts() cause a new copy of the string to
be allocated. This un-sharing is wasteful, and entirely unnecessary when
sharing ownership with an rvalue that is about to release its ownership
anyway. Even for lvalues, sharing ownership is not a problem and
reallocating a unique copy of the string is wasteful.

This removes non-const accesses of _M_pathname in the
path::_M_split_cmpts() members.

libstdc++-v3/ChangeLog:

* src/c++17/fs_path.cc (path::_M_split_cmpts()): Remove
micro-optimization for "/" path.
* src/filesystem/path.cc (path::_M_split_cmpts()): Only access
the contents of _M_pathname using const member functions.

(cherry picked from commit e9089e4fa9f726405a83d8ce46baeda469ca1a1d)

2 years agolibstdc++: Add self-merge check to std::forward_list::merge [PR103853]
Pavel I. Kryukov [Thu, 6 Jan 2022 12:32:36 +0000 (12:32 +0000)]
libstdc++: Add self-merge check to std::forward_list::merge [PR103853]

This implements the proposed resolution of LWG 3088, so that x.merge(x)
is a no-op, consistent with std::list::merge.

Signed-off-by: Pavel I. Kryukov <pavel.kryukov@phystech.edu>
Co-authored-by: Jonathan Wakely <jwakely@redhat.com>
libstdc++-v3/ChangeLog:

PR libstdc++/103853
* include/bits/forward_list.tcc (forward_list::merge): Check for
self-merge.
* testsuite/23_containers/forward_list/operations/merge.cc: New test.

(cherry picked from commit 52ebc2be0990d6d3a46bb716164f9cef6f661021)

2 years agolibstdc++: Ignore cv-quals when std::allocator<void> constructs
Jonathan Wakely [Thu, 13 Jan 2022 21:59:13 +0000 (21:59 +0000)]
libstdc++: Ignore cv-quals when std::allocator<void> constructs

When I added the std::allocator_traits<std::allocator<void>>
specialization it broke code like this:

  std::allocate_shared<const int>(std::allocator<void>());

The problem is that allocator_traits<allocator<void>>::construct(a, p)
now uses std::_Construct(p), which only does a static_cast<void*>(p) and
so fails if the pointer has cv-quals.

This changes std::_Construct (and the related std::_Construct_novalue)
to use a C-style cast to (void*) which matches the effects of the
"voidify" helper in the C++20 standard.

libstdc++-v3/ChangeLog:

* include/bits/stl_construct.h (_Construct, _Construct_novalue):
Also cast away cv-qualifiers when converting pointer to void.
* testsuite/20_util/allocator/void.cc: Test construct function
with cv-qualified types.

(cherry picked from commit fc6f1128ae603164aea6303ce2b3ed0b57e6a378)

2 years agolibstdc++: Do not use std::isdigit in <charconv> [PR103911]
Jonathan Wakely [Wed, 5 Jan 2022 16:25:47 +0000 (16:25 +0000)]
libstdc++: Do not use std::isdigit in <charconv> [PR103911]

This avoids a potential race condition if std::setlocale is used
concurrently with std::from_chars.

libstdc++-v3/ChangeLog:

PR libstdc++/103911
* include/std/charconv (__from_chars_alpha_to_num): Return
char instead of unsigned char. Change invalid return value to
127 instead of using numeric trait.
(__from_chars_alnum): Fix comment. Do not use std::isdigit.
Change type of variable to char.

(cherry picked from commit c83ecfbe74a5cf107642b9c5e1680b548ff1a0e1)

2 years agolibstdc++: Avoid overflow in ranges::advance(i, n, bound)
Jonathan Wakely [Wed, 26 Jan 2022 16:08:51 +0000 (16:08 +0000)]
libstdc++: Avoid overflow in ranges::advance(i, n, bound)

When (bound - i) or n is the most negative value of its type, the
negative of the value will overflow. Instead of abs(n) >= abs(bound - i)
use n >= (bound - i) when positive and n <= (bound - i) when negative.
The function has a precondition that they must have the same sign, so
this works correctly. The precondition check can be moved into the else
branch, and simplified.

The standard requires calling ranges::advance(i, bound) even if i==bound
is already true, which is technically observable, but that's pointless.
We can just return n in that case. Similarly, for i!=bound but n==0 we
are supposed to call ranges::advance(i, n), but that's pointless. An LWG
issue to allow omitting the pointless calls is expected to be filed.

libstdc++-v3/ChangeLog:

* include/bits/ranges_base.h (ranges::advance): Avoid signed
overflow. Do nothing if already equal to desired result.
* testsuite/24_iterators/range_operations/advance_overflow.cc:
New test.

(cherry picked from commit f21f22d1baf7e90f3edbfc48040c76fb14103803)

2 years agolibstdc++: Increase timeout for pthread7-rope.cc test
Jonathan Wakely [Thu, 6 Jan 2022 11:10:31 +0000 (11:10 +0000)]
libstdc++: Increase timeout for pthread7-rope.cc test

This test spawns thousands of threads and so times out if the tests are
run with a low timeout value and the machine is busy.

libstdc++-v3/ChangeLog:

* testsuite/ext/rope/pthread7-rope.cc: Add dg-timeout-factor.

(cherry picked from commit e19e2989c36c5148ceb67a1f2575718fc1927ce6)

2 years agolibstdc++: Fix test failure on AIX
Jonathan Wakely [Thu, 3 Mar 2022 22:20:32 +0000 (22:20 +0000)]
libstdc++: Fix test failure on AIX

This fixes a test failure due to a non-reserved name in an AIX system
header (included via <pthread.h>). That name clashes with one of the
names we check our own headers for, so skip checking that name on AIX.

libstdc++-v3/ChangeLog:

* testsuite/17_intro/names.cc (func): Undef on AIX.

(cherry picked from commit 64cdf49962996747b4c5687a705551d5fc61fac8)

2 years agolibstdc++: Use LTLIBICONV when linking libstdc++.so [PR93602]
Jonathan Wakely [Wed, 13 Apr 2022 13:09:33 +0000 (14:09 +0100)]
libstdc++: Use LTLIBICONV when linking libstdc++.so [PR93602]

This fixes missing libiconv symbols when libstdc++ is built on a system
that has libiconv installed. If the libiconv headers are found then
libstdc++ depends on libiconv_open etc instead of libc's iconv_open. But
without this fix libstdc++ is not linked to the libiconv library that
provides the definitions of those symbols.

As discussed in PR 93602 this changed means that libstdc++.so.6 might
have an rpath pointing to the location of the libiconv.so library. If
that is not desired, then GCC must be configured to link to a static
libiconv.a instead, using either --with-libiconv-type=static or an
in-tree build of libiconv.

libstdc++-v3/ChangeLog:

PR libstdc++/93602
* doc/xml/manual/prerequisites.xml: Document libiconv
workarounds.
* doc/html/manual/setup.html: Regenerate.
* src/Makefile.am (CXXLINK): Add $(LTLIBICONV).
* src/Makefile.in: Regenerate.

(cherry picked from commit c644b7df11afc818d6308c3776813e50e4ebe551)

2 years agolibstdc++: Fix incorrect IS number in doc comment
Jonathan Wakely [Thu, 14 Apr 2022 10:54:26 +0000 (11:54 +0100)]
libstdc++: Fix incorrect IS number in doc comment

libstdc++-v3/ChangeLog:

* doc/xml/manual/intro.xml: Fix comment.

(cherry picked from commit 832fcbbc7311c706f81e85043b5721e5f16b0a16)

2 years agolibstdc++: Fix macro checked by test
Jonathan Wakely [Wed, 20 Apr 2022 12:50:14 +0000 (13:50 +0100)]
libstdc++: Fix macro checked by test

The macro being tested here is wrong, but just happens to have the same
value as the one supposed to be tested.

libstdc++-v3/ChangeLog:

* testsuite/21_strings/basic_string_view/operations/copy/char/constexpr.cc:
Check correct feature test macro.

(cherry picked from commit 67ded3a1f5b667b4cb5eb2fee8a031e8e4060a7d)

2 years agolibstdc++: Fix warning in __moneypunct_cache::_M_cache [PR104966]
Jonathan Wakely [Thu, 17 Mar 2022 13:33:07 +0000 (13:33 +0000)]
libstdc++: Fix warning in __moneypunct_cache::_M_cache [PR104966]

GCC thinks the following can lead to a buffer overflow when __ns.size()
equals zero:

  const basic_string<_CharT>& __ns = __mp.negative_sign();
  _M_negative_sign_size = __ns.size();
  __negative_sign = new _CharT[_M_negative_sign_size];
  __ns.copy(__negative_sign, _M_negative_sign_size);

This happens because operator new might be replaced with something that
writes to this->_M_negative_sign_size and so the basic_string::copy call
could use a non-zero size to write to a zero-length buffer.

The solution suggested by Richi is to cache the size in a local variable
so that the compiler knows it won't be changed between the allocation
and the copy.

libstdc++-v3/ChangeLog:

PR middle-end/104966
* include/bits/locale_facets_nonio.tcc
(__moneypunct_cache::_M_cache): Store string sizes in local
variable that doesn't escape.

2 years agolibstdc++: Avoid -Wzero-as-null-pointer-constant warning [PR103848]
Jonathan Wakely [Tue, 4 Jan 2022 21:57:16 +0000 (21:57 +0000)]
libstdc++: Avoid -Wzero-as-null-pointer-constant warning [PR103848]

libstdc++-v3/ChangeLog:

PR libstdc++/103848
* include/bits/stl_deque.h (operator-): Do not use 0 as null
pointer constant.

(cherry picked from commit 76a45931ab7c831e32cebf13a6317e5e142f8151)

2 years agosparc: Preserve ORIGINAL_REGNO in epilogue_renumber [PR105257]
Jakub Jelinek [Tue, 19 Apr 2022 16:58:59 +0000 (18:58 +0200)]
sparc: Preserve ORIGINAL_REGNO in epilogue_renumber [PR105257]

The following testcase ICEs, because the pic register is
(reg:DI 24 %i0 [109]) and is used in the delay slot of a return.
We invoke epilogue_renumber and that changes it to
(reg:DI 8 %o0) which no longer satisfies sparc_pic_register_p
predicate, so we don't recognize the insn anymore.

The following patch fixes that by preserving ORIGINAL_REGNO if
specified, so we get (reg:DI 8 %o0 [109]) instead.

2022-04-19  Jakub Jelinek  <jakub@redhat.com>

PR target/105257
* config/sparc/sparc.c (epilogue_renumber): If ORIGINAL_REGNO,
use gen_raw_REG instead of gen_rtx_REG and copy over also
ORIGINAL_REGNO.  Use return 0; instead of /* fallthrough */.

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

(cherry picked from commit eeca2b8bd03f57c59c6cf48bf6b9bd6dc86924f6)

2 years agoemit-rtl: Fix -fcompare-debug bug with label references in debug insns [PR105203]
Jakub Jelinek [Thu, 21 Apr 2022 07:43:30 +0000 (09:43 +0200)]
emit-rtl: Fix -fcompare-debug bug with label references in debug insns [PR105203]

When we compute LABEL_NUSES from scratch, mark_all_labels doesn't call
mark_jump_label on DEBUG_INSNs:
              if (NONDEBUG_INSN_P (insn))
                mark_jump_label (PATTERN (insn), insn, 0);
and so doesn't increment LABEL_NUSES from references in DEBUG_INSNs.
But, when we call emit_copy_of_insn_after e.g. when duplicating some
DEBUG_INSNs, we call it even on those, which then results in LABEL_NUSES
differences and -fcompare-debug failures.

The following patch makes sure we don't call it on DEBUG_INSNs.

2022-04-21  Jakub Jelinek  <jakub@redhat.com>

PR debug/105203
* emit-rtl.c (emit_copy_of_insn_after): Don't call mark_jump_label
on DEBUG_INSNs.

* gfortran.dg/g77/pr105203.f: New test.

(cherry picked from commit 504b02c70abcc31e0e9b56e69f82f85b5261bca9)

2 years agogcov-profile: Allow negative counts of indirect calls [PR105282]
Sergei Trofimovich [Fri, 15 Apr 2022 07:35:27 +0000 (08:35 +0100)]
gcov-profile: Allow negative counts of indirect calls [PR105282]

TOPN metrics are histograms that contain overall count and per-bucket
count. Overall count can be negative when two profiles merge and some
of per-bucket metrics are disacarded.

Noticed as an ICE on python PGO build where gcc crashes as:

    during IPA pass: modref
    a.c:36:1: ICE: in stream_out_histogram_value, at value-prof.cc:340
       36 | }
          | ^
    stream_out_histogram_value(output_block*, histogram_value_t*)
            gcc/value-prof.c:340

gcc/ChangeLog:

PR gcov-profile/105282
* value-prof.c (stream_out_histogram_value): Allow negative counts
on HIST_TYPE_INDIR_CALL.

(cherry picked from commit 90a29845bfe7d6002e6c2fd49a97820b00fbc4a3)

2 years agoc++: don't ICE on NAMESPACE_DECL inside FUNCTION_DECL
Matthias Kretz [Wed, 15 Dec 2021 08:45:06 +0000 (09:45 +0100)]
c++: don't ICE on NAMESPACE_DECL inside FUNCTION_DECL

Code like
  void swap() {
    namespace __variant = __detail::__variant;
    ...
  }
create a NAMESPACE_DECL where the CP_DECL_CONTEXT is a FUNCTION_DECL.
DECL_TEMPLATE_INFO fails on NAMESPACE_DECL and therefore must be handled
first in the assertion.

Signed-off-by: Matthias Kretz <m.kretz@gsi.de>
gcc/cp/ChangeLog:

* module.cc (trees_out::get_merge_kind): NAMESPACE_DECLs also
cannot have a DECL_TEMPLATE_INFO.

(cherry picked from commit 6bcb6ed5a44b6f271891246ef7ae568bfdc14e9c)

2 years agoUpdate BASE-VER to 11.3.1
Richard Biener [Thu, 21 Apr 2022 08:12:46 +0000 (10:12 +0200)]
Update BASE-VER to 11.3.1

This updates BASE-VER to 11.3.1 after the 11.3 release.

2022-04-21  Richard Biener  <rguenther@suse.de>

* BASE-VER: Set to 11.3.1

2 years agoUpdate ChangeLog and version files for release releases/gcc-11.3.0
Richard Biener [Thu, 21 Apr 2022 07:59:17 +0000 (07:59 +0000)]
Update ChangeLog and version files for release

2 years agoDaily bump.
GCC Administrator [Thu, 21 Apr 2022 00:18:25 +0000 (00:18 +0000)]
Daily bump.

2 years agoc++: Fix up CONSTRUCTOR_PLACEHOLDER_BOUNDARY handling [PR105256]
Jakub Jelinek [Tue, 19 Apr 2022 16:27:41 +0000 (18:27 +0200)]
c++: Fix up CONSTRUCTOR_PLACEHOLDER_BOUNDARY handling [PR105256]

The CONSTRUCTOR_PLACEHOLDER_BOUNDARY bit is supposed to separate
PLACEHOLDER_EXPRs that should be replaced by one object or subobjects of it
(variable, TARGET_EXPR slot, ...) from other PLACEHOLDER_EXPRs that should
be replaced by different objects or subobjects.
The bit is set when finding PLACEHOLDER_EXPRs inside of a CONSTRUCTOR, not
looking into nested CONSTRUCTOR_PLACEHOLDER_BOUNDARY ctors, and we prevent
elision of TARGET_EXPRs (through TARGET_EXPR_NO_ELIDE) whose initializer
is a CONSTRUCTOR_PLACEHOLDER_BOUNDARY ctor.  The following testcase ICEs
though, we don't replace the placeholders in there at all, because
CONSTRUCTOR_PLACEHOLDER_BOUNDARY isn't set on the TARGET_EXPR_INITIAL
ctor, but on a ctor nested in such a ctor.  replace_placeholders should be
run on the whole TARGET_EXPR slot.

So, the following patch fixes it by moving the CONSTRUCTOR_PLACEHOLDER_BOUNDARY
bit from nested CONSTRUCTORs to the CONSTRUCTOR containing those (but only
if it is closely nested, if there is some other tree sandwiched in between,
it doesn't do it).

2022-04-19  Jakub Jelinek  <jakub@redhat.com>

PR c++/105256
* typeck2.c (process_init_constructor_array,
process_init_constructor_record, process_init_constructor_union): Move
CONSTRUCTOR_PLACEHOLDER_BOUNDARY flag from CONSTRUCTOR elements to the
containing CONSTRUCTOR.

* g++.dg/cpp0x/pr105256.C: New test.

(cherry picked from commit eb03e424598d30fed68801af6d6ef6236d32e32e)

2 years agoDaily bump.
GCC Administrator [Wed, 20 Apr 2022 00:18:12 +0000 (00:18 +0000)]
Daily bump.

2 years agodoc/install.texi: CRIS: Remove gone websites. Adjust CRIS targets
Hans-Peter Nilsson [Mon, 18 Apr 2022 22:30:43 +0000 (00:30 +0200)]
doc/install.texi: CRIS: Remove gone websites. Adjust CRIS targets

That is, support for cris-linux-gnu was removed in gcc-11, but
install.texi wasn't adjusted accordingly.  Also, unfortunately the
developer-related sites are gone with no replacements.  And, CRIS is
used in other chip series as well, but allude rather than list.

The generated manpages, info, pdf and html were sanity-checked.

gcc:
* doc/install.texi <CRIS>: Remove references to removed websites and
adjust for cris-*-elf being the only remaining toolchain.
(cherry picked from commit d2a0a5d4ad23f1974c72ef8abaa55c1707c0b27f)

2 years agodoc/invoke.texi: CRIS: Remove references to cris-axis-linux-gnu
Hans-Peter Nilsson [Mon, 18 Apr 2022 22:30:24 +0000 (00:30 +0200)]
doc/invoke.texi: CRIS: Remove references to cris-axis-linux-gnu

...and related options.  These stale bits were overlooked when support
for "Linux/GNU" and CRIS v32 was removed, before the gcc-11 release.

Resulting pdf, html and info inspected for sanity.

gcc:
* doc/invoke.texi <CRIS>: Remove references to options for removed
subtarget cris-axis-linux-gnu and tweak wording accordingly.
(cherry picked from commit a897a88c592cd7abcf3869fcd7b667a016eccc89)

2 years agotree-optimization/104880 - move testcase
Richard Biener [Tue, 19 Apr 2022 11:48:02 +0000 (13:48 +0200)]
tree-optimization/104880 - move testcase

This renames the testcase to something picked up by the suites regexp.

2022-04-19  Richard Biener  <rguenther@suse.de>

PR tree-optimization/104880
* g++.dg/opt/pr104880.cc: Rename to ...
* g++.dg/opt/pr104880.C: ... this.

(cherry picked from commit 214d2860f4e1573f04ef57bfea59da0cc66883ce)

2 years agoDaily bump.
GCC Administrator [Tue, 19 Apr 2022 00:18:21 +0000 (00:18 +0000)]
Daily bump.

2 years agoDaily bump.
GCC Administrator [Mon, 18 Apr 2022 00:18:28 +0000 (00:18 +0000)]
Daily bump.

2 years agoDaily bump.
GCC Administrator [Sun, 17 Apr 2022 00:18:30 +0000 (00:18 +0000)]
Daily bump.

2 years agoDaily bump.
GCC Administrator [Sat, 16 Apr 2022 00:18:40 +0000 (00:18 +0000)]
Daily bump.

2 years agoDaily bump.
GCC Administrator [Fri, 15 Apr 2022 00:18:46 +0000 (00:18 +0000)]
Daily bump.

2 years agolibstdc++: Update incorrect statement about mainline in docs
Jonathan Wakely [Thu, 14 Apr 2022 10:22:40 +0000 (11:22 +0100)]
libstdc++: Update incorrect statement about mainline in docs

libstdc++-v3/ChangeLog:

* doc/xml/manual/status_cxx1998.xml: Refer to GCC 11 not
mainline.
* doc/xml/manual/status_cxx2011.xml: Likewise.
* doc/xml/manual/status_cxx2014.xml: Likewise.
* doc/xml/manual/status_cxx2017.xml: Likewise.
* doc/xml/manual/status_cxx2020.xml: Likewise.
* doc/xml/manual/status_cxxtr1.xml: Likewise.
* doc/xml/manual/status_cxxtr24733.xml: Likewise.
* doc/html/manual/status.html: Regenerate.

2 years agoIBM zSystems: Add support for z16 as CPU name.
Andreas Krebbel [Wed, 13 Apr 2022 05:41:08 +0000 (07:41 +0200)]
IBM zSystems: Add support for z16 as CPU name.

So far z16 was identified as arch14. After the machine has been
announced we can now add the real name.

gcc/ChangeLog:

* common/config/s390/s390-common.c: Rename PF_ARCH14 to PF_Z16.
* config.gcc: Add z16 as march/mtune switch.
* config/s390/driver-native.c (s390_host_detect_local_cpu):
Recognize z16 with -march=native.
* config/s390/s390-opts.h (enum processor_type): Rename
PROCESSOR_ARCH14 to PROCESSOR_3931_Z16.
* config/s390/s390.c (PROCESSOR_ARCH14): Rename to ...
(PROCESSOR_3931_Z16): ... throughout the file.
(s390_processor processor_table): Add z16 as cpu string.
* config/s390/s390.h (enum processor_flags): Rename PF_ARCH14 to
PF_Z16.
(TARGET_CPU_ARCH14): Rename to ...
(TARGET_CPU_Z16): ... this.
(TARGET_CPU_ARCH14_P): Rename to ...
(TARGET_CPU_Z16_P): ... this.
(TARGET_ARCH14): Rename to ...
(TARGET_Z16): ... this.
(TARGET_ARCH14_P): Rename to ...
(TARGET_Z16_P): ... this.
* config/s390/s390.md (cpu_facility): Rename arch14 to z16 and
check TARGET_Z16 instead of TARGET_ARCH14.
* config/s390/s390.opt: Add z16 to processor_type.
* doc/invoke.texi: Document z16 and arch14.

(cherry picked from commit 82a4c5c704433249aa2adc89ef58b6b70e50c930)

2 years agoDarwin, rs6000: Amend lo_sum use for forced constants [PR104117].
Iain Sandoe [Mon, 7 Feb 2022 15:36:35 +0000 (15:36 +0000)]
Darwin, rs6000: Amend lo_sum use for forced constants [PR104117].

Two issues resulted in this PR, which manifests when we force a constant into
memory in LRA (in PIC code on Darwin).  The presence of such forced constants
is quite dependent on other RTL optimisations, and it is easy for the issue to
become latent for a specific case.

First, in the Darwin-specific rs6000 backend code, we were not being careful
enough in rejecting invalid symbolic addresses.  Specifically, when generating
PIC code, we require a SYMBOL_REF to be wrapped in an UNSPEC_MACHOPIC_OFFSET.

We now split the Darwin high/low selectors into two:
 1. One that handles non-PIC addresses (kernel mode, mdynamic-no-pic).
 2. One that handles PIC addresses and rejects SYMBOL_REFs unless they are
    suitably wrapped in the MACHOPIC_OFFSET unspec.

The second case is handled by providing a new predicate (macho_pic_address)
that checks the requirements.

Backported from 4c3792d448964f7bd99e7eac2c29c9eb7c2bfb84 and
f1b3e3853329b58fb2e50c17487df2ecbc4a5608

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
Co-authored-by: Vladimir Makarov <vmakarov@redhat.com>
PR target/104117

gcc/ChangeLog:

* config/rs6000/rs6000.c (darwin_rs6000_legitimate_lo_sum_const_p):
Check for UNSPEC_MACHOPIC_OFFSET wrappers on symbolic addresses when
emitting PIC code.
(legitimate_lo_sum_address_p): Likewise.
(rs6000_legitimize_address): Do not apply the TLS processing to
Darwin.
* config/rs6000/darwin.md (@machopic_high_<mode>): New.
(@machopic_low_<mode>): New.
* config/rs6000/predicates.md (macho_pic_address): New.

2 years agoDarwin: Rework handling for unwinder code in libgcc_s and specs [PR80556].
Iain Sandoe [Sat, 18 Sep 2021 22:38:53 +0000 (23:38 +0100)]
Darwin: Rework handling for unwinder code in libgcc_s and specs [PR80556].

This addresses a long-standing problem where a work-around for an unwinder
issue (also a regression) regresses other functionality.  The patch replaces
several work-arounds with a fix for PR80556 and a work-around for PR88590.

* The fix for PR80556 requires a bump to the SO name for libgcc_s, since we
need to remove the unwinder symbols from it.  This would trigger PR88590
hence the work-around for that.

* We weaken the symbols for emulated TLS support so that it is possible
for a DSO linked with static-libgcc to interoperate with a DSO linked with
libgcc_s.  Likewise main exes.

* We remove all the gcc-4.2.1 era stubs machinery and workarounds.

* libgcc is always now linked ahead of libc, which avoids fails where the
libc (libSystem) builtins implementations are not up to date.

* The unwinder now always comes from the system
 - for Darwin9 from /usr/lib/libgcc_s.1.dylib
 - for Darwin10 from /usr/lib/libSystem.dylib
 - for Darwin11+ from /usr/lib/system/libunwind.dylib.

 We still insert a shim on Darwin10 to fix an omitted unwind function, but
 the underlying unwinder remains the system one.

* The work-around for PR88590 has two parts (1) we always link libgcc from
its convenience lib on affected system versions (avoiding the need to find
the DSO path); (2) we add and export the emutls functions from DSOs - this
makes a relatively small (20k) addition to a DSO.  These can be backed out
when a proper fix for PR88590 is committed.

For distributions that wish to install a libgcc_s.1.dylib to satisfy linkage
from exes that linked against the stubs can use a reexported libgcc_s.1.1
(since that contains all the symbols that were previously exported via the
 stubs).

The replacement libgcc_s.1 forwards the symbols from the new SO.
In order to support DYLD_LIBRARY_PATH on systems (where it works)
we forward the libSystem unwinder symbols from 10.7+ and a
compiler-local version of the libgcc unwinder on earlier.

For macOS 10.4 to 10.6 this is 'bug-compatible' with existing uses.
For 10.7+ the behaviour will now actually be correct.

Backported from commits d4943ce939d9654932624b9ece24c3a474ae4157,
7add7f7bb3d35726a0c45322ffdbbab2bbf6a348,
b504917e43b9a559c9ac779e08784ad412125f2e,
32731fa5b0abf092029b8e2be64319b978bda514,
574c09da48a5a0ff4c32dd4577eaf65bac8c94a0 and
c18ddb05b0391a397f8882fc6a12a1bab7e0df52

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
gcc/ChangeLog:

PR target/80556
* config/darwin-driver.c (darwin_driver_init): Handle exported
symbols and symbol lists (suppress automatic export of the TLS
symbols).
* config/darwin.c (darwin_rename_builtins): Remove workaround.
* config/darwin.h (LINK_GCC_C_SEQUENCE_SPEC): Likewise.
(REAL_LIBGCC_SPEC): Handle revised library uses.
* config/darwin.opt (nodefaultexport): New.
* config/i386/darwin.h (PR80556_WORKAROUND): Remove.
* config/i386/darwin32-biarch.h (PR80556_WORKAROUND): Likewise.
* config/i386/darwin64-biarch.h (PR80556_WORKAROUND): Likewise.

libgcc/ChangeLog:

* config.host: Add weak emutls crt to the extra_parts.
(*-*-darwin*): Add logic to build a shared unwinder library for
Darwin8-10.  Add shim declaration header to powerpc*-darwin builds.
* config/i386/darwin-lib.h (DECLARE_LIBRARY_RENAMES): Remove
workaround.
* config/libgcc-libsystem.ver: Add exclude list for the system-
provided unwinder.
* config/t-slibgcc-darwin: Bump SO version, remove stubs code.
Build a legacy libgcc_s.1 and the supporting pieces (all FAT libs).
* config/t-darwin-ehs: Add dependencies to the shared unwinder
objects.  Add dependency on unwind.h.
* config/t-darwin: Reorganise the EH fragments to place them for
inclusion in a shared EH lib.  Add libgcc_tm.h to the dependencies
for darwin10-unwind-find-enc-func.
* config/i386/libgcc-darwin.10.4.ver: Removed.
* config/i386/libgcc-darwin.10.5.ver: Removed.
* config/rs6000/libgcc-darwin.10.4.ver: Removed.
* config/rs6000/libgcc-darwin.10.5.ver: Removed.
* config/i386/t-darwin: Build legacy libgcc_s.1.
* config/rs6000/t-darwin: Likewise.
* config/rs6000/t-darwin-ehs: Remove dependency on the powerpc end
file.  Add darwin-fallback.o.

gcc/testsuite/ChangeLog:

* gcc.dg/torture/fp-int-convert-timode-3.c: Remove XFAIL.
* gcc.dg/torture/fp-int-convert-timode-4.c: Likewise.

2 years agolibgcc, emutls: Allow building weak definitions of the emutls functions.
Iain Sandoe [Sun, 19 Sep 2021 11:35:46 +0000 (12:35 +0100)]
libgcc, emutls: Allow building weak definitions of the emutls functions.

In order to better support use of the emulated TLS between objects with
DSO dependencies and static-linked libgcc, allow a target to make weak
definitions.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
libgcc/ChangeLog:

* config/t-darwin: Build weak-defined emutls objects.
* emutls.c (__emutls_get_address): Add optional attributes.
(__emutls_register_common): Likewise.
(EMUTLS_ATTR): New.

(cherry picked from commit b9873b4e2c9a9955789318f4d550147ef9405b07)

2 years agoDarwin: Revise handling of some driver opts.
Iain Sandoe [Fri, 14 Jun 2019 18:14:30 +0000 (19:14 +0100)]
Darwin: Revise handling of some driver opts.

[Fixes a regression in driver output with empty comand lines, also a pre-
 requisite for fixes in PR80556]

Darwin has a user convenience feature where some linker options are exposed
at the driver level (so one can type '-all_load' instead of '-Wl,-all_load'
or '-Xlinker -all_load').  We retain this feature, but now these options are
all marked as 'Driver' and we process them as early as possible so that they
get allocated to the right toolchain command.  There are a couple of special
cases where these driver opts are used multiple times, or to control
operations on more than one command (e.g. dynamiclib).  These are handled
specially and we then add %<xxxx specs for the commands that _do not_ need
them.  NOTE: the ordering of 'shared' and 'dynamiclib' is significant, hence
they are placed out of alphabetical order at the start.  Likewise, we keep
a couple of cases where a negative option originally appeared after the
positive alternate, potentially overriding it.

When we report an error with %e, it seems necessary to strip the option
before doing so, otherwise it survives to the cc1 command line (%e does not
appear to abort the program before this).

Right now there is no mechanism to split up the 'variable portion' (%*) of
the matched spec string, so where we have some driver specs that take 2 or
3 arguments, these cannot be processed here, but are deferred until the
LINK_SPEC, where they are copied verbatim.

We have a 'safe' version of the macOS version string, that has been sanity-
checked and truncated to minor version.  If the 'tiny' (3rd) portion of the
value is not significant, it is better to use the safe one in version-compare().

We were not wrapping all the default libraries in checks for whether
they should be used.  We were also wasting a process launch calling
dsymutil for 'r' link lines (a NOP in practice).  Order the checks
that exclude linking from most likely to occur, downwards.

We were pushing a spec value for weak_reference_mismatches unconditionally
which is not needed (the value was the default) and the side-effect of
this was that we appeared to need to drive a link command; leading to
unexpected diagnostics for cases where gcc was invoked with an empty
command line.

Also we were pushing flags for sysroot, os minimum version and controls
even if the command line was empty.

Backported from 353cb291a486af3be93dd9320dde9e38b542a1bd,
4aef14b09557ce072f1269bd8a05fa2b1df0eda2 and
ff56eea24e48f7a8a3b39db7049d1da532d4b8af

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
gcc/ChangeLog:

* config/darwin-driver.c (darwin_driver_init): Revise comments, handle
filelist and framework options in specs instead of code. Exit from the
option handling early if the command line is definitely enpty.
* config/darwin.h (SUBTARGET_DRIVER_SELF_SPECS): Update to handle link
specs that are really driver ones. Remove setting for the default content
of weak_reference_mismatches
(DARWIN_CC1_SPEC): Likewise.
(CPP_SPEC): Likewise.
(SYSROOT_SPEC): Append space.
(LINK_SYSROOT_SPEC): Remove most driver link specs.
(STANDARD_STARTFILE_PREFIX_2): Update link-related specs.
(STARTFILE_SPEC): Likewise.
(ASM_MMACOSX_VERSION_MIN_SPEC): Fix line wrap.
(ASM_SPEC): Update driver-related specs.
(ASM_FINAL_SPEC): Likewise.
(LINK_COMMAND_SPEC_A): Update 'r' handling to skip gomp and itm when r
or nodefaultlibs is given.
(DSYMUTIL_SPEC): Do not call dsymutil for '-r' link lines.
Update ordering of exclusions, remove duplicate 'v' addition
(collect2 will add this from the main command line).
* config/darwin.opt: Remove now unused option aliases.
* config/i386/darwin.h (EXTRA_ASM_OPTS): Ensure space after opt.
(ASM_SPEC): Update driver-related specs.

2 years agolibstdc++, testsuite: Add a prune expression for external tool bug.
Iain Sandoe [Fri, 19 Nov 2021 15:52:29 +0000 (15:52 +0000)]
libstdc++, testsuite: Add a prune expression for external tool bug.

Depending on the permutation of CPU, OS version and shared/non-
shared library inclusion, we get can get warnings from the external
tools (ld64, dsymutil) which are not actually libstdc++ issues but
relate to the external tools themselves.  This is already pruned
in the main testsuite, this adds it to the library.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
libstdc++-v3/ChangeLog:

* testsuite/lib/prune.exp: Prune dsymutil (ld64) warning.

(cherry picked from commit c7b782d847d8682af9d5d91c0614a880cc2436f1)

2 years agoconfigure, Darwin: Set appropriate defaults for host-shared.
Iain Sandoe [Fri, 12 Nov 2021 17:05:13 +0000 (17:05 +0000)]
configure, Darwin: Set appropriate defaults for host-shared.

Darwin x86_64 and aarch64 platforms are PIC (shared) by default,
and user-space code must be built in this mode.  The patch
ensures that this is set correctly and applies a default when
--enable-host-shared is not set.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
ChangeLog:

* configure: Regenerate.
* configure.ac: Ensure that PIC (shared) defaults are set
correctly for Darwin.

(cherry picked from commit a1d2b16202601e597fac1c0e6af6ee8cd09b52c0)

2 years agoIPA: Provide a mechanism to register static DTORs via cxa_atexit.
Iain Sandoe [Thu, 4 Nov 2021 09:37:14 +0000 (09:37 +0000)]
IPA: Provide a mechanism to register static DTORs via cxa_atexit.

For at least one target (Darwin) the platform convention is to
register static destructors (i.e. __attribute__((destructor)))
with __cxa_atexit rather than placing them into a list that is
run by some other mechanism.

This patch provides a target hook that allows a target to opt
into this and handling for the process in ipa_cdtor_merge ().

When the mode is enabled (dtors_from_cxa_atexit is set) we:

 * Generate new CTORs to register static destructors with
   __cxa_atexit and add them to the existing list of CTORs;
   we then process the revised CTORs list.

 * We sort the DTORs into priority and then TU order, this
   means that they are registered in that order with
   __cxa_atexit () and therefore will be run in the reverse
   order.

 * Likewise, CTORs are sorted into priority and then TU order,
   which means that they will run in that order.

This matches the behavior of using init/fini (or
mod_init_func/mod_term_func) sections.

This also fixes a bug where Fortran needs a DTOR to be run to
close IO.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
PR fortran/102992

gcc/ChangeLog:

* config/darwin.h (TARGET_DTORS_FROM_CXA_ATEXIT): New.
* doc/tm.texi: Regenerated.
* doc/tm.texi.in: Add TARGET_DTORS_FROM_CXA_ATEXIT hook.
* ipa.c (cgraph_build_static_cdtor_1): Return the built
function decl.
(build_cxa_atexit_decl): New.
(build_dso_handle_decl): New.
(build_cxa_dtor_registrations): New.
(compare_cdtor_tu_order): New.
(build_cxa_atexit_fns): New.
(ipa_cdtor_merge): If dtors_from_cxa_atexit is set,
process the DTORs/CTORs accordingly.
(pass_ipa_cdtor_merge::gate): Also run if
dtors_from_cxa_atexit is set.
* target.def (dtors_from_cxa_atexit): New hook.

(cherry picked from commit fabe8cc41e9b01913e2016861237d1d99d7567bf)

2 years agoDarwin : Make trampoline templates linker-visible.
Iain Sandoe [Wed, 2 Sep 2020 19:33:00 +0000 (20:33 +0100)]
Darwin : Make trampoline templates linker-visible.

For aarch64, the alignment of the LTRAMPn symbols matters.

Actually, the LTRAMPn  symbols _are_ 8 byte aligned, but because
they are Local, the linker doesn't know that this guarantee can be met.
It assumes that they are not necessarily more aligned than the
containing section (ld64 atoms strike again).

The fix is to publish the trampoline symbol for the linker to access
directly - it can then see that the atom is suitably aligned.

Fixes issue #11 on the development branch.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
gcc/ChangeLog:

* config/darwin.h (ASM_GENERATE_INTERNAL_LABEL): Add LTRAMP
to the list of symbol prefixes that must be made linker-
visible.

(cherry picked from commit f1e2879ecfc8897df0e25a53e81d1868363c5e08)

2 years agoDarwin, crts: Fix a build warning.
Iain Sandoe [Mon, 1 Nov 2021 16:58:20 +0000 (16:58 +0000)]
Darwin, crts: Fix a build warning.

We have a shim crt for Darwin10 that implements functionality
missing in libSystem. Provide this with a prototype to silence the
warning about this.

libgcc/ChangeLog:

* config/darwin10-unwind-find-enc-func.c: Include libgcc_tm.h.
* config/i386/darwin-lib.h: Declare Darwin10 crt function.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
(cherry picked from commit 7a300b413a62e1989bd89064fd5594aabe371d3a)

2 years agoDarwin, config: Amend for Darwin 21 / macOS 12.
Saagar Jha [Tue, 15 Jun 2021 11:08:23 +0000 (04:08 -0700)]
Darwin, config: Amend for Darwin 21 / macOS 12.

It seems that the OS major version is now tracking the kernel
major version - 9.  Minor version has been set to kernel
minor - 1.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
Signed-off-by: Saagar Jha <saagar@saagarjha.com>
gcc/ChangeLog:

* config.gcc: Adjust for Darwin21.
* config/darwin-c.c (macosx_version_as_macro): Likewise.
* config/darwin-driver.c (validate_macosx_version_min):
Likewise.
(darwin_find_version_from_kernel): Likewise.

2 years agocollect2: Fix missing cleanups.
Iain Sandoe [Wed, 6 Oct 2021 13:58:33 +0000 (14:58 +0100)]
collect2: Fix missing cleanups.

The code that checks to see if objects have LTO content via
simple-object was not releasing resources, fixed thus.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
gcc/ChangeLog:

* collect2.c (is_lto_object_file): Release simple-object
resources, close files.

(cherry picked from commit 43ae43f654749d291d871ca6ef7c96ea16580fad)

2 years agoDarwin, PPC : Fix R13 for PPC64.
Iain Sandoe [Fri, 11 Dec 2020 00:29:42 +0000 (00:29 +0000)]
Darwin, PPC : Fix R13 for PPC64.

We have a somewhat unusual situation in that for PPC64, R13 is
both reserved and callee-saved (it is used internally by the
pthreads implementation to contain pthread_self).

So add R13 to the fixed regs, but also keep it in the callee-
saved set.

gcc/ChangeLog:

* config/rs6000/darwin.h (FIXED_R13): Add for PPC64.
(FIRST_SAVED_GP_REGNO): Save from R13 even when it is one
of the fixed regs.

(cherry picked from commit b12d6e79899fd27833c53ffc3c973538244f62e1)

2 years agoDarwin, crts: Build Darwin10 unwinder shim as a library.
Iain Sandoe [Sat, 18 Sep 2021 16:08:42 +0000 (17:08 +0100)]
Darwin, crts: Build Darwin10 unwinder shim as a library.

We have a small unwinder shim that is only used for Darwin10
(and only then in quite specific cases).  To avoid linking
this code for every executable or DSO, we can present the crt
as a convenience library (rather than a .o file).

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
gcc/ChangeLog:

* config/darwin.h (LINK_COMMAND_SPEC_A): Use Darwin10
unwinder shim as a convenience library.

libgcc/ChangeLog:

* config.host: Use convenience library for Darwin10
unwinder shim.
* config/t-darwin: Build Darwin10 unwinder shim as a
convenience library.

(cherry picked from commit 873854387865d18484bd0d39324773cd1e76df85)

2 years agoJit, testsuite: Amend expect processing to tolerate more platforms.
Iain Sandoe [Thu, 19 Aug 2021 12:01:14 +0000 (13:01 +0100)]
Jit, testsuite: Amend expect processing to tolerate more platforms.

The current 'fixed_host_execute' implementation fails on Darwin
platforms for a number of reasons:

1/ If the sub-process spawn fails (e.g. because of missing or mal-
   formed params); rather than reporting the fail output into the
   match stream, as indicated by the expect manual, it terminates
   the script.

 - We fix this by (a) checking that the executable is valid as well
   as existing (b) we put the spawn into a catch block and report
   a failure.

2/ There is no recovery path at all for a buffer-full case (and we
   do see buffer-full events with the default sizes).

 - Added by the patch here, however it is not as sophisticated as
   the methods used by dejagnu internally.  Here we set the process
   to be "nowait" and then close the connection - with the intent
   that this will terminate the spawned process.

3/  The expect logic assumes that 'Totals:' is a valid indicator
    for the end of the spawned process output.  This is not true
    even for the default dejagnu header (there are a number of
    additional reporting lines after).  In addition to this, there
    are some tests that intentionally produce more output after
    the totals report (and there are tests that do not use that
    mechanism at all).

    The effect is the we might arrive at the "wait" for the spawned
    process to finish - but that process might not have completed
    all its output.  For Darwin, at least that causes a deadlock
    between expect and the spawnee - the latter is doing a non-
    cancellable write and the former is waiting for the latter to
    terminate.  For some reason this does not seem to affect Linux
    perhaps the pty implementation allows the write(s) are able to
    proceed even though there is no reader.

 -  This is fixed by modifying the loop termination condition to be
    either EOF (which will be the 'correct' condition) or a timeout
    which would represent an error either in the runtime or in the
    parsing of the output.  As added precautions, we only try to
    wait if there is a correcly-spawned process, and we are also
    specific about which process we are waiting for.

4/  Darwin appears to have a bug in either the tcl or termios
    'cooking' code that ocassionally inserts an additional CR char
    into the stream - thus '\n' => '\r\r\n' instead of '\r\n'. The
    original program output is correct (it only contains a single
    \n) - the additional character is being inserted somewhere in
    the translations applied before the output reaches expect.

    The logic of this expect implementation does not tolerate single
    \r or \n characters (it will fail with a timeout or buffer-full
    if that occurs).

 -  This is fixed by having a line-end match that is adjusted for
    Darwin.

5/  The default buffer size does seem to be too small in some cases
    noting that GCC uses 10000 as the match buffer size and the
    default is 2000.

 -  Fixed by increasing the size to 8192.

6/  There is a somewhat arbitrary dumping of output where we match
    ^$prefix\tSOMETHING... and then process the something.  This
    essentially allows the match to start at any place in the buffer
    following any collection of non-line-end chars.

 -  Fixed by amending the match for 'general' lines to accommodate
    these cases, and reporting such lines to the log.  At least this
    should allow debugging of any cases where output that should be
    recognized is being dropped.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
gcc/testsuite/ChangeLog:

* jit.dg/jit.exp (fixed_local_execute): Amend the match and
exit conditions to cater for more platforms.

(cherry picked from commit 124c354ad70f09c31610f67743b277a359527649)

2 years agoconfigure: Avoid unnecessary constraints on executables for $build.
Iain Sandoe [Thu, 26 Aug 2021 11:52:29 +0000 (12:52 +0100)]
configure: Avoid unnecessary constraints on executables for $build.

The executables for GCC's c-family compilers must be built with no-PIE
because they use PCH and the current model for this requires that the
exe is always lauched at the same address.  Since the other language
compilers share code with the c-family this constraint is also applied
to them.

However, the executables that run on $build (generators, and parsers
for md and def files) need not have any such constraint they do not
consume PCH files.

This change simplifies the configuration and Makefile content by
removing the code enforcing no-PIE on these exes.  This also fixes a
bootstrap issue with some Darwin versions and clang as the bootstrap
compiler,  where -no-PIE causes the correct relocation model to be
switched off leading to invalid user-space code.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
gcc/ChangeLog:

* Makefile.in: Remove variables related to applying no-PIE
to the exes on $build.
* configure: Regenerate.
* configure.ac: Remove configuration related to applying
no-PIE to the exes on $build.

(cherry picked from commit fb32372651882adee2d41052f1e59012e8bb32a7)

2 years agolibgcc, X86: Adjust guard for Mach-O code.
Iain Sandoe [Wed, 22 Sep 2021 06:42:21 +0000 (07:42 +0100)]
libgcc, X86: Adjust guard for Mach-O code.

Existing code in the sfp-machine header has been using __MACH__
as a guard for Mach-O, where currently symbols aliases are not
supported.

__MACH__ is not a sufficient guard for this, since the define
is also emitted for HURD, at least.

Fixed by amending the guard to use __APPLE__ instead.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
libgcc/ChangeLog:

* config/i386/sfp-machine.h: Guard Mach-O-specific code
using __APPLE__.

(cherry picked from commit 578b76873383784841f5478573f4ac5d251aa0ba)

2 years agolibgcc, soft-float: Fix strong_alias macro use for Darwin.
Iain Sandoe [Fri, 3 Sep 2021 07:41:06 +0000 (08:41 +0100)]
libgcc, soft-float: Fix strong_alias macro use for Darwin.

Darwin does not support strong symbol aliases and a work-
around is provided in sfp-machine.h where a second function
is created that simply calls the original.  However this
needs the arguments to the synthesized function to track
the mode of the original function.

So the fix here is to match known floating point modes from
the incoming function and apply the one found to the new
function args.

The matching is highly specific to the current set of modes
and will need adjusting should more cases be added.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
libgcc/ChangeLog:

* config/i386/sfp-machine.h (alias_SFtype
alias_DFtype, alias_TFtype): New.
(ALIAS_SELECTOR): New.
(strong_alias): Use __typeof and a _Generic selector to
provide the type to the synthesized function.

(cherry picked from commit 3ccb523bdd78e6ba3c133064be90cdf19dcbf896)

2 years agolibiberty, configure, Darwin: Avoid detecting deprecated sbrk.
Iain Sandoe [Mon, 23 Aug 2021 16:27:25 +0000 (17:27 +0100)]
libiberty, configure, Darwin: Avoid detecting deprecated sbrk.

Darwin provides an implementation of sbrk, which is detected by
the configuration process.  However, it is deprecated which leads
to build warnings.  The malloc-based implementation is more
suitable.  This patch removes sbrk from the functions searched
for Darwin.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
libiberty/ChangeLog:

* configure: Regenerate.
* configure.ac: Do not search for sbrk on Darwin.
* xmalloc.c: Do not declare sbrk unless it has been found
by configure.

(cherry picked from commit fbb334a6acc5cc5d8944712daeda8089ef1d7fd2)

2 years agotestsuite, Darwin : Skip a test requiring strndup in libc.
Iain Sandoe [Mon, 15 Mar 2021 21:40:40 +0000 (21:40 +0000)]
testsuite, Darwin : Skip a test requiring strndup in libc.

Before Darwin11 there is no strndup in libc. This test fails with
warning output because of that - so skip it on these versions (since
they are not able to use strndup anyway).

gcc/testsuite/ChangeLog:

* gcc.dg/analyzer/strndup-1.c: Skip for Darwin versions
without strndup support in libc.

(cherry picked from commit dc033e0149fd7790b89f816041e87a6ddc22e21c)

2 years agoDarwin : Mark the mod init/term section starts with a linker-visible sym.
Iain Sandoe [Sat, 29 Aug 2020 21:05:30 +0000 (22:05 +0100)]
Darwin : Mark the mod init/term section starts with a linker-visible sym.

Some newer assemblers emit section start temp symbols for mod init and term
sections if there is no suitable symbol present already.
The temp symbols are linker visible and therefore appear in the symbol tables.
Since the temp symbol number can vary when debug is enabled, that causes
compare-debug fails.  The solution is to provide a stable linker-visible
symbol.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
gcc/ChangeLog:

* config/darwin.c (finalize_ctors): Add a section-start linker-
visible symbol.
(finalize_dtors): Likewise.
* config/darwin.h (MIN_LD64_INIT_TERM_START_LABELS): New.

(cherry picked from commit 66526c6a1c01b6110eaeda94ecc885177c636605)

2 years agotestsuite, JIT, Darwin: Adjust asm tests for Mach-O.
Iain Sandoe [Fri, 13 Aug 2021 19:25:59 +0000 (20:25 +0100)]
testsuite, JIT, Darwin: Adjust asm tests for Mach-O.

This provides adjusted assembler fragments that are suitable
for x86_64 Mach-O.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
gcc/testsuite/ChangeLog:

* jit.dg/test-asm.c: Provide Mach-O fragment.
* jit.dg/test-asm.cc: Likewise.

(cherry picked from commit cb23be4fa59be26a7ba08918d6973e1d94629f8a)

2 years agoJIT, testsuite, Darwin: Initial testsuite fixes.
Iain Sandoe [Thu, 5 Aug 2021 09:07:03 +0000 (10:07 +0100)]
JIT, testsuite, Darwin: Initial testsuite fixes.

The testsuite setup for jit is not compatible with Darwin since it
assumes that all targets support --export-dynamic.

 - this is fixed by adding '-rdynamic' conditionally upon target
   support for that (-rdynamic will be converted to the appropriate
   linker option).

There is also an assumption that a suitable version of dejagnu.h
is present in some default include search path that is usable from
the testsuite.  This is not the case for Darwin (dejagnu.h is not
installed, and would not, in general, be found in any default include
search path if installed via one of the main 'distros').  Also the
upstream dejagnu.h has a definition of 'wait()' that clashes with a
libc routines and therefore causes fails in the testsuite.

 - This patch imports the header from dejagnu-1.6.2 and
   * renames it to 'jit-dejagnu.h'
   * patches it to avoid unused variable warnings and the clash
     with the libc definition of wait ()
   * In accordance with the advice in the expect man page, ensures
     that the final output of the 'totals' print is stable.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
gcc/jit/ChangeLog:

* docs/examples/tut04-toyvm/toyvm.c: Include jit-dejagnu.h.
* docs/examples/tut04-toyvm/toyvm.cc: Likewise.
* jit-dejagnu.h: New file, imported from dejagnu-1.6.2 and
patched for this application.

gcc/testsuite/ChangeLog:

* jit.dg/harness.h: Include jit-dejagnu.h.
* jit.dg/jit.exp: Use -rdynamic conditionally on target
support, instead of unconditional -Wl,--export-dynamic.

(cherry picked from commit eea1677fd03a1cb820cbb72044d4a0770f8a7a93)

2 years agoDarwin, jit: Fix build [PR100613].
Iain Sandoe [Thu, 5 Aug 2021 08:55:19 +0000 (09:55 +0100)]
Darwin, jit: Fix build [PR100613].

The generic unix build is not completely suitable for Darwin
platforms:

 * It is a convention to encode the library versioning in the
   binary and to have only one level of symlink for the installed
   files. This needs to be applied to the installation too.
 * The library needs to be built with its correct install name
   so that two-level library naming works.
 * The extension for shared libraries should be .dylib

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
PR jit/100613 - libgccjit should produce dylib on macOS

PR jit/100613

gcc/jit/ChangeLog:

* Make-lang.in: Provide clauses for Darwin hosts.

(cherry picked from commit 08defd9c4e4f8dc428f2f490705ab816af81a03d)

2 years agoconfigure: Allow host fragments to react to --enable-host-shared.
Iain Sandoe [Sat, 7 Aug 2021 13:40:33 +0000 (14:40 +0100)]
configure: Allow host fragments to react to --enable-host-shared.

This makes the host_shared value available to host makefile
fragments.

It uses this to adjust Darwin's mdynamic-no-pic in the case that
shared host resources are required.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
ChangeLog:

* Makefile.in: Regenerate.
* Makefile.tpl: Make the state of the configured host
shared flag available to makefile fragements.

config/ChangeLog:

* mh-darwin: Require a non-shared host configuration to
enable  mdynamic-no-pic where that is supported.

(cherry picked from commit d39367fa82d95b646f0587a442156069100ee245)

2 years agolibiberty, Darwin : Fix simple-object LTO table for cross-endian case.
Iain Sandoe [Fri, 9 Apr 2021 12:40:11 +0000 (13:40 +0100)]
libiberty, Darwin : Fix simple-object LTO table for cross-endian case.

We encapsulate streamed IR in three special sections with a table
that describes their entries.  The table is expected to be written
with native endianness for the target, but for cross-endian cross-
compilation the swapping was omitted.  Fixed thus.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
libiberty/ChangeLog:

* simple-object-mach-o.c (simple_object_mach_o_write_segment):
Arrange to swap the LTO index tables where needed.

(cherry picked from commit 220c410162ebece4fffa2912ed79e348d3731d77)

2 years agoDarwin: Reset section names table at the end of compile.
Iain Sandoe [Fri, 13 Aug 2021 19:20:04 +0000 (20:20 +0100)]
Darwin: Reset section names table at the end of compile.

For a single use (typical compile) this vector will be reclaimed
as GGC.  For JIT this is not sufficient since it does not reset
the pointer to NULL (and thus we think the the vector is already
allocated when a context is reused).

The clears the vector and sets the pointer to NULL at the end
of object output.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
gcc/ChangeLog:

* config/darwin.c (darwin_file_end): Reset and reclaim the
section names table at the end of compile.

(cherry picked from commit 2d9da1c89778be1d6604cc1465b0dd50f241a352)

2 years agoDarwin, libcc1: Handle hosts with mdynamic-no-pic support.
Iain Sandoe [Sun, 4 Jul 2021 16:56:05 +0000 (17:56 +0100)]
Darwin, libcc1: Handle hosts with mdynamic-no-pic support.

The default for building host-side binaries for mdynamic-no-pic
hosts is to enable this.  However, it is not compatible with
dynamic libraries, so must be switched off for libcc1.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
libcc1/ChangeLog:

* Makefile.am: Switch mdynamic-no-pic to fPIC.
* Makefile.in: Regenerated.

2 years agoDarwin, configury : Allow for specification and detection of dsymutil.
Iain Sandoe [Sun, 13 Dec 2020 17:21:16 +0000 (17:21 +0000)]
Darwin, configury : Allow for specification and detection of dsymutil.

In order to enable DWARF versions > 2 we need a sufficiently modern
version of dsymutil (in addition to the assembler / linker).  This
allows the user to configure a different path from the installed one.

In addition, there are several sources of dsymutil so we differentiate
these in order to be get accurate version information.

Backported from commits 3b5e8ee4f1ecc6d407f391695f65960bcbd63cff and
b019b28ebd65462a092c96d95e9e356c8bb39b78

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
gcc/ChangeLog:

* configure.ac: Handle --with-dsymutil in the same way as we
do for the assembler and linker.  (DEFAULT_DSYMUTIL): New.
Extract the type and version for the dsymutil configured or
found by the default searches.
* config.in: Regenerated.
* configure: Regenerated.
* collect2.c (do_dsymutil): Handle locating dsymutil in the
same way as for the assembler and  linker.
* config/darwin.h (DSYMUTIL): Delete.
* gcc.c: Report a configured dsymutil correctly.
* exec-tool.in: Allow for dsymutil.
* doc/install.texi: Document --with-dsymutil.

ChangeLog:

* Makefile.def: Add dsymutil defs.
* Makefile.in: Regenerated.
* Makefile.tpl: Add dsymutil to flags.
* configure: Regenerated.
* configure.ac: Add dsymutil to target and build recipes.

2 years agoDarwin, config: Revise host config fragment.
Iain Sandoe [Sat, 3 Jul 2021 14:42:16 +0000 (15:42 +0100)]
Darwin, config: Revise host config fragment.

There were two uses for the Darwin host config fragment:

The first is to arrange for targets that support mdynamic-no-pic
to be built with that enabled (since it makes a significant
difference to the compiler performance).  We can be more specific
in the application of this, since it only applies to 32b hosts
plus powerpc64-darwin9.

The second was to work around a tool bug where -fno-PIE was not
propagated to the link stage.  This second use is redundant,
since the buggy toolchain cannot bootstrap current GCC sources
anyway.

This makes the host fragment more specific and reduces the number
of toolchains for which it is included which reduces clutter in
configure lines.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
config/ChangeLog:

* mh-darwin: Make this specific to handling the
mdynamic-no-pic case.

ChangeLog:

* configure: Regenerate.
* configure.ac: Adjust cases for which it is necessary to
include the Darwin host config fragment.

(cherry picked from commit 54258e22b0846aaa6bd3265f592feb161eecda75)

2 years agoDaily bump.
GCC Administrator [Thu, 14 Apr 2022 00:19:04 +0000 (00:19 +0000)]
Daily bump.

2 years agoi386: Fix ICE caused by ix86_emit_i387_log1p [PR105214]
Jakub Jelinek [Tue, 12 Apr 2022 07:19:11 +0000 (09:19 +0200)]
i386: Fix ICE caused by ix86_emit_i387_log1p [PR105214]

The following testcase ICEs, because ix86_emit_i387_log1p attempts to
emit something like
  if (cond)
    some_code1;
  else
    some_code2;
and emits a conditional jump using emit_jump_insn (standard way in
the file) and an unconditional jump using emit_jump.
The problem with that is that if there is pending stack adjustment,
it isn't emitted before the conditional jump, but is before the
unconditional jump and therefore stack is adjusted only conditionally
(at the end of some_code1 above), which makes dwarf2 pass unhappy about it
but is a serious wrong-code even if it doesn't ICE.

This can be fixed either by emitting pending stack adjust before the
conditional jump as the following patch does, or by not using
  emit_jump (label2);
and instead hand inlining what that function does except for the
pending stack adjustment, like:
  emit_jump_insn (targetm.gen_jump (label2));
  emit_barrier ();
In that case there will be no stack adjustment in the sequence and
it will be done later on somewhere else.

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

PR target/105214
* config/i386/i386-expand.c (ix86_emit_i387_log1p): Call
do_pending_stack_adjust.

* gcc.dg/asan/pr105214.c: New test.

(cherry picked from commit d481d13786cb84f6294833538133dbd6f39d2e55)

2 years agobuiltins: Fix up expand_builtin_int_roundingfn_2 [PR105211]
Jakub Jelinek [Tue, 12 Apr 2022 07:16:06 +0000 (09:16 +0200)]
builtins: Fix up expand_builtin_int_roundingfn_2 [PR105211]

The expansion of __builtin_iround{,f,l} etc. builtins in some cases
emits calls to a different fallback builtin.  To locate the right builtin
it uses mathfn_built_in_1 with the type of the first argument.
If its TYPE_MAIN_VARIANT is {float,double,long_double}_type_node, all is
fine, but on the following testcase, because GIMPLE considers scalar
float conversions between types with the same mode as useless,
TYPE_MAIN_VARIANT of the arg's type is float32_type_node and because there
isn't __builtin_lroundf32 returns NULL and we ICE.

This patch will first try the type of the first argument of the builtin's
prototype (so that say on sizeof(double)==sizeof(long double) target it honors
whether it was a *l or non-*l call; though even that can't be 100% trusted,
user could incorrectly prototype it) and as fallback the type argument.
If neither works, doesn't fallback.

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

PR rtl-optimization/105211
* builtins.c (expand_builtin_int_roundingfn_2): If mathfn_built_in_1
fails for TREE_TYPE (arg), retry it with
TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fndecl))) and if even that
fails, emit call normally.

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

(cherry picked from commit 91a38e8a848c61b2e23ee277306dc8cd194d135b)

2 years agoc-family: Initialize ridpointers for __int128 etc. [PR105186]
Jakub Jelinek [Mon, 11 Apr 2022 08:41:07 +0000 (10:41 +0200)]
c-family: Initialize ridpointers for __int128 etc. [PR105186]

The following testcase ICEs with C++ and is incorrectly rejected with C.
The reason is that both FEs use ridpointers identifiers for CPP_KEYWORD
and value or u.value for CPP_NAME e.g. when parsing attributes or OpenMP
directives etc., like:
         /* Save away the identifier that indicates which attribute
            this is.  */
         identifier = (token->type == CPP_KEYWORD)
           /* For keywords, use the canonical spelling, not the
              parsed identifier.  */
           ? ridpointers[(int) token->keyword]
           : id_token->u.value;

         identifier = canonicalize_attr_name (identifier);
I've tried to change those to use ridpointers only if non-NULL and otherwise
use the value/u.value even for CPP_KEYWORDS, but that was a large 10 hunks
patch.

The following patch instead just initializes ridpointers for the __intNN
keywords.  It can't be done earlier before we record_builtin_type as there
are 2 different spellings and if we initialize those ridpointers early, the
second record_builtin_type fails miserably.

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

PR c++/105186
* c-common.c (c_common_nodes_and_builtins): After registering __int%d
and __int%d__ builtin types, initialize corresponding ridpointers
entry.

* c-c++-common/pr105186.c: New test.

(cherry picked from commit 083e8e66d2e90992fa83a53bfc3553dfa91abda1)

2 years agofold-const: Fix up make_range_step [PR105189]
Jakub Jelinek [Fri, 8 Apr 2022 07:14:44 +0000 (09:14 +0200)]
fold-const: Fix up make_range_step [PR105189]

The following testcase is miscompiled, because fold_truth_andor
incorrectly folds
(unsigned) foo () >= 0U && 1
into
foo () >= 0
For the unsigned comparison (which is useless in this case,
as >= 0U is always true, but hasn't been folded yet), previous
make_range_step derives exp (unsigned) foo () and +[0U, -]
range for it.  Next we process the NOP_EXPR.  We have special code
for unsigned to signed casts, already earlier punt if low or high
aren't representable in arg0_type or if it is a narrowing conversion.
For the signed to unsigned casts, I think if high is specified we
are still fine, as we punt for non-representable values in arg0_type,
n_high is then still representable and so was smaller or equal to
signed maximum and either low is not present (equivalent to 0U), or
low must be smaller or equal to high and so for unsigned exp
+[low, high] the signed exp +[n_low, n_high] will be correct.
Similarly, if both low and high aren't specified (always true or
always false), it is ok too.
But if we have for unsigned exp +[low, -] or -[low, -], using
+[n_low, -] or -[n_high, -] is incorrect.  Because low is smaller
or equal to signed maximum and high is unspecified (i.e. unsigned
maximum), when signed that range is a union of +[n_low, -] and
+[-, -1] which is equivalent to -[0, n_low-1], unless low
is 0, in that case we can treat it as [-, -].

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

PR tree-optimization/105189
* fold-const.c (make_range_step): Fix up handling of
(unsigned) x +[low, -] ranges for signed x if low fits into
typeof (x).

* g++.dg/torture/pr105189.C: New test.

(cherry picked from commit 5e6597064b0c7eb93b8f720afc4aa970eefb0628)

2 years agocombine: Don't record for UNDO_MODE pointers into regno_reg_rtx array [PR104985]
Jakub Jelinek [Wed, 6 Apr 2022 16:42:52 +0000 (18:42 +0200)]
combine: Don't record for UNDO_MODE pointers into regno_reg_rtx array [PR104985]

The testcase in the PR fails under valgrind on mips64 (but only Martin
can reproduce, I couldn't).
But the problem reported there is that SUBST_MODE remembers addresses
into the regno_reg_rtx array, then some splitter needs a new pseudo
and calls gen_reg_rtx, which reallocates the regno_reg_rtx array
and finally undo operation is done and dereferences the old regno_reg_rtx
entry.
The rtx values stored in regno_reg_rtx array seems to be created
by gen_reg_rtx only and since then aren't modified, all we do for it
is adjusting its fields (e.g. adjust_reg_mode that SUBST_MODE does).

So, I think it is useless to use where.r for UNDO_MODE and store
&regno_reg_rtx[regno] in struct undo, we can store just
regno_reg_rtx[regno] (i.e. pointer to the REG itself instead of
pointer to pointer to REG) or could also store just the regno.

The following patch does the latter, and because SUBST_MODE no longer
needs to be a macro, changes all SUBST_MODE uses to subst_mode.

2022-04-06  Jakub Jelinek  <jakub@redhat.com>

PR rtl-optimization/104985
* combine.c (struct undo): Add where.regno member.
(do_SUBST_MODE): Rename to ...
(subst_mode): ... this.  Change first argument from rtx * into int,
operate on regno_reg_rtx[regno] and save regno into where.regno.
(SUBST_MODE): Remove.
(try_combine): Use subst_mode instead of SUBST_MODE, change first
argument from regno_reg_rtx[whatever] to whatever.  For UNDO_MODE, use
regno_reg_rtx[undo->where.regno] instead of *undo->where.r.
(undo_to_marker): For UNDO_MODE, use regno_reg_rtx[undo->where.regno]
instead of *undo->where.r.
(simplify_set): Use subst_mode instead of SUBST_MODE, change first
argument from regno_reg_rtx[whatever] to whatever.

(cherry picked from commit 61bee6aed26eb30b798c75b9a595c9d51e080442)

2 years agoDaily bump.
GCC Administrator [Wed, 13 Apr 2022 00:18:25 +0000 (00:18 +0000)]
Daily bump.

This page took 0.108266 seconds and 5 git commands to generate.