[LLVMdev] Using asserts in LLVM
Nadav Rotem
nadav256 at gmail.com
Wed Jun 18 10:50:53 PDT 2008
Hello,
I am testing the new cool LLVM python bindings that Mahadevan wrote over
the past few weeks. I came across a problem in the python binding which
directed me to use of 'cassert'[1] in LLVM itself.
When LLVM users make a mistake in using the library's constructs they
usually hit an assertion. This form of defensive programming is great
for detecting errors as soon as they happen, especially in c++.
However, when I use the python bindings and hit an assertion, I get
kicked out of my shell (which sucks). For example:
>>> Type.function(Type.void(), [Type.void()])
Type.cpp:474: llvm::FunctionType::FunctionType(const llvm::Type*, const
std::vector<const llvm::Type*, std::allocator<const llvm::Type*> >&,
bool): Assertion `(Params[i]->isFirstClassType() ||
isa<OpaqueType>(Params[i])) && "Function arguments must be value
types!"' failed.
Aborted (core dumped)
I would like LLVM to raise an exception which the python wrapper could
catch and pass to my program. I know that the current LLVM code does not
use exceptions. Also, the current stl "cassert.h" implementation is sufficient
for 99% of the developers which write C++ code. One way of solving this is to
rewrite all of the asserts in Python before calling the C++ code. This means
duplication of a ton of code. Another way would be to get around this is to
place a hook over 'abort' in runtime. This is ugly as sin and may not always work.
Would you consider changing the implementation of 'assert' so that it
would throw exceptions rather then abort the program ?
Thank you,
Nadav
1: http://www.ishiboo.com/~nirva/c++/stl-ref/assert.html
More information about the llvm-dev
mailing list