[LLVMdev] How to halt a program

Victor Campos victorsc at dcc.ufmg.br
Fri Aug 19 05:27:12 PDT 2011


Guys,

    I would like to instrument the bytecode that LLVM produces with
assertions. I have written the instrumentation code manually, but I do not
know how to halt the program in case the assertion is false. I took a look
into the bytecode that LLVM produces for a program like:

#include <stdlib.h>
int main() {
  exit(1);
}

And it is like this:

define i32 @main() nounwind {
entry:
  %retval = alloca i32                            ; <i32*> [#uses=1]
  %0 = alloca i32                                 ; <i32*> [#uses=0]
  %"alloca point" = bitcast i32 0 to i32          ; <i32> [#uses=0]
  call void @exit(i32 1) noreturn nounwind
  unreachable
return:                                           ; No predecessors!
  %retval1 = load i32* %retval                    ; <i32> [#uses=1]
  ret i32 %retval1
}

So, what is the LLVM code to insert the call "call void @exit(i32 1)
noreturn nounwind"? I thought about something like:

CallInst *abort = CallInst::Create(/*POINTER TO ABORT*/, ArrayRef<Value*>(),
Twine(), assertfail);
abort->addAttribute(~0, Attribute::NoReturn);
abort->addAttribute(~0, Attribute::NoUnwind);

However, I do not know what to fill up in /*POINTER TO ABORT*/. Can anyone
help me?

Thank you very much,

Victor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110819/e3dcf414/attachment.html>


More information about the llvm-dev mailing list