[clang] bb26fa8 - [clang-scan-deps] Add support for clang-cl

Alexandre Ganea via cfe-commits cfe-commits at lists.llvm.org
Sat Apr 17 11:23:05 PDT 2021


Author: Sylvain Audi
Date: 2021-04-17T14:22:51-04:00
New Revision: bb26fa8c286bf524ed9235c3e293ad22ecf3e984

URL: https://github.com/llvm/llvm-project/commit/bb26fa8c286bf524ed9235c3e293ad22ecf3e984
DIFF: https://github.com/llvm/llvm-project/commit/bb26fa8c286bf524ed9235c3e293ad22ecf3e984.diff

LOG: [clang-scan-deps] Add support for clang-cl

clang-scan-deps contains some command line parsing and modifications.
This patch adds support for clang-cl command options.

Differential Revision: https://reviews.llvm.org/D92191

Added: 
    clang/test/ClangScanDeps/Inputs/modules_cdb_clangcl.json
    clang/test/ClangScanDeps/Inputs/regular_cdb_clangcl.json

Modified: 
    clang/test/ClangScanDeps/Inputs/has_include_if_elif.json
    clang/test/ClangScanDeps/Inputs/header_stat_before_open_cdb.json
    clang/test/ClangScanDeps/Inputs/headerwithdirname.json
    clang/test/ClangScanDeps/Inputs/headerwithdirnamefollowedbyinclude.json
    clang/test/ClangScanDeps/Inputs/no-werror.json
    clang/test/ClangScanDeps/Inputs/static-analyzer-cdb.json
    clang/test/ClangScanDeps/Inputs/strip_diag_serialize.json
    clang/test/ClangScanDeps/Inputs/target-filename-cdb.json
    clang/test/ClangScanDeps/Inputs/vfsoverlay_cdb.json
    clang/test/ClangScanDeps/error.cpp
    clang/test/ClangScanDeps/has_include_if_elif.cpp
    clang/test/ClangScanDeps/header_stat_before_open.m
    clang/test/ClangScanDeps/headerwithdirname.cpp
    clang/test/ClangScanDeps/headerwithdirnamefollowedbyinclude.cpp
    clang/test/ClangScanDeps/modules-full.cpp
    clang/test/ClangScanDeps/modules.cpp
    clang/test/ClangScanDeps/no-werror.cpp
    clang/test/ClangScanDeps/regular_cdb.cpp
    clang/test/ClangScanDeps/static-analyzer.c
    clang/test/ClangScanDeps/strip_diag_serialize.cpp
    clang/test/ClangScanDeps/target-filename.cpp
    clang/test/ClangScanDeps/vfsoverlay.cpp
    clang/tools/clang-scan-deps/ClangScanDeps.cpp

Removed: 
    


################################################################################
diff  --git a/clang/test/ClangScanDeps/Inputs/has_include_if_elif.json b/clang/test/ClangScanDeps/Inputs/has_include_if_elif.json
index 36ca006b03297..8fcc7ea34a9bc 100644
--- a/clang/test/ClangScanDeps/Inputs/has_include_if_elif.json
+++ b/clang/test/ClangScanDeps/Inputs/has_include_if_elif.json
@@ -3,5 +3,10 @@
   "directory": "DIR",
   "command": "clang -E DIR/has_include_if_elif2.cpp -IInputs",
   "file": "DIR/has_include_if_elif2.cpp"
+},
+{
+  "directory": "DIR",
+  "command": "clang-cl /E /IInputs -- DIR/has_include_if_elif2_clangcl.cpp",
+  "file": "DIR/has_include_if_elif2_clangcl.cpp"
 }
 ]

diff  --git a/clang/test/ClangScanDeps/Inputs/header_stat_before_open_cdb.json b/clang/test/ClangScanDeps/Inputs/header_stat_before_open_cdb.json
index c5f027e9fd28a..b99b541b12986 100644
--- a/clang/test/ClangScanDeps/Inputs/header_stat_before_open_cdb.json
+++ b/clang/test/ClangScanDeps/Inputs/header_stat_before_open_cdb.json
@@ -3,5 +3,10 @@
   "directory": "DIR",
   "command": "clang -E DIR/header_stat_before_open_input.m -iframework Inputs/frameworks",
   "file": "DIR/header_stat_before_open_input.m"
+},
+{
+  "directory": "DIR",
+  "command": "clang-cl /E -Xclang -iframework -Xclang Inputs/frameworks -- DIR/header_stat_before_open_input_clangcl.m",
+  "file": "DIR/header_stat_before_open_input_clangcl.m"
 }
 ]

diff  --git a/clang/test/ClangScanDeps/Inputs/headerwithdirname.json b/clang/test/ClangScanDeps/Inputs/headerwithdirname.json
index 2ae561935bec3..ac12c92308fda 100644
--- a/clang/test/ClangScanDeps/Inputs/headerwithdirname.json
+++ b/clang/test/ClangScanDeps/Inputs/headerwithdirname.json
@@ -3,5 +3,10 @@
       "directory": "DIR",
       "command": "clang -c -IDIR -IDIR/foodir -IInputs DIR/headerwithdirname_input.cpp",
       "file": "DIR/headerwithdirname_input.cpp"
+    },
+    {
+      "directory": "DIR",
+      "command": "clang-cl /c /IDIR /IDIR/foodir -IInputs -- DIR/headerwithdirname_input_clangcl.cpp",
+      "file": "DIR/headerwithdirname_input_clangcl.cpp"
     }
 ]

diff  --git a/clang/test/ClangScanDeps/Inputs/headerwithdirnamefollowedbyinclude.json b/clang/test/ClangScanDeps/Inputs/headerwithdirnamefollowedbyinclude.json
index de7759d0b110c..1886328a9c3e9 100644
--- a/clang/test/ClangScanDeps/Inputs/headerwithdirnamefollowedbyinclude.json
+++ b/clang/test/ClangScanDeps/Inputs/headerwithdirnamefollowedbyinclude.json
@@ -3,5 +3,10 @@
       "directory": "DIR",
       "command": "clang -c -IDIR -IInputs DIR/headerwithdirname_input.cpp",
       "file": "DIR/headerwithdirname_input.cpp"
+    },
+    {
+      "directory": "DIR",
+      "command": "clang-cl /c /IDIR /IInputs -- DIR/headerwithdirname_input_clangcl.cpp",
+      "file": "DIR/headerwithdirname_input_clangcl.cpp"
     }
 ]

diff  --git a/clang/test/ClangScanDeps/Inputs/modules_cdb_clangcl.json b/clang/test/ClangScanDeps/Inputs/modules_cdb_clangcl.json
new file mode 100644
index 0000000000000..a1f12867c45d5
--- /dev/null
+++ b/clang/test/ClangScanDeps/Inputs/modules_cdb_clangcl.json
@@ -0,0 +1,22 @@
+[
+{
+  "directory": "DIR",
+  "command": "clang-cl /E /IInputs /D INCLUDE_HEADER2 /clang:-MD /clang:-MF /clang:DIR/modules_cdb2_clangcl.d /clang:-fmodules /clang:-fcxx-modules /clang:-fmodules-cache-path=DIR/module-cache_clangcl /clang:-fimplicit-modules /clang:-fimplicit-module-maps -- DIR/modules_cdb_input2.cpp",
+  "file": "DIR/modules_cdb_input2.cpp"
+},
+{
+  "directory": "DIR",
+  "command": "clang-cl /E /IInputs /clang:-fmodules /clang:-fcxx-modules /clang:-fmodules-cache-path=DIR/module-cache_clangcl /clang:-fimplicit-modules /clang:-fimplicit-module-maps -- DIR/modules_cdb_input.cpp",
+  "file": "DIR/modules_cdb_input.cpp"
+},
+{
+  "directory": "DIR",
+  "command": "clang-cl /E /IInputs /clang:-fmodules /clang:-fcxx-modules /clang:-fmodules-cache-path=DIR/module-cache_clangcl /clang:-fimplicit-modules /clang:-fimplicit-module-maps -o a.o -- DIR/modules_cdb_input.cpp",
+  "file": "DIR/modules_cdb_input.cpp"
+},
+{
+  "directory": "DIR",
+  "command": "clang-cl /E /IInputs /clang:-fmodules /clang:-fcxx-modules /clang:-fmodules-cache-path=DIR/module-cache_clangcl /clang:-fimplicit-modules /clang:-fimplicit-module-maps -o b.o -- DIR/modules_cdb_input.cpp",
+  "file": "DIR/modules_cdb_input.cpp"
+}
+]

diff  --git a/clang/test/ClangScanDeps/Inputs/no-werror.json b/clang/test/ClangScanDeps/Inputs/no-werror.json
index 2d1f46cf3af29..7438b670e8535 100644
--- a/clang/test/ClangScanDeps/Inputs/no-werror.json
+++ b/clang/test/ClangScanDeps/Inputs/no-werror.json
@@ -3,5 +3,10 @@
   "directory": "DIR",
   "command": "clang -E DIR/no-werror_input.cpp -IInputs -std=c++17 -Weverything -Werror",
   "file": "DIR/no-werror.cpp"
+},
+{
+  "directory": "DIR",
+  "command": "clang-cl /E /IInputs /std:c++17 -Weverything -Werror -- DIR/no-werror_input_clangcl.cpp",
+  "file": "DIR/no-werror_clangcl.cpp"
 }
 ]

diff  --git a/clang/test/ClangScanDeps/Inputs/regular_cdb_clangcl.json b/clang/test/ClangScanDeps/Inputs/regular_cdb_clangcl.json
new file mode 100644
index 0000000000000..bdb84bc9172fb
--- /dev/null
+++ b/clang/test/ClangScanDeps/Inputs/regular_cdb_clangcl.json
@@ -0,0 +1,17 @@
+[
+{
+  "directory": "DIR",
+  "command": "clang --driver-mode=cl /E /IInputs /D INCLUDE_HEADER2 /clang:-MD /clang:-MF /clang:DIR/regular_cdb2_clangcl.d -- DIR/regular_cdb_input2.cpp",
+  "file": "DIR/regular_cdb_input2.cpp"
+},
+{
+  "directory": "DIR",
+  "command": "clang-cl /E /IInputs -- DIR/regular_cdb_input.cpp",
+  "file": "DIR/regular_cdb_input.cpp"
+},
+{
+  "directory": "DIR",
+  "command": "clang-cl /E /IInputs /Foadena.o -- DIR/regular_cdb_input.cpp",
+  "file": "DIR/regular_cdb_input.cpp"
+}
+]

diff  --git a/clang/test/ClangScanDeps/Inputs/static-analyzer-cdb.json b/clang/test/ClangScanDeps/Inputs/static-analyzer-cdb.json
index a466d87afaa43..a375f457aecb8 100644
--- a/clang/test/ClangScanDeps/Inputs/static-analyzer-cdb.json
+++ b/clang/test/ClangScanDeps/Inputs/static-analyzer-cdb.json
@@ -1,7 +1,12 @@
 [
 {
   "directory": "DIR",
-  "command": "clang --analyze DIR/static-analyzer.c",
-  "file": "DIR/static-analyzer.c"
+  "command": "clang --analyze DIR/static-analyzer_clang.c",
+  "file": "DIR/static-analyzer_clang.c"
+},
+{
+  "directory": "DIR",
+  "command": "clang-cl --analyze -- DIR/static-analyzer_clangcl.c",
+  "file": "DIR/static-analyzer_clangcl.c"
 }
 ]

diff  --git a/clang/test/ClangScanDeps/Inputs/strip_diag_serialize.json b/clang/test/ClangScanDeps/Inputs/strip_diag_serialize.json
index a774d95a3b023..7af1acdc378ad 100644
--- a/clang/test/ClangScanDeps/Inputs/strip_diag_serialize.json
+++ b/clang/test/ClangScanDeps/Inputs/strip_diag_serialize.json
@@ -3,5 +3,10 @@
   "directory": "DIR",
   "command": "clang -E -fsyntax-only DIR/strip_diag_serialize_input.cpp --serialize-diagnostics /does/not/exist",
   "file": "DIR/strip_diag_serialize_input.cpp"
+},
+{
+  "directory": "DIR",
+  "command": "clang-cl /E --serialize-diagnostics A:/does/not/exist -- DIR/strip_diag_serialize_input_clangcl.cpp",
+  "file": "DIR/strip_diag_serialize_input_clangcl.cpp"
 }
 ]

diff  --git a/clang/test/ClangScanDeps/Inputs/target-filename-cdb.json b/clang/test/ClangScanDeps/Inputs/target-filename-cdb.json
index af2e43e4e171e..90a3c81e57f43 100644
--- a/clang/test/ClangScanDeps/Inputs/target-filename-cdb.json
+++ b/clang/test/ClangScanDeps/Inputs/target-filename-cdb.json
@@ -18,5 +18,50 @@
   "directory": "DIR",
   "command": "clang -E DIR/target-filename_input.cpp -o first.o -o last.o",
   "file": "DIR/target-filename_input.cpp"
