Commit Graph

190290 Commits

Author SHA1 Message Date
Piotr Trojanek
a83c4eea27 [Ada] Split spec and body of expression function with Subprogram_Variant
gcc/ada/

	* libgnat/s-valuti.ads (Scan_Natural_Ghost): Split body from
	spec and put it into private part, so that GNATprove can pick it
	both when analysing the unit and its clients.
2021-12-02 16:26:23 +00:00
Piotr Trojanek
d43fbe0151 [Ada] Remove extra space after assignment symbol
gcc/ada/

	* exp_aggr.adb, exp_ch6.adb, par-ch4.adb, sem_ch13.adb: Remove
	extra space after ":=" symbol.
	* gen_il-gen.adb: Likewise; add missing headerbox.
2021-12-02 16:26:23 +00:00
Richard Kenner
eccc7c8cbf [Ada] Don't allow entry in implicit with chain to be ghost
gcc/ada/

	* rtsfind.adb (Maybe_Add_With): Ensure that the added "with" is
	never marked as ignored ghost code.
2021-12-02 16:26:23 +00:00
Piotr Trojanek
ea7f9e0530 [Ada] Simplify iteration over record components
gcc/ada/

	* freeze.adb (Freeze_Entity): Replace First_Entity/Next_Entity
	with First_Component/Next_Component; remove condition with Ekind
	equal to E_Component.
	* sem_ch13.adb (Check_Record_Representation_Clause): Likewise
	for component-or-discriminant.
	* sem_util.adb (Is_Fully_Initialized_Type): Likewise; rename Ent
	to a more specific Comp.
	* sem_warn.adb (Check_References): Likewise.
2021-12-02 16:26:22 +00:00
Piotr Trojanek
1fde9333dc [Ada] Refactor nested loops in warning on unassigned out parameter
gcc/ada/

	* sem_warn.adb (Warn_On_Unassigned_Out_Parameter): Move inner
	loop at the beginning of subprogram, so it is executed only
	once; fix order in the "add an ad hoc" phrase.
2021-12-02 16:26:22 +00:00
Piotr Trojanek
e2e877266d [Ada] Remove duplicated condition in warnings about read-before-write
gcc/ada/

	* sem_warn.adb (Check_References): Remove redundant condition.
2021-12-02 16:26:22 +00:00
Doug Rupp
28acd56a7a [Ada] vx7r2cert/light-tasking-rtp: undefined refs on ppc/ppc64
gcc/ada/

	* vxworks7-cert-rtp-link__ppcXX.spec: New file.
	* Makefile.rtl: Use it.
2021-12-02 16:26:21 +00:00
Yannick Moy
76bbe3972b [Ada] Proof of Interfaces.C with SPARK
gcc/ada/

	* libgnat/i-c.adb: Add ghost code.
	(C_Length_Ghost): New ghost functions to query the C length of a
	string.
	(To_Ada): Insert constant Count_Cst where needed to comply with
	SPARK.  Homogeneize code between variants for char, wchar_t,
	char16_t and char32_t. Use char16_nul and char32_nul
	systematically instead of their value. Fix the type of index To
	to be Integer instead of Positive, to avoid a possible range
	check failure on an empty Target. Insert an exit statement to
	avoid a possible overflow failure when the last index in Target
	is Natural'Last (possibly on a small string as well).
	* libgnat/i-c.ads: Add contracts.
	(C_Length_Ghost): New ghost functions to query the C length of a
	string.
	* libgnat/s-os_lib.adb: Remove pragma Compiler_Unit_Warning
	causing a spurious error during compilation of GNAT, as this
	pragma is not needed anymore now that we bootstrap (stage1) with
	the base compiler runtime.
2021-12-02 16:26:20 +00:00
Piotr Trojanek
7e650bf84b [Ada] Add contract to Ada.Task_Identification.Activation_Is_Complete
gcc/ada/

	* libgnarl/a-taside.ads (Activation_Is_Complete): Add
	precondition.
2021-12-02 16:26:20 +00:00
Piotr Trojanek
45be761038 [Ada] More intuitive names in sanity-checking of derived types
gcc/ada/

	* sem_ch3.adb (Check_Derived_Type): Rename local variables; fix
	style in comment.
2021-12-02 16:26:20 +00:00
Yannick Moy
40b180995a [Ada] Proof of System.Val_Util utilities for 'Value support
gcc/ada/

	* libgnat/s-valboo.adb (First_Non_Space_Ghost): Move to
	utilities.
	(Value_Boolean): Prefix call to First_Non_Space_Ghost.
	* libgnat/s-valboo.ads (First_Non_Space_Ghost): Move to
	utilities.
	(Is_Boolean_Image_Ghost, Value_Boolean): Prefix call to
	First_Non_Space_Ghost.
	* libgnat/s-valuer.adb (Scan_Raw_Real): Adapt to change of
	function Scan_Exponent to procedure.
	* libgnat/s-valueu.adb (Scan_Raw_Unsigned): Adapt to change of
	function Scan_Exponent to procedure.
	* libgnat/s-valuti.adb (First_Non_Space_Ghost): Function moved
	here.
	(Last_Number_Ghost): New ghost query function.
	(Scan_Exponent): Change function with side-effects into
	procedure, to mark in SPARK. Prove procedure wrt contract.
	Change type of local P to avoid possible range check failure (it
	is not known whether this can be activated by callers).
	(Scan_Plus_Sign, Scan_Sign): Change type of local P to avoid
	possible range check failure. Add loop invariants and assertions
	for proof.
	(Scan_Trailing_Blanks): Add loop invariant.
	(Scan_Underscore): Remove SPARK_Mode Off.
	* libgnat/s-valuti.ads (First_Non_Space_Ghost): Function moved
	here.
	(Last_Number_Ghost, Only_Number_Ghost, Is_Natural_Format_Ghost,
	Scan_Natural_Ghost): New ghost query functions.
	(Scan_Plus_Sign, Scan_Sign, Scan_Exponent, Scan_Trailing_Blanks,
	Scan_Underscore): Add functional contracts.
