summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2012-01-13 23:06:53 +0000
committerDouglas Gregor <dgregor@apple.com>2012-01-13 23:06:53 +0000
commit81bd038623cf5c8f93bdd6b31b3ec37497993d3d (patch)
tree97ecdaef0f633ddf1ecaf8d8119c7cd484525e98
parentfcf732c7a6e74bdd6861dd8003a3f82fef16ec93 (diff)
downloadbcm5719-llvm-81bd038623cf5c8f93bdd6b31b3ec37497993d3d.tar.gz
bcm5719-llvm-81bd038623cf5c8f93bdd6b31b3ec37497993d3d.zip
Make sure to consider non-DeclContext scopes properly when finding
multiple name lookup results in C/Objective-C. Fixes a regression a caused in r147533, found by Enea Zaffanella! llvm-svn: 148154
-rw-r--r--clang/lib/Sema/SemaLookup.cpp40
-rw-r--r--clang/test/Sema/function.c3
2 files changed, 33 insertions, 10 deletions
diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index c69022d935c..15c3e836a2c 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -1163,20 +1163,40 @@ bool Sema::LookupName(LookupResult &R, Scope *S, bool AllowBuiltinCreation) {
// Check whether there are any other declarations with the same name
// and in the same scope.
if (I != IEnd) {
- DeclContext *DC = (*I)->getDeclContext()->getRedeclContext();
+ // Find the scope in which this declaration was declared (if it
+ // actually exists in a Scope).
+ while (S && !S->isDeclScope(D))
+ S = S->getParent();
+
+ // If the scope containing the declaration is the translation unit,
+ // then we'll need to perform our checks based on the matching
+ // DeclContexts rather than matching scopes.
+ if (S && isNamespaceOrTranslationUnitScope(S))
+ S = 0;
+
+ // Compute the DeclContext, if we need it.
+ DeclContext *DC = 0;
+ if (!S)
+ DC = (*I)->getDeclContext()->getRedeclContext();
+
IdentifierResolver::iterator LastI = I;
for (++LastI; LastI != IEnd; ++LastI) {
- DeclContext *LastDC
- = (*LastI)->getDeclContext()->getRedeclContext();
+ if (S) {
+ // Match based on scope.
+ if (!S->isDeclScope(*LastI))
+ break;
+ } else {
+ // Match based on DeclContext.
+ DeclContext *LastDC
+ = (*LastI)->getDeclContext()->getRedeclContext();
+ if (!LastDC->Equals(DC))
+ break;
+ }
+
+ // If the declaration isn't in the right namespace, skip it.
if (!(*LastI)->isInIdentifierNamespace(IDNS))
continue;
-
- if (!LastDC->Equals(DC))
- break;
-
- if (!LastDC->isFileContext() && !S->isDeclScope(*LastI))
- break;
-
+
D = R.isHiddenDeclarationVisible()? *LastI : getVisibleDecl(*LastI);
if (D)
R.addDecl(D);
diff --git a/clang/test/Sema/function.c b/clang/test/Sema/function.c
index 1eb5ac4623d..1b0dc2adeb7 100644
--- a/clang/test/Sema/function.c
+++ b/clang/test/Sema/function.c
@@ -89,3 +89,6 @@ unknown_type t19(int* P) { // expected-error {{unknown type name 'unknown_type
// missing ',' before '...'
void t20(int i...) { } // expected-error {{requires a comma}}
+
+int n;
+void t21(int n, int (*array)[n]);
OpenPOWER on IntegriCloud