public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ PATCH] Add tests for a const member and a reference member for launder.
@ 2016-10-30 18:53 Ville Voutilainen
  2016-10-31 13:31 ` Jason Merrill
  0 siblings, 1 reply; 4+ messages in thread
From: Ville Voutilainen @ 2016-10-30 18:53 UTC (permalink / raw)
  To: gcc-patches, Jason Merrill

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

So, how about adding these? They should give us regression tests
that make sure launder does the right in in case some optimizations
attempt to reuse const/reference members.

Tested on Linux-x64.

2016-10-30  Ville Voutilainen  <ville.voutilainen@gmail.com>

    Add tests for a const member and a reference member for launder.
    * g++.dg/cpp1z/launder3.C: New.
    * g++.dg/cpp1z/launder4.C: Likewise.

[-- Attachment #2: launder-tests.diff --]
[-- Type: text/plain, Size: 1339 bytes --]

diff --git a/gcc/testsuite/g++.dg/cpp1z/launder3.C b/gcc/testsuite/g++.dg/cpp1z/launder3.C
new file mode 100644
index 0000000..2a2afc5
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/launder3.C
@@ -0,0 +1,38 @@
+// { dg-do run { target c++11 } }
+// { dg-additional-options "-O2" }
+
+#include <cassert>
+
+void *
+operator new (decltype (sizeof (0)), void *p)
+{
+  return p;
+}
+
+namespace std
+{
+  template <typename T>
+  T *
+  launder (T *p)
+  {
+    return __builtin_launder (p);
+  }
+}
+
+struct A
+{
+  const int x;
+};
+
+struct B
+{
+  A a;
+};
+
+int
+main ()
+{
+  B b{{42}};
+  new (&b.a) A{666};
+  assert(std::launder(&b.a)->x == 666);
+}
diff --git a/gcc/testsuite/g++.dg/cpp1z/launder4.C b/gcc/testsuite/g++.dg/cpp1z/launder4.C
new file mode 100644
index 0000000..3a65eb2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/launder4.C
@@ -0,0 +1,40 @@
+// { dg-do run { target c++11 } }
+// { dg-additional-options "-O2" }
+
+#include <cassert>
+
+void *
+operator new (decltype (sizeof (0)), void *p)
+{
+  return p;
+}
+
+namespace std
+{
+  template <typename T>
+  T *
+  launder (T *p)
+  {
+    return __builtin_launder (p);
+  }
+}
+
+struct A
+{
+  int& x;
+};
+
+struct B
+{
+  A a;
+};
+
+int
+main ()
+{
+  int x = 42;
+  B b{{x}};
+  int y = 666;
+  new (&b.a) A{y};
+  assert(std::launder(&b.a)->x == 666);
+}

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

* Re: [C++ PATCH] Add tests for a const member and a reference member for launder.
  2016-10-30 18:53 [C++ PATCH] Add tests for a const member and a reference member for launder Ville Voutilainen
@ 2016-10-31 13:31 ` Jason Merrill
  2016-10-31 16:13   ` Ville Voutilainen
  0 siblings, 1 reply; 4+ messages in thread
From: Jason Merrill @ 2016-10-31 13:31 UTC (permalink / raw)
  To: Ville Voutilainen; +Cc: gcc-patches

On Sun, Oct 30, 2016 at 2:53 PM, Ville Voutilainen
<ville.voutilainen@gmail.com> wrote:
> So, how about adding these? They should give us regression tests
> that make sure launder does the right in in case some optimizations
> attempt to reuse const/reference members.

Good idea.  You might put the reuse in a separate function in order to
hide it from the optimizer.

Jason

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

* Re: [C++ PATCH] Add tests for a const member and a reference member for launder.
  2016-10-31 13:31 ` Jason Merrill
@ 2016-10-31 16:13   ` Ville Voutilainen
  2016-10-31 16:47     ` Jason Merrill
  0 siblings, 1 reply; 4+ messages in thread
From: Ville Voutilainen @ 2016-10-31 16:13 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches

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

On 31 October 2016 at 15:31, Jason Merrill <jason@redhat.com> wrote:
> Good idea.  You might put the reuse in a separate function in order to
> hide it from the optimizer.


Ok, new patch, tested on Linux-x64, ok for trunk?

2016-10-31  Ville Voutilainen  <ville.voutilainen@gmail.com>

    Add tests for a const member and a reference member for launder.
    * g++.dg/cpp1z/launder3.C: New.
    * g++.dg/cpp1z/launder4.C: Likewise.
    * g++.dg/cpp1z/launder5.C: Likewise.
    * g++.dg/cpp1z/launder5.cc: Likewise.
    * g++.dg/cpp1z/launder5.h: Likewise.
    * g++.dg/cpp1z/launder6.C: Likewise.
    * g++.dg/cpp1z/launder6.cc: Likewise.
    * g++.dg/cpp1z/launder6.h: Likewise.

[-- Attachment #2: launder-tests_2.diff --]
[-- Type: text/plain, Size: 3936 bytes --]

diff --git a/gcc/testsuite/g++.dg/cpp1z/launder3.C b/gcc/testsuite/g++.dg/cpp1z/launder3.C
new file mode 100644
index 0000000..2a2afc5
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/launder3.C
@@ -0,0 +1,38 @@
+// { dg-do run { target c++11 } }
+// { dg-additional-options "-O2" }
+
+#include <cassert>
+
+void *
+operator new (decltype (sizeof (0)), void *p)
+{
+  return p;
+}
+
+namespace std
+{
+  template <typename T>
+  T *
+  launder (T *p)
+  {
+    return __builtin_launder (p);
+  }
+}
+
+struct A
+{
+  const int x;
+};
+
+struct B
+{
+  A a;
+};
+
+int
+main ()
+{
+  B b{{42}};
+  new (&b.a) A{666};
+  assert(std::launder(&b.a)->x == 666);
+}
diff --git a/gcc/testsuite/g++.dg/cpp1z/launder4.C b/gcc/testsuite/g++.dg/cpp1z/launder4.C
new file mode 100644
index 0000000..3a65eb2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/launder4.C
@@ -0,0 +1,40 @@
+// { dg-do run { target c++11 } }
+// { dg-additional-options "-O2" }
+
+#include <cassert>
+
+void *
+operator new (decltype (sizeof (0)), void *p)
+{
+  return p;
+}
+
+namespace std
+{
+  template <typename T>
+  T *
+  launder (T *p)
+  {
+    return __builtin_launder (p);
+  }
+}
+
+struct A
+{
+  int& x;
+};
+
+struct B
+{
+  A a;
+};
+
+int
+main ()
+{
+  int x = 42;
+  B b{{x}};
+  int y = 666;
+  new (&b.a) A{y};
+  assert(std::launder(&b.a)->x == 666);
+}
diff --git a/gcc/testsuite/g++.dg/cpp1z/launder5.C b/gcc/testsuite/g++.dg/cpp1z/launder5.C
new file mode 100644
index 0000000..483d6f2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/launder5.C
@@ -0,0 +1,25 @@
+// { dg-do run { target c++11 } }
+// { dg-additional-options "-O2" }
+// { dg-additional-sources "launder5.cc" }
+
+#include <cassert>
+#include "launder5.h"
+
+namespace std
+{
+  template <typename T>
+  T *
+  launder (T *p)
+  {
+    return __builtin_launder (p);
+  }
+}
+
+
+int
+main ()
+{
+  B b{{42}};
+  f(b);
+  assert(std::launder(&b.a)->x == 666);
+}
diff --git a/gcc/testsuite/g++.dg/cpp1z/launder5.cc b/gcc/testsuite/g++.dg/cpp1z/launder5.cc
new file mode 100644
index 0000000..f9d867d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/launder5.cc
@@ -0,0 +1,12 @@
+#include "launder5.h"
+
+void *
+operator new (decltype (sizeof (0)), void *p)
+{
+  return p;
+}
+
+void f(B& b)
+{
+  new (&b.a) A{666};
+}
diff --git a/gcc/testsuite/g++.dg/cpp1z/launder5.h b/gcc/testsuite/g++.dg/cpp1z/launder5.h
new file mode 100644
index 0000000..b66103a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/launder5.h
@@ -0,0 +1,16 @@
+#ifndef GCC_TEST_LAUNDER5_H
+#define GCC_TEST_LAUNDER5_H
+
+struct A
+{
+  const int x;
+};
+
+struct B
+{
+  A a;
+};
+
+void f(B& b);
+
+#endif
diff --git a/gcc/testsuite/g++.dg/cpp1z/launder6.C b/gcc/testsuite/g++.dg/cpp1z/launder6.C
new file mode 100644
index 0000000..babc4b4
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/launder6.C
@@ -0,0 +1,24 @@
+// { dg-do run { target c++11 } }
+// { dg-additional-options "-O2" }
+// { dg-additional-sources "launder6.cc" }
+#include <cassert>
+#include "launder6.h"
+
+namespace std
+{
+  template <typename T>
+  T *
+  launder (T *p)
+  {
+    return __builtin_launder (p);
+  }
+}
+
+int
+main ()
+{
+  int x = 42;
+  B b{{x}};
+  f(b);
+  assert(std::launder(&b.a)->x == 666);
+}
diff --git a/gcc/testsuite/g++.dg/cpp1z/launder6.cc b/gcc/testsuite/g++.dg/cpp1z/launder6.cc
new file mode 100644
index 0000000..1822891
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/launder6.cc
@@ -0,0 +1,14 @@
+#include "launder6.h"
+
+void *
+operator new (decltype (sizeof (0)), void *p)
+{
+  return p;
+}
+
+int y = 666;
+
+void f(B& b)
+{
+  new (&b.a) A{y};
+}
diff --git a/gcc/testsuite/g++.dg/cpp1z/launder6.h b/gcc/testsuite/g++.dg/cpp1z/launder6.h
new file mode 100644
index 0000000..eca2ad4
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/launder6.h
@@ -0,0 +1,16 @@
+#ifndef GCC_TEST_LAUNDER6_H
+#define GCC_TEST_LAUNDER6_H
+
+struct A
+{
+  int& x;
+};
+
+struct B
+{
+  A a;
+};
+
+void f(B& b);
+
+#endif

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

* Re: [C++ PATCH] Add tests for a const member and a reference member for launder.
  2016-10-31 16:13   ` Ville Voutilainen
@ 2016-10-31 16:47     ` Jason Merrill
  0 siblings, 0 replies; 4+ messages in thread
From: Jason Merrill @ 2016-10-31 16:47 UTC (permalink / raw)
  To: Ville Voutilainen; +Cc: gcc-patches

OK, thanks.

On Mon, Oct 31, 2016 at 12:13 PM, Ville Voutilainen
<ville.voutilainen@gmail.com> wrote:
> On 31 October 2016 at 15:31, Jason Merrill <jason@redhat.com> wrote:
>> Good idea.  You might put the reuse in a separate function in order to
>> hide it from the optimizer.
>
>
> Ok, new patch, tested on Linux-x64, ok for trunk?
>
> 2016-10-31  Ville Voutilainen  <ville.voutilainen@gmail.com>
>
>     Add tests for a const member and a reference member for launder.
>     * g++.dg/cpp1z/launder3.C: New.
>     * g++.dg/cpp1z/launder4.C: Likewise.
>     * g++.dg/cpp1z/launder5.C: Likewise.
>     * g++.dg/cpp1z/launder5.cc: Likewise.
>     * g++.dg/cpp1z/launder5.h: Likewise.
>     * g++.dg/cpp1z/launder6.C: Likewise.
>     * g++.dg/cpp1z/launder6.cc: Likewise.
>     * g++.dg/cpp1z/launder6.h: Likewise.

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

end of thread, other threads:[~2016-10-31 16:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-30 18:53 [C++ PATCH] Add tests for a const member and a reference member for launder Ville Voutilainen
2016-10-31 13:31 ` Jason Merrill
2016-10-31 16:13   ` Ville Voutilainen
2016-10-31 16:47     ` 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).