Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assertion triggered after modifying code #12

Closed
ktran opened this issue Mar 20, 2017 · 2 comments
Closed

Assertion triggered after modifying code #12

ktran opened this issue Mar 20, 2017 · 2 comments
Labels

Comments

@ktran
Copy link

ktran commented Mar 20, 2017

Hello!

I'm currently using the SVF analysis for a project and I run into an issue using the analysis
for newly inserted instructions. In short, I get the following error whenever I try to check
whether the newly inserted instruction (AllocaInst) aliases with another value :

SVF/include/MemoryModel/MemModel.h:554:
SymID SymbolTableInfo::getValSym(const llvm::Value*): Assertion `iter!=valSymMap.end() &&"value sym not found"' failed.

Below is a test pass that should throw this error for any loop containing a load.
Weirdly, this only happens if I compile Svf & the pass in Debug mode, but not if I build it in
MinSizeRel mode.

In general I believe that I need to update the pointer analysis after having modified the code, however, I'm not sure how to properly update the analysis. The test pass below contains some of my failed trials of naively re-running it (see commented lines).

What I am doing wrong? How do I properly update/re-run the analysis? And, do you know why this is
only happening if compiled in Debug mode?

#include "llvm/Analysis/LoopPass.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/IR/IRBuilder.h"

#include "MemoryModel/PointerAnalysis.h"
#include "WPA/Andersen.h"

using namespace llvm;

namespace {
  struct TestSvf : public LoopPass {
    static char ID;

    TestSvf() : LoopPass(ID) {}

    virtual void getAnalysisUsage(AnalysisUsage &AU) const {
      AU.addRequired<LoopInfoWrapperPass>();
    }
    virtual bool runOnLoop(Loop *L, LPPassManager &LPM);
  };
}

bool TestSvf::runOnLoop(Loop *L, LPPassManager &LPM) {
  // Create AA before changing loop
  Module &M = *L->getHeader()->getParent()->getParent();
  AndersenWaveDiff *AA = AndersenWaveDiff::createAndersenWaveDiff(M);

  // Change loop: add an alloca instruction
  BasicBlock *H = L->getHeader();
  IRBuilder<> Builder(&*(H->getFirstInsertionPt()));
  AllocaInst *Alloca = Builder.CreateAlloca(Type::getInt1Ty(getGlobalContext()), 0, "test_alloca");

  // Try to recalculate AA
  // 1st try: AA->analyze(M);

  // 2nd try:
  // AndersenWaveDiff::releaseAndersenWaveDiff();
  // AA = AndersenWaveDiff::createAndersenWaveDiff(M);

  // 3rd try: 
  // delete(AA);
  // AA = AndersenWaveDiff::createAndersenWaveDiff(M);

  
  // Find first load in loop
  for (BasicBlock *BB : L->getBlocks()) {
    for (Instruction &I : *BB) {
      if (LoadInst *Load = dyn_cast<LoadInst>(&I)) {
	Value *LoadedVal = Load->getPointerOperand();

	// Check AA information between loaded value & alloca instruction
	// throws error
	errs() << AA->alias(Alloca, LoadedVal) << "\n";
      }
    }
  }
    
  return false;
}

char TestSvf::ID = 0;
static RegisterPass<TestSvf> X("test-svf", "TestSvf_pass", false, true);
@yuleisui
Copy link
Collaborator

yuleisui commented Mar 20, 2017

Hi Kim,

Thanks for your question.

SVF does not support incremental recalculation at this stage. PAG will keep the same even if the analysis analysis is released or deleted. I would strongly suggest you separate the instrumentation as an additional pass. You may wish to first generate the instrumented bc code and analyze the new bc again by SVF.

For example:
example.bc ====> Andersen + your instrumentation ====> example.bc.wpa ====> Andersen/Flow-sensitive analysis

You can also use llvm metadata/annotation (please refer to "llvm/IR/Metadata.h") to mark the newly instrumented instructions for your alias queries in your later passes.

Separating instrumentations from analyses will also make you code base clean.

Good luck!

@ktran
Copy link
Author

ktran commented Mar 21, 2017

Hi Yulei,

I see - ok, thanks a lot for the quick reply and the suggestion!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants