platform/upstream/gcc.git
3 years agoc++: Add __builtin_bit_cast to implement std::bit_cast [PR93121]
Jakub Jelinek [Thu, 3 Dec 2020 14:46:54 +0000 (15:46 +0100)]
c++: Add __builtin_bit_cast to implement std::bit_cast [PR93121]

The following patch adds __builtin_bit_cast builtin, similarly to
clang or MSVC which implement std::bit_cast using such an builtin too.
It checks the various std::bit_cast requirements, when not constexpr
evaluated acts pretty much like VIEW_CONVERT_EXPR of the source argument
to the destination type and the hardest part is obviously the constexpr
evaluation.
I've left out PDP11 handling of those, couldn't figure out how exactly are
bitfields laid out there

2020-12-03  Jakub Jelinek  <jakub@redhat.com>

PR libstdc++/93121
* fold-const.h (native_encode_initializer): Add mask argument
defaulted to nullptr.
(find_bitfield_repr_type): Declare.
(native_interpret_aggregate): Declare.
* fold-const.c (find_bitfield_repr_type): New function.
(native_encode_initializer): Add mask argument and support for
filling it.  Handle also some bitfields without integral
DECL_BIT_FIELD_REPRESENTATIVE.
(native_interpret_aggregate): New function.
* gimple-fold.h (clear_type_padding_in_mask): Declare.
* gimple-fold.c (struct clear_padding_struct): Add clear_in_mask
member.
(clear_padding_flush): Handle buf->clear_in_mask.
(clear_padding_union): Copy clear_in_mask.  Don't error if
buf->clear_in_mask is set.
(clear_padding_type): Don't error if buf->clear_in_mask is set.
(clear_type_padding_in_mask): New function.
(gimple_fold_builtin_clear_padding): Set buf.clear_in_mask to false.
* doc/extend.texi (__builtin_bit_cast): Document.

* c-common.h (enum rid): Add RID_BUILTIN_BIT_CAST.
* c-common.c (c_common_reswords): Add __builtin_bit_cast.

* cp-tree.h (cp_build_bit_cast): Declare.
* cp-tree.def (BIT_CAST_EXPR): New tree code.
* cp-objcp-common.c (names_builtin_p): Handle RID_BUILTIN_BIT_CAST.
(cp_common_init_ts): Handle BIT_CAST_EXPR.
* cxx-pretty-print.c (cxx_pretty_printer::postfix_expression):
Likewise.
* parser.c (cp_parser_postfix_expression): Handle
RID_BUILTIN_BIT_CAST.
* semantics.c (cp_build_bit_cast): New function.
* tree.c (cp_tree_equal): Handle BIT_CAST_EXPR.
(cp_walk_subtrees): Likewise.
* pt.c (tsubst_copy): Likewise.
* constexpr.c (check_bit_cast_type, cxx_eval_bit_cast): New functions.
(cxx_eval_constant_expression): Handle BIT_CAST_EXPR.
(potential_constant_expression_1): Likewise.
* cp-gimplify.c (cp_genericize_r): Likewise.

* g++.dg/cpp2a/bit-cast1.C: New test.
* g++.dg/cpp2a/bit-cast2.C: New test.
* g++.dg/cpp2a/bit-cast3.C: New test.
* g++.dg/cpp2a/bit-cast4.C: New test.
* g++.dg/cpp2a/bit-cast5.C: New test.

3 years agoc++: consteval-defarg1.C test variant for templates
Jakub Jelinek [Thu, 3 Dec 2020 14:32:31 +0000 (15:32 +0100)]
c++: consteval-defarg1.C test variant for templates

We weren't recognizing a default argument for a consteval member function as
being in immediate function context because there was no function parameter
scope to look at.

The following testcase is an attempt to test it with templates, both
non-dependent and dependent consteval calls in both function and class
templates, and with r11-5694 it now passes.

2020-12-03  Jakub Jelinek  <jakub@redhat.com>

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

3 years agotree-ssa-threadedge.c (record_temporary_equivalences_from_stmts_at_dest): Do not...
Ilya Leoshkevich [Thu, 3 Dec 2020 00:38:47 +0000 (01:38 +0100)]
tree-ssa-threadedge.c (record_temporary_equivalences_from_stmts_at_dest): Do not allow __builtin_constant_p.

This is the same as commit 70a62009181f ("tree-ssa-threadbackward.c
(profitable_jump_thread_path): Do not allow __builtin_constant_p."), but
for the old forward threader.

gcc/ChangeLog:

2020-12-03  Ilya Leoshkevich  <iii@linux.ibm.com>

* tree-ssa-threadedge.c (record_temporary_equivalences_from_stmts_at_dest):
Do not allow __builtin_constant_p on a threading path.

3 years agoFix division by 0 in printf_strlen_execute when dumping
Ilya Leoshkevich [Thu, 3 Dec 2020 01:01:16 +0000 (02:01 +0100)]
Fix division by 0 in printf_strlen_execute when dumping

gcc/ChangeLog:

2020-12-03  Ilya Leoshkevich  <iii@linux.ibm.com>

* tree-ssa-strlen.c (printf_strlen_execute): Avoid division by
0.

3 years agoRISC-V: Canonicalize --with-arch
Kito Cheng [Wed, 25 Nov 2020 09:30:29 +0000 (17:30 +0800)]
RISC-V: Canonicalize --with-arch

 - We would like to canonicalize the arch string for --with-arch for
   easier handling multilib, so split canonicalization part to a stand
   along script to shared the logic.

gcc/ChangeLog:

* config/riscv/multilib-generator (arch_canonicalize): Move
code to arch-canonicalize, and call that script to canonicalize arch
string.
(canonical_order): Move code to arch-canonicalize.
(LONG_EXT_PREFIXES): Ditto.
(IMPLIED_EXT): Ditto.
* config/riscv/arch-canonicalize: New.
* config.gcc (riscv*-*-*): Canonicalize --with-arch.

3 years agoaarch64: Add +flagm to -march
Przemyslaw Wirkus [Thu, 3 Dec 2020 09:24:59 +0000 (09:24 +0000)]
aarch64: Add +flagm to -march

New +flagm (Condition flag manipulation) feature option for -march command line
option.

Please note that FLAGM stays a Armv8.4-A feature but now can be
assigned to other architectures or CPUs.

gcc/ChangeLog:

* config/aarch64/aarch64-option-extensions.def
(AARCH64_OPT_EXTENSION): New +flagm option in -march for AArch64.
* config/aarch64/aarch64.h (AARCH64_FL_FLAGM): Add new flagm extension bit
mask.
(AARCH64_FL_FOR_ARCH8_4): Add flagm to Armv8.4-A.
* doc/invoke.texi: Update docs with +flagm.

3 years agotestsuite: Add testcase for already fixed PR [PR98104]
Jakub Jelinek [Thu, 3 Dec 2020 09:02:02 +0000 (10:02 +0100)]
testsuite: Add testcase for already fixed PR [PR98104]

This testcase got broken with r11-3826 and got fixed with r11-5628.

2020-12-03  Jakub Jelinek  <jakub@redhat.com>

PR c++/98104
* g++.dg/warn/pr98104.C: New test.

3 years agoOptimize vpsubusw compared to 0 into vpcmpleuw or vpcmpnleuw [PR96906]
liuhongt [Mon, 30 Nov 2020 05:27:16 +0000 (13:27 +0800)]
Optimize vpsubusw compared to 0 into vpcmpleuw or vpcmpnleuw [PR96906]

For signed comparisons, it handles cases that are eq or neq to 0.
For unsigned comparisons, it additionaly handles cases that are le or
gt to 0(equivilent to eq or neq to 0). Transform case eq to leu,
case neq to gtu.

.i.e. for -mavx512bw -mavx512vl transform eq case code from

vpsubusw        %xmm1, %xmm0, %xmm0
vpxor   %xmm1, %xmm1, %xmm1
vpcmpeqw  %xmm1, %xmm0, %k0
to
vpcmpleuw       %xmm1, %xmm0, %k0

.i.e. for -mavx512bw -mavx512vl transform neq case code from

vpsubusw        %xmm1, %xmm0, %xmm0
vpxor   %xmm1, %xmm1, %xmm1
vpcmpneqw  %xmm1, %xmm0, %k0
to
vpcmpnleuw       %xmm1, %xmm0, %k0

gcc/ChangeLog
PR target/96906
* config/i386/sse.md
(<avx512>_ucmp<mode>3<mask_scalar_merge_name>): Add a new
define_split after this insn.

gcc/testsuite/ChangeLog

* gcc.target/i386/avx512bw-pr96906-1.c: New test.
* gcc.target/i386/pr96906-1.c: Add -mno-avx512f.

3 years agoFix incorrect replacement of vmovdqu32 with vpblendd which can cause fault.
liuhongt [Tue, 3 Nov 2020 09:26:43 +0000 (17:26 +0800)]
Fix incorrect replacement of vmovdqu32 with vpblendd which can cause fault.

gcc/ChangeLog:

PR target/97642
* config/i386/i386-expand.c
(ix86_expand_special_args_builtin): Don't move all-ones mask
operands into register.
* config/i386/sse.md (UNSPEC_MASKLOAD): New unspec.
(*<avx512>_load<mode>_mask): New define_insns for masked load
instructions.
(<avx512>_load<mode>_mask): Changed to define_expands which
specifically handle memory or all-ones mask operands.
(<avx512>_blendm<mode>): Changed to define_insns which are same
as original <avx512>_load<mode>_mask with adjustment of
operands order.
(*<avx512>_load<mode>): New define_insn_and_split which is
used to optimize for masked load with all one mask.

gcc/testsuite/ChangeLog:

* gcc.target/i386/avx512bw-vmovdqu16-1.c: Adjust testcase to
make sure only masked load instruction is generated.
* gcc.target/i386/avx512bw-vmovdqu8-1.c: Ditto.
* gcc.target/i386/avx512f-vmovapd-1.c: Ditto.
* gcc.target/i386/avx512f-vmovaps-1.c: Ditto.
* gcc.target/i386/avx512f-vmovdqa32-1.c: Ditto.
* gcc.target/i386/avx512f-vmovdqa64-1.c: Ditto.
* gcc.target/i386/avx512vl-vmovapd-1.c: Ditto.
* gcc.target/i386/avx512vl-vmovaps-1.c: Ditto.
* gcc.target/i386/avx512vl-vmovdqa32-1.c: Ditto.
* gcc.target/i386/avx512vl-vmovdqa64-1.c: Ditto.
* gcc.target/i386/pr97642-1.c: New test.
* gcc.target/i386/pr97642-2.c: New test.

3 years agoc++: Push parms when late parsing default args
Jason Merrill [Wed, 2 Dec 2020 22:11:48 +0000 (17:11 -0500)]
c++: Push parms when late parsing default args

In this testcase we weren't catching the error in A::f because the parameter
'I' wasn't in scope, so the default argument for 'b' found the global
typedef I.  Fixed by pushing the parms before parsing.  This is a bit
complicated because pushdecl clears DECL_CHAIN; do_push_parm_decls deals
with this by nreversing first, but that doesn't work here because we only
want to push them one at a time; if we pushed all of them before parsing,
we'd wrongly reject A::g.

gcc/cp/ChangeLog:

* parser.c (cp_parser_primary_expression): Distinguish
parms from vars in error.
(cp_parser_late_parsing_default_args): Pushdecl parms
as we go.

gcc/testsuite/ChangeLog:

* g++.dg/parse/defarg17.C: New test.

3 years agoc++: Fix late-parsed default arg context
Jason Merrill [Wed, 2 Dec 2020 19:35:50 +0000 (14:35 -0500)]
c++: Fix late-parsed default arg context

Jakub noticed that we weren't recognizing a default argument for a consteval
member function as being in immediate function context because there was no
function parameter scope to look at.

Note that this patch doesn't actually push the parameters into the scope,
that happens in a separate commit.

gcc/cp/ChangeLog:

* name-lookup.c (begin_scope): Set immediate_fn_ctx_p.
* parser.c (cp_parser_late_parsing_default_args): Push
sk_function_parms scope.

gcc/testsuite/ChangeLog:

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

3 years agoAdd popcount<mode> expander to enable popcount auto vectorization under AVX512BITALG...
Hongyu Wang [Wed, 11 Nov 2020 01:41:13 +0000 (09:41 +0800)]
Add popcount<mode> expander to enable popcount auto vectorization under AVX512BITALG/AVX512POPCNTDQ target.

gcc/ChangeLog

PR target/97770
* config/i386/sse.md (popcount<mode>2): New expander
for SI/DI vector modes.
(popcount<mode>2): Likewise for QI/HI vector modes.

gcc/testsuite/ChangeLog

PR target/97770
* gcc.target/i386/avx512bitalg-pr97770-1.c: New test.
* gcc.target/i386/avx512vpopcntdq-pr97770-1.c: Likewise.
* gcc.target/i386/avx512vpopcntdq-pr97770-2.c: Likewise.
* gcc.target/i386/avx512vpopcntdqvl-pr97770-1.c: Likewise.

3 years agointroduce overridable clear_cache emitter
Alexandre Oliva [Thu, 3 Dec 2020 01:10:32 +0000 (22:10 -0300)]
introduce overridable clear_cache emitter

This patch introduces maybe_emit_call_builtin___clear_cache for the
builtin expander machinery and the trampoline initializers to use to
clear the instruction cache, removing a source of inconsistencies and
subtle errors in low-level machinery.

I've adjusted all trampoline_init implementations that used to issue
explicit calls to __clear_cache or similar to use this new primitive.

Specifically on vxworks targets, we needed to drop the __clear_cache
symbol in libgcc, for reasons related with linking that I didn't need
to understand, and we wanted to call cacheTextUpdate directly, despite
the different calling conventions: the second argument is a length
rather than the end address.

So I introduced a target hook to enable target OS-level overriding of
builtin __clear_cache call emission, retaining nearly (*) the same
logic to govern the decision on whether to emit a call (or nothing, or
a machine-dependent insn) but enabling a call to a target
system-defined function with different calling conventions to be
issued, without having to modify .md files of the various
architectures supported by the target system to introduce or modify
clear_cache insns.

(*) I write "nearly" mainly because, when not optimizing, we'd issue a
call regardless, but since the call may now be overridden, I added it
to the set of builtins that are not directly turned into calls when
not optimizing, following the normal expansion path instead.  It
wouldn't be hard to skip the emission of cache-clearing insns when not
optimizing, but it didn't seem very important, especially for the new
uses from trampoline init.

    Another difference that might be relevant is that now we expand
the begin and end arguments unconditionally.  This might make a
difference if they have side effects.  That's prettty much impossible
at expand time, but I thought I'd mention it.

I have NOT modified targets that did not issue cache-clearing calls in
trampoline init to use the new clear_cache-calling infrastructure even
if it would expand to nothing.  I have considered doing so, to have
__builtin___clear_cache and trampoline init call cacheTextUpdate on
all vxworks targets, but decided not to, since on targets that don't
do any cache clearing, cacheTextUpdate ought to be a no-op, even
though rs6000 seems to use icbi and dcbf instructions in the function
called to initialize a trampoline, but AFAICT not in the __clear_cache
builtin.  Hopefully target maintainers will have a look and take
advantage of this new piece of infrastructure to remove such
(apparent?) inconsistencies.  Not rs6000 and other that call asm-coded
trampoline setup instructions, for sure, but they might wish to
introduce a CLEAR_INSN_CACHE macro or a clear_cache expander if they
don't have one.

for  gcc/ChangeLog

* builtins.c (default_emit_call_builtin___clear_cache): New.
(maybe_emit_call_builtin___clear_cache): New.
(expand_builtin___clear_cache): Split into the above.
(expand_builtin): Do not issue clear_cache call any more.
* builtins.h (maybe_emit_call_builtin___clear_cache): Declare.
* config/aarch64/aarch64.c (aarch64_trampoline_init): Use
maybe_emit_call_builtin___clear_cache.
* config/arc/arc.c (arc_trampoline_init): Likewise.
* config/arm/arm.c (arm_trampoline_init): Likewise.
* config/c6x/c6x.c (c6x_initialize_trampoline): Likewise.
* config/csky/csky.c (csky_trampoline_init): Likewise.
* config/m68k/linux.h (FInALIZE_TRAMPOLINE): Likewise.
* config/tilegx/tilegx.c (tilegx_trampoline_init): Likewise.
* config/tilepro/tilepro.c (tilepro_trampoline_init): Ditto.
* config/vxworks.c: Include rtl.h, memmodel.h, and optabs.h.
(vxworks_emit_call_builtin___clear_cache): New.
* config/vxworks.h (CLEAR_INSN_CACHE): Drop.
(TARGET_EMIT_CALL_BUILTIN___CLEAR_CACHE): Define.
* target.def (trampoline_init): In the documentation, refer to
maybe_emit_call_builtin___clear_cache.
(emit_call_builtin___clear_cache): New.
* doc/tm.texi.in: Add new hook point.
(CLEAR_CACHE_INSN): Remove duplicate 'both'.
* doc/tm.texi: Rebuilt.
* targhooks.h (default_meit_call_builtin___clear_cache):
Declare.
* tree.h (BUILTIN_ASM_NAME_PTR): New.

for  libgcc/ChangeLog

* config/t-vxworks (LIB2ADD): Drop.
* config/t-vxworks7 (LIB2ADD): Likewise.
* config/vxcache.c: Remove.

3 years agooptions.exp: unsupport tests that depend on missing language
Alexandre Oliva [Thu, 3 Dec 2020 01:10:26 +0000 (22:10 -0300)]
options.exp: unsupport tests that depend on missing language

There's a help.exp test that checks that the help message for
-Wabsolute-value mentions it's available in C and ObjC, when compiling
a C++ program.

However, if GCC is built with the C++ language disabled, the
.cc file is compiled as C, and the message [available in C...] becomes
[disabled] instead, because that's the default for the flag in C.

I suppose it might also be possible to disable the C language, and
then the multitude of help.exp tests that name c as the source
language will fail.

This patch avoids these fails: it detects the message "compiler not
installed" in the compiler output, and bails out as "unsupported".

for  gcc/testsuite/ChangeLog

* lib/options.exp (check_for_options_with_filter): Detect
unavailable compiler for the selected language, and bail out
as unsupported.

3 years agoAdjust tests even more to avoid ILP32 failures after r11-5622 (PR middle-end/97373)
Martin Sebor [Thu, 3 Dec 2020 00:29:59 +0000 (17:29 -0700)]
Adjust tests even more to avoid ILP32 failures after r11-5622 (PR middle-end/97373)

gcc/testsuite/ChangeLog:
* gcc.dg/tree-ssa/builtin-sprintf-warn-1.c: Adjust expected warnings
to correctly reflect the maximum object size.
* gcc.dg/tree-ssa/builtin-sprintf-warn-11.c: Same.
* gcc.dg/tree-ssa/builtin-sprintf-warn-18.c: Same.

3 years agotree-ssa-threadbackward.c (profitable_jump_thread_path): Do not allow __builtin_const...
Ilya Leoshkevich [Wed, 3 Jun 2020 18:55:20 +0000 (20:55 +0200)]
tree-ssa-threadbackward.c (profitable_jump_thread_path): Do not allow __builtin_constant_p.

Linux Kernel (specifically, drivers/leds/trigger/ledtrig-cpu.c) build
with GCC 10 fails on s390 with "impossible constraint".

Explanation by Jeff Law:

```
So what we have is a b_c_p at the start of an if-else chain.  Subsequent
tests on the "true" arm of the the b_c_p test may throw us off the
constant path (because the constants are out of range).  Once all the
tests are passed (it's constant and the constant is in range) the true
arm's terminal block has a special asm that requires a constant
argument.   In the case where we get to the terminal block on the true
arm, the argument to the b_c_p is used as the constant argument to the
special asm.

At first glace jump threading seems to be doing the right thing.  Except
that we end up with two paths to that terminal block with the special
asm, one for each of the two constant arguments to the b_c_p call.
Naturally since that same value is used in the asm, we have to introduce
a PHI to select between them at the head of the terminal block.   Now
the argument in the asm is no longer constant and boom we fail.
```

Fix by disallowing __builtin_constant_p on threading paths.

gcc/ChangeLog:

2020-06-03  Ilya Leoshkevich  <iii@linux.ibm.com>

* tree-ssa-threadbackward.c (thread_jumps::profitable_jump_thread_path):
Do not allow __builtin_constant_p on a threading path.

gcc/testsuite/ChangeLog:

2020-06-03  Ilya Leoshkevich  <iii@linux.ibm.com>

* gcc.target/s390/builtin-constant-p-threading.c: New test.

3 years agoDaily bump.
GCC Administrator [Thu, 3 Dec 2020 00:16:47 +0000 (00:16 +0000)]
Daily bump.

3 years agoc++: Treat OPAQUE_TYPE types as an aggregate type [PR97947]
Peter Bergner [Thu, 3 Dec 2020 00:12:59 +0000 (18:12 -0600)]
c++: Treat OPAQUE_TYPE types as an aggregate type [PR97947]

MODE_OPAQUE and the associated OPAQUE_TYPE were added to stop the optimizers
from knowing how the bits in a variable with an opaque type are laid out.
This makes them a kind of pseudo aggregate type and we need to treat them
as such when we process the INIT initializer for variables with an
opaque type.

2020-12-02  Peter Bergner  <bergner@linux.ibm.com>

gcc/cp/
PR c++/97947
* typeck2.c (digest_init_r): Handle OPAQUE_TYPE as an aggregate type.

gcc/testsuite/
PR c++/97947
* g++.target/powerpc/pr97947.C: New test.

3 years agodwarf2out: Fix up add_scalar_info not to create invalid DWARF
Jakub Jelinek [Wed, 2 Dec 2020 23:29:46 +0000 (00:29 +0100)]
dwarf2out: Fix up add_scalar_info not to create invalid DWARF

As discussed in https://sourceware.org/bugzilla/show_bug.cgi?id=26987 ,
for very large bounds (which don't fit into HOST_WIDE_INT) GCC emits invalid
DWARF.
In DWARF2, DW_AT_{lower,upper}_bound were constant reference class.
In DWARF3 they are block constant reference and the
Static and Dynamic Properties of Types
chapter says:
"For a block, the value is interpreted as a DWARF expression; evaluation of the expression
yields the value of the attribute."
In DWARF4/5 they are constant exprloc reference class.
Now, for add_AT_wide we use DW_FORM_data16 (valid in constant class)
when -gdwarf-5, but otherwise just use DW_FORM_block1, which is not constant
class, but block.
For DWARF3 this means emitting clearly invalid DWARF, because the
DW_FORM_block1 should contain a DWARF expression, not random bytes
containing the constant directly.
For DWARF2/DWARF4/5 it could be considered a GNU extension, but a very badly
designed one when it means something different in DWARF3.

The following patch uses add_AT_wide only if we know we'll be using
DW_FORM_data16, and otherwise wastes 2 extra bytes and emits in there
DW_OP_implicit_value <size> before the constant.

2020-12-03  Jakub Jelinek  <jakub@redhat.com>

* dwarf2out.c (add_scalar_info): Only use add_AT_wide for 128-bit
constants and only in dwarf-5 or later, where DW_FORM_data16 is
available.  Otherwise use DW_FORM_block*/DW_FORM_exprloc with
DW_OP_implicit_value to describe the constant.

3 years agoc++: Implement LWG3396 Clarify point of reference for source_location::current()...
Jakub Jelinek [Wed, 2 Dec 2020 23:25:51 +0000 (00:25 +0100)]
c++: Implement LWG3396 Clarify point of reference for source_location::current() [PR80780, PR93093]

While std::source_location::current () is static consteval source_location
current() noexcept; in the standard, it also says with LWG3396:
"Any call to current that appears as a default member initializer
([class.mem]), or as a subexpression thereof, should correspond to the
location of the constructor definition or aggregate initialization that uses
the default member initializer.  Any call to current that appears as a
default argument ([dcl.fct.default]), or as a subexpression thereof, should
correspond to the location of the invocation of the function that uses the
default argument ([expr.call])."
so it must work as compiler magic rather than normal immediate functions,
in particular we need to defer its evaluation when parsing default arguments
or nsdmis.

This patch actually defers evaluation of all the calls to
std::source_location::current () until genericization (or constant expression
evaluation when called from constant expression contexts).
I had to change constexpr.c too so that it temporarily adjusts
current_function_decl from the constexpr evaluation context, but we do the
same already from __builtin_FUNCTION ().

2020-12-03  Jakub Jelinek  <jakub@redhat.com>

PR c++/80780
PR c++/93093
* cp-tree.h (source_location_current_p): Declare.
* tree.c (source_location_current_p): New function.
* call.c (immediate_invocation_p): New function.
(build_over_call): Use it to resolve LWG3396.
* constexpr.c (cxx_eval_builtin_function_call): Temporarily set
current_function_decl from ctx->call->fundef->decl if any.
* cp-gimplify.c (cp_genericize_r) <case CALL_EXPR>: Fold calls
to immediate function std::source_location::current ().

* g++.dg/cpp2a/srcloc15.C: New test.
* g++.dg/cpp2a/srcloc16.C: New test.
* g++.dg/cpp2a/srcloc17.C: New test.
* g++.dg/cpp2a/srcloc18.C: New test.

3 years agortl-optimization: Fix data flow maintenance bug in reg-stack.c [pr97777]
qing zhao [Wed, 2 Dec 2020 22:48:02 +0000 (23:48 +0100)]
rtl-optimization: Fix data flow maintenance bug in reg-stack.c [pr97777]

reg-stack pass does not maintain the data flow information correctly.
call df_insn_rescan_all after the transformation is done.

        gcc/
PR rtl-optimization/97777
* reg-stack.c (rest_of_handle_stack_regs): call
df_insn_rescan_all if reg_to_stack return true.

gcc/testsuite/
PR rtl-optimization/97777
* gcc.target/i386/pr97777.c: New test.

3 years agolibstdc++: Fix std::any pretty printer [PR 68735]
Jonathan Wakely [Wed, 2 Dec 2020 21:39:08 +0000 (21:39 +0000)]
libstdc++: Fix std::any pretty printer [PR 68735]

This fixes errors seen on powerpc64 (big endian only) due to the
printers for std::any and std::experimental::any being unable to find
the manager function.

libstdc++-v3/ChangeLog:

PR libstdc++/65480
PR libstdc++/68735
* python/libstdcxx/v6/printers.py (function_pointer_to_name):
New helper function to get the name of a function from its
address.
(StdExpAnyPrinter.__init__): Use it.

3 years agoc++: Give better placeholder diagnostic
Jason Merrill [Thu, 26 Nov 2020 10:45:02 +0000 (05:45 -0500)]
c++: Give better placeholder diagnostic

We were saying 'auto parameter not permitted' in a place where 'auto' is in
fact permitted in C++20, but a class template placeholder is not.

gcc/cp/ChangeLog:

* decl.c (grokdeclarator): Improve diagnostic for
disallowed CTAD placeholder.

gcc/testsuite/ChangeLog:

* g++.dg/other/pr88187.C: Adjust expected error.
* g++.dg/cpp2a/class-deduction-abbrev1.C: New test.

3 years agoc++: Improve init handling
Jason Merrill [Tue, 24 Nov 2020 23:21:38 +0000 (18:21 -0500)]
c++: Improve init handling

While looking at another issue I noticed that in a template we were failing
to find the INIT_EXPR we were looking for, and so ended up doing redundant
processing.  No testcase, as the redundant processing ended up getting the
right result.

gcc/cp/ChangeLog:

* decl.c (check_initializer): Also look through STMT_EXPR
and BIND_EXPR.

3 years agoc++: typename_type structural comparison
Nathan Sidwell [Wed, 2 Dec 2020 20:53:23 +0000 (12:53 -0800)]
c++: typename_type structural comparison

For modules we need to compare structurally all the way down.  This
means inhibiting typename_type resolution, independent of comparing
specializations.

gcc/cp/
* cp-tree.h (comparing_typenames): Declare.
* pt.c (comparing_typenames): Define.
(spec_hasher::equal): Increment it around comparisons.
* typeck.c (structural_comptypes): Adjust TYPENAME resolution
check.

3 years agogit: Tell git send-email where to send patches.
Jason Merrill [Tue, 1 Dec 2020 15:46:13 +0000 (10:46 -0500)]
git: Tell git send-email where to send patches.

I've been using

  git send-email --annotate --suppress-from --to=gcc-patches@gcc.gnu.org \
  ${@:-HEAD^} ':!*/ChangeLog' ':!*configure'

for sending most patches, but it occurs to me that it would be useful to put
the To: address in the configury.

If someone were feeling ambitious, they could write a script to analyze a
patch and add the relevant maintainers to To: or CC:.

contrib/ChangeLog:

* gcc-git-customization.sh: Configure sendemail.to.

3 years agoc++: Fix ICE with inline variable in template [PR97975]
Marek Polacek [Tue, 1 Dec 2020 15:39:08 +0000 (10:39 -0500)]
c++: Fix ICE with inline variable in template [PR97975]

In this test, we have

  static inline const int c = b;

in a class template, and we call store_init_value as usual.  There, the
value is

  IMPLICIT_CONV_EXPR<const float>(b)

which is is_nondependent_static_init_expression but isn't
is_nondependent_constant_expression (they only differ in STRICT).
We call fold_non_dependent_expr, but that just returns the expression
because it only instantiates is_nondependent_constant_expression
expressions.  Since we're not checking the initializer of a constexpr
variable, we go on to call maybe_constant_init, whereupon we crash
because it tries to evaluate all is_nondependent_static_init_expression
expressions, which our value is, but it still contains a template code.

I think the fix is to call fold_non_dependent_init instead of
maybe_constant_init, and only call fold_non_dependent_expr on the
"this is a constexpr variable" path so as to avoid instantiating twice
in a row.  Outside a template this should also avoid evaluating the
value twice.

gcc/cp/ChangeLog:

PR c++/97975
* constexpr.c (fold_non_dependent_init): Add a tree parameter.
Use it.
* cp-tree.h (fold_non_dependent_init): Add a tree parameter with
a default value.
* typeck2.c (store_init_value): Call fold_non_dependent_expr
only when checking the initializer for constexpr variables.
Call fold_non_dependent_init instead of maybe_constant_init.

gcc/testsuite/ChangeLog:

PR c++/97975
* g++.dg/cpp1z/inline-var8.C: New test.

3 years agoc++: Fix tsubst ICE with invalid code [PR97993, PR97187]
Marek Polacek [Mon, 30 Nov 2020 19:53:24 +0000 (14:53 -0500)]
c++: Fix tsubst ICE with invalid code [PR97993, PR97187]

I had a strong sense of deja vu when looking into this, and no wonder,
since this is almost identical to c++/95728.

Since r11-423 tsubst_copy_and_build/TREE_LIST uses tsubst_tree_list
instead of open coding it.  While the latter could return an error
node wrapped in a TREE_LIST, the former can return a naked error node.

That broke in tsubst_copy_and_build/NEW_EXPR, because we were accessing
TREE_VALUE of an error node.

gcc/cp/ChangeLog:

PR c++/97187
PR c++/97993
* pt.c (tsubst_copy_and_build) <case NEW_EXPR>: Return error_mark_node
if init is erroneous.

gcc/testsuite/ChangeLog:

PR c++/97187
PR c++/97993
* g++.dg/eh/crash2.C: New test.
* g++.dg/template/crash132.C: New test.

3 years agoC++: Module-specific tree flags
Nathan Sidwell [Wed, 2 Dec 2020 19:22:35 +0000 (11:22 -0800)]
C++: Module-specific tree flags

gcc/cp/
* cp-tree.h (DECL_MODULE_PURVIEW_P, DECL_MODULE_IMPORT_P)
(DECL_MODULE_ENTITY_P): New.
(DECL_MODULE_PENDING_SPECIALIZATIONS_P): New.
(DECL_MODULE_PENDING_MEMBERS_P): New.
(DECL_MODULE_ATTACHMENTS_P): New.
(DECL_MODULE_EXPORT_P): New.
(struct lang_decl_base): Shrink sel field.  Add new
module-specific fields.

3 years agolibbacktrace: correct buffer overflow tests
Ian Lance Taylor [Wed, 2 Dec 2020 19:06:40 +0000 (11:06 -0800)]
libbacktrace: correct buffer overflow tests

* dwarf.c (resolve_string): Use > rather than >= to check whether
string index extends past buffer.
(resolve_addr_index): Similarly for address index.

3 years agoAdjust test to avoid ILP32 failures after r11-5622 (PR middle-end/97373)
Martin Sebor [Wed, 2 Dec 2020 18:29:11 +0000 (11:29 -0700)]
Adjust test to avoid ILP32 failures after r11-5622 (PR middle-end/97373)

gcc/testsuite/ChangeLog:
* gcc.dg/tree-ssa/builtin-sprintf-warn-1.c: Adjust expected warnings
to correctly reflect the maximum object size.
* gcc.dg/tree-ssa/builtin-sprintf-warn-11.c: Same.
* gcc.dg/tree-ssa/builtin-sprintf-warn-18.c: Same.

3 years agoIBM Z: Use llihf and oilf to load large immediates into GPRs
Ilya Leoshkevich [Thu, 26 Nov 2020 01:16:17 +0000 (02:16 +0100)]
IBM Z: Use llihf and oilf to load large immediates into GPRs

Currently GCC loads large immediates into GPRs from the literal pool,
which is not as efficient as loading two halves with llihf and oilf.

gcc/ChangeLog:

2020-11-30  Ilya Leoshkevich  <iii@linux.ibm.com>

* config/s390/s390-protos.h (s390_const_int_pool_entry_p): New
function.
* config/s390/s390.c (s390_const_int_pool_entry_p): New
function.
* config/s390/s390.md: Add define_peephole2 that produces llihf
and oilf.

gcc/testsuite/ChangeLog:

2020-11-30  Ilya Leoshkevich  <iii@linux.ibm.com>

* gcc.target/s390/load-imm64-1.c: New test.
* gcc.target/s390/load-imm64-2.c: New test.

3 years agoSync .gitignore with binutils-gdb
Simon Marchi [Wed, 2 Dec 2020 18:04:01 +0000 (11:04 -0700)]
Sync .gitignore with binutils-gdb

* .gitignore: Sync with binutils-gdb

3 years agoGo testsuite: update semi6.go from source repo
Ian Lance Taylor [Wed, 2 Dec 2020 17:42:49 +0000 (09:42 -0800)]
Go testsuite: update semi6.go from source repo

This should have been part of c7932d5626a81a35686a3992b5a02570aba5cd0b,
but I forgot.

3 years agolibstdc++: Use libatomic for tests on all 32-bit powerpc targets
Jonathan Wakely [Wed, 2 Dec 2020 16:37:56 +0000 (16:37 +0000)]
libstdc++: Use libatomic for tests on all 32-bit powerpc targets

In addition to the existing powerpc targets, powerpc64 needs libatomic
for 64-bit atomics when testing the 32-bit multilib with -m32. Adjust
the existing target checks to match all 32-bit powerpc targets, but not
64-bit ones.

libstdc++-v3/ChangeLog:

* testsuite/lib/dg-options.exp (add_options_for_libatomic):
Replace powerpc-ibm-aix* and powerpc*-*-darwin* with check for
powerpc && ilp32.

3 years agoc++: RTTI accessors for modules
Nathan Sidwell [Wed, 2 Dec 2020 16:27:53 +0000 (08:27 -0800)]
c++: RTTI accessors for modules

The module machinery needs to serialize tinfo types and vars by
meaning, not literally.  This adds the necessary pieces to rtti.

gcc/cp/
* cp-tree.h (DECL_TINFO_P): Also for TYPE_DECLs.
(get_tinfo_decl_direct): Declare.
(get_pseudo_tinfo_index, get_pseudo_tinfo_type): Declare.
* rtti.c (get_tinfo_decl_direct): Externalize.
(get_tinfo_desc): Set DECL_TINFO_P on the typedef.
(get_pseudo_tinfo_index, get_pseudo_tinfo_type): New.

3 years agocompiler: reword "declared and not used" error message
Ian Lance Taylor [Fri, 27 Nov 2020 04:13:16 +0000 (20:13 -0800)]
compiler: reword "declared and not used" error message

This is a gofrontend copy of https://golang.org/cl/203282.

From the CL 203282 description:

    "declared and not used" is technically correct, but might confuse
    the user. Switching "and" to "but" will hopefully create the
    contrast for the users: they did one thing (declaration), but
    not the other --- actually using the variable.

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

3 years agocompiler: improve mixed named/unnamed parameter error message
Ian Lance Taylor [Fri, 27 Nov 2020 04:03:57 +0000 (20:03 -0800)]
compiler: improve mixed named/unnamed parameter error message

Use the same error as the current gc compiler.

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

3 years agocompiler: don't advance past unexpected semicolon
Ian Lance Taylor [Wed, 2 Dec 2020 03:15:57 +0000 (19:15 -0800)]
compiler: don't advance past unexpected semicolon

We've already read the unexpected semicolon, so advancing again causes
us to skip the next token, causing future errors to be out of sync.

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

3 years agoUpgrade ACATS testsuite to latest ACATS 2.6
Eric Botcazou [Wed, 2 Dec 2020 15:40:32 +0000 (16:40 +0100)]
Upgrade ACATS testsuite to latest ACATS 2.6

This upgrades the ACATS tesuite present in ada/acats from 2.5 to latest 2.6,
removing 3 tests and adding 11 tests, some of them written very recently.

gcc/testsuite/ChangeLog:
* ada/acats/support/acats25.lst: Delete.
* ada/acats/support/acats26.lst: New file.
* ada/acats/support/fcndecl.ada: Minor tweak.
* ada/acats/support/impdef.a: Add commentary.
* ada/acats/support/impdefg.a (Negative_Zero return): Simplify.
* ada/acats/support/macro.dfs (TASK_STORAGE_SIZE): Bump.
* ada/acats/support/repbody.ada: Upgrade to ACATS 2.6.
* ada/acats/support/tctouch.ada: Likewise.
* ada/acats/tests/c3/c352001.a: New file.
* ada/acats/tests/c4/c433001.a: Correct error messages.
* ada/acats/tests/c4/c453001.a: New file.
* ada/acats/tests/c4/c45622a.ada: Delete.
* ada/acats/tests/c4/c45624a.ada: Likewise.
* ada/acats/tests/c4/c45624b.ada: Likewise.
* ada/acats/tests/c4/c460013.a: New file.
* ada/acats/tests/c4/c460014.a: Likewise.
* ada/acats/tests/c6/c620001.a: Likewise.
* ada/acats/tests/c6/c620002.a: Likewise.
* ada/acats/tests/c7/c761006.a: Redo Unchecked_Deallocation case.
* ada/acats/tests/c9/c96004a.ada: Adjust for Ada 2005.
* ada/acats/tests/c9/c96007a.ada: Likewise.
* ada/acats/tests/cb/cb41004.a: Adjust for AI95-0044.
* ada/acats/tests/cc/cc3016f.ada: Minor tweak.
* ada/acats/tests/cd/cd30011.a: New file.
* ada/acats/tests/cd/cd30012.a: Likewise.
* ada/acats/tests/cd/cd90001.a: Fix comparison.
* ada/acats/tests/cxa/cxa3004.a: New file.
* ada/acats/tests/cxa/cxa5013.a: Likewise.
* ada/acats/tests/cxa/cxac005.a: Adjust for return-by-reference.
* ada/acats/tests/cxb/cxb30061.am: New file.
* ada/acats/tests/cxf/cxf2001.a: Fix failure message.

3 years agoc++: Add lang_decl, type_decl API
Nathan Sidwell [Wed, 2 Dec 2020 15:40:49 +0000 (07:40 -0800)]
c++: Add lang_decl, type_decl API

We need to call the lang_decl and type_decl creators from the module
loading machinery.  This makes them reachable.

gcc/cp/
* cp-tree.h (maybe_add_lang_decl_raw, maybe_add_lang_type_raw):
Declare.
* lex.c (maybe_add_lang_decl_raw, maybe_add_lang_type_raw):
Externalize, reformat.

3 years agoc++: Extend build_array_type API
Nathan Sidwell [Wed, 2 Dec 2020 15:35:23 +0000 (07:35 -0800)]
c++: Extend build_array_type API

The modules machinery needs to construct array types, and that wanted
to determine type dependency.  That doesn't work during loading, but
the module loader can stream that fact too and tell the array builder.
Thus this extends the API to allow a caller to specify the dependency
explicitly.  The call in cp_build_qualified_type_real is unreachable
during the loading, so that one's ok as is.

gcc/cp/
* cp-tree.h (build_cplus_array_type): Add defaulted DEP parm.
* tree.c (set_array_type_common): Add DEP parm.
(build_cplus_array_type): Add DEP parm, determine dependency if
needed.
(cp_build_qualified_type_real): Adjust array-building call.
(strip_typedefs): Likewise.

3 years agoc++: Fix bootstrap
Nathan Sidwell [Wed, 2 Dec 2020 15:28:30 +0000 (07:28 -0800)]
c++:  Fix bootstrap

I made the prefix for dumping a binding-vector slightly too small.
Fixed thusly.

gcc/cp/
* ptree.c (cxx_print_xnode): Increase binding-vector prefix size.

3 years agotree-optimization/97630 - fix SLP cycle memory leak
Richard Biener [Wed, 2 Dec 2020 13:43:59 +0000 (14:43 +0100)]
tree-optimization/97630 - fix SLP cycle memory leak

This fixes SLP cycles leaking memory by maintaining a double-linked
list of allocatd SLP nodes we can zap when we free the alloc pool.

2020-12-02  Richard Biener  <rguenther@suse.de>

PR tree-optimization/97630
* tree-vectorizer.h (_slp_tree::next_node,
_slp_tree::prev_node): New.
(vect_slp_init): Declare.
(vect_slp_fini): Likewise.
* tree-vectorizer.c (vectorize_loops): Call vect_slp_init/fini.
(pass_slp_vectorize::execute): Likewise.
* tree-vect-slp.c (vect_slp_init): New.
(vect_slp_fini): Likewise.
(slp_first_node): New global.
(_slp_tree::_slp_tree): Link node into the SLP tree list.
(_slp_tree::~_slp_tree): Delink node from the SLP tree list.

3 years agovec.h: Fix GCC build with -std=gnu++20 [PR98059]
Scott Snyder [Wed, 2 Dec 2020 14:42:56 +0000 (15:42 +0100)]
vec.h: Fix GCC build with -std=gnu++20 [PR98059]

Apparently vec.h doesn't build with -std=c++20/gnu++20, since the
DR2237 r11-532 change.
template <typename T>
class auto_delete_vec
{
private:
  auto_vec_delete<T> (const auto_delete_vec<T> &) = delete;
};
which vec.h uses is invalid C++20, one needs to use
  auto_vec_delete (const auto_delete_vec &) = delete;
instead which is valid all the way back to C++11 (and without = delete
to C++98).

2020-12-02  Scott Snyder  <sss@li-snyder.org>

PR plugins/98059
* vec.h (auto_delete_vec): Use
DISABLE_COPY_AND_ASSIGN(auto_delete_vec) instead of
DISABLE_COPY_AND_ASSIGN(auto_delete_vec<T>) to make it valid C++20
after DR2237.

3 years agoC++ Module Binding Vector
Nathan Sidwell [Wed, 2 Dec 2020 13:52:14 +0000 (05:52 -0800)]
C++ Module Binding Vector

This adds the vector necessary to hold different module's namespace
bindings.  We add a new tree-node 'tree_binding_vec', which contains a
sparse array, indexed by module number.  To avoid space wasting, this
is allocated in clusters using 'unsigned short' as the index value (so
that's one of the upper bounds on module importing).  If there are
only bindings from the current TU, there is no vector, so we have the
same representation as a non-module compilation.

To support lazy loading, a binding slot can contain either a tree (the
binding), or a cookie that the module machinery uses to load the
required binding on demand.

The first 2 or 3 slots end up being reserved for fixed meanings.
There are a couple of flags we have to record on a binding, to know
whether the same declaration could appear in two different slots.

gcc/cp/
* cp-tree.def (BINDING_VECTOR): New.
* name-lookup.h (struct binding_slot): New.
(BINDING_VECTOR_SLOTS_PER_CLUSTER): New.
(struct binding_index, struct binding_cluster): New.
(BINDING_VECTOR_ALLOC_CLUSTERS, BINDING_VECTOR_CLUSTER_BASE)
(BINDING_VECTOR_CLUSTER): New.
(struct tree_binding_vec): New.
(BINDING_VECTOR_NAME, BINDING_VECTOR_GLOBAL_DUPS_P)
(BINDING_VECTOR_PARTITION_DUPS_P): New.
(BINDING_BINDING_GLOBAL_P, BINDING_BINDING_PARTITION_P): New.
(BINDING_VECTOR_PENDING_SPECIALIZATIONS)
(BINDING_VECTOR_PENDING_IS_HEADER_P)
(BINDING_VECTOR_PENDING_IS_PARTITION_P): New.
* cp-tree.h (enum cp_tree_node_structure_enum): Add
TS_CP_BINDING_VECTOR.
(union lang_tree_node): Add binding_vec field.
(make_binding_vec): Declare.
(named_decl_hash::hash, named_decl_hash::equal): Check for binding
vector.
* decl.c (cp_tree_node_structure): Add BINDING_VECTOR case.
* ptree.c (cxx_print_xnode): Add BINDING_VECTOR case.
* tree.c (make_binding_vec): New.

3 years agoMAINTAINERS: Add myself as arc port maintainer
Claudiu Zissulescu [Wed, 2 Dec 2020 14:09:21 +0000 (16:09 +0200)]
MAINTAINERS: Add myself as arc port maintainer

2020-12-02  Claudiu Zissulescu  <claziss@gmail.com>

* MAINTAINERS: Add myself as arc port maintainer.

3 years agoipa: do not DECL_IS_MALLOC for void fns
Martin Liska [Wed, 2 Dec 2020 12:01:47 +0000 (13:01 +0100)]
ipa: do not DECL_IS_MALLOC for void fns

gcc/ChangeLog:

PR ipa/98075
* cgraph.c (cgraph_node::dump): Dump decl_is_malloc flag.
* ipa-pure-const.c (propagate_malloc): Do not set malloc
attribute for void functions.

gcc/testsuite/ChangeLog:

PR ipa/98075
* g++.dg/ipa/pr98075.C: New test.

3 years agoUse the section flag 'o' for __patchable_function_entries
H.J. Lu [Wed, 2 Dec 2020 13:32:37 +0000 (05:32 -0800)]
Use the section flag 'o' for __patchable_function_entries

This commit in GNU binutils 2.35:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=b7d072167715829eed0622616f6ae0182900de3e

added the section flag 'o' to .section directive:

.section __patchable_function_entries,"awo",@progbits,foo

which specifies the symbol name which the section references.  Assembler
creates a unique __patchable_function_entries section with the section,
where foo is defined, as its linked-to section.  Linker keeps a section
if its linked-to section is kept during garbage collection.

This patch checks assembler support for the section flag 'o' and uses
it to implement __patchable_function_entries section.  Since Solaris may
use GNU assembler with Solairs ld.  Even if GNU assembler supports the
section flag 'o', it doesn't mean that Solairs ld supports it.  This
feature is disabled for Solairs targets.

gcc/

PR middle-end/93195
PR middle-end/93197
* configure.ac (HAVE_GAS_SECTION_LINK_ORDER): New.  Define 1 if
the assembler supports the section flag 'o' for specifying
section with link-order.
* output.h (SECTION_LINK_ORDER): New.  Defined to 0x8000000.
(SECTION_MACH_DEP): Changed from 0x8000000 to 0x10000000.
* targhooks.c (default_print_patchable_function_entry): Pass
SECTION_LINK_ORDER to switch_to_section if the section flag 'o'
works.  Pass current_function_decl to switch_to_section.
* varasm.c (default_elf_asm_named_section): Use 'o' flag for
SECTION_LINK_ORDER if assembler supports it.
* config.in: Regenerated.
* configure: Likewise.
* doc/sourcebuild.texi: Document o_flag_in_section.

gcc/testsuite/

PR middle-end/93195
* g++.dg/pr93195a.C: New test.
* g++.dg/pr93195b.C: Likewise.
* lib/target-supports.exp
(check_effective_target_o_flag_in_section): New proc.

3 years agox86: Add the missing '.' for -mneeded
H.J. Lu [Wed, 2 Dec 2020 13:16:12 +0000 (05:16 -0800)]
x86: Add the missing '.' for -mneeded

* config/i386/i386.opt: Add the missing '.' for -mneeded.

3 years agolibstdc++: Use longer timeout for istream::gcount() overflow tests
Jonathan Wakely [Wed, 2 Dec 2020 12:34:20 +0000 (12:34 +0000)]
libstdc++: Use longer timeout for istream::gcount() overflow tests

On targets with 32-bit poitners these tests do extra work, so give them
longer to run.

libstdc++-v3/ChangeLog:

* testsuite/27_io/basic_istream/ignore/char/94749.cc: Add
dg-timeout-factor for ilp32 targets.
* testsuite/27_io/basic_istream/ignore/wchar_t/94749.cc:
Likewise.

3 years agolibstdc++: Fix null pointer dereferences in __gnu_cxx::rope
Jonathan Wakely [Wed, 2 Dec 2020 12:29:00 +0000 (12:29 +0000)]
libstdc++: Fix null pointer dereferences in __gnu_cxx::rope

This fixes UBsan errors like:

/usr/include/c++/10/ext/ropeimpl.h:593:9: runtime error: member access within null pointer of type 'struct _RopeRep'
/usr/include/c++/10/ext/ropeimpl.h:593:9: runtime error: member call on null pointer of type 'struct _Rope_rep_base'
/usr/include/c++/10/ext/rope:556:17: runtime error: reference binding to null pointer of type 'struct allocator_type'
/usr/include/c++/10/ext/ropeimpl.h:593:9: runtime error: reference binding to null pointer of type 'struct allocator_type'
/usr/include/c++/10/ext/rope:1700:30: runtime error: member call on null pointer of type 'struct new_allocator'
/usr/include/c++/10/ext/new_allocator.h:105:29: runtime error: member call on null pointer of type 'struct new_allocator'
/usr/include/c++/10/ext/rope:1702:26: runtime error: reference binding to null pointer of type 'const struct allocator'
/usr/include/c++/10/bits/allocator.h:148:34: runtime error: reference binding to null pointer of type 'const struct new_allocator'
/usr/include/c++/10/ext/rope:1664:39: runtime error: reference binding to null pointer of type 'const struct allocator'
/usr/include/c++/10/ext/rope:1665:9: runtime error: reference binding to null pointer of type 'const struct allocator_type'
/usr/include/c++/10/ext/rope:725:36: runtime error: reference binding to null pointer of type 'const struct allocator_type'
/usr/include/c++/10/ext/rope:614:64: runtime error: reference binding to null pointer of type 'const struct allocator_type'

The problem is calling r->_M_get_allocator() when r is null.

libstdc++-v3/ChangeLog:

* include/ext/rope (rope::_S_concat_char_iter)
(rope::_S_destr_concat_char_iter): Add allocator parameter.
(rope::push_back, rope::append, rope::insert, operator+):
Pass allocator.
* include/ext/ropeimpl.h (rope::_S_concat_char_iter)
(rope::_S_destr_concat_char_iter): Add allocator parameter
and use it.
(_Rope_char_ref_proxy::operator=(_CharT)): Pass allocator.

3 years agolibstdc++: Fix indentation in rope
Jonathan Wakely [Wed, 2 Dec 2020 11:25:42 +0000 (11:25 +0000)]
libstdc++: Fix indentation in rope

libstdc++-v3/ChangeLog:

* include/ext/rope: Fix indentation of access specifiers.

3 years agoAdd new test-case.
Martin Liska [Wed, 2 Dec 2020 12:08:56 +0000 (13:08 +0100)]
Add new test-case.

gcc/testsuite/ChangeLog:

PR tree-optimization/98084
* gcc.dg/tree-ssa/pr98094.c: New test.

3 years agoguard maybe_set_vectorized_backedge_value calls
Richard Biener [Wed, 2 Dec 2020 10:07:43 +0000 (11:07 +0100)]
guard maybe_set_vectorized_backedge_value calls

This makes sure to not call maybe_set_vectorized_backedge_value when
we did not vectorize the latch def candidate.

2020-12-02  Richard Biener  <rguenther@suse.de>

* tree-vect-loop.c (vect_transform_loop_stmt): Return whether
we vectorized a stmt.
(vect_transform_loop): Only call maybe_set_vectorized_backedge_value
when we vectorized the stmt.

3 years agoexpansion: Fix up infinite recursion due to double-word modulo optimization
Jakub Jelinek [Wed, 2 Dec 2020 10:33:33 +0000 (11:33 +0100)]
expansion: Fix up infinite recursion due to double-word modulo optimization

Jeff has reported that my earlier patch broke rl78-elf, e.g. with
unsigned short foo (unsigned short x) { return x % 7; }
when compiled with -O2 -mg14.  The problem is that rl78 is a BITS_PER_WORD
== 8 target which doesn't have 8-bit modulo or divmod optab, but has instead
16-bit divmod, so my patch attempted to optimize it, then called
expand_divmod to do 8-bit modulo and that in turn tried to do 16-bit modulo
again.

The following patch fixes it in two ways.
One is to not perform the optimization when we have {u,s}divmod_optab
handler for the double-word mode, in that case it is IMHO better to just
do whatever we used to do before.  This alone should fix the infinite
recursion.  But I'd be afraid some other target might have similar problem
and might not have a divmod pattern, but only say a library call.
So the patch also introduces a methods argument to expand_divmod such that
normally we allow everything that was allowed before (using libcalls and
widening), but when called from these expand_doubleword*mod routines we
restrict it to no widening and no libcalls.

2020-12-02  Jakub Jelinek  <jakub@redhat.com>

* expmed.h (expand_divmod): Only declare if GCC_OPTABS_H is defined.
Add enum optabs_method argument defaulted to OPTAB_LIB_WIDEN.
* expmed.c: Include expmed.h after optabs.h.
(expand_divmod): Add methods argument, if it is not OPTAB_{,LIB_}WIDEN,
don't choose a wider mode, and pass it to other calls instead of
hardcoded OPTAB_LIB_WIDEN.  Avoid emitting libcalls if not
OPTAB_LIB or OPTAB_LIB_WIDEN.
* optabs.c: Include expmed.h after optabs.h.
(expand_doubleword_mod, expand_doubleword_divmod): Pass OPTAB_DIRECT
as last argument to expand_divmod.
(expand_binop): Punt if {s,u}divmod_optab has handler for double-word
int_mode.
* expr.c: Include expmed.h after optabs.h.
* explow.c: Include expmed.h after optabs.h.

3 years agoexpansion: Further improve double-word modulo, division and divmod [PR97459]
Jakub Jelinek [Wed, 2 Dec 2020 10:32:19 +0000 (11:32 +0100)]
expansion: Further improve double-word modulo, division and divmod [PR97459]

The following patch implements what Thomas wrote about, in particular
that we can handle also double-word divison by the constants for which
the earlier patch optimized modulo (if it would be otherwise a library
call) and that we can also easily handle such constants shifted to the left.
Unfortunately, seems CSE isn't able to optimize away the two almost
identical sequences (one to compute remainder, one to compute quotient),
probably because of the ADD_OVERFLOW introduced jumps, so the patch also
adjusts expand_DIVMOD.

2020-12-02  Jakub Jelinek  <jakub@redhat.com>

PR rtl-optimization/97459
* optabs.h (expand_doubleword_divmod): Declare.
* optabs.c (expand_doubleword_divmod): New function.
(expand_binop): Use it.
* internal-fn.c (expand_DIVMOD): Likewise.

* gcc.target/i386/pr97282.c (foo): Use 123456 divisor instead of
10.
* gcc.dg/pr97459-1.c (TESTS): Add tests for 10, 12 and
6144.
* gcc.dg/pr97459-2.c (TESTS): Likewise.
* gcc.dg/pr97459-3.c: New test.
* gcc.dg/pr97459-4.c: New test.
* gcc.dg/pr97459-5.c: New test.
* gcc.dg/pr97459-6.c: New test.

3 years agoFix __builtin_clear_padding for empty struct.
Martin Liska [Wed, 2 Dec 2020 08:44:40 +0000 (09:44 +0100)]
Fix __builtin_clear_padding for empty struct.

gcc/ChangeLog:

PR c/98087
* gimple-fold.c (clear_padding_type): Do not divide by zero.

gcc/testsuite/ChangeLog:

PR c/98087
* gcc.c-torture/compile/pr98087.c: New test.

3 years agoGDB hooks: improve documentation
Martin Liska [Wed, 2 Dec 2020 09:19:19 +0000 (10:19 +0100)]
GDB hooks: improve documentation

gcc/ChangeLog:

* gdbinit.in: Write what each command calls
for a debugging function.

3 years agors6000: Disable HTM for Power10 and later by default
Kewen Lin [Wed, 2 Dec 2020 07:55:34 +0000 (01:55 -0600)]
rs6000: Disable HTM for Power10 and later by default

Power ISA 3.1 has dropped transactional memory support, this patch
is to disable HTM feature for power10 and later by default.

Bootstrapped/regtested on powerpc64le-linux-gnu P8 and P10.

gcc/ChangeLog:

* config/rs6000/rs6000.c (rs6000_option_override_internal):
Use OPTION_MASK_DIRECT_MOVE for Power8 target_enable instead
of OPTION_MASK_HTM.
* config/rs6000/rs6000-cpus.def (ISA_2_7_MASKS_SERVER):
Remove OPTION_MASK_HTM.
(RS6000_CPU): Add OPTION_MASK_HTM to power8, power9 and
powerpc64le entries.

3 years agoi386: Fix abs an maxmin expanders for TARGET_PARTIAL_REG_STALL [PR98079].
Uros Bizjak [Wed, 2 Dec 2020 07:15:03 +0000 (08:15 +0100)]
i386: Fix abs an maxmin expanders for TARGET_PARTIAL_REG_STALL [PR98079].

QImode shold be enabled only for !TARGET_PARTIAL_REG_STALL

2020-12-02  UroÅ¡ Bizjak  <ubizjak@gmail.com>

PR target/98079

gcc/
* config/i386/i386.md (abs<mode>2): Enable QImode
only for !TARGET_PARTIAL_REG_STALL.
(*abs<mode>2_1): Ditto.
(<maxmin:code><mode>3): Ditto.
(*<maxmin:code><mode>3_1): Ditto.

gcc/testsuite/
* gcc.target/i386/pr98079.c: New test.

3 years agodiagnostics: ignore -fmax-errors for ICE
Martin Liska [Tue, 1 Dec 2020 16:33:35 +0000 (17:33 +0100)]
diagnostics: ignore -fmax-errors for ICE

Right now I see:
./xgcc -B. ~/Programming/testcases/json.i -c -O2 -fmax-errors=1
/home/marxin/Programming/testcases/json.i: In function â€˜json_variant_type’:
/home/marxin/Programming/testcases/json.i:22:1: error: non-integral type switch statement
   22 | }
      | ^
int *
switch (v_2(D)) <default: <L16> [INV], case 0B: <L11> [INV], case 5B: <L12> [INV], case 6B: <L13> [INV], case 7B: <L14> [INV], case 8B: <L15> [INV]>
compilation terminated due to -fmax-errors=1.

with the patch I get:

./xgcc -B. ~/Programming/testcases/json.i -c -O2 -fmax-errors=1 -c
/home/marxin/Programming/testcases/json.i: In function â€˜json_variant_type’:
/home/marxin/Programming/testcases/json.i:22:1: error: non-integral type switch statement
   22 | }
      | ^
int *
switch (v_2(D)) <default: <L16> [INV], case 0B: <L11> [INV], case 5B: <L12> [INV], case 6B: <L13> [INV], case 7B: <L14> [INV], case 8B: <L15> [INV]>
during GIMPLE pass: iftoswitch
/home/marxin/Programming/testcases/json.i:22:1: internal compiler error: verify_gimple failed
0xe4478c verify_gimple_in_cfg(function*, bool)
/home/marxin/Programming/gcc/gcc/tree-cfg.c:5467
0xd201cf execute_function_todo
/home/marxin/Programming/gcc/gcc/passes.c:2042
0xd2101c do_per_function
/home/marxin/Programming/gcc/gcc/passes.c:1687
0xd2101c execute_todo
/home/marxin/Programming/gcc/gcc/passes.c:2096
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

gcc/ChangeLog:

* diagnostic.c (diagnostic_report_diagnostic): ICE causes to
terminate compiler immediately, so I guess it should be printed
always.

3 years agoif-to-switch: Support chain with 2 BBs.
Martin Liska [Tue, 1 Dec 2020 11:18:46 +0000 (12:18 +0100)]
if-to-switch: Support chain with 2 BBs.

As seen in the test-case, even 2 BBs can handle interesting
cases covered by a jump table or a bit-test.

gcc/ChangeLog:

PR tree-optimization/88702
* gimple-if-to-switch.cc (pass_if_to_switch::execute):
Require at least 2 BBs.
* gimple-if-to-switch.cc (find_conditions): Require
equal precision for low and high of a range.

gcc/testsuite/ChangeLog:

PR tree-optimization/88702
* gcc.dg/tree-ssa/if-to-switch-9.c: New test.

3 years agoif-to-switch: consider only integral types
Martin Liska [Tue, 1 Dec 2020 16:25:36 +0000 (17:25 +0100)]
if-to-switch: consider only integral types

gcc/ChangeLog:

PR tree-optimization/98084
* gimple-if-to-switch.cc (find_conditions): Consider only
integral types.

gcc/testsuite/ChangeLog:

PR tree-optimization/98084
* gcc.dg/tree-ssa/pr98084.c: New test.

3 years agoUse add/sub/neg insns to eliminate compare/test insns on H8
Jeff Law [Wed, 2 Dec 2020 04:48:10 +0000 (21:48 -0700)]
Use add/sub/neg insns to eliminate compare/test insns on H8

gcc/

* config/h8300/addsub.md (addqi3_clobber_flags): Rename to
addqi3_flags and annotate with a <cczn> for define_subst.
(addhi3_h8sx_clobber_flags): Likewise.
(subqi3_clobber_flags, sub<mode>3_clobber_flags): Likewise.
(neg<mode2>_clobber_flags): Similarly.
(addsi3_clobber_flags): Similarly.  Update last argument to
output_plussi to distinguish when we need flags or do not need
flags.
(addhi3_clobber_flags): Similarly.  Twiddle code for cases
+-1, +-2 and +-4.
* config/h8300/h8300.md: Define iterators, mode attributes and
substitutions for use in compare/test elimination.
* config/h8300/jumpcall.md (branch, branch_1): Use H8cc mode
iterator to cover the different modes for the CC register.
(branch_1_false): Likewise.

gcc/testsuite
* gcc.target/h8300/add.c: New test.
* gcc.target/h8300/add-2.c: New test.
* gcc.target/h8300/add-3.c: New test.
* gcc.target/h8300/sub.c: New test.
* gcc.target/h8300/sub-2.c: New test.
* gcc.target/h8300/sub-3.c: New test.

3 years agoloop-iv: Fix typo in `iv_analyze_expr' description
Maciej W. Rozycki [Wed, 2 Dec 2020 04:28:26 +0000 (04:28 +0000)]
loop-iv: Fix typo in `iv_analyze_expr' description

gcc/
* loop-iv.c: Fix a typo, s/bu/by/, in the `iv_analyze_expr'
description in the introduction.

3 years agogo-test.exp: permit trailing */ on ERROR line
Ian Lance Taylor [Wed, 2 Dec 2020 02:18:34 +0000 (18:18 -0800)]
go-test.exp: permit trailing */ on ERROR line

* go.test/go-test.exp (errchk): Permit trailing */ on ERROR line.

3 years agoUse SHF_GNU_RETAIN to preserve symbol definitions
H.J. Lu [Mon, 3 Feb 2020 19:55:43 +0000 (11:55 -0800)]
Use SHF_GNU_RETAIN to preserve symbol definitions

In assemly code, the section flag 'R' sets the SHF_GNU_RETAIN flag to
indicate that the section must be preserved by the linker.

Add SECTION_RETAIN to indicate a section should be retained by the linker
and set SECTION_RETAIN on section for the preserved symbol if assembler
supports SHF_GNU_RETAIN.  All retained symbols are placed in separate
sections with

.section .data.rel.local.preserved_symbol,"awR"
preserved_symbol:
...
.section .data.rel.local,"aw"
not_preserved_symbol:
...

to avoid

.section .data.rel.local,"awR"
preserved_symbol:
...
not_preserved_symbol:
...

which places not_preserved_symbol definition in the SHF_GNU_RETAIN
section.

gcc/

2020-12-01  H.J. Lu  <hjl.tools@gmail.com>

* configure.ac (HAVE_GAS_SHF_GNU_RETAIN): New.  Define 1 if
the assembler supports marking sections with SHF_GNU_RETAIN flag.
* output.h (SECTION_RETAIN): New.  Defined as 0x4000000.
(SECTION_MACH_DEP): Changed from 0x4000000 to 0x8000000.
(default_unique_section): Add a bool argument.
* varasm.c (get_section): Set SECTION_RETAIN for the preserved
symbol with HAVE_GAS_SHF_GNU_RETAIN.
(resolve_unique_section): Used named section for the preserved
symbol if assembler supports SHF_GNU_RETAIN.
(get_variable_section): Handle the preserved common symbol with
HAVE_GAS_SHF_GNU_RETAIN.
(default_elf_asm_named_section): Require the full declaration and
use the 'R' flag for SECTION_RETAIN.
* config.in: Regenerated.
* configure: Likewise.
* doc/sourcebuild.texi: Document R_flag_in_section.

gcc/testsuite/

2020-12-01  H.J. Lu  <hjl.tools@gmail.com>
    Jozef Lawrynowicz  <jozef.l@mittosystems.com>

* c-c++-common/attr-used.c: Check the 'R' flag.
* c-c++-common/attr-used-2.c: Likewise.
* c-c++-common/attr-used-3.c: New test.
* c-c++-common/attr-used-4.c: Likewise.
* gcc.c-torture/compile/attr-used-retain-1.c: Likewise.
* gcc.c-torture/compile/attr-used-retain-2.c: Likewise.
* lib/target-supports.exp
(check_effective_target_R_flag_in_section): New proc.

3 years agolibstdc++: Make preprocessor checks for __cpp_lib_atomic_wait consistent
Jonathan Wakely [Wed, 2 Dec 2020 00:39:22 +0000 (00:39 +0000)]
libstdc++: Make preprocessor checks for __cpp_lib_atomic_wait consistent

This changes some #ifdef checks to use #if instead.

libstdc++-v3/ChangeLog:

* include/bits/atomic_timed_wait.h: Use #if instead of #ifdef.
* include/bits/semaphore_base.h: Likewise.
* include/std/version: Remove trailing whitespace.

3 years agolibstdc++: Fix filesystem::path pretty printer test failure
Jonathan Wakely [Wed, 2 Dec 2020 00:39:21 +0000 (00:39 +0000)]
libstdc++: Fix filesystem::path pretty printer test failure

On some systems libstdc++-prettyprinters/cxx17.cc FAILs with this error:

skipping: Python Exception <type 'exceptions.AttributeError'> 'gdb.Type' object has no attribute 'name': ^M
got: $27 = filesystem::path "/dir/."^M
FAIL: libstdc++-prettyprinters/cxx17.cc print path2

The gdb.Type.name attribute isn't present in GDB 7.6, so we get an
exception from StdPathPrinter._iterator.__next__ trying to use it.
The StdPathPrinter._iterator is already passed the type's name in its
constructor, so we can just store that and use it instead of
gdb.Type.name.

libstdc++-v3/ChangeLog:

* python/libstdcxx/v6/printers.py (StdExpPathPrinter): Store the
name of the type and pass it to the iterator.
(StdPathPrinter): Likewise.
* testsuite/libstdc++-prettyprinters/filesystem-ts.cc: New test.

3 years agox86: Add -mneeded for GNU_PROPERTY_X86_ISA_1_V[234] marker
H.J. Lu [Mon, 9 Nov 2020 17:29:23 +0000 (09:29 -0800)]
x86: Add -mneeded for GNU_PROPERTY_X86_ISA_1_V[234] marker

GCC 11 supports -march=x86-64-v[234] to enable x86 micro-architecture ISA
levels:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97250

Binutils has been updated to support GNU_PROPERTY_X86_ISA_1_V[234] marker:

https://gitlab.com/x86-psABIs/x86-64-ABI/-/merge_requests/13

with

commit b0ab06937385e0ae25cebf1991787d64f439bf12
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Fri Oct 30 06:49:57 2020 -0700

    x86: Support GNU_PROPERTY_X86_ISA_1_BASELINE marker

and

commit 32930e4edbc06bc6f10c435dbcc63131715df678
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Fri Oct 9 05:05:57 2020 -0700

    x86: Support GNU_PROPERTY_X86_ISA_1_V[234] marker

in x86 ELF binaries.

Add -mneeded to emit GNU_PROPERTY_X86_ISA_1_NEEDED property to indicate
the micro-architecture ISA level required to execute the binary.

gcc/

* config.gcc: Replace cet.o with gnu-property.o.  Replace
i386/t-cet with i386/t-gnu-property.
* config/i386/cet.c: Renamed to ...
* config/i386/gnu-property.c: This.
(emit_gnu_property): New function.
(file_end_indicate_exec_stack_and_cet): Renamed to ...
(file_end_indicate_exec_stack_and_gnu_property): This.  Call
emit_gnu_property to generate GNU_PROPERTY_X86_FEATURE_1_AND and
GNU_PROPERTY_X86_ISA_1_NEEDED properties.
* config/i386/i386.opt (mneeded): New.
* config/i386/linux-common.h (file_end_indicate_exec_stack_and_cet):
Renamed to ...
(file_end_indicate_exec_stack_and_gnu_property): This.
(TARGET_ASM_FILE_END): Updated.
* config/i386/t-cet: Renamed to ...
* config/i386/t-gnu-property: This.
(cet.o): Renamed to ...
(gnu-property.o): This.
* doc/invoke.texi: Document -mneeded.

gcc/testsuite/

* gcc.target/i386/x86-needed-1.c: New test.
* gcc.target/i386/x86-needed-2.c: Likewise.
* gcc.target/i386/x86-needed-3.c: Likewise.

3 years agoDaily bump.
GCC Administrator [Wed, 2 Dec 2020 00:16:41 +0000 (00:16 +0000)]
Daily bump.

3 years agoAdd feature test macro for atomic<T>::wait
Thomas Rodgers [Tue, 1 Dec 2020 23:41:08 +0000 (15:41 -0800)]
Add feature test macro for atomic<T>::wait

Adds __cpp_lib_atomic_wait feature test macro which was overlooked in
the initial commit of this feature. Replaces uses of
_GLIBCXX_HAVE_ATOMIC_WAIT.

libstdc++-v3/ChangeLog:

* include/bits/atomic_base.h: Replace usage of
_GLIBCXX_HAVE_ATOMIC_WAIT with __cpp_lib_atomic_wait.
* include/bits/atomic_timed_wait.h: Likewise.
* include/bits/atomic_wait.h: Define __cpp_lib_atomic_wait
feature test macro.
* include/bits/semaphore_base.h: Replace usage of
_GLIBCXX_HAVE_ATOMIC_WAIT with __cpp_lib_atomic_wait.
* include/std/atomic: Likewise.
* include/std/latch: Likewise.
* include/std/semaphore: Likewise.
* include/std/version: Define __cpp_lib_atomic wait
feature test macro and replace usage of
_GLIBCXX_HAVE_ATOMIC_WAIT.
* testsuite/29_atomics/atomic/wait_notify/1.cc: New test.
* testsuite/29_atomics/atomic/wait_notify/2.cc: Likewise.

3 years agoOptimize max/min pattern with comparison
Eugene Rozenfeld [Tue, 1 Dec 2020 23:26:59 +0000 (16:26 -0700)]
Optimize max/min pattern with comparison

gcc/
PR tree-optimization/96708
* match.pd: New pattern for comparing X with MAX (X, Y)
or MIN (X, y).

gcc/testsuite
* gcc.dg/pr96708-negative.c: New test.
* gcc.dg/pr96708-positive.c: New test.

3 years agoFix mcore multilib specification
Jeff Law [Tue, 1 Dec 2020 23:23:05 +0000 (16:23 -0700)]
Fix mcore multilib specification

gcc
* config/mcore/t-mcore (MULTILIB_EXCEPTIONS): Define.

3 years agoAdd pretty-printing support for __is_nothrow_{assignable,constructible}.
Ville Voutilainen [Tue, 1 Dec 2020 22:20:46 +0000 (00:20 +0200)]
Add pretty-printing support for __is_nothrow_{assignable,constructible}.

gcc/cp/ChangeLog:

PR c++/98054
* cxx-pretty-print.c (pp_cxx_trait_expression):
Add support for __is_nothrow_{assignable,constructible}.

3 years agoPR middle-end/97595 - bogus -Wstringop-overflow due to DECL_SIZE_UNIT underreporting...
Martin Sebor [Tue, 1 Dec 2020 22:10:30 +0000 (15:10 -0700)]
PR middle-end/97595 - bogus -Wstringop-overflow due to DECL_SIZE_UNIT underreporting field size

gcc/ChangeLog:

PR middle-end/97595
* tree.c (component_ref_size): Fail when DECL_SIZE != TYPE_SIZE.
* tree.h (DECL_SIZE, TYPE_SIZE): Update comment.

gcc/testsuite/ChangeLog:

PR middle-end/97595
* g++.dg/warn/Warray-bounds-14.C: New test.
* g++.dg/warn/Wstringop-overflow-6.C: New test.

3 years agoFix more minor testsuite fallout from improved switch optimization
Jeff Law [Tue, 1 Dec 2020 22:06:48 +0000 (15:06 -0700)]
Fix more minor testsuite fallout from improved switch optimization

gcc/testsuite
* gcc.dg/tree-ssa/pr96480.c: Disable jump table optimization

3 years agoFeature: Macros for identifying the wide and narrow execution string literal encoding
JeanHeyd Meneide [Tue, 1 Dec 2020 21:39:47 +0000 (14:39 -0700)]
Feature: Macros for identifying the wide and narrow execution string literal encoding

gcc/c-family
* c-cppbuiltin.c (c_cpp_builtins): Add predefined
{__GNUC_EXECUTION_CHARSET_NAME} and
_WIDE_EXECUTION_CHARSET_NAME} macros.

gcc/
* doc/cpp.texi: Document new macros.

gcc/testsuite/
* c-c++-common/cpp/wide-narrow-predef-macros.c: New test.

libcpp/
* charset.c (init_iconv_desc): Initialize "to" and "from" fields.
* directives.c (cpp_get_narrow_charset_name): New function.
(cpp_get_wide_charset_name): Likewise.
* include/cpplib.h (cpp_get_narrow_charset_name): Prototype.
(cpp_get_wide_charset_name): Likewise.
* internal.h (cset_converter): Add "to" and "from" fields.

3 years agolibstdc++: Pretty printers for _Bit_reference and _Bit_iterator
Michael Weghorn [Tue, 1 Dec 2020 21:19:20 +0000 (21:19 +0000)]
libstdc++: Pretty printers for _Bit_reference and _Bit_iterator

'std::_Bit_iterator' and 'std::_Bit_const_iterator' are the iterators
used by 'std::vector<bool>'.
'std::_Bit_reference' is e.g. used in range-based for loops over
'std::vector<bool>'  like

    std::vector<bool> vb {true, false, false};
    for (auto b : vb) {
        // b is of type std::_Bit_reference here
        // ...
    }

Like iterators of vectors for other types, the actual value is printed.

libstdc++-v3/ChangeLog:

* python/libstdcxx/v6/printers.py (StdBitIteratorPrinter)
(StdBitReferencePrinter): Add pretty-printers for
_Bit_reference, _Bit_iterator and _Bit_const_iterator.
* testsuite/libstdc++-prettyprinters/simple.cc: Test
std::_Bit_reference, std::_Bit_iterator and
std::_Bit_const_iterator.
* testsuite/libstdc++-prettyprinters/simple11.cc: Likewise.

3 years agoFix compromised tests after recent switch table improvements
Jeff Law [Tue, 1 Dec 2020 21:27:38 +0000 (14:27 -0700)]
Fix compromised tests after recent switch table improvements

gcc/testsuite
* gcc.dg/pr46309-2.c: Add -fno-bit-tests and -fno-jump-tables
to avoid compromising the test.

3 years agoopenmp: Avoid ICE on depend clause on depobj OpenMP construct [PR98072]
Jakub Jelinek [Tue, 1 Dec 2020 20:41:44 +0000 (21:41 +0100)]
openmp: Avoid ICE on depend clause on depobj OpenMP construct [PR98072]

Since r11-5430 we ICE on the following testcase.  When parsing the depobj
directive we don't really use cp_parser_omp_all_clauses routine which ATM
disables generation of location wrappers and the newly added assertion
that there are no location wrappers thus triggers.

Fixed by adding the location wrappers suppression sentinel.

Longer term, we should handle location wrappers inside of OpenMP clauses.

2020-12-01  Jakub Jelinek  <jakub@redhat.com>

PR c++/98072
* parser.c (cp_parser_omp_depobj): Suppress location wrappers when
parsing depend clause.

* c-c++-common/gomp/depobj-2.c: New test.

3 years agoPR middle-end/97373 - missing warning on sprintf into allocated destination
Martin Sebor [Tue, 1 Dec 2020 20:38:08 +0000 (13:38 -0700)]
PR middle-end/97373 - missing warning on sprintf into allocated destination

gcc/ChangeLog:

PR middle-end/97373
* builtins.c (compute_objsize): Rename...
(compute_objsize_r): to this.  Change order and types of arguments.
Use new argument.  Adjust calls to self.
(access_ref::get_ref): New member function.
(pointer_query::pointer_query): New member function.
(pointer_query::get_ref): Same.
(pointer_query::put_ref): Same.
(handle_min_max_size): Change order and types of arguments.
(maybe_emit_free_warning): Add a test.
* builtins.h (class pointer_query): New class.
(compute_objsize): Declare an overload.
* gimple-ssa-sprintf.c (get_destination_size): Add argument.
(handle_printf_call): Change argument type.
* tree-ssa-strlen.c (adjust_last_stmt): Add an argument and use it.
(maybe_warn_overflow): Same.
(handle_builtin_strcpy): Same.
(maybe_diag_stxncpy_trunc): Same.
(handle_builtin_memcpy): Change argument type.  Adjust calls.
(handle_builtin_strcat): Same.
(handle_builtin_memset): Same.
(handle_store): Same.
(strlen_check_and_optimize_call): Same.
(check_and_optimize_stmt): Same.
(strlen_dom_walker): Add new data members.
(strlen_dom_walker::before_dom_children): Use new member.
(printf_strlen_execute): Dump cache performance counters.  Remove
objsize pass cleanup.
* tree-ssa-strlen.h (maybe_diag_stxncpy_trunc): Add argument.
(handle_printf_call): Change argument type.

gcc/testsuite/ChangeLog:

PR middle-end/97373
* gcc.dg/tree-ssa/builtin-sprintf-warn-25.c: New test.

3 years agoMake -fzero-call-used-regs work on the SPARC
Eric Botcazou [Tue, 1 Dec 2020 20:12:54 +0000 (21:12 +0100)]
Make -fzero-call-used-regs work on the SPARC

This contains both a generic fixlet for targets implementing the leaf
register optimization (SPARC and Xtensa) and the implementation of the
target hook TARGET_ZERO_CALL_USED_REGS which is needed to make this work
on the SPARC.

gcc/ChangeLog:
* function.c (gen_call_used_regs_seq): In a function subject to the
leaf register optimization, skip registers that are not present.
* config/sparc/sparc.c (TARGET_ZERO_CALL_USED_REGS): Define to...
(sparc_zero_call_used_regs): ...this.  New function.

3 years agotestsuite: replace .* with a better regex
Martin Liska [Tue, 1 Dec 2020 20:02:15 +0000 (21:02 +0100)]
testsuite: replace .* with a better regex

gcc/testsuite/ChangeLog:

* g++.dg/tree-ssa/if-to-switch-1.C: Do not allow newlines
in .* pattern.
* gcc.dg/tree-ssa/if-to-switch-1.c: Likewise.
* gcc.dg/tree-ssa/if-to-switch-2.c: Likewise.
* gcc.dg/tree-ssa/if-to-switch-3.c: Likewise.
* gcc.dg/tree-ssa/if-to-switch-5.c: Likewise.

3 years agoDarwin, D : Adjust the X spec to cater for duplicate use.
Iain Sandoe [Tue, 1 Dec 2020 15:34:11 +0000 (15:34 +0000)]
Darwin, D : Adjust the X spec to cater for duplicate use.

The '-X' flag is an obsolete spelling for a command to tell the
linker to 'strip local symbols'.  This has been the default action
for a long time - but, as per the usual GCC approach, although the
flag is retired, we have not removed it; rather, we just delete it
in the driver self-spec.

The D language adds this flag as a front end option (to emit json)
which means that deleting it in the driver disables that function
in D.

This patch works around the duplication by removing the unused flag
in the link_spec instead of the driver self-spec.

gcc/ChangeLog:

* config/darwin.h: Remove unused 'X' specs in the link spec
rather than driver self-specs.

3 years agoif-to-switch: Fix test-suite patterns.
Martin Liska [Tue, 1 Dec 2020 19:38:40 +0000 (20:38 +0100)]
if-to-switch: Fix test-suite patterns.

gcc/testsuite/ChangeLog:

PR testsuite/98085
* g++.dg/tree-ssa/if-to-switch-1.C: Do not expect precise number
of BBs.
* gcc.dg/tree-ssa/if-to-switch-1.c: Likewise.
* gcc.dg/tree-ssa/if-to-switch-2.c: Likewise. Find better name
for the function.
* gcc.dg/tree-ssa/if-to-switch-3.c: Likewise. Find better name
for the function.
* gcc.dg/tree-ssa/if-to-switch-5.c: Likewise.

3 years agoC++ Module keywords
Nathan Sidwell [Tue, 1 Dec 2020 19:44:34 +0000 (11:44 -0800)]
C++ Module keywords

This adds the module keywords.  These are special internal tokens
generated by the preprocessor's module-control-line token peeking
logic.  Spelling them with a space means that they turn back into
regular tokens in preprocessor output (but do skew the column
numbering :()

gcc/c-family/
* c-common.c (module, import, export): New internal tokens (with
trailing space).
* c-common.h (RID__MODULE, RID__IMPORT & RID__EXPORT): Enumerate
them.
(D_CXX_MODULES, D_CXX_MODULES_FLAGS): Enable them.
* c-cppbuiltin.c (c_cpp_builtins): Feature macro.
gcc/cp/
* lex.c (init_reswords): Maybe enable module keywords.

3 years agoC++ Module parameters & timers
Nathan Sidwell [Tue, 1 Dec 2020 19:39:38 +0000 (11:39 -0800)]
C++ Module parameters & timers

Here is the new parameter and instrumentation timers for modules.

gcc/
* params.opt (lazy-modules): New.
* timevar.def (TV_MODULE_IMPORT, TV_MODULE_EXPORT)
(TV_MODULE_MAPPER): New.

3 years agoC++ Module options
Nathan Sidwell [Tue, 1 Dec 2020 18:28:15 +0000 (10:28 -0800)]
C++ Module options

This adds the C++ module options, and wires them into lang-specs.  The
options are not connected to any machinery.  The options! They do
nothing!

gcc/c-family/
* c-opts.c (c_common_init_options): Ask for module dependencies.
(c_common_handle_option): Handle -Mmodules -Mno-modules.
* c-pch.c (c_common_valid_pch): ... does not play with C++
modules.
* c.opt (Mmodules, Mno-modules): New preprocessor dependency
options.
(fmodules-ts, fmodule-header, fmodule-implicit-inline)
(fmodule-only, fmodule-mapper, fmodule-lazy)
(fmodule-version-ignore, Winvalid-imported-macros)
(flang-info-include-translate, flang-info-include-translate-not):
New options
gcc/cp/
* lang-specs.h: Add module-related options.

3 years agoImprove double-word mod even on powerpc [PR97459]
Jakub Jelinek [Tue, 1 Dec 2020 15:25:06 +0000 (16:25 +0100)]
Improve double-word mod even on powerpc [PR97459]

I have noticed that while my (already committed, thanks for review)
patch works on x86, it doesn't work on powerpc*.  The problem is that
we don't have lshr double-word optab (neither TImode nor for -m32 DImode),
but as expander has code for double-word shift, that doesn't really matter.
As the implementation is prepared to punt whenever something can't be
expanded with OPTAB_DIRECT and in the end also punts if any library calls
would be emitted, the optab_handler checks were just to save compile time.

On the other side, for even divisors, we know that (1 << bit) % (2 * x)
for bit > 0 will never be equal to 1, because both dividend and divisor
are even and so remainder will be even too, so we can save some compile time
by adding an early exit.

The even divisors can be handled with the approach Thomas wrote about
(perhaps generalized into divisors equal to what expand_doubleword_mod
can handle times some power of two where we can handle power of two modulo
cheaply), but that would be done in a different function...
And we could use ctz to find the power of two...

2020-12-01  Jakub Jelinek  <jakub@redhat.com>

PR rtl-optimization/97459
* optabs.c (expand_doubleword_mod): Punt early for even op1.
(expand_binop): Don't require lshr_optab double-word handler.

3 years agoloop-invariant: JUMP_INSNs aren't loop invariant [PR97954]
Jakub Jelinek [Tue, 1 Dec 2020 15:23:59 +0000 (16:23 +0100)]
loop-invariant: JUMP_INSNs aren't loop invariant [PR97954]

The following testcase ICEs because loop invariant motion moves asm goto
with a single output as invariant.
Normally, jumps aren't really moved, because if they are single set,
they have their SET_DEST (pc) and pc_rtx has VOIDmode on which one of the
functions find_invariant_insn calls bails out.  The code already punts on
insns that can throw or trap.  And for asm goto without outputs, it isn't
single set, or asm goto with two or more outputs it isn't single set either.

2020-12-01  Jakub Jelinek  <jakub@redhat.com>

PR rtl-optimization/97954
* loop-invariant.c (find_invariant_insn): Punt on JUMP_P insns.

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

3 years agoconfigury : Fix LEB128 support for non-GNU assemblers.
Iain Sandoe [Sat, 25 Aug 2018 12:58:02 +0000 (13:58 +0100)]
configury : Fix LEB128 support for non-GNU assemblers.

The current configuration test for LEB128 support in the assembler is
(a) specific to GNU assemblers and (b) only checks that the directives
are accepted, not that they give correct output.

The patch extends the asm test to cover one failure case present in
assemblers based off an older version of GAS (where a 64 bit value with
the MSB set presented to a .uleb128 directive causes a fail).

The test is now generalized such that it does not make use of any
specific test for assembler source/version, but checks that the output
is as expected.  We cater for scanning the object with objdump (either
binutils or LLVM) or Darwin otool.

gcc/ChangeLog:

* configure.ac (check leb128 support): Check that assemblers both
accept the LEB128 directives and also give the expected output.
Add a test for uleb128 with the MSB set for a 64 bit value.
* configure: Regenerated.

3 years agolibstdc++: Simplify detection of built-in functions
Jonathan Wakely [Tue, 1 Dec 2020 14:14:18 +0000 (14:14 +0000)]
libstdc++: Simplify detection of built-in functions

This fixes a regression affecting the Intel compiler. Because that
compiler defines __GNUC__ to match whatever version of GCC it finds on
the host system, it might claim to be a brand new GCC despite not
actually supporting all the built-ins that the latest GCC supports. This
means the config checks for __GNUC__ don't work. Most recently this
broke when r11-3569-g73ae6eb572515ad627b575a7fbdfdd47a4368e1c switched
us from using __is_same_as to __is_same when __GNUC__ >= 11.

Because __has_builtin is supported by all of GCC, Clang, and Intel we can
use that to reliably detect whether a given built-in is supported,
instead of hardcoding anything based on __GNUC__. The big caveat is
that for versions of Clang <= 9.0.0 and for (as far as I can tell) all
released versions of Intel icc, __has_builtin only evaluates to true for
built-ins with a name starting "__builtin_". For __is_aggregate,
__is_same, and __has_unique_object_representations it's necessary to use
__is_identifier to check if it's a valid identifeir token instead.

The solution used in this patch is to define _GLIBCXX_HAS_BUILTIN and
use that instead of using __has_builtin directly. For compilers that
define __is_identifier as well as __has_builtin we use both, so that if
__has_builtin evaluates to false we try again using !__is_identifier.

libstdc++-v3/ChangeLog:

* include/bits/c++config (_GLIBCXX_HAS_BUILTIN): Define macro to
work around different implementations of __has_builtin.
(_GLIBCXX_HAVE_BUILTIN_HAS_UNIQ_OBJ_REP)
(_GLIBCXX_HAVE_BUILTIN_IS_AGGREGATE)
(_GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED)
(_GLIBCXX_HAVE_BUILTIN_IS_SAME, _GLIBCXX_HAVE_BUILTIN_LAUNDER):
Define using _GLIBCXX_HAS_BUILTIN.

3 years agoRegenerate a configure script omitted in r11-5520.
Iain Sandoe [Tue, 1 Dec 2020 13:52:28 +0000 (13:52 +0000)]
Regenerate a configure script omitted in r11-5520.

Additional change for : hppa64-hpux11 build to remove source paths
from embedded path.

gcc/ChangeLog:

* configure: Regnerated.

3 years agotestsuite: Correct check_effective_target_hwaddress_exec
Matthew Malcomson [Tue, 1 Dec 2020 11:40:18 +0000 (11:40 +0000)]
testsuite: Correct check_effective_target_hwaddress_exec

This test should ensure that we can compile with hwasan, that such a compiled
binary runs as expected, *and* that we're running on a kernel which implements
the capability to ignore the top bytes of pointers in syscalls.

It was expected that a basic test of `int main(void) { return 0; }` would check
this, since there is a check called during `__hwasan_init` in libhwasan to
ensure that the kernel we're running on provides a `prctl` to request the
relaxed ABI.

Unfortunately, the check in libhwasan has a bug in it, and does not correctly
fail when the kernel feature is not around.  This means that check is not
automatically provided by the runtime.

The sanitizer runtime will be fixed but would like to install this fix here in
case fixing the library is not quick enough for the release (and so that people
running the testsuite do not see spurious errors in the meantime).

Tested by running testsuite on an AArch64 machine with and without the required
kernel.
Observed that the test does indeed fail when the kernel feature is unavailable
and pass when the feature is available.

Note that this test is directly targetting AArch64 by using `prctl` numbers
specific to it.  That's unfortunate, but once the runtime fix has gone in we
will be able to remove that requirement.

Ok for trunk?

gcc/testsuite/ChangeLog:

* lib/hwasan-dg.exp (check_effective_target_hwaddress_exec): Fix
check for correct kernel version.

3 years agoC++ : Adjust warning for misplaced attributes.
Iain Sandoe [Fri, 27 Nov 2020 23:02:45 +0000 (23:02 +0000)]
C++ : Adjust warning for misplaced attributes.

This removes the reference to Objective-C++ for the warning that
attributes may not be placed before linkage specifications.  It also
adds a note that they may be placed after that.

gcc/cp/ChangeLog:

* parser.c (cp_parser_declaration): Add a not about where
attributes may be placed.

3 years agoIntroduce can_vec_cmp_compare_p
Ilya Leoshkevich [Tue, 24 Nov 2020 22:45:59 +0000 (23:45 +0100)]
Introduce can_vec_cmp_compare_p

This is the same as dcd2ca63ec5c ("Introduce can_vcond_compare_p
function"), but for vec_cmp.  The reason it's needed is that since
5d9ade39b872 ("IBM Z: Fix PR97326: Enable fp compares in vec_cmp")
and 4acba4859013 ("IBM Z: Restrict vec_cmp<m><n> on z13") s390's vec_cmp
expander advertises that it supports floating point comparisons except
signaling ones on z13, but the common code ignores the latter
restriction.

gcc/ChangeLog:

2020-11-25  Ilya Leoshkevich  <iii@linux.ibm.com>

* optabs-tree.c (vec_cmp_icode_p): New function.
(vec_cmp_eq_icode_p): New function.
(expand_vec_cmp_expr_p): Use vec_cmp_icode_p and
vec_cmp_eq_icode_p.
(vcond_icode_p): Use get_rtx_code_1, just to be uniform with
vec_cmp_icode_p.
* optabs.c (unsigned_optab_p): New function.
(insn_predicate_matches_p): New function.
(can_vec_cmp_compare_p): New function.
(can_vcond_compare_p): Use unsigned_optab_p and
insn_predicate_matches_p.
(get_rtx_code): Use get_rtx_code_1.
(get_rtx_code_1): Version of get_rtx_code that returns UNKNOWN
instead of asserting.
* optabs.h (can_vec_cmp_compare_p): New function.
(get_rtx_code_1): New function.

3 years agolibstdc++: Use longer timeout for slow running tests
Jonathan Wakely [Tue, 1 Dec 2020 10:51:25 +0000 (10:51 +0000)]
libstdc++: Use longer timeout for slow running tests

libstdc++-v3/ChangeLog:

* testsuite/27_io/basic_istream/get/char/lwg3464.cc: Add
dg-timeout-factor directive.
* testsuite/27_io/basic_istream/get/wchar_t/lwg3464.cc:
Likewise.

3 years agoAdd if-chain to switch conversion pass.
Martin Liska [Fri, 28 Aug 2020 08:26:13 +0000 (10:26 +0200)]
Add if-chain to switch conversion pass.

gcc/ChangeLog:

PR tree-optimization/14799
PR ipa/88702
* Makefile.in: Add gimple-if-to-switch.o.
* dbgcnt.def (DEBUG_COUNTER): Add new debug counter.
* passes.def: Include new pass_if_to_switch pass.
* timevar.def (TV_TREE_IF_TO_SWITCH): New timevar.
* tree-pass.h (make_pass_if_to_switch): New.
* tree-ssa-reassoc.c (struct operand_entry): Move to the header.
(dump_range_entry): Move to header file.
(debug_range_entry): Likewise.
(no_side_effect_bb): Make it global.
* tree-switch-conversion.h (simple_cluster::simple_cluster):
Add inline for couple of functions in order to prevent error
about multiple defined symbols.
* gimple-if-to-switch.cc: New file.
* tree-ssa-reassoc.h: New file.

gcc/testsuite/ChangeLog:

PR tree-optimization/14799
PR ipa/88702
* gcc.dg/tree-ssa/pr96480.c: Disable if-to-switch conversion.
* gcc.dg/tree-ssa/reassoc-32.c: Likewise.
* g++.dg/tree-ssa/if-to-switch-1.C: New test.
* gcc.dg/tree-ssa/if-to-switch-1.c: New test.
* gcc.dg/tree-ssa/if-to-switch-2.c: New test.
* gcc.dg/tree-ssa/if-to-switch-3.c: New test.
* gcc.dg/tree-ssa/if-to-switch-4.c: New test.
* gcc.dg/tree-ssa/if-to-switch-5.c: New test.
* gcc.dg/tree-ssa/if-to-switch-6.c: New test.
* gcc.dg/tree-ssa/if-to-switch-7.c: New test.
* gcc.dg/tree-ssa/if-to-switch-8.c: New test.