Commit graph

210211 commits

Author SHA1 Message Date
Jonathan Wakely
4896bb3199 libstdc++: Implement std::formatter<std:🧵:id> without <sstream> [PR115099]
The std:🧵:id formatter uses std::basic_ostringstream without
including <sstream>, which went unnoticed because the test for it uses
a stringstream to check the output is correct.

The fix implemented here is to stop using basic_ostringstream for
formatting thread::id and just use std::format instead.

As a drive-by fix, the formatter specialization is constrained to
require that the thread:🆔:native_handle_type can be formatted, to
avoid making the formatter ill-formed if the pthread_t type is not a
pointer or integer. Since non-void pointers can't be formatted, ensure
that we convert pointers to const void* for formatting. Make a similar
change to the existing operator<< overload so that in the unlikely case
that pthread_t is a typedef for char* we don't treat it as a
null-terminated string when inserting into a stream.

libstdc++-v3/ChangeLog:

	PR libstdc++/115099
	* include/bits/std_thread.h: Declare formatter as friend of
	thread::id.
	* include/std/thread (operator<<): Convert non-void pointers to
	void pointers for output.
	(formatter): Add constraint that thread::native_handle_type is a
	pointer or integer.
	(formatter::format): Reimplement without basic_ostringstream.
	* testsuite/30_threads/thread/id/output.cc: Check output
	compiles before <sstream> has been included.

(cherry picked from commit 1a5e4dd83788ea4c049d354d83ad58a6a3d747e6)
2024-05-22 10:06:52 +01:00
Jakub Jelinek
fc9fb69ad6 strlen: Fix up !si->full_string_p handling in count_nonzero_bytes_addr [PR115152]
The following testcase is miscompiled because
strlen_pass::count_nonzero_bytes_addr doesn't handle correctly
the !si->full_string_p case.
If si->full_string_p, it correctly computes minlen and maxlen as
minimum and maximum length of the '\0' terminated stgring and
clears *nulterm (ie. makes sure !full_string_p in the ultimate
caller) if minlen is equal or larger than nbytes and so
'\0' isn't guaranteed to be among those bytes.
But in the !si->full_string_p case, all we know is that there
are [minlen,maxlen] non-zero bytes followed by unknown bytes,
so effectively the maxlen is infinite (but caller cares about only
the first nbytes bytes) and furthermore, we never know if there is
any '\0' char among those, so *nulterm needs to be always cleared.

2024-05-22  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/115152
	* tree-ssa-strlen.cc (strlen_pass::count_nonzero_bytes_addr): If
	!si->full_string_p, clear *nulterm and set maxlen to nbytes.

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

(cherry picked from commit dbc9b45a3c2468ad134b3a9bd4961f7ae6bc1e67)
2024-05-22 09:19:01 +02:00
Jakub Jelinek
d224c7d8d8 ubsan: Use right address space for MEM_REF created for bool/enum sanitization [PR115172]
The following testcase is miscompiled, because -fsanitize=bool,enum
creates a MEM_REF without propagating there address space qualifiers,
so what should be normally loaded using say %gs:/%fs: segment prefix
isn't.  Together with asan it then causes that load to be sanitized.

2024-05-22  Jakub Jelinek  <jakub@redhat.com>

	PR sanitizer/115172
	* ubsan.cc (instrument_bool_enum_load): If rhs is not in generic
	address space, use qualified version of utype with the right
	address space.  Formatting fix.

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

(cherry picked from commit d3c506eff54fcbac389a529c2e98da108a410b7f)
2024-05-22 09:19:00 +02:00
Haochen Jiang
1ad5c9d524 i386: Disable ix86_expand_vecop_qihi2 when !TARGET_AVX512BW
Since vpermq is really slow, we should avoid using it for permutation
when vpmovwb is not available (needs AVX512BW) for ix86_expand_vecop_qihi2
and fall back to ix86_expand_vecop_qihi.

gcc/ChangeLog:

	PR target/115069
	* config/i386/i386-expand.cc (ix86_expand_vecop_qihi2):
	Do not enable the optimization when AVX512BW is not enabled.

gcc/testsuite/ChangeLog:

	PR target/115069
	* gcc.target/i386/pr115069.c: New.
2024-05-22 10:26:42 +08:00
GCC Administrator
d2f4279516 Daily bump. 2024-05-22 00:22:39 +00:00
Jonathan Wakely
5b96d547ce c++: Fix std dialect hint for std::to_address [PR107800]
The correct dialect for std::to_address is cxx20 not cxx11.

gcc/cp/ChangeLog:

	PR libstdc++/107800
	* cxxapi-data.csv <to_address>: Change dialect to cxx20.
	* std-name-hint.gperf: Regenerate.
	* std-name-hint.h: Regenerate.

(cherry picked from commit 826a7d3d19d3ebf04e21d6f1c89eb341a36fb5d1)
2024-05-21 22:02:57 +01:00
Patrick Palka
caf43cc9e5 c++: folding non-dep enumerator from current inst [PR115139]
After the tsubst_copy removal r14-4796-g3e3d73ed5e85e7 GCC 14 ICEs during
fold_non_dependent_expr for 'e1 | e2' below ultimately because we no
longer exit early when substituting the CONST_DECLs for e1 and e2 with
args=NULL_TREE and instead proceed to substitute the class context A<Ts...>
(also with args=NULL_TREE) which ends up ICEing from tsubst_pack_expansion
(due to processing_template_decl being cleared).

Incidentally, the ICE went away on trunk ever since the tsubst_aggr_type
removal r15-123-gf04dc89a991ddc since it changed the CONST_DECL case of
tsubst_expr to use tsubst to substitute the context, which short circuits
for empty args and so avoids the ICE.

This patch fixes this ICE for GCC 14 by narrowly restoring the early exit
for empty args that would've happened in tsubst_copy when substituting an
enumerator CONST_DECL.  We might as well apply this to trunk too, as a
small optimization.

	PR c++/115139

gcc/cp/ChangeLog:

	* pt.cc (tsubst_expr) <case CONST_DECL>: Exit early if args
	is empty.

gcc/testsuite/ChangeLog:

	* g++.dg/template/non-dependent33.C: New test.

Reviewed-by: Marek Polacek <mpolacek@redhat.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
(cherry picked from commit f0c0bced62b9c728ed1e672747aa234d918da22c)
2024-05-21 15:55:26 -04:00
Harald Anlauf
edde60a53c Fortran: fix dependency checks for inquiry refs [PR115039]
gcc/fortran/ChangeLog:

	PR fortran/115039
	* expr.cc (gfc_traverse_expr): An inquiry ref does not constitute
	a dependency and cannot collide with a symbol.

gcc/testsuite/ChangeLog:

	PR fortran/115039
	* gfortran.dg/statement_function_5.f90: New test.

(cherry picked from commit d4974fd22730014e337fd7ec2471945ba8afb00e)
2024-05-21 21:01:40 +02:00
Andrew Pinski
b2bb49d6a7 match: Disable (type)zero_one_valuep*CST for 1bit signed types [PR115154]
The problem here is the pattern added in r13-1162-g9991d84d2a8435
assumes that it is well defined to multiply zero_one_valuep by the truncated
converted integer constant. It is well defined for all types except for signed 1bit types.
Where `a * -1` is produced which is undefined/
So disable this pattern for 1bit signed types.

Note the pattern added in r14-3432-gddd64a6ec3b38e is able to workaround the undefinedness except when
`-fsanitize=undefined` is turned on, this is why I added a testcase for that.

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

	PR tree-optimization/115154

gcc/ChangeLog:

	* match.pd (convert (mult zero_one_valued_p@1 INTEGER_CST@2)): Disable
	for 1bit signed types.

gcc/testsuite/ChangeLog:

	* c-c++-common/ubsan/signed1bitfield-1.c: New test.
	* gcc.c-torture/execute/signed1bitfield-1.c: New test.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
(cherry picked from commit 49c87d22535ac4f8aacf088b3f462861c26cacb4)
2024-05-21 07:25:30 -07:00
GCC Administrator
786597185d Daily bump. 2024-05-21 01:18:26 +00:00
Andrew Pinski
89ab128656 PHIOPT: Don't transform minmax if middle bb contains a phi [PR115143]
The problem here is even if last_and_only_stmt returns a statement,
the bb might still contain a phi node which defines a ssa name
which is used in that statement so we need to add a check to make sure
that the phi nodes are empty for the middle bbs in both the
`CMP?MINMAX:MINMAX` case and the `CMP?MINMAX:B` cases.

Bootstrapped and tested on x86_64_linux-gnu with no regressions.

	PR tree-optimization/115143

gcc/ChangeLog:

	* tree-ssa-phiopt.cc (minmax_replacement): Check for empty
	phi nodes for middle bbs for the case where middle bb is not empty.

gcc/testsuite/ChangeLog:

	* gcc.c-torture/compile/pr115143-1.c: New test.
	* gcc.c-torture/compile/pr115143-2.c: New test.
	* gcc.c-torture/compile/pr115143-3.c: New test.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
(cherry picked from commit 9ff8f041331ef8b56007fb3c4d41d76f9850010d)
2024-05-20 14:56:11 -07:00
Patrick Palka
a983793420 c++: aggregate CTAD w/ paren init and bases [PR115114]
During aggregate CTAD with paren init, we're accidentally overlooking
base classes since TYPE_FIELDS of a template type doesn't contain
corresponding base fields.  So we need to consider them separately.

	PR c++/115114

gcc/cp/ChangeLog:

	* pt.cc (maybe_aggr_guide): Consider bases in the paren init case.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp2a/class-deduction-aggr15.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
