platform/upstream/gcc.git
2 years agolibstdc++: Begin lifetime of chars in constexpr std::string [PR103295]
Jonathan Wakely [Thu, 18 Nov 2021 10:33:14 +0000 (10:33 +0000)]
libstdc++: Begin lifetime of chars in constexpr std::string [PR103295]

Clang gives errors for constexpr std::string because the memory returned
by std::allocator<T>::allocate does not contain any objects yet, and
attempting to set them using char_traits::assign or char_traits::copy
fails with:

assignment to object outside its lifetime is not allowed in a constant expression
              *__result = *__first;
                        ^
This adds code to std::char_traits to use std::construct_at to begin
lifetimes when called during constant evaluation. To support
specializations of std::basic_string that don't use std::char_traits
there is now another layer of wrapper around the allocator_traits, so
that the lifetime of characters is begun as soon as the memory is
allocated. By doing it in the char traits and allocator traits, the rest
of basic_string can ignore the problem.

While modifying char_traits::copy and char_traits::assign to begin
lifetimes for the constexpr cases, I also replaced their uses of
std::copy and std::fill_n respectively. That means we don't need
<bits/stl_algobase.h> for char_traits.

libstdc++-v3/ChangeLog:

PR libstdc++/103295
* include/bits/basic_string.h (_Alloc_traits): Replace typedef
with struct for C++20 mode.
* include/bits/basic_string.tcc (_M_replace): Use _Alloc_traits
for allocation.
* include/bits/char_traits.h (__gnu_cxx::char_traits::assign):
Use std::_Construct during constant evaluation.
(__gnu_cxx::char_traits::assign(CharT*, const CharT*, size_t)):
Likewise. Replace std::fill_n with memset or manual loop.
(__gnu_cxx::char_traits::copy): Likewise, replacing std::copy
with memcpy.
* include/ext/vstring.h: Include <bits/stl_algobase.h> for
std::min.
* include/std/string_view: Likewise.
* testsuite/21_strings/basic_string/capacity/char/resize_and_overwrite.cc:
Add constexpr test.

2 years agooptions: Make -Ofast switch off -fsemantic-interposition
Martin Jambor [Fri, 19 Nov 2021 17:46:00 +0000 (18:46 +0100)]
options: Make -Ofast switch off -fsemantic-interposition

Using -fno-semantic-interposition has been reported by various people
to bring about considerable speed up at the cost of strict compliance
to the ELF symbol interposition rules  See for example
https://fedoraproject.org/wiki/Changes/PythonNoSemanticInterpositionSpeedup

As such I believe it should be implied by our -Ofast optimization
level, not only so that benchmarks that can benefit run faster, but
also so that people looking at -Ofast documentation for options that
could speed their programs find it.

gcc/ChangeLog:

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

* opts.c (default_options_table): Switch off
flag_semantic_interposition at Ofast.
* doc/invoke.texi (Optimize Options): Document that Ofast switches off
-fsemantic-interposition.

2 years agoUse modref even for nested functions in ref_maybe_used_by_call_p_1
Jan Hubicka [Fri, 19 Nov 2021 17:09:13 +0000 (18:09 +0100)]
Use modref even for nested functions in ref_maybe_used_by_call_p_1

Remove test for function not having call chain guarding modref use in
ref_maybe_used_by_call_p_1.  It never made sense since modref treats call chain
accesses explicitly. It was however copied from earlier check for ECF_CONST
(which seems dubious too, but I would like to discuss it independelty).

This enables us to detect that memory pointed to static chain (or parts of it)
are unused by the function.

lto-bootstrapped-regtested all lanugages on x86_64-linux.

gcc/ChangeLog:

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

* tree-ssa-alias.c (ref_maybe_used_by_call_p_1): Do not guard modref
by !gimple_call_chain.

gcc/testsuite/ChangeLog:

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

* gcc.dg/tree-ssa/modref-dse-6.c: New test.

2 years agoRestore ancient -Waddress for weak symbols [PR33925].
Martin Sebor [Fri, 19 Nov 2021 16:44:31 +0000 (09:44 -0700)]
Restore ancient -Waddress for weak symbols [PR33925].

Resolves:
PR c/33925 - gcc -Waddress lost some useful warnings
PR c/102867 - -Waddress from macro expansion in readelf.c

gcc/c-family/ChangeLog:

PR c++/33925
PR c/102867
* c-common.c (decl_with_nonnull_addr_p): Call maybe_nonzero_address
and improve handling tof defined symbols.

gcc/c/ChangeLog:

PR c++/33925
PR c/102867
* c-typeck.c (maybe_warn_for_null_address): Suppress warnings for
code resulting from macro expansion.

gcc/cp/ChangeLog:

PR c++/33925
PR c/102867
* typeck.c (warn_for_null_address): Suppress warnings for code
resulting from macro expansion.

gcc/ChangeLog:

PR c++/33925
PR c/102867
* doc/invoke.texi (-Waddress): Update.

gcc/testsuite/ChangeLog:

PR c++/33925
PR c/102867
* g++.dg/warn/Walways-true-2.C: Adjust to avoid a valid warning.
* c-c++-common/Waddress-5.c: New test.
* c-c++-common/Waddress-6.c: New test.
* g++.dg/warn/Waddress-7.C: New test.
* gcc.dg/Walways-true-2.c: Adjust to avoid a valid warning.
* gcc.dg/weak/weak-3.c: Expect a warning.

2 years agoLimit depth for all GORI expressions.
Andrew MacLeod [Wed, 17 Nov 2021 19:14:06 +0000 (14:14 -0500)]
Limit depth for all GORI expressions.

Apply the logical_depth limit ranger uses to all stmts with multiple ssa-names
to avoid excessive outgoing calculations.

gcc/
PR tree-optimization/103254
* gimple-range-gori.cc (range_def_chain::get_def_chain): Limit the
depth for all statements with multple ssa names.

gcc/testsuite/
* gcc.dg/pr103254.c: New.

2 years agoIBM Z: Fix load-and-test peephole2 condition
Stefan Schulze Frielinghaus [Fri, 19 Nov 2021 15:56:56 +0000 (16:56 +0100)]
IBM Z: Fix load-and-test peephole2 condition

For a peephole2 condition variable insn points to the first matched
insn.  In order to refer to the second matched insn use
peep2_next_insn(1) instead.

gcc/ChangeLog:

* config/s390/s390.md (define_peephole2): Variable insn points
to the first matched insn.  Use peep2_next_insn(1) to refer to
the second matched insn.

gcc/testsuite/ChangeLog:

* gcc.target/s390/20211119.c: New test.

2 years agomiddle-end: Handle FMA_CONJ correctly after SLP layout update.
Tamar Christina [Fri, 19 Nov 2021 15:12:38 +0000 (15:12 +0000)]
middle-end: Handle FMA_CONJ correctly after SLP layout update.

Apologies, I got dinged by the i386 regressions bot for a test I didn't have in
my tree at the time I made the previous patch.  The bot was telling me that FMA
stopped working after I strengthened the FMA check in the previous patch.

The reason is that the check is slightly early.  The first check can indeed only
exit early when either node isn't a mult.  However we need to delay till we know
if the node is a MUL or FMA before enforcing that both nodes must be a MULT
since the node to inspect is different if the operation is a MUL or FMA.

Also with the update patch for GCC 11 tree layout update to the new GCC 12 one
I had missed that the difference in which node is conjucated is not symmetrical.

So the test for it can just be testing the inverse order.  It was Currently
no detecting when the first node was conjucated instead of the second one.

This also made me wonder why my own test didn't detect this.  It turns out that
the tests, being copied from the _Float16 ones were incorrectly marked as
xfail.  The _Float16 ones are marked as xfail since C doesn't have a conj
operation for _Float16, which means you get extra type-casts in between.

While you could use the GCC _Complex extension here I opted to mark them xfail
since I wanted to include detection over the widenings next year.

Secondly the double tests were being skipped because Adv. SIMD was missing from
targets supporting Complex Double vectorization.

With these changes all other tests run and pass and only XFAIL ones are
correctly the _Float16 ones.  Sorry for missing this before, testing should now
cover all cases.

gcc/ChangeLog:

PR tree-optimization/103311
PR target/103330
* tree-vect-slp-patterns.c (vect_validate_multiplication): Fix CONJ
test to new codegen.
(complex_mul_pattern::matches): Move check downwards.

gcc/testsuite/ChangeLog:

PR tree-optimization/103311
PR target/103330
* gcc.dg/vect/complex/fast-math-bb-slp-complex-mla-double.c: Fix it.
* gcc.dg/vect/complex/fast-math-bb-slp-complex-mla-float.c: Likewise.
* gcc.dg/vect/complex/fast-math-bb-slp-complex-mls-double.c: Likewise.
* gcc.dg/vect/complex/fast-math-bb-slp-complex-mls-float.c: Likewise.
* gcc.dg/vect/complex/fast-math-bb-slp-complex-mul-double.c: Likewise.
* gcc.dg/vect/complex/fast-math-bb-slp-complex-mul-float.c: Likewise.
* lib/target-supports.exp
(check_effective_target_vect_complex_add_double): Add Adv. SIMD.

2 years agoRevert "Remove MAY_HAVE_DEBUG_MARKER_STMTS and MAY_HAVE_DEBUG_BIND_STMTS."
Martin Liska [Fri, 19 Nov 2021 14:29:35 +0000 (15:29 +0100)]
Revert "Remove MAY_HAVE_DEBUG_MARKER_STMTS and MAY_HAVE_DEBUG_BIND_STMTS."

This reverts commit 206b22d021d94adbaa79e1d443c87415254b15de.

2 years agoDo not abort compilation when dump file is /dev/*
Giuliano Belinassi [Tue, 16 Nov 2021 16:25:32 +0000 (13:25 -0300)]
Do not abort compilation when dump file is /dev/*

The `configure` scripts generated with autoconf often tests compiler
features by setting output to `/dev/null`, which then sets the dump
folder as being /dev/* and the compilation halts with an error because
GCC cannot create files in /dev/. This is a problem when configure is
testing for compiler features because it cannot tell if the failure was
due to unsupported features or any other problem, and disable it even
if it is working.

As an example, running configure overriding CFLAGS="-fdump-ipa-clones"
will result in several compiler-features as being disabled because of
gcc halting with an error creating files in /dev/*.

This commit fixes this issue by checking if the output file is
/dev/null or /dev/zero. In this case we use the current working
directory for dump output instead of the directory of the output
file because we cannot write to /dev/*.

gcc/ChangeLog
2021-11-16  Giuliano Belinassi  <gbelinassi@suse.de>

* gcc.c (process_command): Skip dumpdir override if file is a
not_actual_file_p.
* doc/invoke.texi: Update -dumpdir documentation.

gcc/testsuite/ChangeLog
2021-11-16  Giuliano Belinassi  <gbelinassi@suse.de>

* gcc.dg/devnull-dump.c: New.

Signed-off-by: Giuliano Belinassi <gbelinassi@suse.de>
2 years agoc++: cp_walk_subtrees simplification for *_CAST_EXPR
Patrick Palka [Fri, 19 Nov 2021 14:01:09 +0000 (09:01 -0500)]
c++: cp_walk_subtrees simplification for *_CAST_EXPR

Let walk_tree_1 do the operand walking for us.

gcc/cp/ChangeLog:

* tree.c (cp_walk_subtrees) <case *_CAST_EXPR>: Don't explicitly
walk the operands.

2 years agoc++: nested lambda capturing a capture proxy [PR94376]
Patrick Palka [Fri, 19 Nov 2021 13:54:25 +0000 (08:54 -0500)]
c++: nested lambda capturing a capture proxy [PR94376]

Here when determining the type of the FIELD_DECL for the by-value capture
of 'i' in the inner lambda, we incorrectly give it the type const int
instead of int since the effective initializer is the proxy for the outer
capture, and this proxy is const since the outer lambda is non-mutable.

This patch fixes this by making lambda_capture_field_type handle
by-value capturing of capture proxies specially, namely we instead
consider the type of their FIELD_DECL which unlike the proxy has the
true cv-quals of the captured entity.

PR c++/94376

gcc/cp/ChangeLog:

* lambda.c (lambda_capture_field_type): Simplify by handling the
is_this case first.  When capturing by-value a capture proxy,
consider the type of the corresponding field instead.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/lambda/lambda-nested9.C: New test.

2 years agolibphobos: Increase size of defaultStackPages on OSX X86_64 targets.
Iain Buclaw [Fri, 19 Nov 2021 13:43:07 +0000 (14:43 +0100)]
libphobos: Increase size of defaultStackPages on OSX X86_64 targets.

As of macOS 11, libunwind now requires more stack space than 16k, so
default to a larger stack size. This is only applied to X86 as the
PAGESIZE is still 4k, however on AArch64 it is 16k.

libphobos/ChangeLog:

* libdruntime/core/thread/fiber.d (defaultStackPages): Increase size
on OSX X86_64 targets.

2 years agolibphobos: Don't call __gthread_key_delete in the emutls destroy function.
Iain Buclaw [Fri, 19 Nov 2021 13:26:07 +0000 (14:26 +0100)]
libphobos: Don't call __gthread_key_delete in the emutls destroy function.

Fixes a EXC_BAD_ACCESS issue seen on Darwin when the libphobos DSO gets
unloaded.  Based on reading libgcc's emutls implementation, as it
doesn't call __gthread_key_delete directly, neither should libphobos.

libphobos/ChangeLog:

* libdruntime/gcc/emutls.d (emutlsDestroyThread): Don't remove entry
from global array.
(_d_emutls_destroy): Don't call __gthread_key_delete.

2 years agoFix tree-optimization/103314 : Limit folding of (type) X op CST where type is a nop...
Andrew Pinski [Fri, 19 Nov 2021 01:42:41 +0000 (01:42 +0000)]
Fix tree-optimization/103314 : Limit folding of (type) X op CST where type is a nop convert to gimple

There is some re-association code in fold_binary which conflicts with
this optimization due keeping around some "constants" which are not
INTEGER_CST (1 << -1) so we end up in an infinite loop because of that.
So we need to limit this case to GIMPLE level only.

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

PR tree-optimization/103314

gcc/ChangeLog:

* match.pd ((type) X op CST): Restrict the equal
TYPE_PRECISION case to GIMPLE only.

gcc/testsuite/ChangeLog:

* gcc.c-torture/compile/pr103314-1.c: New test.

2 years agoFix IPA modref ubsan.
Martin Liska [Thu, 18 Nov 2021 12:14:25 +0000 (13:14 +0100)]
Fix IPA modref ubsan.

modref_tree<tree_node*>::merge(modref_tree<tree_node*>*, vec<modref_parm_map, va_heap, vl_ptr>*, modref_parm_map*, bool)

is called with modref_parm_map chain_map;

The variable has uninitialized m.parm_offset_known and it is accessed
here:

gcc/ipa-modref-tree.h:572 a.parm_offset_known &= m.parm_offset_known;

PR ipa/103230

gcc/ChangeLog:

* ipa-modref-tree.h (struct modref_parm_map): Add default
constructor.
* ipa-modref.c (ipa_merge_modref_summary_after_inlining): Use it.

2 years agoc++/103326 - fix ICE in tsubst with VECTOR_CST
Richard Biener [Fri, 19 Nov 2021 07:54:18 +0000 (08:54 +0100)]
c++/103326 - fix ICE in tsubst with VECTOR_CST

This adds missing handling of VECTOR_CST.

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

PR c++/103326
* pt.c (tsubst_copy): Handle VECTOR_CST.

* g++.dg/pr103326.C: New testcase.

2 years agoc++: Fix up -fstrong-eval-order handling of call arguments [PR70796]
Jakub Jelinek [Fri, 19 Nov 2021 09:05:01 +0000 (10:05 +0100)]
c++: Fix up -fstrong-eval-order handling of call arguments [PR70796]

For -fstrong-eval-order (default for C++17 and later) we make sure to
gimplify arguments in the right order, but as the following testcase
shows that is not enough.
The problem is that some lvalues can satisfy the is_gimple_val / fb_rvalue
predicate used by gimplify_arg for is_gimple_reg_type typed expressions,
or is_gimple_lvalue / fb_either used for other types.
E.g. in foo we have:
  C::C (&p,  ++i,  ++i)
before gimplification where i is an automatic int variable and without this
patch gimplify that as:
  i = i + 1;
  i = i + 1;
  C::C (&p, i, i);
which means that the ctor is called with the original i value incremented
by 2 in both arguments, while because the call is CALL_EXPR_ORDERED_ARGS
the first argument should be different.  Similarly in qux we have:
  B::B (&p, TARGET_EXPR <D.2274, *(const struct A &) A::operator++ (&i)>,
        TARGET_EXPR <D.2275, *(const struct A &) A::operator++ (&i)>)
and gimplify it as:
      _1 = A::operator++ (&i);
      _2 = A::operator++ (&i);
      B::B (&p, MEM[(const struct A &)_1], MEM[(const struct A &)_2]);
but because A::operator++ returns the passed in argument, again we have
the same value in both cases due to gimplify_arg doing:
      /* Also strip a TARGET_EXPR that would force an extra copy.  */
      if (TREE_CODE (*arg_p) == TARGET_EXPR)
        {
          tree init = TARGET_EXPR_INITIAL (*arg_p);
          if (init
              && !VOID_TYPE_P (TREE_TYPE (init)))
            *arg_p = init;
        }
which is perfectly fine optimization for calls with unordered arguments,
but breaks the ordered ones.
Lastly, in corge, we have before gimplification:
  D::foo (NON_LVALUE_EXPR <p>, 3,  ++p)
and gimplify it as
  p = p + 4;
  D::foo (p, 3, p);
which is again wrong, because the this argument isn't before the
side-effects but after it.
The following patch adds cp_gimplify_arg wrapper, which if ordered
and is_gimple_reg_type forces non-SSA_NAME is_gimple_variable
result into a temporary, and if ordered, not is_gimple_reg_type
and argument is TARGET_EXPR bypasses the gimplify_arg optimization.
So, in foo with this patch we gimplify it as:
  i = i + 1;
  i.0_1 = i;
  i = i + 1;
  C::C (&p, i.0_1, i);
in qux as:
      _1 = A::operator++ (&i);
      D.2312 = MEM[(const struct A &)_1];
      _2 = A::operator++ (&i);
      B::B (&p, D.2312, MEM[(const struct A &)_2]);
where D.2312 is a temporary and in corge as:
  p.9_1 = p;
  p = p + 4;
  D::foo (p.9_1, 3, p);
The is_gimple_reg_type forcing into a temporary should be really cheap
(I think even at -O0 it should be optimized if there is no modification in
between), the aggregate copies might be more expensive but I think e.g. SRA
or FRE should be able to deal with those if there are no intervening
changes.  But still, the patch tries to avoid those when it is cheaply
provable that nothing bad happens (if no argument following it in the
strong evaluation order doesn't have TREE_SIDE_EFFECTS, then even VAR_DECLs
etc. shouldn't be modified after it).  There is also an optimization to
avoid doing that for this or for arguments with reference types as nothing
can modify the parameter values during evaluation of other argument's
side-effects.

I've tried if e.g.
  int i = 1;
  return i << ++i;
doesn't suffer from this problem as well, but it doesn't, the FE uses
  SAVE_EXPR <i>, SAVE_EXPR <i> << ++i;
in that case which gimplifies the way we want (temporary in the first
operand).

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

PR c++/70796
* cp-gimplify.c (cp_gimplify_arg): New function.
(cp_gimplify_expr): Use cp_gimplify_arg instead of gimplify_arg,
pass true as last argument to it if there are any following
arguments in strong evaluation order with side-effects.

* g++.dg/cpp1z/eval-order11.C: New test.

2 years agolibstdc++: Fix ctype changed after newlib update.
Tamar Christina [Fri, 19 Nov 2021 08:48:11 +0000 (08:48 +0000)]
libstdc++: Fix ctype changed after newlib update.

Newlib changed ctype.h recently[1] by moving the short labels from ctype.h intro
the private namespace in ctype_.h.  This broke embedded builds due to them no
longer being found.  Instead they now expose the long names to match glibc.

This patch now uses the short or long names depending on is the short ones are
defined or not.

[1] https://github.com/bminor/newlib/commit/3ba1bd0d9dbc015c14a0aaafcef042f706d1249a

libstdc++-v3/ChangeLog:

PR libstdc++/103305
* config/os/newlib/ctype_base.h (upper, lower, alpha, digit, xdigit,
space, print, graph, cntrl, punct, alnum, blank): Use short or long
names depending on if short ones are defined.

2 years agomiddle-end/103248 - fix RDIV_EXPR handling with fixed point
Richard Biener [Tue, 16 Nov 2021 10:47:26 +0000 (11:47 +0100)]
middle-end/103248 - fix RDIV_EXPR handling with fixed point

This fixes the previous adjustment to operation_could_trap_helper_p
where I failed to realize that RDIV_EXPR is also used for
fixed-point types.  It also fixes that handling by properly
checking for a fixed_zerop divisor.

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

PR middle-end/103248
* tree-eh.c (operation_could_trap_helper_p): Properly handle
fixed-point RDIV_EXPR.

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

2 years agotree-optimization/102436 - restore loop store motion
Richard Biener [Thu, 18 Nov 2021 12:40:32 +0000 (13:40 +0100)]
tree-optimization/102436 - restore loop store motion

This restores a case of conditional store motion we fail to handle
after the rewrite.  We can recognize the special case of all
stores in a loop happening in a single conditionally executed
block which ensures stores are not re-ordered by executing them
in different loop iterations.  Separating out the case avoids
complicating the already complex main path.

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

PR tree-optimization/102436
* tree-ssa-loop-im.c (execute_sm_if_changed): Add mode
to just create the if structure and return the then block.
(execute_sm): Add flag to indicate the var will re-use
another flag var.
(hoist_memory_references): Support a single conditional
block with all stores as special case.

* gcc.dg/torture/20211118-1.c: New testcase.
* gcc.dg/tree-ssa/ssa-lim-18.c: Likewise.

2 years agoFix PR 103317, ICE after PHI-OPT, minmax_replacement producing invalid SSA
Andrew Pinski [Thu, 18 Nov 2021 23:38:30 +0000 (23:38 +0000)]
Fix PR 103317, ICE after PHI-OPT, minmax_replacement producing invalid SSA

The problem is r12-5300-gf98f373dd822b35c allows phiopt to recognize more basic blocks
but missed one location where the basic block does not need to be empty but still
needs to have a single predecessor. This patch fixes that over sight.

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

PR tree-optimization/103317

gcc/ChangeLog:

* tree-ssa-phiopt.c (minmax_replacement): For the non empty
middle bb case, check to make sure it has a single predecessor.

gcc/testsuite/ChangeLog:

* gcc.c-torture/compile/pr103317-1.c: New test.

2 years agoFix tree-optimization/103257: Missed jump threading due too early conversion of bool...
Andrew Pinski [Tue, 16 Nov 2021 04:46:21 +0000 (04:46 +0000)]
Fix tree-optimization/103257: Missed jump threading due too early conversion of bool*A into bool?A:0

So like many optimizations on the gimple level, sometimes it makes sense to do the
optimization early or later. In this case, creating a cond expression early causes
other optimizations to be missed.  So just disable it until canonicalize_math_p ()
is false.

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

PR tree-optimization/103257

gcc/ChangeLog:

* match.pd
((m1 >/</>=/<= m2) * d -> (m1 >/</>=/<= m2) ? d : 0):
Disable until !canonicalize_math_p ().

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/vrp116.c: Check optimized instead of vrp1.
* gcc.dg/tree-ssa/pr103257-1.c: New test.

2 years agoc++: Implement -Wuninitialized for mem-initializers (redux) [PR19808]
Marek Polacek [Wed, 11 Nov 2020 01:07:24 +0000 (20:07 -0500)]
c++: Implement -Wuninitialized for mem-initializers (redux) [PR19808]

2021 update: Last year I posted a version of this patch:
<https://gcc.gnu.org/pipermail/gcc-patches/2020-November/559162.html>
but it didn't make it in.  The main objection seemed to be that the
patch tried to do too much, and overlapped with the ME uninitialized
warnings.  Since the patch used walk_tree without any data flow info,
it issued false positives for things like a(0 ? b : 42) and similar.

I'll admit I've been dreading resurrecting this because of the lack
of clarity about where we should warn about what.  On the other hand,
I think we really should do something about this.  So I've simplified
the original patch as much as it seemed reasonable.  For instance, it
doesn't even attempt to handle cases like "a((b = 42)), c(b)" -- for
these I simply give up for the whole mem-initializer (but who writes
code like that, anyway?).  I also give up when a member is initialized
with a function call, because we don't know what the call could do.
See Wuninitialized-17.C, for which clang emits a false positive but
we don't.  I remember having a hard time dealing with initializer lists
in my previous patch, so now I only handle simple a{b} cases, but no
more.  It turned out that this abridged version still warns about 90%
cases where users would expect a warning.

More complicated cases are left for the ME, which, for unused inline
functions, will only warn with -fkeep-inline-functions, but so be it.
(This is bug 21678.)

This patch implements the long-desired -Wuninitialized warning for
member initializer lists, so that the front end can detect bugs like

  struct A {
    int a;
    int b;
    A() : b(1), a(b) { }
  };

where the field 'b' is used uninitialized because the order of member
initializers in the member initializer list is irrelevant; what matters
is the order of declarations in the class definition.

I've implemented this by keeping a hash set holding fields that are not
initialized yet, so at first it will be {a, b}, and after initializing
'a' it will be {b} and so on.  Then I use walk_tree to walk the
initializer and if we see that an uninitialized object is used, we warn.
Of course, when we use the address of the object, we may not warn:

  struct B {
    int &r;
    int *p;
    int a;
    B() : r(a), p(&a), a(1) { } // ok
  };

Likewise, don't warn in unevaluated contexts such as sizeof.  Classes
without an explicit initializer may still be initialized by their
default constructors; whether or not something is considered initialized
is handled in perform_member_init, see member_initialized_p.

PR c++/19808
PR c++/96121

gcc/cp/ChangeLog:

* init.c (perform_member_init): Remove a forward declaration.
Walk the initializer using find_uninit_fields_r.  New parameter
to track uninitialized fields.  If a member is initialized,
remove it from the hash set.
(perform_target_ctor): Return the initializer.
(struct find_uninit_data): New class.
(find_uninit_fields_r): New function.
(find_uninit_fields): New function.
(emit_mem_initializers): Keep and initialize a set holding fields
that are not initialized.  When handling delegating constructors,
walk the constructor tree using find_uninit_fields_r.  Also when
initializing base clases.  Pass uninitialized down to
perform_member_init.

gcc/ChangeLog:

* doc/invoke.texi: Update documentation for -Wuninitialized.
* tree.c (stabilize_reference): Set location.

gcc/testsuite/ChangeLog:

* g++.dg/warn/Wuninitialized-14.C: New test.
* g++.dg/warn/Wuninitialized-15.C: New test.
* g++.dg/warn/Wuninitialized-16.C: New test.
* g++.dg/warn/Wuninitialized-17.C: New test.
* g++.dg/warn/Wuninitialized-18.C: New test.
* g++.dg/warn/Wuninitialized-19.C: New test.
* g++.dg/warn/Wuninitialized-20.C: New test.
* g++.dg/warn/Wuninitialized-21.C: New test.
* g++.dg/warn/Wuninitialized-22.C: New test.
* g++.dg/warn/Wuninitialized-23.C: New test.
* g++.dg/warn/Wuninitialized-24.C: New test.
* g++.dg/warn/Wuninitialized-25.C: New test.
* g++.dg/warn/Wuninitialized-26.C: New test.
* g++.dg/warn/Wuninitialized-27.C: New test.
* g++.dg/warn/Wuninitialized-28.C: New test.
* g++.dg/warn/Wuninitialized-29.C: New test.
* g++.dg/warn/Wuninitialized-30.C: New test.

2 years agoReduce cost of aligned sse register store.
liuhongt [Sat, 9 Oct 2021 01:42:10 +0000 (09:42 +0800)]
Reduce cost of aligned sse register store.

Make them be equal to cost of unaligned ones to avoid odd alignment
peeling.

Impact for SPEC2017 on CLX:
fprate:
  503.bwaves_r    BuildSame
  507.cactuBSSN_r     -0.22
  508.namd_r          -0.02
  510.parest_r        -0.28
  511.povray_r        -0.20
  519.lbm_r       BuildSame
  521.wrf_r           -0.58
  526.blender_r       -0.30
  527.cam4_r           1.07
  538.imagick_r        0.01
  544.nab_r           -0.09
  549.fotonik3d_r BuildSame
  554.roms_r      BuildSame
intrate:
  500.perlbench_r     -0.25
  502.gcc_r           -0.15
  505.mcf_r       BuildSame
  520.omnetpp_r        1.03
  523.xalancbmk_r     -0.13
  525.x264_r          -0.05
  531.deepsjeng_r     -0.27
  541.leela_r         -0.24
  548.exchange2_r     -0.06
  557.xz_r            -0.10
  999.specrand_ir      2.69

gcc/ChangeLog:

PR target/102543
* config/i386/x86-tune-costs.h (skylake_cost): Reduce cost of
storing 256/512-bit SSE register to be equal to cost of
unaligned store to avoid odd alignment peeling.
(icelake_cost): Ditto.

gcc/testsuite/ChangeLog:

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

2 years agoc++: implicit dummy object in requires clause [PR103198]
Patrick Palka [Fri, 19 Nov 2021 00:32:22 +0000 (19:32 -0500)]
c++: implicit dummy object in requires clause [PR103198]

In the testcase below satisfaction misbehaves for f and g ultimately
because find_template_parameters fails to notice that the constraint
'val.x' depends on the template parms of the class template.  In
contrast, satisfaction works just fine for h.

The problem seems to come down to a difference in how any_template_parm_r
handles 'this' vs a dummy object: it walks the TREE_TYPE of the former
but not the latter, and this causes us to miss the tparm dependencies in
f/g's constraints since in their case the implicit object parm through
which we access 'val' is a dummy object.  (For h, since we know it's a
non-static member function when parsing its trailing constraints, the
implicit object parm is 'this', not a dummy object.)

This patch fixes this inconsistency by making any_template_parm_r walk
into the TREE_TYPE of a dummy object, like it already does for 'this'.

PR c++/103198

gcc/cp/ChangeLog:

* pt.c (any_template_parm_r): Walk the TREE_TYPE of a dummy
object.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/concepts-this1.C: New test.

2 years agoDaily bump.
GCC Administrator [Fri, 19 Nov 2021 00:16:34 +0000 (00:16 +0000)]
Daily bump.

2 years agod: Use HOST_WIDE_INT for type size temporaries.
Iain Buclaw [Thu, 18 Nov 2021 21:43:40 +0000 (22:43 +0100)]
d: Use HOST_WIDE_INT for type size temporaries.

These variables are later used as the value for the format specifier
`%wd`, which the expected type may not match dinteger_t, causing
unnecessary -Wformat warnings.

gcc/d/ChangeLog:

* decl.cc (d_finish_decl): Use HOST_WIDE_INT for type size
temporaries.

2 years agoc++: Implement C++23 P0849R8 - auto(x) [PR103049]
Marek Polacek [Wed, 3 Nov 2021 15:04:22 +0000 (11:04 -0400)]
c++: Implement C++23 P0849R8 - auto(x) [PR103049]

This patch implements P0849R8 which allows auto in a functional cast,
the result of which is a prvalue.

[expr.type.conv]/1 says that the type is determined by placeholder type
deduction.  We only accept 'auto', not 'decltype(auto)' -- that the
type shall be auto comes from [dcl.type.auto.deduct].  Therefore the
rules are like for [temp.deduct.call], deducing template arguments from
a function call, so the result type will never be a reference, and we
decay arrays/functions.

PR c++/103049

gcc/cp/ChangeLog:

* semantics.c (finish_compound_literal): Accept C++23 auto{x}.
* typeck2.c (build_functional_cast_1): Accept C++23 auto(x).

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/auto25.C: Adjust dg-error.
* g++.dg/cpp0x/auto9.C: Likewise.
* g++.dg/cpp2a/concepts-pr84979-2.C: Likewise.
* g++.dg/cpp2a/concepts-pr84979-3.C: Likewise.
* g++.dg/cpp23/auto-fncast1.C: New test.
* g++.dg/cpp23/auto-fncast2.C: New test.
* g++.dg/cpp23/auto-fncast3.C: New test.
* g++.dg/cpp23/auto-fncast4.C: New test.
* g++.dg/cpp23/auto-fncast5.C: New test.
* g++.dg/cpp23/auto-fncast6.C: New test.

2 years agoFix rs6000 predicates.md use of decl_replaceable_p
David Edelsohn [Thu, 18 Nov 2021 18:43:22 +0000 (13:43 -0500)]
Fix rs6000 predicates.md use of decl_replaceable_p

gcc/ChangeLog:

* config/rs6000/predicates.md (current_file_function_operand):
Add flag_semantic_interposition to call of decl_replaceable_p.

2 years agoFortran: NULL() is not interoperable
Harald Anlauf [Wed, 17 Nov 2021 21:21:24 +0000 (22:21 +0100)]
Fortran: NULL() is not interoperable

gcc/fortran/ChangeLog:

PR fortran/101329
* check.c (is_c_interoperable): Reject NULL() as it is not
interoperable.

gcc/testsuite/ChangeLog:

PR fortran/101329
* gfortran.dg/pr101329.f90: New test.

Co-authored-by: Steven G. Kargl <kargl@gcc.gnu.org>
2 years agoIPA: fix reproducibility in IPA MOD REF
Martin Liska [Thu, 18 Nov 2021 16:50:19 +0000 (17:50 +0100)]
IPA: fix reproducibility in IPA MOD REF

gcc/ChangeLog:

* ipa-modref.c (analyze_function): Do not execute the code
only if dump_file != NULL.

2 years agoIPA: use cgraph_node instance
Martin Liska [Thu, 18 Nov 2021 16:39:23 +0000 (17:39 +0100)]
IPA: use cgraph_node instance

gcc/ChangeLog:

* ipa-modref.c (analyze_function): Use fnode instead of repeated
cgraph_node::get (current_function_decl).

2 years agoc++: error recovery during C++20 template-id ADL failure
Patrick Palka [Thu, 18 Nov 2021 18:10:28 +0000 (13:10 -0500)]
c++: error recovery during C++20 template-id ADL failure

When diagnosing ADL failure we try to perform a second unqualified
lookup for backwards compatibility with legacy code (via -fpermissive),
and for better diagnostics.

But for C++20 template-id ADL, the backwards compatibility code
sometimes causes confusing subsequent diagnostics such as in the
testcase below where we end up diagnosing deduction failure after
emitting the helpful "no declarations were found by ADL".  This happens
because the code just discards the arguments of the template-id callee
when replacing it with the later-declared template, which leads to
overload resolution failure:

  <stdin>: In instantiation of ‘void f() [with T = int]’:
  <stdin>:12:22:   required from here
  <stdin>:5:9: error: ‘g’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
  <stdin>:10:6: note: ‘template<class T> void g(int)’ declared here, later in the translation unit
  <stdin>:5:9: error: no matching function for call to ‘g(int)’
  <stdin>:10:6: note: candidate: ‘template<class T> void g(int)’
  <stdin>:10:6: note:   template argument deduction/substitution failed:
  <stdin>:5:9: note:   couldn’t deduce template parameter ‘T’

So for C++20 template-id ADL, this patch disables the backwards
compatibility code while keeping the helpful "no declarations were
found by ADL" diagnostic.

gcc/cp/ChangeLog:

* pt.c (tsubst_copy_and_build) <case CALL_EXPR>: Disable the
-fpermissive fallback for C++20 template-id ADL, but keep the
diagnostic.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/fn-template25.C: New test.

2 years agoTurn -fsemantic-interposition to optimization flag
Jan Hubicka [Thu, 18 Nov 2021 17:42:35 +0000 (18:42 +0100)]
Turn -fsemantic-interposition to optimization flag

Turn flag_semantic_interposition to optimization option so it can be enabled
with per-function granuality.  This is done by adding the flag among visibility
flags into the symbol table.

gcc/ChangeLog:

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

* cgraph.c (cgraph_node::get_availability): Update call of
decl_replaceable_p.
(cgraph_node::verify_node): Verify that semantic_interposition flag
is set correclty.
* cgraph.h: (symtab_node): Add semantic_interposition flag.
* cgraphclones.c (set_new_clone_decl_and_node_flags): Clear
semantic_interposition flag.
* cgraphunit.c (cgraph_node::finalize_function): Set
semantic_interposition flag.
(cgraph_node::add_new_function): Likewise.
(varpool_node::finalize_decl): Likewise.
(cgraph_node::create_wrapper): Likewise.
* common.opt (fsemantic-interposition): Turn to optimization node.
* lto-cgraph.c (lto_output_node): Stream semantic_interposition.
(lto_output_varpool_node): Likewise.
(input_overwrite_node): Likewise.
(input_varpool_node): Likewise.
* symtab.c (symtab_node::dump_base): Dump new flag.
* varasm.c (decl_replaceable_p): Add semantic_interposition_p
parameter.
* varasm.h (decl_replaceable_p): Update declaration.
* varpool.c (varpool_node::ctor_useable_for_folding_p):
Use semantic_interposition flag.
(varpool_node::get_availability): Likewise.
(varpool_node::create_alias): Copy semantic_interposition flag.

gcc/cp/ChangeLog:

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

* decl.c (finish_function): Update use of decl_replaceable_p.

gcc/lto/ChangeLog:

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

* lto-partition.c (promote_symbol): Clear semantic_interposition flag.

gcc/testsuite/ChangeLog:

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

* gcc.dg/lto/semantic-interposition-1_0.c: New test.
* gcc.dg/lto/semantic-interposition-1_1.c: New test.

2 years agoFix modref wrt __builtin_assume_aligned
Jan Hubicka [Thu, 18 Nov 2021 17:41:43 +0000 (18:41 +0100)]
Fix modref wrt __builtin_assume_aligned

__builtin_assume_aligned has bit contraictionary fnspec description "1cX "
which means that parameter 1 is returned but also unused.  PTA code takes
precedence to parameter being returned, while modref takes the info that
parameter is unused.  This patch tweaks modref to follow PTA semantics (as
suggested by Richard in the PR log)

gcc/ChangeLog:

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

PR ipa/103266
* ipa-modref.c (modref_eaf_analysis::merge_call_lhs_flags): Unused
parameter may still be returned.
(modref_eaf_analysis::analyze_ssa_name): Call merge_call_lhs_flags
even for unused function args.

gcc/testsuite/ChangeLog:

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

PR ipa/103266
* g++.dg/torture/pr103266.C: New test.

2 years agomiddle-end: check that both sides of complex expression is a mul.
Tamar Christina [Thu, 18 Nov 2021 17:10:36 +0000 (17:10 +0000)]
middle-end: check that both sides of complex expression is a mul.

Both sides of the VEC_PERM_EXPR need to be a MULT but the check
was accidentally checking if both sides are a mul.

The FMS case would be handled by the validate_multiplication but
this makes the requirement more explicit and we exit earlier.

gcc/ChangeLog:

PR tree-optimization/103311
* tree-vect-slp-patterns.c (complex_mul_pattern::matches,
complex_fms_pattern::matches): Check for multiplications.

gcc/testsuite/ChangeLog:

PR tree-optimization/103311
* gcc.target/aarch64/pr103311.c: New test.

2 years agox86: Add -mindirect-branch-cs-prefix
H.J. Lu [Wed, 27 Oct 2021 13:27:15 +0000 (06:27 -0700)]
x86: Add -mindirect-branch-cs-prefix

Add -mindirect-branch-cs-prefix to add CS prefix to call and jmp to
indirect thunk with branch target in r8-r15 registers so that the call
and jmp instruction length is 6 bytes to allow them to be replaced with
"lfence; call *%r8-r15" or "lfence; jmp *%r8-r15" at run-time.

gcc/

PR target/102952
* config/i386/i386.c (ix86_output_jmp_thunk_or_indirect): Emit
CS prefix for -mindirect-branch-cs-prefix.
(ix86_output_indirect_branch_via_reg): Likewise.
* config/i386/i386.opt: Add -mindirect-branch-cs-prefix.
* doc/invoke.texi: Document -mindirect-branch-cs-prefix.

gcc/testsuite/

PR target/102952
* gcc.target/i386/indirect-thunk-cs-prefix-1.c: New test.
* gcc.target/i386/indirect-thunk-cs-prefix-2.c: Likewise.

2 years agolibstdc++: Fix std::char_traits<C>::move for constexpr
Jonathan Wakely [Thu, 18 Nov 2021 12:39:20 +0000 (12:39 +0000)]
libstdc++: Fix std::char_traits<C>::move for constexpr

The constexpr branch in __gnu_cxx::char_traits::move compares the string
arguments to see if they overlap, but relational comparisons between
unrelated pointers are not core constant expressions.

I want to replace the comparisons with a loop using pointer equality to
determine whether the end of the source string is in the destination
string. However, that doesn't work with GCC, due to PR c++/89074 so
allocate a temporary buffer instead and copy out into that first, so
that overlapping source and destination don't matter. The allocation
isn't supported by the current Intel icc so use the loop as a fallback.

libstdc++-v3/ChangeLog:

* include/bits/char_traits.h (__gnu_cxx::char_traits::move):
Do not compare unrelated pointers during constant evaluation.
* testsuite/21_strings/char_traits/requirements/constexpr_functions_c++20.cc:
Improve tests for char_traits::move.

2 years agoFix MIPS test after recent match.pd changes
Jeff Law [Thu, 18 Nov 2021 15:47:21 +0000 (10:47 -0500)]
Fix MIPS test after recent match.pd changes

gcc/testsuite
* gcc.target/mips/octeon-bbit-1.c (f3): Add noipa attribute.

2 years agoFix typo.
David Edelsohn [Thu, 18 Nov 2021 15:20:12 +0000 (10:20 -0500)]
Fix typo.

libgomp/ChangeLog:

* alloc.c (gomp_aligned_alloc): Fix typo.

2 years agoc++: template-id ADL and partial instantiation [PR99911]
Patrick Palka [Thu, 18 Nov 2021 15:05:13 +0000 (10:05 -0500)]
c++: template-id ADL and partial instantiation [PR99911]

Here when partially instantiating the call get<U>(T{}) with T=N::A
(for which earlier unqualified name lookup for 'get' found nothing)
the arguments after substitution are no longer dependent but the callee
still is, so perform_koenig_lookup postpones ADL.  But then we go on to
diagnose the unresolved template name anyway, as if ADL was already
performed and failed.

This patch fixes this by avoiding the error path in question when the
template arguments of an unresolved template-id are still dependent,
mirroring the dependence check in perform_koenig_lookup.

PR c++/99911

gcc/cp/ChangeLog:

* pt.c (tsubst_copy_and_build) <case CALL_EXPR>: Don't diagnose
name lookup failure if the arguments to an unresolved template
name are still dependent.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/fn-template24.C: New test.

2 years agoc++: unqual lookup performed twice w/ template-id ADL [PR102670]
Patrick Palka [Thu, 18 Nov 2021 15:04:27 +0000 (10:04 -0500)]
c++: unqual lookup performed twice w/ template-id ADL [PR102670]

Here we're incorrectly performing unqualified lookup of 'adl' again at
substitution time for the call adl<I>(t) (for which name lookup at parse
time found nothing) which causes us to reject the testcase because the
second unqualified lookup finds the later-declared variable template
'adl', leading to confusion.  Fixed thusly.

The testcase concepts-recursive-sat1.C needed to be adjusted to use ADL
proper instead of relying on this incorrect second unqualified lookup.

PR c++/102670

gcc/cp/ChangeLog:

* pt.c (tsubst_copy_and_build) <case CALL_EXPR>: When looking
for an identifier callee in the koenig_p case, also look through
TEMPLATE_ID_EXPR.  Use tsubst_copy to substitute through the
template arguments of the template-id.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/concepts-recursive-sat1.C: Adjust to use ADL
proper.
* g++.dg/cpp2a/fn-template23.C: New test.

2 years agoaix: detect power10 processor.
David Edelsohn [Wed, 17 Nov 2021 18:26:36 +0000 (13:26 -0500)]
aix: detect power10 processor.

For -mcpu=native, GCC needs to detect the processor.  This
patch adds the processor value for Power10.

Suggested by Kevin Alder.

* config/rs6000/driver-rs6000.c (detect_processor_aix): Add
power10.

2 years agolibstdc++: Replace AC_CACHE_VAL with AC_CACHE_CHECK
Jonathan Wakely [Wed, 17 Nov 2021 20:14:52 +0000 (20:14 +0000)]
libstdc++: Replace AC_CACHE_VAL with AC_CACHE_CHECK

This replaces most uses of AC_CACHE_VAL with AC_CACHE_CHECK, which means
we don't need separate AC_MSG_CHECKING and AC_MSG_RESULT macros.

There are a few trivial bugs fixed as a side effect, where an
AC_MSG_RESULT was printed out even if the actual checks hadn't been
done. That didn't affect the results, only the content of config.log.

libstdc++-v3/ChangeLog:

* acinclude.m4: Replace AC_CACHE_VAL with AC_CACHE_CHECK.
* configure: Regenerate.

2 years agomiddle-end: Fix FMA detection when inspecting gimple which have no LHS.
Tamar Christina [Thu, 18 Nov 2021 11:22:11 +0000 (11:22 +0000)]
middle-end: Fix FMA detection when inspecting gimple which have no LHS.

convert_mult_to_fma assumes that all gimple_assigns have a LHS set.  This
assumption is however not true when an IFN is kept around just for the
side-effects.  In those situations you have just the IFN and lhs will be null.

Since there's no LHS, there also can't be any ADD and such it can't be an FMA
so it's correct to just return early if no LHS.

gcc/ChangeLog:

PR tree-optimization/103253
* tree-ssa-math-opts.c (convert_mult_to_fma): Check for LHS.

gcc/testsuite/ChangeLog:

PR tree-optimization/103253
* gcc.dg/vect/pr103253.c: New test.

2 years agoc-family: Add __builtin_assoc_barrier
Matthias Kretz [Fri, 16 Jul 2021 08:46:24 +0000 (10:46 +0200)]
c-family: Add __builtin_assoc_barrier

New builtin to enable explicit use of PAREN_EXPR in C & C++ code.

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

* c-c++-common/builtin-assoc-barrier-1.c: New test.

gcc/cp/ChangeLog:

* constexpr.c (cxx_eval_constant_expression): Handle PAREN_EXPR
via cxx_eval_constant_expression.
* cp-objcp-common.c (names_builtin_p): Handle
RID_BUILTIN_ASSOC_BARRIER.
* cp-tree.h: Adjust TREE_LANG_FLAG documentation to include
PAREN_EXPR in REF_PARENTHESIZED_P.
(REF_PARENTHESIZED_P): Add PAREN_EXPR.
* parser.c (cp_parser_postfix_expression): Handle
RID_BUILTIN_ASSOC_BARRIER.
* pt.c (tsubst_copy_and_build): If the PAREN_EXPR is not a
parenthesized initializer, build a new PAREN_EXPR.
* semantics.c (force_paren_expr): Simplify conditionals. Set
REF_PARENTHESIZED_P on PAREN_EXPR.
(maybe_undo_parenthesized_ref): Test PAREN_EXPR for
REF_PARENTHESIZED_P.

gcc/c-family/ChangeLog:

* c-common.c (c_common_reswords): Add __builtin_assoc_barrier.
* c-common.h (enum rid): Add RID_BUILTIN_ASSOC_BARRIER.

gcc/c/ChangeLog:

* c-decl.c (names_builtin_p): Handle RID_BUILTIN_ASSOC_BARRIER.
* c-parser.c (c_parser_postfix_expression): Likewise.

gcc/ChangeLog:

* doc/extend.texi: Document __builtin_assoc_barrier.

2 years agolibsanitizer: Fix bootstrap on FreeBSD [PR102675]
Jakub Jelinek [Thu, 18 Nov 2021 09:06:01 +0000 (10:06 +0100)]
libsanitizer: Fix bootstrap on FreeBSD [PR102675]

Here is an alternative to the patch changing a file imported from
compiler-rt upstream, so that we don't need to cary a local patch for that
particular problem.

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

PR bootstrap/102675
* sanitizer_common/Makefile.am: Use -DUSE_SYSTEM_MD5 in AM_CXXFLAGS
of sanitizer_platform_limits_freebsd.cpp.
* sanitizer_common/Makefile.in: Regenerated.

2 years agoRemove MAY_HAVE_DEBUG_MARKER_STMTS and MAY_HAVE_DEBUG_BIND_STMTS.
Martin Liska [Fri, 15 Oct 2021 14:34:34 +0000 (16:34 +0200)]
Remove MAY_HAVE_DEBUG_MARKER_STMTS and MAY_HAVE_DEBUG_BIND_STMTS.

The macros correspond 1:1 to an option flags and make it harder
to find all usages of the flags.

gcc/c-family/ChangeLog:

* c-gimplify.c (genericize_c_loop): Use option directly.

gcc/c/ChangeLog:

* c-parser.c (add_debug_begin_stmt): Use option directly.

gcc/ChangeLog:

* cfgexpand.c (pass_expand::execute): Use option directly.
* function.c (allocate_struct_function): Likewise.
* gimple-low.c (lower_function_body): Likewise.
(lower_stmt): Likewise.
* gimple-ssa-backprop.c (backprop::prepare_change): Likewise.
* ipa-param-manipulation.c (ipa_param_adjustments::modify_call): Likewise.
* ipa-split.c (split_function): Likewise.
* lto-streamer-in.c (input_function): Likewise.
* sese.c (sese_insert_phis_for_liveouts): Likewise.
* ssa-iterators.h (num_imm_uses): Likewise.
* tree-cfg.c (make_blocks): Likewise.
(gimple_merge_blocks): Likewise.
* tree-inline.c (tree_function_versioning): Likewise.
* tree-loop-distribution.c (generate_loops_for_partition): Likewise.
* tree-sra.c (analyze_access_subtree): Likewise.
* tree-ssa-dce.c (remove_dead_stmt): Likewise.
* tree-ssa-loop-ivopts.c (remove_unused_ivs): Likewise.
* tree-ssa-phiopt.c (spaceship_replacement): Likewise.
* tree-ssa-reassoc.c (reassoc_remove_stmt): Likewise.
* tree-ssa-tail-merge.c (tail_merge_optimize): Likewise.
* tree-ssa-threadedge.c (propagate_threaded_block_debug_into): Likewise.
* tree-ssa.c (gimple_replace_ssa_lhs): Likewise.
(target_for_debug_bind): Likewise.
(insert_debug_temp_for_var_def): Likewise.
(insert_debug_temps_for_defs): Likewise.
(reset_debug_uses): Likewise.
* tree-ssanames.c (release_ssa_name_fn): Likewise.
* tree-vect-loop-manip.c (adjust_vec_debug_stmts): Likewise.
(adjust_debug_stmts): Likewise.
(adjust_phi_and_debug_stmts): Likewise.
(vect_do_peeling): Likewise.
* tree-vect-loop.c (vect_transform_loop_stmt): Likewise.
(vect_transform_loop): Likewise.
* tree.h (MAY_HAVE_DEBUG_MARKER_STMTS): Remove
(MAY_HAVE_DEBUG_BIND_STMTS): Remove.
(MAY_HAVE_DEBUG_STMTS): Use options directly.

gcc/cp/ChangeLog:

* parser.c (add_debug_begin_stmt): Use option directly.

2 years agotestsuite/103278 - adjust gcc.dg/tree-ssa/if-to-switch-3.c
Richard Biener [Thu, 18 Nov 2021 08:49:38 +0000 (09:49 +0100)]
testsuite/103278 - adjust gcc.dg/tree-ssa/if-to-switch-3.c

Analysis shows that after the CD-DCE change we produce better
code which makes if-to-switch run into case-values-threshold on
some architectures, thus the switch is deemed to simple to be
worth generating.  The following statically provides
--param case-values-threshold to make the testcase less
target dependent.

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

PR testsuite/103278
* gcc.dg/tree-ssa/if-to-switch-3.c: Supply
--param case-values-threshold=4.

2 years agotree-optimization/103277 - do abnormal cleanup after call DSE
Richard Biener [Thu, 18 Nov 2021 08:07:22 +0000 (09:07 +0100)]
tree-optimization/103277 - do abnormal cleanup after call DSE

We can now DSE calls in more cases which requires us to eventually
purge dead abnormal edges.  This implements this.

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

PR tree-optimization/103277
* tree-ssa-dse.c (need_ab_cleanup): New.
(dse_optimize_redundant_stores): Adjust.
(delete_dead_or_redundant_assignment): Get extra
need_ab_cleanup argument and set when abnormal cleanup is
needed.
(dse_optimize_call): Adjust.
(dse_optimize_stmt): Likewise.
(pass_dse::execute): Allocate and deallocate need_ab_cleanup.
Perform abnormal cleanup.
* tree-ssa-dse.h (delete_dead_or_redundant_assignment): Adjust.

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

2 years agoi386: Fix wrong codegen for -mrelax-cmpxchg-loop
Hongyu Wang [Thu, 18 Nov 2021 06:45:23 +0000 (14:45 +0800)]
i386: Fix wrong codegen for -mrelax-cmpxchg-loop

For -mrelax-cmpxchg-loop introduced by PR 103069/r12-5265, it would
produce infinite loop. The correct code should be

.L84:
        movl    (%rdi), %ecx
        movl    %eax, %edx
        orl     %esi, %edx
        cmpl    %eax, %ecx
        jne     .L82
        lock cmpxchgl   %edx, (%rdi)
        jne     .L84
movl    %r8d, %eax  <<< retval is missing in previous impl
ret
.L82:
        rep nop
        jmp     .L84

Adjust corresponding expander to fix such issue, and fix runtime test
so the problem would be exposed.

gcc/ChangeLog:

* config/i386/i386-expand.c (ix86_expand_atomic_fetch_op_loop):
Adjust generated cfg to avoid infinite loop.

gcc/testsuite/ChangeLog:

* gcc.target/i386/pr103069-2.c: Adjust.

2 years agolibgomp: Ensure that either gomp_team is properly aligned [PR102838]
Jakub Jelinek [Thu, 18 Nov 2021 08:10:40 +0000 (09:10 +0100)]
libgomp: Ensure that either gomp_team is properly aligned [PR102838]

struct gomp_team has struct gomp_work_share array inside of it.
If that latter structure has 64-byte aligned member in the middle,
the whole struct gomp_team needs to be 64-byte aligned, but we weren't
allocating it using gomp_aligned_alloc.

This patch fixes that, except that on gcn team_malloc is special, so
I've instead decided at least for now to avoid using aligned member
and use the padding instead on gcn.

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

PR libgomp/102838
* libgomp.h (GOMP_USE_ALIGNED_WORK_SHARES): Define if
GOMP_HAVE_EFFICIENT_ALIGNED_ALLOC is defined and __AMDGCN__ is not.
(struct gomp_work_share): Use GOMP_USE_ALIGNED_WORK_SHARES instead of
GOMP_HAVE_EFFICIENT_ALIGNED_ALLOC.
* work.c (alloc_work_share, gomp_work_share_start): Likewise.
* team.c (gomp_new_team): If GOMP_USE_ALIGNED_WORK_SHARES, use
gomp_aligned_alloc instead of team_malloc.

2 years agolibgomp: Fix up aligned_alloc arguments [PR102838]
Jakub Jelinek [Thu, 18 Nov 2021 08:07:31 +0000 (09:07 +0100)]
libgomp: Fix up aligned_alloc arguments [PR102838]

C says that aligned_alloc size must be an integral multiple of alignment.
While glibc doesn't care about it, apparently Solaris does.
So, this patch decreases the priority of aligned_alloc among the other
variants because it needs more work and can waste more memory and rounds
up the size to multiple of alignment.

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

PR libgomp/102838
* alloc.c (gomp_aligned_alloc): Prefer _aligned_alloc over
memalign over posix_memalign over aligned_alloc over fallback
with malloc instead of aligned_alloc over _aligned_alloc over
posix_memalign over memalign over fallback with malloc.  For
aligned_alloc, round up size up to multiple of al.

2 years agoi386: add alias for f*mul_*ch intrinsics
konglin1 [Wed, 10 Nov 2021 07:31:04 +0000 (15:31 +0800)]
i386: add alias for f*mul_*ch intrinsics

gcc/ChangeLog:

* config/i386/avx512fp16intrin.h (_mm512_mul_pch): Add alias for _mm512_fmul_pch.
(_mm512_mask_mul_pch): Likewise.
(_mm512_maskz_mul_pch): Likewise.
(_mm512_mul_round_pch): Likewise.
(_mm512_mask_mul_round_pch): Likewise.
(_mm512_maskz_mul_round_pch): Likewise.
(_mm512_cmul_pch): Likewise.
(_mm512_mask_cmul_pch): Likewise.
(_mm512_maskz_cmul_pch): Likewise.
(_mm512_cmul_round_pch): Likewise.
(_mm512_mask_cmul_round_pch): Likewise.
(_mm512_maskz_cmul_round_pch): Likewise.
(_mm_mul_sch): Likewise.
(_mm_mask_mul_sch): Likewise.
(_mm_maskz_mul_sch): Likewise.
(_mm_mul_round_sch): Likewise.
(_mm_mask_mul_round_sch): Likewise.
(_mm_maskz_mul_round_sch): Likewise.
(_mm_cmul_sch): Likewise.
(_mm_mask_cmul_sch): Likewise.
(_mm_maskz_cmul_sch): Likewise.
(_mm_cmul_round_sch): Likewise.
(_mm_mask_cmul_round_sch): Likewise.
(_mm_maskz_cmul_round_sch): Likewise.
* config/i386/avx512fp16vlintrin.h (_mm_mul_pch): Likewise.
(_mm_mask_mul_pch): Likewise.
(_mm_maskz_mul_pch): Likewise.
(_mm256_mul_pch): Likewise.
(_mm256_mask_mul_pch): Likewise.
(_mm256_maskz_mul_pch): Likewise.
(_mm_cmul_pch): Likewise.
(_mm_mask_cmul_pch): Likewise.
(_mm_maskz_cmul_pch): Likewise.
(_mm256_cmul_pch): Likewise.
(_mm256_mask_cmul_pch): Likewise.
(_mm256_maskz_cmul_pch): Likewise.

gcc/testsuite/ChangeLog:

* gcc.target/i386/avx512fp16-vfcmulcph-1a.c: Add new test for alias.
* gcc.target/i386/avx512fp16-vfcmulcsh-1a.c: Likewise.
* gcc.target/i386/avx512fp16-vfmulcph-1a.c: Likewise.
* gcc.target/i386/avx512fp16-vfmulcsh-1a.c: Likewise.
* gcc.target/i386/avx512fp16vl-vfcmulcph-1a.c: Likewise.
* gcc.target/i386/avx512fp16vl-vfmulcph-1a.c: Likewise.

2 years agoDaily bump.
GCC Administrator [Thu, 18 Nov 2021 00:16:34 +0000 (00:16 +0000)]
Daily bump.

2 years agoFix PR tree-optimization/103228 and 103228: folding of (type) X op CST where type...
Andrew Pinski [Mon, 15 Nov 2021 09:31:20 +0000 (09:31 +0000)]
Fix PR tree-optimization/103228 and 103228: folding of (type) X op CST where type is a nop convert

Currently we fold (type) X op CST into (type) (X op ((type-x) CST)) when the conversion widens
but not when the conversion is a nop. For the same reason why we move the widening conversion
(the possibility of removing an extra conversion), we should do the same if the conversion is a
nop.

Committed as approved with the comment change.

PR tree-optimization/103228
PR tree-optimization/55177

gcc/ChangeLog:

* match.pd ((type) X bitop CST): Also do this
transformation for nop conversions.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/pr103228-1.c: New test.
* gcc.dg/tree-ssa/pr55177-1.c: New test.

2 years agolibstdc++: Fix author name in ChangeLog
Jonathan Wakely [Wed, 17 Nov 2021 22:32:33 +0000 (22:32 +0000)]
libstdc++: Fix author name in ChangeLog

The constexpr std::string commit was my own work, but the commit still
had the author name from an earlier cherry-pick that eventually got
entirely reverted. This fixes the name in the ChangeLog file.

2 years agolibcpp: capture and underline ranges in -Wbidi-chars= [PR103026]
David Malcolm [Tue, 2 Nov 2021 19:45:22 +0000 (15:45 -0400)]
libcpp: capture and underline ranges in -Wbidi-chars= [PR103026]

This patch converts the bidi::vec to use a struct so that we can
capture location_t values for the bidirectional control characters.

Before:

  Wbidi-chars-1.c: In function ‘main’:
  Wbidi-chars-1.c:6:43: warning: unpaired UTF-8 bidirectional control character detected [-Wbidi-chars=]
      6 |     /*<U+202E> } <U+2066>if (isAdmin)<U+2069> <U+2066> begin admins only */
        |                                                                           ^
  Wbidi-chars-1.c:9:28: warning: unpaired UTF-8 bidirectional control character detected [-Wbidi-chars=]
      9 |     /* end admins only <U+202E> { <U+2066>*/
        |                                            ^

After:

  Wbidi-chars-1.c: In function ‘main’:
  Wbidi-chars-1.c:6:43: warning: unpaired UTF-8 bidirectional control characters detected [-Wbidi-chars=]
      6 |     /*<U+202E> } <U+2066>if (isAdmin)<U+2069> <U+2066> begin admins only */
        |       ~~~~~~~~                                ~~~~~~~~                    ^
        |       |                                       |                           |
        |       |                                       |                           end of bidirectional context
        |       U+202E (RIGHT-TO-LEFT OVERRIDE)         U+2066 (LEFT-TO-RIGHT ISOLATE)
  Wbidi-chars-1.c:9:28: warning: unpaired UTF-8 bidirectional control characters detected [-Wbidi-chars=]
      9 |     /* end admins only <U+202E> { <U+2066>*/
        |                        ~~~~~~~~   ~~~~~~~~ ^
        |                        |          |        |
        |                        |          |        end of bidirectional context
        |                        |          U+2066 (LEFT-TO-RIGHT ISOLATE)
        |                        U+202E (RIGHT-TO-LEFT OVERRIDE)

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
gcc/testsuite/ChangeLog:
PR preprocessor/103026
* c-c++-common/Wbidi-chars-ranges.c: New test.

libcpp/ChangeLog:
PR preprocessor/103026
* lex.c (struct bidi::context): New.
(bidi::vec): Convert to a vec of context rather than unsigned
char.
(bidi::ctx_at): Rename to...
(bidi::pop_kind_at): ...this and reimplement for above change.
(bidi::current_ctx): Update for change to vec.
(bidi::current_ctx_ucn_p): Likewise.
(bidi::current_ctx_loc): New.
(bidi::on_char): Update for usage of context struct.  Add "loc"
param and pass it when pushing contexts.
(get_location_for_byte_range_in_cur_line): New.
(get_bidi_utf8): Rename to...
(get_bidi_utf8_1): ...this, reintroducing...
(get_bidi_utf8): ...as a wrapper, setting *OUT when the result is
not NONE.
(get_bidi_ucn): Rename to...
(get_bidi_ucn_1): ...this, reintroducing...
(get_bidi_ucn): ...as a wrapper, setting *OUT when the result is
not NONE.
(class unpaired_bidi_rich_location): New.
(maybe_warn_bidi_on_close): Use unpaired_bidi_rich_location when
reporting on unpaired bidi chars.  Split into singular vs plural
spellings.
(maybe_warn_bidi_on_char): Pass in a location_t rather than a
const uchar * and use it when emitting warnings, and when calling
bidi::on_char.
(_cpp_skip_block_comment): Capture location when kind is not NONE
and pass it to maybe_warn_bidi_on_char.
(skip_line_comment): Likewise.
(forms_identifier_p): Likewise.
(lex_raw_string): Likewise.
(lex_string): Likewise.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2 years agolibcpp: escape non-ASCII source bytes in -Wbidi-chars= [PR103026]
David Malcolm [Tue, 2 Nov 2021 13:54:32 +0000 (09:54 -0400)]
libcpp: escape non-ASCII source bytes in -Wbidi-chars= [PR103026]

This flags rich_locations associated with -Wbidi-chars= so that
non-ASCII bytes will be escaped when printing the source lines
(using the diagnostics support I added in
r12-4825-gbd5e882cf6e0def3dd1bc106075d59a303fe0d1e).

In particular, this ensures that the printed source lines will
be pure ASCII, and thus the visual ordering of the characters
will be the same as the logical ordering.

Before:

  Wbidi-chars-1.c: In function ‘main’:
  Wbidi-chars-1.c:6:43: warning: unpaired UTF-8 bidirectional control character detected [-Wbidi-chars=]
      6 |     /*‮ } ⁦if (isAdmin)⁩ ⁦ begin admins only */
        |                                           ^
  Wbidi-chars-1.c:9:28: warning: unpaired UTF-8 bidirectional control character detected [-Wbidi-chars=]
      9 |     /* end admins only ‮ { ⁦*/
        |                            ^

  Wbidi-chars-11.c:6:15: warning: UTF-8 vs UCN mismatch when closing a context by "U+202C (POP DIRECTIONAL FORMATTING)" [-Wbidi-chars=]
      6 | int LRE_‪_PDF_\u202c;
        |               ^
  Wbidi-chars-11.c:8:19: warning: UTF-8 vs UCN mismatch when closing a context by "U+202C (POP DIRECTIONAL FORMATTING)" [-Wbidi-chars=]
      8 | int LRE_\u202a_PDF_‬_;
        |                   ^
  Wbidi-chars-11.c:10:28: warning: UTF-8 vs UCN mismatch when closing a context by "U+202C (POP DIRECTIONAL FORMATTING)" [-Wbidi-chars=]
     10 | const char *s1 = "LRE_‪_PDF_\u202c";
        |                            ^
  Wbidi-chars-11.c:12:33: warning: UTF-8 vs UCN mismatch when closing a context by "U+202C (POP DIRECTIONAL FORMATTING)" [-Wbidi-chars=]
     12 | const char *s2 = "LRE_\u202a_PDF_‬";
        |                                 ^

After:

  Wbidi-chars-1.c: In function ‘main’:
  Wbidi-chars-1.c:6:43: warning: unpaired UTF-8 bidirectional control character detected [-Wbidi-chars=]
      6 |     /*<U+202E> } <U+2066>if (isAdmin)<U+2069> <U+2066> begin admins only */
        |                                                                           ^
  Wbidi-chars-1.c:9:28: warning: unpaired UTF-8 bidirectional control character detected [-Wbidi-chars=]
      9 |     /* end admins only <U+202E> { <U+2066>*/
        |                                            ^

  Wbidi-chars-11.c:6:15: warning: UTF-8 vs UCN mismatch when closing a context by "U+202C (POP DIRECTIONAL FORMATTING)" [-Wbidi-chars=]
      6 | int LRE_<U+202A>_PDF_\u202c;
        |                       ^
  Wbidi-chars-11.c:8:19: warning: UTF-8 vs UCN mismatch when closing a context by "U+202C (POP DIRECTIONAL FORMATTING)" [-Wbidi-chars=]
      8 | int LRE_\u202a_PDF_<U+202C>_;
        |                   ^
  Wbidi-chars-11.c:10:28: warning: UTF-8 vs UCN mismatch when closing a context by "U+202C (POP DIRECTIONAL FORMATTING)" [-Wbidi-chars=]
     10 | const char *s1 = "LRE_<U+202A>_PDF_\u202c";
        |                                    ^
  Wbidi-chars-11.c:12:33: warning: UTF-8 vs UCN mismatch when closing a context by "U+202C (POP DIRECTIONAL FORMATTING)" [-Wbidi-chars=]
     12 | const char *s2 = "LRE_\u202a_PDF_<U+202C>";
        |                                 ^

libcpp/ChangeLog:
PR preprocessor/103026
* lex.c (maybe_warn_bidi_on_close): Use a rich_location
and call set_escape_on_output (true) on it.
(maybe_warn_bidi_on_char): Likewise.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2 years agoAvoid pathological function redeclarations when checking access sizes [PR102759].
Martin Sebor [Wed, 17 Nov 2021 22:09:23 +0000 (15:09 -0700)]
Avoid pathological function redeclarations when checking access sizes [PR102759].

Resolves:
PR tree-optimization/102759 - ICE: Segmentation fault in maybe_check_access_sizes since r12-2976-gb48d4e6818674898

gcc/ChangeLog:

PR tree-optimization/102759
* gimple-array-bounds.cc (build_printable_array_type): Move...
* gimple-ssa-warn-access.cc (build_printable_array_type): Avoid
pathological function redeclarations that remove a previously
declared prototype.
Improve formatting of function arguments in informational notes.
* pointer-query.cc (build_printable_array_type): ...to here.
* pointer-query.h (build_printable_array_type): Declared.

gcc/testsuite/ChangeLog:

PR tree-optimization/102759
* gcc.dg/Warray-parameter-10.c: New test.
* gcc.dg/Wstringop-overflow-82.c: New test.

2 years agox86: Add -mharden-sls=[none|all|return|indirect-branch]
H.J. Lu [Wed, 27 Oct 2021 14:48:54 +0000 (07:48 -0700)]
x86: Add -mharden-sls=[none|all|return|indirect-branch]

Add -mharden-sls= to mitigate against straight line speculation (SLS)
for function return and indirect branch by adding an INT3 instruction
after function return and indirect branch.

gcc/

PR target/102952
* config/i386/i386-opts.h (harden_sls): New enum.
* config/i386/i386.c (output_indirect_thunk): Mitigate against
SLS for function return.
(ix86_output_function_return): Likewise.
(ix86_output_jmp_thunk_or_indirect): Mitigate against indirect
branch.
(ix86_output_indirect_jmp): Likewise.
(ix86_output_call_insn): Likewise.
* config/i386/i386.opt: Add -mharden-sls=.
* doc/invoke.texi: Document -mharden-sls=.

gcc/testsuite/

PR target/102952
* gcc.target/i386/harden-sls-1.c: New test.
* gcc.target/i386/harden-sls-2.c: Likewise.
* gcc.target/i386/harden-sls-3.c: Likewise.
* gcc.target/i386/harden-sls-4.c: Likewise.
* gcc.target/i386/harden-sls-5.c: Likewise.

2 years agox86: Remove "%!" before ret
H.J. Lu [Wed, 17 Nov 2021 19:41:12 +0000 (11:41 -0800)]
x86: Remove "%!" before ret

Before MPX was removed, "%!" was mapped to

        case '!':
          if (ix86_bnd_prefixed_insn_p (current_output_insn))
            fputs ("bnd ", file);
          return;

After CET was added and MPX was removed, "%!" was mapped to

       case '!':
          if (ix86_notrack_prefixed_insn_p (current_output_insn))
            fputs ("notrack ", file);
          return;

ix86_notrack_prefixed_insn_p always returns false on ret since the
notrack prefix is only for indirect branches.  Remove the unused "%!"
before ret.

PR target/103307
* config/i386/i386.c (ix86_code_end): Remove "%!" before ret.
(ix86_output_function_return): Likewise.
* config/i386/i386.md (simple_return_pop_internal): Likewise.

2 years agoFix modref summary streaming
Jan Hubicka [Wed, 17 Nov 2021 21:04:26 +0000 (22:04 +0100)]
Fix modref summary streaming

Fixes bug in streaming in modref access tree that now cause a failure
of gamess benchmark.  The bug is quite old (present in GCC11 release) but it
needs quite interesting series of events to manifest. In particular
 1) At lto time ISRA turns some parameters passed by reference to scalar
 2) At lto time modref computes summaries for old parameters and then updates
    them but does so quite stupidly believing that the load from parameters
    are now unkonwn loads (rather than optimized out).
    This renders summary not very useful since it thinks every memory aliasing
    int is now accssed (as opposed as parameter dereference)
 3) At stream in we notice too early that summary is useless, set every_access
    flag and drop the list.  However while reading rest of the summary we
    overwrite the flag back to 0 which makes us to lose part of summary.
 4) right selection of partitions needs to be done to avoid late modref from
    recalculating and thus fixing the summary.

This patch fixes the stream in bug, however we also should fix updating of
summaries.

gcc/ChangeLog:

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

PR ipa/103246
* ipa-modref.c (read_modref_records): Fix streaminig in of every_access
flag.

2 years agoi386: Redefine indirect_thunks_used as HARD_REG_SET.
Uros Bizjak [Wed, 17 Nov 2021 19:47:48 +0000 (20:47 +0100)]
i386: Redefine indirect_thunks_used as HARD_REG_SET.

Change indirect_thunks_used to HARD_REG_SET to avoid recalculations
of correct register numbers and allow usage of SET/TEST_HARD_REG_BIT
accessors.

2021-11-17  Uroš Bizjak  <ubizjak@gmail.com>

gcc/ChangeLog:

* config/i386/i386.c (indirect_thunks_used): Redefine as HARD_REG_SET.
(ix86_code_end): Use TEST_HARD_REG_BIT on indirect_thunks_used.
(ix86_output_indirect_branch_via_reg): Use SET_HARD_REG_BIT
on indirect_thunks_used.
(ix86_output_indirect_function_return): Ditto.

2 years agoAdd very basic IPA part of modref-kill analysis
Jan Hubicka [Wed, 17 Nov 2021 19:40:44 +0000 (20:40 +0100)]
Add very basic IPA part of modref-kill analysis

gcc/ChangeLog:

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

* ipa-modref-tree.c: Include cgraph.h and tree-streamer.h.
(modref_access_node::stream_out): New member function.
(modref_access_node::stream_in): New member function.
* ipa-modref-tree.h (modref_access_node::stream_out,
modref_access_node::stream_in): Declare.
* ipa-modref.c (modref_summary_lto::useful_p): Free useless kills.
(modref_summary_lto::dump): Dump kills.
(analyze_store): Record kills for LTO
(analyze_stmt): Likewise.
(modref_summaries_lto::duplicate): Duplicate kills.
(write_modref_records): Use new stream_out member function.
(read_modref_records): Likewise.
(modref_write): Stream out kills.
(read_section): Stream in kills
(remap_kills): New function.
(update_signature): Use it.

2 years agoi386: Introduce LEGACY_SSE_REGNO_P predicate
Uros Bizjak [Wed, 17 Nov 2021 19:32:23 +0000 (20:32 +0100)]
i386: Introduce LEGACY_SSE_REGNO_P predicate

Introduce LEGACY_SSE_REGNO_P predicate to simplify a couple of places.

No functional changes.

2021-11-17  Uroš Bizjak  <ubizjak@gmail.com>

gcc/ChangeLog:

* config/i386/i386.h (LEGACY_SSE_REGNO_P): New predicate.
(SSE_REGNO_P): Use LEGACY_SSE_REGNO_P predicate.
* config/i386/i386.c (zero_all_vector_registers):
Use LEGACY_SSE_REGNO_P predicate.
(ix86_register_priority): Use REX_INT_REGNO_P, REX_SSE_REGNO_P
and EXT_REG_SSE_REGNO_P predicates.
(ix86_hard_regno_call_part_clobbered): Use REX_SSE_REGNO_P
and LEGACY_SSE_REGNO_P predicates.

