[llvm-commits] [llvm-gcc-4.0] r42287 - in /llvm-gcc-4.0/trunk/gcc: c-common.h llvm-backend.cpp objc/objc-act.c stub-objc.c

Bill Wendling isanbard at gmail.com
Mon Sep 24 19:51:18 PDT 2007


Author: void
Date: Mon Sep 24 21:51:18 2007
New Revision: 42287

URL: http://llvm.org/viewvc/llvm-project?rev=42287&view=rev
Log:
During the processing of Objective-C "protocols", the objc frontend creates two
decls for the protocol. One for the metadata and another for when it's
referenced. However, protocols are "internal global", so when we do a lookup
for the reference, it doesn't find the first decl because it's not "external".
This will perform a second lookup for objective C protocols if we don't find
it among the "external globals".


Modified:
    llvm-gcc-4.0/trunk/gcc/c-common.h
    llvm-gcc-4.0/trunk/gcc/llvm-backend.cpp
    llvm-gcc-4.0/trunk/gcc/objc/objc-act.c
    llvm-gcc-4.0/trunk/gcc/stub-objc.c

Modified: llvm-gcc-4.0/trunk/gcc/c-common.h
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.0/trunk/gcc/c-common.h?rev=42287&r1=42286&r2=42287&view=diff

==============================================================================
--- llvm-gcc-4.0/trunk/gcc/c-common.h (original)
+++ llvm-gcc-4.0/trunk/gcc/c-common.h Mon Sep 24 21:51:18 2007
@@ -1139,6 +1139,12 @@
 extern void objc_remove_weak_read (tree*);
 /* APPLE LOCAL end radar 4426814 */
 
+/* APPLE LOCAL begin - LLVM radar 5476262 */
+#ifdef ENABLE_LLVM
+extern bool objc_is_protocol_reference (const char *name);
+#endif
+/* APPLE LOCAL end - LLVM radar 5476262 */
+
 /* APPLE LOCAL begin C* language */
 extern void objc_set_method_opt (int);
 void objc_finish_foreach_loop (location_t, tree, tree, tree, tree);

Modified: llvm-gcc-4.0/trunk/gcc/llvm-backend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.0/trunk/gcc/llvm-backend.cpp?rev=42287&r1=42286&r2=42287&view=diff

==============================================================================
--- llvm-gcc-4.0/trunk/gcc/llvm-backend.cpp (original)
+++ llvm-gcc-4.0/trunk/gcc/llvm-backend.cpp Mon Sep 24 21:51:18 2007
@@ -66,6 +66,7 @@
 #include "function.h"
 #include "tree-inline.h"
 #include "langhooks.h"
+#include "c-common.h"
 }
 
 // Non-zero if bytecode from PCH is successfully read.
@@ -1060,6 +1061,14 @@
       // If the global has a name, prevent multiple vars with the same name from
       // being created.
       GlobalVariable *GVE = TheModule->getGlobalVariable(Name);
+
+      // And Objective-C "@protocol" will create a decl for the
+      // protocol metadata and then when the protocol is
+      // referenced. However, protocols have file-scope, so they
+      // aren't found in the GlobalVariable list unless we look at
+      // non-extern globals as well.
+      if (!GVE && c_dialect_objc() && objc_is_protocol_reference(Name))
+	GVE = TheModule->getGlobalVariable(Name, true);
     
       if (GVE == 0) {
         GV = new GlobalVariable(Ty, false, GlobalValue::ExternalLinkage,0,

Modified: llvm-gcc-4.0/trunk/gcc/objc/objc-act.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.0/trunk/gcc/objc/objc-act.c?rev=42287&r1=42286&r2=42287&view=diff

==============================================================================
--- llvm-gcc-4.0/trunk/gcc/objc/objc-act.c (original)
+++ llvm-gcc-4.0/trunk/gcc/objc/objc-act.c Mon Sep 24 21:51:18 2007
@@ -11669,6 +11669,19 @@
     }
 }
 
+/* APPLE LOCAL begin - LLVM radar 5476262 */
+#ifdef ENABLE_LLVM
+/* This routine returns true if the name is the same as a protocol
+   reference name.  */
+
+bool
+objc_is_protocol_reference (const char *name)
+{
+  return flag_objc_abi == 2 && strstr (name, "_OBJC_PROTOCOL_$_") != 0;
+}
+#endif
+/* APPLE LOCAL end - LLVM radar 5476262 */
+
 /* This routine builds the protocol_reference_chain for each protocol name used
    @protocol(MyProtocol) expression. IDENT is current protocol name.  */
 

Modified: llvm-gcc-4.0/trunk/gcc/stub-objc.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.0/trunk/gcc/stub-objc.c?rev=42287&r1=42286&r2=42287&view=diff

==============================================================================
--- llvm-gcc-4.0/trunk/gcc/stub-objc.c (original)
+++ llvm-gcc-4.0/trunk/gcc/stub-objc.c Mon Sep 24 21:51:18 2007
@@ -548,3 +548,13 @@
   return false;
 }
 /* APPLE LOCAL end radar 4985544 */
+
+/* APPLE LOCAL begin - LLVM radar 5476262 */
+#ifdef ENABLE_LLVM
+bool
+objc_is_protocol_reference (const char * ARG_UNUSED(name))
+{
+  return false;
+}
+#endif
+/* APPLE LOCAL end - LLVM radar 5476262 */





More information about the llvm-commits mailing list