Commit Graph

189754 Commits

Author SHA1 Message Date
Jonathan Wakely
5ea8803e65 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.
2021-11-17 17:28:52 +00:00
Jonathan Wakely
5a9572e486 libstdc++: Simplify std::string constructors
Several std::basic_string constructors dispatch to one of the
two-argument overloads of _M_construct, which then dispatches again to
_M_construct_aux to detect whether the arguments are iterators or not.
That then dispatches to one of _M_construct(size_type, char_type) or
_M_construct(Iter, Iter, iterator_traits<Iter>::iterator_category{}).

For most of those constructors this is a waste of time, because we know
the arguments are already iterators. For basic_string(const CharT*) and
basic_string(initializer_list<C>) we know that we call _M_construct with
two pointers, and for basic_string(const basic_string&) we call it with
two const_iterators.  Those constructors can call the three-argument
overload of _M_construct with the iterator category tag right away,
without the intermediate dispatching.

The case where this doesn't apply is basic_string(InputIter, InputIter),
but for C++11 and later this is constrained so we know it's an iterator
here as well. We can restrict the dispatching in this constructor to
only be done for C++98 and to call _M_construct_aux directly, which
allows us to remove the two-argument _M_construct(InputIter, InputIter)
overload entirely.

N.B. When calling the three-arg _M_construct with pointers or string
iterators, we pass forward_iterator_tag not random_access_iterator_tag.
This is because it makes no difference which overload gets called, and
simplifies overload resolution to not have to do a base-to-derived
check. If we ever add a new overload of M_construct for random access
iterators we would have to revisit this, but that seems unlikely.

This patch also moves the __is_null_pointer checks from the three-arg
_M_construct into the constructors where a null pointer argument is
actually possible. This avoids redundant checks where we know we have a
non-null pointer, or don't have a pointer at all.

Finally, this patch replaces some try-blocks with an RAII type, so that
memory is deallocated during unwinding. This avoids the overhead of
catching and rethrowing an exception.

libstdc++-v3/ChangeLog:

	* include/bits/basic_string.h (_M_construct_aux): Only define
	for C++98. Remove constexpr.
	(_M_construct_aux_2): Likewise.
	(_M_construct(InputIter, InputIter)): Remove.
	(basic_string(const basic_string&)): Call _M_construct with
	iterator category argument.
	(basic_string(const basic_string&, size_type, const Alloc&)):
	Likewise.
	(basic_string(const basic_string&, size_type, size_type)):
	Likewise.
	(basic_string(const charT*, size_type, const Alloc&)): Likewise.
	Check for null pointer.
	(basic_string(const charT*, const Alloc&)): Likewise.
	(basic_string(initializer_list<charT>, const Alloc&)): Call
	_M_construct with iterator category argument.
	(basic_string(const basic_string&, const Alloc&)): Likewise.
	(basic_string(basic_string&&, const Alloc&)): Likewise.
	(basic_string(_InputIter, _InputIter, const Alloc&)): Likewise
	for C++11 and later, call _M_construct_aux for C++98.
	* include/bits/basic_string.tcc
	(_M_construct(I, I, input_iterator_tag)): Replace try-block with
	RAII type.
	(_M_construct(I, I, forward_iterator_tag)): Likewise. Remove
	__is_null_pointer check.
2021-11-17 17:28:44 +00:00
Jonathan Wakely
6afa1083c6 libstdc++: Set active member of union in std::string [PR103295]
Clang diagnoses that the new constexpr std::string constructors are not
usable in constant expressions, because they start to write to members
of the union without setting an active member.

This adds a new helper function which returns the address of the local
buffer after making it the active member.

This doesn't fix all problems with Clang, because it still refuses to
write to memory returned by the allocator.

libstdc++-v3/ChangeLog:

	PR libstdc++/103295
	* include/bits/basic_string.h (_M_use_local_data()): New
	member function to make local buffer the active member.
	(assign(const basic_string&)): Use it.
	* include/bits/basic_string.tcc (_M_construct, reserve()):
	Likewise.
2021-11-17 17:21:25 +00:00
Jonathan Wakely
054bf99841 libstdc++: Fix std::type_info::before for ARM [PR103240]
The r179236 fix for std::type_info::operator== should also have been
applied to std::type_info::before. Otherwise two distinct types can
compare equivalent due to using a string comparison, when they should do
a pointer comparison.

libstdc++-v3/ChangeLog:

	PR libstdc++/103240
	* libsupc++/tinfo2.cc (type_info::before): Use unadjusted name
	to check for the '*' prefix.
	* testsuite/util/testsuite_shared.cc: Add type_info object for
	use in new test.
	* testsuite/18_support/type_info/103240.cc: New test.
2021-11-17 17:21:24 +00:00
Jeff Law
c705464823 Fix two mips target tests compromised by recent IPA work
gcc/testsuite
	* gcc.target/mips/frame-header-1.c (bar): Add noipa attribute.
	* gcc.target/mips/frame-header-2.c (bar): Likewise.
2021-11-17 11:55:50 -05:00
Jakub Jelinek
049f0efeaa libcpp: Fix up handling of block comments in -fdirectives-only mode [PR103130]
Normal preprocessing, -fdirectives-only preprocessing before the Nathan's
rewrite, and all other compilers I've tried on godbolt treat even \*/
as end of a block comment, but the new -fdirectives-only handling doesn't.

2021-11-17  Jakub Jelinek  <jakub@redhat.com>

	PR preprocessor/103130
	* lex.c (cpp_directive_only_process): Treat even \*/ as end of block
	comment.

	* c-c++-common/cpp/dir-only-9.c: New test.
2021-11-17 17:31:40 +01:00
Przemyslaw Wirkus
dd159a4167 aarch64: Add new vector mode V8DI
This patch is adding new V8DI mode which will be used with new Armv8.7-A
LS64 extension intrinsics.

gcc/ChangeLog:

	* config/aarch64/aarch64-modes.def (VECTOR_MODE): New V8DI mode.
	* config/aarch64/aarch64.c (aarch64_hard_regno_mode_ok): Handle
	V8DImode.
	* config/aarch64/iterators.md (define_mode_attr nunits): Add entry
	for V8DI.
2021-11-17 13:59:42 +00:00
Martin Uecker
4e6bf0b9dd Fix ICE when mixing VLAs and statement expressions [PR91038]
When returning VM-types from statement expressions, this can
lead to an ICE when declarations from the statement expression
are referred to later. Most of these issues can be addressed by
gimplifying the base expression earlier in gimplify_compound_lval.
Another issue is fixed by wrapping the pointer expression in
pointer_int_sum. This fixes PR91038 and some of the test cases
from PR29970 (structs with VLA members need further work).

gcc/
	PR c/91038
	PR c/29970
	* gimplify.c (gimplify_var_or_parm_decl): Update comment.
	(gimplify_compound_lval): Gimplify base expression first.
	(gimplify_target_expr): Add comment.

gcc/c-family/
	PR c/91038
	PR c/29970
	* c-common.c (pointer_int_sum): Make sure pointer expressions
	are evaluated first when the size expression depends on for
	variably-modified types.

gcc/testsuite/
	PR c/91038
	PR c/29970
	* gcc.dg/vla-stexp-3.c: New test.
	* gcc.dg/vla-stexp-4.c: New test.
	* gcc.dg/vla-stexp-5.c: New test.
	* gcc.dg/vla-stexp-6.c: New test.
	* gcc.dg/vla-stexp-7.c: New test.
	* gcc.dg/vla-stexp-8.c: New test.
	* gcc.dg/vla-stexp-9.c: New test.
2021-11-17 14:29:50 +01:00
Jakub Jelinek
077425c890 lim: Reset flow sensitive info even for pointers [PR103192]
Since 2014 is lim clearing SSA_NAME_RANGE_INFO for integral SSA_NAMEs
if moving them from conditional contexts inside of a loop into unconditional
before the loop, but as the miscompilation of gimplify.c shows, we need to
treat pointers the same, even for them we need to reset whether the pointer
can/can't be null or the recorded pointer alignment.

This fixes
-FAIL: libgomp.c/../libgomp.c-c++-common/target-in-reduction-2.c (internal compiler error)
-FAIL: libgomp.c/../libgomp.c-c++-common/target-in-reduction-2.c (test for excess errors)
-UNRESOLVED: libgomp.c/../libgomp.c-c++-common/target-in-reduction-2.c compilation failed to produce executable
-FAIL: libgomp.c++/../libgomp.c-c++-common/target-in-reduction-2.c (internal compiler error)
-FAIL: libgomp.c++/../libgomp.c-c++-common/target-in-reduction-2.c (test for excess errors)
-UNRESOLVED: libgomp.c++/../libgomp.c-c++-common/target-in-reduction-2.c compilation failed to produce executable
-FAIL: libgomp.c++/target-in-reduction-2.C (internal compiler error)
-FAIL: libgomp.c++/target-in-reduction-2.C (test for excess errors)
-UNRESOLVED: libgomp.c++/target-in-reduction-2.C compilation failed to produce executable
on both x86_64 and i686.

2021-11-17  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/103192
	* tree-ssa-loop-im.c (move_computations_worker): Use
	reset_flow_sensitive_info instead of manually clearing
	SSA_NAME_RANGE_INFO and do it for all SSA_NAMEs, not just ones
	with integral types.
2021-11-17 14:18:42 +01:00
Jakub Jelinek
c39cb6bf83 ranger: Fix up fold_using_range::range_of_address [PR103255]
If on &base->member the offset isn't constant or isn't zero and
-fdelete-null-pointer-checks and not -fwrapv-pointer and base has a range
that doesn't include NULL, we return the range of the base.
Usually it isn't a big deal, because for most pointers we just use
varying, range_zero and range_nonzero ranges and nothing beyond that,
but if a pointer is initialized from a constant, we actually track the
exact range and in that case this causes miscompilation.
As discussed on IRC, I think doing something like:
              offset_int off2;
              if (off_cst && off.is_constant (&off2))
                {
                  tree cst = wide_int_to_tree (sizetype, off2 / BITS_PER_UNIT);
                  // adjust range r with POINTER_PLUS_EXPR cst
                  if (!range_includes_zero_p (&r))
                    return true;
                }
              // Fallback
              r = range_nonzero (TREE_TYPE (gimple_assign_rhs1 (stmt)));
              return true;
could work, given that most of the pointer ranges are just the simple ones
perhaps it is too much for little benefit.

2021-11-17  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/103255
	* gimple-range-fold.cc (fold_using_range::range_of_address): Return
	range_nonzero rather than unadjusted base's range.  Formatting fixes.

	* gcc.c-torture/execute/pr103255.c: New test.
2021-11-17 13:45:53 +01:00
Richard Sandiford
7061300025 Add IFN_COND_FMIN/FMAX functions
This patch adds conditional forms of FMAX and FMIN, following
the pattern for existing conditional binary functions.

gcc/
	* doc/md.texi (cond_fmin@var{mode}, cond_fmax@var{mode}): Document.
	* optabs.def (cond_fmin_optab, cond_fmax_optab): New optabs.
	* internal-fn.def (COND_FMIN, COND_FMAX): New functions.
	* internal-fn.c (first_commutative_argument): Handle them.
	(FOR_EACH_COND_FN_PAIR): Likewise.
	* match.pd (UNCOND_BINARY, COND_BINARY): Likewise.
	* config/aarch64/aarch64-sve.md (cond_<fmaxmin><mode>): New
	pattern.

gcc/testsuite/
	* gcc.target/aarch64/sve/cond_fmaxnm_5.c: New test.
	* gcc.target/aarch64/sve/cond_fmaxnm_5_run.c: Likewise.
	* gcc.target/aarch64/sve/cond_fmaxnm_6.c: Likewise.
	* gcc.target/aarch64/sve/cond_fmaxnm_6_run.c: Likewise.
	* gcc.target/aarch64/sve/cond_fmaxnm_7.c: Likewise.
	* gcc.target/aarch64/sve/cond_fmaxnm_7_run.c: Likewise.
	* gcc.target/aarch64/sve/cond_fmaxnm_8.c: Likewise.
	* gcc.target/aarch64/sve/cond_fmaxnm_8_run.c: Likewise.
	* gcc.target/aarch64/sve/cond_fminnm_5.c: Likewise.
	* gcc.target/aarch64/sve/cond_fminnm_5_run.c: Likewise.
	* gcc.target/aarch64/sve/cond_fminnm_6.c: Likewise.
	* gcc.target/aarch64/sve/cond_fminnm_6_run.c: Likewise.
	* gcc.target/aarch64/sve/cond_fminnm_7.c: Likewise.
	* gcc.target/aarch64/sve/cond_fminnm_7_run.c: Likewise.
	* gcc.target/aarch64/sve/cond_fminnm_8.c: Likewise.
	* gcc.target/aarch64/sve/cond_fminnm_8_run.c: Likewise.
2021-11-17 12:28:44 +00:00
Kewen Lin
bf5f41e4fc i386: Fix non-robust split condition in define_insn_and_split
This patch is to fix some non-robust split conditions in some
define_insn_and_splits, to make each of them applied on top of
the corresponding condition for define_insn part, otherwise the
splitting could perform unexpectedly.

gcc/ChangeLog:

	* config/i386/i386.md (*add<dwi>3_doubleword, *addv<dwi>4_doubleword,
	*addv<dwi>4_doubleword_1, *sub<dwi>3_doubleword,
	*subv<dwi>4_doubleword, *subv<dwi>4_doubleword_1,
	*add<dwi>3_doubleword_cc_overflow_1, *divmodsi4_const,
	*neg<dwi>2_doubleword, *tls_dynamic_gnu2_combine_64_<mode>): Fix split
	condition.
2021-11-17 04:02:20 -06:00
Andrew Pinski
1a15a91a00 Fix PR 103288, ICE after PHI-OPT, move an assigment when still in use for another bb
The problem is r12-5300-gf98f373dd822b35c allows phiopt to recognize more basic blocks
but missed one location where phiopt could move an assignment from the middle block
to the non-middle one.  This patch fixes that.

OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.

	PR tree-optimization/103288

gcc/ChangeLog:

	* tree-ssa-phiopt.c (value_replacement): Return early if middle
	block has more than one pred.

gcc/testsuite/ChangeLog:

	* gcc.c-torture/compile/pr103288-1.c: New test.
2021-11-17 08:04:14 +00:00
Kewen Lin
b8ce19bb1a visium: Fix non-robust split condition in define_insn_and_split
This patch is to fix some non-robust split conditions in some
define_insn_and_splits, to make each of them applied on top of
the corresponding condition for define_insn part, otherwise the
splitting could perform unexpectedly.

gcc/ChangeLog:

	* config/visium/visium.md (*add<mode>3_insn, *addsi3_insn, *addi3_insn,
	*sub<mode>3_insn, *subsi3_insn, *subdi3_insn, *neg<mode>2_insn,
	*negdi2_insn, *and<mode>3_insn, *ior<mode>3_insn, *xor<mode>3_insn,
	*one_cmpl<mode>2_insn, *ashl<mode>3_insn, *ashr<mode>3_insn,
	*lshr<mode>3_insn, *trunchiqi2_insn, *truncsihi2_insn,
	*truncdisi2_insn, *extendqihi2_insn, *extendqisi2_insn,
	*extendhisi2_insn, *extendsidi2_insn, *zero_extendqihi2_insn,
	*zero_extendqisi2_insn, *zero_extendsidi2_insn): Fix split condition.
2021-11-16 23:55:01 -06:00
Marek Polacek
51c500269b libcpp: Implement -Wbidi-chars for CVE-2021-42574 [PR103026]
From a link below:
"An issue was discovered in the Bidirectional Algorithm in the Unicode
Specification through 14.0. It permits the visual reordering of
characters via control sequences, which can be used to craft source code
that renders different logic than the logical ordering of tokens
ingested by compilers and interpreters. Adversaries can leverage this to
encode source code for compilers accepting Unicode such that targeted
vulnerabilities are introduced invisibly to human reviewers."

More info:
https://nvd.nist.gov/vuln/detail/CVE-2021-42574
https://trojansource.codes/

This is not a compiler bug.  However, to mitigate the problem, this patch
implements -Wbidi-chars=[none|unpaired|any] to warn about possibly
misleading Unicode bidirectional control characters the preprocessor may
encounter.

The default is =unpaired, which warns about improperly terminated
bidirectional control characters; e.g. a LRE without its corresponding PDF.
The level =any warns about any use of bidirectional control characters.

This patch handles both UCNs and UTF-8 characters.  UCNs designating
bidi characters in identifiers are accepted since r204886.  Then r217144
enabled -fextended-identifiers by default.  Extended characters in C/C++
identifiers have been accepted since r275979.  However, this patch still
warns about mixing UTF-8 and UCN bidi characters; there seems to be no
good reason to allow mixing them.

We warn in different contexts: comments (both C and C++-style), string
literals, character constants, and identifiers.  Expectedly, UCNs are ignored
in comments and raw string literals.  The bidirectional control characters
can nest so this patch handles that as well.

I have not included nor tested this at all with Fortran (which also has
string literals and line comments).

Dave M. posted patches improving diagnostic involving Unicode characters.
This patch does not make use of this new infrastructure yet.

	PR preprocessor/103026

gcc/c-family/ChangeLog:

	* c.opt (Wbidi-chars, Wbidi-chars=): New option.

gcc/ChangeLog:

	* doc/invoke.texi: Document -Wbidi-chars.

libcpp/ChangeLog:

	* include/cpplib.h (enum cpp_bidirectional_level): New.
	(struct cpp_options): Add cpp_warn_bidirectional.
	(enum cpp_warning_reason): Add CPP_W_BIDIRECTIONAL.
	* internal.h (struct cpp_reader): Add warn_bidi_p member
	function.
	* init.c (cpp_create_reader): Set cpp_warn_bidirectional.
	* lex.c (bidi): New namespace.
	(get_bidi_utf8): New function.
	(get_bidi_ucn): Likewise.
	(maybe_warn_bidi_on_close): Likewise.
	(maybe_warn_bidi_on_char): Likewise.
	(_cpp_skip_block_comment): Implement warning about bidirectional
	control characters.
	(skip_line_comment): Likewise.
	(forms_identifier_p): Likewise.
	(lex_identifier): Likewise.
	(lex_string): Likewise.
	(lex_raw_string): Likewise.

gcc/testsuite/ChangeLog:

	* c-c++-common/Wbidi-chars-1.c: New test.
	* c-c++-common/Wbidi-chars-2.c: New test.
	* c-c++-common/Wbidi-chars-3.c: New test.
	* c-c++-common/Wbidi-chars-4.c: New test.
	* c-c++-common/Wbidi-chars-5.c: New test.
	* c-c++-common/Wbidi-chars-6.c: New test.
	* c-c++-common/Wbidi-chars-7.c: New test.
	* c-c++-common/Wbidi-chars-8.c: New test.
	* c-c++-common/Wbidi-chars-9.c: New test.
	* c-c++-common/Wbidi-chars-10.c: New test.
	* c-c++-common/Wbidi-chars-11.c: New test.
	* c-c++-common/Wbidi-chars-12.c: New test.
	* c-c++-common/Wbidi-chars-13.c: New test.
	* c-c++-common/Wbidi-chars-14.c: New test.
	* c-c++-common/Wbidi-chars-15.c: New test.
	* c-c++-common/Wbidi-chars-16.c: New test.
	* c-c++-common/Wbidi-chars-17.c: New test.
2021-11-16 21:56:16 -05:00
David Malcolm
111fd515f2 analyzer: fix missing -Wanalyzer-write-to-const [PR102695]
This patch fixes -Wanalyzer-write-to-const so that it will complain
about attempts to write to functions, to labels.
It also "teaches" the analyzer about strchr, in that strchr can either
return a pointer into the input area (and thus -Wanalyzer-write-to-const
can now complain about writes into a string literal seen this way),
or return NULL (and thus the analyzer can complain about NULL
dereferences if the result is used without a check).

gcc/analyzer/ChangeLog:
	PR analyzer/102695
	* region-model-impl-calls.cc (region_model::impl_call_strchr): New.
	* region-model-manager.cc
	(region_model_manager::maybe_fold_unaryop): Simplify cast to
	pointer type of an existing pointer to a region.
	* region-model.cc (region_model::on_call_pre): Handle
	BUILT_IN_STRCHR and "strchr".
	(write_to_const_diagnostic::emit): Add auto_diagnostic_group.  Add
	alternate wordings for functions and labels.
	(write_to_const_diagnostic::describe_final_event): Add alternate
	wordings for functions and labels.
	(region_model::check_for_writable_region): Handle RK_FUNCTION and
	RK_LABEL.
	* region-model.h (region_model::impl_call_strchr): New decl.

gcc/testsuite/ChangeLog:
	PR analyzer/102695
	* gcc.dg/analyzer/pr102695.c: New test.
	* gcc.dg/analyzer/strchr-1.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2021-11-16 21:01:14 -05:00
David Malcolm
a80d4e098b analyzer: don't assume target has alloca [PR102779]
gcc/testsuite/ChangeLog:
	PR analyzer/102779
	* gcc.dg/analyzer/capacity-1.c: Add dg-require-effective-target
	alloca.  Use __builtin_alloca rather than alloca.
	* gcc.dg/analyzer/capacity-3.c: Likewise.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2021-11-16 20:59:49 -05:00
Jan Hubicka
8c693978dd Fix clearing of to_info_lto in ipa_merge_modref_summary_after_inlining
This patch fixes bug that caused some optimizations to be dropped with
-fdump-ipa-inline.

gcc/ChangeLog:

2021-11-17  Jan Hubicka  <hubicka@ucw.cz>

	PR ipa/103246
	* ipa-modref.c (ipa_merge_modref_summary_after_inlining): Fix clearing
	of to_info_lto
2021-11-17 01:44:28 +01:00
GCC Administrator
6b1695f4a0 Daily bump. 2021-11-17 00:16:29 +00:00
Jonathan Wakely
73e4d9f175 libstdc++: Fix tests for constexpr std::string
Some tests fail when run with -D_GLIBCXX_USE_CXX11_ABI or -stdgnu++20.

libstdc++-v3/ChangeLog:

	* include/bits/basic_string.h (operator<=>): Use constexpr
	unconditionally.
	* testsuite/21_strings/basic_string/modifiers/constexpr.cc:
	Require cxx11-abit effective target.
	* testsuite/21_strings/headers/string/synopsis.cc: Add
	conditional constexpr to declarations, and adjust relational
	operators for C++20.
2021-11-16 22:48:15 +00:00
Jason Merrill
395848255c c-family: don't cache large vecs
Patrick observed recently that an element of the vector cache could be
arbitrarily large.  Let's only cache relatively small vecs.

