error in InsertElementInst

Hello everybody,

What I am trying to do is to create a vector <4 x i32> and save some values to initialize the vector.
However, I am using the insertElementInst() and the errors I get are the following;

error: within this context
Instruction Insert = new InsertElementInst(instr, emptyVec, index0, “test”);
error: ‘llvm::InsertElementInst::InsertElementInst(llvm::Value
, llvm::Value*, llvm::Value*, const llvm::Twine&, llvm::Instruction*)’ is private

The code I have used is the following:
Type *Instr_vector = VectorType::get(Int32, 4);
Value emptyVec = UndefValue::get(Instr_vector);
index0 = Constant::getIntegerValue(u32Ty, llvm::APInt(32, 0));
Instruction *Insert = new InsertElementInst(instr, emptyVec, index0, “test”);
b->getInstList().insertAfter(Xor_flip, Insert);

Do you have any suggestions for these errors?
Thanks in Advance,

Hi Vasilis,

Do you have any suggestions for these errors?

It looks like the constructor is private to make sure the type of the
vector and the overall instruction match up properly. You should use
InsertElementInst::Create instead (see

Actually, it's usually better to create your instructions using the
IRBuilder class rather than directly. It handles inserting them into a
basic block more conveniently, and smooths out some of the differences
between various instructions (like this one).



Hello Tim,

Thanks for the help, just a silly mistake...It works now perfectly!