On Wed, 6 Apr 2022, Jakub Jelinek wrote: > On Wed, Apr 06, 2022 at 09:49:25AM +0200, Richard Biener wrote: > > On trees we'd use tree_[sign_]nop_conversion () instead of > > useless_type_conversion_p, I think it's OK to allow all such > > pointer conversions. In the end this probably means being > > more forgiving than TYPE_MAIN_VARIANT equivalence throughout, that > > would also make the code more similar to > > gimple_builtin_call_types_compatible_p besides > > s/useless_type_conversion_p/tree_sign_nop_conversion/ > > > > What do you think? If we don't go for strict TYPE_MAIN_VARIANT > > compatibility we should apply lax rules for all, the return > > type and all argument types. It's not that the GENERIC we end > > up building from GIMPLE in various places adheres to the strict > > GENERIC type compatibility rules ... > > Dunno, we don't really have a verifier for GENERIC. > > Don't we even require that the types are actually same rather than > similar for say binary ops other than shifts, or for comparisons, > or result and first argument for unary and binary etc.?
I think it's fine to use typedef variants or CV qualified variants there. But indeed fold-const.cc in most places fold_convert()s everything, but mostly because it strips nop conversions before applying patterns. > I think at least for the most common cases the C/C++ FEs ensure that > through choosing some common type for the operation and folding the > arguments to that type. Though I bet we violate it pretty often > with e.g. sizetype vs. size_type_node differences etc. Yeah. I think if we can trust the GENERIC input then we'll be fine. Of course as we see here, the GENERIC input from frontends can be garbage (which IMHO as said is a bug in the frontends). We shouldn't worry too much to be precise when trying to fend off garbage input, we just have to make sure to make the output not even worse. Richard.