[LLVMdev] please advise on PassManager

Kostya Serebryany kcc at google.com
Wed Oct 17 07:34:34 PDT 2012


Hello,

I've recently changed AddressSanitizer (asan) compiler pass from ModulePass
to FunctionPass and it could a bit of mayhem.

The problem is that asan FunctionPass instruments a function foo, then foo
gets inlined into bar, then bar gets instrumented
and thus the code of foo gets instrumented twice (which causes run-time
crash).
This happens only at -O0; at -O1 we get the correct order of events for
some reason (foo gets inlined, then foo and bar are instrumented).

The code looks like this:

tools/clang/lib/CodeGen/BackendUtil.cpp
  if (LangOpts.AddressSanitizer) {


    PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast,


                           addAddressSanitizerPass);


    PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,


                           addAddressSanitizerPass);


  }


lib/Transforms/IPO/PassManagerBuilder.cpp
void PassManagerBuilder::populateModulePassManager(PassManagerBase &MPM) {


  // If all optimizations are disabled, just run the always-inline pass.


  if (OptLevel == 0) {


    if (Inliner) {


      MPM.add(Inliner);


      Inliner = 0;


    }


    addExtensionsToPM(EP_EnabledOnOptLevel0, MPM);


    return;


  }

...
  if (Inliner) {


    MPM.add(Inliner);


    Inliner = 0;


  }
...
  addExtensionsToPM(EP_OptimizerLast, MPM);




At O0 we use PassManagerBuilder::EP_EnabledOnOptLevel0 insertion point, at
-O1+ we use PassManagerBuilder::EP_OptimizerLast,
but the logic looks the same.
What do I miss?

Thanks!

--kcc
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20121017/2e5a1b49/attachment.html>


More information about the llvm-dev mailing list