Skip to content

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

Merged
merged 1 commit into from
May 10, 2024

Conversation

augusto2112
Copy link
Contributor

rdar://127251788

@augusto2112
Copy link
Contributor Author

@swift-ci smoke test

@adrian-prantl
Copy link
Contributor

I don't understand how the test failure only happens on this branch, but: swiftlang/llvm-project#8714

@augusto2112
Copy link
Contributor Author

@swift-ci smoke test

@@ -1418,6 +1418,9 @@ bool DeclContext::isAsyncContext() const {
}

SourceLoc swift::extractNearestSourceLoc(const DeclContext *dc) {
if (!dc)
return SourceLoc();
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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.

@augusto2112 augusto2112 force-pushed the nullptr-source-lock branch from c55ccb5 to 5fa686b Compare May 8, 2024 21:55
@augusto2112 augusto2112 changed the title Add nullptr check in swift::extractNearestSourceLoc Add nullptr check in maybeExtractNearestSourceLoc May 8, 2024
@augusto2112 augusto2112 requested a review from xedin May 8, 2024 21:55
@augusto2112
Copy link
Contributor Author

@swift-ci smoke test

For templated types which are pointers, check if the pointer is null in
maybeExtractNearestSourceLoc.

rdar://127251788
@augusto2112 augusto2112 force-pushed the nullptr-source-lock branch from 5fa686b to b7bc872 Compare May 9, 2024 16:50
@augusto2112
Copy link
Contributor Author

@swift-ci smoke test

@augusto2112 augusto2112 merged commit db1c721 into swiftlang:main May 10, 2024
3 checks passed
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.

3 participants