Avoid using rvalue references with trivially copyable types.

Summary:
When the dereference operator returns a value that is trivially
copyable (like a pointer), copy it. After this change, modernize-loop-convert
check can be applied to the whole llvm source code without breaking any build
or test.

Reviewers: alexfh, klimek

Subscribers: alexfh, cfe-commits

Differential Revision: http://reviews.llvm.org/D12675

llvm-svn: 246989
diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
index 116ec5c..d0b2e81 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
@@ -349,11 +349,13 @@
 
   // Check that the declared type is the same as (or a reference to) the
   // container type.
-  QualType DeclarationType = VDecl->getType();
-  if (DeclarationType->isReferenceType())
-    DeclarationType = DeclarationType.getNonReferenceType();
   QualType InitType = Init->getType();
-  if (!Context->hasSameUnqualifiedType(DeclarationType, InitType))
+  QualType DeclarationType = VDecl->getType();
+  if (!DeclarationType.isNull() && DeclarationType->isReferenceType())
+    DeclarationType = DeclarationType.getNonReferenceType();
+
+  if (InitType.isNull() || DeclarationType.isNull() ||
+      !Context->hasSameUnqualifiedType(DeclarationType, InitType))
     return false;
 
   switch (Init->getStmtClass()) {