Index: include/clang/Tooling/Inclusions/HeaderIncludes.h =================================================================== --- include/clang/Tooling/Inclusions/HeaderIncludes.h +++ include/clang/Tooling/Inclusions/HeaderIncludes.h @@ -42,8 +42,7 @@ std::string FileName; // This refers to a substring in FileName. StringRef FileStem; - // Regex is not thread-safe. - mutable SmallVector CategoryRegexs; + SmallVector CategoryRegexs; }; /// Generates replacements for inserting or deleting #include directives in a Index: lib/Format/BreakableToken.h =================================================================== --- lib/Format/BreakableToken.h +++ lib/Format/BreakableToken.h @@ -155,7 +155,7 @@ /// file. virtual Split getSplit(unsigned LineIndex, unsigned TailOffset, unsigned ColumnLimit, unsigned ContentStartColumn, - llvm::Regex &CommentPragmasRegex) const = 0; + const llvm::Regex &CommentPragmasRegex) const = 0; /// Emits the previously retrieved \p Split via \p Whitespaces. virtual void insertBreak(unsigned LineIndex, unsigned TailOffset, Split Split, @@ -190,7 +190,7 @@ /// If the split is not contained within one token, for example when reflowing /// line comments, returns (0, ). virtual Split getReflowSplit(unsigned LineIndex, - llvm::Regex &CommentPragmasRegex) const { + const llvm::Regex &CommentPragmasRegex) const { return Split(StringRef::npos, 0); } @@ -255,7 +255,7 @@ Split getSplit(unsigned LineIndex, unsigned TailOffset, unsigned ColumnLimit, unsigned ContentStartColumn, - llvm::Regex &CommentPragmasRegex) const override; + const llvm::Regex &CommentPragmasRegex) const override; void insertBreak(unsigned LineIndex, unsigned TailOffset, Split Split, unsigned ContentIndent, WhitespaceManager &Whitespaces) const override; @@ -298,7 +298,7 @@ unsigned getLineCount() const override; Split getSplit(unsigned LineIndex, unsigned TailOffset, unsigned ColumnLimit, unsigned ContentStartColumn, - llvm::Regex &CommentPragmasRegex) const override; + const llvm::Regex &CommentPragmasRegex) const override; void compressWhitespace(unsigned LineIndex, unsigned TailOffset, Split Split, WhitespaceManager &Whitespaces) const override; @@ -309,7 +309,7 @@ // Checks if the content of line LineIndex may be reflown with the previous // line. virtual bool mayReflow(unsigned LineIndex, - llvm::Regex &CommentPragmasRegex) const = 0; + const llvm::Regex &CommentPragmasRegex) const = 0; // Contains the original text of the lines of the block comment. // @@ -363,7 +363,7 @@ Split getSplit(unsigned LineIndex, unsigned TailOffset, unsigned ColumnLimit, unsigned ContentStartColumn, - llvm::Regex &CommentPragmasRegex) const override; + const llvm::Regex &CommentPragmasRegex) const override; unsigned getRangeLength(unsigned LineIndex, unsigned Offset, StringRef::size_type Length, unsigned StartColumn) const override; @@ -375,7 +375,7 @@ unsigned ContentIndent, WhitespaceManager &Whitespaces) const override; Split getReflowSplit(unsigned LineIndex, - llvm::Regex &CommentPragmasRegex) const override; + const llvm::Regex &CommentPragmasRegex) const override; void reflow(unsigned LineIndex, WhitespaceManager &Whitespaces) const override; bool introducesBreakBeforeToken() const override; @@ -384,7 +384,7 @@ Split getSplitAfterLastLine(unsigned TailOffset) const override; bool mayReflow(unsigned LineIndex, - llvm::Regex &CommentPragmasRegex) const override; + const llvm::Regex &CommentPragmasRegex) const override; // Contains Javadoc annotations that require additional indent when continued // on multiple lines. @@ -448,14 +448,14 @@ unsigned ContentIndent, WhitespaceManager &Whitespaces) const override; Split getReflowSplit(unsigned LineIndex, - llvm::Regex &CommentPragmasRegex) const override; + const llvm::Regex &CommentPragmasRegex) const override; void reflow(unsigned LineIndex, WhitespaceManager &Whitespaces) const override; void adaptStartOfLine(unsigned LineIndex, WhitespaceManager &Whitespaces) const override; void updateNextToken(LineState &State) const override; bool mayReflow(unsigned LineIndex, - llvm::Regex &CommentPragmasRegex) const override; + const llvm::Regex &CommentPragmasRegex) const override; private: // OriginalPrefix[i] contains the original prefix of line i, including Index: lib/Format/BreakableToken.cpp =================================================================== --- lib/Format/BreakableToken.cpp +++ lib/Format/BreakableToken.cpp @@ -88,11 +88,11 @@ StringRef::size_type SpaceOffset = Text.find_last_of(Blanks, MaxSplitBytes); - static auto *const kNumberedListRegexp = new llvm::Regex("^[1-9][0-9]?\\."); + static const auto kNumberedListRegexp = llvm::Regex("^[1-9][0-9]?\\."); while (SpaceOffset != StringRef::npos) { // Do not split before a number followed by a dot: this would be interpreted // as a numbered list, which would prevent re-flowing in subsequent passes. - if (kNumberedListRegexp->match(Text.substr(SpaceOffset).ltrim(Blanks))) + if (kNumberedListRegexp.match(Text.substr(SpaceOffset).ltrim(Blanks))) SpaceOffset = Text.find_last_of(Blanks, SpaceOffset); // In JavaScript, some @tags can be followed by {, and machinery that parses // these comments will fail to understand the comment if followed by a line @@ -245,7 +245,7 @@ BreakableToken::Split BreakableStringLiteral::getSplit( unsigned LineIndex, unsigned TailOffset, unsigned ColumnLimit, - unsigned ContentStartColumn, llvm::Regex &CommentPragmasRegex) const { + unsigned ContentStartColumn, const llvm::Regex &CommentPragmasRegex) const { return getStringSplit(Line.substr(TailOffset), ContentStartColumn, ColumnLimit - Postfix.size(), Style.TabWidth, Encoding); } @@ -271,7 +271,7 @@ BreakableToken::Split BreakableComment::getSplit(unsigned LineIndex, unsigned TailOffset, unsigned ColumnLimit, unsigned ContentStartColumn, - llvm::Regex &CommentPragmasRegex) const { + const llvm::Regex &CommentPragmasRegex) const { // Don't break lines matching the comment pragmas regex. if (CommentPragmasRegex.match(Content[LineIndex])) return Split(StringRef::npos, 0); @@ -316,9 +316,9 @@ // Numbered lists may also start with a number followed by '.' // To avoid issues if a line starts with a number which is actually the end // of a previous line, we only consider numbers with up to 2 digits. - static auto *const kNumberedListRegexp = new llvm::Regex("^[1-9][0-9]?\\. "); + static const auto kNumberedListRegexp = llvm::Regex("^[1-9][0-9]?\\. "); hasSpecialMeaningPrefix = - hasSpecialMeaningPrefix || kNumberedListRegexp->match(Content); + hasSpecialMeaningPrefix || kNumberedListRegexp.match(Content); // Simple heuristic for what to reflow: content should contain at least two // characters and either the first or second character must be @@ -458,7 +458,7 @@ BreakableToken::Split BreakableBlockComment::getSplit( unsigned LineIndex, unsigned TailOffset, unsigned ColumnLimit, - unsigned ContentStartColumn, llvm::Regex &CommentPragmasRegex) const { + unsigned ContentStartColumn, const llvm::Regex &CommentPragmasRegex) const { // Don't break lines matching the comment pragmas regex. if (CommentPragmasRegex.match(Content[LineIndex])) return Split(StringRef::npos, 0); @@ -597,9 +597,8 @@ PrefixWithTrailingIndent.size()); } -BreakableToken::Split -BreakableBlockComment::getReflowSplit(unsigned LineIndex, - llvm::Regex &CommentPragmasRegex) const { +BreakableToken::Split BreakableBlockComment::getReflowSplit( + unsigned LineIndex, const llvm::Regex &CommentPragmasRegex) const { if (!mayReflow(LineIndex, CommentPragmasRegex)) return Split(StringRef::npos, 0); @@ -706,8 +705,8 @@ return Split(StringRef::npos, 0); } -bool BreakableBlockComment::mayReflow(unsigned LineIndex, - llvm::Regex &CommentPragmasRegex) const { +bool BreakableBlockComment::mayReflow( + unsigned LineIndex, const llvm::Regex &CommentPragmasRegex) const { // Content[LineIndex] may exclude the indent after the '*' decoration. In that // case, we compute the start of the comment pragma manually. StringRef IndentContent = Content[LineIndex]; @@ -845,7 +844,7 @@ } BreakableComment::Split BreakableLineCommentSection::getReflowSplit( - unsigned LineIndex, llvm::Regex &CommentPragmasRegex) const { + unsigned LineIndex, const llvm::Regex &CommentPragmasRegex) const { if (!mayReflow(LineIndex, CommentPragmasRegex)) return Split(StringRef::npos, 0); @@ -955,7 +954,7 @@ } bool BreakableLineCommentSection::mayReflow( - unsigned LineIndex, llvm::Regex &CommentPragmasRegex) const { + unsigned LineIndex, const llvm::Regex &CommentPragmasRegex) const { // Line comments have the indent as part of the prefix, so we need to // recompute the start of the line. StringRef IndentContent = Content[LineIndex]; Index: lib/Format/NamespaceEndCommentsFixer.cpp =================================================================== --- lib/Format/NamespaceEndCommentsFixer.cpp +++ lib/Format/NamespaceEndCommentsFixer.cpp @@ -92,24 +92,24 @@ // Matches a valid namespace end comment. // Valid namespace end comments don't need to be edited. - static llvm::Regex *const NamespaceCommentPattern = - new llvm::Regex("^/[/*] *(end (of )?)? *(anonymous|unnamed)? *" - "namespace( +([a-zA-Z0-9:_]+))?\\.? *(\\*/)?$", - llvm::Regex::IgnoreCase); - static llvm::Regex *const NamespaceMacroCommentPattern = - new llvm::Regex("^/[/*] *(end (of )?)? *(anonymous|unnamed)? *" - "([a-zA-Z0-9_]+)\\(([a-zA-Z0-9:_]*)\\)\\.? *(\\*/)?$", - llvm::Regex::IgnoreCase); + static const llvm::Regex NamespaceCommentPattern = + llvm::Regex("^/[/*] *(end (of )?)? *(anonymous|unnamed)? *" + "namespace( +([a-zA-Z0-9:_]+))?\\.? *(\\*/)?$", + llvm::Regex::IgnoreCase); + static const llvm::Regex NamespaceMacroCommentPattern = + llvm::Regex("^/[/*] *(end (of )?)? *(anonymous|unnamed)? *" + "([a-zA-Z0-9_]+)\\(([a-zA-Z0-9:_]*)\\)\\.? *(\\*/)?$", + llvm::Regex::IgnoreCase); SmallVector Groups; if (NamespaceTok->is(TT_NamespaceMacro) && - NamespaceMacroCommentPattern->match(Comment->TokenText, &Groups)) { + NamespaceMacroCommentPattern.match(Comment->TokenText, &Groups)) { StringRef NamespaceTokenText = Groups.size() > 4 ? Groups[4] : ""; // The name of the macro must be used. if (NamespaceTokenText != NamespaceTok->TokenText) return false; } else if (NamespaceTok->isNot(tok::kw_namespace) || - !NamespaceCommentPattern->match(Comment->TokenText, &Groups)) { + !NamespaceCommentPattern.match(Comment->TokenText, &Groups)) { // Comment does not match regex. return false; } Index: lib/Format/UnwrappedLineParser.cpp =================================================================== --- lib/Format/UnwrappedLineParser.cpp +++ lib/Format/UnwrappedLineParser.cpp @@ -2495,9 +2495,10 @@ // Checks if \p FormatTok is a line comment that continues the line comment // section on \p Line. -static bool continuesLineCommentSection(const FormatToken &FormatTok, - const UnwrappedLine &Line, - llvm::Regex &CommentPragmasRegex) { +static bool +continuesLineCommentSection(const FormatToken &FormatTok, + const UnwrappedLine &Line, + const llvm::Regex &CommentPragmasRegex) { if (Line.Tokens.empty()) return false; Index: tools/clang-refactor/TestSupport.cpp =================================================================== --- tools/clang-refactor/TestSupport.cpp +++ tools/clang-refactor/TestSupport.cpp @@ -303,9 +303,10 @@ // See the doc comment for this function for the explanation of this // syntax. - static Regex RangeRegex("range[[:blank:]]*([[:alpha:]_]*)?[[:blank:]]*=[[:" - "blank:]]*(\\+[[:digit:]]+)?[[:blank:]]*(->[[:blank:]" - "]*[\\+\\:[:digit:]]+)?"); + static const Regex RangeRegex( + "range[[:blank:]]*([[:alpha:]_]*)?[[:blank:]]*=[[:" + "blank:]]*(\\+[[:digit:]]+)?[[:blank:]]*(->[[:blank:]" + "]*[\\+\\:[:digit:]]+)?"); std::map> GroupedRanges; @@ -352,7 +353,7 @@ unsigned EndOffset; if (!Matches[3].empty()) { - static Regex EndLocRegex( + static const Regex EndLocRegex( "->[[:blank:]]*(\\+[[:digit:]]+):([[:digit:]]+)"); SmallVector EndLocMatches; if (!EndLocRegex.match(Matches[3], &EndLocMatches)) {