gcc.git
4 years agoarm: Fix up gcc.target/arm/lto/pr96939_* FAIL
Jakub Jelinek [Mon, 14 Sep 2020 08:53:50 +0000 (10:53 +0200)]
arm: Fix up gcc.target/arm/lto/pr96939_* FAIL

The following patch on top of the
https://gcc.gnu.org/pipermail/gcc-patches/2020-September/553801.html
patch fixes the gcc.target/arm/lto/pr96939_* test in certain ARM
configurations.
As said in the above mentioned patch, the generic code takes care of
saving/restoring TargetVariables or Target Save options, so this just
arranges for the generic code to save those instead of needing the
arm backend to do it manually.

2020-09-14  Jakub Jelinek  <jakub@redhat.com>

* config/arm/arm.opt (x_arm_arch_string, x_arm_cpu_string,
x_arm_tune_string): Remove TargetSave entries.
(march=, mcpu=, mtune=): Add Save keyword.
* config/arm/arm.c (arm_option_save): Remove.
(TARGET_OPTION_SAVE): Don't redefine.
(arm_option_restore): Don't restore x_arm_*_string here.

4 years agolibgccjit: Regenerate documentation for new entry point.
Andrea Corallo [Mon, 14 Sep 2020 07:01:18 +0000 (09:01 +0200)]
libgccjit: Regenerate documentation for new entry point.

Fix missing doc regeneration that should have been done by
4ecc0061c4 "libgccjit: Add new gcc_jit_global_set_initializer entry
point"
<https://gcc.gnu.org/onlinedocs/jit/internals/index.html#submitting-patches>.

gcc/jit/ChangeLog

2020-09-14  Andrea Corallo  <andrea.corallo@arm.com>

* docs/_build/texinfo/libgccjit.texi: Regenerate.

4 years agooptions: Save and restore opts_set for Optimization and Target options
Jakub Jelinek [Mon, 14 Sep 2020 07:04:45 +0000 (09:04 +0200)]
options: Save and restore opts_set for Optimization and Target options

> Seems a latent issue.
> Neither cl_optimization_{save,restore} nor cl_target_option_{save,restore}
> (nor any of the target hooks they call) saves or restores any opts_set
> values, so I think opts_set can be trusted only during option processing (if
> at all), but not later.
> So, short term a fix would be IMHO just stop using opts_set altogether in
> arm_configure_build_target, it doesn't make much sense to me, it should test
> if those strings are non-NULL instead, or at least do that when it is
> invoked from arm_option_restore (e.g. could be done by calling it with
> opts instead of &global_options_set ).
> Longer term, the question is if cl_optimization_{save,restore} and
> cl_target_option_{save,restore} shouldn't be changed not to only
> save/restore the options, but also save the opts_set flags.
> It could be done e.g. by adding a bool array or set of bool members
> to struct cl_optimization and struct cl_target_option , or even more compact
> by using bitmasks, pack each 64 adjacent option flags into a UHWI element
> of an array.

So, I've tried under debugger how it behaves and seems global_options_set
is really an or of whether an option has been ever seen as explicit, either
on the command line or in any of the option pragmas or optimize/target
attributes seen so far, so it isn't something that can be relied on.

The following patch implements the saving/restoring of the opts_set bits
(though only for the options/variables saved by the generic options-save.c
code, for the target specific stuff that isn't handled by the generic code
the opts_set argument is now passed to the hook and the backends can choose
e.g. to use a TargetSave variable to save the flags either individually or
together in some bitmask (or ignore it if they never need opts_set for the
options).

This patch itself doesn't fix the testcase failing on arm, but a follow up
patch will.

2020-09-14  Jakub Jelinek  <jakub@redhat.com>

gcc/
* opt-read.awk: Also initialize extra_target_var_types array.
* opth-gen.awk: Emit explicit_mask arrays to struct cl_optimization
and cl_target_option.  Adjust cl_optimization_save,
cl_optimization_restore, cl_target_option_save and
cl_target_option_restore declarations.
* optc-save-gen.awk: Add opts_set argument to cl_optimization_save,
cl_optimization_restore, cl_target_option_save and
cl_target_option_restore functions and save or restore opts_set
next to the opts values into or from explicit_mask arrays.
In cl_target_option_eq and cl_optimization_option_eq compare
explicit_mask arrays, in cl_target_option_hash and cl_optimization_hash
hash them and in cl_target_option_stream_out,
cl_target_option_stream_in, cl_optimization_stream_out and
cl_optimization_stream_in stream them.
* tree.h (build_optimization_node, build_target_option_node): Add
opts_set argument.
* tree.c (build_optimization_node): Add opts_set argument, pass it
to cl_optimization_save.
(build_target_option_node): Add opts_set argument, pass it to
cl_target_option_save.
* function.c (invoke_set_current_function_hook): Adjust
cl_optimization_restore caller.
* ipa-inline-transform.c (inline_call): Adjust cl_optimization_restore
and build_optimization_node callers.
* target.def (TARGET_OPTION_SAVE, TARGET_OPTION_RESTORE): Add opts_set
argument.
* target-globals.c (save_target_globals_default_opts): Adjust
cl_optimization_restore callers.
* toplev.c (process_options): Adjust build_optimization_node and
cl_optimization_restore callers.
(target_reinit): Adjust cl_optimization_restore caller.
* tree-streamer-in.c (lto_input_ts_function_decl_tree_pointers):
Adjust build_optimization_node and cl_optimization_restore callers.
* doc/tm.texi: Updated.
* config/aarch64/aarch64.c (aarch64_override_options): Adjust
build_target_option_node caller.
(aarch64_option_save, aarch64_option_restore): Add opts_set argument.
(aarch64_set_current_function): Adjust cl_target_option_restore
caller.
(aarch64_option_valid_attribute_p): Adjust cl_target_option_save,
cl_target_option_restore, cl_optimization_restore,
build_optimization_node and build_target_option_node callers.
* config/aarch64/aarch64-c.c (aarch64_pragma_target_parse): Adjust
cl_target_option_restore and build_target_option_node callers.
* config/arm/arm.c (arm_option_save, arm_option_restore): Add
opts_set argument.
(arm_option_override): Adjust cl_target_option_save,
build_optimization_node and build_target_option_node callers.
(arm_set_current_function): Adjust cl_target_option_restore caller.
(arm_valid_target_attribute_tree): Adjust build_target_option_node
caller.
(add_attribute): Formatting fix.
(arm_valid_target_attribute_p): Adjust cl_optimization_restore,
cl_target_option_restore, arm_valid_target_attribute_tree and
build_optimization_node callers.
* config/arm/arm-c.c (arm_pragma_target_parse): Adjust
cl_target_option_restore callers.
* config/csky/csky.c (csky_option_override): Adjust
build_target_option_node and cl_target_option_save callers.
* config/gcn/gcn.c (gcn_fixup_accel_lto_options): Adjust
build_optimization_node and cl_optimization_restore callers.
* config/i386/i386-builtins.c (get_builtin_code_for_version):
Adjust cl_target_option_save and cl_target_option_restore
callers.
* config/i386/i386-c.c (ix86_pragma_target_parse): Adjust
build_target_option_node and cl_target_option_restore callers.
* config/i386/i386-options.c (ix86_function_specific_save,
ix86_function_specific_restore): Add opts_set arguments.
(ix86_valid_target_attribute_tree): Adjust build_target_option_node
caller.
(ix86_valid_target_attribute_p): Adjust build_optimization_node,
cl_optimization_restore, cl_target_option_restore,
ix86_valid_target_attribute_tree and build_optimization_node callers.
(ix86_option_override_internal): Adjust build_target_option_node
caller.
(ix86_reset_previous_fndecl, ix86_set_current_function): Adjust
cl_target_option_restore callers.
* config/i386/i386-options.h (ix86_function_specific_save,
ix86_function_specific_restore): Add opts_set argument.
* config/nios2/nios2.c (nios2_option_override): Adjust
build_target_option_node caller.
(nios2_option_save, nios2_option_restore): Add opts_set argument.
(nios2_valid_target_attribute_tree): Adjust build_target_option_node
caller.
(nios2_valid_target_attribute_p): Adjust build_optimization_node,
cl_optimization_restore, cl_target_option_save and
cl_target_option_restore callers.
(nios2_set_current_function, nios2_pragma_target_parse): Adjust
cl_target_option_restore callers.
* config/pru/pru.c (pru_option_override): Adjust
build_target_option_node caller.
(pru_set_current_function): Adjust cl_target_option_restore
callers.
* config/rs6000/rs6000.c (rs6000_debug_reg_global): Adjust
cl_target_option_save caller.
(rs6000_option_override_internal): Adjust build_target_option_node
caller.
(rs6000_valid_attribute_p): Adjust build_optimization_node,
cl_optimization_restore, cl_target_option_save,
cl_target_option_restore and build_target_option_node callers.
(rs6000_pragma_target_parse): Adjust cl_target_option_restore and
build_target_option_node callers.
(rs6000_activate_target_options): Adjust cl_target_option_restore
callers.
(rs6000_function_specific_save, rs6000_function_specific_restore):
Add opts_set argument.
* config/s390/s390.c (s390_function_specific_restore): Likewise.
(s390_option_override_internal): Adjust s390_function_specific_restore
caller.
(s390_option_override, s390_valid_target_attribute_tree): Adjust
build_target_option_node caller.
(s390_valid_target_attribute_p): Adjust build_optimization_node,
cl_optimization_restore and cl_target_option_restore callers.
(s390_activate_target_options): Adjust cl_target_option_restore
caller.
* config/s390/s390-c.c (s390_cpu_cpp_builtins): Adjust
cl_target_option_save caller.
(s390_pragma_target_parse): Adjust build_target_option_node and
cl_target_option_restore callers.
gcc/c-family/
* c-attribs.c (handle_optimize_attribute): Adjust
cl_optimization_save, cl_optimization_restore and
build_optimization_node callers.
* c-pragma.c (handle_pragma_optimize): Adjust
build_optimization_node caller.
(handle_pragma_push_options): Adjust
build_optimization_node and build_target_option_node callers.
(handle_pragma_pop_options, handle_pragma_reset_options):
Adjust cl_optimization_restore callers.
gcc/go/
* go-gcc.cc (Gcc_backend::function): Adjust
cl_optimization_save, cl_optimization_restore and
build_optimization_node callers.
gcc/ada/
* gcc-interface/trans.c (gigi): Adjust build_optimization_node
caller.

4 years ago[libgomp, nvptx] Add __sync_compare_and_swap_16
Tom de Vries [Sat, 5 Sep 2020 10:45:07 +0000 (12:45 +0200)]
[libgomp, nvptx] Add __sync_compare_and_swap_16

As reported here
( https://gcc.gnu.org/pipermail/gcc-patches/2020-September/553070.html  ),
when running test-case libgomp.c-c++-common/reduction-16.c for powerpc host
with nvptx accelerator, we run into:
...
unresolved symbol __sync_val_compare_and_swap_16
...

I can reproduce the problem on x86_64 with a trigger patch that:
- initializes ix86_isa_flags2 to TARGET_ISA2_CX16
- enables define_expand "atomic_load<mode>" in gcc/config/i386/sync.md
  for TImode

The problem is that omp-expand.c generates atomic builtin calls based on
checks whether those are supported on the host, which forces the target to
support these, even though those checks fail for the accelerator target.

Fix this by:
- adding a __sync_val_compare_and_swap_16 in libgomp for nvptx,
  which falls back onto libatomic's __atomic_compare_and_swap_16
- adding -foffload=-latomic in the test-case

Tested libgomp on x86_64-linux with nvptx accelerator.

Tested libgomp with trigger patch on x86_64-linux with nvptx accelerator.

libgomp/ChangeLog:

* config/nvptx/atomic.c: New file.  Add
__sync_val_compare_and_swap_16.
* testsuite/libgomp.c-c++-common/reduction-16.c: Add -latomic for
target offload_target_nvptx.

4 years agoDaily bump.
GCC Administrator [Mon, 14 Sep 2020 00:16:23 +0000 (00:16 +0000)]
Daily bump.

4 years agoImprove costs for DImode shifts of interger constants.
John David Anglin [Sun, 13 Sep 2020 18:47:59 +0000 (18:47 +0000)]
Improve costs for DImode shifts of interger constants.

2020-09-13  Roger Sayle  <roger@nextmovesoftware.com>

gcc/ChangeLog
* config/pa/pa.c (hppa_rtx_costs) [ASHIFT, ASHIFTRT, LSHIFTRT]:
Provide accurate costs for DImode shifts of integer constants.

4 years agoDaily bump.
GCC Administrator [Sun, 13 Sep 2020 00:16:23 +0000 (00:16 +0000)]
Daily bump.

4 years agod: Return promoted types in d_type_promotes_to when linkage is not D
Iain Buclaw [Sat, 12 Sep 2020 14:48:58 +0000 (16:48 +0200)]
d: Return promoted types in d_type_promotes_to when linkage is not D

This enables warnings to be shown when a bad type is passed to va_arg
inside an extern(C) or extern(C++) function.

gcc/d/ChangeLog:

PR d/97002
* d-codegen.cc (d_build_call): Set input_location on CALL_EXPR.
* d-lang.cc: Include function.h.
(d_type_promotes_to): Do default conversions for C and C++ functions.
* intrinsics.cc (expand_intrinsic_vaarg): Use build1_loc to build
VA_ARG_EXPR.

gcc/testsuite/ChangeLog:

PR d/97002
* gdc.dg/pr97002.d: New test.

4 years agod: Build TYPE_DECLs for non-numeric enum types.
Iain Buclaw [Sat, 12 Sep 2020 14:26:58 +0000 (16:26 +0200)]
d: Build TYPE_DECLs for non-numeric enum types.

This is done so that the DWARF pass will emit a DW_TAG_typedef where the
member type of an enum can't be represented in an ENUMERAL_TYPE.

gcc/d/ChangeLog:

* d-builtins.cc (d_build_d_type_nodes): Call build_ctype() on all
basic front-end types.
* decl.cc (DeclVisitor::visit (EnumDeclaration *)): Always add decl to
current binding level.
(build_type_decl): Build TYPE_DECL as a typedef if not for an enum or
record type.
* types.cc (TypeVisitor::visit (TypeEnum *)): Set underlying type for
ENUMERAL_TYPEs.  Build TYPE_DECL for non-numeric enums.

4 years agoAdd new shrpsi instruction variands to gcc/config/pa/pa.md.
John David Anglin [Sat, 12 Sep 2020 14:38:51 +0000 (14:38 +0000)]
Add new shrpsi instruction variands to gcc/config/pa/pa.md.

2020-09-12  Roger Sayle  <roger@nextmovesoftware.com>
    John David Anglin  <danglin@gcc.gnu.org>

gcc/ChangeLog
* config/pa/pa.md (shrpsi4_1, shrpsi4_2): New define_insns split
out from previous shrpsi4 providing two commutitive variants using
plus_xor_ior_operator as a predicate.
(shrpdi4_1, shrpdi4_2, shrpdi_3, shrpdi_4): Likewise DImode versions
where _1 and _2 take register shifts, and _3 and _4 for integers.
(rotlsi3_internal): Name this anonymous instruction.
(rotrdi3): New DImode insn copied from rotrsi3.
(rotldi3): New DImode expander copied from rotlsi3.
(rotldi4_internal): New DImode insn copied from rotsi3_internal.

4 years agoAdd preliminary support for 128-bit integer types
Eric Botcazou [Sat, 12 Sep 2020 10:59:09 +0000 (12:59 +0200)]
Add preliminary support for 128-bit integer types

This is only the gigi part, in preparation for the bulk of the
implementation.

gcc/ada/ChangeLog:
* fe.h: Fix pilot error in previous change.
* gcc-interface/gigi.h (enum standard_datatypes): Add ADT_mulv128_decl.
(mulv128_decl): New macro.
(get_target_long_long_long_size): Declare.
* gcc-interface/decl.c (gnat_to_gnu_entity): Use a maximum size of
128 bits for discrete types if Enable_128bit_Types is true.
* gcc-interface/targtyps.c: Include target.h.
(get_target_long_long_long_size): New function.
* gcc-interface/trans.c (gigi): Initialize mulv128_decl if need be.
(build_binary_op_trapv): Call it for 128-bit multiplication.
* gcc-interface/utils.c (make_type_from_size): Enforce a maximum
size of 128 bits if Enable_128bit_Types is true.

4 years agoFix small inconsistency in new predicate
Eric Botcazou [Sat, 12 Sep 2020 10:47:39 +0000 (12:47 +0200)]
Fix small inconsistency in new predicate

This can result on the mainline in a segfault when an object declared
at library level is used in the declaration of another, local object.

gcc/ada/ChangeLog:
* gcc-interface/trans.c (lvalue_for_aggr_p) <N_Object_Declaration>:
Return false unconditionally.

4 years agoMinor tweak to line debug info
Eric Botcazou [Sat, 12 Sep 2020 10:42:06 +0000 (12:42 +0200)]
Minor tweak to line debug info

This prevents the SLOC of the expression for a tag from being present
in the line debug info every time it is referenced for coverage purposes.

gcc/ada/ChangeLog:
* gcc-interface/trans.c (gnat_to_gnu) <N_Object_Declaration>: Clear
the SLOC of the expression of a tag.

4 years agoAccept absolute address clause for array of UNC nominal subtype
Eric Botcazou [Sat, 12 Sep 2020 10:36:30 +0000 (12:36 +0200)]
Accept absolute address clause for array of UNC nominal subtype

This changes the compiler to accept again absolute address clause for
aliased array of unconstrained nominal subtype, instead of erroring
out in this case.

gcc/ada/ChangeLog:
* gcc-interface/decl.c (gnat_to_gnu_entity) <E_Variable>: Only give
a warning for the overlay of an aliased array with an unconstrained
nominal subtype if the address is absolute.

4 years agoDaily bump.
GCC Administrator [Sat, 12 Sep 2020 00:16:30 +0000 (00:16 +0000)]
Daily bump.

4 years agoPowerPC: rename some functions.
Michael Meissner [Fri, 11 Sep 2020 22:10:14 +0000 (18:10 -0400)]
PowerPC: rename some functions.

gcc/
2020-09-11  Michael Meissner  <meissner@linux.ibm.com>

* config/rs6000/rs6000.c (rs6000_maybe_emit_maxc_minc): Rename
from rs6000_emit_p9_fp_minmax.  Change return type to bool.  Add
comments to document NaN/signed zero behavior.
(rs6000_maybe_emit_fp_cmove): Rename from rs6000_emit_p9_fp_cmove.
(have_compare_and_set_mask): New helper function.
(rs6000_emit_cmove): Update calls to new names and the new helper
function.

4 years agoi386: Fix array index in expander
Nathan Sidwell [Fri, 11 Sep 2020 21:13:52 +0000 (14:13 -0700)]
i386: Fix array index in expander

I noticed a compiler warning about out-of-bound access.  Fixed thusly.

gcc/
* config/i386/sse.md (mov<mode>): Fix operand indices.

4 years agolibstdc++: only pull in bits/align.h if C++11 or later
Thomas Rodgers [Fri, 11 Sep 2020 20:51:07 +0000 (13:51 -0700)]
libstdc++: only pull in bits/align.h if C++11 or later

libstdc++-v3/ChangeLog:

* include/std/memory: Move #include <bits/align.h> inside C++11
conditional includes.

4 years agoc++: Concepts and local externs
Nathan Sidwell [Fri, 11 Sep 2020 20:42:59 +0000 (13:42 -0700)]
c++: Concepts and local externs

I discovered that we'd accept constraints on block-scope function
decls inside templates.  This fixes that.

gcc/cp/
* decl.c (grokfndecl): Don't attach to local extern.

4 years ago[PATCH,rs6000] Testsuite fixup pr96139 tests
Will Schmidt [Wed, 9 Sep 2020 15:59:38 +0000 (10:59 -0500)]
[PATCH,rs6000] Testsuite fixup pr96139 tests

Hi,
  As reported, the recently added pr96139 tests will fail on older targets
  because the tests are missing the appropriate -mvsx or -maltivec options.
  This adds the options and clarifies the dg-require statements.

  The pr96139-c.c test needs -maltivec to work, but does not actually use
  vectors, so does not require -mvsx like the others.

  Sniff-regtested OK when specifying older targets on a power7 host.
  --target_board=unix/'{-mcpu=power4,-mcpu=power5,-mcpu=power6,-mcpu=power7,
  -mcpu=power8,-mcpu=power9}''{-m64,-m32}'"

gcc/testsuite/ChangeLog:
* gcc.target/powerpc/pr96139-a.c: Specify -mvsx option and update the
dg-require stanza to match.
* gcc.target/powerpc/pr96139-b.c: Same.
* gcc.target/powerpc/pr96139-c.c: Specify -maltivec option and update
the dg-require stanza to match.

4 years agolibstdc++: Split std::align/assume_aligned to bits/align.h
Thomas Rodgers [Fri, 11 Sep 2020 18:55:18 +0000 (11:55 -0700)]
libstdc++: Split std::align/assume_aligned to bits/align.h

We would like to be able to use std::align and std::assume_aligned
without pulling in everything in <memory>.

libstdc++-v3/ChangeLog:

* include/Makefile.am (bits_headers): Add new header.
* include/Makefile.in: Regenerate.
* include/bits/align.h: New file.
* include/std/memory (align): Move definition to bits/align.h.
(assume_aligned): Likewise.

4 years agolibstdc++: Fix chrono::__detail::ceil to work with C++11
Jonathan Wakely [Fri, 11 Sep 2020 18:59:11 +0000 (19:59 +0100)]
libstdc++: Fix chrono::__detail::ceil to work with C++11

In C++11 constexpr functions can only have a return statement, so we
need to fix __detail::ceil to make it valid in C++11. This can be done
by moving the comparison and increment into a new function, __ceil_impl,
and calling that with the result of the duration_cast.

This would mean the standard C++17 std::chrono::ceil function would make
two further calls, which would add too much overhead when not inlined.
For C++17 and later use a using-declaration to add chrono::ceil to
namespace __detail. For C++11 and C++14 define chrono::__detail::__ceil
as a C++11-compatible constexpr function template.

libstdc++-v3/ChangeLog:

* include/std/chrono [C++17] (chrono::__detail::ceil): Add
using declaration to make chrono::ceil available for internal
use with a consistent name.
(chrono::__detail::__ceil_impl): New function template.
(chrono::__detail::ceil): Use __ceil_impl to compare and
increment the value. Remove SFINAE constraint.

4 years agoFix fma test case [PR97018]
Sunil K Pandey [Fri, 11 Sep 2020 06:17:59 +0000 (23:17 -0700)]
Fix fma test case [PR97018]

These tests are written for 256 bit vector. For -march=cascadelake,
vector size changed to 512 bit. It doubles the number of fma
instruction and test fail. Fix is to explicitly disable 512 bit
vector by passing additional option -mno-avx512f.

Tested on x86-64.

gcc/testsuite/ChangeLog:

PR target/97018
* gcc.target/i386/l_fma_double_1.c: Add option -mno-avx512f.
* gcc.target/i386/l_fma_double_2.c: Likewise.
* gcc.target/i386/l_fma_double_3.c: Likewise.
* gcc.target/i386/l_fma_double_4.c: Likewise.
* gcc.target/i386/l_fma_double_5.c: Likewise.
* gcc.target/i386/l_fma_double_6.c: Likewise.
* gcc.target/i386/l_fma_float_1.c: Likewise.
* gcc.target/i386/l_fma_float_2.c: Likewise.
* gcc.target/i386/l_fma_float_3.c: Likewise.
* gcc.target/i386/l_fma_float_4.c: Likewise.
* gcc.target/i386/l_fma_float_5.c: Likewise.
* gcc.target/i386/l_fma_float_6.c: Likewise.

4 years agoMove/correct offset adjustment (PR middle-end/96903).
Martin Sebor [Fri, 11 Sep 2020 15:40:45 +0000 (09:40 -0600)]
Move/correct offset adjustment (PR middle-end/96903).

Resolves:
PR middle-end/96903 - bogus warning on memcpy at negative offset from array end

gcc/ChangeLog:

PR middle-end/96903
* builtins.c (compute_objsize): Remove incorrect offset adjustment.
(compute_objsize): Adjust offset range here instead.

gcc/testsuite/ChangeLog:

PR middle-end/96903
* gcc.dg/Wstringop-overflow-42.c:: Add comment.
* gcc.dg/Wstringop-overflow-43.c: New test.

4 years agoobjc++: Always pop scope with method definitions [PR97015]
Nathan Sidwell [Fri, 11 Sep 2020 15:23:32 +0000 (08:23 -0700)]
objc++: Always pop scope with method definitions [PR97015]

Syntax errors in method definition lists could leave us in a function
scope.  My recent change for block scope externs didn't like that.
This reimplements the parsing loop to finish the method definition we
started.  AFAICT the original code was attempting to provide some
error recovery.  Also while there, simply do the token peeking at the
top of the loop, rather than at the two(!) ends.

gcc/cp/
* parser.c (cp_parser_objc_method_definition_list): Reimplement
loop, make sure we pop scope.
gcc/testsuite/
* obj-c++.dg/syntax-error-9.mm: Adjust expected errors.

4 years agoc++: Remove LOOKUP_CONSTINIT.
Marek Polacek [Thu, 10 Sep 2020 23:18:34 +0000 (19:18 -0400)]
c++: Remove LOOKUP_CONSTINIT.

Since we now have DECL_DECLARED_CONSTINIT_P, we no longer need
LOOKUP_CONSTINIT.

gcc/cp/ChangeLog:

* cp-tree.h (LOOKUP_CONSTINIT): Remove.
(LOOKUP_REWRITTEN): Adjust.
* decl.c (duplicate_decls): Set DECL_DECLARED_CONSTINIT_P.
(check_initializer): Use DECL_DECLARED_CONSTINIT_P instead of
LOOKUP_CONSTINIT.
(cp_finish_decl): Don't set DECL_DECLARED_CONSTINIT_P.  Use
DECL_DECLARED_CONSTINIT_P instead of LOOKUP_CONSTINIT.
(grokdeclarator): Set DECL_DECLARED_CONSTINIT_P.
* decl2.c (grokfield): Don't handle LOOKUP_CONSTINIT.
* parser.c (cp_parser_decomposition_declaration): Remove
LOOKUP_CONSTINIT handling.
(cp_parser_init_declarator): Likewise.
* pt.c (tsubst_expr): Likewise.
(instantiate_decl): Likewise.
* typeck2.c (store_init_value): Use DECL_DECLARED_CONSTINIT_P instead
of LOOKUP_CONSTINIT.

4 years agolibstdc++: Fix build error in <bits/regex_error.h>
Jonathan Wakely [Fri, 11 Sep 2020 13:51:36 +0000 (14:51 +0100)]
libstdc++: Fix build error in <bits/regex_error.h>

libstdc++-v3/ChangeLog:

* include/bits/regex_error.h (__throw_regex_error): Fix
parameter declaration and use reserved attribute names.

4 years agolibstdc++: Avoid rounding errors on custom clocks in condition_variable
Mike Crowe [Fri, 11 Sep 2020 13:25:00 +0000 (14:25 +0100)]
libstdc++: Avoid rounding errors on custom clocks in condition_variable

The fix for PR68519 in 83fd5e73b3c16296e0d7ba54f6c547e01c7eae7b only
applied to condition_variable::wait_for. This problem can also apply to
condition_variable::wait_until but only if the custom clock is using a
more recent epoch so that a small enough delta can be calculated. let's
use the newly-added chrono::__detail::ceil to fix this and also make use
of that function to simplify the previous wait_for fixes.

Also, simplify the existing test case for PR68519 a little and make its
variables local so we can add a new test case for the above problem.
Unfortunately, the test would have only started failing if sufficient
time has passed since the chrono::steady_clock epoch had passed anyway,
but it's better than nothing.

libstdc++-v3/ChangeLog:

* include/std/condition_variable (condition_variable::wait_until):
Convert delta to steady_clock duration before adding to current
steady_clock time to avoid rounding errors described in PR68519.
(condition_variable::wait_for): Simplify calculation of absolute
time by using chrono::__detail::ceil in both overloads.
* testsuite/30_threads/condition_variable/members/68519.cc:
(test_wait_for): Renamed from test01. Replace unassigned val
variable with constant false. Reduce scope of mx and cv
variables to just test_wait_for function.
(test_wait_until): Add new test case.

4 years agolibstdc++: Avoid rounding errors in std::future::wait_* [PR 91486]
Mike Crowe [Fri, 11 Sep 2020 13:25:00 +0000 (14:25 +0100)]
libstdc++: Avoid rounding errors in std::future::wait_* [PR 91486]

Convert the specified duration to the target clock's duration type
before adding it to the current time in
__atomic_futex_unsigned::_M_load_when_equal_for and
_M_load_when_equal_until.  This removes the risk of the timeout being
rounded down to the current time resulting in there being no wait at all
when the duration type lacks sufficient precision to hold the
steady_clock current time.

Rather than using the style of fix from PR68519, let's expose the C++17
std::chrono::ceil function as std::chrono::__detail::ceil so that it can
be used in code compiled with earlier standards versions and simplify
the fix. This was suggested by John Salmon in
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91486#c5 .

This problem has become considerably less likely to trigger since I
switched the __atomic__futex_unsigned::__clock_t reference clock from
system_clock to steady_clock and added the loop, but the consequences of
triggering it have changed too.

By my calculations it takes just over 194 days from the epoch for the
current time not to be representable in a float. This means that
system_clock is always subject to the problem (with the standard 1970
epoch) whereas steady_clock with float duration only runs out of
resolution machine has been running for that long (assuming the Linux
implementation of CLOCK_MONOTONIC.)

The recently-added loop in
__atomic_futex_unsigned::_M_load_when_equal_until turns this scenario
into a busy wait.

Unfortunately the combination of both of these things means that it's
not possible to write a test case for this occurring in
_M_load_when_equal_until as it stands.

libstdc++-v3/ChangeLog:

PR libstdc++/91486
* include/bits/atomic_futex.h
(__atomic_futex_unsigned::_M_load_when_equal_for)
(__atomic_futex_unsigned::_M_load_when_equal_until): Use
__detail::ceil to convert delta to the reference clock
duration type to avoid resolution problems.
* include/std/chrono (__detail::ceil): Move implementation
of std::chrono::ceil into private namespace so that it's
available to pre-C++17 code.
* testsuite/30_threads/async/async.cc (test_pr91486):
Test __atomic_futex_unsigned::_M_load_when_equal_for.

4 years agolibstdc++: Loop when futex waits against arbitrary clock
Mike Crowe [Fri, 11 Sep 2020 13:25:00 +0000 (14:25 +0100)]
libstdc++: Loop when futex waits against arbitrary clock

If std::future::wait_until is passed a time point measured against a
clock that is neither std::chrono::steady_clock nor
std::chrono::system_clock then the generic implementation of
__atomic_futex_unsigned::_M_load_when_equal_until is called which
calculates the timeout based on __clock_t and calls the
_M_load_when_equal_until method for that clock to perform the actual
wait.

There's no guarantee that __clock_t is running at the same speed as the
caller's clock, so if the underlying wait times out timeout we need to
check the timeout against the caller's clock again before potentially
looping.

Also add two extra tests to the testsuite's async.cc:

* run test03 with steady_clock_copy, which behaves identically to
  chrono::steady_clock, but isn't chrono::steady_clock. This causes
  the overload of __atomic_futex_unsigned::_M_load_when_equal_until
  that takes an arbitrary clock to be called.

* invent test04 which uses a deliberately slow running clock in order
  to exercise the looping behaviour of
  __atomic_futex_unsigned::_M_load_when_equal_until described above.

libstdc++-v3/ChangeLog:

* include/bits/atomic_futex.h
(__atomic_futex_unsigned::_M_load_when_equal_until): Add
loop on generic _Clock to check the timeout against _Clock
again after _M_load_when_equal_until returns indicating a
timeout.
* testsuite/30_threads/async/async.cc: Invent slow_clock
that runs at an eleventh of steady_clock's speed. Use it
to test the user-supplied-clock variant of
__atomic_futex_unsigned::_M_load_when_equal_until works
generally with test03 and loops correctly when the timeout
time hasn't been reached in test04.

4 years agolibstdc++: Use std::chrono::steady_clock as atomic_futex reference clock
Mike Crowe [Fri, 11 Sep 2020 13:25:00 +0000 (14:25 +0100)]
libstdc++: Use std::chrono::steady_clock as atomic_futex reference clock

The user-visible effect of this change is that std::future::wait_for now
uses std::chrono::steady_clock to determine the timeout.  This makes it
immune to changes made to the system clock.  It also means that anyone
using their own clock types with std::future::wait_until will have the
timeout converted to std::chrono::steady_clock rather than
std::chrono::system_clock.

Now that use of both std::chrono::steady_clock and
std::chrono::system_clock are correctly supported for the wait timeout, I
believe that std::chrono::steady_clock is a better choice for the reference
clock that all other clocks are converted to since it is guaranteed to
advance steadily.  The previous behaviour of converting to
std::chrono::system_clock risks timeouts changing dramatically when the
system clock is changed.

libstdc++-v3/ChangeLog:

* include/bits/atomic_futex.h (__atomic_futex_unsigned): Change
__clock_t typedef to use steady_clock so that unknown clocks are
synced to it rather than system_clock. Change existing __clock_t
overloads of _M_load_and_text_until_impl and
_M_load_when_equal_until to use system_clock explicitly. Remove
comment about DR 887 since these changes address that problem as
best as we currently able.

4 years agolibstdc++: Support futex waiting on chrono::steady_clock directly
Mike Crowe [Fri, 11 Sep 2020 13:25:00 +0000 (14:25 +0100)]
libstdc++: Support futex waiting on chrono::steady_clock directly

The user-visible effect of this change is for std::future::wait_until to
use CLOCK_MONOTONIC when passed a timeout of std::chrono::steady_clock
type.  This makes it immune to any changes made to the system clock
CLOCK_REALTIME.

Add an overload of __atomic_futex_unsigned::_M_load_and_text_until_impl
that accepts a std::chrono::steady_clock, and correctly passes this
through to __atomic_futex_unsigned_base::_M_futex_wait_until_steady
which uses CLOCK_MONOTONIC for the timeout within the futex system call.
These functions are mostly just copies of the std::chrono::system_clock
versions with small tweaks.

Prior to this commit, a std::chrono::steady timeout would be converted
via std::chrono::system_clock which risks reducing or increasing the
timeout if someone changes CLOCK_REALTIME whilst the wait is happening.
(The commit immediately prior to this one increases the window of
opportunity for that from a short period during the calculation of a
relative timeout, to the entire duration of the wait.)

FUTEX_WAIT_BITSET was added in kernel v2.6.25.  If futex reports ENOSYS
to indicate that this operation is not supported then the code falls
back to using clock_gettime(2) to calculate a relative time to wait for.

I believe that I've added this functionality in a way that it doesn't
break ABI compatibility, but that has made it more verbose and less type
safe.  I believe that it would be better to maintain the timeout as an
instance of the correct clock type all the way down to a single
_M_futex_wait_until function with an overload for each clock.  The
current scheme of separating out the seconds and nanoseconds early risks
accidentally calling the wait function for the wrong clock.
Unfortunately, doing this would break code that compiled against the old
header.

libstdc++-v3/ChangeLog:

* config/abi/pre/gnu.ver: Update for addition of
__atomic_futex_unsigned_base::_M_futex_wait_until_steady.
* include/bits/atomic_futex.h (__atomic_futex_unsigned_base):
Add comments to clarify that _M_futex_wait_until and
_M_load_and_test_until use CLOCK_REALTIME.
(__atomic_futex_unsigned_base::_M_futex_wait_until_steady)
(__atomic_futex_unsigned_base::_M_load_and_text_until_steady):
New member functions that use CLOCK_MONOTONIC.
(__atomic_futex_unsigned_base::_M_load_and_test_until_impl)
(__atomic_futex_unsigned_base::_M_load_when_equal_until): Add
overloads that accept a steady_clock time_point and use the
new member functions.
* src/c++11/futex.cc: Include headers required for
clock_gettime.
(futex_clock_monotonic_flag): New constant to tell futex to
use CLOCK_MONOTONIC to match existing futex_clock_realtime_flag.
(futex_clock_monotonic_unavailable): New global to store the
result of trying to use CLOCK_MONOTONIC.
(__atomic_futex_unsigned_base::_M_futex_wait_until_steady): Add
new variant of _M_futex_wait_until that uses CLOCK_MONOTONIC to
support waiting using steady_clock.

4 years agolibstdc++: Use FUTEX_CLOCK_REALTIME for futex wait
Mike Crowe [Fri, 11 Sep 2020 13:24:59 +0000 (14:24 +0100)]
libstdc++: Use FUTEX_CLOCK_REALTIME for futex wait

The futex system call supports waiting for an absolute time if
FUTEX_WAIT_BITSET is used rather than FUTEX_WAIT.  Doing so provides two
benefits:

1. The call to gettimeofday is not required in order to calculate a
   relative timeout.

2. If someone changes the system clock during the wait then the futex
   timeout will correctly expire earlier or later.  Currently that only
   happens if the clock is changed prior to the call to gettimeofday.

According to futex(2), support for FUTEX_CLOCK_REALTIME was added in the
v2.6.28 Linux kernel and FUTEX_WAIT_BITSET was added in v2.6.25.  To
ensure that the code still works correctly with earlier kernel versions,
an ENOSYS error from futex[1] results in the
futex_clock_realtime_unavailable flag being set.  This flag is used to
avoid the unnecessary unsupported futex call in the future and to fall
back to the previous gettimeofday and relative time implementation.

glibc applied an equivalent switch in pthread_cond_timedwait to use
FUTEX_CLOCK_REALTIME and FUTEX_WAIT_BITSET rather than FUTEX_WAIT for
glibc-2.10 back in 2009.  See
glibc:cbd8aeb836c8061c23a5e00419e0fb25a34abee7

The futex_clock_realtime_unavailable flag is accessed using
std::memory_order_relaxed to stop it becoming a bottleneck.  If the
first two calls to _M_futex_wait_until happen to happen simultaneously
then the only consequence is that both will try to use
FUTEX_CLOCK_REALTIME, both risk discovering that it doesn't work and, if
so, both set the flag.

[1] This is how glibc's nptl-init.c determines whether these flags are
    supported.

libstdc++-v3/ChangeLog:

* src/c++11/futex.cc: Add new constants for required futex
flags.  Add futex_clock_realtime_unavailable flag to store
result of trying to use FUTEX_CLOCK_REALTIME.
(__atomic_futex_unsigned_base::_M_futex_wait_until): Try to
use FUTEX_WAIT_BITSET with FUTEX_CLOCK_REALTIME and only
fall back to using gettimeofday and FUTEX_WAIT if that's not
supported.

4 years agolibstdc++: Improve std::async test
Mike Crowe [Fri, 11 Sep 2020 13:24:59 +0000 (14:24 +0100)]
libstdc++: Improve std::async test

Add tests for waiting for the future using both chrono::steady_clock and
chrono::system_clock in preparation for dealing with those clocks
properly in futex.cc.

libstdc++-v3/ChangeLog:

* testsuite/30_threads/async/async.cc (test02): Test steady_clock
with std::future::wait_until.
(test03): Add new test templated on clock type waiting for future
associated with async to resolve.
(main): Call test03 to test both system_clock and steady_clock.

4 years agolibstdc++-v3/libsupc++/eh_call.cc: Avoid "set but not used" warning
Christophe Lyon [Fri, 11 Sep 2020 12:07:02 +0000 (12:07 +0000)]
libstdc++-v3/libsupc++/eh_call.cc: Avoid "set but not used" warning

When building with -fno-exceptions, bad_exception_allowed is set but
not used, causing a warning during the build.

This patch adds __attribute__((unused)) to avoid it.

2020-09-11  Torbjörn SVENSSON  <torbjorn.svensson@st.com>
    Christophe Lyon  <christophe.lyon@linaro.org>

libstdc++-v3/
* libsupc++/eh_call.cc: Avoid warning with -fno-exceptions.

4 years agolibstdc++-v3/libsupc++/eh_call.cc: Avoid warning with -fno-exceptions.
Christophe Lyon [Fri, 11 Sep 2020 09:21:55 +0000 (09:21 +0000)]
libstdc++-v3/libsupc++/eh_call.cc: Avoid warning with -fno-exceptions.

When building with -fno-exceptions, __throw_exception_again expands to
nothing, causing a "suggest braces around empty body in an 'if'
statement" warning.

This patch adds braces, like what was done in eh_personality.cc in svn
r193295 (git g:54ba39f599fc2f3d59fd3cd828a301ce9b731a20)

2020-09-11  Torbjörn SVENSSON  <torbjorn.svensson@st.com>
    Christophe Lyon  <christophe.lyon@linaro.org>

libstdc++-v3/
* libsupc++/eh_call.cc: Avoid warning with -fno-exceptions.

4 years agolibstdc++-v3/include/bits/regex_error.h: Avoid warning with -fno-exceptions.
Christophe Lyon [Fri, 11 Sep 2020 11:53:15 +0000 (11:53 +0000)]
libstdc++-v3/include/bits/regex_error.h: Avoid warning with -fno-exceptions.

When building with -fno-exceptions, __GLIBCXX_THROW_OR_ABORT expands to
abort(), causing warnings:
unused parameter '__ecode'
unused parameter '__what'

This patch adds __attribute__((unused)) to avoid them.

2020-09-11  Torbjörn SVENSSON <torbjorn.svensson@st.com>
    Christophe Lyon  <christophe.lyon@linaro.org>

libstdc++-v3/
* include/bits/regex_error.h: Avoid warning with -fno-exceptions.

4 years agotree-optimization/97020 - account SLP cost in loop vect again
Richard Biener [Fri, 11 Sep 2020 11:51:58 +0000 (13:51 +0200)]
tree-optimization/97020 - account SLP cost in loop vect again

The previous re-org made the cost of SLP vector stmts in loop
vectorization ignored.  The following rectifies this mistake.

2020-09-11  Richard Biener  <rguenther@suse.de>

PR tree-optimization/97020
* tree-vect-slp.c (vect_slp_analyze_operations): Apply
SLP costs when doing loop vectorization.

4 years agotestsuite: gimplefe-44 requires exceptions
Andrew Stubbs [Thu, 10 Sep 2020 13:58:15 +0000 (14:58 +0100)]
testsuite: gimplefe-44 requires exceptions

This avoids an ICE on amdgcn.

gcc/testsuite/ChangeLog:

* gcc.dg/gimplefe-44.c: Require exceptions.

4 years agolibgccjit: Add new gcc_jit_global_set_initializer entry point
Andrea Corallo [Sat, 30 May 2020 09:33:08 +0000 (10:33 +0100)]
libgccjit: Add new gcc_jit_global_set_initializer entry point

gcc/jit/ChangeLog

2020-08-01  Andrea Corallo  <andrea.corallo@arm.com>

* docs/topics/compatibility.rst (LIBGCCJIT_ABI_14): New ABI tag.
* docs/topics/expressions.rst (gcc_jit_global_set_initializer):
Document new entry point in section 'Global variables'.
* jit-playback.c (global_new_decl, global_finalize_lvalue): New
method.
(playback::context::new_global): Make use of global_new_decl,
global_finalize_lvalue.
(load_blob_in_ctor): New template function in use by the
following.
(playback::context::new_global_initialized): New method.
* jit-playback.h (class context): Decl 'new_global_initialized',
'global_new_decl', 'global_finalize_lvalue'.
(lvalue::set_initializer): Add implementation.
* jit-recording.c (recording::memento_of_get_pointer::get_size)
(recording::memento_of_get_type::get_size): Add implementation.
(recording::global::write_initializer_reproducer): New function in
use by 'recording::global::write_reproducer'.
(recording::global::replay_into)
(recording::global::write_to_dump)
(recording::global::write_reproducer): Handle
initialized case.
* jit-recording.h (class type): Decl 'get_size' and
'num_elements'.
* libgccjit++.h (class lvalue): Declare new 'set_initializer'
method.
(class lvalue): Decl 'is_global' and 'set_initializer'.
(class global) Decl 'write_initializer_reproducer'. Add
'm_initializer', 'm_initializer_num_bytes' fields.  Implement
'set_initializer'. Add a destructor to free 'm_initializer'.
* libgccjit.c (gcc_jit_global_set_initializer): New function.
* libgccjit.h (gcc_jit_global_set_initializer): New function
declaration.
* libgccjit.map (LIBGCCJIT_ABI_14): New ABI tag.

gcc/testsuite/ChangeLog

2020-08-01  Andrea Corallo  <andrea.corallo@arm.com>

* jit.dg/all-non-failing-tests.h: Add test-blob.c.
* jit.dg/test-global-set-initializer.c: New testcase.

4 years ago[libatomic] Add nvptx support
Tom de Vries [Mon, 7 Sep 2020 08:47:25 +0000 (10:47 +0200)]
[libatomic] Add nvptx support

Add nvptx support to libatomic.

Given that atomic_test_and_set is not implemented for nvptx (PR96964), the
compiler translates __atomic_test_and_set falling back onto the "Failing all
else, assume a single threaded environment and simply perform the operation"
case in expand_atomic_test_and_set, so it doesn't map onto an actual atomic
operation.

Still, that counts as supported for the configure test of libatomic, so we
end up with HAVE_ATOMIC_TAS_1/2/4/8/16 == 1, and the corresponding
__atomic_test_and_set_1/2/4/8/16 in libatomic all using that non-atomic
implementation.

Fix this by adding an atomic_test_and_set expansion for nvptx, that uses
libatomics __atomic_test_and_set_1.

This again makes the configure tests for HAVE_ATOMIC_TAS_1/2/4/8/16 fail, so
instead we use this case in tas_n.c:
...
/* If this type is smaller than word-sized, fall back to a word-sized
   compare-and-swap loop.  */
bool
SIZE(libat_test_and_set) (UTYPE *mptr, int smodel)
...
which for __atomic_test_and_set_8 uses INVERT_MASK_8.

Add INVERT_MASK_8 in libatomic_i.h, as well as MASK_8.

Tested libatomic testsuite on nvptx.

gcc/ChangeLog:

PR target/96964
* config/nvptx/nvptx.md (define_expand "atomic_test_and_set"): New
expansion.

libatomic/ChangeLog:

PR target/96898
* configure.tgt: Add nvptx.
* libatomic_i.h (MASK_8, INVERT_MASK_8): New macro definition.
* config/nvptx/host-config.h: New file.
* config/nvptx/lock.c: New file.

4 years agoamdgcn: align TImode registers
Andrew Stubbs [Thu, 10 Sep 2020 09:10:32 +0000 (10:10 +0100)]
amdgcn: align TImode registers

This prevents execution failures caused by partially overlapping input and
output registers.  This is the same solution already used for DImode.

gcc/ChangeLog:

* config/gcn/gcn.c (gcn_hard_regno_mode_ok): Align TImode registers.
* config/gcn/gcn.md: Assert that TImode registers do not early clobber.

4 years agoimprove BB vectorization dump locations
Richard Biener [Fri, 11 Sep 2020 07:57:18 +0000 (09:57 +0200)]
improve BB vectorization dump locations

This tries to improve BB vectorization dumps by providing more
precise locations.  Currently the vect_location is simply the
very last stmt in a basic-block that has a location.  So for

double a[4], b[4];
int x[4], y[4];
void foo()
{
  a[0] = b[0]; // line 5
  a[1] = b[1];
  a[2] = b[2];
  a[3] = b[3];
  x[0] = y[0]; // line 9
  x[1] = y[1];
  x[2] = y[2];
  x[3] = y[3];
} // line 13

we show the user with -O3 -fopt-info-vec

t.c:13:1: optimized: basic block part vectorized using 16 byte vectors

while with the patch we point to both independently vectorized
opportunities:

t.c:5:8: optimized: basic block part vectorized using 16 byte vectors
t.c:9:8: optimized: basic block part vectorized using 16 byte vectors

there's the possibility that the location regresses in case the
root stmt in the SLP instance has no location.  For a SLP subgraph
with multiple entries the location also chooses one entry at random,
not sure in which case we want to dump both.

Still as the plan is to extend the basic-block vectorization
scope from single basic-block to multiple ones this is a first
step to preserve something sensible.

Implementation-wise this makes both costing and code-generation
happen on the subgraphs as analyzed.

2020-09-11  Richard Biener  <rguenther@suse.de>

* tree-vectorizer.h (_slp_instance::location): New method.
(vect_schedule_slp): Adjust prototype.
* tree-vectorizer.c (vec_info::remove_stmt): Adjust
the BB region begin if we removed the stmt it points to.
* tree-vect-loop.c (vect_transform_loop): Adjust.
* tree-vect-slp.c (_slp_instance::location): Implement.
(vect_analyze_slp_instance): For BB vectorization set
vect_location to that of the instance.
(vect_slp_analyze_operations): Likewise.
(vect_bb_vectorization_profitable_p): Remove wrapper.
(vect_slp_analyze_bb_1): Remove cost check here.
(vect_slp_region): Cost check and code generate subgraphs separately,
report optimized locations and missed optimizations due to
profitability for each of them.
(vect_schedule_slp): Get the vector of SLP graph entries to
vectorize as argument.

4 years agoFix ICE on nested packed variant record type
Eric Botcazou [Fri, 11 Sep 2020 09:14:49 +0000 (11:14 +0200)]
Fix ICE on nested packed variant record type

This is a regression present on the mainline and 10 branch: the compiler
aborts on code accessing a component of a packed record type whose type
is a packed discriminated record type with variant part.

gcc/ada/ChangeLog:
* gcc-interface/utils.c (type_has_variable_size): New function.
(create_field_decl): In the packed case, also force byte alignment
when the type of the field has variable size.

gcc/testsuite/ChangeLog:
* gnat.dg/pack27.adb: New test.
* gnat.dg/pack27_pkg.ads: New helper.

4 years agoAdd missing stride entry in debug info
Eric Botcazou [Fri, 11 Sep 2020 09:13:54 +0000 (11:13 +0200)]
Add missing stride entry in debug info

This adds a missing stride entry for bit-packed arrays of record types.

gcc/ada/ChangeLog:
* gcc-interface/misc.c (get_array_bit_stride): Return TYPE_ADA_SIZE
for record and union types.

4 years agoDrop GNAT encodings for fixed-point types
Eric Botcazou [Fri, 11 Sep 2020 08:54:11 +0000 (10:54 +0200)]
Drop GNAT encodings for fixed-point types

GDB can now deal with the DWARF representation just fine.

gcc/ada/ChangeLog:
* gcc-interface/misc.c (gnat_get_fixed_point_type): Bail out only
when the GNAT encodings are specifically used.

4 years agoFix crash on array component with nonstandard index type
Eric Botcazou [Fri, 11 Sep 2020 08:41:28 +0000 (10:41 +0200)]
Fix crash on array component with nonstandard index type

This is a regression present on mainline, 10 and 9 branches: the compiler
goes into an infinite recursion eventually exhausting the stack for the
declaration of a discriminated record type with an array component having
a discriminant as bound and an index type that is an enumeration type with
a non-standard representation clause.

gcc/ada/ChangeLog:
* gcc-interface/decl.c (gnat_to_gnu_entity) <E_Array_Subtype>: Only
create extra subtypes for discriminants if the RM size of the base
type of the index type is lower than that of the index type.

gcc/testsuite/ChangeLog:
* gnat.dg/specs/discr7.ads: New test.

4 years agoAdjust email address
Eric Botcazou [Fri, 11 Sep 2020 08:16:17 +0000 (10:16 +0200)]
Adjust email address

4 years agoAdjust email address
Eric Botcazou [Fri, 11 Sep 2020 08:12:28 +0000 (10:12 +0200)]
Adjust email address

4 years agoAdjust email address
Eric Botcazou [Fri, 11 Sep 2020 08:09:59 +0000 (10:09 +0200)]
Adjust email address

4 years agotree-optimization/97013 - avoid duplicate 'vectorization is not profitable'
Richard Biener [Fri, 11 Sep 2020 06:59:58 +0000 (08:59 +0200)]
tree-optimization/97013 - avoid duplicate 'vectorization is not profitable'

This avoids dumping 'vectorization is not profitable' one more time
if none of the opportunities in a BB is profitable.

2020-09-11  Richard Biener  <rguenther@suse.de>

PR tree-optimization/97013
* tree-vect-slp.c (vect_slp_analyze_bb_1): Remove duplicate dumping.

4 years agorandom vectorizer fixes
Richard Biener [Thu, 10 Sep 2020 14:23:29 +0000 (16:23 +0200)]
random vectorizer fixes

This fixes random things found when doing SLP discovery from
arbitrary sets of stmts.

2020-09-10  Richard Biener  <rguenther@suse.de>

* tree-vect-slp.c (vect_build_slp_tree_1): Check vector
types for all lanes are compatible.
(vect_analyze_slp_instance): Appropriately check for stores.
(vect_schedule_slp): Likewise.

4 years ago[nvptx] Fix UB in nvptx_assemble_value
Tom de Vries [Fri, 11 Sep 2020 05:13:25 +0000 (07:13 +0200)]
[nvptx] Fix UB in nvptx_assemble_value

When nvptx_assemble_value is called with size == 16, this bitshift runs
into UB:
...
  val &= ((unsigned  HOST_WIDE_INT)2 << (size * BITS_PER_UNIT - 1)) - 1;
...

Fix this by checking the shift amount.

Tested on nvptx.

gcc/ChangeLog:

* config/nvptx/nvptx.c (nvptx_assemble_value): Fix undefined
behaviour.

4 years ago[nvptx] Fix printing of 128-bit constant (negative case)
Tom de Vries [Fri, 11 Sep 2020 03:40:36 +0000 (05:40 +0200)]
[nvptx] Fix printing of 128-bit constant (negative case)

For this code:
...
__int128 min_one = -1;
...
we currently generate:
...
.visible .global .align 8 .u64 min_one[2] = { -1, 0 };
...

Fix this in nvptx_assemble_value, such that we have instead:
...
.visible .global .align 8 .u64 min_one[2] = { -1, -1 };
...

gcc/ChangeLog:

* config/nvptx/nvptx.c (nvptx_assemble_value): Handle negative
__int128.

gcc/testsuite/ChangeLog:

* gcc.target/nvptx/int128.c: New test.

4 years ago[PATCH][PR96791] disable POImode ld/st for memcpy
Aaron Sawdey [Thu, 10 Sep 2020 20:12:49 +0000 (15:12 -0500)]
[PATCH][PR96791] disable POImode ld/st for memcpy

This is a (hopefully temporary) fix to PR96791. This will make
the default be -mno-block-ops-vector-pair even on power10, so we will
not hit the issue of DSE trying to truncate a POImode register. I am
still concerned it will be possible to hit this because the MMA builtins
will also generate POImode stores, but I think any example of that will
be somewhat more contrived.

gcc/ChangeLog:

* config/rs6000/rs6000.c (rs6000_option_override_internal):
Change default.

4 years agoanalyzer: stricter handling of non-pure builtins [PR96798]
David Malcolm [Mon, 31 Aug 2020 19:55:45 +0000 (15:55 -0400)]
analyzer: stricter handling of non-pure builtins [PR96798]

Amongst other things PR analyzer/96798 notes that
region_model::on_call_pre treats any builtin that hasn't been coded
yet as a no-op (albeit with an unknown return value), which is wrong
for non-pure builtins.

This patch updates that function's handling of such builtins so that it
instead conservatively assumes that any escaped/reachable regions can
be affected by the call, and implements enough handling of specific
builtins to avoid regressing the testsuite (I hope).

gcc/analyzer/ChangeLog:
PR analyzer/96798
* region-model-impl-calls.cc (region_model::impl_call_memcpy):
New.
(region_model::impl_call_strcpy): New.
* region-model.cc (region_model::on_call_pre): Flag unhandled
builtins that are non-pure as having unknown side-effects.
Implement BUILT_IN_MEMCPY, BUILT_IN_MEMCPY_CHK, BUILT_IN_STRCPY,
BUILT_IN_STRCPY_CHK, BUILT_IN_FPRINTF, BUILT_IN_FPRINTF_UNLOCKED,
BUILT_IN_PUTC, BUILT_IN_PUTC_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_PUTCHAR,
BUILT_IN_PUTCHAR_UNLOCKED, BUILT_IN_PUTS, BUILT_IN_PUTS_UNLOCKED,
BUILT_IN_VFPRINTF, BUILT_IN_VPRINTF.
* region-model.h (region_model::impl_call_memcpy): New decl.
(region_model::impl_call_strcpy): New decl.

gcc/testsuite/ChangeLog:
PR analyzer/96798
* gcc.dg/analyzer/memcpy-1.c: New test.
* gcc.dg/analyzer/strcpy-1.c: New test.

4 years agoDaily bump.
GCC Administrator [Fri, 11 Sep 2020 00:16:28 +0000 (00:16 +0000)]
Daily bump.

4 years agoPowerPC: Change cmove function return to bool.
Michael Meissner [Thu, 10 Sep 2020 23:11:45 +0000 (19:11 -0400)]
PowerPC: Change cmove function return to bool.

In doing the other work for adding ISA 3.1 128-bit minimum, maximum, and
conditional move support, I noticed the two functions that process conditional
moves return 'int' instead of 'bool'.  This patch changes these functions to
return 'bool'.

gcc/
2020-09-10  Michael Meissner  <meissner@linux.ibm.com>

* config/rs6000/rs6000-protos.h (rs6000_emit_cmove): Change return
type to bool.
(rs6000_emit_int_cmove): Change return type to bool.
* config/rs6000/rs6000.c (rs6000_emit_cmove): Change return type
to bool.
(rs6000_emit_int_cmove): Change return type to bool.

4 years ago[nvptx] Fix printing of 128-bit constant
Tom de Vries [Thu, 10 Sep 2020 13:54:14 +0000 (15:54 +0200)]
[nvptx] Fix printing of 128-bit constant

Currently, for this code from c-c++-common/spec-barrier-1.c:
...
__int128 g = 9;
...
we generate:
...
// BEGIN GLOBAL VAR DEF: g
.visible .global .align 8 .u64 g[2] = { 9, 9 };
...
and consequently the test-case fails in execution.

The problem is caused by a shift in nvptx_assemble_value:
...
      val >>= part * BITS_PER_UNIT;
...
where the shift amount is equal to the number of bits in val, which is
undefined behaviour.

Fix this by detecting the situation and setting val to 0.

Tested on nvptx.

gcc/ChangeLog:

PR target/97004
* config/nvptx/nvptx.c (nvptx_assemble_value): Handle shift by
number of bits in shift operand.

4 years agolto: Fix up lto BLOCK tree streaming
Jakub Jelinek [Thu, 10 Sep 2020 18:55:46 +0000 (20:55 +0200)]
lto: Fix up lto BLOCK tree streaming

When I've tried to backport recent LTO changes of mine, I've ran into
FAIL: g++.dg/ubsan/align-3.C   -O2 -flto -fno-use-linker-plugin -flto-partition=none  output pattern test
FAIL: g++.dg/ubsan/align-3.C   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  output pattern test
regressions that don't for some reason show up on the trunk.

I've tracked it down to input_location_and_block being called recursively,
first on some UBSAN_NULL ifn call's location which needs to stream a BLOCK
that hasn't been streamed yet, which in turn needs to stream some locations
for the decls in the BLOCK.

Looking at that align-3.C testcase on the trunk, I also see the recursive
lto_output_location_1 calls as well.  First on block:
$18 = <block 0x7fffea738480>
which is in the block tree from what I can see just fine (see the end of
mail).

Now, output_function has code that should stream the BLOCK tree leafs:
  /* Output DECL_INITIAL for the function, which contains the tree of
     lexical scopes.  */
  stream_write_tree (ob, DECL_INITIAL (function), true);
  /* As we do not recurse into BLOCK_SUBBLOCKS but only BLOCK_SUPERCONTEXT
     collect block tree leafs and stream those.  */
  auto_vec<tree> block_tree_leafs;
  if (DECL_INITIAL (function))
    collect_block_tree_leafs (DECL_INITIAL (function), block_tree_leafs);
  streamer_write_uhwi (ob, block_tree_leafs.length ());
  for (unsigned i = 0; i < block_tree_leafs.length (); ++i)
    stream_write_tree (ob, block_tree_leafs[i], true);

static void
collect_block_tree_leafs (tree root, vec<tree> &leafs)
{
  for (root = BLOCK_SUBBLOCKS (root); root; root = BLOCK_CHAIN (root))
    if (! BLOCK_SUBBLOCKS (root))
      leafs.safe_push (root);
    else
      collect_block_tree_leafs (BLOCK_SUBBLOCKS (root), leafs);
}

but the problem is that it is broken, it doesn't cover all block leafs,
but only leafs with an odd depth from DECL_INITIAL (and only some of those).

The following patch fixes that, but I guess we are going to stream at that
point significantly more blocks than before (though I guess most of the time
we'd stream them later on when streaming the gimple_locations that refer to
them).

2020-09-10  Jakub Jelinek  <jakub@redhat.com>

* lto-streamer-out.c (collect_block_tree_leafs): Recurse on
root rather than BLOCK_SUBBLOCKS (root).

4 years agolibstdc++: Fix -Wsign-compare warnings
Jonathan Wakely [Thu, 10 Sep 2020 17:57:39 +0000 (18:57 +0100)]
libstdc++: Fix -Wsign-compare warnings

libstdc++-v3/ChangeLog:

* include/bits/locale_conv.h (__do_str_codecvt, __str_codecvt_in_all):
Add casts to compare types of the same signedness.

4 years agolibstdc++: Fix -Wunused-local-typedefs warning
Jonathan Wakely [Thu, 10 Sep 2020 17:57:05 +0000 (18:57 +0100)]
libstdc++: Fix -Wunused-local-typedefs warning

libstdc++-v3/ChangeLog:

* include/bits/ranges_algobase.h (__equal_fn): Remove unused
typedef.

4 years agolibstdc++: Fix macro redefinition warnings
Jonathan Wakely [Thu, 10 Sep 2020 17:51:24 +0000 (18:51 +0100)]
libstdc++: Fix macro redefinition warnings

Including <version> after <iterator> gives a warning about redefining
the __cpp_lib_array_constexpr macro. What happens is that <iterator>
sets the C++20 value, then <version> redefines it to the C++17 value,
then undefines it and defines it again to the C++20 value.

This change avoids defining it to the C++17 value when compiling C++20
or later (which also means we no longer need the #undef).

A similar warning happens for __cpp_lib_constexpr_char_traits when
including <version> after any header that includes <bits/char_traits.h>.

libstdc++-v3/ChangeLog:

* include/std/version (__cpp_lib_array_constexpr):
(__cpp_lib_constexpr_char_traits): Only define C++17 value when
compiling C++17.

4 years agolibstdc++: Fix -Wdeprecated-declarations warnings
Jonathan Wakely [Thu, 10 Sep 2020 17:48:25 +0000 (18:48 +0100)]
libstdc++: Fix -Wdeprecated-declarations warnings

libstdc++-v3/ChangeLog:

* include/experimental/bits/shared_ptr.h (shared_ptr(auto_ptr&&))
(operator=(auto_ptr&&)): Add diagnostic pragmas to suppress
warnings for uses of std::auto_ptr.
* include/experimental/type_traits (is_literal_type_v):
Likewise, for use of std::is_literal_type.
* include/std/condition_variable (condition_variable_any::_Unlock):
Likewise, for use of std::uncaught_exception.

4 years agolibstdc++: Fix -Wnarrowing warnings
Jonathan Wakely [Thu, 10 Sep 2020 17:47:08 +0000 (18:47 +0100)]
libstdc++: Fix -Wnarrowing warnings

libstdc++-v3/ChangeLog:

* include/bits/fs_path.h (path::_List::type()): Avoid narrowing
conversion.
* include/std/chrono (operator+(const year&, const years&)):
Likewise.

4 years agoc++: TINFO_VAR_DECLARED_CONSTINIT -> DECL_DECLARED_CONSTINIT_P
Nathan Sidwell [Thu, 10 Sep 2020 13:53:31 +0000 (06:53 -0700)]
c++: TINFO_VAR_DECLARED_CONSTINIT -> DECL_DECLARED_CONSTINIT_P

We need to record whether template function-scopestatic decls are
constinit.  That's currently held on the var's TEMPLATE_INFO data.
But I want to get rid of such decl's template header as they're not
really templates, and they're never instantiated separately from their
containing function's definition.  (Just like auto vars, which don't
get them for instance).

This patch moves the flag into a spare decl_lang_flag.

gcc/cp/
* cp-tree.h (TINFO_VAR_DECLARED_CONSTINIT): Replace with ...
(DECL_DECLARED_CONSTINIT_P): ... this.
* decl.c (start_decl): No need to retrofit_lang_decl for constinit
flag.
(cp_finish_decl): Use DECL_DECLARED_CONSTINIT_P.
* pt.c (tsubst_decl): No need to handle constinit flag
propagation.
(tsubst_expr): Or here.

4 years agoaarch64: Add support for Cortex-R82
Alex Coplan [Thu, 10 Sep 2020 16:08:57 +0000 (17:08 +0100)]
aarch64: Add support for Cortex-R82

This adds support for Arm's Cortex-R82 CPU to GCC. For more information about
this CPU, see [0].

[0] : https://developer.arm.com/ip-products/processors/cortex-r/cortex-r82

gcc/ChangeLog:

* config/aarch64/aarch64-cores.def: Add Cortex-R82.
* config/aarch64/aarch64-tune.md: Regenerate.
* doc/invoke.texi: Add entry for Cortex-R82.

4 years agoaarch64: Add support for Armv8-R
Alex Coplan [Thu, 10 Sep 2020 16:05:40 +0000 (17:05 +0100)]
aarch64: Add support for Armv8-R

This adds support for Armv8-R AArch64 to GCC. It adds the -march value
armv8-r and sets the ACLE feature macro __ARM_ARCH_PROFILE correctly
when -march is set to armv8-r.

gcc/ChangeLog:

* common/config/aarch64/aarch64-common.c
(aarch64_get_extension_string_for_isa_flags): Don't force +crc for
Armv8-R.
* config/aarch64/aarch64-arches.def: Add entry for Armv8-R.
* config/aarch64/aarch64-c.c (aarch64_define_unconditional_macros): Set
__ARM_ARCH_PROFILE correctly for Armv8-R.
* config/aarch64/aarch64.h (AARCH64_FL_V8_R): New.
(AARCH64_FL_FOR_ARCH8_R): New.
(AARCH64_ISA_V8_R): New.
* doc/invoke.texi: Add Armv8-R to architecture table.

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/acle/armv8-r.c: New test.

4 years agolibstdc++: Fix some -Wunused-parameter warnings
Jonathan Wakely [Thu, 10 Sep 2020 16:09:16 +0000 (17:09 +0100)]
libstdc++: Fix some -Wunused-parameter warnings

libstdc++-v3/ChangeLog:

* include/bits/codecvt.h (codecvt_byname): Remove names of
unused parameters.

4 years agolibstdc++: Clean up inconsistent whitespace
Jonathan Wakely [Thu, 10 Sep 2020 16:09:16 +0000 (17:09 +0100)]
libstdc++: Clean up inconsistent whitespace

libstdc++-v3/ChangeLog:

* include/bits/locale_facets_nonio.tcc: Adjust whitespace.

4 years agolibstdc++: Add parentheses around assignments used as truth values
Krystian Kuźniarek [Thu, 10 Sep 2020 16:09:16 +0000 (17:09 +0100)]
libstdc++: Add parentheses around assignments used as truth values

libstdc++-v3/ChangeLog:

* include/c_global/cmath (__lerp): Avoid -Wparentheses warnings.

4 years agolibstdc++: Add unused attributes to suppress warnings
Krystian Kuźniarek [Thu, 10 Sep 2020 16:09:15 +0000 (17:09 +0100)]
libstdc++: Add unused attributes to suppress warnings

libstdc++-v3/ChangeLog:

* include/bits/atomic_base.h: Fix -Wunused-variable
warnings.
* include/ext/new_allocator.h: Fix -Wunused-parameter
warnings.

4 years agolibstdc++: Enforce LWG 3472 preconditions on std::counted_iterator
Jonathan Wakely [Thu, 10 Sep 2020 16:09:15 +0000 (17:09 +0100)]
libstdc++: Enforce LWG 3472 preconditions on std::counted_iterator

libstdc++-v3/ChangeLog:

* include/bits/stl_iterator.h (counted_iterator): Add assertions
to check preconditions added by LWG 3472.

4 years agolibphobos: libdruntime doesn't support shadow stack (PR95680)
Iain Buclaw [Wed, 9 Sep 2020 23:30:20 +0000 (01:30 +0200)]
libphobos: libdruntime doesn't support shadow stack (PR95680)

The first implementation hit a front-end implementation bug where
version conditions are resolved ahead of static if confitions.

The logic for whether to use asm implemented fiber_switchContext or
libc's swapcontext has been moved from GNU_Enable_CET to version CET.

libphobos/ChangeLog:

PR d/95680
PR d/97007
* Makefile.am (AM_MAKEFLAGS): Remove $(CET_FLAGS).
* Makefile.in: Regenerate.
* configure: Regenerate.
* configure.ac (DCFG_ENABLE_CET): Remove substitution.
(CET_DFLAGS): Substitute.
* libdruntime/Makefile.am (AM_DFLAGS): Add $(CET_DFLAGS).
(AM_CFLAGS): Add $(CET_FLAGS).
(AM_CCASFLAGS): Likewise.
* libdruntime/Makefile.in: Regenerate.
* libdruntime/core/thread.d: Replace static if GNU_Enable_CET
condition with `version (CET)'.
* libdruntime/gcc/config.d.in (GNU_Enable_CET): Remove.
* src/Makefile.am (AM_DFLAGS): Add $(CET_DFLAGS).
(AM_CFLAGS): Add $(CET_FLAGS).
* src/Makefile.in: Regenerate.
* testsuite/Makefile.in: Regenerate.
* testsuite/testsuite_flags.in: Add $(CET_DFLAGS) to --gdcflags.

4 years agod: Enable miscellaneous warnings by -Wextra flag
Iain Buclaw [Tue, 8 Sep 2020 16:22:04 +0000 (18:22 +0200)]
d: Enable miscellaneous warnings by -Wextra flag

These warnings are handled outside of the D core language front-end, so
shouldn't be enabled by -Wall.

gcc/d/ChangeLog:

* lang.opt (Waddress): Enable warning by -Wextra.
(Wcast-result): Likewise.
(Wunknown-pragmas): Likewise.

4 years agod: Don't warn about variables initialized with 'void'
Iain Buclaw [Tue, 8 Sep 2020 16:16:45 +0000 (18:16 +0200)]
d: Don't warn about variables initialized with 'void'

There is no problem with using `T var = void', it is if the variable
remains uninitialized on first use that a warning should be issued.

gcc/d/ChangeLog:

* decl.cc (DeclVisitor::visit (VarDeclaration *)): Don't warn about
variables initialized with 'void'.

4 years agod: Warn when casting from a D class to a C++ class.
Iain Buclaw [Tue, 8 Sep 2020 15:15:33 +0000 (17:15 +0200)]
d: Warn when casting from a D class to a C++ class.

Before, the warning was only issued when casting in the other direction.
Now a warning is printed for both directions.

gcc/d/ChangeLog:

* d-convert.cc (convert_expr): Warn when casting from a D class to a
C++ class.

gcc/testsuite/ChangeLog:

* gdc.dg/Waddress.d: New test.
* gdc.dg/Wcastresult1.d: New test.
* gdc.dg/Wcastresult2.d: New test.

4 years agoFix bogus error on Value_Size clause for variant record type
Eric Botcazou [Thu, 10 Sep 2020 15:59:11 +0000 (17:59 +0200)]
Fix bogus error on Value_Size clause for variant record type

This is a regression present on the mainline and 10 branch: the compiler
rejects a Value_Size clause on a discriminated record type with variant.

gcc/ada/ChangeLog:
* gcc-interface/decl.c (set_rm_size): Do not take into account the
Value_Size clause if it is not for the entity itself.

gcc/testsuite/ChangeLog:
* gnat.dg/specs/size_clause5.ads: New test.

4 years agoFix uninitialized variable with nested variant record types
Eric Botcazou [Thu, 10 Sep 2020 15:47:32 +0000 (17:47 +0200)]
Fix uninitialized variable with nested variant record types

This fixes a wrong code issue with nested variant record types: the
compiler generates move instructions that depend on an uninitialized
variable, which was initially a SAVE_EXPR not instantiated early enough.

gcc/ada/ChangeLog:
* gcc-interface/decl.c (build_subst_list): For a definition, make
sure to instantiate the SAVE_EXPRs generated by the elaboration of
the constraints in front of the elaboration of the type itself.

gcc/testsuite/ChangeLog:
* gnat.dg/discr59.adb: New test.
* gnat.dg/discr59_pkg1.ads: New helper.
* gnat.dg/discr59_pkg2.ads: Likewise.

4 years agoAdd emergency dump after an ICE
Eric Botcazou [Thu, 10 Sep 2020 11:26:31 +0000 (13:26 +0200)]
Add emergency dump after an ICE

This is only for internal debugging purposes.

gcc/ada/ChangeLog:
* gcc-interface/misc.c: Include tree-pass.h.
(internal_error_function): Call emergency_dump_function.

4 years agoarm: Fix up arm_override_options_after_change_1
Jakub Jelinek [Thu, 10 Sep 2020 15:40:08 +0000 (17:40 +0200)]
arm: Fix up arm_override_options_after_change_1

Looking further at arm_override_options_after_change_1, it also seems to be
incorrect, rather than testing
!opts->x_str_align_functions
it should be really testing
!opts_set->x_str_align_functions
and get &global_options_set or similar passed to it as additional opts_set
argument.  That is because otherwise the decision will be sticky, while it
should be done whenever use provided -falign-functions but didn't provide
-falign-functions= (either on the command line, or through optimize
attribute or pragma).

Here is a fix for that (incremental change on top of the previous patch).

2020-09-10  Jakub Jelinek  <jakub@redhat.com>

* config/arm/arm.c (arm_override_options_after_change_1): Add opts_set
argument, test opts_set->x_str_align_functions rather than
opts->x_str_align_functions.
(arm_override_options_after_change, arm_option_override_internal,
arm_set_current_function): Adjust callers.

4 years agoarm: Fix up arm_override_options_after_change [PR96939]
Jakub Jelinek [Thu, 10 Sep 2020 15:39:00 +0000 (17:39 +0200)]
arm: Fix up arm_override_options_after_change [PR96939]

As mentioned in the PR, the testcase fails to link, because when set_cfun is
being called on the crc function, arm_override_options_after_change is
called from set_cfun -> invoke_set_current_function_hook:
      /* Change optimization options if needed.  */
      if (optimization_current_node != opts)
        {
          optimization_current_node = opts;
          cl_optimization_restore (&global_options, TREE_OPTIMIZATION (opts));
        }
and at that point target_option_default_node actually matches even the
current state of options, so this means armv7 (or whatever) arch is set as
arm_active_target, then
      targetm.set_current_function (fndecl);
is called later in that function, which because the crc function's
DECL_FUNCTION_SPECIFIC_TARGET is different from the current one will do:
  cl_target_option_restore (&global_options, TREE_TARGET_OPTION (new_tree));
which calls arm_option_restore and sets arm_active_target to armv8-a+crc
(so far so good).
Later arm_set_current_function calls:
  save_restore_target_globals (new_tree);
which in this case calls:
      /* Call target_reinit and save the state for TARGET_GLOBALS.  */
      TREE_TARGET_GLOBALS (new_tree) = save_target_globals_default_opts ();
which because optimization_current_node != optimization_default_node
(the testcase is LTO, so all functions have their
DECL_FUNCTION_SPECIFIC_TARGET and TREE_OPTIMIZATION nodes) will call:
      cl_optimization_restore
        (&global_options,
         TREE_OPTIMIZATION (optimization_default_node));
and
      cl_optimization_restore (&global_options,
                               TREE_OPTIMIZATION (opts));
The problem is that these call arm_override_options_after_change again,
and that one uses the target_option_default_node as what to set the
arm_active_target to (i.e. back to armv7 or whatever, but not to the
armv8-a+crc that should be the active target for the crc function).
That means we then error on the builtin call in that function.

Now, the targetm.override_options_after_change hook is called always at the
end of cl_optimization_restore, i.e. when we change the Optimization marked
generic options.  So it seems unnecessary to call arm_configure_build_target
at that point (nothing it depends on changed), and additionally incorrect
(because it uses the target_option_default_node, rather than the current
set of options; we'd need to revert
https://gcc.gnu.org/legacy-ml/gcc-patches/2016-12/msg01390.html
otherwise so that it works again with global_options otherwise).
The options that arm_configure_build_target cares about will change only
during option parsing (which is where it is called already), or during
arm_set_current_function, where it is done during the
cl_target_option_restore.
Now, arm_override_options_after_change_1 wants to adjust the
str_align_functions, which depends on the current Optimization options (e.g.
optimize_size and flag_align_options and str_align_functions) as well as
the target options target_flags, so IMHO needs to be called both
when the Optimization options (possibly) change, i.e. from
the targetm.override_options_after_change hook, and from when the target
options change (set_current_function hook).

2020-09-10  Jakub Jelinek  <jakub@redhat.com>

PR target/96939
* config/arm/arm.c (arm_override_options_after_change): Don't call
arm_configure_build_target here.
(arm_set_current_function): Call arm_override_options_after_change_1
at the end.

* gcc.target/arm/lto/pr96939_0.c: New test.
* gcc.target/arm/lto/pr96939_1.c: New file.

4 years agoFix instruction types.
Pat Haugen [Thu, 10 Sep 2020 14:46:46 +0000 (09:46 -0500)]
Fix instruction types.

I noticed that some of the VSR<->GPR move instructions are not typed correctly. This patch fixes those instructions so that the scheduler treats them with the correct latency.

2020-09-10  Pat Haugen  <pthaugen@linux.ibm.com>

gcc/
* config/rs6000/rs6000.md
(lfiwzx, floatunssi<mode>2_lfiwzx, p8_mtvsrwz, p8_mtvsrd_sf): Fix insn
type.
* config/rs6000/vsx.md
(vsx_concat_<mode>, vsx_splat_<mode>_reg, vsx_splat_v4sf): Likewise.

4 years agolibstdc++: handle small max_blocks_per_chunk in pool resources [PR 94160]
Jonathan Wakely [Thu, 10 Sep 2020 14:39:15 +0000 (15:39 +0100)]
libstdc++: handle small max_blocks_per_chunk in pool resources [PR 94160]

When a pool resource is constructed with max_blocks_per_chunk=1 it ends
up creating a pool with blocks_per_chunk=0 which means it never
allocates anything. Instead it returns null pointers, which should be
impossible.

To avoid this problem, round the max_blocks_per_chunk value to a
multiple of four, so it's never smaller than four.

libstdc++-v3/ChangeLog:

PR libstdc++/94160
* src/c++17/memory_resource.cc (munge_options): Round
max_blocks_per_chunk to a multiple of four.
(__pool_resource::_M_alloc_pools()): Simplify slightly.
* testsuite/20_util/unsynchronized_pool_resource/allocate.cc:
Check that valid pointers are returned when small values are
used for max_blocks_per_chunk.

4 years agolibstdc++: Reduce monotonic_buffer_resource overallocation [PR 96942]
Jonathan Wakely [Thu, 10 Sep 2020 14:39:15 +0000 (15:39 +0100)]
libstdc++: Reduce monotonic_buffer_resource overallocation [PR 96942]

The primary reason for this change is to reduce the size of buffers
allocated by std::pmr::monotonic_buffer_resource. Previously, a new
buffer would always add the size of the linked list node (11 bytes) and
then round up to the next power of two. This results in a huge increase
if the expected size of the next buffer is already a power of two. For
example, if the resource is constructed with a desired initial size of
4096 the first buffer it allocates will be std::bit_ceil(4096+11) which
is 8192.  If the user has carefully selected the initial size to match
their expected memory requirements then allocating double that amount
wastes a lot of memory.

After this patch the allocated size will be rounded up to a 64-byte
boundary, instead of to a power of two. This means for an initial size
of 4096 only 4160 bytes get allocated.

Previously only the base-2 logarithm of the size was stored, which could
be stored in a single 8-bit integer. Now that the size isn't always a
power of two we need to use more bits to store it. As the size is always
a multiple of 64 the low six bits are not needed, and so we can use the
same approach that the pool resources already use of storing the base-2
logarithm of the alignment in the low bits that are not used for the
size. To avoid code duplication, a new aligned_size<N> helper class is
introduced by this patch, which is then used by both the pool resources'
big_block type and the monotonic_buffer_resource::_Chunk type.

Originally the big_block type used two bit-fields to store the size and
alignment in the space of a single size_t member. The aligned_size type
uses a single size_t member and uses masks and bitwise operations to
manipulate the size and alignment values. This results in better code
than the old version, because the bit-fields weren't optimally ordered
for little endian architectures, so the alignment was actually stored in
the high bits, not the unused low bits, requiring additional shifts to
calculate the values. Using bitwise operations directly avoids needing
to reorder the bit-fields depending on the endianness.

While adapting the _Chunk and big_block types to use aligned_size<N> I
also added checks for size overflows (technically, unsigned wraparound).
The memory resources now ensure that when they require an allocation
that is too large to represent in size_t they will request SIZE_MAX
bytes from the upstream resource, rather than requesting a small value
that results from wrapround. The testsuite is enhanced to verify this.

libstdc++-v3/ChangeLog:

PR libstdc++/96942
* include/std/memory_resource (monotonic_buffer_resource::do_allocate):
Use __builtin_expect when checking if a new buffer needs to be
allocated from the upstream resource, and for checks for edge
cases like zero sized buffers and allocations.
* src/c++17/memory_resource.cc (aligned_size): New class template.
(aligned_ceil): New helper function to round up to a given
alignment.
(monotonic_buffer_resource::chunk): Replace _M_size and _M_align
with an aligned_size member. Remove _M_canary member. Change _M_next
to pointer instead of unaligned buffer.
(monotonic_buffer_resource::chunk::allocate): Round up to multiple
of 64 instead of to power of two. Check for size overflow. Remove
redundant check for minimum required alignment.
(monotonic_buffer_resource::chunk::release): Adjust for changes
to data members.
(monotonic_buffer_resource::_M_new_buffer): Use aligned_ceil.
(big_block): Replace _M_size and _M_align with aligned_size
member.
(big_block::big_block): Check for size overflow.
(big_block::size, big_block::align): Adjust to use aligned_size.
(big_block::alloc_size): Use aligned_ceil.
(munge_options): Use aligned_ceil.
(__pool_resource::allocate): Use big_block::align for alignment.
* testsuite/20_util/monotonic_buffer_resource/allocate.cc: Check
upstream resource gets expected values for impossible sizes.
* testsuite/20_util/unsynchronized_pool_resource/allocate.cc:
Likewise. Adjust checks for expected alignment in existing test.

4 years agoc++: DECL_LOCAL_FUNCTION_P -> DECL_LOCAL_DECL_P
Nathan Sidwell [Thu, 10 Sep 2020 12:38:29 +0000 (05:38 -0700)]
c++: DECL_LOCAL_FUNCTION_P -> DECL_LOCAL_DECL_P

Our handling of block-scope extern decls is insufficient for modern
C++, in particular modules, (but also constexprs).  We mark such local
function decls, and this patch extends that to marking local var decls
too, so mainly a macro rename.  Also, we set this flag earlier, rather
than learning about it when pushing the decl.  This is a step towards
handling these properly.

gcc/cp/
* cp-tree.h (DECL_LOCAL_FUNCTION_P): Rename to ...
(DECL_LOCAL_DECL_P): ... here.  Accept both fns and vars.
* decl.c (start_decl): Set DECL_LOCAL_DECL_P for local externs.
(omp_declare_variant_finalize_one): Use DECL_LOCAL_DECL_P.
(local_variable_p): Simplify.
* name-lookup.c (set_decl_context_in_fn): Assert DECL_LOCAL_DECL_P
is as expected.  Simplify.
(do_pushdecl): Don't set decl_context_in_fn for friends.
(is_local_extern): Simplify.
* call.c (equal_functions): Use DECL_LOCAL_DECL_P.
* parser.c (cp_parser_postfix_expression): Likewise.
(cp_parser_omp_declare_reduction): Likewise.
* pt.c (check_default_tmpl_args): Likewise.
(tsubst_expr): Assert nested reduction function is local.
(type_dependent_expression_p): Use DECL_LOCAL_DECL_P.
* semantics.c (finish_call_expr): Likewise.
libcc1/
* libcp1plugin.cc (plugin_build_call_expr): Use DECL_LOCAL_DECL_P.

4 years ago[testsuite] Add missing require-effective-target allloca
Tom de Vries [Thu, 10 Sep 2020 11:18:50 +0000 (13:18 +0200)]
[testsuite] Add missing require-effective-target allloca

Add a missing require-effect-target alloca directive.

Tested on nvptx.

gcc/testsuite/ChangeLog:

* gcc.dg/analyzer/vla-1.c: Add require-effective-target alloca.

4 years agoCygwin/MinGW: Do not version lto plugins
Jonathan Yong [Thu, 10 Sep 2020 11:48:41 +0000 (11:48 +0000)]
Cygwin/MinGW: Do not version lto plugins

GCC on Linux already uses liblto_plugin.so directly without
the libtool version suffix, adjust windows GCC to do the same.

gcc/ChangeLog:

* config.host: Adjust plugin name for Windows.

lto-plugin/ChangeLog:

* Makefile.am: drop versioning from libtool completely.
* Makefile.in: regenerate.

4 years ago[tree-optimization] Don't clear ctrl-altering flag for IFN_UNIQUE
Tom de Vries [Thu, 10 Sep 2020 10:44:20 +0000 (12:44 +0200)]
[tree-optimization] Don't clear ctrl-altering flag for IFN_UNIQUE

There's an invariant for IFN_UNIQUE, listed here in
gimple_call_initialize_ctrl_altering:
...
      /* IFN_UNIQUE should be the last insn, to make checking for it
         as cheap as possible.  */
      || (gimple_call_internal_p (stmt)
          && gimple_call_internal_unique_p (stmt)))
    gimple_call_set_ctrl_altering (stmt, true);
...

Recent commit fab77644842 "tree-optimization/96931 - clear ctrl-altering flag
more aggressively" breaks this invariant, causing an ICE triggered during
libgomp testing for x86_64 with nvptx accelerator:
...
during RTL pass: mach
asyncwait-1.f90: In function ‘MAIN__._omp_fn.0’:
asyncwait-1.f90:19: internal compiler error: in nvptx_find_par, at \
  config/nvptx/nvptx.c:3293
...

Fix this by listing IFN_UNIQUE as exception in
cleanup_call_ctrl_altering_flag.

Build for x86_64 with nvptx accelerator, tested libgomp.

gcc/ChangeLog:

PR tree-optimization/97000
* tree-cfgcleanup.c (cleanup_call_ctrl_altering_flag): Don't clear
flag for IFN_UNIQUE.

4 years agolto: Stream current working directory for first streamed relative filename and adjust...
Jakub Jelinek [Thu, 10 Sep 2020 09:25:02 +0000 (11:25 +0200)]
lto: Stream current working directory for first streamed relative filename and adjust relative paths [PR93865]

If the gcc -c -flto ... commands to compile some or all objects are run in a
different directory (or in different directories) from the directory in
which the gcc -flto link line is invoked, then the .debug_line will be
incorrect if there are any relative filenames, it will use those relative
filenames while .debug_info will contain a different DW_AT_comp_dir.

The following patch streams (at most once after each clear_line_info)
the current working directory (what we record in DW_AT_comp_dir) when
encountering the first relative pathname, and when reading the location info
reads it back and if the current working directory at that point is
different from the saved one, adjusts relative paths by adding a relative
prefix how to go from the current working directory to the previously saved
path (with a fallback e.g. for DOS e:\\foo vs. d:\\bar change to use
absolute directory).

2020-09-10  Jakub Jelinek  <jakub@redhat.com>

PR debug/93865
* lto-streamer.h (struct output_block): Add emit_pwd member.
* lto-streamer-out.c: Include toplev.h.
(clear_line_info): Set emit_pwd.
(lto_output_location_1): Encode the ob->current_file != xloc.file
bit directly into the location number.  If changing file, emit
additionally a bit whether pwd is emitted and emit it before the
first relative pathname since clear_line_info.
(output_function, output_constructor): Don't call clear_line_info
here.
* lto-streamer-in.c (struct string_pair_map): New type.
(struct string_pair_map_hasher): New type.
(string_pair_map_hasher::hash): New method.
(string_pair_map_hasher::equal): New method.
(path_name_pair_hash_table, string_pair_map_allocator): New variables.
(relative_path_prefix, canon_relative_path_prefix,
canon_relative_file_name): New functions.
(canon_file_name): Add relative_prefix argument, if non-NULL
and string is a relative path, return canon_relative_file_name.
(lto_location_cache::input_location_and_block): Decode file change
bit from the location number.  If changing file, unpack bit whether
pwd is streamed and stream in pwd.  Adjust canon_file_name caller.
(lto_free_file_name_hash): Delete path_name_pair_hash_table
and string_pair_map_allocator.

4 years agotree-optimization/96043 - BB vectorization costing improvement
Richard Biener [Tue, 8 Sep 2020 12:49:59 +0000 (14:49 +0200)]
tree-optimization/96043 - BB vectorization costing improvement

This makes the BB vectorizer cost independent SLP subgraphs
separately.  While on pristine trunk and for x86_64 I failed to
distill a testcase where the vectorizer would think _any_
basic-block vectorization opportunity is not profitable I do
have pending work that would make the cost savings of a
profitable opportunity make another independently not
profitable opportunity vectorized.

2020-09-08  Richard Biener  <rguenther@suse.de>

PR tree-optimization/96043
* tree-vectorizer.h (_slp_instance::cost_vec): New.
(_slp_instance::subgraph_entries): Likewise.
(BB_VINFO_TARGET_COST_DATA): Remove.
* tree-vect-slp.c (vect_free_slp_instance): Free
cost_vec and subgraph_entries.
(vect_analyze_slp_instance): Initialize them.
(vect_slp_analyze_operations): Defer passing costs to
the target, instead record them in the SLP graph entry.
(get_ultimate_leader): New helper for graph partitioning.
(vect_bb_partition_graph_r): Likewise.
(vect_bb_partition_graph): New function to partition the
SLP graph into independently costable parts.
(vect_bb_vectorization_profitable_p): Adjust to work on
a subgraph.
(vect_bb_vectorization_profitable_p): New wrapper,
discarding non-profitable vectorization of subgraphs.
(vect_slp_analyze_bb_1): Call vect_bb_partition_graph before
costing.

