[llvm-bugs] [Bug 47851] New: Crash in Lexer when doing code completion

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Oct 15 01:24:54 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=47851

            Bug ID: 47851
           Summary: Crash in Lexer when doing code completion
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Core LLVM classes
          Assignee: unassignedbugs at nondot.org
          Reporter: christian.kandeler at qt.io
                CC: llvm-bugs at lists.llvm.org

Created attachment 24063
  --> https://bugs.llvm.org/attachment.cgi?id=24063&action=edit
example source file

Consider this simple piece of source code:

#define MY_MACRO() 0
#if MY_MACRO(

If you try to complete at the very end, you get a lexer crash:

$ clang++ -cc1 -xc -fsyntax-only -code-completion-at crash.cpp:2:14 crash.cpp
Stack dump:
0.      Program arguments: /usr/bin/clang++ -cc1 -xc -fsyntax-only
-code-completion-at crash.cpp:2:14 crash.cpp -fcolor-diagnostics 
1.      crash.cpp:2:2: current parser token 'if'
 #0 0x00007fdff8de6eeb llvm::sys::PrintStackTrace(llvm::raw_ostream&)
(/usr/bin/../lib/libLLVM-10.so+0x9e9eeb)
 #1 0x00007fdff8de4a44 llvm::sys::RunSignalHandlers()
(/usr/bin/../lib/libLLVM-10.so+0x9e7a44)
 #2 0x00007fdff8de4b99 (/usr/bin/../lib/libLLVM-10.so+0x9e7b99)
 #3 0x00007fdff80946a0 __restore_rt (/usr/bin/../lib/libc.so.6+0x3d6a0)
 #4 0x00007fdffdfd8143 clang::Preprocessor::HandleIfDirective(clang::Token&,
clang::Token const&, bool) (/usr/bin/../lib/libclang-cpp.so.10+0x7c0143)
 #5 0x00007fdffdfdfe74 clang::Preprocessor::HandleDirective(clang::Token&)
(/usr/bin/../lib/libclang-cpp.so.10+0x7c7e74)
 #6 0x00007fdffdfa5af2 clang::Lexer::LexTokenInternal(clang::Token&, bool)
(/usr/bin/../lib/libclang-cpp.so.10+0x78daf2)
 #7 0x00007fdffe014cc0 clang::Preprocessor::Lex(clang::Token&)
(/usr/bin/../lib/libclang-cpp.so.10+0x7fccc0)
 #8 0x00007fdffe01b85f clang::ParseAST(clang::Sema&, bool, bool)
(/usr/bin/../lib/libclang-cpp.so.10+0x80385f)
 #9 0x00007fdfff8a90a9 clang::FrontendAction::Execute()
(/usr/bin/../lib/libclang-cpp.so.10+0x20910a9)
#10 0x00007fdfff85da94
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)
(/usr/bin/../lib/libclang-cpp.so.10+0x2045a94)
#11 0x00007fdfff92d832
clang::ExecuteCompilerInvocation(clang::CompilerInstance*)
(/usr/bin/../lib/libclang-cpp.so.10+0x2115832)
#12 0x000055a8ec3f97ed cc1_main(llvm::ArrayRef<char const*>, char const*,
void*) (/usr/bin/clang+++0x127ed)
#13 0x000055a8ec3f6ffc (/usr/bin/clang+++0xfffc)
#14 0x000055a8ec3f3525 main (/usr/bin/clang+++0xc525)
#15 0x00007fdff807f152 __libc_start_main (/usr/bin/../lib/libc.so.6+0x28152)
#16 0x000055a8ec3f696e _start (/usr/bin/clang+++0xf96e)


A short investigation shows that in Preprocessor::EnterMacro(), a null CurLexer
gets pushed on the stack via PushIncludeMacroStack(). After the next call to
PopIncludeMacroStack(), this null Lexer is being used in
Preprocessor::HandleIfDirective(), causing a segfault.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20201015/8af48c86/attachment-0001.html>


More information about the llvm-bugs mailing list