Skip to content

[clang-repl] fix segfault in CleanUpPTU() #75629

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions clang/lib/Interpreter/IncrementalParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,13 @@ std::unique_ptr<llvm::Module> IncrementalParser::GenModule() {

void IncrementalParser::CleanUpPTU(PartialTranslationUnit &PTU) {
TranslationUnitDecl *MostRecentTU = PTU.TUPart;
if (!MostRecentTU)
return;

TranslationUnitDecl *FirstTU = MostRecentTU->getFirstDecl();
if (!FirstTU)
return;

if (StoredDeclsMap *Map = FirstTU->getPrimaryContext()->getLookupPtr()) {
for (auto I = Map->begin(); I != Map->end(); ++I) {
StoredDeclsList &List = I->second;
Expand Down
10 changes: 10 additions & 0 deletions clang/test/Interpreter/anonymous-scope-fail.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// RUN: clang-repl "int x = 10;" "{ int t; a::b(t); }" "int y = 10;"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this in the code-undo.cpp test?

Copy link
Author

@p4vook p4vook Dec 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite understand, the code-undo.cpp doesn't seem to have anything that produces an error, but this test does.
If we define a::b(t), clang-repl stops segfaulting here.
Is it okay to put tests with errors into code-undo.cpp?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then we can put it in a new file called error-recovery.cpp.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@p4vook ping.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, we can, I'll try to do it this evening. I couldn't figure out why this test failed though, I probably need to fix it somehow.

// REQUIRES: host-supports-jit
// UNSUPPORTED: system-aix
// RUN: cat %s | not clang-repl | FileCheck %s
{ int t; a::b(t); }
extern "C" int printf(const char *, ...);
int i = 42;
auto r1 = printf("i = %d\n", i);
// CHECK: i = 42
%quit