* gcc.dg/vect/costmodel/x86_64/costmodel-pr69297.c: Adjust.

4 years agoFixup config/ChangeLog.
Rainer Orth [Thu, 10 Sep 2020 08:17:51 +0000 (10:17 +0200)]
Fixup config/ChangeLog.

4 years agoDaily bump.
GCC Administrator [Thu, 10 Sep 2020 00:16:28 +0000 (00:16 +0000)]
Daily bump.

4 years agoc++: Further tweaks for new-expression and paren-init [PR77841]
Marek Polacek [Sun, 6 Sep 2020 00:50:32 +0000 (20:50 -0400)]
c++: Further tweaks for new-expression and paren-init [PR77841]

This patch corrects our handling of array new-expression with ()-init:

  new int[4](1, 2, 3, 4);

should work even with the explicit array bound, and

  new char[3]("so_sad");

should cause an error, but we weren't giving any.

Fixed by handling array new-expressions with ()-init in the same spot
where we deduce the array bound in array new-expression.  I'm now
always passing STRING_CSTs to build_new_1 wrapped in { } which allowed
me to remove the special handling of STRING_CSTs in build_new_1.  And
since the DIRECT_LIST_INIT_P block in build_new_1 calls digest_init, we
report errors about too short arrays. reshape_init now does the {"foo"}
-> "foo" transformation even for CONSTRUCTOR_IS_PAREN_INIT, so no need
to do it in build_new.

I took a stab at cp_complete_array_type's "FIXME: this code is duplicated
from reshape_init", but calling reshape_init there, I ran into issues
with has_designator_problem: when we reshape an already reshaped
CONSTRUCTOR again, d.cur.index has been filled, so we think that we
have a user-provided designator (though there was no designator in the
source code), and report an error.

gcc/cp/ChangeLog:

PR c++/77841
* decl.c (reshape_init): If we're initializing a char array from
a string-literal that is enclosed in braces, unwrap it.
* init.c (build_new_1): Don't handle string-initializers here.
(build_new): Handle new-expression with paren-init when the
array bound is known.  Always pass string constants to build_new_1
enclosed in braces.  Don't handle string-initializers in any
special way.

gcc/testsuite/ChangeLog:

PR c++/77841
* g++.old-deja/g++.ext/arrnew2.C: Expect the error only in C++17
and less.
* g++.old-deja/g++.robertl/eb58.C: Adjust dg-error.
* g++.old-deja/g++.robertl/eb63.C: Expect the error only in C++17
and less.
* g++.dg/cpp2a/new-array5.C: New test.
* g++.dg/cpp2a/paren-init36.C: New test.
* g++.dg/cpp2a/paren-init37.C: New test.
* g++.dg/pr84729.C: Adjust dg-error.

4 years agoc++: Fix ICE in reshape_init with init-list [PR95164]
Marek Polacek [Fri, 4 Sep 2020 20:04:26 +0000 (16:04 -0400)]
c++: Fix ICE in reshape_init with init-list [PR95164]

This patch fixes a long-standing bug in reshape_init_r.  Since r209314
we implement DR 1467 which handles list-initialization with a single
initializer of the same type as the target.  In this test this causes
a crash in reshape_init_r when we're processing a constructor that has
undergone the DR 1467 transformation.

Take e.g. the

  foo({{1, {H{k}}}});

line in the attached test.  {H{k}} initializes the field b of H in I.
H{k} is a functional cast, so has TREE_HAS_CONSTRUCTOR set, so is
COMPOUND_LITERAL_P.  We perform the DR 1467 transformation and turn
{H{k}} into H{k}.  Then we attempt to reshape H{k} again and since
first_initializer_p is null and it's COMPOUND_LITERAL_P, we go here:

           else if (COMPOUND_LITERAL_P (stripped_init))
             gcc_assert (!BRACE_ENCLOSED_INITIALIZER_P (stripped_init));

then complain about the missing braces, go to reshape_init_class and ICE
on
               gcc_checking_assert (d->cur->index
                                    == get_class_binding (type, id));

because due to the missing { } we're looking for 'b' in H, but that's
not found.

So we have to be prepared to handle an initializer whose outer braces
have been removed due to DR 1467.

gcc/cp/ChangeLog:

PR c++/95164
* decl.c (reshape_init_r): When initializing an aggregate member
with an initializer from an initializer-list, also consider
COMPOUND_LITERAL_P.

gcc/testsuite/ChangeLog:

PR c++/95164
* g++.dg/cpp0x/initlist123.C: New test.

4 years agoanalyzer: generalize sm-malloc to new/delete [PR94355]
David Malcolm [Fri, 28 Aug 2020 17:43:56 +0000 (13:43 -0400)]
analyzer: generalize sm-malloc to new/delete [PR94355]

This patch generalizes the state machine in sm-malloc.c to support
multiple allocator APIs, and adds just enough support for C++ new and
delete to demonstrate the feature, allowing for detection of code
paths where the result of new in C++ can leak - for some crude examples,
at least (bearing in mind that the analyzer doesn't yet know about
e.g. vfuncs, exceptions, inheritance, RTTI, etc)

It also implements a new warning: -Wanalyzer-mismatching-deallocation.
For example:

demo.cc: In function 'void test()':
demo.cc:8:8: warning: 'f' should have been deallocated with 'delete'
  but was deallocated with 'free' [CWE-762] [-Wanalyzer-mismatching-deallocation]
    8 |   free (f);
      |   ~~~~~^~~
  'void test()': events 1-2
    |
    |    7 |   foo *f = new foo;
    |      |                ^~~
    |      |                |
    |      |                (1) allocated here (expects deallocation with 'delete')
    |    8 |   free (f);
    |      |   ~~~~~~~~
    |      |        |
    |      |        (2) deallocated with 'free' here; allocation at (1) expects deallocation with 'delete'
    |

The patch also adds just enough knowledge of exception-handling to
suppress a false positive from -Wanalyzer-malloc-leak on
g++.dg/analyzer/pr96723.C on the exception-handling CFG edge after
operator new.  It does this by adding a constraint that the result is
NULL if an exception was thrown from operator new, since the result from
operator new is lost when following that exception-handling CFG edge.

gcc/analyzer/ChangeLog:
PR analyzer/94355
* analyzer.opt (Wanalyzer-mismatching-deallocation): New warning.
* region-model-impl-calls.cc
(region_model::impl_call_operator_new): New.
(region_model::impl_call_operator_delete): New.
* region-model.cc (region_model::on_call_pre): Detect operator new
and operator delete.
(region_model::on_call_post): Likewise.
(region_model::maybe_update_for_edge): Detect EH edges and call...
(region_model::apply_constraints_for_exception): New function.
* region-model.h (region_model::impl_call_operator_new): New decl.
(region_model::impl_call_operator_delete): New decl.
(region_model::apply_constraints_for_exception): New decl.
* sm-malloc.cc (enum resource_state): New.
(struct allocation_state): New state subclass.
(enum wording): New.
(struct api): New.
(malloc_state_machine::custom_data_t): New typedef.
(malloc_state_machine::add_state): New decl.
(malloc_state_machine::m_unchecked)
(malloc_state_machine::m_nonnull)
(malloc_state_machine::m_freed): Delete these states in favor
of...
(malloc_state_machine::m_malloc)
(malloc_state_machine::m_scalar_new)
(malloc_state_machine::m_vector_new): ...this new api instances,
which own their own versions of these states.
(malloc_state_machine::on_allocator_call): New decl.
(malloc_state_machine::on_deallocator_call): New decl.
(api::api): New ctor.
(dyn_cast_allocation_state): New.
(as_a_allocation_state): New.
(get_rs): New.
(unchecked_p): New.
(nonnull_p): New.
(freed_p): New.
(malloc_diagnostic::describe_state_change): Use unchecked_p and
nonnull_p.
(class mismatching_deallocation): New.
(double_free::double_free): Add funcname param for initializing
m_funcname.
(double_free::emit): Use m_funcname in warning message rather
than hardcoding "free".
(double_free::describe_state_change): Likewise.  Use freed_p.
(double_free::describe_call_with_state): Use freed_p.
(double_free::describe_final_event): Use m_funcname in message
rather than hardcoding "free".
(double_free::m_funcname): New field.
(possible_null::describe_state_change): Use unchecked_p.
(possible_null::describe_return_of_state): Likewise.
(use_after_free::use_after_free): Add param for initializing m_api.
(use_after_free::emit): Use m_api->m_dealloc_funcname in message
rather than hardcoding "free".
(use_after_free::describe_state_change): Use freed_p.  Change the
wording of the message based on the API.
(use_after_free::describe_final_event): Use
m_api->m_dealloc_funcname in message rather than hardcoding
"free".  Change the wording of the message based on the API.
(use_after_free::m_api): New field.
(malloc_leak::describe_state_change): Use unchecked_p.  Update
for renaming of m_malloc_event to m_alloc_event.
(malloc_leak::describe_final_event): Update for renaming of
m_malloc_event to m_alloc_event.
(malloc_leak::m_malloc_event): Rename...
(malloc_leak::m_alloc_event): ...to this.
(free_of_non_heap::free_of_non_heap): Add param for initializing
m_funcname.
(free_of_non_heap::emit): Use m_funcname in message rather than
hardcoding "free".
(free_of_non_heap::describe_final_event): Likewise.
(free_of_non_heap::m_funcname): New field.
(allocation_state::dump_to_pp): New.
(allocation_state::get_nonnull): New.
(malloc_state_machine::malloc_state_machine): Update for changes
to state fields and new api fields.
(malloc_state_machine::add_state): New.
(malloc_state_machine::on_stmt): Move malloc/calloc handling to
on_allocator_call and call it, passing in the API pointer.
Likewise for free, moving it to on_deallocator_call.  Handle calls
to operator new and delete in an analogous way.  Use unchecked_p
when testing for possibly-null-arg and possibly-null-deref, and
transition to the non-null for the correct API.  Remove redundant
node param from call to on_zero_assignment.  Use freed_p for
use-after-free check, and pass in API.
(malloc_state_machine::on_allocator_call): New, based on code in
on_stmt.
(malloc_state_machine::on_deallocator_call): Likewise.
(malloc_state_machine::on_phi): Mark node param with
ATTRIBUTE_UNUSED; don't pass it to on_zero_assignment.
(malloc_state_machine::on_condition): Mark node param with
ATTRIBUTE_UNUSED.  Replace on_transition calls with get_state and
set_next_state pairs, transitioning to the non-null state for the
appropriate API.
(malloc_state_machine::can_purge_p): Port to new state approach.
(malloc_state_machine::on_zero_assignment): Replace on_transition
calls with get_state and set_next_state pairs.  Drop redundant
node param.
* sm.h (state_machine::add_custom_state): New.

gcc/ChangeLog:
PR analyzer/94355
* doc/invoke.texi: Document -Wanalyzer-mismatching-deallocation.

gcc/testsuite/ChangeLog:
PR analyzer/94355
* g++.dg/analyzer/new-1.C: New test.
* g++.dg/analyzer/new-vs-malloc.C: New test.

4 years agoUpdate include/ChangeLog
Caroline Tice [Wed, 9 Sep 2020 21:11:33 +0000 (14:11 -0700)]
Update include/ChangeLog

ChangeLog entry did not get properly updated with previous commit.
Fix that.

2020-09-09  Caroline Tice  <cmtice@google.com>

include/

* dwarf2.h (enum dwarf_sect_v5): A new enum section for the
sections in a DWARF 5 DWP file (DWP version 5).

4 years agoAdd codes for DWARF v5 .dwp sections to dwarf2.h.
Caroline Tice [Tue, 8 Sep 2020 16:14:29 +0000 (09:14 -0700)]
Add codes for DWARF v5 .dwp sections to dwarf2.h.

(Note: This patch has already been accepted/committed in binutils/GDB.
This will bring the same change into the GCC tree.)

For DWARF v5 Dwarf Package Files (.dwp files), the section identifier encodings
have changed. This patch updates dwarf2.h to contain the new
encodings.  The table below shows the old & new encodings:
[ref http://dwarfstd.org/doc/DWARF5.pdf, section 7.3.5. ]

Val  DW4 section       DW4 section id  DW5 section         DW5 section id
--- -----------------  --------------  -----------------   --------------
 1  .debug_info.dwo    DW_SECT_INFO    .debug_info.dwo     DW_SECT_INFO
 2  .debug_types.dwo   DW_SECT_TYPES         --              reserved
 3  .debug_abbrev.dwo  DW_SECT_ABBREV  .debug_abbrev.dwo   DW_SECT_ABBREV
 4  .debug_line.dwo    DW_SECT_LINE    .debug_line.dwo     DW_SECT_LINE
 5  .debug_loc.dwo     DW_SECT_LOC     .debug_loclists.dwo DW_SECT_LOCLISTS
 6  .debug_str_offsets.dwo             .debug_str_offsets.dwo
                       DW_SECT_STR_OFFSETS                 DW_SECT_STR_OFFSETS
 7  .debug_macinfo.dwo DW_SECT_MACINFO .debug_macro.dwo    DW_SECT_MACRO
 8  .debug_macro.dwo   DW_SECT_MACRO   .debug_rnglists.dwo DW_SECT_RNGLISTS

2020-09-09  Caroline Tice  <cmtice@google.com>

include/

* dwarf2.h (enum dwarf_sect_v5): A new enum section for the
sections in a DWARF 5 DWP file (DWP version 5).

4 years agoanalyzer: eliminate sm_context::warn_for_state in favor of a new 'warn' vfunc
David Malcolm [Fri, 28 Aug 2020 14:10:38 +0000 (10:10 -0400)]
analyzer: eliminate sm_context::warn_for_state in favor of a new 'warn' vfunc

This patch is yet more preliminary work towards generalizing sm-malloc.cc
beyond just malloc/free.

It eliminates sm_context::warn_for_state in terms of a new sm_context::warn
vfunc, guarded by sm_context::get_state calls.

gcc/analyzer/ChangeLog:
* diagnostic-manager.cc
(null_assignment_sm_context::warn_for_state): Replace with...
(null_assignment_sm_context::warn): ...this.
* engine.cc (impl_sm_context::warn_for_state): Replace with...
(impl_sm_context::warn): ...this.
* sm-file.cc (fileptr_state_machine::on_stmt): Replace
warn_for_state and on_transition calls with a get_state
test guarding warn and set_next_state calls.
* sm-malloc.cc (malloc_state_machine::on_stmt): Likewise.
* sm-pattern-test.cc (pattern_test_state_machine::on_condition):
Replace warn_for_state call with warn call.
* sm-sensitive.cc
(sensitive_state_machine::warn_for_any_exposure): Replace
warn_for_state call with a get_state test guarding a warn call.
* sm-signal.cc (signal_state_machine::on_stmt): Likewise.
* sm-taint.cc (taint_state_machine::on_stmt):  Replace
warn_for_state and on_transition calls with a get_state
test guarding warn and set_next_state calls.
* sm.h (sm_context::warn_for_state): Replace with...
(sm_context::warn): ...this.

4 years agoanalyzer: reimplement on_transition in terms of get_state/set_next_state
David Malcolm [Fri, 28 Aug 2020 11:07:18 +0000 (07:07 -0400)]
analyzer: reimplement on_transition in terms of get_state/set_next_state

This patch is further preliminary work towards generalizing sm-malloc.cc
beyond just malloc/free.

Reimplement sm_context's on_transition vfunc in terms of new get_state
and set_next_state vfuncs, so that in followup patches we can implement
richer transitions (e.g. where the states are parametrized by
allocator).

gcc/analyzer/ChangeLog:
* diagnostic-manager.cc
(null_assignment_sm_context::null_assignment_sm_context): Add old_state
and ext_state params, initializing m_old_state and m_ext_state.
(null_assignment_sm_context::on_transition): Split into...
(null_assignment_sm_context::get_state): ...this new vfunc
implementation and...
(null_assignment_sm_context::set_next_state): ...this new vfunc
implementation.
(null_assignment_sm_context::m_old_state): New field.
(null_assignment_sm_context::m_ext_state): New field.
(diagnostic_manager::add_events_for_eedge): Pass in old state and
ext_state when creating sm_ctxt.
* engine.cc (impl_sm_context::on_transition): Split into...
(impl_sm_context::get_state): ...this new vfunc
implementation and...
(impl_sm_context::set_next_state): ...this new vfunc
implementation.
* sm.h (sm_context::get_state): New pure virtual function.
(sm_context::set_next_state): Likewise.
(sm_context::on_transition): Convert from a pure virtual function
to a regular function implemented in terms of get_state and
set_next_state.