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-15342] Placing nested function after a return triggers a SIL verification failure #57664

Closed
BradLarson opened this issue Oct 14, 2021 · 1 comment
Labels
assertion failure Bug → crash: An assertion failure 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 SIL swift 5.6 verifier

Comments

@BradLarson
Copy link
Collaborator

Previous ID SR-15342
Radar None
Original Reporter @BradLarson
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 81dcda5e22e46ceb37d6783cfd9cc555

Issue Description:

If you place the definition of a nested function after a return that passes on a value returned by that nested function, a SIL verification failure results: "external declaration of internal SILFunction not allowed: F->isAvailableExternally()". This does not appear to be a recent regression, as it fails with all of the various toolchains I have on hand.

To reproduce, place the following simple code in a file

func testFunc(_ value: Int) -> Int {
  return testFunc2(value)
  
  func testFunc2(_ value: Int) -> Int {
    return value * 2
  }
}

Building triggers the following failure:

SIL verification failed: external declaration of internal SILFunction not allowed: F->isAvailableExternally()
In function:
// testFunc2 #​1 (_:) in testFunc(_:)
sil private @$s21NestedFunctionCrasher8testFuncyS2iF0D5Func2L_yS2iF : $@convention(thin) (Int) -> Int

Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project and the crash backtrace.
Stack dump:
0.  Program arguments: /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2021-10-05-a.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file NestedFunctionCrasher.swift -target x86_64-apple-macosx11.0 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk -color-diagnostics -new-driver-path /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2021-10-05-a.xctoolchain/usr/bin/swift-driver -resource-dir /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2021-10-05-a.xctoolchain/usr/lib/swift -module-name NestedFunctionCrasher -target-sdk-version 11.3.0 -o /var/folders/1s/z_s04yq55wq2jvgqghm8zm7w0000gp/T/TemporaryDirectory.R9kI74/NestedFunctionCrasher-1.o
1.  Apple Swift version 5.6-dev (LLVM 7aef0efea99e2c6, Swift e4f71c8e118fc09)
2.  Compiling with the current language version
3.  While evaluating request ASTLoweringRequest(Lowering AST to SIL for file "NestedFunctionCrasher.swift")
4.  While verifying SIL function "@$s21NestedFunctionCrasher8testFuncyS2iF0D5Func2L_yS2iF".
 for 'testFunc2(_:)' (at NestedFunctionCrasher.swift:4:3)
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  swift-frontend           0x00000001076bd8f7 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 39
1  swift-frontend           0x00000001076bcb15 llvm::sys::RunSignalHandlers() + 85
2  swift-frontend           0x00000001076be146 SignalHandler(int) + 278
3  libsystem_platform.dylib 0x00007fff2040cd7d _sigtramp + 29
4  libsystem_platform.dylib 0x000000011405354b _sigtramp + 18446603344605898731
5  libsystem_c.dylib        0x00007fff2031c406 abort + 125
6  swift-frontend           0x0000000102f7baae (anonymous namespace)::SILVerifier::_require(bool, llvm::Twine const&, std::__1::function<void ()> const&) + 1358
7  swift-frontend           0x0000000102f7c449 (anonymous namespace)::SILVerifier::visitSILFunction(swift::SILFunction*) + 601
8  swift-frontend           0x0000000102f7ae83 swift::SILModule::verify() const + 275
9  swift-frontend           0x0000000103328584 swift::Lowering::SILGenModule::~SILGenModule() + 36
10 swift-frontend           0x000000010333281f swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const + 5391
11 swift-frontend           0x00000001034015f6 swift::SimpleRequest<swift::ASTLoweringRequest, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> > (swift::ASTLoweringDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::ASTLoweringRequest const&, swift::Evaluator&) + 134
12 swift-frontend           0x000000010333637d llvm::Expected<swift::ASTLoweringRequest::OutputType> swift::Evaluator::getResultUncached<swift::ASTLoweringRequest>(swift::ASTLoweringRequest const&) + 413
13 swift-frontend           0x0000000103332ae4 swift::performASTLowering(swift::FileUnit&, swift::Lowering::TypeConverter&, swift::SILOptions const&) + 116
14 swift-frontend           0x0000000102cd8d1a performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 618
15 swift-frontend           0x0000000102ccdc82 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 4850
16 swift-frontend           0x0000000102c95cd2 swift::mainEntry(int, char const**) + 546
17 libdyld.dylib            0x00007fff203e2f3d start + 1
18 libdyld.dylib            0x0000000000000015 start + 18446603339975217369
@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@BradLarson
Copy link
Collaborator Author

This is no longer reproducible as of nightly snapshots dating back to February 2023, so I'm considering it as fixed in the meantime.

@AnthonyLatsis AnthonyLatsis added verifier crash Bug: A crash, i.e., an abnormal termination of software SIL assertion failure Bug → crash: An assertion failure swift 5.6 labels Sep 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
assertion failure Bug → crash: An assertion failure 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 SIL swift 5.6 verifier
Projects
None yet
Development

No branches or pull requests

2 participants