2021-12-02 16:26:19 +00:00
Yannick Moy
6df3ec0e7e [Ada] Proof of Boolean'Image and Boolean'Value
gcc/ada/

	* libgnat/s-imgboo.adb: Mark in SPARK.
	* libgnat/s-imgboo.ads: Mark in SPARK. Change from Pure to
	Preelaborate unit in order to be able to depend on
	System.Val_Bool.
	(Image_Boolean): Functionally specify the result of the
	procedure by calling System.Val_Bool.Value_Boolean on the
	result.
	* libgnat/s-valboo.adb: Mark in SPARK.
	(First_Non_Space_Ghost): New ghost function.
	(Value_Boolean): Change type of L and F to avoid possible range
	check failure on empty Str.
	* libgnat/s-valboo.ads: Mark in SPARK. Duplicate with-clause
	from body in the spec to be able to call
	System.Val_Util.Only_Space_Ghost in the contract.
	(First_Non_Space_Ghost): New ghost function computing the first
	non-space character in a string.
	(Is_Boolean_Image_Ghost): New ghost function computing whether a
	string is the image of a boolean value.
	(Value_Boolean): Add in precondition the conditions to avoid
	raising Constraint_Error. This precondition is never executed,
	and only used in proof, thanks to the use of pragma
	Assertion_Policy. Given that precondition, the postcondition can
	simply check the first non-space character to decide whether
	True or False is read.
	* libgnat/s-valuti.adb: Mark in SPARK, but use SPARK_Mode Off on
	all subprograms not yet proved.
	(Bad_Value): Annotate expected exception.
	(Normalize_String): Rewrite to avoid possible overflow when
	incrementing F in the first loop. Add loop invariants.
	* libgnat/s-valuti.ads: Mark in SPARK.
	(Bad_Value): Add Depends contract to avoid warning on unused S.
	(Only_Space_Ghost): New ghost function to query if string has
	only space in the specified range.
	(Normalize_String): Add functional contract.
	(Scan_Exponent): Mark spec as not in SPARK as this function has
	side-effects.
2021-12-02 16:26:19 +00:00
Pascal Obry
261d367a10 [Ada] Fix possible memory corruption for hostnames longer than 1024 bytes
gcc/ada/

	* libgnat/g-socket.ads (Max_Name_Length): Initialize with
	NI_MAXHOST.
2021-12-02 16:26:18 +00:00
Pascal Obry
0ef5185a15 [Ada] Minor style fix (no dot on single line comment)
gcc/ada/

	* libgnat/g-socket.ads: Minor style fix.
2021-12-02 16:26:17 +00:00
Vladimir N. Makarov
7d02c8bf75 [PR103437] Use long long multiplication as backup for overflow processing
__builtin_smul_overflow can be unavailable for some C++ compilers.
Add long long multiplication as backup for overflow processing.

gcc/ChangeLog:
	PR rtl-optimization/103437
	* ira-color.c (setup_allocno_priorities): Use long long
	multiplication as backup for overflow processing.
2021-12-02 11:00:56 -05:00
Iain Buclaw
a27940feff libphobos: Push all callee-save registers on the stack before GC scan on ARM
This is the library fix for PR103520 that also prevents the garbage
collector from releasing live memory.  However this requires that the
host compiler has been patched with this fix, so the GC will remain
disabled in the D front-end for now until enough time has passed for
this to have trickled down into enough releases.

libphobos/ChangeLog:

	* libdruntime/core/thread/osthread.d (callWithStackShell): Push all
	callee-save registers on the stack for AArch64 and ARM.
2021-12-02 15:41:27 +01:00
Tamar Christina
9b8830b6f3 AArch64: Optimize right shift rounding narrowing
This optimizes right shift rounding narrow instructions to
rounding add narrow high where one vector is 0 when the shift amount is half
that of the original input type.

i.e.

uint32x4_t foo (uint64x2_t a, uint64x2_t b)
{
  return vrshrn_high_n_u64 (vrshrn_n_u64 (a, 32), b, 32);
}

now generates:

foo:
        movi    v3.4s, 0
        raddhn  v0.2s, v2.2d, v3.2d
        raddhn2 v0.4s, v2.2d, v3.2d

instead of:

foo:
        rshrn   v0.2s, v0.2d, 32
        rshrn2  v0.4s, v1.2d, 32
        ret

On Arm cores this is an improvement in both latency and throughput.
Because a vector zero is needed I created a new method
aarch64_gen_shareable_zero that creates zeros using V4SI and then takes a subreg
of the zero to the desired type.  This allows CSE to share all the zero
constants.

gcc/ChangeLog:

	* config/aarch64/aarch64-protos.h (aarch64_gen_shareable_zero): New.
	* config/aarch64/aarch64-simd.md (aarch64_rshrn<mode>,
	aarch64_rshrn2<mode>): Generate rounding half-ing add when appropriate.
	* config/aarch64/aarch64.c (aarch64_gen_shareable_zero): New.

gcc/testsuite/ChangeLog:

	* gcc.target/aarch64/advsimd-intrinsics/shrn-1.c: New test.
	* gcc.target/aarch64/advsimd-intrinsics/shrn-2.c: New test.
	* gcc.target/aarch64/advsimd-intrinsics/shrn-3.c: New test.
	* gcc.target/aarch64/advsimd-intrinsics/shrn-4.c: New test.
2021-12-02 14:39:43 +00:00
Vladimir N. Makarov
d47393d0b4 [PR103437] Process multiplication overflow in priority calculation for allocno assignments
We process overflows in cost calculations but for huge functions
priority calculation can overflow as priority can be bigger the cost
used for it.  The patch fixes the problem.

gcc/ChangeLog:

	PR rtl-optimization/103437
	* ira-color.c (setup_allocno_priorities): Process multiplication
	overflow.
2021-12-02 08:51:53 -05:00
Tamar Christina
7d6c20c06c testsuite: make bic-bitmask-18.c test more precise [PR103479]
This updates the testcase bic-bitmask-18.c to seach for " = 0;" as an expression
so it doesn't match any other partial expressions.

gcc/testsuite/ChangeLog:

	PR testsuite/103479
	* gcc.dg/bic-bitmask-18.c: Update regexpr to expect = 0;.
2021-12-02 13:30:08 +00:00
Marek Polacek
9af081003f c++: Fix bogus error with __integer_pack [PR94490]
Here we issue a bogus:

error: '(0 ? fake_tuple_size_v<int> : fake_tuple_size_v<int>)' is not a constant expression

because cxx_constant_value in expand_integer_pack gets

*(0 ? VIEW_CONVERT_EXPR<const int>(fake_tuple_size_v) : VIEW_CONVERT_EXPR<const int>(fake_tuple_size_v))

which is a REFERENCE_REF_P and we evaluate its operand to 3, so we end
up with *3 and that fails.  Sounds like we need to get rid of the
REFERENCE_REF_P then.  That is what tsubst_copy_and_build/INDIRECT_REF
will do:

        if (REFERENCE_REF_P (t))
          {
            /* A type conversion to reference type will be enclosed in
               such an indirect ref, but the substitution of the cast
               will have also added such an indirect ref.  */
            r = convert_from_reference (r);
          }

so I think it's reasonable to call instantiate_non_dependent_expr_sfinae.

	PR c++/94490

gcc/cp/ChangeLog:

	* pt.c (expand_integer_pack): Call
	instantiate_non_dependent_expr_sfinae.

gcc/testsuite/ChangeLog:

	* g++.dg/ext/integer-pack5.C: New test.
2021-12-02 08:21:24 -05:00
Martin Liska
cde87638bf Implement -fprofile-prefix-map.
PR gcov-profile/96092

gcc/ChangeLog:

	* common.opt: New option.
	* coverage.c (coverage_begin_function): Emit filename with
	remap_profile_filename.
	* doc/invoke.texi: Document the new option.
	* file-prefix-map.c (add_profile_prefix_map): New.
	(remap_profile_filename): Likewise.
	* file-prefix-map.h (add_profile_prefix_map): Likewise.
	(remap_profile_filename): Likewise.
	* lto-opts.c (lto_write_options): Handle
	OPT_fprofile_prefix_map_.
	* opts-global.c (handle_common_deferred_options): Likewise.
	* opts.c (common_handle_option): Likewise.
	(gen_command_line_string): Likewise.
	* profile.c (output_location): Emit filename with
	remap_profile_filename.
2021-12-02 14:13:09 +01:00
Marek Polacek
6f43a8a080 c++: ICE with unnamed tparm and concept [PR103408]
Here we crash when issuing the "constraint C has type T, not bool"
error, because pp_cxx_parameter_mapping wasn't prepared to see an
anonymous template parameter.  With this patch we print

error: constraint 'auto(<lambda>) [with <unnamed> = 0]' has type '<lambda()>', not 'bool'

The "<unnamed>" is what this patch adds.

	PR c++/103408

gcc/cp/ChangeLog:

	* cxx-pretty-print.c (pp_cxx_parameter_mapping): Print "<unnamed>"
	rather than crash on an unnamed template parameter.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp23/concepts-err1.C: New test.
2021-12-02 08:11:39 -05:00
Richard Biener
06b8cdc8d7 middle-end/103271 - avoid VLA init of register
This avoids using VLA types to initalize a register with
-ftrivial-auto-var-init in some cases.

2021-12-02  Richard Biener  <rguenther@suse.de>

	PR middle-end/103271
	* internal-fn.c (expand_DEFERRED_INIT): When the base
	of the LHS is a decl with matching constant size use
	that as the initialization target instead of an
	eventual VLA typed one.
2021-12-02 13:35:19 +01:00
Richard Biener
70ece2d4ca tree-optimization/103527 - always use thruth type forgather mask
This makes sure to always use a truth type to build the gather
mask argument even when the target builtin prototype in the end
wants a float vector.

2021-12-02  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/103527
	* tree-vect-stmts.c (vect_build_gather_load_calls): Always
	use a truth type for building the vector mask.
2021-12-02 13:32:11 +01:00
Rasmus Villemoes
1ea226fad1 fix spelling of -linker-output-auto-nolto-rel
The transposition nolto -> notlo is confusing and it makes the long
name even harder to read than it already is - I kept reading it as
"not lo" until I realized it was a simple typo.

Fixes: 5269b24605 (Silence warning in LTO mode on VxWorks)

lto-plugin/
	* lto-plugin.c: Fix -linker-output-auto-notlo-rel ->
	-linker-output-auto-nolto-rel typo.
	(process_option): Adjust accordingly, accepting both old and
	new spelling.

gcc/
	* config/vxworks.h (LTO_PLUGIN_SPEC): Adapt to corrected
	spelling of -linker-output-auto-nolto-rel.
2021-12-02 12:52:24 +01:00
Chung-Lin Tang
1ac7a8c9e4 fortran: OpenMP/OpenACC array mapping alignment fix (PR90030)
Fix issue with the Fortran front-end when mapping arrays: when creating the
data MEM_REF for the map clause, there was a convention of casting the
referencing pointer to 'c_char *' by
fold_convert (build_pointer_type (char_type_node), ptr).

This causes the alignment passed to the libgomp runtime for array data
hardwared to '1', and causes alignment errors on the offload target.

This patch fixes this by removing the char_type_node pointer converts, and
adding gcc_asserts to ensure POINTER_TYPE_P (TREE_TYPE (ptr)).

	PR fortran/90030

gcc/fortran/ChangeLog:

	* trans-openmp.c (gfc_omp_finish_clause): Remove fold_convert to pointer
	to char_type_node, add gcc_assert of POINTER_TYPE_P.
	(gfc_trans_omp_array_section): Likewise.
	(gfc_trans_omp_clauses): Likewise.

gcc/testsuite/ChangeLog:

	* gfortran.dg/goacc/finalize-1.f: Adjust scan test.
	* gfortran.dg/gomp/affinity-clause-1.f90: Likewise.
	* gfortran.dg/gomp/affinity-clause-5.f90: Likewise.
	* gfortran.dg/gomp/defaultmap-4.f90: Likewise.
	* gfortran.dg/gomp/defaultmap-5.f90: Likewise.
	* gfortran.dg/gomp/defaultmap-6.f90: Likewise.
	* gfortran.dg/gomp/map-3.f90: Likewise.
	* gfortran.dg/gomp/pr78260-2.f90: Likewise.
	* gfortran.dg/gomp/pr78260-3.f90: Likewise.

libgomp/ChangeLog:

	* testsuite/libgomp.oacc-fortran/pr90030.f90: New test.
	* testsuite/libgomp.fortran/pr90030.f90: New test.
2021-12-02 18:27:16 +08:00
Iain Buclaw
1c5317d621 libphobos: Add missing ControlState variable for AArch64
Fixes a typo that occurred during the splitting of the std.math module
into a package.

libphobos/ChangeLog:

	* src/std/math/hardware.d (FloatingPointControl.getControlState): Add
	missing ControlState variable for AArch64.
2021-12-02 01:46:55 +01:00
Iain Buclaw
fa10faa72d d: Disable the D runtime garbage collector after initializing (PR103520)
Not all targets that support building libdruntime have a stable garbage
collector, so to avoid running into problems where live memory allocated
by the D GC is freed, disable all in-flight collections until a time
when scanning is more reliably implemented everywhere.

	PR d/103520

gcc/d/ChangeLog:

	* d-frontend.h (gc_disable): Declare.
	* d-lang.cc (d_init_options): Disable the D runtime garbage collector
	after initializing.
2021-12-02 01:46:07 +01:00
Iain Buclaw
12421a3645 d: Prefix object files from the root package with 'root-'
None of the front-end module names in either the dmd or root package
collide just yet, but that does not mean they won't in the future.

gcc/d/ChangeLog:

	* Make-lang.in (D_FRONTEND_OBJS): Prefix object files from the root
	package with root-.
	(d/root-%.o): New recipe.
2021-12-02 01:45:00 +01:00
GCC Administrator
40fa651e60 Daily bump. 2021-12-02 00:16:33 +00:00
David Malcolm
860c56b5bc analyzer: fix false leak seen in Juliet 1.3 [PR102471]
Juliet 1.3's CWE415_Double_Free__malloc_free_*_67a.c
were showing leak false positives in non-LTO builds; fixed thusly.

gcc/analyzer/ChangeLog:
	PR analyzer/102471
	* region-model-reachability.cc (reachable_regions::handle_parm):
	Treat all svalues within a compound parm has reachable, and those
	wrapped in a cast.

gcc/testsuite/ChangeLog:
	PR analyzer/102471
	* gcc.dg/analyzer/leak-3.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2021-12-01 18:20:34 -05:00
Uros Bizjak
7eb961d83b i386: Improve V8HI and V8HF inserts [PR102811]
Introduce vec_set_0 pattern for V8HI and V8HF modes to implement scalar
element 0 inserts to from a GP register, SSE register or memory.  Also
add V8HI and V8HF AVX2 (x,x,x) alternative to PINSR insn pattern, which is
split after reload to a sequence of PBROADCASTW and PBLENDW.

The V8HF inserts from memory improve from:

-       vpbroadcastw    4(%esp), %xmm1
-       vpblendw        $16, %xmm1, %xmm0, %xmm0
+       vpinsrw $4, 4(%esp), %xmm0, %xmm0

and V8HF inserts from SSE register to element 0 improve from:

        vpxor   %xmm2, %xmm2, %xmm2
-       vpbroadcastw    %xmm0, %xmm0
        vpblendw        $1, %xmm0, %xmm2, %xmm0

Based on the above improvements, the register allocator is able to determine
the optimal instruction (or instruction sequence) based on the register set
of the input value, so there is no need to manually expand V8HI and V8HF
inserts to the sequence of VEC_DUPLICATE and VEC_MERGE RTXes.

2021-12-01  Uroš Bizjak  <ubizjak@gmail.com>

gcc/ChangeLog:

	PR target/102811
	* config/i386/sse.md (VI2F): Remove mode iterator.
	(VI2F_256_512): New mode iterator.
	(vec_set<V8_128:mode>_0): New insn pattern.
	(vec_set<VI2F_256_512:mode>_0>): Rename from vec_set<VI2F:mode>mode.
	Use VI2F_256_512 mode iterator instead of VI2F.
	(*axv512fp16_movsh): Remove.
	(<sse2p4_1>_pinsr<ssemodesuffix>): Add (x,x,x) AVX2 alternative.
	Do not disable V8HF mode insn on AVX2 targets.
	(pinsrw -> pbroadcast + pblendw peephole2): New peephole.
	(pinsrw -> pbroadcast + pblendw splitter): New post-reload splitter.
	* config/i386/i386.md (extendhfsf): Call gen_vec_setv8hf_0.
	* config/i386/i386-expand.c (ix86_expand_vector_set)
	<case E_V8HFmode>: Use vec_merge path for TARGET_AVX2.

gcc/testsuite/ChangeLog:

	PR target/102881
	* gcc.target/i386/pr102811-1.c: New test.
	* gcc.target/i386/avx512fp16-1c.c (dg-final): Update
	scan-assembler-times scan strings for ia32 targets.
	* gcc.target/i386/pr102327-1.c (dg-final): Ditto.
	* gcc.target/i386/pr102811.c: Rename from ...
	* gcc.target/i386/avx512vl-vcvtps2ph-pr102811.c: ... this.
2021-12-01 23:03:42 +01:00
Roger Sayle
de3e5aae6c Final value replacement improvements for until-wrap loops.
This middle-end patch is inspired by the Richard Beiner's until-wrap
loop example in PR tree-optimization/101145.

unsigned foo(unsigned val, unsigned start)
{
  unsigned cnt = 0;
  for (unsigned i = start; i > val; ++i)
    cnt++;
  return cnt;
}

For this loop, the tree optimizers currently generate:

unsigned int foo (unsigned int val, unsigned int start)
{
  unsigned int cnt;
  unsigned int _1;
  unsigned int _5;

  <bb 2> [local count: 118111600]:
  if (start_3(D) > val_4(D))
    goto <bb 3>; [89.00%]
  else
    goto <bb 4>; [11.00%]

  <bb 3> [local count: 105119324]:
  _1 = start_3(D) + 1;
  _5 = -start_3(D);
  cnt_2 = _1 > val_4(D) ? _5 : 1;

  <bb 4> [local count: 118111600]:
  # cnt_11 = PHI <cnt_2(3), 0(2)>
  return cnt_11;
}

or perhaps slightly easier to read:

  if (start > val) {
    cnt = (start+1) > val ? -start : 1;
  } else cnt = 0;

In this snippet, if we know start > val, then (start+1) > val
unless start+1 overflows, i.e. (start+1) == 0 and start == ~0.
We can use this (loop header) context to simplify the ternary
expression to "(start != -1) ? -start : 1", which with a little
help from match.pd can be folded to -start.  Hence the optimal
final value replacement should be:

  cnt = (start > val) ? -start : 0;

Or as now generated by this patch:

unsigned int foo (unsigned int val, unsigned int start)
{
  unsigned int cnt;

  <bb 2> [local count: 118111600]:
  if (start_3(D) > val_4(D))
    goto <bb 3>; [89.00%]
  else
    goto <bb 4>; [11.00%]

  <bb 3> [local count: 105119324]:
  cnt_2 = -start_3(D);

  <bb 4> [local count: 118111600]:
  # cnt_11 = PHI <cnt_2(3), 0(2)>
  return cnt_11;
}

We can also improve until-wrap loops that don't have a (suitable) loop
header, as determined by simplify_using_initial_conditions.

unsigned bar(unsigned val, unsigned start)
{
  unsigned cnt = 0;
  unsigned i = start;
  do {
    cnt++;
    i++;
  } while (i > val);
  return cnt;
}

which is currently optimized to:

unsigned int foo (unsigned int val, unsigned int start)
{
  unsigned int cnt;
  unsigned int _9;
  unsigned int _10;

  <bb 2> [local count: 118111600]:
  _9 = start_4(D) + 1;
  _10 = -start_4(D);
  cnt_3 = val_7(D) < _9 ? _10 : 1;
  return cnt_3;
}

Here we have "val < (start+1) ? -start : 1", which again with the
help of match.pd can be slightly simplified to "val <= start ? -start : 1"
when dealing with unsigned types, because at the complicating value where
start == ~0, we fortunately have -start == 1, hence it doesn't matter
whether the second or third operand of the ternary operator is returned.

To summarize, this patch (in addition to tweaking may_be_zero in
number_of_iterations_until_wrap) adds three new constant folding
transforms to match.pd.

X != C1 ? -X : C2 simplifies to -X when -C1 == C2.
which is the generalized form of the simplification above.

X != C1 ? ~X : C2 simplifies to ~X when ~C1 == C2.
which is the BIT_NOT_EXPR analog of the NEGATE_EXPR case.

and the "until-wrap final value replacement without context":

(X + 1) > Y ? -X : 1 simplifies to X >= Y ? -X : 1 when
X is unsigned, as when X + 1 overflows, X is -1, so -X == 1.

2021-12-01  Roger Sayle  <roger@nextmovesoftware.com>
	    Richard Biener  <rguenther@suse.de>

gcc/ChangeLog
	* tree-ssa-loop-niter.c (number_of_iterations_until_wrap):
	Check if simplify_using_initial_conditions allows us to
	simplify the expression for may_be_zero.
	* match.pd (X != C ? -X : -C -> -X): New transform.
	(X != C ? ~X : ~C -> ~X): Likewise.
	((X+1) > Y ? -X : 1 -> X >= Y ? -X : 1): Likewise.

gcc/testsuite/ChangeLog
	* gcc.dg/fold-condneg-1.c: New test case.
	* gcc.dg/fold-condneg-2.c: New test case.
	* gcc.dg/fold-condnot-1.c: New test case.
	* gcc.dg/pr101145-1.c: New test case.
	* gcc.dg/pr101145-2.c: New test case.
2021-12-01 19:58:40 +00:00
Peter Bergner
5b1ef8b9db middle-end: Skip initialization of opaque type variables [PR103127]
For -ftrivial-auto-var-init=*, skip initializing the variable if it is an
opaque type, because CONST0_RTX(mode) is not defined for opaque modes.

2021-12-01  Peter Bergner  <bergner@linux.ibm.com>

gcc/
	PR middle-end/103127
	* gimplify.c (is_var_need_auto_init): Handle opaque types.

gcc/testsuite/
	PR middle-end/103127
	* gcc.target/powerpc/pr103127.c: New test.
2021-12-01 13:22:36 -06:00
Iain Buclaw
185b307b03 darwin, d: Support outfile substitution for libphobos
In the gdc driver, this takes the previous fix for the Darwin D
bootstrap, and extends it to the -static-libphobos option as well.
Rather than pushing the -static-libphobos option back onto the command
line, the setting of SKIPOPT is instead conditionally removed.  The same
change has been repeated for -static-libstdc++ so there is now no need
to call generate_option to re-add it.

In the gcc driver, -static-libphobos has been added as a common option,
validated, and a new outfile substition added to config/darwin.h to
correctly replace -lgphobos with libgphobos.a.

gcc/ChangeLog:

	* common.opt (static-libphobos): Add option.
	* config/darwin.h (LINK_SPEC): Substitute -lgphobos with libgphobos.a
	when linking statically.
	* gcc.c (driver_handle_option): Set -static-libphobos as always valid.

gcc/d/ChangeLog:

	* d-spec.cc (lang_specific_driver): Set SKIPOPT on -static-libstdc++
	and -static-libphobos only when target supports LD_STATIC_DYNAMIC.
	Remove generate_option to re-add -static-libstdc++.

libphobos/ChangeLog:

	* testsuite/testsuite_flags.in: Add libphobos library directory as
	search path to --gdcldflags.
2021-12-01 19:49:44 +01:00
Jason Merrill
53caa4723d c++: constexpr, fold, weak redecl, fp/0 [PR103310]
For PR61825, honza changed tree_single_nonzero_warnv_p to prevent a later
declaration from marking a function as weak after we've determined that it
wasn't weak before.  But we shouldn't do that for speculative folding; we
should only do it when we actually need a constant value.  In C++, such a
context is called "manifestly constant-evaluated".  In fold, this seems to
correspond to the folding_initializer flag, since in C this situation only
occurs in static initializers.

This change makes nonzero-1.c well-formed; I've added a nonzero-1a.c to
verify that we delete the null check eventually if there is no weak
redeclaration.

The varasm.c change is so that if we do get the weak redeclaration error, we
get it at the position of the weak declaration rather than the previous
declaration.

Using the FOLD_INIT paths also affects floating point arithmetic: notably,
this makes floating point division by zero in a manifestly
constant-evaluated context constant, as in a C static initializer.  I've had
some success convincing CWG that this is the right direction; C++ should
follow C's floating point semantics more than we have been doing, and Joseph
says that the C policy is that Annex F overrides other parts of the standard
that say that some operations are undefined.  But since we're in stage 3,
I'm only making this change with the new flag -fconstexpr-fp-except.  It may
turn on by default in a future release.

I think this distinction is only relevant for binary operations; arithmetic
for the floating point case, comparison for possibly non-zero addresses.

	PR c++/103310

gcc/ChangeLog:

	* fold-const.c (maybe_nonzero_address): Use get_create or get
	depending on folding_initializer.
	(fold_binary_initializer_loc): New.
	* fold-const.h (fold_binary_initializer_loc): Declare.
	* varasm.c (mark_weak): Don't use the decl location.
	* doc/invoke.texi: Document -fconstexpr-fp-except.

gcc/c-family/ChangeLog:

	* c.opt: Add -fconstexpr-fp-except.

gcc/cp/ChangeLog:

	* constexpr.c (cxx_eval_binary_expression): Use
	fold_binary_initializer_loc if manifestly cxeval.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp0x/constexpr-fp-except1.C: New test.
	* g++.dg/cpp1z/constexpr-if36.C: New test.
	* gcc.dg/tree-ssa/nonzero-1.c: Now well-formed.
	* gcc.dg/tree-ssa/nonzero-1a.c: New test.
2021-12-01 13:24:36 -05:00
Bill Schmidt
d683a1b3e8 rs6000: Mirror fix for PR102347 in new builtins support
Recently Kewen fixed a problem in the old builtins support where
rs6000_builtin_decl prematurely indicated that a target builtin is
unavailable.  This also needs to be done for the new builtins support, but in
this case we have to ensure the error message is still produced from the
overload support in rs6000-c.c.  Unfortunately, this is less straightforward
than it could be, because header file includes need to be adjusted to make this
happen.  Someday we'll consolidate all the builtin code in one file and this
won't have to be so ugly.

2021-12-01  Bill Schmidt  <wschmidt@linux.ibm.com>

gcc/
	PR target/102347
	* config/rs6000/rs6000-c.c (rs6000-builtins.h): Stop including.
	(rs6000-internal.h): Include.
	(altivec_resolve_new_overloaded_builtin): Move call to
	rs6000_invalid_new_builtin here from rs6000_new_builtin_decl.
	* config/rs6000/rs6000-call.c (rs6000-builtins.h): Stop including.
	(rs6000_invalid_new_builtin): Remove static qualifier.
	(rs6000_new_builtin_decl): Remove test for supported builtin.
	* config/rs6000/rs6000-internal.h (rs6000-builtins.h): Include.
	(rs6000_invalid_new_builtin): Declare.
	* config/rs6000/rs6000.c (rs6000-builtins.h): Don't include.
2021-12-01 12:17:22 -06:00
Aldy Hernandez
54ebec35ab path solver: Use only one ssa_global_cache.
We're using a temporary range cache while computing ranges for PHIs to
make sure the real cache doesn't get set until all PHIs are computed.
With the ltrans beast in LTO mode this causes undue overhead.

Since we already have a bitmap to indicate whether there's a cache
entry, we can avoid the extra cache object by clearing it while PHIs
are being calculated.

gcc/ChangeLog:

	PR tree-optimization/103409
	* gimple-range-path.cc (path_range_query::compute_ranges_in_phis):
	Do all the work with just one ssa_global_cache.
	* gimple-range-path.h: Remove m_tmp_phi_cache.
2021-12-01 17:11:12 +01:00
Jonathan Wakely
056551414a libstdc++: Clear RB tree after moving elements [PR103501]
If the allocator-extended move constructor move-constructs each element
into the new container, the contents of the old container are left in
moved-from states. We cannot know if those states preserve the
container's ordering and uniqueness guarantees, so just erase all
moved-from elements.

libstdc++-v3/ChangeLog:

	PR libstdc++/103501
	* include/bits/stl_tree.h (_Rb_tree(_Rb_tree&&, false_type)):
	Clear container if elements have been moved-from.
	* testsuite/23_containers/map/allocator/move_cons.cc: Expect
	moved-from container to be empty.
	* testsuite/23_containers/multimap/allocator/move_cons.cc:
	Likewise.
	* testsuite/23_containers/multiset/allocator/103501.cc: New test.
	* testsuite/23_containers/set/allocator/103501.cc: New test.
