[cfe-dev] Fixing super lookup in class methods (GNU ObjC runtime)

steve naroff snaroff at apple.com
Sun Apr 19 10:36:09 PDT 2009


On Apr 19, 2009, at 8:44 AM, David Chisnall wrote:

> On 19 Apr 2009, at 02:34, Chris Lattner wrote:
>
>> On Apr 18, 2009, at 4:12 PM, Chris Lattner wrote:
>>
>>>
>>> On Apr 17, 2009, at 11:57 AM, David Chisnall wrote:
>>>
>>>> Hi,
>>>>
>>>> This patch fixes message sends to super in class methods for the
>>>> GNU runtime (currently an instance method lookup is being
>>>> performed).
>>>
>>> Applied, thanks!
>>> http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20090413/015828.html
>>>
>>
>> And reverted here.  This patch broke test/Coverage/codegen-gnu.m, one
>> of the few tests we have for the gnu runtime codegen.  Please make
>> sure that your patches pass basic sanity tests before submitting  
>> them,
>> thanks.
>
> This test failure is due to a bug in Sema.  Under the comment:
>
> // Synthesize "typedef struct objc_object { Class isa; } *id;"
>
> It is synthesising "typedef struct objc_object *id", i.e. synthesising
> id as a pointer to an opaque type.  This is incorrect (and I'm fairly
> sure a recent regression).

David,

I don't believe this is a recent regression.

The struct body was removed ~10 months ago (6/21/08), when the code  
moved from Sema::Sema to Sema::ActOnTranslationUnitScope.

I don't see why you think this is incorrect. It doesn't seem to be  
biting anyone else...

snaroff

[steve-naroffs-imac-2:~/llvm/tools/clang] snaroff% svn info -r52593
Path: trunk
URL: https://llvm.org/svn/llvm-project/cfe/trunk
Repository Root: https://llvm.org/svn/llvm-project
Repository UUID: 91177308-0d34-0410-b5e6-96231b3b80d8
Revision: 52593
Node Kind: directory
Last Changed Author: lattner
Last Changed Rev: 52593
Last Changed Date: 2008-06-21 16:20:39 -0400 (Sat, 21 Jun 2008)

Index: test/CodeGen/empty-union-init.c
===================================================================
--- test/CodeGen/empty-union-init.c	(revision 52592)
+++ test/CodeGen/empty-union-init.c	(revision 52593)
@@ -1,4 +1,5 @@
  // RUN: clang -emit-llvm < %s -o -
+// PR2419

  struct Mem {
          union {
Index: test/Sema/objc-string.m
===================================================================
--- test/Sema/objc-string.m	(revision 52592)
+++ test/Sema/objc-string.m	(revision 52593)
@@ -1,11 +1,15 @@
  // RUN: clang %s -verify -fsyntax-only
+// RUN: clang %s -verify -fsyntax-only -DDECLAREIT

+// a declaration of NSConstantString is not required.
+#ifdef DECLAREIT
  @interface NSConstantString;
  @end
+#endif



-NSConstantString *s = @"123"; // simple
-NSConstantString *t = @"123" @"456"; // concat
-NSConstantString *u = @"123" @ blah; // expected-error: {{unexpected  
token}}
+id s = @"123"; // simple
+id t = @"123" @"456"; // concat
+id u = @"123" @ blah; // expected-error: {{unexpected token}}

Index: lib/Sema/Sema.cpp
===================================================================
--- lib/Sema/Sema.cpp	(revision 52592)
+++ lib/Sema/Sema.cpp	(revision 52593)
@@ -45,17 +45,6 @@
    CurContext = Context.getTranslationUnitDecl();
    if (!PP.getLangOptions().ObjC1) return;

-  TypedefType *t;
-
-  // Add the built-in ObjC types.
-  t = cast<TypedefType>(Context.getObjCIdType().getTypePtr());
-  PushOnScopeChains(t->getDecl(), TUScope);
-  t = cast<TypedefType>(Context.getObjCClassType().getTypePtr());
-  PushOnScopeChains(t->getDecl(), TUScope);
-  ObjCInterfaceType *it =  
cast<ObjCInterfaceType>(Context.getObjCProtoType());
-  ObjCInterfaceDecl *IDecl = it->getDecl();
-  PushOnScopeChains(IDecl, TUScope);
-
    // Synthesize "typedef struct objc_selector *SEL;"
    RecordDecl *SelTag = RecordDecl::Create(Context,  
TagDecl::TK_struct, CurContext,
                                            SourceLocation(),
@@ -70,6 +59,40 @@
                                                  SelT, 0);
    PushOnScopeChains(SelTypedef, TUScope);
    Context.setObjCSelType(SelTypedef);
