Commit Graph

182576 Commits

Author SHA1 Message Date
Jakub Jelinek
c48514bea6 Update Copyright in ChangeLog files
Do this separately from all other Copyright updates, as ChangeLog files
can be modified only separately.
2021-01-04 09:35:45 +01:00
GCC Administrator
2e96eec614 Daily bump. 2021-01-04 00:16:18 +00:00
Eric Botcazou
f14f89c5c4 Bump copyright year
gcc/ada/
	* gnatvsn.ads: Bump copyright year.
2021-01-03 13:43:01 +01:00
Mike Frysinger
3335c9f954 config: import pkg.m4 from pkg-config
We use this in the sim tree currently.  Rather than require people to
have pkg-config installed, include it in the config/ dir.

config/ChangeLog:

	* pkg.m4: New file from pkg-config-0.29.2.
2021-01-02 21:53:56 -05:00
Mike Frysinger
37d0bb1f5b libiberty.h: punt duplicate strverscmp prototype
SVN r216772 accidentally copied & pasted this prototype when adding
other ones nearby.

include/ChangeLog:

	* libiberty.h (strverscmp): Delete duplicate prototype.
2021-01-02 21:51:14 -05:00
GCC Administrator
2eacfdbd6a Daily bump. 2021-01-03 00:16:20 +00:00
Iain Sandoe
ef370f933c Darwin : Adjust defaults for the linker.
Ideally, the linker will be queried for its version and that will be
used to determine capabilities that cannot be discovered from
reasonable configuration testing.

When building cross tools, this might not be possible, and we have
strategies for providing useful defaults.  These are adjusted here to
refect current choices.

gcc/ChangeLog:

	* config/darwin.h (MIN_LD64_NO_COAL_SECTS): Adjust.
	Amend handling for LD64_VERSION fallback defaults.
2021-01-02 19:56:19 +00:00
Iain Sandoe
4a04f09dc7 Darwin, Simplify headers 4/5 : Remove redundant headers.
The darwinN.h headers (with the sole exception of darwin7.h,
which contains a target macro definition) now only contain
values that set fall-backs for cross-compilations, these can
be provided from the config.gcc script which means we no longer
need the darwinN.h - so delete them.

gcc/ChangeLog:

	* config.gcc: Compute default version information
	from the configured target.  Likewise defaults for
	ld64.
	* config/darwin10.h: Removed.
	* config/darwin12.h: Removed.
	* config/darwin9.h: Removed.
	* config/rs6000/darwin8.h: Removed.
2021-01-02 19:56:19 +00:00
Iain Sandoe
5282e22f0e Darwin, Simplify headers 3/5 : Delete dead code.
Darwin defines ASM_OUTPUT_ALIGNED_DECL_COMMON which is used in
preference to ASM_OUTPUT_ALIGNED_COMMON, which makes the latter
definition dead code.  Remove this.

gcc/ChangeLog:

	* config/darwin9.h (ASM_OUTPUT_ALIGNED_COMMON): Delete.
2021-01-02 19:56:19 +00:00
Iain Sandoe
ac6ecec4b3 Darwin, Simplify headers 2/5 : Move spec for STACK_CHECK_STATIC_BUILTIN.
We now need a modern (C++11) toolchain to bootstrap GCC, so there's no
need to skip the stack protect for Darwin < 9.

gcc/ChangeLog:

	* config/darwin9.h (STACK_CHECK_STATIC_BUILTIN): Move from here..
	* config/darwin.h (STACK_CHECK_STATIC_BUILTIN): .. to here.
2021-01-02 19:56:19 +00:00
Iain Sandoe
896607741f Darwin, Simplify headers 1/5 : Move LINK_GCC_C_SEQUENCE_SPEC [NFC].
There is no need to make the LINK_GCC_C_SEQUENCE_SPEC conditional on
configuration parameters, it is adequately conditionalized on the
macosx-version-min.

gcc/ChangeLog:

	* config/darwin10.h (LINK_GCC_C_SEQUENCE_SPEC): Move from
	here...
	* config/darwin.h (LINK_GCC_C_SEQUENCE_SPEC): ... to here.
2021-01-02 19:56:19 +00:00
Iain Sandoe
1dfeaca014 Darwin, Simplify headers 0/5 : Move spec for Darwin 10 unwind stub [NFC].
The darwinN.h headers were (presumably) introduced to allow specs to be
adjusted when there was no mmacosx-version-min handling, or that was
considered unreliable.

We have version-specific specs for the values that have configuration
data, and the version is set in the driver (so may be considered
reliably present).

Some of the 'darwinN.h' content has become dead code, and the reminder
is either conditionalised on version information (or is setting values
used as fall-backs in cross-compilations).

With the changes needed for Darwin20 / macOS 11 the 'darwnN.h' headers
are now too unwieldy to be useful - so this series moves the relevant
specs definitons to the common 'darwin.h' header and then finally uses
the config.gcc script to supply the fall-back defaults for cross-
compilations.

We can then delete all but the main header, since the darwinN.h are
unused.

This change moves a spec from darwin10.h to the main darwin.h
target header.

gcc/ChangeLog:

	* config/darwin10.h (LINK_GCC_C_SEQUENCE_SPEC): Move the spec
	for the Darwin10 unwinder stub from here ...
	* config/darwin.h (LINK_COMMAND_SPEC_A): ... to here.
2021-01-02 19:56:19 +00:00
Iain Sandoe
b2cee5e1e8 Darwin : Adjust defaults for current bootstrap constraints.
The toolchain now requires a C++11 compiler to bootstrap and
none of the older Darwin toolchains which were based on stabs
debugging are suitable.  We can simplify the debug setup now.

gcc/ChangeLog:

	* config/darwin.h (DSYMUTIL_SPEC): Default to DWARF
	(ASM_DEBUG_SPEC):Only define if the assembler supports
	stabs.
	(PREFERRED_DEBUGGING_TYPE): Default to DWARF.
	(DARWIN_PREFER_DWARF): Define.
	* config/darwin9.h (PREFERRED_DEBUGGING_TYPE): Remove.
	(DARWIN_PREFER_DWARF): Likewise
	(DSYMUTIL_SPEC): Likewise.
	(COLLECT_RUN_DSYMUTIL): Likewise.
	(ASM_DEBUG_SPEC): Likewise.
	(ASM_DEBUG_OPTION_SPEC): Likewise.
2021-01-02 19:56:19 +00:00
Jan Hubicka
ae99b315ba ggc_free basic blocks
* cfg.c (free_block): ggc_free bb.
2021-01-02 16:05:17 +01:00
Jan Hubicka
c304a68e41 Free datastructures pointing to CFG after parsing
* cp-tree.h (cp_tree_c_finish_parsing): Declare.
	* decl2.c (c_parse_final_cleanups): Call cp_tree_c_finish_parsing.
	* tree.c (cp_tree_c_finish_parsing): New function.
2021-01-02 16:04:24 +01:00
GCC Administrator
b6dd195aac Daily bump. 2021-01-02 00:16:24 +00:00
Ian Lance Taylor
5a4e0d121a internal/cpu: add aarch64 support functions
Patch from Andreas Schwab.

Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/281000
2021-01-01 15:13:50 -08:00
Ian Lance Taylor
0b9ef8be40 runtime: move startupRandomData back to runtime2.go
In libgo it's referenced from os_gccgo.go on all platforms.

Fixes go/98496

Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/280999
2021-01-01 15:11:45 -08:00
Ian Lance Taylor
abca670596 internal/cpu, golang.org/x/sys/cpu: support other GOARCH values
Add support (mostly dummy support) for GOARCH values supported by
gofrontend but not gc.  Fix PPC handling.

Fixes https://gcc.gnu.org/PR98493

Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/280932
2021-01-01 15:10:06 -08:00
Harald Anlauf
d816b0c144 PR fortran/96381 - invalid read in gfc_find_derived_vtab
An invalid declaration of a CLASS instance can lead to an internal state
with inconsistent attributes during parsing that needs to be handled with
sufficient care when processing subsequent statements.  Avoid a lookup of
the vtab entry for such cases.

gcc/fortran/ChangeLog:

	* class.c (gfc_find_vtab): Add check on attribute is_class.
2021-01-01 18:55:41 +01:00
Jakub Jelinek
4b24d500f4 Update copyright dates.
Manual part of copyright year updates.

2021-01-01  Jakub Jelinek  <jakub@redhat.com>

gcc/
	* gcc.c (process_command): Update copyright notice dates.
	* gcov-dump.c (print_version): Ditto.
	* gcov.c (print_version): Ditto.
	* gcov-tool.c (print_version): Ditto.
	* gengtype.c (create_file): Ditto.
	* doc/cpp.texi: Bump @copying's copyright year.
	* doc/cppinternals.texi: Ditto.
	* doc/gcc.texi: Ditto.
	* doc/gccint.texi: Ditto.
	* doc/gcov.texi: Ditto.
	* doc/install.texi: Ditto.
	* doc/invoke.texi: Ditto.
gcc/ada/
	* gnat_ugn.texi: Bump @copying's copyright year.
	* gnat_rm.texi: Likewise.
gcc/d/
	* gdc.texi: Bump @copyrights-d year.
gcc/fortran/
	* gfortranspec.c (lang_specific_driver): Update copyright notice
	dates.
	* gfc-internals.texi: Bump @copying's copyright year.
	* gfortran.texi: Ditto.
	* intrinsic.texi: Ditto.
	* invoke.texi: Ditto.
gcc/go/
	* gccgo.texi: Bump @copyrights-go year.
libgomp/
	* libgomp.texi: Bump @copying's copyright year.
libitm/
	* libitm.texi: Bump @copying's copyright year.
libquadmath/
	* libquadmath.texi: Bump @copying's copyright year.
2021-01-01 17:45:07 +01:00
Jakub Jelinek
618e665a0f Rotate ChangeLog files - step 2 - remove 2020 entries from ChangeLog files.
Can't be committed together with the previous one due to the ChangeLog vs.
other files restrictions.
2021-01-01 17:30:04 +01:00
Jakub Jelinek
6e92696278 Rotate ChangeLog files - part 1 - add ChangeLog-2020.
2021-01-01  Jakub Jelinek  <jakub@redhat.com>

gcc/
	* ChangeLog-2020: Rotate ChangeLog.  New file.
gcc/ada/
	* ChangeLog-2020: Rotate ChangeLog.  New file.
gcc/cp/
	* ChangeLog-2020: Rotate ChangeLog.  New file.
gcc/d/
	* ChangeLog-2020: Rotate ChangeLog.  New file.
gcc/fortran/
	* ChangeLog-2020: Rotate ChangeLog.  New file.
gcc/testsuite/
	* ChangeLog-2020: Rotate ChangeLog.  New file.
libgfortran/
	* ChangeLog-2020: Rotate ChangeLog.  New file.
libstdc++-v3/
	* ChangeLog-2020: Rotate ChangeLog.  New file.
2021-01-01 17:27:52 +01:00
Joel Brobecker
43dcbb07d2 disable some aapcs/vfp*.c test if not arm_fp16_alternative_ok
The tests use -mfp16-format=alternative, and so should not be run
if that option isn't supported.


for  gcc/testsuite/ChangeLog

	* lib/target-supports.exp
	(check_effective_target_arm_fp16_alternative_ok_nocache):
	Return zero for *-*-vxworks7r* targets.
	* gcc.target/arm/aapcs/vfp22.c: Require arm_fp16_alternative_ok.
	* gcc.target/arm/aapcs/vfp23.c: Likewise.
	* gcc.target/arm/aapcs/vfp24.c: Likewise.
	* gcc.target/arm/aapcs/vfp25.c: Likewise.
2021-01-01 02:13:20 -03:00
Jerome Lambourg
a210519cdd fix testsuite/g++.dg/init/new26.C for C++-14 and later
This test fails during the execution on VxWorks 7 when using
C++-14 and C++-17.


for  gcc/testsuite/ChangeLog

	* g++.dg/init/new26.C: Fix overriding of the delete operator
	for c++14 profile.
2021-01-01 02:12:06 -03:00
Jerome Lambourg
063bb8edbe g++.dg/tls/pr79288.C: Skip on vxworks_kernel (TLS model not supported)
The only TLS model supported in VxWorks kernel mode is local-exec.


for  gcc/testsuite/ChangeLog

	* g++.dg/tls/pr79288.C: Skip on vxworks_kernel (TLS model
	not supported).
2021-01-01 02:10:57 -03:00
Joel Brobecker
ba34b26564 compile gcc.target/arm/{pr78255-2.c,memset-inline-2.c} with -mno-long-calls
If the target is configured such that -mlong-call is passed
by default, the function calls these tests are trying to detect
by scanning the assembly file are performed using long calls,
like so:

    | foo:
    |     @ memset-inline-2.c:12:   memset (a, -1, 14);
    |         mov     r2, #14 @,
    |         mvn     r1, #0  @,
    |         ldr     r0, .L2 @,
    |         ldr     r3, .L2+4       @ tmp112,
    |         bx      r3              @ tmp112

Looking at .L2 (and in particular at .L2+4):

    | .L2:
    |         .word   a
    |         .word   memset   <<<---

This change adds -mno-long-calls to the list of compiler options
to make sure we generate short call code, allowing the assembly
matching to pass.

This is added unconditionally to the dg-options (as opposed to using
dg-additional-options) because this test is already specific to ARM
targets, and -mno-long-calls is available on all ARM targets.


for  gcc/testsuite/ChangeLog

	* gcc.target/arm/memset-inline-2.c: Add -mno-long-calls to
	the test's dg-options.
	* gcc.target/arm/pr78255-2.c: Likewise.
2021-01-01 02:07:16 -03:00
Jerome Lambourg
7ba5ce389c Fix testsuite/g++.old-deja/g++.mike/p658.C build failure on VxWorks RTP
The conflicting definition of OK is present in VxWorks RTP headers too.


for  gcc/testsuite/ChangeLog

	* g++.old-deja/g++.mike/p658.C: Also undefine OK on VxWorks RTP.
2021-01-01 02:06:42 -03:00
Jerome Lambourg
0bcaee87e8 Fix testsuite/g++.dg/opt/20050511-1.C compilation error on VxWorks 7
In VxWorks 7, UINT32 is defined in both modes, kernel and rtp.  Adjust
the work around accordingly.


for  gcc/testsuite/ChangeLog

	* g++.dg/opt/20050511-1.C: Work around UINT32 in vxworks rtp
	headers too.
2021-01-01 02:05:57 -03:00
Jerome Lambourg
59cd72afce Skip testsuite/g++.old-deja/g++.pt/const2.C on vxworks_kernel
Linking in vxworks kernel-mode is partial linking, so missing symbols
are not detected.


for  gcc/testsuite/ChangeLog

	* g++.old-deja/g++.pt/const2.C: Skip on vxworks kernel.
2021-01-01 02:00:55 -03:00
Jerome Lambourg
75df9435f3 Remove VxWorks-specific test directives in g++.dg/warn/miss-format-1.C
These are no longer applicable.


for  gcc/testsuite/ChangeLog

	* g++.dg/warn/miss-format-1.C: Remove vxworks-specific test
	directives.
2021-01-01 01:59:32 -03:00
Jerome Lambourg
8aba274de2 Undefine ERROR in g++.dg/tree-ssa/copyprop.C
VxWorks headers define ERROR as a macro, which conflicts with the use
in the test.


for  gcc/testsuite/ChangeLog

	* g++.dg/tree-ssa/copyprop.C: Undefine ERROR if defined.
2021-01-01 01:56:25 -03:00
Jerome Lambourg
af655dee79 skip testsuite/g++.dg/other/anon5.C on vxworks_kernel targets
The vxworks kernel-mode linking is partial linking, so it cannot
detect missing symbols.


for  gcc/testsuite/ChangeLog

	* g++.dg/other/anon5.C: Skip on vxworks kernel.
