How can I call AAResults::getModRefInfo in module pass

Hi,

I' m writing a module pass with LLVM 7.0.0.

I want to use AAResults::getModRefInfo(const Instruction *I, const Optional<MemoryLocation> &OptLoc) to check if somes instructions may write the specified memory location in my module pass.

So in getAnalyisisUsage function of my pass I have:

AU\.addRequired&lt;llvm::AAResultsWrapperPass&gt;\(\);

AU\.addRequired&lt;llvm::DominatorTreeWrapperPass&gt;\(\);

AU\.addRequired&lt;llvm::TargetLibraryInfoWrapperPass&gt;\(\);

And I get the AAResults by

AAResults&amp; AA = getAnalysis&lt;AAResultsWrapperPass&gt;\(\*I\-&gt;getFunction\(\)\)\.getAAResults\(\);

In the main function I define a legacy::PassManager, and I do this

PassRegistry &amp;Registry = \*PassRegistry::getPassRegistry\(\);

initializeCore\(Registry\);

initializeScalarOpts\(Registry\);

initializeIPO\(Registry\);

initializeAnalysis\(Registry\);

initializeTransformUtils\(Registry\);

initializeInstCombine\(Registry\);

initializeInstrumentation\(Registry\);

initializeTarget\(Registry\);

Then I call

Passes\.add\(new MyModulePass\(\)\);

Passes\.run\(M\);

However I get a segmentation fault when AAResults::getModRefInfo() encounters a StoreInst.

Could you please tell me if there is something that I’m doing wrong?

Thanks.

Hi,

bottom line, AA in ModulePasses is broken. I’m not completely sure what causes your particular error, even if it would not crash, you probably would not get the expected results. The reason is that analysis groups (like AliasAnalysis) do not work with ad-hoc passes (like what you get when calling getAnalysis with an argument).

Have you tried your code on llvm 8 or trunk?

All of this should work with the non-legacy PassManager though, so I suggest trying that out! You might encounter bugs there too, seeing that you’re on llvm 7. So I’d recommend moving to 8 or trunk for that as well!

Cheers,
Philip