2 years agoHandle folded nonconstant array bounds [PR101702]
Martin Sebor [Wed, 17 Nov 2021 18:51:33 +0000 (11:51 -0700)]
Handle folded nonconstant array bounds [PR101702]

PR c/101702 - ICE: in handle_argspec_attribute, at c-family/c-attribs.c:3623

gcc/c/ChangeLog:

PR c/101702
* c-decl.c (get_parm_array_spec): Strip casts earlier and fold array
bounds before deciding if they're constant.

gcc/testsuite/ChangeLog:

PR c/101702
* gcc.dg/Warray-parameter-11.c: New test.

2 years agodoc: document -fimplicit-constexpr
Jason Merrill [Wed, 17 Nov 2021 10:45:02 +0000 (05:45 -0500)]
doc: document -fimplicit-constexpr

I forgot this in the implementation patch.

gcc/ChangeLog:

* doc/invoke.texi (C++ Dialect Options): Document
-fimplicit-constexpr.

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

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

libstdc++-v3/ChangeLog:

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

2 years agolibstdc++: Simplify std::string constructors
Jonathan Wakely [Wed, 17 Nov 2021 10:46:18 +0000 (10:46 +0000)]
libstdc++: Simplify std::string constructors

Several std::basic_string constructors dispatch to one of the
two-argument overloads of _M_construct, which then dispatches again to
_M_construct_aux to detect whether the arguments are iterators or not.
That then dispatches to one of _M_construct(size_type, char_type) or
_M_construct(Iter, Iter, iterator_traits<Iter>::iterator_category{}).

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

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

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

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

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

libstdc++-v3/ChangeLog:

* include/bits/basic_string.h (_M_construct_aux): Only define
for C++98. Remove constexpr.
(_M_construct_aux_2): Likewise.
(_M_construct(InputIter, InputIter)): Remove.
(basic_string(const basic_string&)): Call _M_construct with
iterator category argument.
(basic_string(const basic_string&, size_type, const Alloc&)):
Likewise.
(basic_string(const basic_string&, size_type, size_type)):
Likewise.
(basic_string(const charT*, size_type, const Alloc&)): Likewise.
Check for null pointer.
(basic_string(const charT*, const Alloc&)): Likewise.
(basic_string(initializer_list<charT>, const Alloc&)): Call
_M_construct with iterator category argument.
(basic_string(const basic_string&, const Alloc&)): Likewise.
(basic_string(basic_string&&, const Alloc&)): Likewise.
(basic_string(_InputIter, _InputIter, const Alloc&)): Likewise
for C++11 and later, call _M_construct_aux for C++98.
* include/bits/basic_string.tcc
(_M_construct(I, I, input_iterator_tag)): Replace try-block with
RAII type.
(_M_construct(I, I, forward_iterator_tag)): Likewise. Remove
__is_null_pointer check.

2 years agolibstdc++: Set active member of union in std::string [PR103295]
Jonathan Wakely [Wed, 17 Nov 2021 10:23:14 +0000 (10:23 +0000)]
libstdc++: Set active member of union in std::string [PR103295]

Clang diagnoses that the new constexpr std::string constructors are not
usable in constant expressions, because they start to write to members
of the union without setting an active member.

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

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

libstdc++-v3/ChangeLog:

PR libstdc++/103295
* include/bits/basic_string.h (_M_use_local_data()): New
member function to make local buffer the active member.
(assign(const basic_string&)): Use it.
* include/bits/basic_string.tcc (_M_construct, reserve()):
Likewise.

2 years agolibstdc++: Fix std::type_info::before for ARM [PR103240]
Jonathan Wakely [Tue, 16 Nov 2021 21:03:21 +0000 (21:03 +0000)]
libstdc++: Fix std::type_info::before for ARM [PR103240]

The r179236 fix for std::type_info::operator== should also have been
applied to std::type_info::before. Otherwise two distinct types can
compare equivalent due to using a string comparison, when they should do
a pointer comparison.

libstdc++-v3/ChangeLog:

PR libstdc++/103240
* libsupc++/tinfo2.cc (type_info::before): Use unadjusted name
to check for the '*' prefix.
* testsuite/util/testsuite_shared.cc: Add type_info object for
use in new test.
* testsuite/18_support/type_info/103240.cc: New test.

2 years agoFix two mips target tests compromised by recent IPA work
Jeff Law [Wed, 17 Nov 2021 16:55:50 +0000 (11:55 -0500)]
Fix two mips target tests compromised by recent IPA work

gcc/testsuite
* gcc.target/mips/frame-header-1.c (bar): Add noipa attribute.
* gcc.target/mips/frame-header-2.c (bar): Likewise.

2 years agolibcpp: Fix up handling of block comments in -fdirectives-only mode [PR103130]
Jakub Jelinek [Wed, 17 Nov 2021 16:31:40 +0000 (17:31 +0100)]
libcpp: Fix up handling of block comments in -fdirectives-only mode [PR103130]

Normal preprocessing, -fdirectives-only preprocessing before the Nathan's
rewrite, and all other compilers I've tried on godbolt treat even \*/
as end of a block comment, but the new -fdirectives-only handling doesn't.

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

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

* c-c++-common/cpp/dir-only-9.c: New test.

2 years agoaarch64: Add new vector mode V8DI
Przemyslaw Wirkus [Wed, 17 Nov 2021 13:38:24 +0000 (13:38 +0000)]
aarch64: Add new vector mode V8DI

This patch is adding new V8DI mode which will be used with new Armv8.7-A
LS64 extension intrinsics.

gcc/ChangeLog:

* config/aarch64/aarch64-modes.def (VECTOR_MODE): New V8DI mode.
* config/aarch64/aarch64.c (aarch64_hard_regno_mode_ok): Handle
V8DImode.
* config/aarch64/iterators.md (define_mode_attr nunits): Add entry
for V8DI.

2 years agoFix ICE when mixing VLAs and statement expressions [PR91038]
Martin Uecker [Wed, 17 Nov 2021 13:20:59 +0000 (14:20 +0100)]
Fix ICE when mixing VLAs and statement expressions [PR91038]

When returning VM-types from statement expressions, this can
lead to an ICE when declarations from the statement expression
are referred to later. Most of these issues can be addressed by
gimplifying the base expression earlier in gimplify_compound_lval.
Another issue is fixed by wrapping the pointer expression in
pointer_int_sum. This fixes PR91038 and some of the test cases
from PR29970 (structs with VLA members need further work).

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

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

gcc/testsuite/
PR c/91038
PR c/29970
* gcc.dg/vla-stexp-3.c: New test.
* gcc.dg/vla-stexp-4.c: New test.
* gcc.dg/vla-stexp-5.c: New test.
* gcc.dg/vla-stexp-6.c: New test.
* gcc.dg/vla-stexp-7.c: New test.
* gcc.dg/vla-stexp-8.c: New test.
* gcc.dg/vla-stexp-9.c: New test.

2 years agolim: Reset flow sensitive info even for pointers [PR103192]
Jakub Jelinek [Wed, 17 Nov 2021 13:18:42 +0000 (14:18 +0100)]
lim: Reset flow sensitive info even for pointers [PR103192]

Since 2014 is lim clearing SSA_NAME_RANGE_INFO for integral SSA_NAMEs
if moving them from conditional contexts inside of a loop into unconditional
before the loop, but as the miscompilation of gimplify.c shows, we need to
treat pointers the same, even for them we need to reset whether the pointer
can/can't be null or the recorded pointer alignment.

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

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

PR tree-optimization/103192
* tree-ssa-loop-im.c (move_computations_worker): Use
reset_flow_sensitive_info instead of manually clearing
SSA_NAME_RANGE_INFO and do it for all SSA_NAMEs, not just ones
with integral types.

2 years agoranger: Fix up fold_using_range::range_of_address [PR103255]
Jakub Jelinek [Wed, 17 Nov 2021 12:45:53 +0000 (13:45 +0100)]
ranger: Fix up fold_using_range::range_of_address [PR103255]

If on &base->member the offset isn't constant or isn't zero and
-fdelete-null-pointer-checks and not -fwrapv-pointer and base has a range
that doesn't include NULL, we return the range of the base.
Usually it isn't a big deal, because for most pointers we just use
varying, range_zero and range_nonzero ranges and nothing beyond that,
but if a pointer is initialized from a constant, we actually track the
exact range and in that case this causes miscompilation.
As discussed on IRC, I think doing something like:
              offset_int off2;
              if (off_cst && off.is_constant (&off2))
                {
                  tree cst = wide_int_to_tree (sizetype, off2 / BITS_PER_UNIT);
                  // adjust range r with POINTER_PLUS_EXPR cst
                  if (!range_includes_zero_p (&r))
                    return true;
                }
              // Fallback
              r = range_nonzero (TREE_TYPE (gimple_assign_rhs1 (stmt)));
              return true;
could work, given that most of the pointer ranges are just the simple ones
perhaps it is too much for little benefit.

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

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

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

2 years agoAdd IFN_COND_FMIN/FMAX functions
Richard Sandiford [Wed, 17 Nov 2021 12:28:44 +0000 (12:28 +0000)]
Add IFN_COND_FMIN/FMAX functions

This patch adds conditional forms of FMAX and FMIN, following
the pattern for existing conditional binary functions.

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

gcc/testsuite/
* gcc.target/aarch64/sve/cond_fmaxnm_5.c: New test.
* gcc.target/aarch64/sve/cond_fmaxnm_5_run.c: Likewise.
* gcc.target/aarch64/sve/cond_fmaxnm_6.c: Likewise.
* gcc.target/aarch64/sve/cond_fmaxnm_6_run.c: Likewise.
* gcc.target/aarch64/sve/cond_fmaxnm_7.c: Likewise.
* gcc.target/aarch64/sve/cond_fmaxnm_7_run.c: Likewise.
* gcc.target/aarch64/sve/cond_fmaxnm_8.c: Likewise.
* gcc.target/aarch64/sve/cond_fmaxnm_8_run.c: Likewise.
* gcc.target/aarch64/sve/cond_fminnm_5.c: Likewise.
* gcc.target/aarch64/sve/cond_fminnm_5_run.c: Likewise.
* gcc.target/aarch64/sve/cond_fminnm_6.c: Likewise.
* gcc.target/aarch64/sve/cond_fminnm_6_run.c: Likewise.
* gcc.target/aarch64/sve/cond_fminnm_7.c: Likewise.
* gcc.target/aarch64/sve/cond_fminnm_7_run.c: Likewise.
* gcc.target/aarch64/sve/cond_fminnm_8.c: Likewise.
* gcc.target/aarch64/sve/cond_fminnm_8_run.c: Likewise.

2 years agoi386: Fix non-robust split condition in define_insn_and_split
Kewen Lin [Wed, 17 Nov 2021 10:02:20 +0000 (04:02 -0600)]
i386: Fix non-robust split condition in define_insn_and_split

This patch is to fix some non-robust split conditions in some
define_insn_and_splits, to make each of them applied on top of
the corresponding condition for define_insn part, otherwise the
splitting could perform unexpectedly.

gcc/ChangeLog:

* config/i386/i386.md (*add<dwi>3_doubleword, *addv<dwi>4_doubleword,
*addv<dwi>4_doubleword_1, *sub<dwi>3_doubleword,
*subv<dwi>4_doubleword, *subv<dwi>4_doubleword_1,
*add<dwi>3_doubleword_cc_overflow_1, *divmodsi4_const,
*neg<dwi>2_doubleword, *tls_dynamic_gnu2_combine_64_<mode>): Fix split
condition.

2 years agoFix PR 103288, ICE after PHI-OPT, move an assigment when still in use for another bb
Andrew Pinski [Tue, 16 Nov 2021 23:37:08 +0000 (23:37 +0000)]
Fix PR 103288, ICE after PHI-OPT, move an assigment when still in use for another bb

The problem is r12-5300-gf98f373dd822b35c allows phiopt to recognize more basic blocks
but missed one location where phiopt could move an assignment from the middle block
to the non-middle one.  This patch fixes that.

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

PR tree-optimization/103288

gcc/ChangeLog:

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

gcc/testsuite/ChangeLog:

* gcc.c-torture/compile/pr103288-1.c: New test.

2 years agovisium: Fix non-robust split condition in define_insn_and_split
Kewen Lin [Wed, 17 Nov 2021 05:55:01 +0000 (23:55 -0600)]
visium: Fix non-robust split condition in define_insn_and_split

This patch is to fix some non-robust split conditions in some
define_insn_and_splits, to make each of them applied on top of
the corresponding condition for define_insn part, otherwise the
splitting could perform unexpectedly.

gcc/ChangeLog:

* config/visium/visium.md (*add<mode>3_insn, *addsi3_insn, *addi3_insn,
*sub<mode>3_insn, *subsi3_insn, *subdi3_insn, *neg<mode>2_insn,
*negdi2_insn, *and<mode>3_insn, *ior<mode>3_insn, *xor<mode>3_insn,
*one_cmpl<mode>2_insn, *ashl<mode>3_insn, *ashr<mode>3_insn,
*lshr<mode>3_insn, *trunchiqi2_insn, *truncsihi2_insn,
*truncdisi2_insn, *extendqihi2_insn, *extendqisi2_insn,
*extendhisi2_insn, *extendsidi2_insn, *zero_extendqihi2_insn,
*zero_extendqisi2_insn, *zero_extendsidi2_insn): Fix split condition.

2 years agolibcpp: Implement -Wbidi-chars for CVE-2021-42574 [PR103026]
Marek Polacek [Wed, 6 Oct 2021 18:33:59 +0000 (14:33 -0400)]
libcpp: Implement -Wbidi-chars for CVE-2021-42574 [PR103026]

From a link below:
"An issue was discovered in the Bidirectional Algorithm in the Unicode
Specification through 14.0. It permits the visual reordering of
characters via control sequences, which can be used to craft source code
that renders different logic than the logical ordering of tokens
ingested by compilers and interpreters. Adversaries can leverage this to
encode source code for compilers accepting Unicode such that targeted
vulnerabilities are introduced invisibly to human reviewers."

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

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

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

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

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

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

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

PR preprocessor/103026

gcc/c-family/ChangeLog:

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

gcc/ChangeLog:

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

libcpp/ChangeLog:

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

gcc/testsuite/ChangeLog:

* c-c++-common/Wbidi-chars-1.c: New test.
* c-c++-common/Wbidi-chars-2.c: New test.
* c-c++-common/Wbidi-chars-3.c: New test.
* c-c++-common/Wbidi-chars-4.c: New test.
* c-c++-common/Wbidi-chars-5.c: New test.
* c-c++-common/Wbidi-chars-6.c: New test.
* c-c++-common/Wbidi-chars-7.c: New test.
* c-c++-common/Wbidi-chars-8.c: New test.
* c-c++-common/Wbidi-chars-9.c: New test.
* c-c++-common/Wbidi-chars-10.c: New test.
* c-c++-common/Wbidi-chars-11.c: New test.
* c-c++-common/Wbidi-chars-12.c: New test.
* c-c++-common/Wbidi-chars-13.c: New test.
* c-c++-common/Wbidi-chars-14.c: New test.
* c-c++-common/Wbidi-chars-15.c: New test.
* c-c++-common/Wbidi-chars-16.c: New test.
* c-c++-common/Wbidi-chars-17.c: New test.

2 years agoanalyzer: fix missing -Wanalyzer-write-to-const [PR102695]
David Malcolm [Tue, 16 Nov 2021 15:36:49 +0000 (10:36 -0500)]
analyzer: fix missing -Wanalyzer-write-to-const [PR102695]

This patch fixes -Wanalyzer-write-to-const so that it will complain
about attempts to write to functions, to labels.
It also "teaches" the analyzer about strchr, in that strchr can either
return a pointer into the input area (and thus -Wanalyzer-write-to-const
can now complain about writes into a string literal seen this way),
or return NULL (and thus the analyzer can complain about NULL
dereferences if the result is used without a check).

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

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

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2 years agoanalyzer: don't assume target has alloca [PR102779]
David Malcolm [Mon, 15 Nov 2021 23:23:08 +0000 (18:23 -0500)]
analyzer: don't assume target has alloca [PR102779]

gcc/testsuite/ChangeLog:
PR analyzer/102779
* gcc.dg/analyzer/capacity-1.c: Add dg-require-effective-target
alloca.  Use __builtin_alloca rather than alloca.
* gcc.dg/analyzer/capacity-3.c: Likewise.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2 years agoFix clearing of to_info_lto in ipa_merge_modref_summary_after_inlining
Jan Hubicka [Wed, 17 Nov 2021 00:43:57 +0000 (01:43 +0100)]
Fix clearing of to_info_lto in ipa_merge_modref_summary_after_inlining

This patch fixes bug that caused some optimizations to be dropped with
-fdump-ipa-inline.

gcc/ChangeLog:

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

PR ipa/103246
* ipa-modref.c (ipa_merge_modref_summary_after_inlining): Fix clearing
of to_info_lto

2 years agoDaily bump.
GCC Administrator [Wed, 17 Nov 2021 00:16:29 +0000 (00:16 +0000)]
Daily bump.

2 years agolibstdc++: Fix tests for constexpr std::string
Jonathan Wakely [Tue, 16 Nov 2021 21:00:50 +0000 (21:00 +0000)]
libstdc++: Fix tests for constexpr std::string

Some tests fail when run with -D_GLIBCXX_USE_CXX11_ABI or -stdgnu++20.

libstdc++-v3/ChangeLog:

* include/bits/basic_string.h (operator<=>): Use constexpr
unconditionally.
* testsuite/21_strings/basic_string/modifiers/constexpr.cc:
Require cxx11-abit effective target.
* testsuite/21_strings/headers/string/synopsis.cc: Add
conditional constexpr to declarations, and adjust relational
operators for C++20.

2 years agoc-family: don't cache large vecs
Jason Merrill [Wed, 10 Nov 2021 21:23:12 +0000 (16:23 -0500)]
c-family: don't cache large vecs

Patrick observed recently that an element of the vector cache could be
arbitrarily large.  Let's only cache relatively small vecs.

gcc/c-family/ChangeLog:

* c-common.c (release_tree_vector): Only cache vecs smaller than
16 elements.

2 years agoUse modref summaries for byte-wise dead store elimination.
Jan Hubicka [Tue, 16 Nov 2021 22:01:28 +0000 (23:01 +0100)]
Use modref summaries for byte-wise dead store elimination.

gcc/ChangeLog:

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

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/modref-dse-4.c: New test.

2 years agoMAINTAINERS: Add myself to DCO section and update email address
Martin Uecker [Tue, 16 Nov 2021 21:35:20 +0000 (22:35 +0100)]
MAINTAINERS: Add myself to DCO section and update email address

ChangeLog:

* MAINTAINERS: Add myself to DCO section and update email address.

2 years agoFortran: avoid NULL pointer dereference on invalid range in logical SELECT CASE
Harald Anlauf [Tue, 16 Nov 2021 20:06:06 +0000 (21:06 +0100)]
Fortran: avoid NULL pointer dereference on invalid range in logical SELECT CASE

gcc/fortran/ChangeLog:

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

gcc/testsuite/ChangeLog:

PR fortran/103286
* gfortran.dg/pr103286.f90: New test.

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

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

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

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

2 years agoPCH: Make the save and restore diagnostics more robust.
Iain Sandoe [Sat, 13 Nov 2021 12:26:16 +0000 (12:26 +0000)]
PCH: Make the save and restore diagnostics more robust.

When saving, if we cannot obtain a suitable memory segment there
is no point in continuing, so exit with an error.

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

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

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

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

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

* ggc-common.c (gt_pch_save): If we cannot find a suitable
memory segment for save, then error-out, do not try to
continue.
(gt_pch_restore): Save the existing line table, and when
the replacement is being read, use that when constructing
diagnostics.

2 years agors6000: MMA test case emits wrong code when building a vector pair [PR102976]
Peter Bergner [Tue, 16 Nov 2021 18:14:22 +0000 (12:14 -0600)]
rs6000: MMA test case emits wrong code when building a vector pair [PR102976]

PR102976 shows a test case where we generate wrong code when building
a vector pair from 2 vector registers.  The bug here is that with unlucky
register assignments, we can clobber one of the input operands before
we write both registers of the output operand.  The solution is to use
early-clobbers in the assemble pair and accumulator patterns.

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

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

gcc/testsuite/
PR target/102976
* gcc.target/powerpc/pr102976.c: New test.

2 years agofortran: Identify arguments by their names
Mikael Morin [Sun, 7 Nov 2021 13:40:36 +0000 (14:40 +0100)]
fortran: Identify arguments by their names

This provides a new function to get the name of a dummy argument,
so that identifying an argument can be made using just its name
instead of a mix of name matching (for keyword actual arguments)
and argument counting (for other actual arguments).

gcc/fortran/ChangeLog:
* interface.c (gfc_dummy_arg_get_name): New function.
* gfortran.h (gfc_dummy_arg_get_name): Declare it.
* trans-array.c (arg_evaluated_for_scalarization): Pass a dummy
argument wrapper as argument instead of an actual argument
and an index number.  Check it’s non-NULL.  Use its name
to identify it.
(gfc_walk_elemental_function_args): Update call to
arg_evaluated for scalarization.  Remove argument counting.

2 years agofortran: Delete redundant missing_arg_type field
Mikael Morin [Sun, 7 Nov 2021 13:40:24 +0000 (14:40 +0100)]
fortran: Delete redundant missing_arg_type field

Now that we can get information about an actual arg's associated
dummy using the associated_dummy attribute, the field missing_arg_type
contains redundant information.
This removes it.

gcc/fortran/ChangeLog:
* gfortran.h (gfc_actual_arglist::missing_arg_type): Remove.
* interface.c (gfc_compare_actual_formal): Remove
missing_arg_type initialization.
* intrinsic.c (sort_actual): Ditto.
* trans-expr.c (gfc_conv_procedure_call): Use associated_dummy
and gfc_dummy_arg_get_typespec to get the dummy argument type.

2 years agofortran: simplify elemental arguments walking
Mikael Morin [Sun, 7 Nov 2021 13:40:11 +0000 (14:40 +0100)]
fortran: simplify elemental arguments walking

This adds two functions working with the wrapper struct gfc_dummy_arg
and makes usage of them to simplify a bit the walking of elemental
procedure arguments for scalarization.  As information about dummy arguments
can be obtained from the actual argument through the just-introduced
associated_dummy field, there is no need to carry around the procedure
interface and walk dummy arguments manually together with actual arguments.

gcc/fortran/ChangeLog:
* interface.c (gfc_dummy_arg_get_typespec,
gfc_dummy_arg_is_optional): New functions.
* gfortran.h (gfc_dummy_arg_get_typespec,
gfc_dummy_arg_is_optional): Declare them.
* trans.h (gfc_ss_info::dummy_arg): Use the wrapper type
as declaration type.
* trans-array.c (gfc_scalar_elemental_arg_saved_as_reference):
use gfc_dummy_arg_get_typespec function to get the type.
(gfc_walk_elemental_function_args): Remove proc_ifc argument.
Get info about the dummy arg using the associated_dummy field.
* trans-array.h (gfc_walk_elemental_function_args): Update declaration.
* trans-intrinsic.c (gfc_walk_intrinsic_function):
Update call to gfc_walk_elemental_function_args.
* trans-stmt.c (gfc_trans_call): Ditto.
(get_proc_ifc_for_call): Remove.

2 years agofortran: Reverse actual vs dummy argument mapping
Mikael Morin [Sun, 7 Nov 2021 13:39:59 +0000 (14:39 +0100)]
fortran: Reverse actual vs dummy argument mapping

There was originally no way from an actual argument to get
to the corresponding dummy argument, even if the job of sorting
and matching actual with dummy arguments was done.
The closest was a field named actual in gfc_intrinsic_arg that was
used as scratch data when sorting arguments of one specific call.
However that value was overwritten later on as arguments of another
call to the same procedure were sorted and matched.

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

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

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

gcc/fortran/ChangeLog:
* gfortran.h (gfc_dummy_arg_kind, gfc_dummy_arg): New.
(gfc_actual_arglist): New field associated_dummy.
(gfc_intrinsic_arg): Remove field actual.
* interface.c (get_nonintrinsic_dummy_arg): New.
(gfc_compare_actual): Initialize associated_dummy.
* intrinsic.c (get_intrinsic_dummy_arg): New.
(sort_actual):  Add argument vectors.
Use loops with indices on argument vectors.
Initialize associated_dummy.

2 years agofortran: Tiny sort_actual internal refactoring
Mikael Morin [Sun, 7 Nov 2021 13:39:47 +0000 (14:39 +0100)]
fortran: Tiny sort_actual internal refactoring

Preliminary refactoring to make further changes more obvious.
No functional change.

gcc/fortran/ChangeLog:
* intrinsic.c (sort_actual): initialise variable and use it earlier.