-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[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
base: main
Are you sure you want to change the base?
Conversation
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]>
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write If you have received no comments on your PR for a week, you can request a review If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-clang Author: Pavel Kalugin (p4vook) ChangesCheck 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: #72980 Full diff: https://github.com/llvm/llvm-project/pull/75629.diff 2 Files Affected:
diff --git a/clang/lib/Interpreter/IncrementalParser.cpp b/clang/lib/Interpreter/IncrementalParser.cpp
index 370bcbfee8b014..f894af881134bb 100644
--- a/clang/lib/Interpreter/IncrementalParser.cpp
+++ b/clang/lib/Interpreter/IncrementalParser.cpp
@@ -373,7 +373,15 @@ 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;
diff --git a/clang/test/Interpreter/anonymous-scope-fail.cpp b/clang/test/Interpreter/anonymous-scope-fail.cpp
new file mode 100644
index 00000000000000..c32b42d2859d97
--- /dev/null
+++ b/clang/test/Interpreter/anonymous-scope-fail.cpp
@@ -0,0 +1,10 @@
+// RUN: clang-repl "int x = 10;" "{ int t; a::b(t); }" "int y = 10;"
+// 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
|
@@ -0,0 +1,10 @@ | |||
// RUN: clang-repl "int x = 10;" "{ int t; a::b(t); }" "int y = 10;" |
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.
Can you move this in the code-undo.cpp
test?
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.
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
?
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.
Then we can put it in a new file called error-recovery.cpp
.
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.
@p4vook ping.
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.
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.
Co-authored-by: Vassil Vassilev <[email protected]>
Co-authored-by: Vassil Vassilev <[email protected]>
I converted the PR to draft, as this seems to be a part of a bigger problem with inserting statements into wrong nodes of the syntax tree (this seems to only show up when namespaces are present). I believe it shouldn't be fixed just by a simple check for |
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: #72980