[clang] e044824 - [Lex] Stop allocating/deallocating MacroInfo on a linked list. NFC

Sam McCall via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 26 07:24:33 PDT 2022


Author: Sam McCall
Date: 2022-10-26T16:24:25+02:00
New Revision: e0448245671342ad4f0431aeabef8d575cfd80f5

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

LOG: [Lex] Stop allocating/deallocating MacroInfo on a linked list. NFC

This list was originally used for to make sure MacroInfo's clever memory
management got called (1f1e4bdbf7815c), but that was
simplified in 73a29662b9bf640a and 1f1e4bdbf7815c, and there's nothing left.

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

Added: 
    

Modified: 
    clang/include/clang/Lex/MacroInfo.h
    clang/include/clang/Lex/Preprocessor.h
    clang/lib/Lex/PPDirectives.cpp
    clang/lib/Lex/Preprocessor.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Lex/MacroInfo.h b/clang/include/clang/Lex/MacroInfo.h
index 1947bc8fc509e..dc7ddb1a5939e 100644
--- a/clang/include/clang/Lex/MacroInfo.h
+++ b/clang/include/clang/Lex/MacroInfo.h
@@ -117,9 +117,8 @@ class MacroInfo {
   /// Whether this macro was used as header guard.
   bool UsedForHeaderGuard : 1;
 
-  // Only the Preprocessor gets to create and destroy these.
+  // Only the Preprocessor gets to create these.
   MacroInfo(SourceLocation DefLoc);
-  ~MacroInfo() = default;
 
 public:
   /// Return the location that the macro was defined at.

diff  --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h
index 98596e563e9ee..2c0f8f3a632ff 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -1011,15 +1011,6 @@ class Preprocessor {
   /// invoked (at which point the last position is popped).
   std::vector<CachedTokensTy::size_type> BacktrackPositions;
 
-  struct MacroInfoChain {
-    MacroInfo MI;
-    MacroInfoChain *Next;
-  };
-
-  /// MacroInfos are managed as a chain for easy disposal.  This is the head
-  /// of that list.
-  MacroInfoChain *MIChainHead = nullptr;
-
   /// True if \p Preprocessor::SkipExcludedConditionalBlock() is running.
   /// This is used to guard against calling this function recursively.
   ///

diff  --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index 4a43cfdb0448c..3fc0606d62b9a 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -57,9 +57,8 @@ using namespace clang;
 //===----------------------------------------------------------------------===//
 
 MacroInfo *Preprocessor::AllocateMacroInfo(SourceLocation L) {
-  auto *MIChain = new (BP) MacroInfoChain{L, MIChainHead};
-  MIChainHead = MIChain;
-  return &MIChain->MI;
+  static_assert(std::is_trivially_destructible_v<MacroInfo>, "");
+  return new (BP) MacroInfo(L);
 }
 
 DefMacroDirective *Preprocessor::AllocateDefMacroDirective(MacroInfo *MI,

diff  --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp
index 1cc1dc310d46c..3b11a7a58b681 100644
--- a/clang/lib/Lex/Preprocessor.cpp
+++ b/clang/lib/Lex/Preprocessor.cpp
@@ -165,12 +165,6 @@ Preprocessor::~Preprocessor() {
 
   IncludeMacroStack.clear();
 
-  // Destroy any macro definitions.
-  while (MacroInfoChain *I = MIChainHead) {
-    MIChainHead = I->Next;
-    I->~MacroInfoChain();
-  }
-
   // Free any cached macro expanders.
   // This populates MacroArgCache, so all TokenLexers need to be destroyed
   // before the code below that frees up the MacroArgCache list.


        


More information about the cfe-commits mailing list