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-11630] Broken module found, compilation aborted! Trap 6 #54041

Open
krzyzanowskim opened this issue Oct 17, 2019 · 5 comments
Open

[SR-11630] Broken module found, compilation aborted! Trap 6 #54041

krzyzanowskim opened this issue Oct 17, 2019 · 5 comments
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

Comments

@krzyzanowskim
Copy link
Contributor

Previous ID SR-11630
Radar rdar://problem/56378005
Original Reporter @krzyzanowskim
Type Bug

Attachment: Download

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash
Assignee None
Priority Medium

md5: b06099272141edaa8c5a64a008703bfa

Issue Description:

Xcode 11.1 said I should report crash log, so I'm doing:

To reproduce, try to build Tests for https://github.com/krzyzanowskim/CryptoSwift

Global variable initializer type does not match global variable type!
[12 x i8]* @"$s11CryptoSwift15BlockModeOptionV4noneACvpZ"
Global variable initializer type does not match global variable type!
[12 x i8]* @"$s11CryptoSwift15BlockModeOptionV28initializationVectorRequiredACvpZ"
Global variable initializer type does not match global variable type!
[12 x i8]* @"$s11CryptoSwift15BlockModeOptionV15paddingRequiredACvpZ"
Global variable initializer type does not match global variable type!
[12 x i8]* @"$s11CryptoSwift15BlockModeOptionV19useEncryptToDecryptACvpZ"
<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!
0  swift                    0x0000000106bfeeb3 PrintStackTraceSignalHandler(void*) + 51
1  swift                    0x0000000106bfe686 SignalHandler(int) + 358
2  libsystem_platform.dylib 0x00007fff7caa6b5d _sigtramp + 29
3  libsystem_platform.dylib 0x0000700008c306f0 _sigtramp + 2350422960
4  libsystem_c.dylib        0x00007fff7c9606a6 abort + 127
5  swift                    0x000000010284d150 std::__1::unique_ptr<swift::DiagnosticConsumer, std::__1::default_delete<swift::DiagnosticConsumer> > llvm::function_ref<std::__1::unique_ptr<swift::DiagnosticConsumer, std::__1::default_delete<swift::DiagnosticConsumer> > (swift::InputFile const&)>::callback_fn<createSerializedDiagnosticConsumerIfNeeded(swift::FrontendInputsAndOutputs const&)::$_15>(long, swift::InputFile const&) + 0
6  swift                    0x0000000106b77cd6 llvm::report_fatal_error(llvm::Twine const&, bool) + 278
7  swift                    0x0000000106b77bbb llvm::report_fatal_error(char const*, bool) + 43
8  swift                    0x0000000106b37e9c (anonymous namespace)::VerifierLegacyPass::doFinalization(llvm::Module&) + 204
9  swift                    0x0000000106ad9423 llvm::FPPassManager::doFinalization(llvm::Module&) + 51
10 swift                    0x0000000106ae1a72 llvm::legacy::FunctionPassManagerImpl::doFinalization(llvm::Module&) + 82
11 swift                    0x0000000102a64f15 swift::performLLVM(swift::IRGenOptions&, swift::DiagnosticEngine*, llvm::sys::SmartMutex<false>*, llvm::GlobalVariable*, llvm::Module*, llvm::TargetMachine*, swift::version::Version const&, llvm::StringRef, swift::UnifiedStatsReporter*) + 4677
12 swift                    0x0000000102a699a0 (anonymous namespace)::LLVMCodeGenThreads::Thread::run() + 208
13 swift                    0x0000000102a69849 (anonymous namespace)::LLVMCodeGenThreads::runThread(void*) + 9
14 libsystem_pthread.dylib  0x00007fff7caaf2eb _pthread_body + 126
15 libsystem_pthread.dylib  0x00007fff7cab2249 _pthread_start + 66
16 libsystem_pthread.dylib  0x00007fff7caae40d thread_start + 13
error: Abort trap: 6 (in target 'CryptoSwift' from project 'CryptoSwift')
@jckarter
Copy link
Member

@swift-ci create

@krzyzanowskim
Copy link
Contributor Author

As of now, it looks that it's something with ENABLE_TESTABILITY = YES

@krzyzanowskim
Copy link
Contributor Author

This is the troublemaker code:

public struct BlockModeOption: OptionSet {
    public let rawValue: Int

    public init(rawValue: Int) {
        self.rawValue = rawValue
    }

    static let none = BlockModeOption(rawValue: 1 << 0)
    static let initializationVectorRequired = BlockModeOption(rawValue: 1 << 1)
    static let paddingRequired = BlockModeOption(rawValue: 1 << 2)
    static let useEncryptToDecrypt = BlockModeOption(rawValue: 1 << 3)
}

if I mark properties as "public" it will build with testability, otherwise it crashes

@beccadax
Copy link
Contributor

This bug reproduced for me. Interestingly, I couldn’t reproduce it with SwiftPM—I had to open the xcworkspace instead. This is because one of the xcconfig files enables BUILD_LIBRARY_FOR_DISTRIBUTION; if I comment out that line, Swift compilation in Xcode completes and I get an ld error instead.

After investigating, I think we’re running into trouble because we’re doing a @testable import of a resilient module. With swift-DEVELOPMENT-SNAPSHOT-2019-10-14-a.xctoolchain, I get a failed assertion in the SIL GlobalOpt pass:

Assertion failed: (isLoadableOrOpaque(Ty)), function createStruct, file /Users/buildnode/jenkins/workspace/oss-swift-package-osx/swift/include/swift/SIL/SILBuilder.h, line 1230.
[snip]
1.  Apple Swift version 5.1.1-dev (LLVM 6e04008c7f, Swift 9a4abf47a4)
2.  While running pass #&#8203;250564 SILModuleTransform "GlobalOpt".

-sil-verify-all does not narrow this down any further. lldb backtrace:

