Kewen Lin [Wed, 11 May 2022 06:18:30 +0000 (01:18 -0500)]
rs6000: Fix constraint v with rs6000_constraints[RS6000_CONSTRAINT_v]
Currently we hardcode ALTIVEC_REGS for register constraint v and
RS6000_CONSTRAINT_v looks confusing, this is to fix it with
rs6000_constraints[RS6000_CONSTRAINT_v] to align with some other
existing register constraints with RS6000_CONSTRAINT_*.
gcc/ChangeLog:
* config/rs6000/constraints.md (register constraint v): Use
rs6000_constraints[RS6000_CONSTRAINT_v] instead of ALTIVEC_REGS.
Martin Liska [Tue, 26 Apr 2022 09:41:09 +0000 (11:41 +0200)]
opts: do not allow Separate+Joined ending with =
Do not allow strange option format:
-msmall-data-limit= 11.
For -output-pch we need to use Separate syntax as lang spec
rules automatically append a space.
PR target/105355
gcc/ChangeLog:
* config/riscv/riscv.opt: Remove Separate from
-msmall-data-limit=.
* optc-gen.awk: Report error for the described situation.
* gcc.cc: Use Separate syntax.
* opts.cc (gen_command_line_string): Change option name.
gcc/c-family/ChangeLog:
* c-opts.cc (c_common_handle_option): Change option name.
* c.opt: Remove Joined and use Separate option.
Harald Anlauf [Mon, 9 May 2022 20:14:21 +0000 (22:14 +0200)]
Fortran: check TEAM arguments to coarray intrinsics
TEAM arguments to coarray intrinsics must be scalar expressions of type
TEAM_TYPE of intrinsic module ISO_FORTRAN_ENV.
gcc/fortran/ChangeLog:
PR fortran/105526
* resolve.cc (check_team): New.
(gfc_resolve_code): Add checks for arguments to coarray intrinsics
FORM TEAM, CHANGE TEAM, and SYNC TEAM.
gcc/testsuite/ChangeLog:
PR fortran/105526
* gfortran.dg/coarray_50.f90: New test.
H.J. Lu [Fri, 6 May 2022 17:55:53 +0000 (10:55 -0700)]
x86: Add .note.GNU-stack section only for Linux
Add .note.GNU-stack section only for Linux since it may not be supported
on non-Linux OSes. __ELF__ isn't checked since these tests can only run
on Linux/x86 ELF systems.
Jakub Jelinek [Tue, 10 May 2022 16:34:08 +0000 (18:34 +0200)]
isel: Fix up gimple_expand_vec_set_expr [PR105528]
The following testcase ICEs (and only without -g), because we don't replace
one VEC_COND_EXPR with .VCOND* call.
We don't do that because gimple_expand_vec_set_expr adds some stmts before
*gsi and then uses gsi_remove to remove it. gsi_remove moves the iterator
to the next stmt and in the caller we then do gsi_next before looking at
another stmt, which means we can skip processing of one stmt, which in this
case happened to be a VEC_COND_EXPR but with -g is some debug stmt in
between. As we always emit some stmts before it, it is easy to update the
iterator to the last stmt emitted there, so that caller continues really
with the next stmt.
2022-05-10 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/105528
* gimple-isel.cc (gimple_expand_vec_set_expr): After gsi_remove
set *gsi to gsi_for_stmt (ass_stmt). Fix up function comment.
Unlike in C, in C++ the conditional operator yields an lvalue if both
branches are lvalues, so these setter macros are unnecessary; we can
just assign to PACK_EXPANSION_PATTERN and ARGUMENT_PACK_ARGS directly.
As at r2.2 of the RISC-V ISA specification[1] (equivalent to version 2.0
of the "F" and "D" standard architecture extensions for single-precision
and double-precision floating-point respectively) the FMIN and FMAX
machine instructions fully match our requirement for the `fminM3' and
`fmaxM3' standard RTL patterns:
"For FMIN and FMAX, if at least one input is a signaling NaN, or if both
inputs are quiet NaNs, the result is the canonical NaN. If one operand
is a quiet NaN and the other is not a NaN, the result is the non-NaN
operand."
suitably for the IEEE 754-2008 `minNum' and `maxNum' operations.
However we only define `sminM3' and `smaxM3' standard RTL patterns to
produce the FMIN and FMAX machine instructions, which in turn causes the
`__builtin_fmin' and `__builtin_fmax' family of intrinsics to emit the
corresponding libcalls rather than the relevant machine instructions.
This is according to earlier revisions of the RISC-V ISA specification,
which we however do not support anymore, as from commit 4b81528241ca
("RISC-V: Support version controling for ISA standard extensions").
As from r20190608 of the RISC-V ISA specification (equivalent to version
2.2 of the "F" and "D" standard ISA extensions for single-precision and
double-precision floating-point respectively) the definition of the FMIN
and FMAX machine instructions has been updated[2]:
"Defined the signed-zero behavior of FMIN.fmt and FMAX.fmt, and changed
their behavior on signaling-NaN inputs to conform to the minimumNumber
and maximumNumber operations in the proposed IEEE 754-201x
specification."
and specifically[3]:
"Floating-point minimum-number and maximum-number instructions FMIN.S
and FMAX.S write, respectively, the smaller or larger of rs1 and rs2 to
rd. For the purposes of these instructions only, the value -0.0 is
considered to be less than the value +0.0. If both inputs are NaNs, the
result is the canonical NaN. If only one operand is a NaN, the result
is the non-NaN operand. Signaling NaN inputs set the invalid operation
exception flag, even when the result is not NaN."
Consequently for forwards compatibility with r20190608+ hardware we
cannot use the FMIN and FMAX machine instructions unconditionally even
where the ISA level of r2.2 has been specified with the `-misa-spec=2.2'
option where operation would be different between ISA revisions, that
is the handling of signaling NaN inputs.
Therefore provide new `fmin<mode>3' and `fmax<mode>3' patterns removing
the need to emit libcalls with the `__builtin_fmin' and `__builtin_fmax'
family of intrinsics, however limit them to where `-fno-signaling-nans'
is in effect, deferring to other code generation strategies otherwise as
applicable. Use newly-defined UNSPECs as the operation codes so that
the patterns are only ever used if referred to by their names, as there
is no RTL expression defined for the IEEE 754-2008 `minNum' and `maxNum'
operations.
References:
[1] "The RISC-V Instruction Set Manual, Volume I: User-Level ISA",
Document Version 2.2, May 7, 2017, Section 8.3 "NaN Generation and
Propagation", p. 48
[1] "The RISC-V Instruction Set Manual, Volume I: Unprivileged ISA",
Document Version 20190608-Base-Ratified, June 8, 2019, "Preface",
p. ii
[2] same, Section 11.6 "Single-Precision Floating-Point Computational
Instructions", p. 66
gcc/
* config/riscv/riscv.md (UNSPEC_FMIN, UNSPEC_FMAX): New
constants.
(fmin<mode>3, fmax<mode>3): New insns.
gcc/testsuite/
* gcc.target/riscv/fmax-snan.c: New test.
* gcc.target/riscv/fmax.c: New test.
* gcc.target/riscv/fmaxf-snan.c: New test.
* gcc.target/riscv/fmaxf.c: New test.
* gcc.target/riscv/fmin-snan.c: New test.
* gcc.target/riscv/fmin.c: New test.
* gcc.target/riscv/fminf-snan.c: New test.
* gcc.target/riscv/fminf.c: New test.
* gcc.target/riscv/smax-ieee.c: New test.
* gcc.target/riscv/smax.c: New test.
* gcc.target/riscv/smaxf-ieee.c: New test.
* gcc.target/riscv/smaxf.c: New test.
* gcc.target/riscv/smin-ieee.c: New test.
* gcc.target/riscv/smin.c: New test.
* gcc.target/riscv/sminf-ieee.c: New test.
* gcc.target/riscv/sminf.c: New test.
Richard Biener [Tue, 10 May 2022 13:39:46 +0000 (15:39 +0200)]
Use gimple-match folding in fold_build_cond_expr
The following cleans up if-conversions fold_build_cond_expr to
use gimple-match folding instead of GENERIC folding.
2022-05-10 Richard Biener <rguenther@suse.de>
* tree-if-conv.cc (fold_build_cond_expr): Use
match-and-simplify to simplify the condition.
(ifcvt_follow_ssa_use_edges): Remove.
(predicate_scalar_phi): Use follow_all_ssa_edges.
Thomas Schwinge [Mon, 2 May 2022 13:15:26 +0000 (15:15 +0200)]
Make 'c-c++-common/goacc/kernels-decompose-pr100400-1-*.c' behave consistently, regardless of checking level
Fix-up for commit c14ea6a72fb1ae66e3d32ac8329558497c6e4403
"Catch 'GIMPLE_DEBUG' misbehavior in OpenACC 'kernels' decomposition
[PR100400, PR103836, PR104061]".
For C++ compilation of 'c-c++-common/goacc/kernels-decompose-pr100400-1-2.c',
we first emit a 'sorry' diagnostic, and then a 'gcc_unreachable' (or
'internal_error', see below) diagnostic, but for example, for
'--enable-checking=release' (thus, '!CHECKING_P'), the second one may actually
be turned into a 'confused by earlier errors, bailing out' diagnostic. (See
'gcc/diagnostic.cc:diagnostic_report_diagnostic': "When not checking, ICEs are
converted to fatal errors when an error has already occurred.") Thus, make
'c-c++-common/goacc/kernels-decompose-pr100400-1-2.c' behave consistently via
'-Wfatal-errors', and thus only matching the 'sorry' diagnostic.
For example, for '--enable-checking=no' (thus, '!ENABLE_ASSERT_CHECKING'), a
call to 'gcc_unreachable' cannot be assumed emit an 'internal_error'-like
diagnostic, so explicitly call 'internal_error' in
'gcc/omp-oacc-kernels-decompose.cc:visit_loops_in_gang_single_region', in the
'GIMPLE_OMP_FOR' case, to avoid regressing
'c-c++-common/goacc/kernels-decompose-pr100400-1-3.c', and
'c-c++-common/goacc/kernels-decompose-pr100400-1-4.c'.
Nathan Sidwell [Mon, 9 May 2022 11:40:43 +0000 (04:40 -0700)]
[c++] Disambiguate ModuleKind flags
In modules, 'attached to global module' nearly always means 'not in
module purview'. Also the implementation treats, 'in global module &&
in module purview' as meaning 'header unit'. The ModuleKind flags
reflected that. The 'nearly always' means there are cases that the
first condition is not invariant, and that of course invalidates the
second equivalence.
This disambiguates the ModuleKind flags to allow that 'not quite', and
separate out header-unitness from the GMF & purview flags combination.
1) Separate out named-module vs header-unit from the MODULE/GLOBAL flags.
2) Replace the MODULE/GLOBAL flags with PURVIEW & ATTACH flags.
3) Adjust the parser state handling.
Lays ground-work for language-declaration changes.
Richard Biener [Tue, 10 May 2022 09:44:40 +0000 (11:44 +0200)]
middle-end/105537 - debug processing
The following makes sure to have a consistent state of
flag_var_tracking_assignments with the distributed handling
in process_options and finish_options by moving everything to
finish_options which also restores diagnostics for
-g0 -fvar-tracking which was lost with previous changes.
Richard Biener [Tue, 10 May 2022 07:47:06 +0000 (09:47 +0200)]
Properly use opts in finish_options
When code was moved from process_options to finish_options it
was not properly adjusted to look at and alter the opts set
passed to the function but continued to modify the global options
set. The following rectifies this and makes sure the same
mistake isn't repeated by poisoning global_options{,_set}.
2022-05-10 Richard Biener <rguenther@suse.de>
* flags.h (dwarf_debuginfo_p): Add opts argument, guard
API with !GENERATOR_FILE.
* opts.cc (global_options): Poison.
(global_options_set): Likewise.
(finish_options): Refer to options via opts.
Roger Sayle [Tue, 10 May 2022 08:44:34 +0000 (09:44 +0100)]
Avoid andb %dil when optimizing for size.
The simple test case below has the unfortunate property that on x86_64,
it is larger when compiled with -Os than when compiled with -O2.
int foo(char x)
{
return (x & 123) != 0;
}
The issue is x86's complex instruction encoding, where andb $XX,%dil
requires more bytes than andl $XX,%edi. This patch adds logic to
i386.md's *testqi_1_maybe_si and *andqi_2_maybe_si define_insn patterns
to prefer the shorter SImode alternative when optimizing for size.
2022-05-10 Uroš Bizjak <ubizjak@gmail.com>
Roger Sayle <roger@nextmovesoftware.com>
gcc/ChangeLog
* config/i386/i386.md (*testqi_1_maybe_si): Prefer shorter SImode
alternative when optimizing for size and the immediate operand is
const_0_to_127_operand.
(*andqi_2_maybe_si): Likewise.
* config/i386/predicates.md (const_0_to_127_operand): New predicate.
gcc/testsuite/ChangeLog
* gcc.target/i386/and-1.c: New test case.
Roger Sayle [Tue, 10 May 2022 08:38:47 +0000 (09:38 +0100)]
Improved constant folding for scalar evolution.
This patch adds a small (follow-up) optimization to chrec_apply for
linear chrecs to clean-up the final value expressions sometimes generated
by GCC's scalar evolution pass. The transformation of A+(X-1)*A into
A*X is usually unsafe with respect to overflow (see PR92712), and so
can't be performed by match.pd (or fold-const). However, during scalar
evolution's evaluation of recurrences it's known that X-1 can't be negative
(in fact X-1 is unsigned even when A is signed), hence this optimization
can be applied. Interestingly, this expression does get simplified in
later passes once the range of X-1 is bounded by VRP, but that occurs
long after the decision of whether to perform final value replacement,
which is based on the complexity of this expression.
The motivating test case is the optimization of the loop (from comment
int square(int x) {
int result = 0;
for (int i = 0; i < x; ++i)
result += x;
return result;
}
which is currently optimized, with final value replacement to:
final value replacement:
with expr: (int) ((unsigned int) x_3(D) + 4294967295) * x_3(D) + x_3(D)
but with this patch it first gets simplified further:
final value replacement:
with expr: x_3(D) * x_3(D)
2022-05-10 Roger Sayle <roger@nextmovesoftware.com>
gcc/ChangeLog
* tree-chrec.cc (chrec_apply): Attempt to fold the linear chrec
"{a, +, a} (x-1)" as "a*x", as the number of loop iterations, x-1,
can't be negative.
gcc/testsuite/ChangeLog
* gcc.dg/tree-ssa/pr65855-2.c: New test case.
Validity checking of enumerations with nonstandard representation
starts by checking the value range, then calling _rep_to_pos to verify
that the value itself is valid. The value range check is thus
redundant and inefficient: the _rep_to_pos call is normally inlined
when optimizing for speed and the range check slows down the fast
path; it is unnecesary and undesirable when optimizing for size, and
just unnecessary when not optimizing. This patch thus drops the range
check for nonstandard boolean types.
gcc/ada/
* exp_attr.adb (Expand_N_Attribute_Reference) <Attribute_Valid>:
Drop redundant range check for nonstandard booleans.
Alexandre Oliva [Wed, 29 Dec 2021 07:10:46 +0000 (04:10 -0300)]
[Ada] Optimize nonstandard boolean conversions
This patch improves the generated code for nonstandard boolean types.
One of the improvements extends the code that avoids converting back
to the nonstandard boolean type an expression computed as standard
boolean, when it will be converted to a(nother) nonstandard boolean
type.
The other improvement involves using the literal representation
constants in an If_Expression instead of dereferencing the T'Val array
when converting to a (nonstandard) boolean type. Avoiding the array
dereference enables the compiler middle-end to propagate the constants
and perform optimizations based on them, to the point of obviating the
improvement above.
Unfortunately, the code generated with this alternate expansion tends
to be slightly larger if it turns out to not enable any further
optimization, though it's most certainly faster, especially on targets
with conditional moves, more so if "store flag" is slow, as on x86.
Still, the array dereference is more straightforward and shorter, so
I've arranged for this alternate expansion to be used only when
optimizing for speed.
gcc/ada/
* exp_util.adb (Adjust_Result_Type): Leave result in
Standard.Boolean if it's going to be converted to another
boolean type.
* exp_ch4.adb (Expand_N_Type_Conversion): When optimizing,
convert to nonstandard booleans with an if_expression with
boolean literals.
Alexandre Oliva [Wed, 29 Dec 2021 07:10:45 +0000 (04:10 -0300)]
[Ada] Handle non-standard booleans in if_expression condition
We failed to call Adjust_Condition for the condition expression of an
if_expression, so non-standard booleans were expanded like standard
booleans, disregarding representation clauses. Fixed.
gcc/ada/
* exp_ch4.adb (Expand_N_If_Expression): Call Adjust_Condition to
handle non-standard booleans.
Justin Squirek [Fri, 21 Jan 2022 17:09:29 +0000 (17:09 +0000)]
[Ada] Incorrect ineffective use type clause warning
This patch fixes an issue in the compiler whereby a use_type_clause
incorrectly gets flagged as ineffective when the use of it comes after a
generic package instantiation where the installation of private use
clauses are required and one such clause references the same type.
gcc/ada/
* sem_ch8.adb (Use_One_Type): Remove code in charge of setting
Current_Use_Clause when Id is known to be redundant, and modify
the printing of errors associated with redundant use type
clauses so that line number gets included in more cases.
Piotr Trojanek [Mon, 24 Jan 2022 11:19:19 +0000 (12:19 +0100)]
[Ada] Simplify call to overloaded Earlier_In_Extended_Unit
We have two variants of Earlier_In_Extended_Unit that take either
Node_Id or Source_Ptr values. The caller can simply use another variant
and not explicitly convert parameters.
Code cleanup; semantics is unaffected.
gcc/ada/
* sem_warn.adb (Check_Unset_Reference): Use variant of
Earlier_In_Extended_Unit that calls Sloc internally.
Piotr Trojanek [Thu, 20 Jan 2022 17:05:39 +0000 (18:05 +0100)]
[Ada] Remove repeated conversions between Source_Ptr and Int
Both Source_Ptr and Int are integer types (and even happen to have equal
ranges). Their values can be calculated without converting
back-and-forth, e.g.:
Int (Loc1) - Int (Loc2)
can be written simply as:
Int (Loc1 - Loc2)
Code cleanup related to handling of references to unset objects.
Offending occurrences found with various invocations of grep.
gcc/ada/
* par-ch10.adb, scng.adb, sem_res.adb, sinfo-utils.adb,
treepr.adb: Simplify calculations with Source_Ptr and Loc
values.
Piotr Trojanek [Thu, 20 Jan 2022 19:14:20 +0000 (20:14 +0100)]
[Ada] Cleanup detection of No_Elist with No and Present
Replace equality and inequality operators with calls to No and Present.
Offending occurrences found with:
$ grep -n " /\?= No_Elist" *.adb
Code cleanup only; semantics is unaffected.
gcc/ada/
* exp_ch11.adb, exp_ch5.adb, exp_prag.adb, gnat_cuda.adb,
sem_ch12.adb, sem_ch3.adb, sem_ch6.adb, sem_util.adb,
treepr.adb: Replace /= and = operators with No and Present,
respectively.
Piotr Trojanek [Thu, 20 Jan 2022 21:37:30 +0000 (22:37 +0100)]
[Ada] Remove tiny and incomplete optimization for unset references
Code cleanup; behaviour is unaffected.
gcc/ada/
* sem_warn.adb (Check_Unset_Reference): The early test was only
saving time of calls to Original_Node, Comes_From_Source and
Nkind, which are all quick and cheap.
Piotr Trojanek [Thu, 20 Jan 2022 19:12:52 +0000 (20:12 +0100)]
[Ada] Refine iteration from entities to formals
When matching formal parameters from spec and body it is cleaner and
more efficient to iterate with First_Formal/Next_Formal and not with
First_Entity/Next_Entity. The previous iteration could unintentionally
pick entities from within the subprogram body, e.g. objects declared
within the subprogram.
gcc/ada/
* sem_ch6.adb (Analyze_Subprogram_Body_Helper): Replace
First_Entity/Next_Entity with First_Formal/Next_Formal; rename
E1/E2 to F1/F2.
Piotr Trojanek [Sat, 22 Jan 2022 15:32:57 +0000 (16:32 +0100)]
[Ada] Check declare and qualified expressions for unset references
Detection of references to unset (uninitialized) objects requires calls
to Check_Unset_Reference on every subexpression of a composite statement
and expression. For declare and qualified expressions this was done only
when they occurred within another composite statement/expression.
gcc/ada/
* sem_res.adb (Resolve_Declare_Expression): Check expression for
references to unset objects.
(Resolve_Qualified_Expression): Likewise.
* sem_warn.adb (Check_Unset_Reference): Remove handling of
declare and qualified expressions; clarify comment for type
conversions.
Piotr Trojanek [Thu, 20 Jan 2022 23:33:06 +0000 (00:33 +0100)]
[Ada] Check if- and case-expressions for unset references
Detection of references to unset (uninitialized) objects requires calls
to Check_Unset_Reference on every subexpression of a composite statement
and expression. This was missing for if-expressions and incomplete for
case-expressions.
gcc/ada/
* sem_res.adb (Resolve_Case_Expression): Check alternative
expressions for references to unset objects.
(Resolve_If_Expression): Check condition, then and else
expressions for references to unset objects.
Claire Dross [Fri, 21 Jan 2022 09:42:49 +0000 (10:42 +0100)]
[Ada] Accept Structural in aspect Subprogram_Variant and pragma Loop_Variant
Add a new form of variants to ensure termination of loops or recursive
subprograms. Structural variants correspond to objects which designate a
part of the data-structure they used to designate in the previous loop
iteration or recursive call. They only imply termination if the
data-structure is acyclic, which is the case in SPARK but not in Ada in
general. The fact that these variants are correct is only verified
formally by the proof tool and not by the compiler or dynamically at
execution like other forms of variants.
gcc/ada/
* snames.ads-tmpl: Add "Structural" as a name.
* sem_prag.adb: (Analyze_Pragma): Accept modifier "Structural"
in pragmas Loop_Variant and Subprogram_Variant. Check that items
associated to Structural occur alone in the pragma associations.
(Analyze_Subprogram_Variant_In_Decl_Part): Idem.
* exp_prag.adb (Expand_Pragma_Loop_Variant): Discard structural
variants.
(Expand_Pragma_Subprogram_Variant): Idem.
Claire Dross [Thu, 20 Jan 2022 08:15:28 +0000 (09:15 +0100)]
[Ada] Proof of System.Val_Int at gold level
gcc/ada/
* libgnat/s-valint.ads: Add SPARK_Mode and pragma to ignore
assertions in instance and add additional ghost parameters to
the instance of Value_I.
* libgnat/s-vallli.ads: Idem.
* libgnat/s-valllli.ads: Idem.
* libgnat/s-valuei.ads, libgnat/s-valuei.adb: New generic
parameters for ghost functions from System.Valueu. Add
functional contracts.
Eric Botcazou [Thu, 13 Jan 2022 23:05:54 +0000 (00:05 +0100)]
[Ada] Fix hiding of user-defined operator that is not a homograph
This adds a missing test for the presence of a homograph when applying
the RM 8.4(10) clause about the visibility of operators, and removes
resolution code made obsolete by the change. There is also a fixlet
for a previously undetected ambiguity in the runtime.
Eric Botcazou [Sat, 22 Jan 2022 09:56:05 +0000 (10:56 +0100)]
[Ada] Fix oversight for case expression in Eval_Integer_Literal
The intent of the entry test is to treat conditional expressions, that is
to say if-expression and case-expression, alike and to require that a second
condition be true for them. But an N_Case_Expression_Alternative is not an
N_Subexpr so this second condition was short-circuited for this node.
gcc/ada/
* sem_eval.adb (Eval_Integer_Literal): Fix oversight in entry test.
Piotr Trojanek [Tue, 18 Jan 2022 20:24:32 +0000 (21:24 +0100)]
[Ada] Avoid repeated conversions from Int to Char_Code
When expanding aggregates like "(others => 'x')" into strings we
repeated conversion from Int to Char_Code for every character. Now we
convert once and use the Char_Code directly.
Cleanup related to handling characters in GNATprove counterexamples;
semantics is unaffected.
gcc/ada/
* exp_aggr.adb (Expand_N_Aggregate): Replace UI_To_Int with
UI_To_CC; replace magic literals with high-level routines that
recognise wide and wide wide characters; reorder if-then-elsif
condition, because we don't have a routine to detect wide wide
characters.
Etienne Servais [Tue, 18 Jan 2022 14:45:40 +0000 (15:45 +0100)]
[Ada] Reject numeric literals with too big exponents
While the compiler can compute numeric literal with arbitrary large
exponents, this may take ages and is most likely a typo. Better emit an
error when we certainly expect it to take long. The chosen threshold
takes about 100s to compute.
Piotr Trojanek [Wed, 19 Jan 2022 12:35:46 +0000 (13:35 +0100)]
[Ada] Replace variables with constants in expanded code for task names
Using constants instead of variables is cleaner both in human-written
and auto-generated code.
Cleanup related to handling of character values in SPARK
counterexamples, which just like the code for names of tasks create
N_Character_Literal nodes.
Marc Poulhiès [Fri, 17 Dec 2021 13:34:15 +0000 (14:34 +0100)]
[Ada] Fix incorrect range computation
When the type range [Lo, Hi] and the computed expression range [Lor,
Hir] are disjoint, the range-constraining logic breaks and returns an
incorrect range. For example, when Lo<Hi<Lor<Hir, it currently returns
[Lor, Hi]. Instead, return the computed range.
The current constraining logic would require returning the base type's
bounds. However, this would miss an opportunity to warn about out of
range values for some cases (e.g. when type's upper bound is equal to
base type upper bound).
The alternative of always returning the computed values, even when
ranges are intersecting, has unwanted effects (mainly useless
constraint checks are inserted) in the Enable_Overflow_Check and
Apply_Scalar_Range_Check as these bounds have a special interpretation.
gcc/ada/
* checks.adb (Determine_Range): Fix range refining.
Steve Baird [Fri, 14 Jan 2022 22:10:25 +0000 (14:10 -0800)]
[Ada] Failure compiling "for ... of" loop over a slice
In some cases involving a "for ... of" loop (not to be confused with the
more common "for ... in" loop) iterating over a slice, compilation would
fail with an internal compiler error.
gcc/ada/
* sem_util.adb (Get_Actual_Subtype): If a new subtype is built,
do not freeze it if Expander_Active is False. The idea here is
to avoid generating an unwanted Freeze_Node for a subtype that
has been conjured up solely for purposes of preanalysis.
Piotr Trojanek [Wed, 19 Jan 2022 12:29:46 +0000 (13:29 +0100)]
[Ada] Fix comment about building names in task arrays
Cleanup related to handling of character values in SPARK
counterexamples, which just like the code for names in task arrays
create N_Character_Literal nodes.
gcc/ada/
* exp_util.adb (Build_Task_Array_Image): Fix style in the
structure of generated code; add Pref'Length as the component of
the Sum initialization expression.
Piotr Trojanek [Wed, 19 Jan 2022 13:05:16 +0000 (14:05 +0100)]
[Ada] Simplify conversion from Character to Char_Code
Replace "Char_Code (Character'Pos (...))" with "Get_Char_Code (...)".
The Get_Char_Code routine is inlined, so there is no performance penalty
when it is called with static actual parameters.
The N_Character_Literal has field Char_Literal_Value of type Unat, but
we should really only store there values from Char_Code type (e.g. there
are no characters with negative ASCII codes). It seems cleaner to use
UI_From_CC and not a more general UI_From_Int when setting the character
literal values.
Cleanup related to handling of character values in SPARK
counterexamples, which just like the code for names in task arrays
create N_Character_Literal nodes.
gcc/ada/
* exp_prag.adb (Expand_Pragma_Import_Or_Interface): Use
Get_Char_Code.
* exp_util.adb (Build_Task_Array_Image): Simplify conversion to
Char_Code.
(Build_Task_Image_Prefix): Likewise.
(Build_Task_Record_Image): Likewise.
* cstand.adb (Create_Standard): Use UI_From_Int instead of
UI_From_CC.
* exp_ch11.adb (Expand_N_Exception_Declaration): Likewise.
* sem_res.adb (Patch_Up_Value): Likewise.
* stringt.adb (Write_String_Table_Entry): Use Get_Char_Code.
Eric Botcazou [Tue, 10 May 2022 07:33:16 +0000 (09:33 +0200)]
Fix internal error with vectorization on SPARC
This is a regression present since the 10.x series, but the underlying issue
has been there since the TARGET_VEC_PERM_CONST hook was implemented, in the
form of an ICE when expanding a constant VEC_PERM_EXPR in V4QI, while the
back-end only supports V8QI constant VEC_PERM_EXPRs.
gcc/
PR target/105292
* config/sparc/sparc.cc (sparc_vectorize_vec_perm_const): Return
true only for 8-byte vector modes.
gcc/testsuite/
* gcc.target/sparc/20220510-1.c: New test.
Jason Merrill [Mon, 9 May 2022 20:03:35 +0000 (16:03 -0400)]
c++: fix arm-eabi crash building libstdc++ [PR105529]
My recent change to cxx_eval_store_expression asserts that the target and
value can only end up having different types in the case of an empty base;
this was crashing arm-eabi compilers because in that ABI [cd]tors
return *this, and weren't converting it to void* first.
This also shares the 'return this' code between the three places it occurs.
Thanks to Marek for the tests.
PR c++/105529
gcc/cp/ChangeLog:
* decl.cc (maybe_return_this): Replace...
(finish_constructor_body, finish_destructor_body): ...these.
(finish_function_body): Call it.
* optimize.cc (build_delete_destructor_body): Call it.
* cp-tree.h (maybe_return_this): Declare.
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/constexpr-dtor13.C: New test.
* g++.dg/cpp2a/constexpr-dtor14.C: New test.
Marek Polacek [Sun, 8 May 2022 21:36:34 +0000 (17:36 -0400)]
c++: Implement P2324R2, labels at the end of compound-stmts [PR103539]
This patch implements C++23 <https://wg21.link/p2324r2>, which allows
labels at the end of a compound statement. Its C FE counterpart was
already implemented in r11-4813.
In cp_parser_statement I rely on in_compound to determine whether we're
in a compound-statement, so that the patch doesn't accidentally allow
void fn(int c) {
if (c)
label:
}
Strangely, in_compound was reset after seeing a label (this is tested in
c-c++-common/gomp/pr63326.c), so I've made a modifiable copy specific
for OpenMP #pragma purposes.
PR c++/103539
gcc/cp/ChangeLog:
* parser.cc (cp_parser_statement): Constify the in_compound parameter.
Create a modifiable copy. Allow labels at the end of compound
statements.
gcc/testsuite/ChangeLog:
* g++.dg/cpp23/label1.C: New test.
* g++.dg/cpp23/label2.C: New test.
Harald Anlauf [Sun, 8 May 2022 20:04:27 +0000 (22:04 +0200)]
Fortran: check for non-optional spaces between adjacent keywords
In free format, spaces between adjacent keywords are not optional except
when a combination is explicitly listed (e.g. F2018: table 6.2). The
following combinations thus require separating blanks: CHANGE TEAM,
ERROR STOP, EVENT POST, EVENT WAIT, FAIL IMAGE, FORM TEAM, SELECT RANK,
SYNC ALL, SYNC IMAGES, SYNC MEMORY, SYNC TEAM, TYPE IS.
gcc/fortran/ChangeLog:
PR fortran/105501
* match.cc (gfc_match_if): Adjust patterns used for matching.
(gfc_match_select_rank): Likewise.
* parse.cc (decode_statement): Likewise.
gcc/testsuite/ChangeLog:
PR fortran/105501
* gfortran.dg/pr105501.f90: New test.
testsuite: Silence analyzer/pr51628-30.c for default_packed
On default_packed targets like PRU, a warning in the file included from
analyzer/pr51628-30.c is reported as spurious one, even though it has been
annotated there:
Excess errors:
gcc/gcc/testsuite/gcc.dg/analyzer/torture/../../../c-c++-common/pr51628-30.c:7:19: warning: 'packed' attribute ignored for field of type 'struct B' [-Wattributes]
Mark that gcc.dg/analyzer/torture/pr51628-30.c generates excess warnings
for default_packed targets. This is safe because the original test case
covered an ICE, not a diagnostic error.
gcc/testsuite/ChangeLog:
* gcc.dg/analyzer/torture/pr51628-30.c: Test can spill excess
errors for default_packed targets.
Qing Zhao [Mon, 9 May 2022 15:34:34 +0000 (15:34 +0000)]
i386: Adjust -fzero-call-used-regs to always use XOR [PR101891]
Currently on i386, -fzero-call-used-regs uses a pattern of:
XOR regA,regA
MOV regA,regB
MOV regA,regC
...
RET
However, this introduces both a register ordering dependency (e.g. the CPU
cannot clear regB without clearing regA first), and while greatly reduces
available ROP gadgets, it does technically leave a set of "MOV" ROP gadgets
at the end of functions (e.g. "MOV regA,regC; RET").
This patch will switch to always use XOR on i386:
XOR regA,regA
XOR regB,regB
XOR regC,regC
...
RET
gcc/ChangeLog:
PR target/101891
* config/i386/i386.cc (zero_call_used_regno_mode): use V2SImode
as a generic MMX mode instead of V4HImode.
(zero_all_mm_registers): Use SET to zero instead of MOV for
zeroing scratch registers.
(ix86_zero_call_used_regs): Likewise.
Patrick Palka [Mon, 9 May 2022 13:53:27 +0000 (09:53 -0400)]
c++: constexpr init of union sub-aggr w/ base [PR105491]
Here ever since r10-7313-gb599bf9d6d1e18, reduced_constant_expression_p
in C++11/14 is rejecting the marked sub-aggregate initializer (of type S)
W w = {.D.2445={.s={.D.2387={.m=0}, .b=0}}};
^
ultimately because said initializer has CONSTRUCTOR_NO_CLEARING set,
hence the function must verify that all fields of S are initialized.
And before C++17 it doesn't expect to see base class fields (since
next_initializable_field skips over them), so the presence thereof
causes r_c_e_p to return false.
The reason r10-7313-gb599bf9d6d1e18 causes this is because in that
commit we began using CONSTRUCTOR_NO_CLEARING to precisely track whether
we're in middle of activating a union member. This ends up affecting
clear_no_implicit_zero, which recurses into sub-aggregate initializers
only if the outer initializer has CONSTRUCTOR_NO_CLEARING set. After
that commit, the outer union initializer above no longer has the flag
set at this point and so clear_no_implicit_zero no longer recurses into
the marked inner initializer.
But arguably r_c_e_p should be able to accept the marked initializer
regardless of whether CONSTRUCTOR_NO_CLEARING is set. The primary bug
therefore seems to be that r_c_e_p relies on next_initializable_field
which skips over base class fields in C++11/14. To fix this, this patch
introduces a new helper function next_subobject_field which is like
next_initializable_field except that it never skips base class fields,
and makes r_c_e_p use it. This patch then renames next_initializable_field
to next_aggregate_field (and makes it skip over vptr fields again).
Implement permutation with pslldq + psrldq + por when pshufb is not available.
pand/pandn may be used to clear upper/lower bits of the operands, in
that case there will be 4-5 instructions for permutation, and it's
still better than scalar codes.
gcc/ChangeLog:
PR target/105354
* config/i386/i386-expand.cc
(expand_vec_perm_pslldq_psrldq_por): New function.
(ix86_expand_vec_perm_const_1): Try
expand_vec_perm_pslldq_psrldq_por for both 3-instruction and
4/5-instruction sequence.
gcc/testsuite/ChangeLog:
* gcc.target/i386/pr105354-1.c: New test.
* gcc.target/i386/pr105354-2.c: New test.
Nathan Sidwell [Mon, 9 May 2022 11:36:30 +0000 (04:36 -0700)]
[c++][NFC] Rename Attached to Keyed
With modules, certain decls are 'scoped' with another decl. I chose
the name 'attached', but that has become something specific in the
modules context, so is no longer a good name. The alternative name I
considered was 'keyed', but we already had the concept of a key
virtual function (from the ABI), which is why I went with 'attached'.
However, I think 'keyed' is the less worse name. I think there's less
chance of confusion.
gcc/cp/
* cp-tree.h (DECL_MODULE_KEYED_DECLS_P): Renamed from
DECL_MODULE_ATTACHMENTS_P.
(struct lane_decl_base): Rename module_attached_p to
module_keyed_decls_p.
(maybe_key_decl): Renamed from maybe_attach_decl.
* lambda.cc (record_lambda_scope): Adjust.
* lex.cc (cxx_dup_lang_specific_decl): Adjust.
* module.cc (keyed_map_t, keyed_table): Renamed from attached_map_t,
attached_table.
(enum merge_kind): Rename MK_attached to MK_keyed.
(trees_out::lang_decl_bools): Adjust.
(trees_in::lang_decl_bools): Adjust.
(trees_in::decl_value): Adjust.
(trees_out::get_merge_kind): Adjust.
(trees_out::key_mergeable): Adjust.
(trees_in::key_mergeable): Adjust.
(maybe_key_decl): Rename from maybe_attach_decl.
(direct_import): Adjust.
(fini_modules): Adjust.
Martin Liška [Thu, 5 May 2022 12:18:58 +0000 (14:18 +0200)]
Simplify STATIC_ASSERT macro.
For C++, use always __static_assert and for C, use the negative array
index.
gcc/ChangeLog:
* basic-block.h (STATIC_ASSERT): Use normal STATIC_ASSERT.
* system.h (STATIC_ASSERT): Define as static_assert for C++
and fallback to array index in C.
Richard Biener [Mon, 9 May 2022 09:33:44 +0000 (11:33 +0200)]
tree-optimization/105517 - avoid offset truncation during VN
When value-numbering an address expression like
&p_74(D)->a1x[4294967295].a1; we are accumulating the byte offset
in an 64bit integer. When later exploiting the duality between
that and a POINTER_PLUS_EXPR we should avoid truncating that
offset to fit in the target specific sizetype. While such
overflows are generally undefined behavior, exploiting this
may leads to spurious missing diagnostics.
2022-05-09 Richard Biener <rguenther@suse.de>
PR tree-optimization/105517
* tree-ssa-sccvn.cc (vn_reference_lookup): Make sure the accumulated
offset can be represented in the POINTER_PLUS_EXPR IL.
(vn_reference_insert): Likewise.
* poly-int.h (sext_hwi): Add poly version of sext_hwi.
Yannick Moy [Wed, 19 Jan 2022 10:19:50 +0000 (11:19 +0100)]
[Ada] Suggest use of First_Valid/Last_Valid on type with static predicate
Attributes First_Valid/Last_Valid can be used on types with static
predicate, instead of First/Last/Range. Include that suggestion in
the corresponding error message.
Piotr Trojanek [Tue, 18 Jan 2022 22:04:12 +0000 (23:04 +0100)]
[Ada] Raise Constraint_Error when converting negative values to Char_Code
GNATprove relies on the comment for Get_Enum_Lit_From_Pos, which
promises to raise Constraint_Error when its Pos parameter is not among
the representation values for enumeration literal. However, this promise
was only respected in builds with range checks enabled.
The root problem was that a similar comment for conversion from Uint to
Char_Code was likewise only respected in builds with range checks
enabled.
Now both routines respect promises in their comments. The behaviour of
GNAT itself is not affected. The fix is needed to filter garbage
counterexamples generated by provers for characters objects in SPARK.
gcc/ada/
* uintp.adb (UI_To_CC): Guard against illegal inputs; reuse
UI_To_Int.
Justin Squirek [Tue, 18 Jan 2022 09:46:23 +0000 (10:46 +0100)]
[Ada] Fix invalid memory access on finalization of class-wide type
This patch corrects issues in the compiler whereby finalization of a
heap- allocated class-wide type may cause an invalid memory read at
runtime when the type in question contains a component whose type has a
large alignment.
gcc/ada/
* exp_attr.adb (Expand_N_Attribute_Reference) <Attribute_Tag>:
Deal specifically wth class-wide equivalent types without a
parent.
* exp_util.adb (Build_Allocate_Deallocate_Proc): Extract
allocator node for calculation of alignment actual and modify
alignment for allocators of class-wide types with associated
expressions.
(Make_CW_Equivalent_Type): Handle interface types differently
when generating the equivalent record.
* sem_aux.adb (First_Tag_Component): Accept class-wide
equivalent types too.
Etienne Servais [Mon, 17 Jan 2022 15:26:00 +0000 (16:26 +0100)]
[Ada] Fully qualify name in JSON representation info
The current termination condition of the recursion is wrong. When in
JSON mode, names should be fully qualified. This requires to stop not at
the first encountered compilation unit but to recurse up to Standard.
Piotr Trojanek [Tue, 18 Jan 2022 00:08:53 +0000 (01:08 +0100)]
[Ada] Remove extra space around binary operators
Style cleanups. Violation initially spotted while reading the code for
UI_Expon; other occurrences found with grep (and examined manually,
because sometimes the extra space is needed for a code layout).
gcc/ada/
* bindgen.adb, errout.adb, exp_unst.adb, gnatchop.adb,
libgnat/a-ngcefu.adb, libgnat/a-strunb.adb,
libgnat/a-stwiun.adb, libgnat/a-stzunb.adb,
libgnat/a-wtedit.adb, libgnat/g-debpoo.adb, osint.adb,
sigtramp-vxworks.c, uintp.adb: Remove extra whitespace around +,
-, *, / and **.
Piotr Trojanek [Fri, 14 Jan 2022 17:43:53 +0000 (18:43 +0100)]
[Ada] Prevent inlining-for-proof for calls inside ELSIF condition
In GNATprove we don't want inlining-for-proof to expand subprogram
bodies into actions attached to nodes. These actions are attached either
to expressions or to statements.
For expressions, we prevented inlining by Is_Potentially_Unevaluated.
For statements, we prevented inlining by In_While_Loop_Condition, but
forgot about actions attached to ELSIF condition.
There are no other expression or statements nodes where actions could be
attached, so this fix is exhaustive.
gcc/ada/
* sem_util.ads (In_Statement_Condition_With_Actions): Renamed
from In_While_Loop_Condition; move to fit the alphabetic order.
* sem_util.adb (In_Statement_Condition_With_Actions): Detect
Elsif condition; stop search on other statements; prevent search
from going too far; move to fit the alphabetic order.
* sem_res.adb (Resolve_Call): Adapt caller.
Eric Botcazou [Fri, 14 Jan 2022 21:36:13 +0000 (22:36 +0100)]
[Ada] Fix missing error on actual for In/Out parameter
The compiler was failing to give an error on the result of a call to the
Input attribute passed as actual for an In/Out parameter.
gcc/ada/
* sem_util.adb (Is_OK_Variable_For_Out_Formal): Remove test on
Comes_From_Source in the condition dealing with the expression
of an N_Unchecked_Type_Conversion node.
Justin Squirek [Mon, 3 Jan 2022 08:26:44 +0000 (08:26 +0000)]
[Ada] Improve error messages to include full package name
This patch improves error messages in the compiler so that missing
'with' error messages show the complete package name instead of a
limited number of selectors.
gcc/ada/
* err_vars.ads: Add new error message names and nodes.
* erroutc.adb (Set_Msg_Insertion_Name,
Set_Msg_Insertion_Name_Literal): Likewise.
* errout.adb (Set_Msg_Insertion_Node): Likewise.
* errout.ads: Likewise.
* exp_disp.adb (Check_Premature_Freezing): Modify setting of
Error_Msg_Node_2 to occur directly before Error_Msg call where
applicable.
* sem_ch8.adb (Error_Missing_With_Of_Known_Unit): Added to
handle the printing of full package names of known units.
(Undefined, Find_Expanded_Name): Replace error printing with
call to Error_Missing_With_Of_Known_Unit.
Yannick Moy [Thu, 13 Jan 2022 16:35:24 +0000 (17:35 +0100)]
[Ada] Set Error_Msg_Warn before use of << insertion
Calls to Error_Msg procedures with a message using the < or <<
insertions need to set appropriately Error_Msg_Warn. This was not done
in one call, which would lead to spurious errors when changing the
implementation of a runtime unit. This fixes it so that changes can be
applied.
gcc/ada/
* exp_ch4.adb (Expand_Allocator_Expression): Set Error_Msg_Warn
correctly.
Steve Baird [Wed, 15 Dec 2021 23:13:39 +0000 (15:13 -0800)]
[Ada] Properly handle unprefixed references to components
In some cases, the compiler would incorrectly reject unprefixed uses of
component names in an aspect specification for the composite type.
Correct this error.
gcc/ada/
* sem_ch13.adb (Replace_Type_Ref): In the case of an identifier
that names a component of the type, simplify the test to decide
whether to build a prefix for it (the prefix denotes the current
instance of the enclosing type): if the identifier doesn't
already have a prefix, then give it one. This isn't quite right
in the corner case of a quantified expression or some other such
expression that declares an object with the same name as a
component, but it is still an improvement.
Ed Schonberg [Wed, 12 Jan 2022 11:04:58 +0000 (12:04 +0100)]
[Ada] Fix package installation for private array type of private element
The problem comes from the construction of Stream operations, which
happens at the point a tagged type is frozen. Streams need to see the
full view of types, so that for example the Read attribute for an array
can be expanded into a loop over the Read attribute for the component
type. Now if during that expansion we have a private type we may need
to retrieve the full view of the type to find its structure. And the
corresponding tree must be compiled in the context of the package that
defines the type, which might not be the current package. The problem
arises when both array and component types are private, then the
described mechanism is invoked twice.
gcc/ada/
* exp_attr.adb (Compile_Stream_Body_In_Scope): Do not install
package if array type and element type come from the same
package, and the original array type is private.
Eric Botcazou [Fri, 7 Jan 2022 23:48:58 +0000 (00:48 +0100)]
[Ada] Fix internal error on declaration of derived discriminated record type
When the parent type has a variant part and the derived type is also
discriminated but statically selects a variant, the initialization
routine of the derived type may attempt to access components of other
variants that are no longer present.
gcc/ada/
* exp_ch4.adb (Handle_Changed_Representation): Simplify and fix
thinko in the loop building the constraints for discriminants.
* exp_ch5.adb (Make_Component_List_Assign): Try also to extract
discriminant values for a derived type.
Ed Schonberg [Mon, 3 Jan 2022 14:29:09 +0000 (15:29 +0100)]
[Ada] Fix visibility inside declare_expression
The first implementation just created a scope for the analysis of the
declarations and the expression, so that visibility would just work as
it does for all other constructs. However this led to an annoying bug
when one of the declarations or the expression itself creates a
transient scope: there may be a confusion on scope exit between those
two scopes. As a result visibility is handled by explicit traversal of
the expression and replacement of occurrences of the local variables,
see Replace_Local_Ref in Resolve_Declare_Expression (sem_res.adb). The
current code does not take into account that there may be references to
a local object in a subsequent declaration (not just in the expression).
gcc/ada/
* sem_res.adb (Resolve_Declare_Expression): Traverse the
expression to replace references to local variables that occur
within declarations of the declare_expression; fix typos in
comments.