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-8754] EXC_BAD_ACCESS visiting Swift stdlib interface #429

Closed
mdiep opened this issue Sep 14, 2018 · 3 comments
Closed

[SR-8754] EXC_BAD_ACCESS visiting Swift stdlib interface #429

mdiep opened this issue Sep 14, 2018 · 3 comments
Labels
bug Something isn't working

Comments

@mdiep
Copy link

mdiep commented Sep 14, 2018

Previous ID SR-8754
Radar None
Original Reporter @mdiep
Type Bug

Attachment: Download

Environment

Xcode 10.0.0 beta 6
Apple Swift version 4.2 (swiftlang-1000.0.36 clang-1000.10.44)
Target: x86_64-apple-darwin17.7.0

SwiftSyntax 26b6ef6

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

md5: cc35c21c959ded0f5ad3a888ff9377d7

Issue Description:

I created a bare-bones Visitor and fed it the generated interface that Xcode shows from the Swift stdlib. It crashes here on the last line:

  public func child(at index: Int) -> Syntax? {
    guard raw.layout.indices.contains(index) else { return nil }
    guard let childData = data.cachedChild(at: index) else { return nil }
    return makeSyntax(root: _root, data: childData)
  }

I've attached the generated interface that I'm trying to visit. Since it's the generated interface, it doesn't have definitions for any of the functions. That might be what's causing problems.

But I think this should still work and it definitely shouldn't crash.

@mdiep
Copy link
Author

mdiep commented Sep 14, 2018

I was able to reduce the crash to:

protocol C {
    subscript(bounds: Range<Array<Int>.Index>) -> Int { get }
}

@belkadan
Copy link

I don't think generated interfaces count as valid Swift syntax, but the reduction you've provided certainly is!

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 9, 2022
@ahoppen
Copy link
Collaborator

ahoppen commented Jun 21, 2022

The reduced example no longer crashes when parsed as SwiftSyntax.

import SwiftSyntax
import SwiftSyntaxParser

let content = """
protocol C {
    subscript(bounds: Range<Array<Int>.Index>) -> Int { get }
}
"""

let sourceFile = try SyntaxParser.parse(source: content)
print(sourceFile)

Sorry for only now getting to this, we missed the issue in JIRA and I only now found it after the migration to GitHub issues.

@ahoppen ahoppen closed this as completed Jun 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants