Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

_LIBCPP_DEBUG=1 std::transform in-place: abort() (Attempted to dereference a non-dereferenceable iterator) #40244

Open Quuxplusone opened 5 years ago

Quuxplusone commented 5 years ago
Bugzilla Link PR41274
Status NEW
Importance P normal
Reported by Andreas Schulz (andi.schulz@me.com)
Reported on 2019-03-28 07:17:54 -0700
Last modified on 2019-03-29 08:24:39 -0700
Version 8.0
Hardware PC MacOS X
CC dblaikie@gmail.com, llvm-bugs@lists.llvm.org, mclow.lists@gmail.com
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
When using std::transform on a copy-initialized std::string to transform it in-
place, compiling the program with -D_LIBCPP_DEBUG=1 makes the iterator checks
at runtime fail. When compiling without the debug flag, the program works both
optimized and unoptimized as expected. I'm using the LLVM 8.0.0 release build
on macOS, installed to /usr/local/opt/llvm.

Example program:

#include <algorithm>
#include <iostream>

int main(int argc, char *argv[]) {
    std::string source = "hello";

    std::string the_copy = source;

    std::transform(source.begin(), source.end(), source.begin(), [](unsigned char c) -> unsigned char {
        return std::toupper(c);
    });

    std::cout << "transformed source: " << source << "\n\n";

    std::transform(the_copy.begin(), the_copy.end(), the_copy.begin(), [](unsigned char c) -> unsigned char {
        return std::toupper(c);
    });

    std::cout << "transformed copy: " << the_copy << "\n\n";
}

Compile command:

/usr/local/opt/llvm/bin/clang++ main.cpp -o main -D_LIBCPP_DEBUG=1 -g -isysroot
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk
/usr/local/opt/llvm/lib/libc++.a -lc++abi -nodefaultlibs -lSystem -std=c++17

Output:

transformed source: HELLO

/usr/local/opt/llvm/bin/../include/c++/v1/iterator:1372: _LIBCPP_ASSERT
'__get_const_db()->__dereferenceable(this)' failed. Attempted to dereference a
non-dereferenceable iterator
[1]    32560 abort      ./main
Quuxplusone commented 5 years ago

I just tried this with ToT clang/libc++, and got no errors.

Quuxplusone commented 5 years ago
Hm, I've just built the current trunk (357241), but the error still occurs:

/usr/local/opt/llvm-trunk/bin/clang++ main.cpp -o main -D_LIBCPP_DEBUG=1 -g -
isysroot
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk
/usr/local/opt/llvm-trunk/lib/libc++.a -lc++abi -nodefaultlibs -lSystem -
std=c++17 -v && ./main

clang version 9.0.0 (trunk 357241)
Target: x86_64-apple-darwin18.5.0
Thread model: posix
InstalledDir: /usr/local/opt/llvm-trunk/bin
 "/usr/local/opt/llvm-trunk/bin/clang-9" -cc1 -triple x86_64-apple-macosx10.14.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name main.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -masm-verbose -munwind-tables -target-sdk-version=10.14 -target-cpu penryn -dwarf-column-info -debug-info-kind=standalone -dwarf-version=4 -debugger-tuning=lldb -ggnu-pubnames -target-linker-version 450.3 -v -resource-dir /usr/local/opt/llvm-trunk/lib/clang/9.0.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -D _LIBCPP_DEBUG=1 -stdlib=libc++ -internal-isystem /usr/local/opt/llvm-trunk/bin/../include/c++/v1 -std=c++17 -fdeprecated-macro -fdebug-compilation-dir /Users/aschulz/Desktop -ferror-limit 19 -fmessage-length 204 -stack-protector 1 -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fobjc-runtime=macosx-10.14.0 -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/fh/hy204nsd0flg5prp8w2p66tnt23r80/T/main-cd5263.o -x c++ main.cpp
clang -cc1 version 9.0.0 based upon LLVM 9.0.0svn default target x86_64-apple-
darwin18.5.0
ignoring nonexistent directory
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/c++/v1"
ignoring nonexistent directory
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/local/include"
ignoring nonexistent directory
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/opt/llvm-trunk/bin/../include/c++/v1
 /usr/local/opt/llvm-trunk/lib/clang/9.0.0/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks (framework directory)
End of search list.
 "/usr/bin/ld" -demangle -lto_library /usr/local/opt/llvm-trunk/lib/libLTO.dylib -no_deduplicate -dynamic -arch x86_64 -macosx_version_min 10.14.0 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -o main /var/folders/fh/hy204nsd0flg5prp8w2p66tnt23r80/T/main-cd5263.o /usr/local/opt/llvm-trunk/lib/libc++.a -lc++abi -lSystem
 "/usr/local/opt/llvm-trunk/bin/dsymutil" -o main.dSYM main

transformed source: HELLO

/usr/local/opt/llvm-trunk/bin/../include/c++/v1/iterator:1383: _LIBCPP_ASSERT
'__get_const_db()->__dereferenceable(this)' failed. Attempted to dereference a
non-dereferenceable iterator
[1]    98640 abort      ./main
Quuxplusone commented 5 years ago

Ok, that's very odd. Mine definitely doss NOT.

I even threw in a return *the_copy.end() to check, and got a "Attempted to dereference a non-dereferenceable iterator" from that.

I will investigate further.