diff options
author | Andy Gibbs <andyg1001@hotmail.co.uk> | 2012-10-19 12:36:49 +0000 |
---|---|---|
committer | Andy Gibbs <andyg1001@hotmail.co.uk> | 2012-10-19 12:36:49 +0000 |
commit | ac51de6ec2f01fce1d9dadf59a86ffe825c42bc7 (patch) | |
tree | 0791be5a26a231653d9a6c1aa0172dca1afc4662 /clang/lib/Frontend/VerifyDiagnosticConsumer.cpp | |
parent | 8eb77d847e8a5cba03682bd948613c7162e56a86 (diff) | |
download | bcm5719-llvm-ac51de6ec2f01fce1d9dadf59a86ffe825c42bc7.tar.gz bcm5719-llvm-ac51de6ec2f01fce1d9dadf59a86ffe825c42bc7.zip |
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.
llvm-svn: 166279
Diffstat (limited to 'clang/lib/Frontend/VerifyDiagnosticConsumer.cpp')
-rw-r--r-- | clang/lib/Frontend/VerifyDiagnosticConsumer.cpp | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp b/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp index e0acd42ab2d..4f30d4213af 100644 --- a/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp +++ b/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp @@ -226,10 +226,22 @@ public: // 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 @@ static bool ParseDirective(StringRef S, ExpectedData *ED, SourceManager &SM, 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(); |