Illegal instruction: 4

My debug compile is failing with: Illegal instruction: 4

I can archive and release to testflight with no problem.. the program happens when running in debugger what is up with this?

Replies

Is the Swift compiler itself crashing? If so, what do you see in the Report navigator?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

I get;


Error

Illegal instruction: 4

Command CompileSwift failed with a nonzero exit code

CompileSwift normal arm64 /Users/maduser/Projects/iOS/ProjectName/dir/MyTaggedIncidentsCell.swift (in target 'Foo' from project 'Foo')

cd /Users/maduser/Projects/iOS/FooApp

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c /Users/maduser/Projects/iOS/ProjectName/dir/Models/HistoryDetailData.swift /Users/maduser/Projects/iOS/ProjectName/dir/Utils.swift /Users/maduser/Projects/iOS/ProjectName/dir/MyPlateIncidentsDetailViewController.swift /Users/maduser/Projects/iOS/ProjectName/dir/MyTaggedIncidentsViewController.swift /Users/maduser/Projects/iOS/ProjectName/dir/SwiftyXMLParser/Accessor.swift /Users/maduser/Projects/iOS/ProjectName/dir/HistoryDetailCell.swift /Users/maduser/Projects/iOS/ProjectName/dir/HistoryDetailViewController.swift /Users/maduser/Projects/iOS/ProjectName/dir/Foo2ViewController.swift /Users/maduser/Projects/iOS/ProjectName/dir/SwiftyXMLParser/Error.swift /Users/maduser/Projects/iOS/ProjectName/dir/ViewController.swift /Users/maduser/Projects/iOS/ProjectName/dir/HistoryViewController.swift /Users/maduser/Projects/iOS/ProjectName/dir/AppDelegate.swift /Users/maduser/Projects/iOS/ProjectName/dir/MyPlateIncidentsViewController.swift /Users/maduser/Projects/iOS/ProjectName/dir/SetupViewController.swift /Users/maduser/Projects/iOS/ProjectName/dir/DropdownCell.swift /Users/maduser/Projects/iOS/ProjectName/dir/Models/EditHistoryData.swift /Users/maduser/Projects/iOS/ProjectName/dir/MenuView.swift /Users/maduser/Projects/iOS/ProjectName/dir/SwiftyXMLParser/Parser.swift /Users/maduser/Projects/iOS/ProjectName/dir/Models/HistoryData.swift /Users/maduser/Projects/iOS/ProjectName/dir/Models/Country.swift /Users/maduser/Projects/iOS/ProjectName/dir/HistoryCell.swift /Users/maduser/Projects/iOS/ProjectName/dir/SwiftyXMLParser/Element.swift /Users/maduser/Projects/iOS/ProjectName/dir/MenuViewCell.swift /Users/maduser/Projects/iOS/ProjectName/dir/Models/HistoryDetailInfo.swift -primary-file /Users/maduser/Projects/iOS/ProjectName/dir/MyTaggedIncidentsCell.swift /Users/maduser/Projects/iOS/ProjectName/dir/EditHistoryDetailViewController.swift /Users/maduser/Projects/iOS/ProjectName/dir/SwiftyXMLParser/XML.swift /Users/maduser/Projects/iOS/ProjectName/dir/DropdownView.swift /Users/maduser/Projects/iOS/ProjectName/dir/RecoverAccountViewController.swift /Users/maduser/Projects/iOS/ProjectName/dir/SceneDelegate.swift /Users/maduser/Projects/iOS/ProjectName/dir/Constants.swift -emit-module-path /Users/maduser/Library/Developer/Xcode/DerivedData/Foo-dricxfjiycdbavacbivcskgbvfut/Build/Intermediates.noindex/Foo.build/Debug-iphoneos/Foo.build/Objects-normal/arm64/MyTaggedIncidentsCell\~partial.swiftmodule -emit-module-doc-path /Users/maduser/Library/Developer/Xcode/DerivedData/Foo-dricxfjiycdbavacbivcskgbvfut/Build/Intermediates.noindex/Foo.build/Debug-iphoneos/Foo.build/Objects-normal/arm64/MyTaggedIncidentsCell\~partial.swiftdoc -emit-module-source-info-path /Users/maduser/Library/Developer/Xcode/DerivedData/Foo-dricxfjiycdbavacbivcskgbvfut/Build/Intermediates.noindex/Foo.build/Debug-iphoneos/Foo.build/Objects-normal/arm64/MyTaggedIncidentsCell\~partial.swiftsourceinfo -serialize-diagnostics-path /Users/maduser/Library/Developer/Xcode/DerivedData/Foo-dricxfjiycdbavacbivcskgbvfut/Build/Intermediates.noindex/Foo.build/Debug-iphoneos/Foo.build/Objects-normal/arm64/MyTaggedIncidentsCell.dia -emit-dependencies-path /Users/maduser/Library/Developer/Xcode/DerivedData/Foo-dricxfjiycdbavacbivcskgbvfut/Build/Intermediates.noindex/Foo.build/Debug-iphoneos/Foo.build/Objects-normal/arm64/MyTaggedIncidentsCell.d -emit-reference-dependencies-path /Users/maduser/Library/Developer/Xcode/DerivedData/Foo-dricxfjiycdbavacbivcskgbvfut/Build/Intermediates.noindex/Foo.build/Debug-iphoneos/Foo.build/Objects-normal/arm64/MyTaggedIncidentsCell.swiftdeps -target arm64-apple-ios13.3 -Xllvm -aarch64-use-tbi -enable-objc-interop -stack-check -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.4.sdk -I /Users/maduser/Library/Developer/Xcode/DerivedData/Foo-dricxfjiycdbavacbivcskgbvfut/Build/Products/Debug-iphoneos -F /Users/maduser/Library/Developer/Xcode/DerivedData/Foo-dricxfjiycdbavacbivcskgbvfut/Build/Products/Debug-iphoneos -enable-testing -g -module-cache-path /Users/maduser/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 5 -enforce-exclusivity=checked -Onone -D DEBUG -serialize-debugging-options -Xcc -working-directory -Xcc /Users/maduser/Projects/iOS/FooApp -enable-anonymous-context-mangled-names -Xcc -I/Users/maduser/Library/Developer/Xcode/DerivedData/Foo-dricxfjiycdbavacbivcskgbvfut/Build/Intermediates.noindex/Foo.build/Debug-iphoneos/Foo.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/maduser/Library/Developer/Xcode/DerivedData/Foo-dricxfjiycdbavacbivcskgbvfut/Build/Intermediates.noindex/Foo.build/Debug-iphoneos/Foo.build/Foo-generated-files.hmap -Xcc -I/Users/maduser/Library/Developer/Xcode/DerivedData/Foo-dricxfjiycdbavacbivcskgbvfut/Build/Intermediates.noindex/Foo.build/Debug-iphoneos/Foo.build/Foo-own-target-headers.hmap -Xcc -I/Users/maduser/Library/Developer/Xcode/DerivedData/Foo-dricxfjiycdbavacbivcskgbvfut/Build/Intermediates.noindex/Foo.build/Debug-iphoneos/Foo.build/Foo-all-target-headers.hmap -Xcc -iquote -Xcc /Users/maduser/Library/Developer/Xcode/DerivedData/Foo-dricxfjiycdbavacbivcskgbvfut/Build/Intermediates.noindex/Foo.build/Debug-iphoneos/Foo.build/Foo-project-headers.hmap -Xcc -I/Users/maduser/Library/Developer/Xcode/DerivedData/Foo-dricxfjiycdbavacbivcskgbvfut/Build/Products/Debug-iphoneos/include -Xcc -I/Users/maduser/Library/Developer/Xcode/DerivedData/Foo-dricxfjiycdbavacbivcskgbvfut/Build/Intermediates.noindex/Foo.build/Debug-iphoneos/Foo.build/DerivedSources-normal/arm64 -Xcc -I/Users/maduser/Library/Developer/Xcode/DerivedData/Foo-dricxfjiycdbavacbivcskgbvfut/Build/Intermediates.noindex/Foo.build/Debug-iphoneos/Foo.build/DerivedSources/arm64 -Xcc -I/Users/maduser/Library/Developer/Xcode/DerivedData/Foo-dricxfjiycdbavacbivcskgbvfut/Build/Intermediates.noindex/Foo.build/Debug-iphoneos/Foo.build/DerivedSources -Xcc -DDEBUG=1 -Xcc -DCOCOAPODS=1 -module-name Foo -o /Users/maduser/Library/Developer/Xcode/DerivedData/Foo-dricxfjiycdbavacbivcskgbvfut/Build/Intermediates.noindex/Foo.build/Debug-iphoneos/Foo.build/Objects-normal/arm64/MyTaggedIncidentsCell.o -embed-bitcode-marker -index-store-path /Users/maduser/Library/Developer/Xcode/DerivedData/Foo-dricxfjiycdbavacbivcskgbvfut/Index/DataStore -index-system-modules