gcc/c-family/ChangeLog:

	* c-common.c (release_tree_vector): Only cache vecs smaller than
	16 elements.
2021-11-16 17:35:15 -05:00
Jan Hubicka
6dc90c4dbb Use modref summaries for byte-wise dead store elimination.
gcc/ChangeLog:

	* ipa-modref.c (get_modref_function_summary): Declare.
	* ipa-modref.h (get_modref_function_summary): New function.
	* tree-ssa-dse.c (clear_live_bytes_for_ref): Break out from ...
	(clear_bytes_written_by): ... here; also clear memory killed by
	calls.

gcc/testsuite/ChangeLog:

	* gcc.dg/tree-ssa/modref-dse-4.c: New test.
2021-11-16 23:01:28 +01:00
Martin Uecker
42cdf08ad8 MAINTAINERS: Add myself to DCO section and update email address
ChangeLog:

	* MAINTAINERS: Add myself to DCO section and update email address.
2021-11-16 22:49:55 +01:00
Harald Anlauf
3b3c993233 Fortran: avoid NULL pointer dereference on invalid range in logical SELECT CASE
gcc/fortran/ChangeLog:

	PR fortran/103286
	* resolve.c (resolve_select): Choose appropriate range limit to
	avoid NULL pointer dereference when generating error message.

gcc/testsuite/ChangeLog:

	PR fortran/103286
	* gfortran.dg/pr103286.f90: New test.
2021-11-16 21:06:06 +01:00
Iain Sandoe
a1d2b16202 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.
2021-11-16 19:44:51 +00:00
Iain Sandoe
e464119128 PCH: Make the save and restore diagnostics more robust.
When saving, if we cannot obtain a suitable memory segment there
is no point in continuing, so exit with an error.

When reading in the PCH, we have a situation that the read-in
data will replace the line tables used by the diagnostics output.
However, the state of the read-oin line tables is indeterminate
at some points where diagnostics might be needed.

To make this more robust, we save the existing line tables at
the start and, once we have read in the pointer to the new one,
put that to one side and restore the original table.  This
avoids compiler hangs if the read or memory acquisition code
issues an assert, fatal_error, segv etc.

Once the read is complete, we swap in the new line table that
came from the PCH.

If the read-in PCH is corrupted then we still have a broken
compilation w.r.t any future diagnostics - but there is little
that can be done about that without more careful validation of
the file.

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

gcc/ChangeLog:

	* ggc-common.c (gt_pch_save): If we cannot find a suitable
	memory segment for save, then error-out, do not try to
	continue.
	(gt_pch_restore): Save the existing line table, and when
	the replacement is being read, use that when constructing
	diagnostics.
2021-11-16 19:42:35 +00:00
Peter Bergner
4cdf7db9a3 rs6000: MMA test case emits wrong code when building a vector pair [PR102976]
PR102976 shows a test case where we generate wrong code when building
a vector pair from 2 vector registers.  The bug here is that with unlucky
register assignments, we can clobber one of the input operands before
we write both registers of the output operand.  The solution is to use
early-clobbers in the assemble pair and accumulator patterns.

2021-11-16  Peter Bergner  <bergner@linux.ibm.com>

gcc/
	PR target/102976
	* config/rs6000/mma.md (*vsx_assemble_pair): Add early-clobber for
	output operand.
	(*mma_assemble_acc): Likewise.

gcc/testsuite/
	PR target/102976
	* gcc.target/powerpc/pr102976.c: New test.
2021-11-16 12:14:22 -06:00
Mikael Morin
48a8c5be5b fortran: Identify arguments by their names
This provides a new function to get the name of a dummy argument,
so that identifying an argument can be made using just its name
instead of a mix of name matching (for keyword actual arguments)
and argument counting (for other actual arguments).

gcc/fortran/ChangeLog:
	* interface.c (gfc_dummy_arg_get_name): New function.
	* gfortran.h (gfc_dummy_arg_get_name): Declare it.
	* trans-array.c (arg_evaluated_for_scalarization): Pass a dummy
	argument wrapper as argument instead of an actual argument
	and an index number.  Check it’s non-NULL.  Use its name
	to identify it.
	(gfc_walk_elemental_function_args): Update call to
	arg_evaluated for scalarization.  Remove argument counting.
2021-11-16 19:07:51 +01:00
Mikael Morin
e94e2cf9f9 fortran: Delete redundant missing_arg_type field
Now that we can get information about an actual arg's associated
dummy using the associated_dummy attribute, the field missing_arg_type
contains redundant information.
This removes it.

gcc/fortran/ChangeLog:
	* gfortran.h (gfc_actual_arglist::missing_arg_type): Remove.
	* interface.c (gfc_compare_actual_formal): Remove
	missing_arg_type initialization.
	* intrinsic.c (sort_actual): Ditto.
	* trans-expr.c (gfc_conv_procedure_call): Use associated_dummy
	and gfc_dummy_arg_get_typespec to get the dummy argument type.
2021-11-16 19:07:50 +01:00
Mikael Morin
5d9d16db96 fortran: simplify elemental arguments walking
This adds two functions working with the wrapper struct gfc_dummy_arg
and makes usage of them to simplify a bit the walking of elemental
procedure arguments for scalarization.  As information about dummy arguments
can be obtained from the actual argument through the just-introduced
associated_dummy field, there is no need to carry around the procedure
interface and walk dummy arguments manually together with actual arguments.

gcc/fortran/ChangeLog:
	* interface.c (gfc_dummy_arg_get_typespec,
	gfc_dummy_arg_is_optional): New functions.
	* gfortran.h (gfc_dummy_arg_get_typespec,
	gfc_dummy_arg_is_optional): Declare them.
	* trans.h (gfc_ss_info::dummy_arg): Use the wrapper type
	as declaration type.
	* trans-array.c (gfc_scalar_elemental_arg_saved_as_reference):
	use gfc_dummy_arg_get_typespec function to get the type.
	(gfc_walk_elemental_function_args): Remove proc_ifc argument.
	Get info about the dummy arg using the associated_dummy field.
	* trans-array.h (gfc_walk_elemental_function_args): Update declaration.
	* trans-intrinsic.c (gfc_walk_intrinsic_function):
	Update call to gfc_walk_elemental_function_args.
	* trans-stmt.c (gfc_trans_call): Ditto.
	(get_proc_ifc_for_call): Remove.
2021-11-16 19:07:50 +01:00
Mikael Morin
5888512f24 fortran: Reverse actual vs dummy argument mapping
There was originally no way from an actual argument to get
to the corresponding dummy argument, even if the job of sorting
and matching actual with dummy arguments was done.
The closest was a field named actual in gfc_intrinsic_arg that was
used as scratch data when sorting arguments of one specific call.
However that value was overwritten later on as arguments of another
call to the same procedure were sorted and matched.

This change removes that field from gfc_intrinsic_arg and adds instead
a new field associated_dummy in gfc_actual_arglist.

The new field has as type a new wrapper struct gfc_dummy_arg that provides
a common interface to both dummy arguments of user-defined procedures
(which have type gfc_formal_arglist) and dummy arguments of intrinsic procedures
(which have type gfc_intrinsic_arg).

As the removed field was used in the code sorting and matching arguments,
that code has to be updated.  Two local vectors with matching indices
are introduced for respectively dummy and actual arguments, and the
loops are modified to use indices and update those argument vectors.

gcc/fortran/ChangeLog:
	* gfortran.h (gfc_dummy_arg_kind, gfc_dummy_arg): New.
	(gfc_actual_arglist): New field associated_dummy.
	(gfc_intrinsic_arg): Remove field actual.
	* interface.c (get_nonintrinsic_dummy_arg): New.
	(gfc_compare_actual): Initialize associated_dummy.
	* intrinsic.c (get_intrinsic_dummy_arg): New.
	(sort_actual):  Add argument vectors.
	Use loops with indices on argument vectors.
	Initialize associated_dummy.
2021-11-16 19:07:50 +01:00
Mikael Morin
c31733c3bf fortran: Tiny sort_actual internal refactoring
Preliminary refactoring to make further changes more obvious.
No functional change.

gcc/fortran/ChangeLog:
	* intrinsic.c (sort_actual): initialise variable and use it earlier.
2021-11-16 19:07:50 +01:00
Patrick Palka
7461b58131 libstdc++: Merge latest Ryu sources
libstdc++-v3/ChangeLog:

	* src/c++17/ryu/MERGE: Update the commit hash.
	* src/c++17/ryu/d2s_intrinsics.h: Merge from Ryu's master
	branch.

Signed-off-by: Patrick Palka <ppalka@redhat.com>
2021-11-16 12:23:27 -05:00
Michael de Lang
b96e2ff9d8 libstdc++: Implement constexpr std::basic_string for C++20
This is only supported for the cxx11 ABI, not for COW strings.

libstdc++-v3/ChangeLog:

	* include/bits/basic_string.h (basic_string, operator""s): Add
	constexpr for C++20.
	(basic_string::basic_string(basic_string&&)): Only copy
	initialized portion of the buffer.
	(basic_string::basic_string(basic_string&&, const Alloc&)):
	Likewise.
	* include/bits/basic_string.tcc (basic_string): Add constexpr
	for C++20.
	(basic_string::swap(basic_string&)): Only copy initialized
	portions of the buffers.
	(basic_string::_M_replace): Add constexpr implementation that
	doesn't depend on pointer comparisons.
	* include/bits/cow_string.h: Adjust comment.
	* include/ext/type_traits.h (__is_null_pointer): Add constexpr.
	* include/std/string (erase, erase_if): Add constexpr.
	* include/std/version (__cpp_lib_constexpr_string): Update
	value.
	* testsuite/21_strings/basic_string/cons/char/constexpr.cc:
	New test.
	* testsuite/21_strings/basic_string/cons/wchar_t/constexpr.cc:
	New test.
	* testsuite/21_strings/basic_string/literals/constexpr.cc:
	New test.
	* testsuite/21_strings/basic_string/modifiers/constexpr.cc: New test.
	* testsuite/21_strings/basic_string/modifiers/swap/char/constexpr.cc:
	New test.
	* testsuite/21_strings/basic_string/modifiers/swap/wchar_t/constexpr.cc:
	New test.
	* testsuite/21_strings/basic_string/version.cc: New test.
2021-11-16 16:43:20 +00:00
Jonathan Wakely
59434931fb libstdc++: Use hidden friends for vector<bool>::reference swap overloads
These swap overloads are non-standard, but are needed to make swap work
for vector<bool>::reference rvalues. They don't need to be called
explicitly, only via ADL, so hide them from normal lookup. This is what
I've proposed as the resolution to LWG 3638.

libstdc++-v3/ChangeLog:

	* include/bits/stl_bvector.h (swap(_Bit_reference, _Bit_reference))
	(swap(_Bit_reference, bool&), swap(bool&, _Bit_reference)):
	Define as hidden friends of _Bit_reference.
2021-11-16 16:42:59 +00:00
Martin Sebor
ba6e17e78d Avoid assuming maximum string length is constant [PR102960].
Resolves:
PR tree-optimization/102960 - ICE: in sign_mask, at wide-int.h:855 in GCC 10.3.0

