[clang] 6f79f80 - [HIP] Fix duplicate clang -cc1 options on MSVC toolchain

Yaxun Liu via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 18 11:48:27 PDT 2020


Author: Yaxun (Sam) Liu
Date: 2020-03-18T14:48:04-04:00
New Revision: 6f79f80e6e473e1b28ee678cc11bc44efb2448a4

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

LOG: [HIP] Fix duplicate clang -cc1 options on MSVC toolchain

HIPToolChain::TranslateArgs call TranslateArgs of host toolchain with
the input args to get a list of derived args called DAL, then
go through the input args by itself and append them to DAL.

This assumes that the host toolchain should not append any unchanged
args to DAL, otherwise there will be duplicates since
HIPToolChain will append it again.

This works for GNU toolchain since it returns an empty list for DAL.

However, MSVC toolchain will append unchanged args to DAL, which
causes duplicate args.

This patch let MSVC toolchain not append unchanged args for HIP
offloading kind, which fixes this issue.

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

Added: 
    

Modified: 
    clang/lib/Driver/ToolChains/MSVC.cpp
    clang/test/Driver/hip-options.hip

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/MSVC.cpp b/clang/lib/Driver/ToolChains/MSVC.cpp
index b7dd6793efea..e0e25479bf59 100644
--- a/clang/lib/Driver/ToolChains/MSVC.cpp
+++ b/clang/lib/Driver/ToolChains/MSVC.cpp
@@ -1483,7 +1483,8 @@ static void TranslateDArg(Arg *A, llvm::opt::DerivedArgList &DAL,
 
 llvm::opt::DerivedArgList *
 MSVCToolChain::TranslateArgs(const llvm::opt::DerivedArgList &Args,
-                             StringRef BoundArch, Action::OffloadKind) const {
+                             StringRef BoundArch,
+                             Action::OffloadKind OFK) const {
   DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs());
   const OptTable &Opts = getDriver().getOpts();
 
@@ -1522,7 +1523,8 @@ MSVCToolChain::TranslateArgs(const llvm::opt::DerivedArgList &Args,
     } else if (A->getOption().matches(options::OPT_D)) {
       // Translate -Dfoo#bar into -Dfoo=bar.
       TranslateDArg(A, *DAL, Opts);
-    } else {
+    } else if (OFK != Action::OFK_HIP) {
+      // HIP Toolchain translates input args by itself.
       DAL->append(A);
     }
   }

diff  --git a/clang/test/Driver/hip-options.hip b/clang/test/Driver/hip-options.hip
index b2ad0424b306..59afa3fdb2d7 100644
--- a/clang/test/Driver/hip-options.hip
+++ b/clang/test/Driver/hip-options.hip
@@ -8,3 +8,8 @@
 //
 // CHECK: clang{{.*}}" "-cc1" {{.*}} "-fcuda-is-device"
 // CHECK-SAME: "--gpu-max-threads-per-block=1024"
+
+// RUN: %clang -### -x hip -target x86_64-pc-windows-msvc -fms-extensions \
+// RUN:   -mllvm -amdgpu-early-inline-all=true  %s 2>&1 | \
+// RUN:   FileCheck -check-prefix=MLLVM %s
+// MLLVM-NOT: "-mllvm"{{.*}}"-amdgpu-early-inline-all=true"{{.*}}"-mllvm"{{.*}}"-amdgpu-early-inline-all=true"


        


More information about the cfe-commits mailing list