Skip to content

Commit bf6380c

Browse files
committed
[Driver] Don't pass -ffile-compilation-dir through to cc1
This is a driver only flag so it has to be expanded when invoking cc1. Differential Revision: https://reviews.llvm.org/D97528
1 parent a3beae6 commit bf6380c

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,11 @@ static void addDebugCompDirArg(const ArgList &Args, ArgStringList &CmdArgs,
620620
const llvm::vfs::FileSystem &VFS) {
621621
if (Arg *A = Args.getLastArg(options::OPT_ffile_compilation_dir_EQ,
622622
options::OPT_fdebug_compilation_dir_EQ)) {
623-
A->render(Args, CmdArgs);
623+
if (A->getOption().matches(options::OPT_ffile_compilation_dir_EQ))
624+
CmdArgs.push_back(Args.MakeArgString(Twine("-fdebug-compilation-dir=") +
625+
A->getValue()));
626+
else
627+
A->render(Args, CmdArgs);
624628
} else if (llvm::ErrorOr<std::string> CWD =
625629
VFS.getCurrentWorkingDirectory()) {
626630
CmdArgs.push_back(Args.MakeArgString("-fdebug-compilation-dir=" + *CWD));
@@ -862,10 +866,14 @@ static void addPGOAndCoverageFlags(const ToolChain &TC, Compilation &C,
862866

863867
if (Arg *A = Args.getLastArg(options::OPT_ffile_compilation_dir_EQ,
864868
options::OPT_fcoverage_compilation_dir_EQ)) {
865-
A->render(Args, CmdArgs);
869+
if (A->getOption().matches(options::OPT_ffile_compilation_dir_EQ))
870+
CmdArgs.push_back(Args.MakeArgString(
871+
Twine("-fcoverage-compilation-dir=") + A->getValue()));
872+
else
873+
A->render(Args, CmdArgs);
866874
} else if (llvm::ErrorOr<std::string> CWD =
867875
D.getVFS().getCurrentWorkingDirectory()) {
868-
Args.MakeArgString("-fcoverage-compilation-dir=" + *CWD);
876+
CmdArgs.push_back(Args.MakeArgString("-fcoverage-compilation-dir=" + *CWD));
869877
}
870878

871879
if (Args.hasArg(options::OPT_fprofile_exclude_files_EQ)) {

clang/test/Driver/clang_f_opts.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -504,12 +504,15 @@
504504
// RUN: %clang -### -S -fdebug-compilation-dir=. %s 2>&1 | FileCheck -check-prefix=CHECK-DEBUG-COMPILATION-DIR %s
505505
// RUN: %clang -### -fdebug-compilation-dir . -x assembler %s 2>&1 | FileCheck -check-prefix=CHECK-DEBUG-COMPILATION-DIR %s
506506
// RUN: %clang -### -fdebug-compilation-dir=. -x assembler %s 2>&1 | FileCheck -check-prefix=CHECK-DEBUG-COMPILATION-DIR %s
507-
// RUN: %clang -### -ffile-compilation-dir=. -x assembler %s 2>&1 | FileCheck -check-prefix=CHECK-FILE-COMPILATION-DIR %s
507+
// RUN: %clang -### -S -ffile-compilation-dir=. %s 2>&1 | FileCheck -check-prefix=CHECK-DEBUG-COMPILATION-DIR %s
508+
// RUN: %clang -### -ffile-compilation-dir=. -x assembler %s 2>&1 | FileCheck -check-prefixes=CHECK-DEBUG-COMPILATION-DIR %s
508509
// CHECK-DEBUG-COMPILATION-DIR: "-fdebug-compilation-dir=."
510+
// CHECK-DEBUG-COMPILATION-DIR-NOT: "-ffile-compilation-dir=."
509511

510-
// RUN: %clang -### -S -ffile-compilation-dir=. %s 2>&1 | FileCheck -check-prefix=CHECK-FILE-COMPILATION-DIR %s
511-
// RUN: %clang -### -ffile-compilation-dir=. -x assembler %s 2>&1 | FileCheck -check-prefix=CHECK-FILE-COMPILATION-DIR %s
512-
// CHECK-FILE-COMPILATION-DIR: "-ffile-compilation-dir=."
512+
// RUN: %clang -### -S -fprofile-instr-generate -fcoverage-compilation-dir=. %s 2>&1 | FileCheck -check-prefix=CHECK-COVERAGE-COMPILATION-DIR %s
513+
// RUN: %clang -### -S -fprofile-instr-generate -ffile-compilation-dir=. %s 2>&1 | FileCheck -check-prefix=CHECK-COVERAGE-COMPILATION-DIR %s
514+
// CHECK-COVERAGE-COMPILATION-DIR: "-fcoverage-compilation-dir=."
515+
// CHECK-COVERAGE-COMPILATION-DIR-NOT: "-ffile-compilation-dir=."
513516

514517
// RUN: %clang -### -S -fdiscard-value-names %s 2>&1 | FileCheck -check-prefix=CHECK-DISCARD-NAMES %s
515518
// RUN: %clang -### -S -fno-discard-value-names %s 2>&1 | FileCheck -check-prefix=CHECK-NO-DISCARD-NAMES %s

0 commit comments

Comments
 (0)