gcc/ChangeLog:

	PR tree-optimization/102960
	* gimple-fold.c (get_range_strlen): Take bitmap as an argument rather
	than a pointer to it.
	(get_range_strlen_tree): Same.  Remove bitmap allocation.  Use
	an auto_bitmap.
	(get_maxval_strlen): Use an auto_bitmap.
	* tree-ssa-strlen.c (get_range_strlen_dynamic): Factor out PHI
	handling...
	(get_range_strlen_phi): ...into this function.
	Avoid assuming maximum string length is constant
	(printf_strlen_execute): Dump pointer query cache contents when
	details are requisted.

gcc/testsuite/ChangeLog:

	PR tree-optimization/102960
	* gcc.dg/Wstringop-overflow-84.c: New test.
2021-11-16 09:18:25 -07:00
Tamar Christina
0002a8a199 shrn-combine-10: update test to current codegen.
When the rshrn commit was reverted I missed this testcase.
This now updates it.

gcc/testsuite/ChangeLog:

	* gcc.target/aarch64/shrn-combine-10.c: Use shrn.
2021-11-16 15:39:28 +00:00
Tamar Christina
9836e907c4 signbit-2: make test check for scalar or vector versions
This updates the signbit-2 test to check for
the scalar optimization if the target does not
support vectorization.

gcc/testsuite/ChangeLog:

	* gcc.dg/signbit-2.c: CHeck vect or scalar.
2021-11-16 15:38:28 +00:00
David Malcolm
e1c0c908f8 analyzer: fix overeager sharing of bounded_range instances [PR102662]
This was leading to an assertion failure ICE on a switch stmt when using
-fstrict-enums, due to erroneously reusing a range involving one enum
with a range involving a different enum.

gcc/analyzer/ChangeLog:
	PR analyzer/102662
	* constraint-manager.cc (bounded_range::operator==): Require the
	types to be the same for equality.

gcc/testsuite/ChangeLog:
	PR analyzer/102662
	* g++.dg/analyzer/pr102662.C: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2021-11-16 10:23:04 -05:00
Jason Merrill
132f1c2777 c++: improve print_node of PTRMEM_CST
It's been inconvenient that pretty-printing of PTRMEM_CST didn't display
what member the constant refers to.

Adding that is complicated by the absence of a langhook for CONSTANT_CLASS_P
nodes; the simplest fix for that is to use the tcc_exceptional hook for
tcc_constant as well.

gcc/cp/ChangeLog:

	* ptree.c (cxx_print_xnode): Handle PTRMEM_CST.

gcc/ChangeLog:

	* langhooks.h (struct lang_hooks): Adjust comment.
	* print-tree.c (print_node): Also call print_xnode hook for
	tcc_constant class.
2021-11-16 10:20:30 -05:00
Andrew Pinski
11c4a06a6c tree-optimization: [PR103218] Fold ((type)(a<0)) << SIGNBITOFA into ((type)a) & signbit
This folds Fold ((type)(a<0)) << SIGNBITOFA into ((type)a) & signbit inside match.pd.
This was already handled in fold-cost by:
/* A < 0 ? <sign bit of A> : 0 is simply (A & <sign bit of A>).  */
I have not removed as we only simplify "a ? POW2 : 0" at the gimple level to "a << CST1"
and fold actually does the reverse of folding "(a<0)<<CST" into "(a<0) ? 1<<CST : 0".

OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.

	PR tree-optimization/103218

gcc/ChangeLog:

	* match.pd: New pattern for "((type)(a<0)) << SIGNBITOFA".

gcc/testsuite/ChangeLog:

	* gcc.dg/tree-ssa/pr103218-1.c: New test.
2021-11-16 15:07:39 +00:00
Jonathan Wakely
8d8e8f3ad5 libstdc++: Fix out-of-bound array accesses in testsuite
I fixed some undefined behaviour in string tests in r238609, but I only
fixed the narrow char versions. This applies the same fixes to the
wchar_t ones. These problems were found when testing a patch to make
std::basic_string usable in constexpr.

libstdc++-v3/ChangeLog:

	* testsuite/21_strings/basic_string/modifiers/append/wchar_t/1.cc:
	Fix reads past the end of strings.
	* testsuite/21_strings/basic_string/operations/compare/wchar_t/1.cc:
	Likewise.
	* testsuite/experimental/string_view/operations/compare/wchar_t/1.cc:
	Likewise.
2021-11-16 14:09:00 +00:00
Jonathan Wakely
9719769471 libstdc++: Fix typos in tests
libstdc++-v3/ChangeLog:

	* testsuite/21_strings/basic_string/allocator/71964.cc: Fix
	typo.
	* testsuite/23_containers/set/allocator/71964.cc: Likewise.
2021-11-16 14:08:42 +00:00
Claudiu Zissulescu
b796ab35d1 arc: Update (u)maddhisi4 patterns
The (u)maddsihi4 patterns are using the ARC's VMAC2H(U)
instruction with null destination, however, VMAC2H(U) doesn't
rewrite the accumulator.  This patch solves the destination issue
of VMAC2H by replacing it with DMACH(U) instruction.

gcc/

	* config/arc/arc.md (maddhisi4): Use a single move to accumulator.
	(umaddhisi4): Likewise.
	(machi): Update pattern.
	(umachi): Likewise.

gcc/testsuite/

	* gcc.target/arc/tmac-4.c: New test.

Signed-off-by: Claudiu Zissulescu <claziss@synopsys.com>
2021-11-16 12:34:59 +02:00
Richard Biener
0452064503 tree-optimization/102880 - improve CD-DCE
The PR shows a missed control-dependent DCE caused by CFG cleanup
merging a forwarder resulting in a partially degenerate PHI node.
With control-dependent DCE we need to mark control dependences
of incoming edges into PHIs as necessary but that is unnecessarily
conservative for the case when two edges have the same value.
There is no easy way to mark only a subset of control dependences
of both edges necessary so the fix is to produce forwarder blocks
where then the control dependence captures the requirements more
precisely.

For gcc.dg/tree-ssa/ssa-dom-thread-7.c the number of edges in the
CFG decrease as we have commonized PHI arguments which in turn
results in different threadings.  The testcase is too complex
and the dump scanning too simple to do anything meaningful here
but to adjust the number of expected threads.

The same CFG massaging could be useful at RTL expansion time to
reduce the number of copies we need to insert on edges.

FAIL: gcc.dg/tree-ssa/ssa-hoist-4.c scan-tree-dump-times optimized "MAX_EXPR" 1

2021-11-12  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/102880
	* tree-ssa-dce.c (sort_phi_args): New function.
	(make_forwarders_with_degenerate_phis): Likewise.
	(perform_tree_ssa_dce): Call
	make_forwarders_with_degenerate_phis.

	* gcc.dg/tree-ssa/pr102880.c: New testcase.
	* gcc.dg/tree-ssa/pr69270-3.c: Robustify.
	* gcc.dg/tree-ssa/ssa-dom-thread-7.c: Change the number of
	expected threadings.
2021-11-16 11:31:56 +01:00
Richard Biener
f98f373dd8 tree-optimization/102880 - make PHI-OPT recognize more CFGs
This allows extra edges into the middle BB for the PHI-OPT
transforms using replace_phi_edge_with_variable that do not
end up moving stmts from that middle BB.  This avoids regressing
gcc.dg/tree-ssa/ssa-hoist-4.c with the actual fix for PR102880
where CFG cleanup has the choice to remove two forwarders and
picks "the wrong" leading to

   if (a > b) /
       /\    /
      /  <BB>
     /    |
  # PHI <a, b>

rather than

   if (a > b)  |
       /\      |
    <BB> \     |
     /    \    |
  # PHI <a, b, b>

but it's relatively straight-forward to support extra edges
into the middle-BB in paths ending in replace_phi_edge_with_variable
and that do not require moving stmts.  That's because we really
only want to remove the edge from the condition to the middle BB.
Of course actually doing that means updating dominators in non-trival
ways which is why I kept the original code for the single edge
case and simply defer to CFG cleanup by adjusting the condition for
the complicated case.

The testcase needs to be a GIMPLE one since it's quite unreliable
to produce the desired CFG.

2021-11-15  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/102880
	* tree-ssa-phiopt.c (tree_ssa_phiopt_worker): Push
	single_pred (bb1) condition to places that really need it.
	(match_simplify_replacement): Likewise.
	(value_replacement): Likewise.
	(replace_phi_edge_with_variable): Deal with extra edges
	into the middle BB.

	* gcc.dg/tree-ssa/phi-opt-26.c: New testcase.
2021-11-16 11:31:05 +01:00
Claudiu Zissulescu
d699f03720 arc: Update arc specific tests
Update assembly output test pattern. Take into consideration also for
which platform we do execute the test (baremetal or linux).

gcc/testsuite/ChangeLog:

	* gcc.target/arc/add_n-combine.c: Update test patterns.
	* gcc.target/arc/builtin_eh.c: Update test for linux platforms.
	* gcc.target/arc/mul64-1.c: Disable this test while running on
	linux.
	* gcc.target/arc/tls-gd.c: Update matching patterns.
	* gcc.target/arc/tls-ie.c: Likewise.
	* gcc.target/arc/tls-ld.c: Likewise.
	* gcc.target/arc/uncached-8.c: Likewise.

Signed-off-by: Claudiu Zissulescu <claziss@synopsys.com>
2021-11-16 11:58:24 +02:00
Martin Jambor
23125fab7b
Replace more DEBUG_EXPR_DECL creations with build_debug_expr_decl
As discussed on the mailing list, this patch replaces all but one
remaining open coded constructions of DEBUG_EXPR_DECL with calls to
build_debug_expr_decl, even if - in order not to introduce any
functional change - the mode of the constructed decl is then
overwritten.

It is not clear if changing the mode has any effect in practice and
therefore I have added a FIXME note to code which does it, as
requested.

After this patch, DEBUG_EXPR_DECLs are created only by
build_debug_expr_decl and make_debug_expr_from_rtl which looks like
it should be left alone.

gcc/ChangeLog:

2021-11-11  Martin Jambor  <mjambor@suse.cz>

	* cfgexpand.c (expand_gimple_basic_block): Use build_debug_expr_decl,
	add a fixme note about the mode assignment perhaps being unnecessary.
	* ipa-param-manipulation.c (ipa_param_adjustments::modify_call):
	Likewise.
	(ipa_param_body_adjustments::mark_dead_statements): Likewise.
	(ipa_param_body_adjustments::reset_debug_stmts): Likewise.
	* tree-inline.c (remap_ssa_name): Likewise.
	(tree_function_versioning): Likewise.
	* tree-into-ssa.c (rewrite_debug_stmt_uses): Likewise.
	* tree-ssa-loop-ivopts.c (remove_unused_ivs): Likewise.
	* tree-ssa.c (insert_debug_temp_for_var_def): Likewise.
2021-11-16 10:45:46 +01:00
Martin Jambor
9f7fc82014
ipa-sra: Testcase that removing a "returns_nonnull" retval works
Since we can now remove return values of functions with return_nonnull
type attribute, I'll feel a bit safer if we can test this does not ICE
when someone attempts to access a non-existent call LHS.  Eventually
we should probably drop the attribute when this happens.

gcc/testsuite/ChangeLog:

2021-11-15  Martin Jambor  <mjambor@suse.cz>

	* gcc.dg/ipa/ipa-sra-ret-nonull.c: New test.
2021-11-16 10:45:32 +01:00
Jakub Jelinek
9ceaf0fee3 libgomp: Mark thread_limit clause to target construct as implemented
After the Fortran changes we can mark it as implemented...

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

	* libgomp.texi (OpenMP 5.1): Mark thread_limit clause to target
	construct as implemented.
2021-11-16 10:21:56 +01:00