[clang] f5f1813 - [clang] Extract attribute plugin instantiation to function (NFC)

Anders Waldenborg via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 13 08:48:32 PDT 2023


Author: Anders Waldenborg
Date: 2023-03-13T16:47:51+01:00
New Revision: f5f1813defb5810223de8f916380808a8ed34584

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

LOG: [clang] Extract attribute plugin instantiation to function (NFC)

This moves the code to instantiate the attribute plugins to the same
place where the plugin registry is defined so they live together and the
user of the plugins doesn't have the burden of instantiating the
plugins.

No functional change intended.

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

Added: 
    

Modified: 
    clang/include/clang/Basic/ParsedAttrInfo.h
    clang/lib/Basic/ParsedAttrInfo.cpp
    clang/lib/Sema/ParsedAttr.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Basic/ParsedAttrInfo.h b/clang/include/clang/Basic/ParsedAttrInfo.h
index 3dc022aa4db3..788c960b01bf 100644
--- a/clang/include/clang/Basic/ParsedAttrInfo.h
+++ b/clang/include/clang/Basic/ParsedAttrInfo.h
@@ -20,6 +20,7 @@
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/Support/Registry.h"
 #include <climits>
+#include <list>
 
 namespace clang {
 
@@ -137,6 +138,8 @@ struct ParsedAttrInfo {
 
 typedef llvm::Registry<ParsedAttrInfo> ParsedAttrInfoRegistry;
 
+const std::list<std::unique_ptr<ParsedAttrInfo>> &getAttributePluginInstances();
+
 } // namespace clang
 
 #endif // LLVM_CLANG_BASIC_PARSEDATTRINFO_H

diff  --git a/clang/lib/Basic/ParsedAttrInfo.cpp b/clang/lib/Basic/ParsedAttrInfo.cpp
index 497e05483585..7757f30da511 100644
--- a/clang/lib/Basic/ParsedAttrInfo.cpp
+++ b/clang/lib/Basic/ParsedAttrInfo.cpp
@@ -12,7 +12,21 @@
 //===----------------------------------------------------------------------===//
 
 #include "clang/Basic/ParsedAttrInfo.h"
+#include "llvm/Support/ManagedStatic.h"
+#include <list>
+#include <memory>
 
 using namespace clang;
 
 LLVM_INSTANTIATE_REGISTRY(ParsedAttrInfoRegistry)
+
+const std::list<std::unique_ptr<ParsedAttrInfo>> &
+clang::getAttributePluginInstances() {
+  static llvm::ManagedStatic<std::list<std::unique_ptr<ParsedAttrInfo>>>
+      PluginAttrInstances;
+  if (PluginAttrInstances->empty())
+    for (auto It : ParsedAttrInfoRegistry::entries())
+      PluginAttrInstances->emplace_back(It.instantiate());
+
+  return *PluginAttrInstances;
+}

diff  --git a/clang/lib/Sema/ParsedAttr.cpp b/clang/lib/Sema/ParsedAttr.cpp
index 67254e1aaf23..50191d45b100 100644
--- a/clang/lib/Sema/ParsedAttr.cpp
+++ b/clang/lib/Sema/ParsedAttr.cpp
@@ -19,7 +19,6 @@
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
-#include "llvm/Support/ManagedStatic.h"
 #include <cassert>
 #include <cstddef>
 #include <utility>
@@ -118,13 +117,7 @@ const ParsedAttrInfo &ParsedAttrInfo::get(const AttributeCommonInfo &A) {
   if (A.getParsedKind() == AttributeCommonInfo::IgnoredAttribute)
     return IgnoredParsedAttrInfo;
 
-  // Otherwise this may be an attribute defined by a plugin. First instantiate
-  // all plugin attributes if we haven't already done so.
-  static llvm::ManagedStatic<std::list<std::unique_ptr<ParsedAttrInfo>>>
-      PluginAttrInstances;
-  if (PluginAttrInstances->empty())
-    for (auto It : ParsedAttrInfoRegistry::entries())
-      PluginAttrInstances->emplace_back(It.instantiate());
+  // Otherwise this may be an attribute defined by a plugin.
 
   // Search for a ParsedAttrInfo whose name and syntax match.
   std::string FullName = A.getNormalizedFullName();
@@ -132,7 +125,7 @@ const ParsedAttrInfo &ParsedAttrInfo::get(const AttributeCommonInfo &A) {
   if (SyntaxUsed == AttributeCommonInfo::AS_ContextSensitiveKeyword)
     SyntaxUsed = AttributeCommonInfo::AS_Keyword;
 
-  for (auto &Ptr : *PluginAttrInstances)
+  for (auto &Ptr : getAttributePluginInstances())
     for (auto &S : Ptr->Spellings)
       if (S.Syntax == SyntaxUsed && S.NormalizedFullName == FullName)
         return *Ptr;


        


More information about the cfe-commits mailing list