You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Attempting to compile the following program will crash the compiler:
func foo() -> Int {
func a(_ x: Int) -> Int {
return b(x)
}
return a(100)
func b(_ x: Int) -> Int {
return x + 1
}
}
Compiler output:
> swiftc test2.swift
test2.swift:8:3: warning: code after 'return' will never be executed
func b(_ x: Int) -> Int {
^
Global is external, but doesn't have external or weak linkage!
i64 (i64)* @"$s5test23fooSiyF1bL_yS2iF"
<unknown>:0: error: fatal error encountered during compilation; please file a bug report with your project and the crash log
<unknown>:0: note: Broken module found, compilation aborted!
Stack dump:
0. Program arguments: /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file test2.swift -target x86_64-apple-darwin20.1.0 -enable-objc-interop -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.0.sdk -color-diagnostics -target-sdk-version 11.0 -module-name test2 -o /var/folders/9h/l__gbp5s4z79p76b4c8vgqvr0000gn/T/test2-57ab32.o
1. Apple Swift version 5.3.1 (swiftlang-1200.0.41 clang-1200.0.32.8)
0 swift 0x000000010e411c15 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1 swift 0x000000010e412332 SignalHandler(int) + 610
2 libsystem_platform.dylib 0x00007fff205c0d7d _sigtramp + 29
3 libsystem_platform.dylib 000000000000000000 _sigtramp + 18446603339973259936
4 libsystem_c.dylib 0x00007fff204ce720 abort + 120
5 swift 0x0000000109c1a7a1 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*)::$_1::__invoke(void*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool) + 1137
6 swift 0x000000010e3751a7 llvm::report_fatal_error(llvm::Twine const&, bool) + 279
7 swift 0x000000010e375082 llvm::report_fatal_error(char const*, bool) + 50
8 swift 0x000000010e31639c (anonymous namespace)::VerifierLegacyPass::doFinalization(llvm::Module&) + 188
9 swift 0x000000010e2b5ff2 llvm::FPPassManager::doFinalization(llvm::Module&) + 50
10 swift 0x000000010e2b54a0 llvm::legacy::FunctionPassManagerImpl::doFinalization(llvm::Module&) + 80
11 swift 0x0000000109fc58ef swift::performLLVM(swift::IRGenOptions const&, swift::DiagnosticEngine&, llvm::sys::SmartMutex<false>*, llvm::GlobalVariable*, llvm::Module*, llvm::TargetMachine*, swift::version::Version const&, llvm::StringRef, swift::UnifiedStatsReporter*) + 4991
12 swift 0x0000000109c29ba8 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*) + 3944
13 swift 0x0000000109c19603 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 21363
14 swift 0x0000000109b9a2c1 main + 1265
15 libdyld.dylib 0x00007fff20597591 start + 1
<unknown>:0: error: unable to execute command: Abort trap: 6
<unknown>:0: error: compile command failed due to signal 6 (use -v to see invocation)
Moving the return statement to after the declaration of `b` does not cause any sort of crash or compiler warning. If I'm not mistaken, this type of forward reference from function `a` to function `b` is legal in Swift.
Additional Detail from JIRA
md5: 5044c3ff6a500995411d4ad6dc423f96
Issue Description:
Attempting to compile the following program will crash the compiler:
Compiler output:
Moving the return statement to after the declaration of `b` does not cause any sort of crash or compiler warning. If I'm not mistaken, this type of forward reference from function `a` to function `b` is legal in Swift.
Bug repro inspired by discussion here: https://forums.swift.org/t/clarify-scoping-behavior-with-local-functions/40558
The text was updated successfully, but these errors were encountered: