<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<body bgcolor="#ffffff" text="#000000">
I noticed a strange behavior when a non-prototyped user-defined
function is called.<br>
<br>
E.g. for the following test.c code segment:<br>
<br>
void foo(void);<br>
void bar(void);<br>
<br>
void foo(void){<br>
bar();<br>
}<br>
<br>
void bar(void){<br>
printf("inside bar()");<br>
}<br>
<br>
<br>
LLVM-GCC 2.7 -O0 will generate the following code for foo(), which
is all fine.<br>
<br>
define void @foo() nounwind {<br>
entry:<br>
<font color="#006600"><b> call void @bar() nounwind</b></font><br>
br label %return<br>
<br>
return: ; preds = %entry<br>
ret void<br>
}<br>
<br>
However, if I comment out the first 2 lines (the prototype
declarations), llvm-gcc will generate the following code for foo()
instead:<br>
define void @foo() nounwind {<br>
entry:<br>
<font color="#ff0000"><big> %0 = call i32 (...)* bitcast (void ()*
@bar to i32 (...)*)() nounwind ; <i32> [#uses=0]</big></font><br>
br label %return<br>
<br>
return: ; preds = %entry<br>
ret void<br>
}<br>
<br>
Notice there is now a bitcast operator embedded inside the call
instruction.<br>
<br>
The problem, however, is that the 2nd flavor of LLVM IR breaks my
code, which tries to detect all Call Instructions inside all
Functions:<br>
...<br>
if (BitCastInst *BCI = dyn_cast<BitCastInst>(II)){<br>
errs() <<"find BitCastInst\n";<br>
...<br>
}<br>
<br>
if (CallInst *CI = dyn_cast<CallInst>(II)){<br>
errs() <<"find CallInst\n";<br>
...<br>
}<br>
...<br>
<br>
As a result, neither of the above two cases can trigger.<br>
<br>
I am asking how I can detect all such function calls as CallInsts.<br>
<br>
Thank you very much<br>
<br>
Chuck<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
</body>
</html>