Launchpad has imported 6 comments from the remote bug at
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67707.

If you reply to an imported comment from within Launchpad, your comment
will be sent to the remote bug automatically. Read more about
Launchpad's inter-bugtracker facilities at
https://documentation.ubuntu.com/launchpad/user/reference/bugs/multi-project-bugs/about-multi-project-bugs/#bugs-in-external-trackers.

------------------------------------------------------------------------
On 2015-09-24T09:01:50+00:00 Roland Dreier wrote:

With gcc 5.2 I see a deque with non-is_always_equal allocator get
corrupted state when moved from.  My understanding is that a moved-from
container is in a valid but indeterminate state, and it is OK to assign
to it.  The code below reproduces this for me:

$ cat a.cpp
#include <stdio.h>
#include <utility>
#include <deque>
#include <memory>

template<typename T>
struct my_allocator: public std::allocator<T>
{
        typedef size_t size_type;
        typedef T * pointer;
        typedef const T * const_pointer;

        typedef std::false_type is_always_equal;

        template<typename _Tp1>
        struct rebind
        {
                typedef my_allocator<_Tp1> other;
        };

        pointer allocate(size_type n, const void *hint = nullptr)
        {
                return std::allocator<T>::allocate(n, hint);
        }

        void deallocate(pointer p, size_type n)
        {
                return std::allocator<T>::deallocate(p, n);
        }

        size_type max_size() const
        {
                return std::allocator<T>::max_size();
        }

        my_allocator() : std::allocator<T>() { }
        ~my_allocator() { }

        my_allocator(const my_allocator & a) : std::allocator<T>(a) { }
        template<typename U>
        my_allocator(const my_allocator<U> & a) : std::allocator<T>(a) { }
};

int main(int argc, char * argv[])
{
        std::deque<int, my_allocator<int>> a;

        printf("empty %d size %zd\n", a.empty(), a.size());
        a.emplace_back(1);
        printf("empty %d size %zd\n", a.empty(), a.size());
        std::deque<int, my_allocator<int>> b = std::move(a);
        printf("empty %d size %zd\n", a.empty(), a.size());
        a = std::deque<int, my_allocator<int>>();
        printf("empty %d size %zd\n", a.empty(), a.size());

        return 0;
}


$ g++-5 -v --std=c++11 a.cpp
Using built-in specs.
COLLECT_GCC=g++-5
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/5/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 5.2.1-17ubuntu4' 
--with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs 
--enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr 
--program-suffix=-5 --enable-shared --enable-linker-build-id 
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix 
--libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu 
--enable-libstdcxx-debug --enable-libstdcxx-time=yes 
--with-default-libstdcxx-abi=new --enable-gnu-unique-object 
--disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib 
--disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo 
--with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-amd64/jre --enable-java-home 
--with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-amd64 
--with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-amd64 
--with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar 
--enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 
--with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib 
--with-tune=generic --enable-checking=release --build=x86_64-linux-gnu 
--host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 5.2.1 20150911 (Ubuntu 5.2.1-17ubuntu4) 
COLLECT_GCC_OPTIONS='-v' '-std=c++11' '-shared-libgcc' '-mtune=generic' 
'-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/5/cc1plus -quiet -v -imultiarch x86_64-linux-gnu 
-D_GNU_SOURCE a.cpp -quiet -dumpbase a.cpp -mtune=generic -march=x86-64 
-auxbase a -std=c++11 -version -fstack-protector-strong -Wformat 
-Wformat-security -o /tmp/ccqiuI35.s
GNU C++11 (Ubuntu 5.2.1-17ubuntu4) version 5.2.1 20150911 (x86_64-linux-gnu)
        compiled by GNU C version 5.2.1 20150911, GMP version 6.0.0, MPFR 
version 3.1.3, MPC version 1.0.3
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring duplicate directory "/usr/include/x86_64-linux-gnu/c++/5"
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory 
"/usr/lib/gcc/x86_64-linux-gnu/5/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/5
 /usr/include/x86_64-linux-gnu/c++/5
 /usr/include/c++/5/backward
 /usr/lib/gcc/x86_64-linux-gnu/5/include
 /usr/local/include
 /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
GNU C++11 (Ubuntu 5.2.1-17ubuntu4) version 5.2.1 20150911 (x86_64-linux-gnu)
        compiled by GNU C version 5.2.1 20150911, GMP version 6.0.0, MPFR 
version 3.1.3, MPC version 1.0.3
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 5f8f5aa667996d1fc1f2a670de0c5b24
COLLECT_GCC_OPTIONS='-v' '-std=c++11' '-shared-libgcc' '-mtune=generic' 
'-march=x86-64'
 as -v --64 -o /tmp/cc2UlERW.o /tmp/ccqiuI35.s
GNU assembler version 2.25.1 (x86_64-linux-gnu) using BFD version (GNU Binutils 
for Ubuntu) 2.25.1
COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/5/:/usr/lib/gcc/x86_64-linux-gnu/5/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/5/:/usr/lib/gcc/x86_64-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/5/:/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/5/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-std=c++11' '-shared-libgcc' '-mtune=generic' 
'-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/5/collect2 -plugin 
/usr/lib/gcc/x86_64-linux-gnu/5/liblto_plugin.so 
-plugin-opt=/usr/lib/gcc/x86_64-linux-gnu/5/lto-wrapper 
-plugin-opt=-fresolution=/tmp/cc0395GN.res -plugin-opt=-pass-through=-lgcc_s 
-plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc 
-plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc --sysroot=/ 
--build-id --eh-frame-hdr -m elf_x86_64 --hash-style=gnu --as-needed 
-dynamic-linker /lib64/ld-linux-x86-64.so.2 -z relro 
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crt1.o 
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crti.o 
/usr/lib/gcc/x86_64-linux-gnu/5/crtbegin.o -L/usr/lib/gcc/x86_64-linux-gnu/5 
-L/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu 
-L/usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib -L/lib/x86_64-linux-gnu 
-L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib 
-L/usr/lib/gcc/x86_64-linux-gnu/5/../../.. /tmp/cc2UlERW.o -lstdc++ 
--push-state --as-needed -latomic --pop-state -lm -lgcc_s -lgcc -lc -lgcc_s 
-lgcc /usr/lib/gcc/x86_64-linux-gnu/5/crtend.o 
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crtn.o

$ ./a.out
empty 1 size 0
empty 0 size 1
empty 1 size -128
Segmentation fault (core dumped)


By comparison, gcc 4.9 does what I expect:

$ g++-4.9 -v --std=c++11 a.cpp
Using built-in specs.
COLLECT_GCC=g++-4.9
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.9/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.9.3-4ubuntu1' 
--with-bugurl=file:///usr/share/doc/gcc-4.9/README.Bugs 
--enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr 
--program-suffix=-4.9 --enable-shared --enable-linker-build-id 
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix 
--with-gxx-include-dir=/usr/include/c++/4.9 --libdir=/usr/lib --enable-nls 
--with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug 
--enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-vtable-verify 
--enable-plugin --with-system-zlib --disable-browser-plugin 
--enable-java-awt=gtk --enable-gtk-cairo 
--with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.9-amd64/jre --enable-java-home 
--with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.9-amd64 
--with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.9-amd64 
--with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar 
--enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 
--with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib 
--with-tune=generic --enable-checking=release --build=x86_64-linux-gnu 
--host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.9.3 (Ubuntu 4.9.3-4ubuntu1) 
COLLECT_GCC_OPTIONS='-v' '-std=c++11' '-shared-libgcc' '-mtune=generic' 
'-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/4.9/cc1plus -quiet -v -imultiarch 
x86_64-linux-gnu -D_GNU_SOURCE a.cpp -quiet -dumpbase a.cpp -mtune=generic 
-march=x86-64 -auxbase a -std=c++11 -version -fstack-protector-strong -Wformat 
-Wformat-security -o /tmp/ccHIR4DO.s
GNU C++ (Ubuntu 4.9.3-4ubuntu1) version 4.9.3 (x86_64-linux-gnu)
        compiled by GNU C version 4.9.3, GMP version 6.0.0, MPFR version 3.1.3, 