(cherry picked from commit 5aaf47cb1987bbc5508c4b9b7dad5ea7d69af2c2)
2024-05-20 09:51:24 -04:00
Patrick Palka
b3399b445b c++: lvalueness of non-dependent assignment expr [PR114994]
r14-4111-g6e92a6a2a72d3b made us check non-dependent simple assignment
expressions ahead of time and give them a type, as was already done for
compound assignments.  Unlike for compound assignments however, if a
simple assignment resolves to an operator overload we represent it as a
(typed) MODOP_EXPR instead of a CALL_EXPR to the selected overload.
(I reckoned this was at worst a pessimization -- we'll just have to repeat
overload resolution at instantiatiation time.)

But this turns out to break the below testcase ultimately because
MODOP_EXPR (of non-reference type) is always treated as an lvalue
according to lvalue_kind, which is incorrect for the MODOP_EXPR
representing x=42.

We can fix this by representing such class assignment expressions as
CALL_EXPRs as well, but this turns out to require some tweaking of our
-Wparentheses warning logic and may introduce other fallout making it
unsuitable for backporting.

So this patch instead fixes lvalue_kind to consider the type of a
MODOP_EXPR representing a class assignment.

	PR c++/114994

gcc/cp/ChangeLog:

	* tree.cc (lvalue_kind) <case MODOP_EXPR>: For a class
	assignment, consider the result type.

gcc/testsuite/ChangeLog:

	* g++.dg/template/non-dependent32.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
(cherry picked from commit c6cc6d4741a880109c4e0e64d5a189687fb526f6)
2024-05-20 09:51:23 -04:00
GCC Administrator
2502ac4b2e Daily bump. 2024-05-20 01:10:46 +00:00
GCC Administrator
a7240b0bde Daily bump. 2024-05-19 19:09:01 +00:00
Wolfgang Hospital
3b88dade7f AVR: target/115065 - Tweak __clzhi2.
The libgcc implementation of __clzhi2 can be tweaked by
one cycle in some situations by re-arranging the instructions.
It also reduces the WCET by 1 cycle.

libgcc/
	PR target/115065
	* config/avr/lib1funcs.S (__clzhi2): Tweak.

(cherry picked from commit 988838da722dea09bd81ee9d49800a6f24980372)
2024-05-18 15:14:58 +02:00
Paul Thomas
c887341432 Fortran: Fix select type regression due to r14-9489 [PR114874]
2024-05-17  Paul Thomas  <pault@gcc.gnu.org>

gcc/fortran
	PR fortran/114874
	* gfortran.h: Add 'assoc_name_inferred' to gfc_namespace.
	* match.cc (gfc_match_select_type): Set 'assoc_name_inferred'
	in select type namespace if the selector has inferred type.
	* primary.cc (gfc_match_varspec): If a select type temporary
	is apparently scalar and a left parenthesis has been detected,
	check the current namespace has 'assoc_name_inferred' set. If
	so, set inferred_type.
	* resolve.cc (resolve_variable): If the namespace of a select
	type temporary is marked with 'assoc_name_inferred' call
	gfc_fixup_inferred_type_refs to ensure references are OK.
	(gfc_fixup_inferred_type_refs): Catch invalid array refs..

gcc/testsuite/
	PR fortran/114874
	* gfortran.dg/pr114874_1.f90: New test for valid code.
	* gfortran.dg/pr114874_2.f90: New test for invalid code.

(cherry picked from commit 5f5074fe7aaf9524defb265299a985eecba7f914)
2024-05-17 15:22:57 +01:00
Jonathan Wakely
e909d360df
libstdc++: Fix typo in _Grapheme_cluster_view::_Iterator [PR115119]
libstdc++-v3/ChangeLog:

	PR libstdc++/115119
	* include/bits/unicode.h (_Iterator::operator++(int)): Fix typo
	in increment expression.
	* testsuite/ext/unicode/grapheme_view.cc: Check post-increment
	on view's iterator.

(cherry picked from commit c9e05b03c18e898be604ab90401476e9c473cc52)
2024-05-17 13:48:43 +01:00
Richard Biener
1e9ae50d4d tree-optimization/114998 - use-after-free with loop distribution
When loop distribution releases a PHI node of the original IL it
can end up clobbering memory that's re-used when it upon releasing
its RDG resets all stmt UIDs back to -1, even those that got released.

The fix is to avoid resetting UIDs based on stmts in the RDG but
instead reset only those still present in the loop.

	PR tree-optimization/114998
	* tree-loop-distribution.cc (free_rdg): Take loop argument.
	Reset UIDs of stmts still in the IL rather than all stmts
	referenced from the RDG.
	(loop_distribution::build_rdg): Pass loop to free_rdg.
	(loop_distribution::distribute_loop): Likewise.
	(loop_distribution::transform_reduction_loop): Likewise.

	* gcc.dg/torture/pr114998.c: New testcase.

