Exception handling in LLVM

In this recipe, we will look into the exception handling infrastructure of LLVM. We will discuss how the exception handling information looks in the IR and the intrinsic functions provided by LLVM for exception handling.

Getting ready...

You must understand how exception handling works normally and the concepts of try, catch and throw and so on. You must also have Clang and LLVM installed in your path.

How to do it…

We will take an example to describe how exception handling works in LLVM:

  1. Open a file to write down the source code, and enter the source code to test exception handling:
    $ cat eh.cpp
    class Ex1 {};
    void throw_exception(int a, int b) {
      Ex1 ex1;
      if (a > b) {
        throw ex1;
      }
    }
    
    int test_try_catch() {
      try {
     throw_exception(2, ...

Get LLVM Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.