On Wed, 22 Feb 2023 at 12:16, Jonathan Wakely <jwak...@redhat.com> wrote: > > On Wed, 22 Feb 2023 at 11:49, Richard Biener <rguent...@suse.de> wrote: > > > > On Wed, 22 Feb 2023, Jakub Jelinek wrote: > > > > > On Wed, Feb 22, 2023 at 09:52:06AM +0000, Richard Biener wrote: > > > > > The following testcase ICEs because we still have some spots that > > > > > treat BUILT_IN_UNREACHABLE specially but not BUILT_IN_UNREACHABLE_TRAP > > > > > the same. > > > > > > This patch uses (fndecl_built_in_p (node, BUILT_IN_UNREACHABLE) > > > || fndecl_built_in_p (node, BUILT_IN_UNREACHABLE_TRAP)) > > > a lot and from grepping around, we do something like that in lots of > > > other places, or in some spots instead as > > > (fndecl_built_in_p (node, BUILT_IN_NORMAL) > > > && (DECL_FUNCTION_CODE (node) == BUILT_IN_WHATEVER1 > > > || DECL_FUNCTION_CODE (node) == BUILT_IN_WHATEVER2)) > > > The following patch adds an overload for this case, so we can write > > > it in a shorter way. It isn't worth for 3+, code in that case > > > typically uses the fndecl_built_in_p (node, BUILT_IN_NORMAL) > > > + switch in DECL_FUNCTION_CODE. > > > > > > If this isn't appropriate for GCC 13 (or not at all), I think we'll > > > need to change at least ipa-prop.cc because it suffers from the same > > > problem as the previous patch was fixing. > > > > Is it possible to use C++ (template) magic to expand the > 1 argument > > case to > > > > if (fndecl_built_in_p (BUILT_IN_NORMA) > > && (... || ... || ... > > > > lispy we'd expand to the head check and then recursively on the > > first and the remaining args. > > In C++17 yes, there are fold expressions, so you'd write it as literally: > > if (fndecl_built_in_p (BUILT_IN_NORMA) > && (DECL_FUNCTION_CODE (node) == name || ...) > > Where "name" is a parameter pack, and the "..." is literally what the > code would contain, not an abbreviation for the example :-) > > For C++11 you can write it recursively. Something like: > > > // Single argument case terminates recursion. > inline bool > fndecl_built_in_matches_name_p (const_tree node, built_in_function name1) > { > return DECL_FUNCTION_CODE (node) == name1; > } > > // Recursive case. If names... is an empty pack then the overload above > // is a better match. > template<typename... Functions> > inline bool > fndecl_built_in_matches_name_p (const_tree node, built_in_function name1, > Functions... names) > { > return DECL_FUNCTION_CODE (node) == name1 > || fndecl_built_in_matches_name_p (node, names...); > } > > // Call with one or more names. > template<typename... Functions> > inline bool > fndecl_built_in_p (const_tree node, built_in_function name1, > Functions names...) > { > return (fndecl_built_in_p (node, BUILT_IN_NORMAL) > && fndecl_built_in_matches_name_p (node, name1, names...); > } > > I think the "is a better match" comment is the status of C++ after a > DR, so might not actually be true in C++11 with GCC 4.8, I can check > that (and if needed, rewrite the recursive case to avoid the problem).
Yes, I was right, it doesn't work in gcc 4.8. This does though (with typos above fixed too, and actually tested on GCC 4.8.5): // Single argument case terminates recursion. inline bool fndecl_built_in_matches_name_p (const_tree node, built_in_function name1) { return DECL_FUNCTION_CODE (node) == name1; } // Recursive case for two or more names. template<typename... Functions> inline bool fndecl_built_in_matches_name_p (const_tree node, built_in_function name1, built_in_function name2, Functions... names) { return DECL_FUNCTION_CODE (node) == name1 || fndecl_built_in_matches_name_p (node, name2, names...); } // Call with one or more names. template<typename... Functions> inline bool fndecl_built_in_p (const_tree node, built_in_function name1, Functions... names) { return fndecl_built_in_p (node, BUILT_IN_NORMAL) && fndecl_built_in_matches_name_p (node, name1, names...); } The variadic template fndecl_builtin_p above can replace the existing one in gcc/tree.h and will work for all the existing cases with a single name argument, but also support multiple names.