diff mbox series

middle-end: Add another testcase for PR 95493

Message ID 20200616170415.GA1499146@redhat.com
State New
Headers show
Series middle-end: Add another testcase for PR 95493 | expand

Commit Message

Jonathan Wakely June 16, 2020, 5:04 p.m. UTC
This was reported on the gcc-help mailing list. The regression started
with r10-589 and was fixed by r11-963.

gcc/testsuite/ChangeLog:

	* g++.dg/torture/pr95493-1.C: New test.

Tested x86_64-linux. OK for master?
commit 03f6e6bea110994d4e1d49a2469f808082d5bded
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Tue Jun 16 17:57:23 2020 +0100

    middle-end: Add another testcase for PR 95493
    
    This was reported on the gcc-help mailing list. The regression started
    with r10-589 and was fixed by r11-963.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/torture/pr95493-1.C: New test.

Comments

Li, Pan2 via Gcc-patches June 16, 2020, 10:02 p.m. UTC | #1
On Tue, 2020-06-16 at 18:04 +0100, Jonathan Wakely via Gcc-patches wrote:
> This was reported on the gcc-help mailing list. The regression started
> with r10-589 and was fixed by r11-963.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/torture/pr95493-1.C: New test.
> 
> Tested x86_64-linux. OK for master?
OK
jeff
Richard Biener June 17, 2020, 6:05 a.m. UTC | #2
On Tue, 16 Jun 2020, Jonathan Wakely wrote:

> This was reported on the gcc-help mailing list. The regression started
> with r10-589 and was fixed by r11-963.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/torture/pr95493-1.C: New test.
> 
> Tested x86_64-linux. OK for master?

OK.

Richard.
diff mbox series

Patch

diff --git a/gcc/testsuite/g++.dg/torture/pr95493-1.C b/gcc/testsuite/g++.dg/torture/pr95493-1.C
new file mode 100644
index 00000000000..907d191ebfe
--- /dev/null
+++ b/gcc/testsuite/g++.dg/torture/pr95493-1.C
@@ -0,0 +1,95 @@ 
+// { dg-do run { target c++11 } }
+// PR rtl-optimization/95493 comment 8
+
+#include <array>
+#include <iostream>
+
+struct Point
+{
+    std::array<int, 3> array;
+
+    Point(int x, int y, int z) : array{x, y, z} {}
+    
+    Point(const Point & other) : array{other.array} {} // OK if commented
+    //Point(const Point &) = default; // OK
+
+    //Point(Point && other) = default; // OK
+
+    int  operator[] (std::size_t i) const { return array[i]; }
+    int& operator[] (std::size_t i)       { return array[i]; }
+};
+
+//using Point = std::array<int, 3>; // OK
+
+struct Cell
+{
+    Point point;
+    Cell(Point const& pt) : point(pt) {}
+    int   operator[] (std::size_t i) const { return point[i]; }
+    int&  operator[] (std::size_t i)       { return point[i]; }
+};
+
+//using Cell = Point; // OK
+
+std::ostream & operator<< (std::ostream & out, Cell const& object)
+//std::ostream & operator<< (std::ostream & out, Cell object) // Fails with f2 too
+{
+    for ( std::size_t i = 0; i < 3; ++i )
+        out << object[ i ] << " ";
+    return out;
+}
+
+
+struct DirIterator
+{
+    std::size_t dir;
+    Cell cell;
+
+    DirIterator(Cell c)
+        : dir(0), cell(c)
+    {
+        find(); // OK if commented
+    }
+
+    void find()
+    {
+        //while (dir < 3) // Fails with f2 too
+        while (dir < 3 && (cell[dir] % 2) == 0)
+            ++dir;
+    }
+};
+
+Cell uIncident(Cell c, std::size_t k)
+//Cell uIncident(Cell& c, std::size_t k) // OK
+{
+    --c[k];
+    return c;
+}
+
+Cell uSpel(Point p)
+{
+    for (std::size_t i = 0; i < 3; ++i)
+        p[i] += p[i] + 1;
+    return Cell(p);
+}
+
+
+int main ()
+{
+    Cell c = uSpel(Point{0, 0, 0}); // Fails
+    //Cell c( Point(1, 1, 1) ); // OK
+
+    auto q = DirIterator( c );
+
+    Cell f1 = uIncident( c, q.dir ); // Fails
+    //Cell f1 = uIncident( c, 0 ); // OK
+
+    Cell f2 = f1; // f2 is the right cell that f1 should be
+
+    std::cout << "q.dir = " << q.dir << " ; f1 = " << f1 << " ; f2 = " << f2 << std::endl;
+    //std::cout << "q.dir = " << q.dir << " ; f1 = " << f1[0] << " " << f1[1] << " " << f1[2] << " ; f2 = " << f2[0] << " " << f2[1] << " " << f2[2] << std::endl; // OK
+
+    for (int i = 0; i < 3; ++i)
+      if (f1[i] != f2[i])
+        __builtin_abort();
+}