Repository: opencv
Issue: imgwrap from master branch makes clang 391 segfaults
Labels: bug,category: build/install

<!--
If you have a question rather than reporting a bug please go to http://answers.opencv.org where you get much faster responses.
If you need further assistance please read [How To Contribute](https://github.com/opencv/opencv/wiki/How_to_contribute).

This is a template helping you to create an issue which can be processed as quickly as possible. This is the bug reporting section for the OpenCV library.
-->

##### System information (version)
<!-- Example
- OpenCV => 3.1
- Operating System / Platform => Windows 64 Bit
- Compiler => Visual Studio 2015
-->

- OpenCV => 3.x
- Operating System / Platform => debian 6
- Compiler => clang 391 x64

##### Detailed description
Building opencv git master makes clang 391 debian 6 x64 segfaults with following stack trace.
Attached resulting imgwrap sources files in txt file.

````
[3/177] Building CXX object modules/imgproc/CMakeFiles/opencv_imgproc.dir/src/imgwarp.cpp.o
FAILED: modules/imgproc/CMakeFiles/opencv_imgproc.dir/src/imgwarp.cpp.o
/home/userbuild/clangroot/bin/clang++  -DCVAPI_EXPORTS -D__OPENCV_BUILD=1 -I. -I../modules/imgproc/include -I../modules/imgproc/src -Imodules/imgproc -I../modules/core/include -stdlib=libc++   -fsigned-char -W -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -fdiagnostics-show-option -Wno-long-long -pthread -Qunused-arguments -fno-omit-frame-pointer -msse -msse2 -mno-avx -msse3 -mno-ssse3 -mno-sse4.1 -mno-sse4.2 -ffunction-sections -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG -fPIC -MD -MT modules/imgproc/CMakeFiles/opencv_imgproc.dir/src/imgwarp.cpp.o -MF modules/imgproc/CMakeFiles/opencv_imgproc.dir/src/imgwarp.cpp.o.d -o modules/imgproc/CMakeFiles/opencv_imgproc.dir/src/imgwarp.cpp.o -c /home/userbuild/somelibs/opencv-master/modules/imgproc/src/imgwarp.cpp
#0 0x00000000011fa6c5 llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/home/userbuild/clangroot/bin/clang-3.9+0x11fa6c5)
#1 0x00000000011fac56 SignalHandler(int) (/home/userbuild/clangroot/bin/clang-3.9+0x11fac56)
#2 0x00007ffdcd2b9ff0 __restore_rt (/lib/libpthread.so.0+0xeff0)
#3 0x00000000011bc764 llvm::FoldingSetImpl::RemoveNode(llvm::FoldingSetImpl::Node*) (/home/userbuild/clangroot/bin/clang-3.9+0x11bc764)
#4 0x000000000179cec2 llvm::SelectionDAG::RemoveNodeFromCSEMaps(llvm::SDNode*) (/home/userbuild/clangroot/bin/clang-3.9+0x179cec2)
#5 0x00000000017bfaff llvm::SelectionDAG::MorphNodeTo(llvm::SDNode*, unsigned int, llvm::SDVTList, llvm::ArrayRef<llvm::SDValue>) (/home/userbuild/clangroot/bin/clang-3.9+0x17bfaff)
#6 0x00000000017d3776 llvm::SelectionDAGISel::MorphNode(llvm::SDNode*, unsigned int, llvm::SDVTList, llvm::ArrayRef<llvm::SDValue>, unsigned int) (/home/userbuild/clangroot/bin/clang-3.9+0x17d3776)
#7 0x00000000017d5eae llvm::SelectionDAGISel::SelectCodeCommon(llvm::SDNode*, unsigned char const*, unsigned int) (/home/userbuild/clangroot/bin/clang-3.9+0x17d5eae)
#8 0x0000000000a7ccec (anonymous namespace)::X86DAGToDAGISel::Select(llvm::SDNode*) (/home/userbuild/clangroot/bin/clang-3.9+0xa7ccec)
#9 0x00000000017d059c llvm::SelectionDAGISel::DoInstructionSelection() (/home/userbuild/clangroot/bin/clang-3.9+0x17d059c)
#10 0x00000000017cfd98 llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/home/userbuild/clangroot/bin/clang-3.9+0x17cfd98)
#11 0x00000000017cf82f llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/home/userbuild/clangroot/bin/clang-3.9+0x17cf82f)
#12 0x00000000017cd1dc llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/home/userbuild/clangroot/bin/clang-3.9+0x17cd1dc)
#13 0x0000000000a783f1 (anonymous namespace)::X86DAGToDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/home/userbuild/clangroot/bin/clang-3.9+0xa783f1)
#14 0x0000000000d1ea3b llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/home/userbuild/clangroot/bin/clang-3.9+0xd1ea3b)
#15 0x0000000000eff4bf llvm::FPPassManager::runOnFunction(llvm::Function&) (/home/userbuild/clangroot/bin/clang-3.9+0xeff4bf)
#16 0x0000000000eff6ab llvm::FPPassManager::runOnModule(llvm::Module&) (/home/userbuild/clangroot/bin/clang-3.9+0xeff6ab)
#17 0x0000000000effb21 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/home/userbuild/clangroot/bin/clang-3.9+0xeffb21)
#18 0x0000000001317956 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::DataLayout const&, llvm::Module*, clang::BackendAction, std::__1::unique_ptr<llvm::raw_pwrite_stream, std::__1::default_delete<llvm::raw_pwrite_stream> >) (/home/userbuild/clangroot/bin/clang-3.9+0x1317956)
#19 0x00000000018698b7 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/home/userbuild/clangroot/bin/clang-3.9+0x18698b7)
#20 0x0000000001ba0a26 clang::ParseAST(clang::Sema&, bool, bool) (/home/userbuild/clangroot/bin/clang-3.9+0x1ba0a26)
#21 0x00000000015ec45d clang::FrontendAction::Execute() (/home/userbuild/clangroot/bin/clang-3.9+0x15ec45d)
#22 0x00000000015bd1b8 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/userbuild/clangroot/bin/clang-3.9+0x15bd1b8)
#23 0x000000000165e002 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/userbuild/clangroot/bin/clang-3.9+0x165e002)
#24 0x00000000007630d8 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/userbuild/clangroot/bin/clang-3.9+0x7630d8)
#25 0x0000000000761de6 main (/home/userbuild/clangroot/bin/clang-3.9+0x761de6)
#26 0x00007ffdcc8b8c8d __libc_start_main /home/aurel32/eglibc/eglibc-2.11.3/csu/libc-start.c:260:0
#27 0x000000000075f621 _start (/home/userbuild/clangroot/bin/clang-3.9+0x75f621)
Stack dump:
0.      Program arguments: /home/userbuild/clangroot/bin/clang-3.9 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -disable-free -disable-llvm-verifier -discard-value-names -main-file-name imgwarp.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -target-feature +sse -target-feature +sse2 -target-feature -avx -target-feature +sse3 -target-feature -ssse3 -target-feature -sse4.1 -target-feature -sse4.2 -momit-leaf-frame-pointer -dwarf-column-info -debugger-tuning=gdb -ffunction-sections -coverage-file /home/userbuild/somelibs/opencv-master/b1/modules/imgproc/CMakeFiles/opencv_imgproc.dir/src/imgwarp.cpp.o -resource-dir /home/userbuild/clangroot/bin/../lib/clang/3.9.1 -dependency-file modules/imgproc/CMakeFiles/opencv_imgproc.dir/src/imgwarp.cpp.o.d -sys-header-deps -MT modules/imgproc/CMakeFiles/opencv_imgproc.dir/src/imgwarp.cpp.o -D CVAPI_EXPORTS -D __OPENCV_BUILD=1 -I . -I ../modules/imgproc/include -I ../modules/imgproc/src -I modules/imgproc -I ../modules/core/include -D NDEBUG -D NDEBUG -internal-isystem /home/userbuild/clangroot/bin/../include/c++/v1 -internal-isystem /usr/local/include -internal-isystem /home/userbuild/clangroot/bin/../lib/clang/3.9.1/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O3 -W -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-long-long -fdeprecated-macro -fdebug-compilation-dir /home/userbuild/somelibs/opencv-master/b1 -ferror-limit 19 -fmessage-length 0 -fvisibility hidden -fvisibility-inlines-hidden -pthread -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -vectorize-loops -vectorize-slp -o modules/imgproc/CMakeFiles/opencv_imgproc.dir/src/imgwarp.cpp.o -x c++ /home/userbuild/somelibs/opencv-master/modules/imgproc/src/imgwarp.cpp
1.      <eof> parser at end of file
2.      Code generation
3.      Running pass 'Function Pass Manager' on module '/home/userbuild/somelibs/opencv-master/modules/imgproc/src/imgwarp.cpp'.
4.      Running pass 'X86 DAG->DAG Instruction Selection' on function '@_ZN2cvL13remapBilinearINS_4CastIffEENS_10RemapNoVecEfEEvRKNS_3MatERS4_S6_S6_PKviRKNS_7Scalar_IdEE'
clang-3.9: error: unable to execute command: Segmentation fault
clang-3.9: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 3.9.1 (tags/RELEASE_391/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/userbuild/clangroot/bin
clang-3.9: note: diagnostic msg: PLEASE submit a bug report to  and include the crash backtrace, preprocessed source, and associated run script.
clang-3.9: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-3.9: note: diagnostic msg: /tmp/imgwarp-e39ddc.cpp
clang-3.9: note: diagnostic msg: /tmp/imgwarp-e39ddc.sh
clang-3.9: note: diagnostic msg:

********************
[4/177] Building CXX object modules/imgproc/CMakeFiles/opencv_imgproc.dir/src/connectedcomponents.cpp.o
ninja: build stopped: subcommand failed.
````

<!-- your description -->

##### Steps to reproduce

build opencv using cmake,
```
cmake -DBUILD_PNG=ON -DBUILD_JPEG=ON \


-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_CXX_FLAGS="-stdlib=libc++" -DCMAKE_SHARED_LINKER_FLAGS="-stdlib=libc++" /somedir/opencvrootsrc
```






[imgwarp-e39ddc.sh.txt](https://github.com/opencv/opencv/files/705847/imgwarp-e39ddc.sh.txt)
[imgwarp-e39ddc.cpp.txt](https://github.com/opencv/opencv/files/705849/imgwarp-e39ddc.cpp.txt)