From f2db46026408095de13e9b74659fd06d9c02f7f3 Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Wed, 3 Oct 2018 10:30:10 +0200 Subject: [PATCH] Properly mark lambdas in GCOV (PR gcov-profile/86109). 2018-10-03 Martin Liska PR gcov-profile/86109 * coverage.c (coverage_begin_function): Do not mark lambdas as artificial. * tree-core.h (struct GTY): Remove tm_clone_flag and introduce new lambda_function. * tree.h (DECL_LAMBDA_FUNCTION): New macro. 2018-10-03 Martin Liska PR gcov-profile/86109 * parser.c (cp_parser_lambda_declarator_opt): Set DECL_LAMBDA_FUNCTION for lambdas. 2018-10-03 Martin Liska PR gcov-profile/86109 * g++.dg/gcov/pr86109.C: New test. From-SVN: r264806 --- gcc/ChangeLog | 9 +++++++++ gcc/coverage.c | 3 ++- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/parser.c | 1 + gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/gcov/pr86109.C | 16 ++++++++++++++++ gcc/tree-core.h | 2 +- gcc/tree.h | 4 ++++ 8 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/gcov/pr86109.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 9906789b510..a6e1a8ebdf0 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2018-10-03 Martin Liska + + PR gcov-profile/86109 + * coverage.c (coverage_begin_function): Do not + mark lambdas as artificial. + * tree-core.h (struct GTY): Remove tm_clone_flag + and introduce new lambda_function. + * tree.h (DECL_LAMBDA_FUNCTION): New macro. + 2018-10-02 Aaron Sawdey PR target/87474 diff --git a/gcc/coverage.c b/gcc/coverage.c index 701460cf929..599a3bb9aeb 100644 --- a/gcc/coverage.c +++ b/gcc/coverage.c @@ -630,7 +630,8 @@ coverage_begin_function (unsigned lineno_checksum, unsigned cfg_checksum) gcov_write_string (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl))); gcov_write_unsigned (DECL_ARTIFICIAL (current_function_decl) - && !DECL_FUNCTION_VERSIONED (current_function_decl)); + && !DECL_FUNCTION_VERSIONED (current_function_decl) + && !DECL_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/ChangeLog b/gcc/cp/ChangeLog index fd0fb8a720a..53ff0eb0a27 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2018-10-03 Martin Liska + + PR gcov-profile/86109 + * parser.c (cp_parser_lambda_declarator_opt): + Set DECL_LAMBDA_FUNCTION for lambdas. + 2018-10-02 Richard Biener * name-lookup.c (check_local_shadow): Do not test DECL_FROM_INLINE. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 6696f174d75..a17cc3f23f2 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -10641,6 +10641,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)) = closure_identifier; + DECL_LAMBDA_FUNCTION (fco) = 1; } if (template_param_list) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ce3b03b01a2..a888b8ffa4d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-10-03 Martin Liska + + PR gcov-profile/86109 + * g++.dg/gcov/pr86109.C: New test. + 2018-10-02 Marc Glisse * gcc.dg/tree-ssa/muldiv-1.c: New file. diff --git a/gcc/testsuite/g++.dg/gcov/pr86109.C b/gcc/testsuite/g++.dg/gcov/pr86109.C new file mode 100644 index 00000000000..9052d2e5a04 --- /dev/null +++ b/gcc/testsuite/g++.dg/gcov/pr86109.C @@ -0,0 +1,16 @@ + +/* { dg-options "-fprofile-arcs -ftest-coverage -std=c++11" } */ +/* { dg-do run { target native } } */ + +int main() +{ + auto partially_uncovered_lambda = [](int i) { /* count(1) */ + if (i > 10) /* count(1) */ + return 0; /* count(1) */ + return 1; /* count(#####) */ + }; + + return partially_uncovered_lambda(20); /* count(1) */ +} + +/* { dg-final { run-gcov pr86109.C } } */ diff --git a/gcc/tree-core.h b/gcc/tree-core.h index dee27f89dec..cd3a2bad08c 100644 --- a/gcc/tree-core.h +++ b/gcc/tree-core.h @@ -1789,8 +1789,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 35536f372a3..a0f24b61ef1 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -3041,6 +3041,10 @@ extern vec **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 lambda function. */ +#define DECL_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)\ -- 2.30.2