vscode-cpptools icon indicating copy to clipboard operation
vscode-cpptools copied to clipboard

`llvm-project` parser crash on file: `clang\test\parser\parser_overflow.c`

Open shiltian opened this issue 2 years ago • 5 comments

Environment

  • OS and Version: macOS 12.4
  • VS Code Version: 1.69.2
  • C/C++ Extension Version: v1.11.4
  • Other extensions you installed (and if the issue persists after disabling them):
  • If using SSH remote, specify OS of remote machine: Fedora 35
  • A clear and concise description of what the bug is, including information about the workspace (i.e. is the workspace a single project or multiple projects, size of the project, etc). I was looking into the source code of llvm-project. Every a couple a minutes, I will get error messages from the Output view under the cpptools, saying:
[Error - 1:55:32 PM] Connection to server got closed. Server will not be restarted.
[Error - 1:55:32 PM] Request textDocument/documentHighlight failed.
Error: Connection got disposed.
	at Object.dispose (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:50563:25)
	at Object.dispose (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:51483:35)
	at LanguageClient.handleConnectionClosed (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:53565:42)
	at LanguageClient.handleConnectionClosed (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:54755:15)
	at closeHandler (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:53552:18)
	at CallbackList.invoke (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:49281:39)
	at Emitter.fire (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:49339:36)
	at closeHandler (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:49913:26)
	at CallbackList.invoke (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:49281:39)
	at Emitter.fire (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:49339:36)
	at StreamMessageReader.fireClose (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:50729:27)
	at Socket.<anonymous> (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:50769:46)
	at Socket.emit (node:events:402:35)
	at Pipe.<anonymous> (node:net:687:12)
[Error - 1:55:32 PM] Request textDocument/hover failed.
Error: Connection got disposed.
	at Object.dispose (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:50563:25)
	at Object.dispose (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:51483:35)
	at LanguageClient.handleConnectionClosed (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:53565:42)
	at LanguageClient.handleConnectionClosed (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:54755:15)
	at closeHandler (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:53552:18)
	at CallbackList.invoke (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:49281:39)
	at Emitter.fire (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:49339:36)
	at closeHandler (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:49913:26)
	at CallbackList.invoke (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:49281:39)
	at Emitter.fire (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:49339:36)
	at StreamMessageReader.fireClose (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:50729:27)
	at Socket.<anonymous> (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:50769:46)
	at Socket.emit (node:events:402:35)
	at Pipe.<anonymous> (node:net:687:12)
[Error - 1:55:32 PM] Request textDocument/definition failed.
Error: Connection got disposed.
	at Object.dispose (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:50563:25)
	at Object.dispose (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:51483:35)
	at LanguageClient.handleConnectionClosed (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:53565:42)
	at LanguageClient.handleConnectionClosed (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:54755:15)
	at closeHandler (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:53552:18)
	at CallbackList.invoke (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:49281:39)
	at Emitter.fire (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:49339:36)
	at closeHandler (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:49913:26)
	at CallbackList.invoke (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:49281:39)
	at Emitter.fire (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:49339:36)
	at StreamMessageReader.fireClose (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:50729:27)
	at Socket.<anonymous> (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:50769:46)
	at Socket.emit (node:events:402:35)
	at Pipe.<anonymous> (node:net:687:12)
[Error - 1:55:32 PM] Request textDocument/documentHighlight failed.
Error: Connection got disposed.
	at Object.dispose (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:50563:25)
	at Object.dispose (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:51483:35)
	at LanguageClient.handleConnectionClosed (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:53565:42)
	at LanguageClient.handleConnectionClosed (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:54755:15)
	at closeHandler (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:53552:18)
	at CallbackList.invoke (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:49281:39)
	at Emitter.fire (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:49339:36)
	at closeHandler (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:49913:26)
	at CallbackList.invoke (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:49281:39)
	at Emitter.fire (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:49339:36)
	at StreamMessageReader.fireClose (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:50729:27)
	at Socket.<anonymous> (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:50769:46)
	at Socket.emit (node:events:402:35)
	at Pipe.<anonymous> (node:net:687:12)
[Error - 1:55:32 PM] Request textDocument/definition failed.
Error: Connection got disposed.
	at Object.dispose (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:50563:25)
	at Object.dispose (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:51483:35)
	at LanguageClient.handleConnectionClosed (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:53565:42)
	at LanguageClient.handleConnectionClosed (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:54755:15)
	at closeHandler (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:53552:18)
	at CallbackList.invoke (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:49281:39)
	at Emitter.fire (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:49339:36)
	at closeHandler (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:49913:26)
	at CallbackList.invoke (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:49281:39)
	at Emitter.fire (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:49339:36)
	at StreamMessageReader.fireClose (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:50729:27)
	at Socket.<anonymous> (/home/shiltian/.vscode-server/extensions/ms-vscode.cpptools-1.11.4-linux-x64/dist/main.js:50769:46)
	at Socket.emit (node:events:402:35)
	at Pipe.<anonymous> (node:net:687:12)

That usually happens when I place my pointer onto some C++ symbols.

Bug Summary and Steps to Reproduce

Bug Summary: cpptools complains "Connection to server got closed. Server will not be restarted."

Steps to reproduce:

  1. Simply open the llvm-project on a remote machine.
  2. Browse any C++ source file.
  3. In a short while, the output window of cpptools will show:
[Error - 1:55:32 PM] Connection to server got closed. Server will not be restarted.
[Error - 1:55:32 PM] Request textDocument/documentHighlight failed.

Expected behavior

No error emitted from cpptools.

Code sample and Logs

Code sample: I was looking into the LLVM project, so any C++ source file in the project could do it, such as clang/lib/CodeGen/CGClass.cpp.

Configurations in c_cpp_properties.json:
{
    "configurations": [
        {
            "name": "Linux",
            "intelliSenseMode": "linux-clang-x64",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "cStandard": "c11",
            "cppStandard": "c++14",
            "compilerPath": "/home/shiltian/.local/llvm/bin/clang++",
            "compileCommands": "${workspaceFolder}/compile_commands.json",
            "configurationProvider": "ms-vscode.cmake-tools"
        }
    ],
    "version": 4
}


Logs from running C/C++: Log Diagnostics from the VS Code command palette:
-------- Diagnostics - 7/27/2022, 1:52:31 PM
Version: 1.11.4
Current Configuration:
{
    "name": "Linux",
    "intelliSenseMode": "linux-clang-x64",
    "includePath": [
        "${workspaceFolder}/**"
    ],
    "cStandard": "c11",
    "cppStandard": "c++14",
    "compilerPath": "/home/shiltian/.local/llvm/bin/clang++",
    "compileCommands": "${workspaceFolder}/compile_commands.json",
    "configurationProvider": "ms-vscode.cmake-tools",
    "compilerPathIsExplicit": true,
    "cStandardIsExplicit": true,
    "cppStandardIsExplicit": true,
    "intelliSenseModeIsExplicit": true,
    "mergeConfigurations": false,
    "browse": {
        "path": [
            "${workspaceFolder}/**"
        ],
        "limitSymbolsToIncludedHeaders": true
    }
}
Translation Unit Mappings:
[ /home/shiltian/Documents/vscode/llvm-project/clang/lib/CodeGen/CGClass.cpp ]:
    /home/shiltian/Documents/vscode/llvm-project/clang/lib/CodeGen/CGClass.cpp
[ /home/shiltian/Documents/vscode/llvm-project/clang/lib/CodeGen/CGExprCXX.cpp ]:
    /home/shiltian/Documents/vscode/llvm-project/clang/lib/CodeGen/CGExprCXX.cpp
Translation Unit Configurations:
[ /home/shiltian/Documents/vscode/llvm-project/clang/lib/CodeGen/CGClass.cpp ]:
    Process ID: 3017654
    Memory Usage: 460 MB
    Compiler Path: /home/shiltian/.local/llvm/bin/clang++
    Includes:
        /nvm/0/shiltian/build/llvm/release/tools/clang/lib/CodeGen
        /home/shiltian/Documents/vscode/llvm-project/clang/lib/CodeGen
        /home/shiltian/Documents/vscode/llvm-project/clang/include
        /nvm/0/shiltian/build/llvm/release/tools/clang/include
        /nvm/0/shiltian/build/llvm/release/include
        /home/shiltian/Documents/vscode/llvm-project/llvm/include
        /home/opt/cuda/11.4/targets/x86_64-linux/include
        /home/shiltian/.local/llvm-14/include
        /home/shiltian/.local/include
        /home/shiltian/Documents/vscode/llvm-project
        /usr/include/c++/11
        /usr/include/c++/11/x86_64-redhat-linux
        /usr/include/c++/11/backward
        /home/shiltian/.local/llvm-14/lib/clang/14.0.5/include
        /usr/local/include
        /usr/include
    Defines:
        GTEST_HAS_RTTI=0
        _DEBUG
        _GNU_SOURCE
        __STDC_CONSTANT_MACROS
        __STDC_FORMAT_MACROS
        __STDC_LIMIT_MACROS
        NDEBUG
    Standard Version: c++14
    IntelliSense Mode: linux-clang-x64
    Other Flags:
        --clang
        --clang_version=140005
    compile_commands.json entry:
        directory: /nvm/0/shiltian/build/llvm/release
        file: /home/shiltian/Documents/vscode/llvm-project/clang/lib/CodeGen/CGClass.cpp
        command: /usr/bin/clang++ -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/nvm/0/shiltian/build/llvm/release/tools/clang/lib/CodeGen -I/home/shiltian/Documents/vscode/llvm-project/clang/lib/CodeGen -I/home/shiltian/Documents/vscode/llvm-project/clang/include -I/nvm/0/shiltian/build/llvm/release/tools/clang/include -I/nvm/0/shiltian/build/llvm/release/include -I/home/shiltian/Documents/vscode/llvm-project/llvm/include  -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -fdiagnostics-color -ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual -Wno-nested-anon-types -O2 -g -DNDEBUG  -fno-exceptions -fno-rtti -UNDEBUG -std=c++14 -o tools/clang/lib/CodeGen/CMakeFiles/obj.clangCodeGen.dir/CGClass.cpp.o -c /home/shiltian/Documents/vscode/llvm-project/clang/lib/CodeGen/CGClass.cpp
[ /home/shiltian/Documents/vscode/llvm-project/clang/lib/CodeGen/CGExprCXX.cpp ]: not ready
    Process ID: 3017709
    Memory Usage: 460 MB
    Compiler Path: /home/shiltian/.local/llvm/bin/clang++
    Includes:
        /nvm/0/shiltian/build/llvm/release/tools/clang/lib/CodeGen
        /home/shiltian/Documents/vscode/llvm-project/clang/lib/CodeGen
... GitHub complains it's too long.

------- Workspace parsing diagnostics -------
Number of files discovered (not excluded): 202348

Logs from the language server logging:
loggingLevel: Debug
loggingLevel has changed to: Debug
cpptools/didChangeCppProperties
$/setTraceNotification
cpptools/getCodeActions: /home/shiltian/Documents/vscode/llvm-project/clang/lib/CodeGen/CGClass.cpp (id: 23)
cpptools/textEditorSelectionChange
cpptools/textEditorSelectionChange
textDocument/definition: /home/shiltian/Documents/vscode/llvm-project/clang/lib/CodeGen/CGClass.cpp (id: 24)
cpptools/activeDocumentChange: /home/shiltian/Documents/vscode/llvm-project/clang/lib/CodeGen/CGClass.cpp
textDocument/hover: /home/shiltian/Documents/vscode/llvm-project/clang/lib/CodeGen/CGClass.cpp (id: 25)
Request canceled: 25
cpptools/getCodeActions: /home/shiltian/Documents/vscode/llvm-project/clang/lib/CodeGen/CGClass.cpp (id: 26)
cpptools/getFoldingRanges: /home/shiltian/Documents/vscode/llvm-project/clang/lib/CodeGen/CGClass.cpp (id: 27)
textDocument/definition: /home/shiltian/Documents/vscode/llvm-project/clang/lib/CodeGen/CGClass.cpp (id: 28)
cpptools/textEditorSelectionChange
cpptools/activeDocumentChange: /home/shiltian/Documents/vscode/llvm-project/clang/lib/CodeGen/CGClass.cpp
  tag parsing file: /home/shiltian/Documents/vscode/llvm-project/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.create_directories/create_directories.pass.cpp
  tag parsing file: /home/shiltian/Documents/vscode/llvm-project/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.create_directory/create_directory.pass.cpp
  tag parsing file: /nvm/0/shiltian/build/llvm/release/lib/Target/AMDGPU/AMDGPUGenMCCodeEmitter.inc
  tag parsing file: /home/shiltian/Documents/vscode/llvm-project/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.create_directory/create_directory_with_attributes.pass.cpp
  tag parsing file: /home/shiltian/Documents/vscode/llvm-project/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.create_directory_symlink/create_directory_symlink.pass.cpp
  tag parsing file: /nvm/0/shiltian/build/llvm/release/lib/Target/AMDGPU/AMDGPUGenMCPseudoLowering.inc
  tag parsing file: /home/shiltian/Documents/vscode/llvm-project/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.create_hard_link/create_hard_link.pass.cpp
  tag parsing file: /home/shiltian/Documents/vscode/llvm-project/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.create_symlink/create_symlink.pass.cpp
  tag parsing file: 
... Github complains it's too long...

Screenshots

No response

Additional context

No response

shiltian avatar Jul 27 '22 18:07 shiltian

Hi @shiltian . It looks like the cpptools process is crashing due to a stack overflow, while trying to parse the file clang\test\parser\parser_overflow.c. Since it tries to ensure all files in the workspace are parsed, it repeatedly encounters the issue. I've opened an internal issue for this with our IntelliSense parser team.

Colengms avatar Jul 27 '22 19:07 Colengms

@Colengms Thanks for the quick response. Feel free to let me know what I can help.

shiltian avatar Jul 28 '22 01:07 shiltian

Actually is there any way to work around the issue for now? Like excluding some specific files to be scanned by cpptools?

shiltian avatar Jul 28 '22 01:07 shiltian

@shiltian You can add something like "**/clang/test/parser": true to the C_Cpp.files.exclude setting. That should cause the folder to be skipped for workspace tag parsing.

sean-mcmanus avatar Jul 28 '22 20:07 sean-mcmanus

@sean-mcmanus that works! Thanks!

shiltian avatar Jul 29 '22 03:07 shiltian

Fixed with https://github.com/microsoft/vscode-cpptools/releases/tag/v1.12.1 (1.10.5 may also have a "workaround" for it).

It looks like it's just "workedaround"...the actual fix is being tracked internally by 1582747 .

sean-mcmanus avatar Aug 16 '22 23:08 sean-mcmanus

I believe this has since been fully addressed. The work-around was removed from the code.

Colengms avatar Feb 01 '23 02:02 Colengms