Skip to content

Commit afc8762

Browse files
authored
Merge pull request swiftlang#30406 from lhames/fix-imm-static-inits
[Immediate] Fix static constructor/destructor calls in RunImmediately.
2 parents cc4bfe8 + 2c083d8 commit afc8762

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

lib/Immediate/Immediate.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ int swift::RunImmediately(CompilerInstance &CI,
350350

351351
using MainFnTy = int(*)(int, char*[]);
352352

353+
LLVM_DEBUG(llvm::dbgs() << "Running static constructors\n");
353354
if (auto Err = JIT->runConstructors()) {
354355
llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "");
355356
return -1;
@@ -363,11 +364,14 @@ int swift::RunImmediately(CompilerInstance &CI,
363364
return -1;
364365
}
365366

366-
LLVM_DEBUG(llvm::dbgs() << "Running static constructors\n");
367-
if (auto Err = JIT->runConstructors()) {
367+
LLVM_DEBUG(llvm::dbgs() << "Running main\n");
368+
int Result = llvm::orc::runAsMain(JITMain, CmdLine);
369+
370+
LLVM_DEBUG(llvm::dbgs() << "Running static destructors\n");
371+
if (auto Err = JIT->runDestructors()) {
368372
logAllUnhandledErrors(std::move(Err), llvm::errs(), "");
369373
return -1;
370374
}
371-
LLVM_DEBUG(llvm::dbgs() << "Running main\n");
372-
return llvm::orc::runAsMain(JITMain, CmdLine);
375+
376+
return Result;
373377
}

0 commit comments

Comments
 (0)