title: Is there LLVM API for setting funclet operand bundle in LLVM/MSVC exception handling?
body: <p>I'm using LLVM 3.9.1 Core libraries in implementation of a compiler front-end that targets Windows x64. I'm currently implementing exception handling.</p>
  
  <p>For Windows x64 target LLVM generates so called funclets for catch and clean-up code. To catch an exception you generate a catchswitch instruction and then a catchpad instruction for each exception type caught:</p>
  
  <pre><code>...
  catchsection0:                                    ; preds = %entry
    %8 = catchswitch within none [label %catch0] unwind to caller
  
  catch0:                                           ; preds = %catchsection0
    %9 = catchpad within %8 [i8** @exceptionClassDescriptor", i32 8, i8** %1]
    %10 = load i8*, i8** %1
    br label %target10
  
  target10:                                         ; preds = %catch0
    %11 = load i8*, i8** @__CD0
    %12 = call i1 @RtHandleException(i8* %10, i8* %11) [ "funclet"(token %9) ]
    br i1 %12, label %thisHandlerTarget10, label %nextHandlerTarget10
  ...
  </code></pre>
  
  <p>In order to call a function in a catch-block you need to set a funclet operand bundle for the call instruction passing the token returned by the catchpad instruction as argument:</p>
  
  <pre><code>%12 = call i1 @RtHandleException(i8* %10, i8* %11) [ "funclet"(token %9) ]
  </code></pre>
  
  <p>I have tried to search from the LLVM doxygen documentation and through the LLVM library source code for an API how to set the funclet operand bundle for the call or invoke instruction but without any success.</p>
  
  <p>Does anyone know how to create an operand bundle and set it to the call instruction?</p>
  
  <hr>
  
  <p>I found a solution that was simpler than I thought:
  CallInst::Create and InvokeInst::Create instructions have overloads that take vector/array of OperandBundleDef as arguments. Problem solved.</p>
  
  <p>Seppo</p>