aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/Interpreter/InterpreterTest.cpp
diff options
context:
space:
mode:
authorVassil Vassilev <v.g.vassilev@gmail.com>2024-01-21 03:00:38 +0200
committerGitHub <noreply@github.com>2024-01-20 17:00:38 -0800
commit2759e47067ea286f6302adcfe93b653cfaf6f2eb (patch)
tree47c3b71d578e0299bd09aee75397a1b550480f62 /clang/unittests/Interpreter/InterpreterTest.cpp
parentdedc7d4d362b8045c6810f8ca7f947bbdb63b7ec (diff)
downloadllvm-2759e47067ea286f6302adcfe93b653cfaf6f2eb.zip
llvm-2759e47067ea286f6302adcfe93b653cfaf6f2eb.tar.gz
llvm-2759e47067ea286f6302adcfe93b653cfaf6f2eb.tar.bz2
[clang-repl] We do not need to call new in the object allocation. (#78843)
This test demonstrates template instantiation via the interpreter code. In order to do that we can allocate the object on the stack and extend its lifetime by boxing it into a clang::Value. That avoids the subtle problem where we call the new operator on an object only known to the interpreter and we cannot destroy it from compiled code since there is not suitable facility in clang::Value yet. That should resolve the asan issues that was reported in llvm/llvm-project#76218.
Diffstat (limited to 'clang/unittests/Interpreter/InterpreterTest.cpp')
-rw-r--r--clang/unittests/Interpreter/InterpreterTest.cpp15
1 files changed, 6 insertions, 9 deletions
diff --git a/clang/unittests/Interpreter/InterpreterTest.cpp b/clang/unittests/Interpreter/InterpreterTest.cpp
index d6eb068..e76c067 100644
--- a/clang/unittests/Interpreter/InterpreterTest.cpp
+++ b/clang/unittests/Interpreter/InterpreterTest.cpp
@@ -34,12 +34,6 @@ using namespace clang;
#define CLANG_INTERPRETER_NO_SUPPORT_EXEC
#endif
-#if LLVM_ADDRESS_SANITIZER_BUILD || LLVM_HWADDRESS_SANITIZER_BUILD
-#include <sanitizer/lsan_interface.h>
-#else
-extern "C" void __lsan_ignore_object(const void *p) {}
-#endif
-
int Global = 42;
// JIT reports symbol not found on Windows without the visibility attribute.
REPL_EXTERNAL_VISIBILITY int getGlobal() { return Global; }
@@ -257,7 +251,12 @@ TEST(IncrementalProcessing, FindMangledNameSymbol) {
static Value AllocateObject(TypeDecl *TD, Interpreter &Interp) {
std::string Name = TD->getQualifiedNameAsString();
Value Addr;
- cantFail(Interp.ParseAndExecute("new " + Name + "()", &Addr));
+ // FIXME: Consider providing an option in clang::Value to take ownership of
+ // the memory created from the interpreter.
+ // cantFail(Interp.ParseAndExecute("new " + Name + "()", &Addr));
+
+ // The lifetime of the temporary is extended by the clang::Value.
+ cantFail(Interp.ParseAndExecute(Name + "()", &Addr));
return Addr;
}
@@ -317,8 +316,6 @@ TEST(IncrementalProcessing, InstantiateTemplate) {
auto fn =
cantFail(Interp->getSymbolAddress(MangledName)).toPtr<TemplateSpecFn>();
EXPECT_EQ(42, fn(NewA.getPtr()));
- // FIXME: release the memory.
- __lsan_ignore_object(NewA.getPtr());
}
#ifdef CLANG_INTERPRETER_NO_SUPPORT_EXEC