https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121500
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |ppalka at gcc dot
gnu.org
Target Milestone|--- |17.0
Status|NEW |ASSIGNED
--- Comment #3 from Patrick Palka <ppalka at gcc dot gnu.org> ---
The GENERIC dump (-fdump-tree-generic=/dev/stdout) shows the problem:
;; Function main()::<lambda(this auto:1)> [with auto:1 = main()::<lambda(this
auto:1)>] (null)
;; enabled by -tree-original
{
struct A data [value-expr: self.__data];
struct A data [value-expr: self.__data];
return <retval> = data.n != 42;
}
A's non-trivial copy constructor in turn makes the lambda non trivially
copyable, which makes us pass the explicit by-value this parameter 'self' by
invisible reference.
But since self is now an invisiref parameter, the self.__data access is
nonsensical and should be rewritten to (*self).__data. We're failing to do
that because cp_genericize_r never walks into DECL_VALUE_EXPR!
This fixes it
diff --git a/gcc/cp/cp-gimplify.cc b/gcc/cp/cp-gimplify.cc
index 9d96ce99ea92..5edc3f62342d 100644
--- a/gcc/cp/cp-gimplify.cc
+++ b/gcc/cp/cp-gimplify.cc
@@ -1871,6 +1871,14 @@ cp_genericize_r (tree *stmt_p, int *walk_subtrees, void
*data)
return NULL;
}
+ if (TREE_CODE (stmt) == VAR_DECL
+ && DECL_HAS_VALUE_EXPR_P (stmt))
+ {
+ tree u = DECL_VALUE_EXPR (stmt);
+ cp_walk_tree (&u, cp_genericize_r, data, NULL);
+ SET_DECL_VALUE_EXPR (stmt, u);
+ }
+
/* Dereference invisible reference parms. */
if (wtd->handle_invisiref_parm_p && is_invisiref_parm (stmt))
{
It's too late to fix this for GCC 16 (at least with this approach), so
deferring to next stage1