2021-01-01 01:56:25 -03:00
Jerome Lambourg
76d00e0045 Add conditions on VxWorks versions for gcc.dg/vxworks/initpri?.c
Adjust vxworks initpri expectations, given that vxworks7 has switched
to .init_array.


for  gcc/testsuite/ChangeLog

	* gcc.dg/vxworks/initpri1.c: Tigthen VxWorks version check.
	* gcc.dg/vxworks/initpri2.c: Likewise.
2021-01-01 01:56:25 -03:00
Joel Brobecker
06450993d4 gcc.dg/intmax_t-1.c compiles without error on VxWorks 7 SR06x0
This test currently fails on VxWorks 7 SR06x0 targets when in kernel
mode, because it expects a discrepancy between built-in and system
intmax_t for all VxWorks targets when in kernel mode.  Fortunately,
this has now been fixed when targetting VxWorks 7 SR06x0, so this
commit adjusts the "dg-error" condition to exclude newer versions of
VxWorks 7.

for  gcc/testsuite/ChangeLog

	* gcc.dg/intmax_t-1.c: Do not expect an error on *-*-vxworks7r*
	targets.
2021-01-01 01:54:58 -03:00
Olivier Hainque
6990be171f Fix VxWorks xfail filters on pthread-init-?.c
Match xfail on kernel instead of rtp mode.


for  gcc/testsuite/changeLog

	* gcc.dg/pthread-init-1.c: Fix the VxWorks xfail filters.
	* gcc.dg/pthread-init-2.c: Ditto.
2021-01-01 01:54:57 -03:00
Olivier Hainque
0292de4582 Add missing vxworks filters to lib/target-supports.exp functions
Explicitly disable some vxworks-missing features in the testsuite, that
the current feature tests detect as present.


for  gcc/testsuite/ChangeLog

	* lib/target-supports.exp (check_weak_available,
	check_fork_available, check_effective_target_lto,
	check_effective_target_mempcpy): Add vxworks filters.
2021-01-01 01:46:34 -03:00
Alexandre Oliva
8afe0911e0 -mno-long-calls for mve_libcall tests
The implicit -mlong-calls used in our vxworks configurations changes
the call sequences from those expected in the mve_libcall testcases.

This patch brings the test output in line with the expectations, with
an explicit -mno-long-calls.


for  gcc/testsuite/ChangeLog

	* gcc.target/arm/mve/intrinsics/mve_libcall1.c: Pass an
	explicit -mno-long-calls.
	* gcc.target/arm/mve/intrinsics/mve_libcall2.c: Likewise.
2021-01-01 01:46:34 -03:00
Alexandre Oliva
a9ff287b11 -mno-long-calls for arm/no_unique_address tests
The implicit -mlong-calls from our vxworks configurations makes the
tail-call instructions differ from those expected by the
no_unique_address tests in gcc.target/arm.

This patch adds -mno-long-calls to the compilation commands, so that
we generate the expected sequences.


for  gcc/testsuite/ChangeLog

	* g++.target/arm/no_unique_address_1.C: Add -mno-long-calls.
	* g++.target/arm/no_unique_address_2.C: Likewise.
2021-01-01 01:40:40 -03:00
Alexandre Oliva
02d2706db3 -mno-long-calls for arm/headmerge tests
The headmerge tests pass a constant to conditional calls, so that the
same constant is always passed to a function, though it's a different
function depending on which path is taken.

The test checks that the constant appears only once in the assembly
output, as a means to verify that the insns setting up the argument
are unified: they appear as separate insns up to jump2, where
crossjump identifies a common prefix to all conditional paths and
unifies them.

Alas, with -mlong-calls, that we enable in our arm-vxworks
configurations, the argument register is loaded after loading the
callee address into another register.  Since each path calls a
different function, there's no common initial code sequence for
crossjump to unify, and the argument register set up remains separate,
so the test fails.

Though it would surely be desirable for the compiler to perform the
unification of the argument register setting up, this patch merely
avoids the effects of -mlong-calls, with an explicit -mno-long-calls.


for  gcc/testsuite/ChangeLog

	* gcc.target/arm/headmerge-1.c: Add -mno-long-calls.
	* gcc.target/arm/headmerge-2.c: Likewise.
2021-01-01 01:39:49 -03:00
Alexandre Oliva
fe0e54c69f -mno-long-calls for expected regalloc in arm/fp16-aapcs-2.c test
The implicit -mlong-calls used in our arm-vxworks configurations
changes the register allocation patterns in the arm/fp16-aapcs-2.c
test: r3 ends up used in the long-call sequence, and we end up using
ip as a temporary, which doesn't match the expected mov patterns.

This patch adds an explicit -mno-long-calls for the generated code to
match the expectation.


for  gcc/testsuite/ChangeLog

	* gcc.target/arm/fp16-aapcs-2.c: Use -mno-long-calls.
2021-01-01 01:38:16 -03:00
GCC Administrator
53be78f071 Daily bump. 2021-01-01 00:16:20 +00:00
Jakub Jelinek
3ab7a91f36 testsuite: Fix up pr56719.c testcase [PR98489]
On some targets, there are no < 8191; and >= 8191; strings,
but < 8191) and >= 8191), so just remove the ; from the regexps.

2021-01-01  Jakub Jelinek  <jakub@redhat.com>

	PR testsuite/98489
	PR tree-optimization/56719
	* gcc.dg/tree-ssa/pr56719.c: Remove semicolon from
	scan-tree-dump-times regexps.
2021-01-01 00:03:35 +01:00
Richard Sandiford
58a12b0ead vect: Avoid generating out-of-range shifts [PR98302]
In this testcase we end up with:

  unsigned long long x = ...;
  char y = (char) (x << 37);

The overwidening pattern realised that only the low 8 bits
of x << 37 are needed, but then tried to turn that into:

  unsigned long long x = ...;
  char y = (char) x << 37;

which gives an out-of-range shift.  In this case y can simply
be replaced by zero, but as the comment in the patch says,
it's kind-of awkward to do that in the middle of vectorisation.

Most of the overwidening stuff is about keeping operations
as narrow as possible, which is important for vectorisation
but could be counter-productive for scalars (especially on
RISC targets).  In contrast, optimising y to zero in the above
feels like an independent optimisation that would benefit scalar
code and that should happen before vectorisation.

gcc/
	PR tree-optimization/98302
	* tree-vect-patterns.c (vect_determine_precisions_from_users): Make
	sure that the precision remains greater than the shift count.

gcc/testsuite/
	PR tree-optimization/98302
	* gcc.dg/vect/pr98302.c: New test.
2020-12-31 16:51:34 +00:00
Richard Sandiford
9fa5b473b5 vect: Fix bogus alignment assumption in alias checks [PR94994]
This PR is about a case in which the vectoriser was feeding
incorrect alignment information to tree-data-ref.c, leading
to incorrect runtime alias checks.  The alignment was taken
from the TREE_TYPE of the DR_REF, which in this case was a
COMPONENT_REF with a normally-aligned type.  However, the
underlying MEM_REF was only byte-aligned.

This patch uses dr_alignment to calculate the (byte) alignment
instead, just like we do when creating vector MEM_REFs.

gcc/
	PR tree-optimization/94994
	* tree-vect-data-refs.c (vect_vfa_align): Use dr_alignment.

gcc/testsuite/
	PR tree-optimization/94994
	* gcc.dg/vect/pr94994.c: New test.
2020-12-31 16:51:33 +00:00
Richard Sandiford
0411210fdd genmodes: Update GET_MODE_MASK when changing NUNITS [PR98214]
The static GET_MODE_MASKs for SVE vectors are based on the
static precisions, which in turn are based on 128-bit SVE.
The precisions are later updated based on -msve-vector-bits
(usually to become variable length), but the GET_MODE_MASK
stayed the same.  This caused combine to fold:

  (*_extract:DI (subreg:DI (reg:VNxMM R) 0) ...)

to zero because the extracted bits appeared to be insignificant.

gcc/
	PR rtl-optimization/98214
	* genmodes.c (emit_insn_modes_h): Emit a definition of CONST_MODE_MASK.
	(emit_mode_mask): Treat mode_mask_array as non-constant if adj_nunits.
	(emit_mode_adjustments): Update GET_MODE_MASK when updating
	GET_MODE_NUNITS.
	* machmode.h (mode_mask_array): Use CONST_MODE_MASK.
2020-12-31 16:10:47 +00:00
Jakub Jelinek
d2eb616a0f match.pd: Add clz(X) == 0 -> (int)X < 0 etc. simpifications [PR94802]
The following patch adds some clz simplifications.  If
clz is 0, then the MSB of the argument is set, and if clz is prec-1, then
the argument is 1.

2020-12-31  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/94802
	* match.pd (clz(X) == 0 -> (int)X < 0): New simplification.
	(clz(X) == (prec-1) -> X == 1): Likewise.

	* gcc.dg/tree-ssa/pr94802-1.c: New test.
2020-12-31 11:09:26 +01:00
Jakub Jelinek
8f12ce2ea3 match.pd: Add (-(X < 0) | 1) * X -> abs (X) etc. simplifications [PR94785]
The following patch adds two simplifications to recognize idioms
for ABS_EXPR resp. ABSU_EXPR.

2020-12-31  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/94785
	* match.pd ((-(X < 0) | 1) * X -> abs (X)): New simplification.
	((-(X < 0) | 1U) * X -> absu (X)): Likewise.

	* gcc.dg/tree-ssa/pr94785.c: New test.
2020-12-31 11:08:15 +01:00
Jakub Jelinek
9e603837f7 wide-int: Fix wi::to_mpz [PR98474]
The following testcase is miscompiled, because niter analysis miscomputes
the number of iterations to 0.
The problem is that niter analysis uses mpz_t (wonder why, wouldn't
widest_int do the same job?) and when wi::to_mpz is called e.g. on the
TYPE_MAX_VALUE of __uint128_t, it initializes the mpz_t result with wrong
value.
wi::to_mpz has code to handle negative wide_ints in signed types by
inverting all bits, importing to mpz and complementing it, which is fine,
but doesn't handle correctly the case when the wide_int's len (times
HOST_BITS_PER_WIDE_INT) is smaller than precision when wi::neg_p.
E.g. the 0xffffffffffffffffffffffffffffffff TYPE_MAX_VALUE is represented
in wide_int as 0xffffffffffffffff len 1, and wi::to_mpz would create
0xffffffffffffffff mpz_t value from that.
This patch handles it by adding the needed -1 host wide int words (and has
also code to deal with precision that aren't multiple of
HOST_BITS_PER_WIDE_INT).

2020-12-31  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/98474
	* wide-int.cc (wi::to_mpz): If wide_int has MSB set, but type
	is unsigned and excess negative, append set bits after len until
	precision.

	* gcc.c-torture/execute/pr98474.c: New test.
2020-12-31 11:06:56 +01:00
Jakub Jelinek
a9ec9902d7 fold-const: Avoid (cast) ((cast2) x p+ y) folding for -fsanitize=alignment [PR98206]
The following testcase is diagnosed by UBSan as invalid, even when it is
valid.
We have a derived type Base2 at offset 1 with alignment 1 and do:
(const Derived &) ((const Base2 *) this + -1)
but the folder before ubsan in the FE gets a chance to instrument it
optimizes that into:
(const Derived &) this + -1
and so we require that this has 8-byte alignment which Derived class needs.

Fixed by avoiding such an optimization when -fsanitize=alignment is in
effect if it would affect the alignments (and guarded with !in_gimple_form
because we don't really care during GIMPLE, though pointer conversions are
useless then and so such folding isn't needed very much during GIMPLE).

2020-12-31  Jakub Jelinek  <jakub@redhat.com>

	PR c++/98206
	* fold-const.c: Include asan.h.
	(fold_unary_loc): Don't optimize (ptr_type) (((ptr_type2) x) p+ y)
	into ((ptr_type) x) p+ y if sanitizing alignment in GENERIC and
	ptr_type points to type with higher alignment than ptr_type2.

	* g++.dg/ubsan/align-4.C: New test.
2020-12-31 10:20:39 +01:00