Hi! As discussed in the https://gcc.gnu.org/pipermail/gcc-patches/2025-January/674492.html thread, the following patch attempts to improve build_vec_init generated code. E.g. on g++.dg/eh/aggregate1.C test the patch has differences like: D.2988 = &D.2950->e1; D.2989 = D.2988; D.2990 = 1; try { goto <D.2996>; <D.2997>: A::A (D.2989); D.2990 = D.2990 + -1; D.2989 = D.2989 + 1; <D.2996>: if (D.2990 >= 0) goto <D.2997>; else goto <D.2995>; <D.2995>: retval.4 = D.2988; _13 = &D.2950->e2; A::A (_13); - D.2990 = 1; + D.2988 = 0B; D.2951 = D.2951 + -1; } catch { { struct A * D.2991; if (D.2988 != 0B) goto <D.3028>; else goto <D.3029>; <D.3028>: _11 = 1 - D.2990; _12 = (sizetype) _11; D.2991 = D.2988 + _12; <D.3030>: if (D.2991 == D.2988) goto <D.3031>; else goto <D.3032>; <D.3032>: D.2991 = D.2991 + 18446744073709551615; A::~A (D.2991); goto <D.3030>; <D.3031>: goto <D.3033>; <D.3029>: <D.3033>: } } in 3 spots. As you can see, both setting D.2990 (i.e. iterator) to maxindex and setting D.2988 (i.e. rval) to nullptr have the same effect of not actually destructing anything anymore in the cleanup, the advantage of clearing rval is that setting something to zero is often less expensive than potentially huge maxindex and that the cleanup tests that value first.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2025-04-30 Jakub Jelinek <ja...@redhat.com> PR c++/117827 * init.cc (build_vec_init): Push to *cleanup_flags clearing of rval instead of setting of iterator to maxindex. --- gcc/cp/init.cc.jj 2025-01-24 19:26:31.980193087 +0100 +++ gcc/cp/init.cc 2025-01-24 19:45:03.324702001 +0100 @@ -4749,7 +4749,8 @@ build_vec_init (tree base, tree maxindex itself. But that breaks when gimplify_target_expr adds a clobber cleanup that runs before the build_vec_init cleanup. */ if (cleanup_flags) - vec_safe_push (*cleanup_flags, build_tree_list (iterator, maxindex)); + vec_safe_push (*cleanup_flags, + build_tree_list (rval, build_zero_cst (ptype))); } /* Should we try to create a constant initializer? */ Jakub