From: Martin Liska Date: Fri, 25 Nov 2016 14:23:25 +0000 (+0100) Subject: Don't use priority {cd}tors if not supported by a target (PR X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=78681a7b92549b1daa579aeeb78bb498aa167040;p=gcc.git Don't use priority {cd}tors if not supported by a target (PR PR gcov-profile/78086 * g++.dg/gcov/pr16855.C: Clean up the test case. * g++.dg/gcov/pr16855-priority.C: New test. * coverage.c (build_init_ctor): Don't use priority {cd}tors if not supported by a target. Set priority to 100 if possible. (build_gcov_exit_decl): Likewise. From-SVN: r242877 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index f87b9c5d68b..39e980a254e 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2016-11-25 Martin Liska + + PR gcov-profile/78086 + * coverage.c (build_init_ctor): Don't use priority {cd}tors if + not supported by a target. Set priority to 100 if possible. + (build_gcov_exit_decl): Likewise. + 2016-11-25 Richard Biener PR ipa/78515 diff --git a/gcc/coverage.c b/gcc/coverage.c index 8810710be4f..4167e26b208 100644 --- a/gcc/coverage.c +++ b/gcc/coverage.c @@ -1056,8 +1056,10 @@ build_init_ctor (tree gcov_info_type) stmt = build_call_expr (init_fn, 1, stmt); append_to_statement_list (stmt, &ctor); - /* Generate a constructor to run it (with priority 99). */ - cgraph_build_static_cdtor ('I', ctor, DEFAULT_INIT_PRIORITY - 1); + /* Generate a constructor to run it. */ + int priority = SUPPORTS_INIT_PRIORITY + ? MAX_RESERVED_INIT_PRIORITY: DEFAULT_INIT_PRIORITY; + cgraph_build_static_cdtor ('I', ctor, priority); } /* Generate the destructor function to call __gcov_exit. */ @@ -1078,8 +1080,11 @@ build_gcov_exit_decl (void) tree stmt = build_call_expr (init_fn, 0); append_to_statement_list (stmt, &dtor); - /* Generate a destructor to run it (with priority 99). */ - cgraph_build_static_cdtor ('D', dtor, MAX_RESERVED_INIT_PRIORITY - 1); + /* Generate a destructor to run it. */ + int priority = SUPPORTS_INIT_PRIORITY + ? MAX_RESERVED_INIT_PRIORITY: DEFAULT_INIT_PRIORITY; + + cgraph_build_static_cdtor ('D', dtor, priority); } /* Create the gcov_info types and object. Generate the constructor diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 39465545501..25663cefe0a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2016-11-25 Martin Liska + + PR gcov-profile/78086 + * g++.dg/gcov/pr16855.C: Clean up the test case. + * g++.dg/gcov/pr16855-priority.C: New test. + 2016-11-25 Richard Biener PR ipa/78515 diff --git a/gcc/testsuite/g++.dg/gcov/pr16855-priority.C b/gcc/testsuite/g++.dg/gcov/pr16855-priority.C new file mode 100644 index 00000000000..7e395652a63 --- /dev/null +++ b/gcc/testsuite/g++.dg/gcov/pr16855-priority.C @@ -0,0 +1,79 @@ +/* { dg-options "-fprofile-arcs -ftest-coverage" } */ +/* { dg-do run { target native } } */ +/* { dg-require-effective-target init_priority } */ + +#include +#include + +int a; + +void +foo () +{ + fprintf (stderr, "In foo\n"); + a = 123; /* count(1) */ +} + +using namespace std; +class Test +{ +public: + Test (void) { fprintf (stderr, "In Test::Test\n"); /* count(1) */ } + ~Test (void) { fprintf (stderr, "In Test::~Test\n"); /* count(1) */ } +} T1; + +void +uncalled (void) +{ + fprintf (stderr, "In uncalled\n"); /* count(#####) */ +} + +int +main (void) +{ + atexit (&foo); + fprintf (stderr, "In main\n"); /* count(1) */ + return 0; +} + +static void __attribute__ ((constructor)) ctor_default () +{ + fprintf (stderr, "in constructor(())\n"); /* count(1) */ +} + +static void __attribute__ ((constructor ((101)))) ctor_100 () +{ + fprintf (stderr, "in constructor((101))\n"); /* count(1) */ +} + +static void __attribute__ ((constructor ((500)))) ctor_500 () +{ + fprintf (stderr, "in constructor((500))\n"); /* count(1) */ +} + +static void __attribute__ ((constructor ((65535)))) ctor_65535 () +{ + fprintf (stderr, "in constructor((65535))\n"); /* count(1) */ +} + +static void __attribute__ ((destructor)) dtor_default () +{ + fprintf (stderr, "in destructor(())\n"); /* count(1) */ +} + +static void __attribute__ ((destructor ((101)))) dtor_100 () +{ + fprintf (stderr, "in destructor((101))\n"); /* count(1) */ +} + +static void __attribute__ ((destructor ((500)))) dtor_500 () +{ + fprintf (stderr, "in destructor((500))\n"); /* count(1) */ +} + +static void __attribute__ ((destructor ((65535)))) dtor_65535 () +{ + fprintf (stderr, "in destructor((65535))\n"); /* count(1) */ +} + +/* { dg-final { run-gcov branches { -b pr16855-priority.C } } } */ diff --git a/gcc/testsuite/g++.dg/gcov/pr16855.C b/gcc/testsuite/g++.dg/gcov/pr16855.C index 91801d4d1e9..d7aa8a4f72c 100644 --- a/gcc/testsuite/g++.dg/gcov/pr16855.C +++ b/gcc/testsuite/g++.dg/gcov/pr16855.C @@ -2,46 +2,47 @@ /* { dg-do run { target native } } */ #include +#include int a; -void foo() +void +foo () { - a = 123; /* count(1) */ + fprintf (stderr, "In foo\n"); + a = 123; /* count(1) */ } -#include using namespace std; -class Test { +class Test +{ public: - Test(void){ - cout<< "In Test ctor" << endl; /* count(1) */ - } - ~Test(void){ - cout<< "In Test dtor" << endl; /* count(1) */ - } -}T1; - -void uncalled(void){ - cout<< "In uncalled" << endl; /* count(#####) */ -} -int main(void){ -atexit (&foo); -// Test T2; -cout<< "In main" << endl; /* count(1) */ -return 0; + Test (void) { fprintf (stderr, "In Test::Test\n"); /* count(1) */ } + ~Test (void) { fprintf (stderr, "In Test::~Test\n"); /* count(1) */ } +} T1; + +void +uncalled (void) +{ + fprintf (stderr, "In uncalled\n"); /* count(#####) */ } -#include +int +main (void) +{ + atexit (&foo); + fprintf (stderr, "In main\n"); /* count(1) */ + return 0; +} -__attribute__((constructor)) -static void construct_navigationBarImages() { - fprintf (stderr, "((construct_navigationBarImages))"); /* count(1) */ +static void __attribute__ ((constructor)) ctor_default () +{ + fprintf (stderr, "in constructor(())\n"); /* count(1) */ } -__attribute__((destructor)) -static void destroy_navigationBarImages() { - fprintf (stderr, "((destroy_navigationBarImages))"); /* count(1) */ +static void __attribute__ ((destructor)) dtor_default () +{ + fprintf (stderr, "in destructor(())\n"); /* count(1) */ } /* { dg-final { run-gcov branches { -b pr16855.C } } } */