(cherry picked from commit 34d15a4d630a0d54eddb99bdab086c506e10dac5)
2024-05-17 11:26:40 +02:00
Joseph Myers
81c627d47c Update gcc sv.po
* sv.po: Update.
2024-05-16 21:21:48 +00:00
GCC Administrator
82e4bdc5c3 Daily bump. 2024-05-16 00:22:15 +00:00
Richard Biener
1d89cb4394 middle-end/114931 - type_hash_canon and structual equality types
TYPE_STRUCTURAL_EQUALITY_P is part of our type system so we have
to make sure to include that into the type unification done via
type_hash_canon.  This requires the flag to be set before querying
the hash which is the biggest part of the patch.

	PR middle-end/114931
gcc/
	* tree.cc (type_hash_canon_hash): Hash TYPE_STRUCTURAL_EQUALITY_P.
	(type_cache_hasher::equal): Compare TYPE_STRUCTURAL_EQUALITY_P.
	(build_array_type_1): Set TYPE_STRUCTURAL_EQUALITY_P before
	probing with type_hash_canon.
	(build_function_type): Likewise.
	(build_method_type_directly): Likewise.
	(build_offset_type): Likewise.
	(build_complex_type): Likewise.
	* attribs.cc (build_type_attribute_qual_variant): Likewise.

gcc/c-family/
	* c-common.cc (complete_array_type): Set TYPE_STRUCTURAL_EQUALITY_P
	before probing with type_hash_canon.

gcc/testsuite/
	* gcc.dg/pr114931.c: New testcase.

(cherry picked from commit b09c2e9560648b0cf993c2ca9ad972c34e6bddfa)
2024-05-15 13:40:20 +02:00
Richard Biener
573e1df0ec Avoid changing type in the type_hash_canon hash
When building a type and type_hash_canon returns an existing type
avoid changing it, in particular its TYPE_CANONICAL.

	PR middle-end/114931
	* tree.cc (build_array_type_1): Return early when type_hash_canon
	returned an older existing type.
	(build_function_type): Likewise.
	(build_method_type_directly): Likewise.
	(build_offset_type): Likewise.

(cherry picked from commit 7a212ac678e13e0df5da2d090144b246a1262b64)
2024-05-15 13:40:13 +02:00
GCC Administrator
7c49e45fbf Daily bump. 2024-05-15 00:22:45 +00:00
Jonathan Wakely
eefa4c0648 libstdc++: Guard dynamic_cast use in src/c++23/print.cc [PR115015]
Do not use dynamic_cast unconditionally, in case libstdc++ is built with
-fno-rtti.

libstdc++-v3/ChangeLog:

	PR libstdc++/115015
	* src/c++23/print.cc (__open_terminal(streambuf*)) [!__cpp_rtti]:
	Do not use dynamic_cast.
2024-05-14 15:06:56 +01:00
Jonathan Wakely
c60205cd4a libstdc++: Fix typo in std::stacktrace::max_size [PR115063]
libstdc++-v3/ChangeLog:

	PR libstdc++/115063
	* include/std/stacktrace (basic_stacktrace::max_size): Fix typo
	in reference to _M_alloc member.
	* testsuite/19_diagnostics/stacktrace/stacktrace.cc: Check
	max_size() compiles.

(cherry picked from commit dd9677f3343ca2a4b4aab9428b8129774accac29)
2024-05-14 10:50:20 +01:00
Jonathan Wakely
4d3b358fd7 libstdc++: Guard uses of is_pointer_interconvertible_v [PR114891]
This type trait isn't supported by Clang 18. It's only used in static
assertions, so they can just be omitted if the trait isn't available.

libstdc++-v3/ChangeLog:

	PR libstdc++/114891
	* include/std/generator: Check feature test macro before using
	is_pointer_interconvertible_v.

(cherry picked from commit 1fbe1a50d86df11f434351cf62461a32747f9710)
2024-05-14 10:50:19 +01:00
Jonathan Wakely
788ccd269e libstdc++: Update ABI test to disallow adding to released symbol versions
If we update the list of "active" symbols versions now, rather than when
adding a new symbol version, we will notice if new symbols get added to
the wrong version (as in PR 114692).

libstdc++-v3/ChangeLog:

	* testsuite/util/testsuite_abi.cc: Update latest versions to
	new versions that should be used in future.

(cherry picked from commit 6e25ca387fbbb412a2e498e28ea5db28e033a318)
2024-05-14 10:50:19 +01:00
Jonathan Wakely
b0f022f93a libstdc++: Fix handling of incomplete UTF-8 sequences in _Unicode_view
Eddie Nolan reported to me that _Unicode_view was not correctly
implementing the substitution of ill-formed subsequences with U+FFFD,
due to failing to increment the counter when the iterator reaches the
end of the sequence before a multibyte sequence is complete.  As a
result, the incomplete sequence was not completely consumed, and then
the remaining character was treated as another ill-formed sequence,
giving two U+FFFD characters instead of one.