First up, if you can distill this down to a small test project, or are willing to share your main project, you should file a bug about this. The Swift compiler shouldn’t crash.

Please post your bug number, just for the record.

Secondly, when the compiler crashes like this it often generates a backtrace. You should be able to see this in the full build transcript, which you can save via the Export button in the Report navigator. The backtrace there might yield some clues as to what’s gone wrong.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

I had this exact problem and after pain staking countless hours, I went through my entire app, removed everything and added each line back into the app and then built the app after every line... I even continued to make sure it wasn't a fluke, but this line of code is what caused my Illegal instruction: 4

let pos = CGPoint(x: Double.random(in: 0 ... 2000), y: Double.random(in: 0 ... (self.view?.bounds.height)!))

This line was in a class called gameBoard: SKScene

Not sure if this will help anyone else's issue with illegal instruction: 4 but this is what caused mine and rewriting it fixed it.

  • Hi, I am getting the Illegal instruction: 4.

    This is just with Xcode 13, my project has millions of lines of code so the solution of going one by one is impossible.

    I have filed a bug with Apple, the backtrace report doesn't seem to say anything useful either.

    Any help would be greatly appreciated.

Add a Comment

Hi, I am getting the Illegal instruction: 4.

This is just with Xcode 13, my project has millions of lines of code so the solution of going one by one is impossible.

