[LLVMdev] incorrect DSCallGraph for simple indirect call with vtable nearby

Ben Liblit liblit at cs.wisc.edu
Thu Aug 11 09:10:43 PDT 2011


I wrote:
> I'll keep poking at this some more and let you folks know if I hit any other surprises.

Well, that didn't take long.  :-)  I have found two new surprises in 
DSCallGraph as built by TDDataStructures.  Consider the following 
program, which is complete and self-contained and which has one simple 
indirect call site:

	volatile int unknown;

	static void red() { }
	static void blue() { }

	int main()
	{
	  (unknown ? red : blue)();
	  return 0;
	}

If I save this as "test.c", compile it with clang, and run my 
ShowCallGraph testing pass, DSCallGraph lists *zero* callees and claims 
that its results for the indirect call site are incomplete.  Why is it 
unable to identify the two (seemingly-obvious) callees in this case? 
The bitcode generated for this call looks like:

     %7 = phi void (...)* [ bitcast (void ()* @red to void (...)*), %4 ],
                          [ bitcast (void ()* @blue to void (...)*), %5 ]
     call void (...)* %7()

If I save this same program as "test.cpp", compile it with clang, and 
run my ShowCallGraph testing pass, DSCallGraph correctly lists both 
red() and blue() as possible callees.  However, it still claims that its 
results are incomplete.  Why doesn't it know that its callee set is 
complete here?  The bitcode generated for this call is slightly 
different than for "test.c".  Here it looks like:

     %7 = phi void ()* [ @_Z3redv, %4 ], [ @_Z4bluev, %5 ]
     call void %7()

I would have expected any analysis to give the same results for either 
version of the bitcode: callee set is {red, blue} and this answer is 
complete.  What's going wrong here?

Attached below is an updated copy of my "ShowCallGraph.cpp" pass.  It 
now uses TDDataStructures (instead of EQTDDataStructures) and prints an 
additional line of output identifying incomplete callee sets.

Thanks for any hints,
Ben
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ShowCallGraph.cpp
Type: text/x-c++src
Size: 1536 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110811/66060862/attachment.cpp>


More information about the llvm-dev mailing list