To avoid similar mistakes in future, this change introduces a lambda
that increments the iterator and the counter together. This ensures the
counter is always incremented when the iterator is incremented, so that
we always know how many characters have been consumed.

libstdc++-v3/ChangeLog:

	* include/bits/unicode.h (_Unicode_view::_M_read_utf8): Ensure
	count of characters consumed is correct when the end of the
	input is reached unexpectedly.
	* testsuite/ext/unicode/view.cc: Test incomplete UTF-8
	sequences.

(cherry picked from commit 3f04f3939ea0ac8fdd766a60655d29de2ffb44e5)
2024-05-14 10:50:19 +01:00
Jonathan Wakely
95055199ee libstdc++: Fix <memory> for -std=c++23 -ffreestanding [PR114866]
std::shared_ptr isn't declared for freestanding, so guard uses of it
with #if _GLIBCXX_HOSTED in <bits/out_ptr.h>.

libstdc++-v3/ChangeLog:

	PR libstdc++/114866
	* include/bits/out_ptr.h [!_GLIBCXX_HOSTED]: Don't refer to
	shared_ptr, __shared_ptr or __is_shred_ptr.
	* testsuite/20_util/headers/memory/114866.cc: New test.

(cherry picked from commit 9927059bb88e966e0a45f09e4fd1193f93df708f)
2024-05-14 10:50:19 +01:00
GCC Administrator
679fa4dd81 Daily bump. 2024-05-14 00:21:46 +00:00
Patrick Palka
57cd8665fe c++: nested aggregate/alias CTAD fixes [PR114974, PR114901, PR114903]
During maybe_aggr_guide with a nested class template and paren init,
like with list init we need to consider the generic template type rather
than the partially instantiated type since partial instantiations don't
have (partially instantiated) TYPE_FIELDS.  In turn we need to partially
substitute PARMs in the paren init case as well.  As a drive-by improvement
it seems better to use outer_template_args instead of DECL_TI_ARGS during
this partial substitution so that we lower instead of substitute the
innermost template parameters, which is generally more robust.

And during alias_ctad_tweaks with a nested class template, even though
the guides may be already partially instantiated we still need to
substitute the outermost arguments into its constraints.

	PR c++/114974
	PR c++/114901
	PR c++/114903

gcc/cp/ChangeLog:

	* pt.cc (maybe_aggr_guide): Fix obtaining TYPE_FIELDS in
	the paren init case.  Hoist out partial substitution logic
	to apply to the paren init case as well.
	(alias_ctad_tweaks): Substitute outer template arguments into
	a guide's constraints.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp2a/class-deduction-aggr14.C: New test.
	* g++.dg/cpp2a/class-deduction-alias20.C: New test.
	* g++.dg/cpp2a/class-deduction-alias21.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
(cherry picked from commit 6d31a370e26eeb950c326332633b3e8e84b6630b)
2024-05-13 09:54:53 -04:00
Joseph Myers
0b5642e17a Update gcc .po files
* be.po, da.po, de.po, el.po, es.po, fi.po, fr.po, hr.po, id.po,
	ja.po, nl.po, ru.po, sr.po, sv.po, tr.po, uk.po, vi.po, zh_CN.po,
	zh_TW.po: Update.
2024-05-13 13:46:48 +00:00
GCC Administrator
8fcc4e7870 Daily bump. 2024-05-13 08:56:24 +00:00
Gerald Pfeifer
80ccc90be4 doc: Describe limitations re Ada, D, and Go on FreeBSD
gcc:
	PR target/69374
	PR target/112959
	* doc/install.texi (Specific) <*-*-freebsd*>: The Ada and D
	run-time libraries are broken on i386 which also can affect
	64-bit builds. Go is broken.

(cherry picked from commit ff98aab108a6a4e50a831e7cfc011c2131f8d19c)
2024-05-12 15:31:33 +02:00
Gerald Pfeifer
609f9699cd doc: FreeBSD no longer has a GNU toolchain in base
gcc:
	PR target/69374
	PR target/112959
	* doc/install.texi (Specific) <*-*-freebsd*>: No longer refer
	to GCC or binutils in base. Recommend bootstrap using binutils.

(cherry picked from commit 0695aba3e987f4bb06c95f29ff90a8a3234e1507)
2024-05-12 15:30:18 +02:00
Gerald Pfeifer
7939f8823e doc: Remove old details on libunwind for ia64-*-hpux*
gcc:
	PR target/69374
	* doc/install.texi (Specific) <ia64-*-hpux*>: Remove details
	on libunwind for GCC 3.4 and earlier.

(cherry picked from commit 81f7965e63028c1289ae3b1836750da74b01bc4a)
2024-05-12 15:28:27 +02:00
Gerald Pfeifer
cf43da54f8 doc: Remove references to FreeBSD 7 and older
FreeBSD 7 has been end of life for years and current GCC most likely
would not build there anymore anyways.

gcc:
	PR target/69374
	PR target/112959
	* doc/install.texi (Specific) <*-*-freebsd*>: Remove references to
	FreeBSD 7 and older.

(cherry picked from commit 507f3ce34c55e78b23eeaf57bc4d927a1f25f8fb)
2024-05-12 15:26:34 +02:00
Georg-Johann Lay
fcdd723779 AVR: target/114981 - Tweak __builtin_powif / __powisf2
Implement __powisf2 in assembly.

	PR target/114981
libgcc/
	* config/avr/t-avr (LIB2FUNCS_EXCLUDE): Add _powisf2.
	(LIB1ASMFUNCS) [!avrtiny]: Add _powif.
	* config/avr/lib1funcs.S (mov4): New .macro.
	(L_powif, __powisf2) [!avrtiny]: New module and function.

gcc/testsuite/
	* gcc.target/avr/pr114981-powif.c: New test.

(cherry picked from commit af64af69c3cc85dbe00c520651a54850bf5cadc1)
2024-05-10 12:02:14 +02:00
Jakub Jelinek
a805de33f7 c++, mingw: Fix up types of dtor hooks to __cxa_{,thread_}atexit/__cxa_throw on mingw ia32 [PR114968]
__cxa_atexit/__cxa_thread_atexit/__cxa_throw functions accept function
pointers to usually directly destructors rather than wrappers around
them.
Now, mingw ia32 uses implicitly __attribute__((thiscall)) calling
conventions for METHOD_TYPE (where the this pointer is passed in %ecx
register, the rest on the stack), so these functions use:
in config/os/mingw32/os_defines.h:
 #if defined (__i386__)
 #define _GLIBCXX_CDTOR_CALLABI __thiscall
 #endif
in libsupc++/cxxabi.h
__cxa_atexit(void (_GLIBCXX_CDTOR_CALLABI *)(void*), void*, void*) _GLIBCXX_NOTHROW;
__cxa_thread_atexit(void (_GLIBCXX_CDTOR_CALLABI *)(void*), void*, void *) _GLIBCXX_NOTHROW;
__cxa_throw(void*, std::type_info*, void (_GLIBCXX_CDTOR_CALLABI *) (void *))
__attribute__((__noreturn__));

Now, mingw for some weird reason uses
 #define TARGET_CXX_USE_ATEXIT_FOR_CXA_ATEXIT hook_bool_void_true
so it never actually uses __cxa_atexit, but does use __cxa_thread_atexit
and __cxa_throw.  Recent changes for modules result in more detailed
__cxa_*atexit/__cxa_throw prototypes precreated by the compiler, and if
that happens and one also includes <cxxabi.h>, the compiler complains about
mismatches in the prototypes.

One thing is the missing thiscall attribute on the FUNCTION_TYPE, the
other problem is that all of atexit/__cxa_atexit/__cxa_thread_atexit
get function pointer types created by a single function,
get_atexit_fn_ptr_type (), which creates it depending on if atexit
or __cxa_atexit will be used as either void(*)(void) or void(*)(void *),
but when using atexit and __cxa_thread_atexit it uses the wrong function
type for __cxa_thread_atexit.

The following patch adds a target hook to add the thiscall attribute to the
function pointers, and splits the get_atexit_fn_ptr_type () function into
get_atexit_fn_ptr_type () and get_cxa_atexit_fn_ptr_type (), the former always
creates shared void(*)(void) type, the latter creates either
void(*)(void*) (on most targets) or void(__attribute__((thiscall))*)(void*)
(on mingw ia32).  So that we don't waiste another GTY global tree for it,
because cleanup_type used for the same purpose for __cxa_throw should be
the same, the code changes it to use that type too.

In register_dtor_fn then based on the decision whether to use atexit,
__cxa_atexit or __cxa_thread_atexit it picks the right function pointer
type, and also if it decides to emit a __tcf_* wrapper for the cleanup,
uses that type for that wrapper so that it agrees on calling convention.

2024-05-10  Jakub Jelinek  <jakub@redhat.com>

	PR target/114968
gcc/
	* target.def (use_atexit_for_cxa_atexit): Remove spurious space
	from comment.
	(adjust_cdtor_callabi_fntype): New cxx target hook.
	* targhooks.h (default_cxx_adjust_cdtor_callabi_fntype): Declare.
	* targhooks.cc (default_cxx_adjust_cdtor_callabi_fntype): New
	function.
	* doc/tm.texi.in (TARGET_CXX_ADJUST_CDTOR_CALLABI_FNTYPE): Add.
	* doc/tm.texi: Regenerate.
	* config/i386/i386.cc (ix86_cxx_adjust_cdtor_callabi_fntype): New
	function.
	(TARGET_CXX_ADJUST_CDTOR_CALLABI_FNTYPE): Redefine.
gcc/cp/
	* cp-tree.h (atexit_fn_ptr_type_node, cleanup_type): Adjust macro
	comments.
	(get_cxa_atexit_fn_ptr_type): Declare.
	* decl.cc (get_atexit_fn_ptr_type): Adjust function comment, only
	build type for atexit argument.
	(get_cxa_atexit_fn_ptr_type): New function.
	(get_atexit_node): Call get_cxa_atexit_fn_ptr_type rather than
	get_atexit_fn_ptr_type when using __cxa_atexit.
	(get_thread_atexit_node): Call get_cxa_atexit_fn_ptr_type
	rather than get_atexit_fn_ptr_type.
	(start_cleanup_fn): Add ob_parm argument, call
	get_cxa_atexit_fn_ptr_type or get_atexit_fn_ptr_type depending
	on it and create PARM_DECL also based on that argument.
	(register_dtor_fn): Adjust start_cleanup_fn caller, use
	get_cxa_atexit_fn_ptr_type rather than get_atexit_fn_ptr_type
	for use_dtor casts.
	* except.cc (build_throw): Use get_cxa_atexit_fn_ptr_type ().

(cherry picked from commit e5d8fd9ce05611093191d500ebc39f150d0ece2b)
2024-05-10 11:07:59 +02:00
Xi Ruoyao
21051de4be
driver: Move -fdiagnostics-urls= early like -fdiagnostics-color= [PR114980]
In GCC 14 we started to emit URLs for "command-line option <option> is
valid for <language> but not <another language>" and "-Werror= argument
'-Werror=<option>' is not valid for <language>" warnings.  So we should
have moved -fdiagnostics-urls= early like -fdiagnostics-color=, or
-fdiagnostics-urls= wouldn't be able to control URLs in these warnings.

No test cases are added because with TERM=xterm-256colors PR114980
already triggers some test failures.

gcc/ChangeLog:

	PR driver/114980
	* opts-common.cc (prune_options): Move -fdiagnostics-urls=
	early like -fdiagnostics-color=.

(cherry picked from commit f75806ec63ec1af2d76a194e5fa73e114b2b8857)
2024-05-10 11:21:08 +08:00
Harald Anlauf
a504623550 Fortran: fix issues with class(*) assignment [PR114827]
gcc/fortran/ChangeLog:

	PR fortran/114827
	* trans-array.cc (gfc_alloc_allocatable_for_assignment): Take into
	account _len of unlimited polymorphic entities when calculating
	the effective element size for allocation size and array span.
	Set _len of lhs to _len of rhs.
	* trans-expr.cc (trans_class_assignment): Take into account _len
	of unlimited polymorphic entities for allocation size.

gcc/testsuite/ChangeLog:

	PR fortran/114827
	* gfortran.dg/asan/unlimited_polymorphic_34.f90: New test.

(cherry picked from commit 21e7aa5f3ea44ca2fef8deb8788edffc04901b5c)
2024-05-09 20:22:49 +02:00
GCC Administrator
93793ed35d Daily bump. 2024-05-09 11:03:31 +00:00
Jakub Jelinek
726e7a64ed testsuite: Fix up vector-subaccess-1.C test for ia32 [PR89224]
The test FAILs on i686-linux due to
.../gcc/testsuite/g++.dg/torture/vector-subaccess-1.C:16:6: warning: SSE vector argument without SSE enabled changes the ABI [-Wpsabi]
excess warnings.

This fixes it by adding -Wno-psabi, like commonly done in other tests.

2024-05-09  Jakub Jelinek  <jakub@redhat.com>

	PR c++/89224
	* g++.dg/torture/vector-subaccess-1.C: Add -Wno-psabi as additional
	options.

(cherry picked from commit 8fb65ec816ff8f0d529b6d30821abace4328c9a2)
2024-05-09 11:22:41 +02:00
Georg-Johann Lay
bbb76ac0a0 AVR: target/114975 - Add combine-pattern for __parityqi2.
PR target/114975
gcc/
	* config/avr/avr.md: Add combine pattern for
	8-bit parity detection.

gcc/testsuite/
	* gcc.target/avr/pr114975-parity.c: New test.

(cherry picked from commit 41bc359c322d45ec1adfb51f7a45c7ef02ce6ca9)
2024-05-09 10:37:59 +02:00
Georg-Johann Lay
4ef09dd8ce AVR: target/114975 - Add combine-pattern for __popcountqi2.
PR target/114975
gcc/
	* config/avr/avr.md: Add combine pattern for
	8-bit popcount detection.

gcc/testsuite/
	* gcc.target/avr/pr114975-popcount.c: New test.

(cherry picked from commit c8f4bbb824fafecf021a802324cd79e64b03b947)
2024-05-09 10:37:26 +02:00
Georg-Johann Lay
a9e313ed38 AVR: target/114981 - Support __builtin_powi[l] / __powidf2.
This supports __powidf2 by means of a double wrapper for already
existing f7_powi (renamed to __f7_powi by f7-renames.h).
It tweaks the implementation so that it does not perform trivial
multiplications with 1.0 any more, but instead uses a move.
It also fixes the last statement of f7_powi, which was wrong.
Notice that f7_powi was unused until now.

	PR target/114981
