From 68c755e99c4c6233882c811bf3053de6517b858d Mon Sep 17 00:00:00 2001 From: Steven Wu Date: Fri, 10 May 2024 15:44:54 -0700 Subject: [PATCH] [Caching] Temporarily using llvm style diagnostics in caching When caching is enabled, using swift style diagnotics can lead to crashes due to some uninitialized variables. Even more, the swift style diagnostics is not going to render the same when replay from the cache since the currect caching diagnostics processor is not capture all information that is needed to render diagnostis from SwiftSyntax. Temprarily using llvm style for caching builds. rdar://127530204 --- include/swift/Basic/SourceManager.h | 4 ++-- lib/Frontend/CompilerInvocation.cpp | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/include/swift/Basic/SourceManager.h b/include/swift/Basic/SourceManager.h index fec88a8ef5208..350ea0744d948 100644 --- a/include/swift/Basic/SourceManager.h +++ b/include/swift/Basic/SourceManager.h @@ -61,10 +61,10 @@ class GeneratedSourceInfo { CharSourceRange generatedSourceRange; /// The opaque pointer for an ASTNode for which this buffer was generated. - void *astNode; + void *astNode = nullptr; /// The declaration context in which this buffer logically resides. - DeclContext *declContext; + DeclContext *declContext = nullptr; /// The custom attribute for an attached macro. CustomAttr *attachedMacroCustomAttr = nullptr; diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 90e399f034365..584cc8f6e33df 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -2172,7 +2172,7 @@ static bool ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args, Args.hasFlag(OPT_color_diagnostics, OPT_no_color_diagnostics, /*Default=*/llvm::sys::Process::StandardErrHasColors()); - // If no style options are specified, default to LLVM style. + // If no style options are specified, default to Swift style. Opts.PrintedFormattingStyle = DiagnosticOptions::FormattingStyle::Swift; if (const Arg *arg = Args.getLastArg(OPT_diagnostic_style)) { StringRef contents = arg->getValue(); @@ -2186,6 +2186,9 @@ static bool ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args, return true; } } + // Swift style is not fully supported in cached mode yet. + if (Args.hasArg(OPT_cache_compile_job)) + Opts.PrintedFormattingStyle = DiagnosticOptions::FormattingStyle::LLVM; for (const Arg *arg: Args.filtered(OPT_emit_macro_expansion_files)) { StringRef contents = arg->getValue();