[llvm-commits] [llvm-gcc-4.2] r46340 - in /llvm-gcc-4.2/trunk/gcc: llvm-backend.cpp llvm.h objc/objc-act.c

Dale Johannesen dalej at apple.com
Thu Jan 24 17:44:38 PST 2008


Author: johannes
Date: Thu Jan 24 19:44:38 2008
New Revision: 46340

URL: http://llvm.org/viewvc/llvm-project?rev=46340&view=rev
Log:
Fix more missing ObjC metadata at -O0.  This one is
a little trickier since the type needs to be redone also.


Modified:
    llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp
    llvm-gcc-4.2/trunk/gcc/llvm.h
    llvm-gcc-4.2/trunk/gcc/objc/objc-act.c

Modified: llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp?rev=46340&r1=46339&r2=46340&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp Thu Jan 24 19:44:38 2008
@@ -815,6 +815,48 @@
   GV->setInitializer(Init);
 }
   
+/// reset_type_and_initializer_llvm - Change the type and initializer for 
+/// a global variable.
+void reset_type_and_initializer_llvm(tree decl) {
+  // If there were earlier errors we can get here when DECL_LLVM has not
+  // been set.  Don't crash.
+  if ((errorcount || sorrycount) && !DECL_LLVM(decl))
+    return;
+
+  // Get or create the global variable now.
+  GlobalVariable *GV = cast<GlobalVariable>(DECL_LLVM(decl));
+  
+  // Temporary to avoid infinite recursion (see comments emit_global_to_llvm)
+  GV->setInitializer(UndefValue::get(GV->getType()->getElementType()));
+
+  // Convert the initializer over.
+  Constant *Init = TreeConstantToLLVM::Convert(DECL_INITIAL(decl));
+
+  // If we had a forward definition that has a type that disagrees with our
+  // initializer, insert a cast now.  This sort of thing occurs when we have a
+  // global union, and the LLVM type followed a union initializer that is
+  // different from the union element used for the type.
+  if (GV->getType()->getElementType() != Init->getType()) {
+    GV->removeFromParent();
+    GlobalVariable *NGV = new GlobalVariable(Init->getType(), GV->isConstant(),
+                                             GV->getLinkage(), 0,
+                                             GV->getName(), TheModule);
+    NGV->setVisibility(GV->getVisibility());
+    GV->replaceAllUsesWith(ConstantExpr::getBitCast(NGV, GV->getType()));
+    if (AttributeUsedGlobals.count(GV)) {
+      AttributeUsedGlobals.remove(GV);
+      AttributeUsedGlobals.insert(NGV);
+    }
+    changeLLVMValue(GV, NGV);
+    delete GV;
+    SET_DECL_LLVM(decl, NGV);
+    GV = NGV;
+  }
+
+  // Set the initializer.
+  GV->setInitializer(Init);
+}
+  
 /// emit_global_to_llvm - Emit the specified VAR_DECL or aggregate CONST_DECL to
 /// LLVM as a global variable.  This function implements the end of
 /// assemble_variable.

Modified: llvm-gcc-4.2/trunk/gcc/llvm.h
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm.h?rev=46340&r1=46339&r2=46340&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm.h (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm.h Thu Jan 24 19:44:38 2008
@@ -44,6 +44,11 @@
 /* make_decl_llvm - This is also defined in tree.h and used by macros there. */
 void make_decl_llvm(union tree_node*);
 
+/* reset_type_and_initializer_llvm - Change the initializer for a global 
+ * variable.
+ */
+void reset_type_and_initializer_llvm(union tree_node*);
+
 /* reset_initializer_llvm - Change the initializer for a global variable. */
 void reset_initializer_llvm(union tree_node*);
 

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

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/objc/objc-act.c (original)
+++ llvm-gcc-4.2/trunk/gcc/objc/objc-act.c Thu Jan 24 19:44:38 2008
@@ -12269,6 +12269,11 @@
                                         build_fold_addr_expr (UOBJC_V2_VTABLE_decl)); 
 
   finish_var_decl (class_decl, initlist);
+  /* LLVM LOCAL begin */
+  /* At -O0, we may have emitted references to the decl earlier. */
+  if (!optimize)
+    reset_type_and_initializer_llvm(class_decl);
+  /* LLVM LOCAL end */
   objc_add_to_class_list_chain (class_decl);
   if (CLASS_OR_CATEGORY_HAS_LOAD_IMPL (objc_implementation_context) != NULL_TREE)
     objc_add_to_nonlazy_class_list_chain (class_decl);





More information about the llvm-commits mailing list