swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.33k stars 10.34k forks source link

[SR-12727] Compiler crashes when using URL(fileURLWithPath:) in script #55172

Open swift-ci opened 4 years ago

swift-ci commented 4 years ago
Previous ID SR-12727
Radar rdar://problem/62895085
Original Reporter jacob.weightman (JIRA User)
Type Bug
Environment Apple Swift version 5.2.2 (swiftlang-1103.0.32.6 clang-1103.0.32.51) Target: x86_64-apple-darwin19.2.0
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: 6d752f9950ffd826ebc284733688c3a3

Issue Description:

I have the following Swift script:

#!/usr/bin/env xcrun swift
import Foundation
let folderURL = URL(fileURLWithPath: "")

And when I run this from the command line using

./myscript

I get the following stack trace:

Stack dump:
0.  Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -interpret ./crash -enable-objc-interop -stack-check -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -color-diagnostics -module-name crash 
1.  Apple Swift version 5.2.2 (swiftlang-1103.0.32.6 clang-1103.0.32.51)
2.  While running user code "./crash"
0  swift                    0x000000010e9a84ea PrintStackTraceSignalHandler(void*) + 42
1  swift                    0x000000010e9a7cc0 SignalHandler(int) + 352
2  libsystem_platform.dylib 0x00007fff68fb842d _sigtramp + 29
3  libsystem_platform.dylib 0x00007ffee55a89d8 _sigtramp + 2086602184
4  swift                    0x000000010a72b48a llvm::MCJIT::runFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>) + 458
5  swift                    0x000000010a7324fb 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                    0x000000010a7075ba 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                    0x000000010a6fbf75 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 55813
8  swift                    0x000000010a671f53 main + 1283
9  libdyld.dylib            0x00007fff68dbf7fd start + 1
Segmentation fault: 11
beccadax commented 4 years ago

@swift-ci create

eeckstein commented 4 years ago

jacob.weightman (JIRA User) I cannot reproduce this crash.
Maybe something is wrong with your Xcode installation?

Which macOS version are you running?

swift-ci commented 4 years ago

Comment by Jacob Weightman (JIRA)

I'm using MacOS Catalina 10.15.2

Edit: for what it's worth, my copy of Xcode is installed through the App store and up to date. I've also confirmed that this is the selected version of Xcode.

swift-ci commented 4 years ago

Comment by Jacob Weightman (JIRA)

Also, I was not able to reproduce the issue on a Macbook Pro 2019. I encountered this on a Mid 2015 Macbook Pro. @eeckstein do you have ideas about what could be wrong with my Xcode installation?

eeckstein commented 4 years ago

Can you do one experiment: does the crash reproduce if you compile the test statically?

swift test.swift -o a.out && a.out

Is the new MacBook also on 10.15.2?
Maybe you can try to upgrade the os to 10.15.4

swift-ci commented 4 years ago

Comment by Jacob Weightman (JIRA)

Unfortunately I cannot update to 10.15.4 just yet—I encountered this bug on my work computer and IT has not allowed updating to 10.15.4 for whatever reason yet. I've also just confirmed that the 2019 MacBook Pro has been updated to 10.15.4.

I've tried the proposed experiment on the 2015 Macbook Pro, with an interesting result. Running with swift produces the same crash (and no a.out, of course):

swift crash.swift -o a.out

But running with swiftc behaves correctly:

swiftc crash.swift -o a.out && a.out

At the time of reporting I knew that this code would successfully compile in an Xcode project and playground, which was why I reported it as a script-only bug.

eeckstein commented 4 years ago

ok, thanks for the info

eeckstein commented 4 years ago

We fixed a few bugs in the JIT, which will be included in the upcoming swift 5.3 release.
Most likely this crash will be fixed in 5.3

swift-ci commented 4 years ago

Comment by Jacob Weightman (JIRA)

I realize this is still running Swift 5.2, but I just wanted to note that the crash still occurs on Xcode 11.5. I will no longer have suitable hardware to reproduce this bug after today.

Apple Swift version 5.2.4 (swiftlang-1103.0.32.9 clang-1103.0.32.53)
Target: x86_64-apple-darwin19.2.0