summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2018-08-02 20:30:52 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2018-08-02 20:30:52 +0000
commit98f1120b4983a57202df2eb6a801fe63d12d5de1 (patch)
tree696b3784901970fab3a67d700b19ee9793322381
parentca1825c22bcd57397ebaf7d9d842134fe29fb4a2 (diff)
Fix assertion failure when emitting code for a merged lambda.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@338766 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/AST/DeclCXX.cpp15
-rw-r--r--test/Modules/merge-lambdas.cpp2
2 files changed, 14 insertions, 3 deletions
diff --git a/lib/AST/DeclCXX.cpp b/lib/AST/DeclCXX.cpp
index c43bdfb58f..8582b543df 100644
--- a/lib/AST/DeclCXX.cpp
+++ b/lib/AST/DeclCXX.cpp
@@ -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());
diff --git a/test/Modules/merge-lambdas.cpp b/test/Modules/merge-lambdas.cpp
index d14483aa3a..8b3b501328 100644
--- a/test/Modules/merge-lambdas.cpp
+++ b/test/Modules/merge-lambdas.cpp
@@ -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