PR middle-end/97840 - Bogus -Wmaybe-uninitialized passing an empty object to a function

gcc/ChangeLog:
	* tree-ssa-uninit.c (maybe_warn_operand): Call is_empty_type.
	* tree.c (default_is_empty_type): Rename...
	(is_empty_type): ...to this.
	* tree.h (is_empty_type): Declare.
This commit is contained in:
Martin Sebor 2020-11-16 20:01:10 -07:00
parent b1ecb86569
commit 3072125a40
3 changed files with 7 additions and 9 deletions

View File

@ -404,10 +404,7 @@ maybe_warn_operand (ao_ref &ref, gimple *stmt, tree lhs, tree rhs,
tree rhstype = TREE_TYPE (rhs);
if (POINTER_TYPE_P (rhstype))
rhstype = TREE_TYPE (rhstype);
if (TYPE_EMPTY_P (rhstype)
|| (RECORD_OR_UNION_TYPE_P (rhstype)
&& (!first_field (rhstype)
|| default_is_empty_record (rhstype))))
if (is_empty_type (rhstype))
return NULL_TREE;
bool warned = false;

View File

@ -15136,22 +15136,22 @@ get_nonnull_args (const_tree fntype)
/* Returns true if TYPE is a type where it and all of its subobjects
(recursively) are of structure, union, or array type. */
static bool
default_is_empty_type (tree type)
bool
is_empty_type (const_tree type)
{
if (RECORD_OR_UNION_TYPE_P (type))
{
for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
if (TREE_CODE (field) == FIELD_DECL
&& !DECL_PADDING_P (field)
&& !default_is_empty_type (TREE_TYPE (field)))
&& !is_empty_type (TREE_TYPE (field)))
return false;
return true;
}
else if (TREE_CODE (type) == ARRAY_TYPE)
return (integer_minus_onep (array_type_nelts (type))
|| TYPE_DOMAIN (type) == NULL_TREE
|| default_is_empty_type (TREE_TYPE (type)));
|| is_empty_type (TREE_TYPE (type)));
return false;
}
@ -15170,7 +15170,7 @@ default_is_empty_record (const_tree type)
if (TREE_ADDRESSABLE (type))
return false;
return default_is_empty_type (TYPE_MAIN_VARIANT (type));
return is_empty_type (TYPE_MAIN_VARIANT (type));
}
/* Determine whether TYPE is a structure with a flexible array member,

View File

@ -6233,6 +6233,7 @@ extern void gt_pch_nx (tree &);
extern void gt_pch_nx (tree &, gt_pointer_operator, void *);
extern bool nonnull_arg_p (const_tree);
extern bool is_empty_type (const_tree);
extern bool default_is_empty_record (const_tree);
extern bool flexible_array_type_p (const_tree);
extern HOST_WIDE_INT arg_int_size_in_bytes (const_tree);