Jan Hubicka [Wed, 25 Nov 2020 19:52:20 +0000 (20:52 +0100)]
New ipa-modref testcases
gcc/testsuite/ChangeLog:
* gcc.dg/lto/modref-3_0.c: New test.
* gcc.dg/lto/modref-3_1.c: New test.
* gcc.dg/lto/modref-4_0.c: New test.
* gcc.dg/lto/modref-4_1.c: New test.
* gcc.dg/tree-ssa/modref-5.c: New test.
Jan Hubicka [Wed, 25 Nov 2020 19:51:26 +0000 (20:51 +0100)]
Add EAF_NODIRECTESCAPE flag
Main limitation of modref is the fact that it does not
track anything in memory. This is intentional - I wanted the initial
implementation to be cheap. However it also makes it very limited when it comes
to detecting noescape especially because it is paranoid about what memory
accesses may be used to copy (bits of) pointers.
This patch adds EAF_NODIRECTSCAPE that is weaker vairant of EAF_NOESCAPE where
we only know that the pointer itself does not escape, but memory pointed to
may. This is a lot more reliable to auto-detect that EAF_NOESCAPE and still
enables additional optimization. With patch we get nodirectscape flag for b
that enables in practice similar optimization as EAF_NOESCAPE for arrays of
integers that points nowhere :)
gcc/ChangeLog:
* gimple.c (gimple_call_arg_flags): Also imply EAF_NODIRECTESCAPE.
* tree-core.h (EAF_NODRECTESCAPE): New flag.
* tree-ssa-structalias.c (make_indirect_escape_constraint): New
function.
(handle_rhs_call): Hanlde EAF_NODIRECTESCAPE.
* ipa-modref.c (dump_eaf_flags): Print EAF_NODIRECTESCAPE.
(deref_flags): Dereference is always EAF_NODIRECTESCAPE.
(modref_lattice::init): Also set EAF_NODIRECTESCAPE.
(analyze_ssa_name_flags): Pure functions do not affect
EAF_NODIRECTESCAPE.
(analyze_params): Likewise.
(ipa_merge_modref_summary_after_inlining): Likewise.
(modref_merge_call_site_flags): Likewise.
Jan Hubicka [Wed, 25 Nov 2020 19:33:00 +0000 (20:33 +0100)]
Copy arg_flags in duplication hoooks in ipa-modref
* ipa-modref.c (modref_summaries::duplicate,
modref_summaries_lto::duplicate): Copy arg_flags.
(remap_arg_flags): Fix remapping of arg_flags.
Harald Anlauf [Wed, 25 Nov 2020 19:20:44 +0000 (20:20 +0100)]
PR fortran/85796 - Floating point exception with implied do
Catch invalid step=0 in implied do loop within data statements.
gcc/fortran/ChangeLog:
PR fortran/85796
* resolve.c (traverse_data_list): Fix copy&paste errors; catch
step=0 in implied do loop.
gcc/testsuite/ChangeLog:
PR fortran/85796
* gfortran.dg/pr85796.f90: New test.
Thomas Schwinge [Wed, 25 Nov 2020 10:41:45 +0000 (11:41 +0100)]
Add 'g++.dg/gomp/map-{1,2}.C'
gcc/testsuite/
* g++.dg/gomp/map-1.C: New.
* g++.dg/gomp/map-2.C: Likewise.
* c-c++-common/gomp/map-1.c: Adjust.
* c-c++-common/gomp/map-2.c: Likewise.
Thomas Schwinge [Wed, 25 Nov 2020 12:03:52 +0000 (13:03 +0100)]
Fix templatized C++ OpenACC 'cache' directive ICEs
This has been broken forever, whoops...
gcc/cp/
* pt.c (tsubst_omp_clauses): Handle 'OMP_CLAUSE__CACHE_'.
(tsubst_expr): Handle 'OACC_CACHE'.
gcc/testsuite/
* c-c++-common/goacc/cache-1.c: Update.
* c-c++-common/goacc/cache-2.c: Likewise.
* g++.dg/goacc/cache-1.C: New.
* g++.dg/goacc/cache-2.C: Likewise.
libgomp/
* testsuite/libgomp.oacc-c++/cache-1.C: New.
* testsuite/libgomp.oacc-c-c++-common/cache-1.c: Update.
Stefan Kanthak [Wed, 25 Nov 2020 18:36:51 +0000 (11:36 -0700)]
Improve abs with overflow implementations
libgcc/
* libgcc2.c (absvSI2): Simplify/improve implementation by using
builtin_add_overflow.
(absvsi2, absvDI2): Likewise.
Jonathan Wakely [Wed, 25 Nov 2020 17:59:44 +0000 (17:59 +0000)]
libstdc++: Remove redundant clock conversions in atomic waits
For the case where a timeout is specified using the system_clock we
perform a conversion to the preferred clock (which is either
steady_clock or system_clock itself), wait using __cond_wait_until_impl,
and then check the time by that clock again to see if it was reached.
This is entirely redundant, as we can just call __cond_wait_until_impl
directly. It will wait using the specified clock, and there's no need to
check the time twice. For the no_timeout case this removes two
unnecessary calls to the clock's now() function, and for the timeout
case it removes three calls.
libstdc++-v3/ChangeLog:
* include/bits/atomic_timed_wait.h (__cond_wait_until): Do not
perform redundant conversions to the same clock.
Jonathan Wakely [Wed, 25 Nov 2020 14:24:21 +0000 (14:24 +0000)]
libstdc++: Encapsulate __gthread_cond_t as std::__condvar
This introduces a new internal utility, std::__condvar, which is a
simplified form of std::condition_variable. It has no dependency on
<chrono> or std::unique_lock, which allows it to be used in
<bits/atomic_wait.h>.
This avoids repeating the #ifdef __GTHREAD_COND_INIT preprocessor
conditions and associated logic for initializing a __gthread_cond_t
correctly. It also encapsulates most of the __gthread_cond_xxx functions
as member functions of __condvar.
libstdc++-v3/ChangeLog:
* include/bits/atomic_timed_wait.h (__cond_wait_until_impl):
Do not define when _GLIBCXX_HAVE_LINUX_FUTEX is defined. Use
__condvar and mutex instead of __gthread_cond_t and
unique_lock<mutex>.
(__cond_wait_until): Likewise. Fix test for return value of
__cond_wait_until_impl.
(__timed_waiters::_M_do_wait_until): Use __condvar instead
of __gthread_cond_t.
* include/bits/atomic_wait.h: Remove <bits/unique_lock.h>
include. Only include <bits/std_mutex.h> if not using futexes.
(__platform_wait_max_value): Remove unused variable.
(__waiters::lock_t): Use lock_guard instead of unique_lock.
(__waiters::_M_cv): Use __condvar instead of __gthread_cond_t.
(__waiters::_M_do_wait(__platform_wait_t)): Likewise.
(__waiters::_M_notify()): Likewise. Use notify_one() if not
asked to notify all.
* include/bits/std_mutex.h (__condvar): New type.
* include/std/condition_variable (condition_variable::_M_cond)
(condition_variable::wait_until): Use __condvar instead of
__gthread_cond_t.
* src/c++11/condition_variable.cc (condition_variable): Define
default constructor and destructor as defaulted.
(condition_variable::wait, condition_variable::notify_one)
(condition_variable::notify_all): Forward to corresponding
member function of __condvar.
Jonathan Wakely [Wed, 25 Nov 2020 14:39:54 +0000 (14:39 +0000)]
libstdc++: Fix testsuite helper functions [PR 97936]
This fixes a race condition in the util/atomic/wait_notify_util.h header
used by several tests, which should make the tests work properly.
libstdc++-v3/ChangeLog:
PR libstdc++/97936
* testsuite/29_atomics/atomic/wait_notify/bool.cc: Re-eneable
test.
* testsuite/29_atomics/atomic/wait_notify/generic.cc: Likewise.
* testsuite/29_atomics/atomic/wait_notify/pointers.cc: Likewise.
* testsuite/29_atomics/atomic_flag/wait_notify/1.cc: Likewise.
* testsuite/29_atomics/atomic_float/wait_notify.cc: Likewise.
* testsuite/29_atomics/atomic_integral/wait_notify.cc: Likewise.
* testsuite/util/atomic/wait_notify_util.h: Fix missed
notifications by making the new thread wait until the parent
thread is waiting on the condition variable.
Martin Sebor [Wed, 25 Nov 2020 18:00:10 +0000 (11:00 -0700)]
PR middle-end/97956 - ICE due to type mismatch in pointer_plus_expr during memchr folding
gcc/ChangeLog:
PR middle-end/97956
* gimple-fold.c (gimple_fold_builtin_memchr): Use sizetype for pointer
offsets.
gcc/testsuite/ChangeLog:
PR middle-end/97956
* gcc.dg/memchr-3.c: New test.
Jonathan Wakely [Wed, 25 Nov 2020 17:18:44 +0000 (17:18 +0000)]
libstdc++: Fix missing subsumption in std::iterator_traits [PR 97935]
libstdc++-v3/ChangeLog:
PR libstdc++/97935
* include/bits/iterator_concepts.h (__detail::__iter_without_category):
New helper concept.
(__iterator_traits::__cat): Use __detail::__iter_without_category.
* testsuite/24_iterators/associated_types/iterator.traits.cc: New test.
Jonathan Wakely [Wed, 25 Nov 2020 16:58:05 +0000 (16:58 +0000)]
libstdc++: Fix test failure on AIX
This fixes a failure on AIX 7.2:
FAIL: 17_intro/names.cc (test for excess errors)
Excess errors:
/home/jwakely/src/gcc/libstdc++-v3/testsuite/17_intro/names.cc:99: error: expected identifier before '(' token
/usr/include/sys/var.h:187: error: expected unqualified-id before '{' token
/usr/include/sys/var.h:187: error: expected ')' before '{' token
/usr/include/sys/var.h:337: error: expected unqualified-id before ';' token
/usr/include/sys/var.h:337: error: expected ')' before ';' token
libstdc++-v3/ChangeLog:
* testsuite/17_intro/names.cc: Do not test 'v' on AIX.
Matthew Malcomson [Wed, 25 Nov 2020 16:33:56 +0000 (16:33 +0000)]
libsanitizer: Add recently added commit to LOCAL_PATCHES
libsanitizer/ChangeLog:
* LOCAL_PATCHES: Add one commit.
Matthew Malcomson [Wed, 25 Nov 2020 16:31:49 +0000 (16:31 +0000)]
libsanitizer: Add tests
Only interesting thing here is that we have to make sure the tagging mechanism
is deterministic to avoid flaky tests.
gcc/testsuite/ChangeLog:
* c-c++-common/ubsan/sanitize-recover-7.c: Update error message format.
* lib/asan-dg.exp (asan_link_flags): Implement as a helper
function asan_link_flags_1 which asan_link_flags and
hwasan_link_flags use.
(asan_link_flags_1): Parametrised version of asan_link_flags.
* c-c++-common/hwasan/aligned-alloc.c: New test.
* c-c++-common/hwasan/alloca-array-accessible.c: New test.
* c-c++-common/hwasan/alloca-base-init.c: New test.
* c-c++-common/hwasan/alloca-gets-different-tag.c: New test.
* c-c++-common/hwasan/alloca-outside-caught.c: New test.
* c-c++-common/hwasan/arguments-1.c: New test.
* c-c++-common/hwasan/arguments-2.c: New test.
* c-c++-common/hwasan/arguments-3.c: New test.
* c-c++-common/hwasan/arguments.c: New test.
* c-c++-common/hwasan/asan-pr63316.c: New test.
* c-c++-common/hwasan/asan-pr70541.c: New test.
* c-c++-common/hwasan/asan-pr78106.c: New test.
* c-c++-common/hwasan/asan-pr79944.c: New test.
* c-c++-common/hwasan/asan-rlimit-mmap-test-1.c: New test.
* c-c++-common/hwasan/bitfield-1.c: New test.
* c-c++-common/hwasan/bitfield-2.c: New test.
* c-c++-common/hwasan/builtin-special-handling.c: New test.
* c-c++-common/hwasan/check-interface.c: New test.
* c-c++-common/hwasan/halt_on_error-1.c: New test.
* c-c++-common/hwasan/handles-poly_int-marked-vars.c: New test.
* c-c++-common/hwasan/heap-overflow.c: New test.
* c-c++-common/hwasan/hwasan-poison-optimisation.c: New test.
* c-c++-common/hwasan/hwasan-thread-access-parent.c: New test.
* c-c++-common/hwasan/hwasan-thread-basic-failure.c: New test.
* c-c++-common/hwasan/hwasan-thread-clears-stack.c: New test.
* c-c++-common/hwasan/hwasan-thread-success.c: New test.
* c-c++-common/hwasan/kernel-defaults.c: New test.
* c-c++-common/hwasan/large-aligned-0.c: New test.
* c-c++-common/hwasan/large-aligned-1.c: New test.
* c-c++-common/hwasan/large-aligned-untagging-0.c: New test.
* c-c++-common/hwasan/large-aligned-untagging-1.c: New test.
* c-c++-common/hwasan/large-aligned-untagging-2.c: New test.
* c-c++-common/hwasan/large-aligned-untagging-3.c: New test.
* c-c++-common/hwasan/large-aligned-untagging-4.c: New test.
* c-c++-common/hwasan/large-aligned-untagging-5.c: New test.
* c-c++-common/hwasan/large-aligned-untagging-6.c: New test.
* c-c++-common/hwasan/large-aligned-untagging-7.c: New test.
* c-c++-common/hwasan/macro-definition.c: New test.
* c-c++-common/hwasan/no-sanitize-attribute.c: New test.
* c-c++-common/hwasan/param-instrument-mem-intrinsics.c: New test.
* c-c++-common/hwasan/param-instrument-reads-and-writes.c: New test.
* c-c++-common/hwasan/param-instrument-reads.c: New test.
* c-c++-common/hwasan/param-instrument-writes.c: New test.
* c-c++-common/hwasan/random-frame-tag.c: New test.
* c-c++-common/hwasan/sanity-check-pure-c.c: New test.
* c-c++-common/hwasan/setjmp-longjmp-0.c: New test.
* c-c++-common/hwasan/setjmp-longjmp-1.c: New test.
* c-c++-common/hwasan/stack-tagging-basic-0.c: New test.
* c-c++-common/hwasan/stack-tagging-basic-1.c: New test.
* c-c++-common/hwasan/stack-tagging-disable.c: New test.
* c-c++-common/hwasan/unprotected-allocas-0.c: New test.
* c-c++-common/hwasan/unprotected-allocas-1.c: New test.
* c-c++-common/hwasan/use-after-free.c: New test.
* c-c++-common/hwasan/vararray-outside-caught.c: New test.
* c-c++-common/hwasan/vararray-stack-restore-correct.c: New test.
* c-c++-common/hwasan/very-large-objects.c: New test.
* g++.dg/hwasan/hwasan.exp: New test.
* g++.dg/hwasan/rvo-handled.C: New test.
* gcc.dg/hwasan/hwasan.exp: New test.
* gcc.dg/hwasan/nested-functions-0.c: New test.
* gcc.dg/hwasan/nested-functions-1.c: New test.
* gcc.dg/hwasan/nested-functions-2.c: New test.
* lib/hwasan-dg.exp: New file.
Matthew Malcomson [Wed, 25 Nov 2020 16:31:47 +0000 (16:31 +0000)]
libsanitizer: Add hwasan pass and associated gimple changes
There are four main features to this change:
1) Check pointer tags match address tags.
When sanitizing for hwasan we now put HWASAN_CHECK internal functions before
memory accesses in the `asan` pass. This checks that a tag in the pointer
being used match the tag stored in shadow memory for the memory region being
used.
These internal functions are expanded into actual checks in the sanopt
pass that happens just before expansion into RTL.
We use the same mechanism that currently inserts ASAN_CHECK internal
functions to insert the new HWASAN_CHECK functions.
2) Instrument known builtin function calls.
Handle all builtin functions that we know use memory accesses.
This commit uses the machinery added for ASAN to identify builtin
functions that access memory.
The main differences between the approaches for HWASAN and ASAN are:
- libhwasan intercepts much less builtin functions.
- Alloca needs to be transformed differently (instead of adding
redzones it needs to tag shadow memory and return a tagged pointer).
- stack_restore needs to untag the shadow stack between the current
position and where it's going.
- `noreturn` functions can not be handled by simply unpoisoning the
entire shadow stack -- there is no "always valid" tag.
(exceptions and things such as longjmp need to be handled in a
different way, usually in the runtime).
For hardware implemented checking (such as AArch64's memory tagging
extension) alloca and stack_restore will need to be handled by hooks in
the backend rather than transformation at the gimple level. This will
allow architecture specific handling of such stack modifications.
3) Introduce HWASAN block-scope poisoning
Here we use exactly the same mechanism as ASAN_MARK to poison/unpoison
variables on entry/exit of a block.
In order to simply use the exact same machinery we're using the same
internal functions until the SANOPT pass. This means that all handling
of ASAN_MARK is the same.
This has the negative that the naming may be a little confusing, but a
positive that handling of the internal function doesn't have to be
duplicated for a function that behaves exactly the same but has a
different name.
gcc/ChangeLog:
* asan.c (asan_instrument_reads): New.
(asan_instrument_writes): New.
(asan_memintrin): New.
(handle_builtin_stack_restore): Account for HWASAN.
(handle_builtin_alloca): Account for HWASAN.
(get_mem_refs_of_builtin_call): Special case strlen for HWASAN.
(hwasan_instrument_reads): New.
(hwasan_instrument_writes): New.
(hwasan_memintrin): New.
(report_error_func): Assert not HWASAN.
(build_check_stmt): Make HWASAN_CHECK instead of ASAN_CHECK.
(instrument_derefs): HWASAN does not tag globals.
(instrument_builtin_call): Use new helper functions.
(maybe_instrument_call): Don't instrument `noreturn` functions.
(initialize_sanitizer_builtins): Add new type.
(asan_expand_mark_ifn): Account for HWASAN.
(asan_expand_check_ifn): Assert never called by HWASAN.
(asan_expand_poison_ifn): Account for HWASAN.
(asan_instrument): Branch based on whether using HWASAN or ASAN.
(pass_asan::gate): Return true if sanitizing HWASAN.
(pass_asan_O0::gate): Return true if sanitizing HWASAN.
(hwasan_check_func): New.
(hwasan_expand_check_ifn): New.
(hwasan_expand_mark_ifn): New.
(gate_hwasan): New.
* asan.h (hwasan_expand_check_ifn): New decl.
(hwasan_expand_mark_ifn): New decl.
(gate_hwasan): New decl.
(asan_intercepted_p): Always false for hwasan.
(asan_sanitize_use_after_scope): Account for HWASAN.
* builtin-types.def (BT_FN_PTR_CONST_PTR_UINT8): New.
* gimple-fold.c (gimple_build): New overload for building function
calls without arguments.
(gimple_build_round_up): New.
* gimple-fold.h (gimple_build): New decl.
(gimple_build): New inline function.
(gimple_build_round_up): New decl.
(gimple_build_round_up): New inline function.
* gimple-pretty-print.c (dump_gimple_call_args): Account for
HWASAN.
* gimplify.c (asan_poison_variable): Account for HWASAN.
(gimplify_function_tree): Remove requirement of
SANITIZE_ADDRESS, requiring asan or hwasan is accounted for in
`asan_sanitize_use_after_scope`.
* internal-fn.c (expand_HWASAN_CHECK): New.
(expand_HWASAN_ALLOCA_UNPOISON): New.
(expand_HWASAN_CHOOSE_TAG): New.
(expand_HWASAN_MARK): New.
(expand_HWASAN_SET_TAG): New.
* internal-fn.def (HWASAN_ALLOCA_UNPOISON): New.
(HWASAN_CHOOSE_TAG): New.
(HWASAN_CHECK): New.
(HWASAN_MARK): New.
(HWASAN_SET_TAG): New.
* sanitizer.def (BUILT_IN_HWASAN_LOAD1): New.
(BUILT_IN_HWASAN_LOAD2): New.
(BUILT_IN_HWASAN_LOAD4): New.
(BUILT_IN_HWASAN_LOAD8): New.
(BUILT_IN_HWASAN_LOAD16): New.
(BUILT_IN_HWASAN_LOADN): New.
(BUILT_IN_HWASAN_STORE1): New.
(BUILT_IN_HWASAN_STORE2): New.
(BUILT_IN_HWASAN_STORE4): New.
(BUILT_IN_HWASAN_STORE8): New.
(BUILT_IN_HWASAN_STORE16): New.
(BUILT_IN_HWASAN_STOREN): New.
(BUILT_IN_HWASAN_LOAD1_NOABORT): New.
(BUILT_IN_HWASAN_LOAD2_NOABORT): New.
(BUILT_IN_HWASAN_LOAD4_NOABORT): New.
(BUILT_IN_HWASAN_LOAD8_NOABORT): New.
(BUILT_IN_HWASAN_LOAD16_NOABORT): New.
(BUILT_IN_HWASAN_LOADN_NOABORT): New.
(BUILT_IN_HWASAN_STORE1_NOABORT): New.
(BUILT_IN_HWASAN_STORE2_NOABORT): New.
(BUILT_IN_HWASAN_STORE4_NOABORT): New.
(BUILT_IN_HWASAN_STORE8_NOABORT): New.
(BUILT_IN_HWASAN_STORE16_NOABORT): New.
(BUILT_IN_HWASAN_STOREN_NOABORT): New.
(BUILT_IN_HWASAN_TAG_MISMATCH4): New.
(BUILT_IN_HWASAN_HANDLE_LONGJMP): New.
(BUILT_IN_HWASAN_TAG_PTR): New.
* sanopt.c (sanopt_optimize_walker): Act for hwasan.
(pass_sanopt::execute): Act for hwasan.
* toplev.c (compile_file): Use `gate_hwasan` function.
Matthew Malcomson [Wed, 25 Nov 2020 16:31:45 +0000 (16:31 +0000)]
libsanitizer: mid-end: Introduce stack variable handling for HWASAN
Handling stack variables has three features.
1) Ensure HWASAN required alignment for stack variables
When tagging shadow memory, we need to ensure that each tag granule is
only used by one variable at a time.
This is done by ensuring that each tagged variable is aligned to the tag
granule representation size and also ensure that the end of each
object is aligned to ensure the start of any other data stored on the
stack is in a different granule.
This patch ensures the above by forcing the stack pointer to be aligned
before and after allocating any stack objects. Since we are forcing
alignment we also use `align_local_variable` to ensure this new alignment
is advertised properly through SET_DECL_ALIGN.
2) Put tags into each stack variable pointer
Make sure that every pointer to a stack variable includes a tag of some
sort on it.
The way tagging works is:
1) For every new stack frame, a random tag is generated.
2) A base register is formed from the stack pointer value and this
random tag.
3) References to stack variables are now formed with RTL describing an
offset from this base in both tag and value.
The random tag generation is handled by a backend hook. This hook
decides whether to introduce a random tag or use the stack background
based on the parameter hwasan-random-frame-tag. Using the stack
background is necessary for testing and bootstrap. It is necessary
during bootstrap to avoid breaking the `configure` test program for
determining stack direction.
Using the stack background means that every stack frame has the initial
tag of zero and variables are tagged with incrementing tags from 1,
which also makes debugging a bit easier.
Backend hooks define the size of a tag, the layout of the HWASAN shadow
memory, and handle emitting the code that inserts and extracts tags from a
pointer.
3) For each stack variable, tag and untag the shadow stack on function
prologue and epilogue.
On entry to each function we tag the relevant shadow stack region for
each stack variable. This stack region is tagged to match the tag added to
each pointer to that variable.
This is the first patch where we use the HWASAN shadow space, so we need
to add in the libhwasan initialisation code that creates this shadow
memory region into the binary we produce. This instrumentation is done
in `compile_file`.
When exiting a function we need to ensure the shadow stack for this
function has no remaining tags. Without clearing the shadow stack area
for this stack frame, later function calls could get false positives
when those later function calls check untagged areas (such as parameters
passed on the stack) against a shadow stack area with left-over tag.
Hence we ensure that the entire stack frame is cleared on function exit.
config/ChangeLog:
* bootstrap-hwasan.mk: Disable random frame tags for stack-tagging
during bootstrap.
gcc/ChangeLog:
* asan.c (struct hwasan_stack_var): New.
(hwasan_sanitize_p): New.
(hwasan_sanitize_stack_p): New.
(hwasan_sanitize_allocas_p): New.
(initialize_sanitizer_builtins): Define new builtins.
(ATTR_NOTHROW_LIST): New macro.
(hwasan_current_frame_tag): New.
(hwasan_frame_base): New.
(stack_vars_base_reg_p): New.
(hwasan_maybe_init_frame_base_init): New.
(hwasan_record_stack_var): New.
(hwasan_get_frame_extent): New.
(hwasan_increment_frame_tag): New.
(hwasan_record_frame_init): New.
(hwasan_emit_prologue): New.
(hwasan_emit_untag_frame): New.
(hwasan_finish_file): New.
(hwasan_truncate_to_tag_size): New.
* asan.h (hwasan_record_frame_init): New declaration.
(hwasan_record_stack_var): New declaration.
(hwasan_emit_prologue): New declaration.
(hwasan_emit_untag_frame): New declaration.
(hwasan_get_frame_extent): New declaration.
(hwasan_maybe_enit_frame_base_init): New declaration.
(hwasan_frame_base): New declaration.
(stack_vars_base_reg_p): New declaration.
(hwasan_current_frame_tag): New declaration.
(hwasan_increment_frame_tag): New declaration.
(hwasan_truncate_to_tag_size): New declaration.
(hwasan_finish_file): New declaration.
(hwasan_sanitize_p): New declaration.
(hwasan_sanitize_stack_p): New declaration.
(hwasan_sanitize_allocas_p): New declaration.
(HWASAN_TAG_SIZE): New macro.
(HWASAN_TAG_GRANULE_SIZE): New macro.
(HWASAN_STACK_BACKGROUND): New macro.
* builtin-types.def (BT_FN_VOID_PTR_UINT8_PTRMODE): New.
* builtins.def (DEF_SANITIZER_BUILTIN): Enable for HWASAN.
* cfgexpand.c (align_local_variable): When using hwasan ensure
alignment to tag granule.
(align_frame_offset): New.
(expand_one_stack_var_at): For hwasan use tag offset.
(expand_stack_vars): Record stack objects for hwasan.
(expand_one_stack_var_1): Record stack objects for hwasan.
(init_vars_expansion): Initialise hwasan state.
(expand_used_vars): Emit hwasan prologue and generate hwasan epilogue.
(pass_expand::execute): Emit hwasan base initialization if needed.
* doc/tm.texi (TARGET_MEMTAG_TAG_SIZE,TARGET_MEMTAG_GRANULE_SIZE,
TARGET_MEMTAG_INSERT_RANDOM_TAG,TARGET_MEMTAG_ADD_TAG,
TARGET_MEMTAG_SET_TAG,TARGET_MEMTAG_EXTRACT_TAG,
TARGET_MEMTAG_UNTAGGED_POINTER): Document new hooks.
* doc/tm.texi.in (TARGET_MEMTAG_TAG_SIZE,TARGET_MEMTAG_GRANULE_SIZE,
TARGET_MEMTAG_INSERT_RANDOM_TAG,TARGET_MEMTAG_ADD_TAG,
TARGET_MEMTAG_SET_TAG,TARGET_MEMTAG_EXTRACT_TAG,
TARGET_MEMTAG_UNTAGGED_POINTER): Document new hooks.
* explow.c (get_dynamic_stack_base): Take new `base` argument.
* explow.h (get_dynamic_stack_base): Take new `base` argument.
* sanitizer.def (BUILT_IN_HWASAN_INIT): New.
(BUILT_IN_HWASAN_TAG_MEM): New.
* target.def (target_memtag_tag_size,target_memtag_granule_size,
target_memtag_insert_random_tag,target_memtag_add_tag,
target_memtag_set_tag,target_memtag_extract_tag,
target_memtag_untagged_pointer): New hooks.
* targhooks.c (HWASAN_SHIFT): New.
(HWASAN_SHIFT_RTX): New.
(default_memtag_tag_size): New default hook.
(default_memtag_granule_size): New default hook.
(default_memtag_insert_random_tag): New default hook.
(default_memtag_add_tag): New default hook.
(default_memtag_set_tag): New default hook.
(default_memtag_extract_tag): New default hook.
(default_memtag_untagged_pointer): New default hook.
* targhooks.h (default_memtag_tag_size): New default hook.
(default_memtag_granule_size): New default hook.
(default_memtag_insert_random_tag): New default hook.
(default_memtag_add_tag): New default hook.
(default_memtag_set_tag): New default hook.
(default_memtag_extract_tag): New default hook.
(default_memtag_untagged_pointer): New default hook.
* toplev.c (compile_file): Call hwasan_finish_file when finished.
Matthew Malcomson [Wed, 25 Nov 2020 16:31:43 +0000 (16:31 +0000)]
libsanitizer: options: Add hwasan flags and argument parsing
These flags can't be used at the same time as any of the other
sanitizers.
We add an equivalent flag to -static-libasan in -static-libhwasan to
ensure static linking.
The -fsanitize=kernel-hwaddress option is for compiling targeting the
kernel. This flag has defaults to match the LLVM implementation and
sets some other behaviors to work in the kernel (e.g. accounting for
the fact that the stack pointer will have 0xff in the top byte and to not
call the userspace library initialisation routines).
The defaults are that we do not sanitize variables on the stack and
always recover from a detected bug.
Since we are introducing a few more conflicts between sanitizer flags we
refactor the checking for such conflicts to use a helper function which
makes checking for such conflicts more easy and consistent.
We introduce a backend hook `targetm.memtag.can_tag_addresses` that
indicates to the mid-end whether a target has a feature like AArch64 TBI
where the top byte of an address is ignored.
Without this feature hwasan sanitization is not done.
gcc/ChangeLog:
* common.opt (flag_sanitize_recover): Default for kernel
hwaddress.
(static-libhwasan): New cli option.
* config/aarch64/aarch64.c (aarch64_can_tag_addresses): New.
(TARGET_MEMTAG_CAN_TAG_ADDRESSES): New.
* config/gnu-user.h (LIBHWASAN_EARLY_SPEC): hwasan equivalent of
asan command line flags.
* cppbuiltin.c (define_builtin_macros_for_compilation_flags):
Add hwasan equivalent of __SANITIZE_ADDRESS__.
* doc/invoke.texi: Document hwasan command line flags.
* doc/tm.texi: Document new hook.
* doc/tm.texi.in: Document new hook.
* flag-types.h (enum sanitize_code): New sanitizer values.
* gcc.c (STATIC_LIBHWASAN_LIBS): New macro.
(LIBHWASAN_SPEC): New macro.
(LIBHWASAN_EARLY_SPEC): New macro.
(SANITIZER_EARLY_SPEC): Update to include hwasan.
(SANITIZER_SPEC): Update to include hwasan.
(sanitize_spec_function): Use hwasan options.
* opts.c (finish_options): Describe conflicts between address
sanitizers.
(find_sanitizer_argument): New.
(report_conflicting_sanitizer_options): New.
(sanitizer_opts): Introduce new sanitizer flags.
(common_handle_option): Add defaults for kernel sanitizer.
* params.opt (hwasan--instrument-stack): New
(hwasan-random-frame-tag): New
(hwasan-instrument-allocas): New
(hwasan-instrument-reads): New
(hwasan-instrument-writes): New
(hwasan-instrument-mem-intrinsics): New
* target.def (HOOK_PREFIX): Add new hook.
(can_tag_addresses): Add new hook under memtag prefix.
* targhooks.c (default_memtag_can_tag_addresses): New.
* targhooks.h (default_memtag_can_tag_addresses): New decl.
* toplev.c (process_options): Ensure hwasan only on
architectures that advertise the possibility.
Matthew Malcomson [Wed, 25 Nov 2020 16:31:41 +0000 (16:31 +0000)]
libsanitizer: Add option to bootstrap using HWASAN
This is an analogous option to --bootstrap-asan to configure. It allows
bootstrapping GCC using HWASAN.
For the same reasons as for ASAN we have to avoid using the HWASAN
sanitizer when compiling libiberty and the lto-plugin.
Also add a function to query whether -fsanitize=hwaddress has been
passed.
ChangeLog:
* configure: Regenerate.
* configure.ac: Add --bootstrap-hwasan option.
config/ChangeLog:
* bootstrap-hwasan.mk: New file.
gcc/ChangeLog:
* doc/install.texi: Document new option.
libiberty/ChangeLog:
* configure: Regenerate.
* configure.ac: Avoid using sanitizer.
lto-plugin/ChangeLog:
* Makefile.am: Avoid using sanitizer.
* Makefile.in: Regenerate.
Matthew Malcomson [Wed, 25 Nov 2020 16:31:39 +0000 (16:31 +0000)]
libsanitizer: Only build libhwasan when targeting AArch64
Though the library has limited support for x86, we don't have any
support for generating code targeting x86 so there is no point building
for that target.
Ensure we build for AArch64 but not for AArch64 ilp32.
libsanitizer/ChangeLog:
* Makefile.am: Condition Build hwasan directory.
* Makefile.in: Regenerate.
* configure: Regenerate.
* configure.ac: Set HWASAN_SUPPORTED based on target
architecture.
* configure.tgt: Likewise.
Matthew Malcomson [Wed, 25 Nov 2020 16:31:37 +0000 (16:31 +0000)]
libsanitizer: Tie the hwasan library into our build system
This patch tries to tie libhwasan into the GCC build system in the same way
that the other sanitizer runtime libraries are handled.
libsanitizer/ChangeLog:
* Makefile.am: Build libhwasan.
* Makefile.in: Build libhwasan.
* asan/Makefile.in: Build libhwasan.
* configure: Build libhwasan.
* configure.ac: Build libhwasan.
* hwasan/Makefile.am: New file.
* hwasan/Makefile.in: New file.
* hwasan/libtool-version: New file.
* interception/Makefile.in: Build libhwasan.
* libbacktrace/Makefile.in: Build libhwasan.
* libsanitizer.spec.in: Build libhwasan.
* lsan/Makefile.in: Build libhwasan.
* sanitizer_common/Makefile.in: Build libhwasan.
* tsan/Makefile.in: Build libhwasan.
* ubsan/Makefile.in: Build libhwasan.
Matthew Malcomson [Wed, 25 Nov 2020 16:31:35 +0000 (16:31 +0000)]
libsanitizer: Hwasan reporting check for dladdr failing
In `GetGlobalSizeFromDescriptor` we use `dladdr` to get info on the the
current address. `dladdr` returns 0 if it failed.
During testing on Linux this returned 0 to indicate failure, and
populated the `info` structure with a NULL pointer which was
dereferenced later.
This patch checks for `dladdr` returning 0, and in that case returns 0
from `GetGlobalSizeFromDescriptor` to indicate failure of identifying
the address.
This occurs when `GetModuleNameAndOffsetForPC` succeeds for some address
not in a dynamically loaded library. One example is when the found
"module" is '[stack]' having come from parsing /proc/self/maps.
Cherry-pick from
83ac18205ec69a00ac2be3b603bc3a61293fbe89.
Differential Revision: https://reviews.llvm.org/D91344
Martin Liska [Fri, 13 Nov 2020 16:06:48 +0000 (17:06 +0100)]
libsanitizer: add hwasan.
Introduce the libhwasan library from LLVM sources.
Jakub Jelinek [Wed, 25 Nov 2020 16:25:36 +0000 (17:25 +0100)]
testsuite: Rename test to avoid typo in its name [PR95862]
2020-11-25 Jakub Jelinek <jakub@redhat.com>
PR rtl-optimization/95862
* gcc.dg/builtin-artih-overflow-5.c: Renamed to ...
* gcc.dg/builtin-arith-overflow-5.c: ... this.
Richard Sandiford [Wed, 25 Nov 2020 16:14:20 +0000 (16:14 +0000)]
aarch64: Avoid false dependencies for SVE unary operations
For calls like:
z0 = svabs_s8_x (p0, z1)
we previously generated:
abs z0.b, p0/m, z1.b
However, this creates a false dependency on z0 (the merge input).
This can lead to strange results in some cases, e.g. serialising
the operation behind arbitrary earlier operations, or preventing
two iterations of a loop from being executed in parallel.
This patch therefore ties the input to the output, using a MOVPRFX
if necessary and possible. (The SVE2 unary long instructions do
not support MOVPRFX.)
When testing the patch, I hit a bug in the big-endian SVE move
optimisation in aarch64_maybe_expand_sve_subreg_move. I don't
have an indepenedent testcase for it, so I didn't split it out
into a separate patch.
gcc/
* config/aarch64/aarch64.c (aarch64_maybe_expand_sve_subreg_move):
Do not optimize LRA subregs.
* config/aarch64/aarch64-sve.md
(@aarch64_pred_<SVE_INT_UNARY:optab><mode>): Tie the input to the
output.
(@aarch64_sve_revbhw_<SVE_ALL:mode><PRED_HSD:mode>): Likewise.
(*<ANY_EXTEND:optab><SVE_PARTIAL_I:mode><SVE_HSDI:mode>2): Likewise.
(@aarch64_pred_sxt<SVE_FULL_HSDI:mode><SVE_PARTIAL_I:mode>): Likewise.
(*cnot<mode>): Likewise.
(@aarch64_pred_<SVE_COND_FP_UNARY:optab><mode>): Likewise.
(@aarch64_sve_<optab>_nontrunc<SVE_FULL_F:mode><SVE_FULL_HSDI:mode>):
Likewise.
(@aarch64_sve_<optab>_trunc<VNx2DF_ONLY:mode><VNx4SI_ONLY:mode>):
Likewise.
(@aarch64_sve_<optab>_nonextend<SVE_FULL_HSDI:mode><SVE_FULL_F:mode>):
Likewise.
(@aarch64_sve_<optab>_extend<VNx4SI_ONLY:mode><VNx2DF_ONLY:mode>):
Likewise.
(@aarch64_sve_<optab>_trunc<SVE_FULL_SDF:mode><SVE_FULL_HSF:mode>):
Likewise.
(@aarch64_sve_<optab>_trunc<VNx4SF_ONLY:mode><VNx8BF_ONLY:mode>):
Likewise.
(@aarch64_sve_<optab>_nontrunc<SVE_FULL_HSF:mode><SVE_FULL_SDF:mode>):
Likewise.
* config/aarch64/aarch64-sve2.md
(@aarch64_pred_<SVE2_COND_FP_UNARY_LONG:sve_fp_op><mode>): Likewise.
(@aarch64_pred_<SVE2_COND_FP_UNARY_NARROWB:sve_fp_op><mode>): Likewise.
(@aarch64_pred_<SVE2_U32_UNARY:sve_int_op><mode>): Likewise.
(@aarch64_pred_<SVE2_COND_INT_UNARY_FP:sve_fp_op><mode>): Likewise.
gcc/testsuite/
* gcc.target/aarch64/sve/acle/asm/abs_f16.c (abs_f16_x_untied): Expect
a MOVPRFX instruction.
* gcc.target/aarch64/sve/acle/asm/abs_f32.c (abs_f32_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/abs_f64.c (abs_f64_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/abs_s16.c (abs_s16_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/abs_s32.c (abs_s32_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/abs_s64.c (abs_s64_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/abs_s8.c (abs_s8_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/cls_s16.c (cls_s16_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/cls_s32.c (cls_s32_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/cls_s64.c (cls_s64_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/cls_s8.c (cls_s8_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/clz_s16.c (clz_s16_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/clz_s32.c (clz_s32_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/clz_s64.c (clz_s64_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/clz_s8.c (clz_s8_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/clz_u16.c (clz_u16_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/clz_u32.c (clz_u32_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/clz_u64.c (clz_u64_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/clz_u8.c (clz_u8_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/cnot_s16.c (cnot_s16_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/cnot_s32.c (cnot_s32_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/cnot_s64.c (cnot_s64_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/cnot_s8.c (cnot_s8_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/cnot_u16.c (cnot_u16_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/cnot_u32.c (cnot_u32_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/cnot_u64.c (cnot_u64_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/cnot_u8.c (cnot_u8_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/cnt_bf16.c (cnt_bf16_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/cnt_f16.c (cnt_f16_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/cnt_f32.c (cnt_f32_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/cnt_f64.c (cnt_f64_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/cnt_s16.c (cnt_s16_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/cnt_s32.c (cnt_s32_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/cnt_s64.c (cnt_s64_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/cnt_s8.c (cnt_s8_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/cnt_u16.c (cnt_u16_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/cnt_u32.c (cnt_u32_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/cnt_u64.c (cnt_u64_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/cnt_u8.c (cnt_u8_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/cvt_bf16.c (cvt_bf16_f32_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/cvt_f16.c (cvt_f16_f32_x_untied)
(cvt_f16_f64_x_untied, cvt_f16_s16_x_untied, cvt_f16_s32_x_untied)
(cvt_f16_s64_x_untied, cvt_f16_u16_x_untied, cvt_f16_u32_x_untied)
(cvt_f16_u64_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/cvt_f32.c (cvt_f32_f16_x_untied)
(cvt_f32_f64_x_untied, cvt_f32_s16_x_untied, cvt_f32_s32_x_untied)
(cvt_f32_s64_x_untied, cvt_f32_u16_x_untied, cvt_f32_u32_x_untied)
(cvt_f32_u64_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/cvt_f64.c (cvt_f64_f16_x_untied)
(cvt_f64_f32_x_untied, cvt_f64_s16_x_untied, cvt_f64_s32_x_untied)
(cvt_f64_s64_x_untied, cvt_f64_u16_x_untied, cvt_f64_u32_x_untied)
(cvt_f64_u64_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/cvt_s16.c (cvt_s16_f16_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/cvt_s32.c (cvt_s32_f16_x_untied)
(cvt_s32_f32_x_untied, cvt_s32_s64_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/cvt_s64.c (cvt_s64_f16_x_untied)
(cvt_s64_f32_x_untied, cvt_s64_s64_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/cvt_u16.c (cvt_u16_f16_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/cvt_u32.c (cvt_u32_f16_x_untied)
(cvt_u32_f32_x_untied, cvt_u32_u64_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/cvt_u64.c (cvt_u64_f16_x_untied)
(cvt_u64_f32_x_untied, cvt_u64_u64_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/extb_s16.c (extb_s16_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/extb_s32.c (extb_s32_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/extb_s64.c (extb_s64_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/exth_s32.c (exth_s32_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/exth_s64.c (exth_s64_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/extw_s64.c (extw_s64_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/neg_f16.c (neg_f16_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/neg_f32.c (neg_f32_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/neg_f64.c (neg_f64_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/neg_s16.c (neg_s16_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/neg_s32.c (neg_s32_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/neg_s64.c (neg_s64_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/neg_s8.c (neg_s8_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/not_s16.c (not_s16_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/not_s32.c (not_s32_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/not_s64.c (not_s64_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/not_s8.c (not_s8_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/not_u16.c (not_u16_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/not_u32.c (not_u32_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/not_u64.c (not_u64_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/not_u8.c (not_u8_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/rbit_s16.c (rbit_s16_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/rbit_s32.c (rbit_s32_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/rbit_s64.c (rbit_s64_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/rbit_s8.c (rbit_s8_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/rbit_u16.c (rbit_u16_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/rbit_u32.c (rbit_u32_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/rbit_u64.c (rbit_u64_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/rbit_u8.c (rbit_u8_x_untied): Ditto.
* gcc.target/aarch64/sve/acle/asm/recpx_f16.c (recpx_f16_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/recpx_f32.c (recpx_f32_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/recpx_f64.c (recpx_f64_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/revb_s16.c (revb_s16_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/revb_s32.c (revb_s32_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/revb_s64.c (revb_s64_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/revb_u16.c (revb_u16_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/revb_u32.c (revb_u32_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/revb_u64.c (revb_u64_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/revh_s32.c (revh_s32_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/revh_s64.c (revh_s64_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/revh_u32.c (revh_u32_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/revh_u64.c (revh_u64_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/revw_s64.c (revw_s64_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/revw_u64.c (revw_u64_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/rinta_f16.c (rinta_f16_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/rinta_f32.c (rinta_f32_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/rinta_f64.c (rinta_f64_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/rinti_f16.c (rinti_f16_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/rinti_f32.c (rinti_f32_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/rinti_f64.c (rinti_f64_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/rintm_f16.c (rintm_f16_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/rintm_f32.c (rintm_f32_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/rintm_f64.c (rintm_f64_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/rintn_f16.c (rintn_f16_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/rintn_f32.c (rintn_f32_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/rintn_f64.c (rintn_f64_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/rintp_f16.c (rintp_f16_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/rintp_f32.c (rintp_f32_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/rintp_f64.c (rintp_f64_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/rintx_f16.c (rintx_f16_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/rintx_f32.c (rintx_f32_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/rintx_f64.c (rintx_f64_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/rintz_f16.c (rintz_f16_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/rintz_f32.c (rintz_f32_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/rintz_f64.c (rintz_f64_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/sqrt_f16.c (sqrt_f16_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/sqrt_f32.c (sqrt_f32_x_untied):
Ditto.
* gcc.target/aarch64/sve/acle/asm/sqrt_f64.c (sqrt_f64_x_untied):
Ditto.
* gcc.target/aarch64/sve2/acle/asm/cvtx_f32.c (cvtx_f32_f64_x_untied):
Ditto.
* gcc.target/aarch64/sve2/acle/asm/logb_f16.c (logb_f16_x_untied):
Ditto.
* gcc.target/aarch64/sve2/acle/asm/logb_f32.c (logb_f32_x_untied):
Ditto.
* gcc.target/aarch64/sve2/acle/asm/logb_f64.c (logb_f64_x_untied):
Ditto.
* gcc.target/aarch64/sve2/acle/asm/qabs_s16.c (qabs_s16_x_untied):
Ditto.
* gcc.target/aarch64/sve2/acle/asm/qabs_s32.c (qabs_s32_x_untied):
Ditto.
* gcc.target/aarch64/sve2/acle/asm/qabs_s64.c (qabs_s64_x_untied):
Ditto.
* gcc.target/aarch64/sve2/acle/asm/qabs_s8.c (qabs_s8_x_untied):
Ditto.
* gcc.target/aarch64/sve2/acle/asm/qneg_s16.c (qneg_s16_x_untied):
Ditto.
* gcc.target/aarch64/sve2/acle/asm/qneg_s32.c (qneg_s32_x_untied):
Ditto.
* gcc.target/aarch64/sve2/acle/asm/qneg_s64.c (qneg_s64_x_untied):
Ditto.
* gcc.target/aarch64/sve2/acle/asm/qneg_s8.c (qneg_s8_x_untied):
Ditto.
* gcc.target/aarch64/sve2/acle/asm/recpe_u32.c (recpe_u32_x_untied):
Ditto.
* gcc.target/aarch64/sve2/acle/asm/rsqrte_u32.c (rsqrte_u32_x_untied):
Ditto.
* gcc.target/aarch64/sve2/acle/asm/cvtlt_f32.c
(cvtlt_f32_f16_x_untied): Expect a MOV instruction.
* gcc.target/aarch64/sve2/acle/asm/cvtlt_f64.c
(cvtlt_f64_f32_x_untied): Likewise.
Ian Lance Taylor [Tue, 24 Nov 2020 01:48:28 +0000 (17:48 -0800)]
compiler: avoid silent truncation for string(1 << 32)
In the conversion of a constant integer to a string type, the value of
the constant integer was being silently truncated from unsigned long
to unsigned int, producing the wrong string value. Add an explicit
overflow check to avoid this problem.
For golang/go#42790
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/272611
Jakub Jelinek [Wed, 25 Nov 2020 14:42:38 +0000 (15:42 +0100)]
middle-end: __builtin_mul_overflow expansion improvements [PR95862]
The following patch adds some improvements for __builtin_mul_overflow
expansion.
One optimization is for the u1 * u2 -> sr case, as documented we normally
do:
u1 * u2 -> sr
res = (S) (u1 * u2)
ovf = res < 0 || main_ovf (true)
where main_ovf (true) stands for jump on unsigned multiplication overflow.
If we know that the most significant bits of both operands are clear (such
as when they are zero extended from something smaller), we can
emit better coe by handling it like s1 * s2 -> sr, i.e. just jump on
overflow after signed multiplication.
Another two cases are s1 * s2 -> ur or s1 * u2 -> ur, if we know the minimum
precision needed to encode all values of both arguments summed together
is smaller or equal to destination precision (such as when the two arguments
are sign (or zero) extended from half precision types, we know the overflows
happen only iff one argument is negative and the other argument is positive
(not zero), because even if both have maximum possible values, the maximum
is still representable (e.g. for char * char -> unsigned short
0x7f * 0x7f = 0x3f01 and for char * unsigned char -> unsigned short
0x7f * 0xffU = 0x7e81) and as the result is unsigned, all negative results
do overflow, but are also representable if we consider the result signed
- all of them have the MSB set. So, it is more efficient to just
do the normal multiplication in that case and compare the result considered
as signed value against 0, if it is smaller, overflow happened.
And the get_min_precision change is to improve the char to short handling,
we have there in the IL
_2 = (int) arg_1(D);
promotion from C promotions from char or unsigned char arg, and the caller
adds a NOP_EXPR cast to short or unsigned short. get_min_precision punts
on the narrowing cast though, it handled only widening casts, but we can
handle narrowing casts fine too, by recursing on the narrowing cast operands
and using it only if it has in the end smaller minimal precision, which
would duplicate the sign bits (or zero bits) to both the bits above the
narrowing conversion and also at least one below that.
2020-10-25 Jakub Jelinek <jakub@redhat.com>
PR rtl-optimization/95862
* internal-fn.c (get_min_precision): For narrowing conversion, recurse
on the operand and if the operand precision is smaller than the
current one, return that smaller precision.
(expand_mul_overflow): For s1 * u2 -> ur and s1 * s2 -> ur cases
if the sum of minimum precisions of both operands is smaller or equal
to the result precision, just perform normal multiplication and
set overflow to the sign bit of the multiplication result. For
u1 * u2 -> sr if both arguments have the MSB known zero, use
normal s1 * s2 -> sr expansion.
* gcc.dg/builtin-artih-overflow-5.c: New test.
Jan Hubicka [Wed, 25 Nov 2020 14:05:41 +0000 (15:05 +0100)]
Free more of CFG
* cfg.c (free_block): New function.
(clear_edges): Rename to ....
(free_cfg): ... this one; also free BBs and vectors.
(expunge_block): Update comment.
* cfg.h (clear_edges): Rename to ...
(free_cfg): ... this one.
* cgraph.c (release_function_body): Use free_cfg.
Richard Biener [Wed, 25 Nov 2020 11:31:54 +0000 (12:31 +0100)]
middle-end/97579 - lower VECTOR_BOOLEAN_TYPE_P VEC_COND_EXPRs
This makes sure to lower VECTOR_BOOLEAN_TYPE_P typed non-vector
mode VEC_COND_EXPRs so we don't try to use vcond to expand those.
That's required for x86 and gcn integer mode boolean vectors.
2020-11-25 Richard Biener <rguenther@suse.de>
PR middle-end/97579
* gimple-isel.cc (gimple_expand_vec_cond_expr): Lower
VECTOR_BOOLEAN_TYPE_P, non-vector mode VEC_COND_EXPRs.
* gcc.dg/pr97579.c: New testcase.
Andrew Stubbs [Wed, 11 Nov 2020 12:50:34 +0000 (12:50 +0000)]
Fix atomic_capture-1.f90 testcase
The testcase had invalid assumptions about which loop iterations would run
first and last.
libgomp/ChangeLog
* testsuite/libgomp.oacc-fortran/atomic_capture-1.f90 (main): Adjust
expected results.
Ed Schonberg [Sun, 18 Oct 2020 16:17:51 +0000 (12:17 -0400)]
[Ada] Further optimization with uninitialized aggregates
gcc/ada/
* freeze.adb (Is_Uninitialized_Aggregate): Move...
* exp_util.adb (Is_Uninitialized_Aggregate): ... here.
(Expand_Subtype_From_Expr): If the expression is an
uninitialized aggregate, capture subtype for declared object and
remove expression to suppress further superfluous expansion.
Ed Schonberg [Fri, 16 Oct 2020 18:25:03 +0000 (14:25 -0400)]
[Ada] Spurious error on instance with predicated actual
gcc/ada/
* sem_eval.adb (Subtypes_Statically_Compatible): Scalar types
with compatible static bounds are statically compatible if
predicates are compatible, even if they are not static subtypes.
Same for private types without discriminants.
Eric Botcazou [Fri, 16 Oct 2020 17:53:40 +0000 (19:53 +0200)]
[Ada] Fix couple of minor issues with local exception propagation
gcc/ada/
* exp_ch11.adb (Expand_N_Raise_Statement): Use Is_Entity_Name
consistently in tests on the name of the statement.
* exp_prag.adb (Expand_Pragma_Check): In the local propagation
case, wrap the raise statement in a block statement.
Piotr Trojanek [Thu, 15 Oct 2020 08:45:28 +0000 (10:45 +0200)]
[Ada] Remove shadowing by a nested subprogram parameter
gcc/ada/
* exp_ch8.adb (Expand_N_Exception_Renaming_Declaration): Move
"Nam" constant after the body of a nested subprogram; change "T"
from variable to constant.
Piotr Trojanek [Wed, 14 Oct 2020 21:43:21 +0000 (23:43 +0200)]
[Ada] Merge duplicated processing for gnatmake -u and -U switches
gcc/ada/
* make.adb (Scan_Make_Arg): Merge ELSIF branches for -u and -U.
Piotr Trojanek [Wed, 14 Oct 2020 13:49:17 +0000 (15:49 +0200)]
[Ada] Document attribute Has_Tagged_Values in GNAT RM
gcc/ada/
* doc/gnat_rm/implementation_defined_attributes.rst
(Has_Tagged_Values): Document based on the existing description
of Has_Access_Type and the comment for Has_Tagged_Component,
which is where frontend evaluates this attribute.
* gnat_rm.texi: Regenerate.
* sem_attr.adb (Analyze_Attribute): Merge processing of
Has_Access_Type and Has_Tagged_Component attributes.
* sem_util.adb (Has_Access_Type): Fix casing in comment.
* sem_util.ads (Has_Tagged_Component): Remove wrong (or
outdated) comment about the use of this routine to implement the
equality operator.
Piotr Trojanek [Wed, 14 Oct 2020 13:56:34 +0000 (15:56 +0200)]
[Ada] Minor whitespace fix in expansion of attribute Size
gcc/ada/
* exp_attr.adb (Expand_Size_Attribute): Remove whitespace;
simplify with a membership test, which are now allowed in the
frontend code.
Piotr Trojanek [Wed, 14 Oct 2020 23:10:18 +0000 (01:10 +0200)]
[Ada] Use hardcoded names when converting aspects to pragmas
gcc/ada/
* sem_ch13.adb (Analyze_One_Aspect): Fix inconsistent calls to
Make_Aitem_Pragma.
Piotr Trojanek [Wed, 14 Oct 2020 22:55:16 +0000 (00:55 +0200)]
[Ada] Reuse Is_Named_Number where possible
gcc/ada/
* sem_ch13.adb (Check_Expr_Constants): Simplify with
Is_Named_Number.
* sem_prag.adb (Process_Convention): Likewise.
Piotr Trojanek [Wed, 14 Oct 2020 22:39:29 +0000 (00:39 +0200)]
[Ada] Simplify aspect processing with membership tests
gcc/ada/
* sem_ch13.adb (Analyze_One_Aspect): Detect aspect identifiers
with membership tests.
(Check_Aspect_At_End_Of_Declarations): Likewise.
(Freeze_Entity_Checks): Likewise; a local constant is no longer
needed.
(Is_Operational_Item): Similar simplification for attribute
identifiers.
(Is_Type_Related_Rep_Item): Likewise.
(Resolve_Iterable_Operation): Detect names with a membership
test.
(Validate_Independence): Replace repeated Ekind with a
membership test.
Piotr Trojanek [Wed, 14 Oct 2020 22:13:51 +0000 (00:13 +0200)]
[Ada] Fix copy-paste mistake in diagnostics for aspect Effective_Writes
gcc/ada/
* sem_ch13.adb (Analyze_One_Aspect): Replace duplicate of
Effective_Reads.
Piotr Trojanek [Wed, 14 Oct 2020 21:30:49 +0000 (23:30 +0200)]
[Ada] Simplify Ekind tests with wrappers and membership tests
gcc/ada/
* einfo.adb: Use composite wrappers (e.g.
Is_Subprogram_Or_Entry) and membership tests where it appears to
improve clarity.
Piotr Trojanek [Wed, 14 Oct 2020 20:49:08 +0000 (22:49 +0200)]
[Ada] Simplify Is_Standard_xxx_Type routines with membership tests
gcc/ada/
* einfo.adb (Is_Standard_Character_Type,
Is_Standard_String_Type): Simplify.
(Last_Formal): Use procedural variant of Next_Formal.
Piotr Trojanek [Wed, 14 Oct 2020 20:45:15 +0000 (22:45 +0200)]
[Ada] Consistently use explicit Entity_Id type instead of alias
gcc/ada/
* einfo.adb: Replace "E" with Entity_Id in local object
declarations.
Steve Baird [Tue, 13 Oct 2020 19:23:11 +0000 (12:23 -0700)]
[Ada] Don't constant-fold renamed qualified expressions
gcc/ada/
* exp_ch2.adb (Expand_Entity_Reference): A new local predicate
Is_Object_Renaming_Name indicates whether a given expression
occurs (after looking through qualified expressions and type
conversions) as the name of an object renaming declaration. If
Current_Value is available but this new predicate is True, then
ignore the availability of Current_Value.
Piotr Trojanek [Wed, 14 Oct 2020 14:22:16 +0000 (16:22 +0200)]
[Ada] Remove dead and duplicated diagnostics for generic access types
gcc/ada/
* sem_ch12.adb (Instantiate_Type): Remove extra whitespace.
(Validate_Access_Type_Instance): Remove dead (and duplicated)
code.
Gary Dismukes [Wed, 14 Oct 2020 18:09:06 +0000 (14:09 -0400)]
[Ada] Remove hyphens in two cases of "side-effect" used as a noun
gcc/ada/
* exp_util.adb (Possible_Side_Effect_In_SPARK): Replace hyphen
with a space in "side-effect" (two instances).
Justin Squirek [Mon, 12 Oct 2020 16:06:08 +0000 (12:06 -0400)]
[Ada] Crash on right shift operator for signed integers
gcc/ada/
* doc/gnat_rm/intrinsic_subprograms.rst (Shifts and Rotates):
Document behavior on negative numbers
* gnat_rm.texi: Regenerate.
* sem_eval.adb (Fold_Shift): Set modulus to be based on the RM
size for non-modular integer types.
Olivier Hainque [Fri, 9 Oct 2020 12:33:24 +0000 (12:33 +0000)]
[Ada] Reinstate utime based code for vx6 in __gnat_copy_attribs
gcc/ada/
* adaint.c (__gnat_copy_attribs): Reinstate code based on utime
for timestamp processing on VxWorks 6.
Yannick Moy [Fri, 9 Oct 2020 13:59:24 +0000 (15:59 +0200)]
[Ada] Minimize side-effect removal in GNATprove mode
gcc/ada/
* exp_util.adb (Remove_Side_Effects): Only remove side-effects
in GNATprove mode when this is useful.
* sem_res.adb (Set_Slice_Subtype): Make sure in GNATprove mode
to define the Itype when needed, so that run-time errors can be
analyzed.
* sem_util.adb (Enclosing_Declaration): Correctly take into
account renaming declarations.
Eric Botcazou [Tue, 13 Oct 2020 07:15:23 +0000 (09:15 +0200)]
[Ada] Adjust support for 128-bit integer types in System.Random_Numbers
gcc/ada/
* libgnat/s-rannum.adb (Random_Discrete): Specifically deal with
the case where the size of the base type is larger than 64 bits.
Yannick Moy [Mon, 12 Oct 2020 15:32:45 +0000 (17:32 +0200)]
[Ada] Fix internal compilation error on circular type in SPARK code
gcc/ada/
* sem_ch3.adb (Access_Type_Declaration): Set Etype before
checking for volatility compatibility.
Eric Botcazou [Mon, 12 Oct 2020 19:12:56 +0000 (21:12 +0200)]
[Ada] Add support for 128-bit integer types to GNAT.Random_Numbers
gcc/ada/
* libgnat/g-rannum.ads (Random): New functions returning 128-bit.
* libgnat/g-rannum.adb (Random): Implement them and alphabetize.
(To_Signed): New unchecked conversion function for 128-bit.
Arnaud Charlet [Mon, 12 Oct 2020 07:50:53 +0000 (03:50 -0400)]
[Ada] Allow debugging finalization-related expanded code
gcc/ada/
* exp_ch7.adb (Build_Finalization_Master, Build_Finalizer,
Build_Object_Declarations, Make_Deep_Array_Body,
Wrap_Transient_Expression): Call Set_Debug_Info_Needed on
temporaries when Debug_Generated_Code is True.
Liaiss Merzougue [Thu, 8 Oct 2020 15:26:11 +0000 (15:26 +0000)]
[Ada] Unrecursify Set_Digit/Set_Image_Unsigned procedure
gcc/ada/
* libgnat/s-imagei.adb
(Set_Digits): Rewrite the procedure to remove recursion.
(Image_Integer, Set_Image_Integer): Update assertions and remove
redundant ones.
* libgnat/s-imageu.adb
(Set_Image_Unsigned): Rewrite the procedure to remove recursion.
Piotr Trojanek [Fri, 9 Oct 2020 13:49:29 +0000 (15:49 +0200)]
[Ada] Remove repeated calls to Attribute_Name
gcc/ada/
* exp_util.adb (Attribute_Constrained_Static_Value): Fix body
box.
* sem_attr.adb (Eval_Attribute): Replace repeated calls to
Attribute_Name with a captured value of the Attribute_Id; also,
remove extra parens around Is_Generic_Type.
Ghjuvan Lacambre [Fri, 9 Oct 2020 14:36:45 +0000 (16:36 +0200)]
[Ada] Fix crash on invalid `pragma Profile`
gcc/ada/
* sem_prag.adb (Analyze_Pragma): Emit error on wrong argument
nkind.
Piotr Trojanek [Fri, 9 Oct 2020 12:03:38 +0000 (14:03 +0200)]
[Ada] Reuse Is_Named_Number where possible
gcc/ada/
* sem_attr.adb, sem_prag.adb: Use Is_Named_Number.
Piotr Trojanek [Fri, 9 Oct 2020 11:59:04 +0000 (13:59 +0200)]
[Ada] Fix style and typos in code for expanding attribute references
gcc/ada/
* exp_attr.adb, exp_util.adb: Fix style and typos in comments.
Piotr Trojanek [Fri, 9 Oct 2020 07:59:22 +0000 (09:59 +0200)]
[Ada] Minor refine type of a counter variable
gcc/ada/
* exp_attr.adb (Expand_N_Attribute_Reference): A variable that
is only incremented in the code has now type Nat; conversion is
now unnecessary.
Stam Markianos-Wright [Wed, 25 Nov 2020 12:50:06 +0000 (12:50 +0000)]
arm: Add test that was missing from old commit [PR91816]
A while back I submitted GCC10 commit:
44f77a6dea2f312ee1743f3dde465c1b8453ee13
for PR91816.
Turns out I was an idiot and forgot to include the test in the actual git commit.
Tested that the test still passes on a cross arm-none-eabi and also in a
Cortex A-15 bootstrap with no regressions.
gcc/testsuite/ChangeLog:
PR target/91816
* gcc.target/arm/pr91816.c: New test.
Jonathan Wakely [Wed, 25 Nov 2020 12:16:07 +0000 (12:16 +0000)]
libstdc++: Fix silly typos [PR 97936]
libstdc++-v3/ChangeLog:
PR libstdc++/97936
* include/bits/atomic_wait.h (__platform_wait): Check errno,
not just the value of EAGAIN.
(__waiters::__waiters()): Fix name of data member.
Jonathan Wakely [Wed, 25 Nov 2020 10:26:09 +0000 (10:26 +0000)]
libstdc++: Fix handling of futex wake [PR 97936]
The __platform_wait function is supposed to wait until *addr != old.
The futex syscall checks the initial value and returns EAGAIN if *addr
!= old is already true, which should cause __platform_wait to return.
Instead it loops and keeps doing a futex wait, which keeps returning
EAGAIN.
libstdc++-v3/ChangeLog:
PR libstdc++/97936
* include/bits/atomic_wait.h (__platform_wait): Return if futex
sets EAGAIN.
* testsuite/30_threads/latch/3.cc: Re-enable test.
* testsuite/30_threads/semaphore/try_acquire_until.cc: Likewise.
Jakub Jelinek [Wed, 25 Nov 2020 09:37:58 +0000 (10:37 +0100)]
middle-end: Reject flexible array members in __builtin_clear_padding [PR97943]
As mentioned in the PR, we currently ICE on flexible array members in
structs and unions during __builtin_clear_padding processing.
Jason said in the PR he'd prefer an error in these cases over forcefully
handling it as [0] arrays (everything is padding then) or consider the
arrays to have as many whole elements as would fit into the tail padding.
So, this patch implements that.
2020-11-25 Jakub Jelinek <jakub@redhat.com>
PR middle-end/97943
* gimple-fold.c (clear_padding_union, clear_padding_type): Error on and
ignore flexible array member fields. Ignore fields with
error_mark_node type.
* c-c++-common/builtin-clear-padding-2.c: New test.
* c-c++-common/builtin-clear-padding-3.c: New test.
* g++.dg/ext/builtin-clear-padding-1.C: New test.
* gcc.dg/builtin-clear-padding-2.c: New test.
GCC Administrator [Wed, 25 Nov 2020 09:34:01 +0000 (09:34 +0000)]
Daily bump.
Martin Liska [Wed, 25 Nov 2020 06:56:57 +0000 (07:56 +0100)]
changelog: fix parsing of a revert commit
contrib/ChangeLog:
* gcc-changelog/git_commit.py: Use revert_regex instead
of string prefix. Convert sets to literals.
Jonathan Wakely [Tue, 24 Nov 2020 23:22:01 +0000 (23:22 +0000)]
libstdc++: Disable failing tests [PR 97936]
These tests are unstable and causing failures due to timeouts. Disable
them until the cause can be found, so that testing doesn't have to wait
for them to timeout.
libstdc++-v3/ChangeLog:
PR libstdc++/97936
PR libstdc++/97944
* testsuite/29_atomics/atomic_integral/wait_notify.cc: Disable.
Do not require pthreads, but add -pthread when appropriate.
* testsuite/30_threads/jthread/95989.cc: Likewise.
* testsuite/30_threads/latch/3.cc: Likewise.
* testsuite/30_threads/semaphore/try_acquire_until.cc: Likewise.
Martin Sebor [Tue, 24 Nov 2020 22:23:57 +0000 (15:23 -0700)]
PR c/97955 - ICE in build_array_type_1 on invalid redeclaration of function with VLA parameter
gcc/c-family/ChangeLog:
* c-warn.c (warn_parm_array_mismatch): Avoid invalid redeclarations.
gcc/testsuite/ChangeLog:
* gcc.dg/pr97955.c: New test.
Martin Sebor [Tue, 24 Nov 2020 20:28:55 +0000 (13:28 -0700)]
Add a note.
gcc/testsuite/ChangeLog:
* gcc.dg/Wstringop-overflow-47.c: Add a note.
Jason Merrill [Fri, 20 Nov 2020 21:50:20 +0000 (16:50 -0500)]
c++: ICE with int{} in template. [PR97899]
split_nonconstant_init_1 was confused by a CONSTRUCTOR with non-aggregate
type, which (with COMPOUND_LITERAL_P set) we use in a template to represent
a braced functional cast. It seems to me that there's no good reason to do
split_nonconstant_init at all in a template.
gcc/cp/ChangeLog:
PR c++/97899
* typeck2.c (store_init_value): Don't split_nonconstant_init in a
template.
gcc/testsuite/ChangeLog:
PR c++/97899
* g++.dg/cpp0x/initlist-template3.C: New test.
Ulrich Weigand [Tue, 24 Nov 2020 18:30:01 +0000 (19:30 +0100)]
Revert: "Fix -ffast-math flags handling inconsistencies"
This reverts commit
c4fa3728ab4f78984a549894e0e8c4d6a253e540,
which caused a regression in the default for flag_excess_precision.
2020-11-24 Ulrich Weigand <uweigand@de.ibm.com>
gcc/
PR tree-optimization/97970
* doc/invoke.texi (-ffast-math): Revert last change.
* opts.c: Revert last change.
Martin Sebor [Tue, 24 Nov 2020 16:57:40 +0000 (09:57 -0700)]
Adjust regex pattern to expect an additional attribute and function return type
gcc/testsuite/ChangeLog:
* gfortran.dg/gomp/declare-target-4.f90: Adjust pattern to expect
an additional attribute and function return type.
Vladimir N. Makarov [Tue, 24 Nov 2020 16:25:16 +0000 (11:25 -0500)]
[PR97933] LRA: find correctly last empty dest block.
gcc/
2020-11-24 Vladimir Makarov <vmakarov@redhat.com>
PR bootstrap/97933
* lra.c (lra_process_new_insns): Stop on the first real insn after
head of e->dest.
Richard Earnshaw [Tue, 24 Nov 2020 16:21:17 +0000 (16:21 +0000)]
arm: correctly handle negating INT_MIN in arm_split_atomic_op [PR97534]
arm_split_atomic_op handles subtracting a constant by converting it
into addition of the negated constant. But if the type of the operand
is int and the constant is -1 we currently end up generating invalid
RTL which can lead to an abort later on.
The problem is that in a HOST_WIDE_INT, INT_MIN is represented as
0xffffffff80000000 and the negation of this is 0x0000000080000000, but
that's not a valid constant for use in SImode operations.
The fix is straight-forward which is to use gen_int_mode rather than
simply GEN_INT. This knows how to correctly sign-extend the negated
constant when this is needed.
gcc/
PR target/97534
* config/arm/arm.c (arm_split_atomic_op): Use gen_int_mode when
negating a const_int.
gcc/testsuite
* gcc.dg/pr97534.c: New test.
Nathan Sidwell [Tue, 24 Nov 2020 16:23:55 +0000 (08:23 -0800)]
preprocessor: Add deferred macros
Deferred macros are needed for C++ modules. Header units may export
macro definitions and undefinitions. These are resolved lazily at the
point of (potential) use. (The language specifies that, it's not just
a useful optimization.) Thus, identifier nodes grow a 'deferred'
field, which fortunately doesn't expand the structure on 64-bit
systems as there was padding there. This is non-zero on NT_MACRO
nodes, if the macro is deferred. When such an identifier is lexed, it
is resolved via a callback that I added recently. That will either
provide the macro definition, or discover it there was an overriding
undef. Either way the identifier is no longer a deferred macro.
Notice it is now possible for NT_MACRO nodes to have a NULL macro
expansion.
libcpp/
* include/cpplib.h (struct cpp_hashnode): Add deferred field.
(cpp_set_deferred_macro): Define.
(cpp_get_deferred_macro): Declare.
(cpp_macro_definition): Reformat, add overload.
(cpp_macro_definition_location): Deal with deferred macro.
(cpp_alloc_token_string, cpp_compare_macro): Declare.
* internal.h (_cpp_notify_macro_use): Return bool
(_cpp_maybe_notify_macro_use): Likewise.
* directives.c (do_undef): Check macro is not undef before
warning.
(do_ifdef, do_ifndef): Deal with deferred macro.
* expr.c (parse_defined): Likewise.
* lex.c (cpp_allocate_token_string): Break out of ...
(create_literal): ... here. Call it.
(cpp_maybe_module_directive): Deal with deferred macro.
* macro.c (cpp_get_token_1): Deal with deferred macro.
(warn_of_redefinition): Deal with deferred macro.
(compare_macros): Rename to ...
(cpp_compare_macro): ... here. Make extern.
(cpp_get_deferred_macro): New.
(_cpp_notify_macro_use): Deal with deferred macro, return bool
indicating definedness.
(cpp_macro_definition): Deal with deferred macro.
Richard Sandiford [Tue, 24 Nov 2020 15:01:45 +0000 (15:01 +0000)]
aarch64: Fix aapcs64 testsuite failures
Various aapcs64 tests were failing at -O1 and above because
the assignments to testfunc_ptr were being deleted as dead.
That in turn happened because FUNC_VAL_CHECK hid the tail call
to myfunc using an LR asm trick:
asm volatile ("mov %0, x30" : "=r" (saved_return_address));
asm volatile ("mov x30, %0" : : "r" ((unsigned long long) myfunc));
and so the compiler couldn't see any calls that might read
testfunc_ptr.
That in itself could be fixed by adding a memory clobber to the
second asm above, forcing the compiler to keep both the testfunc_ptr
and the saved_return_address assignments. But since this is an ABI
test, it seems better to make sure that we don't do any IPA at all.
The fact that doing IPA caused a problem was kind-of helpful and
so it might be better to avoid making the test “work” in the
presence of IPA.
The patch therefore just replaced “noinline” with “noipa”.
gcc/testsuite/
* gcc.target/aarch64/aapcs64/abitest.h (FUNC_VAL_CHECK): Use
noipa rather than noinline.
* gcc.target/aarch64/aapcs64/abitest-2.h (FUNC_VAL_CHECK): Likewise.
Jonathan Wakely [Tue, 24 Nov 2020 13:11:13 +0000 (13:11 +0000)]
libstdc++: Run all tests in file
libstdc++-v3/ChangeLog:
* testsuite/30_threads/jthread/95989.cc: Run all three test
functions, not just the first one twice.
Jonathan Wakely [Tue, 24 Nov 2020 12:48:31 +0000 (12:48 +0000)]
libstdc++: Throw instead of segfaulting in std::thread constructor [PR 67791]
This turns a mysterious segfault into an exception with a more useful
message. If the exception isn't caught, the user sees this instead of
just a segfault:
terminate called after throwing an instance of 'std::system_error'
what(): Enable multithreading to use std::thread: Operation not permitted
Aborted (core dumped)
libstdc++-v3/ChangeLog:
PR libstdc++/67791
* src/c++11/thread.cc (thread::_M_start_thread(_State_ptr, void (*)())):
Check that gthreads is available before calling __gthread_create.
Jonathan Wakely [Tue, 24 Nov 2020 12:29:30 +0000 (12:29 +0000)]
libstdc++: Use __libc_single_threaded for locale initialization
Most initialization of locales and facets happens before main() during
startup, when the program is likely to only have one thread. By using
the new __gnu_cxx::__is_single_threaded() function instead of checking
__gthread_active_p() we can avoid using pthread_once or atomics for the
common case.
That said, I'm not sure why we don't just use a local static variable
instead, as __cxa_guard_acquire() already optimizes for the
single-threaded case:
static const bool init = (_S_initialize_once(), true);
I'll revisit that for GCC 12.
libstdc++-v3/ChangeLog:
* src/c++98/locale.cc (locale::facet::_S_get_c_locale())
(locale::id::_M_id() const): Use __is_single_threaded.
* src/c++98/locale_init.cc (locale::_S_initialize()):
Likewise.
Andrew Stubbs [Mon, 23 Nov 2020 17:18:27 +0000 (17:18 +0000)]
Tweak plugin-gcn.c defines
Ensure the code will continue to compile when elf.h gets these definitions.
libgomp/ChangeLog:
* plugin/plugin-gcn.c: Don't redefine relocations if elf.h has them.
(reserved): Delete unused define.
Ilya Leoshkevich [Mon, 23 Nov 2020 23:22:52 +0000 (00:22 +0100)]
IBM Z: Restrict vec_cmp<m><n> on z13
Commit
5d9ade39b872 ("IBM Z: Fix PR97326: Enable fp compares in
vec_cmp") made it possible to create rtxes that describe signaling
comparisons on z13, which are not supported by the hardware. Restrict
this by using vcond_comparison_operator predicate.
gcc/ChangeLog:
2020-11-24 Ilya Leoshkevich <iii@linux.ibm.com>
* config/s390/vector.md: Use vcond_comparison_operator
predicate.
Ilya Leoshkevich [Mon, 23 Nov 2020 20:13:40 +0000 (21:13 +0100)]
IBM Z: Update autovec-*-quiet-uneq expectations
Commit
229752afe315 ("VEC_COND_EXPR optimizations") has improved code
generation: we no longer need "vx x,x,-1", which turned out to be
superfluous. Instead, we simply swap 0 and -1 arguments of the
preceding "vsel".
gcc/testsuite/ChangeLog:
2020-11-23 Ilya Leoshkevich <iii@linux.ibm.com>
* gcc.target/s390/zvector/autovec-double-quiet-uneq.c: Expect
that "vx" is not emitted.
* gcc.target/s390/zvector/autovec-float-quiet-uneq.c: Likewise.
Ulrich Weigand [Tue, 24 Nov 2020 09:32:20 +0000 (10:32 +0100)]
Fix -ffast-math flags handling inconsistencies
This patch implements the following set of changes:
1. If a component flag of -ffast-math (or -funsafe-math-optimizations)
is explicitly set (or reset) on the command line, this should override
any implicit change due to -f(no-)fast-math, no matter in which order
the flags come on the command line. This change affects all flags.
2. Any component flag modified from its default by -ffast-math should
be reset to the default by -fno-fast-math. This was previously
not done for the following flags:
-fcx-limited-range
-fexcess-precision=
3. Once -ffinite-math-only is true, the -f(no-)signaling-nans flag has
no meaning (if we have no NaNs at all, it does not matter whether
there is a difference between quiet and signaling NaNs). Therefore,
it does not make sense for -ffast-math to imply -fno-signaling-nans.
(This is also a documentation change.)
4. -ffast-math is documented to imply -fno-rounding-math, however the
latter setting is the default anyway; therefore it does not make
sense to try to modify it from its default setting.
5. The __FAST_MATH__ preprocessor macro should be defined if and only
if all the component flags of -ffast-math are set to the value that
is documented as the effect of -ffast-math. The following flags
were currently *not* so tested:
-fcx-limited-range
-fassociative-math
-freciprocal-math
-frounding-math
(Note that we should still *test* for -fno-rounding-math here even
though it is not set as to 4. -ffast-math -frounding-math should
not set the __FAST_MATH__ macro.)
This is also a documentation change.
2020-11-24 Ulrich Weigand <uweigand@de.ibm.com>
gcc/
* doc/invoke.texi (-ffast-math): Remove mention of -fno-signaling-nans.
Clarify conditions when __FAST_MATH__ preprocessor macro is defined.
* opts.c (common_handle_option): Pass OPTS_SET to set_fast_math_flags
and set_unsafe_math_optimizations_flags.
(set_fast_math_flags): Add OPTS_SET argument, and use it to avoid
setting flags already explicitly set on the command line. In the !set
case, also reset x_flag_cx_limited_range and x_flag_excess_precision.
Never reset x_flag_signaling_nans or x_flag_rounding_math.
(set_unsafe_math_optimizations_flags): Add OPTS_SET argument, and use
it to avoid setting flags already explicitly set on the command line.
(fast_math_flags_set_p): Also test x_flag_cx_limited_range,
x_flag_associative_math, x_flag_reciprocal_math, and
x_flag_rounding_math.
Piotr Trojanek [Fri, 9 Oct 2020 12:27:08 +0000 (14:27 +0200)]
[Ada] Fix inconsistent parameter of SPARK_Msg_NE
gcc/ada/
* sem_prag.adb (Analyze_Global_Item): Call SPARK_Msg_NE with the
entity, not with its identifier.
Arnaud Charlet [Fri, 9 Oct 2020 07:49:57 +0000 (09:49 +0200)]
[Ada] Cannot process -S -o with GNAT LLVM
gcc/ada/
* opt.ads (Generate_Asm): New flag.
* osint-c.adb (Set_Output_Object_File_Name): Accept any
extension when generating assembly.
* adabkend.adb (Scan_Compiler_Args): Recognize -S.
Piotr Trojanek [Thu, 8 Oct 2020 21:55:49 +0000 (23:55 +0200)]
[Ada] Reuse Is_Packed_Array where possible
gcc/ada/
* exp_attr.adb, exp_ch4.adb, exp_intr.adb, sem_ch8.adb,
sem_res.adb, sem_type.adb, sem_util.adb: Reuse Is_Packed_Array.
Piotr Trojanek [Thu, 8 Oct 2020 21:39:07 +0000 (23:39 +0200)]
[Ada] Fix minor typos in comments
gcc/ada/
* checks.adb (Apply_Access_Check): Remove unbalanced paren.
* exp_attr.adb (Expand_N_Attribute_Reference): Fix typo in
comment.
Justin Squirek [Tue, 6 Oct 2020 19:01:15 +0000 (15:01 -0400)]
[Ada] Compiler crash on assertion pragma in ghost region
gcc/ada/
* sem_prag.adb (Analyze_Pragma): Mark relevant pragmas as ghost
when they are within a ghost region.
Piotr Trojanek [Wed, 7 Oct 2020 20:27:46 +0000 (22:27 +0200)]
[Ada] Reuse In_Same_List where possible
gcc/ada/
* contracts.adb, freeze.adb, sem_ch12.adb, sem_prag.adb: Reuse
In_Same_List.
Piotr Trojanek [Wed, 7 Oct 2020 20:12:45 +0000 (22:12 +0200)]
[Ada] Simplify Is_Loop_Pragma
gcc/ada/
* sem_prag.adb (Is_Loop_Pragma): Avoid repeated calls to
Original_Node; remove unnecessary IF statement.
Piotr Trojanek [Tue, 6 Oct 2020 10:12:28 +0000 (12:12 +0200)]
[Ada] Replace chained if-then-elsif with case stmt for attribute ids
gcc/ada/
* exp_spark.adb (Expand_SPARK_N_Attribute_Reference): Rewrite
with a CASE statement.
Piotr Trojanek [Tue, 6 Oct 2020 09:58:45 +0000 (11:58 +0200)]
[Ada] Cleanup expansion of attribute Constrained
gcc/ada/
* exp_attr.adb (Expand_N_Attribute_Reference): Replace calls to
Sloc with a local constant Loc; remove call to
Analyze_And_Resolve and return, which is exactly what happens
anyway (and other branches in the Constrained declare block
appear to rely on analysis, resolution and returning happening
in all cases).
* sem_util.adb: Remove useless parens.
Piotr Trojanek [Thu, 1 Oct 2020 20:23:24 +0000 (22:23 +0200)]
[Ada] Recognize delta and extension aggregates as objects
gcc/ada/
* sem_util.adb (Is_Object_Reference): Delta and extension
aggregates are objects.
Ghjuvan Lacambre [Wed, 30 Sep 2020 08:50:47 +0000 (10:50 +0200)]
[Ada] Implement No_Unrecognized_{Aspects,Pragmas} restrictions
gcc/ada/
* libgnat/s-rident.ads (System.Rident): Register new restriction
IDs.
* par-ch13.adb (Get_Aspect_Specifications): Add restriction check.
* par-prag.adb (Process_Restrictions_Or_Restriction_Warnings):
Register No_Unrecognized_Aspects restriction.
* sem_prag.adb (Analyze_Pragma): Add restriction check.
* snames.ads-tmpl: Create restriction names.
Piotr Trojanek [Wed, 7 Oct 2020 21:19:28 +0000 (23:19 +0200)]
[Ada] Accept local objects in the prefix of attribute Loop_Entry
gcc/ada/
* sem_attr.adb (Declared_Within): Return True for objects
declared within the attribute Loop_Entry prefix itself.
Yannick Moy [Mon, 5 Oct 2020 07:05:06 +0000 (09:05 +0200)]
[Ada] Fix crash in GNATprove on inlined subprogram in default expression
gcc/ada/
* sem_ch3.adb (Process_Discriminants): Correctly set right
context for analyzing default value of discriminant.
Arnaud Charlet [Fri, 2 Oct 2020 15:20:23 +0000 (11:20 -0400)]
[Ada] Wrong resolution of universal_access = operators
gcc/ada/
* sem_type.adb (Add_One_Interp.Is_Universal_Operation): Account
for universal_access = operator.
(Disambiguate): Take into account preference on universal_access
= operator when relevant.
(Disambiguate.Is_User_Defined_Anonymous_Access_Equality): New.
Arnaud Charlet [Sat, 19 Sep 2020 08:02:00 +0000 (04:02 -0400)]
[Ada] Premature finalization on build in place return and case expression
gcc/ada/
* exp_util.adb (Is_Finalizable_Transient): Take into account return
statements containing N_Expression_With_Actions. Also clean up a
condition to make it more readable.
* exp_ch6.adb: Fix typo.
Eric Botcazou [Tue, 6 Oct 2020 19:14:01 +0000 (21:14 +0200)]
[Ada] Small cleanup in the Ada.Text_IO hierarchy
gcc/ada/
* libgnat/a-wtdeio.adb (TFT): Delete and adjust throughout.
* libgnat/a-wtenau.adb (TFT): Likewise.
* libgnat/a-wtfiio.adb (TFT): Likewise.
* libgnat/a-wtflio.adb (TFT): Likewise.
* libgnat/a-wtinio.adb (TFT): Likewise.
* libgnat/a-wtinio__128.adb (TFT): Likewise.
* libgnat/a-wtmoio.adb (TFT): Likewise.
* libgnat/a-wtmoio__128.adb (TFT): Likewise.
* libgnat/a-ztdeio.adb (TFT): Likewise.
* libgnat/a-ztenau.adb (TFT): Likewise.
* libgnat/a-ztfiio.adb (TFT): Likewise.
* libgnat/a-ztflio.adb (TFT): Likewise.
* libgnat/a-ztinio.adb (TFT): Likewise.
* libgnat/a-ztinio__128.adb (TFT): Likewise.
* libgnat/a-ztmoio.adb (TFT): Likewise.
* libgnat/a-ztmoio__128.adb (TFT): Likewise.
Arnaud Charlet [Wed, 30 Sep 2020 12:34:57 +0000 (08:34 -0400)]
[Ada] AI12-0394 Named Numbers and User-Defined Numeric Literals
gcc/ada/
* sem_ch13.adb (Validate_Literal_Aspect): Add support for named
numbers and in particular overload of the Real_Literal function.
* sem_res.adb (Resolve): Add support for named numbers in
Real_Literal and Integer_Literal resolution.
* einfo.adb, einfo.ads (Related_Expression,
Set_Related_Expression): Allow E_Function.
* uintp.ads (UI_Image_Max): Bump size of buffer to avoid loosing
precision.
* sem_eval.adb: Fix typo in comment.
* libgnat/a-nbnbin.adb, libgnat/a-nbnbin.ads (From_String):
Return a Valid_Big_Integer.
* libgnat/a-nbnbre.adb, libgnat/a-nbnbre.ads (From_String): New
variant taking two strings. Return a Valid_Big_Real.