[clang-tools-extra] 988c3f5 - [clang-tidy] Fix RenamerClangTidyChecks suggesting invalid macro identifiers

Logan Smith via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 10 10:35:14 PST 2022


Author: Logan Smith
Date: 2022-01-10T10:35:04-08:00
New Revision: 988c3f5f96925e3bcd757043314e345b8f65589f

URL: https://github.com/llvm/llvm-project/commit/988c3f5f96925e3bcd757043314e345b8f65589f
DIFF: https://github.com/llvm/llvm-project/commit/988c3f5f96925e3bcd757043314e345b8f65589f.diff

LOG: [clang-tidy] Fix RenamerClangTidyChecks suggesting invalid macro identifiers

This behavior was fixed for regular identifiers in
9f3edc323a88c1a179a0a5a9dc9a87a2964c0d48, but the same fix was not applied to
macro fixits. This addresses https://github.com/llvm/llvm-project/issues/52895.

Differential Revision: https://reviews.llvm.org/D116824

Added: 
    

Modified: 
    clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
    clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
index a0dcca7f9973c..73b47dca20930 100644
--- a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
@@ -486,6 +486,9 @@ void RenamerClangTidyCheck::checkMacro(SourceManager &SourceMgr,
   NamingCheckFailure &Failure = NamingCheckFailures[ID];
   SourceRange Range(MacroNameTok.getLocation(), MacroNameTok.getEndLoc());
 
+  if (!isValidAsciiIdentifier(Info.Fixup))
+    Failure.FixStatus = ShouldFixStatus::FixInvalidIdentifier;
+
   Failure.Info = std::move(Info);
   addUsage(ID, Range);
 }

diff  --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier.cpp
index 555c673a3f43b..da8a27588611e 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier.cpp
@@ -171,6 +171,11 @@ int _;
 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: declaration uses identifier '_', which is reserved in the global namespace; cannot be fixed automatically [bugprone-reserved-identifier]
 // CHECK-FIXES: {{^}}int _;{{$}}
 
+// https://github.com/llvm/llvm-project/issues/52895
+#define _5_kmph_rpm 459
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: declaration uses identifier '_5_kmph_rpm', which is reserved in the global namespace; cannot be fixed automatically [bugprone-reserved-identifier]
+// CHECK-FIXES: {{^}}#define _5_kmph_rpm 459{{$}}
+
 // these should pass
 #define MACRO(m) int m = 0
 


        


More information about the cfe-commits mailing list