-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Add nullptr check in maybeExtractNearestSourceLoc #73499
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
Conversation
@swift-ci smoke test |
I don't understand how the test failure only happens on this branch, but: swiftlang/llvm-project#8714 |
@swift-ci smoke test |
lib/AST/DeclContext.cpp
Outdated
@@ -1418,6 +1418,9 @@ bool DeclContext::isAsyncContext() const { | |||
} | |||
|
|||
SourceLoc swift::extractNearestSourceLoc(const DeclContext *dc) { | |||
if (!dc) | |||
return SourceLoc(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels like it should be an assert instead and callers should be responsible for action on nullptr
. It should be possible to add additional checks to maybeExtractNearestSourceLoc
in SimpleRequest
to prevent calls to extractNearestSourceLoc
on invalid inputs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xedin I added the check in maybeExtractNearestSourceLoc
for any pointer types instead, let me know what you think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Please add parenthesis though before merging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xedin, sorry, parenthesis around what? The constexpr?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I meant curly braces 🤦 At least for the outer if statement with constexpr, ideally both.
c55ccb5
to
5fa686b
Compare
@swift-ci smoke test |
For templated types which are pointers, check if the pointer is null in maybeExtractNearestSourceLoc. rdar://127251788
5fa686b
to
b7bc872
Compare
@swift-ci smoke test |
rdar://127251788