eja08
eja08

Reputation: 4840

Segmentation fault on a simple swift script

I have a very simple script written in swift and running this with swift file.swift

import Foundation

let url = URL(string: "www.google.com")

and this gives me a segfault error with this message

Stack dump:
0.  Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -interpret file.swift -enable-objc-interop -stack-check -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -color-diagnostics -module-name file 
1.  Apple Swift version 5.2 (swiftlang-1103.0.32.1 clang-1103.0.32.29)
2.  While running user code "file.swift"
0  swift                    0x00000001101354ea PrintStackTraceSignalHandler(void*) + 42
1  swift                    0x0000000110134cc0 SignalHandler(int) + 352
2  libsystem_platform.dylib 0x00007fff6c0aa5fd _sigtramp + 29
3  libsystem_platform.dylib 0x00007ffee3e196a8 _sigtramp + 2010575048
4  swift                    0x000000010beb89ba llvm::MCJIT::runFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>) + 458
5  swift                    0x000000010bebfa2b llvm::ExecutionEngine::runFunctionAsMain(llvm::Function*, 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&, char const* const*) + 2011
6  swift                    0x000000010be94aea performCompileStepsPostSILGen(swift::CompilerInstance&, swift::CompilerInvocation&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, bool, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, bool, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 14362
7  swift                    0x000000010be894a5 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 55813
8  swift                    0x000000010bdff4d3 main + 1283
9  libdyld.dylib            0x00007fff6beb1cc9 start + 1
zsh: segmentation fault  swift file.swift

any ideas as to where the problem is? Thanks!

EDIT: I have tried putting the code to Xcode and it works as it should.

Upvotes: 2

Views: 503

Answers (1)

Mert
Mert

Reputation: 6065

I had a script which was working and suddenly stopped. Exactly on the line where I have created an URL. It was working on Xcode but not from terminal.

Looks like, it is bug.

If you first compile by using swiftc then run it, it is working.

I have found the answer in the following page:

https://blog.kulman.sk/workaround-for-swift-scripts-crash/

Upvotes: 2

Related Questions