-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
[clang-tidy] Fix crash in C language in readability-non-const-parameter #100461
Merged
PiotrZSL
merged 1 commit into
llvm:main
from
PiotrZSL:100340-clang-tidy-crash-with-readability-non-const-parameter-and-kr-declarations
Jul 25, 2024
Merged
[clang-tidy] Fix crash in C language in readability-non-const-parameter #100461
PiotrZSL
merged 1 commit into
llvm:main
from
PiotrZSL:100340-clang-tidy-crash-with-readability-non-const-parameter-and-kr-declarations
Jul 25, 2024
Conversation
This file contains 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
Fix crash that happen when redeclaration got diffrent number of parameters than definition. Fixes llvm#100340
@llvm/pr-subscribers-clang-tools-extra @llvm/pr-subscribers-clang-tidy Author: Piotr Zegar (PiotrZSL) ChangesFix crash that happen when redeclaration got No release notes, as this will be backported. Fixes #100340 Full diff: https://github.com/llvm/llvm-project/pull/100461.diff 2 Files Affected:
diff --git a/clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp b/clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
index 95a3a5165e2e8..43b69a24bdb16 100644
--- a/clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
@@ -157,9 +157,12 @@ void NonConstParameterCheck::diagnoseNonConstParameters() {
if (!Function)
continue;
unsigned Index = Par->getFunctionScopeIndex();
- for (FunctionDecl *FnDecl : Function->redecls())
+ for (FunctionDecl *FnDecl : Function->redecls()) {
+ if (FnDecl->getNumParams() <= Index)
+ continue;
Fixes.push_back(FixItHint::CreateInsertion(
FnDecl->getParamDecl(Index)->getBeginLoc(), "const "));
+ }
diag(Par->getLocation(), "pointer parameter '%0' can be pointer to const")
<< Par->getName() << Fixes;
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.c b/clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.c
new file mode 100644
index 0000000000000..db50467f3dd94
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.c
@@ -0,0 +1,11 @@
+// RUN: %check_clang_tidy %s readability-non-const-parameter %t
+
+static int f();
+
+int f(p)
+ int *p;
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: pointer parameter 'p' can be pointer to const [readability-non-const-parameter]
+// CHECK-FIXES: {{^}} const int *p;{{$}}
+{
+ return *p;
+}
|
njames93
approved these changes
Jul 25, 2024
yuxuanchen1997
pushed a commit
that referenced
this pull request
Jul 25, 2024
…er (#100461) Summary: Fix crash that happen when redeclaration got different number of parameters than definition. Fixes #100340 Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60250525
llvmbot
pushed a commit
to llvmbot/llvm-project
that referenced
this pull request
Aug 4, 2024
…er (llvm#100461) Fix crash that happen when redeclaration got different number of parameters than definition. Fixes llvm#100340 (cherry picked from commit a27f816)
tru
pushed a commit
to llvmbot/llvm-project
that referenced
this pull request
Aug 19, 2024
…er (llvm#100461) Fix crash that happen when redeclaration got different number of parameters than definition. Fixes llvm#100340 (cherry picked from commit a27f816)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fix crash that happen when redeclaration got
different number of parameters than definition.
No release notes, as this will be backported.
Fixes #100340