[LLVMdev] use of CallInst()

me22 me22.ca at gmail.com
Wed Mar 7 09:39:05 PST 2007


On 3/7/07, Ryan M. Lefever <lefever at crhc.uiuc.edu> wrote:
> Doesn't the code above make an assumption about how std::vector is
> implemented?  If ArgVec is defined as
>
> std::vector<Value*> ArgVec;
>
> then &ArgVec[0] returns a Value**.  Let us define
>
> Value** Params = &ArgVec[0];
>
> The constructor for CallInst accesses Params using the [] operator in a
> for loop.  That should only work if the std::vector<Value*> is
> implemented using an array of Value*s.  I looked at the documentation
> for STL and did not see anything about vector being guaranteed to be
> implemented as an array.
>
As of the 2003 revision of the standard, std::vector is guaranteed to
use contiguous storage: &vec[0] + i == &vec[i] for all i in
[0,vec.size()). (See 23.2.4.1)

That said, with the complexity requirements, it'd be difficult to
implement it any other way.  And as Gordon said, there are no common
implementations that ever did it differently--and likely never were
any at all.



More information about the llvm-dev mailing list