Codegen assignment to self correctly, patch by David Chisnall!


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@49201 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp
index 66aeea3..c80b6a7 100644
--- a/lib/CodeGen/CGExpr.cpp
+++ b/lib/CodeGen/CGExpr.cpp
@@ -386,7 +386,13 @@
 }
 
 LValue CodeGenFunction::EmitPreDefinedLValue(const PreDefinedExpr *E) {
-  std::string FunctionName(CurFuncDecl->getName());
+  std::string FunctionName;
+  if(const FunctionDecl *FD = dyn_cast<FunctionDecl>(CurFuncDecl)) {
+    FunctionName = FD->getName();
+  }
+  else {
+    assert(0 && "Attempting to load predefined constant for invalid decl type");
+  }
   std::string GlobalVarName;
   
   switch (E->getIdentType()) {
@@ -404,7 +410,7 @@
       break;
   }
   
-  GlobalVarName += CurFuncDecl->getName();
+  GlobalVarName += FunctionName;
   
   // FIXME: Can cache/reuse these within the module.
   llvm::Constant *C=llvm::ConstantArray::get(FunctionName);
@@ -581,8 +587,10 @@
     
   // Get object pointer and coerce object pointer to correct type.
   llvm::Value *Object = EmitLValue(E->getBase()).getAddress();
+  Object = Builder.CreateLoad(Object, E->getDecl()->getName());
   if (Object->getType() != ObjectType)
     Object = Builder.CreateBitCast(Object, ObjectType);
+
   
   // Return a pointer to the right element.
   return LValue::MakeAddr(Builder.CreateStructGEP(Object, Index,