Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coverage: fix handling of constructors and top-level decls (SR-7446) #15966

Merged
merged 3 commits into from Apr 17, 2018

Conversation

vedantk
Copy link
Member

@vedantk vedantk commented Apr 17, 2018

  1. Instrument constructor initializers, instead of the delegating constructors which just call them.

  2. Once that's done, make sure that a parent region is available inside of member initializers and top-level code decls. This fixes a reporting bug for if-exprs by getting rid of the RegionStack.empty() case.

  3. Remove some defensive heuristic code which dealt with closures and if-exprs within member initializers.

We need to instrument constructor initializers, instead of the
delegating constructors which just call them.

rdar://39460313
@vedantk vedantk changed the title Coverage: fix handling of constructors and top-level decls (SR-7446) (WIP) Coverage: fix handling of constructors and top-level decls (SR-7446) Apr 17, 2018
@vedantk
Copy link
Member Author

vedantk commented Apr 17, 2018

This scheme of using a designated constructor for profiling purposes is a bit brittle. One concrete issue with this is that swift ends up attempting to create distinct SILProfilers for different constructors of a nominal type, and stored property initializers we want coverage for may not be emitted in the designated constructor.

A simpler idea is to store a map from nominal types to SILProfilers, and to then create a single merged profiler instance for all constructors of a nominal type.

@vedantk vedantk changed the title (WIP) Coverage: fix handling of constructors and top-level decls (SR-7446) Coverage: fix handling of constructors and top-level decls (SR-7446) Apr 17, 2018
@vedantk
Copy link
Member Author

vedantk commented Apr 17, 2018

@swift-ci test and merge

1 similar comment
@vedantk
Copy link
Member Author

vedantk commented Apr 17, 2018

@swift-ci test and merge

…zers

This fixes coverage reporting for member initializers and cuts down on
repeated AST traversals of pattern bindings within nominal type decls.

This allows us to remove some defensive heuristic code which dealt with
closures and if-exprs within member initializers.
@vedantk
Copy link
Member Author

vedantk commented Apr 17, 2018

@swift-ci smoke test and merge

1 similar comment
@vedantk
Copy link
Member Author

vedantk commented Apr 17, 2018

@swift-ci smoke test and merge

@vedantk vedantk merged commit 8a003a4 into apple:master Apr 17, 2018
vedantk added a commit to vedantk/swift that referenced this pull request Apr 17, 2018
…pple#15966)

* [Coverage] Instrument constructor initializers (SR-7446)

We need to instrument constructor initializers, instead of the
delegating constructors which just call them.

rdar://39460313

* [Coverage] Remove dead code, NFC

* [Coverage] Use a shared profiler for constructors and member initializers

This fixes coverage reporting for member initializers and cuts down on
repeated AST traversals of pattern bindings within nominal type decls.

This allows us to remove some defensive heuristic code which dealt with
closures and if-exprs within member initializers.

(cherry picked from commit 8a003a4)
@slavapestov
Copy link
Member

@vedantk What if a type has multiple designated initializers?

@slavapestov
Copy link
Member

Also unrelated, this caused a failure in the ASAN bot:

=================================================================
==56930==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x602000013258 at pc 0x000110a768cf bp 0x7ffee1c1f970 sp 0x7ffee1c1f968
READ of size 8 at 0x602000013258 thread T0
    #0 0x110a768ce in (anonymous namespace)::PGOMapping::loadExecutionCount(swift::ASTNode) SILProfiler.cpp:407
    #1 0x110a75c37 in (anonymous namespace)::PGOMapping::walkToDeclPre(swift::Decl*) SILProfiler.cpp:416
    #2 0x111887091 in (anonymous namespace)::Traversal::doIt(swift::Decl*) ASTWalker.cpp:1137
    #3 0x11189f55b in (anonymous namespace)::Traversal::visitNominalTypeDecl(swift::NominalTypeDecl*) ASTWalker.cpp:262
    #4 0x11188718a in (anonymous namespace)::Traversal::doIt(swift::Decl*) ASTWalker.cpp
    #5 0x111886d5a in swift::Decl::walk(swift::ASTWalker&) ASTWalker.cpp:1741
    #6 0x110a63a30 in swift::SILProfiler::assignRegionCounters() SILProfiler.cpp:977
    #7 0x110a60d68 in swift::SILProfiler::create(swift::SILModule&, swift::ForDefinition_t, swift::ASTNode) SILProfiler.cpp:130
    #8 0x10f7dee50 in swift::Lowering::SILGenModule::getOrCreateProfilerForConstructors(swift::NominalTypeDecl*) SILGen.cpp:501
    #9 0x10f7fa562 in swift::Lowering::SILGenModule::emitConstructor(swift::ConstructorDecl*)::$_3::operator()(swift::SILFunction*) const SILGen.cpp:779
    #10 0x10f7f1b33 in swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*, llvm::Optional<unsigned int>, bool) functional:1921
    #11 0x10f7f22f0 in swift::performSILGeneration(swift::ModuleDecl*, swift::SILOptions&, bool) SILGen.cpp:1626
    #12 0x10e0c00aa in performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) FrontendTool.cpp:804
    #13 0x10e0b68c7 in swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) FrontendTool.cpp:1772
    #14 0x10dfe126f in main driver.cpp:161
    #15 0x7fff7dbc9114 in start (libdyld.dylib:x86_64+0x1114)

0x602000013258 is located 0 bytes to the right of 8-byte region [0x602000013250,0x602000013258)
allocated by thread T0 here:
    #0 0x1215f5b32 in wrap__Znwm (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x62b32)
    #1 0x11051e13e in std::__1::vector<swift::Expr*, std::__1::allocator<swift::Expr*> >::vector(std::__1::vector<swift::Expr*, std::__1::allocator<swift::Expr*> > const&) new:226
    #2 0x1167599b3 in llvm::IndexedInstrProfReader::getInstrProfRecord(llvm::StringRef, unsigned long long) vector:1194
    #3 0x110a62fcc in swift::SILProfiler::assignRegionCounters() SILProfiler.cpp:1036
    #4 0x110a60d68 in swift::SILProfiler::create(swift::SILModule&, swift::ForDefinition_t, swift::ASTNode) SILProfiler.cpp:130
    #5 0x10f7dee50 in swift::Lowering::SILGenModule::getOrCreateProfilerForConstructors(swift::NominalTypeDecl*) SILGen.cpp:501
    #6 0x10f7fa562 in swift::Lowering::SILGenModule::emitConstructor(swift::ConstructorDecl*)::$_3::operator()(swift::SILFunction*) const SILGen.cpp:779
    #7 0x10f7f1b33 in swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*, llvm::Optional<unsigned int>, bool) functional:1921
    #8 0x10f7f22f0 in swift::performSILGeneration(swift::ModuleDecl*, swift::SILOptions&, bool) SILGen.cpp:1626
    #9 0x10e0c00aa in performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) FrontendTool.cpp:804
    #10 0x10e0b68c7 in swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) FrontendTool.cpp:1772
    #11 0x10dfe126f in main driver.cpp:161
    #12 0x7fff7dbc9114 in start (libdyld.dylib:x86_64+0x1114)

SUMMARY: AddressSanitizer: heap-buffer-overflow SILProfiler.cpp:407 in (anonymous namespace)::PGOMapping::loadExecutionCount(swift::ASTNode)
Shadow bytes around the buggy address:
  0x1c04000025f0: fa fa fd fd fa fa fd fa fa fa fd fa fa fa fd fd
  0x1c0400002600: fa fa fd fa fa fa fd fd fa fa fd fa fa fa fd fa
  0x1c0400002610: fa fa fd fa fa fa fd fa fa fa fd fa fa fa fd fa
  0x1c0400002620: fa fa fd fa fa fa fd fa fa fa fd fa fa fa fd fa
  0x1c0400002630: fa fa fd fa fa fa fd fa fa fa fd fd fa fa fd fa
=>0x1c0400002640: fa fa 00 fa fa fa fd fa fa fa 00[fa]fa fa fa fa
  0x1c0400002650: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x1c0400002660: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x1c0400002670: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x1c0400002680: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x1c0400002690: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
==56930==ABORTING
Stack dump:
0.	Program arguments: /Users/buildnode/jenkins/workspace/oss-swift-incremental-ASAN-RA-osx/buildbot_incremental_asan/swift-macosx-x86_64/bin/swiftc -frontend -target x86_64-apple-macosx10.9 -module-cache-path /Users/buildnode/jenkins/workspace/oss-swift-incremental-ASAN-RA-osx/buildbot_incremental_asan/swift-macosx-x86_64/./swift-test-results/x86_64-apple-macosx10.9/clang-module-cache -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -swift-version 3 /Users/buildnode/jenkins/workspace/oss-swift-incremental-ASAN-RA-osx/swift/test/SILGen/pgo_checked_cast.swift -Xllvm -sil-full-demangle -profile-use=/Users/buildnode/jenkins/workspace/oss-swift-incremental-ASAN-RA-osx/buildbot_incremental_asan/swift-macosx-x86_64/test-macosx-x86_64/SILGen/Output/pgo_checked_cast.swift.tmp/default.profdata -emit-sorted-sil -emit-sil -module-name pgo_checked_cast -o - 
1.	While silgen constructor initializer SIL function "@$S16pgo_checked_cast1BCACycfc".
 for 'init()' at /Users/buildnode/jenkins/workspace/oss-swift-incremental-ASAN-RA-osx/swift/test/SILGen/pgo_checked_cast.swift:30:14
FileCheck error: '-' is empty.
FileCheck command line:  /Users/buildnode/jenkins/workspace/oss-swift-incremental-ASAN-RA-osx/buildbot_incremental_asan/llvm-macosx-x86_64/bin/FileCheck /Users/buildnode/jenkins/workspace/oss-swift-incremental-ASAN-RA-osx/swift/test/SILGen/pgo_checked_cast.swift --check-prefix=SIL

--

@vedantk
Copy link
Member Author

vedantk commented Apr 18, 2018

@slavapestov If a type has multiple designated initializers, coverage for each should be reported separately (each constructor decl is visited). I'm taking a look at the asan failure now.

@vedantk
Copy link
Member Author

vedantk commented Apr 18, 2018

Here's a PR to address the asan issue: #16012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants