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-392] Creating a String from an object of type ErrorType segfaults #43009

Closed
swift-ci opened this issue Dec 27, 2015 · 7 comments
Closed

[SR-392] Creating a String from an object of type ErrorType segfaults #43009

swift-ci opened this issue Dec 27, 2015 · 7 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. runtime The Swift Runtime standard library Area: Standard library umbrella

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-392
Radar None
Original Reporter austin (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

OS X 10.11.2, running development version built from source (SHA: 3d0b77c). I made sure all dependencies were updated and ran the build script with the --clean flag.

Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Bug, Runtime
Assignee jder (JIRA)
Priority Medium

md5: 665c561a48400ef5cc296a7e706545e5

blocks:

  • SR-88 Remove old mirrors

relates to:

  • SR-372 Swift emits a segfaulting program for this source listing

Issue Description:

A variable of type 'ErrorType' causes a segfault if a program attempts to construct a String from it, either using the "String(a)" or "String(reflecting: a)" initializers.

As an example, the following code, whether run in the REPL or compiled into a Swift program, causes a segmentation fault when executed:

class MyErrorClass : ErrorType { }
let a = MyErrorClass()

// These are fine
print("(String(reflecting: a))")
print("(String(a))")

let b : ErrorType = a
// Either of these cause a segfault
print("(String(reflecting: b))")
print("(String(b))")

Note that this does NOT happen when using the version of swiftc bundled with Xcode 7.2. It seems like a regression.

@swift-ci
Copy link
Collaborator Author

Comment by Austin Zheng (JIRA)

A bit of context: I'm rewriting _dump() to not use _Reflectable, which means I can't rely upon _MirrorType's 'summary' property. A natural alternative is to ask the instance to describe itself, via debugDescription, description, etc, which is where the String(reflecting: ) constructor comes in.

@swift-ci
Copy link
Collaborator Author

Comment by Austin Zheng (JIRA)

After doing some more testing, it appears that the crash happens as early as "let b : ErrorType = a".

Also, I occasionally get the following error:

Assertion failed: (newval + quantum >= RC_ONE && "releasing reference with a refcount of zero"), function doDecrementShouldDeallocate, file /Users/austinzheng/Developer/Swift/swift/include/swift/Runtime/../../../stdlib/public/SwiftShims/RefCount.h, line 207.
Abort trap: 6

@swift-ci
Copy link
Collaborator Author

swift-ci commented Jan 2, 2016

Comment by Jesse Rusak (JIRA)

I ran a git bisect on this last night and it identified the following commit as causing this regression:

e09027c

Reverting that commit on top of master seems to fix the issue. I'm guessing the issue has to do with the DynamicCastFlags::DestroyOnFailure flag being passed to the _fail call, which could now destroy the srcDynamicValue rather than the srcValue.

@swift-ci
Copy link
Collaborator Author

swift-ci commented Jan 2, 2016

Comment by Austin Zheng (JIRA)

Thanks for looking into this, I really appreciate it. Is this something you'd like to pursue further, or would you prefer to hand it off to someone else?

@swift-ci
Copy link
Collaborator Author

swift-ci commented Jan 2, 2016

Comment by Jesse Rusak (JIRA)

Yes, I'll try to put something together for this; just wanted to finish up a couple other things before taking it on.

@swift-ci
Copy link
Collaborator Author

swift-ci commented Jan 3, 2016

Comment by Jesse Rusak (JIRA)

I've put up a PR for this here: #861

@swift-ci
Copy link
Collaborator Author

swift-ci commented Jan 9, 2016

Comment by Jesse Rusak (JIRA)

PR was merged here: 35448a1

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 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. runtime The Swift Runtime standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

1 participant