[llvm-dev] Crash using exceptions
Lang Hames via llvm-dev
llvm-dev at lists.llvm.org
Thu Nov 21 12:01:41 PST 2019
Hi Julien,
You can turn on exceptions for your example by adding '-frtti -fexceptions'
to your clang invocation:
clang++ -g toy.cpp `llvm-config --cxxflags --ldflags --system-libs --libs
core orcjit native` -frtti -fexceptions -O3 -fexceptions -o toy
You can also enable exception support and RTTI in your LLVM builds by
adding -DLLVM_ENABLE_RTTI=On -DLLVM_ENABLE_EH=On to your CMake invocation.
Cheers,
Lang.
On Mon, Nov 18, 2019 at 5:44 AM Julien Lopez via llvm-dev <
llvm-dev at lists.llvm.org> wrote:
> 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
>
> https://github.com/llvm-mirror/llvm/tree/master/examples/Kaleidoscope/BuildingAJIT/Chapter2
> .
> 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
> ready> var 3 = 2
> ready> Error: expected identifier after var
>
> ready> 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 https://github.com/llvm-mirror/llvm.git
> - clang version 8.0.0-3
>
> Thank you,
>
> --
> Julien Lopez
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20191121/00b59c4b/attachment.html>
More information about the llvm-dev
mailing list