When a dispatching call is made to a primitive function with a controlling
tagged result, the call is dispatching on result and thus must return the
class-wide type of the tagged type to accommodate all possible results.
This was ensured by Expand_Dispatching_Call only in the common case where
the result type is the type of the controlling argument, which does not
cover the case of a primitive function inherited from an ancestor type.
gcc/ada/
* exp_disp.adb (Expand_Dispatching_Call): Fix detection of calls
that are dispatching on tagged result.
Target specific runtime files must be added to a the exclude list so the
files don't automatically get copied to other runtimes.
gcc/ada/
* Makefile.rtl (ADA_EXCLUDE_SRCS): Add s-qnx.ads.
The local function Rewrite_As_Renaming can be called twice in certain
circumstances, which is both not quite safe and unnecessary, so this
replaces it with a local variable whose value is computed only once.
No functional changes.
gcc/ada/
* exp_ch3.adb (Expand_N_Object_Declaration) <OK_To_Rename_Ref>: New
local function.
<Rewrite_As_Renaming>: Change to a local variable whose value is
computed once and generate a call to Finalize after this is done.
Simplify the code creating the renaming at the end.
Attribute Index, which was added to Ada 2022 by AI12-0143, is resolved
just like attribute Count. However, code duplication rightly triggered a
CodePeer warning.
gcc/ada/
* sem_attr.adb (Resolve_Attribute): Refactor duplicated code for
Count and Index attributes.
This changes the expanded code generated for if-expressions of 1-dimensional
arrays to create a static temporary on the stack if a small upper bound can
be computed for the length of a subtype covering the result. Static stack
allocation is preferred over dynamic allocation for code generation purpose.
This also contains a couple of enhancements to the support code for checks,
so as to avoid generating useless checks during the modified expansion.
gcc/ada/
* checks.adb (Apply_Length_Check_On_Assignment): Return early if
the Suppress_Assignment_Checks flag is set.
(Selected_Range_Checks): Deal with conditional expressions.
* exp_ch4.adb (Too_Large_Length_For_Array): New constant.
(Expand_Concatenate): Use it in lieu of Too_Large_Max_Length.
(Expand_N_If_Expression): If the result has a unidimensional array
type but the dependent expressions have constrained subtypes with
known bounds, create a static temporary on the stack with a subtype
covering the result.
(Get_First_Index_Bounds): Deal with string literals.
* uintp.ads (Uint_256): New deferred constant.
* sinfo.ads (Suppress_Assignment_Checks): Document new usage.
gcc/ada/
* exp_ch3.adb (Expand_N_Object_Declaration.Rewrite_As_Renaming):
Do not rewrite if the declaration has got constraints.
* sinfo.ads (Case Expression Alternative): Fix typo.
This changes the expanded code generated for dynamic concatenations to
use a static array subtype for the temporary created on the stack if a
small upper bound can be computed for the length of the result. Static
stack allocation is preferred over dynamic allocation for code
generation purposes.
gcc/ada/
* exp_ch3.adb (Expand_N_Object_Declaration.Rewrite_As_Renaming):
Be prepared for slices.
* exp_ch4.adb (Get_First_Index_Bounds): New procedure.
(Expand_Array_Comparison.Length_Less_Than_4): Call it.
(Expand_Concatenate): Try to compute a maximum length for
operands with variable length and a maximum total length at the
end. If the concatenation is dynamic, but a sensible maximum
total length has been computed, use this length to create a
static array subtype for the temporary and return a slice of it.
If a constrained subtype is given when a deferred constant is declared,
then the subtype given in the completion is required (at compile time)
to be subject to a statically matching constraint. This rule was not
properly enforced in some cases and constructs that should have been
rejected were incorrectly accepted.
gcc/ada/
* sem_ch3.adb (Check_Possible_Deferred_Completion): Delete
Prev_Obj_Def formal parameter. Reorganize code so that
statically matching check is also performed in the case where
the subtype given in the initial declaration is constrained and
the subtype given in the completion is not.
Add predicates on subtypes E and N.
gcc/ada/
* einfo-utils.ads, einfo-utils.adb: Add predicates on subtypes E
and N. Change some parameters to use the unpredicated subtypes,
because they sometimes return e.g. Empty. Note that N_Entity_Id
has a predicate; Entity_Id does not.
* exp_tss.adb (Base_Init_Proc): Use Entity_Id instead of E,
because otherwise we fail the predicate. We shouldn't be
referring to single-letter names from far away anyway.
* sem_aux.adb (Is_Derived_Type): Likewise.
* sem_res.adb (Is_Definite_Access_Type): Use N_Entity_Id for
predicate.
* types.ads (Entity_Id): Add comment explaining the difference
between Entity_Id and N_Entity_Id.
This patch corrects removes some code duplication within the GNAT
compiler.
gcc/ada/
* exp_util.adb (Remove_Side_Effects): Combine identical
branches.
* sem_attr.adb (Analyze_Attribute): Combine identical cases
Attribute_Has_Same_Storage and Attribute_Overlaps_Storage.
* sem_prag.adb (Check_Role): Combine E_Out_Parameter case with
general case for parameters.
* sem_util.adb (Accessibility_Level): Combine identical
branches.
* sprint.adb (Sprint_Node_Actual): Combine cases for
N_Real_Range_Specification and N_Signed_Integer_Type_Definition.
This patch corrects an issue in the compiler whereby calling
Quote_Argument with an argument that is of size 1 may lead to a
CONSTRAINT_ERROR raised at runtime due to an undersized buffer.
gcc/ada/
* libgnat/s-os_lib.adb (Quote_Argument): Modify the result
buffer size calculation to handle the case where Arg'Length is
1.
For X'Access, the designated subtype of the access type must statically
match the nominal subtype of X. This patch fixes a bug where the error
was not detected when there is an unrelated declaration of the form "Y :
T := X;", where T is an unconstrained array subtype.
gcc/ada/
* exp_util.adb (Expand_Subtype_From_Expr): Generate a new
subtype when Is_Constr_Subt_For_UN_Aliased is True, so the
Is_Constr_Subt_For_U_Nominal flag will not be set on the
preexisting subtype.
* sem_attr.adb, sem_ch3.adb: Minor.
It was only used in specific cases for controlled types but no longer
provides any significant benefit in practice.
gcc/ada/
* debug.adb (d.9): Remove usage.
* exp_ch6.adb (Expand_Simple_Function_Return): Remove redundant
test on Debug_Flag_Dot_L.
(Is_Build_In_Place_Result_Type): Return false for nonlimited types.
(Is_Build_In_Place_Function): Tidy up and remove redundant test on
Debug_Flag_Dot_L.
This changes the compiler to build in place almost all objects that need
finalization and are initialized with the result of a function call, thus
saving a pair of Adjust/Finalize calls for the anonymous return object.
gcc/ada/
* exp_ch3.adb (Expand_N_Object_Declaration): Don't adjust the object
if the expression is a function call.
<Rewrite_As_Renaming>: Return true if the object needs finalization
and is initialized with the result of a function call returned on
the secondary stack.
* exp_ch6.adb (Expand_Ctrl_Function_Call): Add Use_Sec_Stack boolean
parameter. Early return if the parent is an object declaration and
Use_Sec_Stack is false.
(Expand_Call_Helper): Adjust call to Expand_Ctrl_Function_Call.
* exp_ch7.adb (Find_Last_Init): Be prepared for initialization still
present in the object declaration.
* sem_ch3.adb (Analyze_Object_Declaration): Call the predicates
Needs_Secondary_Stack and Needs_Finalization to guard the renaming
optimization.
This patch adds the new Generic_Keys.Key function to the set children
of Ada.Containers.
gcc/ada/
* libgnat/a-cbhase.ads, libgnat/a-cborse.ads,
libgnat/a-cihase.ads, libgnat/a-ciorse.ads,
libgnat/a-cohase.ads, libgnat/a-coorse.ads (Key): New function
that takes a Container parameter, implemented as an expression
function, so it is self explanatory (doesn't need a comment).
In some cases when a legal allocator which defines a new subtype for the
allocated object occurs as part of a record component constraint
expression, the compiler would incorrectly reject the allocator.
gcc/ada/
* sem_ch4.adb (Analyze_Allocator): After calling Insert_Action
to insert a subtype declaration associated with an allocator,
the subtype declaration will usually be analyzed. But not
always. Add an explicit call to Preanalyze to cope with the
unusual case. The subtype declaration must be at least
preanalyzed before the call to Sem_Ch3.Process_Subtype a little
while later, during which we analyze an identifier that refers
to the subtype.
The -gnatwc switch enables warnings for test condition outcomes that are
known at compile time. Such warnings are unlikely to be useful in the
case of an assertion expression (or a subexpression thereof), so do not
generate them in that case.
gcc/ada/
* sem_warn.adb (Warn_On_Constant_Valid_Condition): Do not
generate a warning if the expression in question is an assertion
expression, or a subexpression thereof. But do call
Test_Comparison so that it can generate warnings for the cases
that it generates warnings for.
* sem_prag.ads: Modify Assertion_Expression_Pragma constant so
that the predicate Sem_Util.In_Assertion_Expression_Pragma
returns True for the expression of a Compile_Time_Error pragma.
Modify the RM to take into account the new functional container.
gcc/ada/
* doc/gnat_rm/the_gnat_library.rst: Add the new entry.
* gnat_rm.texi: Regenerate.
When the code responsible for giving errors on ambiguous operands of
comparison and equality operators was moved from the 1st phase (analysis)
to the 2nd phase (resolution) of semantic processing, it was incorrectly
restricted to the operator case, which was valid during the 1st phase but
is not during the 2nd phase.
gcc/ada/
* sem_res.adb (Resolve_Comparison_Op): Deal with ambiguous operands
in all cases.
(Resolve_Equality_Op): Likewise, except for the case of the implicit
inequality operator created for a user-defined operator that is not
an intrinsic subprogram.
This patch adds some Ada 2022 features to the set children of
Ada.Containers.
gcc/ada/
* libgnat/a-cbhase.adb, libgnat/a-cbhase.ads,
libgnat/a-cborse.adb, libgnat/a-cborse.ads,
libgnat/a-cihase.adb, libgnat/a-cihase.ads,
libgnat/a-ciorse.adb, libgnat/a-ciorse.ads,
libgnat/a-cohase.adb, libgnat/a-cohase.ads,
libgnat/a-conhel.adb, libgnat/a-conhel.ads,
libgnat/a-coorse.adb, libgnat/a-coorse.ads: Add Has_Element,
Element, Query_Element, and Next subprograms that take a Set
parameter. Add Tampering_With_Cursors_Prohibited function. These
are all new in Ada 2022.
Functional containers are now controlled. Update the documentation
accordingly.
gcc/ada/
* doc/gnat_rm/the_gnat_library.rst: Functional vectors, sets,
and maps are now controlled.
* gnat_rm.texi: Regenerate.
All assertion pragmas are enabled by default when using -gnata. We need
to add the GNAT specific ones to the list.
gcc/ada/
* doc/gnat_ugn/building_executable_programs_with_gnat.rst
(Debugging and Assertion Control): Add GNAT specific assertion
pragmas to the equivalent Assertion_Policy for the -gnata
option.
* gnat_ugn.texi: Regenerate.
This patch corrects an error in the compiler whereby the presence of a
call to a function returning a type with an access discriminant within
an expanded loop condition caused the wrong value to be supplied for the
extra- accessibility-of-result actual, thus causing incorrect checks
within the callee at the point of return.
This change also corrects a problem where spurious "null value not
allowed" warnings were generated for tagged type declarations with an
access discriminant specified as "null."
gcc/ada/
* sem_disp.adb (Most_Descendant_Use_Clause): Remove call to
deprecated Is_Internal.
* sem_util.adb (Innermost_Master_Scope_Depth): Use
Find_Enclosing_Scope instead of Nearest_Dynamic_Scope to avoid
cases where relevant scopes get skipped leading to an incorrect
scope depth calculation.
When the result type of a function requiring built-in-place return is
only visible through a limited_with clause, the compiled needs to wait
for the nonlimited view to be available in order to compute whether
the built-in-place return is needed, and this comprises tagging the
function with the Returns_By_Ref flag.
gcc/ada/
* exp_ch6.adb (Build_In_Place_Formal): Also compute Returns_By_Ref
for the function if the extra formals were not built initially.
When resolving the Iterable aspect we look for a functions that are
declared in the same scope as the annotated type and that have the
required number and types formal parameters. However, we didn't guard
against functions that have no formal parameter at all.
gcc/ada/
* sem_ch13.adb (Resolve_Iterable_Operation): Add guard to
prevent crash when the examined function has no formal
parameters and Etype is called on Empty entity.
Add a new unbounded functional sequence. This sequence is indexed by
Big_Positive and so is unbounded from the user and spark points view.
Hower the actually implemented sequence are bounded by Count_Type'Last.
gcc/ada/
* libgnat/a-cfinse.adb, libgnat/a-cfinse.ads: Implementation
files of the sequence.
* Makefile.rtl, impunit.adb: Take into account the add of the
new files
The current wording can be read as implying that the result of a call
to a pure function does not depend on the context, which is incorrect.
The pragma only guarantees the absence of side effects of such a call.
gcc/ada/
* doc/gnat_rm/implementation_defined_pragmas.rst (Pure_Function):
Fix ambiguous wording about context dependence.
* gnat_rm.texi: Regenerate.
When autopar uses graphites canonicalize_loop_closed_ssa it fails to
check whether propagation is allowed and thus it ends up messing up
abnormal constraints.
2022-07-01 Richard Biener <rguenther@suse.de>
PR tree-optimization/106055
* graphite.cc (canonicalize_loop_closed_ssa): Check whether
we can propagate.
* gcc.dg/graphite/pr106055.c: New testcase.
1. Add a predicate for constant vectors which can be converted to integer
constants suitable for constant integer stores. For a 8-byte constant
vector, the converted 64-bit integer must be valid for store with 64-bit
immediate, which is a 64-bit integer sign-extended from a 32-bit integer.
2. Add a new pattern to allow 2-byte, 4-byte and 8-byte constant vector
stores, like
(set (mem:V2HI (reg:DI 84))
(const_vector:V2HI [(const_int 0 [0]) (const_int 1 [0x1])]))
3. After reload, convert constant vector stores to constant integer
stores, like
(set (mem:SI (reg:DI 5 di [84]))
(const_int 65536 [0x10000]))
For
void
foo (short * c)
{
c[0] = 0;
c[1] = 1;
}
it generates
movl $65536, (%rdi)
instead of
movl .LC0(%rip), %eax
movl %eax, (%rdi)
gcc/
PR target/106022
* config/i386/i386-protos.h (ix86_convert_const_vector_to_integer):
New.
* config/i386/i386.cc (ix86_convert_const_vector_to_integer):
New.
* config/i386/mmx.md (V_16_32_64): New.
(*mov<mode>_imm): New patterns for stores with 16-bit, 32-bit
and 64-bit constant vector.
* config/i386/predicates.md (x86_64_const_vector_operand): New.
gcc/testsuite/
PR target/106022
* gcc.target/i386/pr106022-1.c: New test.
* gcc.target/i386/pr106022-2.c: Likewise.
* gcc.target/i386/pr106022-3.c: Likewise.
* gcc.target/i386/pr106022-4.c: Likewise.
Now that vrange_storage is in its own file, I think it's prudent to
move all the vrange allocator code there since it's all related.
The users of value-range.h do not need to know the implementation
details of the storage facilities.
Tested and benchmarked on x86-64 Linux.
gcc/ChangeLog:
* gimple-range-cache.cc: Include value-range-storage.h.
* gimple-range-cache.h (class block_range_cache): Add "class" to
m_range_allocator.
* gimple-range-edge.cc
(gimple_outgoing_range::gimple_outgoing_range): Allocate allocator.
(gimple_outgoing_range::~gimple_outgoing_range): Free allocator.
(gimple_outgoing_range::calc_switch_ranges): Dereference allocator.
* gimple-range-edge.h: Add "class" to m_range_allocator.
* gimple-range-infer.cc
(infer_range_manager::infer_range_manager): Allocate allocator.
(infer_range_manager::~infer_range_manager): Free allocator.
(infer_range_manager::get_nonzero): Dereference allocator.
(infer_range_manager::add_range): Same.
* gimple-range-infer.h (class vrange_allocator): Add "class" to
m_range_allocator.
* value-range-storage.h (class vrange_allocator): Move from
value-range.h.
(class obstack_vrange_allocator): Same.
(class ggc_vrange_allocator): Same.
(vrange_allocator::alloc_vrange): Same.
(vrange_allocator::alloc_irange): Same.
* value-range.h (class vrange_allocator): Move to value-range-storage.h.
(class obstack_vrange_allocator): Same.
(class ggc_vrange_allocator): Same.
This patch implements a storage class that will be used to stream out
ranges to long term storage, initially in SSA_NAME_RANGE_INFO, but it
is flexible enough to use with our obstack allocator. For instance,
in the future we could use it in the ranger cache to save memory.
The current size of range_info_def which is used in
SSA_NAME_RANGE_INFO is 16 bytes. With this patch, the size of the
slot (irange_storage_slot) will be 24 bytes. But we'll have the
ability to be able to store up to 5 pairs of sub-ranges if necessary.
If we ever need to save more (say for switches), we could explore a
trailing_wide_ints structure with a pointer to the m_len[N] bits as
Jakub has suggested.
In follow-up patches I will contribute the SSA_NAME_RANGE_INFO changes
as well as changes storing the nonzero bits within an irange.
For reference, the main interface is rather simple:
class vrange_storage
{
public:
vrange_storage (vrange_allocator *alloc) : m_alloc (alloc) { }
void *alloc_slot (const vrange &r);
void free (void *slot);
void get_vrange (const void *slot, vrange &r, tree type);
void set_vrange (void *slot, const vrange &r);
static bool fits_p (const void *slot, const vrange &r);
};
The above class will have the knowledge to stream out the different
ranges we support (currently only irange_storage_slot). As has been
discussed, the irange storage will use trailing wide ints:
class GTY ((variable_size)) irange_storage_slot
{
<snip>
<snip>
// This is the maximum number of wide_int's allowed in the trailing
// ints structure, without going over 16 bytes (128 bits) in the
// control word that preceeds the HOST_WIDE_INTs in
// trailing_wide_ints::m_val[].
static const unsigned MAX_INTS = 12;
// Maximum number of range pairs we can handle, considering the
// nonzero bits take one wide_int.
static const unsigned MAX_PAIRS = (MAX_INTS - 1) / 2;
trailing_wide_ints<MAX_INTS> m_ints;
};
Tested on x86-64 Linux.
gcc/ChangeLog:
* Makefile.in (OBJS): Add value-range-storage.o.
(GTFILES): Add value-range-storage.h.
* gengtype.cc (open_base_files): Add value-range-storage.h.
* value-range-storage.cc: New file.
* value-range-storage.h: New file.
Integer division by zero is undefined behavior anyway, and there are
already many platforms where neither the GCC port and the hardware do
anything to trap on division by zero. So any portable program shall not
rely on SIGFPE on division by zero, in both theory and practice. As the
result, there is no real reason to cost two additional instructions just
for the trap on division by zero with a new ISA.
One remaining reason to trap on division by zero may be debugging,
especially while -fsanitize=integer-divide-by-zero is not implemented
for LoongArch yet. To make debugging easier, keep -mcheck-zero-division
as the default for -O0 and -Og, but use -mno-check-zero-division as the
default for all other optimization levels.
Co-authored-by: Lulu Cheng <chenglulu@loongson.cn>
gcc/ChangeLog:
* config/loongarch/loongarch.cc (loongarch_check_zero_div_p):
New static function.
(loongarch_idiv_insns): Use loongarch_check_zero_div_p instead
of TARGET_CHECK_ZERO_DIV.
(loongarch_output_division): Likewise.
* common/config/loongarch/loongarch-common.cc
(TARGET_DEFAULT_TARGET_FLAGS): Remove unneeded hook.
* doc/invoke.texi: Update to match the new behavior.
gcc/testsuite/ChangeLog:
* gcc.c-torture/execute/20101011-1.c (dg-additional-options):
add -mcheck-zero-division for LoongArch targets.
The patch changes the types inside the tests for the allocation size
checker to fixed-width types of stdint.h to account for different
architectures with different type widths.
2022-07-03 Tim Lange <mail@tim-lange.me>
gcc/testsuite/ChangeLog:
* gcc.dg/analyzer/allocation-size-1.c: Use fixed-length types.
* gcc.dg/analyzer/allocation-size-2.c: Likewise.
* gcc.dg/analyzer/allocation-size-3.c: Likewise.
* gcc.dg/analyzer/allocation-size-4.c: Likewise.
* gcc.dg/analyzer/allocation-size-5.c: Likewise.
gcc/ChangeLog:
* tree-ssa-dse.cc (dse_optimize_stmt): Only delete a trapping
statement if -fdelete-dead-exceptions.
gcc/testsuite/ChangeLog:
* g++.dg/torture/except-1.C: New test.
This patch adds an checker that warns about code paths in which a buffer
is assigned to a incompatible type, i.e. when the allocated buffer size
is not a multiple of the pointee's size.
Regression-tested on x86_64 Linux. Also compiled coreutils, curl, openssh and
httpd with the patch enabled.
2022-07-01 Tim Lange <mail@tim-lange.me>
gcc/analyzer/ChangeLog:
PR analyzer/105900
* analyzer.opt: Added Wanalyzer-allocation-size.
* checker-path.cc (region_creation_event::get_desc): Added call to new
virtual function pending_diagnostic::describe_region_creation_event.
* checker-path.h: Added region_creation_event::get_desc.
* diagnostic-manager.cc (diagnostic_manager::add_event_on_final_node):
New function.
* diagnostic-manager.h:
Added diagnostic_manager::add_event_on_final_node.
* pending-diagnostic.h (struct region_creation): New event_desc struct.
(pending_diagnostic::describe_region_creation_event): Added virtual
function to overwrite description of a region creation.
* region-model.cc (class dubious_allocation_size): New class.
(capacity_compatible_with_type): New helper function.
(class size_visitor): New class.
(struct_or_union_with_inheritance_p): New helper function.
(is_any_cast_p): New helper function.
(region_model::check_region_size): New function.
(region_model::set_value): Added call to
region_model::check_region_size.
* region-model.h (class region_model): New function check_region_size.
* svalue.cc (region_svalue::accept): Changed to post-order traversal.
(initial_svalue::accept): Likewise.
(unaryop_svalue::accept): Likewise.
(binop_svalue::accept): Likewise.
(sub_svalue::accept): Likewise.
(repeated_svalue::accept): Likewise.
(bits_within_svalue::accept): Likewise.
(widening_svalue::accept): Likewise.
(unmergeable_svalue::accept): Likewise.
(compound_svalue::accept): Likewise.
(conjured_svalue::accept): Likewise.
(asm_output_svalue::accept): Likewise.
(const_fn_result_svalue::accept): Likewise.
gcc/ChangeLog:
PR analyzer/105900
* doc/invoke.texi: Added Wanalyzer-allocation-size.
gcc/testsuite/ChangeLog:
PR analyzer/105900
* gcc.dg/analyzer/pr96639.c: Changed buffer size to omit warning.
* gcc.dg/analyzer/allocation-size-1.c: New test.
* gcc.dg/analyzer/allocation-size-2.c: New test.
* gcc.dg/analyzer/allocation-size-3.c: New test.
* gcc.dg/analyzer/allocation-size-4.c: New test.
* gcc.dg/analyzer/allocation-size-5.c: New test.
Signed-off-by: Tim Lange <mail@tim-lange.me>
This patch adds a new state machine to the analyzer for checking usage of POSIX file descriptor
APIs with five new warnings.
It adds:
- check for FD leaks (CWE 775).
- check for double "close" of a FD (CWE-1341).
- check for read/write of a closed file descriptor.
- check whether a file descriptor was used without being checked for validity.
- check for read/write of a descriptor opened for just writing/reading.
gcc/ChangeLog:
PR analyzer/106003
* Makefile.in (ANALYZER_OBJS): Add sm-fd.o.
* doc/invoke.texi: Add -Wanalyzer-fd-double-close, -Wanalyzer-fd-leak,
-Wanalyzer-fd-access-mode-mismatch, -Wanalyzer-fd-use-without-check,
-Wanalyzer-fd-use-after-close.
gcc/analyzer/ChangeLog:
PR analyzer/106003
* analyzer.opt (Wanalyzer-fd-leak): New option.
(Wanalyzer-fd-access-mode-mismatch): New option.
(Wanalyzer-fd-use-without-check): New option.
(Wanalyzer-fd-double-close): New option.
(Wanalyzer-fd-use-after-close): New option.
* sm.h (make_fd_state_machine): New decl.
* sm.cc (make_checkers): Call make_fd_state_machine.
* sm-fd.cc: New file.
gcc/testsuite/ChangeLog:
PR analyzer/106003
* gcc.dg/analyzer/fd-1.c: New test.
* gcc.dg/analyzer/fd-2.c: New test.
* gcc.dg/analyzer/fd-3.c: New test.
* gcc.dg/analyzer/fd-4.c: New test.
Use the correct initialization order for
var a = c
var b, c = x.(bool)
The global c is initialized by the preinit of b, but were missing a
dependency of c on b, so a would be initialized to the zero value of c
rather than the correct value.
Simply adding the dependency of c on b didn't work because the preinit
of b refers to c, so that appeared circular. So this patch changes
the init order to skip dependencies that only appear on the left hand
side of assignments in preinit blocks.
Doing that didn't work because the write barrier pass can transform "a
= b" into code like "gcWriteBarrier(&a, b)" that is not obviously a
simple assigment. So this patch moves the collection of dependencies
to just after lowering, before the write barriers are inserted.
Making those changes permit relaxing the requirement that we don't
warn about self-dependency in preinit blocks, so now we correctly warn
for
var a, b any = b.(bool)
The test case is https://go.dev/cl/415238.
Fixesgolang/go#53619
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/415594
Currently global ranges are stored in SSA_NAME_RANGE_INFO as a pair of
wide_int-like objects along with the nonzero bits. We frequently lose
precision when streaming out our higher resolution iranges. The plan
was always to store the full irange between passes. However, as was
originally discussed eons ago:
https://gcc.gnu.org/pipermail/gcc-patches/2017-May/475139.html
...we need a memory efficient way of saving iranges, preferably using
the trailing_wide_ints idiom.
The problem with doing so is that trailing_wide_ints assume a
compile-time specified number of elements. For irange, we need to
determine the size at run-time.
One solution is to adapt trailing_wide_ints such that N is the maximum
number of elements allowed, and allow setting the actual number at
run-time (defaulting to N). The attached patch does this, while
requiring no changes to existing users.
It uses a byte to store the number of elements in the
trailing_wide_ints control word. The control word is currently a
16-bit precision, an 8-bit max-length, and the rest is used for
m_len[N]. On a 64-bit architecture, this allows for 5 elements in
m_len without having to use an extra word. With this patch, m_len[]
would be smaller by one byte (4) before consuming the padding. This
shouldn't be a problem as the only users of trailing_wide_ints use N=2
for NUM_POLY_INT_COEFFS in aarch64, and N=3 for range_info_def.
For irange, my plan is to use one more word to fit a maximum of 12
elements (the above 4 plus 8 more). This would allow for 6 pairs of
sub-ranges which would be more than adequate for our needs. In
previous tests we found that 99% of ranges fit within 3-4 pairs. More
precisely, this would allow for 5 pairs, plus the nonzero bits, plus a
spare wide-int for future development.
Ultimately this means that streaming an irange would consume one more
word than what we currently do for range_info_def. IMO this is a nice
trade-off considering we started storing a slew of wide-ints directly
;-).
Tested and benchmarked on x86-64 Linux. There was no discernible
performance change in our benchmark suite.
gcc/ChangeLog:
* wide-int.h (struct trailing_wide_ints): Add m_num_elements.
(trailing_wide_ints::set_precision): Add num_elements argument.
(trailing_wide_ints::extra_size): Same.
The ${host_builddir}/largefile-config.h header can't be written until
its parent directory has been created, so it needs to have the creation
of that directory as a prerequisite.
libstdc++-v3/ChangeLog:
PR libstdc++/106162
* include/Makefile.am (largefile-config.h): Add
stamp-${host_alias} prerequisite.
* include/Makefile.in: Regenerate.
The code to determine whether a given token starts a module directive is
currently repeated in 4 places in parser.cc. I am about to submit a patch
that needs to add it in a 5th place, so since the code is not completely
trivial (needing to check for 3 different token types), it seems worthwhile
to factor this logic into its own function.
gcc/cp/ChangeLog:
* parser.cc (cp_token_is_module_directive): New function
refactoring common code.
(cp_parser_skip_to_closing_parenthesis_1): Use the new function.
(cp_parser_skip_to_end_of_statement): Likewise.
(cp_parser_skip_to_end_of_block_or_statement): Likewise.
(cp_parser_declaration): Likewise.