[PATCH] D105201: [hwasan] Detect use after scope within function.

Vitaly Buka via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 23 10:37:35 PDT 2021


vitalybuka added a comment.

In D105201#2899455 <https://reviews.llvm.org/D105201#2899455>, @fmayer wrote:

> In D105201#2898812 <https://reviews.llvm.org/D105201#2898812>, @vitalybuka wrote:
>
>> maybe this lazy Tree construction?
>
> This change doesn't preserve the property that Evgenii mentioned in the comment thread about this. In Aarch64StackTagging this is done in the way it was in this change before to avoid running the analysis on the whole module if not all of the functions actually need to be instrumented. In general I think it would be nice to have the AArch64StackTagging and this implementation as close as possible, that makes it easier to reason about and I am planning to refactor this a bit to factor out the common pieces down the line.

Reasons not to optimize:

1. AArch64StackTagging is different. AArch64StackTagging is added always for aarch64, so it can compile modules where almost all functions have no attribute.

However HWAddressSanitizerLegacyPass one added only for stuff compiler with -fsanitizer=hwaddres, so almost everything will have this attribute.

2. For new PM llvm::function does exactly as you like and even better, it will avoid DT for empty AllocasToInstrument, and legacy PM is deprecated and will be removed.

If you still want optimize even legacy PM:
This stuff is Pass specific, but HWAddressSanitizer class is not a pass, it's a tool used by Pass, so it's more reasonable to have this optimization inside of HWAddressSanitizerLegacyPass.
E.g.:

  bool runOnFunction(Function &F) override {
      auto TargetTriple = Triple(F.getParent()->getTargetTriple());
      if (shouldUseStackSafetyAnalysis(TargetTriple, DisableOptimization)) {
        // We cannot call getAnalysis in doInitialization, that would cause a
        // crash as the required analyses are not initialized yet.
        HWASan->setSSI(
            &getAnalysis<StackSafetyGlobalInfoWrapperPass>().getResult());
      }
      std::unique_ptr<DominatorTree> DeleteDT;
      std::unique_ptr<PostDominatorTree> DeletePDT;
      return HWASan->sanitizeFunction(
          F,
          [&]() -> const DominatorTree & {
            if (auto *P = getAnalysisIfAvailable<DominatorTreeWrapperPass>())
              return P->getDomTree();
            if (!DeleteDT)
              DeleteDT = std::make_unique<DominatorTree>(F);
            return *DeleteDT;
          },
          [&]() -> const PostDominatorTree & {
            if (auto *P = getAnalysisIfAvailable<PostDominatorTreeWrapperPass>())
              return P->getPostDomTree();
            if (!DeletePDT)
              DeletePDT = std::make_unique<PostDominatorTree>(F);
            return *DeletePDT;
          });
    }
  
  # AU.addRequired<>() -> AU.addUsedIfAvailable<>();
  # And you need to keep INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass) INITIALIZE_PASS_DEPENDENCY(PostDominatorTreeWrapperPass) either way


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105201/new/

https://reviews.llvm.org/D105201



More information about the llvm-commits mailing list