[PATCH] D91915: [clang-tidy] Fix RenamerClangTidy checks trying to emit a fix that isnt a valid identifier
Nathan James via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 23 12:05:02 PST 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9f3edc323a88: [clang-tidy] Fix RenamerClangTidy checks trying to emit a fix that isnt a valid… (authored by njames93).
Changed prior to commit:
https://reviews.llvm.org/D91915?vs=306854&id=307156#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D91915/new/
https://reviews.llvm.org/D91915
Files:
clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.h
clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming-bugfix-name-conflicts.cpp
Index: clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming-bugfix-name-conflicts.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming-bugfix-name-conflicts.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming-bugfix-name-conflicts.cpp
@@ -25,3 +25,13 @@
return 0;
}
+
+int func3(int _0Bad) {
+ // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: invalid case style for parameter '_0Bad'; cannot be fixed automatically [readability-identifier-naming]
+ // CHECK-FIXES: {{^}}int func3(int _0Bad) {{{$}}
+ if (_0Bad == 1) {
+ // CHECK-FIXES: {{^}} if (_0Bad == 1) {{{$}}
+ return 2;
+ }
+ return 0;
+}
Index: clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.h
===================================================================
--- clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.h
+++ clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.h
@@ -59,6 +59,9 @@
/// automatically.
ConflictsWithMacroDefinition,
+ /// The fixup results in an identifier that is not a valid c/c++ identifier.
+ FixInvalidIdentifier,
+
/// Values pass this threshold will be ignored completely
/// i.e no message, no fixup.
IgnoreFailureThreshold,
Index: clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
+++ clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
@@ -10,6 +10,7 @@
#include "ASTUtils.h"
#include "clang/AST/CXXInheritance.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Basic/CharInfo.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Lex/PPCallbacks.h"
#include "clang/Lex/Preprocessor.h"
@@ -463,6 +464,8 @@
Failure.FixStatus = ShouldFixStatus::ConflictsWithKeyword;
else if (Ident->hasMacroDefinition())
Failure.FixStatus = ShouldFixStatus::ConflictsWithMacroDefinition;
+ } else if (!isValidIdentifier(Info.Fixup)) {
+ Failure.FixStatus = ShouldFixStatus::FixInvalidIdentifier;
}
Failure.Info = std::move(Info);
@@ -503,7 +506,8 @@
static std::string
getDiagnosticSuffix(const RenamerClangTidyCheck::ShouldFixStatus FixStatus,
const std::string &Fixup) {
- if (Fixup.empty())
+ if (Fixup.empty() ||
+ FixStatus == RenamerClangTidyCheck::ShouldFixStatus::FixInvalidIdentifier)
return "; cannot be fixed automatically";
if (FixStatus == RenamerClangTidyCheck::ShouldFixStatus::ShouldFix)
return {};
@@ -517,7 +521,6 @@
RenamerClangTidyCheck::ShouldFixStatus::ConflictsWithMacroDefinition)
return "; cannot be fixed because '" + Fixup +
"' would conflict with a macro definition";
-
llvm_unreachable("invalid ShouldFixStatus");
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91915.307156.patch
Type: text/x-patch
Size: 2938 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201123/e4655527/attachment.bin>
More information about the cfe-commits
mailing list