summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManman Ren <manman.ren@gmail.com>2016-09-06 18:16:54 +0000
committerManman Ren <manman.ren@gmail.com>2016-09-06 18:16:54 +0000
commitc748359c14956ae6453435a7fa7659af0b46916b (patch)
treedb4eba535c7f2a223ef2f8340c56fc5a05331266
parent4e463b4a2c34c9a98cdf408b3f57ea661209cf70 (diff)
downloadbcm5719-llvm-c748359c14956ae6453435a7fa7659af0b46916b.tar.gz
bcm5719-llvm-c748359c14956ae6453435a7fa7659af0b46916b.zip
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
-rw-r--r--clang/lib/AST/DeclBase.cpp10
-rw-r--r--clang/test/Modules/Inputs/lookup-assert/Base.h4
-rw-r--r--clang/test/Modules/Inputs/lookup-assert/Derive.h3
-rw-r--r--clang/test/Modules/Inputs/lookup-assert/H3.h1
-rw-r--r--clang/test/Modules/Inputs/lookup-assert/module.map4
-rw-r--r--clang/test/Modules/lookup-assert.m10
6 files changed, 28 insertions, 4 deletions
diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp
index 8342c0f2e39..4586d4bd2aa 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<Decl>(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 00000000000..8d5e06b4363
--- /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 00000000000..313a96188d2
--- /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 00000000000..3d8f878905d
--- /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 00000000000..e8a89eb095a
--- /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 00000000000..2697fb15d01
--- /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 <H3.h>
+@implementation DerivedInterface
+- (void)test {
+}
+@end
OpenPOWER on IntegriCloud