Improve "[cling] DefinitionShadower: allow shadowing of non-user-defined declarations (#6571)"

The patch applies a patch to remove duplicated entries from the StoredDeclsList.
Apparently, reading a yet-to-be-determined PCM file adds the same `Decl *` to
the lookup table. Trying to remove it using `StoredDeclsList::remove()` makes
an internal assertion to fail, as it expects the Decl to disappear from the
lookup table after being removed.

So far, `darwin.pcm` seems like one of the possible causes of this problem, but
more investigation is needed.
This commit is contained in:
Vassil Vassilev 2020-11-12 19:30:49 +00:00 committed by jenkins
parent 74e4407225
commit fedeedc2cd

View File

@ -19,6 +19,8 @@
#include "clang/Sema/Lookup.h"
#include "clang/Sema/Sema.h"
#include <algorithm>
using namespace clang;
namespace cling {
@ -77,8 +79,15 @@ namespace cling {
m_Sema->IdResolver.RemoveDecl(D);
}
clang::StoredDeclsList &SDL = (*m_TU->getLookupPtr())[D->getDeclName()];
if (SDL.getAsVector() || SDL.getAsDecl() == D)
SDL.remove(D);
if (SDL.getAsDecl() == D) {
SDL.setOnlyValue(nullptr);
}
if (auto Vec = SDL.getAsVector()) {
// FIXME: investigate why StoredDeclList has duplicated entries coming from PCM.
Vec->erase(std::remove_if(Vec->begin(), Vec->end(),
[D](Decl *Other) { return cast<Decl>(D) == Other; }),
Vec->end());
}
if (InterpreterCallbacks *IC = m_Interp.getCallbacks())
IC->DefinitionShadowed(D);