+
+  RecordDecl *ClassTag = RecordDecl::Create(Context,  
TagDecl::TK_struct,
+                                            CurContext,
+                                            SourceLocation(),
+                                             
&Context.Idents.get("objc_class"),
+                                            0);
+  QualType ClassT =  
Context.getPointerType(Context.getTagDeclType(ClassTag));
+  TypedefDecl *ClassTypedef =
+    TypedefDecl::Create(Context, CurContext, SourceLocation(),
+                        &Context.Idents.get("Class"), ClassT, 0);
+  PushOnScopeChains(ClassTag, TUScope);
+  PushOnScopeChains(ClassTypedef, TUScope);
+  Context.setObjCClassType(ClassTypedef);
+  // Synthesize "@class Protocol;
+  ObjCInterfaceDecl *ProtocolDecl =
+    ObjCInterfaceDecl::Create(Context, SourceLocation(), 0,
+                              &Context.Idents.get("Protocol"),
+                              SourceLocation(), true);
+  Context.setObjCProtoType(Context.getObjCInterfaceType(ProtocolDecl));
+  PushOnScopeChains(ProtocolDecl, TUScope);
+
+  // Synthesize "typedef struct objc_object { Class isa; } *id;"
+  RecordDecl *ObjectTag =
+    RecordDecl::Create(Context, TagDecl::TK_struct, CurContext,
+                       SourceLocation(),
+                       &Context.Idents.get("objc_object"), 0);
+  QualType ObjT =  
Context.getPointerType(Context.getTagDeclType(ObjectTag));
+  PushOnScopeChains(ObjectTag, TUScope);
+  TypedefDecl *IdTypedef = TypedefDecl::Create(Context, CurContext,
+                                               SourceLocation(),
+                                                
&Context.Idents.get("id"),
+                                               ObjT, 0);
+  PushOnScopeChains(IdTypedef, TUScope);
+  Context.setObjCIdType(IdTypedef);
  }

  Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer)
@@ -92,46 +115,6 @@
    KnownFunctionIDs[id_vsprintf]  = &IT.get("vsprintf");
    KnownFunctionIDs[id_vprintf]   = &IT.get("vprintf");

-  // FIXME: Move this initialization up to  
Sema::ActOnTranslationUnitScope()
-  // and make sure the decls get inserted into TUScope!
-  // FIXME: And make sure they don't leak!
-  if (PP.getLangOptions().ObjC1) {
-    TranslationUnitDecl *TUDecl = Context.getTranslationUnitDecl();
-
-    // Synthesize "typedef struct objc_class *Class;"
-    RecordDecl *ClassTag = RecordDecl::Create(Context,  
TagDecl::TK_struct,
-                                              TUDecl,
-                                              SourceLocation(),
-                                              &IT.get("objc_class"),  
0);
-    QualType ClassT =  
Context.getPointerType(Context.getTagDeclType(ClassTag));
-    TypedefDecl *ClassTypedef =
-      TypedefDecl::Create(Context, TUDecl, SourceLocation(),
-                          &Context.Idents.get("Class"), ClassT, 0);
-    Context.setObjCClassType(ClassTypedef);
-
-    // Synthesize "@class Protocol;
-    ObjCInterfaceDecl *ProtocolDecl =
-      ObjCInterfaceDecl::Create(Context, SourceLocation(), 0,
-                                &Context.Idents.get("Protocol"),
-                                SourceLocation(), true);
-     
Context.setObjCProtoType(Context.getObjCInterfaceType(ProtocolDecl));
-
-    // Synthesize "typedef struct objc_object { Class isa; } *id;"
-    RecordDecl *ObjectTag =
-      RecordDecl::Create(Context, TagDecl::TK_struct, TUDecl,
-                         SourceLocation(),
-                         &IT.get("objc_object"), 0);
-    FieldDecl *IsaDecl = FieldDecl::Create(Context, SourceLocation(),
-                                           &Context.Idents.get("isa"),
-                                           Context.getObjCClassType());
-    ObjectTag->defineBody(&IsaDecl, 1);
-    QualType ObjT =  
Context.getPointerType(Context.getTagDeclType(ObjectTag));
-    TypedefDecl *IdTypedef = TypedefDecl::Create(Context, TUDecl,
-                                                 SourceLocation(),
-                                                  
&Context.Idents.get("id"),
-                                                 ObjT, 0);
-    Context.setObjCIdType(IdTypedef);
-  }
    TUScope = 0;
  }





More information about the cfe-dev mailing list