MPC version 1.0.3
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring duplicate directory "/usr/include/x86_64-linux-gnu/c++/4.9"
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory 
"/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/4.9
 /usr/include/x86_64-linux-gnu/c++/4.9
 /usr/include/c++/4.9/backward
 /usr/lib/gcc/x86_64-linux-gnu/4.9/include
 /usr/local/include
 /usr/lib/gcc/x86_64-linux-gnu/4.9/include-fixed
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
GNU C++ (Ubuntu 4.9.3-4ubuntu1) version 4.9.3 (x86_64-linux-gnu)
        compiled by GNU C version 4.9.3, GMP version 6.0.0, MPFR version 3.1.3, 
MPC version 1.0.3
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: a3254b33421ed13322187046e7455455
COLLECT_GCC_OPTIONS='-v' '-std=c++11' '-shared-libgcc' '-mtune=generic' 
'-march=x86-64'
 as -v --64 -o /tmp/cce6HLF0.o /tmp/ccHIR4DO.s
GNU assembler version 2.25.1 (x86_64-linux-gnu) using BFD version (GNU Binutils 
for Ubuntu) 2.25.1
COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.9/:/usr/lib/gcc/x86_64-linux-gnu/4.9/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.9/:/usr/lib/gcc/x86_64-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.9/:/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-std=c++11' '-shared-libgcc' '-mtune=generic' 
'-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/4.9/collect2 -plugin 
/usr/lib/gcc/x86_64-linux-gnu/4.9/liblto_plugin.so 
-plugin-opt=/usr/lib/gcc/x86_64-linux-gnu/4.9/lto-wrapper 
-plugin-opt=-fresolution=/tmp/cc4WaRIc.res -plugin-opt=-pass-through=-lgcc_s 
-plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc 
-plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc --sysroot=/ 
--build-id --eh-frame-hdr -m elf_x86_64 --hash-style=gnu --as-needed 
-dynamic-linker /lib64/ld-linux-x86-64.so.2 -z relro 
/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu/crt1.o 
/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu/crti.o 
/usr/lib/gcc/x86_64-linux-gnu/4.9/crtbegin.o 
-L/usr/lib/gcc/x86_64-linux-gnu/4.9 
-L/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu 
-L/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../lib -L/lib/x86_64-linux-gnu 
-L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib 
-L/usr/lib/gcc/x86_64-linux-gnu/4.9/../../.. /tmp/cce6HLF0.o -lstdc++ -lm 
-lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/x86_64-linux-gnu/4.9/crtend.o 
/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu/crtn.o

$ ./a.out
empty 1 size 0
empty 0 size 1
empty 1 size 0
empty 1 size 0


Also, removing the custom allocator works OK with gcc 5.2.  It seems the move 
assignment code in the specialization _M_move_assign1(deque&& __x, /* always 
equal: */ false_type) is incorrect somewhere.

Reply at:
https://bugs.launchpad.net/ubuntu/+source/gcc-5/+bug/1499564/comments/0

------------------------------------------------------------------------
On 2015-09-24T09:40:28+00:00 Trippels wrote:

It is a libstc++11 issue. Confirmed.

markus@x4 tmp % clang++ -stdlib=libc++ -std=c++11 a.cpp
markus@x4 tmp % ./a.out
empty 1 size 0
empty 0 size 1
empty 1 size 0
empty 1 size 0
markus@x4 tmp % g++ -fsanitize=undefined --std=c++11 a.cpp
markus@x4 tmp % ./a.out
empty 1 size 0
empty 0 size 1
empty 1 size -128
/usr/lib/gcc/x86_64-pc-linux-gnu/5.2.1/include/g++-v5/bits/stl_deque.h:2162:20: 
runtime error: load of null pointer of type 'int *'

Reply at:
https://bugs.launchpad.net/ubuntu/+source/gcc-5/+bug/1499564/comments/1

