Fix directive parsing in VerifyDiagnosticConsumer so that it ensures that "expected" is at the start of the word and will no longer accept typos such as "junkexpected-*" as a valid "expected-*" directive.  A very few test-cases had to be amended to adhere to the new rule.

Patch reviewed by David Blaikie.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@166279 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Frontend/VerifyDiagnosticConsumer.cpp b/lib/Frontend/VerifyDiagnosticConsumer.cpp
index e0acd42..4f30d42 100644
--- a/lib/Frontend/VerifyDiagnosticConsumer.cpp
+++ b/lib/Frontend/VerifyDiagnosticConsumer.cpp
@@ -226,10 +226,22 @@
 
   // Return true if string literal is found.
   // When true, P marks begin-position of S in content.
-  bool Search(StringRef S) {
-    P = std::search(C, End, S.begin(), S.end());
-    PEnd = P + S.size();
-    return P != End;
+  bool Search(StringRef S, bool EnsureStartOfWord = false) {
+    do {
+      P = std::search(C, End, S.begin(), S.end());
+      PEnd = P + S.size();
+      if (P == End)
+        break;
+      if (!EnsureStartOfWord
+            // Check if string literal starts a new word.
+            || P == Begin || isspace(P[-1])
+            // Or it could be preceeded by the start of a comment.
+            || (P > (Begin + 1) && (P[-1] == '/' || P[-1] == '*')
+                                &&  P[-2] == '/'))
+        return true;
+      // Otherwise, skip and search again.
+    } while (Advance());
+    return false;
   }
 
   // Advance 1-past previous next/search.
@@ -271,7 +283,7 @@
   bool FoundDirective = false;
   for (ParseHelper PH(S); !PH.Done();) {
     // Search for token: expected
-    if (!PH.Search("expected"))
+    if (!PH.Search("expected", true))
       break;
     PH.Advance();