[clang] [clang-repl] Expose markUserCodeStart() in extended Interpreter interface (PR #87064)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 29 06:11:02 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Stefan Gränitz (weliveindetail)
<details>
<summary>Changes</summary>
Adding code for built-in functionality during initialization is very common. Call this function afterwards to hide it from Undo. Any serious interpreter needs it.
---
Full diff: https://github.com/llvm/llvm-project/pull/87064.diff
2 Files Affected:
- (modified) clang/include/clang/Interpreter/Interpreter.h (+5-2)
- (modified) clang/unittests/Interpreter/InterpreterExtensionsTest.cpp (+18-4)
``````````diff
diff --git a/clang/include/clang/Interpreter/Interpreter.h b/clang/include/clang/Interpreter/Interpreter.h
index 970e0245417b51..b21a95009918dc 100644
--- a/clang/include/clang/Interpreter/Interpreter.h
+++ b/clang/include/clang/Interpreter/Interpreter.h
@@ -44,7 +44,7 @@ class IncrementalParser;
/// Create a pre-configured \c CompilerInstance for incremental processing.
class IncrementalCompilerBuilder {
public:
- IncrementalCompilerBuilder() {}
+ IncrementalCompilerBuilder() = default;
void SetCompilerArgs(const std::vector<const char *> &Args) {
UserArgs = Args;
@@ -122,6 +122,10 @@ class Interpreter {
// JIT engine. In particular, it doesn't run cleanup or destructors.
void ResetExecutor();
+ // Adding code for built-in functionality during initialization is very
+ // common. Call this function afterwards to hide it from Undo.
+ void markUserCodeStart();
+
// Lazily construct the RuntimeInterfaceBuilder. The provided instance will be
// used for the entire lifetime of the interpreter. The default implementation
// targets the in-process __clang_Interpreter runtime. Override this to use a
@@ -184,7 +188,6 @@ class Interpreter {
private:
size_t getEffectivePTUSize() const;
- void markUserCodeStart();
llvm::DenseMap<CXXRecordDecl *, llvm::orc::ExecutorAddr> Dtors;
diff --git a/clang/unittests/Interpreter/InterpreterExtensionsTest.cpp b/clang/unittests/Interpreter/InterpreterExtensionsTest.cpp
index 1ba865a79ed778..bb39946a31a1d3 100644
--- a/clang/unittests/Interpreter/InterpreterExtensionsTest.cpp
+++ b/clang/unittests/Interpreter/InterpreterExtensionsTest.cpp
@@ -66,10 +66,9 @@ struct LLVMInitRAII {
~LLVMInitRAII() { llvm::llvm_shutdown(); }
} LLVMInit;
-class TestCreateResetExecutor : public Interpreter {
+class TestInterpreter : public Interpreter {
public:
- TestCreateResetExecutor(std::unique_ptr<CompilerInstance> CI,
- llvm::Error &Err)
+ TestInterpreter(std::unique_ptr<CompilerInstance> CI, llvm::Error &Err)
: Interpreter(std::move(CI), Err) {}
llvm::Error testCreateJITBuilderError() {
@@ -83,6 +82,7 @@ class TestCreateResetExecutor : public Interpreter {
}
void resetExecutor() { Interpreter::ResetExecutor(); }
+ void markUserCodeStart() { Interpreter::markUserCodeStart(); }
private:
llvm::Expected<std::unique_ptr<llvm::orc::LLJITBuilder>>
@@ -95,6 +95,20 @@ class TestCreateResetExecutor : public Interpreter {
std::unique_ptr<llvm::orc::LLJITBuilder> JB;
};
+TEST(InterpreterExtensionsTest, MarkUserCodeStart) {
+ clang::IncrementalCompilerBuilder CB;
+ llvm::Error ErrOut = llvm::Error::success();
+ TestInterpreter Interp(cantFail(CB.CreateCpp()), ErrOut);
+ cantFail(std::move(ErrOut));
+ llvm::Error Parse = Interp.Parse("int builtin = 42;").takeError();
+ EXPECT_THAT_ERROR(std::move(Parse), llvm::Succeeded());
+ // Hide above PTU from Undo
+ Interp.markUserCodeStart();
+ llvm::Error Undo = Interp.Undo(1);
+ EXPECT_THAT_ERROR(std::move(Undo), llvm::FailedWithMessage(
+ "Operation failed. Too many undos"));
+}
+
#ifdef CLANG_INTERPRETER_PLATFORM_CANNOT_CREATE_LLJIT
TEST(InterpreterExtensionsTest, DISABLED_ExecutorCreateReset) {
#else
@@ -106,7 +120,7 @@ TEST(InterpreterExtensionsTest, ExecutorCreateReset) {
clang::IncrementalCompilerBuilder CB;
llvm::Error ErrOut = llvm::Error::success();
- TestCreateResetExecutor Interp(cantFail(CB.CreateCpp()), ErrOut);
+ TestInterpreter Interp(cantFail(CB.CreateCpp()), ErrOut);
cantFail(std::move(ErrOut));
EXPECT_THAT_ERROR(Interp.testCreateJITBuilderError(),
llvm::FailedWithMessage("TestError"));
``````````
</details>
https://github.com/llvm/llvm-project/pull/87064
More information about the cfe-commits
mailing list