On Fri, Dec 20, 2019 at 3:10 PM Richard Biener
<richard.guent...@gmail.com> wrote:
>
> On December 20, 2019 2:13:47 AM GMT+01:00, "Bin.Cheng" 
> <amker.ch...@gmail.com> wrote:
> >On Fri, Dec 13, 2019 at 11:26 AM bin.cheng
> ><bin.ch...@linux.alibaba.com> wrote:
> >>
> >> Hi,
> >>
> >> As reported in PR92926, constant ctor is shared translation unit wide
> >because of constexpr_call_table,
> >> however, during gimplify, the shared ctor could be modified.  This
> >patch fixes the issue by unsharing
> >> it before modification in gimplify.  A test is reduced from cppcoro
> >library and added.
> >>
> >> Bootstrap and test ongoing.  Not sure if this is the correct fix
> >though, any comments?
> >Ping.  Any comment?
>
> Looks reasonable to me.
Given PR92926 is marked as duplicate of PR93143, I updated test case
of the patch.

Thanks,
bin

2019-12-13  Bin Cheng  <bin.li...@linux.alibaba.com>

        PR tree-optimization/93143
        * gimplify.c (gimplify_init_constructor): Unshare ctor node before
        clearing.

gcc/testsuite
2019-12-13  Bin Cheng  <bin.li...@linux.alibaba.com>

        PR tree-optimization/93143
        * g++.dg/pr93143.C: New test.
From 77252c3bb41887af1daa9e83615a8aa32dc330f9 Mon Sep 17 00:00:00 2001
From: "bin.cheng" <chengbin.cb@alibaba-inc.com>
Date: Thu, 9 Jan 2020 14:13:08 +0800
Subject: [PATCH] Fix pr93143.

---
 gcc/gimplify.c                 |  2 ++
 gcc/testsuite/g++.dg/pr93143.C | 73 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 75 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/pr93143.C

diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index 73fb2e7..55d7a93 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -5083,6 +5083,8 @@ gimplify_init_constructor (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p,
 	    /* Zap the CONSTRUCTOR element list, which simplifies this case.
 	       Note that we still have to gimplify, in order to handle the
 	       case of variable sized types.  Avoid shared tree structures.  */
+	    ctor = unshare_expr (ctor);
+	    TREE_OPERAND (*expr_p, 1) = ctor;
 	    CONSTRUCTOR_ELTS (ctor) = NULL;
 	    TREE_SIDE_EFFECTS (ctor) = 0;
 	    object = unshare_expr (object);
diff --git a/gcc/testsuite/g++.dg/pr93143.C b/gcc/testsuite/g++.dg/pr93143.C
new file mode 100644
index 0000000..40710cf
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr93143.C
@@ -0,0 +1,73 @@
+// { dg-do run }
+// { dg-options "-O3 -std=c++14" }
+
+struct array
+{
+    constexpr unsigned char operator[](int i) const noexcept
+    {
+        return arr[i];
+    }
+
+    unsigned char arr[16];
+};
+
+
+class v6 {
+public:
+    using bytes_type = array;
+    constexpr v6(bytes_type const & bytes);
+    constexpr bool is_loopback() const noexcept;
+    static constexpr v6 loopback() noexcept
+    {
+        return v6(v6::bytes_type{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1});
+    }
+private:
+    bytes_type bytes_;
+};
+
+
+
+constexpr v6::v6(bytes_type const & bytes)
+    : bytes_(bytes)
+{}
+
+constexpr
+bool v6::is_loopback() const noexcept
+{
+    return bytes_[0] == 0 &&
+        bytes_[1] == 0 &&
+        bytes_[2] == 0 &&
+        bytes_[3] == 0 &&
+        bytes_[4] == 0 &&
+        bytes_[5] == 0 &&
+        bytes_[6] == 0 &&
+        bytes_[7] == 0 &&
+        bytes_[8] == 0 &&
+        bytes_[9] == 0 &&
+        bytes_[10] == 0 &&
+        bytes_[11] == 0 &&
+        bytes_[12] == 0 &&
+        bytes_[13] == 0 &&
+        bytes_[14] == 0 &&
+        bytes_[15] == 1;
+}
+
+void v6_type()
+{
+    [[maybe_unused]] constexpr auto loopback = v6::loopback();
+}
+
+int main()
+{
+    v6_type();
+
+    constexpr auto a = v6::loopback();
+    if (!a.is_loopback())
+        __builtin_abort();
+
+    auto b = v6::loopback();
+    if (!b.is_loopback())
+        __builtin_abort();
+
+    return 0;
+}
-- 
1.8.3.1

Reply via email to