[llvm-dev] Crash using exceptions

Julien Lopez via llvm-dev llvm-dev at lists.llvm.org
Mon Nov 18 05:43:45 PST 2019


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


More information about the llvm-dev mailing list