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

Combination of -g and -O flags with Embedded Swift crashes swiftc in IRGen #72118

Open
MaxDesiatov opened this issue Mar 6, 2024 · 0 comments
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 debug info Area → compiler → IRGen: Debug information emission embedded Embedded Swift IRGen LLVM IR generation optimized only Flag: An issue whose reproduction requires optimized compilation

Comments

@MaxDesiatov
Copy link
Member

Description

Build the source snippet pasted in this issue with swiftc -enable-experimental-feature Embedded -wmo repro.swift -g -O with latest development snapshot off the main branch of the compiler to observe the crash.

Reproduction

struct Plotter {
    let width: Int

    func plot(_ storage: UnsafeMutableBufferPointer<Float>) {
        let samplesPerPixel = storage.count / self.width

        var sampleCounter = 0
        var averageCounter = 0
        var average: Float = 0
        
        for sample in storage {
            average += sample

            if sampleCounter < samplesPerPixel {
                sampleCounter += 1
                average += sample
            } else {
                averageCounter += 1 
                average = 0
                sampleCounter = 0
            }
        }
    }
}

let buffer = UnsafeMutableBufferPointer<Float>.allocate(capacity: 42)
Plotter(width: 1000).plot(buffer)

Stack dump

1.      Apple Swift version 6.0-dev (LLVM 7fe091223bc821e, Swift 92f5eeeefc88005)
2.      Compiling with effective version 5.10
3.      While evaluating request IRGenRequest(IR Generation for module repro)
4.      While emitting IR SIL function "@$s5repro7PlotterV4plotyySrySfGF".
 for 'plot(_:)' (at repro.swift:4: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           0x0000000106216e18 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x00000001062155e4 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x0000000106217460 SignalHandler(int) + 304
3  libsystem_platform.dylib 0x00000001970e3584 _sigtramp + 56
4  libsystem_pthread.dylib  0x00000001970b2c20 pthread_kill + 288
5  libsystem_c.dylib        0x0000000196fbfa20 abort + 180
6  libsystem_c.dylib        0x0000000196fbed10 err + 0
7  swift-frontend           0x000000010629b44c void llvm::function_ref<void (swift::irgen::IRGenFunction&)>::callback_fn<getAllocateBoxedOpaqueExistentialBufferFunction(swift::irgen::IRGenModule&, (anonymous namespace)::OpaqueExistentialLayout)::$_4>(long, swift::irgen::IRGenFunction&) (.cold.1) + 0
8  swift-frontend           0x000000010122541c void llvm::function_ref<void (swift::irgen::IRGenFunction&)>::callback_fn<getAllocateBoxedOpaqueExistentialBufferFunction(swift::irgen::IRGenModule&, (anonymous namespace)::OpaqueExistentialLayout)::$_4>(long, swift::irgen::IRGenFunction&) + 0
9  swift-frontend           0x00000001012c371c swift::irgen::IRGenModule::getTypeInfoForUnlowered(swift::Type) + 88
10 swift-frontend           0x00000001012f5844 (anonymous namespace)::IRGenDebugInfoImpl::collectGenericParams(swift::BoundGenericType*) + 216
11 swift-frontend           0x00000001012f3558 (anonymous namespace)::IRGenDebugInfoImpl::createType(swift::irgen::DebugTypeInfo, llvm::StringRef, llvm::DIScope*, llvm::DIFile*) + 3284
12 swift-frontend           0x00000001012f1f54 (anonymous namespace)::IRGenDebugInfoImpl::getOrCreateType(swift::irgen::DebugTypeInfo) + 2892
13 swift-frontend           0x00000001012f2b94 (anonymous namespace)::IRGenDebugInfoImpl::createType(swift::irgen::DebugTypeInfo, llvm::StringRef, llvm::DIScope*, llvm::DIFile*) + 784
14 swift-frontend           0x00000001012f1f54 (anonymous namespace)::IRGenDebugInfoImpl::getOrCreateType(swift::irgen::DebugTypeInfo) + 2892
15 swift-frontend           0x00000001012f78d0 (anonymous namespace)::IRGenDebugInfoImpl::createMemberType(swift::irgen::DebugTypeInfo, llvm::StringRef, unsigned int&, llvm::DIScope*, llvm::DIFile*, llvm::DINode::DIFlags) + 100
16 swift-frontend           0x00000001012f47a4 (anonymous namespace)::IRGenDebugInfoImpl::createStructType(swift::irgen::DebugTypeInfo, swift::NominalTypeDecl*, swift::Type, llvm::DIScope*, llvm::DIFile*, unsigned int, unsigned int, unsigned int, llvm::DINode::DIFlags, llvm::DIType*, unsigned int, llvm::StringRef) + 592
17 swift-frontend           0x00000001012f3250 (anonymous namespace)::IRGenDebugInfoImpl::createType(swift::irgen::DebugTypeInfo, llvm::StringRef, llvm::DIScope*, llvm::DIFile*) + 2508
18 swift-frontend           0x00000001012f1f54 (anonymous namespace)::IRGenDebugInfoImpl::getOrCreateType(swift::irgen::DebugTypeInfo) + 2892
19 swift-frontend           0x00000001012ebd90 (anonymous namespace)::IRGenDebugInfoImpl::emitVariableDeclaration(swift::irgen::IRBuilder&, llvm::ArrayRef<llvm::Value*>, swift::irgen::DebugTypeInfo, swift::SILDebugScope const*, std::__1::optional<swift::SILLocation>, swift::SILDebugVariable, swift::irgen::IndirectionKind, swift::irgen::ArtificialKind, swift::irgen::AddrDbgInstrKind) + 404
20 swift-frontend           0x00000001012ebbb0 swift::irgen::IRGenDebugInfo::emitVariableDeclaration(swift::irgen::IRBuilder&, llvm::ArrayRef<llvm::Value*>, swift::irgen::DebugTypeInfo, swift::SILDebugScope const*, std::__1::optional<swift::SILLocation>, swift::SILDebugVariable, swift::irgen::IndirectionKind, swift::irgen::ArtificialKind, swift::irgen::AddrDbgInstrKind) + 224
21 swift-frontend           0x0000000101340144 (anonymous namespace)::IRGenSILFunction::visitSILBasicBlock(swift::SILBasicBlock*) + 73892
22 swift-frontend           0x000000010132cf08 (anonymous namespace)::IRGenSILFunction::emitSILFunction() + 9164
23 swift-frontend           0x000000010132a5f4 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 1524
24 swift-frontend           0x00000001011cffcc swift::irgen::IRGenerator::emitGlobalTopLevel(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>> const&) + 740
25 swift-frontend           0x00000001012dd69c swift::IRGenRequest::evaluate(swift::Evaluator&, swift::IRGenDescriptor) const + 2160
26 swift-frontend           0x0000000101329af4 swift::GeneratedModule swift::SimpleRequest<swift::IRGenRequest, swift::GeneratedModule (swift::IRGenDescriptor), (swift::RequestFlags)9>::callDerived<0ul>(swift::Evaluator&, std::__1::integer_sequence<unsigned long, 0ul>) const + 200
27 swift-frontend           0x00000001012e5f14 swift::IRGenRequest::OutputType swift::Evaluator::getResultUncached<swift::IRGenRequest, swift::IRGenRequest::OutputType swift::evaluateOrFatal<swift::IRGenRequest>(swift::Evaluator&, swift::IRGenRequest)::'lambda'()>(swift::IRGenRequest const&, swift::IRGenRequest::OutputType swift::evaluateOrFatal<swift::IRGenRequest>(swift::Evaluator&, swift::IRGenRequest)::'lambda'()) + 212
28 swift-frontend           0x00000001012de760 swift::performIRGeneration(swift::ModuleDecl*, swift::IRGenOptions const&, swift::TBDGenOptions const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>, llvm::GlobalVariable**) + 1400
29 swift-frontend           0x0000000100dfbe28 generateIR(swift::IRGenOptions const&, swift::TBDGenOptions const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>, swift::PrimarySpecificPaths const&, llvm::StringRef, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, llvm::GlobalVariable*&, llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>) + 272
30 swift-frontend           0x0000000100df8058 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*) + 1416
31 swift-frontend           0x0000000100df7724 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1164
32 swift-frontend           0x0000000100e0865c withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) + 160
33 swift-frontend           0x0000000100df9b10 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 708
34 swift-frontend           0x0000000100df8a7c swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2368
35 swift-frontend           0x0000000100c2f4dc swift::mainEntry(int, char const**) + 3096
36 dyld                     0x0000000196d2a0e0 start + 2360

Expected behavior

No crash or an actionable diagnostic error message

Environment

Apple Swift version 6.0-dev (LLVM 7fe091223bc821e, Swift 92f5eee)
Target: arm64-apple-macosx14.0

Additional information

No response

@MaxDesiatov MaxDesiatov added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. IRGen LLVM IR generation optimized only Flag: An issue whose reproduction requires optimized compilation debug info Area → compiler → IRGen: Debug information emission crash Bug: A crash, i.e., an abnormal termination of software embedded Embedded Swift labels Mar 6, 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 debug info Area → compiler → IRGen: Debug information emission embedded Embedded Swift IRGen LLVM IR generation optimized only Flag: An issue whose reproduction requires optimized compilation
Projects
None yet
Development

No branches or pull requests

1 participant