[clang] 1343632 - [clang] Fix gcc-6 compilation error. (NFC)

2022-07-03 Thread Sunho Kim via cfe-commits

Author: Sunho Kim
Date: 2022-07-04T05:33:05+09:00
New Revision: 134363208b9272a967c911f7b56c255a72a6f0a0

URL: 
https://github.com/llvm/llvm-project/commit/134363208b9272a967c911f7b56c255a72a6f0a0
DIFF: 
https://github.com/llvm/llvm-project/commit/134363208b9272a967c911f7b56c255a72a6f0a0.diff

LOG: [clang] Fix gcc-6 compilation error. (NFC)

Fix https://github.com/llvm/llvm-project/issues/55626.

Differential Revision: https://reviews.llvm.org/D129049

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index da538aa332ffc..9b729e347a245 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -496,7 +496,7 @@ ByteCodeExprGen::getGlobalIdx(const VarDecl *VD) {
 
 template 
 const RecordType *ByteCodeExprGen::getRecordTy(QualType Ty) {
-  if (auto *PT = dyn_cast(Ty))
+  if (const PointerType *PT = dyn_cast(Ty))
 return PT->getPointeeType()->getAs();
   else
 return Ty->getAs();



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 72ea1a7 - [ORC] Fix weak hidden symbols failure on PPC with runtimedyld

2022-07-28 Thread Sunho Kim via cfe-commits

Author: Sunho Kim
Date: 2022-07-28T21:12:25+09:00
New Revision: 72ea1a721e005f29c6fea4a684807a68abd93c39

URL: 
https://github.com/llvm/llvm-project/commit/72ea1a721e005f29c6fea4a684807a68abd93c39
DIFF: 
https://github.com/llvm/llvm-project/commit/72ea1a721e005f29c6fea4a684807a68abd93c39.diff

LOG: [ORC] Fix weak hidden symbols failure on PPC with runtimedyld

Fix "JIT session error: Symbols not found: [ DW.ref.__gxx_personality_v0 ] 
error" which happens when trying to use exceptions on ppc linux. To do this, it 
expands AutoClaimSymbols option in RTDyldObjectLinkingLayer to also claim weak 
symbols before they are tried to be resovled. In ppc linux, DW.ref symbols is 
emitted as weak hidden symbols in the later stage of MC pipeline. This means 
when using IRLayer (i.e. LLJIT), IRLayer will not claim responsibility for such 
symbols and RuntimeDyld will skip defining this symbol even though it couldn't 
resolve corresponding external symbol.

Reviewed By: sgraenitz

Differential Revision: https://reviews.llvm.org/D129175

Added: 


Modified: 
clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
llvm/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp

Removed: 




diff  --git 
a/clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp 
b/clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
index 75928d912dd4..a1dbcfa3410f 100644
--- a/clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
+++ b/clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
@@ -98,11 +98,6 @@ extern "C" int throw_exception() {
   // FIXME: Re-enable the excluded target triples.
   const clang::CompilerInstance *CI = Interp->getCompilerInstance();
   const llvm::Triple &Triple = CI->getASTContext().getTargetInfo().getTriple();
-  // FIXME: PPC fails due to `Symbols not found: [DW.ref.__gxx_personality_v0]`
-  // The current understanding is that the JIT should emit this symbol if it 
was
-  // not (eg. the way passing clang -fPIC does it).
-  if (Triple.isPPC())
-return;
 
   // FIXME: ARM fails due to `Not implemented relocation type!`
   if (Triple.isARM())

diff  --git a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp 
b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
index 1926ef1ecc72..17ad0a2170f9 100644
--- a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
@@ -746,6 +746,11 @@ LLJIT::createObjectLinkingLayer(LLJITBuilderState &S, 
ExecutionSession &ES) {
 Layer->setAutoClaimResponsibilityForObjectSymbols(true);
   }
 
+  if (S.JTMB->getTargetTriple().isOSBinFormatELF() &&
+  (S.JTMB->getTargetTriple().getArch() == Triple::ArchType::ppc64 ||
+   S.JTMB->getTargetTriple().getArch() == Triple::ArchType::ppc64le))
+Layer->setAutoClaimResponsibilityForObjectSymbols(true);
+
   // FIXME: Explicit conversion to std::unique_ptr added to 
silence
   //errors from some GCC / libstdc++ bots. Remove this conversion (i.e.
   //just return ObjLinkingLayer) once those bots are upgraded.

diff  --git a/llvm/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp 
b/llvm/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp
index 27044f66a55d..5d1c9afc560a 100644
--- a/llvm/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp
@@ -108,6 +108,7 @@ void RTDyldObjectLinkingLayer::emit(
   // filter these later.
   auto InternalSymbols = std::make_shared>();
   {
+SymbolFlagsMap ExtraSymbolsToClaim;
 for (auto &Sym : (*Obj)->symbols()) {
 
   // Skip file symbols.
@@ -128,6 +129,33 @@ void RTDyldObjectLinkingLayer::emit(
 return;
   }
 
+  // Try to claim responsibility of weak symbols
+  // if AutoClaimObjectSymbols flag is set.
+  if (AutoClaimObjectSymbols &&
+  (*SymFlagsOrErr & object::BasicSymbolRef::SF_Weak)) {
+auto SymName = Sym.getName();
+if (!SymName) {
+  ES.reportError(SymName.takeError());
+  R->failMaterialization();
+  return;
+}
+
+// Already included in responsibility set, skip it
+SymbolStringPtr SymbolName = ES.intern(*SymName);
+if (R->getSymbols().count(SymbolName))
+  continue;
+
+auto SymFlags = JITSymbolFlags::fromObjectSymbol(Sym);
+if (!SymFlags) {
+  ES.reportError(SymFlags.takeError());
+  R->failMaterialization();
+  return;
+}
+
+ExtraSymbolsToClaim[SymbolName] = *SymFlags;
+continue;
+  }
+
   // Don't include symbols that aren't global.
   if (!(*SymFlagsOrErr & object::BasicSymbolRef::SF_Global)) {
 if (auto SymName = Sym.getName())
@@ -139,6 +167,13 @@ void RTDyldObjectLinkingLayer::emit(
 }
   }
 }
+
+if (!ExtraSymbolsToClaim.empty()) {
+  if (au

[clang] 3cc3be8 - [clang-repl] Add host exception support check utility flag.

2022-07-28 Thread Sunho Kim via cfe-commits

Author: Sunho Kim
Date: 2022-07-28T21:14:58+09:00
New Revision: 3cc3be8fa471c69ac7cf9c071554a14020226158

URL: 
https://github.com/llvm/llvm-project/commit/3cc3be8fa471c69ac7cf9c071554a14020226158
DIFF: 
https://github.com/llvm/llvm-project/commit/3cc3be8fa471c69ac7cf9c071554a14020226158.diff

LOG: [clang-repl] Add host exception support check utility flag.

Add host exception support check utility flag. This is needed to not run tests 
that require exception support in few buildbots that lacks related symbols for 
some reason.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D129242

Added: 
clang/test/Interpreter/simple-exception.cpp

Modified: 
clang/test/lit.cfg.py
clang/tools/clang-repl/ClangRepl.cpp

Removed: 




diff  --git a/clang/test/Interpreter/simple-exception.cpp 
b/clang/test/Interpreter/simple-exception.cpp
new file mode 100644
index 0..c56fbbb417f08
--- /dev/null
+++ b/clang/test/Interpreter/simple-exception.cpp
@@ -0,0 +1,14 @@
+// clang-format off
+// REQUIRES: host-supports-jit, host-supports-exception 
+// UNSUPPORTED: system-aix
+// XFAIL: arm, arm64-apple, windows-msvc, windows-gnu
+// RUN: cat %s | clang-repl | FileCheck %s
+extern "C" int printf(const char *, ...);
+
+int f() { throw "Simple exception"; return 0; }
+int checkException() { try { printf("Running f()\n"); f(); } catch (const char 
*e) { printf("%s\n", e); } return 0; }
+auto r1 = checkException();
+// CHECK: Running f()
+// CHECK-NEXT: Simple exception
+
+%quit
\ No newline at end of file

diff  --git a/clang/test/lit.cfg.py b/clang/test/lit.cfg.py
index d95ea5d2da198..01da76de86a15 100644
--- a/clang/test/lit.cfg.py
+++ b/clang/test/lit.cfg.py
@@ -70,7 +70,7 @@
 if config.clang_examples:
 config.available_features.add('examples')
 
-def have_host_jit_support():
+def have_host_jit_feature_support(feature_name):
 clang_repl_exe = lit.util.which('clang-repl', config.clang_tools_dir)
 
 if not clang_repl_exe:
@@ -79,7 +79,7 @@ def have_host_jit_support():
 
 try:
 clang_repl_cmd = subprocess.Popen(
-[clang_repl_exe, '--host-supports-jit'], stdout=subprocess.PIPE)
+[clang_repl_exe, '--host-supports-' + feature_name], 
stdout=subprocess.PIPE)
 except OSError:
 print('could not exec clang-repl')
 return False
@@ -89,9 +89,12 @@ def have_host_jit_support():
 
 return 'true' in clang_repl_out
 
-if have_host_jit_support():
+if have_host_jit_feature_support('jit'):
 config.available_features.add('host-supports-jit')
 
+if have_host_jit_feature_support('exception'):
+config.available_features.add('host-supports-exception')
+
 if config.clang_staticanalyzer:
 config.available_features.add('staticanalyzer')
 tools.append('clang-check')

diff  --git a/clang/tools/clang-repl/ClangRepl.cpp 
b/clang/tools/clang-repl/ClangRepl.cpp
index 4f673bdcb7cc5..490e2feed50e1 100644
--- a/clang/tools/clang-repl/ClangRepl.cpp
+++ b/clang/tools/clang-repl/ClangRepl.cpp
@@ -28,6 +28,8 @@ static llvm::cl::list
   llvm::cl::CommaSeparated);
 static llvm::cl::opt OptHostSupportsJit("host-supports-jit",
   llvm::cl::Hidden);
+static llvm::cl::opt OptHostSupportsException("host-supports-exception",
+llvm::cl::Hidden);
 static llvm::cl::list OptInputs(llvm::cl::Positional,
  llvm::cl::desc("[code to run]"));
 
@@ -65,6 +67,42 @@ static int checkDiagErrors(const clang::CompilerInstance 
*CI) {
   return Errs ? EXIT_FAILURE : EXIT_SUCCESS;
 }
 
+// Check if the host environment supports c++ exception handling
+// by querying the existence of symbol __cxa_throw.
+static bool checkExceptionSupport() {
+  auto J = llvm::orc::LLJITBuilder().create();
+  if (!J) {
+llvm::consumeError(J.takeError());
+return false;
+  }
+
+  std::vector Dummy;
+  auto CI = clang::IncrementalCompilerBuilder::create(Dummy);
+  if (!CI) {
+llvm::consumeError(CI.takeError());
+return false;
+  }
+
+  auto Interp = clang::Interpreter::create(std::move(*CI));
+  if (!Interp) {
+llvm::consumeError(Interp.takeError());
+return false;
+  }
+
+  if (auto Err = (*Interp)->ParseAndExecute("")) {
+llvm::consumeError(std::move(Err));
+return false;
+  }
+
+  auto Sym = (*Interp)->getSymbolAddress("__cxa_throw");
+  if (!Sym) {
+llvm::consumeError(Sym.takeError());
+return false;
+  }
+
+  return true;
+}
+
 llvm::ExitOnError ExitOnErr;
 int main(int argc, const char **argv) {
   ExitOnErr.setBanner("clang-repl: ");
@@ -87,6 +125,14 @@ int main(int argc, const char **argv) {
 return 0;
   }
 
+  if (OptHostSupportsException) {
+if (checkExceptionSupport())
+  llvm::outs() << "true\n";
+else
+  llvm::outs() << "false\n";
+return 0;
+  }
+
   // FIXME: Investigate if we

[clang] bd08f41 - [clang-repl] Disable exception unittest on AIX.

2022-07-28 Thread Sunho Kim via cfe-commits

Author: Sunho Kim
Date: 2022-07-28T22:48:51+09:00
New Revision: bd08f413c089da5a56438cc8902f60df91a08a66

URL: 
https://github.com/llvm/llvm-project/commit/bd08f413c089da5a56438cc8902f60df91a08a66
DIFF: 
https://github.com/llvm/llvm-project/commit/bd08f413c089da5a56438cc8902f60df91a08a66.diff

LOG: [clang-repl] Disable exception unittest on AIX.

AIX platform was not supported but it was not explicitly checked in exception 
test as it was excluded by isPPC() check.

Added: 


Modified: 
clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp

Removed: 




diff  --git 
a/clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp 
b/clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
index a1dbcfa3410f8..7a5f07e25bc6f 100644
--- a/clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
+++ b/clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
@@ -99,6 +99,10 @@ extern "C" int throw_exception() {
   const clang::CompilerInstance *CI = Interp->getCompilerInstance();
   const llvm::Triple &Triple = CI->getASTContext().getTargetInfo().getTriple();
 
+  // AIX is unsupported.
+  if (Triple.isOSAIX())
+return;
+
   // FIXME: ARM fails due to `Not implemented relocation type!`
   if (Triple.isARM())
 return;



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] c619d4f - [clang-repl] Support destructors of global objects.

2022-07-28 Thread Sunho Kim via cfe-commits

Author: Sunho Kim
Date: 2022-07-29T02:38:40+09:00
New Revision: c619d4f840dcba54751ff8c5aaafce0f173a4ad5

URL: 
https://github.com/llvm/llvm-project/commit/c619d4f840dcba54751ff8c5aaafce0f173a4ad5
DIFF: 
https://github.com/llvm/llvm-project/commit/c619d4f840dcba54751ff8c5aaafce0f173a4ad5.diff

LOG:  [clang-repl] Support destructors of global objects.

Supports destructors of global objects by properly calling jitdylib 
deinitialize which calls the global dtors of ir modules.

This supersedes https://reviews.llvm.org/D127945. There was an issue when 
calling deinitialize on windows but it got fixed by 
https://reviews.llvm.org/D128037.

Reviewed By: v.g.vassilev

Differential Revision: https://reviews.llvm.org/D128589

Added: 
clang/test/Interpreter/global-dtor-win.cpp
clang/test/Interpreter/global-dtor.cpp

Modified: 
clang/lib/Interpreter/IncrementalExecutor.cpp
clang/lib/Interpreter/IncrementalExecutor.h
clang/lib/Interpreter/Interpreter.cpp
clang/test/Interpreter/execute.cpp
clang/tools/clang-repl/ClangRepl.cpp

Removed: 




diff  --git a/clang/lib/Interpreter/IncrementalExecutor.cpp 
b/clang/lib/Interpreter/IncrementalExecutor.cpp
index 227ab9703dc76..37d230b61f766 100644
--- a/clang/lib/Interpreter/IncrementalExecutor.cpp
+++ b/clang/lib/Interpreter/IncrementalExecutor.cpp
@@ -76,6 +76,12 @@ llvm::Error 
IncrementalExecutor::removeModule(PartialTranslationUnit &PTU) {
   return llvm::Error::success();
 }
 
+// Clean up the JIT instance.
+llvm::Error IncrementalExecutor::cleanUp() {
+  // This calls the global dtors of registered modules.
+  return Jit->deinitialize(Jit->getMainJITDylib());
+}
+
 llvm::Error IncrementalExecutor::runCtors() const {
   return Jit->initialize(Jit->getMainJITDylib());
 }

diff  --git a/clang/lib/Interpreter/IncrementalExecutor.h 
b/clang/lib/Interpreter/IncrementalExecutor.h
index 5b0f982b62ddf..54d37c76326b8 100644
--- a/clang/lib/Interpreter/IncrementalExecutor.h
+++ b/clang/lib/Interpreter/IncrementalExecutor.h
@@ -50,6 +50,7 @@ class IncrementalExecutor {
   llvm::Error addModule(PartialTranslationUnit &PTU);
   llvm::Error removeModule(PartialTranslationUnit &PTU);
   llvm::Error runCtors() const;
+  llvm::Error cleanUp();
   llvm::Expected
   getSymbolAddress(llvm::StringRef Name, SymbolNameKind NameKind) const;
   llvm::orc::LLJIT *getExecutionEngine() const { return Jit.get(); }

diff  --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index 0191ad78581d9..bdba4ae9312ac 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -183,7 +183,14 @@ Interpreter::Interpreter(std::unique_ptr 
CI,
*TSCtx->getContext(), Err);
 }
 
-Interpreter::~Interpreter() {}
+Interpreter::~Interpreter() {
+  if (IncrExecutor) {
+if (llvm::Error Err = IncrExecutor->cleanUp())
+  llvm::report_fatal_error(
+  llvm::Twine("Failed to clean up IncrementalExecutor: ") +
+  toString(std::move(Err)));
+  }
+}
 
 llvm::Expected>
 Interpreter::create(std::unique_ptr CI) {

diff  --git a/clang/test/Interpreter/execute.cpp 
b/clang/test/Interpreter/execute.cpp
index 0396ad82e9b36..124f6492179ec 100644
--- a/clang/test/Interpreter/execute.cpp
+++ b/clang/test/Interpreter/execute.cpp
@@ -1,3 +1,4 @@
+// clang-format off
 // RUN: clang-repl "int x = 10;" "int y=7; err;" "int y = 10;"
 // RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
 // RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck 
--check-prefix=CHECK-DRIVER %s

diff  --git a/clang/test/Interpreter/global-dtor-win.cpp 
b/clang/test/Interpreter/global-dtor-win.cpp
new file mode 100644
index 0..4e03298205611
--- /dev/null
+++ b/clang/test/Interpreter/global-dtor-win.cpp
@@ -0,0 +1,14 @@
+// clang-format off
+// FIXME: Merge into global-dtor.cpp when exception support arrives on 
windows-msvc
+// REQUIRES: host-supports-jit && windows-msvc
+//
+// Tests that a global destructor is ran in windows-msvc platform.
+//
+// RUN: cat %s | clang-repl | FileCheck %s
+
+extern "C" int printf(const char *, ... );
+
+struct D { float f = 1.0; D *m = nullptr; D(){} ~D() { printf("D[f=%f, 
m=0x%llx]\n", f, reinterpret_cast(m)); }} d;
+// CHECK: D[f=1.00, m=0x0]
+
+%quit
\ No newline at end of file

diff  --git a/clang/test/Interpreter/global-dtor.cpp 
b/clang/test/Interpreter/global-dtor.cpp
new file mode 100644
index 0..7367fe42eb8b7
--- /dev/null
+++ b/clang/test/Interpreter/global-dtor.cpp
@@ -0,0 +1,14 @@
+// clang-format off
+// REQUIRES: host-supports-jit, host-supports-exception 
+// UNSUPPORTED: system-aix
+//
+// Tests that a global destructor is ran on platforms with gnu exception 
support.
+//
+// RUN: cat %s | clang-repl | FileCheck %s
+
+extern "C" int printf(const char *, ...);
+
+struct D { float f = 1.0; D *m = nullptr

[clang] 4191d66 - [clang-repl] Disable execution unittests on unsupported platforms.

2022-07-29 Thread Sunho Kim via cfe-commits

Author: Sunho Kim
Date: 2022-07-30T02:28:03+09:00
New Revision: 4191d661c74622c6fa72c1643e4567f45e6c9e1b

URL: 
https://github.com/llvm/llvm-project/commit/4191d661c74622c6fa72c1643e4567f45e6c9e1b
DIFF: 
https://github.com/llvm/llvm-project/commit/4191d661c74622c6fa72c1643e4567f45e6c9e1b.diff

LOG: [clang-repl] Disable execution unittests on unsupported platforms.

After the intoduction of global destructor support, there is a possiblity to 
run invalid instructions in the destructor of Interpreter class. Completely 
disable tests in platforms with failing test cases.

Differential Revision: https://reviews.llvm.org/D130786

Added: 


Modified: 
clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
clang/unittests/Interpreter/InterpreterTest.cpp

Removed: 




diff  --git 
a/clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp 
b/clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
index 7a5f07e25bc6f..d827c915e070f 100644
--- a/clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
+++ b/clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
@@ -46,6 +46,7 @@ createInterpreter(const Args &ExtraArgs = {},
 }
 
 TEST(InterpreterTest, CatchException) {
+  llvm::llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
   llvm::InitializeNativeTarget();
   llvm::InitializeNativeTargetAsmPrinter();
 
@@ -130,8 +131,6 @@ extern "C" int throw_exception() {
   EXPECT_ANY_THROW(ThrowException());
   std::string CapturedStdOut = testing::internal::GetCapturedStdout();
   EXPECT_EQ(CapturedStdOut, "Caught: 'To be caught in JIT'\n");
-
-  llvm::llvm_shutdown();
 }
 
 } // end anonymous namespace

diff  --git a/clang/unittests/Interpreter/InterpreterTest.cpp 
b/clang/unittests/Interpreter/InterpreterTest.cpp
index 745e36071936a..d266dd0c0c768 100644
--- a/clang/unittests/Interpreter/InterpreterTest.cpp
+++ b/clang/unittests/Interpreter/InterpreterTest.cpp
@@ -28,6 +28,12 @@
 
 using namespace clang;
 
+#if defined(_AIX) || defined(__hexagon__) ||   
\
+(defined(_WIN32) &&
\
+ (defined(__aarch64__) || defined(_M_ARM64) || defined(__arm__)))
+#define CLANG_INTERPRETER_NO_SUPPORT_EXEC
+#endif
+
 namespace {
 using Args = std::vector;
 static std::unique_ptr
@@ -191,7 +197,7 @@ struct LLVMInitRAII {
   ~LLVMInitRAII() { llvm::llvm_shutdown(); }
 } LLVMInit;
 
-#ifdef _AIX
+#ifdef CLANG_INTERPRETER_NO_SUPPORT_EXEC
 TEST(IncrementalProcessing, DISABLED_FindMangledNameSymbol) {
 #else
 TEST(IncrementalProcessing, FindMangledNameSymbol) {
@@ -253,7 +259,7 @@ static NamedDecl *LookupSingleName(Interpreter &Interp, 
const char *Name) {
   return R.getFoundDecl();
 }
 
-#ifdef _AIX
+#ifdef CLANG_INTERPRETER_NO_SUPPORT_EXEC
 TEST(IncrementalProcessing, DISABLED_InstantiateTemplate) {
 #else
 TEST(IncrementalProcessing, InstantiateTemplate) {



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 65c9265 - [clang-repl] Disable exectuion unitests on unsupported platform by lljit instance test.

2022-07-29 Thread Sunho Kim via cfe-commits

Author: Sunho Kim
Date: 2022-07-30T07:18:04+09:00
New Revision: 65c9265f4158512e8dc85558ef8e73c0714e90c3

URL: 
https://github.com/llvm/llvm-project/commit/65c9265f4158512e8dc85558ef8e73c0714e90c3
DIFF: 
https://github.com/llvm/llvm-project/commit/65c9265f4158512e8dc85558ef8e73c0714e90c3.diff

LOG: [clang-repl] Disable exectuion unitests on unsupported platform by lljit 
instance test.

The method used in 4191d661c74622c6fa72c1643e4567f45e6c9e1b was fragile because 
it didn't consider cross-platform builds and rely on enlisting unsupported 
targets. Uses the host-supports-jit mechanism to make an escape path. This 
should fix buildbot failures happening in upstream as well as out-of-tree.

Added: 


Modified: 
clang/unittests/Interpreter/InterpreterTest.cpp

Removed: 




diff  --git a/clang/unittests/Interpreter/InterpreterTest.cpp 
b/clang/unittests/Interpreter/InterpreterTest.cpp
index d266dd0c0c76..a8fdff0d7e3b 100644
--- a/clang/unittests/Interpreter/InterpreterTest.cpp
+++ b/clang/unittests/Interpreter/InterpreterTest.cpp
@@ -20,6 +20,7 @@
 #include "clang/Sema/Lookup.h"
 #include "clang/Sema/Sema.h"
 
+#include "llvm/ExecutionEngine/Orc/LLJIT.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/TargetSelect.h"
 
@@ -28,9 +29,7 @@
 
 using namespace clang;
 
-#if defined(_AIX) || defined(__hexagon__) ||   
\
-(defined(_WIN32) &&
\
- (defined(__aarch64__) || defined(_M_ARM64) || defined(__arm__)))
+#if defined(_AIX)
 #define CLANG_INTERPRETER_NO_SUPPORT_EXEC
 #endif
 
@@ -189,6 +188,14 @@ static std::string MangleName(NamedDecl *ND) {
   return RawStr.str();
 }
 
+static bool HostSupportsJit() {
+  auto J = llvm::orc::LLJITBuilder().create();
+  if (J)
+return true;
+  LLVMConsumeError(llvm::wrap(J.takeError()));
+  return false;
+}
+
 struct LLVMInitRAII {
   LLVMInitRAII() {
 llvm::InitializeNativeTarget();
@@ -209,6 +216,11 @@ TEST(IncrementalProcessing, FindMangledNameSymbol) {
   EXPECT_EQ(1U, DeclsSize(PTU.TUPart));
   auto R1DeclRange = PTU.TUPart->decls();
 
+  // We cannot execute on the platform.
+  if (!HostSupportsJit()) {
+return;
+  }
+
   NamedDecl *FD = cast(*R1DeclRange.begin());
   // Lower the PTU
   if (llvm::Error Err = Interp->Execute(PTU)) {
@@ -281,6 +293,11 @@ TEST(IncrementalProcessing, InstantiateTemplate) {
   auto PTUDeclRange = PTU.TUPart->decls();
   EXPECT_EQ(1, std::distance(PTUDeclRange.begin(), PTUDeclRange.end()));
 
+  // We cannot execute on the platform.
+  if (!HostSupportsJit()) {
+return;
+  }
+
   // Lower the PTU
   if (llvm::Error Err = Interp->Execute(PTU)) {
 // We cannot execute on the platform.



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 32f59b3 - [clang-repl] Add missing link component.

2022-07-29 Thread Sunho Kim via cfe-commits

Author: Sunho Kim
Date: 2022-07-30T08:00:15+09:00
New Revision: 32f59b34b663c48c217047d4963ad3d1a2378c23

URL: 
https://github.com/llvm/llvm-project/commit/32f59b34b663c48c217047d4963ad3d1a2378c23
DIFF: 
https://github.com/llvm/llvm-project/commit/32f59b34b663c48c217047d4963ad3d1a2378c23.diff

LOG: [clang-repl] Add missing link component.

OrcJIT was missing in LLVM_LINK_COMPONENTS.

Added: 


Modified: 
clang/unittests/Interpreter/CMakeLists.txt

Removed: 




diff  --git a/clang/unittests/Interpreter/CMakeLists.txt 
b/clang/unittests/Interpreter/CMakeLists.txt
index 03a4ca4a048b..a69ae025b350 100644
--- a/clang/unittests/Interpreter/CMakeLists.txt
+++ b/clang/unittests/Interpreter/CMakeLists.txt
@@ -1,6 +1,8 @@
 set(LLVM_LINK_COMPONENTS
   ${LLVM_TARGETS_TO_BUILD}
   Core
+  OrcJIT
+  Support
   )
 
 add_clang_unittest(ClangReplInterpreterTests



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] a8f2e24 - [clang-repl] Disable building when LLVM_STATIC_LINK_CXX_STDLIB is ON.

2022-07-30 Thread Sunho Kim via cfe-commits

Author: Sunho Kim
Date: 2022-07-31T05:42:57+09:00
New Revision: a8f2e24e48fddb3707301c9d24cc50ab778d4fda

URL: 
https://github.com/llvm/llvm-project/commit/a8f2e24e48fddb3707301c9d24cc50ab778d4fda
DIFF: 
https://github.com/llvm/llvm-project/commit/a8f2e24e48fddb3707301c9d24cc50ab778d4fda.diff

LOG: [clang-repl] Disable building when LLVM_STATIC_LINK_CXX_STDLIB is ON.

We have seen random symbol not found "__cxa_throw" error in fuschia build bots 
and out-of-tree users. The understanding have been that they are built without 
exception support, but it turned out that these platforms have 
LLVM_STATIC_LINK_CXX_STDLIB ON so that they link libstdc++ to llvm statically. 
The reason why this is problematic for clang-repl is that by default clang-repl 
tries to find symbols from symbol table of executable and dynamic libraries 
loaded by current process. It needs to load another libstdc++, but the platform 
that had LLVM_STATIC_LINK_CXX_STDLIB turned on is usally those with missing or 
obsolate shared libstdc++ in the first place -- trying to load it again would 
be destined to fail eventually with a risk to introuduce mixed libstdc++ 
versions.

A proper solution that doesn't take a workaround is statically link the same 
libstdc++ by clang-repl side, but this is not possible with old JIT linker 
runtimedyld. New just-in-time linker JITLink handles this relatively well, but 
it's not availalbe in majority of platforms. For now, this patch just disables 
the building of clang-repl when LLVM_STATIC_LINK_CXX_STDLIB is ON and removes 
the "__cxa_throw" check in exception unittest as well as reverting previous 
exception check flag patch.

Reviewed By: v.g.vassilev

Differential Revision: https://reviews.llvm.org/D130788

Added: 
clang/test/Interpreter/lit.local.cfg

Modified: 
clang/CMakeLists.txt
clang/test/CMakeLists.txt
clang/test/Interpreter/code-undo.cpp
clang/test/Interpreter/execute-weak.cpp
clang/test/Interpreter/execute.cpp
clang/test/Interpreter/global-dtor.cpp
clang/test/Interpreter/plugins.cpp
clang/test/Interpreter/simple-exception.cpp
clang/test/lit.cfg.py
clang/tools/CMakeLists.txt
clang/tools/clang-repl/ClangRepl.cpp
clang/unittests/CMakeLists.txt
clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp

Removed: 
clang/test/Interpreter/global-dtor-win.cpp



diff  --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index 480f13e73c9f5..82207fae0c015 100644
--- a/clang/CMakeLists.txt
+++ b/clang/CMakeLists.txt
@@ -504,6 +504,13 @@ CMAKE_DEPENDENT_OPTION(CLANG_PLUGIN_SUPPORT
   "Build clang with plugin support" ON
   "HAVE_CLANG_PLUGIN_SUPPORT" OFF)
 
+# If libstdc++ is statically linked, clang-repl needs to statically link 
libstdc++
+# itself, which is not possible in many platforms because of current 
limitations in 
+# JIT stack. (more platforms need to be supported by JITLink)
+if(NOT LLVM_STATIC_LINK_CXX_STDLIB)
+  set(HAVE_CLANG_REPL_SUPPORT ON)
+endif()
+
 option(CLANG_ENABLE_ARCMT "Build ARCMT." ON)
 option(CLANG_ENABLE_STATIC_ANALYZER
   "Include static analyzer in clang binary." ON)

diff  --git a/clang/test/CMakeLists.txt b/clang/test/CMakeLists.txt
index 5b604b2a3eeba..a05c372fbd346 100644
--- a/clang/test/CMakeLists.txt
+++ b/clang/test/CMakeLists.txt
@@ -66,7 +66,6 @@ list(APPEND CLANG_TEST_DEPS
   clang-import-test
   clang-rename
   clang-refactor
-  clang-repl
   clang-
diff 
   clang-scan-deps
   diagtool
@@ -147,6 +146,12 @@ if(CLANG_ENABLE_STATIC_ANALYZER)
   endif()
 endif()
 
+if (HAVE_CLANG_REPL_SUPPORT)
+  list(APPEND CLANG_TEST_DEPS
+clang-repl
+)
+endif()
+
 # Copy gen_ast_dump_json_test.py to the clang build dir. This allows invoking
 # it without having to pass the --clang= argument
 configure_file(AST/gen_ast_dump_json_test.py

diff  --git a/clang/test/Interpreter/code-undo.cpp 
b/clang/test/Interpreter/code-undo.cpp
index 9a908d6b7e455..c963e45b9f224 100644
--- a/clang/test/Interpreter/code-undo.cpp
+++ b/clang/test/Interpreter/code-undo.cpp
@@ -1,6 +1,5 @@
 // RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
 // RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck 
--check-prefix=CHECK-DRIVER %s
-// REQUIRES: host-supports-jit
 // UNSUPPORTED: system-aix
 // CHECK-DRIVER: i = 10
 // RUN: cat %s | clang-repl | FileCheck %s

diff  --git a/clang/test/Interpreter/execute-weak.cpp 
b/clang/test/Interpreter/execute-weak.cpp
index 7d0b7061e5019..5b343512c5456 100644
--- a/clang/test/Interpreter/execute-weak.cpp
+++ b/clang/test/Interpreter/execute-weak.cpp
@@ -1,7 +1,6 @@
 // RUN: clang-repl "int x = 10;" "int y=7; err;" "int y = 10;"
 // RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
 // RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck 
--check-prefix=CHECK-DRIVER %s
-// REQUIRES: host-supports-jit
 // CHECK-DRIVER: i = 10
 // UNSUPPORTED: 

[clang] 773d51c - [clang-repl] XFAIL windows properly in simple-exception test case.

2022-07-31 Thread Sunho Kim via cfe-commits

Author: Sunho Kim
Date: 2022-08-01T09:06:35+09:00
New Revision: 773d51ce3bedd091539aa86a5e5fc15a9174ff7b

URL: 
https://github.com/llvm/llvm-project/commit/773d51ce3bedd091539aa86a5e5fc15a9174ff7b
DIFF: 
https://github.com/llvm/llvm-project/commit/773d51ce3bedd091539aa86a5e5fc15a9174ff7b.diff

LOG: [clang-repl] XFAIL windows properly in simple-exception test case.

We don't have proper exception support in LLJIT on windows yet. We have to 
xfail windows machine, but the previous check missed out some targets.

Added: 


Modified: 
clang/test/Interpreter/simple-exception.cpp

Removed: 




diff  --git a/clang/test/Interpreter/simple-exception.cpp 
b/clang/test/Interpreter/simple-exception.cpp
index dc13402d2a515..5af656396d4a3 100644
--- a/clang/test/Interpreter/simple-exception.cpp
+++ b/clang/test/Interpreter/simple-exception.cpp
@@ -1,6 +1,6 @@
 // clang-format off
 // UNSUPPORTED: system-aix
-// XFAIL: arm, arm64-apple, windows-msvc, windows-gnu
+// XFAIL: arm, arm64-apple, system-windows
 // RUN: cat %s | clang-repl | FileCheck %s
 extern "C" int printf(const char *, ...);
 



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 7bc00ce - [clang-repl] Remove memory leak of ASTContext/TargetMachine.

2022-06-17 Thread Sunho Kim via cfe-commits

Author: Sunho Kim
Date: 2022-06-18T06:36:25+09:00
New Revision: 7bc00ce5cd41aad5fd0775f58c8e85a0a8d9ee56

URL: 
https://github.com/llvm/llvm-project/commit/7bc00ce5cd41aad5fd0775f58c8e85a0a8d9ee56
DIFF: 
https://github.com/llvm/llvm-project/commit/7bc00ce5cd41aad5fd0775f58c8e85a0a8d9ee56.diff

LOG: [clang-repl] Remove memory leak of ASTContext/TargetMachine.

Removes memory leak of ASTContext and TargetMachine. When DisableFree is turned 
on, it intentionally leaks these instances as they can be trivially 
deallocated. This patch turns this off and delete Parser instance early so that 
they will not reference dangling pargma headers.

Asan shouldn't detect these as leaks normally, since burypointer is called for 
them. But, every invocation of incremental parser createa an additional leak of 
TargetMachine. If there are many invocations within a single test case, we 
easily reach number of leaks exceeding kGraveYardMaxSize (which is 12) and 
leaks start to get reported by asan buildbots.

Reviewed By: v.g.vassilev

Differential Revision: https://reviews.llvm.org/D127991

Added: 


Modified: 
clang/lib/Interpreter/IncrementalParser.cpp
clang/lib/Interpreter/Interpreter.cpp

Removed: 




diff  --git a/clang/lib/Interpreter/IncrementalParser.cpp 
b/clang/lib/Interpreter/IncrementalParser.cpp
index 0f1ef3233a2a1..e5712303cbbb2 100644
--- a/clang/lib/Interpreter/IncrementalParser.cpp
+++ b/clang/lib/Interpreter/IncrementalParser.cpp
@@ -134,7 +134,10 @@ 
IncrementalParser::IncrementalParser(std::unique_ptr Instance,
   P->Initialize();
 }
 
-IncrementalParser::~IncrementalParser() { Act->FinalizeAction(); }
+IncrementalParser::~IncrementalParser() {
+  P.reset();
+  Act->FinalizeAction();
+}
 
 llvm::Expected
 IncrementalParser::ParseOrWrapTopLevelDecl() {

diff  --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index 470c9c289a749..564b24efebdd0 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -116,6 +116,9 @@ CreateCI(const llvm::opt::ArgStringList &Argv) {
   // times, reusing the same AST.
   Clang->getCodeGenOpts().ClearASTBeforeBackend = false;
 
+  Clang->getFrontendOpts().DisableFree = false;
+  Clang->getCodeGenOpts().DisableFree = false;
+
   return std::move(Clang);
 }
 



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 9de8b05 - [clang-repl] Support destructors of global objects.

2022-06-26 Thread Sunho Kim via cfe-commits

Author: Sunho Kim
Date: 2022-06-26T19:02:19+09:00
New Revision: 9de8b05bfe0de2915d2443d06159396c5f9d389f

URL: 
https://github.com/llvm/llvm-project/commit/9de8b05bfe0de2915d2443d06159396c5f9d389f
DIFF: 
https://github.com/llvm/llvm-project/commit/9de8b05bfe0de2915d2443d06159396c5f9d389f.diff

LOG: [clang-repl] Support destructors of global objects.

Supports destructors of global objects by properly calling jitdylib 
deinitialize which calls the global dtors of ir modules.

This supersedes https://reviews.llvm.org/D127945. There was an issue when 
calling deinitialize on windows but it got fixed by 
https://reviews.llvm.org/D128037.

Reviewed By: v.g.vassilev

Differential Revision: https://reviews.llvm.org/D128589

Added: 


Modified: 
clang/lib/Interpreter/IncrementalExecutor.cpp
clang/lib/Interpreter/IncrementalExecutor.h
clang/lib/Interpreter/Interpreter.cpp
clang/test/Interpreter/execute.cpp
clang/tools/clang-repl/ClangRepl.cpp
clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp

Removed: 




diff  --git a/clang/lib/Interpreter/IncrementalExecutor.cpp 
b/clang/lib/Interpreter/IncrementalExecutor.cpp
index 75c385aa409f3..c5ed9b0fb4571 100644
--- a/clang/lib/Interpreter/IncrementalExecutor.cpp
+++ b/clang/lib/Interpreter/IncrementalExecutor.cpp
@@ -52,6 +52,12 @@ 
IncrementalExecutor::IncrementalExecutor(llvm::orc::ThreadSafeContext &TSC,
 
 IncrementalExecutor::~IncrementalExecutor() {}
 
+// Clean up the JIT instance.
+llvm::Error IncrementalExecutor::cleanUp() {
+  // This calls the global dtors of registered modules.
+  return Jit->deinitialize(Jit->getMainJITDylib());
+}
+
 llvm::Error IncrementalExecutor::addModule(std::unique_ptr M) {
   return Jit->addIRModule(llvm::orc::ThreadSafeModule(std::move(M), TSCtx));
 }

diff  --git a/clang/lib/Interpreter/IncrementalExecutor.h 
b/clang/lib/Interpreter/IncrementalExecutor.h
index 51b4d83d10b1c..75c181d76302a 100644
--- a/clang/lib/Interpreter/IncrementalExecutor.h
+++ b/clang/lib/Interpreter/IncrementalExecutor.h
@@ -43,6 +43,7 @@ class IncrementalExecutor {
 
   llvm::Error addModule(std::unique_ptr M);
   llvm::Error runCtors() const;
+  llvm::Error cleanUp();
   llvm::Expected
   getSymbolAddress(llvm::StringRef Name, SymbolNameKind NameKind) const;
   llvm::orc::LLJIT *getExecutionEngine() const { return Jit.get(); }

diff  --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index 564b24efebdd0..c3bbfcfec8cbe 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -183,7 +183,14 @@ Interpreter::Interpreter(std::unique_ptr 
CI,
*TSCtx->getContext(), Err);
 }
 
-Interpreter::~Interpreter() {}
+Interpreter::~Interpreter() {
+  if (IncrExecutor) {
+if (llvm::Error Err = IncrExecutor->cleanUp())
+  llvm::report_fatal_error(
+  llvm::Twine("Failed to clean up IncrementalExecutor: ") +
+  toString(std::move(Err)));
+  }
+}
 
 llvm::Expected>
 Interpreter::create(std::unique_ptr CI) {

diff  --git a/clang/test/Interpreter/execute.cpp 
b/clang/test/Interpreter/execute.cpp
index f5d75074947d4..4f01f8349be2f 100644
--- a/clang/test/Interpreter/execute.cpp
+++ b/clang/test/Interpreter/execute.cpp
@@ -1,3 +1,4 @@
+// clang-format off
 // RUN: clang-repl "int x = 10;" "int y=7; err;" "int y = 10;"
 // RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
 // RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck 
--check-prefix=CHECK-DRIVER %s
@@ -18,4 +19,7 @@ auto r2 = printf("S[f=%f, m=0x%llx]\n", s.f, 
reinterpret_cast(m)); }} d;
+// CHECK: D[f=1.00, m=0x0]
+
 quit

diff  --git a/clang/tools/clang-repl/ClangRepl.cpp 
b/clang/tools/clang-repl/ClangRepl.cpp
index ca784ad0c07de..271ec2695789e 100644
--- a/clang/tools/clang-repl/ClangRepl.cpp
+++ b/clang/tools/clang-repl/ClangRepl.cpp
@@ -70,6 +70,8 @@ int main(int argc, const char **argv) {
   ExitOnErr.setBanner("clang-repl: ");
   llvm::cl::ParseCommandLineOptions(argc, argv);
 
+  llvm::llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
+
   std::vector ClangArgv(ClangArgs.size());
   std::transform(ClangArgs.begin(), ClangArgs.end(), ClangArgv.begin(),
  [](const std::string &s) -> const char * { return s.data(); 
});
@@ -121,7 +123,5 @@ int main(int argc, const char **argv) {
   // later errors use the default handling behavior instead.
   llvm::remove_fatal_error_handler();
 
-  llvm::llvm_shutdown();
-
   return checkDiagErrors(Interp->getCompilerInstance());
 }

diff  --git 
a/clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp 
b/clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
index 75928d912dd47..73f7a01a20bf0 100644
--- a/clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
+++ b/clang/unittests/Interprete

[clang] 45b6c38 - Revert "[clang-repl] Support destructors of global objects."

2022-06-26 Thread Sunho Kim via cfe-commits

Author: Sunho Kim
Date: 2022-06-26T22:10:28+09:00
New Revision: 45b6c38145e72d8a2593f9637c01015122b0b28c

URL: 
https://github.com/llvm/llvm-project/commit/45b6c38145e72d8a2593f9637c01015122b0b28c
DIFF: 
https://github.com/llvm/llvm-project/commit/45b6c38145e72d8a2593f9637c01015122b0b28c.diff

LOG: Revert "[clang-repl] Support destructors of global objects."

This reverts commit 9de8b05bfe0de2915d2443d06159396c5f9d389f.

Added: 


Modified: 
clang/lib/Interpreter/IncrementalExecutor.cpp
clang/lib/Interpreter/IncrementalExecutor.h
clang/lib/Interpreter/Interpreter.cpp
clang/test/Interpreter/execute.cpp
clang/tools/clang-repl/ClangRepl.cpp
clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp

Removed: 




diff  --git a/clang/lib/Interpreter/IncrementalExecutor.cpp 
b/clang/lib/Interpreter/IncrementalExecutor.cpp
index 2445ba906a4c2..c055827281b4f 100644
--- a/clang/lib/Interpreter/IncrementalExecutor.cpp
+++ b/clang/lib/Interpreter/IncrementalExecutor.cpp
@@ -53,12 +53,6 @@ 
IncrementalExecutor::IncrementalExecutor(llvm::orc::ThreadSafeContext &TSC,
 
 IncrementalExecutor::~IncrementalExecutor() {}
 
-// Clean up the JIT instance.
-llvm::Error IncrementalExecutor::cleanUp() {
-  // This calls the global dtors of registered modules.
-  return Jit->deinitialize(Jit->getMainJITDylib());
-}
-
 llvm::Error IncrementalExecutor::addModule(PartialTranslationUnit &PTU) {
   llvm::orc::ResourceTrackerSP RT =
   Jit->getMainJITDylib().createResourceTracker();

diff  --git a/clang/lib/Interpreter/IncrementalExecutor.h 
b/clang/lib/Interpreter/IncrementalExecutor.h
index fd93b1d390357..580724e1e24e2 100644
--- a/clang/lib/Interpreter/IncrementalExecutor.h
+++ b/clang/lib/Interpreter/IncrementalExecutor.h
@@ -51,7 +51,6 @@ class IncrementalExecutor {
   llvm::Error addModule(PartialTranslationUnit &PTU);
   llvm::Error removeModule(PartialTranslationUnit &PTU);
   llvm::Error runCtors() const;
-  llvm::Error cleanUp();
   llvm::Expected
   getSymbolAddress(llvm::StringRef Name, SymbolNameKind NameKind) const;
   llvm::orc::LLJIT *getExecutionEngine() const { return Jit.get(); }

diff  --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index 0ffb40c217cd9..a10eb79b413b3 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -183,14 +183,7 @@ Interpreter::Interpreter(std::unique_ptr 
CI,
*TSCtx->getContext(), Err);
 }
 
-Interpreter::~Interpreter() {
-  if (IncrExecutor) {
-if (llvm::Error Err = IncrExecutor->cleanUp())
-  llvm::report_fatal_error(
-  llvm::Twine("Failed to clean up IncrementalExecutor: ") +
-  toString(std::move(Err)));
-  }
-}
+Interpreter::~Interpreter() {}
 
 llvm::Expected>
 Interpreter::create(std::unique_ptr CI) {

diff  --git a/clang/test/Interpreter/execute.cpp 
b/clang/test/Interpreter/execute.cpp
index 914a9285117e0..f5c70c21ac507 100644
--- a/clang/test/Interpreter/execute.cpp
+++ b/clang/test/Interpreter/execute.cpp
@@ -1,4 +1,3 @@
-// clang-format off
 // RUN: clang-repl "int x = 10;" "int y=7; err;" "int y = 10;"
 // RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
 // RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck 
--check-prefix=CHECK-DRIVER %s
@@ -19,7 +18,4 @@ auto r2 = printf("S[f=%f, m=0x%llx]\n", s.f, 
reinterpret_cast(m)); }} d;
-// CHECK: D[f=1.00, m=0x0]
-
 %quit

diff  --git a/clang/tools/clang-repl/ClangRepl.cpp 
b/clang/tools/clang-repl/ClangRepl.cpp
index d3253738c6da1..4f673bdcb7cc5 100644
--- a/clang/tools/clang-repl/ClangRepl.cpp
+++ b/clang/tools/clang-repl/ClangRepl.cpp
@@ -70,8 +70,6 @@ int main(int argc, const char **argv) {
   ExitOnErr.setBanner("clang-repl: ");
   llvm::cl::ParseCommandLineOptions(argc, argv);
 
-  llvm::llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
-
   std::vector ClangArgv(ClangArgs.size());
   std::transform(ClangArgs.begin(), ClangArgs.end(), ClangArgv.begin(),
  [](const std::string &s) -> const char * { return s.data(); 
});
@@ -129,5 +127,7 @@ int main(int argc, const char **argv) {
   // later errors use the default handling behavior instead.
   llvm::remove_fatal_error_handler();
 
+  llvm::llvm_shutdown();
+
   return checkDiagErrors(Interp->getCompilerInstance());
 }

diff  --git 
a/clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp 
b/clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
index 73f7a01a20bf0..75928d912dd47 100644
--- a/clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
+++ b/clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
@@ -48,7 +48,6 @@ createInterpreter(const Args &ExtraArgs = {},
 TEST(InterpreterTest, CatchException) {
   llvm::InitializeNativeTarget();
   llvm::InitializeNativeTar

[clang] [ORC] Implement basic reoptimization. (PR #67050)

2023-09-21 Thread Sunho Kim via cfe-commits

https://github.com/sunho created https://github.com/llvm/llvm-project/pull/67050

None

>From 9d759677e725c244a7a3eb06864d6474253b6d86 Mon Sep 17 00:00:00 2001
From: Sunho Kim 
Date: Mon, 21 Aug 2023 15:48:26 +0900
Subject: [PATCH 1/4] [ORC] Introduce RedirectionManager interface and
 implementation using JITLink.

---
 .../Orc/JITLinkRedirectableSymbolManager.h| 106 +++
 .../ExecutionEngine/Orc/RedirectionManager.h  | 102 ++
 llvm/lib/ExecutionEngine/Orc/CMakeLists.txt   |   2 +
 .../Orc/JITLinkRedirectableSymbolManager.cpp  | 179 ++
 .../Orc/RedirectionManager.cpp|  28 +++
 .../ExecutionEngine/Orc/CMakeLists.txt|   1 +
 .../Orc/JITLinkRedirectionManagerTest.cpp | 100 ++
 7 files changed, 518 insertions(+)
 create mode 100644 
llvm/include/llvm/ExecutionEngine/Orc/JITLinkRedirectableSymbolManager.h
 create mode 100644 llvm/include/llvm/ExecutionEngine/Orc/RedirectionManager.h
 create mode 100644 
llvm/lib/ExecutionEngine/Orc/JITLinkRedirectableSymbolManager.cpp
 create mode 100644 llvm/lib/ExecutionEngine/Orc/RedirectionManager.cpp
 create mode 100644 
llvm/unittests/ExecutionEngine/Orc/JITLinkRedirectionManagerTest.cpp

diff --git 
a/llvm/include/llvm/ExecutionEngine/Orc/JITLinkRedirectableSymbolManager.h 
b/llvm/include/llvm/ExecutionEngine/Orc/JITLinkRedirectableSymbolManager.h
new file mode 100644
index 000..5de0da1f52d0db6
--- /dev/null
+++ b/llvm/include/llvm/ExecutionEngine/Orc/JITLinkRedirectableSymbolManager.h
@@ -0,0 +1,106 @@
+//===- JITLinkRedirectableSymbolManager.h - JITLink redirection -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Redirectable Symbol Manager implementation using JITLink
+//
+//===--===//
+
+#ifndef LLVM_EXECUTIONENGINE_ORC_JITLINKREDIRECABLEMANAGER_H
+#define LLVM_EXECUTIONENGINE_ORC_JITLINKREDIRECABLEMANAGER_H
+
+#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
+#include "llvm/ExecutionEngine/Orc/RedirectionManager.h"
+#include "llvm/Support/StringSaver.h"
+
+namespace llvm {
+namespace orc {
+
+class JITLinkRedirectableSymbolManager : public RedirectableSymbolManager,
+ public ResourceManager {
+public:
+  /// Create redirection manager that uses JITLink based implementaion.
+  static Expected>
+  Create(ExecutionSession &ES, ObjectLinkingLayer &ObjLinkingLayer,
+ JITDylib &JD) {
+Error Err = Error::success();
+auto RM = std::unique_ptr(
+new JITLinkRedirectableSymbolManager(ES, ObjLinkingLayer, JD, Err));
+if (Err)
+  return Err;
+return std::move(RM);
+  }
+
+  void emitRedirectableSymbols(std::unique_ptr 
R,
+   const SymbolAddrMap &InitialDests) override;
+
+  Error redirect(JITDylib &TargetJD, const SymbolAddrMap &NewDests) override;
+
+  Error handleRemoveResources(JITDylib &TargetJD, ResourceKey K) override;
+
+  void handleTransferResources(JITDylib &TargetJD, ResourceKey DstK,
+   ResourceKey SrcK) override;
+
+private:
+  using StubHandle = unsigned;
+  constexpr static unsigned StubBlockSize = 256;
+  constexpr static StringRef JumpStubPrefix = "$__IND_JUMP_STUBS";
+  constexpr static StringRef StubPtrPrefix = "$IND_JUMP_PTR_";
+  constexpr static StringRef JumpStubTableName = "$IND_JUMP_";
+  constexpr static StringRef StubPtrTableName = "$__IND_JUMP_PTRS";
+
+  JITLinkRedirectableSymbolManager(ExecutionSession &ES,
+   ObjectLinkingLayer &ObjLinkingLayer,
+   JITDylib &JD, Error &Err)
+  : ES(ES), ObjLinkingLayer(ObjLinkingLayer), JD(JD),
+AnonymousPtrCreator(
+jitlink::getAnonymousPointerCreator(ES.getTargetTriple())),
+PtrJumpStubCreator(
+jitlink::getPointerJumpStubCreator(ES.getTargetTriple())) {
+if (!AnonymousPtrCreator || !PtrJumpStubCreator)
+  Err = make_error("Architecture not supported",
+inconvertibleErrorCode());
+if (Err)
+  return;
+ES.registerResourceManager(*this);
+  }
+
+  ~JITLinkRedirectableSymbolManager() { ES.deregisterResourceManager(*this); }
+
+  StringRef JumpStubSymbolName(unsigned I) {
+return *ES.intern((JumpStubPrefix + Twine(I)).str());
+  }
+
+  StringRef StubPtrSymbolName(unsigned I) {
+return *ES.intern((StubPtrPrefix + Twine(I)).str());
+  }
+
+  unsigned GetNumAvailableStubs() const { return AvailableStubs.size(); }
+
+  Error redirectInner(JITDylib &TargetJD, const SymbolAddrMap &NewDests);
+  Error grow(unsigned Need);
+
+  ExecutionSession &ES;
+  ObjectLinkingLayer &ObjLinkingLayer;
+  JITDyli

[clang] Karikari (PR #67253)

2023-09-23 Thread Sunho Kim via cfe-commits

sunho wrote:

Oh mistake

https://github.com/llvm/llvm-project/pull/67253
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Karikari (PR #67253)

2023-09-23 Thread Sunho Kim via cfe-commits

https://github.com/sunho closed https://github.com/llvm/llvm-project/pull/67253
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits