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-15137] Null Pointer Dereference in SILFunction.front() #57463

Open
swift-ci opened this issue Aug 30, 2021 · 3 comments
Open

[SR-15137] Null Pointer Dereference in SILFunction.front() #57463

swift-ci opened this issue Aug 30, 2021 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-15137
Radar None
Original Reporter justinfargnoli (JIRA User)
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee jonathanalvares9009 (JIRA)
Priority Medium

md5: b4666bf8c44aac3523ff8b945b555370

Issue Description:

If `SILFunction.front()` link is called on a SILFunction that contains zero basic blocks, then `*begin()` will be a null pointer dereference.

@typesanitizer
Copy link

This is in line with how the C++ standard library's front and back methods on vector work. Is there a specific case where you have hit this null pointer dereference in practice?

@swift-ci
Copy link
Contributor Author

Comment by Justin Fargnoli (JIRA)

I ran into this bug when writing cloneModule for my Alive2 for SIL GSoC project. The `SILCloner` infrastructure that `cloneModule` uses would trigger this bug for ceratin `SILModule`s.

My project mentor, CodaFi (JIRA User), recommended that we add an `assert` here instead of invoking undefined behavior.

Do we want to follow the C++ standard library's example in this case? If we do, then we should edit the `SILCloner` code that invoked the null pointer dereference.

@typesanitizer
Copy link

I think adding an assert is okay, we do have assertions in other places for similar checks.

// Type.h
  TypeBase *operator->() const {
    assert(Ptr && "Cannot dereference a null Type!");
    return Ptr;
  }

An assert will still be compiled away in release mode though (such as in shipping builds).

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 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 itself
Projects
None yet
Development

No branches or pull requests

2 participants