Skip to content

Revert "[clang-tidy] Preserve line endings in macro-to-enum fixes"#202247

Merged
zeyi2 merged 1 commit into
mainfrom
revert-202054-acp/zeyi2/8493648801080207
Jun 8, 2026
Merged

Revert "[clang-tidy] Preserve line endings in macro-to-enum fixes"#202247
zeyi2 merged 1 commit into
mainfrom
revert-202054-acp/zeyi2/8493648801080207

Conversation

@zeyi2
Copy link
Copy Markdown
Member

@zeyi2 zeyi2 commented Jun 8, 2026

This commit encountered PCH related errors on buildbot, so revert it for now.

@llvmorg-github-actions
Copy link
Copy Markdown

llvmorg-github-actions Bot commented Jun 8, 2026

@llvm/pr-subscribers-clang-tools-extra

@llvm/pr-subscribers-clang-tidy

Author: Zeyi Xu (zeyi2)

Changes

This commit encountered PCH related errors on buildbot, so revert it for now.


Full diff: https://github.com/llvm/llvm-project/pull/202247.diff

6 Files Affected:

  • (modified) clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp (+2-7)
  • (modified) clang-tools-extra/docs/ReleaseNotes.rst (-4)
  • (modified) clang-tools-extra/test/.gitattributes (-2)
  • (removed) clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/macro-to-enum/crlf.cpp (-2)
  • (removed) clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/macro-to-enum/crlf.cpp.expected (-4)
  • (removed) clang-tools-extra/test/clang-tidy/checkers/modernize/macro-to-enum-crlf.cpp (-6)
diff --git a/clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp b/clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp
index aa4732ceba7e0..1c49c32f9fecb 100644
--- a/clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp
@@ -470,15 +470,11 @@ void MacroToEnumCallbacks::warnMacroEnum(const EnumMacro &Macro) const {
 void MacroToEnumCallbacks::fixEnumMacro(const MacroList &MacroList) const {
   SourceLocation Begin =
       MacroList.front().Directive->getMacroInfo()->getDefinitionLoc();
-  const StringRef LineEnding =
-      SM.getBufferData(SM.getFileID(Begin)).detectEOL();
-
   Begin = SM.translateLineCol(SM.getFileID(Begin),
                               SM.getSpellingLineNumber(Begin), 1);
   const DiagnosticBuilder Diagnostic =
       Check->diag(Begin, "replace macro with enum")
-      << FixItHint::CreateInsertion(Begin,
-                                    (llvm::Twine("enum {") + LineEnding).str());
+      << FixItHint::CreateInsertion(Begin, "enum {\n");
 
   for (size_t I = 0U; I < MacroList.size(); ++I) {
     const EnumMacro &Macro = MacroList[I];
@@ -507,8 +503,7 @@ void MacroToEnumCallbacks::fixEnumMacro(const MacroList &MacroList) const {
       LangOpts);
   End = SM.translateLineCol(SM.getFileID(End),
                             SM.getSpellingLineNumber(End) + 1, 1);
-  Diagnostic << FixItHint::CreateInsertion(
-      End, (llvm::Twine("};") + LineEnding).str());
+  Diagnostic << FixItHint::CreateInsertion(End, "};\n");
 }
 
 void MacroToEnumCheck::registerPPCallbacks(const SourceManager &SM,
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index 350ff0872c8e5..fca6c21f22768 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -581,10 +581,6 @@ Changes in existing checks
   positives on project headers that use the same name as a standard library
   header.
 
-- Improved :doc:`modernize-macro-to-enum
-  <clang-tidy/checks/modernize/macro-to-enum>` check by preserving source file
-  line endings in fix-it replacements.
-
 - Improved :doc:`modernize-pass-by-value
   <clang-tidy/checks/modernize/pass-by-value>` check by adding `IgnoreMacros`
   option to suppress warnings in macros.
diff --git a/clang-tools-extra/test/.gitattributes b/clang-tools-extra/test/.gitattributes
index 3c39030a95eab..3d4df1e9976bc 100644
--- a/clang-tools-extra/test/.gitattributes
+++ b/clang-tools-extra/test/.gitattributes
@@ -13,5 +13,3 @@ clang-tidy/infrastructure/export-diagnostics.cpp -text
 # These test input files rely on two-byte Windows (CRLF) line endings.
 clang-apply-replacements/Inputs/crlf/crlf.cpp -text
 clang-apply-replacements/Inputs/crlf/crlf.cpp.expected -text
-clang-tidy/checkers/modernize/Inputs/macro-to-enum/crlf.cpp -text
-clang-tidy/checkers/modernize/Inputs/macro-to-enum/crlf.cpp.expected -text
diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/macro-to-enum/crlf.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/macro-to-enum/crlf.cpp
deleted file mode 100644
index c05d3cd5823ba..0000000000000
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/macro-to-enum/crlf.cpp
+++ /dev/null
@@ -1,2 +0,0 @@
-#define RED 1
-#define GREEN 2
diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/macro-to-enum/crlf.cpp.expected b/clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/macro-to-enum/crlf.cpp.expected
deleted file mode 100644
index 31100df321bb3..0000000000000
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/macro-to-enum/crlf.cpp.expected
+++ /dev/null
@@ -1,4 +0,0 @@
-enum {
-RED = 1,
-GREEN = 2
-};
diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/macro-to-enum-crlf.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/macro-to-enum-crlf.cpp
deleted file mode 100644
index ae54e5b7fe430..0000000000000
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/macro-to-enum-crlf.cpp
+++ /dev/null
@@ -1,6 +0,0 @@
-// Verify the fix-it preserves CRLF line endings.
-
-// RUN: cp %S/Inputs/macro-to-enum/crlf.cpp %t.cpp
-// RUN: chmod u+w %t.cpp
-// RUN: clang-tidy %t.cpp -fix --checks='-*,modernize-macro-to-enum' > %t.out 2>&1
-// RUN: diff %t.cpp %S/Inputs/macro-to-enum/crlf.cpp.expected

@zeyi2 zeyi2 disabled auto-merge June 8, 2026 02:46
@zeyi2 zeyi2 merged commit cc52760 into main Jun 8, 2026
14 of 15 checks passed
@zeyi2 zeyi2 deleted the revert-202054-acp/zeyi2/8493648801080207 branch June 8, 2026 02:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant