Hi,<br><br>I want to clone a given function, and add an argument to it. I then want to add a call to that new function. I have a callInstruction CI, which I want to transform to call this new function, and to take a new argument.<br>

<br>The code I added was as follows <br><br>CI->getCalledFunction()->dump();<br> Function* DirectF = CloneFunction(CI->getCalledFunction());<br> DirectF->setName(CI->getCalledFunction()->getNameStr() + "_SPEC");<br>

 DirectF->setLinkage(GlobalValue::InternalLinkage);<br>// add the extra argument<br> new Argument(GEP->getPointerOperand()->getType(),"arg",DirectF);<br> M.getFunctionList().push_back(DirectF);<br>DirectF->dump();<br>

<br>SmallVector<Value*, 8> Args;<br>     for(unsigned j =1;j<CI->getNumOperands();j++) {<br>      Args.push_back(CI->getOperand(j));<br>}<br>//Add the extra parameter<br>Args.push_back(GEP->getPointerOperand());<br>

CallInst *CallI = CallInst::Create(DirectF,Args.begin(), Args.end(),"", CI);<br>CallI->dump();<br><br><br>But I get the following exception<br><br>  call void @point_DIRECT(i16* %tmp1324mod, i16* %tmp1322mod) nounwind<br>

<br>define internal void @point_DIRECT(i16* %x, i16* %y) nounwind {<br>entry:<br>  %xx = alloca i32                                ; <i32*> [#uses=3]<br>  %yy = alloca i32                                ; <i32*> [#uses=3]<br>

  %tmp = load %struct.MT** @mt, align 8, !dbg !1018 ; <%struct.MT*> [#uses=1]<br>  %tmp1 = icmp eq %struct.MT* %tmp, null, !dbg !1018 ; <i1> [#uses=1]<br>  br i1 %tmp1, label %return, label %bb, !dbg !1018<br>

<br>bb:                                               ; preds = %entry<br>  %tmp2 = load i16* %x, align 2, !dbg !1023       ; <i16> [#uses=1]<br>  %tmp3 = sext i16 %tmp2 to i32, !dbg !1023       ; <i32> [#uses=1]<br>

  store i32 %tmp3, i32* %xx, align 4, !dbg !1023<br>  %tmp4 = load i16* %y, align 2, !dbg !1024       ; <i16> [#uses=1]<br>  %tmp5 = sext i16 %tmp4 to i32, !dbg !1024       ; <i32> [#uses=1]<br>  store i32 %tmp5, i32* %yy, align 4, !dbg !1024<br>

  %tmp6 = load %struct.MT** @mt, align 8, !dbg !1025 ; <%struct.MT*> [#uses=1]<br>  call void @MTPoint_DIRECT(%struct.MT* %tmp6, i32* %xx, i32* %yy) nounwind<br>  %tmp8 = load i32* %xx, align 4, !dbg !1026      ; <i32> [#uses=1]<br>

  %tmp9 = trunc i32 %tmp8 to i16, !dbg !1026      ; <i16> [#uses=1]<br>  store i16 %tmp9, i16* %x, align 2, !dbg !1026<br>  %tmp10 = load i32* %yy, align 4, !dbg !1027     ; <i32> [#uses=1]<br>  %tmp11 = trunc i32 %tmp10 to i16, !dbg !1027    ; <i16> [#uses=1]<br>

  store i16 %tmp11, i16* %y, align 2, !dbg !1027<br>  ret void<br><br>return:                                           ; preds = %entry<br>  ret void<br>}<br><br><br>define internal void @point_DIRECT_SPEC(i16* %x, i16* %y, %struct.termbox* %arg) nounwind {<br>

entry:<br>  %xx = alloca i32                                ; <i32*> [#uses=3]<br>  %yy = alloca i32                                ; <i32*> [#uses=3]<br>  %tmp = load %struct.MT** @mt, align 8, !dbg !1018 ; <%struct.MT*> [#uses=1]<br>

  %tmp1 = icmp eq %struct.MT* %tmp, null, !dbg !1018 ; <i1> [#uses=1]<br>  br i1 %tmp1, label %return, label %bb, !dbg !1018<br><br>bb:                                               ; preds = %entry<br>  %tmp2 = load i16* %x, align 2, !dbg !1023       ; <i16> [#uses=1]<br>

  %tmp3 = sext i16 %tmp2 to i32, !dbg !1023       ; <i32> [#uses=1]<br>  store i32 %tmp3, i32* %xx, align 4, !dbg !1023<br>  %tmp4 = load i16* %y, align 2, !dbg !1024       ; <i16> [#uses=1]<br>  %tmp5 = sext i16 %tmp4 to i32, !dbg !1024       ; <i32> [#uses=1]<br>

  store i32 %tmp5, i32* %yy, align 4, !dbg !1024<br>  %tmp6 = load %struct.MT** @mt, align 8, !dbg !1025 ; <%struct.MT*> [#uses=1]<br>  call void @MTPoint_DIRECT(%struct.MT* %tmp6, i32* %xx, i32* %yy) nounwind<br>  %tmp8 = load i32* %xx, align 4, !dbg !1026      ; <i32> [#uses=1]<br>

  %tmp9 = trunc i32 %tmp8 to i16, !dbg !1026      ; <i16> [#uses=1]<br>  store i16 %tmp9, i16* %x, align 2, !dbg !1026<br>  %tmp10 = load i32* %yy, align 4, !dbg !1027     ; <i32> [#uses=1]<br>  %tmp11 = trunc i32 %tmp10 to i16, !dbg !1027    ; <i16> [#uses=1]<br>

  store i16 %tmp11, i16* %y, align 2, !dbg !1027<br>  ret void<br><br>return:                                           ; preds = %entry<br>  ret void<br>}<br><br>opt: /home/vadve/aggarwa4/llvm27/llvm-2.7/lib/VMCore/Instructions.cpp:307: void llvm::CallInst::init(llvm::Value*, llvm::Value* const*, unsigned int): Assertion `(NumParams == FTy->getNumParams() || (FTy->isVarArg() && NumParams > FTy->getNumParams())) && "Calling a function with bad signature!"' failed.<br>

<br><br>When I looked at the excption, it occurs when creating the CallInst.<br><br>The type of the function being called at that point is still the old type, without the extra parameter, though the extra parameter seems to have been added when I dump DirectF.<br>

<br>Can I get any pointers to what I am doing wrong, and what might be a potential solution.<br><br>Thanks,<br>Arushi<br>