On Tue, 10 Aug 2021, Eric Botcazou wrote: > > The question is whether we instead want to amend build3 to > > set TREE_THIS_VOLATILE automatically when the FIELD_DECL has > > it set. At least for the Fortran FE cases the gimplifier > > fails to see some volatile references and thus can generate > > wrong code which is a latent issue. > > What do we do for other similar flags, e.g. TREE_READONLY?
build3 currently does no special processing for the FIELD_DECL operand, it just sets TREE_THIS_VOLATILE from operand zero for tcc_references. The C and C++ frontends have repeated patterns like ref = build3 (COMPONENT_REF, subtype, datum, subdatum, NULL_TREE); SET_EXPR_LOCATION (ref, loc); if (TREE_READONLY (subdatum) || (use_datum_quals && TREE_READONLY (datum))) TREE_READONLY (ref) = 1; if (TREE_THIS_VOLATILE (subdatum) || (use_datum_quals && TREE_THIS_VOLATILE (datum))) TREE_THIS_VOLATILE (ref) = 1; Leaving out TREE_READONLY shouldn't have any correctness issue. It's just that when adjusting the SSA operand scanner to correctly interpret GENERIC that this uncovers pre-existing issues in the Fortran frontend (one manifests in a testsuite FAIL - otherwise I wouldn't have noticed). I'm fine with just plugging the Fortran FE holes as we discover them but I did not check other frontends and testsuite coverage is weak. Now - I wonder if there's a reason a frontend might _not_ want to set TREE_THIS_VOLATILE on a COMPONENT_REF when the FIELD_DECL has TREE_THIS_VOLATILE set. I guess I'll do one more experiment and add verification that TREE_THIS_VOLATILE on COMPONENT_REFs and FIELD_DECLs is consistent and see where that trips. Richard.