correct way to pass data structures between passes?

Hi all,
I have a function pass which does some analysis and populates

A a;

where

typedef std::map< std::string, B* > A;

class B {
typedef std::vector< C* > D;
D d;
}

class C {
// some class packing information about basic blocks;
}

Hence I have a map of vectors traversed by string.
I wrote associated destructors for these classes. This pass works successfully on its own.

I have another function pass needing this structure of type A to make some transformations. I used

bool secondPass::doInitialization(Module &M) {
errs() << “now running secondPass\n”;
a = getAnalysis().getA();

return false;
}

void secondPass::getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired();
AU.setPreservesAll();
}

the whole code compiles fine. But I get seg. fault when printing this structure at the end of my first pass if I call my second pass since B* is null.

How should I wrap this data structure and pass it to the second pass without issues?

Thanks in advance.

Hi all,
I have a function pass which does some analysis and populates

A a;

where

typedef std::map< std::string, B* > A;

class B {
typedef std::vector< C* > D;
D d;
}

class C {
// some class packing information about basic blocks;
}

Hence I have a map of vectors traversed by string.
I wrote associated destructors for these classes. This pass works successfully on its own.

I have another function pass needing this structure of type A to make some transformations. I used

bool secondPass::doInitialization(Module &M) {
errs() << “now running secondPass\n”;
a = getAnalysis().getA();

You probably shouldn’t call getAnalysis in doInitialization. doInitialization, according to the document, “is designed to do simple stuff not depend on the functions begin processed”.
You should call getAnalysis in runOnFunction.

return false;
}

void secondPass::getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired();
AU.setPreservesAll();
}

the whole code compiles fine. But I get seg. fault when printing this structure at the end of my first pass if I call my second pass since B* is null.

Have you checked(set a breakpoint for example) to see if firstPass::runOnFunction is executed?

How should I wrap this data structure and pass it to the second pass without issues?

Thanks in advance.

Best,
Bekket