+},
+{
+  "directory": "DIR",
+  "command": "clang-cl /E -- DIR/target-filename_input.cpp",
+  "file": "DIR/target-filename_input.cpp"
+},
+{
+  "directory": "DIR",
+  "command": "clang-cl /E -o clangcl-a.o -- DIR/target-filename_input.cpp",
+  "file": "DIR/target-filename_input.cpp"
+},
+{
+  "directory": "DIR",
+  "command": "clang-cl /E -oclangcl-b.o -- DIR/target-filename_input.cpp",
+  "file": "DIR/target-filename_input.cpp"
+},
+{
+  "directory": "DIR",
+  "command": "clang-cl /E /o clangcl-c.o -- DIR/target-filename_input.cpp",
+  "file": "DIR/target-filename_input.cpp"
+},
+{
+  "directory": "DIR",
+  "command": "clang-cl /E /oclangcl-d.o -- DIR/target-filename_input.cpp",
+  "file": "DIR/target-filename_input.cpp"
+},
+{
+  "directory": "DIR",
+  "command": "clang-cl /E /Foclangcl-e.o -- DIR/target-filename_input.cpp",
+  "file": "DIR/target-filename_input.cpp"
+},
+{
+  "directory": "DIR",
+  "command": "clang-cl /E -o clangcl-firstf.o -o clangcl-lastf.o -- DIR/target-filename_input.cpp",
+  "file": "DIR/target-filename_input.cpp"
+},
+{
+  "directory": "DIR",
+  "command": "clang-cl /E /oclangcl-firstg.o /Foclangcl-lastg.o -- DIR/target-filename_input.cpp",
+  "file": "DIR/target-filename_input.cpp"
+},
+{
+  "directory": "DIR",
+  "command": "clang-cl /E /Foclangcl-firsth.o -o clangcl-midh.o /oclangcl-lasth.o -- DIR/target-filename_input.cpp",
+  "file": "DIR/target-filename_input.cpp"
 }
 ]

diff  --git a/clang/test/ClangScanDeps/Inputs/vfsoverlay_cdb.json b/clang/test/ClangScanDeps/Inputs/vfsoverlay_cdb.json
index 779203bac674b..1b501fa7af417 100644
--- a/clang/test/ClangScanDeps/Inputs/vfsoverlay_cdb.json
+++ b/clang/test/ClangScanDeps/Inputs/vfsoverlay_cdb.json
@@ -3,5 +3,10 @@
   "directory": "DIR",
   "command": "clang -E DIR/vfsoverlay_input.cpp -IInputs -ivfsoverlay DIR/vfsoverlay.yaml",
   "file": "DIR/vfsoverlay_input.cpp"
+},
+{
+  "directory": "DIR",
+  "command": "clang-cl /E /IInputs -Xclang -ivfsoverlay -Xclang DIR/vfsoverlay.yaml -- DIR/vfsoverlay_input_clangcl.cpp",
+  "file": "DIR/vfsoverlay_input_clangcl.cpp"
 }
 ]

diff  --git a/clang/test/ClangScanDeps/error.cpp b/clang/test/ClangScanDeps/error.cpp
index e4e052527890c..e18bf302af26f 100644
--- a/clang/test/ClangScanDeps/error.cpp
+++ b/clang/test/ClangScanDeps/error.cpp
@@ -3,11 +3,16 @@
 // RUN: mkdir -p %t.dir
 // RUN: cp %s %t.dir/regular_cdb_input.cpp
 // RUN: sed -e "s|DIR|%/t.dir|g" %S/Inputs/regular_cdb.json > %t.cdb
+// RUN: sed -e "s|DIR|%/t.dir|g" %S/Inputs/regular_cdb_clangcl.json > %t_clangcl.cdb
 //
 // RUN: not clang-scan-deps -compilation-database %t.cdb -j 1 2>%t.dir/errs
 // RUN: echo EOF >> %t.dir/errs
 // RUN: FileCheck %s --input-file %t.dir/errs
 
+// RUN: not clang-scan-deps -compilation-database %t_clangcl.cdb -j 1 2>%t.dir/errs_clangcl
+// RUN: echo EOF >> %t.dir/errs_clangcl
+// RUN: FileCheck %s --input-file %t.dir/errs_clangcl
+
 #include "missing.h"
 
 // CHECK: Error while scanning dependencies

diff  --git a/clang/test/ClangScanDeps/has_include_if_elif.cpp b/clang/test/ClangScanDeps/has_include_if_elif.cpp
index dd56ecac69dbd..17eda40c16629 100644
--- a/clang/test/ClangScanDeps/has_include_if_elif.cpp
+++ b/clang/test/ClangScanDeps/has_include_if_elif.cpp
@@ -2,6 +2,7 @@
 // RUN: rm -rf %t.cdb
 // RUN: mkdir -p %t.dir
 // RUN: cp %s %t.dir/has_include_if_elif2.cpp
+// RUN: cp %s %t.dir/has_include_if_elif2_clangcl.cpp
 // RUN: mkdir %t.dir/Inputs
 // RUN: cp %S/Inputs/header.h %t.dir/Inputs/header.h
 // RUN: cp %S/Inputs/header.h %t.dir/Inputs/header2.h
@@ -36,3 +37,9 @@
 // CHECK-NEXT: Inputs{{/|\\}}header2.h
 // CHECK-NEXT: Inputs{{/|\\}}header3.h
 // CHECK-NEXT: Inputs{{/|\\}}header4.h
+
+// CHECK: has_include_if_elif2_clangcl.cpp
+// CHECK-NEXT: Inputs{{/|\\}}header.h
+// CHECK-NEXT: Inputs{{/|\\}}header2.h
+// CHECK-NEXT: Inputs{{/|\\}}header3.h
+// CHECK-NEXT: Inputs{{/|\\}}header4.h

diff  --git a/clang/test/ClangScanDeps/header_stat_before_open.m b/clang/test/ClangScanDeps/header_stat_before_open.m
index f9f7d240f2c11..ce6f58f434aed 100644
--- a/clang/test/ClangScanDeps/header_stat_before_open.m
+++ b/clang/test/ClangScanDeps/header_stat_before_open.m
@@ -2,6 +2,7 @@
 // RUN: rm -rf %t.cdb
 // RUN: mkdir -p %t.dir
 // RUN: cp %s %t.dir/header_stat_before_open_input.m
+// RUN: cp %s %t.dir/header_stat_before_open_input_clangcl.m
 // RUN: mkdir %t.dir/Inputs
 // RUN: cp -R %S/Inputs/frameworks %t.dir/Inputs/frameworks
 // RUN: sed -e "s|DIR|%/t.dir|g" %S/Inputs/header_stat_before_open_cdb.json > %t.cdb
@@ -16,3 +17,8 @@
 // CHECK-NEXT: header_stat_before_open_input.m
 // CHECK-NEXT: Inputs{{/|\\}}frameworks{{/|\\}}Framework.framework{{/|\\}}Headers{{/|\\}}Framework.h
 // CHECK-NEXT: Inputs{{/|\\}}frameworks{{/|\\}}Framework.framework{{/|\\}}PrivateHeaders{{/|\\}}PrivateHeader.h
+
+// CHECK: header_stat_before_open_input_clangcl.o
+// CHECK-NEXT: header_stat_before_open_input_clangcl.m
+// CHECK-NEXT: Inputs{{/|\\}}frameworks{{/|\\}}Framework.framework{{/|\\}}Headers{{/|\\}}Framework.h
+// CHECK-NEXT: Inputs{{/|\\}}frameworks{{/|\\}}Framework.framework{{/|\\}}PrivateHeaders{{/|\\}}PrivateHeader.h

diff  --git a/clang/test/ClangScanDeps/headerwithdirname.cpp b/clang/test/ClangScanDeps/headerwithdirname.cpp
index b0f60333aa4c3..b6c7f796e90e0 100644
--- a/clang/test/ClangScanDeps/headerwithdirname.cpp
+++ b/clang/test/ClangScanDeps/headerwithdirname.cpp
@@ -4,6 +4,7 @@
 // RUN: mkdir -p %t.dir
 // RUN: mkdir -p %t.dir/foodir
 // RUN: cp %s %t.dir/headerwithdirname_input.cpp
+// RUN: cp %s %t.dir/headerwithdirname_input_clangcl.cpp
 // RUN: mkdir %t.dir/Inputs
 // RUN: cp %S/Inputs/foodir %t.dir/Inputs/foodir
 // RUN: sed -e "s|DIR|%/t.dir|g" %S/Inputs/headerwithdirname.json > %t.cdb
@@ -15,3 +16,7 @@
 // CHECK: headerwithdirname_input.o
 // CHECK-NEXT: headerwithdirname_input.cpp
 // CHECK-NEXT: Inputs{{/|\\}}foodir
+
+// CHECK: headerwithdirname_input_clangcl.o
+// CHECK-NEXT: headerwithdirname_input_clangcl.cpp
+// CHECK-NEXT: Inputs{{/|\\}}foodir

diff  --git a/clang/test/ClangScanDeps/headerwithdirnamefollowedbyinclude.cpp b/clang/test/ClangScanDeps/headerwithdirnamefollowedbyinclude.cpp
index e8e8a69e82e26..1f9133dc74e8f 100644
--- a/clang/test/ClangScanDeps/headerwithdirnamefollowedbyinclude.cpp
+++ b/clang/test/ClangScanDeps/headerwithdirnamefollowedbyinclude.cpp
@@ -7,6 +7,7 @@
 
 // RUN: cp %S/Inputs/header.h %t.dir/foodir/foodirheader.h
 // RUN: cp %s %t.dir/headerwithdirname_input.cpp
+// RUN: cp %s %t.dir/headerwithdirname_input_clangcl.cpp
 // RUN: mkdir %t.dir/Inputs
 // RUN: cp %S/Inputs/foodir %t.dir/Inputs/foodir
 // RUN: sed -e "s|DIR|%/t.dir|g" %S/Inputs/headerwithdirnamefollowedbyinclude.json > %t.cdb
@@ -19,3 +20,7 @@
 // CHECK: headerwithdirname_input.o
 // CHECK-NEXT: headerwithdirname_input.cpp
 // CHECK-NEXT: Inputs{{/|\\}}foodir
+
+// CHECK: headerwithdirname_input_clangcl.o
+// CHECK-NEXT: headerwithdirname_input_clangcl.cpp
+// CHECK-NEXT: Inputs{{/|\\}}foodir

diff  --git a/clang/test/ClangScanDeps/modules-full.cpp b/clang/test/ClangScanDeps/modules-full.cpp
index 1e6a740c27392..db2549670392f 100644
--- a/clang/test/ClangScanDeps/modules-full.cpp
+++ b/clang/test/ClangScanDeps/modules-full.cpp
@@ -8,12 +8,18 @@
 // RUN: cp %S/Inputs/header2.h %t.dir/Inputs/header2.h
 // RUN: cp %S/Inputs/module.modulemap %t.dir/Inputs/module.modulemap
 // RUN: sed -e "s|DIR|%/t.dir|g" %S/Inputs/modules_cdb.json > %t.cdb
+// RUN: sed -e "s|DIR|%/t.dir|g" %S/Inputs/modules_cdb_clangcl.json > %t_clangcl.cdb
 //
 // RUN: echo %t.dir > %t.result
 // RUN: clang-scan-deps -compilation-database %t.cdb -j 4 -full-command-line \
 // RUN:   -mode preprocess-minimized-sources -format experimental-full >> %t.result
 // RUN: cat %t.result | sed 's/\\/\//g' | FileCheck --check-prefixes=CHECK %s
 
+// RUN: echo %t.dir > %t_clangcl.result
+// RUN: clang-scan-deps -compilation-database %t_clangcl.cdb -j 4 -full-command-line \
+// RUN:   -mode preprocess-minimized-sources -format experimental-full >> %t_clangcl.result
+// RUN: cat %t_clangcl.result | sed 's/\\/\//g' | FileCheck --check-prefixes=CHECK %s
+
 // FIXME: Backslash issues.
 // XFAIL: system-windows
 
@@ -33,7 +39,7 @@
 // CHECK-NEXT:       "command-line": [
 // CHECK-NEXT:         "-fno-implicit-modules",
 // CHECK-NEXT:         "-fno-implicit-module-maps",
-// CHECK-NEXT:         "-fmodule-file=[[PREFIX]]/module-cache/[[CONTEXT_HASH_H1]]/header2-{{[A-Z0-9]+}}.pcm",
+// CHECK-NEXT:         "-fmodule-file=[[PREFIX]]/module-cache{{(_clangcl)?}}/[[CONTEXT_HASH_H1]]/header2-{{[A-Z0-9]+}}.pcm",
 // CHECK-NEXT:         "-fmodule-map-file=[[PREFIX]]/Inputs/module.modulemap"
 // CHECK-NEXT:       ],
 // CHECK-NEXT:       "context-hash": "[[CONTEXT_HASH_H1]]",
@@ -84,7 +90,7 @@
 // CHECK-NEXT:       "command-line": [
 // CHECK-NEXT:         "-fno-implicit-modules",
 // CHECK-NEXT:         "-fno-implicit-module-maps",
-// CHECK-NEXT:         "-fmodule-file=[[PREFIX]]/module-cache/[[CONTEXT_HASH_H2]]/header1-{{[A-Z0-9]+}}.pcm",
+// CHECK-NEXT:         "-fmodule-file=[[PREFIX]]/module-cache{{(_clangcl)?}}/[[CONTEXT_HASH_H2]]/header1-{{[A-Z0-9]+}}.pcm",
 // CHECK-NEXT:         "-fmodule-map-file=[[PREFIX]]/Inputs/module.modulemap"
 // CHECK-NEXT:       ],
 // CHECK-NEXT:       "file-deps": [
@@ -103,7 +109,7 @@
 // CHECK-NEXT:       "command-line": [
 // CHECK-NEXT:         "-fno-implicit-modules",
 // CHECK-NEXT:         "-fno-implicit-module-maps",
-// CHECK-NEXT:         "-fmodule-file=[[PREFIX]]/module-cache/[[CONTEXT_HASH_H2]]/header1-{{[A-Z0-9]+}}.pcm",
+// CHECK-NEXT:         "-fmodule-file=[[PREFIX]]/module-cache{{(_clangcl)?}}/[[CONTEXT_HASH_H2]]/header1-{{[A-Z0-9]+}}.pcm",
 // CHECK-NEXT:         "-fmodule-map-file=[[PREFIX]]/Inputs/module.modulemap"
 // CHECK-NEXT:       ],
 // CHECK-NEXT:       "file-deps": [
@@ -122,7 +128,7 @@
 // CHECK-NEXT:       "command-line": [
 // CHECK-NEXT:         "-fno-implicit-modules",
 // CHECK-NEXT:         "-fno-implicit-module-maps",
-// CHECK-NEXT:         "-fmodule-file=[[PREFIX]]/module-cache/[[CONTEXT_HASH_H2]]/header1-{{[A-Z0-9]+}}.pcm",
+// CHECK-NEXT:         "-fmodule-file=[[PREFIX]]/module-cache{{(_clangcl)?}}/[[CONTEXT_HASH_H2]]/header1-{{[A-Z0-9]+}}.pcm",
 // CHECK-NEXT:         "-fmodule-map-file=[[PREFIX]]/Inputs/module.modulemap"
 // CHECK-NEXT:       ],
 // CHECK-NEXT:       "file-deps": [
@@ -141,9 +147,9 @@
 // CHECK-NEXT:       "command-line": [
 // CHECK-NEXT:         "-fno-implicit-modules",
 // CHECK-NEXT:         "-fno-implicit-module-maps",
-// CHECK-NEXT:         "-fmodule-file=[[PREFIX]]/module-cache/[[CONTEXT_HASH_H1]]/header2-{{[A-Z0-9]+}}.pcm",
+// CHECK-NEXT:         "-fmodule-file=[[PREFIX]]/module-cache{{(_clangcl)?}}/[[CONTEXT_HASH_H1]]/header2-{{[A-Z0-9]+}}.pcm",
 // CHECK-NEXT:         "-fmodule-map-file=[[PREFIX]]/Inputs/module.modulemap",
-// CHECK-NEXT:         "-fmodule-file=[[PREFIX]]/module-cache/[[CONTEXT_HASH_H1]]/header1-{{[A-Z0-9]+}}.pcm",
+// CHECK-NEXT:         "-fmodule-file=[[PREFIX]]/module-cache{{(_clangcl)?}}/[[CONTEXT_HASH_H1]]/header1-{{[A-Z0-9]+}}.pcm",
 // CHECK-NEXT:         "-fmodule-map-file=[[PREFIX]]/Inputs/module.modulemap"
 // CHECK-NEXT:       ],
 // CHECK-NEXT:       "file-deps": [

diff  --git a/clang/test/ClangScanDeps/modules.cpp b/clang/test/ClangScanDeps/modules.cpp
index 599fcd1b43536..f0d97dc0c5c22 100644
--- a/clang/test/ClangScanDeps/modules.cpp
+++ b/clang/test/ClangScanDeps/modules.cpp
@@ -1,6 +1,8 @@
 // RUN: rm -rf %t.dir
 // RUN: rm -rf %t.cdb
+// RUN: rm -rf %t_clangcl.cdb
 // RUN: rm -rf %t.module-cache
+// RUN: rm -rf %t.module-cache_clangcl
 // RUN: mkdir -p %t.dir
 // RUN: cp %s %t.dir/modules_cdb_input.cpp
 // RUN: cp %s %t.dir/modules_cdb_input2.cpp
@@ -9,9 +11,12 @@
 // RUN: cp %S/Inputs/header2.h %t.dir/Inputs/header2.h
 // RUN: cp %S/Inputs/module.modulemap %t.dir/Inputs/module.modulemap
 // RUN: sed -e "s|DIR|%/t.dir|g" %S/Inputs/modules_cdb.json > %t.cdb
+// RUN: sed -e "s|DIR|%/t.dir|g" %S/Inputs/modules_cdb_clangcl.json > %t_clangcl.cdb
 //
 // RUN: clang-scan-deps -compilation-database %t.cdb -j 1 -mode preprocess-minimized-sources | \
 // RUN:   FileCheck --check-prefixes=CHECK1,CHECK2,CHECK2NO %s
+// RUN: clang-scan-deps -compilation-database %t_clangcl.cdb -j 1 -mode preprocess-minimized-sources | \
+// RUN:   FileCheck --check-prefixes=CHECK1,CHECK2,CHECK2NO %s
 //
 // The output order is non-deterministic when using more than one thread,
 // so check the output using two runs. Note that the 'NOT' check is not used
@@ -20,12 +25,20 @@
 //
 // RUN: clang-scan-deps -compilation-database %t.cdb -j 2 -mode preprocess-minimized-sources | \
 // RUN:   FileCheck --check-prefix=CHECK1 %s
+// RUN: clang-scan-deps -compilation-database %t_clangcl.cdb -j 2 -mode preprocess-minimized-sources | \
+// RUN:   FileCheck --check-prefix=CHECK1 %s
 // RUN: clang-scan-deps -compilation-database %t.cdb -j 2 -mode preprocess | \
 // RUN:   FileCheck --check-prefix=CHECK1 %s
+// RUN: clang-scan-deps -compilation-database %t_clangcl.cdb -j 2 -mode preprocess | \
+// RUN:   FileCheck --check-prefix=CHECK1 %s
 // RUN: clang-scan-deps -compilation-database %t.cdb -j 2 -mode preprocess-minimized-sources | \
 // RUN:   FileCheck --check-prefix=CHECK2 %s
+// RUN: clang-scan-deps -compilation-database %t_clangcl.cdb -j 2 -mode preprocess-minimized-sources | \
+// RUN:   FileCheck --check-prefix=CHECK2 %s
 // RUN: clang-scan-deps -compilation-database %t.cdb -j 2 -mode preprocess | \
 // RUN:   FileCheck --check-prefix=CHECK2 %s
+// RUN: clang-scan-deps -compilation-database %t_clangcl.cdb -j 2 -mode preprocess | \
+// RUN:   FileCheck --check-prefix=CHECK2 %s
 
 #include "header.h"
 

diff  --git a/clang/test/ClangScanDeps/no-werror.cpp b/clang/test/ClangScanDeps/no-werror.cpp
index 95407c51b3cc2..11f1b718dac54 100644
--- a/clang/test/ClangScanDeps/no-werror.cpp
+++ b/clang/test/ClangScanDeps/no-werror.cpp
@@ -2,6 +2,7 @@
 // RUN: rm -rf %t.cdb
 // RUN: mkdir -p %t.dir
 // RUN: cp %s %t.dir/no-werror_input.cpp
+// RUN: cp %s %t.dir/no-werror_input_clangcl.cpp
 // RUN: mkdir %t.dir/Inputs
 // RUN: cp %S/Inputs/sys-header.h %t.dir/Inputs/sys-header.h
 // RUN: sed -e "s|DIR|%/t.dir|g" %S/Inputs/no-werror.json > %t.cdb
@@ -14,3 +15,6 @@
 
 // CHECK: no-werror_input.cpp
 // CHECK-NEXT: Inputs{{/|\\}}sys-header.h
+
+// CHECK: no-werror_input_clangcl.cpp
+// CHECK-NEXT: Inputs{{/|\\}}sys-header.h

diff  --git a/clang/test/ClangScanDeps/regular_cdb.cpp b/clang/test/ClangScanDeps/regular_cdb.cpp
index 8fb94350e4c22..d7ba2519067e9 100644
--- a/clang/test/ClangScanDeps/regular_cdb.cpp
+++ b/clang/test/ClangScanDeps/regular_cdb.cpp
@@ -1,5 +1,6 @@
 // RUN: rm -rf %t.dir
 // RUN: rm -rf %t.cdb
+// RUN: rm -rf %t_clangcl.cdb
 // RUN: mkdir -p %t.dir
 // RUN: cp %s %t.dir/regular_cdb_input.cpp
 // RUN: cp %s %t.dir/regular_cdb_input2.cpp
@@ -7,17 +8,28 @@
 // RUN: cp %S/Inputs/header.h %t.dir/Inputs/header.h
 // RUN: cp %S/Inputs/header2.h %t.dir/Inputs/header2.h
 // RUN: sed -e "s|DIR|%/t.dir|g" %S/Inputs/regular_cdb.json > %t.cdb
+// RUN: sed -e "s|DIR|%/t.dir|g" %S/Inputs/regular_cdb_clangcl.json > %t_clangcl.cdb
 //
 // RUN: clang-scan-deps -compilation-database %t.cdb -j 1 -mode preprocess-minimized-sources | \
 // RUN:   FileCheck --check-prefixes=CHECK1,CHECK2,CHECK2NO,CHECK3 %s
+// RUN: clang-scan-deps -compilation-database %t_clangcl.cdb -j 1 -mode preprocess-minimized-sources | \
+// RUN:   FileCheck --check-prefixes=CHECK1,CHECK2,CHECK2NO,CHECK3 %s
+
 // RUN: clang-scan-deps -compilation-database %t.cdb -j 1 -mode preprocess | \
 // RUN:   FileCheck --check-prefixes=CHECK1,CHECK2,CHECK2NO,CHECK3 %s
+// RUN: clang-scan-deps -compilation-database %t_clangcl.cdb -j 1 -mode preprocess | \
+// RUN:   FileCheck --check-prefixes=CHECK1,CHECK2,CHECK2NO,CHECK3 %s
+
 // RUN: clang-scan-deps -compilation-database %t.cdb -j 1 -mode preprocess-minimized-sources \
 // RUN:   -skip-excluded-pp-ranges=0 | FileCheck --check-prefixes=CHECK1,CHECK2,CHECK2NO,CHECK3 %s
+// RUN: clang-scan-deps -compilation-database %t_clangcl.cdb -j 1 -mode preprocess-minimized-sources \
+// RUN:   -skip-excluded-pp-ranges=0 | FileCheck --check-prefixes=CHECK1,CHECK2,CHECK2NO,CHECK3 %s
 //
 // Make sure we didn't produce any dependency files!
 // RUN: not cat %t.dir/regular_cdb.d
+// RUN: not cat %t.dir/regular_cdb_clangcl.d
 // RUN: not cat %t.dir/regular_cdb2.d
+// RUN: not cat %t.dir/regular_cdb2_clangcl.d
 //
 // The output order is non-deterministic when using more than one thread,
 // so check the output using two runs. Note that the 'NOT' check is not used
@@ -26,12 +38,23 @@
 //
 // RUN: clang-scan-deps -compilation-database %t.cdb -j 2 -mode preprocess-minimized-sources | \
 // RUN:   FileCheck --check-prefix=CHECK1 %s
+// RUN: clang-scan-deps -compilation-database %t_clangcl.cdb -j 2 -mode preprocess-minimized-sources | \
+// RUN:   FileCheck --check-prefix=CHECK1 %s
+
 // RUN: clang-scan-deps -compilation-database %t.cdb -j 2 -mode preprocess | \
 // RUN:   FileCheck --check-prefix=CHECK1 %s
