[llvm-commits] [llvm-gcc-4.2] r138429 - /llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp

Duncan Sands baldrick at free.fr
Wed Aug 24 01:06:14 PDT 2011


Author: baldrick
Date: Wed Aug 24 03:06:14 2011
New Revision: 138429

URL: http://llvm.org/viewvc/llvm-project?rev=138429&view=rev
Log:
As fallout from the new type system, a GCC pointer type may be
converted to different LLVM pointer types depending on whether
it is converted directly or as part of converting a containing
struct.  This broke some testcases in FrontendObjC in which the
type of an initial value (which is built up field by field, so
any fields with pointer type were being converted directly, not
as a side effect of converting the containing struct) didn't
match the type of the global value (for which the fields with
pointer type were type converted as a side effect of converting
the containing struct type - the type of the global).  If such
a mismatch happens, change the type of the global variable to
match that of the initializer.

Modified:
    llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp

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=138429&r1=138428&r2=138429&view=diff
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp Wed Aug 24 03:06:14 2011
@@ -1381,6 +1381,22 @@
   Constant *Init = TreeConstantToLLVM::Convert(DECL_INITIAL(decl));
 
   // Set the initializer.
+  if (GV->getType()->getElementType() != Init->getType()) {
+    GV->removeFromParent();
+    GlobalVariable *NGV = new GlobalVariable(*TheModule, Init->getType(), 
+                                             GV->isConstant(),
+                                             GV->getLinkage(), 0,
+                                             GV->getName());
+    NGV->setVisibility(GV->getVisibility());
+    NGV->setSection(GV->getSection());
+    NGV->setAlignment(GV->getAlignment());
+    NGV->setLinkage(GV->getLinkage());
+    GV->replaceAllUsesWith(TheFolder->CreateBitCast(NGV, GV->getType()));
+    changeLLVMConstant(GV, NGV);
+    delete GV;
+    SET_DECL_LLVM(decl, NGV);
+    GV = NGV;
+  }
   GV->setInitializer(Init);
   if (GV->hasHiddenVisibility() || GV->hasInternalLinkage() ||
       GV->hasPrivateLinkage())





More information about the llvm-commits mailing list