Hi Jason > On 26 May 2025, at 15:07, Jason Merrill <ja...@redhat.com> wrote: > > Tested x86_64-pc-linux-gnu, OK for trunk? > > Iain, will you verify that one of your coroutine testcases breaks without this > fix?
Yes; all current coroutine ramp cleanups are exposed to (potential) UB at -O > 0. This patch resolves the issue (together with a typo fix that I should get applied later today). Note: this is very hard to test by execution since, on most platforms I’ve tried, the coroutine frame content remains after it is freed and so the dangling pointer still sees something that looks valid. I’ve been manually checking the gimple; possibly we might find some not-too-fragile test that way. Iain. > I don't think lambda or anonymous union uses of DECL_VALUE_EXPR can break > in the same way, though this change is also correct for them. > > -- 8< -- > > This PR noted that fold_truth_andor was wrongly changing && to & where the > RHS is a VAR_DECL with DECL_VALUE_EXPR; we can't assume that such can be > evaluated unconditionally. > > To be more precise we could recurse into DECL_VALUE_EXPR, but that doesn't > seem worth bothering with since typical uses involve a COMPONENT_REF, which > is not simple. > > PR c++/120400 > > gcc/ChangeLog: > > * fold-const.cc (simple_operand_p): False for vars with > DECL_VALUE_EXPR. > --- > gcc/fold-const.cc | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc > index 5f48ced5063..014f4218793 100644 > --- a/gcc/fold-const.cc > +++ b/gcc/fold-const.cc > @@ -5085,6 +5085,11 @@ simple_operand_p (const_tree exp) > #pragma weak, etc). */ > && ! TREE_PUBLIC (exp) > && ! DECL_EXTERNAL (exp) > + /* DECL_VALUE_EXPR will expand to something non-simple. */ > + && ! ((VAR_P (exp) > + || TREE_CODE (exp) == PARM_DECL > + || TREE_CODE (exp) == RESULT_DECL) > + && DECL_HAS_VALUE_EXPR_P (exp)) > /* Weakrefs are not safe to be read, since they can be NULL. > They are !TREE_PUBLIC && !DECL_EXTERNAL but still > have DECL_WEAK flag set. */ > > base-commit: f59ff19bc3d37f4dd159db541ed4f07efb10fcc8 > -- > 2.49.0 >