Skip to content

Add a defensive nullptr check. #37422

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

Merged
merged 1 commit into from
May 18, 2021

Conversation

adrian-prantl
Copy link
Contributor

ASTContext::get##NAME##Type() can return an empty type and we have LLDB crash
logs that show this can really happen.

rdar://74503567
(cherry picked from commit 9c8f325)

ASTContext::get##NAME##Type() can return an empty type and we have LLDB crash
logs that show this can really happen.

rdar://74503567
(cherry picked from commit 9c8f325)
@adrian-prantl
Copy link
Contributor Author

@swift-ci test

@adrian-prantl adrian-prantl requested a review from beccadax May 14, 2021 16:17
@CodaFi
Copy link
Contributor

CodaFi commented May 14, 2021

You shouldn't get the null type period from these functions. This usually indicates the standard library is not being loaded.

@adrian-prantl
Copy link
Contributor Author

... which is something that can happen in LLDB.

@adrian-prantl
Copy link
Contributor Author

I only have a crashlog and no reproducer, so I don't know if the root cause was that the stdlib wasn't loaded (which can happen if we reconstruct the triple wrong, or debug a binary built with a different toolchain, or ...) but if a function can return a nullptr the result needs to be checked so the error can be bubbled up and diagnosed.

@CodaFi
Copy link
Contributor

CodaFi commented May 15, 2021

I want to have these functions crash on null. If LLDB doesn't have stdlib loaded, it should not be allowed to make semantic queries into the compiler. Anything that can go wrong, will go wrong.

https://github.com/apple/swift/blob/42a89af00cafcbd58438c8852e7d15a2b5f50c1f/lib/Frontend/Frontend.cpp#L1056

@CodaFi
Copy link
Contributor

CodaFi commented May 15, 2021

That said, my opposition here is philosophical in nature. We should still take this check.

@tschuett
Copy link
Contributor

It feels like you are hiding the real problem and it may deserve a log message.

@adrian-prantl adrian-prantl merged commit f500823 into swiftlang:release/5.4 May 18, 2021
@adrian-prantl
Copy link
Contributor Author

I want to have these functions crash on null.

This is very understandable from a compiler developer's point of view, but long-lived tools like the Swift REPL or LLDB that embed the Swift compiler as a library you generally want to always report or log errors and avoid crashing at all costs. Crashing the debugger is always a terrible user experience. It's fine if evaluating an expression is returning an error, and there are lots of useful things you can do in the debugger even if the Swift AST context is broken.

As for this specific case, I don't have any data about the root cause here. Generally, LLDB avoids using a Swift AST context once it went into a fatal error state, but for that to work reliably we need to make sure to actually bubble up all errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants