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

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


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf5f1813defb5: [clang] Extract attribute plugin instantiation to function (NFC) (authored by wanders).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144403/new/

https://reviews.llvm.org/D144403

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


Index: clang/lib/Sema/ParsedAttr.cpp
===================================================================
--- clang/lib/Sema/ParsedAttr.cpp
+++ 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 @@
   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 @@
   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;
Index: clang/lib/Basic/ParsedAttrInfo.cpp
===================================================================
--- clang/lib/Basic/ParsedAttrInfo.cpp
+++ 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;
+}
Index: clang/include/clang/Basic/ParsedAttrInfo.h
===================================================================
--- clang/include/clang/Basic/ParsedAttrInfo.h
+++ 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 @@
 
 typedef llvm::Registry<ParsedAttrInfo> ParsedAttrInfoRegistry;
 
+const std::list<std::unique_ptr<ParsedAttrInfo>> &getAttributePluginInstances();
+
 } // namespace clang
 
 #endif // LLVM_CLANG_BASIC_PARSEDATTRINFO_H


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144403.504683.patch
Type: text/x-patch
Size: 2930 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230313/6a6dbd3b/attachment.bin>


More information about the cfe-commits mailing list