diff options
author | Jakub Jelinek <jakub@redhat.com> | 2024-11-02 18:47:27 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2024-11-02 18:47:27 +0100 |
commit | 1fb467dbcc2cdd3bb89fa860a1f86b7e334e0ce3 (patch) | |
tree | 1342bde0718230af0e71f05c1e4cc8229f01e2f2 /gcc/gimplify.cc | |
parent | 815e48e3d42231b675bae1dec5fa26890f048ef1 (diff) | |
download | gcc-1fb467dbcc2cdd3bb89fa860a1f86b7e334e0ce3.zip gcc-1fb467dbcc2cdd3bb89fa860a1f86b7e334e0ce3.tar.gz gcc-1fb467dbcc2cdd3bb89fa860a1f86b7e334e0ce3.tar.bz2 |
gimplify: Fix up RAW_DATA_CST related ICE [PR117384]
Apparently tree_output_constant_def doesn't strictly guarantee that the
returned VAR_DECL will have the same or uselessly convertible type as
the type of the constant passed to it, compare_constants says:
/* For arrays, check that mode, size and storage order match. */
/* For record and union constructors, require exact type equality. */
The older use of tree_output_constant_def in gimplify.cc was already
handling this right:
ctor = tree_output_constant_def (ctor);
if (!useless_type_conversion_p (type, TREE_TYPE (ctor)))
ctor = build1 (VIEW_CONVERT_EXPR, type, ctor);
but the spot I've added for RAW_DATA_CST missed this.
So, the following patch adds that.
2024-11-02 Jakub Jelinek <jakub@redhat.com>
PR middle-end/117384
* gimplify.cc (gimplify_init_ctor_eval): Add VIEW_CONVERT_EXPR around
rctor if it doesn't have expected type.
* c-c++-common/init-7.c: New test.
Diffstat (limited to 'gcc/gimplify.cc')
-rw-r--r-- | gcc/gimplify.cc | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc index fd18d8b..827941b 100644 --- a/gcc/gimplify.cc +++ b/gcc/gimplify.cc @@ -5420,6 +5420,8 @@ gimplify_init_ctor_eval (tree object, vec<constructor_elt, va_gc> *elts, cref = build2 (MEM_REF, rtype, addr, build_int_cst (ptr_type_node, 0)); rctor = tree_output_constant_def (rctor); + if (!useless_type_conversion_p (rtype, TREE_TYPE (rctor))) + rctor = build1 (VIEW_CONVERT_EXPR, rtype, rctor); if (gimplify_expr (&cref, pre_p, NULL, is_gimple_lvalue, fb_lvalue) != GS_ERROR) gimplify_seq_add_stmt (pre_p, |