I have filed a bug with Apple, the backtrace report doesn't seem to say anything useful either.

Any help would be greatly appreciated.

  • Did you have some answer for this problem? I had this same issue and I don't even know how to fix :(

  • I also have same problem while try to using php artisan key:generate for my project Illegal instruction: 4

Add a Comment

I encountered this compiler failure while using XCode 13.4.1 on MacOS 12.6. The source of the problem seems to be when I try and compile this method that creates a SwiftUI toolbar. In order to get the compiler to stop failing I have to comment out this method.

func buildToolbar() -> ToolbarItemGroup<some View> {
    ToolbarItemGroup(placement: .navigationBarTrailing) {
        Button(action: {
            viewModel.signOut()
        },
            label: {
                Label(viewModel.resetLabel, systemImage: "clear")
                    .labelStyle(.titleOnly)
            }
        )
            .confirmationDialog(
                "Are you sure?",
                isPresented: $viewModel.isConfirmPresented,
                titleVisibility: .visible
            ) {
                Button("Not now", role: .cancel) {
                }
                Button("Reset", role: .destructive) {
                    viewModel.didConfirmSignOut()
                }
            } message: {
                if viewModel.isSomething {
                    Text("This will sign out of your account and will clear all [REDACTED]
                } else {
                    Text("This will attempt to deregister any accounts with the [REDACTOED]
                }
            }
    }
}

I had this exact same issue. The compiler was confused about a weak callback with this code:

{ [weak self] in
    guard let self = self else { return }
}

Using a reserved word seems to be a bad idea. Rename the conditional variable fixed the compiler:

guard let this = self else { return }
  • Sorry, I posted my reply a little too quickly. The compiler was confused on this specific line:

    progressLayer.frame.size.width = (progressLayer.superlayer?.frame.width ?? .zero) * progress
    
    Which was in a function called from the weak callback mentioned above -

    The reason was because it did't want to use this optional value: 'progressLayer.superlayer?.frame.width'. And for the record, this error appeared in Xcode 13, but Xcode 14 had no issue compiling with this line.

Add a Comment