<div dir="ltr"><div dir="ltr">Hi Julien,<div><br></div><div>You can turn on exceptions for your example by adding '-frtti -fexceptions' to your clang invocation:</div><div><br></div><div><div><font face="monospace">clang++ -g toy.cpp `llvm-config --cxxflags --ldflags --system-libs --libs core orcjit native` -frtti -fexceptions -O3 -fexceptions -o toy</font></div></div><div><br></div><div>You can also enable exception support and RTTI in your LLVM builds by adding <font face="monospace">-DLLVM_ENABLE_RTTI=On -DLLVM_ENABLE_EH=On</font> to your CMake invocation.</div><div><br></div><div>Cheers,</div><div>Lang.</div><div><br></div><div><br></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Nov 18, 2019 at 5:44 AM Julien Lopez via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">Hello,<br>
<br>
I get a crash in my program that uses exceptions and the LLVM JIT,<br>
even though the exceptions are controlled and thrown/catched in a part<br>
that doesn't deal with LLVM. I noticed that llvm-config --cxxflags<br>
includes the -fno-exceptions flag. Do I need to throw no exceptions<br>
whatsoever in my application to use LLVM JIT?<br>
<br>
As a minimal example, I modified the code in<br>
<a href="https://github.com/llvm-mirror/llvm/tree/master/examples/Kaleidoscope/BuildingAJIT/Chapter2" rel="noreferrer" target="_blank">https://github.com/llvm-mirror/llvm/tree/master/examples/Kaleidoscope/BuildingAJIT/Chapter2</a>.<br>
In toy.cpp, I update LogError to throw an exception:<br>
<br>
std::unique_ptr<ExprAST> LogError(const char *Str) {<br>
fprintf(stderr, "Error: %s\n", Str);<br>
throw std::runtime_error("");<br>
}<br>
<br>
and I catch that exception in MainLoop:<br>
<br>
static void MainLoop() {<br>
while (true) {<br>
fprintf(stderr, "ready> ");<br>
try {<br>
switch (CurTok) {<br>
...<br>
}<br>
} catch (std::runtime_error &e) {<br>
fprintf(stderr, "%s\n", e.what());<br>
}<br>
}<br>
}<br>
<br>
I compile with:<br>
<br>
clang++ -g toy.cpp `llvm-config --cxxflags --ldflags --system-libs<br>
--libs core orcjit native` -O3 -fexceptions -o toy<br>
./toy<br>
ready> var 3 = 2<br>
ready> Error: expected identifier after var<br>
<br>
ready> 1<br>
terminate called after throwing an instance of 'std::bad_alloc'<br>
what(): std::bad_alloc<br>
zsh: abort ./toy<br>
<br>
Technical details:<br>
- LLVM latest master (commit 2c4ca6832fa6b306ee6a7010bfb80a3f2596f824)<br>
on <a href="https://github.com/llvm-mirror/llvm.git" rel="noreferrer" target="_blank">https://github.com/llvm-mirror/llvm.git</a><br>
- clang version 8.0.0-3<br>
<br>
Thank you,<br>
<br>
-- <br>
Julien Lopez<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>