Commit Graph

179350 Commits

Author SHA1 Message Date
Jonathan Yong
ae6cf62861 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.
2020-09-10 11:54:28 +00:00
Tom de Vries
f96b6328fa [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 fab7764484 "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.
2020-09-10 12:59:29 +02:00
Jakub Jelinek
3d0af0c997 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.
2020-09-10 11:25:02 +02:00
Richard Biener
47ddf4c7b1 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.
2020-09-10 11:18:18 +02:00
Rainer Orth
484af18ee1 Fixup config/ChangeLog. 2020-09-10 10:17:51 +02:00
GCC Administrator
80f86e78ac Daily bump. 2020-09-10 00:16:28 +00:00
Marek Polacek
81de459ec7 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.
2020-09-09 17:46:04 -04:00
Marek Polacek
acbe30bbc8 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.
2020-09-09 17:39:49 -04:00
David Malcolm
1690a839cf 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.
2020-09-09 17:22:06 -04:00
Caroline Tice
fcf56ef5d5 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).
2020-09-09 14:11:33 -07:00
Caroline Tice
de8421dd8a 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).
2020-09-09 14:05:04 -07:00
David Malcolm
25ef215abb 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.
2020-09-09 16:59:32 -04:00
David Malcolm
6d9ca8c860 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.
2020-09-09 16:58:13 -04:00
David Malcolm
10fc42a839 analyzer: use objects for state_machine::state_t
This patch is preliminary work towards generalizing sm-malloc.cc so that
it can check APIs other than just malloc/free (and e.g. detect
mismatching alloc/dealloc pairs).

Generalize states in state machines so that, rather than state_t being
just an "unsigned", it becomes a "const state *", where the underlying
state objects are immutable objects managed by the state machine in
question, and can e.g. have vfuncs and extra fields.  The start state
m_start becomes a member of the state_machine base_class.

gcc/analyzer/ChangeLog:
	* checker-path.cc (state_change_event::get_desc): Update
	state_machine::get_state_name calls to state::get_name.
	(warning_event::get_desc): Likewise.
	* diagnostic-manager.cc
	(null_assignment_sm_context::on_transition): Update comparison
	against 0 with comparison with m_sm.get_start_state.
	(diagnostic_manager::prune_for_sm_diagnostic): Update
	state_machine::get_state_name calls to state::get_name.
	* engine.cc (impl_sm_context::on_transition): Likewise.
	(exploded_node::get_dot_fillcolor): Use get_id when summing
	the sm states.
	* program-state.cc (sm_state_map::sm_state_map): Don't hardcode
	0 as the start state when initializing m_global_state.
	(sm_state_map::print): Use dump_to_pp rather than get_state_name
	when dumping states.
	(sm_state_map::is_empty_p): Don't hardcode 0 as the start state
	when examining m_global_state.
	(sm_state_map::hash): Use get_id when hashing states.
	(selftest::test_sm_state_map): Use state objects rather than
	arbitrary hardcoded integers.
	(selftest::test_program_state_merging): Likewise.
	(selftest::test_program_state_merging_2): Likewise.
	* sm-file.cc (fileptr_state_machine::m_start): Move to base class.
	(file_diagnostic::describe_state_change): Use get_start_state.
	(fileptr_state_machine::fileptr_state_machine): Drop m_start
	initialization.
	* sm-malloc.cc (malloc_state_machine::m_start): Move to base
	class.
	(malloc_diagnostic::describe_state_change): Use get_start_state.
	(possible_null::describe_state_change): Likewise.
	(malloc_state_machine::malloc_state_machine): Drop m_start
	initialization.
	* sm-pattern-test.cc (pattern_test_state_machine::m_start): Move
	to base class.
	(pattern_test_state_machine::pattern_test_state_machine): Drop
	m_start initialization.
	* sm-sensitive.cc (sensitive_state_machine::m_start): Move to base
	class.
	(sensitive_state_machine::sensitive_state_machine): Drop m_start
	initialization.
	* sm-signal.cc (signal_state_machine::m_start): Move to base
	class.
	(signal_state_machine::signal_state_machine): Drop m_start
	initialization.
	* sm-taint.cc (taint_state_machine::m_start): Move to base class.
	(taint_state_machine::taint_state_machine): Drop m_start
	initialization.
	* sm.cc (state_machine::state::dump_to_pp): New.
	(state_machine::state_machine): Move here from sm.h.  Initialize
	m_next_state_id and m_start.
	(state_machine::add_state): Reimplement in terms of state objects.
	(state_machine::get_state_name): Delete.
	(state_machine::get_state_by_name): Reimplement in terms of state
	objects.  Make const.
	(state_machine::validate): Delete.
	(state_machine::dump_to_pp): Reimplement in terms of state
	objects.
	* sm.h (state_machine::state): New class.
	(state_machine::state_t): Convert typedef from "unsigned" to
	"const state_machine::state *".
	(state_machine::state_machine): Move to sm.cc.
	(state_machine::get_default_state): Use m_start rather than
	hardcoding 0.
	(state_machine::get_state_name): Delete.
	(state_machine::get_state_by_name): Make const.
	(state_machine::get_start_state): New accessor.
	(state_machine::alloc_state_id): New.
	(state_machine::m_state_names): Drop in favor of...
	(state_machine::m_states): New field
	(state_machine::m_start): New field
	(start_start_p): Delete.
2020-09-09 16:57:03 -04:00
Nathan Sidwell
749476b4be c++: omp reduction cleanups
omp reductions are modeled as nested functions, which is a thing C++
doesn't have.  Leading to much confusion until I figured out what was
happening.  Not helped by some duplicate code and inconsistencies in
the dependent and non-dependent paths.  This patch removes the parser
duplication and fixes up some bookkeeping.  Added some asserts and
comments too.

	gcc/cp/
	* parser.c (cp_parser_omp_declare_reduction): Refactor to avoid
	code duplication.  Update DECL_TI_TEMPLATE's context.
	* pt.c (tsubst_expr): For OMP reduction function, set context to
	global_namespace before pushing.
	(tsubst_omp_udr): Assert current_function_decl, add comment about
	decl context.
2020-09-09 12:37:21 -07:00
Marek Polacek
782d3ea603 testsuite: Use C++14 in g++.dg/warn/Wnonnull6.C.
This test uses C++14 features so is failing with -std=c++11.

gcc/testsuite/ChangeLog:

	* g++.dg/warn/Wnonnull6.C: Use target c++14.
2020-09-09 14:19:35 -04:00
Marek Polacek
919373a6bf testsuite: Move auto-96647.C to c++1y/.
This test uses a C++14 feature so fails with -std=c++11.  Therefore
I've moved it to cpp1y/ and used target c++14.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp0x/auto-96647.C: Moved to...
	* g++.dg/cpp1y/auto-96647.C: ...here.  Use target c++14.
2020-09-09 13:51:18 -04:00
H.J. Lu
bf69edf8ce x32: Update gcc.target/i386/builtin_thread_pointer.c
Update gcc.target/i386/builtin_thread_pointer.c for x32.  For

int
foo3 (int i)
{
  int* p = (int*) __builtin_thread_pointer ();
  return p[i];
}

we can't generate:

	movl	%fs:0(,%edi,4), %eax
	ret

for x32 since the address of %fs:0(,%edi,4) is %fs + zero-extended to 64
bits of 0(,%edi,4).  Instead, we generate:

	movl	%fs:0, %eax
	movl	(%eax,%edi,4), %eax

	PR target/96955
	* gcc.target/i386/builtin_thread_pointer.c: Update scan-assembler
	for x32.
