https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93258
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2020-01-14
Ever confirmed|0 |1
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Global CTORs are not gimplified at all, we have to work hard in
canonicalize_constructor_val to make it "valid". Like
/* In CONSTRUCTORs we may see unfolded constants like (int (*) ()) 0. */
if (TREE_CODE (cval) == INTEGER_CST)
{
if (TREE_OVERFLOW_P (cval))
cval = drop_tree_overflow (cval);
if (!useless_type_conversion_p (TREE_TYPE (orig_cval), TREE_TYPE (cval)))
cval = fold_convert (TREE_TYPE (orig_cval), cval);
return cval;
}
(const char *) "" + 6; looks like it should be handled by
if (TREE_CODE (cval) == POINTER_PLUS_EXPR
&& TREE_CODE (TREE_OPERAND (cval, 1)) == INTEGER_CST)
{
tree ptr = TREE_OPERAND (cval, 0);
if (is_gimple_min_invariant (ptr))
cval = build1_loc (EXPR_LOCATION (cval),
ADDR_EXPR, TREE_TYPE (ptr),
fold_build2 (MEM_REF, TREE_TYPE (TREE_TYPE (ptr)),
ptr,
fold_convert (ptr_type_node,
TREE_OPERAND (cval,
1))));
}
but we need another STRIP_NOPS before the is_gimple_min_invariant (ptr) check
on ptr I guess?
Btw, on trunk I see it optimized, maybe some recent CTOR "fixing" fixed it
again? Can you double-check?
If it's fixed again I suggest to add the testcase (ck should be elided
in the assembly?)