[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
Sat Nov 21 09:48:18 PST 2020
njames93 created this revision.
njames93 added reviewers: aaron.ballman, alexfh, gribozavr2.
Herald added subscribers: cfe-commits, xazax.hun.
Herald added a project: clang.
njames93 requested review of this revision.
Addresses https://bugs.llvm.org/show_bug.cgi?id=48230.
Handle the case when the Fixup suggested isn't a valid c/c++ identifer.
Repository:
rG LLVM Github Monorepo
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 because '0_bad' is not a valid identifier [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);
@@ -517,6 +520,9 @@
RenamerClangTidyCheck::ShouldFixStatus::ConflictsWithMacroDefinition)
return "; cannot be fixed because '" + Fixup +
"' would conflict with a macro definition";
+ if (FixStatus == RenamerClangTidyCheck::ShouldFixStatus::FixInvalidIdentifier)
+ return "; cannot be fixed because '" + Fixup +
+ "' is not a valid identifier";
llvm_unreachable("invalid ShouldFixStatus");
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91915.306854.patch
Type: text/x-patch
Size: 2713 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201121/a7690cce/attachment-0001.bin>
More information about the cfe-commits
mailing list