------------------------------------------------------------------------
On 2015-09-24T14:42:06+00:00 Redi wrote:

Ugh, I hate allocators.

I probably should have added a completely new std::__cxx11::deque for
gcc-5 with nothrow move and full allocator support, instead of trying to
bolt it on to our existing std::deque.

Testing this fix:

--- a/libstdc++-v3/include/bits/stl_deque.h
+++ b/libstdc++-v3/include/bits/stl_deque.h
@@ -644,6 +644,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
        _Tp_alloc_type __sink __attribute((__unused__)) {std::move(__alloc)};
        // Create an empty map that allocates using the moved-from allocator.
        _Deque_base __empty{__alloc};
+       __empty._M_initialize_map(0);
        // Now safe to modify current allocator and perform non-throwing swaps.
        _Deque_impl __ret{std::move(_M_get_Tp_allocator())};
        _M_impl._M_swap_data(__ret);

Reply at:
https://bugs.launchpad.net/ubuntu/+source/gcc-5/+bug/1499564/comments/2

------------------------------------------------------------------------
On 2015-09-24T15:46:56+00:00 Redi wrote:

Author: redi
Date: Thu Sep 24 15:46:24 2015
New Revision: 228090

URL: https://gcc.gnu.org/viewcvs?rev=228090&root=gcc&view=rev
Log:
Leave moved-from std::deque in a valid state

        PR libstdc++/67707
        * include/bits/stl_deque.h (_Deque_base::_M_move_impl): Initialize
        empty object.
        * testsuite/23_containers/deque/allocator/move.cc: Check moved-from
        deque.

Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/include/bits/stl_deque.h
    trunk/libstdc++-v3/testsuite/23_containers/deque/allocator/move.cc

Reply at:
https://bugs.launchpad.net/ubuntu/+source/gcc-5/+bug/1499564/comments/3

------------------------------------------------------------------------
On 2015-10-02T20:08:43+00:00 Redi wrote:

Author: redi
Date: Fri Oct  2 20:08:11 2015
New Revision: 228420

URL: https://gcc.gnu.org/viewcvs?rev=228420&root=gcc&view=rev
Log:
Backport PR libstdc++/67707 fix from mainline

        PR libstdc++/67707
        * include/bits/stl_deque.h (_Deque_base::_M_move_impl): Initialize
        empty object.
        * testsuite/23_containers/deque/allocator/move.cc: Check moved-from
        deque.
        * testsuite/23_containers/deque/requirements/dr438/assign_neg.cc:
        Adjust dg-error line number.
        * testsuite/23_containers/deque/requirements/dr438/
        constructor_1_neg.cc: Likewise.
        * testsuite/23_containers/deque/requirements/dr438/
        constructor_2_neg.cc: Likewise.
        * testsuite/23_containers/deque/requirements/dr438/insert_neg.cc:
        Likewise.

Modified:
    branches/gcc-5-branch/libstdc++-v3/ChangeLog
    branches/gcc-5-branch/libstdc++-v3/include/bits/stl_deque.h
    
branches/gcc-5-branch/libstdc++-v3/testsuite/23_containers/deque/allocator/move.cc
    
branches/gcc-5-branch/libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/assign_neg.cc
    
branches/gcc-5-branch/libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/constructor_1_neg.cc
    
branches/gcc-5-branch/libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/constructor_2_neg.cc
    
branches/gcc-5-branch/libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/insert_neg.cc

Reply at:
https://bugs.launchpad.net/ubuntu/+source/gcc-5/+bug/1499564/comments/7

------------------------------------------------------------------------
On 2015-10-02T20:13:46+00:00 Redi wrote:

Fixed

Reply at:
https://bugs.launchpad.net/ubuntu/+source/gcc-5/+bug/1499564/comments/8


** Changed in: gcc
       Status: Unknown => Fix Released

** Changed in: gcc
   Importance: Unknown => Medium

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/1499564

Title:
  gcc-5.2.1 miscompiles moved-from deque with private allocator

To manage notifications about this bug go to:
https://bugs.launchpad.net/gcc/+bug/1499564/+subscriptions


-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to