Dynamic Creation of a simple program

Hi Misha,

Thanks for your answer

I was doing this:

Please post the assertion failure and/or backtrace, or alternatively,
send me your code offline.

I was doing this:

  BasicBlock *BBlock = new BasicBlock("entry", MyFunc);
  Value *Zero = ConstantSInt::get(Type::IntTy, 0);
  Value *UZero = ConstantUInt::get(Type::UIntTy, 0);

  MallocInst* mi = new MallocInst( STyStru );
  BBlock->getInstList().push_back( mi );
  GetElementPtrInst *m_Next = new GetElementPtrInst(mi, UZero, Zero, "tmp.3", BBlock );

Here's the issue: you flipped the order of the signed/unsigned indices.
The first index is signed, it's for addressing into arrays, the second
is the one addressing into structure elements, and must be unsigned, so
you want to do this:

GetElementPtrInst *m_Next =
  new GetElementPtrInst(mi, Zero, UZero, "tmp.3", BBlock );

The getelementptr docs have a good explanation of this and examples of
what you're trying to do:


But I tried your code instead of the lines above:

GetElementPtrInst *GEP =
  new GetElementPtrInst(mi, // %tmp.0
                        ConstantSInt::get(Type::IntTy, 0),
                        ConstantUInt::get(Type::UIntTy, 1),
                        "tmp.3", BBlock);

My code was trying to parallel what you want your target output to be,
and it did not work because your resulting type is { \2 * }, you forgot
to include the integer as the first element, so '1' is not a valid index
into that structure. Adding the int type into the struct makes it work
for me.