Fix assertion failure when emitting code for a merged lambda.

llvm-svn: 338766
This commit is contained in:
Richard Smith 2018-08-02 20:30:52 +00:00
parent db89ec1185
commit 2425338bac
2 changed files with 14 additions and 3 deletions

View File

@ -1327,6 +1327,15 @@ bool CXXRecordDecl::isGenericLambda() const {
return getLambdaData().IsGenericLambda;
}
#ifndef NDEBUG
static bool allLookupResultsAreTheSame(const DeclContext::lookup_result &R) {
for (auto *D : R)
if (!declaresSameEntity(D, R.front()))
return false;
return true;
}
#endif
CXXMethodDecl* CXXRecordDecl::getLambdaCallOperator() const {
if (!isLambda()) return nullptr;
DeclarationName Name =
@ -1334,7 +1343,8 @@ CXXMethodDecl* CXXRecordDecl::getLambdaCallOperator() const {
DeclContext::lookup_result Calls = lookup(Name);
assert(!Calls.empty() && "Missing lambda call operator!");
assert(Calls.size() == 1 && "More than one lambda call operator!");
assert(allLookupResultsAreTheSame(Calls) &&
"More than one lambda call operator!");
NamedDecl *CallOp = Calls.front();
if (const auto *CallOpTmpl = dyn_cast<FunctionTemplateDecl>(CallOp))
@ -1349,7 +1359,8 @@ CXXMethodDecl* CXXRecordDecl::getLambdaStaticInvoker() const {
&getASTContext().Idents.get(getLambdaStaticInvokerName());
DeclContext::lookup_result Invoker = lookup(Name);
if (Invoker.empty()) return nullptr;
assert(Invoker.size() == 1 && "More than one static invoker operator!");
assert(allLookupResultsAreTheSame(Invoker) &&
"More than one static invoker operator!");
NamedDecl *InvokerFun = Invoker.front();
if (const auto *InvokerTemplate = dyn_cast<FunctionTemplateDecl>(InvokerFun))
return cast<CXXMethodDecl>(InvokerTemplate->getTemplatedDecl());

View File

@ -1,4 +1,4 @@
// RUN: %clang_cc1 -fmodules -verify %s
// RUN: %clang_cc1 -fmodules -verify %s -emit-llvm-only
// expected-no-diagnostics
#pragma clang module build A