Hi.

The PR is about a function (__tls_init) that ends before it begins
(from line point of view). The patch uses location of a variable where
we first create the function declaration. I'm not much familiar with C++ FE,
but it works.

Survives bootstrap and regression test on ppc64le-linux-gnu.

Ready for trunk?
Thanks,
Martin

gcc/cp/ChangeLog:

2018-11-30  Martin Liska  <mli...@suse.cz>

        PR c++/88263
        * decl2.c (get_local_tls_init_fn): Add location_t argument and
        use it.
        (get_tls_init_fn): Call it with location of variable for which
        we'll need to create tls_init function.
        (handle_tls_init): Likewise.

gcc/testsuite/ChangeLog:

2018-11-30  Martin Liska  <mli...@suse.cz>

        * g++.dg/gcov/pr88263.C: New test.
---
 gcc/cp/decl2.c                      | 12 ++++++------
 gcc/testsuite/g++.dg/gcov/pr88263.C | 30 +++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 6 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/gcov/pr88263.C


diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
index ffc0d0d6ec4..0c1f3026c16 100644
--- a/gcc/cp/decl2.c
+++ b/gcc/cp/decl2.c
@@ -3327,15 +3327,15 @@ var_needs_tls_wrapper (tree var)
    translation unit.  */
 
 static tree
-get_local_tls_init_fn (void)
+get_local_tls_init_fn (location_t loc)
 {
   tree sname = get_identifier ("__tls_init");
   tree fn = get_global_binding (sname);
   if (!fn)
     {
-      fn = build_lang_decl (FUNCTION_DECL, sname,
-			     build_function_type (void_type_node,
-						  void_list_node));
+      fn = build_lang_decl_loc (loc, FUNCTION_DECL, sname,
+				build_function_type (void_type_node,
+						     void_list_node));
       SET_DECL_LANGUAGE (fn, lang_c);
       TREE_PUBLIC (fn) = false;
       DECL_ARTIFICIAL (fn) = true;
@@ -3365,7 +3365,7 @@ get_tls_init_fn (tree var)
   /* If the variable is internal, or if we can't generate aliases,
      call the local init function directly.  */
   if (!TREE_PUBLIC (var) || !TARGET_SUPPORTS_ALIASES)
-    return get_local_tls_init_fn ();
+    return get_local_tls_init_fn (DECL_SOURCE_LOCATION (var));
 
   tree sname = mangle_tls_init_fn (var);
   tree fn = get_global_binding (sname);
@@ -4431,7 +4431,7 @@ handle_tls_init (void)
   set_decl_tls_model (guard, decl_default_tls_model (guard));
   pushdecl_top_level_and_finish (guard, NULL_TREE);
 
-  tree fn = get_local_tls_init_fn ();
+  tree fn = get_local_tls_init_fn (loc);
   start_preparsed_function (fn, NULL_TREE, SF_PRE_PARSED);
   tree body = begin_function_body ();
   tree if_stmt = begin_if_stmt ();
diff --git a/gcc/testsuite/g++.dg/gcov/pr88263.C b/gcc/testsuite/g++.dg/gcov/pr88263.C
new file mode 100644
index 00000000000..4dc4063fe7e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/gcov/pr88263.C
@@ -0,0 +1,30 @@
+// PR gcov-profile/88045
+// { dg-options "-fprofile-arcs -ftest-coverage -std=c++11" }
+// { dg-do run { target native } }
+
+#include <sstream>
+
+namespace log {
+
+class Logstream {
+public:
+
+private:
+    /// The logging stream
+    static thread_local std::ostringstream os_;
+};
+
+}
+
+namespace log {
+
+thread_local std::ostringstream Logstream::os_;
+
+}
+
+int main()
+{
+  return 0;
+}
+
+// { dg-final { run-gcov pr88263.C } }

Reply via email to