SVF-tools / SVF

Static Value-Flow Analysis Framework for Source Code
http://svf-tools.github.io/SVF/
Other
1.35k stars 430 forks source link

Question on usage of pointer analysis #148

Open ktran opened 4 years ago

ktran commented 4 years ago

Hi!

Thanks for sharing and maintaining such a great project!

I'm trying to use Andersen's analysis (DiffWave) in order to find aliases between pointer operands. Now there are obvious aliases that I cannot be able to detect, and I highly suspect that I'm just using the analysis in a wrong way. I've read related issues and have been debugging but I didn't get to the correct alias info yet, so I figured it might be faster to ask you directly.

This is an excerpt of the piece of code I'm currently analyzing:

  %76 = load %"class.soplex::SVector"**, %"class.soplex::SVector"*** %data.i109, align 8, !dbg !4458
  %arrayidx.i111 = getelementptr inbounds %"class.soplex::SVector"*, %"class.soplex::SVector"** %76, i64 %idxprom.i149, !dbg !4458
  store %"class.soplex::SVector"* %cond-lvalue.i141, %"class.soplex::SVector"** %arrayidx.i111, align 8, !dbg !4459
// .. some irrelevant code (debug info and ++i) ..
  %77 = load %"class.soplex::SVector"**, %"class.soplex::SVector"*** %data.i109, align 8, !dbg !4464
  %arrayidx.i108 = getelementptr inbounds %"class.soplex::SVector"*, %"class.soplex::SVector"** %77, i64 %idxprom.i149, !dbg !4464
  %78 = load %"class.soplex::SVector"*, %"class.soplex::SVector"** %arrayidx.i108, align 8, !dbg !4465

The store and the load to %78 should clearly alias, since the store is updating the value that is loaded afterwards. However, I always get NoAlias.

I'm using Andersen in the following way, using it with opt and the -ander flag on my LLVM IR:

WPAPass *wpa = new WPAPass();
wpa->runOnModule(&M);
Value *LPointer = Load->getPointerOperand();
Value *SPointer = Store->getPointerOperand();
wpa->alias(LPointer, SPointer) // always gives me NoAlias

I plotted the PAG and it is reflected there that they are linked to each other (see pag here). Looking at their (LPointer, SPointer) points-to-set (given the node ids in the pag) they are completely empty.

What am I doing wrong?

I'm currently using the latest version of SVF on LLVM 8.0 (I made a few syntactical changes to be updated to the latest LLVM, not anything more than that). I saw that the DominanceFrontier is used in some tools, which doesn't exist in the latest LLVM anymore, but I'm only using the PointerAnalysis itself, which shouldn't be affected.

Best,

Kim

yuleisui commented 4 years ago

May I have a look at your C test case?

Alternatively, you can also test the alias results via a stub function "MAYALIAS(p,q)" in your code when running SVF's analysis.

Please see : https://github.com/SVF-tools/PTABen/blob/master/basic_c_tests/CI-global.c

ktran commented 4 years ago

Thanks for your quick answer! The code is from a bigger benchmark (450.soplex), but the relevant lines are here:

         matrix[j] = &theLP->vector(id); // store
         nzCount += matrix[j++]->size(); // load of matrix[j]

But unfortunately it's not a small test case, if that is what you wanted. I'll have a look at the MAYALIAS stub, and will get back to you!