Hello,
I get a crash in my program that uses exceptions and the LLVM JIT,
even though the exceptions are controlled and thrown/catched in a part
that doesn't deal with LLVM. I noticed that llvm-config --cxxflags
includes the -fno-exceptions flag. Do I need to throw no exceptions
whatsoever in my application to use LLVM JIT?
As a minimal example, I modified the code in
llvm/examples/Kaleidoscope/BuildingAJIT/Chapter2 at master · llvm-mirror/llvm · GitHub.
In toy.cpp, I update LogError to throw an exception:
std::unique_ptr<ExprAST> LogError(const char *Str) {
fprintf(stderr, "Error: %s\n", Str);
throw std::runtime_error("");
}
and I catch that exception in MainLoop:
static void MainLoop() {
while (true) {
fprintf(stderr, "ready> ");
try {
switch (CurTok) {
...
}
} catch (std::runtime_error &e) {
fprintf(stderr, "%s\n", e.what());
}
}
}
I compile with:
clang++ -g toy.cpp `llvm-config --cxxflags --ldflags --system-libs
--libs core orcjit native` -O3 -fexceptions -o toy
./toy
var 3 = 2
Error: expected identifier after var
1
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
zsh: abort ./toy
Technical details:
- LLVM latest master (commit 2c4ca6832fa6b306ee6a7010bfb80a3f2596f824)
on GitHub - llvm-mirror/llvm: Project moved to: https://github.com/llvm/llvm-project
- clang version 8.0.0-3
Thank you,