clangd / clangd

clangd language server
https://clangd.llvm.org
Apache License 2.0
1.5k stars 61 forks source link

Crash on completing `using enum ...` (C++20) #1281

Closed i-ky closed 1 year ago

i-ky commented 2 years ago

Crash occurs when user types using enum ....

Can be reproduced with the following code (test.cpp):

enum class Foo {Bar, Baz};

void test() {}

and the following configuration (.clangd):

CompileFlags:
  Add:
  - -std=c++20

Jump to function body using VS Code (but the crash can be observed with other editors too):

code --goto test.cpp:3:14

Start typing using enum Foo;, after typing F clangd crashes.

I am using clangd compiled from source (updated every morning) with a little patch of mine (which should not affect this behaviour).

Logs

Logs obtained from VS Code, but the same crash can be experienced with Kate editor and it's built-in LSP Client plugin. To shorten the logs I've actually pasted using enum F from clipboard and triggered autocomplete with Ctrl+Space

I[16:45:12.866] clangd version 16.0.0 (https://github.com/llvm/llvm-project.git b53bccb18d2a437b04f4259cdcced479c909cbfd)
I[16:45:12.866] Features: linux+grpc
I[16:45:12.866] PID: 96326
I[16:45:12.866] Working directory: /tmp
I[16:45:12.866] argv[0]: /usr/local/bin/clangd
I[16:45:12.866] argv[1]: --query-driver=/opt/**/*-gcc-*,/**/cc,/**/cxx,/**/gcc,/**/g++,/**/clang-tool
I[16:45:12.866] argv[2]: --log=verbose
V[16:45:12.866] User config file is /home/i-ky/.config/clangd/config.yaml
I[16:45:12.866] Starting LSP over stdin/stdout
V[16:45:12.866] <<< {"id":0,"jsonrpc":"2.0","method":"initialize","params":{"capabilities":{"general":{"markdown":{"parser":"marked","version":"1.1.0"},"positionEncodings":["utf-16"],"regularExpressions":{"engine":"ECMAScript","version":"ES2020"},"staleRequestSupport":{"cancel":true,"retryOnContentModified":["textDocument/semanticTokens/full","textDocument/semanticTokens/range","textDocument/semanticTokens/full/delta"]}},"notebookDocument":{"synchronization":{"dynamicRegistration":true,"executionSummarySupport":true}},"textDocument":{"callHierarchy":{"dynamicRegistration":true},"codeAction":{"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}},"dataSupport":true,"disabledSupport":true,"dynamicRegistration":true,"honorsChangeAnnotations":false,"isPreferredSupport":true,"resolveSupport":{"properties":["edit"]}},"codeLens":{"dynamicRegistration":true},"colorProvider":{"dynamicRegistration":true},"completion":{"completionItem":{"commitCharactersSupport":true,"deprecatedSupport":true,"documentationFormat":["markdown","plaintext"],"insertReplaceSupport":true,"insertTextModeSupport":{"valueSet":[1,2]},"labelDetailsSupport":true,"preselectSupport":true,"resolveSupport":{"properties":["documentation","detail","additionalTextEdits"]},"snippetSupport":true,"tagSupport":{"valueSet":[1]}},"completionItemKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]},"completionList":{"itemDefaults":["commitCharacters","editRange","insertTextFormat","insertTextMode"]},"contextSupport":true,"dynamicRegistration":true,"editsNearCursor":true,"insertTextMode":2},"declaration":{"dynamicRegistration":true,"linkSupport":true},"definition":{"dynamicRegistration":true,"linkSupport":true},"diagnostic":{"dynamicRegistration":true,"relatedDocumentSupport":false},"documentHighlight":{"dynamicRegistration":true},"documentLink":{"dynamicRegistration":true,"tooltipSupport":true},"documentSymbol":{"dynamicRegistration":true,"hierarchicalDocumentSymbolSupport":true,"labelSupport":true,"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]},"tagSupport":{"valueSet":[1]}},"foldingRange":{"dynamicRegistration":true,"foldingRange":{"collapsedText":false},"foldingRangeKind":{"valueSet":["comment","imports","region"]},"lineFoldingOnly":true,"rangeLimit":5000},"formatting":{"dynamicRegistration":true},"hover":{"contentFormat":["markdown","plaintext"],"dynamicRegistration":true},"implementation":{"dynamicRegistration":true,"linkSupport":true},"inlayHint":{"dynamicRegistration":true,"resolveSupport":{"properties":["tooltip","textEdits","label.tooltip","label.location","label.command"]}},"inlineValue":{"dynamicRegistration":true},"linkedEditingRange":{"dynamicRegistration":true},"onTypeFormatting":{"dynamicRegistration":true},"publishDiagnostics":{"codeDescriptionSupport":true,"dataSupport":true,"relatedInformation":true,"tagSupport":{"valueSet":[1,2]},"versionSupport":false},"rangeFormatting":{"dynamicRegistration":true},"references":{"dynamicRegistration":true},"rename":{"dynamicRegistration":true,"honorsChangeAnnotations":true,"prepareSupport":true,"prepareSupportDefaultBehavior":1},"selectionRange":{"dynamicRegistration":true},"semanticTokens":{"augmentsSyntaxTokens":true,"dynamicRegistration":true,"formats":["relative"],"multilineTokenSupport":false,"overlappingTokenSupport":false,"requests":{"full":{"delta":true},"range":true},"serverCancelSupport":true,"tokenModifiers":["declaration","definition","readonly","static","deprecated","abstract","async","modification","documentation","defaultLibrary"],"tokenTypes":["namespace","type","class","enum","interface","struct","typeParameter","parameter","variable","property","enumMember","event","function","method","macro","keyword","modifier","comment","string","number","regexp","operator","decorator"]},"signatureHelp":{"contextSupport":true,"dynamicRegistration":true,"signatureInformation":{"activeParameterSupport":true,"documentationFormat":["markdown","plaintext"],"parameterInformation":{"labelOffsetSupport":true}}},"synchronization":{"didSave":true,"dynamicRegistration":true,"willSave":true,"willSaveWaitUntil":true},"typeDefinition":{"dynamicRegistration":true,"linkSupport":true},"typeHierarchy":{"dynamicRegistration":true}},"window":{"showDocument":{"support":true},"showMessage":{"messageActionItem":{"additionalPropertiesSupport":true}},"workDoneProgress":true},"workspace":{"applyEdit":true,"codeLens":{"refreshSupport":true},"configuration":true,"diagnostics":{"refreshSupport":true},"didChangeConfiguration":{"dynamicRegistration":true},"didChangeWatchedFiles":{"dynamicRegistration":true,"relativePatternSupport":true},"executeCommand":{"dynamicRegistration":true},"fileOperations":{"didCreate":true,"didDelete":true,"didRename":true,"dynamicRegistration":true,"willCreate":true,"willDelete":true,"willRename":true},"inlayHint":{"refreshSupport":true},"inlineValue":{"refreshSupport":true},"semanticTokens":{"refreshSupport":true},"symbol":{"dynamicRegistration":true,"resolveSupport":{"properties":["location.range"]},"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]},"tagSupport":{"valueSet":[1]}},"workspaceEdit":{"changeAnnotationSupport":{"groupsOnLabel":true},"documentChanges":true,"failureHandling":"textOnlyTransactional","normalizesLineEndings":true,"resourceOperations":["create","rename","delete"]},"workspaceFolders":true}},"clientInfo":{"name":"Visual Studio Code","version":"1.71.0"},"initializationOptions":{"clangdFileStatus":true,"fallbackFlags":[]},"locale":"en-us","processId":96232,"rootPath":null,"rootUri":null,"trace":"off","workspaceFolders":null}}

I[16:45:12.866] <-- initialize(0)
I[16:45:12.866] --> reply:initialize(0) 0 ms
V[16:45:12.866] >>> {"id":0,"jsonrpc":"2.0","result":{"capabilities":{"astProvider":true,"callHierarchyProvider":true,"clangdInlayHintsProvider":true,"codeActionProvider":{"codeActionKinds":["quickfix","refactor","info"]},"compilationDatabase":{"automaticReload":true},"completionProvider":{"resolveProvider":false,"triggerCharacters":[".","<",">",":","\"","/","*"]},"declarationProvider":true,"definitionProvider":true,"documentFormattingProvider":true,"documentHighlightProvider":true,"documentLinkProvider":{"resolveProvider":false},"documentOnTypeFormattingProvider":{"firstTriggerCharacter":"\n","moreTriggerCharacter":[]},"documentRangeFormattingProvider":true,"documentSymbolProvider":true,"executeCommandProvider":{"commands":["clangd.applyFix","clangd.applyTweak"]},"foldingRangeProvider":true,"hoverProvider":true,"implementationProvider":true,"inlayHintProvider":true,"memoryUsageProvider":true,"referencesProvider":true,"renameProvider":{"prepareProvider":true},"selectionRangeProvider":true,"semanticTokensProvider":{"full":{"delta":true},"legend":{"tokenModifiers":["declaration","deprecated","deduced","readonly","static","abstract","virtual","dependentName","defaultLibrary","usedAsMutableReference","functionScope","classScope","fileScope","globalScope"],"tokenTypes":["variable","variable","parameter","function","method","function","property","variable","class","interface","enum","enumMember","type","type","unknown","namespace","typeParameter","concept","type","macro","comment"]},"range":false},"signatureHelpProvider":{"triggerCharacters":["(",")","{","}","<",">",","]},"standardTypeHierarchyProvider":true,"textDocumentSync":{"change":2,"openClose":true,"save":true},"typeDefinitionProvider":true,"typeHierarchyProvider":true,"workspaceSymbolProvider":true},"serverInfo":{"name":"clangd","version":"clangd version 16.0.0 (https://github.com/llvm/llvm-project.git b53bccb18d2a437b04f4259cdcced479c909cbfd) linux+grpc x86_64-unknown-linux-gnu"}}}

V[16:45:12.867] <<< {"jsonrpc":"2.0","method":"initialized","params":{}}

I[16:45:12.867] <-- initialized
V[16:45:12.869] <<< {"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"languageId":"cpp","text":"enum class Foo {Bar, Baz};\n\nvoid test() {}\n","uri":"file:///tmp/test.cpp","version":1}}}

I[16:45:12.869] <-- textDocument/didOpen
V[16:45:12.869] config note at /tmp/.clangd:1:0: Parsing config fragment
V[16:45:12.869] config note at /tmp/.clangd:1:0: Parsed 1 fragments from file
V[16:45:12.869] Config fragment: compiling /tmp/.clangd:1 -> 0x00007F76D80023C0 (trusted=false)
I[16:45:12.869] --> textDocument/publishDiagnostics
V[16:45:12.869] >>> {"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"diagnostics":[],"uri":"file:///tmp/.clangd"}}

I[16:45:12.869] Failed to find compilation database for /tmp/test.cpp
I[16:45:12.869] ASTWorker building file /tmp/test.cpp version 1 with command clangd fallback
[/tmp]
/usr/lib/llvm-14/bin/clang -std=c++20 -resource-dir=/home/i-ky/llvm-project/build/lib/clang/16.0.0 -- /tmp/test.cpp
V[16:45:12.870] Driver produced command: cc1 -cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name test.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -mllvm -treat-scalable-fixed-error-as-warning -debugger-tuning=gdb -fcoverage-compilation-dir=/tmp -resource-dir /home/i-ky/llvm-project/build/lib/clang/16.0.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/x86_64-linux-gnu/c++/11 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/backward -internal-isystem /home/i-ky/llvm-project/build/lib/clang/16.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/11/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -std=c++20 -fdeprecated-macro -fdebug-compilation-dir=/tmp -ferror-limit 19 -fgnuc-version=4.2.1 -fno-implicit-modules -fcxx-exceptions -fexceptions -no-round-trip-args -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -x c++ /tmp/test.cpp
I[16:45:12.870] --> textDocument/clangd.fileStatus
V[16:45:12.870] >>> {"jsonrpc":"2.0","method":"textDocument/clangd.fileStatus","params":{"state":"parsing includes, running Update","uri":"file:///tmp/test.cpp"}}

V[16:45:12.870] Building first preamble for /tmp/test.cpp version 1
V[16:45:12.874] <<< {"id":1,"jsonrpc":"2.0","method":"textDocument/documentSymbol","params":{"textDocument":{"uri":"file:///tmp/test.cpp"}}}

I[16:45:12.874] <-- textDocument/documentSymbol(1)
V[16:45:12.874] <<< {"id":2,"jsonrpc":"2.0","method":"textDocument/documentSymbol","params":{"textDocument":{"uri":"file:///tmp/test.cpp"}}}

I[16:45:12.874] <-- textDocument/documentSymbol(2)
V[16:45:12.874] indexed preamble AST for /tmp/test.cpp version 1:
  symbol slab: 0 symbols, 120 bytes
  ref slab: 0 symbols, 0 refs, 128 bytes
  relations slab: 0 relations, 24 bytes
V[16:45:12.874] <<< {"id":3,"jsonrpc":"2.0","method":"textDocument/codeAction","params":{"context":{"diagnostics":[],"triggerKind":2},"range":{"end":{"character":13,"line":2},"start":{"character":13,"line":2}},"textDocument":{"uri":"file:///tmp/test.cpp"}}}

I[16:45:12.874] <-- textDocument/codeAction(3)
I[16:45:12.874] Built preamble of size 214848 for file /tmp/test.cpp version 1 in 0.00 seconds
I[16:45:12.874] --> workspace/semanticTokens/refresh(0)
V[16:45:12.874] >>> {"id":0,"jsonrpc":"2.0","method":"workspace/semanticTokens/refresh","params":null}

I[16:45:12.874] --> textDocument/clangd.fileStatus
V[16:45:12.874] >>> {"jsonrpc":"2.0","method":"textDocument/clangd.fileStatus","params":{"state":"parsing includes, running Build AST","uri":"file:///tmp/test.cpp"}}

I[16:45:12.874] --> textDocument/clangd.fileStatus
V[16:45:12.874] >>> {"jsonrpc":"2.0","method":"textDocument/clangd.fileStatus","params":{"state":"parsing includes, parsing main file","uri":"file:///tmp/test.cpp"}}

V[16:45:12.874] <<< {"id":4,"jsonrpc":"2.0","method":"textDocument/documentLink","params":{"textDocument":{"uri":"file:///tmp/test.cpp"}}}

I[16:45:12.874] <-- textDocument/documentLink(4)
V[16:45:12.874] <<< {"id":5,"jsonrpc":"2.0","method":"textDocument/inlayHint","params":{"range":{"end":{"character":0,"line":3},"start":{"character":0,"line":0}},"textDocument":{"uri":"file:///tmp/test.cpp"}}}

I[16:45:12.874] <-- textDocument/inlayHint(5)
V[16:45:12.875] <<< {"id":0,"jsonrpc":"2.0","result":null}

I[16:45:12.875] <-- reply(0)
V[16:45:12.876] indexed file AST for /tmp/test.cpp version 1:
  symbol slab: 4 symbols, 5144 bytes
  ref slab: 4 symbols, 4 refs, 4320 bytes
  relations slab: 0 relations, 24 bytes
V[16:45:12.876] Build dynamic index for main-file symbols with estimated memory usage of 13080 bytes
I[16:45:12.876] --> textDocument/publishDiagnostics
V[16:45:12.876] >>> {"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"diagnostics":[],"uri":"file:///tmp/test.cpp","version":1}}

V[16:45:12.876] ASTWorker running DocumentSymbols on version 1 of /tmp/test.cpp
I[16:45:12.876] --> reply:textDocument/documentSymbol(1) 2 ms
V[16:45:12.876] >>> {"id":1,"jsonrpc":"2.0","result":[{"children":[{"detail":"Foo","kind":22,"name":"Bar","range":{"end":{"character":19,"line":0},"start":{"character":16,"line":0}},"selectionRange":{"end":{"character":19,"line":0},"start":{"character":16,"line":0}}},{"detail":"Foo","kind":22,"name":"Baz","range":{"end":{"character":24,"line":0},"start":{"character":21,"line":0}},"selectionRange":{"end":{"character":24,"line":0},"start":{"character":21,"line":0}}}],"detail":"enum","kind":10,"name":"Foo","range":{"end":{"character":25,"line":0},"start":{"character":0,"line":0}},"selectionRange":{"end":{"character":14,"line":0},"start":{"character":11,"line":0}}},{"detail":"void ()","kind":12,"name":"test","range":{"end":{"character":14,"line":2},"start":{"character":0,"line":2}},"selectionRange":{"end":{"character":9,"line":2},"start":{"character":5,"line":2}}}]}

V[16:45:12.876] ASTWorker running DocumentSymbols on version 1 of /tmp/test.cpp
I[16:45:12.877] --> reply:textDocument/documentSymbol(2) 2 ms
V[16:45:12.877] >>> {"id":2,"jsonrpc":"2.0","result":[{"children":[{"detail":"Foo","kind":22,"name":"Bar","range":{"end":{"character":19,"line":0},"start":{"character":16,"line":0}},"selectionRange":{"end":{"character":19,"line":0},"start":{"character":16,"line":0}}},{"detail":"Foo","kind":22,"name":"Baz","range":{"end":{"character":24,"line":0},"start":{"character":21,"line":0}},"selectionRange":{"end":{"character":24,"line":0},"start":{"character":21,"line":0}}}],"detail":"enum","kind":10,"name":"Foo","range":{"end":{"character":25,"line":0},"start":{"character":0,"line":0}},"selectionRange":{"end":{"character":14,"line":0},"start":{"character":11,"line":0}}},{"detail":"void ()","kind":12,"name":"test","range":{"end":{"character":14,"line":2},"start":{"character":0,"line":2}},"selectionRange":{"end":{"character":9,"line":2},"start":{"character":5,"line":2}}}]}

V[16:45:12.877] ASTWorker running EnumerateTweaks on version 1 of /tmp/test.cpp
I[16:45:12.877] --> reply:textDocument/codeAction(3) 2 ms
V[16:45:12.877] >>> {"id":3,"jsonrpc":"2.0","result":[]}

V[16:45:12.877] ASTWorker running DocumentLinks on version 1 of /tmp/test.cpp
I[16:45:12.877] --> reply:textDocument/documentLink(4) 2 ms
V[16:45:12.877] >>> {"id":4,"jsonrpc":"2.0","result":[]}

V[16:45:12.877] ASTWorker running InlayHints on version 1 of /tmp/test.cpp
I[16:45:12.877] --> reply:textDocument/inlayHint(5) 2 ms
V[16:45:12.877] >>> {"id":5,"jsonrpc":"2.0","result":[]}

I[16:45:12.877] --> textDocument/clangd.fileStatus
V[16:45:12.877] >>> {"jsonrpc":"2.0","method":"textDocument/clangd.fileStatus","params":{"state":"idle","uri":"file:///tmp/test.cpp"}}

V[16:45:12.878] <<< {"id":6,"jsonrpc":"2.0","method":"textDocument/semanticTokens/full","params":{"textDocument":{"uri":"file:///tmp/test.cpp"}}}

I[16:45:12.878] <-- textDocument/semanticTokens/full(6)
V[16:45:12.878] ASTWorker running SemanticHighlights on version 1 of /tmp/test.cpp
I[16:45:12.878] --> reply:textDocument/semanticTokens/full(6) 0 ms
V[16:45:12.878] >>> {"id":6,"jsonrpc":"2.0","result":{"data":[0,11,3,10,8193,0,5,3,11,8201,0,5,3,11,8201,2,5,4,3,8193],"resultId":"1"}}

I[16:45:12.878] --> textDocument/clangd.fileStatus
V[16:45:12.878] >>> {"jsonrpc":"2.0","method":"textDocument/clangd.fileStatus","params":{"state":"idle","uri":"file:///tmp/test.cpp"}}

V[16:45:13.073] <<< {"id":7,"jsonrpc":"2.0","method":"textDocument/foldingRange","params":{"textDocument":{"uri":"file:///tmp/test.cpp"}}}

I[16:45:13.073] <-- textDocument/foldingRange(7)
I[16:45:13.073] --> reply:textDocument/foldingRange(7) 0 ms
V[16:45:13.073] >>> {"id":7,"jsonrpc":"2.0","result":[]}

V[16:45:14.827] <<< {"jsonrpc":"2.0","method":"textDocument/didChange","params":{"contentChanges":[{"range":{"end":{"character":13,"line":2},"start":{"character":13,"line":2}},"rangeLength":0,"text":"using enum F"}],"textDocument":{"uri":"file:///tmp/test.cpp","version":2}}}

I[16:45:14.827] <-- textDocument/didChange
I[16:45:14.827] --> textDocument/clangd.fileStatus
V[16:45:14.827] >>> {"jsonrpc":"2.0","method":"textDocument/clangd.fileStatus","params":{"state":"file is queued","uri":"file:///tmp/test.cpp"}}

V[16:45:14.827] <<< {"id":8,"jsonrpc":"2.0","method":"textDocument/documentSymbol","params":{"textDocument":{"uri":"file:///tmp/test.cpp"}}}

I[16:45:14.827] <-- textDocument/documentSymbol(8)
I[16:45:14.827] Failed to find compilation database for /tmp/test.cpp
I[16:45:14.827] ASTWorker building file /tmp/test.cpp version 2 with command clangd fallback
[/tmp]
/usr/lib/llvm-14/bin/clang -std=c++20 -resource-dir=/home/i-ky/llvm-project/build/lib/clang/16.0.0 -- /tmp/test.cpp
V[16:45:14.828] Driver produced command: cc1 -cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name test.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -mllvm -treat-scalable-fixed-error-as-warning -debugger-tuning=gdb -fcoverage-compilation-dir=/tmp -resource-dir /home/i-ky/llvm-project/build/lib/clang/16.0.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/x86_64-linux-gnu/c++/11 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/backward -internal-isystem /home/i-ky/llvm-project/build/lib/clang/16.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/11/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -std=c++20 -fdeprecated-macro -fdebug-compilation-dir=/tmp -ferror-limit 19 -fgnuc-version=4.2.1 -fno-implicit-modules -fcxx-exceptions -fexceptions -no-round-trip-args -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -x c++ /tmp/test.cpp
I[16:45:14.828] --> textDocument/clangd.fileStatus
V[16:45:14.828] >>> {"jsonrpc":"2.0","method":"textDocument/clangd.fileStatus","params":{"state":"parsing includes, running DocumentSymbols","uri":"file:///tmp/test.cpp"}}

V[16:45:14.828] Reusing preamble version 1 for version 2 of /tmp/test.cpp
V[16:45:14.828] ASTWorker rebuilding evicted AST to run DocumentSymbols: /tmp/test.cpp version 2
V[16:45:14.830] Trying to fix include for incomplete type F
V[16:45:14.830] ASTWorker running DocumentSymbols on version 2 of /tmp/test.cpp
I[16:45:14.830] --> reply:textDocument/documentSymbol(8) 3 ms
V[16:45:14.830] >>> {"id":8,"jsonrpc":"2.0","result":[{"children":[{"detail":"Foo","kind":22,"name":"Bar","range":{"end":{"character":19,"line":0},"start":{"character":16,"line":0}},"selectionRange":{"end":{"character":19,"line":0},"start":{"character":16,"line":0}}},{"detail":"Foo","kind":22,"name":"Baz","range":{"end":{"character":24,"line":0},"start":{"character":21,"line":0}},"selectionRange":{"end":{"character":24,"line":0},"start":{"character":21,"line":0}}}],"detail":"enum","kind":10,"name":"Foo","range":{"end":{"character":25,"line":0},"start":{"character":0,"line":0}},"selectionRange":{"end":{"character":14,"line":0},"start":{"character":11,"line":0}}},{"detail":"void ()","kind":12,"name":"test","range":{"end":{"character":26,"line":2},"start":{"character":0,"line":2}},"selectionRange":{"end":{"character":9,"line":2},"start":{"character":5,"line":2}}}]}

I[16:45:14.830] Skipping rebuild of the AST for /tmp/test.cpp, inputs are the same.
V[16:45:14.830] indexed file AST for /tmp/test.cpp version 2:
  symbol slab: 4 symbols, 5144 bytes
  ref slab: 4 symbols, 4 refs, 4320 bytes
  relations slab: 0 relations, 24 bytes
V[16:45:14.831] Build dynamic index for main-file symbols with estimated memory usage of 13080 bytes
I[16:45:14.831] --> textDocument/publishDiagnostics
V[16:45:14.831] >>> {"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"diagnostics":[{"code":"forward_ref_enum","message":"ISO C++ forbids forward references to 'enum' types","range":{"end":{"character":25,"line":2},"start":{"character":24,"line":2}},"relatedInformation":[],"severity":1,"source":"clang"},{"code":"incomplete_enum","message":"Enumeration 'F' is incomplete","range":{"end":{"character":25,"line":2},"start":{"character":24,"line":2}},"relatedInformation":[{"location":{"range":{"end":{"character":25,"line":2},"start":{"character":24,"line":2}},"uri":"file:///tmp/test.cpp"},"message":"Declared here"}],"severity":1,"source":"clang"},{"code":"expected_after","message":"Expected ';' after using-enum declaration (fix available)","range":{"end":{"character":26,"line":2},"start":{"character":25,"line":2}},"relatedInformation":[],"severity":1,"source":"clang"},{"code":"expected","message":"Expected '}'","range":{"end":{"character":0,"line":3},"start":{"character":0,"line":3}},"relatedInformation":[{"location":{"range":{"end":{"character":13,"line":2},"start":{"character":12,"line":2}},"uri":"file:///tmp/test.cpp"},"message":"To match this '{'"}],"severity":1,"source":"clang"}],"uri":"file:///tmp/test.cpp","version":2}}

I[16:45:14.831] --> textDocument/clangd.fileStatus
V[16:45:14.831] >>> {"jsonrpc":"2.0","method":"textDocument/clangd.fileStatus","params":{"state":"idle","uri":"file:///tmp/test.cpp"}}

V[16:45:14.963] <<< {"id":9,"jsonrpc":"2.0","method":"textDocument/foldingRange","params":{"textDocument":{"uri":"file:///tmp/test.cpp"}}}

I[16:45:14.963] <-- textDocument/foldingRange(9)
I[16:45:14.963] --> reply:textDocument/foldingRange(9) 0 ms
V[16:45:14.963] >>> {"id":9,"jsonrpc":"2.0","result":[]}

V[16:45:15.059] <<< {"id":10,"jsonrpc":"2.0","method":"textDocument/semanticTokens/full/delta","params":{"previousResultId":"1","textDocument":{"uri":"file:///tmp/test.cpp"}}}

I[16:45:15.059] <-- textDocument/semanticTokens/full/delta(10)
V[16:45:15.059] ASTWorker running SemanticHighlights on version 2 of /tmp/test.cpp
I[16:45:15.059] --> reply:textDocument/semanticTokens/full/delta(10) 0 ms
V[16:45:15.059] >>> {"id":10,"jsonrpc":"2.0","result":{"edits":[],"resultId":"2"}}

I[16:45:15.059] --> textDocument/clangd.fileStatus
V[16:45:15.059] >>> {"jsonrpc":"2.0","method":"textDocument/clangd.fileStatus","params":{"state":"idle","uri":"file:///tmp/test.cpp"}}

V[16:45:15.090] <<< {"id":11,"jsonrpc":"2.0","method":"textDocument/codeAction","params":{"context":{"diagnostics":[{"code":"forward_ref_enum","message":"ISO C++ forbids forward references to 'enum' types","range":{"end":{"character":25,"line":2},"start":{"character":24,"line":2}},"relatedInformation":[],"severity":1,"source":"clang"},{"code":"incomplete_enum","message":"Enumeration 'F' is incomplete","range":{"end":{"character":25,"line":2},"start":{"character":24,"line":2}},"relatedInformation":[{"location":{"range":{"end":{"character":25,"line":2},"start":{"character":24,"line":2}},"uri":"file:///tmp/test.cpp"},"message":"Declared here"}],"severity":1,"source":"clang"},{"code":"expected_after","message":"Expected ';' after using-enum declaration (fix available)","range":{"end":{"character":26,"line":2},"start":{"character":25,"line":2}},"relatedInformation":[],"severity":1,"source":"clang"}],"triggerKind":2},"range":{"end":{"character":25,"line":2},"start":{"character":25,"line":2}},"textDocument":{"uri":"file:///tmp/test.cpp"}}}

I[16:45:15.090] <-- textDocument/codeAction(11)
V[16:45:15.090] ASTWorker running EnumerateTweaks on version 2 of /tmp/test.cpp
I[16:45:15.090] --> reply:textDocument/codeAction(11) 0 ms
V[16:45:15.090] >>> {"id":11,"jsonrpc":"2.0","result":[{"diagnostics":[{"code":"expected_after","message":"Expected ';' after using-enum declaration (fix available)","range":{"end":{"character":26,"line":2},"start":{"character":25,"line":2}},"severity":1,"source":"clang"}],"edit":{"changes":{"file:///tmp/test.cpp":[{"newText":";","range":{"end":{"character":25,"line":2},"start":{"character":25,"line":2}}}]}},"isPreferred":true,"kind":"quickfix","title":"insert ';'"}]}

I[16:45:15.090] --> textDocument/clangd.fileStatus
V[16:45:15.090] >>> {"jsonrpc":"2.0","method":"textDocument/clangd.fileStatus","params":{"state":"idle","uri":"file:///tmp/test.cpp"}}

V[16:45:15.113] <<< {"id":12,"jsonrpc":"2.0","method":"textDocument/documentSymbol","params":{"textDocument":{"uri":"file:///tmp/test.cpp"}}}

I[16:45:15.113] <-- textDocument/documentSymbol(12)
V[16:45:15.113] ASTWorker running DocumentSymbols on version 2 of /tmp/test.cpp
I[16:45:15.114] --> reply:textDocument/documentSymbol(12) 0 ms
V[16:45:15.114] >>> {"id":12,"jsonrpc":"2.0","result":[{"children":[{"detail":"Foo","kind":22,"name":"Bar","range":{"end":{"character":19,"line":0},"start":{"character":16,"line":0}},"selectionRange":{"end":{"character":19,"line":0},"start":{"character":16,"line":0}}},{"detail":"Foo","kind":22,"name":"Baz","range":{"end":{"character":24,"line":0},"start":{"character":21,"line":0}},"selectionRange":{"end":{"character":24,"line":0},"start":{"character":21,"line":0}}}],"detail":"enum","kind":10,"name":"Foo","range":{"end":{"character":25,"line":0},"start":{"character":0,"line":0}},"selectionRange":{"end":{"character":14,"line":0},"start":{"character":11,"line":0}}},{"detail":"void ()","kind":12,"name":"test","range":{"end":{"character":26,"line":2},"start":{"character":0,"line":2}},"selectionRange":{"end":{"character":9,"line":2},"start":{"character":5,"line":2}}}]}

I[16:45:15.114] --> textDocument/clangd.fileStatus
V[16:45:15.114] >>> {"jsonrpc":"2.0","method":"textDocument/clangd.fileStatus","params":{"state":"idle","uri":"file:///tmp/test.cpp"}}

V[16:45:15.763] <<< {"id":13,"jsonrpc":"2.0","method":"textDocument/documentLink","params":{"textDocument":{"uri":"file:///tmp/test.cpp"}}}

I[16:45:15.763] <-- textDocument/documentLink(13)
V[16:45:15.763] ASTWorker running DocumentLinks on version 2 of /tmp/test.cpp
I[16:45:15.763] --> reply:textDocument/documentLink(13) 0 ms
V[16:45:15.763] >>> {"id":13,"jsonrpc":"2.0","result":[]}

I[16:45:15.763] --> textDocument/clangd.fileStatus
V[16:45:15.763] >>> {"jsonrpc":"2.0","method":"textDocument/clangd.fileStatus","params":{"state":"idle","uri":"file:///tmp/test.cpp"}}

V[16:45:16.014] <<< {"id":14,"jsonrpc":"2.0","method":"textDocument/inlayHint","params":{"range":{"end":{"character":0,"line":3},"start":{"character":0,"line":0}},"textDocument":{"uri":"file:///tmp/test.cpp"}}}

I[16:45:16.014] <-- textDocument/inlayHint(14)
V[16:45:16.014] ASTWorker running InlayHints on version 2 of /tmp/test.cpp
I[16:45:16.014] --> reply:textDocument/inlayHint(14) 0 ms
V[16:45:16.014] >>> {"id":14,"jsonrpc":"2.0","result":[]}

I[16:45:16.014] --> textDocument/clangd.fileStatus
V[16:45:16.014] >>> {"jsonrpc":"2.0","method":"textDocument/clangd.fileStatus","params":{"state":"idle","uri":"file:///tmp/test.cpp"}}

V[16:45:16.484] <<< {"id":15,"jsonrpc":"2.0","method":"textDocument/completion","params":{"context":{"triggerKind":1},"position":{"character":25,"line":2},"textDocument":{"uri":"file:///tmp/test.cpp"}}}

I[16:45:16.484] <-- textDocument/completion(15)
V[16:45:16.487] Code complete: fuzzyFind({
  "AnyScope": true,
  "Limit": 100,
  "PreferredTypes": [],
  "ProximityPaths": [
    "/tmp/test.cpp"
  ],
  "Query": "F",
  "RestrictForCodeCompletion": true,
  "Scopes": [
    ""
  ]
})
I[16:45:16.488] Code complete: sema context EnumTag, query scopes [] (AnyScope=true), expected type <none>
 #0 0x00005593fb0dc1b5 PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
 #1 0x00005593fb0da0b4 SignalHandler(int) Signals.cpp:0:0
 #2 0x00007f7725a3c520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x00005593fb1a4551 clang::TagDecl::getDefinition() const (/usr/local/bin/clangd+0x725551)
 #4 0x00005593fbbd9e7a clang::Sema::ActOnUsingEnumDeclaration(clang::Scope*, clang::AccessSpecifier, clang::SourceLocation, clang::SourceLocation, clang::DeclSpec const&) (/usr/local/bin/clangd+0x115ae7a)
 #5 0x00005593fcd8a02e clang::Parser::ParseUsingDeclaration(clang::DeclaratorContext, clang::Parser::ParsedTemplateInfo const&, clang::SourceLocation, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (/usr/local/bin/clangd+0x230b02e)
 #6 0x00005593fcd961a5 clang::Parser::ParseUsingDirectiveOrDeclaration(clang::DeclaratorContext, clang::Parser::ParsedTemplateInfo const&, clang::SourceLocation&, clang::ParsedAttributes&) (/usr/local/bin/clangd+0x23171a5)
 #7 0x00005593fcd73d15 clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) (/usr/local/bin/clangd+0x22f4d15)
 #8 0x00005593fce0cdd4 clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&) (/usr/local/bin/clangd+0x238ddd4)
 #9 0x00005593fce0d6dc clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) (/usr/local/bin/clangd+0x238e6dc)
#10 0x00005593fce0e501 clang::Parser::ParseCompoundStatementBody(bool) (/usr/local/bin/clangd+0x238f501)
#11 0x00005593fce10fda clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/usr/local/bin/clangd+0x2391fda)
#12 0x00005593fcd44fb3 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/usr/local/bin/clangd+0x22c5fb3)
#13 0x00005593fcd71780 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/usr/local/bin/clangd+0x22f2780)
#14 0x00005593fcd408e0 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (.part.0) Parser.cpp:0:0
#15 0x00005593fcd47a48 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/usr/local/bin/clangd+0x22c8a48)
#16 0x00005593fcd48b21 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/usr/local/bin/clangd+0x22c9b21)
#17 0x00005593fcd3a1ea clang::ParseAST(clang::Sema&, bool, bool) (/usr/local/bin/clangd+0x22bb1ea)
#18 0x00005593fcb333f9 clang::FrontendAction::Execute() (/usr/local/bin/clangd+0x20b43f9)
#19 0x00005593fc0f8cae clang::clangd::(anonymous namespace)::semaCodeComplete(std::unique_ptr<clang::CodeCompleteConsumer, std::default_delete<clang::CodeCompleteConsumer> >, clang::CodeCompleteOptions const&, clang::clangd::(anonymous namespace)::SemaCompleteInput const&, clang::clangd::IncludeStructure*) (.isra.0) CodeComplete.cpp:0:0
#20 0x00005593fc102b94 clang::clangd::codeComplete(llvm::StringRef, clang::clangd::Position, clang::clangd::PreambleData const*, clang::clangd::ParseInputs const&, clang::clangd::CodeCompleteOptions, clang::clangd::SpeculativeFuzzyFind*) (/usr/local/bin/clangd+0x1683b94)
#21 0x00005593fc0da731 clang::clangd::ClangdServer::codeComplete(llvm::StringRef, clang::clangd::Position, clang::clangd::CodeCompleteOptions const&, llvm::unique_function<void (llvm::Expected<clang::clangd::CodeCompleteResult>)>)::'lambda'(llvm::Expected<clang::clangd::InputsAndPreamble>)::operator()(llvm::Expected<clang::clangd::InputsAndPreamble>) ClangdServer.cpp:0:0
#22 0x00005593fc0dae84 void llvm::detail::UniqueFunctionBase<void, llvm::Expected<clang::clangd::InputsAndPreamble> >::CallImpl<clang::clangd::ClangdServer::codeComplete(llvm::StringRef, clang::clangd::Position, clang::clangd::CodeCompleteOptions const&, llvm::unique_function<void (llvm::Expected<clang::clangd::CodeCompleteResult>)>)::'lambda'(llvm::Expected<clang::clangd::InputsAndPreamble>)>(void*, llvm::Expected<clang::clangd::InputsAndPreamble>&) ClangdServer.cpp:0:0
#23 0x00005593fc295c74 clang::clangd::TUScheduler::runWithPreamble(llvm::StringRef, llvm::StringRef, clang::clangd::TUScheduler::PreambleConsistency, llvm::unique_function<void (llvm::Expected<clang::clangd::InputsAndPreamble>)>)::'lambda'()::operator()() TUScheduler.cpp:0:0
#24 0x00005593fc4864f6 void* llvm::thread::ThreadProxy<std::tuple<clang::clangd::AsyncTaskRunner::runAsync(llvm::Twine const&, llvm::unique_function<void ()>)::'lambda0'()> >(void*) Threading.cpp:0:0
#25 0x00007f7725a8eb43 start_thread ./nptl/./nptl/pthread_create.c:442:8
#26 0x00007f7725b20a00 ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:83:0
Signalled during preamble action: CodeComplete
  Filename: test.cpp
  Directory: /tmp
  Command Line: /usr/lib/llvm-14/bin/clang -std=c++20 -resource-dir=/home/i-ky/llvm-project/build/lib/clang/16.0.0 -- /tmp/test.cpp
[Error - 4:45:16 PM] The Clang Language Server server crashed 1 times in the last 3 minutes. The server will not be restarted. See the output for more information.
[Error - 4:45:16 PM] Request textDocument/completion failed.
[object Object]

System information

Output of clangd --version:

clangd version 16.0.0 (https://github.com/llvm/llvm-project.git b53bccb18d2a437b04f4259cdcced479c909cbfd)
Features: linux+grpc
Platform: x86_64-unknown-linux-gnu

Editor/LSP plugin:

Operating system: Ubuntu 22.04

i-ky commented 2 years ago

Also in the following code:

enum class Foo {Bar, Baz};

void test() {
  using enum Foo;
  Bar;
}

hovering over Bar; (line 5) gives the following tip: image Note the hex value (pointer address?) instead of enum name.

HighCommander4 commented 2 years ago

Also in the following code [...] hovering over Bar; (line 5) gives the following tip

For tracking purposes, could you please file this as a separate issue?

i-ky commented 2 years ago

For tracking purposes, could you please file this as a separate issue?

Seems you have already done so (#1283). Thanks!

HighCommander4 commented 2 years ago

For tracking purposes, could you please file this as a separate issue?

Seems you have already done so (#1283). Thanks!

No, that one is yet another issue about the color of the Foo token in using enum Foo

i-ky commented 2 years ago

OK, created #1284.

tom-anders commented 1 year ago

The problem seems to be that DS.getTypeSpecType() returns DeclSpec::TST_unspecified which is not handled in the switch.

The following patch fixes the crash and provides the correct completion candidate (Foo), but to me it looks like it only fixes the symptom rather than the underlying issue.

But maybe this is a good starting point for someone with more knowledge in that area. According to git blame, @urnathan wrote most of this code.

diff --git c/clang/lib/Sema/SemaDeclCXX.cpp i/clang/lib/Sema/SemaDeclCXX.cpp
index bad298c8c8..94c57ae74a 100644
--- c/clang/lib/Sema/SemaDeclCXX.cpp
+++ i/clang/lib/Sema/SemaDeclCXX.cpp
@@ -11855,6 +11855,9 @@ Decl *Sema::ActOnUsingEnumDeclaration(Scope *S, AccessSpecifier AS,
   case DeclSpec::TST_enum:
     break;

+  case DeclSpec::TST_unspecified:
+    return nullptr;
+
   case DeclSpec::TST_typename:
     Diag(DS.getTypeSpecTypeLoc(), diag::err_using_enum_is_dependent);
     return nullptr;
--------------------------------------------------
sam-mccall commented 1 year ago

That patch is tempting, it's not obvious what the right pattern is.

Sent https://reviews.llvm.org/D134243, which is a maybe-slightly-clearer way to get the same thing.

urnathan commented 1 year ago

On 9/19/22 07:00, Tom Praschan wrote:

The problem seems to be that |DS.getTypeSpecType()| returns |DeclSpec::TST_unspecified| which is not handled in the |switch|.

The following patch fixes the crash and provides the correct completion candidate (|Foo|), but to me it looks like it only fixes the symptom rather than the underlying issue.

this may well be mooted by fixing #57659, which I'm working on

nathan

-- Nathan Sidwell