<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Crash in Lexer when doing code completion"
   href="https://bugs.llvm.org/show_bug.cgi?id=47851">47851</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Crash in Lexer when doing code completion
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Core LLVM classes
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>christian.kandeler@qt.io
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=24063" name="attach_24063" title="example source file">attachment 24063</a> <a href="attachment.cgi?id=24063&action=edit" title="example source file">[details]</a></span>
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.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>