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

Compiler crashed: Referring os.Logger instance in custom constructor of String #72733

Open
mtgto opened this issue Mar 31, 2024 · 0 comments
Open
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. crash Bug: A crash, i.e., an abnormal termination of software triage needed This issue needs more specific labels

Comments

@mtgto
Copy link

mtgto commented Mar 31, 2024

Description

The Swift compiler crashes when refers os.Logger instance in custom constructor of String.

  • I also refer Logger instance in constructor of URL, Data, but compiler does not crash.

Reproduction

Sources/main.swift

import os

let logger = Logger(subsystem: "net.mtgto.example-logger-in-constructor", category: "main")

extension String {
    init?(notUsed: Int) {
        logger.log("foobar")
        return nil
    }
}

Package.swift

// swift-tools-version: 5.10
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "example-logger-in-constructor",
    platforms: [.macOS(.v13)],
    targets: [
        // Targets are the basic building blocks of a package, defining a module or a test suite.
        // Targets can depend on other targets in this package and products from dependencies.
        .executableTarget(
            name: "example-logger-in-constructor"),
    ]
)

Stack dump

❯ swift build
Building for debugging...
error: compile command failed due to signal 11 (use -v to see invocation)
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.      Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file /Users/user/work/cocoa/example-logger-in-constructor/Sources/main.swift -emit-dependencies-path /Users/user/work/cocoa/example-logger-in-constructor/.build/arm64-apple-macosx/debug/example_logger_in_constructor.build/main.d -emit-reference-dependencies-path /Users/user/work/cocoa/example-logger-in-constructor/.build/arm64-apple-macosx/debug/example_logger_in_constructor.build/main.swiftdeps -target arm64-apple-macosx13.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -stack-check -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk -I /Users/user/work/cocoa/example-logger-in-constructor/.build/arm64-apple-macosx/debug -I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -F /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -color-diagnostics -enable-testing -g -module-cache-path /Users/user/work/cocoa/example-logger-in-constructor/.build/arm64-apple-macosx/debug/ModuleCache -swift-version 5 -Onone -D SWIFT_PACKAGE -D DEBUG -new-driver-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-driver -entry-point-function-name example_logger_in_constructor_main -empty-abi-descriptor -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -Xcc -isysroot -Xcc /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk -Xcc -F -Xcc /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -Xcc -fPIC -Xcc -g -module-name example_logger_in_constructor -package-name example_logger_in_constructor -disable-clang-spi -target-sdk-version 14.4 -target-sdk-name macosx14.4 -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk/usr/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk/usr/local/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/local/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -plugin-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/local/lib/swift/host/plugins -o /Users/user/work/cocoa/example-logger-in-constructor/.build/arm64-apple-macosx/debug/example_logger_in_constructor.build/main.swift.o -index-store-path /Users/user/work/cocoa/example-logger-in-constructor/.build/arm64-apple-macosx/debug/index/store -index-system-modules
1.      Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
2.      Compiling with the current language version
3.      While evaluating request ExecuteSILPipelineRequest(Run pipelines { Mandatory Diagnostic Passes + Enabling Optimization Passes } on SIL for example_logger_in_constructor)
4.      While running pass #84 SILFunctionTransform "OSLogOptimization" on SILFunction "@$sSS29example_logger_in_constructorE7notUsedSSSgSi_tcfC".
 for 'init(notUsed:)' (at /Users/user/work/cocoa/example-logger-in-constructor/Sources/main.swift:6:5)
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           0x00000001064bff3c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x00000001064bf0f8 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x00000001064c0544 SignalHandler(int) + 360
3  libsystem_platform.dylib 0x0000000189bcb584 _sigtramp + 56
4  swift-frontend           0x00000001017dc2f4 (anonymous namespace)::OSLogOptimization::run() + 12648
5  swift-frontend           0x00000001017fba68 swift::SILPassManager::runFunctionPasses(unsigned int, unsigned int) + 3856
6  swift-frontend           0x00000001017f8384 swift::SILPassManager::executePassPipelinePlan(swift::SILPassPipelinePlan const&) + 14952
7  swift-frontend           0x0000000101831354 swift::SimpleRequest<swift::ExecuteSILPipelineRequest, std::__1::tuple<> (swift::SILPipelineExecutionDescriptor), (swift::RequestFlags)1>::evaluateRequest(swift::ExecuteSILPipelineRequest const&, swift::Evaluator&) + 56
8  swift-frontend           0x0000000101815184 llvm::Expected<swift::ExecuteSILPipelineRequest::OutputType> swift::Evaluator::getResultUncached<swift::ExecuteSILPipelineRequest>(swift::ExecuteSILPipelineRequest const&) + 476
9  swift-frontend           0x0000000101817974 swift::runSILDiagnosticPasses(swift::SILModule&) + 412
10 swift-frontend           0x0000000100fcccf8 swift::CompilerInstance::performSILProcessing(swift::SILModule*) + 84
11 swift-frontend           0x0000000100dbdf98 performCompileStepsPostSILGen(swift::CompilerInstance&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) + 1128
12 swift-frontend           0x0000000100dbd444 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 608
13 swift-frontend           0x0000000100dc1694 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1448
14 swift-frontend           0x0000000100dbf6d0 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 4968
15 swift-frontend           0x0000000100d4ee8c swift::mainEntry(int, char const**) + 2612
16 dyld                     0x00000001898120e0 start + 2360

Expected behavior

Succeed to compile.

Environment

  • Xcode 15.3 and it's command line tools.
  • macOS 14.4.1 (Apple Silicon)
❯ swiftc -version
swift-driver version: 1.90.11.1 Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
Target: arm64-apple-macosx14.0

Additional information

No response

@mtgto mtgto added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. crash Bug: A crash, i.e., an abnormal termination of software triage needed This issue needs more specific labels labels Mar 31, 2024
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. crash Bug: A crash, i.e., an abnormal termination of software triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

1 participant