Skip to content

Commit 495a177

Browse files
Merge pull request #72168 from cachemeifyoucan/eng/PR-124222904
[Caching] Normalize DebugInfo flags
2 parents 7652ac7 + d38caf1 commit 495a177

File tree

3 files changed

+58
-10
lines changed

3 files changed

+58
-10
lines changed

include/swift/Frontend/Frontend.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class CompilerInvocation {
156156
/// Serialize the command line arguments for emitting them
157157
/// to DWARF or CodeView and inject SDKPath if necessary.
158158
static void buildDebugFlags(std::string &Output,
159-
const ArrayRef<const char*> &Args,
159+
const llvm::opt::ArgList &Args,
160160
StringRef SDKPath,
161161
StringRef ResourceDir);
162162

lib/Frontend/CompilerInvocation.cpp

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2484,23 +2484,43 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
24842484
}
24852485

24862486
void CompilerInvocation::buildDebugFlags(std::string &Output,
2487-
const ArrayRef<const char*> &Args,
2487+
const ArgList &Args,
24882488
StringRef SDKPath,
24892489
StringRef ResourceDir) {
2490+
ArgStringList ReducedArgs;
2491+
for (auto *A : Args) {
2492+
// Do not encode cache invariant options, even for non-caching build.
2493+
// Those options do not affect compilation task thus do not need to be
2494+
// tracked.
2495+
if (A->getOption().hasFlag(options::CacheInvariant))
2496+
continue;
2497+
2498+
A->render(Args, ReducedArgs);
2499+
2500+
// If the argument is file list, the path itself is irrelevant.
2501+
if (A->getOption().hasFlag(options::ArgumentIsFileList)) {
2502+
assert(A->getValues().size() == 1 &&
2503+
A->getOption().getRenderStyle() == Option::RenderSeparateStyle &&
2504+
"filelist options all have one argument and are all Separate<>");
2505+
ReducedArgs.pop_back();
2506+
ReducedArgs.push_back("<filelist>");
2507+
}
2508+
}
2509+
24902510
// This isn't guaranteed to be the same temp directory as what the driver
24912511
// uses, but it's highly likely.
24922512
llvm::SmallString<128> TDir;
24932513
llvm::sys::path::system_temp_directory(true, TDir);
24942514

24952515
llvm::raw_string_ostream OS(Output);
2496-
interleave(Args,
2516+
interleave(ReducedArgs,
24972517
[&](const char *Argument) { PrintArg(OS, Argument, TDir.str()); },
24982518
[&] { OS << " "; });
24992519

25002520
// Inject the SDK path and resource dir if they are nonempty and missing.
25012521
bool haveSDKPath = SDKPath.empty();
25022522
bool haveResourceDir = ResourceDir.empty();
2503-
for (auto A : Args) {
2523+
for (auto A : ReducedArgs) {
25042524
StringRef Arg(A);
25052525
// FIXME: this should distinguish between key and value.
25062526
if (!haveSDKPath && Arg.equals("-sdk"))
@@ -2579,14 +2599,10 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
25792599
"unknown -g<kind> option");
25802600
}
25812601
if (Opts.DebugInfoLevel >= IRGenDebugInfoLevel::LineTables) {
2582-
if (Args.hasArg(options::OPT_debug_info_store_invocation)) {
2583-
ArgStringList RenderedArgs;
2584-
for (auto A : Args)
2585-
A->render(Args, RenderedArgs);
2602+
if (Args.hasArg(options::OPT_debug_info_store_invocation))
25862603
CompilerInvocation::buildDebugFlags(Opts.DebugFlags,
2587-
RenderedArgs, SDKPath,
2604+
Args, SDKPath,
25882605
ResourceDir);
2589-
}
25902606

25912607
if (const Arg *A = Args.getLastArg(OPT_file_compilation_dir))
25922608
Opts.DebugCompilationDir = A->getValue();

test/CAS/debuginfo_invariant.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: split-file %s %t
3+
4+
// RUN: %target-swift-frontend -scan-dependencies -module-name Test -module-cache-path %t/clang-module-cache -O -g \
5+
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -parse-stdlib \
6+
// RUN: %t/main.swift -o %t/deps.json -swift-version 5 -cache-compile-job -cas-path %t/cas
7+
8+
// RUN: %{python} %S/Inputs/GenerateExplicitModuleMap.py %t/deps.json > %t/map.json
9+
// RUN: llvm-cas --cas %t/cas --make-blob --data %t/map.json > %t/map.casid
10+
11+
// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps.json Test > %t/MyApp.cmd
12+
13+
// RUN: echo %t/main.swift > %t/inputs.FileList
14+
// RUN: %target-swift-frontend -emit-ir -o %t/main.ll -g -O \
15+
// RUN: -cache-compile-job -cas-path %t/cas -swift-version 5 \
16+
// RUN: -disable-implicit-swift-modules -swift-version 5 -enable-cross-import-overlays \
17+
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -parse-stdlib \
18+
// RUN: -module-name Test -explicit-swift-module-map-file @%t/map.casid \
19+
// RUN: -filelist %t/inputs.FileList @%t/MyApp.cmd -debug-info-store-invocation -Rcache-compile-job
20+
21+
// RUN: %FileCheck %s --input-file=%t/main.ll
22+
23+
// CHECK: distinct !DICompileUnit(language: DW_LANG_Swift,
24+
// CHECK-SAME: flags:
25+
// CHECK-SAME: -filelist
26+
27+
/// option that should not be encoded
28+
// CHECK-NOT: -Rcache-compile-job
29+
// CHECK-NOT: inputs.FileList
30+
31+
//--- main.swift
32+
public func test() {}

0 commit comments

Comments
 (0)