-
Notifications
You must be signed in to change notification settings - Fork 14.4k
Remove unneeded checks for null; NFC #145686
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
AaronBallman
merged 2 commits into
llvm:main
from
AaronBallman:aballman-sa-token-annotator
Jun 25, 2025
Merged
Remove unneeded checks for null; NFC #145686
AaronBallman
merged 2 commits into
llvm:main
from
AaronBallman:aballman-sa-token-annotator
Jun 25, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
At the start of the case for `tok::colon`, we do an early return if `Prev` is null. Nothing else within that case modifies the value of `Prev`, so the checks for null are unnecessary and were confusing static analysis tools.
@llvm/pr-subscribers-clang-format Author: Aaron Ballman (AaronBallman) ChangesAt the start of the case for Full diff: https://github.com/llvm/llvm-project/pull/145686.diff 1 Files Affected:
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index d2f8b2703a9a3..6ad9a79998426 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1371,7 +1371,7 @@ class AnnotatingParser {
Tok->setType(TT_InlineASMColon);
} else if (Contexts.back().ColonIsDictLiteral || Style.isProto()) {
Tok->setType(TT_DictLiteral);
- if (Prev && Style.isTextProto())
+ if (Style.isTextProto())
Prev->setType(TT_SelectorName);
} else if (Contexts.back().ColonIsObjCMethodExpr ||
Line.startsWith(TT_ObjCMethodSpecifier)) {
@@ -1408,7 +1408,6 @@ class AnnotatingParser {
}
} else if (Contexts.back().ContextType == Context::C11GenericSelection) {
Tok->setType(TT_GenericSelectionColon);
- assert(Prev);
if (Prev->isPointerOrReference())
Prev->setFinalizedType(TT_PointerOrReference);
} else if ((CurrentToken && CurrentToken->is(tok::numeric_constant)) ||
@@ -1419,8 +1418,6 @@ class AnnotatingParser {
!Line.getFirstNonComment()->isOneOf(tok::kw_enum, tok::kw_case,
tok::kw_default) &&
!Line.startsWith(tok::kw_typedef, tok::kw_enum)) {
- if (!Prev)
- break;
if (Prev->isOneOf(tok::r_paren, tok::kw_noexcept) ||
Prev->ClosesRequiresClause) {
Tok->setType(TT_CtorInitializerColon);
|
HazardyKnusperkeks
approved these changes
Jun 25, 2025
owenca
added a commit
that referenced
this pull request
Jun 26, 2025
anthonyhatran
pushed a commit
to anthonyhatran/llvm-project
that referenced
this pull request
Jun 26, 2025
At the start of the case for `tok::colon`, we do an early return if `Prev` is null. Nothing else within that case modifies the value of `Prev`, so the checks for null are unnecessary and were confusing static analysis tools.
anthonyhatran
pushed a commit
to anthonyhatran/llvm-project
that referenced
this pull request
Jun 26, 2025
rlavaee
pushed a commit
to rlavaee/llvm-project
that referenced
this pull request
Jul 1, 2025
At the start of the case for `tok::colon`, we do an early return if `Prev` is null. Nothing else within that case modifies the value of `Prev`, so the checks for null are unnecessary and were confusing static analysis tools.
rlavaee
pushed a commit
to rlavaee/llvm-project
that referenced
this pull request
Jul 1, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
At the start of the case for
tok::colon
, we do an early return ifPrev
is null. Nothing else within that case modifies the value ofPrev
, so the checks for null are unnecessary and were confusingstatic analysis tools.