xavierd / clang_complete

Vim plugin that use clang for completing C/C++ code.
http://www.vim.org/scripts/script.php?script_id=3302
1.96k stars 308 forks source link

Vim crashes with neocomplcache #230

Closed tetsutan closed 11 years ago

tetsutan commented 11 years ago

When I set g:clang_use_library = 0, Vim was not crashed. But, changed to g:clang_use_library = 1, crashed. In either case, I used neocomplcache.

this is GDB log.

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000008
0x0000000100017b3b in ins_compl_next (allow_get_expansion=1606383760, count=1606383760, insert_match=1606383760) at edit.c:4460
4460            else if (compl_shows_dir == BACKWARD  

and then , _compl_showsdir pointer was 0x00. backtrace is here. https://gist.github.com/4513231

this is My MINIMUM vimrc


" vundle
set nocompatible
filetype off

set rtp+=~/.vim/neobundle.vim.git

if has('vim_starting')
  set runtimepath+=~/.vim/neobundle.vim.git
  call neobundle#rc(expand('~/.vim/bundle/'))
endif

NeoBundle 'Shougo/neocomplcache'
NeoBundle 'Rip-Rip/clang_complete'

filetype on
filetype indent on
filetype plugin on

" neocomplcache
let g:neocomplcache_enable_at_startup = 1

" force omni
if !exists('g:neocomplcache_force_omni_patterns')
  let g:neocomplcache_force_omni_patterns = {}
endif
let g:neocomplcache_force_overwrite_completefunc = 1
let g:neocomplcache_force_omni_patterns.c =
      \ '[^.[:digit:] *\t]\%(\.\|->\)'
let g:neocomplcache_force_omni_patterns.cpp =
      \ '[^.[:digit:] *\t]\%(\.\|->\)\|\h\w*::'
let g:neocomplcache_force_omni_patterns.objc =
      \ '[^.[:digit:] *\t]\%(\.\|->\)'
let g:neocomplcache_force_omni_patterns.objcpp =
      \ '[^.[:digit:] *\t]\%(\.\|->\)\|\h\w*::'

" clang
" let g:clang_path = "clang++"
let g:clang_complete_auto = 0
let g:clang_auto_select = 0
let g:clang_use_library = 1
" let g:clang_library_path = "/usr/lib"
" let g:clang_complete_copen = 0
" let g:clang_user_options='|| exit 0'
" let g:clang_close_preview=1

Vim: (and compiled from source code to use with gdb)

VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Jan 10 2013 10:17:24)
MacOS X (unix) version
Included patches: 1-762
Compiled by yano@masck.local
Huge version without GUI.  Features included (+) or not (-):
+arabic +autocmd -balloon_eval -browse ++builtin_terms +byte_offset +cindent 
-clientserver +clipboard +cmdline_compl +cmdline_hist +cmdline_info +comments 
+conceal +cryptv +cscope +cursorbind +cursorshape +dialog_con +diff +digraphs 
-dnd -ebcdic +emacs_tags +eval +ex_extra +extra_search +farsi +file_in_path 
+find_in_path +float +folding -footer +fork() -gettext -hangul_input +iconv 
+insert_expand +jumplist +keymap +langmap +libcall +linebreak +lispindent 
+listcmds +localmap -lua +menu +mksession +modify_fname +mouse -mouseshape 
+mouse_dec -mouse_gpm -mouse_jsbterm +mouse_netterm +mouse_sgr -mouse_sysmouse 
+mouse_urxvt +mouse_xterm +multi_byte +multi_lang -mzscheme +netbeans_intg 
+path_extra -perl +persistent_undo +postscript +printer +profile +python 
-python3 +quickfix +reltime +rightleft +ruby +scrollbind +signs +smartindent 
-sniff +startuptime +statusline -sun_workshop +syntax +tag_binary 
+tag_old_static -tag_any_white -tcl +terminfo +termresponse +textobjects +title
 -toolbar +user_commands +vertsplit +virtualedit +visual +visualextra +viminfo 
+vreplace +wildignore +wildmenu +windows +writebackup -X11 -xfontset -xim -xsmp
 -xterm_clipboard -xterm_save 
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
      user exrc file: "$HOME/.exrc"
  fall-back for $VIM: "/usr/local/share/vim"
Compilation: /usr/bin/clang -c -I. -Iproto -DHAVE_CONFIG_H   -DMACOS_X_UNIX -no-cpp-precomp  -Os -w -pipe -march=native -Qunused-arguments -mmacosx-version-min=10.8 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1      
Linking: /usr/bin/clang   -L.    -L/usr/local/lib -o vim       -lm  -lncurses -liconv -framework Cocoa     -framework Python   -lruby -lobjc  

clang:

Apple clang version 4.1 (tags/Apple/clang-421.11.66) (based on LLVM 3.1svn)
Target: x86_64-apple-darwin12.2.1
Thread model: posix

OS: MacOS 10.8.2 Mountain Lion. neocomplcache: d62b955 2013-01-07 clang_complete: ef3ddfd 2012-11-20

xavierd commented 11 years ago

Could you try without neocomplcache? (In fact with only clang_complete plugin) Thanks!

tetsutan commented 11 years ago

Without neocomplcache, It shows no error.

On filetype=c file, regardless of using neocomplcache, it have no error and display completions.

On filetype=objc file and import headers of Xcode(e.g. .clang_complete includes "-I /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.0.sdk/usr/include"), Regardless of using neocomplcache (,and regardless of using libclang), It display NO completions.

Crash when ・filetype=objc ・import headers of Xcode ・g:clang_use_library = 1 ・use neocomplcache

No Completion when ・filetype=objc ・import headers of Xcode ・(g:clang_use_library = 1 / 0) ・(with/without neocomplcache)

xavierd commented 11 years ago

When you say "It display NO completions", did you try using ? (It may sound a stupid question, but I want to be sure).

tetsutan commented 11 years ago

I create Xcode project named "first".

yano@masck.local [~/dev/xcode/first/first] [master *]
-> % ls                                                                                                                                                         [05:26:58] .rb system .py 2.7.3 .js v0.8.16
AppDelegate.h          DetailViewController.h MasterViewController.h en.lproj               first-Prefix.pch
AppDelegate.m          DetailViewController.m MasterViewController.m first-Info.plist       main.m
yano@masck.local [~/dev/xcode/first/first] [master *]
-> % cat .clang_complete                                                                                                                                        [05:26:59] .rb system .py 2.7.3 .js v0.8.16
 -I /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.0.sdk/usr/include

 yano@masck.local [~] 
-> % cat .vimrc                                                                                                                                                 [05:34:33] .rb system .py 2.7.3 .js v0.8.16

" vundle
set nocompatible
filetype off

set rtp+=~/.vim/neobundle.vim.git

if has('vim_starting')
  set runtimepath+=~/.vim/neobundle.vim.git
  call neobundle#rc(expand('~/.vim/bundle/'))
endif

NeoBundle 'Shougo/neocomplcache'
NeoBundle 'Rip-Rip/clang_complete'

filetype on
filetype indent on
filetype plugin on

" neocomplcache
let g:neocomplcache_enable_at_startup = 1
" ignore case
let g:neocomplcache_enable_ignore_case = 1
" 大文字小文字を区別する
let g:neocomplcache_enable_smart_case = 1
" キャメルケース補完を有効にする
"let g:neocomplcache_enable_camel_case_completion = 1
" アンダーバー補完を有効にする
let g:neocomplcache_enable_underbar_completion = 1

" force omni
if !exists('g:neocomplcache_force_omni_patterns')
  let g:neocomplcache_force_omni_patterns = {}
endif
let g:neocomplcache_force_overwrite_completefunc = 1
let g:neocomplcache_force_omni_patterns.c =
      \ '[^.[:digit:] *\t]\%(\.\|->\)'
let g:neocomplcache_force_omni_patterns.cpp =
      \ '[^.[:digit:] *\t]\%(\.\|->\)\|\h\w*::'
let g:neocomplcache_force_omni_patterns.objc =
      \ '[^.[:digit:] *\t]\%(\.\|->\)'
let g:neocomplcache_force_omni_patterns.objcpp =
      \ '[^.[:digit:] *\t]\%(\.\|->\)\|\h\w*::'

" clang
let g:clang_complete_auto = 0
let g:clang_auto_select = 0
let g:clang_use_library = 1
" let g:clang_library_path = "/usr/lib"
" let g:clang_complete_copen = 0
" let g:clang_user_options='|| exit 0'
" let g:clang_close_preview=1
" let g:clang_user_options = ' -fblocks -fobjc-arc -D__IPHONE_OS_VERSION_MIN_REQUIRED=40300 -F/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.0.sdk/System/Library/Frameworks -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.0.sdk/usr/include -std=c++11 -include=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.0.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/CoreAudioTypes.h '
let g:clang_user_options = '-std=c++11'

vim crash when open MasterViewController.m and execute ^X^U.

vim does not crash when I create new file (test.cpp) on same directory and execute ^X^U. neocomplcache_enable_at_startup is true, therefore completion is showed automatically on test.cpp. but ^X^U is hooked.

xavierd commented 11 years ago

Thanks for those infos. If you have some time could you try bisecting it? That would help us finding a fix quickly!

xavierd commented 11 years ago

Before doing that, could you test the code in pull request #239, it may solve the issue.

tetsutan commented 11 years ago

Sorry. NO completion is my mistake. g:neocomplcache_force_omni_patterns.objc was wrong.

but segv still occur, when I press ^X^U.

line at 328 on libclang.py, vim.eval('compelte_check()') got segv

this bug may owe vim. The cause is compl_shown_match is NULL on edit.c of vim. libclang.py call vim.eval('complete_check()'). complete_check call ins_compl_check_keys. ins_compl_check_keys call ins_compl_next. ins_compl_next refer to compl_shown_match.

Meanwhile, it is not checked whether compl_shown_match is NULL. I do not know that compl_shown_match must be set. I cannot determine that this is Vim issue or clang_complete issue or neocomplcache issue. Neocomplcache may reset compl_shown_match. If resetting compl_shown_match by neocomplcache is wrong way, I will report to an auther of neocomplcache.

xavierd commented 11 years ago

Since you have access to the backtrace, it would be great if you could fully trace it into clang_complete and neocompletecache. I'm in fact worried about a comment in complete_check documentation that say: "Only to be used by the function specified with the 'completefunc' option."

tetsutan commented 11 years ago

Thanks a lot.

239 solved this bug completely.

this does not seem to come into conflict with neocomplcache.

xavierd commented 11 years ago

Great! Closing this bug.