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-11358] Segmentation Fault when compiling a property wrapper with a mutating get projectedValue #53759

Open
swift-ci opened this issue Aug 23, 2019 · 7 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 property wrappers Feature: property wrappers

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-11358
Radar None
Original Reporter kevlario (JIRA User)
Type Bug

Attachment: Download

Environment

Xcode 11 beta 6, on mac OS mojave 10.14.5

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

md5: b0ae3adefac5b0119769526719ea31a4

Issue Description:

When compiling a project that defines a property wrapper with a `projectedValue` property that happens to have a `mutating` getter, I hit a segmentation fault. changing the getter to not be `mutating` (and removing any code that made `mutating` a requirement) lets the compiler continue.

To reproduce, compile the SPM package attached to this issue, including the tests, (either in Xcode itself or with `swift build --build-tests`) and you'll see the attached segfault. If you change CopyOnWrite.swift by removing mutating and commenting the mutating-required code out, the compiler succeeds.

Edit: See the comment below, this is a smaller sample that exhibits the behavior:

@propertyWrapper
struct Thing<Value> {
    var wrappedValue: Value
    public var projectedValue: Value {
        mutating get { wrappedValue } // if this is not mutating, no segfault
    }
}

class Bar {}
struct Foo { // if this is a class, there's no segfault
    @Thing var name: Bar = Bar()
}
@theblixguy
Copy link
Collaborator

This does not crash for me on master.

@belkadan
Copy link
Contributor

@DougGregor, do you have the dup for this?

@swift-ci
Copy link
Collaborator Author

Comment by Kevin Lundberg (JIRA)

I attached a segfault for yesterday's 5.1 snapshot which looks like it had a slightly different assertion error than the compiler in beta 6 has. The development snapshot also has the bug with a slightly different assertion error too, which is also attached

@swift-ci
Copy link
Collaborator Author

Comment by Kevin Lundberg (JIRA)

I have a smaller example which exhibits the crash (using the compiler in Xcode 11 GM Seed), added to the description above.

It seems that structs can't handle generated code for projected values that are mutating gets. changing Foo to a class doesn't crash, or changing projectedValue's get to not be mutating also doesn't crash.

@theblixguy
Copy link
Collaborator

Might be fixed by #27109

It’s been cherry picked to 5.1 as well, could you verify using the next snapshot?

@swift-ci
Copy link
Collaborator Author

Comment by Kevin Lundberg (JIRA)

Thanks for the suggestion! I just tried using the 5.1 snapshot from yesterday, however it still crashes. Not with a segfault 11, but with an abort trap 6 with an assertion failure:

Assertion failed: (!selfParam.isIndirectMutating() && "passing unmaterialized r-value as inout argument"), function prepareAccessorObjectBaseArg, file /Users/buildnode/jenkins/workspace/oss-swift-5.1-package-osx/swift/lib/SILGen/SILGenApply.cpp, line 5943.

I've attached the full stack dump here, from compiling the updated reduced reproduction case: segfault-5.1-snapshot-9-11.txt

Edit: I just tried the trunk snapshot from 9/11 though, and that DID work. the crash on the 5/1 snapshot from yesterday and from 8/23 looks the same, so its probable that whatever fix was made to master wasn't applied to 5.1 by the time the most recent snapshot was made.

@swift-ci
Copy link
Collaborator Author

Comment by Kevin Lundberg (JIRA)

And yeah, it does look like this and SR-11393 are the same issue

@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
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 property wrappers Feature: property wrappers
Projects
None yet
Development

No branches or pull requests

4 participants