]> granicus.if.org Git - clang/commitdiff
When in objective-c methods, do the built-in name lookup after
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 12 Jan 2010 23:58:59 +0000 (23:58 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 12 Jan 2010 23:58:59 +0000 (23:58 +0000)
ivar name lookup. Fixes pr5986.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@93271 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/Sema.h
lib/Sema/SemaExpr.cpp
test/SemaObjC/ivar-lookup-resolution-builtin.m [new file with mode: 0644]

index d06cecc4678d0297d92f577decc342c6258982ab..bc139c19a87ddeec6ec40d73cfbb07763c88008a 100644 (file)
@@ -1481,7 +1481,8 @@ public:
 
   OwningExprResult LookupInObjCMethod(LookupResult &R,
                                       Scope *S,
-                                      IdentifierInfo *II);
+                                      IdentifierInfo *II,
+                                      bool AllowBuiltinCreation=false);
 
   OwningExprResult ActOnDependentIdExpression(const CXXScopeSpec &SS,
                                               DeclarationName Name,
index c71fd98aa04074955a4539f3193d4fbfdaae45ff..f3093c1bad8efb674f7619b8e87cab360fddf31b 100644 (file)
@@ -1033,12 +1033,13 @@ Sema::OwningExprResult Sema::ActOnIdExpression(Scope *S,
     // Just re-use the lookup done by isTemplateName.
     DecomposeTemplateName(R, Id);
   } else {
-    LookupParsedName(R, S, &SS, true);
+    bool IvarLookupFollowUp = (!SS.isSet() && II && getCurMethodDecl());
+    LookupParsedName(R, S, &SS, !IvarLookupFollowUp);
 
     // If this reference is in an Objective-C method, then we need to do
     // some special Objective-C lookup, too.
-    if (!SS.isSet() && II && getCurMethodDecl()) {
-      OwningExprResult E(LookupInObjCMethod(R, S, II));
+    if (IvarLookupFollowUp) {
+      OwningExprResult E(LookupInObjCMethod(R, S, II, true));
       if (E.isInvalid())
         return ExprError();
 
@@ -1218,7 +1219,8 @@ Sema::BuildQualifiedDeclarationNameExpr(const CXXScopeSpec &SS,
 /// Returns a null sentinel to indicate trivial success.
 Sema::OwningExprResult
 Sema::LookupInObjCMethod(LookupResult &Lookup, Scope *S,
-                         IdentifierInfo *II) {
+                         IdentifierInfo *II,
+                         bool AllowBuiltinCreation) {
   SourceLocation Loc = Lookup.getNameLoc();
 
   // There are two cases to handle here.  1) scoped lookup could have failed,
@@ -1299,7 +1301,18 @@ Sema::LookupInObjCMethod(LookupResult &Lookup, Scope *S,
       T = Context.getObjCClassType();
     return Owned(new (Context) ObjCSuperExpr(Loc, T));
   }
-
+  if (Lookup.empty() && II && AllowBuiltinCreation) {
+    // FIXME. Consolidate this with similar code in LookupName.
+    if (unsigned BuiltinID = II->getBuiltinID()) {
+      if (!(getLangOptions().CPlusPlus &&
+            Context.BuiltinInfo.isPredefinedLibFunction(BuiltinID))) {
+        NamedDecl *D = LazilyCreateBuiltin((IdentifierInfo *)II, BuiltinID,
+                                           S, Lookup.isForRedeclaration(),
+                                           Lookup.getNameLoc());
+        if (D) Lookup.addDecl(D);
+      }
+    }
+  }
   // Sentinel value saying that we didn't do anything special.
   return Owned((Expr*) 0);
 }
diff --git a/test/SemaObjC/ivar-lookup-resolution-builtin.m b/test/SemaObjC/ivar-lookup-resolution-builtin.m
new file mode 100644 (file)
index 0000000..2e90e8e
--- /dev/null
@@ -0,0 +1,40 @@
+// RUN: %clang_cc1  -fsyntax-only -verify %s
+// pr5986
+
+@interface Test {
+  int index;
+}
+- (int) index;
++ (int) ClassMethod;
+@end
+
+@implementation Test
+- (int) index
+{
+  return index;
+}
++ (int) ClassMethod
+{
+  return index;        // expected-error {{instance variable 'index' accessed in class method}}
+}
+@end
+
+@interface Test1 {
+}
+- (int) InstMethod;
++ (int) ClassMethod;
+@end
+
+@implementation Test1
+- (int) InstMethod
+{
+  return index;        // expected-warning {{implicitly declaring C library function 'index'}} \
+                // expected-note {{please include the header <strings.h> or explicitly provide a declaration for 'index'}} \
+                // expected-warning {{incompatible pointer to integer conversion returning}}
+}
++ (int) ClassMethod
+{
+  return index; // expected-warning {{incompatible pointer to integer conversion returning}}
+}
+@end
+