Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation fault on pointer deference #576

Open
jstaursky opened this issue Feb 17, 2020 · 3 comments
Open

Segmentation fault on pointer deference #576

jstaursky opened this issue Feb 17, 2020 · 3 comments
Labels
clang clang bugs/enhancement

Comments

@jstaursky
Copy link


Observed behavior

Work on a fresh new .c file when trying to deference a pointer ccls crashed.

  • Did not create a compile_commands.json, just set ccls to accept my folder as project root and started coding.
    (Detailed info in reproduce section).

Expected behavior

ccls to either give me error information or otherwise auto-complete suggestions.

Steps to reproduce

  1. Follow the build steps ccls/wiki/Build
  • (cloned commit 41e7d6a this morning, but error also occurs in 4711fd3)
  • Downloaded the latest llvm (9.0.1) this morning (but the problem was also occurring when I was using 9.0.0)
  1. Open spacemacs (I use the develop branch w/ commit 30250403a but problem also occurs in f4f95d28f) along with C/C -layer
  2. open the following c file
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct Node {
    void* data;
    struct Node* left;          // lesser
    struct Node* right;         // greater
} Node, *Tree;

int main (int argc, char *argv[])
{
    Tree insert (char*, Tree);

    return 0;
}

Tree insert (char* word, Tree tree)
{
    Tree *tree_p = &tree;
    int compare;

    while (*tree_p)
    {
        compare = strcmp (word, (char*)(*tree_p)->);
        if (compare > 0)
        {
            tree_p = &(*tree_p)->right;
        }

    }
}

ccls-issue

This error (see screenshot bubble) also occurred in the previous version of ccls I was using which I had been using 4711fd3 for a long time without issue.

my *Messages* log shows (its short b/c I was reproducing not b/c any incorrect setup)

LSP :: Connected to [ccls:11761 status:starting].
dap-gdb-lldb: webfreak.debug debug extension are not set. You can download it with M-x dap-gdb-lldb-setup
LSP :: ccls:11761 initialized successfully
ccls: expected expression [4]
LSP :: ccls has exited (segmentation fault (core dumped))
Server ccls:11761 exited with status signal. Do you want to restart it? (y or n) n

System information

  • ccls version (git describe --tags --long): returns fatal: No names found, cannot describe anything. Hope this screenshot of the git log helps.
    image

  • clang version: 9.0.1
    Target: x86_64-unknown-linux-gnu
    Thread model: posix

  • OS: Ubuntu 18.04.3 LTS

  • Editor: emacs 27.0.60 and 28.0.50 (I sync through dropbox my .spacemacs.d and ccls)

  • Language client (and version):
    emacs-ccls inside spacemacs it says ccls-20200204.444 idk if thats enough info to act on but I can tell you I did a fresh install just the other day (might have 1-2 days ago)

  • the problem also occurs in the previous version installed which says ccls-20191219.913
  • this package is configured by spacemacs in the c-c layer

The ccls initializationOptions is initializationOptions: {"compilationDatabaseCommand":"","compilationDatabaseDirectory":"","cache":{"directory":".ccls-cache","format":"binary","hierarchicalPath":false,"retainInMemory":2},"capabilities":{"documentOnTypeFormattingProvider":{"firstTriggerCharacter":"}","moreTriggerCharacter":[]},"foldingRangeProvider":true,"workspace":{"workspaceFolders":{"supported":true,"changeNotifications":true}}},"clang":{"excludeArgs":[],"extraArgs":[],"pathMappings":[],"resourceDir":""},"client":{"diagnosticsRelatedInformation":true,"hierarchicalDocumentSymbolSupport":true,"linkSupport":true,"snippetSupport":true},"codeLens":{"localVariables":true},"completion":{"caseSensitivity":2,"detailedLabel":true,"dropOldRequests":true,"duplicateOptional":true,"filterAndSort":true,"include":{"blacklist":[],"maxPathSize":30,"suffixWhitelist":[".h",".hpp",".hh",".inc"],"whitelist":[]},"maxNum":100,"placeholder":true},"diagnostics":{"blacklist":[],"onChange":1000,"onOpen":0,"onSave":0,"spellChecking":true,"whitelist":[]},"highlight":{"largeFileSize":2097152,"lsRanges":false,"blacklist":[],"whitelist":[]},"index":{"blacklist":[],"comments":2,"initialNoLinkage":false,"initialBlacklist":[],"initialWhitelist":[],"maxInitializerLines":5,"multiVersion":0,"multiVersionBlacklist":[],"multiVersionWhitelist":[],"name":{"suppressUnwrittenScope":false},"onChange":false,"parametersInDeclarations":true,"threads":0,"trackDependency":2,"whitelist":[]},"request":{"timeout":5000},"session":{"maxNum":10},"workspaceSymbol":{"caseSensitivity":1,"maxNum":1000,"sort":true},"xref":{"maxNum":2000}}

@joelhock
Copy link

i can repro with the provided testcase, too.

$ /usr/local/hrt-localcoding/bin/ccls --version
ccls version 0.20190823.4-7-gf35e93d5
clang version 9.0.0 (https://github.com/llvm/llvm-project.git 0399d5a9682b3cef71c653373e38890c63c4c365)

backtrace:

#1  0x0000556372fa904f in clang::Sema::CodeCompleteMemberReferenceExpr(clang::Scope*, clang::Expr*, clang::Expr*, clang::SourceLocation, bool, bool, clang::QualType) ()
#2  0x0000556372d598f8 in clang::Parser::ParsePostfixExpressionSuffix(clang::ActionResult<clang::Expr*, true>) ()
#3  0x0000556372d53502 in clang::Parser::ParseCastExpression(bool, bool, bool&, clang::Parser::TypeCastState, bool) ()
#4  0x0000556372d55db4 in clang::Parser::ParseCastExpression(bool, bool, clang::Parser::TypeCastState, bool) ()
#5  0x0000556372d5b5a7 in clang::Parser::ParseParenExpression(clang::Parser::ParenParseOption&, bool, bool, clang::OpaquePtr<clang::QualType>&, clang::SourceLocation&) ()
#6  0x0000556372d536d5 in clang::Parser::ParseCastExpression(bool, bool, bool&, clang::Parser::TypeCastState, bool) ()
#7  0x0000556372d55db4 in clang::Parser::ParseCastExpression(bool, bool, clang::Parser::TypeCastState, bool) ()
#8  0x0000556372d55e3c in clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState) ()
#9  0x0000556372d58081 in clang::Parser::ParseExpressionList(llvm::SmallVectorImpl<clang::Expr*>&, llvm::SmallVectorImpl<clang::SourceLocation>&, llvm::function_ref<void ()>) ()
#10 0x0000556372d5935c in clang::Parser::ParsePostfixExpressionSuffix(clang::ActionResult<clang::Expr*, true>) ()
#11 0x0000556372d53502 in clang::Parser::ParseCastExpression(bool, bool, bool&, clang::Parser::TypeCastState, bool) ()
#12 0x0000556372d55db4 in clang::Parser::ParseCastExpression(bool, bool, clang::Parser::TypeCastState, bool) ()
#13 0x0000556372d56479 in clang::Parser::ParseRHSOfBinaryExpression(clang::ActionResult<clang::Expr*, true>, clang::prec::Level) ()
#14 0x0000556372d55e4c in clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState) ()
#15 0x0000556372d55ef9 in clang::Parser::ParseExpression(clang::Parser::TypeCastState) ()
#16 0x0000556372da2012 in clang::Parser::ParseExprStatement(clang::Parser::ParsedStmtContext) ()
#17 0x0000556372da0c72 in clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::Parser::ParsedAttributesWithRange&) ()
#18 0x0000556372da1036 in clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) ()
#19 0x0000556372d9cf19 in clang::Parser::ParseCompoundStatementBody(bool) ()
#20 0x0000556372d9d78e in clang::Parser::ParseCompoundStatement(bool, unsigned int) ()
#21 0x0000556372d9d7c2 in clang::Parser::ParseCompoundStatement(bool) ()
#22 0x0000556372da0a22 in clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::Parser::ParsedAttributesWithRange&) ()
#23 0x0000556372da1036 in clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) ()
#24 0x0000556372da1257 in clang::Parser::ParseStatement(clang::SourceLocation*, clang::Parser::ParsedStmtContext) ()
#25 0x0000556372da38b0 in clang::Parser::ParseWhileStatement(clang::SourceLocation*) ()
#26 0x0000556372da0843 in clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::Parser::ParsedAttributesWithRange&) ()
#27 0x0000556372da1036 in clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) ()
#28 0x0000556372d9cf19 in clang::Parser::ParseCompoundStatementBody(bool) ()
#29 0x0000556372da76ae in clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) ()
#30 0x0000556372d14251 in clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) ()
#31 0x0000556372d3415b in clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::SourceLocation*, clang::Parser::ForRangeInit*) ()
#32 0x0000556372d0de97 in clang::Parser::ParseDeclOrFunctionDefInternal(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec&, clang::AccessSpecifier) ()
#33 0x0000556372d0e6f9 in clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*, clang::AccessSpecifier) [clone .part.214] ()
#34 0x0000556372d0e72f in clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*, clang::AccessSpecifier) ()
#35 0x0000556372d157d0 in clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) ()
#36 0x0000556372d165d0 in clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, bool) ()
#37 0x0000556372d09ee5 in clang::ParseAST(clang::Sema&, bool, bool) ()
#38 0x0000556372c820b1 in clang::FrontendAction::Execute() ()
#39 0x0000556372a9bd2f in ccls::(anonymous namespace)::parse (clang=...) at /usr/scratch/joel/ccls/src/sema_manager.cc:332
#40 0x0000556372a9d466 in ccls::(anonymous namespace)::completionMain (manager_=0x7fffd52c5aa0) at /usr/scratch/joel/ccls/src/sema_manager.cc:493
#41 0x00007f4b4d4644a4 in start_thread (arg=0x7f4b35ffe700) at pthread_create.c:456
#42 0x00007f4b4ccc9eef in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:97```

@MaskRay MaskRay added the clang clang bugs/enhancement label Jul 5, 2020
@MaskRay
Copy link
Owner

MaskRay commented Jul 5, 2020

Cannot reproduce with clang llvm-9.0.0-x86_64-linux-gnu-ubuntu-16.04/ (https://releases.llvm.org/download.html#9.0.0) or HEAD..

@jstaursky
Copy link
Author

I am using rtags now but I just tested this again using the snap version found here (using latest/edge release) and had the same issue. Every time I have tested has been using ubuntu 18.04.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang clang bugs/enhancement
Projects
None yet
Development

No branches or pull requests

3 participants