libgcc/config/avr/libf7/
	* libf7-common.mk (F7_ASM_PARTS): Add D_powi
	* libf7-asm.sx (F7MOD_D_powi_, __powidf2): New module and function.
	* libf7.c (f7_powi): Fix last (wrong) statement.
	Tweak trivial multiplications with 1.0.

gcc/testsuite/
	* gcc.target/avr/pr114981-powil.c: New test.

(cherry picked from commit de4eea7d7ea86e54843507c68d6672eca9d8c7bb)
2024-05-09 10:13:54 +02:00
Iain Sandoe
7e8fae89f3 Objective-C, NeXT, v2: Correct a regression in code-gen.
There have been several changes in the ABI of Objective-C which
depend on the OS version targetted.  In this case Protocols and
LabelProtocols should be made weak/hidden/extern from macOS 10.7
however there was a mistake in the code causing this to occur
from macOS 10.6.  Fixed thus.

gcc/objc/ChangeLog:

	* objc-next-runtime-abi-02.cc (WEAK_PROTOCOLS_AFTER): New.
	(next_runtime_abi_02_protocol_decl): Use WEAK_PROTOCOLS_AFTER
	to determine this ABI change.
	(build_v2_protocol_list_address_table): Likewise.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
(cherry picked from commit 9b5c0be59d0f94df0517820f00b4520b5abddd8c)
2024-05-08 10:18:54 +01:00
Jakub Jelinek
d54151df3b reassoc: Fix up optimize_range_tests_to_bit_test [PR114965]
The optimize_range_tests_to_bit_test optimization normally emits a range
test first:
          if (entry_test_needed)
            {
              tem = build_range_check (loc, optype, unshare_expr (exp),
                                       false, lowi, high);
              if (tem == NULL_TREE || is_gimple_val (tem))
                continue;
            }
so during the bit test we already know that exp is in the [lowi, high]
range, but skips it if we have range info which tells us this isn't
necessary.
Also, normally it emits shifts by exp - lowi counter, but has an
optimization to use just exp counter if the mask isn't a more expensive
constant in that case and lowi is > 0 and high is smaller than prec.

The following testcase is miscompiled because the two abnormal cases
are triggered.  The range of exp is [43, 43][48, 48][95, 95], so we on
64-bit arch decide we don't need the entry test, because 95 - 43 < 64.
And we also decide to use just exp as counter, because the range test
tests just for exp == 43 || exp == 48, so high is smaller than 64 too.
Because 95 is in the exp range, we can't do that, we'd either need to
do a range test first, i.e.
if (exp - 43U <= 48U - 43U) if ((1UL << exp) & mask1))
or need to subtract lowi from the shift counter, i.e.
if ((1UL << (exp - 43)) & mask2)
but can't do both unless r.upper_bound () is < prec.

The following patch ensures that.

2024-05-08  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/114965
	* tree-ssa-reassoc.cc (optimize_range_tests_to_bit_test): Don't try to
	optimize away exp - lowi subtraction from shift count unless entry
	test is emitted or unless r.upper_bound () is smaller than prec.

	* gcc.c-torture/execute/pr114965.c: New test.

(cherry picked from commit 9adec2d91e62a479474ae79df5b455fd4b8463ba)
2024-05-08 10:19:01 +02:00
Andrew Pinski
cacc48014c c++/c-common: Fix convert_vector_to_array_for_subscript for qualified vector types [PR89224]
After r7-987-gf17a223de829cb, the access for the elements of a vector type would lose the qualifiers.
So if we had `constvector[0]`, the type of the element of the array would not have const on it.
This was due to a missing build_qualified_type for the inner type of the vector when building the array type.
We need to add back the call to build_qualified_type and now the access has the correct qualifiers. So the
overloads and even if it is a lvalue or rvalue is correctly done.

Note we correctly now reject the testcase gcc.dg/pr83415.c which was incorrectly accepted after r7-987-gf17a223de829cb.

Built and tested for aarch64-linux-gnu.

	PR c++/89224

gcc/c-family/ChangeLog:

	* c-common.cc (convert_vector_to_array_for_subscript): Call build_qualified_type
	for the inner type.

gcc/cp/ChangeLog:

	* constexpr.cc (cxx_eval_array_reference): Compare main variants
	for the vector/array types instead of the types directly.

gcc/testsuite/ChangeLog:

	* g++.dg/torture/vector-subaccess-1.C: New test.
	* gcc.dg/pr83415.c: Change warning to error.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
(cherry picked from commit 4421d35167b3083e0f2e4c84c91fded09a30cf22)
2024-05-07 16:50:09 -07:00