2020-09-09 10:42:27 -07:00
H.J. Lu
c6632dc9a8 libphobos: Include <cet.h> to generate the CET marker for -fcf-protection
Include <cet.h> to generate the CET marker for -fcf-protection to avoid

/bin/ld: ../libdruntime/.libs/libgdruntime_convenience.a(libgdruntime_convenience_la-switchcontext.o): error: missing IBT and SHSTK properties

when -z cet-report=error is passed to the linker to create libgphobos.so
and libgdruntime.so.

	PR d/95680
	* libdruntime/config/x86/switchcontext.S: Include <cet.h> to
	generate the CET marker for -fcf-protection.
2020-09-09 10:37:54 -07:00
Tom de Vries
7b9c26519e [nvptx, libgcc] Fix Wbuiltin-declaration-mismatch in atomic.c
When building for target nvptx, we get this and similar warnings for libgcc:
...
src/libgcc/config/nvptx/atomic.c:39:1: warning: conflicting types for \
  built-in function ‘__sync_val_compare_and_swap_1’; expected \
  ‘unsigned char(volatile void *, unsigned char,  unsigned char)’ \
  [-Wbuiltin-declaration-mismatch]
...

Fix this by making sure in atomic.c that the pointers used are of type
'volatile void *'.

Tested by rebuilding atomic.c.

libgcc/ChangeLog:

	* config/nvptx/atomic.c (__SYNC_SUBWORD_COMPARE_AND_SWAP): Fix
	Wbuiltin-declaration-mismatch.
2020-09-09 19:22:07 +02:00
Segher Boessenkool
69ca5f3a98 bb-reorder: Remove a misfiring micro-optimization (PR96475)
When the compgotos pass copies the tail of blocks ending in an indirect
jump, there is a micro-optimization to not copy the last one, since the
original block will then just be deleted.  This does not work properly
if cleanup_cfg does not merge all pairs of blocks we expect it to.  It
also does not work if that last block can be merged into multiple
predecessors.

2020-09-09  Segher Boessenkool  <segher@kernel.crashing.org>

	PR rtl-optimization/96475
	* bb-reorder.c (maybe_duplicate_computed_goto): Remove single_pred_p
	micro-optimization.
2020-09-09 16:55:22 +00:00
Nick Clifton
ad2a37157d If the lto plugin encounters a file with multiple symbol sections, each of which also has a v1 symbol extension section[1] then it will attempt to read the extension data for *every* symbol from each of the extension sections. This results in reading off the end of a buffer with the associated memory corruption that that entails. This patch fixes that problem.
2020-09-09  Nick Clifton  <nickc@redhat.com>

	* lto-plugin.c (struct plugin_symtab): Add last_sym field.
	(parse_symtab_extension): Only read as many entries as are
	available in the buffer.  Store the data read into the symbol
	table indexed from last_sym.  Increment last_sym.
2020-09-09 15:54:20 +01:00
Tom de Vries
5d3c12e418 [nvptx] Fix Wformat in nvptx_assemble_decl_begin
I'm running into this warning:
...
src/gcc/config/nvptx/nvptx.c: In function \
  ‘void nvptx_assemble_decl_begin(FILE*, const char*, const char*, \
  const_tree, long int, unsigned int, bool)’:
src/gcc/config/nvptx/nvptx.c:2229:29: warning: format ‘%d’ expects argument \
  of type ‘int’, but argument 5 has type ‘long unsigned int’ [-Wformat=]
     elt_size * BITS_PER_UNIT);
                             ^
...
which I seem to have introduced in commit b9c7fe59f9 "[nvptx] Fix array
dimension in nvptx_assemble_decl_begin", but not noticed due to configuring
with --disable-build-format-warnings.

Fix this by using the appropriate format.

Rebuild cc1 on nvptx.

gcc/ChangeLog:

	* config/nvptx/nvptx.c (nvptx_assemble_decl_begin): Fix Wformat
	warning.
2020-09-09 15:53:24 +02:00
Patrick Palka
4e03e2e08b c++: Fix resolving the address of overloaded pmf [PR96647]
In resolve_address_of_overloaded_function, currently only the second
pass over the overload set (which considers just the function templates
in the overload set) checks constraints and performs return type
deduction when necessary.  But as the testcases below show, we need to
do the same when considering non-template functions during the first
pass.

gcc/cp/ChangeLog:

	PR c++/96647
	* class.c (resolve_address_of_overloaded_function): Check
	constraints_satisfied_p and perform return-type deduction via
	maybe_instantiate_decl when considering non-template functions
	in the overload set.
	* cp-tree.h (maybe_instantiate_decl): Declare.
	* decl2.c (maybe_instantiate_decl): Remove static.

gcc/testsuite/ChangeLog:

	PR c++/96647
	* g++.dg/cpp0x/auto-96647.C: New test.
	* g++.dg/cpp0x/error9.C: New test.
	* g++.dg/cpp2a/concepts-fn6.C: New test.
2020-09-09 09:21:09 -04:00
Richard Biener
58905f9043 fix useless unsharing of SLP tree
This avoids unsharing the SLP tree when optimizing load permutations
for reductions but there is no actual permute taking place.

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

	* tree-vect-slp.c (vect_attempt_slp_rearrange_stmts): Do
	nothing when the permutation doesn't permute.
2020-09-09 14:46:14 +02:00
Tom de Vries
505590b796 [nvptx] Fix boolean type test in write_fn_proto
When running this libgomp testcase for nvptx accelerator:
...
/* { dg-do run } */
__uint128_t v;
int main () {
  #pragma omp target
  {
    __uint128_t exp = 2;
    __atomic_compare_exchange_n (&v, &exp, 7, false, __ATOMIC_RELEASE,
				 __ATOMIC_ACQUIRE);
  }
}
...
we run into this assert in write_fn_proto:
...
913             gcc_assert (type == boolean_type_node);
...

This happens when doing some special-handling code for
__atomic_compare_exchange_1/2/4/8/16.  The function decls have a parameter
called weak of type bool, which is skipped when writing the decl because
the corresponding libatomic functions do not have that parameter.  The assert
is there to verify that we skip the correct parameter.

However, we assert because we have different type of bools:
...
(gdb) call debug_generic_expr (type)
_Bool
(gdb) call debug_generic_expr (global_trees[TI_BOOLEAN_TYPE])
bool
...

Fix this by checking for TREE_CODE (type) == BOOLEAN_TYPE instead.

Tested libgomp on x86_64-linux with nvptx accelerator.

Likewise, tested that the test-case above does not ICE anymore.

gcc/ChangeLog:

	PR target/96991
	* config/nvptx/nvptx.c (write_fn_proto): Fix boolean type check.
2020-09-09 14:33:19 +02:00
Richard Biener
db918db2c3 enable live comparison vectorization
This removes a check preventing vectorization of live results of
vectorized comparisons.  I tested it with AVX512 mask registers
(inspecting assembly) and traditional vector masks.

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

	* tree-vect-stmts.c (vectorizable_comparison): Allow
	STMT_VINFO_LIVE_P stmts.

	* gcc.dg/vect/vect-live-6.c: New testcase.
2020-09-09 13:12:27 +02:00
Tobias Burnus
cbc12c5824 gfortran.dg/gomp/combined-if.f90: Update nvptx tree-dump times
nvptx has additional omp simd lines with _simt_ with -O1 and higher.

gcc/testsuite/ChangeLog:

	* gfortran.dg/gomp/combined-if.f90: Update scan-tree-dump-times for
	'omp simd.*if' for nvptx even more.
2020-09-09 11:49:08 +02:00
Richard Biener
783dc66f9c enable live condition vectorization
This removes a check preventing vectorization of live results of
vectorized conditions.

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

	* tree-vect-stmts.c (vectorizable_condition): Allow
	STMT_VINFO_LIVE_P stmts.

	* gcc.dg/vect/vect-cond-13.c: New testcase.
	* gcc.target/i386/pr87007-4.c: Adjust.
	* gcc.target/i386/pr87007-5.c: Likewise.
2020-09-09 11:36:19 +02:00
Rainer Orth
0d7d52131a config: Sync largefile.m4 from binutils-gdb
The following patch improves handling of largefile support with procfs
on 32-bit Solaris.  It has already been approved and installed for
binutils-gdb in the thread starting at

	[PATCH] Unify Solaris procfs and largefile handling
        https://sourceware.org/pipermail/gdb-patches/2020-June/169977.html

I'm syncing the config/largefile.m4 part to gcc now which is the master
for config.  Since ACX_LARGEFILE isn't used anywhere in the gcc tree,
I'm installing it as obvious.

2020-09-09  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

	config:
	* largefile.m4: Sync from binutils-gdb.
2020-09-09 11:02:01 +02:00
Richard Biener
fb51be60c8 tree-optimization/96978 - fix fallout of BB vectorization of live stmts
This avoids looking at STMT_VINFO_LIVE_P when vectorizing BBs.

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

	PR tree-optimization/96978
	* tree-vect-stmts.c (vectorizable_condition): Do not
	look at STMT_VINFO_LIVE_P for BB vectorization.
	(vectorizable_comparison): Likewise.
2020-09-09 10:38:34 +02:00
liuhongt
e470d8af81 Implement __builtin_thread_pointer for x86 TLS.
gcc/ChangeLog:
	PR target/96955
	* config/i386/i386.md (get_thread_pointer<mode>): New
	expander.

gcc/testsuite/ChangeLog:

	* gcc.target/i386/builtin_thread_pointer.c: New test.
2020-09-09 16:17:42 +08:00
Tobias Burnus
61c2d476a5 Fortran: Fixes for OpenMP loop-iter privatization (PRs 95109 + 94690)
This commit also fixes a gfortran.dg/gomp/target1.f90 regression;
target1.f90 tests the resolve.c and openmp.c changes.

gcc/fortran/ChangeLog:

	PR fortran/95109
	PR fortran/94690
	* resolve.c (gfc_resolve_code): Also call
	gfc_resolve_omp_parallel_blocks for 'distribute parallel do (simd)'.
	* openmp.c (gfc_resolve_omp_parallel_blocks): Handle it.
	(gfc_resolve_do_iterator): Remove special code for SIMD, which is
	not needed.
	* trans-openmp.c (gfc_trans_omp_target): For TARGET_PARALLEL_DO_SIMD,
	call simd not do processing function.

gcc/testsuite/ChangeLog:

	PR fortran/95109
	PR fortran/94690
	* gfortran.dg/gomp/combined-if.f90: Update scan-tree-dump-times for
	'omp simd.*if'.
	* gfortran.dg/gomp/openmp-simd-5.f90: New test.
2020-09-09 09:33:51 +02:00
Ian Lance Taylor
f56f1a5a75 libbacktrace: don't strip leading underscore on 64-bit PE
* pecoff.c (coff_initialize_syminfo): Add is_64 parameter.
	(coff_add): Determine and pass is_64.
2020-09-08 19:21:54 -07:00
Ian Lance Taylor
181f877b6c libbacktrace: fetch executable path on macOS
PR libbacktrace/96973
	* fileline.c (macho_get_executable_path): New static function.
	(fileline_initialize): Call macho_get_executable_path.
2020-09-08 19:09:21 -07:00
Ian Lance Taylor
0755f573f0 libbacktrace: avoid ambiguous binary search
Searching for a range match can cause the search order to not match
the sort order, which can cause libbacktrace to miss matching entries.
Allocate an extra entry at the end of function_addrs and unit_addrs vectors,
so that we can safely compare to the next entry when searching.
Adjust the matching code accordingly.

Fixes https://github.com/ianlancetaylor/libbacktrace/issues/44.

	* dwarf.c (function_addrs_search): Compare against the next entry
	low address, not the high address.
	(unit_addrs_search): Likewise.
	(build_address_map): Add a trailing unit_addrs.
	(read_function_entry): Add a trailing function_addrs.
	(read_function_info): Likewise.
	(report_inlined_functions): Search backward for function_addrs
	match.
	(dwarf_lookup_pc): Search backward for unit_addrs and
	function_addrs matches.
2020-09-08 18:22:35 -07:00
GCC Administrator
31a0504624 Daily bump. 2020-09-09 00:16:29 +00:00
Ian Lance Taylor
494c5103c9 libbacktrace: fix tipo in comment
* simple.c (simple_unwind): Correct comment spelling.
2020-09-08 15:07:24 -07:00
Ian Lance Taylor
a8a7a97b4e libbacktrace: correct memory lengths in Mach-O dsym support
* macho.c (macho_add_dsym): Make space for '/' in dsym.  Use
	correct length when freeing diralc.
2020-09-08 14:51:32 -07:00
Julian Brown
8183ebcdc1 openacc: Fix atomic_capture-2.c iteration-ordering issues
The test case was written with assumptions about loop iteration ordering
that are not guaranteed by OpenACC and do not apply on all targets,
in particular AMD GCN. This patch removes those assumptions.

2020-09-08  Julian Brown  <julian@codesourcery.com>

libgomp/
	* testsuite/libgomp.oacc-c-c++-common/atomic_capture-2.c: Remove
	iteration-ordering assumptions.
2020-09-08 13:26:42 -07:00
Julian Brown
e929d65b48 amdgcn: Add waitcnt after LDS write instructions
Data-share write (ds_write) instructions do not necessarily complete
the write to LDS immediately. When a write completes, LGKM_CNT is
decremented. For now, we wait until LGKM_CNT reaches zero after each
ds_write instruction.

This fixes a race condition in the case where LDS is read immediately
after being written. This can happen with broadcast operations.

2020-09-08  Julian Brown  <julian@codesourcery.com>

gcc/
	* config/gcn/gcn-valu.md (scatter<mode>_insn_1offset_ds<exec_scatter>):
	Add waitcnt.
	* config/gcn/gcn.md (*mov<mode>_insn, *movti_insn): Add waitcnt to
	ds_write alternatives.
2020-09-08 13:26:42 -07:00
Julian Brown
3aee3aaf48 openacc: Fix mkoffload SGPR/VGPR count parsing for HSACO v3
If an offload kernel uses a large number of VGPRs, AMD GCN hardware may
need to limit the number of threads/workers launched for that kernel.
The number of SGPRs/VGPRs in use is detected by mkoffload and recorded in
the processed output.  The patterns emitted detailing SGPR/VGPR occupancy
changed between HSACO v2 and v3 though, so this patch updates parsing
to account for that.

2020-09-08  Julian Brown  <julian@codesourcery.com>

gcc/
	* config/gcn/mkoffload.c (process_asm): Initialise regcount.  Update
	scanning for SGPR/VGPR usage for HSACO v3.
2020-09-08 13:26:42 -07:00
Julian Brown
d6d9be7c6b openacc: Fix race condition in Fortran loop collapse tests
The gangs participating in a gang-partitioned loop are not all guaranteed
to complete before some given gang continues to execute beyond that loop.
This means that two existing test cases contain a race condition,
because a loop that may be gang-partitioned is followed immediately by
another loop.  The fix is to place the loops in separate parallel regions.

2020-09-08  Julian Brown  <julian@codesourcery.com>

libgomp/
	* testsuite/libgomp.oacc-fortran/collapse-1.f90: Fix race condition.
	* testsuite/libgomp.oacc-fortran/collapse-2.f90: Likewise.
