<div dir="ltr">Thanks,Cheers!<div><br></div><div>I found the problem is that the "Function *call_print" using the same name as the “class call_print”, which made the compiler wrongly resolved the call_print type!</div>
<div><br></div><div>But I got another problems. I successfully compile the pass and I can insert the call printf (C Lib function) instructions in the LLVM IR(eg: call.bc).  If the call.bc didn't contain call printf instruction ,I can call printf successfully ,but if not ,there exists a problem. the llvm will rename my inserted call function , and the transformed code can not run correctly!</div>
<div><br></div><div>the original .bc file:</div><div><br></div><div><div>; ModuleID = 'call.bc'</div><div>target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"</div>
<div>target triple = "x86_64-unknown-linux-gnu"</div><div><br></div><div>@.str = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 1</div><div><br></div><div>; Function Attrs: nounwind uwtable</div>
<div>define i32 @main() #0 {</div><div>entry:</div><div>  %retval = alloca i32, align 4</div><div>  %a = alloca i32, align 4</div><div>  store i32 0, i32* %retval</div><div>  store i32 3, i32* %a, align 4</div><div>  %0 = load i32* %a, align 4</div>
<div>  %call = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([4 x i8]* @.str, i32 0, i32 0), i32 %0)</div><div>  %1 = load i32* %a, align 4</div><div>  ret i32 %1</div><div>}</div><div><br></div><div>//contains call printf</div>
<div>declare i32 @printf(i8*, ...) #1 </div><div><br></div><div>attributes #0 = { nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf"="true" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "unsafe-fp-math"="false" "use-soft-float"="false" }</div>
<div>attributes #1 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf"="true" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "unsafe-fp-math"="false" "use-soft-float"="false" }</div>
</div><div><br></div><div>here is the .bc file that I get after the transform:</div><div><br></div><div><div>; ModuleID = 'call.opt.bc'</div><div>target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"</div>
<div>target triple = "x86_64-unknown-linux-gnu"</div><div><br></div><div>@.str = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 1</div><div>@.str2 = private constant [4 x i8] c"%d\0A\00"    </div>
<div><br></div><div>; Function Attrs: nounwind uwtable</div><div>define i32 @main() #0 {</div><div>entry:</div><div>  %retval = alloca i32, align 4</div><div>  %a = alloca i32, align 4</div><div>  store i32 0, i32* %retval</div>
<div>  // this is the instruction that I inserted ,which calls a C Lib "printf"</div><div>  %0 = call i32 (i8*, ...)* @printf1(i8* getelementptr inbounds ([4 x i8]* @.str2, i32 0, i32 0), i32 2)</div><div>  store i32 3, i32* %a, align 4</div>
<div>  %1 = load i32* %a, align 4</div><div>  %call = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([4 x i8]* @.str, i32 0, i32 0), i32 %1)</div><div>  %2 = load i32* %a, align 4</div><div>  ret i32 %2</div><div>
}</div><div><br></div><div>declare i32 @printf(i8*, ...) #1</div><div><br></div><div>// if the program didn't contain call printf instruction ,this declaration should be as the one above,but now it was renamed and can not be resolved </div>
<div>declare i32 @printf1(i8*, ...)</div><div><br></div><div>attributes #0 = { nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf"="true" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "unsafe-fp-math"="false" "use-soft-float"="false" }</div>
<div>attributes #1 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf"="true" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "unsafe-fp-math"="false" "use-soft-float"="false" }</div>
</div><div><br></div><div>Is there any method to avoid the rename manipulation ?</div><div>Thanks!</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/12/16 Tim Northover <span dir="ltr"><<a href="mailto:t.p.northover@gmail.com" target="_blank">t.p.northover@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Jin,<br>
<br>
It's difficult to say just from looking at a pass, but one thing looked odd:<br>
<div class="im"><br>
> CallInst *call_print = CallInst::Create(call_print,paramArrayRef,"",ins_temp);<br>
<br>
</div>This looks very dodgy. The "call_print" being used as an argument is<br>
the (uninitialised) one that's just been declared. This could be the<br>
source of the assertion failure (though a segfault is just as likely).<br>
<br>
Other than that I'd suggest hooking up a debugger and going up the<br>
call frames when that assertion hits. That should tell you exactly<br>
which line of your pass is causing trouble.<br>
<br>
Cheers.<br>
<span class="HOEnZb"><font color="#888888"><br>
Tim.<br>
</font></span></blockquote></div><br></div>