Skip to content

Commit ec12f5f

Browse files
committed
[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
1 parent d7d0b17 commit ec12f5f

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

clang/include/clang/Basic/CodeGenOptions.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,27 +278,37 @@ class CodeGenOptions : public CodeGenOptionsBase {
278278
/// -fsymbol-partition (see https://lld.llvm.org/Partitions.html).
279279
std::string SymbolPartition;
280280

281+
/// Regular expression and the string it was created from.
282+
struct RemarkPattern {
283+
std::string Pattern;
284+
std::shared_ptr<llvm::Regex> Regex;
285+
286+
explicit operator bool() const { return Regex != nullptr; }
287+
288+
llvm::Regex *operator->() const { return Regex.get(); }
289+
};
290+
281291
/// Regular expression to select optimizations for which we should enable
282292
/// optimization remarks. Transformation passes whose name matches this
283293
/// expression (and support this feature), will emit a diagnostic
284294
/// whenever they perform a transformation. This is enabled by the
285295
/// -Rpass=regexp flag.
286-
std::shared_ptr<llvm::Regex> OptimizationRemarkPattern;
296+
RemarkPattern OptimizationRemarkPattern;
287297

288298
/// Regular expression to select optimizations for which we should enable
289299
/// missed optimization remarks. Transformation passes whose name matches this
290300
/// expression (and support this feature), will emit a diagnostic
291301
/// whenever they tried but failed to perform a transformation. This is
292302
/// enabled by the -Rpass-missed=regexp flag.
293-
std::shared_ptr<llvm::Regex> OptimizationRemarkMissedPattern;
303+
RemarkPattern OptimizationRemarkMissedPattern;
294304

295305
/// Regular expression to select optimizations for which we should enable
296306
/// optimization analyses. Transformation passes whose name matches this
297307
/// expression (and support this feature), will emit a diagnostic
298308
/// whenever they want to explain why they decided to apply or not apply
299309
/// a given transformation. This is enabled by the -Rpass-analysis=regexp
300310
/// flag.
301-
std::shared_ptr<llvm::Regex> OptimizationRemarkAnalysisPattern;
311+
RemarkPattern OptimizationRemarkAnalysisPattern;
302312

303313
/// Set of files defining the rules for the symbol rewriting.
304314
std::vector<std::string> RewriteMapFiles;

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,8 +1164,8 @@ static void parseAnalyzerConfigs(AnalyzerOptions &AnOpts,
11641164
}
11651165

11661166
/// Create a new Regex instance out of the string value in \p RpassArg.
1167-
/// It returns a pointer to the newly generated Regex instance.
1168-
static std::shared_ptr<llvm::Regex>
1167+
/// It returns the string and a pointer to the newly generated Regex instance.
1168+
static CodeGenOptions::RemarkPattern
11691169
GenerateOptimizationRemarkRegex(DiagnosticsEngine &Diags, ArgList &Args,
11701170
Arg *RpassArg) {
11711171
StringRef Val = RpassArg->getValue();
@@ -1176,7 +1176,7 @@ GenerateOptimizationRemarkRegex(DiagnosticsEngine &Diags, ArgList &Args,
11761176
<< RegexError << RpassArg->getAsString(Args);
11771177
Pattern.reset();
11781178
}
1179-
return Pattern;
1179+
return {std::string(Val), Pattern};
11801180
}
11811181

11821182
static bool parseDiagnosticLevelMask(StringRef FlagName,

0 commit comments

Comments
 (0)