title: Alias Analysis in LLVM
body: <p>I am trying to find the alias between a store instruction's pointer operand and function arguments. This is the code,</p>
  
  <pre><code>virtual void getAnalysisUsage(AnalysisUsage &amp;AU) const {
  
      AU.addRequiredTransitive&lt;AliasAnalysis&gt;();
      AU.addPreserved&lt;AliasAnalysis&gt;();
  }
  
  virtual bool runOnFunction(Function &amp;F) {
  
      AliasAnalysis &amp;AA = getAnalysis&lt;AliasAnalysis&gt;();
  
      for(Function::iterator i=F.begin();i!=F.end();++i){
          for(BasicBlock::iterator j=i-&gt;begin();j!=i-&gt;end();++j)
          {
              if(dyn_cast&lt;StoreInst&gt;(j)){
                  const StoreInst *SI=dyn_cast&lt;StoreInst&gt;(j);
  
                  AliasAnalysis::Location LocA = AA.getLocation(SI);
  
                  const Value *si_v= SI-&gt;getPointerOperand();
  
                  for(Function::arg_iterator k=F.arg_begin(); k!=F.arg_end();++k)
                  {
                      Value *v=dyn_cast&lt;Value&gt;(k);
  
                      AliasAnalysis::Location loc=AliasAnalysis::Location(v);
                      AliasAnalysis::AliasResult ar=AA.alias(LocA,loc);
  
                      switch(ar)
                      {
                      case 0:errs()&lt;&lt;  "NoAlias\n";
                      break;
                      ///&lt; No dependencies.
                      case 1:errs()&lt;&lt;"MayAlias\n";    ///&lt; Anything goes
                      break;
                      case 2: errs()&lt;&lt;"PartialAlias\n";///&lt; Pointers differ, but pointees overlap.
                      break;
  
                      case 3: errs()&lt;&lt;"MustAlias\n";
                      }
                 }
     }
  
     return true;
  }
  };
  }
  </code></pre>
  
  <p>But I get MayAlias result even if the store instruction's pointer operand is not referencing  the function argument. Is there something wrong with the logic? Are there any files in the LLVM source code that contain code to do something similar. Thanks:)</p>