public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Use proper location for tls_init function (PR c++/88263).
@ 2018-11-30 13:32 Martin Liška
  2018-11-30 19:51 ` Jason Merrill
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Martin Liška @ 2018-11-30 13:32 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jason Merrill

[-- Attachment #1: Type: text/plain, Size: 962 bytes --]

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  <mliska@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  <mliska@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



[-- Attachment #2: 0001-Use-proper-location-for-tls_init-function-PR-c-88263.patch --]
[-- Type: text/x-patch, Size: 2211 bytes --]

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 } }


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Use proper location for tls_init function (PR c++/88263).
  2018-11-30 13:32 [PATCH] Use proper location for tls_init function (PR c++/88263) Martin Liška
@ 2018-11-30 19:51 ` Jason Merrill
  2019-01-02 12:41 ` Rainer Orth
  2019-01-14 15:43 ` [PATCH] Fix location of tls_wrapper_fn (PR gcov-profile/88263) Martin Liška
  2 siblings, 0 replies; 6+ messages in thread
From: Jason Merrill @ 2018-11-30 19:51 UTC (permalink / raw)
  To: Martin Liška, gcc-patches

OK.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Use proper location for tls_init function (PR c++/88263).
  2018-11-30 13:32 [PATCH] Use proper location for tls_init function (PR c++/88263) Martin Liška
  2018-11-30 19:51 ` Jason Merrill
@ 2019-01-02 12:41 ` Rainer Orth
  2019-01-02 12:49   ` Martin Liška
  2019-01-14 15:43 ` [PATCH] Fix location of tls_wrapper_fn (PR gcov-profile/88263) Martin Liška
  2 siblings, 1 reply; 6+ messages in thread
From: Rainer Orth @ 2019-01-02 12:41 UTC (permalink / raw)
  To: Martin Liška; +Cc: gcc-patches, Jason Merrill

[-- Attachment #1: Type: text/plain, Size: 2200 bytes --]

Hi Martin,

> 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  <mliska@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  <mliska@suse.cz>
>
> 	* g++.dg/gcov/pr88263.C: New test.

the new testcase FAILs on Solaris:

+FAIL: g++.dg/gcov/pr88263.C   (test for excess errors)

Excess errors:
/vol/gcc/src/hg/trunk/local/gcc/testsuite/g++.dg/gcov/pr88263.C:7:11: error: 'namespace log { }' conflicts with a previous declaration
/vol/gcc/src/hg/trunk/local/gcc/testsuite/g++.dg/gcov/pr88263.C:19:11: error: 'namespace log { }' conflicts with a previous declaration
/vol/gcc/src/hg/trunk/local/gcc/testsuite/g++.dg/gcov/pr88263.C:21:33: error: 'Logstream' has not been declared

/var/gcc/regression/trunk/11.5-gcc/build/gcc/include-fixed/iso/math_iso.h:69:15: note: previous declaration 'namespace std { }::log'

+UNRESOLVED: g++.dg/gcov/pr88263.C   compilation failed to produce executable
+FAIL: g++.dg/gcov/pr88263.C   gcov failed: pr88263.C.gcov does not exist

<iso/math_iso.h> has

namespace std {
extern double log __P((double));
extern "C++" {
	inline float log(float __X) { return __logf(__X); }
	inline long double log(long double __X) { return __logl(__X); }
}
}

Fixed by renaming namespace log to logging to avoid the clash.  Tested
on i386-pc-solaris2.11, sparc-sun-solaris2.11, and x86_64-pc-linux-gnu.
Installed no mainline.

	Rainer

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University


2018-12-28  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

	* g++.dg/gcov/pr88263.C: Rename namespace log to logging.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: sol2-pr88263.patch --]
[-- Type: text/x-patch, Size: 526 bytes --]

# HG changeset patch
# Parent  2f1e3e01d8c86c4908cd3e52bf256667f8ae9bb8
Fix g++.dg/gcov/pr88263.C compilation on Solaris

diff --git a/gcc/testsuite/g++.dg/gcov/pr88263.C b/gcc/testsuite/g++.dg/gcov/pr88263.C
--- a/gcc/testsuite/g++.dg/gcov/pr88263.C
+++ b/gcc/testsuite/g++.dg/gcov/pr88263.C
@@ -4,7 +4,7 @@
 
 #include <sstream>
 
-namespace log {
+namespace logging {
 
 class Logstream {
 public:
@@ -16,7 +16,7 @@ private:
 
 }
 
-namespace log {
+namespace logging {
 
 thread_local std::ostringstream Logstream::os_;
 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Use proper location for tls_init function (PR c++/88263).
  2019-01-02 12:41 ` Rainer Orth
@ 2019-01-02 12:49   ` Martin Liška
  0 siblings, 0 replies; 6+ messages in thread
From: Martin Liška @ 2019-01-02 12:49 UTC (permalink / raw)
  To: Rainer Orth; +Cc: gcc-patches, Jason Merrill

On 1/2/19 1:41 PM, Rainer Orth wrote:
> Hi Martin,
> 
>> 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  <mliska@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  <mliska@suse.cz>
>>
>> 	* g++.dg/gcov/pr88263.C: New test.
> 
> the new testcase FAILs on Solaris:
> 
> +FAIL: g++.dg/gcov/pr88263.C   (test for excess errors)
> 
> Excess errors:
> /vol/gcc/src/hg/trunk/local/gcc/testsuite/g++.dg/gcov/pr88263.C:7:11: error: 'namespace log { }' conflicts with a previous declaration
> /vol/gcc/src/hg/trunk/local/gcc/testsuite/g++.dg/gcov/pr88263.C:19:11: error: 'namespace log { }' conflicts with a previous declaration
> /vol/gcc/src/hg/trunk/local/gcc/testsuite/g++.dg/gcov/pr88263.C:21:33: error: 'Logstream' has not been declared
> 
> /var/gcc/regression/trunk/11.5-gcc/build/gcc/include-fixed/iso/math_iso.h:69:15: note: previous declaration 'namespace std { }::log'
> 
> +UNRESOLVED: g++.dg/gcov/pr88263.C   compilation failed to produce executable
> +FAIL: g++.dg/gcov/pr88263.C   gcov failed: pr88263.C.gcov does not exist
> 
> <iso/math_iso.h> has
> 
> namespace std {
> extern double log __P((double));
> extern "C++" {
> 	inline float log(float __X) { return __logf(__X); }
> 	inline long double log(long double __X) { return __logl(__X); }
> }
> }
> 
> Fixed by renaming namespace log to logging to avoid the clash.  Tested
> on i386-pc-solaris2.11, sparc-sun-solaris2.11, and x86_64-pc-linux-gnu.
> Installed no mainline.

Thanks for the patch.

Martin

> 
> 	Rainer
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] Fix location of tls_wrapper_fn (PR gcov-profile/88263).
  2018-11-30 13:32 [PATCH] Use proper location for tls_init function (PR c++/88263) Martin Liška
  2018-11-30 19:51 ` Jason Merrill
  2019-01-02 12:41 ` Rainer Orth
@ 2019-01-14 15:43 ` Martin Liška
  2019-01-14 16:10   ` Jason Merrill
  2 siblings, 1 reply; 6+ messages in thread
From: Martin Liška @ 2019-01-14 15:43 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jason Merrill

[-- Attachment #1: Type: text/plain, Size: 188 bytes --]

Hi.

This is another fix for the PR where I updated location of
tls_wrapper.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

Ready to be installed?
Thanks,
Martin

[-- Attachment #2: 0001-Fix-location-of-tls_wrapper_fn-PR-gcov-profile-88263.patch --]
[-- Type: text/x-patch, Size: 2073 bytes --]

From 07811d1057196abad898c9aeda08cd9113aedf70 Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Mon, 14 Jan 2019 14:57:01 +0100
Subject: [PATCH] Fix location of tls_wrapper_fn (PR gcov-profile/88263).

gcc/cp/ChangeLog:

2019-01-14  Martin Liska  <mliska@suse.cz>

	PR gcov-profile/88263
	* decl2.c (get_tls_wrapper_fn): Use DECL_SOURCE_LOCATION
	as location of the TLS wrapper.

gcc/testsuite/ChangeLog:

2019-01-14  Martin Liska  <mliska@suse.cz>

	PR gcov-profile/88263
	* g++.dg/gcov/pr88263-2.C: New test.
---
 gcc/cp/decl2.c                        |  4 +++-
 gcc/testsuite/g++.dg/gcov/pr88263-2.C | 25 +++++++++++++++++++++++++
 2 files changed, 28 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/gcov/pr88263-2.C

diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
index dbab95fbc96..9085e5cb154 100644
--- a/gcc/cp/decl2.c
+++ b/gcc/cp/decl2.c
@@ -3433,7 +3433,9 @@ get_tls_wrapper_fn (tree var)
       tree type = non_reference (TREE_TYPE (var));
       type = build_reference_type (type);
       tree fntype = build_function_type (type, void_list_node);
-      fn = build_lang_decl (FUNCTION_DECL, sname, fntype);
+
+      fn = build_lang_decl_loc (DECL_SOURCE_LOCATION (var),
+				FUNCTION_DECL, sname, fntype);
       SET_DECL_LANGUAGE (fn, lang_c);
       TREE_PUBLIC (fn) = TREE_PUBLIC (var);
       DECL_ARTIFICIAL (fn) = true;
diff --git a/gcc/testsuite/g++.dg/gcov/pr88263-2.C b/gcc/testsuite/g++.dg/gcov/pr88263-2.C
new file mode 100644
index 00000000000..f0cf15f5d0a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/gcov/pr88263-2.C
@@ -0,0 +1,25 @@
+// PR gcov-profile/88263
+// { dg-options "-fprofile-arcs -ftest-coverage -std=c++11" }
+// { dg-do run { target native } }
+
+#include <sstream>
+
+namespace logging {
+    class Logstream {
+	~Logstream();
+	static thread_local std::ostringstream os_;
+    };
+}
+namespace logging {
+    thread_local std::ostringstream Logstream::os_;
+    Logstream::~Logstream() {
+	os_.clear();
+    }
+}
+
+int main()
+{
+  return 0;
+}
+
+// { dg-final { run-gcov pr88263-2.C } }
-- 
2.20.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Fix location of tls_wrapper_fn (PR gcov-profile/88263).
  2019-01-14 15:43 ` [PATCH] Fix location of tls_wrapper_fn (PR gcov-profile/88263) Martin Liška
@ 2019-01-14 16:10   ` Jason Merrill
  0 siblings, 0 replies; 6+ messages in thread
From: Jason Merrill @ 2019-01-14 16:10 UTC (permalink / raw)
  To: Martin Liška, gcc-patches

On 1/14/19 10:43 AM, Martin Liška wrote:
> Hi.
> 
> This is another fix for the PR where I updated location of
> tls_wrapper.
> 
> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
> 
> Ready to be installed?

OK.

Jason

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-01-14 16:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-30 13:32 [PATCH] Use proper location for tls_init function (PR c++/88263) Martin Liška
2018-11-30 19:51 ` Jason Merrill
2019-01-02 12:41 ` Rainer Orth
2019-01-02 12:49   ` Martin Liška
2019-01-14 15:43 ` [PATCH] Fix location of tls_wrapper_fn (PR gcov-profile/88263) Martin Liška
2019-01-14 16:10   ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).