Revert r120331 since it causes spurious warnings and a possible assertion hit when self-host.

llvm-svn: 120351
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 807a550..ed45de5 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -1787,35 +1787,11 @@
         << ALE->getSourceRange();
 
   } else if (lhsType->isReferenceType()) {
-    // Perform checking for local temporaries returned by reference.
-    if (RetValExp->Classify(Context).isPRValue()) {
-      Diag(RetValExp->getLocStart(), diag::warn_ret_local_temp_ref)
-        << RetValExp->getSourceRange();
-      return;
-    }
-
     // Perform checking for stack values returned by reference.
     // Check for a reference to the stack
-    if (DeclRefExpr *DR = EvalVal(RetValExp)) {
-      const VarDecl *VD = cast<VarDecl>(DR->getDecl());
-      // Check for returning reference variable that binds to temporary.
-      if (VD->getType()->isReferenceType()) {
-        if (const Expr *init = VD->getInit())
-          if (init->Classify(Context).isPRValue()) {
-            Diag(DR->getLocStart(), diag::warn_ret_local_temp_var_ref)
-              << VD->getDeclName() << RetValExp->getSourceRange();
-            Diag(VD->getLocation(), diag::note_local_temp_var_ref)
-              << VD->getDeclName() << VD->getInit()->getSourceRange();
-          }
-
-        // When returning a reference variable that doesn't bind to temporary,
-        // no warning.
-        return;
-      }
-
+    if (DeclRefExpr *DR = EvalVal(RetValExp))
       Diag(DR->getLocStart(), diag::warn_ret_stack_ref)
-        << VD->getDeclName() << RetValExp->getSourceRange();
-    }
+        << DR->getDecl()->getDeclName() << RetValExp->getSourceRange();
   }
 }
 
@@ -1977,7 +1953,7 @@
     DeclRefExpr *DR = cast<DeclRefExpr>(E);
 
     if (VarDecl *V = dyn_cast<VarDecl>(DR->getDecl()))
-      if (V->hasLocalStorage()) return DR;
+      if (V->hasLocalStorage() && !V->getType()->isReferenceType()) return DR;
 
     return NULL;
   }