* thread #&#8203;1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
  * frame #&#8203;0: 0x00007fff6a66e49a libsystem_kernel.dylib`__pthread_kill + 10
    frame #&#8203;1: 0x00007fff6a72b6cb libsystem_pthread.dylib`pthread_kill + 384
    frame #&#8203;2: 0x00007fff6a5f6a1c libsystem_c.dylib`abort + 120
    frame #&#8203;3: 0x00007fff6a5f5cd6 libsystem_c.dylib`__assert_rtn + 314
    frame #&#8203;4: 0x0000000103f125d3 swift`swift::SILBuilder::createStruct(swift::SILLocation, swift::SILType, llvm::ArrayRef<swift::SILValue>) (.cold.1) + 35
    frame #&#8203;5: 0x00000001008f984e swift`swift::SILBuilder::createStruct(this=<unavailable>, Loc=SILLocation @ 0x00007ffeefbf5810, Ty=<unavailable>, Elements=<unavailable>) at SILBuilder.h:1230:5 [opt]
    frame #&#8203;6: 0x000000010051c063 swift`swift::SILCloner<swift::SILFunctionCloner>::visitStructInst(this=0x00007ffeefbf5b10, Inst=0x00000001235807c0) at SILCloner.h:1809:26 [opt]
    frame #&#8203;7: 0x00000001005114cc swift`swift::SILCloner<swift::SILFunctionCloner>::visitBlocksDepthFirst(swift::SILBasicBlock*) at SILCloner.h:576:14 [opt]
    frame #&#8203;8: 0x0000000100511490 swift`swift::SILCloner<swift::SILFunctionCloner>::visitBlocksDepthFirst(this=0x00007ffeefbf5b10, startBB=<unavailable>) at SILCloner.h:683 [opt]
    frame #&#8203;9: 0x000000010051127f swift`swift::SILCloner<swift::SILFunctionCloner>::cloneFunctionBody(this=0x000000012769a790, F=<unavailable>, clonedEntryBB=0x00007ffeefbf5b10, entryArgs=<unavailable>) at SILCloner.h:630:3 [opt]
    frame #&#8203;10: 0x0000000100510e07 swift`swift::SILFunctionCloner::cloneFunction(this=0x00007ffeefbf5b10, origF=0x00000001128a14d8) at SILCloner.h:515:14 [opt]
    frame #&#8203;11: 0x000000010050c97d swift`(anonymous namespace)::SILGlobalOpt::run() [inlined] genGetterFromInit(FunctionBuilder=<unavailable>, InitF=0x00000001128a14d8, varDecl=<unavailable>) at GlobalOpt.cpp:562:10 [opt]
    frame #&#8203;12: 0x000000010050c932 swift`(anonymous namespace)::SILGlobalOpt::run() [inlined] (anonymous namespace)::SILGlobalOpt::replaceLoadsByKnownValue(this=0x00007ffeefbf6118, CallToOnce=<unavailable>, AddrF=<unavailable>, InitF=0x00000001128a14d8, SILG=<unavailable>, InitVal=0x00000001235807c0, Calls=<unavailable>) at GlobalOpt.cpp:662 [opt]
    frame #&#8203;13: 0x000000010050c7de swift`(anonymous namespace)::SILGlobalOpt::run() [inlined] (anonymous namespace)::SILGlobalOpt::optimizeInitializer(this=0x00007ffeefbf6118, AddrF=<unavailable>, Calls=<unavailable>) at GlobalOpt.cpp:760 [opt]
    frame #&#8203;14: 0x000000010050c377 swift`(anonymous namespace)::SILGlobalOpt::run(this=0x00007ffeefbf6118) at GlobalOpt.cpp:961 [opt]
    frame #&#8203;15: 0x000000010050b6b4 swift`(anonymous namespace)::SILGlobalOptPass::run(this=0x0000000124aa7180) at GlobalOpt.cpp:983:56 [opt]
    frame #&#8203;16: 0x00000001005f357e swift`swift::SILPassManager::runModulePass(this=0x00007ffeefbf6418, TransIdx=14) at PassManager.cpp:557:8 [opt]
    frame #&#8203;17: 0x00000001005f3f9a swift`swift::SILPassManager::execute(this=0x00007ffeefbf6418) at PassManager.cpp:623:7 [opt]
    frame #&#8203;18: 0x00000001001b4c4b swift`swift::SILPassManager::executePassPipelinePlan(this=0x00007ffeefbf6418, Plan=0x00007ffeefbf65f0) at PassManager.h:269:7 [opt]
    frame #&#8203;19: 0x00000001005fb5c5 swift`swift::runSILOptimizationPasses(Module=0x000000011a0ed2c0) at Passes.cpp:103:6 [opt]
    frame #&#8203;20: 0x00000001002782f5 swift`swift::CompilerInstance::performSILProcessing(swift::SILModule*, swift::UnifiedStatsReporter*) [inlined] performSILOptimizations(Invocation=<unavailable>, SM=<unavailable>) at Frontend.cpp:1152:5 [opt]
    frame #&#8203;21: 0x00000001002782ed swift`swift::CompilerInstance::performSILProcessing(this=0x0000000112005c00, silModule=0x000000011a0ed2c0, stats=0x0000000000000000) at Frontend.cpp:1185 [opt]
    frame #&#8203;22: 0x000000010006aabf swift`performCompileStepsPostSILGen(Instance=0x00000000000000ba, Invocation=0x00007ffeefbf6ee8, SM=unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> > @ 0x00007ffeefbf6e38, astGuaranteedToCorrespondToSIL=<unavailable>, MSF=<unavailable>, PSPs=0x00007ffeefbf6c80, moduleIsPublic=<unavailable>, ReturnValue=0x00007ffeefbf800c, observer=0x0000000000000000, Stats=0x0000000000000000) at FrontendTool.cpp:1355:16 [opt]
    frame #&#8203;23: 0x000000010005fb1a swift`performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) [inlined] performCompileStepsPostSema(Invocation=<unavailable>, Instance=<unavailable>, ReturnValue=<unavailable>, observer=0x0000000000000000, Stats=<unavailable>) at FrontendTool.cpp:0 [opt]
    frame #&#8203;24: 0x000000010005fa65 swift`performCompile(Instance=<unavailable>, Invocation=0x00007ffeefbf6ee8, Args=<unavailable>, ReturnValue=0x00007ffeefbf800c, observer=0x0000000000000000, Stats=0x0000000000000000) at FrontendTool.cpp:1150 [opt]
    frame #&#8203;25: 0x000000010005d026 swift`swift::performFrontend(Args=<unavailable>, Argv0=<unavailable>, MainAddr=<unavailable>, observer=0x0000000000000000) at FrontendTool.cpp:1895:5 [opt]
    frame #&#8203;26: 0x00000001000025b9 swift`main(argc_=<unavailable>, argv_=<unavailable>) at driver.cpp:273:12 [opt]
    frame #&#8203;27: 0x00007fff6a51f2e5 libdyld.dylib`start + 1

The instruction it’s trying to clone (Inst in frame #6) is %5 in this basic block:

sil_scope 1 { loc "/Users/brent/Downloads/CryptoSwift-master/Sources/CryptoSwift/BlockMode/BlockModeOptions.swift":24:12 parent @globalinit_018_7DB1384D9A44D7634B13B25ECAE5EDEEA_func33 : $@convention(c) () -> () }
sil_scope 2 { loc "/Users/brent/Downloads/CryptoSwift-master/Sources/CryptoSwift/BlockMode/BlockModeOptions.swift":24:47 parent 1 }
sil_scope 3 { loc "/Users/brent/Downloads/CryptoSwift-master/Sources/CryptoSwift/BlockMode/BlockModeOptions.swift":19:12 parent @$s11CryptoSwift15BlockModeOptionV8rawValueACSi_tcfC : $@convention(method) (Int, @thin BlockModeOption.Type) -> @out BlockModeOption inlined_at 2 }
sil_scope 4 { loc "/Users/brent/Downloads/CryptoSwift-master/Sources/CryptoSwift/BlockMode/BlockModeOptions.swift":19:32 parent 3 inlined_at 2 }
bb0:
  alloc_global @$s11CryptoSwift15BlockModeOptionV28initializationVectorRequiredACvpZ // id: %0
  %1 = global_addr @$s11CryptoSwift15BlockModeOptionV28initializationVectorRequiredACvpZ : $*BlockModeOption // user: %6
  %2 = integer_literal $Builtin.Int64, 2          // user: %3
  %3 = struct $Int (%2 : $Builtin.Int64)          // users: %5, %4
  debug_value %3 : $Int, let, name "rawValue", argno 1 // id: %4
  %5 = struct $BlockModeOption (%3 : $Int)        // user: %6    <===== crashes cloning this intruction
  store %5 to %1 : $*BlockModeOption              // id: %6
  %7 = tuple ()                                   // user: %8
  return %7 : $()                                 // id: %8

The struct in question is:

(struct_decl range=[/Users/brent/Downloads/CryptoSwift-master/Sources/CryptoSwift/BlockMode/BlockModeOptions.swift:16:8 - line:27:1] "BlockModeOption" interface type='BlockModeOption.Type' access=public resilient inherits: OptionSet
[snip]

Note that we’re applying StructInst to a resilient struct from outside the module. Perhaps we’re inlining code from inside the module that isn’t valid from outside it? Or perhaps we were previously confused about the resilience expansion we should use?

@eeckstein
Copy link
Member

@krzyzanowskim Is this still relevant?

@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
Projects
None yet
Development

No branches or pull requests

5 participants