[Bug tree-optimization/34048] [4.3 Regression]: Revision 130040 miscompiles 450.soplex

bonzini at gnu dot org gcc-bugzilla@gcc.gnu.org
Sun Nov 11 07:16:00 GMT 2007



------- Comment #14 from bonzini at gnu dot org  2007-11-11 07:16 -------
It could also be possible to do something like this to avoid default
construction.

@@ -46,8 +46,8 @@ namespace soplex
 class UnitVector : public SVector
 {
 private:
-   Element themem;  ///< memory for 1st sparse vector entry (size)
-   Element themem1; ///< memory for 2nd sparse vector entry (idx,1.0)
+   char themem[sizeof(Element[2])];  ///< memory for 1st sparse vector entry
(size)
+   /*Element themem1;*/ ///< memory for 2nd sparse vector entry (idx,1.0)

 public:
    /// returns value = 1
@@ -62,23 +62,22 @@ public:

    /// construct \c i 'th unit vector.
    UnitVector(int i = 0)
-      : SVector(2, &themem)
+      : SVector(2, reinterpret_cast<Element *> (themem))
    {
-      add(i, 1.0);
+      new(themem[0]) Element (); new (themem[sizeof (Element)]) Element ();
add(i, 1.0);
    }

    ///  copy constructor
    UnitVector(const UnitVector& rhs)
-      : SVector(2, &themem)
-      , themem (rhs.themem)
-      , themem1(rhs.themem1)
-   {}
+      : SVector(2, reinterpret_cast<Element *> (themem))
+   { new(themem[0]) Element (reinterpret_cast<Element *> (rhs.themem[0]));
+     new(themem[sizeof (Element)]) Element (reinterpret_cast<Element *>
(rhs.themem[sizeof (Element)]));  }

    /// assignment
    UnitVector& operator=(const UnitVector& rhs)
    {
       if ( this != &rhs )
-         themem1 = rhs.themem1;
+         new(themem[sizeof (Element)]) Element (reinterpret_cast<Element *>
(rhs.themem[sizeof (Element)]));
       return *this;
    }


Not the cleanest possible code, but I doubt SPEC will like to introduce a
src.alt that makes previous reports not comparable with the new ones.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34048



More information about the Gcc-bugs mailing list