+// RUN: clang-scan-deps -compilation-database %t_clangcl.cdb -j 2 -mode preprocess | \
+// RUN:   FileCheck --check-prefix=CHECK1 %s
+
 // RUN: clang-scan-deps -compilation-database %t.cdb -j 2 -mode preprocess-minimized-sources | \
 // RUN:   FileCheck --check-prefix=CHECK2 %s
+// RUN: clang-scan-deps -compilation-database %t_clangcl.cdb -j 2 -mode preprocess-minimized-sources | \
+// RUN:   FileCheck --check-prefix=CHECK2 %s
+
 // RUN: clang-scan-deps -compilation-database %t.cdb -j 2 -mode preprocess | \
 // RUN:   FileCheck --check-prefix=CHECK2 %s
+// RUN: clang-scan-deps -compilation-database %t_clangcl.cdb -j 2 -mode preprocess | \
+// RUN:   FileCheck --check-prefix=CHECK2 %s
 
 #include "header.h"
 

diff  --git a/clang/test/ClangScanDeps/static-analyzer.c b/clang/test/ClangScanDeps/static-analyzer.c
index c4af9b076bb2c..8edbf3eaae20a 100644
--- a/clang/test/ClangScanDeps/static-analyzer.c
+++ b/clang/test/ClangScanDeps/static-analyzer.c
@@ -1,7 +1,9 @@
 // RUN: rm -rf %t.dir
 // RUN: rm -rf %t-cdb.json
 // RUN: mkdir -p %t.dir
-// RUN: cp %s %t.dir/static-analyzer.c
+// Change file name to avoid false positives in CHECK, since "static-analyzer.c" is found in %S.
+// RUN: cp %s %t.dir/static-analyzer_clang.c
+// RUN: cp %s %t.dir/static-analyzer_clangcl.c
 // RUN: mkdir %t.dir/Inputs
 // RUN: cp %S/Inputs/header.h %t.dir/Inputs/analyze_header_input.h
 // RUN: sed -e "s|DIR|%/t.dir|g" %S/Inputs/static-analyzer-cdb.json > %t-cdb.json
@@ -12,5 +14,8 @@
 #include "Inputs/analyze_header_input.h"
 #endif
 
-// CHECK: analyze_header_input.h
+// CHECK: static-analyzer_clang.c
+// CHECK-NEXT: analyze_header_input.h
 
+// CHECK: static-analyzer_clangcl.c
+// CHECK-NEXT: analyze_header_input.h

diff  --git a/clang/test/ClangScanDeps/strip_diag_serialize.cpp b/clang/test/ClangScanDeps/strip_diag_serialize.cpp
index ec62e75134814..d9f7588820277 100644
--- a/clang/test/ClangScanDeps/strip_diag_serialize.cpp
+++ b/clang/test/ClangScanDeps/strip_diag_serialize.cpp
@@ -2,10 +2,12 @@
 // RUN: rm -rf %t.cdb
 // RUN: mkdir -p %t.dir
 // RUN: cp %s %t.dir/strip_diag_serialize_input.cpp
+// RUN: cp %s %t.dir/strip_diag_serialize_input_clangcl.cpp
 // RUN: sed -e "s|DIR|%/t.dir|g" %S/Inputs/strip_diag_serialize.json > %t.cdb
 //
-// RUN: clang-scan-deps -compilation-database %t.cdb 2>&1 | FileCheck %s
+// RUN: clang-scan-deps -compilation-database %t.cdb -j 1 2>&1 | FileCheck %s
 // CHECK-NOT: unable to open file
 // CHECK: strip_diag_serialize_input.cpp
+// CHECK: strip_diag_serialize_input_clangcl.cpp
 
 #warning "diagnostic"

diff  --git a/clang/test/ClangScanDeps/target-filename.cpp b/clang/test/ClangScanDeps/target-filename.cpp
index c47166b21e4e3..02084ee9b372f 100644
--- a/clang/test/ClangScanDeps/target-filename.cpp
+++ b/clang/test/ClangScanDeps/target-filename.cpp
@@ -18,3 +18,30 @@
 
 // CHECK-NEXT: last.o:
 // CHECK-NEXT: target-filename_input.cpp
+
+// CHECK: target-filename_input.o:
+// CHECK-NEXT: target-filename_input.cpp
+
+// CHECK-NEXT: clangcl-a.o:
+// CHECK-NEXT: target-filename_input.cpp
+
+// CHECK-NEXT: clangcl-b.o:
+// CHECK-NEXT: target-filename_input.cpp
+
+// CHECK-NEXT: clangcl-c.o:
+// CHECK-NEXT: target-filename_input.cpp
+
+// CHECK-NEXT: clangcl-d.o:
+// CHECK-NEXT: target-filename_input.cpp
+
+// CHECK-NEXT: clangcl-e.o:
+// CHECK-NEXT: target-filename_input.cpp
+
+// CHECK-NEXT: clangcl-lastf.o:
+// CHECK-NEXT: target-filename_input.cpp
+
+// CHECK-NEXT: clangcl-lastg.o:
+// CHECK-NEXT: target-filename_input.cpp
+
+// CHECK-NEXT: clangcl-lasth.o:
+// CHECK-NEXT: target-filename_input.cpp

diff  --git a/clang/test/ClangScanDeps/vfsoverlay.cpp b/clang/test/ClangScanDeps/vfsoverlay.cpp
index 517738943ab57..b3a2b23daad71 100644
--- a/clang/test/ClangScanDeps/vfsoverlay.cpp
+++ b/clang/test/ClangScanDeps/vfsoverlay.cpp
@@ -2,6 +2,7 @@
 // RUN: rm -rf %t.cdb
 // RUN: mkdir -p %t.dir
 // RUN: cp %s %t.dir/vfsoverlay_input.cpp
+// RUN: cp %s %t.dir/vfsoverlay_input_clangcl.cpp
 // RUN: sed -e "s|DIR|%/t.dir|g" %S/Inputs/vfsoverlay.yaml > %t.dir/vfsoverlay.yaml
 // RUN: mkdir %t.dir/Inputs
 // RUN: cp %S/Inputs/header.h %t.dir/Inputs/header.h
@@ -15,3 +16,7 @@
 // CHECK: vfsoverlay_input.o
 // CHECK-NEXT: vfsoverlay_input.cpp
 // CHECK-NEXT: Inputs{{/|\\}}header.h
+
+// CHECK: vfsoverlay_input_clangcl.o
+// CHECK-NEXT: vfsoverlay_input_clangcl.cpp
+// CHECK-NEXT: Inputs{{/|\\}}header.h

