This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: How to easily identify that a FUNCTION_DECL is a lambda
- From: Richard Biener <richard dot guenther at gmail dot com>
- To: gcc at gcc dot gnu dot org,Nathan Sidwell <nathan at acm dot org>,Martin Liška <mliska at suse dot cz>,GCC Development <gcc at gcc dot gnu dot org>
- Cc: Jason Merrill <jason at redhat dot com>
- Date: Mon, 16 Jul 2018 18:04:34 +0200
- Subject: Re: How to easily identify that a FUNCTION_DECL is a lambda
- References: <2bc49528-72cc-46fd-2105-63d292074034@suse.cz> <86137da9-4229-4cc7-bb17-607f726aefa5@acm.org>
On July 16, 2018 4:30:42 PM GMT+02:00, Nathan Sidwell <nathan@acm.org> wrote:
>On 07/16/2018 03:23 AM, Martin Liška wrote:
>> Hi.
>>
>> For purpose of --coverage I would like to distinguish lambda
>functions
>> among DECL_ARTIFICIAL functions. Currently, cp-tree.h provides macro:
>>
>> /* Test if FUNCTION_DECL is a lambda function. */
>> #define LAMBDA_FUNCTION_P(FNDECL) \
>> (DECL_DECLARES_FUNCTION_P (FNDECL) \
>> && DECL_OVERLOADED_OPERATOR_P (FNDECL) \
>> && DECL_OVERLOADED_OPERATOR_IS (FNDECL, CALL_EXPR) \
>> && LAMBDA_TYPE_P (CP_DECL_CONTEXT (FNDECL)))
>>
>> That's FE-specific function that probably should not be called from
>> middle-end. Any idea how to distinguish lambdas?
>
>You're going to need a language hook. Lambda fns are just regular
>member fns outside the front-end. Make the hook more than
>'lambda_fn_p', so it can extend to other exciting C++ features.
>Perhaps
>something like:
>
>enum synthetic_fn_kind {
> sfk_none,
> sfk_cxx_lambda,
>};
>synthetic_fn_kind (*categorize_artificial_fn) (tree decl);
>
>We'll have to expose the union of FE's such sythetic fns to the middle
>end, but at least not how the FE distinguishes them.
>
>Hm, but isn't this info lost if we're in LTO at this point? Not sure
>if
>we'll need to propagate this through the LTO streaming. I guess that's
>
>a later bug to handle though.
Just use a spare bit in function_decl, then we can simply stream it.
Richard.
>nathan