Author: Jan Svoboda Date: 2021-02-09T11:12:13+01:00 New Revision: ec12f5febed04dd32e7d4b766b2853d50fca9657
URL: https://github.com/llvm/llvm-project/commit/ec12f5febed04dd32e7d4b766b2853d50fca9657 DIFF: https://github.com/llvm/llvm-project/commit/ec12f5febed04dd32e7d4b766b2853d50fca9657.diff LOG: [clang][codegen] Remember string used to create llvm::Regex for optimization remarks Regular expression patterns passed through the command line are being used to create an instances of `llvm::Regex` and thrown away. There is no API to serialize `Regex` back to the original pattern. This means we have no way to reconstruct the original pattern from command line. This is necessary for serializing `CompilerInvocation`. This patch stores the original pattern string in `CodeGenOptions` alongside the `llvm::Regex` instance. Reviewed By: dexonsmith, thegameg Differential Revision: https://reviews.llvm.org/D96036 Added: Modified: clang/include/clang/Basic/CodeGenOptions.h clang/lib/Frontend/CompilerInvocation.cpp Removed: ################################################################################ diff --git a/clang/include/clang/Basic/CodeGenOptions.h b/clang/include/clang/Basic/CodeGenOptions.h index 73d41e3293c6..38979520b90d 100644 --- a/clang/include/clang/Basic/CodeGenOptions.h +++ b/clang/include/clang/Basic/CodeGenOptions.h @@ -278,19 +278,29 @@ class CodeGenOptions : public CodeGenOptionsBase { /// -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<llvm::Regex> 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<llvm::Regex> 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<llvm::Regex> 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 @@ class CodeGenOptions : public CodeGenOptionsBase { /// 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<llvm::Regex> OptimizationRemarkAnalysisPattern; + RemarkPattern OptimizationRemarkAnalysisPattern; /// Set of files defining the rules for the symbol rewriting. std::vector<std::string> RewriteMapFiles; diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 09444b2dda79..658dad54532e 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -1164,8 +1164,8 @@ static void parseAnalyzerConfigs(AnalyzerOptions &AnOpts, } /// 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<llvm::Regex> +/// 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 @@ GenerateOptimizationRemarkRegex(DiagnosticsEngine &Diags, ArgList &Args, << RegexError << RpassArg->getAsString(Args); Pattern.reset(); } - return Pattern; + return {std::string(Val), Pattern}; } static bool parseDiagnosticLevelMask(StringRef FlagName, _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits