From c748359c14956ae6453435a7fa7659af0b46916b Mon Sep 17 00:00:00 2001 From: Manman Ren Date: Tue, 6 Sep 2016 18:16:54 +0000 Subject: [PATCH] Modules: Fix an assertion in DeclContext::buildLookup. When calling getMostRecentDecl, we can pull in more definitions from a module. We call getPrimaryContext afterwards to make sure that we buildLookup on a primary context. rdar://27926200 llvm-svn: 280728 --- clang/lib/AST/DeclBase.cpp | 10 ++++++---- clang/test/Modules/Inputs/lookup-assert/Base.h | 4 ++++ clang/test/Modules/Inputs/lookup-assert/Derive.h | 3 +++ clang/test/Modules/Inputs/lookup-assert/H3.h | 1 + clang/test/Modules/Inputs/lookup-assert/module.map | 4 ++++ clang/test/Modules/lookup-assert.m | 10 ++++++++++ 6 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 clang/test/Modules/Inputs/lookup-assert/Base.h create mode 100644 clang/test/Modules/Inputs/lookup-assert/Derive.h create mode 100644 clang/test/Modules/Inputs/lookup-assert/H3.h create mode 100644 clang/test/Modules/Inputs/lookup-assert/module.map create mode 100644 clang/test/Modules/lookup-assert.m diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp index 8342c0f..4586d4b 100644 --- a/clang/lib/AST/DeclBase.cpp +++ b/clang/lib/AST/DeclBase.cpp @@ -1411,10 +1411,6 @@ DeclContext::lookup(DeclarationName Name) const { assert(DeclKind != Decl::LinkageSpec && "Should not perform lookups into linkage specs!"); - const DeclContext *PrimaryContext = getPrimaryContext(); - if (PrimaryContext != this) - return PrimaryContext->lookup(Name); - // If we have an external source, ensure that any later redeclarations of this // context have been loaded, since they may add names to the result of this // lookup (or add external visible storage). @@ -1422,6 +1418,12 @@ DeclContext::lookup(DeclarationName Name) const { if (Source) (void)cast(this)->getMostRecentDecl(); + // getMostRecentDecl can change the result of getPrimaryContext. Call + // getPrimaryContext afterwards. + const DeclContext *PrimaryContext = getPrimaryContext(); + if (PrimaryContext != this) + return PrimaryContext->lookup(Name); + if (hasExternalVisibleStorage()) { assert(Source && "external visible storage but no external source?"); diff --git a/clang/test/Modules/Inputs/lookup-assert/Base.h b/clang/test/Modules/Inputs/lookup-assert/Base.h new file mode 100644 index 0000000..8d5e06b --- /dev/null +++ b/clang/test/Modules/Inputs/lookup-assert/Base.h @@ -0,0 +1,4 @@ +@interface BaseInterface +- (void) test; +@end + diff --git a/clang/test/Modules/Inputs/lookup-assert/Derive.h b/clang/test/Modules/Inputs/lookup-assert/Derive.h new file mode 100644 index 0000000..313a961 --- /dev/null +++ b/clang/test/Modules/Inputs/lookup-assert/Derive.h @@ -0,0 +1,3 @@ +#include "Base.h" +@interface DerivedInterface : BaseInterface +@end diff --git a/clang/test/Modules/Inputs/lookup-assert/H3.h b/clang/test/Modules/Inputs/lookup-assert/H3.h new file mode 100644 index 0000000..3d8f878 --- /dev/null +++ b/clang/test/Modules/Inputs/lookup-assert/H3.h @@ -0,0 +1 @@ +#include "Base.h" diff --git a/clang/test/Modules/Inputs/lookup-assert/module.map b/clang/test/Modules/Inputs/lookup-assert/module.map new file mode 100644 index 0000000..e8a89eb --- /dev/null +++ b/clang/test/Modules/Inputs/lookup-assert/module.map @@ -0,0 +1,4 @@ +module X { + header "H3.h" + export * +} diff --git a/clang/test/Modules/lookup-assert.m b/clang/test/Modules/lookup-assert.m new file mode 100644 index 0000000..2697fb1 --- /dev/null +++ b/clang/test/Modules/lookup-assert.m @@ -0,0 +1,10 @@ +// RUN: rm -rf %t +// RUN: %clang_cc1 -fmodules-cache-path=%t -fmodules -fimplicit-module-maps -I %S/Inputs/lookup-assert %s -verify +// expected-no-diagnostics + +#include "Derive.h" +#import +@implementation DerivedInterface +- (void)test { +} +@end -- 2.7.4