[clang-tidy] Add null-checking in Use designated Initializer check - #220093
[clang-tidy] Add null-checking in Use designated Initializer check#220093GTaf wants to merge 1 commit into
Conversation
|
Hello @GTaf 👋 Thank you for submitting a Pull Request (PR) to the LLVM Project. Since this is your first PR, here are a few useful links covering our main contribution policies and review practices.
Please reply to this message to confirm that you have read these policies, especially the LLVM AI Tool Use Policy, and that any AI tool usage has been noted in the PR description. Frequently asked questionsHow do I add reviewers? This PR will be automatically labeled, and the relevant teams will be notified. For some parts of the project, reviewers may also be added automatically. You can also add reviewers manually using the Reviewers section on this page. If you cannot use that section, it is probably because you do not have write permissions for the repository. In that case, you can request a review by tagging reviewers in a comment using What if there are no comments? If you have not received any comments on your PR after a week, you can request a review by pinging the PR with a comment such as “Ping”. The common courtesy ping rate is once a week. Please remember that you are asking for volunteer time from other developers. Are any special GitHub settings required to contribute to LLVM? We only require contributors to have a public email address associated with their GitHub commits, see this section of LLVM Developer Policy for details. If you have questions, feel free to leave a comment on this PR, or ask on LLVM Discord or LLVM Discourse. Thank you, |
|
@llvm/pr-subscribers-clang-tools-extra @llvm/pr-subscribers-clang-tidy Author: GTaf ChangesTrying to fix #219739 Full diff: https://github.com/llvm/llvm-project/pull/220093.diff 1 Files Affected:
diff --git a/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
index 5874c061d299f..696e6f40d66c8 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
@@ -17,6 +17,7 @@
#include "clang/ASTMatchers/ASTMatchersMacros.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Lex/Lexer.h"
+#include "llvm/Support/Casting.h"
using namespace clang::ast_matchers;
@@ -42,7 +43,7 @@ static constexpr bool StrictCppStandardComplianceDefault = true;
static unsigned getNumberOfDesignated(const InitListExpr *SyntacticInitList) {
return llvm::count_if(*SyntacticInitList, [](auto *InitExpr) {
- return isa<DesignatedInitExpr>(InitExpr);
+ return llvm::isa_and_nonnull<DesignatedInitExpr>(InitExpr);
});
}
|
|
Please mention changes in Release Notes. |
And tests |
zeyi2
left a comment
There was a problem hiding this comment.
The code part change LGTM, one nit comment below
| #include "clang/ASTMatchers/ASTMatchersMacros.h" | ||
| #include "clang/Basic/Diagnostic.h" | ||
| #include "clang/Lex/Lexer.h" | ||
| #include "llvm/Support/Casting.h" |
There was a problem hiding this comment.
Looks like unnecessary include, please see https://llvm.org/docs/CodingStandards.html#include-as-little-as-possible
|
Also I removed "Fixes #219739", since this PR only addresses the |
|
Thanks for your feedback. I'm working on your assigned tasks. Making a relevant test is a bit challenging to me has the issue is to say that an invalid code that use to crash the binary now just show the correct error. I'm looking into it. |
774a0ae to
0d4e2c2
Compare
I think you can use invalid code with See |
0d4e2c2 to
ee40584
Compare
|
|
||
| #### Changes in existing checks | ||
|
|
||
| - Fixed a crash in {doc}`modernize-use-designated-initializers |
There was a problem hiding this comment.
Please keep alphabetical order (by check name) in this list.
|
|
||
| - Fixed a crash in {doc}`modernize-use-designated-initializers | ||
| <clang-tidy/checks/modernize/modernize-use-designated-initializers>` when receiving | ||
| a null `Expr`. |
There was a problem hiding this comment.
This is implementation detail. Should be something user-facing.
ee40584 to
3b7de77
Compare
| <clang-tidy/checks/modernize/use-noexcept>` when analyzing malformed template | ||
| code with an unparsed exception specification. | ||
|
|
||
| - Fixed a crash in {doc}`modernize-use-designated-initializers |
There was a problem hiding this comment.
Should be before modernize-use-noexcept.
1b1f7a9 to
bc58258
Compare
|
I believe I did all you pinpointed, thank you very much for your guidance and patience. Please let me know anything that still needs to be fixed |
35ee957 to
30f95ee
Compare
30f95ee to
34a124a
Compare
Part of #219739
This null check should avoid null dereferencing crash in the Use designated Initializer check.
AI has been used in this contribution to understand the code as I'm a beginner to the codebase. The problem understanding and proposed fix is mine.