platform/upstream/gcc.git
20 months agolibstdc++: Add always_inline to trivial range access functions
Jonathan Wakely [Thu, 17 Nov 2022 10:21:54 +0000 (10:21 +0000)]
libstdc++: Add always_inline to trivial range access functions

This makes all the [iterator.range] functions always-inline, except the
ones that construct a std::reverse_iterator, as they do a little more
work. They could probably be made always_inline too though, and maybe
the std::reverse_iterator constructor too.

This means that even for -O0 these functions have no runtime overhead
compared with calling a member of the container, or performing pointer
arithmetic for arrays.

libstdc++-v3/ChangeLog:

* include/bits/range_access.h: Add always_inline attribute to
trivial functions.

20 months agoconstexprify some tree variables
Andrew Pinski [Fri, 18 Nov 2022 05:05:03 +0000 (05:05 +0000)]
constexprify some tree variables

Since we use C++11 by default now, we can
use constexpr for some const decls in tree-core.h.

This patch does that and it allows for better optimizations
of GCC code with checking enabled and without LTO.

For an example generic-match.cc compiling is speed up due
to the less number of basic blocks and less debugging info
produced. I did not check the speed of compiling the same source
but rather the speed of compiling the old vs new sources here
(but with the same compiler base).

The small slow down in the parsing of the arrays in each TU
is migrated by a speed up in how much code/debugging info
is produced in the end.

Note I looked at generic-match.cc since it is one of the
compiling sources which causes parallel building to stall and
I wanted to speed it up.

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

gcc/ChangeLog:

PR middle-end/14840
* tree-core.h (tree_code_type): Constexprify
by including all-tree.def.
(tree_code_length): Likewise.
* tree.cc (tree_code_type): Remove.
(tree_code_length): Remove.

20 months agolibstdc++: Fix -Wsign-compare warnings in std::format
Jonathan Wakely [Fri, 18 Nov 2022 21:06:18 +0000 (21:06 +0000)]
libstdc++: Fix -Wsign-compare warnings in std::format

libstdc++-v3/ChangeLog:

* include/std/format: Fix -Wsign-compare warnings.

20 months agolibstdc++: Fix Doxygen warning
Jonathan Wakely [Thu, 17 Nov 2022 10:20:50 +0000 (10:20 +0000)]
libstdc++: Fix Doxygen warning

This fixes a Doxygen warning about a mismatched parameter name. The
standard uses 'r' here, like the Doxygen comment, so use '__r' instead
of '__e'.

libstdc++-v3/ChangeLog:

* include/bits/ptr_traits.h (pointer_traits::pointer_to): Rename
parameter.

20 months agolibstdc++: Fix one more malformed requires-clause [PR107649]
Jonathan Wakely [Fri, 18 Nov 2022 21:17:51 +0000 (21:17 +0000)]
libstdc++: Fix one more malformed requires-clause [PR107649]

libstdc++-v3/ChangeLog:

PR libstdc++/107649
* include/std/complex (__complex_proj): Fix requires-clause.

20 months agonvptx: In 'STARTFILE_SPEC', fix 'crt0.o' for '-mmainkernel'
Thomas Schwinge [Fri, 18 Nov 2022 22:57:52 +0000 (23:57 +0100)]
nvptx: In 'STARTFILE_SPEC', fix 'crt0.o' for '-mmainkernel'

A recent nvptx-tools change: commit 886a95faf66bf66a82fc0fe7d2a9fd9e9fec2820
"ld: Don't search for input files in '-L'directories" (of
<https://github.com/MentorEmbedded/nvptx-tools/pull/38>
"Match standard 'ld' "search" behavior") in GCC/nvptx target testing
generally causes linking to fail with:

    error opening crt0.o
    collect2: error: ld returned 1 exit status
    compiler exited with status 1

Indeed per GCC '-v' output, there is an undecorated 'crt0.o' on the linker
('collect2') command line:

     [...]/build-gcc/./gcc/collect2 -o [...] crt0.o [...]

This is due to:

    gcc/config/nvptx/nvptx.h:#define STARTFILE_SPEC "%{mmainkernel:crt0.o}"

..., and the fix, as used by numerous other GCC targets, is to instead use
'crt0.o%s'; for '%s' means, per 'gcc/gcc.cc', "The Specs Language":

     %s     current argument is the name of a library or startup file of some sort.
            Search for that file in a standard list of directories
            and substitute the full name found.

With that, we get the expected path to 'crt0.o'.

gcc/
* config/nvptx/nvptx.h (STARTFILE_SPEC): Fix 'crt0.o' for
'-mmainkernel'.

20 months agolibcpp: Add missing config for --enable-valgrind-annotations [PR107691]
Bernhard Reutner-Fischer [Thu, 17 Nov 2022 20:40:53 +0000 (21:40 +0100)]
libcpp: Add missing config for --enable-valgrind-annotations [PR107691]

r7-912 copied (parts of) the valgrind annotation checks from gcc
to libcpp. The above copies the missing pieces to libcpp to diagnose
when libcpp is configured with --enable-valgrind-annotations but
valgrind is not installed.

libcpp/ChangeLog:

PR preprocessor/107691
* configure.ac: Add valgrind header checks.
* configure: Regenerate.

20 months agojit: Use std::mutex instead of pthread_mutex_t
Jonathan Wakely [Fri, 11 Nov 2022 12:48:29 +0000 (12:48 +0000)]
jit: Use std::mutex instead of pthread_mutex_t

This allows JIT to be built with a different thread model from posix
where pthread isn't available

By renaming the acquire_mutex () and release_mutex () member functions
to lock() and unlock() we make the playback::context type meet the C++
Lockable requirements. This allows it to be used with a scoped lock
(i.e. RAII) type as std::lock_guard. This automatically releases the
mutex when leaving the scope.

Co-authored-by: LIU Hao <lh_mouse@126.com>
gcc/jit/ChangeLog:

* jit-playback.cc (playback::context::scoped_lock): Define RAII
lock type.
(playback::context::compile): Use scoped_lock to acquire mutex
for the active playback context.
(jit_mutex): Change to std::mutex.
(playback::context::acquire_mutex): Rename to ...
(playback::context::lock): ... this.
(playback::context::release_mutex): Rename to ...
(playback::context::unlock): ... this.
* jit-playback.h (playback::context): Rename members and declare
scoped_lock.
* jit-recording.cc (INCLUDE_PTHREAD_H): Remove unused define.
* libgccjit.cc (version_mutex): Change to std::mutex.
(struct jit_version_info): Use std::lock_guard to acquire and
release mutex.

gcc/ChangeLog:

* system.h [INCLUDE_MUTEX]: Include header for std::mutex.

20 months agolibgomp/gcn: Prepare for reverse-offload callback handling
Tobias Burnus [Sat, 19 Nov 2022 09:36:27 +0000 (10:36 +0100)]
libgomp/gcn: Prepare for reverse-offload callback handling

libgomp/ChangeLog:

* config/gcn/libgomp-gcn.h: New file; contains
struct output, declared previously in plugin-gcn.c.
* config/gcn/target.c: Include it.
(GOMP_ADDITIONAL_ICVS): Declare as extern var.
(GOMP_target_ext): Handle reverse offload.
* plugin/plugin-gcn.c: Include libgomp-gcn.h.
(struct kernargs): Replace struct def by the one
from libgomp-gcn.h for output_data.
(process_reverse_offload): New.
(console_output): Call it.

20 months agoi386: Outline fast BF -> SF conversion and fix up sNaN handling in it [PR107628]
Jakub Jelinek [Sat, 19 Nov 2022 09:17:01 +0000 (10:17 +0100)]
i386: Outline fast BF -> SF conversion and fix up sNaN handling in it [PR107628]

On Fri, Oct 21, 2022 at 10:23:14AM +0200, Uros Bizjak wrote:
> OK, but now we have two more copies of a function that effectively
> extends BF to SF. Can you please split this utility function out and
> use it here and in cbranchbf4/cstorebf4? I'm talking about this part:
>
> +      op = gen_lowpart (HImode, op1);
> +      if (CONST_INT_P (op))
> +       op = simplify_const_unary_operation (FLOAT_EXTEND, SFmode,
> +                                            op1, BFmode);
> +      else
> +       {
> +         rtx t1 = gen_reg_rtx (SImode);
> +         emit_insn (gen_zero_extendhisi2 (t1, op));
> +         emit_insn (gen_ashlsi3 (t1, t1, GEN_INT (16)));
> +         op = gen_lowpart (SFmode, t1);
> +       }
>
> Taking this a bit further, it looks like a generic function to extend
> BF to SF, when extendbfsf2 named function is not defined.
>
> The above could be a follow-up patch, the proposed patch is OK.

Sorry for the delay, only got to this now.
And I'm fixing the sNaN handling in it too.  If the argument is a BFmode sNaN
constant, we want in this case just a SFmode sNaN constant, but
simplify_const_unary_operation (FLOAT_EXTEND, ...)
in that case returns NULL (as normally conversions of a sNaN to some
other float type should raise an exception).  In this case we want
to bypass that, as we know the sNaN will be used immediately in the SFmode
comparison a few instructions later.  The patch fixes it by just
simplifying the lowpart to HImode and its zero extension to SImode, then
force into a pseudo and do the left shift and subreg to SFmode on the
pseudo.  CSE or combine can handle it later.

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

PR target/107628
* config/i386/i386-protos.h (ix86_expand_fast_convert_bf_to_sf):
Declare.
* config/i386/i386-expand.cc (ix86_expand_fast_convert_bf_to_sf): New
function.
* config/i386/i386.md (cbranchbf4, cstorebf4): Use it.

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

20 months agoc++: Implement C++23 P2647R1 - Permitting static constexpr variables in constexpr...
Jakub Jelinek [Sat, 19 Nov 2022 08:26:44 +0000 (09:26 +0100)]
c++: Implement C++23 P2647R1 - Permitting static constexpr variables in constexpr functions

The following patch implements this paper.
Per further discussions it is implemented for C++23 only, so isn't
treated as a DR, e.g. because the part of the standard the paper is
changing didn't even exist in C++20.
And we gave up on trying to implement it as a pedwarn rather than
error for C++20 and older, because of implicit constexpr lambdas or
-fimplicit-constexpr reasons.
For C++20 and older, the only change is that passing through
definitions of static or thread_local vars usable in constant expressions
is now accepted in statement expressions if they aren't inside of constexpr
or consteval functions.

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

gcc/c-family/
* c-cppbuiltin.cc (c_cpp_builtins): Bump __cpp_constexpr
value from 202207L to 202211L.
gcc/cp/
* constexpr.cc (cxx_eval_constant_expression): Implement C++23
P2647R1 - Permitting static constexpr variables in constexpr functions.
Allow DECL_EXPRs of decl_constant_var_p static or thread_local vars.
(potential_constant_expression_1): Similarly, except use
decl_maybe_constant_var_p instead of decl_constant_var_p if
processing_template_decl.
gcc/testsuite/
* g++.dg/cpp23/constexpr-nonlit17.C: New test.
* g++.dg/cpp23/constexpr-nonlit18.C: New test.
* g++.dg/cpp23/feat-cxx2b.C: Adjust expected __cpp_constexpr
value.
* g++.dg/ext/stmtexpr19.C: Don't expect an error.
* g++.dg/ext/stmtexpr25.C: New test.

20 months agoc++: implement P1492 contracts
Jeff Chapman II [Tue, 29 Jun 2021 20:52:56 +0000 (16:52 -0400)]
c++: implement P1492 contracts

Implement the P1492 versions of contracts, along with extensions that
support the emulation of N4820 and other proposals. This implementation
assigns a concrete semantic (one of: ignore, assume, enforce, or
observe) to each contract attribute depending on its labels and
configuration options.

Co-authored-by: Andrew Sutton <asutton@lock3software.com>
Co-authored-by: Andrew Marmaduke <amarmaduke@lock3software.com>
Co-authored-by: Michael Lopez <mlopez@lock3software.com>
Co-authored-by: Jason Merrill <jason@redhat.com>
gcc/ChangeLog:

* doc/invoke.texi: Document contracts flags.

gcc/c-family/ChangeLog:

* c.opt: Add contracts flags.
* c-cppbuiltin.cc (c_cpp_builtins): Add contracts feature-test
macros.

gcc/cp/ChangeLog:

* cp-tree.h (enum cp_tree_index): Add
CPTI_PSEUDO_CONTRACT_VIOLATION.
(pseudo_contract_violation_type): New macro.
(struct saved_scope): Add x_processing_contract_condition.
(processing_contract_condition): New macro.
(comparing_override_contracts): New variable decl.
(find_contract): New inline.
(set_decl_contracts): New inline.
(get_contract_semantic): New inline.
(set_contract_semantic): New inline.
* constexpr.cc (cxx_eval_assert): Split out from...
(cxx_eval_internal_function): ...here.
(cxx_eval_constant_expression): Use it for contracts.
(potential_constant_expression_1): Handle contracts.
* cp-gimplify.cc (cp_genericize_r): Handle contracts.
* cp-objcp-common.cc (cp_tree_size): Handle contracts.
(cp_common_init_ts): Handle contracts.
(cp_handle_option): Handle contracts.
* decl.cc (duplicate_decls): Handle contracts.
(check_tag_decl): Check for bogus contracts.
(start_decl): Check flag_contracts.
(grokfndecl): Call rebuild_postconditions.
(grokdeclarator): Handle contract attributes.
(start_preparsed_function): Call start_function_contracts.
(finish_function): Call finish_function_contracts.
* decl2.cc (cp_check_const_attributes): Skip contracts.
(comdat_linkage): Handle outlined contracts.
* error.cc (dump_type): Handle null TYPE_IDENTIFIER.
* g++spec.cc (EXPERIMENTAL): New macro.
(lang_specific_driver): Add -lstdc++exp if -fcontracts.
* mangle.cc (write_encoding): Handle outlined contracts.
* module.cc (trees_out::fn_parms_init): Handle outlined contracts.
(trees_in::fn_parms_init): Likewise.
(check_mergeable_decl): Likewise.
(module_state_config::get_dialect): Record -fcontracts.
* parser.h (struct cp_unparsed_functions_entry): Add contracts.
* parser.cc (unparsed_contracts): New macro.
(push_unparsed_function_queues): Adjust.
(contract_attribute_p): New.
(cp_parser_statement): Check contracts.
(cp_parser_decl_specifier_seq): Handle contracts.
(cp_parser_skip_to_closing_square_bracket): Split out...
(cp_parser_skip_up_to_closing_square_bracket): ...this fn.
(cp_parser_class_specifier): Do contract late parsing.
(cp_parser_class_head): Check contracts.
(cp_parser_contract_role): New.
(cp_parser_contract_mode_opt): New.
(find_error, contains_error_p): New.
(cp_parser_contract_attribute_spec): New.
(cp_parser_late_contract_condition): New.
(cp_parser_std_attribute_spec): Handle contracts.
(cp_parser_save_default_args): Also save contracts.
* pt.cc (register_parameter_specializations): No longer static.
(register_local_identity): New.
(check_explicit_specialization): Call remove_contract_attributes.
(tsubst_contract, tsubst_contract_attribute): New.
(tsubst_contract_attributes): New.
(tsubst_attribute): Add comment.
(tsubst_copy): Also allow parm when processing_contract_condition.
(tsubst_expr): Handle contracts.
(regenerate_decl_from_template): Handle contracts.
* search.cc (check_final_overrider): Compare contracts.
* semantics.cc (set_cleanup_locs): Skip POSTCONDITION_STMT.
(finish_non_static_data_member): Check contracts.
(finish_this_expr): Check contracts.
(process_outer_var_ref): Handle contracts.
(finish_id_expression_1): Handle contracts.
(apply_deduced_return_type): Adjust contracts.
* tree.cc (handle_contract_attribute): New.
(get_innermost_component, is_this_expression): New.
(comparing_this_references): New.
(equivalent_member_references): New.
(cp_tree_equal): Check it.
* typeck.cc (check_return_expr): Apply contracts.
* Make-lang.in: Add contracts.o.
* config-lang.in: Add contracts.cc.
* cp-tree.def (ASSERTION_STMT, PRECONDITION_STMT)
(POSTCONDITION_STMT): New.
* contracts.h: New file.
* contracts.cc: New file.

gcc/testsuite/ChangeLog:

* g++.dg/modules/modules.exp: Pass dg-options to link command.
* lib/g++.exp: Add -L for libstdc++exp.a.
* g++.dg/contracts/backtrace_handler/assert_fail.cpp: New test.
* g++.dg/contracts/backtrace_handler/handle_contract_violation.cpp: New test.
* g++.dg/contracts/contracts-access1.C: New test.
* g++.dg/contracts/contracts-assume1.C: New test.
* g++.dg/contracts/contracts-assume2.C: New test.
* g++.dg/contracts/contracts-assume3.C: New test.
* g++.dg/contracts/contracts-assume4.C: New test.
* g++.dg/contracts/contracts-assume5.C: New test.
* g++.dg/contracts/contracts-assume6.C: New test.
* g++.dg/contracts/contracts-comdat1.C: New test.
* g++.dg/contracts/contracts-config1.C: New test.
* g++.dg/contracts/contracts-constexpr1.C: New test.
* g++.dg/contracts/contracts-constexpr2.C: New test.
* g++.dg/contracts/contracts-constexpr3.C: New test.
* g++.dg/contracts/contracts-conversion1.C: New test.
* g++.dg/contracts/contracts-ctor-dtor1.C: New test.
* g++.dg/contracts/contracts-ctor-dtor2.C: New test.
* g++.dg/contracts/contracts-cv1.C: New test.
* g++.dg/contracts/contracts-deduced1.C: New test.
* g++.dg/contracts/contracts-deduced2.C: New test.
* g++.dg/contracts/contracts-friend1.C: New test.
* g++.dg/contracts/contracts-ft1.C: New test.
* g++.dg/contracts/contracts-ignore1.C: New test.
* g++.dg/contracts/contracts-ignore2.C: New test.
* g++.dg/contracts/contracts-large-return.C: New test.
* g++.dg/contracts/contracts-multiline1.C: New test.
* g++.dg/contracts/contracts-multiple-inheritance1.C: New test.
* g++.dg/contracts/contracts-multiple-inheritance2.C: New test.
* g++.dg/contracts/contracts-nested-class1.C: New test.
* g++.dg/contracts/contracts-nested-class2.C: New test.
* g++.dg/contracts/contracts-nocopy1.C: New test.
* g++.dg/contracts/contracts-override.C: New test.
* g++.dg/contracts/contracts-post1.C: New test.
* g++.dg/contracts/contracts-post2.C: New test.
* g++.dg/contracts/contracts-post3.C: New test.
* g++.dg/contracts/contracts-post4.C: New test.
* g++.dg/contracts/contracts-post5.C: New test.
* g++.dg/contracts/contracts-post6.C: New test.
* g++.dg/contracts/contracts-pre1.C: New test.
* g++.dg/contracts/contracts-pre10.C: New test.
* g++.dg/contracts/contracts-pre2.C: New test.
* g++.dg/contracts/contracts-pre2a1.C: New test.
* g++.dg/contracts/contracts-pre2a2.C: New test.
* g++.dg/contracts/contracts-pre3.C: New test.
* g++.dg/contracts/contracts-pre4.C: New test.
* g++.dg/contracts/contracts-pre5.C: New test.
* g++.dg/contracts/contracts-pre6.C: New test.
* g++.dg/contracts/contracts-pre7.C: New test.
* g++.dg/contracts/contracts-pre9.C: New test.
* g++.dg/contracts/contracts-redecl1.C: New test.
* g++.dg/contracts/contracts-redecl2.C: New test.
* g++.dg/contracts/contracts-redecl3.C: New test.
* g++.dg/contracts/contracts-redecl4.C: New test.
* g++.dg/contracts/contracts-redecl5.C: New test.
* g++.dg/contracts/contracts-redecl6.C: New test.
* g++.dg/contracts/contracts-redecl7.C: New test.
* g++.dg/contracts/contracts-redecl8.C: New test.
* g++.dg/contracts/contracts-tmpl-attr1.C: New test.
* g++.dg/contracts/contracts-tmpl-spec1.C: New test.
* g++.dg/contracts/contracts-tmpl-spec2.C: New test.
* g++.dg/contracts/contracts-tmpl-spec3.C: New test.
* g++.dg/contracts/contracts1.C: New test.
* g++.dg/contracts/contracts10.C: New test.
* g++.dg/contracts/contracts11.C: New test.
* g++.dg/contracts/contracts12.C: New test.
* g++.dg/contracts/contracts13.C: New test.
* g++.dg/contracts/contracts14.C: New test.
* g++.dg/contracts/contracts15.C: New test.
* g++.dg/contracts/contracts16.C: New test.
* g++.dg/contracts/contracts17.C: New test.
* g++.dg/contracts/contracts18.C: New test.
* g++.dg/contracts/contracts19.C: New test.
* g++.dg/contracts/contracts2.C: New test.
* g++.dg/contracts/contracts20.C: New test.
* g++.dg/contracts/contracts22.C: New test.
* g++.dg/contracts/contracts24.C: New test.
* g++.dg/contracts/contracts25.C: New test.
* g++.dg/contracts/contracts3.C: New test.
* g++.dg/contracts/contracts35.C: New test.
* g++.dg/contracts/contracts4.C: New test.
* g++.dg/contracts/contracts5.C: New test.
* g++.dg/contracts/contracts6.C: New test.
* g++.dg/contracts/contracts7.C: New test.
* g++.dg/contracts/contracts8.C: New test.
* g++.dg/contracts/contracts9.C: New test.
* g++.dg/modules/contracts-1_a.C: New test.
* g++.dg/modules/contracts-1_b.C: New test.
* g++.dg/modules/contracts-2_a.C: New test.
* g++.dg/modules/contracts-2_b.C: New test.
* g++.dg/modules/contracts-2_c.C: New test.
* g++.dg/modules/contracts-3_a.C: New test.
* g++.dg/modules/contracts-3_b.C: New test.
* g++.dg/modules/contracts-4_a.C: New test.
* g++.dg/modules/contracts-4_b.C: New test.
* g++.dg/modules/contracts-4_c.C: New test.
* g++.dg/modules/contracts-4_d.C: New test.
* g++.dg/modules/contracts-tpl-friend-1_a.C: New test.
* g++.dg/modules/contracts-tpl-friend-1_b.C: New test.
* g++.dg/contracts/backtrace_handler/Makefile: New test.
* g++.dg/contracts/backtrace_handler/README: New test.
* g++.dg/contracts/backtrace_handler/example_out.txt: New test.
* g++.dg/contracts/backtrace_handler/example_pretty.txt: New test.
* g++.dg/contracts/backtrace_handler/prettytrace.sh: New test.
* g++.dg/contracts/except_preload_handler/Makefile: New test.
* g++.dg/contracts/except_preload_handler/README: New test.
* g++.dg/contracts/except_preload_handler/assert_fail.cpp: New test.
* g++.dg/contracts/except_preload_handler/handle_contract_violation.cpp: New test.
* g++.dg/contracts/noexcept_preload_handler/Makefile: New test.
* g++.dg/contracts/noexcept_preload_handler/README: New test.
* g++.dg/contracts/noexcept_preload_handler/assert_fail.cpp: New test.
* g++.dg/contracts/noexcept_preload_handler/handle_contract_violation.cpp: New test.
* g++.dg/contracts/preload_handler/Makefile: New test.
* g++.dg/contracts/preload_handler/README: New test.
* g++.dg/contracts/preload_handler/assert_fail.cpp: New test.
* g++.dg/contracts/preload_handler/handle_contract_violation.cpp: New test.
* g++.dg/contracts/preload_nocontinue_handler/Makefile: New test.
* g++.dg/contracts/preload_nocontinue_handler/README: New test.
* g++.dg/contracts/preload_nocontinue_handler/assert_fail.cpp: New test.
* g++.dg/contracts/preload_nocontinue_handler/handle_contract_violation.cpp: New test.
* g++.dg/contracts/preload_nocontinue_handler/nocontinue.cpp: New test.

20 months agolibstdc++: add experimental Contracts support
Jeff Chapman II [Thu, 3 Nov 2022 19:47:19 +0000 (15:47 -0400)]
libstdc++: add experimental Contracts support

This patch adds the library support for the experimental C++ Contracts
implementation.  This now consists only of a default definition of the
violation handler, which users can override through defining their own
version.  To avoid ABI stability problems with libstdc++.so this is added to
a separate -lstdc++exp static library, which the driver knows to add when it
sees -fcontracts.

Co-authored-by: Andrew Marmaduke <amarmaduke@lock3software.com>
Co-authored-by: Jason Merrill <jason@redhat.com>
libstdc++-v3/ChangeLog:

* acinclude.m4 (glibcxx_SUBDIRS): Add src/experimental.
* include/Makefile.am (experimental_headers): Add contract.
* include/Makefile.in: Regenerate.
* src/Makefile.am (SUBDIRS): Add experimental.
* src/Makefile.in: Regenerate.
* configure: Regenerate.
* src/experimental/contract.cc: New file.
* src/experimental/Makefile.am: New file.
* src/experimental/Makefile.in: New file.
* include/experimental/contract: New file.

20 months agoanalyzer: fix feasibility false +ve on jumps through function ptrs [PR107582]
David Malcolm [Sat, 19 Nov 2022 00:38:25 +0000 (19:38 -0500)]
analyzer: fix feasibility false +ve on jumps through function ptrs [PR107582]

PR analyzer/107582 reports a false +ve from
-Wanalyzer-use-of-uninitialized-value where
the analyzer's feasibility checker erroneously decides
that point (B) in the code below is reachable, with "x" being
uninitialized there:

    pthread_cleanup_push(func, NULL);

    while (ret != ETIMEDOUT)
ret = rand() % 1000;

    /* (A): after the while loop  */

    if (ret != ETIMEDOUT)
      x = &z;

    pthread_cleanup_pop(1);

    if (ret == ETIMEDOUT)
      return 0;

    /* (B): after not bailing out  */

due to these contradictionary conditions somehow both holding:
  * (ret == ETIMEDOUT), at (A) (skipping the initialization of x), and
  * (ret != ETIMEDOUT), at (B)

The root cause is that after the while loop, state merger puts ret in
the exploded graph in an UNKNOWN state, and saves the diagnostic at (B).

Later, as we explore the feasibilty of reaching the enode for (B),
dynamic_call_info_t::update_model is called to push/pop the
frames for handling the call to "func" in pthread_cleanup_pop.
The "ret" at these nodes in the feasible_graph has a conjured_svalue for
"ret", and a constraint on it being either == *or* != ETIMEDOUT.

However dynamic_call_info_t::update_model blithely clobbers the
model with a copy from the exploded_graph, in which "ret" is UNKNOWN.

This patch fixes dynamic_call_info_t::update_model so that it
simulates pushing/popping a frame on the model we're working with,
preserving knowledge of the constraint on "ret", and enabling the
analyzer to "know" that the bail-out must happen.

Doing so fixes the false positive.

gcc/analyzer/ChangeLog:
PR analyzer/107582
* engine.cc (dynamic_call_info_t::update_model): Update the model
by pushing or pop a frame, rather than by clobbering it with the
model from the exploded_node's state.

gcc/testsuite/ChangeLog:
PR analyzer/107582
* gcc.dg/analyzer/feasibility-4.c: New test.
* gcc.dg/analyzer/feasibility-pr107582-1.c: New test.
* gcc.dg/analyzer/feasibility-pr107582-2.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
20 months agoanalyzer: move more impl_* to known_function
David Malcolm [Fri, 18 Nov 2022 21:59:12 +0000 (16:59 -0500)]
analyzer: move more impl_* to known_function

Fix a missing check that the argument to __analyzer_dump_capacity must
be a pointer type (which would otherwise lead to an ICE).

Do so by using the known_function_manager rather than by doing lots of
string matching.  Do the same for many other functions.

Doing so moves the type-checking closer to the logic that makes use
of it, by putting them in the same class, rather than splitting them
up between two source files (and sometimes three, e.g. for "pipe").
I hope this reduces the number of missing checks.

gcc/analyzer/ChangeLog:
* analyzer.cc (is_pipe_call_p): Delete.
* analyzer.h (is_pipe_call_p): Delete.
* region-model-impl-calls.cc (call_details::get_location): New.
(class kf_analyzer_break): New, adapted from
region_model::on_stmt_pre.
(region_model::impl_call_analyzer_describe): Convert to...
(class kf_analyzer_describe): ...this.
(region_model::impl_call_analyzer_dump_capacity): Convert to...
(class kf_analyzer_dump_capacity): ...this.
(region_model::impl_call_analyzer_dump_escaped): Convert to...
(class kf_analyzer_dump_escaped): ...this.
(class kf_analyzer_dump_exploded_nodes): New.
(region_model::impl_call_analyzer_dump_named_constant): Convert
to...
(class kf_analyzer_dump_named_constant): ...this.
(class dump_path_diagnostic): Move here from region-model.cc.
(class kf_analyzer_dump_path) New, adapted from
region_model::on_stmt_pre.
(class kf_analyzer_dump_region_model): Likewise.
(region_model::impl_call_analyzer_eval): Convert to...
(class kf_analyzer_eval): ...this.
(region_model::impl_call_analyzer_get_unknown_ptr): Convert to...
(class kf_analyzer_get_unknown_ptr): ...this.
(class known_function_accept): Rename to...
(class kf_accept): ...this.
(class known_function_bind): Rename to...
(class kf_bind): ...this.
(class known_function_connect): Rename to...
(class kf_connect): ...this.
(region_model::impl_call_errno_location): Convert to...
(class kf_errno_location): ...this.
(class known_function_listen): Rename to...
(class kf_listen): ...this.
(region_model::impl_call_pipe): Convert to...
(class kf_pipe): ...this.
(region_model::impl_call_putenv): Convert to...
(class kf_putenv): ...this.
(region_model::impl_call_operator_new): Convert to...
(class kf_operator_new): ...this.
(region_model::impl_call_operator_delete): Convert to...
(class kf_operator_delete): ...this.
(class known_function_socket): Rename to...
(class kf_socket): ...this.
(register_known_functions): Rename param to KFM.  Break out
existing known functions into a "POSIX" section, and add "pipe",
"pipe2", and "putenv".  Add debugging functions
"__analyzer_break", "__analyzer_describe",
"__analyzer_dump_capacity", "__analyzer_dump_escaped",
"__analyzer_dump_exploded_nodes",
"__analyzer_dump_named_constant", "__analyzer_dump_path",
"__analyzer_dump_region_model", "__analyzer_eval",
"__analyzer_get_unknown_ptr".  Add C++ support functions
"operator new", "operator new []", "operator delete", and
"operator delete []".
* region-model.cc (class dump_path_diagnostic): Move to
region-model-impl-calls.cc.
(region_model::on_stmt_pre): Eliminate special-casing of
"__analyzer_describe", "__analyzer_dump_capacity",
"__analyzer_dump_escaped", "__analyzer_dump_named_constant",
"__analyzer_dump_path", "__analyzer_dump_region_model",
"__analyzer_eval", "__analyzer_break",
"__analyzer_dump_exploded_nodes", "__analyzer_get_unknown_ptr",
"__errno_location", "pipe", "pipe2", "putenv", "operator new",
"operator new []", "operator delete", "operator delete []"
"pipe" and "pipe2", handling them instead via the known_functions
mechanism.
* region-model.h (call_details::get_location): New decl.
(region_model::impl_call_analyzer_describe): Delete decl.
(region_model::impl_call_analyzer_dump_capacity): Delete decl.
(region_model::impl_call_analyzer_dump_escaped): Delete decl.
(region_model::impl_call_analyzer_dump_named_constant): Delete decl.
(region_model::impl_call_analyzer_eval): Delete decl.
(region_model::impl_call_analyzer_get_unknown_ptr): Delete decl.
(region_model::impl_call_errno_location): Delete decl.
(region_model::impl_call_pipe): Delete decl.
(region_model::impl_call_putenv): Delete decl.
(region_model::impl_call_operator_new): Delete decl.
(region_model::impl_call_operator_delete): Delete decl.
* sm-fd.cc: Update comments.

gcc/testsuite/ChangeLog:
* gcc.dg/analyzer/analyzer-debugging-fns-1.c: New test.
* gcc.dg/analyzer/attr-const-3.c: Increase the
"analyzer-max-svalue-depth" from 0 to 4 to ensure that
"__analyzer_eval" is recognized.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
20 months agoRISC-V: No extensions for SImode min/max against safe constant
Philipp Tomsich [Sun, 16 Oct 2022 08:51:47 +0000 (10:51 +0200)]
RISC-V: No extensions for SImode min/max against safe constant

Optimize the common case of a SImode min/max against a constant
that is safe both for sign- and zero-extension.
E.g., consider the case
  int f(unsigned int* a)
  {
    const int C = 1000;
    return *a * 3 > C ? C : *a * 3;
  }
where the constant C will yield the same result in DImode whether
sign- or zero-extended.

This should eventually go away once the lowering to RTL smartens up
and considers the precision/signedness and the value-ranges of the
operands to MIN_EXPR and MAX_EXPR.

gcc/ChangeLog:

* config/riscv/bitmanip.md (*minmax): Additional pattern for
  min/max against constants that are extension-invariant.
* config/riscv/iterators.md (minmax_optab): Add an iterator
  that has only min and max rtl.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/zbb-min-max-02.c: New test.

20 months agoRISC-V: Handle "(a & twobits) == singlebit" in branches using Zbs
Philipp Tomsich [Sun, 16 Oct 2022 10:48:26 +0000 (12:48 +0200)]
RISC-V: Handle "(a & twobits) == singlebit" in branches using Zbs

Use Zbs when generating a sequence for
   "if ((a & twobits) == singlebit) ..."
that can be expressed as
   bexti + bexti + andn.

gcc/ChangeLog:

* config/riscv/bitmanip.md
(*branch<X:mode>_mask_twobits_equals_singlebit):
Handle "if ((a & T) == C)" using Zbs, when T has 2 bits set and C
has one of these tow bits set.
* config/riscv/predicates.md (const_twobits_not_arith_operand):
New predicate.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/zbs-if_then_else-01.c: New test.

20 months agoRISC-V: Use bseti/bclri/binvi to extend reach of ori/andi/xori
Philipp Tomsich [Tue, 11 Oct 2022 21:42:48 +0000 (23:42 +0200)]
RISC-V: Use bseti/bclri/binvi to extend reach of ori/andi/xori

Sequences of the form "a | C" and "a ^ C" with C being the positive
half of a signed immediate's range with one extra bit set in addition
are mapped to ori/xori and one bseti/binvi to avoid using a temporary
(and a multi-insn sequence to load C into that temporary).

Something similar holds for "a & ~C" being representable as either
bclri + bclri or bclri + andi.

gcc/ChangeLog:

* config/riscv/bitmanip.md (*<or_optab>i<mode>_extrabit):
New pattern for binvi+binvi/xori and bseti+bseti/ori
(*andi<mode>_extrabit): New pattern for bclri+bclri/andi
* config/riscv/iterators.md (any_or): Match or and ior
* config/riscv/predicates.md (const_twobits_operand):
New predicate.
(uimm_extra_bit_operand): New predicate.
(uimm_extra_bit_or_twobits): New predicate.
(not_uimm_extra_bit_operand): New predicate.
(not_uimm_extra_bit_or_nottwobits): New predicate.
* config/riscv/riscv.h (UIMM_EXTRA_BIT_OPERAND):
Helper for the uimm_extra_bit_operand and
not_uimm_extra_bit_operand predicates.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/zbs-bclri.c: Rename
* gcc.target/riscv/zbs-bclri-01.c: Renamed from above.
* gcc.target/riscv/zbs-bclri-02.c: New test.
* gcc.target/riscv/zbs-binvi.c: New test.
* gcc.target/riscv/zbs-bseti.c: New test.

20 months agoRISC-V: Optimize slli(.uw)? + addw + zext.w into sh[123]add + zext.w
Philipp Tomsich [Wed, 14 Sep 2022 12:16:27 +0000 (14:16 +0200)]
RISC-V: Optimize slli(.uw)? + addw + zext.w into sh[123]add + zext.w

gcc/ChangeLog:

* config/riscv/bitmanip.md: Handle corner-cases for combine
when chaining slli(.uw)? + addw
* config/riscv/riscv-protos.h (riscv_shamt_matches_mask_p):
Define prototype.
* config/riscv/riscv.cc (riscv_shamt_matches_mask_p):
Helper for evaluating the relationship between two operands.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/zba-shNadd-04.c: New test.

20 months agoRISC-V: split to allow formation of sh[123]add before 32bit divw
Philipp Tomsich [Tue, 8 Nov 2022 19:45:51 +0000 (20:45 +0100)]
RISC-V: split to allow formation of sh[123]add before 32bit divw

When using strength-reduction, we will reduce a multiplication to a
sequence of shifts and adds.  If this is performed with 32-bit types
and followed by a division, the lack of w-form sh[123]add will make
combination impossible and lead to a slli + addw being generated.

Split the sequence with the knowledge that a w-form div will perform
implicit sign-extensions.

gcc/ChangeLog:

* config/riscv/bitmanip.md: Add a define_split to optimize
  slliw + addiw + divw into sh[123]add + divw.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/zba-shNadd-05.c: New test.

20 months agoRISC-V: Optimize branches testing a bit-range or a shifted immediate
Philipp Tomsich [Tue, 11 Oct 2022 13:50:11 +0000 (15:50 +0200)]
RISC-V: Optimize branches testing a bit-range or a shifted immediate

gcc/ChangeLog:

* config/riscv/predicates.md (shifted_const_arith_operand): New predicate.
(uimm_extra_bit_operand): New predicate.
* config/riscv/riscv.md (*branch<ANYI:mode>_shiftedarith_equals_zero):
New pattern.
(*branch<ANYI:mode>_shiftedmask_equals_zero): New pattern.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/branch-1.c: New test.

20 months agoRISC-V: allow bseti on SImode without sign-extension
Philipp Tomsich [Mon, 10 Oct 2022 20:24:02 +0000 (22:24 +0200)]
RISC-V: allow bseti on SImode without sign-extension

As long as the SImode operand is not a partial subreg, we can use a
bseti without postprocessing to or in a bit, as the middle end is
smart enough to stay away from the signbit.

gcc/ChangeLog:

* config/riscv/bitmanip.md (*bsetidisi): New pattern.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/zbs-bseti-02.c: New test.

20 months agolibcpp: Avoid remapping filenames within directives
Richard Purdie [Fri, 18 Nov 2022 20:13:50 +0000 (13:13 -0700)]
libcpp: Avoid remapping filenames within directives

Code such as:

 #include __FILE__

can interact poorly with the *-prefix-map options when cross compiling. In
general you're after to remap filenames for use in target context but the
local paths should be used to find include files at compile time. Ingoring
filename remapping for directives allows avoiding such failures.

Fix this to improve such usage and then document this against file-prefix-map
(referenced by the other *-prefix-map options) to make the behaviour clear
and defined.

libcpp/ChangeLog:

* macro.cc (_cpp_builtin_macro_text): Don't remap filenames within
directives.

gcc/ChangeLog:

* doc/invoke.texi: Document prefix-maps don't affect directives.

20 months agoManually add entries for r13-4128.
Jakub Jelinek [Fri, 18 Nov 2022 18:21:17 +0000 (19:21 +0100)]
Manually add entries for r13-4128.

Aldo, replace some invalid tab + 2 spaces with just tab.

20 months agoFortran: reject NULL actual argument without explicit interface [PR107576]
Harald Anlauf [Thu, 17 Nov 2022 20:36:49 +0000 (21:36 +0100)]
Fortran: reject NULL actual argument without explicit interface [PR107576]

gcc/fortran/ChangeLog:

PR fortran/107576
* interface.cc (gfc_procedure_use): Reject NULL as actual argument
when there is no explicit procedure interface.

gcc/testsuite/ChangeLog:

PR fortran/107576
* gfortran.dg/null_actual_3.f90: New test.

20 months agoDaily bump.
GCC Administrator [Fri, 18 Nov 2022 18:09:19 +0000 (18:09 +0000)]
Daily bump.

20 months agoAdd another commit to ignore
Jakub Jelinek [Fri, 18 Nov 2022 18:05:06 +0000 (19:05 +0100)]
Add another commit to ignore

We can't handle r13-4128-g1957bedf29a1b2cc231972aba680fe80199d5498

* gcc-changelog/git_update_version.py: Add
1957bedf29a1b2cc231972aba680fe80199d5498 to ignored commits.

20 months agoFix PR middle-end/107705: ICE after reclaration error
Andrew Pinski [Thu, 17 Nov 2022 22:03:08 +0000 (22:03 +0000)]
Fix PR middle-end/107705: ICE after reclaration error

The problem here is after we created a call expression
in the C front-end, we replace the decl type with
an error mark node. We then end up calling
aggregate_value_p with the call expression
with the decl with the error mark as the type
and we ICE.

The fix is to check the function type
after we process the call expression inside
aggregate_value_p to get it.

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

Thanks,
Andrew Pinski

gcc/ChangeLog:

PR middle-end/107705
* function.cc (aggregate_value_p): Return 0 if
the function type was an error operand.

gcc/testsuite/ChangeLog:

* gcc.dg/redecl-22.c: New test.

20 months agoFix PRs 106764, 106765, and 107307, all ICE after invalid re-declaration
Andrew Pinski [Thu, 17 Nov 2022 22:08:07 +0000 (22:08 +0000)]
Fix PRs 106764, 106765, and 107307, all ICE after invalid re-declaration

The problem here is the gimplifier returns GS_ERROR but
in some cases we don't check that soon enough and try
to do other work which could crash.
So the fix in these two cases is to return GS_ERROR
early if the gimplify_* functions had return GS_ERROR.

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

Thanks,
Andrew Pinski

gcc/ChangeLog:

PR c/106764
PR c/106765
PR c/107307
* gimplify.cc (gimplify_compound_lval): Return GS_ERROR
if gimplify_expr had return GS_ERROR.
(gimplify_call_expr): Likewise.

gcc/testsuite/ChangeLog:

PR c/106764
PR c/106765
PR c/107307
* gcc.dg/redecl-19.c: New test.
* gcc.dg/redecl-20.c: New test.
* gcc.dg/redecl-21.c: New test.

20 months agoFix testcase for architectures that use .srodata
Yixuan Chen [Fri, 18 Nov 2022 15:47:11 +0000 (08:47 -0700)]
Fix testcase for architectures that use .srodata

gcc/testsuite:

* gcc.dg/pr25521.c: Fix testcase for architectures that use .srodata.

20 months agoaarch64: Fix LDAPURS assembly output
Kyrylo Tkachov [Fri, 18 Nov 2022 14:29:36 +0000 (14:29 +0000)]
aarch64: Fix LDAPURS assembly output

... And another follow-up once I realised that the sign-extending load, of course,
needs to have strictly an X-reg as a destination for DImode extensions and a W-reg
for SImode ones.

Tested on aarch64-none-linux.

gcc/ChangeLog:

* config/aarch64/atomics.md (*aarch64_atomic_load<ALLX:mode>_rcpc_sext):
Use <GPI:w>  for destination format.
* config/aarch64/iterators.md (w_sz): Delete.

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/ldapr-sext.c: Adjust expected output.

20 months agotestsuite: Verify that module-mapper is available
Torbjörn SVENSSON [Thu, 22 Sep 2022 20:14:24 +0000 (22:14 +0200)]
testsuite: Verify that module-mapper is available

For some test cases, it's required that the optional module mapper
"g++-mapper-server" is built. As the server is not required, the
test cases will fail if it can't be found.

gcc/testsuite/ChangeLog:

* lib/target-supports.exp (check_is_prog_name_available):
New.
* lib/target-supports-dg.exp
(dg-require-prog-name-available): New.
* g++.dg/modules/modules.exp: Verify avilability of module
mapper.

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
20 months agoaarch64: Fix up LDAPR codegen
Kyrylo Tkachov [Fri, 18 Nov 2022 09:06:38 +0000 (09:06 +0000)]
aarch64: Fix up LDAPR codegen

Upon some further inspection I realised I had misunderstood some intricacies of the extending loads of the RCPC feature.
This patch fixes up the recent GCC support accordingly. In particular:
* The sign-extending forms are a form of LDAPURS* and are actually part of FEAT_RCPC2
that is enabled with Armv8.4-a rather than the base Armv8.3-a FEAT_RCPC.
The patch introduces a TARGET_RCPC2 macro and gates this combine pattern accordingly.
* The assembly output for the zero-extending LDAPR instruction should always use %w formatting for its destination register.

The testcase is split into zero-extending and sign-extending parts since they require different architecture pragmas.
It's also straightforward to add the rest of the FEAT_RCPC2 codegen
(with immediate offset addressing modes) but that can be done as a separate patch.
Apologies for not catching this sooner, but it hasn't been in trunk long, so no harm done.

Bootstrapped and tested on aarch64-none-linux-gnu.

gcc/ChangeLog:

* config/aarch64/aarch64.h (TARGET_RCPC2): Define.
* config/aarch64/atomics.md (*aarch64_atomic_load<ALLX:mode>_rcpc_zext):
Adjust output template.
(*aarch64_atomic_load<ALLX:mode>_rcpc_sex): Guard on TARGET_RCPC2.
Adjust output template.
* config/aarch64/iterators.md (w_sz): New mode attr.

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/ldapr-ext.c: Rename to...
* gcc.target/aarch64/ldapr-zext.c: ... This.  Fix expected assembly.
* gcc.target/aarch64/ldapr-sext.c: New test.

20 months agoc++: Implement CWG2635 - Constrained structured bindings
Jakub Jelinek [Fri, 18 Nov 2022 08:04:16 +0000 (09:04 +0100)]
c++: Implement CWG2635 - Constrained structured bindings

The following patch implements CWG2635.

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

* decl.cc (grokdeclarator): Implement
CWG2635 - Constrained structured bindings.  Emit a pedwarn on
constrained auto type.  Add auto_diagnostic_group for error_at
and inform for non-auto type on structured bindings declaration.

* g++.dg/cpp2a/decomp5.C: New test.
* g++.dg/cpp2a/decomp6.C: New test.
* g++.dg/cpp2a/decomp7.C: New test.
* g++.dg/cpp2a/concepts-placeholder7.C: Adjust expected diagnostics.
* g++.dg/cpp2a/concepts-placeholder8.C: Likewise.
* g++.dg/cpp2a/concepts-placeholder9.C: New test.
* g++.dg/cpp2a/concepts-placeholder10.C: New test.

20 months agotree-optimization/107647 - avoid FMA from SLP with -ffp-contract=off
Richard Biener [Thu, 17 Nov 2022 08:43:31 +0000 (09:43 +0100)]
tree-optimization/107647 - avoid FMA from SLP with -ffp-contract=off

Only with -ffp-contract=fast we can synthesize FMA operations like
vfmaddsub231ps, so properly guard the transform in SLP pattern
detection.

PR tree-optimization/107647
* tree-vect-slp-patterns.cc (addsub_pattern::recognize): Only
allow FMA generation with -ffp-contract=fast for FP types.
(complex_mul_pattern::matches): Likewise.

* gcc.target/i386/pr107647.c: New testcase.

20 months agoLoongArch: Fix atomic_exchange expanding [PR107713]
Jinyang He [Thu, 17 Nov 2022 06:38:52 +0000 (14:38 +0800)]
LoongArch: Fix atomic_exchange expanding [PR107713]

We used to expand atomic_exchange_n(ptr, new, mem_order) for subword types
into something like:

    {
      __typeof__(*ptr) t = atomic_load_n(ptr, mem_order);
      atomic_compare_exchange_n(ptr, &t, new, true, mem_order, mem_order);
      return t;
    }

It's incorrect because another thread may store a different value into *ptr
after atomic_load_n.  Then atomic_compare_exchange_n will not store into
*ptr, but atomic_exchange_n should always perform the store.

gcc/ChangeLog:

PR target/107713
* config/loongarch/sync.md
(atomic_cas_value_exchange_7_<mode>): New define_insn.
(atomic_exchange): Use atomic_cas_value_exchange_7_si instead of
atomic_cas_value_cmp_and_7_si.

gcc/testsuite/ChangeLog:

PR target/107713
* gcc.target/loongarch/pr107713-1.c: New test.
* gcc.target/loongarch/pr107713-2.c: New test.

20 months agoc++: constinit on pointer to function [PR104066]
Marek Polacek [Thu, 17 Nov 2022 16:59:29 +0000 (11:59 -0500)]
c++: constinit on pointer to function [PR104066]

[dcl.constinit]: "The constinit specifier shall be applied only to
a declaration of a variable with static or thread storage duration."

Thus, this ought to be OK:

  constinit void (*p)() = nullptr;

but the error message I introduced when implementing constinit was
not looking at funcdecl_p, so the code above was rejected.

Fixed thus.  I'm checking constinit_p first because I think that's
far more likely to be false than funcdecl_p.

PR c++/104066

gcc/cp/ChangeLog:

* decl.cc (grokdeclarator): Check funcdecl_p before complaining
about constinit.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/constinit18.C: New test.

20 months agoc: Set the locus of the function result decl
Bernhard Reutner-Fischer [Sat, 6 Nov 2021 05:48:00 +0000 (06:48 +0100)]
c: Set the locus of the function result decl

gcc/c/ChangeLog:

* c-decl.cc (start_function): Set the result decl source
location to the location of the typespec.

20 months agoFortran: Remove double spaces in open() warning [PR99884]
Bernhard Reutner-Fischer [Sun, 31 Oct 2021 12:57:46 +0000 (13:57 +0100)]
Fortran: Remove double spaces in open() warning [PR99884]

gcc/fortran/ChangeLog:

PR fortran/99884
* io.cc (check_open_constraints): Remove double spaces.

20 months agoFix PR 107734: valgrind errors with sbitmap in match.pd
Andrew Pinski [Thu, 17 Nov 2022 17:48:00 +0000 (17:48 +0000)]
Fix PR 107734: valgrind errors with sbitmap in match.pd

sbitmap is a simple bitmap and the memory allocated is not cleared
on creation; you have to clear it or set it to all ones before using
it.  This is unlike bitmap which is a sparse bitmap and the entries are
cleared as created.
The code added in r13-4044-gdc95e1e9702f2f missed that.
This patch fixes that mistake.

Committed as obvious after a bootstrap and test on x86_64-linux-gnu.

gcc/ChangeLog:

PR middle-end/107734
* match.pd (perm + vector op pattern): Clear the sbitmap before
use.

20 months ago[PR tree-optimization/107732] [range-ops] Handle attempt to abs() negatives.
Aldy Hernandez [Thu, 17 Nov 2022 15:47:17 +0000 (16:47 +0100)]
[PR tree-optimization/107732] [range-ops] Handle attempt to abs() negatives.

The threader is creating a scenario where we are trying to solve:

[NEGATIVES] = abs(x)

While solving this we have an intermediate value of UNDEFINED because
we have no positive numbers.  But then we try to union the negative
pair to the final result by querying the bounds.  Since neither
UNDEFINED nor NAN have bounds, they need to be specially handled.

PR tree-optimization/107732

gcc/ChangeLog:

* range-op-float.cc (foperator_abs::op1_range): Early exit when
result is undefined.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/pr107732.c: New test.

20 months agoc, analyzer: fix ICE with -fanalyzer and -Wunused-macros [PR107711]
David Malcolm [Thu, 17 Nov 2022 17:34:56 +0000 (12:34 -0500)]
c, analyzer: fix ICE with -fanalyzer and -Wunused-macros [PR107711]

PR analyzer/107711 reports an ICE since r13-4073-gd8aba860b34203 with
the combination of -fanalyzer and -Wunused-macros.

The issue is that in c_translation_unit::consider_macro's call to
cpp_create_reader I was passing "ident_hash" for use by the the new
reader, but that takes ownership of that hash_table, so that ident_hash
erroneously gets freed when c_translation_unit::consider_macro calls
cpp_destroy, leading to a use-after-free in -Wunused-macros, where:

(gdb) p pfile->hash_table->pfile == pfile
$23 = false

and it's instead pointing at the freed reader from consider_macro,
leading to a use-after-free ICE.

Fixed thusly.

gcc/c/ChangeLog:
PR analyzer/107711
* c-parser.cc (ana::c_translation_unit::consider_macro): Pass NULL
to cpp_create_reader, rather than ident_hash, so that the new
reader gets its own hash table.

gcc/testsuite/ChangeLog:
PR analyzer/107711
* gcc.dg/analyzer/named-constants-Wunused-macros.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
20 months agoRISC-V: Optimize masking with two clear bits not a SMALL_OPERAND
Philipp Tomsich [Thu, 13 Oct 2022 08:55:41 +0000 (10:55 +0200)]
RISC-V: Optimize masking with two clear bits not a SMALL_OPERAND

Add a split for cases where we can use two bclri (or one bclri and an
andi) to clear two bits.

gcc/ChangeLog:

* config/riscv/bitmanip.md (*bclri<mode>_nottwobits): New pattern.
(*bclridisi_nottwobits): New pattern, handling the sign-bit.
* config/riscv/predicates.md (const_nottwobits_operand):
New predicate.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/zbs-bclri.c: New test.

20 months agoRISC-V: bitmanip: add splitter to use bexti for "(a & (1 << BIT_NO)) ? 0 : -1"
Philipp Tomsich [Tue, 9 Nov 2021 17:54:54 +0000 (18:54 +0100)]
RISC-V: bitmanip: add splitter to use bexti for "(a & (1 << BIT_NO)) ? 0 : -1"

Consider creating a polarity-reversed mask from a set-bit (i.e., if
the bit is set, produce all-ones; otherwise: all-zeros).  Using Zbb,
this can be expressed as bexti, followed by an addi of minus-one.  To
enable the combiner to discover this opportunity, we need to split the
canonical expression for "(a & (1 << BIT_NO)) ? 0 : -1" into a form
combinable into bexti.

Consider the function:
    long f(long a)
    {
      return (a & (1 << BIT_NO)) ? 0 : -1;
    }
This produces the following sequence prior to this change:
andi a0,a0,16
seqz a0,a0
neg a0,a0
ret
Following this change, it results in:
bexti a0,a0,4
addi a0,a0,-1
ret

gcc/ChangeLog:

* config/riscv/bitmanip.md: Add a splitter to generate
  polarity-reversed masks from a set bit using bexti + addi.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/zbs-bexti.c: New test.

20 months agoEnable shrink wrapping for the RISC-V target.
mtsamis [Wed, 24 Aug 2022 13:22:58 +0000 (15:22 +0200)]
Enable shrink wrapping for the RISC-V target.

This commit implements the target macros (TARGET_SHRINK_WRAP_*) that
enable separate shrink wrapping for function prologues/epilogues in
RISC-V.

Tested against SPEC CPU 2017, this change always has a net-positive
effect on the dynamic instruction count.  See the following table for
the breakdown on how this reduces the number of dynamic instructions
per workload on a like-for-like (i.e., same config file; suppressing
shrink-wrapping with -fno-shrink-wrap):

                             # dynamic instructions
                w/o shrink-wrap   w/ shrink-wrap      reduction
500.perlbench_r   1265716786593    1262156218578     3560568015   0.28%
500.perlbench_r    779224795689     765337009025    13887786664   1.78%
500.perlbench_r    724087331471     711307152522    12780178949   1.77%
502.gcc_r          204259864844     194517006339     9742858505   4.77%
502.gcc_r          244047794302     231555834722    12491959580   5.12%
502.gcc_r          230896069400     221877703011     9018366389   3.91%
502.gcc_r          192130616624     183856450605     8274166019   4.31%
502.gcc_r          258875074079     247756203226    11118870853   4.30%
505.mcf_r          662653430325     660678680547     1974749778   0.30%
520.omnetpp_r      985114167068     934191310154    50922856914   5.17%
523.xalancbmk_r    927037633578     921688937650     5348695928   0.58%
525.x264_r         490953958454     490565583447      388375007   0.08%
525.x264_r        1994662294421    1993171932425     1490361996   0.07%
525.x264_r        1897617120450    1896062750609     1554369841   0.08%
531.deepsjeng_r   1695189878907    1669304130411    25885748496   1.53%
541.leela_r       1925941222222    1897900861198    28040361024   1.46%
548.exchange2_r   2073816227944    2073816226729           1215   0.00%
557.xz_r           379572090003     379057409041      514680962   0.14%
557.xz_r           953117469352     952680431430      437037922   0.05%
557.xz_r           536859579650     536456690164      402889486   0.08%
                 18421773405376   18223938521833   197834883543   1.07%  totals

Signed-off-by: Manolis Tsamis <manolis.tsamis@vrull.eu>
gcc/ChangeLog:

* config/riscv/riscv.cc (struct machine_function): Add array to store
register wrapping information.
(riscv_for_each_saved_reg): Skip registers that are wrapped separetely.
(riscv_get_separate_components): New function.
(riscv_components_for_bb): Likewise.
(riscv_disqualify_components): Likewise.
(riscv_process_components): Likewise.
(riscv_emit_prologue_components): Likewise.
(riscv_emit_epilogue_components): Likewise.
(riscv_set_handled_components): Likewise.
(TARGET_SHRINK_WRAP_GET_SEPARATE_COMPONENTS): Define.
(TARGET_SHRINK_WRAP_COMPONENTS_FOR_BB): Likewise.
(TARGET_SHRINK_WRAP_DISQUALIFY_COMPONENTS): Likewise.
(TARGET_SHRINK_WRAP_EMIT_PROLOGUE_COMPONENTS): Likewise.
(TARGET_SHRINK_WRAP_EMIT_EPILOGUE_COMPONENTS): Likewise.
(TARGET_SHRINK_WRAP_SET_HANDLED_COMPONENTS): Likewise.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/shrink-wrap-1.c: New test.

20 months agoaarch64: Add mode size check on LDAPR-extend patterns
Kyrylo Tkachov [Thu, 17 Nov 2022 11:16:54 +0000 (11:16 +0000)]
aarch64: Add mode size check on LDAPR-extend patterns

Add an extra safety check as suggested by Richard.
Tested on aarch64-none-linux-gnu.

gcc/ChangeLog:

* config/aarch64/atomics.md (*aarch64_atomic_load<ALLX:mode>_rcpc_zext):
Add mode size check to condition.
(*aarch64_atomic_load<ALLX:mode>_rcpc_sext): Likewise.

20 months ago[PR68097] Try to avoid recursing for floats in gimple_stmt_nonnegative_warnv_p.
Aldy Hernandez [Sat, 12 Nov 2022 10:58:07 +0000 (11:58 +0100)]
[PR68097] Try to avoid recursing for floats in gimple_stmt_nonnegative_warnv_p.

It irks me that a PR named "we should track ranges for floating-point
hasn't been closed in this release.  This is an attempt to do just
that.

As mentioned in the PR, even though we track ranges for floats, it has
been suggested that avoiding recursing through SSA defs in
gimple_assign_nonnegative_warnv_p is also a goal.  This patch uses a
global range query (no on-demand lookups, just global ranges and
minimal folding) to determine if the range of a statement is known to
be non-negative.

PR tree-optimization/68097

gcc/ChangeLog:

* gimple-fold.cc (gimple_stmt_nonnegative_warnv_p): Call
range_of_stmt for floats.

20 months agox86: Enable 256 move by pieces for ALDERLAKE machine.
Lili Cui [Thu, 17 Nov 2022 07:50:46 +0000 (15:50 +0800)]
x86: Enable 256 move by pieces for ALDERLAKE machine.

gcc/ChangeLog:

* config/i386/x86-tune.def
(X86_TUNE_AVX256_MOVE_BY_PIECES): Add alderlake.
(X86_TUNE_AVX256_STORE_BY_PIECES): Ditto.

gcc/testsuite/ChangeLog:

* gcc.target/i386/pieces-memset-50.c: New test.

20 months agomiddle-end: ensure that VEC_PERM operands get lowered to the same SSA_NAME. [PR107717]
Tamar Christina [Thu, 17 Nov 2022 08:20:59 +0000 (08:20 +0000)]
middle-end: ensure that VEC_PERM operands get lowered to the same SSA_NAME. [PR107717]

At the moment when the VEC_PERMs generated by this match.pd rule is generated
it creates two different SSA_NAMEs for the folded operand.  Because of this it
the permute switches from a single operand permute to a two operand permute and
the target may no longer support a permute for this.

This fixes it by ensuring we generate the same SSA_NAME for both operands.

gcc/ChangeLog:

PR tree-optimization/107717
* match.pd: Ensure same SSA_NAME.

gcc/testsuite/ChangeLog:

PR tree-optimization/107717
* gcc.target/aarch64/sve2/pr107717.c: New test.

20 months agomiddle-end: replace GET_MODE_WIDER_MODE with GET_MODE_NEXT_MODE
Tamar Christina [Thu, 17 Nov 2022 08:14:44 +0000 (08:14 +0000)]
middle-end: replace GET_MODE_WIDER_MODE with GET_MODE_NEXT_MODE

After the fix to the addsub patch yesterday for bootstrap I had only regtested on x86.
While looking today it seemed the new tests were failing, this was caused
by a change in the behavior of the GET_MODE_WIDER_MODE macro on trunk.

gcc/ChangeLog:

* match.pd: Replace GET_MODE_WIDER_MODE with
custom code.

20 months ago[range-ops] Minor readability fix.
Aldy Hernandez [Mon, 14 Nov 2022 09:29:13 +0000 (10:29 +0100)]
[range-ops] Minor readability fix.

gcc/ChangeLog:

* range-op-float.cc (range_operator_float::fold_range): Make check
for maybe_isnan more readable.

20 months agoFix typo in gimple_fold_partial_load_store_mem_ref
Kewen Lin [Thu, 17 Nov 2022 05:08:23 +0000 (23:08 -0600)]
Fix typo in gimple_fold_partial_load_store_mem_ref

As Robin spotted, my recent commit r13-3716 caused an ICE
on s390 if vector access with length is enabled there (his
patch for the enablement hasn't been committed yet).  The
failure is caused by one stupid typo, the bias on s390 is
-1, so the assertion should use tree_fits_shwi_p rather
than tree_fits_uhwi_p.  Thanks for Robin's catching.

I just reproduced the ICE and verified the fix worked fine
with a cross build, the optimized dump against the test case
gcc.target/powerpc/pr107412.c looked expected.

gcc/ChangeLog:

* gimple-fold.cc (gimple_fold_partial_load_store_mem_ref): Use
tree_fits_shwi_p rather than tree_fits_uhwi_p as bias is signed.

20 months agoRISC-V: Optimize RVV epilogue logic.
Jia-Wei Chen [Thu, 17 Nov 2022 03:58:54 +0000 (22:58 -0500)]
RISC-V: Optimize RVV epilogue logic.

Sometimes "step1 -= scalable_frame" will cause adjust equal to
zero. And it will generate additional redundant instruction
"addi sp,sp,0". Add checking segement to skip that case.

This testcase mix exist spill-1.c and adding new fun to check if
there have redundant addi intructions. Idea provided by Jeff Law.

gcc/ChangeLog:

* config/riscv/riscv.cc (riscv_expand_epilogue):
Do not emit useless add sp, sp, 0 instrutions.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/base/spill-sp-adjust.c: New test.

20 months agoFix multiple recent sh3/sh3eb regressions
Jeff Law [Thu, 17 Nov 2022 01:47:59 +0000 (18:47 -0700)]
Fix multiple recent sh3/sh3eb regressions

So my tester started showing even more regressions on the sh3/sh4 runs
recently (beyond the one recently reported in BZ triggered by some DCE
related changes).  Bisection kept showing inconsistent results.  I was
starting to think memory management error, but valgrind didn't flag anything.

After a bit of head-banging I was able to track it down to predicate
tests called from the SH specific combiner passes.  And once I started
getting inside the actual code for the predicate function it became
pretty obvious.  The predicate routines are supposed to return a bool,
fine and they dutifully set the low bit in %eax properly.

The *caller* was looking at the full register.  Uh-oh.  Naturally we
became dependent on what happened to be in the upper 31 bits of a register.
That's why the bug would come and go so willy-nilly.  This was ultimately
chased down to an incorrect prototype in sh_treg_combine.cc for predicate
functions defined via define_predicate.

Removing the bogus prototypes and instead including the generated
tm-preds.h fixes this problem.  I also checked the other ports for
similar problems (specifically looking for a extern int.*_operand, then
for each of the hits looking to see if the predicate was defined via
define_predicate).  No other ports had similar braindamage.

This fixes the most recent regressions in my tester for sh3/sh3eb
and I strongly suspect sh4.  It does not fix 107704, but I think
Richi and I both agree that's a visitation order issue and we were
just getting lucky before.

gcc/

* config/sh/sh_treg_combine.cc: Include tm-preds.h.
(t_reg_operand): Remove bogus prototype.
(negt_reg_operand): Likewise.

20 months agolibstdc++: Ensure std::to_chars overloads all declared in <format> [PR107720]
Jonathan Wakely [Wed, 16 Nov 2022 20:47:39 +0000 (20:47 +0000)]
libstdc++: Ensure std::to_chars overloads all declared in <format> [PR107720]

For powerpc64le we need to be able to format both of __ieee128 and
__ibm128, so we need the std::to_chars overloads for both types to be
visible at once. The __ieee128 overloads are always visible in C++23
mode, because they're used to implement the _Float128 overloads. The
__ibm128 overloads are only visible when long double is __ibm128.

libstdc++-v3/ChangeLog:

PR libstdc++/107720
* include/std/format [_GLIBCXX_LONG_DOUBLE_ALT128_COMPAT]:
Declare overloads of std::to_chars for the alternative long
double type.

20 months agoDaily bump.
GCC Administrator [Thu, 17 Nov 2022 00:16:52 +0000 (00:16 +0000)]
Daily bump.

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

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

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

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

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

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

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

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

gcc/fortran/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

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

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

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

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

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

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

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

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

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

PR c++/106649

gcc/c-family/ChangeLog:

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

gcc/cp/ChangeLog:

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

gcc/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

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

This is only a partial fix for the PR.

libstdc++-v3/ChangeLog:

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

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

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

libstdc++-v3/ChangeLog:

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

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

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

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

libstdc++-v3/ChangeLog:

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

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

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

libstdc++-v3/ChangeLog:

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

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

gcc/fortran/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

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

gcc/fortran/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

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

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

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

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

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

gcc/testsuite/ChangeLog:

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

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

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

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

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

gcc/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

libstdc++-v3/ChangeLog:

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

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

libatomic/ChangeLog:

* Makefile.in: Re-generate.

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

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

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

PR libstdc++/107701

libstdc++-v3/ChangeLog:

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

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

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

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

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

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

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

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

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

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

The following patch fixes that.

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

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

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

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

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

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

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

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

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

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

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

gcc/ChangeLog:

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

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

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

Top znver table sizes in insn-automata.o:

Before:

30056 r znver1_fp_min_issue_delay
120224 r znver1_fp_transitions

After:

6720 r znver1_fp_min_issue_delay
53760 r znver1_fp_transitions

gcc/ChangeLog:

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

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

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

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

Top znver table sizes in insn-automata.o:

Before:

428108 r znver1_fp_min_issue_delay
856216 r znver1_fp_transitions

After:

30056 r znver1_fp_min_issue_delay
120224 r znver1_fp_transitions

gcc/ChangeLog:

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

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

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

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

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

libstdc++-v3/ChangeLog:

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

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

libstdc++-v3/ChangeLog:

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

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

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

gcc/ChangeLog:

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

libgomp/ChangeLog:

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

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

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

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

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

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

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

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

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

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

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

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

gcc/ChangeLog:

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

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

The following patch implements CWG 2654.

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

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

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

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

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

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

gcc/ChangeLog:

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

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

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

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

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

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

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

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

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

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

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

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

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

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

libstdc++-v3/ChangeLog:

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

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

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

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

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

CFG simplification result with PR90259's case as example:

*before*

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

*after*

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

PR rtl-optimization/90259

gcc/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

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

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

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

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

because there the qualifier matters.  Likewise in template
specialization:

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

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

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

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

PR c++/107492

gcc/cp/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

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

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

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

gcc/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

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

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

gcc/

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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