https://github.com/p4vook updated https://github.com/llvm/llvm-project/pull/75629
>From 2c4ab0990b55be21ca820d84eebb46b1814bb0aa Mon Sep 17 00:00:00 2001 From: Pavel Kalugin <pa...@pavelthebest.me> Date: Fri, 15 Dec 2023 15:05:45 +0300 Subject: [PATCH 1/3] [clang-repl] fix segfault in CleanUpPTU() 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 Signed-off-by: Pavel Kalugin <pa...@pavelthebest.me> --- clang/lib/Interpreter/IncrementalParser.cpp | 8 ++++++++ clang/test/Interpreter/anonymous-scope-fail.cpp | 10 ++++++++++ 2 files changed, 18 insertions(+) create mode 100644 clang/test/Interpreter/anonymous-scope-fail.cpp 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 >From a6f43640ccfc76f40545a4d083140f39eccd879e Mon Sep 17 00:00:00 2001 From: Pavel Kalugin <pa...@pavelthebest.me> Date: Fri, 15 Dec 2023 20:13:19 +0300 Subject: [PATCH 2/3] Update clang/lib/Interpreter/IncrementalParser.cpp Co-authored-by: Vassil Vassilev <v.g.vassi...@gmail.com> --- clang/lib/Interpreter/IncrementalParser.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/clang/lib/Interpreter/IncrementalParser.cpp b/clang/lib/Interpreter/IncrementalParser.cpp index f894af881134bb..e8c30fbb7aa64b 100644 --- a/clang/lib/Interpreter/IncrementalParser.cpp +++ b/clang/lib/Interpreter/IncrementalParser.cpp @@ -373,9 +373,8 @@ std::unique_ptr<llvm::Module> IncrementalParser::GenModule() { void IncrementalParser::CleanUpPTU(PartialTranslationUnit &PTU) { TranslationUnitDecl *MostRecentTU = PTU.TUPart; - if (!MostRecentTU) { + if (!MostRecentTU) return; - } TranslationUnitDecl *FirstTU = MostRecentTU->getFirstDecl(); if (!FirstTU) { >From acad01c98e7329df3154fe5b16536406639c719f Mon Sep 17 00:00:00 2001 From: Pavel Kalugin <pa...@pavelthebest.me> Date: Fri, 15 Dec 2023 20:13:26 +0300 Subject: [PATCH 3/3] Update clang/lib/Interpreter/IncrementalParser.cpp Co-authored-by: Vassil Vassilev <v.g.vassi...@gmail.com> --- clang/lib/Interpreter/IncrementalParser.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/clang/lib/Interpreter/IncrementalParser.cpp b/clang/lib/Interpreter/IncrementalParser.cpp index e8c30fbb7aa64b..29f66333b61882 100644 --- a/clang/lib/Interpreter/IncrementalParser.cpp +++ b/clang/lib/Interpreter/IncrementalParser.cpp @@ -377,9 +377,8 @@ void IncrementalParser::CleanUpPTU(PartialTranslationUnit &PTU) { return; TranslationUnitDecl *FirstTU = MostRecentTU->getFirstDecl(); - if (!FirstTU) { + if (!FirstTU) return; - } if (StoredDeclsMap *Map = FirstTU->getPrimaryContext()->getLookupPtr()) { for (auto I = Map->begin(); I != Map->end(); ++I) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits