diff --git a/clang/include/clang/Basic/CodeGenOptions.h b/clang/include/clang/Basic/CodeGenOptions.h --- a/clang/include/clang/Basic/CodeGenOptions.h +++ b/clang/include/clang/Basic/CodeGenOptions.h @@ -278,19 +278,29 @@ /// -fsymbol-partition (see https://lld.llvm.org/Partitions.html). std::string SymbolPartition; + /// Regular expression and the string it was created from. + struct RemarkPattern { + std::string Pattern; + std::shared_ptr Regex; + + explicit operator bool() const { return Regex != nullptr; } + + llvm::Regex *operator->() const { return Regex.get(); } + }; + /// Regular expression to select optimizations for which we should enable /// optimization remarks. Transformation passes whose name matches this /// expression (and support this feature), will emit a diagnostic /// whenever they perform a transformation. This is enabled by the /// -Rpass=regexp flag. - std::shared_ptr OptimizationRemarkPattern; + RemarkPattern OptimizationRemarkPattern; /// Regular expression to select optimizations for which we should enable /// missed optimization remarks. Transformation passes whose name matches this /// expression (and support this feature), will emit a diagnostic /// whenever they tried but failed to perform a transformation. This is /// enabled by the -Rpass-missed=regexp flag. - std::shared_ptr OptimizationRemarkMissedPattern; + RemarkPattern OptimizationRemarkMissedPattern; /// Regular expression to select optimizations for which we should enable /// optimization analyses. Transformation passes whose name matches this @@ -298,7 +308,7 @@ /// whenever they want to explain why they decided to apply or not apply /// a given transformation. This is enabled by the -Rpass-analysis=regexp /// flag. - std::shared_ptr OptimizationRemarkAnalysisPattern; + RemarkPattern OptimizationRemarkAnalysisPattern; /// Set of files defining the rules for the symbol rewriting. std::vector RewriteMapFiles; diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -1164,8 +1164,8 @@ } /// Create a new Regex instance out of the string value in \p RpassArg. -/// It returns a pointer to the newly generated Regex instance. -static std::shared_ptr +/// It returns the string and a pointer to the newly generated Regex instance. +static CodeGenOptions::RemarkPattern GenerateOptimizationRemarkRegex(DiagnosticsEngine &Diags, ArgList &Args, Arg *RpassArg) { StringRef Val = RpassArg->getValue(); @@ -1176,7 +1176,7 @@ << RegexError << RpassArg->getAsString(Args); Pattern.reset(); } - return Pattern; + return {std::string(Val), Pattern}; } static bool parseDiagnosticLevelMask(StringRef FlagName,