2021-12-01 15:00:33 +00:00
Jonathan Wakely
74d14778e7 libstdc++: Define std::__is_constant_evaluated() for internal use
This adds std::__is_constant_evaluated() as a C++11 wrapper for
__builtin_is_constant_evaluated, but just returning false if the
built-in isn't supported by the compiler. This allows us to use it
throughout the library without checking __has_builtin every time.

Some uses in std::vector and std::string can only be constexpr when the
std::is_constant_evaluated() function actually works, so we might as
well guard them with a relevant macro and call that function directly,
rather than the built-in or std::__is_constant_evaluated().

The remaining checks of the __cpp_lib_is_constant_evaluated macro could
now be replaced by checking __cplusplus >= 202002 instead, but there's
no practical difference. We still need some kind of preprocessor check
there anyway.

libstdc++-v3/ChangeLog:

	* doc/doxygen/user.cfg.in (PREDEFINED): Change macro name.
	* include/bits/allocator.h (allocate, deallocate): Use
	std::__is_constant_evaluated() unconditionally, instead of
	checking whether std::is_constant_evaluated() (or the built-in)
	can be used.
	* include/bits/basic_string.h: Check new macro. call
	std::is_constant_evaluated() directly in C++20-only code that is
	guarded by a suitable macro.
	* include/bits/basic_string.tcc: Likewise.
	* include/bits/c++config (__is_constant_evaluated): Define.
	(_GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED): Replace with ...
	(_GLIBCXX_HAVE_IS_CONSTANT_EVALUATED): New macro.
	* include/bits/char_traits.h (char_traits): Replace conditional
	calls to std::is_constant_evaluated with unconditional calls to
	std::__is_constant_evaluated.
	* include/bits/cow_string.h: Use new macro.
	* include/bits/ranges_algobase.h (__copy_or_move): Replace
	conditional calls to std::is_constant_evaluated with unconditional
	calls to std::__is_constant_evaluated.
	(__copy_or_move_backward, __fill_n_fn): Likewise.
	* include/bits/ranges_cmp.h (ranges::less): Likewise.
	* include/bits/stl_algobase.h (lexicographical_compare_three_way):
	Likewise.
	* include/bits/stl_bvector.h: Call std::is_constant_evaluated
	directly in C++20-only code that is guarded by a suitable macro.
	* include/bits/stl_construct.h (_Construct, _Destroy, _Destroy_n):
	Replace is_constant_evaluated with __is_constant_evaluated.
	* include/bits/stl_function.h (greater, less, greater_equal)
	(less_equal): Replace __builtin_is_constant_evaluated and
	__builtin_constant_p with __is_constant_evaluated.
	* include/bits/stl_vector.h: Call std::is_constant_evaluated()
	in C++20-only code.
	* include/debug/helper_functions.h (__check_singular): Use
	__is_constant_evaluated instead of built-in, or remove check
	entirely.
	* include/std/array (operator<=>): Use __is_constant_evaluated
	unconditionally.
	* include/std/bit (__bit_ceil): Likewise.
	* include/std/type_traits (is_constant_evaluated): Define using
	'if consteval' if possible.
	* include/std/version: Use new macro.
	* libsupc++/compare: Use __is_constant_evaluated instead of
	__builtin_is_constant_evaluated.
	* testsuite/23_containers/array/tuple_interface/get_neg.cc:
	Adjust dg-error lines.
2021-12-01 15:00:33 +00:00
Jonathan Wakely
2b83bc6097 libstdc++: Optimize ref-count updates in COW std::string
Most ref-count updates in the COW string are done via the functions in
<ext/atomicity.h>, which will use non-atomic ops when the program is
known to be single-threaded. The _M_is_leaked() and _M_is_shared()
functions use __atomic_load_n directly, because <ext/atomicity.h>
doesn't provide a load operation. Those functions can check the
__is_single_threaded() predicate to avoid using __atomic_load_n when not
needed.

The move constructor for the fully-dynamic-string increments the
ref-count by either 2 or 1, for leaked or non-leaked strings
respectively. That can be changed to use a non-atomic store of 1 for all
non-shared strings. It can be non-atomic because even if the program is
multi-threaded, conflicting access to the rvalue object while it's being
moved from would be data race anyway. It can store 1 directly for all
non-shared strings because it doesn't matter whether the initial
refcount was -1 or 0, it should be 1 after the move constructor creates
a second owner.

libstdc++-v3/ChangeLog:

	* include/bits/cow_string.h (basic_string::_M_is_leaked): Use
	non-atomic load when __is_single_threaded() is true.
	(basic_string::_M_is_shared): Likewise.
	(basic_string::(basic_string&&)) [_GLIBCXX_FULLY_DYNAMIC_STRING]:
	Use non-atomic store when rvalue is not shared.
2021-12-01 15:00:33 +00:00
Jonathan Wakely
e9089e4fa9 libstdc++: Avoid unwanted allocations in filesystem::path
When using COW strings, accessing _M_pathname[0] and similar non-const
accessors can cause the string to "leak", meaning it reallocates itself
if it shares ownership with another string object.

This causes test failures for --enable-fully-dynamic-string builds:
/home/jwakely/src/gcc/libstdc++-v3/testsuite/experimental/filesystem/path/construct/90634.cc:62: void test01(): Assertion 'bytes_allocated == 0' failed.
FAIL: experimental/filesystem/path/construct/90634.cc execution test

This FAIL happens because the fully-dynamic move constructor results in
shared ownership, so for path(std::move(std::string("foo"))) the
_M_pathname member shares ownership with the temporary, and the
non-const accesses in _M_split_cmpts() cause a new copy of the string to
be allocated. This un-sharing is wasteful, and entirely unnecessary when
sharing ownership with an rvalue that is about to release its ownership
anyway. Even for lvalues, sharing ownership is not a problem and
reallocating a unique copy of the string is wasteful.

