[llvm] r344274 - [PassManager/Sanitizer] Port of AddresSanitizer pass from legacy to new PassManager

Leonard Chan via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 16 16:47:33 PDT 2018


I created a patch that has the fix and added you as a reviewer:
https://reviews.llvm.org/D53350

This should fix all of the tests related to ASan, but I'm still unsure
about the remaining failing tests. For me, building with your cmake
invocation, I ended up with the following 18 errors:

   Clang :: CodeGen/address-safety-attr-flavors.cpp
    Clang :: CodeGen/address-safety-attr.cpp
    Clang :: CodeGen/address-sanitizer-and-array-cookie.cpp
    Clang :: CodeGen/asan-globals-gc.cpp
    Clang :: CodeGen/asan-globals.cpp
    Clang :: CodeGen/asan-no-globals-no-comdat.cpp
    Clang :: CodeGen/atomic_ops.c
    Clang :: CodeGen/lifetime-asan.c
    Clang :: CodeGen/sanitize-address-field-padding.cpp
    Clang :: CodeGen/sanitize-init-order.cpp
    Clang :: CodeGenCXX/catch-undef-behavior.cpp
    Clang :: CodeGenCXX/finegrain-bitfield-access.cpp
    Clang :: CodeGenCXX/lifetime-asan.cpp
    Clang :: CodeGenObjC/illegal-UTF8.m
    Clang :: CodeGenObjC/no-sanitize.m
    Clang :: CodeGenObjCXX/address-safety-attr.mm
    Clang :: Driver/asan.c
    LLVM :: Bindings/Go/go.test

of which, I was able to fix 15 with the fix in the patch. Although these 3,

    Clang :: CodeGen/atomic_ops.c
    Clang :: CodeGenObjC/illegal-UTF8.m
    LLVM :: Bindings/Go/go.test

are still broken. I don't think they have to do with my ASan patch,
but I'll still look into them for a bit.

- Leonard
On Tue, Oct 16, 2018 at 2:35 PM Leonard Chan <leonardchan at google.com> wrote:
>
> I will take a look. Thanks for bringing this up.
>
> - Leonard
> On Tue, Oct 16, 2018 at 2:21 PM <douglas.yung at sony.com> wrote:
> >
> > Hi Leonard,
> >
> > I encountered some test issues after attempting to build/test your changes on my local machine. I built on my linux machine your change with an ARM target and hit the following failure in multiple tests:
> >
> > FAIL: Clang :: CodeGen/address-safety-attr-flavors.cpp (5007 of 42408)
> > ******************** TEST 'Clang :: CodeGen/address-safety-attr-flavors.cpp' FAILED ********************
> > Script:
> > --
> > : 'RUN: at line 8';   /home/dyung/src/upstream/344274-linux-arm/bin/clang -cc1 -internal-isystem /home/dyung/src/upstream/344274-linux-arm/lib/clang/8.0.0/include -nostdsysteminc -triple i386-unknown-linux -disable-O0-optnone    -emit-llvm -o - /home/dyung/src/upstream/llvm_clean/tools/clang/test/CodeGen/address-safety-attr-flavors.cpp | /home/dyung/src/upstream/344274-linux-arm/bin/FileCheck -check-prefix=CHECK-NOASAN /home/dyung/src/upstream/llvm_clean/tools/clang/test/CodeGen/address-safety-attr-flavors.cpp
> > : 'RUN: at line 11';   /home/dyung/src/upstream/344274-linux-arm/bin/clang -cc1 -internal-isystem /home/dyung/src/upstream/344274-linux-arm/lib/clang/8.0.0/include -nostdsysteminc -triple i386-unknown-linux -fsanitize=address    -disable-O0-optnone -emit-llvm -o - /home/dyung/src/upstream/llvm_clean/tools/clang/test/CodeGen/address-safety-attr-flavors.cpp |    /home/dyung/src/upstream/344274-linux-arm/bin/FileCheck -check-prefix=CHECK-ASAN /home/dyung/src/upstream/llvm_clean/tools/clang/test/CodeGen/address-safety-attr-flavors.cpp
> > : 'RUN: at line 15';   /home/dyung/src/upstream/344274-linux-arm/bin/clang -cc1 -internal-isystem /home/dyung/src/upstream/344274-linux-arm/lib/clang/8.0.0/include -nostdsysteminc -triple i386-unknown-linux -fsanitize=kernel-address    -disable-O0-optnone -emit-llvm -o - /home/dyung/src/upstream/llvm_clean/tools/clang/test/CodeGen/address-safety-attr-flavors.cpp |    /home/dyung/src/upstream/344274-linux-arm/bin/FileCheck -check-prefix=CHECK-KASAN /home/dyung/src/upstream/llvm_clean/tools/clang/test/CodeGen/address-safety-attr-flavors.cpp
> > : 'RUN: at line 19';   /home/dyung/src/upstream/344274-linux-arm/bin/clang -cc1 -internal-isystem /home/dyung/src/upstream/344274-linux-arm/lib/clang/8.0.0/include -nostdsysteminc -triple i386-unknown-linux -fsanitize=hwaddress    -disable-O0-optnone -emit-llvm -o - /home/dyung/src/upstream/llvm_clean/tools/clang/test/CodeGen/address-safety-attr-flavors.cpp |    /home/dyung/src/upstream/344274-linux-arm/bin/FileCheck -check-prefix=CHECK-HWASAN /home/dyung/src/upstream/llvm_clean/tools/clang/test/CodeGen/address-safety-attr-flavors.cpp
> > : 'RUN: at line 23';   /home/dyung/src/upstream/344274-linux-arm/bin/clang -cc1 -internal-isystem /home/dyung/src/upstream/344274-linux-arm/lib/clang/8.0.0/include -nostdsysteminc -triple i386-unknown-linux -fsanitize=kernel-hwaddress    -disable-O0-optnone -emit-llvm -o - /home/dyung/src/upstream/llvm_clean/tools/clang/test/CodeGen/address-safety-attr-flavors.cpp |    /home/dyung/src/upstream/344274-linux-arm/bin/FileCheck -check-prefix=CHECK-KHWASAN /home/dyung/src/upstream/llvm_clean/tools/clang/test/CodeGen/address-safety-attr-flavors.cpp
> > --
> > Exit Code: 2
> >
> > Command Output (stderr):
> > --
> > Pass 'AddressSanitizerFunctionPass' is not initialized.
> > Verify if there is a pass dependency cycle.
> > Required Passes:
> > clang: /home/dyung/src/upstream/llvm_clean/lib/IR/LegacyPassManager.cpp:753: void llvm::PMTopLevelManager::schedulePass(llvm::Pass *): Assertion `PI && "Expected required passes to be initialized"' failed.
> > Stack dump:
> > 0.      Program arguments: /home/dyung/src/upstream/344274-linux-arm/bin/clang -cc1 -internal-isystem /home/dyung/src/upstream/344274-linux-arm/lib/clang/8.0.0/include -nostdsysteminc -triple i386-unknown-linux -fsanitize=address -disable-O0-optnone -emit-llvm -o - /home/dyung/src/upstream/llvm_clean/tools/clang/test/CodeGen/address-safety-attr-flavors.cpp
> > 1.      <eof> parser at end of file
> > #0 0x00000000014eec94 PrintStackTraceSignalHandler(void*) (/home/dyung/src/upstream/344274-linux-arm/bin/clang+0x14eec94)
> > #1 0x00000000014ecb3e llvm::sys::RunSignalHandlers() (/home/dyung/src/upstream/344274-linux-arm/bin/clang+0x14ecb3e)
> > #2 0x00000000014eee52 SignalHandler(int) (/home/dyung/src/upstream/344274-linux-arm/bin/clang+0x14eee52)
> > #3 0x00007fb98dfb5330 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x10330)
> > #4 0x00007fb98cdadc37 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x36c37)
> > #5 0x00007fb98cdb1028 abort (/lib/x86_64-linux-gnu/libc.so.6+0x3a028)
> > #6 0x00007fb98cda6bf6 (/lib/x86_64-linux-gnu/libc.so.6+0x2fbf6)
> > #7 0x00007fb98cda6ca2 (/lib/x86_64-linux-gnu/libc.so.6+0x2fca2)
> > #8 0x0000000000fe7079 llvm::PMTopLevelManager::schedulePass(llvm::Pass*) (/home/dyung/src/upstream/344274-linux-arm/bin/clang+0xfe7079)
> > #9 0x00000000016ba2a0 addAddressSanitizerPasses(llvm::PassManagerBuilder const&, llvm::legacy::PassManagerBase&) (/home/dyung/src/upstream/344274-linux-arm/bin/clang+0x16ba2a0)
> > #10 0x0000000001fe7b9d llvm::PassManagerBuilder::addExtensionsToPM(llvm::PassManagerBuilder::ExtensionPointTy, llvm::legacy::PassManagerBase&) const (/home/dyung/src/upstream/344274-linux-arm/bin/clang+0x1fe7b9d)
> > #11 0x0000000001fe8f9f llvm::PassManagerBuilder::populateModulePassManager(llvm::legacy::PassManagerBase&) (/home/dyung/src/upstream/344274-linux-arm/bin/clang+0x1fe8f9f)
> > #12 0x00000000016ae09a clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::DataLayout const&, llvm::Module*, clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream> >) (/home/dyung/src/upstream/344274-linux-arm/bin/clang+0x16ae09a)
> > #13 0x0000000001f0b4bf clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/home/dyung/src/upstream/344274-linux-arm/bin/clang+0x1f0b4bf)
> > #14 0x000000000279e283 clang::ParseAST(clang::Sema&, bool, bool) (/home/dyung/src/upstream/344274-linux-arm/bin/clang+0x279e283)
> > #15 0x0000000001b792e0 clang::FrontendAction::Execute() (/home/dyung/src/upstream/344274-linux-arm/bin/clang+0x1b792e0)
> > #16 0x0000000001b208b1 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/dyung/src/upstream/344274-linux-arm/bin/clang+0x1b208b1)
> > #17 0x0000000001c19ca9 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/dyung/src/upstream/344274-linux-arm/bin/clang+0x1c19ca9)
> > #18 0x00000000007efbe2 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/dyung/src/upstream/344274-linux-arm/bin/clang+0x7efbe2)
> > #19 0x00000000007ed57a main (/home/dyung/src/upstream/344274-linux-arm/bin/clang+0x7ed57a)
> > #20 0x00007fb98cd98f45 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21f45)
> > #21 0x00000000007ea4ed _start (/home/dyung/src/upstream/344274-linux-arm/bin/clang+0x7ea4ed)
> > FileCheck error: '-' is empty.
> > FileCheck command line:  /home/dyung/src/upstream/344274-linux-arm/bin/FileCheck -check-prefix=CHECK-ASAN /home/dyung/src/upstream/llvm_clean/tools/clang/test/CodeGen/address-safety-attr-flavors.cpp
> >
> > I build using a script which issues the following commands:
> >
> > 1. cmake -G Ninja -DLLVM_BUILD_RUNTIME=OFF -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_ENABLE_TIMESTAMPS=OFF -DLLVM_INCLUDE_EXAMPLES=OFF -DLLVM_OPTIMIZED_TABLEGEN=ON -DLLVM_VERSION_SUFFIX= -DLLVM_TARGETS_TO_BUILD=ARM -DLLVM_DEFAULT_TARGET_TRIPLE=arm-linux-gnueabihf -DLLVM_LIT_ARGS=--verbose -j80 --no-progress-bar -DCMAKE_BUILD_TYPE=Release <path to LLVM sources> -DLLVM_TOOL_LLD_BUILD=OFF
> >
> > 2. ninja all
> > 3. ninja check-all
> >
> > This builds and tests the compiler, and when the testing finishes, 14 of the 19 failures are for the reason above. Can you take a look?
> >
> > Douglas Yung
> >
> > > -----Original Message-----
> > > From: llvm-commits [mailto:llvm-commits-bounces at lists.llvm.org] On
> > > Behalf Of Leonard Chan via llvm-commits
> > > Sent: Thursday, October 11, 2018 11:32
> > > To: llvm-commits at lists.llvm.org
> > > Subject: [llvm] r344274 - [PassManager/Sanitizer] Port of
> > > AddresSanitizer pass from legacy to new PassManager
> > >
> > > Author: leonardchan
> > > Date: Thu Oct 11 11:31:51 2018
> > > New Revision: 344274
> > >
> > > URL: http://llvm.org/viewvc/llvm-project?rev=344274&view=rev
> > > Log:
> > > [PassManager/Sanitizer] Port of AddresSanitizer pass from legacy to new
> > > PassManager
> > >
> > > This patch ports the legacy pass manager to the new one to take
> > > advantage of
> > > the benefits of the new PM. This involved moving a lot of the
> > > declarations for
> > > `AddressSantizer` to a header so that it can be publicly used via
> > > PassRegistry.def which I believe contains all the passes managed by the
> > > new PM.
> > >
> > > This patch essentially decouples the instrumentation from the legacy PM
> > > such
> > > hat it can be used by both legacy and new PM infrastructure.
> > >
> > > Differential Revision: https://reviews.llvm.org/D52739
> > >
> > > Added:
> > >
> > > llvm/trunk/include/llvm/Transforms/Instrumentation/AddressSanitizerPass
> > > .h
> > > Modified:
> > >     llvm/trunk/include/llvm/InitializePasses.h
> > >     llvm/trunk/lib/Passes/PassBuilder.cpp
> > >     llvm/trunk/lib/Passes/PassRegistry.def
> > >     llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp
> > >     llvm/trunk/lib/Transforms/Instrumentation/Instrumentation.cpp
> > >     llvm/trunk/test/Instrumentation/AddressSanitizer/basic.ll
> > >
> > > Modified: llvm/trunk/include/llvm/InitializePasses.h
> > > URL: http://llvm.org/viewvc/llvm-
> > > project/llvm/trunk/include/llvm/InitializePasses.h?rev=344274&r1=344273
> > > &r2=344274&view=diff
> > > =======================================================================
> > > =======
> > > --- llvm/trunk/include/llvm/InitializePasses.h (original)
> > > +++ llvm/trunk/include/llvm/InitializePasses.h Thu Oct 11 11:31:51 2018
> > > @@ -65,8 +65,8 @@ void initializeAAEvalLegacyPassPass(Pass
> > >  void initializeAAResultsWrapperPassPass(PassRegistry&);
> > >  void initializeADCELegacyPassPass(PassRegistry&);
> > >  void initializeAddDiscriminatorsLegacyPassPass(PassRegistry&);
> > > -void initializeAddressSanitizerModulePass(PassRegistry&);
> > > -void initializeAddressSanitizerPass(PassRegistry&);
> > > +void initializeAddressSanitizerModuleLegacyPassPass(PassRegistry &);
> > > +void initializeAddressSanitizerLegacyPassPass(PassRegistry &);
> > >  void initializeAggressiveInstCombinerLegacyPassPass(PassRegistry&);
> > >  void initializeAliasSetPrinterPass(PassRegistry&);
> > >  void initializeAlignmentFromAssumptionsPass(PassRegistry&);
> > >
> > > Added:
> > > llvm/trunk/include/llvm/Transforms/Instrumentation/AddressSanitizerPass
> > > .h
> > > URL: http://llvm.org/viewvc/llvm-
> > > project/llvm/trunk/include/llvm/Transforms/Instrumentation/AddressSanit
> > > izerPass.h?rev=344274&view=auto
> > > =======================================================================
> > > =======
> > > ---
> > > llvm/trunk/include/llvm/Transforms/Instrumentation/AddressSanitizerPass
> > > .h (added)
> > > +++
> > > llvm/trunk/include/llvm/Transforms/Instrumentation/AddressSanitizerPass
> > > .h Thu Oct 11 11:31:51 2018
> > > @@ -0,0 +1,41 @@
> > > +//===--------- Definition of the AddressSanitizer class ---------*-
> > > C++ -*-===//
> > > +//
> > > +//                     The LLVM Compiler Infrastructure
> > > +//
> > > +// This file is distributed under the University of Illinois Open
> > > Source
> > > +// License. See LICENSE.TXT for details.
> > > +//
> > > +//===-----------------------------------------------------------------
> > > -----===//
> > > +//
> > > +// This file declares the AddressSanitizer class which is a port of
> > > the legacy
> > > +// AddressSanitizer pass to use the new PassManager infrastructure.
> > > +//
> > > +//===-----------------------------------------------------------------
> > > -----===//
> > > +#ifndef LLVM_TRANSFORMS_INSTRUMENTATION_ADDRESSSANITIZERPASS_H
> > > +#define LLVM_TRANSFORMS_INSTRUMENTATION_ADDRESSSANITIZERPASS_H
> > > +
> > > +#include "llvm/IR/Function.h"
> > > +#include "llvm/IR/Module.h"
> > > +#include "llvm/IR/PassManager.h"
> > > +
> > > +namespace llvm {
> > > +
> > > +/// Public interface to the address sanitizer pass for instrumenting
> > > code to
> > > +/// check for various memory bugs.
> > > +class AddressSanitizerPass : public
> > > PassInfoMixin<AddressSanitizerPass> {
> > > +public:
> > > +  explicit AddressSanitizerPass(bool CompileKernel = false,
> > > +                                bool Recover = false,
> > > +                                bool UseAfterScope = false);
> > > +  PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
> > > +  PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
> > > +
> > > +private:
> > > +  bool CompileKernel;
> > > +  bool Recover;
> > > +  bool UseAfterScope;
> > > +};
> > > +
> > > +} // namespace llvm
> > > +
> > > +#endif
> > >
> > > Modified: llvm/trunk/lib/Passes/PassBuilder.cpp
> > > URL: http://llvm.org/viewvc/llvm-
> > > project/llvm/trunk/lib/Passes/PassBuilder.cpp?rev=344274&r1=344273&r2=3
> > > 44274&view=diff
> > > =======================================================================
> > > =======
> > > --- llvm/trunk/lib/Passes/PassBuilder.cpp (original)
> > > +++ llvm/trunk/lib/Passes/PassBuilder.cpp Thu Oct 11 11:31:51 2018
> > > @@ -61,7 +61,6 @@
> > >  #include "llvm/Support/Regex.h"
> > >  #include "llvm/Target/TargetMachine.h"
> > >  #include
> > > "llvm/Transforms/AggressiveInstCombine/AggressiveInstCombine.h"
> > > -#include "llvm/Transforms/Instrumentation/CGProfile.h"
> > >  #include "llvm/Transforms/IPO/AlwaysInliner.h"
> > >  #include "llvm/Transforms/IPO/ArgumentPromotion.h"
> > >  #include "llvm/Transforms/IPO/CalledValuePropagation.h"
> > > @@ -87,7 +86,9 @@
> > >  #include "llvm/Transforms/IPO/SyntheticCountsPropagation.h"
> > >  #include "llvm/Transforms/IPO/WholeProgramDevirt.h"
> > >  #include "llvm/Transforms/InstCombine/InstCombine.h"
> > > +#include "llvm/Transforms/Instrumentation/AddressSanitizerPass.h"
> > >  #include "llvm/Transforms/Instrumentation/BoundsChecking.h"
> > > +#include "llvm/Transforms/Instrumentation/CGProfile.h"
> > >  #include "llvm/Transforms/Instrumentation/ControlHeightReduction.h"
> > >  #include "llvm/Transforms/Instrumentation/GCOVProfiler.h"
> > >  #include "llvm/Transforms/Instrumentation/InstrProfiling.h"
> > >
> > > Modified: llvm/trunk/lib/Passes/PassRegistry.def
> > > URL: http://llvm.org/viewvc/llvm-
> > > project/llvm/trunk/lib/Passes/PassRegistry.def?rev=344274&r1=344273&r2=
> > > 344274&view=diff
> > > =======================================================================
> > > =======
> > > --- llvm/trunk/lib/Passes/PassRegistry.def (original)
> > > +++ llvm/trunk/lib/Passes/PassRegistry.def Thu Oct 11 11:31:51 2018
> > > @@ -40,6 +40,7 @@ MODULE_ALIAS_ANALYSIS("globals-aa", Glob
> > >  #define MODULE_PASS(NAME, CREATE_PASS)
> > >  #endif
> > >  MODULE_PASS("always-inline", AlwaysInlinerPass())
> > > +MODULE_PASS("asan", AddressSanitizerPass(false, false, true))
> > >  MODULE_PASS("called-value-propagation", CalledValuePropagationPass())
> > >  MODULE_PASS("cg-profile", CGProfilePass())
> > >  MODULE_PASS("constmerge", ConstantMergePass())
> > > @@ -147,6 +148,7 @@ FUNCTION_PASS("adce", ADCEPass())
> > >  FUNCTION_PASS("add-discriminators", AddDiscriminatorsPass())
> > >  FUNCTION_PASS("aggressive-instcombine", AggressiveInstCombinePass())
> > >  FUNCTION_PASS("alignment-from-assumptions",
> > > AlignmentFromAssumptionsPass())
> > > +FUNCTION_PASS("asan", AddressSanitizerPass(false, false, false))
> > >  FUNCTION_PASS("bdce", BDCEPass())
> > >  FUNCTION_PASS("bounds-checking", BoundsCheckingPass())
> > >  FUNCTION_PASS("break-crit-edges", BreakCriticalEdgesPass())
> > >
> > > Modified:
> > > llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp
> > > URL: http://llvm.org/viewvc/llvm-
> > > project/llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp?
> > > rev=344274&r1=344273&r2=344274&view=diff
> > > =======================================================================
> > > =======
> > > --- llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp
> > > (original)
> > > +++ llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp Thu
> > > Oct 11 11:31:51 2018
> > > @@ -25,7 +25,6 @@
> > >  #include "llvm/ADT/Twine.h"
> > >  #include "llvm/Analysis/MemoryBuiltins.h"
> > >  #include "llvm/Analysis/TargetLibraryInfo.h"
> > > -#include "llvm/Transforms/Utils/Local.h"
> > >  #include "llvm/Analysis/ValueTracking.h"
> > >  #include "llvm/BinaryFormat/MachO.h"
> > >  #include "llvm/IR/Argument.h"
> > > @@ -70,8 +69,10 @@
> > >  #include "llvm/Support/ScopedPrinter.h"
> > >  #include "llvm/Support/raw_ostream.h"
> > >  #include "llvm/Transforms/Instrumentation.h"
> > > +#include "llvm/Transforms/Instrumentation/AddressSanitizerPass.h"
> > >  #include "llvm/Transforms/Utils/ASanStackFrameLayout.h"
> > >  #include "llvm/Transforms/Utils/BasicBlockUtils.h"
> > > +#include "llvm/Transforms/Utils/Local.h"
> > >  #include "llvm/Transforms/Utils/ModuleUtils.h"
> > >  #include "llvm/Transforms/Utils/PromoteMemToReg.h"
> > >  #include <algorithm>
> > > @@ -597,26 +598,22 @@ static size_t RedzoneSizeForScale(int Ma
> > >  namespace {
> > >
> > >  /// AddressSanitizer: instrument the code in module to find memory
> > > bugs.
> > > -struct AddressSanitizer : public FunctionPass {
> > > -  // Pass identification, replacement for typeid
> > > -  static char ID;
> > > -
> > > -  explicit AddressSanitizer(bool CompileKernel = false, bool Recover =
> > > false,
> > > +struct AddressSanitizer {
> > > +  explicit AddressSanitizer(Module &M, DominatorTree *DT,
> > > +                            bool CompileKernel = false, bool Recover =
> > > false,
> > >                              bool UseAfterScope = false)
> > > -      : FunctionPass(ID), UseAfterScope(UseAfterScope ||
> > > ClUseAfterScope) {
> > > +      : UseAfterScope(UseAfterScope || ClUseAfterScope), DT(DT) {
> > >      this->Recover = ClRecover.getNumOccurrences() > 0 ? ClRecover :
> > > Recover;
> > >      this->CompileKernel = ClEnableKasan.getNumOccurrences() > 0 ?
> > >          ClEnableKasan : CompileKernel;
> > > -    initializeAddressSanitizerPass(*PassRegistry::getPassRegistry());
> > > -  }
> > >
> > > -  StringRef getPassName() const override {
> > > -    return "AddressSanitizerFunctionPass";
> > > -  }
> > > -
> > > -  void getAnalysisUsage(AnalysisUsage &AU) const override {
> > > -    AU.addRequired<DominatorTreeWrapperPass>();
> > > -    AU.addRequired<TargetLibraryInfoWrapperPass>();
> > > +    // Initialize the private fields. No one has accessed them before.
> > > +    GlobalsMD.init(M);
> > > +    C = &(M.getContext());
> > > +    LongSize = M.getDataLayout().getPointerSizeInBits();
> > > +    IntptrTy = Type::getIntNTy(*C, LongSize);
> > > +    TargetTriple = Triple(M.getTargetTriple());
> > > +    Mapping = getShadowMapping(TargetTriple, LongSize, CompileKernel);
> > >    }
> > >
> > >    uint64_t getAllocaSizeInBytes(const AllocaInst &AI) const {
> > > @@ -661,12 +658,12 @@ struct AddressSanitizer : public Functio
> > >                                   Value *SizeArgument, uint32_t Exp);
> > >    void instrumentMemIntrinsic(MemIntrinsic *MI);
> > >    Value *memToShadow(Value *Shadow, IRBuilder<> &IRB);
> > > -  bool runOnFunction(Function &F) override;
> > >    bool maybeInsertAsanInitAtFunctionEntry(Function &F);
> > >    void maybeInsertDynamicShadowAtFunctionEntry(Function &F);
> > >    void markEscapedLocalAllocas(Function &F);
> > > -  bool doInitialization(Module &M) override;
> > > -  bool doFinalization(Module &M) override;
> > > +
> > > +  /// Return true if the function changed.
> > > +  bool instrument(Function &F, const TargetLibraryInfo *TLI);
> > >
> > >    DominatorTree &getDominatorTree() const { return *DT; }
> > >
> > > @@ -724,16 +721,12 @@ private:
> > >    DenseMap<const AllocaInst *, bool> ProcessedAllocas;
> > >  };
> > >
> > > -class AddressSanitizerModule : public ModulePass {
> > > +class AddressSanitizerModule {
> > >  public:
> > > -  // Pass identification, replacement for typeid
> > > -  static char ID;
> > > -
> > >    explicit AddressSanitizerModule(bool CompileKernel = false,
> > >                                    bool Recover = false,
> > >                                    bool UseGlobalsGC = true)
> > > -      : ModulePass(ID),
> > > -        UseGlobalsGC(UseGlobalsGC && ClUseGlobalsGC),
> > > +      : UseGlobalsGC(UseGlobalsGC && ClUseGlobalsGC),
> > >          // Not a typo: ClWithComdat is almost completely pointless
> > > without
> > >          // ClUseGlobalsGC (because then it only works on modules
> > > without
> > >          // globals, which are rare); it is a prerequisite for
> > > ClUseGlobalsGC;
> > > @@ -742,14 +735,12 @@ public:
> > >          // ClWithComdat and ClUseGlobalsGC unless the frontend says
> > > it's ok to
> > >          // do globals-gc.
> > >          UseCtorComdat(UseGlobalsGC && ClWithComdat) {
> > > -          this->Recover = ClRecover.getNumOccurrences() > 0 ?
> > > -              ClRecover : Recover;
> > > -          this->CompileKernel = ClEnableKasan.getNumOccurrences() > 0
> > > ?
> > > -              ClEnableKasan : CompileKernel;
> > > -     }
> > > +    this->Recover = ClRecover.getNumOccurrences() > 0 ? ClRecover :
> > > Recover;
> > > +    this->CompileKernel =
> > > +        ClEnableKasan.getNumOccurrences() > 0 ? ClEnableKasan :
> > > CompileKernel;
> > > +  }
> > >
> > > -  bool runOnModule(Module &M) override;
> > > -  StringRef getPassName() const override { return
> > > "AddressSanitizerModule"; }
> > > +  bool instrument(Module &M);
> > >
> > >  private:
> > >    void initializeCallbacks(Module &M);
> > > @@ -1057,18 +1048,100 @@ struct FunctionStackPoisoner : public In
> > >                       Instruction *ThenTerm, Value *ValueIfFalse);
> > >  };
> > >
> > > +class AddressSanitizerLegacyPass : public FunctionPass {
> > > +public:
> > > +  static char ID;
> > > +
> > > +  explicit AddressSanitizerLegacyPass(bool CompileKernel = false,
> > > +                                      bool Recover = false,
> > > +                                      bool UseAfterScope = false)
> > > +      : FunctionPass(ID), CompileKernel(CompileKernel),
> > > Recover(Recover),
> > > +        UseAfterScope(UseAfterScope) {}
> > > +
> > > +  StringRef getPassName() const override {
> > > +    return "AddressSanitizerFunctionPass";
> > > +  }
> > > +
> > > +  void getAnalysisUsage(AnalysisUsage &AU) const override {
> > > +    AU.addRequired<DominatorTreeWrapperPass>();
> > > +    AU.addRequired<TargetLibraryInfoWrapperPass>();
> > > +  }
> > > +
> > > +  bool runOnFunction(Function &F) override {
> > > +    DominatorTree *DTree =
> > > +        &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
> > > +    const TargetLibraryInfo *TLI =
> > > +        &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
> > > +    AddressSanitizer Sanitizer(*F.getParent(), DTree, CompileKernel,
> > > Recover,
> > > +                               UseAfterScope);
> > > +    return Sanitizer.instrument(F, TLI);
> > > +  }
> > > +
> > > +private:
> > > +  bool CompileKernel;
> > > +  bool Recover;
> > > +  bool UseAfterScope;
> > > +};
> > > +
> > > +class AddressSanitizerModuleLegacyPass : public ModulePass {
> > > +public:
> > > +  static char ID;
> > > +
> > > +  explicit AddressSanitizerModuleLegacyPass(bool CompileKernel =
> > > false,
> > > +                                            bool Recover = false,
> > > +                                            bool UseAfterScope = true)
> > > +      : ModulePass(ID), CompileKernel(CompileKernel),
> > > Recover(Recover),
> > > +        UseAfterScope(UseAfterScope) {}
> > > +
> > > +  StringRef getPassName() const override { return
> > > "AddressSanitizerModule"; }
> > > +
> > > +  bool runOnModule(Module &M) override {
> > > +    AddressSanitizerModule Sanitizer(CompileKernel, Recover,
> > > UseAfterScope);
> > > +    return Sanitizer.instrument(M);
> > > +  }
> > > +
> > > +private:
> > > +  bool CompileKernel;
> > > +  bool Recover;
> > > +  bool UseAfterScope;
> > > +};
> > > +
> > >  } // end anonymous namespace
> > >
> > > -char AddressSanitizer::ID = 0;
> > > +AddressSanitizerPass::AddressSanitizerPass(bool CompileKernel, bool
> > > Recover,
> > > +                                           bool UseAfterScope)
> > > +    : CompileKernel(CompileKernel), Recover(Recover),
> > > +      UseAfterScope(UseAfterScope) {}
> > > +
> > > +PreservedAnalyses AddressSanitizerPass::run(Function &F,
> > > +                                            AnalysisManager<Function>
> > > &AM) {
> > > +  DominatorTree *DT = &AM.getResult<DominatorTreeAnalysis>(F);
> > > +  const TargetLibraryInfo *TLI =
> > > &AM.getResult<TargetLibraryAnalysis>(F);
> > > +  AddressSanitizer Sanitizer(*F.getParent(), DT, CompileKernel,
> > > Recover,
> > > +                             UseAfterScope);
> > > +  if (Sanitizer.instrument(F, TLI))
> > > +    return PreservedAnalyses::none();
> > > +  return PreservedAnalyses::all();
> > > +}
> > > +
> > > +PreservedAnalyses AddressSanitizerPass::run(Module &M,
> > > +                                            AnalysisManager<Module>
> > > &AM) {
> > > +  AddressSanitizerModule Sanitizer(CompileKernel, Recover,
> > > UseAfterScope);
> > > +  if (Sanitizer.instrument(M))
> > > +    return PreservedAnalyses::none();
> > > +  return PreservedAnalyses::all();
> > > +}
> > > +
> > > +char AddressSanitizerLegacyPass::ID = 0;
> > >
> > >  INITIALIZE_PASS_BEGIN(
> > > -    AddressSanitizer, "asan",
> > > +    AddressSanitizerLegacyPass, "asan",
> > >      "AddressSanitizer: detects use-after-free and out-of-bounds
> > > bugs.", false,
> > >      false)
> > >  INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
> > >  INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
> > >  INITIALIZE_PASS_END(
> > > -    AddressSanitizer, "asan",
> > > +    AddressSanitizerLegacyPass, "asan",
> > >      "AddressSanitizer: detects use-after-free and out-of-bounds
> > > bugs.", false,
> > >      false)
> > >
> > > @@ -1076,13 +1149,13 @@ FunctionPass *llvm::createAddressSanitiz
> > >                                                         bool Recover,
> > >                                                         bool
> > > UseAfterScope) {
> > >    assert(!CompileKernel || Recover);
> > > -  return new AddressSanitizer(CompileKernel, Recover, UseAfterScope);
> > > +  return new AddressSanitizerLegacyPass(CompileKernel, Recover,
> > > UseAfterScope);
> > >  }
> > >
> > > -char AddressSanitizerModule::ID = 0;
> > > +char AddressSanitizerModuleLegacyPass::ID = 0;
> > >
> > >  INITIALIZE_PASS(
> > > -    AddressSanitizerModule, "asan-module",
> > > +    AddressSanitizerModuleLegacyPass, "asan-module",
> > >      "AddressSanitizer: detects use-after-free and out-of-bounds bugs."
> > >      "ModulePass",
> > >      false, false)
> > > @@ -1091,7 +1164,8 @@ ModulePass *llvm::createAddressSanitizer
> > >                                                     bool Recover,
> > >                                                     bool UseGlobalsGC)
> > > {
> > >    assert(!CompileKernel || Recover);
> > > -  return new AddressSanitizerModule(CompileKernel, Recover,
> > > UseGlobalsGC);
> > > +  return new AddressSanitizerModuleLegacyPass(CompileKernel, Recover,
> > > +                                              UseGlobalsGC);
> > >  }
> > >
> > >  static size_t TypeSizeToSizeIndex(uint32_t TypeSize) {
> > > @@ -2268,7 +2342,7 @@ int AddressSanitizerModule::GetAsanVersi
> > >    return Version;
> > >  }
> > >
> > > -bool AddressSanitizerModule::runOnModule(Module &M) {
> > > +bool AddressSanitizerModule::instrument(Module &M) {
> > >    C = &(M.getContext());
> > >    int LongSize = M.getDataLayout().getPointerSizeInBits();
> > >    IntptrTy = Type::getIntNTy(*C, LongSize);
> > > @@ -2387,25 +2461,6 @@ void AddressSanitizer::initializeCallbac
> > >
> > > ArrayType::get(IRB.getInt8Ty(), 0));
> > >  }
> > >
> > > -// virtual
> > > -bool AddressSanitizer::doInitialization(Module &M) {
> > > -  // Initialize the private fields. No one has accessed them before.
> > > -  GlobalsMD.init(M);
> > > -
> > > -  C = &(M.getContext());
> > > -  LongSize = M.getDataLayout().getPointerSizeInBits();
> > > -  IntptrTy = Type::getIntNTy(*C, LongSize);
> > > -  TargetTriple = Triple(M.getTargetTriple());
> > > -
> > > -  Mapping = getShadowMapping(TargetTriple, LongSize, CompileKernel);
> > > -  return true;
> > > -}
> > > -
> > > -bool AddressSanitizer::doFinalization(Module &M) {
> > > -  GlobalsMD.reset();
> > > -  return false;
> > > -}
> > > -
> > >  bool AddressSanitizer::maybeInsertAsanInitAtFunctionEntry(Function &F)
> > > {
> > >    // For each NSObject descendant having a +load method, this method
> > > is invoked
> > >    // by the ObjC runtime before any of the static constructors is
> > > called.
> > > @@ -2479,7 +2534,7 @@ void AddressSanitizer::markEscapedLocalA
> > >    }
> > >  }
> > >
> > > -bool AddressSanitizer::runOnFunction(Function &F) {
> > > +bool AddressSanitizer::instrument(Function &F, const TargetLibraryInfo
> > > *TLI) {
> > >    if (F.getLinkage() == GlobalValue::AvailableExternallyLinkage)
> > > return false;
> > >    if (!ClDebugFunc.empty() && ClDebugFunc == F.getName()) return
> > > false;
> > >    if (F.getName().startswith("__asan_")) return false;
> > > @@ -2498,7 +2553,6 @@ bool AddressSanitizer::runOnFunction(Fun
> > >    LLVM_DEBUG(dbgs() << "ASAN instrumenting:\n" << F << "\n");
> > >
> > >    initializeCallbacks(*F.getParent());
> > > -  DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
> > >
> > >    FunctionStateRAII CleanupObj(this);
> > >
> > > @@ -2519,8 +2573,6 @@ bool AddressSanitizer::runOnFunction(Fun
> > >    bool IsWrite;
> > >    unsigned Alignment;
> > >    uint64_t TypeSize;
> > > -  const TargetLibraryInfo *TLI =
> > > -      &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
> > >
> > >    // Fill the set of memory operations to instrument.
> > >    for (auto &BB : F) {
> > >
> > > Modified: llvm/trunk/lib/Transforms/Instrumentation/Instrumentation.cpp
> > > URL: http://llvm.org/viewvc/llvm-
> > > project/llvm/trunk/lib/Transforms/Instrumentation/Instrumentation.cpp?r
> > > ev=344274&r1=344273&r2=344274&view=diff
> > > =======================================================================
> > > =======
> > > --- llvm/trunk/lib/Transforms/Instrumentation/Instrumentation.cpp
> > > (original)
> > > +++ llvm/trunk/lib/Transforms/Instrumentation/Instrumentation.cpp Thu
> > > Oct 11 11:31:51 2018
> > > @@ -56,8 +56,8 @@ BasicBlock::iterator llvm::PrepareToSpli
> > >  /// initializeInstrumentation - Initialize all passes in the
> > > TransformUtils
> > >  /// library.
> > >  void llvm::initializeInstrumentation(PassRegistry &Registry) {
> > > -  initializeAddressSanitizerPass(Registry);
> > > -  initializeAddressSanitizerModulePass(Registry);
> > > +  initializeAddressSanitizerLegacyPassPass(Registry);
> > > +  initializeAddressSanitizerModuleLegacyPassPass(Registry);
> > >    initializeBoundsCheckingLegacyPassPass(Registry);
> > >    initializeControlHeightReductionLegacyPassPass(Registry);
> > >    initializeGCOVProfilerLegacyPassPass(Registry);
> > >
> > > Modified: llvm/trunk/test/Instrumentation/AddressSanitizer/basic.ll
> > > URL: http://llvm.org/viewvc/llvm-
> > > project/llvm/trunk/test/Instrumentation/AddressSanitizer/basic.ll?rev=3
> > > 44274&r1=344273&r2=344274&view=diff
> > > =======================================================================
> > > =======
> > > --- llvm/trunk/test/Instrumentation/AddressSanitizer/basic.ll
> > > (original)
> > > +++ llvm/trunk/test/Instrumentation/AddressSanitizer/basic.ll Thu Oct
> > > 11 11:31:51 2018
> > > @@ -1,7 +1,9 @@
> > >  ; Test basic address sanitizer instrumentation.
> > >  ;
> > >  ; RUN: opt < %s -asan -asan-module -S | FileCheck --check-
> > > prefixes=CHECK,CHECK-S3 %s
> > > +; RUN: opt < %s -passes='function(asan),module(asan)' -S | FileCheck -
> > > -check-prefixes=CHECK,CHECK-S3 %s
> > >  ; RUN: opt < %s -asan -asan-module -asan-mapping-scale=5 -S |
> > > FileCheck --check-prefixes=CHECK,CHECK-S5 %s
> > > +; RUN: opt < %s -passes='function(asan),module(asan)' -asan-mapping-
> > > scale=5 -S | FileCheck --check-prefixes=CHECK,CHECK-S5 %s
> > >
> > >  target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-
> > > i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-
> > > f80:128:128-n8:16:32:64"
> > >  target triple = "x86_64-unknown-linux-gnu"
> > >
> > >
> > > _______________________________________________
> > > llvm-commits mailing list
> > > llvm-commits at lists.llvm.org
> > > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list