-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang-repl] Fix error recovery while PTU cleanup #127467
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
Conversation
Should be fixed now
|
@llvm/pr-subscribers-clang Author: Anutosh Bhat (anutosh491) ChangesFixes #123300 What is seen
Though the error is justified, we shouldn't be interested in exiting through a segfault in such cases. The issue is that empty named decls weren't being taken care of resulting into this assert
Can also be seen when the example is attempted through xeus-cpp-lite. Full diff: https://github.com/llvm/llvm-project/pull/127467.diff 2 Files Affected:
diff --git a/clang/lib/Interpreter/IncrementalParser.cpp b/clang/lib/Interpreter/IncrementalParser.cpp
index e43cea1baf43a..1ebef0e434b3d 100644
--- a/clang/lib/Interpreter/IncrementalParser.cpp
+++ b/clang/lib/Interpreter/IncrementalParser.cpp
@@ -178,8 +178,8 @@ void IncrementalParser::CleanUpPTU(TranslationUnitDecl *MostRecentTU) {
if (!ND)
continue;
// Check if we need to clean up the IdResolver chain.
- if (ND->getDeclName().getFETokenInfo() && !D->getLangOpts().ObjC &&
- !D->getLangOpts().CPlusPlus)
+ if (!ND->getDeclName().isEmpty() && ND->getDeclName().getFETokenInfo() &&
+ !D->getLangOpts().ObjC && !D->getLangOpts().CPlusPlus)
S.IdResolver.RemoveDecl(ND);
}
}
diff --git a/clang/unittests/Interpreter/InterpreterTest.cpp b/clang/unittests/Interpreter/InterpreterTest.cpp
index 578f1d4c0eac6..56ab155ebf5a4 100644
--- a/clang/unittests/Interpreter/InterpreterTest.cpp
+++ b/clang/unittests/Interpreter/InterpreterTest.cpp
@@ -114,6 +114,13 @@ TEST_F(InterpreterTest, Errors) {
RecoverErr = Interp->Parse("var1 = 424;");
EXPECT_TRUE(!!RecoverErr);
+
+ Err = Interp->Parse("int x = 5; auto capture = [&]() { return x * 2; };").takeError();
+ EXPECT_THAT(DiagnosticOutput, HasSubstr("error: non-local lambda expression cannot have a capture-default"));
+ EXPECT_EQ("Parsing failed.", llvm::toString(std::move(Err)));
+
+ RecoverErr = Interp->Parse("int validVar = 10;");
+ EXPECT_TRUE(!!RecoverErr);
}
// Here we test whether the user can mix declarations and statements. The
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
Hmmm, the code formatter has a suggestion. Just increases the lines on a simple test. Not sure if the code formatter should be respected here ! |
Thanks! fyi also @hahnjo |
For anyone interested in seeing the error at realtime, I am just leaving the static link for xeus-cpp-lite here. https://compiler-research.org/xeus-cpp/lab/index.html Possibly trying something like
Should display the assertion error in the console. |
cc @vgvassilev |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Thanks for the review. The test lamda.cpp passes (https://github.com/llvm/llvm-project/actions/runs/13810830928/job/38631851756?pr=127467#step:4:20415) and I think this should be ready now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thank you.
/cherry-pick 3b4c51b |
/pull-request #142445 |
Fixes llvm#123300 What is seen ``` clang-repl> int x = 42; clang-repl> auto capture = [&]() { return x * 2; }; In file included from <<< inputs >>>:1: input_line_4:1:17: error: non-local lambda expression cannot have a capture-default 1 | auto capture = [&]() { return x * 2; }; | ^ zsh: segmentation fault clang-repl --Xcc="-v" (lldb) bt * thread llvm#1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x8) * frame #0: 0x0000000107b4f8b8 libclang-cpp.19.1.dylib`clang::IncrementalParser::CleanUpPTU(clang::PartialTranslationUnit&) + 988 frame llvm#1: 0x0000000107b4f1b4 libclang-cpp.19.1.dylib`clang::IncrementalParser::ParseOrWrapTopLevelDecl() + 416 frame llvm#2: 0x0000000107b4fb94 libclang-cpp.19.1.dylib`clang::IncrementalParser::Parse(llvm::StringRef) + 612 frame llvm#3: 0x0000000107b52fec libclang-cpp.19.1.dylib`clang::Interpreter::ParseAndExecute(llvm::StringRef, clang::Value*) + 180 frame llvm#4: 0x0000000100003498 clang-repl`main + 3560 frame llvm#5: 0x000000018d39a0e0 dyld`start + 2360 ``` Though the error is justified, we shouldn't be interested in exiting through a segfault in such cases. The issue is that empty named decls weren't being taken care of resulting into this assert https://github.com/llvm/llvm-project/blob/c1a229252617ed58f943bf3f4698bd8204ee0f04/clang/include/clang/AST/DeclarationName.h#L503 Can also be seen when the example is attempted through xeus-cpp-lite. 
After this change the test labda.cpp is failing on Linaro's Windows on Arm clang bots. They were stuck for other reasons and only just got back up to date, so here's a new build showing the failure:
I've confirmed locally that the test passed before this change. The first RUN line is ok:
The second one fails to parse the lambda:
(also the repeated How can I debug this further, is there a way to enable some verbose parsing / verification? (seems more likely that verification is actually the failing part) |
Also failing on Windows x64, but this time the error is better: And now I see the actual problem, all I had to do was scroll up :)
Puzzling that we don't see this on other platforms though. But this is the error message you are expecting. So it is doing what you expect but the test isn't finding the output. |
Hi, On phone right now so shall have a better look at the error in sometime but just for some clarification, the parsing error is expected (we had a seg fault on master for this whereas a parsing error is expected and that's what the Pr is trying to achieve) Edit: We weren't notified by any failures by the bot or the CI so it's the first time I'm seeing this. Thanks for the report. |
Thanks for confirming, yes, your patch is working as expected but something about Windows' output is tripping up FileCheck I think. Linux does not print the
Which should not be a problem in theory. I'll figure it out. |
I've disabled the failing Let me know if anything stands out to you. Also would be useful if I can see the code produced at the different optimisation levels. |
llvm/llvm-project#143547 for details. For some reason the order of the printf output is not as expected when piped. None of the "fixes" I have are good, so only run this RUN on non-Windows. Test added by llvm/llvm-project#127467.
llvm#143547 for details. For some reason the order of the printf output is not as expected when piped. None of the "fixes" I have are good, so only run this RUN on non-Windows. Test added by llvm#127467.
Fixes llvm#123300 What is seen ``` clang-repl> int x = 42; clang-repl> auto capture = [&]() { return x * 2; }; In file included from <<< inputs >>>:1: input_line_4:1:17: error: non-local lambda expression cannot have a capture-default 1 | auto capture = [&]() { return x * 2; }; | ^ zsh: segmentation fault clang-repl --Xcc="-v" (lldb) bt * thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x8) * frame #0: 0x0000000107b4f8b8 libclang-cpp.19.1.dylib`clang::IncrementalParser::CleanUpPTU(clang::PartialTranslationUnit&) + 988 frame #1: 0x0000000107b4f1b4 libclang-cpp.19.1.dylib`clang::IncrementalParser::ParseOrWrapTopLevelDecl() + 416 frame #2: 0x0000000107b4fb94 libclang-cpp.19.1.dylib`clang::IncrementalParser::Parse(llvm::StringRef) + 612 frame #3: 0x0000000107b52fec libclang-cpp.19.1.dylib`clang::Interpreter::ParseAndExecute(llvm::StringRef, clang::Value*) + 180 frame #4: 0x0000000100003498 clang-repl`main + 3560 frame #5: 0x000000018d39a0e0 dyld`start + 2360 ``` Though the error is justified, we shouldn't be interested in exiting through a segfault in such cases. The issue is that empty named decls weren't being taken care of resulting into this assert https://github.com/llvm/llvm-project/blob/c1a229252617ed58f943bf3f4698bd8204ee0f04/clang/include/clang/AST/DeclarationName.h#L503 Can also be seen when the example is attempted through xeus-cpp-lite. 
This cherry-picks 3b4c51b and beffd15 to 20.x. Which are: [clang-repl] Fix error recovery while PTU cleanup (llvm#127467) [clang][Interpreter] Disable part of lambda test on Windows The latter commit avoids a test failure seen in Windows builds. On main, I turned off one of the RUN lines for Windows, but reviewers on the cherry-pick preferred UNSUPPORTED to disable the whole test. So I have used UNSUPPORTED in this version for 20.x.
This cherry-picks 3b4c51b and beffd15 to 20.x. Which are: [clang-repl] Fix error recovery while PTU cleanup (llvm#127467) [clang][Interpreter] Disable part of lambda test on Windows The latter commit avoids a test failure seen in Windows builds. On main, I turned off one of the RUN lines for Windows, but reviewers on the cherry-pick preferred UNSUPPORTED to disable the whole test. So I have used UNSUPPORTED in this version for 20.x.
llvm#143547 for details. For some reason the order of the printf output is not as expected when piped. None of the "fixes" I have are good, so only run this RUN on non-Windows. Test added by llvm#127467.
Fixes #123300
What is seen
Though the error is justified, we shouldn't be interested in exiting through a segfault in such cases.
The issue is that empty named decls weren't being taken care of resulting into this assert
llvm-project/clang/include/clang/AST/DeclarationName.h
Line 503 in c1a2292
Can also be seen when the example is attempted through xeus-cpp-lite.