Commit Graph

194158 Commits

Author SHA1 Message Date
Bob Duff
3319015b0a [Ada] Fix missing error on 'Access of constrained array
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.
2022-07-04 07:45:56 +00:00
Eric Botcazou
02e41e69d4 [Ada] Do not use front-end build-in-place mechanism for nonlimited types
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.
2022-07-04 07:45:55 +00:00
Eric Botcazou
c901877fac [Ada] Call-initialize all controlled objects in place
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.
2022-07-04 07:45:55 +00:00
Bob Duff
eb6e8a7acd [Ada] Add Ada 2022 Key function to sets containers
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).
2022-07-04 07:45:55 +00:00
Vasiliy Fofanov
cac397f3f6 [Ada] Fix length of title underlines.
gcc/ada/

	* doc/gnat_rm/the_gnat_library.rst: Fix length of title
	underlines.
2022-07-04 07:45:54 +00:00
Steve Baird
063c8f4c01 [Ada] Compiler rejects legal allocator in record component constraint expression
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.
2022-07-04 07:45:54 +00:00
Steve Baird
f7c05e8203 [Ada] Avoid unwanted warnings for statically-known-successful assertions
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.
2022-07-04 07:45:54 +00:00
Julien Bortolussi
e7428fff12 [Ada] Add a RM entry for the functional infinite sequences
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.
2022-07-04 07:45:53 +00:00
Eric Botcazou
4030e83c27 [Ada] Give missing error on ambiguous operand of equality operator
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.
2022-07-04 07:45:53 +00:00
Bob Duff
a8a1da109e [Ada] Add Ada 2022 features to sets containers
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.
2022-07-04 07:45:53 +00:00
Claire Dross
2e9b2ab3b5 [Ada] Update the documentation of functional containers
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.
2022-07-04 07:45:52 +00:00
Claire Dross
82b63eb0f3 [Ada] Add GNAT specific pragmas to the equivalent Assertion_Policy for -gnata
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.
2022-07-04 07:45:52 +00:00
Justin Squirek
ddd8892527 [Ada] Incorrect accessibility check on return of discriminated type
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.
2022-07-04 07:45:52 +00:00
Eric Botcazou
bdd5056736 [Ada] Plug loophole for built-in-place return with limited_with clause
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.
2022-07-04 07:45:51 +00:00
Piotr Trojanek
df69e326b3 [Ada] Fix for resolution of overloaded subprogram for Iterable aspect
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.
2022-07-04 07:45:51 +00:00
Julien Bortolussi
089a4a48ac [Ada] Create new unbounded functional sequence
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
2022-07-04 07:45:51 +00:00
Eric Botcazou
ad7ed87a43 [Ada] Adjust description of Pure_Function pragma
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.
2022-07-04 07:45:50 +00:00
Richard Biener
d74d98784a tree-optimization/106055 - issue with autopar
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.
2022-07-04 09:09:45 +02:00
Haochen Jiang
73f942c08d i386: Extend cvtps2pd to memory
gcc/ChangeLog:

	PR target/43618
	* config/i386/sse.md (extendv2sfv2df2): New define_expand.
	(sse2_cvtps2pd_<mask_name>): Change constraint of operands[1].
	(*sse2_cvtps2pd_<mask_name>_1): Rename from extendvsdfv2df2.

gcc/testsuite/ChangeLog:

	PR target/43618
	* gcc.target/i386/pr43618-1.c: New test.
2022-07-04 14:21:53 +08:00
Aldy Hernandez
bbe836bc7c Remove some deprecated irange methods.
Tested on x86-64 Linux.

gcc/ChangeLog:

	* ipa-cp.cc (ipcp_vr_lattice::meet_with_1): Use operator!=.
	* ipa-prop.cc (struct ipa_vr_ggc_hash_traits): Same.
	* tree-ssa-loop-unswitch.cc (struct unswitch_predicate): Use set
	with two arguments.
	(find_unswitching_predicates_for_bb): Same.
	* tree-vrp.cc (range_fold_unary_symbolics_p): Same.
	* value-range-equiv.cc (value_range_equiv::equal_p): Use operator==.
	* value-range.cc (irange::equal_p): Rename to...
	(irange::operator==): ...this.
	* value-range.h (irange::set): Remove.
	(irange::operator==): Remove.
	(irange::set_zero): Use set with two arguments.
	* vr-values.cc (vr_values::extract_range_from_binary_expr): Same.
	(vr_values::extract_range_from_unary_expr): Same.
	(check_for_binary_op_overflow): Same.
	(bounds_of_var_in_loop): Same.
2022-07-04 07:58:47 +02:00
GCC Administrator
3731dd0bea Daily bump. 2022-07-04 00:16:19 +00:00
H.J. Lu
f3a5e75cb6 x86: Support 2/4/8 byte constant vector stores
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.
2022-07-03 10:30:07 -07:00
Aldy Hernandez
3ae9def085 Move range allocator code to value-range-storage.*
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.
2022-07-03 17:33:23 +02:00
Immad Mir
17f2e2b77b Add myself to write after approval and DCO.
This is text alignment correction for my previous patch.

ChangeLog:
	* MAINTAINERS: add myself.
2022-07-03 14:39:02 +05:30
Immad Mir
21582a7c7d Add myself to write-after-approval and DCO
ChangeLog:
	* MAINTAINERS: Add myself to write after approval and DCO.
2022-07-03 14:28:34 +05:30
Aldy Hernandez
a26f3eb268 Implement class vrange_storage to stream ranges to long term memory.
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.
2022-07-03 08:42:32 +02:00
Xi Ruoyao
f150dc1bd1
loongarch: use -mno-check-zero-division as the default for optimized code
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.
2022-07-03 11:03:26 +08:00
Tim Lange
b5c3dd3df3 Use fixed-width types in allocation size tests
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.
2022-07-03 03:26:05 +02:00
Ian Lance Taylor
d86a20ee8b tree-optimization: only DSE trapping insn if -fdelete-dead-exceptions
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.
2022-07-02 17:34:09 -07:00
GCC Administrator
20f0f30522 Daily bump. 2022-07-03 00:16:23 +00:00
Tim Lange
b58ca9c337 MAINTAINERS: Add myself to write after approval and DCO
2022-07-02  Tim Lange  <mail@tim-lange.me>

ChangeLog:

	* MAINTAINERS: Add myself.
2022-07-02 19:42:32 +02:00
Tim Lange
e6c3bb379f analyzer: add allocation size checker [PR105900]
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>
2022-07-02 19:07:49 +02:00
Immad Mir
97baacba96 analyzer: implement five new warnings for misuse of POSIX file descriptor APIs [PR106003].
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.
2022-07-02 22:14:26 +05:30
GCC Administrator
ed97448899 Daily bump. 2022-07-02 00:16:26 +00:00
Ian Lance Taylor
fbd7665360 compiler: use correct init order for multi-value initialization
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.

Fixes golang/go#53619

Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/415594
2022-07-01 15:45:34 -07:00
Aldy Hernandez
1697806fdf trailing_wide_ints with runtime variable lengths
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.
2022-07-02 00:44:44 +02:00
Jonathan Wakely
8a6ee426c2 libstdc++: Add missing prerequisite to generated header [PR106162]
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.
2022-07-01 22:42:55 +01:00
Lewis Hyatt
ff64a8c951 c++: Minor cleanup in parser.cc
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.
2022-07-01 17:33:13 -04:00
Ian Lance Taylor
1f76941c09 compiler: rename "requires" to "needs"
As of C++20 "requires" is a C++ keyword.

Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/415754
2022-07-01 13:38:08 -07:00
Marek Polacek
ecd11acacd c++: fix broken copy elision with nested TARGET_EXPRs [PR105550]
In this problem, we are failing to properly perform copy elision with
a conditional operator, so this:

  constexpr A a = true ? A{} : A{};

fails with:

  error: 'A{((const A*)(&<anonymous>))}' is not a constant expression

The whole initializer is

  TARGET_EXPR <D.2395, 1 ? TARGET_EXPR <D.2393, {.p=(const struct A *) &<PLACEHOLDER_EXPR struct A>}> : TARGET_EXPR <D.2394, {.p=(const struct A *) &<PLACEHOLDER_EXPR struct A>}>>

where the outermost TARGET_EXPR is elided, but not the nested ones.
Then we end up replacing the PLACEHOLDER_EXPRs with the temporaries the
TARGET_EXPRs represent, which is precisely what should *not* happen with
copy elision.

I've tried the approach of tweaking ctx->object, but I ran into gazillion
problems with that.  I thought that I would let cxx_eval_constant_expression
/TARGET_EXPR create a new object only when ctx->object was null, then
adjust setting of ctx->object in places like cxx_bind_parameters_in_call
and cxx_eval_component_reference but that failed completely.  Sometimes
ctx->object has to be reset, sometimes it cannot be reset, 'this' needed
special handling, etc.  I gave up.

Instead, this patch strips TARGET_EXPRs from the operands of ?: like
we do in various other places in constexpr.c.

	PR c++/105550

gcc/cp/ChangeLog:

	* constexpr.cc (cxx_eval_conditional_expression): Strip TARGET_EXPRs.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp1y/nsdmi-aggr16.C: Remove FIXME.
	* g++.dg/cpp1y/nsdmi-aggr17.C: Remove FIXME.
	* g++.dg/cpp0x/constexpr-elision1.C: New test.
	* g++.dg/cpp1y/constexpr-elision1.C: New test.
2022-07-01 12:07:34 -04:00
Tobias Burnus
9a668532fb OpenMP: Handle tofrom with target enter/exit data
In 5.2, a map clause can be map-entering or map-exiting,
either containing 'tofrom'. The main reason for this is
permit 'map(x)' with 'omp target enter/exit data',
avoiding to specify 'to:/from:' explicitly. (OpenMP
defaults to 'tofrom'.)

gcc/c/ChangeLog:

	* c-parser.cc (c_parser_omp_target_enter_data,
	c_parser_omp_target_exit_data): Accept tofrom
	map-type modifier but use 'to' / 'from' internally.

gcc/cp/ChangeLog:

	* parser.cc (cp_parser_omp_target_enter_data,
	cp_parser_omp_target_exit_data): Accept tofrom
	map-type modifier but use 'to' / 'from' internally.

gcc/fortran/ChangeLog:

	* dump-parse-tree.cc (show_omp_namelist): For the map-type,
	also handle the always modifer and release/delete.
	* openmp.cc (resolve_omp_clauses): Accept tofrom
	map-type modifier for target enter/exit data,
	but use 'to' / 'from' internally.

libgomp/ChangeLog:

	* libgomp.texi (OpenMP 5.2): Mark target enter/exit data
	with fromto as implemented.

gcc/testsuite/ChangeLog:

	* c-c++-common/gomp/target-data-2.c: New test.
	* c-c++-common/gomp/target-data-3.c: New test.
	* gfortran.dg/gomp/target-data-1.f90: New test.
	* gfortran.dg/gomp/target-data-2.f90: New test.
2022-07-01 17:52:03 +02:00
Uros Bizjak
f843bea4ca i386: Use "r" constraint in *andn<mode>3_doubleword_bmi
ANDN is non-destructive, so use "r" instead of "0" for its operand 1 constraint.

2022-07-01  Uroš Bizjak  <ubizjak@gmail.com>

gcc/ChangeLog:

	* config/i386/i386.md (*andn<mode>3_doubleword_bmi):
	Use "r" constraint for operand 1.
2022-07-01 17:26:01 +02:00
Marek Polacek
2ea6c59349 c++: warn about using keywords as identifiers [PR106111]
In C++03, -Wc++11-compat should warn about

  int constexpr;

since 'constexpr' is a keyword in C++11.  Jonathan reports that
we don't emit a similar warning for 'alignas' or 'alignof', and,
as I found out, 'thread_local'.

Similarly, we don't warn for most C++20 keywords.  That happens
because RID_LAST_CXX20 hasn't been updated in a while.

	PR c++/106111

gcc/c-family/ChangeLog:

	* c-common.h (enum rid): Update RID_LAST_CXX20.

gcc/cp/ChangeLog:

	* parser.cc (cp_lexer_get_preprocessor_token): Also warn about
	RID_ALIGNOF, RID_ALIGNAS, RID_THREAD.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp0x/keywords1.C: New test.
	* g++.dg/cpp2a/keywords1.C: New test.
2022-07-01 11:09:38 -04:00
Nick Clifton
9234cdca6e Add a recursion limit to the demangle_const function in the Rust demangler.
libiberty/
	PR demangler/105039
	* rust-demangle.c (demangle_const): Add recursion limit.
2022-07-01 16:00:06 +01:00
Jason Merrill
aefe23f720 c++: tweak resolve_args change
I don't know why I used tf_error instead of complain here.

	PR c++/105779

gcc/cp/ChangeLog:

	* call.cc (resolve_args): Use complain.
2022-07-01 10:49:23 -04:00
Jason Merrill
288c6cce02 c++: add fixup to missing .template warning
I experimented with giving this diagnostic in another place, which didn't
work out, but we can still benefit from adding the fixup.

gcc/cp/ChangeLog:

	* parser.cc (missing_template_diag): Split out...
	(cp_parser_id_expression): ...from here.
2022-07-01 10:49:23 -04:00
Jason Merrill
07ac550393 c++: dependent generic lambda template-id [PR106024]
We were wrongly looking up the generic lambda op() in a dependent scope, and
then trying to look up its instantiation at substitution time, but lambdas
aren't instantiated, so we crashed.  The fix is to not look into dependent
class scopes.

But this created trouble with wrongly trying to use a template from the
enclosing scope when we aren't actually looking at a template-argument-list,
in template/lookup18.C, so let's avoid that.

	PR c++/106024

gcc/cp/ChangeLog:

	* parser.cc (missing_template_diag): Factor out...
	(cp_parser_id_expression): ...from here.
	(cp_parser_lookup_name): Don't look in dependent object_type.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp2a/lambda-generic10.C: New test.
2022-07-01 10:49:23 -04:00
Richard Biener
63abe04999 Avoid unused sbitmap in update_ssa
The following avoids copying and using blocks_to_update to
the interesting_blocks sbitmap when doing update_ssa as it is
unused besides the redundant query in the domwalk.

	* tree-into-ssa.cc (rewrite_update_dom_walker::before_dom_children):
	Do not look at interesting_blocks which is a copy of
	blocks_to_update.
	(update_ssa): Do not initialize it.
	(pass_build_ssa::execute): Set interesting_blocks to NULL
	after releasing it.
2022-07-01 15:21:38 +02:00
Richard Biener
2b0937946b Revert maybe_ne -> known_ne change in vn_reference_lookup_3
This reverts the change as discussed.

2022-07-01  Richard Biener  <rguenther@suse.de>

	* tree-ssa-sccvn.cc (vn_reference_lookup_3): Revert
	back to using maybe_ne (off, -1).
2022-07-01 14:20:40 +02:00
Richard Biener
08ed796ed0 Make sure checking code is conditional in VN
VN has checking code with gcc_unreachable (), the following makes
it cheaper by instead guarding the side-effect with flag_checking.

2022-07-01  Richard Biener  <rguenther@suse.de>

	* tree-ssa-sccvn.cc (vn_nary_op_insert_into): Make
	checking dominance check conditional on flag_checking.
2022-07-01 14:20:35 +02:00