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

[SR-13444] Compiler segfault coercing AnyClass to Any in release configuration #55886

Open
sharplet opened this issue Aug 25, 2020 · 4 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software optimized only Flag: An issue whose reproduction requires optimized compilation

Comments

@sharplet
Copy link

Previous ID SR-13444
Radar rdar://problem/68077098
Original Reporter @sharplet
Type Bug
Environment
% xcodebuild -version
Xcode 12.0
Build version 12A8189h

% swift --version
Apple Swift version 5.3 (swiftlang-1200.0.28.1 clang-1200.0.30.1)
Target: x86_64-apple-darwin20.0.0
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash, OptimizedOnly
Assignee @eeckstein
Priority Medium

md5: a36dba251bfe4fd81452dd26da6aca33

Issue Description:

This method triggers the crash: https://github.com/thoughtbot/CombineViewModel/blob/c486f3f46de9491e47496abae12bf1cbaa5b859d/Sources/CombineViewModel/ObjCRuntime.swift#L25-L44. This diff works around the crash: thoughtbot/CombineViewModel#14

Here's a copy of the compiler stack trace:

1.      Apple Swift version 5.3 (swiftlang-1200.0.28.1 clang-1200.0.30.1)
2.      While evaluating request ExecuteSILPipelineRequest(Run pipelines { EarlyModulePasses, HighLevel+EarlyLoopOpt, MidModulePasses+StackPromote, MidLevel, ClosureSpecialize, LowLevel, LateLoopOpt, SIL Debug Info Generator } on SIL for CombineViewModel.CombineViewModel)
3.      While running pass #​21881 SILFunctionTransform "SILCombine" on SILFunction "@$sSo16UIViewControllerC16CombineViewModelE04hookD7DidLoadyyF".
 for 'hookViewDidLoad()' (at /Users/sharplet/src/thoughtbot/CombineViewModel/Sources/CombineViewModel/ObjCRuntime.swift:25:12)
0  swift                    0x0000000112b45a85 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swift                    0x0000000112b44a85 llvm::sys::RunSignalHandlers() + 85
2  swift                    0x0000000112b4603f SignalHandler(int) + 111
3  libsystem_platform.dylib 0x00007fff6d601d7d _sigtramp + 29
4  libsystem_platform.dylib 0x0000000100000006 _sigtramp + 18446603342976115366
5  swift                    0x000000010eae314d swift::SILBuilder::createApply(swift::SILLocation, swift::SILValue, swift::SubstitutionMap, llvm::ArrayRef<swift::SILValue>, bool, swift::GenericSpecializationInformation const*) + 237
6  swift                    0x000000010ee6c406 swift::SILCombiner::createApplyWithConcreteType(swift::FullApplySite, llvm::SmallDenseMap<unsigned int, swift::ConcreteOpenedExistentialInfo, 4u, llvm::DenseMapInfo<unsigned int>, llvm::detail::DenseMapPair<unsigned int, swift::ConcreteOpenedExistentialInfo> > const&, swift::SILBuilderContext&) + 5766
7  swift                    0x000000010ee6d458 swift::SILCombiner::propagateConcreteTypeOfInitExistential(swift::FullApplySite) + 456
8  swift                    0x000000010ee6e4e2 swift::SILCombiner::visitApplyInst(swift::ApplyInst*) + 1186
9  swift                    0x000000010ee665e5 swift::SILCombiner::doOneIteration(swift::SILFunction&, unsigned int) + 1717
10 swift                    0x000000010ee67929 (anonymous namespace)::SILCombine::run() + 1225
11 swift                    0x000000010ee4e97b swift::SILPassManager::runFunctionPasses(unsigned int, unsigned int) + 4299
12 swift                    0x000000010ee4ad5a swift::SILPassManager::executePassPipelinePlan(swift::SILPassPipelinePlan const&) + 138
13 swift                    0x000000010ee64bfc swift::SimpleRequest<swift::ExecuteSILPipelineRequest, std::__1::tuple<> (swift::SILPipelineExecutionDescriptor), (swift::RequestFlags)1>::evaluateRequest(swift::ExecuteSILPipelineRequest const&, swift::Evaluator&) + 60
14 swift                    0x000000010ee53155 llvm::Expected<swift::ExecuteSILPipelineRequest::OutputType> swift::Evaluator::getResultUncached<swift::ExecuteSILPipelineRequest>(swift::ExecuteSILPipelineRequest const&) + 1045
15 swift                    0x000000010ee563b9 swift::runSILOptimizationPasses(swift::SILModule&) + 425
16 swift                    0x000000010e7ea14e swift::CompilerInstance::performSILProcessing(swift::SILModule*) + 1358
17 swift                    0x000000010e6bccd8 performCompileStepsPostSILGen(swift::CompilerInstance&, swift::CompilerInvocation const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) + 1288
18 swift                    0x000000010e6ad150 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 21152
19 swift                    0x000000010e62e277 main + 1255
20 libdyld.dylib            0x00007fff6d3d3851 start + 1
21 libdyld.dylib            0x0000000000000060 start + 18446603338683435024
error: Segmentation fault: 11 (in target 'CombineViewModel' from project 'CombineViewModel')
@theblixguy
Copy link
Collaborator

Here's a reduced version of the crasher:

import Foundation

class C {}
var key: UInt8 = 0
let anyClass: AnyClass = C.self
func foo(_ object: Any) {
  objc_setAssociatedObject(object, &key, true, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
}
foo(anyClass)

I think you can workaround it by disabling the SILCombine pass by passing -Xllvm -sil-disable-pass=sil-combine (or by changing the type from AnyClass to Any, as you mentioned in your PR)

@theblixguy
Copy link
Collaborator

cc @eeckstein

@sharplet
Copy link
Author

@theblixguy Thank you!

@eeckstein
Copy link
Member

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software optimized only Flag: An issue whose reproduction requires optimized compilation
Projects
None yet
Development

No branches or pull requests

4 participants