diff  --git a/clang/tools/clang-scan-deps/ClangScanDeps.cpp b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
index e3ea098d8211a..baae2c615c625 100644
--- a/clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -12,6 +12,8 @@
 #include "clang/Tooling/DependencyScanning/DependencyScanningTool.h"
 #include "clang/Tooling/DependencyScanning/DependencyScanningWorker.h"
 #include "clang/Tooling/JSONCompilationDatabase.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/Twine.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/FileUtilities.h"
 #include "llvm/Support/InitLLVM.h"
@@ -49,7 +51,8 @@ class ResourceDirectoryCache {
   /// option and cache the results for reuse. \returns resource directory path
   /// associated with the given invocation command or empty string if the
   /// compiler path is NOT an absolute path.
-  StringRef findResourceDir(const tooling::CommandLineArguments &Args) {
+  StringRef findResourceDir(const tooling::CommandLineArguments &Args,
+                            bool ClangCLMode) {
     if (Args.size() < 1)
       return "";
 
@@ -65,8 +68,12 @@ class ResourceDirectoryCache {
     if (CachedResourceDir != Cache.end())
       return CachedResourceDir->second;
 
-    std::vector<StringRef> PrintResourceDirArgs{ClangBinaryName,
-                                                "-print-resource-dir"};
+    std::vector<StringRef> PrintResourceDirArgs{ClangBinaryName};
+    if (ClangCLMode)
+      PrintResourceDirArgs.push_back("/clang:-print-resource-dir");
+    else
+      PrintResourceDirArgs.push_back("-print-resource-dir");
+
     llvm::SmallString<64> OutputFile, ErrorFile;
     llvm::sys::fs::createTemporaryFile("print-resource-dir-output",
                                        "" /*no-suffix*/, OutputFile);
@@ -418,24 +425,52 @@ int main(int argc, const char **argv) {
         bool HasMQ = false;
         bool HasMD = false;
         bool HasResourceDir = false;
+        bool ClangCLMode = false;
         auto FlagsEnd = llvm::find(Args, "--");
         if (FlagsEnd != Args.begin()) {
+          ClangCLMode =
+              llvm::sys::path::stem(Args[0]).contains_lower("clang-cl") ||
+              llvm::is_contained(Args, "--driver-mode=cl");
+
           // Reverse scan, starting at the end or at the element before "--".
           auto R = llvm::make_reverse_iterator(FlagsEnd);
           for (auto I = R, E = Args.rend(); I != E; ++I) {
             StringRef Arg = *I;
-            if (LastO.empty()) {
-              if (Arg == "-o" && I != R)
-                LastO = I[-1]; // Next argument (reverse iterator)
-              else if (Arg.startswith("-o"))
-                LastO = Arg.drop_front(2).str();
+            if (ClangCLMode) {
+              if (LastO.empty()) {
+                // With clang-cl, the output obj file can be specified with
+                // "/opath", "/o path", "/Fopath", and the dash counterparts.
+                // Also, clang-cl adds ".obj" extension if none is found.
+                if ((Arg == "-o" || Arg == "/o") && I != R)
+                  LastO = I[-1]; // Next argument (reverse iterator)
+                else if (Arg.startswith("/Fo") || Arg.startswith("-Fo"))
+                  LastO = Arg.drop_front(3).str();
+                else if (Arg.startswith("/o") || Arg.startswith("-o"))
+                  LastO = Arg.drop_front(2).str();
+
+                if (!LastO.empty() && !llvm::sys::path::has_extension(LastO))
+                  LastO.append(".obj");
+              }
+              if (Arg == "/clang:-MT")
+                HasMT = true;
+              if (Arg == "/clang:-MQ")
+                HasMQ = true;
+              if (Arg == "/clang:-MD")
+                HasMD = true;
+            } else {
+              if (LastO.empty()) {
+                if (Arg == "-o" && I != R)
+                  LastO = I[-1]; // Next argument (reverse iterator)
+                else if (Arg.startswith("-o"))
+                  LastO = Arg.drop_front(2).str();
+              }
+              if (Arg == "-MT")
+                HasMT = true;
+              if (Arg == "-MQ")
+                HasMQ = true;
+              if (Arg == "-MD")
+                HasMD = true;
             }
-            if (Arg == "-MT")
-              HasMT = true;
-            if (Arg == "-MQ")
-              HasMQ = true;
-            if (Arg == "-MD")
-              HasMD = true;
             if (Arg == "-resource-dir")
               HasResourceDir = true;
           }
@@ -444,18 +479,29 @@ int main(int argc, const char **argv) {
         // -o option.
         tooling::CommandLineArguments AdjustedArgs(Args.begin(), FlagsEnd);
         AdjustedArgs.push_back("-o");
+#ifdef _WIN32
+        AdjustedArgs.push_back("nul");
+#else
         AdjustedArgs.push_back("/dev/null");
+#endif
         if (!HasMT && !HasMQ) {
-          AdjustedArgs.push_back("-M");
-          AdjustedArgs.push_back("-MT");
           // We're interested in source dependencies of an object file.
+          std::string FileNameArg;
           if (!HasMD) {
             // FIXME: We are missing the directory unless the -o value is an
             // absolute path.
-            AdjustedArgs.push_back(!LastO.empty() ? LastO
-                                                  : getObjFilePath(FileName));
+            FileNameArg = !LastO.empty() ? LastO : getObjFilePath(FileName);
+          } else {
+            FileNameArg = std::string(FileName);
+          }
+          if (ClangCLMode) {
+            AdjustedArgs.push_back("/clang:-M");
+            AdjustedArgs.push_back("/clang:-MT");
+            AdjustedArgs.push_back(Twine("/clang:", FileNameArg).str());
           } else {
-            AdjustedArgs.push_back(std::string(FileName));
+            AdjustedArgs.push_back("-M");
+            AdjustedArgs.push_back("-MT");
+            AdjustedArgs.push_back(std::move(FileNameArg));
           }
         }
         AdjustedArgs.push_back("-Xclang");
@@ -466,7 +512,7 @@ int main(int argc, const char **argv) {
 
         if (!HasResourceDir) {
           StringRef ResourceDir =
-              ResourceDirCache.findResourceDir(Args);
+              ResourceDirCache.findResourceDir(Args, ClangCLMode);
           if (!ResourceDir.empty()) {
             AdjustedArgs.push_back("-resource-dir");
             AdjustedArgs.push_back(std::string(ResourceDir));


        


More information about the cfe-commits mailing list