Skip to content

clang-repl: SIGSEGV in libclang #72980

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

Open
p4vook opened this issue Nov 21, 2023 · 6 comments · May be fixed by #75629
Open

clang-repl: SIGSEGV in libclang #72980

p4vook opened this issue Nov 21, 2023 · 6 comments · May be fixed by #75629

Comments

@p4vook
Copy link

p4vook commented Nov 21, 2023

Minimal example

echo "{ int x; a::b(x); }" | clang-repl

Expected result

Error is shown, but the evaluation continues

Actual result

Error is shown, clang-repl gets terminated by SIGSEGV.

Stack trace

LLVM 17.0.4

  * frame #0: 0x00007ffff5188a90 libclang-cpp.so.17`clang::Decl::getTranslationUnitDecl()
    frame #1: 0x00007ffff7b72f60 libclang-cpp.so.17`clang::IncrementalParser::CleanUpPTU(clang::PartialTranslationUnit&) + 192
    frame #2: 0x00007ffff7b74308 libclang-cpp.so.17`clang::IncrementalParser::ParseOrWrapTopLevelDecl() + 2264
    frame #3: 0x00007ffff7b74f4d libclang-cpp.so.17`clang::IncrementalParser::Parse(llvm::StringRef) + 1165
    frame #4: 0x00007ffff7b782b8 libclang-cpp.so.17`clang::Interpreter::ParseAndExecute(llvm::StringRef, clang::Value*) + 184
    frame #5: 0x00005555555614be clang-repl`main + 3534
    frame #6: 0x00007fffeaa5078a libc.so.6`___lldb_unnamed_symbol3154 + 122
    frame #7: 0x00007fffeaa50845 libc.so.6`__libc_start_main + 133
    frame #8: 0x000055555555c3b1 clang-repl`_start + 33

Also tested with current master (commit 0d77978), same result.

UPD: worth mentioning that clang++ itself processes this file correctly, without segfaults.

@p4vook
Copy link
Author

p4vook commented Nov 27, 2023

I was able to get debug info:
clang-repl: /var/tmp/portage/sys-devel/clang-18.0.0_pre20231119/work/clang/include/clang/AST/DeclBase.h:1336: clang::NamedDecl* clang::DeclListNode::iterator::operator*() const: Assertion Ptr && "dereferencing end() iterator"' failed.

@p4vook
Copy link
Author

p4vook commented Nov 28, 2023

@EugeneZelenko are you sure clang-repl is clang-tools-extra? The repository layout suggests it's just a part of clang itself. Sorry for tag.

@EugeneZelenko
Copy link
Contributor

@p4vook: Is it separate binary? If so, it's not exactly clang. If there are many issues related to it, it'll make sense to create dedicated label.

@vgvassilev
Copy link
Contributor

@p4vook, can you move the fix of this issue out of the bigger pull request and add a regression test for it?

p4vook added a commit to p4vook/llvm-project that referenced this issue Dec 15, 2023
Check if the last translation unit or its first declaration
are actually empty and do not nead cleanup.

Previously this caused segmentation fault on empty PTUs.

Add a regression test.

Fixes: llvm#72980
Signed-off-by: Pavel Kalugin <[email protected]>
@p4vook p4vook linked a pull request Dec 15, 2023 that will close this issue
@p4vook
Copy link
Author

p4vook commented Dec 15, 2023

Done

@p4vook, can you move the fix of this issue out of the bigger pull request and add a regression test for it?

@p4vook
Copy link
Author

p4vook commented Jan 27, 2024

I believe this is a deeper issue, it shouldn't be fixed up just by a simple check for nullptr, this seems to be an issue of inserting statements into wrong nodes of syntax tree if namespaces are present. I'll convert the PR to draft.

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

Successfully merging a pull request may close this issue.

3 participants