This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: How to easily identify that a FUNCTION_DECL is a lambda


On 07/16/2018 06:09 PM, Nathan Sidwell wrote:
> On 07/16/2018 12:04 PM, Richard Biener wrote:
> 
>> Just use a spare bit in function_decl, then we can simply stream it.
> 
> If there's one, then sure.  (you've reminded me that there are a bunch of mutually disjoint flags in function_decl that could be collapsed to an enumeration.  This may be another such bit.)

There wasn't, but I was able to stole one unused (tm_clone_flag). About mutual disjoint, I believe following 3 can be
an enum:

  unsigned static_ctor_flag : 1;
  unsigned static_dtor_flag : 1;
  unsigned lambda_function: 1;

I'm attaching patch candidate, is the location where I set the flag correct?
Do I miss any other location where that should be set?

Thanks,
Martin

> 
> nathan
> 

diff --git a/gcc/coverage.c b/gcc/coverage.c
index da171c84d3c..a0506b74f82 100644
--- a/gcc/coverage.c
+++ b/gcc/coverage.c
@@ -656,7 +656,8 @@ coverage_begin_function (unsigned lineno_checksum, unsigned cfg_checksum)
   gcov_write_unsigned (cfg_checksum);
   gcov_write_string (IDENTIFIER_POINTER
 		     (DECL_ASSEMBLER_NAME (current_function_decl)));
-  gcov_write_unsigned (DECL_ARTIFICIAL (current_function_decl));
+  gcov_write_unsigned (DECL_ARTIFICIAL (current_function_decl)
+		       && !DECL_CXX_LAMBDA_FUNCTION (current_function_decl));
   gcov_write_filename (xloc.file);
   gcov_write_unsigned (xloc.line);
   gcov_write_unsigned (xloc.column);
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index d0f1e1e9701..bc65fa98b14 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -10639,6 +10639,7 @@ cp_parser_lambda_declarator_opt (cp_parser* parser, tree lambda_expr)
 	DECL_ARTIFICIAL (fco) = 1;
 	/* Give the object parameter a different name.  */
 	DECL_NAME (DECL_ARGUMENTS (fco)) = get_identifier ("__closure");
+	DECL_CXX_LAMBDA_FUNCTION (fco) = 1;
       }
     if (template_param_list)
       {
diff --git a/gcc/tree-core.h b/gcc/tree-core.h
index 4a04e9e8b26..4771312f5b6 100644
--- a/gcc/tree-core.h
+++ b/gcc/tree-core.h
@@ -1788,8 +1788,8 @@ struct GTY(()) tree_function_decl {
   unsigned pure_flag : 1;
   unsigned looping_const_or_pure_flag : 1;
   unsigned has_debug_args_flag : 1;
-  unsigned tm_clone_flag : 1;
   unsigned versioned_function : 1;
+  unsigned lambda_function: 1;
   /* No bits left.  */
 };
 
diff --git a/gcc/tree.h b/gcc/tree.h
index 79b675025d9..cb7975f9ba3 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -3043,6 +3043,10 @@ extern vec<tree, va_gc> **decl_debug_args_insert (tree);
 #define DECL_CXX_DESTRUCTOR_P(NODE)\
    (FUNCTION_DECL_CHECK (NODE)->decl_with_vis.cxx_destructor)
 
+/* In FUNCTION_DECL, this is set if this function is a C++ lambda function.  */
+#define DECL_CXX_LAMBDA_FUNCTION(NODE) \
+  (FUNCTION_DECL_CHECK (NODE)->function_decl.lambda_function)
+
 /* In FUNCTION_DECL that represent an virtual method this is set when
    the method is final.  */
 #define DECL_FINAL_P(NODE)\

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]