diff --git a/clang/lib/Lex/LiteralSupport.cpp b/clang/lib/Lex/LiteralSupport.cpp --- a/clang/lib/Lex/LiteralSupport.cpp +++ b/clang/lib/Lex/LiteralSupport.cpp @@ -1628,11 +1628,18 @@ // Check for raw string if (ThisTokBuf[0] == 'R') { + if (ThisTokBuf[1] != '"') { + // The file may have come from PCH and then changed after loading the + // PCH; Fail gracefully. + return DiagnoseLexingError(StringToks[i].getLocation()); + } ThisTokBuf += 2; // skip R" const char *Prefix = ThisTokBuf; - while (ThisTokBuf[0] != '(') + while (ThisTokBuf - Prefix < 16 && ThisTokBuf[0] != '(') ++ThisTokBuf; + if (ThisTokBuf[0] != '(') + return DiagnoseLexingError(StringToks[i].getLocation()); ++ThisTokBuf; // skip '(' // Remove same number of characters from the end