[llvm-dev] Crash using exceptions

Julien Lopez via llvm-dev llvm-dev at lists.llvm.org
Fri Nov 22 04:12:13 PST 2019


Hi Lang,

Thank you for your reply. I didn't know about LLVM_ENABLE_RTTI and
LLVM_ENABLE_EH, I'll give it a try. I realized yesterday that my
minimal example doesn't actually capture the error I get in my real
application, my mistake. I'll investigate all of this and come back
with a better minimal example if I can't figure it out on my own.

Thanks again!

-- 
Julien

On Thu, 21 Nov 2019 at 21:01, Lang Hames <lhames at gmail.com> wrote:
>
> 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


More information about the llvm-dev mailing list