diff --git a/lib/Lex/Lexer.cpp b/lib/Lex/Lexer.cpp
index ed4666a..a07517a 100644
--- a/lib/Lex/Lexer.cpp
+++ b/lib/Lex/Lexer.cpp
@@ -2063,39 +2063,48 @@ bool Lexer::SaveLineComment(Token &Result, const char *CurPtr) {
 static bool isEndOfBlockCommentWithEscapedNewLine(const char *CurPtr,
                                                   Lexer *L) {
   assert(CurPtr[0] == '\n' || CurPtr[0] == '\r');
+  bool HasSpace = false;
+  bool IsTrigraph = false;
 
-  // Back up off the newline.
-  --CurPtr;
-
-  // If this is a two-character newline sequence, skip the other character.
-  if (CurPtr[0] == '\n' || CurPtr[0] == '\r') {
-    // \n\n or \r\r -> not escaped newline.
-    if (CurPtr[0] == CurPtr[1])
-      return false;
-    // \n\r or \r\n -> skip the newline.
+  // Skip escaped newlines, or return if it's not an escaped newline sequence.
+  do {
+    // Back up off the newline.
     --CurPtr;
-  }
 
-  // If we have horizontal whitespace, skip over it.  We allow whitespace
-  // between the slash and newline.
-  bool HasSpace = false;
-  while (isHorizontalWhitespace(*CurPtr) || *CurPtr == 0) {
-    --CurPtr;
-    HasSpace = true;
-  }
+    // If this is a two-character newline sequence, skip the other character.
+    if (CurPtr[0] == '\n' || CurPtr[0] == '\r') {
+      // \n\n or \r\r -> not escaped newline.
+      if (CurPtr[0] == CurPtr[1])
+        return false;
+      // \n\r or \r\n -> skip the newline.
+      --CurPtr;
+    }
 
-  // If we have a slash, we know this is an escaped newline.
-  if (*CurPtr == '\\') {
-    if (CurPtr[-1] != '*') return false;
-  } else {
-    // It isn't a slash, is it the ?? / trigraph?
-    if (CurPtr[0] != '/' || CurPtr[-1] != '?' || CurPtr[-2] != '?' ||
-        CurPtr[-3] != '*')
+    // If we have horizontal whitespace, skip over it.  We allow whitespace
+    // between the backslash and newline.
+    while (isHorizontalWhitespace(*CurPtr) || *CurPtr == 0) {
+      --CurPtr;
+      HasSpace = true;
+    }
+
+    // If we have a backslash, skip over it.
+    if (*CurPtr == '\\') {
+      --CurPtr;
+    } else if (CurPtr[0] == '/' || CurPtr[-1] == '?' || CurPtr[-2] == '?') {
+      // It was not a backslash, but the trigraph equivalent to backslash.
+      CurPtr -= 3;
+      IsTrigraph = true;
+    } else {
       return false;
+    }
+  } while (*CurPtr == '\n' || *CurPtr == '\r');
 
-    // This is the trigraph ending the comment.  Emit a stern warning!
-    CurPtr -= 2;
+  // If the character before an escaped newline is not '*', the last
+  // slash was not the end of block comment after all.
+  if (*CurPtr != '*')
+    return false;
 
+  if (IsTrigraph) {
     // If no trigraphs are enabled, warn that we ignored this trigraph and
     // ignore this * character.
     if (!L->getLangOpts().Trigraphs) {
@@ -2114,7 +2123,6 @@ static bool isEndOfBlockCommentWithEscapedNewLine(const char *CurPtr,
   // If there was space between the backslash and newline, warn about it.
   if (HasSpace && !L->isLexingRawMode())
     L->Diag(CurPtr, diag::backslash_newline_space);
-
   return true;
 }
 
diff --git a/test/Lexer/block_cmt_end.c b/test/Lexer/block_cmt_end.c
index f54b6a4..e7970ee 100644
--- a/test/Lexer/block_cmt_end.c
+++ b/test/Lexer/block_cmt_end.c
@@ -14,9 +14,20 @@ int i = /*/ */ 1;
 next comment ends with normal escaped newline:
 */
 
-/* expected-warning {{escaped newline}} expected-warning {{backslash and newline}}  *\  
+/* expected-warning {{escaped newline}} expected-warning {{backslash and newline}} *\
+\  
 /
 
+// "*\n/" does not end a comment.
+/* *
+/
+*/
+
+// "* \\\n/" does not end a comment.
+/* * \
+/
+*/
+
 int bar /* expected-error {{expected ';' after top level declarator}} */
 
 /* xyz
