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-10185] Runtime crash using KeyPath: load from misaligned raw pointer #52587

Closed
ole opened this issue Mar 26, 2019 · 3 comments
Closed

[SR-10185] Runtime crash using KeyPath: load from misaligned raw pointer #52587

ole opened this issue Mar 26, 2019 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.

Comments

@ole
Copy link
Contributor

ole commented Mar 26, 2019

Previous ID SR-10185
Radar None
Original Reporter @ole
Type Bug
Status Resolved
Resolution Done
Environment

Swift 5.0, Xcode 10.2, macOS 10.14.3
Apple Swift version 5.0 (swiftlang-1001.0.69.3 clang-1001.0.47)

Additional Detail from JIRA
Votes 0
Component/s
Labels Bug
Assignee None
Priority Medium

md5: 406bc3fa8fe951f827660674e3d9dc0c

relates to:

  • SR-10117 EXC_BAD_INSTRUCTION in playground

Issue Description:

This bug is possibly related to SR-10117, which seems to be a similar problem. It's a Swift 5.0 regression.

Run the following code in a playground or in the REPL:

func ~=<T>(pattern: KeyPath<T, Bool>, value: T) -> Bool {
    return value[keyPath: pattern]
}

let char: Character = "A"
switch char {
case \.isASCII:
    print("ASCII")
default:
    print("no match")
}

This crashes with a fatal error on the case .isASCII line: "load from misaligned raw pointer".

Here's the output from the REPL:

Fatal error: load from misaligned raw pointer
2019-03-26 22:07:57.578793+0100 repl_swift[64810:6294573] Fatal error: load from misaligned raw pointer
Process 64810 stopped
* thread #&#8203;1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
    frame #&#8203;0: 0x0000000101229073 libswiftCore.dylib`function signature specialization <Arg[0] = Exploded, Arg[1] = Exploded, Arg[2] = Dead, Arg[3] = Dead> of Swift._fatalErrorMessage(_: Swift.StaticString, _: Swift.StaticString, file: Swift.StaticString, line: Swift.UInt, flags: Swift.UInt32) -> Swift.Never + 307
libswiftCore.dylib`function signature specialization <Arg[0] = Exploded, Arg[1] = Exploded, Arg[2] = Dead, Arg[3] = Dead> of Swift._fatalErrorMessage(_: Swift.StaticString, _: Swift.StaticString, file: Swift.StaticString, line: Swift.UInt, flags: Swift.UInt32) -> Swift.Never:
->  0x101229073 <+307>: ud2
    0x101229075 <+309>: movq   %r12, %rdi
    0x101229078 <+312>: addq   $0x10, %rdi
    0x10122907c <+316>: cmpl   $0x80, %r14d
Target 0: (repl_swift) stopped.
char: Character = {
  _str = {
    _guts = {
      _object = {
        _countAndFlagsBits = <extracting data from value failed>

        _object = <extracting data from value failed>

      }
    }
  }
}
Execution interrupted. Enter code to recover and continue.
Enter LLDB commands to investigate (type :help for assistance.)

The code runs fine in Xcode 10.1 (Swift 4.2). You'll have to add an extension for the `Character.isASCII` property, which doesn't exist in Swift 4.2. A dummy implementation is good enough:

extension Character {
    var isASCII: Bool {
        return true
    }
}

I haven't tested it on master.

@ole
Copy link
Contributor Author

ole commented Mar 26, 2019

@jckarter
Copy link
Member

I agree, this sounds an awful lot like https://bugs.swift.org/browse/SR-10117.

@Agarunov
Copy link

No crash in Xcode 11.4

@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.
Projects
None yet
Development

No branches or pull requests

3 participants