Skip to content

Commit 2bb3fb0

Browse files
Handle PluginAttrInstances using ManagedStatic
We need to make sure that PluginAttrInstances is deleted before shared libraries are unloaded, because otherwise when deleting its contents we'll try to access a virtual destructor which no longer exists. As shared libraries are managed using ManagedStatic we can do this by also using ManagedStatic for PluginAttrInstances as ManagedStatics are deleted in reverse order of construction and we know that PluginAttrInstances will only be accessed, and thus constructed, after shared libraries have been loaded.
1 parent 00c5793 commit 2bb3fb0

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

clang/lib/Sema/ParsedAttr.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "llvm/ADT/SmallString.h"
2020
#include "llvm/ADT/SmallVector.h"
2121
#include "llvm/ADT/StringRef.h"
22+
#include "llvm/Support/ManagedStatic.h"
2223
#include <cassert>
2324
#include <cstddef>
2425
#include <utility>
@@ -121,18 +122,19 @@ const ParsedAttrInfo &ParsedAttrInfo::get(const AttributeCommonInfo &A) {
121122

122123
// Otherwise this may be an attribute defined by a plugin. First instantiate
123124
// all plugin attributes if we haven't already done so.
124-
static std::list<std::unique_ptr<ParsedAttrInfo>> PluginAttrInstances;
125-
if (PluginAttrInstances.empty())
125+
static llvm::ManagedStatic<std::list<std::unique_ptr<ParsedAttrInfo>>>
126+
PluginAttrInstances;
127+
if (PluginAttrInstances->empty())
126128
for (auto It : ParsedAttrInfoRegistry::entries())
127-
PluginAttrInstances.emplace_back(It.instantiate());
129+
PluginAttrInstances->emplace_back(It.instantiate());
128130

129131
// Search for a ParsedAttrInfo whose name and syntax match.
130132
std::string FullName = A.getNormalizedFullName();
131133
AttributeCommonInfo::Syntax SyntaxUsed = A.getSyntax();
132134
if (SyntaxUsed == AttributeCommonInfo::AS_ContextSensitiveKeyword)
133135
SyntaxUsed = AttributeCommonInfo::AS_Keyword;
134136

135-
for (auto &Ptr : PluginAttrInstances)
137+
for (auto &Ptr : *PluginAttrInstances)
136138
for (auto &S : Ptr->Spellings)
137139
if (S.Syntax == SyntaxUsed && S.NormalizedFullName == FullName)
138140
return *Ptr;

0 commit comments

Comments
 (0)