This removes non-const accesses of _M_pathname in the
path::_M_split_cmpts() members.

libstdc++-v3/ChangeLog:

	* src/c++17/fs_path.cc (path::_M_split_cmpts()): Remove
	micro-optimization for "/" path.
	* src/filesystem/path.cc (path::_M_split_cmpts()): Only access
	the contents of _M_pathname using const member functions.
2021-12-01 15:00:32 +00:00
Richard Sandiford
1e625a44f6 vect: Tighten check for SLP memory groups [PR103517]
When checking for compatible stmts, vect_build_slp_tree_1 did:

	       && !(STMT_VINFO_GROUPED_ACCESS (stmt_info)
		    && (first_stmt_code == ARRAY_REF
			|| first_stmt_code == BIT_FIELD_REF
			|| first_stmt_code == INDIRECT_REF
			|| first_stmt_code == COMPONENT_REF
			|| first_stmt_code == MEM_REF)))

That is, it allowed any rhs_code as long as the first_stmt_code
looked valid.  This had the effect of allowing IFN_MASK_LOAD
to be paired with an earlier non-call code (but didn't allow
the reverse).

This patch makes the check symmetrical.

gcc/
	PR tree-optimization/103517
	* tree-vect-slp.c (vect_build_slp_tree_1): When allowing two
	different component references, check the codes of both them,
	rather than just the first.

gcc/testsuite/
	PR tree-optimization/103517
	* gcc.dg/vect/pr103517.c: New test.
2021-12-01 14:36:24 +00:00
Andrew MacLeod
cb137e8572 Also pre-process PHIs in range-of-stmt.
PR tree-optimization/103464
	* gimple-range.cc (gimple_ranger::prefill_name): Process phis also.
	(gimple_ranger::prefill_stmt_dependencies): Ditto.
2021-12-01 09:10:41 -05:00
Alex Coplan
a7fede6704 testsuite: Fix typo in comment in aapcs64 test
gcc/testsuite/ChangeLog:

	* gcc.target/aarch64/aapcs64/macro-def.h (PTR): Fix typo in
	comment.
2021-12-01 13:59:32 +00:00
Iain Buclaw
d376b73aa1 doc, d: Add note that D front end now requires GDC installed in order to bootstrap.
gcc/ChangeLog:

	* doc/install.texi (Prerequisites): Add note that D front end now
	requires GDC installed in order to bootstrap.
	(Building): Add D compiler section, referencing prerequisites.
2021-12-01 11:56:37 +01:00
Iain Buclaw
47fe7be66e d: Update documentation of new D language options.
Adds documentation for the following:

    - New switch that controls what code is generated on a contract
      failure (throw or abort).
    - New switch that controls mangling of D types in `extern(C++)`
      code, as well as setting the compile-time value of
      `__traits(getTargetInfo "cppStd")`
    - New switches that generate C++ headers from D source files.
    - New switch to save expanded mixins to a file.
    - New switches that now distinguish between D language changes that
      are either (a) an experimental feature or an upcoming breaking
      change, (b) a warning or help on an upcoming change, or (c) revert
      of a change for users who don't want to deal with the breaking
      change for now.

gcc/d/ChangeLog:

	* gdc.texi (Runtime Options): Document -fcheckaction=, -fextern-std=,
	-fpreview=, -frevert=.
	(Code Generation): Document -fdump-c++-spec=, -fdump-c++-spec-verbose,
	-fsave-mixins=.
	(Warnings): Update list of supported -ftransitions=.
2021-12-01 11:56:37 +01:00
Eric Botcazou
82a7daa31a [Ada] Fix incorrect fixed-point computation in expression function
gcc/ada/

	* einfo.ads (E_Decimal_Fixed_Point_Subtype): Fix pasto.
	* freeze.adb (Freeze_Fixed_Point_Type): Retrieve the underlying type
	of the first subtype and do not use a stale value of Small_Value.
	* sem_res.adb (Resolve_Real_Literal): In the case of a fixed-point
	type, make sure that the base type is frozen and use its Small_Value
	to compute the corresponding integer value of the literal.
2021-12-01 10:24:43 +00:00
Piotr Trojanek
ba12deb955 [Ada] Tune whitespace of the bounded lists Aggregate aspect
gcc/ada/

	* libgnat/a-cbdlli.ads (List): Remove extra space in Aggregate
	aspect.
2021-12-01 10:24:43 +00:00
Gary Dismukes
38e7e9ac15 [Ada] Allow formal functions to have a default in the form of an expression function
gcc/ada/

	* doc/gnat_rm/implementation_defined_pragmas.rst: Add
	documentation of the new form of formal subprogram default in
	the section on language extensions (pragma Extensions_Allowed).
	* gnat_rm.texi: Regenerate.
	* gen_il-gen-gen_nodes.adb: Add Expression as a syntactic field
	of N_Formal_(Abstract|Concrete)_Subprogram_Declaration nodes.
	* par-ch12.adb (P_Formal_Subprogram_Declaration): Add parsing
	support for the new default of a parenthesized expression for
	formal functions. Issue an error when extensions are not
	allowed, suggesting use of -gnatX. Update comment with extended
	syntax for SUBPROGRAM_DEFAULT.
	* sem_ch12.adb (Analyze_Formal_Subprogram_Declaration): Issue an
	error when an expression default is given for an abstract formal
	function. When a default expression is present for a formal
	function, install the function's formals and preanalyze the
	expression.
	(Instantiate_Formal_Subprogram): Fix typo in RM paragraph in a
	comment.  When a formal function has a default expression,
	create a body for the function that will evaluate the expression
	and will be called when the default applies in an instantiation.
	The implicit function is marked as inlined and as having
	convention Intrinsic.
2021-12-01 10:24:43 +00:00