2020-09-08 13:26:42 -07:00
Ian Lance Taylor
488e33339e libbacktrace: correctly swap Mach-O 32-bit file offset
libbacktrace/ChangeLog:
	PR libbacktrace/96973
	* macho.c (macho_add_fat): Correctly swap 32-bit file offset.
2020-09-08 13:20:26 -07:00
Ian Lance Taylor
651c61c3ce libbacktrace: only match magic number at start of line
libbacktrace/ChangeLog:
	PR libbacktrace/96971
	* filetype.awk: Only match magic number at start of line.
2020-09-08 12:52:29 -07:00
Felix Willgerodt
87603e5656 floatformat.h: Add bfloat16 support.
This change is motivated by a patchset that adds bfloat16 debugging
support for new avx512 instructions to GDB. The gdb thread can be found
here: https://sourceware.org/pipermail/gdb-patches/2020-July/170820.html

include:
2020-08-17  Felix Willgerodt  <felix.willgerodt@intel.com>

	* floatformat.h (floatformat_bfloat16_big): New.
	(floatformat_bfloat16_little): New.

libiberty:
2020-08-17  Felix Willgerodt  <felix.willgerodt@intel.com>

	* floatformat.c (floatformat_bfloat16_big): New.
	(floatformat_bfloat16_little): New.
2020-09-08 17:38:12 +00:00
David Malcolm
34d926dba0 analyzer: fix another ICE in constructor-handling [PR96949]
PR analyzer/96949 reports an ICE with
--param analyzer-max-svalue-depth=0, where the param value leads
to INTEGER_CST values in a RANGE_EXPR being treated as unknown
symbolic values.

This patch replaces implicit assumptions that these values are
concrete (and thus have concrete bit offsets), adding
error-handling for symbolic cases instead of assertions.

gcc/analyzer/ChangeLog:
	PR analyzer/96949
	* store.cc (binding_map::apply_ctor_val_to_range): Add
	error-handling for the cases where we have symbolic offsets.

gcc/testsuite/ChangeLog:
	PR analyzer/96949
	* gfortran.dg/analyzer/pr96949.f90: New test.
2020-09-08 10:51:22 -04:00
David Malcolm
af656c401e analyzer: fix ICE on RANGE_EXPR with CONSTRUCTOR value [PR96950]
gcc/analyzer/ChangeLog:
	PR analyzer/96950
	* store.cc (binding_map::apply_ctor_to_region): Handle RANGE_EXPR
	where min_index == max_index.
	(binding_map::apply_ctor_val_to_range): Replace assertion that we
	don't have a CONSTRUCTOR value with error-handling.
2020-09-08 10:50:12 -04:00
David Malcolm
47997a32e6 analyzer: fix ICE on machine-specific builtins [PR96962]
In g:ee7bfbe5eb70a23bbf3a2cedfdcbd2ea1a20c3f2 I added a
  switch (DECL_UNCHECKED_FUNCTION_CODE (callee_fndecl))
to region_model::on_call_pre guarded by
  fndecl_built_in_p (callee_fndecl).
I meant to handle only normal built-ins, whereas this
single-argument overload of fndecl_built_in_p returns true for any
kind of built-in.

PR analyzer/96962 reports a case where this matches for a
machine-specific builtin, leading to an ICE.  Fixed thusly.

gcc/analyzer/ChangeLog:
	PR analyzer/96962
	* region-model.cc (region_model::on_call_pre): Fix guard on switch
	on built-ins to only consider BUILT_IN_NORMAL, rather than other
	kinds of build-ins.
2020-09-08 10:49:05 -04:00
Aldy Hernandez
19b0fed7c2 PR tree-optimization/96967 - cast label range to type of switch operand
PR tree-optimization/96967
	* tree-vrp.c (find_case_label_range): Cast label range to
	type of switch operand.
2020-09-08 13:43:35 +02:00