Skip to content

Commit faf71f2

Browse files
committed
[clang][cas] Allow clang-cache on invocations without a compilation
When using clang-cache with a build system that does not have knowledge of which invocations are for compilation vs. linking, we do not want to error when using clang-cache with a link command. E.g. a Makefile with CC="clang-cache clang" where CC is being used as both compiler and linker. In this case ignore the missing compile and disable caching. Also fix emitting command-line parsing warnings during the check. rdar://114581253
1 parent 96d276e commit faf71f2

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

clang/test/CAS/driver-cache-launcher.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,17 @@
114114

115115
// RUN: not %clang-cache 2>&1 | FileCheck %s -check-prefix=NOCOMMAND
116116
// NOCOMMAND: error: missing compiler command for clang-cache
117+
118+
// Link-only job should not attempt to cache.
119+
// RUN: touch %t.o
120+
// RUN: %clang-cache %clang -target arm64-apple-macosx12 %t.o -o %t -Wl,-ObjC -### 2>&1 | FileCheck %s -check-prefix=STATIC_LINK
121+
// STATIC_LINK-NOT: warning:
122+
// STATIC_LINK-NOT: "-cc1depscan"
123+
// STATIC_LINK: "{{[^"]*}}ld"
124+
125+
// Unused option warning should only be emitted once.
126+
// RUN: touch %t.o
127+
// RUN: %clang-cache %clang -target arm64-apple-macosx12 -fsyntax-only %s -Wl,-ObjC 2>&1 | FileCheck %s -check-prefix=UNUSED_OPT
128+
// UNUSED_OPT-NOT: warning:
129+
// UNUSED_OPT: warning: -Wl,-ObjC: 'linker' input unused
130+
// UNUSED_OPT-NOT: warning:

clang/tools/driver/CacheLauncherMode.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "CacheLauncherMode.h"
1010
#include "clang/Basic/DiagnosticCAS.h"
11+
#include "clang/Frontend/CompilerInstance.h"
1112
#include "clang/Frontend/CompilerInvocation.h"
1213
#include "clang/Frontend/TextDiagnosticPrinter.h"
1314
#include "clang/Frontend/Utils.h"
@@ -41,7 +42,10 @@ static bool shouldCacheInvocation(ArrayRef<const char *> Args,
4142
llvm::remove_if(CheckArgs, [](StringRef Arg) { return Arg == "-###"; }),
4243
CheckArgs.end());
4344
CreateInvocationOptions Opts;
44-
Opts.Diags = Diags;
45+
// Ignore diagnostic parsing diagnostics; if they are real issues they will be
46+
// seen when compiling. Just fallback to disabling caching here.
47+
Opts.Diags = CompilerInstance::createDiagnostics(new DiagnosticOptions,
48+
new IgnoringDiagConsumer);
4549
// This enables picking the first invocation in a multi-arch build.
4650
Opts.RecoverOnError = true;
4751
std::shared_ptr<CompilerInvocation> CInvok =

0 commit comments

Comments
 (0)