[LLVMdev] API design

Chris Lattner sabre at nondot.org
Mon Jul 2 14:26:36 PDT 2007


On Sun, 1 Jul 2007, Nick Lewycky wrote:
> 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.

Ick.

> 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.

If the count is zero, the pointer is unused.  The problem with this is 
that it would pollute the callers... :(

>  b) Add an extra element to the vector, then subtract 1 from the size.
> This causes run time memory bloat.

yuck. :(

> - 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.

'b' also prevents many important uses, like passing in a subset of a 
container.

> 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 don't think that this issue causes any problems in practice.  The 
biggest bad thing is that it makes the extra checking code apparently 
useless :(

> 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?

I don't really have a good idea, but I also don't want to significantly 
uglify the sourcebase...

-Chris

-- 
http://nondot.org/sabre/
http://llvm.org/



More information about the llvm-dev mailing list