[LLVMdev] API design

Nick Lewycky nicholas at mxc.ca
Sun Jul 1 19:09:47 PDT 2007


Hi,

I've been running LLVM with _GLIBCXX_DEBUG (extra checks) turned on to
see what would happen, and it's been a complete disaster.

The major problem is the use of this API:

  new CallInst(V, &Args[0], Args.size());

repeated throughout LLVM. When Args is empty, Args[0] is invalid, even
if the next operation is taking the address. Trying to fix it
illustrates the depth of the problem. Here are our choices:

 - Keeping the API
  a) Detect when the vector is empty and then pass a NULL pointer. This
would require that the constructor accept a null pointer when the
argument count is zero.
  b) Add an extra element to the vector, then subtract 1 from the size.
This causes run time memory bloat.

 - Changing the API
  a) Template it to take two iterators. This causes code size bloat.
  b) Template it to take a container. This causes code size bloat.

We could also just ignore the problem. I'm not clear on what the effects
of that would be in the long term. Is this something we can expect will
be changed in C++0x?

I'd like to get the extra checks working so that they can help find our
more subtle bugs. Any idea what we should do here?

Nick Lewycky



More information about the llvm-dev mailing list