platform/upstream/gcc.git
19 months agoc++: comptypes ICE with BOUND_TEMPLATE_TEMPLATE_PARMs [PR107539]
Patrick Palka [Fri, 2 Dec 2022 01:11:53 +0000 (20:11 -0500)]
c++: comptypes ICE with BOUND_TEMPLATE_TEMPLATE_PARMs [PR107539]

Here we end up giving the two BOUND_TEMPLATE_TEMPLATE_PARMs
C<decltype(f::t)> and C<decltype(g::t)> the same TYPE_CANONICAL because
the hash table that interns TYPE_CANONICAL for template type parameters
doesn't set the comparing_specializations flag which controls how
PARM_DECLs from different contexts compare equal.

Later, from spec_hasher::equal for the corresponding two specializations
A<C<decltype(f::t)>> and A<C<decltype(g::t)>>, we compare the two bound
ttps with comparing_specializations set hence they now (structurally)
compare different despite having the same TYPE_CANONICAL, and so we get
the error:

  internal compiler error: same canonical type node for different types
    'C<decltype (t)>' and 'C<decltype (t)>'

This suggests that we should be setting comparing_specializations from
ctp_hasher::equal to match spec_hasher::equal.  But doing so introduces
a separate ICE in cpp2a/concepts-placeholder3.C:

  internal compiler error: canonical types differ for identical types
    'auto [requires ::same_as<<placeholder>, decltype(f::x)>]' and
    'auto [requires ::same_as<<placeholder>, decltype(g::x)>]'

because norm_hasher::equal doesn't set comparing_specializations either.

I'm not sure when exactly we need to set comparing_specializations given
what it controls (TYPENAME_TYPE equality/hashing and PARM_DECL equality)
but it seems to be the conservative choice to set the flag wherever we
have a global hash table that relies on type equality.  To that end this
patch sets comparing_specializations in ctp_hasher and norm_hasher, as
well as in atom_hasher and sat_hasher for good measure.  This turns out
to be a compile time win of about 2% in some concepts tests, probably
because of the improved TYPENAME_TYPE hashing enabled by the flag.

PR c++/107539

gcc/cp/ChangeLog:

* constraint.cc (norm_hasher::hash, norm_hasher::equal): Set
comparing_specializations.
(sat_hasher::hash, sat_hasher::equal): Likewise.
* cp-tree.h (atom_hasher::hash, atom_hasher::equal): Likewise.
* pt.cc (ctp_hasher::hash, ctp_hasher::equal): Likewise.

gcc/testsuite/ChangeLog:

* g++.dg/template/canon-type-19.C: New test.

19 months agolibstdc++: Add error handler for <stacktrace>
Björn Schäpers [Wed, 30 Nov 2022 12:04:16 +0000 (12:04 +0000)]
libstdc++: Add error handler for <stacktrace>

Not providing an error handler results in a null pointer dereference
when an error occurs.

Co-authored-by: Jonathan Wakely <jwakely@redhat.com>
libstdc++-v3/ChangeLog:

* include/std/stacktrace (stacktrace_entry::_S_err_handler): New
static function.
(stacktrace_entry, basic_stacktrace): Pass &_S_err_handler to
all calls to libbacktrace.

19 months agovarasm: Fix type confusion bug
Alex Coplan [Thu, 1 Dec 2022 17:36:02 +0000 (17:36 +0000)]
varasm: Fix type confusion bug

This patch fixes a type confusion bug in varasm.cc:assemble_variable.
The problem is that the current code calls:

  sect = get_variable_section (decl, false);

and then accesses sect->named.name without checking whether the section
is in fact a named section. In the surrounding else clause, we only know
that SECTION_STYLE (sect) != SECTION_NOSWITCH, so it is possible that
the section is an unnamed section.

In practice, this means that we end up doing a wild string compare
between a function pointer and the string literal ".vtable_map_vars".
This is because sect->named.name aliases sect->unnamed.callback in the
section union.

This can be seen in GDB with a simple testcase such as "int x;".

This patch fixes the issue by checking the SECTION_STYLE of the section
is in fact SECTION_NAMED before trying to do the string comparison.

We drop the existing check of whether sect->named.name is non-NULL
because this should presumably always be the case for a named section.

gcc/ChangeLog:

* varasm.cc (assemble_variable): Fix type confusion bug when
checking for ".vtable_map_vars" section.

19 months agogcc: remove incpath.o from CXX_C_OBJS
Martin Liska [Thu, 1 Dec 2022 09:31:51 +0000 (10:31 +0100)]
gcc: remove incpath.o from CXX_C_OBJS

The object is already included in OBJS (libbackend.a), thus
we don't need it.

gcc/cp/ChangeLog:

* Make-lang.in: Remove extra object dependency.

19 months agoRISC-V: Remove tail && mask policy operand for vmclr, vmset, vmld, vmst
Ju-Zhe Zhong [Tue, 29 Nov 2022 01:22:01 +0000 (09:22 +0800)]
RISC-V: Remove tail && mask policy operand for vmclr, vmset, vmld, vmst

1. vector.md: remove tail && mask policy operand for mask mode operations since
   we don't need them according to RVV ISA.
2. riscv-v.cc: adapt emit_pred_op for mask mode predicated mov since all RVV modes
   including vector integer mode && vector float mode  && vector bool mode are
   all use emit_pred_op function. For vector integer mode && vector float mode,
   we have instruction like vle.v/vse.v that we need tail && mask policy.
   However, for vector bool mode, the instruction is vlm/vsm that we don't need
   tail && mask policy. So we add a condition here to add tail && mask policy operand
   during expand if it is not a vector bool modes.

This patch is to cleanup the code and make it be consistent with RVV ISA.

gcc/ChangeLog:

* config/riscv/riscv-v.cc (emit_pred_op): Adapt for mask mode.
* config/riscv/vector.md: Remove Tail && make policy operand for mask mode mov.

19 months agoRISC-V: Add attributes for VSETVL PASS
Ju-Zhe Zhong [Mon, 28 Nov 2022 14:14:06 +0000 (22:14 +0800)]
RISC-V: Add attributes for VSETVL PASS

gcc/ChangeLog:

* config/riscv/riscv-protos.h (enum vlmul_type): New enum.
(get_vlmul): New function.
(get_ratio): Ditto.
* config/riscv/riscv-v.cc (struct mode_vtype_group): New struct.
(ENTRY): Adapt for attributes.
(enum vlmul_type): New enum.
(get_vlmul): New function.
(get_ratio): New function.
* config/riscv/riscv-vector-switch.def (ENTRY): Adapt for attributes.
* config/riscv/riscv.cc (ENTRY): Ditto.
* config/riscv/vector.md (false,true): Add attributes.

19 months agoRISC-V: Add duplicate vector support.
Ju-Zhe Zhong [Fri, 25 Nov 2022 16:06:39 +0000 (00:06 +0800)]
RISC-V: Add duplicate vector support.

gcc/ChangeLog:

* config/riscv/constraints.md (Wdm): New constraint.
* config/riscv/predicates.md (direct_broadcast_operand): New predicate.
* config/riscv/riscv-protos.h (RVV_VLMAX): New macro.
(emit_pred_op): Refine function.
* config/riscv/riscv-selftests.cc (run_const_vector_selftests): New function.
(run_broadcast_selftests): Ditto.
(BROADCAST_TEST): New tests.
(riscv_run_selftests): More tests.
* config/riscv/riscv-v.cc (emit_pred_move): Refine function.
(emit_vlmax_vsetvl): Ditto.
(emit_pred_op): Ditto.
(expand_const_vector): New function.
(legitimize_move): Add constant vector support.
* config/riscv/riscv.cc (riscv_print_operand): New asm print rule for const vector.
* config/riscv/riscv.h (X0_REGNUM): New macro.
* config/riscv/vector-iterators.md: New attribute.
* config/riscv/vector.md (vec_duplicate<mode>): New pattern.
(@pred_broadcast<mode>): New pattern.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/base/dup-1.c: New test.
* gcc.target/riscv/rvv/base/dup-2.c: New test.

19 months agoamdgcn: Add preprocessor builtins for every processor type
Paul-Antoine Arras [Thu, 1 Dec 2022 14:09:54 +0000 (15:09 +0100)]
amdgcn: Add preprocessor builtins for every processor type

Provide a specific builtin for each possible value of '-march'.

gcc/ChangeLog:

* config/gcn/gcn-opts.h (TARGET_FIJI): -march=fiji.
(TARGET_VEGA10): -march=gfx900.
(TARGET_VEGA20): -march=gfx906.
(TARGET_GFX908): -march=gfx908.
(TARGET_GFX90a): -march=gfx90a.
* config/gcn/gcn.h (TARGET_CPU_CPP_BUILTINS): Define a builtin that
uniquely maps to '-march'.

19 months agoada: Strip conversions for the implementation of storage models
Eric Botcazou [Tue, 29 Nov 2022 11:29:30 +0000 (12:29 +0100)]
ada: Strip conversions for the implementation of storage models

This is necessary for unconstrained allocators with qualified expression.

gcc/ada/

* gcc-interface/trans.cc (get_storage_model_access): Strip any type
conversion around the node before looking into it.

19 months agoada: Enforce Aggregate aspect legality rule
Steve Baird [Tue, 29 Nov 2022 22:32:07 +0000 (14:32 -0800)]
ada: Enforce Aggregate aspect legality rule

Ada 2022 requires that an Aggregate aspect specification shall specify a
a name for at least one of Add_Named, Add_Unnamed, or Assign_Indexed.
Enforce this rule.

gcc/ada/

* sem_ch13.adb
(Validate_Aspect_Aggregate): Reject illegal case where none of
Add_Named, Add_Unnamed, and Assign_Indexed are specified.

19 months agoada: Further adjustments to User's Guide for PIE default
Eric Botcazou [Tue, 29 Nov 2022 17:44:33 +0000 (18:44 +0100)]
ada: Further adjustments to User's Guide for PIE default

gcc/ada/

* doc/gnat_ugn/gnat_and_program_execution.rst (Non-Symbolic
Traceback): Add compilation line.
(Symbolic Traceback): Remove obsolete stuff.
* doc/gnat_ugn/gnat_utility_programs.rst (gnatsymbolize): Adjust.
* gnat_ugn.texi: Regenerate.

19 months agoada: Fix misphrasing in comment
Ronan Desplanques [Mon, 28 Nov 2022 15:42:40 +0000 (16:42 +0100)]
ada: Fix misphrasing in comment

gcc/ada/

* lib-xref.adb (Generate_Reference): Fix misphrasing in comment.

19 months agoada: Use the address type of a Storage_Model_Type for 'Address
Gary Dismukes [Fri, 18 Nov 2022 22:43:36 +0000 (17:43 -0500)]
ada: Use the address type of a Storage_Model_Type for 'Address

When an Address attribute applies to an object that is a dereference of
an access value whose type has aspect Designated_Storage_Model, the
attribute will now be treated as having the address type associated
with the Storage_Model_Type of the access type's associated Storage_Model
object instead of being of type System.Address.

gcc/ada/

* sem_attr.adb (Analyze_Attribute, Attribute_Address): In the case
where the attribute's prefix is a dereference of a value of an
access type that has aspect Designated_Storage_Model (or a
renaming of such a dereference), set the attribute's type to the
corresponding Storage_Model_Type's associated address type rather
than System.Address.

19 months agoada: Fix minor issues in reference manual
Ronan Desplanques [Fri, 25 Nov 2022 10:49:47 +0000 (11:49 +0100)]
ada: Fix minor issues in reference manual

This patch fixes a few minor issues in the GNAT library section of
the reference manual.

gcc/ada/

* doc/gnat_rm/the_gnat_library.rst: Fix minor issues.
* gnat_rm.texi: Regenerate.

19 months agoada: Minor updates to gnat/doc configuration
Josue Nava Bello [Mon, 14 Nov 2022 13:45:27 +0000 (13:45 +0000)]
ada: Minor updates to gnat/doc configuration

Minor updates to conf.py (comments, indentation)

gcc/ada/

* doc/share/conf.py: minor updates

19 months agoarm: Fix MVE testsuite fallouts
Christophe Lyon [Thu, 1 Dec 2022 12:50:55 +0000 (12:50 +0000)]
arm: Fix MVE testsuite fallouts

After the recent patches to improve / tidy up MVE tests and patterns,
a few more tests need to be updated (replacing spaces with tabs).

gcc/testsuite/ChangeLog:

* gcc.target/arm/simd/mve-compare-1.c: Update.
* gcc.target/arm/simd/mve-compare-scalar-1.c: Update.
* gcc.target/arm/simd/mve-vabs.c: Update.
* gcc.target/arm/simd/mve-vadd-1.c: Update.
* gcc.target/arm/simd/mve-vadd-scalar-1.c: Update.
* gcc.target/arm/simd/mve-vcmp.c: Update.
* gcc.target/arm/simd/pr101325.c: Update.

19 months agotree-optimization/107937 - uninit predicate simplification fixup
Richard Biener [Thu, 1 Dec 2022 09:12:28 +0000 (10:12 +0100)]
tree-optimization/107937 - uninit predicate simplification fixup

The following changes the predicate representation to record the
value of a predicate with an empty set of AND predicates.  That's
necessary to properly represent the conservative fallback for the
def vs use predicates.  Since simplification now can result in
such an empty set this distinction becomes important and we need
to check for this as we otherwise ICE.

PR tree-optimization/107937
* gimple-predicate-analysis.h (predicate::is_true): New.
(predicate::is_false): Likewise.
(predicate::empty_val): Likewise.
(uninit_analysis::uninit_analysis): Properly initialize
def_preds.
* gimple-predicate-analysis.cc (simplify_1b): Indicate
whether the chain became empty.
(predicate::simplify): Release emptied chain before removing it.
(predicate::normalize): Replace temporary object with assertion.
(uninit_analysis::is_use_guarded): Deal with predicates
that simplify to true/false.

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

19 months agotree-optimization/107935 - fixup equivalence handling in PHI VN
Richard Biener [Thu, 1 Dec 2022 08:01:20 +0000 (09:01 +0100)]
tree-optimization/107935 - fixup equivalence handling in PHI VN

The following makes sure to honor the backedge processing logic
that forces VARYING there.

PR tree-optimization/107935
* tree-ssa-sccvn.cc (visit_phi): Honor forced VARYING on
backedges.

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

19 months agoi386: Improve *concat<mode><dwi>3_{1,2,3,4} patterns [PR107627]
Jakub Jelinek [Thu, 1 Dec 2022 08:29:23 +0000 (09:29 +0100)]
i386: Improve *concat<mode><dwi>3_{1,2,3,4} patterns [PR107627]

On the first testcase we've regressed since 12 at -O2:
-       movq    8(%rsi), %rax
-       movq    %rdi, %r8
-       movq    (%rsi), %rdi
+       movq    (%rsi), %rax
+       movq    8(%rsi), %r8
        movl    %edx, %ecx
-       shrdq   %rdi, %rax
-       movq    %rax, (%r8)
+       xorl    %r9d, %r9d
+       movq    %rax, %rdx
+       xorl    %eax, %eax
+       orq     %r8, %rax
+       orq     %r9, %rdx
+       shrdq   %rdx, %rax
+       movq    %rax, (%rdi)
On the second testcase we've emitted such terrible code
with the useless xors and ors for a long time.
For PR91681 the *concat<mode><dwi>3_{1,2,3,4} patterns have been added
but they allow just register inputs and register or memory offsettable
output.
The following patch fixes this by allowing also memory inputs on those
patterns, because the pattern is then split to 0-2 emit_move_insns or
one xchg and those can handle loads from memory too just fine.
So that we don't narrow memory loads (source has 128-bit (or for ia32
64-bit) load and we would make 64-bit (or for ia32 32-bit) load out of it),
register_operand -> nonmemory_operand change is done only for operands
in zero_extend arguments.  o <- m, m or o <- m, r or o <- r, m alternatives
aren't used, we'd lack registers to perform the moves.  But what is
in addition to the current ro <- r, r supported are r <- m, r and r <- r, m
(in that case we just need to be careful about corner cases, see what
emit_move_insn we'd call and if we wouldn't clobber registers used in m's
address before loading - split_double_concat handles that now) and
&r <- m, m (in that case I think the early clobber is the easiest solution).

The first testcase then on 12 -> patched trunk at -O2 changes:
-       movq    8(%rsi), %rax
-       movq    %rdi, %r8
-       movq    (%rsi), %rdi
+       movq    8(%rsi), %r9
+       movq    (%rsi), %r10
        movl    %edx, %ecx
-       shrdq   %rdi, %rax
-       movq    %rax, (%r8)
+       movq    %r9, %rax
+       shrdq   %r10, %rax
+       movq    %rax, (%rdi)
so same amount of instructions and second testcase 12 -> patched trunk
at -O2 -m32:
-       pushl   %edi
-       xorl    %edi, %edi
        pushl   %esi
-       movl    16(%esp), %esi
+       pushl   %ebx
+       movl    16(%esp), %eax
        movl    20(%esp), %ecx
-       movl    (%esi), %eax
-       movl    4(%esi), %esi
-       movl    %eax, %edx
-       movl    $0, %eax
-       orl     %edi, %edx
-       orl     %esi, %eax
-       shrdl   %edx, %eax
        movl    12(%esp), %edx
+       movl    4(%eax), %ebx
+       movl    (%eax), %esi
+       movl    %ebx, %eax
+       shrdl   %esi, %eax
        movl    %eax, (%edx)
+       popl    %ebx
        popl    %esi
-       popl    %edi

BTW, I wonder if we couldn't add additional patterns which would catch
the case where one of the operands is constant and how does this interact
with the stv pass in 32-bit mode where I think stv is right after combine,
so if we match these patterns, perhaps it would be nice to handle them
in stv (unless they are handled there already).

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

PR target/107627
* config/i386/i386.md (*concat<mode><dwi>3_1, *concat<mode><dwi>3_2):
For operands which are zero_extend arguments allow memory if
output operand is a register.
(*concat<mode><dwi>3_3, *concat<mode><dwi>3_4): Likewise.  If
both input operands are memory, use early clobber on output operand.
* config/i386/i386-expand.cc (split_double_concat): Deal with corner
cases where one input is memory and the other is not and the address
of the memory input uses a register we'd overwrite before loading
the memory into a register.

* gcc.target/i386/pr107627-1.c: New test.
* gcc.target/i386/pr107627-2.c: New test.

19 months agors6000: Corrects comments which are added by r13-4423
Haochen Gui [Thu, 1 Dec 2022 05:55:46 +0000 (13:55 +0800)]
rs6000: Corrects comments which are added by r13-4423

gcc/
* config/rs6000/rs6000-call.cc (swap_endian_selector_for_mode):
Corrects comments of this function and make them clear.

19 months agoc++: small contracts fixes
Jason Merrill [Wed, 30 Nov 2022 19:22:03 +0000 (14:22 -0500)]
c++: small contracts fixes

The first is an actual bug: remove_contract_attributes was only keeping one
attribute.  The second just helps flow analysis in optimizers and static
analyzers.

gcc/cp/ChangeLog:

* contracts.cc (remove_contract_attributes): Actually prepend
to the list.
* pt.cc (tsubst_contract): Only look for a postcondition if type is
nonnull.

19 months agoFix unrecognizable insn due to illegal immediate_operand (const_int 255) of QImode.
liuhongt [Mon, 28 Nov 2022 01:59:47 +0000 (09:59 +0800)]
Fix unrecognizable insn due to illegal immediate_operand (const_int 255) of QImode.

For __builtin_ia32_vec_set_v16qi (a, -1, 2) with
!flag_signed_char. it's transformed to
__builtin_ia32_vec_set_v16qi (_4, 255, 2) in the gimple,
and expanded to (const_int 255) in the rtl. But for immediate_operand,
it expects (const_int 255) to be signed extended to
(const_int -1). The mismatch caused an unrecognizable insn error.

The patch converts (const_int 255) to (const_int -1) in the backend
expander.

gcc/ChangeLog:

PR target/107863
* config/i386/i386-expand.cc (ix86_expand_vec_set_builtin):
Convert op1 to target mode whenever mode mismatch.

gcc/testsuite/ChangeLog:

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

19 months agoanalyzer: fix i18n issues in symbolic out-of-bounds [PR106626]
David Malcolm [Thu, 1 Dec 2022 02:26:43 +0000 (21:26 -0500)]
analyzer: fix i18n issues in symbolic out-of-bounds [PR106626]

gcc/analyzer/ChangeLog:
PR analyzer/106626
* bounds-checking.cc
(symbolic_past_the_end::describe_final_event): Delete, moving to
symbolic_buffer_overflow::describe_final_event and
symbolic_buffer_over_read::describe_final_event, eliminating
composition of text strings via "byte_str" and "m_dir_str".
(symbolic_past_the_end::m_dir_str): Delete field.
(symbolic_buffer_overflow::symbolic_buffer_overflow): Drop
m_dir_str.
(symbolic_buffer_overflow::describe_final_event): New, as noted
above.
(symbolic_buffer_over_read::symbolic_buffer_overflow): Drop
m_dir_str.
(symbolic_buffer_over_read::describe_final_event): New, as noted
above.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
19 months agoanalyzer: unify bounds-checking class hierarchies
David Malcolm [Thu, 1 Dec 2022 02:26:43 +0000 (21:26 -0500)]
analyzer: unify bounds-checking class hierarchies

Convert out-of-bounds class hierarchy from:

  pending_diagnostic
    out_of_bounds
      past_the_end
        buffer_overflow (*)
        buffer_over_read (*)
      buffer_underwrite (*)
      buffer_under_read (*)
    symbolic_past_the_end
      symbolic_buffer_overflow (*)
      symbolic_buffer_over_read (*)

to:

  pending_diagnostic
    out_of_bounds
      concrete_out_of_bounds
        concrete_past_the_end
          concrete_buffer_overflow (*)
          concrete_buffer_over_read (*)
        concrete_buffer_underwrite (*)
        concrete_buffer_under_read (*)
      symbolic_past_the_end
        symbolic_buffer_overflow (*)
        symbolic_buffer_over_read (*)

where the concrete classes (i.e. the instantiable ones) are marked
with a (*).

Doing so undercovered a bug where, for CWE-131-examples.c, we were
emitting an extra:
  warning: heap-based buffer over-read [CWE-122] [-Wanalyzer-out-of-bounds]
at the:
  WidgetList[numWidgets] = NULL;
The issue was that within set_next_state we get the rvalue for the LHS,
which looks like a read to the bounds-checker.  The patch fixes this by
passing NULL as the region_model_context * for such accesses.

gcc/analyzer/ChangeLog:
* bounds-checking.cc (class out_of_bounds): Split out from...
(class concrete_out_of_bounds): New abstract subclass.
(class past_the_end): Rename to...
(class concrete_past_the_end): ...this, and make a subclass of
concrete_out_of_bounds.
(class buffer_overflow): Rename to...
(class concrete_buffer_overflow): ...this, and make a subclass of
concrete_past_the_end.
(class buffer_over_read): Rename to...
(class concrete_buffer_over_read): ...this, and make a subclass of
concrete_past_the_end.
(class buffer_underwrite): Rename to...
(class concrete_buffer_underwrite): ...this, and make a subclass
of concrete_out_of_bounds.
(class buffer_under_read): Rename to...
(class concrete_buffer_under_read): ...this, and make a subclass
of concrete_out_of_bounds.
(class symbolic_past_the_end): Convert to a subclass of
out_of_bounds.
(symbolic_buffer_overflow::get_kind): New.
(symbolic_buffer_over_read::get_kind): New.
(region_model::check_region_bounds): Update for renamings.
* engine.cc (impl_sm_context::set_next_state): Eliminate
"new_ctxt", passing NULL to get_rvalue instead.
(impl_sm_context::warn): Likewise.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
19 months agodiagnostics: tweak diagnostic_path::interprocedural_p [PR106626]
David Malcolm [Thu, 1 Dec 2022 02:26:43 +0000 (21:26 -0500)]
diagnostics: tweak diagnostic_path::interprocedural_p [PR106626]

The region-creation event at the start of...

<source>: In function 'int_arr_write_element_after_end_off_by_one':
<source>:14:11: warning: buffer overflow [CWE-787] [-Wanalyzer-out-of-bounds]
   14 |   arr[10] = x;
      |   ~~~~~~~~^~~
  event 1
    |
    |   10 | int32_t arr[10];
    |      |         ^~~
    |      |         |
    |      |         (1) capacity is 40 bytes
    |
    +--> 'int_arr_write_element_after_end_off_by_one': events 2-3
           |
           |   12 | void int_arr_write_element_after_end_off_by_one(int32_t x)
           |      |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           |      |      |
           |      |      (2) entry to 'int_arr_write_element_after_end_off_by_one'
           |   13 | {
           |   14 |   arr[10] = x;  /* { dg-line line } */
           |      |   ~~~~~~~~~~~
           |      |           |
           |      |           (3) out-of-bounds write from byte 40 till byte 43 but 'arr' ends at byte 40
           |
<source>:14:11: note: write of 4 bytes to beyond the end of 'arr'
   14 |   arr[10] = x;
      |   ~~~~~~~~^~~
<source>:14:11: note: valid subscripts for 'arr' are '[0]' to '[9]'

...makes diagnostic_manager::finish_pruning consider the path to be
interprocedural, and so it doesn't prune the function entry event.

This patch tweaks diagnostic_path::interprocedural_p to ignore
leading events outside of any function, so that it considers the
path to be intraprocedural, and thus diagnostic_manager::finish_pruning
prunes the function entry event, leading to this simpler output:

<source>: In function 'int_arr_write_element_after_end_off_by_one':
<source>:14:11: warning: buffer overflow [CWE-787] [-Wanalyzer-out-of-bounds]
   14 |   arr[10] = x;
      |   ~~~~~~~~^~~
  event 1
    |
    |   10 | int32_t arr[10];
    |      |         ^~~
    |      |         |
    |      |         (1) capacity is 40 bytes
    |
    +--> 'int_arr_write_element_after_end_off_by_one': event 2
           |
           |   14 |   arr[10] = x;
           |      |   ~~~~~~~~^~~
           |      |           |
           |      |           (2) out-of-bounds write from byte 40 till byte 43 but 'arr' ends at byte 40
           |
<source>:14:11: note: write of 4 bytes to beyond the end of 'arr'
<source>:14:11: note: valid subscripts for 'arr' are '[0]' to '[9]'

gcc/ChangeLog:
PR analyzer/106626
* diagnostic-path.h
(diagnostic_path::get_first_event_in_a_function): New decl.
* diagnostic.cc (diagnostic_path::get_first_event_in_a_function):
New.
(diagnostic_path::interprocedural_p): Ignore leading events that
are outside of any function.

gcc/testsuite/ChangeLog:
PR analyzer/106626
* gcc.dg/analyzer/out-of-bounds-multiline-1.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
19 months agoanalyzer: more bounds-checking wording tweaks [PR106626]
David Malcolm [Thu, 1 Dec 2022 02:26:42 +0000 (21:26 -0500)]
analyzer: more bounds-checking wording tweaks [PR106626]

This patch tweaks the wording of -Wanalyzer-out-of-bounds:

* use the spellings/terminology of CWE:
  * replace "underread" with "under-read", as per:
     https://cwe.mitre.org/data/definitions/127.html
  * replace "overread" with "over-read" as per:
     https://cwe.mitre.org/data/definitions/126.html
  * replace "underflow" with "underwrite" as per:
    https://cwe.mitre.org/data/definitions/124.html

* wherever known, specify the memory region of the bad access,
so that it says e.g. "heap-based buffer over-read"
or "stack-based buffer over-read"

gcc/analyzer/ChangeLog:
PR analyzer/106626
* bounds-checking.cc (out_of_bounds::get_memory_space): New.
(buffer_overflow::emit): Use it.
(class buffer_overread): Rename to...
(class buffer_over_read): ...this.
(buffer_over_read::emit): Specify which memory space the read is
from, where known.  Change "overread" to "over-read".
(class buffer_underflow): Rename to...
(class buffer_underwrite): ...this.
(buffer_underwrite::emit): Specify which memory space the write is
to, where known.  Change "underflow" to "underwrite".
(class buffer_underread): Rename to...
(class buffer_under_read): Rename to...
(buffer_under_read::emit): Specify which memory space the read is
from, where known.  Change "underread" to "under-read".
(symbolic_past_the_end::get_memory_space): New.
(symbolic_buffer_overflow::emit): Use it.
(class symbolic_buffer_overread): Rename to...
(class symbolic_buffer_over_read): ...this.
(symbolic_buffer_over_read::emit): Specify which memory space the
read is from, where known.  Change "overread" to "over-read".
(region_model::check_symbolic_bounds): Update for class renaming.
(region_model::check_region_bounds): Likewise.

gcc/testsuite/ChangeLog:
PR analyzer/106626
* gcc.dg/analyzer/call-summaries-2.c: Update expected results.
* gcc.dg/analyzer/out-of-bounds-1.c: Likewise.
* gcc.dg/analyzer/out-of-bounds-2.c: Likewise.
* gcc.dg/analyzer/out-of-bounds-3.c: Likewise.
* gcc.dg/analyzer/out-of-bounds-4.c: Likewise.
* gcc.dg/analyzer/out-of-bounds-5.c: Likewise.
* gcc.dg/analyzer/out-of-bounds-container_of.c: Likewise.
* gcc.dg/analyzer/out-of-bounds-read-char-arr.c: Likewise.  Rename
functions from "int_arr_" to "char_arr_".
* gcc.dg/analyzer/out-of-bounds-read-int-arr.c: Update expected
results.
* gcc.dg/analyzer/out-of-bounds-read-struct-arr.c: New test.
* gcc.dg/analyzer/out-of-bounds-write-char-arr.c: Update expected
results.  Rename functions from "int_arr_" to "char_arr_".
* gcc.dg/analyzer/out-of-bounds-write-int-arr.c: Update expected
results.
* gcc.dg/analyzer/out-of-bounds-write-struct-arr.c: New test.
* gcc.dg/analyzer/pr101962.c: Update expected results.
* gcc.dg/analyzer/realloc-5.c: Update expected results.
* gcc.dg/analyzer/zlib-3.c: Update expected results.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
19 months agoanalyzer: add note about valid subscripts [PR106626]
David Malcolm [Thu, 1 Dec 2022 02:26:42 +0000 (21:26 -0500)]
analyzer: add note about valid subscripts [PR106626]

Consider -fanalyzer on:

#include <stdint.h>

int32_t arr[10];

void int_arr_write_element_after_end_off_by_one(int32_t x)
{
  arr[10] = x;
}

Trunk x86_64: https://godbolt.org/z/17zn3qYY4

Currently we emit:

<source>: In function 'int_arr_write_element_after_end_off_by_one':
<source>:7:11: warning: buffer overflow [CWE-787] [-Wanalyzer-out-of-bounds]
    7 |   arr[10] = x;
      |   ~~~~~~~~^~~
  event 1
    |
    |    3 | int32_t arr[10];
    |      |         ^~~
    |      |         |
    |      |         (1) capacity is 40 bytes
    |
    +--> 'int_arr_write_element_after_end_off_by_one': events 2-3
           |
           |    5 | void int_arr_write_element_after_end_off_by_one(int32_t x)
           |      |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           |      |      |
           |      |      (2) entry to 'int_arr_write_element_after_end_off_by_one'
           |    6 | {
           |    7 |   arr[10] = x;
           |      |   ~~~~~~~~~~~
           |      |           |
           |      |           (3) out-of-bounds write from byte 40 till byte 43 but 'arr' ends at byte 40
           |
<source>:7:11: note: write of 4 bytes to beyond the end of 'arr'
    7 |   arr[10] = x;
      |   ~~~~~~~~^~~

This is worded in terms of bytes, due to the way -Wanalyzer-out-of-bounds
is implemented, but this isn't what the user wrote.

This patch tries to get closer to the user's code by adding a note about
array bounds when we're referring to an array.  In the above example it
adds this trailing note:

  note: valid subscripts for 'arr' are '[0]' to '[9]'

gcc/analyzer/ChangeLog:
PR analyzer/106626
* bounds-checking.cc (out_of_bounds::maybe_describe_array_bounds):
New.
(buffer_overflow::emit): Call maybe_describe_array_bounds.
(buffer_overread::emit): Likewise.
(buffer_underflow::emit): Likewise.
(buffer_underread::emit): Likewise.

gcc/testsuite/ChangeLog:
PR analyzer/106626
* gcc.dg/analyzer/call-summaries-2.c: Add dg-message for expected
note about valid indexes.
* gcc.dg/analyzer/out-of-bounds-1.c: Likewise, fixing up existing
dg-message directives.
* gcc.dg/analyzer/out-of-bounds-write-char-arr.c: Likewise.
* gcc.dg/analyzer/out-of-bounds-write-int-arr.c: Likewise.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
19 months agoanalyzer: fix wording of 'number of bad bytes' note [PR106626]
David Malcolm [Thu, 1 Dec 2022 02:26:42 +0000 (21:26 -0500)]
analyzer: fix wording of 'number of bad bytes' note [PR106626]

Consider -fanalyzer on:

#include <stdint.h>

int32_t arr[10];

void int_arr_write_element_after_end_far(int32_t x)
{
  arr[100] = x;
}

Trunk x86_64: https://godbolt.org/z/7GqEcYGq6

Currently we emit:

<source>: In function 'int_arr_write_element_after_end_far':
<source>:7:12: warning: buffer overflow [CWE-787] [-Wanalyzer-out-of-bounds]
    7 |   arr[100] = x;
      |   ~~~~~~~~~^~~
  event 1
    |
    |    3 | int32_t arr[10];
    |      |         ^~~
    |      |         |
    |      |         (1) capacity is 40 bytes
    |
    +--> 'int_arr_write_element_after_end_far': events 2-3
           |
           |    5 | void int_arr_write_element_after_end_far(int32_t x)
           |      |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           |      |      |
           |      |      (2) entry to 'int_arr_write_element_after_end_far'
           |    6 | {
           |    7 |   arr[100] = x;
           |      |   ~~~~~~~~~~~~
           |      |            |
           |      |            (3) out-of-bounds write from byte 400 till byte 403 but 'arr' ends at byte 40
           |
<source>:7:12: note: write is 4 bytes past the end of 'arr'
    7 |   arr[100] = x;
      |   ~~~~~~~~~^~~

The wording of the final note:
  "write is 4 bytes past the end of 'arr'"
reads to me as if the "4 bytes past" is describing where the access
occurs, which seems wrong, as the write is far beyond the end of the
array.  Looking at the implementation, it's actually describing the
number of bytes within the access that are beyond the bounds of the
buffer.

This patch updates the wording so that the final note reads
  "write of 4 bytes to beyond the end of 'arr'"
which more clearly expresses that it's the size of the access
being described.

The patch also uses inform_n to avoid emitting "1 bytes".

gcc/analyzer/ChangeLog:
PR analyzer/106626
* bounds-checking.cc (buffer_overflow::emit): Use inform_n.
Update wording to clarify that we're talking about the size of
the bad access, rather than its position.
(buffer_overread::emit): Likewise.

gcc/testsuite/ChangeLog:
PR analyzer/106626
* gcc.dg/analyzer/out-of-bounds-read-char-arr.c: Update for
changes to expected wording.
* gcc.dg/analyzer/out-of-bounds-read-int-arr.c: Likewise.
* gcc.dg/analyzer/out-of-bounds-write-char-arr.c: Likewise.
* gcc.dg/analyzer/out-of-bounds-write-int-arr.c: Likewise.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
19 months agoanalyzer: move bounds checking to a new bounds-checking.cc
David Malcolm [Thu, 1 Dec 2022 02:26:42 +0000 (21:26 -0500)]
analyzer: move bounds checking to a new bounds-checking.cc

gcc/ChangeLog:
* Makefile.in (ANALYZER_OBJS): Add analyzer/bounds-checking.o.

gcc/analyzer/ChangeLog:
* bounds-checking.cc: New file, taken from region-model.cc.
* region-model.cc (class out_of_bounds): Move to
bounds-checking.cc.
(class past_the_end): Likewise.
(class buffer_overflow): Likewise.
(class buffer_overread): Likewise.
(class buffer_underflow): Likewise.
(class buffer_underread): Likewise.
(class symbolic_past_the_end): Likewise.
(class symbolic_buffer_overflow): Likewise.
(class symbolic_buffer_overread): Likewise.
(region_model::check_symbolic_bounds): Likewise.
(maybe_get_integer_cst_tree): Likewise.
(region_model::check_region_bounds): Likewise.
* region-model.h: Add comment.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
19 months agoanalyzer: fix ICE on bind/connect with a constant fd [PR107928]
David Malcolm [Thu, 1 Dec 2022 02:26:41 +0000 (21:26 -0500)]
analyzer: fix ICE on bind/connect with a constant fd [PR107928]

gcc/analyzer/ChangeLog:
PR analyzer/107928
* sm-fd.cc (fd_state_machine::on_bind): Handle m_constant_fd in
the "success" outcome.
(fd_state_machine::on_connect): Likewise.
* sm-fd.dot: Add "constant_fd" state and its transitions.

gcc/testsuite/ChangeLog:
PR analyzer/107928
* gcc.dg/analyzer/fd-bind-pr107928.c: New test.
* gcc.dg/analyzer/fd-connect-pr107928.c: New test.
* gcc.dg/analyzer/fd-stream-socket-active-open.c
(test_active_open_from_connect_constant): New, adapted from
test_active_open_from_connect.
* gcc.dg/analyzer/fd-stream-socket-passive-open.c
(test_passive_open_from_bind_constant): New, adapted from
test_passive_open_from_bind.
(test_passive_open_from_listen_constant): New, adapted from
test_passive_open_from_listen.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
19 months agors6000: Generates permute index directly for little endian targets (PR100866)
Haochen Gui [Wed, 30 Nov 2022 07:05:59 +0000 (15:05 +0800)]
rs6000: Generates permute index directly for little endian targets (PR100866)

2022-10-11  Haochen Gui <guihaoc@linux.ibm.com>

gcc/
PR target/100866
* config/rs6000/rs6000-call.cc (swap_endian_selector_for_mode):
Generate permute index directly for little endian targets.
* config/rs6000/vsx.md (revb_<mode>): Call vprem directly with
corresponding permute indexes.

gcc/testsuite/
PR target/100866
* gcc.target/powerpc/pr100866-1.c: New.

19 months agoDaily bump.
GCC Administrator [Thu, 1 Dec 2022 00:17:51 +0000 (00:17 +0000)]
Daily bump.

19 months agomaintainer-scripts: Add gdc to update_web_docs_git
Iain Buclaw [Mon, 21 Nov 2022 10:22:29 +0000 (11:22 +0100)]
maintainer-scripts: Add gdc to update_web_docs_git

So that it's built and uploaded to gcc.gnu.org/onlinedocs.

PR web/107749

maintainer-scripts/ChangeLog:

* update_web_docs_git: Add gdc to MANUALS.

19 months agod: Add language reference section to documentation files.
Iain Buclaw [Sat, 26 Nov 2022 14:52:04 +0000 (15:52 +0100)]
d: Add language reference section to documentation files.

Adds an initial body of documentation for the D front-end - other than
the existing documentation for command-line usage/the man page.

Documentation covers code generation choices specific to GNU D - what
attributes are supported, intrinsics, pragmas, predefined versions,
language extensions, missing features and deviations from spec.

More could be added or elaborated upon, such as what linkage do
different symbols get, mixed language programming with C and C++, the
anatomy of a TypeInfo and ModuleInfo object, and so on.  This is enough
as a first wave just to get it off the ground.

gcc/d/ChangeLog:

* Make-lang.in (D_TEXI_FILES): Add d/implement-d.texi.
* gdc.texi: Adjust introduction, include implement-d.texi.
* implement-d.texi: New file.

19 months agod: Update recipes for building html and pdf documentation
Iain Buclaw [Wed, 30 Nov 2022 17:01:25 +0000 (18:01 +0100)]
d: Update recipes for building html and pdf documentation

gcc/d/ChangeLog:

* Make-lang.in: Only include doc/include when building documentation.
(d.html): Rename html directory to $(build_htmldir)/gdc.

19 months agod: Separate documentation indices into options and keywords.
Iain Buclaw [Mon, 14 Nov 2022 17:31:12 +0000 (18:31 +0100)]
d: Separate documentation indices into options and keywords.

gcc/d/ChangeLog:

* gdc.texi: Separate indices into options and keywords.

19 months agod: Synchronize gdc documentation with options in d/lang.opt
Iain Buclaw [Mon, 14 Nov 2022 17:27:29 +0000 (18:27 +0100)]
d: Synchronize gdc documentation with options in d/lang.opt

gcc/d/ChangeLog:

* gdc.texi: Update gdc option documentation.
* lang.opt (frevert=intpromote): Correct documentation.

19 months agoruntime: force XSI strerror on hurd
Ian Lance Taylor [Wed, 30 Nov 2022 17:36:52 +0000 (09:36 -0800)]
runtime: force XSI strerror on hurd

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

19 months agoFix addvdi3 and subvdi3 patterns
John David Anglin [Wed, 30 Nov 2022 18:40:10 +0000 (18:40 +0000)]
Fix addvdi3 and subvdi3 patterns

While most PA 2.0 instructions support both 32 and 64-bit traps
and conditions, the addi and subi instructions only support 32-bit
traps and conditions. Thus, we need to force immediate operands
to register operands on the 64-bit target and use the add/sub
instructions which can trap on 64-bit signed overflow.

2022-11-30  John David Anglin  <danglin@gcc.gnu.org>

gcc/ChangeLog:

* config/pa/pa.md (addvdi3): Force operand 2 to a register.
Remove "addi,tsv,*" instruction from unamed pattern.
(subvdi3): Force operand 1 to a register.
Remove "subi,tsv" instruction from from unamed pattern.

19 months agoaarch64: Specify that FEAT_MOPS sequences clobber CC
Kyrylo Tkachov [Wed, 30 Nov 2022 17:38:16 +0000 (17:38 +0000)]
aarch64: Specify that FEAT_MOPS sequences clobber CC

According to the architecture pseudocode the FEAT_MOPS sequences overwrite the NZCV flags
as par of their operation, so GCC needs to model that in the relevant RTL patterns.
For the testcase:
void g();
void foo (int a, size_t N, char *__restrict__ in,
         char *__restrict__ out)
{
  if (a != 3)
    __builtin_memcpy (out, in, N);
  if (a > 3)
    g ();
}

we will currently generate:
foo:
        cmp     w0, 3
        bne     .L6
.L1:
        ret
.L6:
        cpyfp   [x3]!, [x2]!, x1!
        cpyfm   [x3]!, [x2]!, x1!
        cpyfe   [x3]!, [x2]!, x1!
        ble     .L1 // Flags reused after CPYF* sequence
        b       g

This is wrong as the result of cmp needs to be recalculated after the MOPS sequence.
With this patch we'll insert a "cmp w0, 3" before the ble, similar to what clang does.

Bootstrapped and tested on aarch64-none-linux-gnu.
Pushing to trunk and to the GCC 12 branch after some baking time.

gcc/ChangeLog:

* config/aarch64/aarch64.md (aarch64_cpymemdi): Specify clobber of CC reg.
(*aarch64_cpymemdi): Likewise.
(aarch64_movmemdi): Likewise.
(aarch64_setmemdi): Likewise.
(*aarch64_setmemdi): Likewise.

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/mops_5.c: New test.
* gcc.target/aarch64/mops_6.c: Likewise.
* gcc.target/aarch64/mops_7.c: Likewise.

19 months agod: Fix ICE on named continue label in an unrolled loop [PR107592]
Iain Buclaw [Fri, 11 Nov 2022 23:54:47 +0000 (00:54 +0100)]
d: Fix ICE on named continue label in an unrolled loop [PR107592]

Continue labels in an unrolled loop require a unique label per
iteration.  Previously this used the Statement body node for each
unrolled iteration to generate a new entry in the label hash table.
This does not work when the continue label has an identifier, as said
named label is pointing to the outer UnrolledLoopStatement node.

What would happen is that during the lowering of `continue label', an
automatic label associated with the unrolled loop would be generated,
and a jump to that label inserted, but because it was never pushed by
the visitor for the loop itself, it subsequently never gets emitted.

To fix, correctly use the UnrolledLoopStatement as the key to look up
and store the break/continue label pair, but remove the continue label
from the value entry after every loop to force a new label to be
generated by the next call to `push_continue_label'

PR d/107592

gcc/d/ChangeLog:

* toir.cc (IRVisitor::push_unrolled_continue_label): New method.
(IRVisitor::pop_unrolled_continue_label): New method.
(IRVisitor::visit (UnrolledLoopStatement *)): Use them instead of
push_continue_label and pop_continue_label.

gcc/testsuite/ChangeLog:

* gdc.dg/pr107592.d: New test.

19 months agoswitch conversion: remove dead variable
Martin Liska [Wed, 30 Nov 2022 14:01:06 +0000 (15:01 +0100)]
switch conversion: remove dead variable

gcc/ChangeLog:

* tree-switch-conversion.cc (bit_test_cluster::emit): Remove
dead variable bt_range.

19 months agofix Clang warning
Martin Liska [Wed, 30 Nov 2022 13:47:03 +0000 (14:47 +0100)]
fix Clang warning

Fixes:
gcc/fortran/parse.cc:5782:32: warning: for loop has empty body [-Wempty-body]

gcc/fortran/ChangeLog:

* parse.cc (parse_omp_structured_block): Remove extra semicolon.

19 months agoMake Warray-bounds alias to Warray-bounds= [PR107787]
Iskander Shakirzyanov [Thu, 24 Nov 2022 14:26:59 +0000 (14:26 +0000)]
Make Warray-bounds alias to Warray-bounds= [PR107787]

According to the documentation, the -Werror= option makes the specified
warning into an error and also automatically implies that option. Then
it seems that the behavior of the compiler when specifying
-Werror=array-bounds=X should be the same as specifying
"-Werror=array-bounds -Warray-bounds=X", so we expect to receive
array-bounds pass diagnostics and they must be processed as errors.

In practice, we observe that the array-bounds pass is indeed invoked,
but its diagnostics are processed as warnings, not errors.

This happens because Warray-bounds and Warray-bounds= are
declared as two different options in common.opt, so when
diagnostic_classify_diagnostic is called, DK_ERROR is set for
the Warray-bounds= option, but diagnostic_report_diagnostic called from
warning_at receives opt_index of Warray-bounds, so information about
DK_ERROR is lost. Fix this by using Alias in declaration of
Warray-bounds (similar to Wattribute-alias).

Co-authored-by: Franz Sirl <Franz.Sirl-kernel@lauterbach.com>
gcc/ChangeLog:

PR driver/107787
* common.opt (Warray-bounds): Turn into alias of
-Warray-bounds=1.
* builtins.cc (c_strlen): Use OPT_Warray_bounds_
instead of OPT_Warray_bounds.
* diagnostic-spec.cc (nowarn_spec_t::nowarn_spec_t): Ditto.
* gimple-array-bounds.cc (array_bounds_checker::check_array_ref,
array_bounds_checker::check_mem_ref,
array_bounds_checker::check_addr_expr,
array_bounds_checker::check_array_bounds): Ditto.
* gimple-ssa-warn-restrict.cc (maybe_diag_access_bounds): Ditto.

gcc/c-family/ChangeLog:

PR driver/107787
* c-common.cc (fold_offsetof,
convert_vector_to_array_for_subscript): Use OPT_Warray_bounds_
instead of OPT_Warray_bounds.

gcc/testsuite/ChangeLog:

PR driver/107787
* gcc.dg/Warray-bounds-34.c: Correct the regular expression
for -Warray-bounds=.
* gcc.dg/Warray-bounds-43.c: Likewise.
* gcc.dg/pr107787.c: New test.

19 months agoImprove profile handling in switch lowering.
Martin Liska [Mon, 24 Jan 2022 14:45:38 +0000 (15:45 +0100)]
Improve profile handling in switch lowering.

PR tree-optimization/101301
PR tree-optimization/103680

gcc/ChangeLog:

* tree-switch-conversion.cc (bit_test_cluster::emit):
Handle correctly remaining probability.
(switch_decision_tree::try_switch_expansion): Fix BB's count
where a cluster expansion happens.
(switch_decision_tree::emit_cmp_and_jump_insns): Fill up also
BB count.
(switch_decision_tree::do_jump_if_equal): Likewise.
(switch_decision_tree::emit_case_nodes): Handle special case
for BT expansion which can also fallback to a default BB.
* tree-switch-conversion.h (cluster::cluster): Add
m_default_prob probability.

19 months agotree-optimization/107919 - predicate simplification in uninit
Richard Biener [Wed, 30 Nov 2022 11:05:29 +0000 (12:05 +0100)]
tree-optimization/107919 - predicate simplification in uninit

The testcase from the PR at -O2 shows

    ((_277 == 2) AND (_79 == 0))
    OR ((NOT (_277 == 0)) AND (NOT (_277 > 2)) AND (NOT (_277 == 2)) AND (_79 == 0))
    OR ((NOT (pretmp_300 == 255)) AND (_277 == 0) AND (NOT (_277 > 2)) AND (NOT (_277 == 2)) AND (_79 == 0))

which we fail to simplify.  The following patch makes us simplify
the relations on _277, producing

    ((_79 == 0) AND (_277 == 2))
    OR ((_79 == 0) AND (_277 <= 1) AND (NOT (_277 == 0)))
    OR ((_79 == 0) AND (_277 == 0) AND (NOT (pretmp_300 == 255)))

which might be an incremental step to resolve a bogus uninit
diagnostic at -O2.  The patch uses maybe_fold_and_comparison for this.

PR tree-optimization/107919
* gimple-predicate-analysis.cc (simplify_1): Rename to ...
(simplify_1a): .. this.
(simplify_1b): New.
(predicate::simplify): Call both simplify_1a and simplify_1b.

19 months agoImprove uninit diagnostic dumps
Richard Biener [Wed, 30 Nov 2022 11:03:56 +0000 (12:03 +0100)]
Improve uninit diagnostic dumps

The following dumps the edge a use is uninitialized in a PHI.

* tree-ssa-uninit.cc (find_uninit_use): Dump the edge for a
PHI node.

19 months agotree-optimization/107919 - uninit diagnostic predicate simplification
Richard Biener [Wed, 30 Nov 2022 09:55:03 +0000 (10:55 +0100)]
tree-optimization/107919 - uninit diagnostic predicate simplification

We fail to simplify

        ((_145 != 0B) AND (_531 == 2) AND (_109 == 0))
        OR ((NOT (_145 != 0B)) AND (_531 == 2) AND (_109 == 0))
        OR ((NOT (_531 == 2)) AND (_109 == 0))

because the existing simplification of !A && B || A && B is implemented
too simplistic.  The following re-implements that which fixes the
bogus uninit diagnostic when using -O1 but not yet at -O2.

PR tree-optimization/107919
* gimple-predicate-analysis.cc (predicate::simplify_2):
Handle predicates of arbitrary length.

* g++.dg/warn/Wuninitialized-pr107919-1.C: New testcase.

19 months agotree-chrec: Fix up ICE on pointer multiplication [PR107835]
Jakub Jelinek [Wed, 30 Nov 2022 10:44:27 +0000 (11:44 +0100)]
tree-chrec: Fix up ICE on pointer multiplication [PR107835]

r13-254-gdd3c7873a61019e9 added an optimization for {a, +, a} (x-1),
but as can be seen on the following testcase, the way it is written
where chrec_fold_multiply is called with type doesn't work for pointers:
             res = build_int_cst (TREE_TYPE (x), 1);
             res = chrec_fold_plus (TREE_TYPE (x), x, res);
             res = chrec_convert_rhs (type, res, NULL);
             res = chrec_fold_multiply (type, chrecr, res);
while what we were doing before and what is still used if the condition
doesn't match is fine:
             res = chrec_convert_rhs (TREE_TYPE (chrecr), x, NULL);
             res = chrec_fold_multiply (TREE_TYPE (chrecr), chrecr, res);
             res = chrec_fold_plus (type, CHREC_LEFT (chrec), res);
because it performs chrec_fold_multiply on TREE_TYPE (chrecr) and converts
only afterwards.

I think the easiest fix is to ignore the new path for pointer types.

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

PR tree-optimization/107835
* tree-chrec.cc (chrec_apply): Don't handle "{a, +, a} (x-1)"
as "a*x" if type is a pointer type.

* gcc.c-torture/compile/pr107835.c: New test.

19 months agolibgomp.texi: List GCN's 'gfx803' under OpenMP Context Selectors
Tobias Burnus [Wed, 30 Nov 2022 10:23:41 +0000 (11:23 +0100)]
libgomp.texi: List GCN's 'gfx803' under OpenMP Context Selectors

libgomp/ChangeLog:

* libgomp.texi (OpenMP Context Selectors): Add 'gfx803' to gcn's isa.

19 months agoamdgcn: Support AMD-specific 'isa' traits in OpenMP context selectors
Paul-Antoine Arras [Tue, 29 Nov 2022 15:22:07 +0000 (16:22 +0100)]
amdgcn: Support AMD-specific 'isa' traits in OpenMP context selectors

Add support for gfx803 as an alias for fiji.
Add test cases for all supported 'isa' values.

gcc/ChangeLog:

* config/gcn/gcn.cc (gcn_omp_device_kind_arch_isa): Add gfx803.
* config/gcn/t-omp-device: Add gfx803.

libgomp/ChangeLog:

* testsuite/libgomp.c/declare-variant-4-fiji.c: New test.
* testsuite/libgomp.c/declare-variant-4-gfx803.c: New test.
* testsuite/libgomp.c/declare-variant-4-gfx900.c: New test.
* testsuite/libgomp.c/declare-variant-4-gfx906.c: New test.
* testsuite/libgomp.c/declare-variant-4-gfx908.c: New test.
* testsuite/libgomp.c/declare-variant-4-gfx90a.c: New test.
* testsuite/libgomp.c/declare-variant-4.h: New header file.

19 months ago[PR107304] note test's ifunc requirement
Alexandre Oliva [Wed, 30 Nov 2022 07:55:11 +0000 (04:55 -0300)]
[PR107304] note test's ifunc requirement

The test uses target_clones, that requires ifunc support.

for  gcc/testsuite/ChangeLog

PR target/107304
* gcc.target/i386/pr107304.c: dg-require ifunc support.

19 months agoLoongArch: Optimize the implementation of stack check.
Lulu Cheng [Tue, 29 Nov 2022 08:06:12 +0000 (16:06 +0800)]
LoongArch: Optimize the implementation of stack check.

The old stack check was performed before the stack was dropped,
which would cause the detection tool to report a memory leak.

The current stack check scheme is as follows:

'-fstack-clash-protection':
1. When the frame->total_size is smaller than the guard page size,
   the stack is dropped according to the original scheme, and there
   is no need to perform stack detection in the prologue.
2. When frame->total_size is greater than or equal to guard page size,
   the first step to drop the stack is to drop the space required by
   the caller-save registers. This space needs to save the caller-save
   registers, so an implicit stack check is performed.
   So just need to check the rest of the stack space.

'-fstack-check':
There is no one-time stack drop and then page-by-page detection as
described in the document. It is also the same as
'-fstack-clash-protection', which is detected immediately after page drop.

It is judged that when frame->total_size is not 0, only the size required
to save the s register is dropped for the first stack down.

The test cases are referenced from aarch64.

gcc/ChangeLog:

* config/loongarch/linux.h (STACK_CHECK_MOVING_SP):
Define this macro to 1.
* config/loongarch/loongarch.cc (STACK_CLASH_PROTECTION_GUARD_SIZE):
Size of guard page.
(loongarch_first_stack_step): Return the size of the first drop stack
according to whether stack checking is performed.
(loongarch_emit_probe_stack_range): Adjust the method of stack checking in prologue.
(loongarch_output_probe_stack_range): Delete useless code.
(loongarch_expand_prologue): Adjust the method of stack checking in prologue.
(loongarch_option_override_internal): Enforce that interval is the same
size as size so the mid-end does the right thing.
* config/loongarch/loongarch.h (STACK_CLASH_MAX_UNROLL_PAGES):
New macro decide whether to loop stack detection.

gcc/testsuite/ChangeLog:

* lib/target-supports.exp:
* gcc.target/loongarch/stack-check-alloca-1.c: New test.
* gcc.target/loongarch/stack-check-alloca-2.c: New test.
* gcc.target/loongarch/stack-check-alloca-3.c: New test.
* gcc.target/loongarch/stack-check-alloca-4.c: New test.
* gcc.target/loongarch/stack-check-alloca-5.c: New test.
* gcc.target/loongarch/stack-check-alloca-6.c: New test.
* gcc.target/loongarch/stack-check-alloca.h: New test.
* gcc.target/loongarch/stack-check-cfa-1.c: New test.
* gcc.target/loongarch/stack-check-cfa-2.c: New test.
* gcc.target/loongarch/stack-check-prologue-1.c: New test.
* gcc.target/loongarch/stack-check-prologue-2.c: New test.
* gcc.target/loongarch/stack-check-prologue-3.c: New test.
* gcc.target/loongarch/stack-check-prologue-4.c: New test.
* gcc.target/loongarch/stack-check-prologue-5.c: New test.
* gcc.target/loongarch/stack-check-prologue-6.c: New test.
* gcc.target/loongarch/stack-check-prologue-7.c: New test.
* gcc.target/loongarch/stack-check-prologue.h: New test.

19 months agoanalyzer: move stdio known fns to sm-file.cc
David Malcolm [Wed, 30 Nov 2022 00:56:27 +0000 (19:56 -0500)]
analyzer: move stdio known fns to sm-file.cc

gcc/analyzer/ChangeLog:
* region-model-impl-calls.cc (class kf_fgets): Move to sm-file.cc.
(kf_fgets::impl_call_pre): Likewise.
(class kf_fread): Likewise.
(kf_fread::impl_call_pre): Likewise.
(class kf_getchar): Likewise.
(class kf_stdio_output_fn): Likewise.
(register_known_functions): Move registration of
BUILT_IN_FPRINTF, BUILT_IN_FPRINTF_UNLOCKED, BUILT_IN_FPUTC,
BUILT_IN_FPUTC_UNLOCKED, BUILT_IN_FPUTS, BUILT_IN_FPUTS_UNLOCKED,
BUILT_IN_FWRITE, BUILT_IN_FWRITE_UNLOCKED, BUILT_IN_PRINTF,
BUILT_IN_PRINTF_UNLOCKED, BUILT_IN_PUTC, BUILT_IN_PUTCHAR,
BUILT_IN_PUTCHAR_UNLOCKED, BUILT_IN_PUTC_UNLOCKED, BUILT_IN_PUTS,
BUILT_IN_PUTS_UNLOCKED, BUILT_IN_VFPRINTF, BUILT_IN_VPRINTF,
"getchar", "fgets", "fgets_unlocked", and "fread" to
register_known_file_functions.
* sm-file.cc (class kf_stdio_output_fn): Move here from
region-model-impl-calls.cc.
(class kf_fgets): Likewise.
(class kf_fread): Likewise.
(class kf_getchar): Likewise.
(register_known_file_functions): Move registration of
BUILT_IN_FPRINTF, BUILT_IN_FPRINTF_UNLOCKED, BUILT_IN_FPUTC,
BUILT_IN_FPUTC_UNLOCKED, BUILT_IN_FPUTS, BUILT_IN_FPUTS_UNLOCKED,
BUILT_IN_FWRITE, BUILT_IN_FWRITE_UNLOCKED, BUILT_IN_PRINTF,
BUILT_IN_PRINTF_UNLOCKED, BUILT_IN_PUTC, BUILT_IN_PUTCHAR,
BUILT_IN_PUTCHAR_UNLOCKED, BUILT_IN_PUTC_UNLOCKED, BUILT_IN_PUTS,
BUILT_IN_PUTS_UNLOCKED, BUILT_IN_VFPRINTF, BUILT_IN_VPRINTF,
"fgets", "fgets_unlocked", "fread", and "getchar" to here from
register_known_functions.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
19 months agoanalyzer work on issues with flex-generated lexers [PR103546]
David Malcolm [Wed, 30 Nov 2022 00:56:27 +0000 (19:56 -0500)]
analyzer work on issues with flex-generated lexers [PR103546]

PR analyzer/103546 tracks various false positives seen on
flex-generated lexers.

Whilst investigating them, I noticed an ICE with
-fanalyzer-call-summaries due to attempting to store sm-state
for an UNKNOWN svalue, which this patch fixes.

This patch also provides known_function implementations of all of the
external functions called by the lexer, reducing the number of false
positives.

The patch doesn't eliminate all false positives, but adds integration
tests to try to establish a baseline from which the remaining false
positives can be fixed.

gcc/analyzer/ChangeLog:
PR analyzer/103546
* analyzer.h (register_known_file_functions): New decl.
* program-state.cc (sm_state_map::replay_call_summary): Rejct
attempts to store sm-state for caller_sval that can't have
associated state.
* region-model-impl-calls.cc (register_known_functions): Call
register_known_file_functions.
* sm-fd.cc (class kf_isatty): New.
(register_known_fd_functions): Register it.
* sm-file.cc (class kf_ferror): New.
(class kf_fileno): New.
(class kf_getc): New.
(register_known_file_functions): New.

gcc/ChangeLog:
PR analyzer/103546
* doc/invoke.texi (Static Analyzer Options): Add isatty, ferror,
fileno, and getc to the list of functions known to the analyzer.

gcc/testsuite/ChangeLog:
PR analyzer/103546
* gcc.dg/analyzer/ferror-1.c: New test.
* gcc.dg/analyzer/fileno-1.c: New test.
* gcc.dg/analyzer/flex-with-call-summaries.c: New test.
* gcc.dg/analyzer/flex-without-call-summaries.c: New test.
* gcc.dg/analyzer/getc-1.c: New test.
* gcc.dg/analyzer/isatty-1.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
19 months agoanalyzer: fix folding of '(PTR + 0) => PTR' [PR105784]
David Malcolm [Wed, 30 Nov 2022 00:56:27 +0000 (19:56 -0500)]
analyzer: fix folding of '(PTR + 0) => PTR' [PR105784]

gcc/analyzer/ChangeLog:
PR analyzer/105784
* region-model-manager.cc
(region_model_manager::maybe_fold_binop): For POINTER_PLUS_EXPR,
PLUS_EXPR and MINUS_EXPR, eliminate requirement that the final
type matches that of arg0 in favor of a cast.

gcc/testsuite/ChangeLog:
PR analyzer/105784
* gcc.dg/analyzer/torture/fold-ptr-arith-pr105784.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
19 months agoc++: ICE with <=> of incompatible pointers [PR107542]
Patrick Palka [Wed, 30 Nov 2022 00:25:37 +0000 (19:25 -0500)]
c++: ICE with <=> of incompatible pointers [PR107542]

In a SFINAE context composite_pointer_type returns error_mark_node if
the given pointer types are incompatible.  But the SPACESHIP_EXPR case
of cp_build_binary_op wasn't prepared for this error_mark_node result,
which led to an ICE (from spaceship_comp_cat) for the below testcase.
(In a non-SFINAE context composite_pointer_type issues a permerror and
returns cv void* in this case, so this ICE seems specific to SFINAE.)

PR c++/107542

gcc/cp/ChangeLog:

* typeck.cc (cp_build_binary_op): In the SPACESHIP_EXPR case,
handle an error_mark_node result type.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/spaceship-sfinae2.C: New test.

19 months agoDaily bump.
GCC Administrator [Wed, 30 Nov 2022 00:17:59 +0000 (00:17 +0000)]
Daily bump.

19 months agosyscall, runtime: always call XSI strerror_r
Ian Lance Taylor [Tue, 29 Nov 2022 23:31:39 +0000 (15:31 -0800)]
syscall, runtime: always call XSI strerror_r

This does the right thing for either glibc or musl on GNU/Linux.

Based on patch by Sören Tempel.

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

19 months agoFortran: intrinsic MERGE shall use all its arguments [PR107874]
Harald Anlauf [Mon, 28 Nov 2022 19:43:02 +0000 (20:43 +0100)]
Fortran: intrinsic MERGE shall use all its arguments [PR107874]

gcc/fortran/ChangeLog:

PR fortran/107874
* simplify.cc (gfc_simplify_merge): When simplifying MERGE with a
constant scalar MASK, ensure that arguments TSOURCE and FSOURCE are
either constant or will be evaluated.
* trans-intrinsic.cc (gfc_conv_intrinsic_merge): Evaluate arguments
before generating conditional expression.

gcc/testsuite/ChangeLog:

PR fortran/107874
* gfortran.dg/merge_init_expr_2.f90: Adjust code to the corrected
simplification.
* gfortran.dg/merge_1.f90: New test.

Co-authored-by: Steven G. Kargl <kargl@gcc.gnu.org>
19 months agolibstdc++: Avoid bogus warning in std::vector::insert [PR107852]
Jonathan Wakely [Tue, 29 Nov 2022 15:50:06 +0000 (15:50 +0000)]
libstdc++: Avoid bogus warning in std::vector::insert [PR107852]

GCC assumes that any global variable might be modified by operator new,
and so in the testcase for this PR all data members get reloaded after
allocating new storage. By making local copies of the _M_start and
_M_finish members we avoid that, and then the compiler has enough info
to remove the dead branches that trigger bogus -Warray-bounds warnings.

libstdc++-v3/ChangeLog:

PR libstdc++/107852
PR libstdc++/106199
PR libstdc++/100366
* include/bits/vector.tcc (vector::_M_fill_insert): Copy
_M_start and _M_finish members before allocating.
(vector::_M_default_append): Likewise.
(vector::_M_range_insert): Likewise.

19 months agolibstdc++: Remove unnecessary tag dispatching in std::vector
Jonathan Wakely [Tue, 29 Nov 2022 15:19:33 +0000 (15:19 +0000)]
libstdc++: Remove unnecessary tag dispatching in std::vector

There's no need to call a _M_xxx_dispatch function with a
statically-known __false_type tag, we can just directly call the
function that should be dispatched to. This will compile a tiny bit
faster and save a function call with optimization or inlining turned
off.

Also add the always_inline attribute to the __iterator_category helper
used for dispatching on the iterator category.

libstdc++-v3/ChangeLog:

* include/bits/stl_iterator_base_types.h (__iterator_category):
Add always_inline attribute.
* include/bits/stl_vector.h (assign(Iter, Iter)): Call
_M_assign_aux directly, instead of _M_assign_dispatch.
(insert(const_iterator, Iter, Iter)): Call _M_range_insert
directly instead of _M_insert_dispatch.

19 months agolibstdc++: Do not use __used or __packed as identifiers
Jonathan Wakely [Mon, 28 Nov 2022 20:48:55 +0000 (20:48 +0000)]
libstdc++: Do not use __used or __packed as identifiers

These names (and __unused) are defined as macros by newlib.

libstdc++-v3/ChangeLog:

* include/std/format: Rename all variables called __used or
__packed.
* testsuite/17_intro/badnames.cc: Add no_pch options.
* testsuite/17_intro/names.cc: Check __packed, __unused and
__used.

19 months agoc++: explicit specialization and trailing requirements [PR107864]
Patrick Palka [Tue, 29 Nov 2022 14:55:21 +0000 (09:55 -0500)]
c++: explicit specialization and trailing requirements [PR107864]

Here we're crashing when using the explicit specialization of the
function template g with trailing requirements ultimately because
earlier decls_match (called indirectly from register_specialization) for
for the explicit specialization returned false since the template has
trailing requirements whereas the specialization doesn't.

In r12-2230-gddd25bd1a7c8f4, we fixed a similar issue concerning template
requirements instead of trailing requirements.  We could extend that fix
to ignore trailing requirement mismatches for explicit specializations
as well, but it seems cleaner to just propagate constraints from the
specialized template to the specialization when declaring an explicit
specialization so that decls_match will naturally return true in this
case.  And it looks like determine_specialization already does this,
albeit inconsistently (only when specializing a non-template member
function of a class template as in cpp2a/concepts-explicit-spec4.C).

So this patch makes determine_specialization consistently propagate
constraints from the specialized template to the specialization, which
in turn lets us get rid of the function_requirements_equivalent_p special
case added by r12-2230.

PR c++/107864

gcc/cp/ChangeLog:

* decl.cc (function_requirements_equivalent_p): Don't check
DECL_TEMPLATE_SPECIALIZATION.
* pt.cc (determine_specialization): Propagate constraints when
specializing a function template too.  Simplify by using
add_outermost_template_args.

gcc/testsuite/ChangeLog:

* g++.dg/concepts/explicit-spec1a.C: New test.

19 months agotree-optimization/107852 - missed optimization with PHIs
Richard Biener [Tue, 29 Nov 2022 11:56:22 +0000 (12:56 +0100)]
tree-optimization/107852 - missed optimization with PHIs

The following deals with the situation where we have

<bb 2> [local count: 1073741824]:
_5 = bytes.D.25336._M_impl.D.24643._M_start;
_6 = bytes.D.25336._M_impl.D.24643._M_finish;
pretmp_66 = bytes.D.25336._M_impl.D.24643._M_end_of_storage;
if (_5 != _6)
  goto <bb 3>; [70.00%]
else
  goto <bb 4>; [30.00%]

...

<bb 6> [local count: 329045359]:
_89 = operator new (4);
_43 = bytes.D.25336._M_impl.D.24643._M_start;
_Num_44 = _137 - _43;
if (_Num_44 != 0)

but fail to see that _137 is equal to _5 and thus eventually _Num_44
is zero if not operator new would possibly clobber the global
bytes variable.

The following resolves this in value-numbering by using the
predicated values for _5 == _6 recorded for the dominating
condition.

PR tree-optimization/107852
* tree-ssa-sccvn.cc (visit_phi): Use equivalences recorded
as predicated values to elide more redundant PHIs.

* gcc.dg/tree-ssa/ssa-fre-101.c: New testcase.

19 months agotree-optimization/106995 - if-conversion and vanishing loops
Richard Biener [Tue, 29 Nov 2022 09:41:36 +0000 (10:41 +0100)]
tree-optimization/106995 - if-conversion and vanishing loops

When we version loops for vectorization during if-conversion it
can happen that either loop vanishes because we run some VN and
CFG cleanup.  If the to-be vectorized part vanishes we already
redirect the versioning condition to the original loop.  The following
does the same in case the original loop vanishes as happened
for the testcase in the bug in the past (but no longer).

PR tree-optimization/106995
* tree-if-conv.cc (pass_if_conversion::execute): Also redirect the
versioning condition to the original loop if this very loop
vanished during CFG cleanup.

19 months agoCouple of testsuite adjustments
Eric Botcazou [Tue, 29 Nov 2022 10:43:32 +0000 (11:43 +0100)]
Couple of testsuite adjustments

gcc/testsuite/
* gcc.dg/ipa/iinline-attr.c: XFAIL on SPARC.
* gcc.dg/signbit-2.c: Replace vect_int selector by vect_shift.

19 months agoFix PR ada/107810
Eric Botcazou [Tue, 29 Nov 2022 10:42:32 +0000 (11:42 +0100)]
Fix PR ada/107810

This just makes the pattern matching more robust.

gcc/testsuite/
PR ada/107810
* gnat.dg/unchecked_convert9.adb: Adjust pattern.

19 months agotree-optimization/107898 - ICE with -Walloca-larger-than
Richard Biener [Tue, 29 Nov 2022 08:03:46 +0000 (09:03 +0100)]
tree-optimization/107898 - ICE with -Walloca-larger-than

The following avoids ICEing with a mismatched prototype for alloca
and -Walloca-larger-than using irange for checks which doesn't
like mismatched types.

PR tree-optimization/107898
* gimple-ssa-warn-alloca.cc (alloca_call_type): Check
the type of the alloca argument is compatible with size_t
before querying ranges.

19 months agoipa/107897 - avoid property verification ICE after error
Richard Biener [Tue, 29 Nov 2022 07:43:55 +0000 (08:43 +0100)]
ipa/107897 - avoid property verification ICE after error

The target clone pass is the only small IPA pass that doesn't disable
itself after errors but has properties whose verification can fail
because we cut off build SSA passes after errors.

PR ipa/107897
* multiple_target.cc (pass_target_clone::gate): Disable
after errors.

19 months agore-run configure
Martin Liska [Tue, 29 Nov 2022 08:33:59 +0000 (09:33 +0100)]
re-run configure

gcc/ChangeLog:

* configure: Regenerate.

19 months agogcc/configure.ac: fix AC_DEFINE ENABLE_MULTIARCH
YunQiang Su [Tue, 29 Nov 2022 03:07:33 +0000 (11:07 +0800)]
gcc/configure.ac: fix AC_DEFINE ENABLE_MULTIARCH

Description section was missing in AC_DEFINE(ENABLE_MULTIARCH, 1).
It makes autoheader fail.

Thanks Lulu Cheng points it out.

gcc/ChangeLog:

* configure.ac: add description for
AC_DEFINE(ENABLE_MULTIARCH, 1)

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

19 months agoc++: simple-requirement starting with 'typename' [PR101733]
Jason Merrill [Sat, 26 Nov 2022 16:13:55 +0000 (11:13 -0500)]
c++: simple-requirement starting with 'typename' [PR101733]

Usually a requirement starting with 'typename' is a type-requirement, but it
might be a simple-requirement such as a functional cast to a typename-type.

PR c++/101733

gcc/cp/ChangeLog:

* parser.cc (cp_parser_requirement): Parse tentatively for the
'typename' case.

gcc/testsuite/ChangeLog:

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

19 months agoc++: be more strict about 'concept bool'
Jason Merrill [Mon, 21 Nov 2022 21:05:23 +0000 (16:05 -0500)]
c++: be more strict about 'concept bool'

Some clang folks mailed me asking about being less permissive about
'concept bool', so let's bump it up from pedwarn to permerror.

gcc/cp/ChangeLog:

* parser.cc (cp_parser_decl_specifier_seq): Change 'concept bool'
diagnostic from pedwarn to permerror.

19 months agoFix comment for (A / (1 << B)) -> (A >> B).
Andrew Pinski [Mon, 28 Nov 2022 20:10:28 +0000 (20:10 +0000)]
Fix comment for (A / (1 << B)) -> (A >> B).

There was a small typo where Also was done
twice. The second also should have been
handled. This fixes that.

Committed as obvious after a build.

gcc/ChangeLog:

* match.pd ((A / (1 << B)) -> (A >> B).):
Fix comment.

19 months agoriscv: improve cost model for loading 64bit constant in rv32
Sinan [Mon, 28 Nov 2022 19:41:17 +0000 (12:41 -0700)]
riscv: improve cost model for loading 64bit constant in rv32

The motivation of this patch is to correct the wrong estimation of the number of instructions needed for loading a 64bit constant in rv32 in the current cost model(riscv_interger_cost). According to the current implementation, if a constant requires more than 3 instructions(riscv_const_insn and riscv_legitimate_constant_p), then the constant will be put into constant pool when expanding gimple to rtl(legitimate_constant_p hook and emit_move_insn). So the inaccurate cost model leads to the suboptimal codegen in rv32 and the wrong estimation part could be corrected through this fix.

e.g. the current codegen for loading 0x839290001 in rv32

  lui     a5,%hi(.LC0)
  lw      a0,%lo(.LC0)(a5)
  lw      a1,%lo(.LC0+4)(a5)
.LC0:
  .word   958988289
  .word   8

output after this patch

  li a0,958988288
  addi a0,a0,1
  li a1,8

gcc/ChangeLog:

* config/riscv/riscv.cc (riscv_build_integer): Improve some cases
of loading 64bit constants for rv32.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rv32-load-64bit-constant.c: New test.

19 months agoRISC-V: Avoid redundant sign-extension for SImode SGE, SGEU, SLE, SLEU
Maciej W. Rozycki [Mon, 28 Nov 2022 19:36:15 +0000 (19:36 +0000)]
RISC-V: Avoid redundant sign-extension for SImode SGE, SGEU, SLE, SLEU

We produce inefficient code for some synthesized SImode conditional set
operations (i.e. ones that are not directly implemented in hardware) on
RV64.  For example a piece of C code like this:

int
sleu (unsigned int x, unsigned int y)
{
  return x <= y;
}

gets compiled (at `-O2') to this:

sleu:
sgtu a0,a0,a1 # 9 [c=4 l=4]  *sgtu_disi
xori a0,a0,1 # 10 [c=4 l=4]  *xorsi3_internal/1
andi a0,a0,1 # 16 [c=4 l=4]  anddi3/1
ret # 25 [c=0 l=4]  simple_return

or (at `-O1') to this:

sleu:
sgtu a0,a0,a1 # 9 [c=4 l=4]  *sgtu_disi
xori a0,a0,1 # 10 [c=4 l=4]  *xorsi3_internal/1
sext.w a0,a0 # 16 [c=4 l=4]  extendsidi2/0
ret # 24 [c=0 l=4]  simple_return

This is because the middle end expands a SLEU operation missing from
RISC-V hardware into a sequence of a SImode SGTU operation followed by
an explicit SImode XORI operation with immediate 1.  And while the SGTU
machine instruction (alias SLTU with the input operands swapped) gives a
properly sign-extended 32-bit result which is valid both as a SImode or
a DImode operand the middle end does not see that through a SImode XORI
operation, because we tell the middle end that the RISC-V target (unlike
MIPS) may hold values in DImode integer registers that are valid for
SImode operations even if not properly sign-extended.

However the RISC-V psABI requires that 32-bit function arguments and
results passed in 64-bit integer registers be properly sign-extended, so
this is explicitly done at the conclusion of the function.

Fix this by making the backend use a sequence of a DImode SGTU operation
followed by a SImode SEQZ operation instead.  The latter operation is
known by the middle end to produce a properly sign-extended 32-bit
result and therefore combine gets rid of the sign-extension operation
that follows and actually folds it into the very same XORI machine
operation resulting in:

sleu:
sgtu a0,a0,a1 # 9 [c=4 l=4]  *sgtu_didi
xori a0,a0,1 # 16 [c=4 l=4]  xordi3/1
ret # 25 [c=0 l=4]  simple_return

instead (although the SEQZ alias SLTIU against immediate 1 machine
instruction would equally do and is actually retained at `-O0').  This
is handled analogously for the remaining synthesized operations of this
kind, i.e. `SLE', `SGEU', and `SGE'.

gcc/
* config/riscv/riscv.cc (riscv_emit_int_order_test): Use EQ 0
rather that XOR 1 for LE and LEU operations.

gcc/testsuite/
* gcc.target/riscv/sge.c: New test.
* gcc.target/riscv/sgeu.c: New test.
* gcc.target/riscv/sle.c: New test.
* gcc.target/riscv/sleu.c: New test.

19 months agoFortran: ICE with elemental and dummy argument with VALUE attribute [PR107819]
Harald Anlauf [Sun, 27 Nov 2022 20:10:18 +0000 (21:10 +0100)]
Fortran: ICE with elemental and dummy argument with VALUE attribute [PR107819]

gcc/fortran/ChangeLog:

PR fortran/107819
* trans-stmt.cc (gfc_conv_elemental_dependencies): In checking for
elemental dependencies, treat dummy argument with VALUE attribute
as implicitly having intent(in).

gcc/testsuite/ChangeLog:

PR fortran/107819
* gfortran.dg/elemental_dependency_7.f90: New test.

19 months agotree-optimization/107896 - allow v2si to dimode unpacks
Richard Biener [Mon, 28 Nov 2022 16:26:15 +0000 (17:26 +0100)]
tree-optimization/107896 - allow v2si to dimode unpacks

The following avoids ICEing for V2SI -> DImode vec_unpacks_lo.

PR tree-optimization/107896
* tree-vect-stmts.cc (supportable_widening_operation):
Handle non-vector mode intermediate mode.

19 months agolibstdc++: [_GLIBCXX_INLINE_VERSION] Adapt dg-error message
François Dumont [Thu, 24 Nov 2022 05:46:43 +0000 (06:46 +0100)]
libstdc++: [_GLIBCXX_INLINE_VERSION] Adapt dg-error message

libstdc++-v3/ChangeLog

* testsuite/20_util/function/cons/70692.cc: Adapt dg-error message.

19 months agoSupport %b, %B for -Wformat-overflow (sprintf, snprintf)
Frolov Daniil [Mon, 28 Nov 2022 17:35:13 +0000 (12:35 -0500)]
Support %b, %B for -Wformat-overflow (sprintf, snprintf)

gcc/ChangeLog:

* gimple-ssa-sprintf.cc (fmtresult::type_max_digits): Handle
base == 2.
(tree_digits): Likewise.
(format_integer): Likewise.
(parse_directive): Add cases for %b and %B directives.

gcc/testsuite/ChangeLog:

* gcc.dg/Wformat-overflow1.c: New test.

19 months agolibstdc++: Fix src/c++17/memory_resource for H8 targets [PR107801]
Jonathan Wakely [Mon, 28 Nov 2022 13:28:53 +0000 (13:28 +0000)]
libstdc++: Fix src/c++17/memory_resource for H8 targets [PR107801]

This fixes compilation failures for H8 multilibs. For the normal
multilib (ILP16L32?), the chunk struct does not have the expected size,
because uint32_t is type long and has alignment 4 (by default). This
forces sizeof(chunk) to be 12 instead of the expected 10. We can fix
that by using bitset::size_type instead of uint32_t, so that we only use
a 16-bit size when size_t and pointers are 16-bit types.

For the I32LP16 multilibs that use -mint32 int is wider than size_t
and so arithmetic expressions involving size_t promote to int. This
means we need some explicit casts back to size_t.

libstdc++-v3/ChangeLog:

PR libstdc++/107801
* src/c++17/memory_resource.cc (chunk::_M_bytes): Change type
from uint32_t to bitset::size_type. Adjust static assertion.
(__pool_resource::_Pool::replenish): Cast to size_t after
multiplication instead of before.
(__pool_resource::_M_alloc_pools): Ensure both arguments to
std::max have type size_t.

19 months agolibstdc++: Fix std::string_view for I32LP16 targets
Jonathan Wakely [Mon, 28 Nov 2022 12:16:21 +0000 (12:16 +0000)]
libstdc++: Fix std::string_view for I32LP16 targets

For H8/300 with -msx -mn -mint32 the type of (_M_len - __pos) is int,
because int is wider than size_t so the operands are promoted.

libstdc++-v3/ChangeLog:

* include/std/string_view (basic_string_view::copy) Use explicit
template argument for call to std::min<size_t>.
(basic_string_view::substr): Likewise.

19 months agolibstdc++: Fix _Hash_bytes for I16LP32 targets [PR107885]
Jonathan Wakely [Mon, 28 Nov 2022 10:52:23 +0000 (10:52 +0000)]
libstdc++: Fix _Hash_bytes for I16LP32 targets [PR107885]

For H8/300 size_t is 32 bits wide, but (unsigned char)buf[2] << 16
promotes to int which is only 16 bits wide. The shift is then undefined.
This fixes it by converting to size_t before shifting.

libstdc++-v3/ChangeLog:

PR libstdc++/107885
* libsupc++/hash_bytes.cc (_Hash_bytes): Convert to size_t
instead of implicit integer promotion to 16 bits.

19 months agoRISC-V: fix stack access before allocation.
Fei Gao [Mon, 28 Nov 2022 16:31:09 +0000 (11:31 -0500)]
RISC-V: fix stack access before allocation.

In current riscv stack frame allocation, 2 steps are used. The first step allocates memories at least for callee saved GPRs and FPRs, and the second step allocates the rest if stack size is greater than signed 12-bit range. But it's observed in some cases, like gcc.target/riscv/stack_frame.c in my patch, callee saved FPRs fail to be included in the first step allocation, so we get generated instructions like this:

li t0,-16384
addi sp,sp,-48
addi t0,t0,752
...
fsw fs4,-4(sp) #issue here of accessing before allocation
...
add sp,sp,t0

"fsw fs4,-4(sp)" has issue here of accessing stack before allocation. Although "add sp,sp,t0" reserves later the memory for fs4, it exposes a risk when an interrupt comes in between "fsw fs4,-4(sp)" and "add sp,sp,t0", resulting in a corruption in the stack storing fs4 after interrupt context saving and a failure to get the correct value of fs4 later.

This patch fixes issue above, adapts testcases identified in regression tests, and add a new testcase for the change.

gcc/ChangeLog:

* config/riscv/riscv.cc (riscv_first_stack_step): Fix computation
of MIN_FIRST_STEP to cover FP save area too.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/pr93304.c: Adapt testcase for the change, constrain
match to assembly instructions only.
* gcc.target/riscv/rvv/base/spill-11.c: Adapt testcase for the change.
* gcc.target/riscv/stack_frame.c: New test.

19 months agoc++: Allow module name to be a single letter on Windows
Torbjörn SVENSSON [Thu, 27 Oct 2022 16:03:15 +0000 (18:03 +0200)]
c++: Allow module name to be a single letter on Windows

On Windows, the ':' character is special and when the module name is
a single character, like 'A', then the flatname would be (for
example) 'A:Foo'. On Windows, 'A:Foo' is treated as an absolute
path by the module loader and is likely not found.

Without this patch, the test case pr98944_c.C fails with:

In module imported at /src/gcc/testsuite/g++.dg/modules/pr98944_b.C:7:1,
of module A:Foo, imported at /src/gcc/testsuite/g++.dg/modules/pr98944_c.C:7:
A:Internals: error: header module expected, module 'A:Internals' found
A:Internals: error: failed to read compiled module: Bad file data
A:Internals: note: compiled module file is 'gcm.cache/A-Internals.gcm'
In module imported at /src/gcc/testsuite/g++.dg/modules/pr98944_c.C:7:8:
A:Foo: error: failed to read compiled module: Bad import dependency
A:Foo: note: compiled module file is 'gcm.cache/A-Foo.gcm'
A:Foo: fatal error: returning to the gate for a mechanical issue
compilation terminated.

gcc/cp/ChangeLog:

* module.cc: On Windows, 'A:Foo' is supposed to be a module
and not a path.

Co-Authored-By: Yvan ROUX <yvan.roux@foss.st.com>
Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
19 months agolibstdc++: Replace non-ASCII character in comment
Jonathan Wakely [Mon, 28 Nov 2022 15:21:52 +0000 (15:21 +0000)]
libstdc++: Replace non-ASCII character in comment

This has an unnecessary UTF-8 non-breaking space.

libstdc++-v3/ChangeLog:

* testsuite/26_numerics/random/subtract_with_carry_engine/cons/lwg3809.cc:
Replace non-ASCII character.

19 months agolibstdc++: Prune versioned namespace from testsuite output
Jonathan Wakely [Mon, 28 Nov 2022 11:18:07 +0000 (11:18 +0000)]
libstdc++: Prune versioned namespace from testsuite output

This means we don't need to use "(__8::)?" in dg-prune-output
directives.

libstdc++-v3/ChangeLog:

* testsuite/20_util/is_complete_or_unbounded/memoization_neg.cc:
Simplify dg-prune-output pattern.
* testsuite/lib/prune.exp (libstdc++-dg-prune): Prune "::__8".

19 months agolibstdc++: Make 16-bit std::subtract_with_carry_engine work [PR107466]
Jonathan Wakely [Mon, 28 Nov 2022 09:44:52 +0000 (09:44 +0000)]
libstdc++: Make 16-bit std::subtract_with_carry_engine work [PR107466]

This implements the proposed resolution of LWG 3809, so that
std::subtract_with_carry_engine can be used with a 16-bit result_type.
Currently this produces a narrowing error when instantiating the
std::linear_congruential_engine to create the initial state. It also
truncates the default_seed constant when passing it as a result_type
argument.

Change the type of the constant to uint_least32_t and pass 0u when the
default_seed should be used.

libstdc++-v3/ChangeLog:

PR libstdc++/107466
* include/bits/random.h (subtract_with_carry_engine): Use 32-bit
type for default seed. Use 0u as default argument for
subtract_with_carry_engine(result_type) constructor and
seed(result_type) member function.
* include/bits/random.tcc (subtract_with_carry_engine): Use
32-bit type for default seed and engine used for initial state.
* testsuite/26_numerics/random/subtract_with_carry_engine/cons/lwg3809.cc:
New test.

19 months agoada: Adjust runtime library and User's Guide to PIE default on Linux
Eric Botcazou [Sat, 26 Nov 2022 09:11:18 +0000 (10:11 +0100)]
ada: Adjust runtime library and User's Guide to PIE default on Linux

gcc/ada/

* libgnat/g-traceb.ads: Minor tweaks in the commentary.
(Executable_Load_Address): New function.
* doc/gnat_ugn/gnat_and_program_execution.rst (Non-Symbolic
Traceback): Adjust to PIE default on Linux.
(Symbolic Traceback): Likewise.
* doc/gnat_ugn/gnat_utility_programs.rst (gnatsymbolize): Likewise.
* gnat_ugn.texi: Regenerate.

19 months agoada: doc/share/conf.py: Switch the HTML documentation to using the RTD theme
Joel Brobecker [Fri, 25 Nov 2022 13:53:53 +0000 (17:53 +0400)]
ada: doc/share/conf.py: Switch the HTML documentation to using the RTD theme

This commit adjust the sphinx configuration to use the "Read The Docs"
theme, which has the advantage of allowing the navigation bar
(containing among other things a search bar, and the TOC) to stay
fixed while scrolling the contents of the page being read. This is
particularly useful to allow access to those features while reading
a long page, for instance.

gcc/ada/

* doc/share/conf.py (extensions): Add 'sphinx_rtd_theme'.
(html_theme): Set to 'sphinx_rtd_theme'.

19 months agoada: Annotate GNAT.Source_Info with an abstract state
Claire Dross [Fri, 25 Nov 2022 15:28:47 +0000 (16:28 +0100)]
ada: Annotate GNAT.Source_Info with an abstract state

So it can be used safely from SPARK code. The abstract state represents
the source code information that is accessed by the functions defined
in Source_Info. It is volatile as it is updated asyncronously when
moving in the code.

gcc/ada/

* libgnat/g-souinf.ads (Source_Code_Information): Add a new
volatile abstract state and add it in the global contract of all
functions defined in Source_Info.

19 months agoada: Fix internal error on conversion as in/out actual with -gnatVa
Eric Botcazou [Fri, 25 Nov 2022 09:28:18 +0000 (10:28 +0100)]
ada: Fix internal error on conversion as in/out actual with -gnatVa

The problem is that the regular expansion of the conversion around the
call to the subprogram is disabled by the expansion of the validity check
around the same call, as documented in Expand_Actuals:

  --  This case is given higher priority because the subsequent check
  --  for type conversion may add an extra copy of the variable and
  --  prevent proper value propagation back in the original object.

Now the two mechanisms need to cooperate in order for the code to compile.

gcc/ada/

* exp_ch6.adb (Expand_Actuals.Add_Call_By_Copy_Code): Deal with a
reference to a validation variable in the actual.
(Expand_Actuals.Add_Validation_Call_By_Copy_Code): Minor tweak.
(Expand_Actuals): Call Add_Validation_Call_By_Copy_Code directly
only if Add_Call_By_Copy_Code is not to be invoked.

19 months agoada: Add PIE support to backtraces on Linux
Eric Botcazou [Fri, 25 Nov 2022 22:11:27 +0000 (23:11 +0100)]
ada: Add PIE support to backtraces on Linux

gcc/ada/

* adaint.c [Linux]: Include <link.h>.
(__gnat_get_executable_load_address) [Linux]: Enable.

19 months agoada: Implement change to SPARK RM rule on state refinement
Yannick Moy [Thu, 24 Nov 2022 15:27:37 +0000 (16:27 +0100)]
ada: Implement change to SPARK RM rule on state refinement

SPARK RM 7.1.4(4) does not mandate anymore that a package with abstract
states has a completing body, unless the package state is mentioned in
Part_Of specifications. Implement that change.

gcc/ada/

* sem_prag.adb (Check_Part_Of_Abstract_State): Add verification
related to use of Part_Of, so that constituents in private childs
that refer to state in a sibling or parent unit force that unit to
have a body.
* sem_util.adb (Check_State_Refinements): Drop the requirement to
have always a package body for state refinement, when the package
state is mentioned in no Part_Of specification.
* sem_ch3.adb (Analyze_Declarations): Refresh SPARK refs in comment.
* sem_ch7.adb (Analyze_Package_Declaration): Likewise.

19 months agotree-optimization/107493 - SCEV analysis with conversions
Richard Biener [Mon, 28 Nov 2022 09:25:44 +0000 (10:25 +0100)]
tree-optimization/107493 - SCEV analysis with conversions

This shows another case where trying to validate conversions during
the CHREC SCC analysis fails because said analysis assumes we are
converting a complete SCC.  Like the constraint on the initial
conversion seen restrict all conversions handled to sign-changes.

PR tree-optimization/107493
* tree-scalar-evolution.cc (scev_dfs::follow_ssa_edge_expr):
Only handle no-op and sign-changing conversions.

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

19 months agogcn: Fix __builtin_gcn_first_call_this_thread_p
Tobias Burnus [Mon, 28 Nov 2022 10:11:43 +0000 (11:11 +0100)]
gcn: Fix __builtin_gcn_first_call_this_thread_p

Contrary naive expectation, unspec_volatile (via prologue_use) did not
prevent the cprop pass (at -O2) to remove the access to the s[0:1]
(PRIVATE_SEGMENT_BUFFER_ARG) register as the volatile got just put on
the preceeding pseudoregister.  Solution: Use gen_rtx_USE instead.
Additionally, this patch removes (gen_)prologue_use_di as it is then no
longer used.

Finally, as we already do bit manipulation, instead of using the full
64bit side - and then just keeping the value of 's0', just move directly
to use only s1 of s[0:1] and do the bit manipulations there, generating
more readable assembly code and better matching the '#else' branch.

gcc/ChangeLog:

* config/gcn/gcn.cc (gcn_expand_builtin_1): Work on s1 instead
of s[0:1] and use USE to prevent removal of setting that register.
* config/gcn/gcn.md (prologue_use_di): Remove.

19 months agoOpenMP/Fortran: Permit end-clause on directive
Tobias Burnus [Mon, 28 Nov 2022 10:08:32 +0000 (11:08 +0100)]
OpenMP/Fortran: Permit end-clause on directive

gcc/fortran/ChangeLog:

* openmp.cc (OMP_DO_CLAUSES, OMP_SCOPE_CLAUSES,
OMP_SECTIONS_CLAUSES): Add 'nowait'.
(OMP_SINGLE_CLAUSES): Add 'nowait' and 'copyprivate'.
(gfc_match_omp_distribute_parallel_do,
gfc_match_omp_distribute_parallel_do_simd,
gfc_match_omp_parallel_do,
gfc_match_omp_parallel_do_simd,
gfc_match_omp_parallel_sections,
gfc_match_omp_teams_distribute_parallel_do,
gfc_match_omp_teams_distribute_parallel_do_simd): Disallow 'nowait'.
(gfc_match_omp_workshare): Match 'nowait' clause.
(gfc_match_omp_end_single): Use clause matcher for 'nowait'.
(resolve_omp_clauses): Reject 'nowait' + 'copyprivate'.
* parse.cc (decode_omp_directive): Break too long line.
(parse_omp_do, parse_omp_structured_block): Diagnose duplicated
'nowait' clause.

libgomp/ChangeLog:

* libgomp.texi (OpenMP 5.2): Mark end-directive as Y.

gcc/testsuite/ChangeLog:

* gfortran.dg/gomp/copyprivate-1.f90: New test.
* gfortran.dg/gomp/copyprivate-2.f90: New test.
* gfortran.dg/gomp/nowait-2.f90: Move dg-error tests ...
* gfortran.dg/gomp/nowait-4.f90: ... to this new file.
* gfortran.dg/gomp/nowait-5.f90: New test.
* gfortran.dg/gomp/nowait-6.f90: New test.
* gfortran.dg/gomp/nowait-7.f90: New test.
* gfortran.dg/gomp/nowait-8.f90: New test.

19 months agoasan: fix unsafe optimization of Asan checks.
Yuri Gribov [Sun, 14 Aug 2022 05:42:44 +0000 (08:42 +0300)]
asan: fix unsafe optimization of Asan checks.

PR sanitizer/106558

gcc/
* sanopt.cc: Do not optimize out checks for non-SSA addresses.

gcc/testsuite/
* c-c++-common/asan/pr106558.c: New test.