Merge branch 'yo-dawg-i-herd-u-like-arrays'

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@145421 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp
index c66b8da..9dd0313 100644
--- a/lib/Sema/SemaChecking.cpp
+++ b/lib/Sema/SemaChecking.cpp
@@ -4297,6 +4297,17 @@
                           << IndexExpr->getSourceRange());
   }
 
+  if (!ND) {
+    // Try harder to find a NamedDecl to point at in the note.
+    while (const ArraySubscriptExpr *ASE =
+           dyn_cast<ArraySubscriptExpr>(BaseExpr))
+      BaseExpr = ASE->getBase()->IgnoreParenCasts();
+    if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(BaseExpr))
+      ND = dyn_cast<NamedDecl>(DRE->getDecl());
+    if (const MemberExpr *ME = dyn_cast<MemberExpr>(BaseExpr))
+      ND = dyn_cast<NamedDecl>(ME->getMemberDecl());
+  }
+
   if (ND)
     DiagRuntimeBehavior(ND->getLocStart(), BaseExpr,
                         PDiag(diag::note_array_index_out_of_bounds)