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-4220] Compiler aborts with code involving IOUs and bridging casts #46803

Closed
tjw opened this issue Mar 11, 2017 · 9 comments
Closed

[SR-4220] Compiler aborts with code involving IOUs and bridging casts #46803

tjw opened this issue Mar 11, 2017 · 9 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

@tjw
Copy link
Contributor

tjw commented Mar 11, 2017

Previous ID SR-4220
Radar rdar://problem/31042965
Original Reporter @tjw
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

macOS 10.12.3
Xcode 8.3 b4

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

md5: ad64252576e492069556fd4db8902049

is duplicated by:

  • SR-4528 Compiler aborts when optimising a specific project

Issue Description:

  • Open the attached project

  • Build the iOS Frameworks in Release mode

  • Crash; Xcode doesn't show the actual error

  • Copy the failing command and run it in Terminal

"output": "PHI node operands are not the same type as the result!\n %155 = phi %CSo6NSDate* [ %168, %163 ], [ %143, %145 ], 87\nPHI node operands are not the same type as the result!\n %168 = phi %CSo6NSDate* [ %114, %110 ], [ %143, %144 ], 87\nLLVM ERROR: Broken function found, compilation aborted!\n",

  • Open Test.swift

  • Uncomment the version that explicitly unwraps the IUOs

  • Build; succeeds.

@belkadan
Copy link
Contributor

Seems to fail in Debug builds as well.

@swift-ci create

@belkadan
Copy link
Contributor

It looks like it's only the argument that matters here. Leaving the return value to be implicitly unwrapped seems to work fine. This seems pretty strange since the error message is complaining about the NSDate, not the String, but that's what I'm observing.

@swift-ci
Copy link
Collaborator

Comment by Dan Loewenherz (JIRA)

I'm getting this crash too, but don't know how to isolate what code is causing it (25k LOC project). 🙁

@belkadan Any hints on how I might be able to track down the culprit?

PHI node operands are not the same type as the result!
  %397 = phi %CSo15NSDecimalNumber* [ %368, %365 ], [ %386, %388 ], !dbg !550
PHI node operands are not the same type as the result!
  %754 = phi %CSo15NSDecimalNumber* [ %717, %714 ], [ %735, %737 ], !dbg !610
LLVM ERROR: Broken function found, compilation aborted!

@tjw
Copy link
Contributor Author

tjw commented Mar 28, 2017

dloewenherz (JIRA User) the approach I took was to notice the `NSDate` mention in the errors and start slicing out bits that referenced `NSDate` with:

fatalError("trimming")
#if false
   ... code referencing NSDate ...
#endif

I got lucky since there weren't many mentions of NSDate in Swift files in the project I was in. You might be able to do the same thing with NSDecimalNumber in your project.

@swift-ci
Copy link
Collaborator

Comment by Dan Loewenherz (JIRA)

@tjw Thanks, that's a great suggestion. There are about 270 references to NSDecimalNumber in my project...but it seems like this compiler error only rears its head during instantiation. I'll comb through and do a binary search on those lines and see what I can find.

@swift-ci
Copy link
Collaborator

Comment by Dan Loewenherz (JIRA)

After two days of wrestling with this, no luck. 🙁

@belkadan is there any way to have the Swift compiler output which line number is the source of the problem?

@swift-ci
Copy link
Collaborator

Comment by Dan Loewenherz (JIRA)

Update: I was able to suppress this compiler error by updating the Swift Compiler Optimization Level in Xcode to "Fast, Single-File Optimization" (was "Fast, Whole Module Optimization"). Still have no idea what line is causing the problem.

@swift-ci
Copy link
Collaborator

swift-ci commented Apr 3, 2017

Comment by Bill Boland (JIRA)

Just wanted to add a reference to the posts at fastlane fastlane/fastlane#8698 about this same compiler issue with Xcode 8.3 release. In my case, it was with the init of NSDecimalNumber. Using Single-File Optimization did not help me...probably because, in my project, an NSDecimalNumber was being created with and without an optional in the same file. I was able to recreate the issue with a new project and two files each having a class that created an NSDecimalNumber (one with a String and one with a String optional). Changed Debug to use WMO and got:

PHI node operands are not the same type as the result!
  %1423 = phi %CSo15NSDecimalNumber* [ %1438, %1433 ], [ %1411, %1413 ], !dbg !12471
PHI node operands are not the same type as the result!
  %1438 = phi %CSo15NSDecimalNumber* [ %1384, %1381 ], [ %1411, %1412 ], !dbg !12471
LLVM ERROR: Broken function found, compilation aborted!

Widget.swift

class Widget {
    func doSomething(_ configDict: [String: Any]) {
        let otherCountStr = configDict["otherCount"] as? String
        let otherCount = NSDecimalNumber(string: otherCountStr)
        print(otherCount)
    }
}

Foo.swift

class Foo {
    func doSomething(_ configDict: [String: Any]) {
        let otherCountStr = configDict["otherCount"] as? String ?? "1"
        let otherCount = NSDecimalNumber(string: otherCountStr)
        print(otherCount)
    }
}

@bob-wilson
Copy link

Arnold fixed this already:
#7306

@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
This issue was closed.
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