python3kgae updated this revision to Diff 450377.
python3kgae marked 3 inline comments as done.
python3kgae added a comment.

Rebase and fix merge conflict.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D125655/new/

https://reviews.llvm.org/D125655

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/HLSL.cpp
  clang/test/Driver/dxc_P.hlsl

Index: clang/test/Driver/dxc_P.hlsl
===================================================================
--- /dev/null
+++ clang/test/Driver/dxc_P.hlsl
@@ -0,0 +1,11 @@
+// RUN: %clang_dxc -Tlib_6_7 -P a.txt -### %s 2>&1 | FileCheck %s
+// RUN: %clang_dxc -Tlib_6_7  -Fo b.txt -P a.txt -### %s 2>&1 | FileCheck %s --check-prefix=WARNING
+
+// Make sure -P option flag which translated into "-E" + "-o" "a.txt".
+// CHECK:"-E" {{.*}} "-o" "a.txt"
+
+// Make sure got warning when -Fo and -P at same time.
+// WARNING: warning: output compiler options like -Fo ignored with Preprocess [-Woption-ignored]
+// WARNING:"-E" {{.*}} "-o" "a.txt"
+
+
Index: clang/lib/Driver/ToolChains/HLSL.cpp
===================================================================
--- clang/lib/Driver/ToolChains/HLSL.cpp
+++ clang/lib/Driver/ToolChains/HLSL.cpp
@@ -154,7 +154,6 @@
   for (Arg *A : Args) {
     if (A->getOption().getID() == options::OPT_dxil_validator_version) {
       StringRef ValVerStr = A->getValue();
-      std::string ErrorMsg;
       if (!isLegalValidatorVersion(ValVerStr, getDriver()))
         continue;
     }
@@ -173,6 +172,15 @@
       A->claim();
       continue;
     }
+    if (A->getOption().getID() == options::OPT_dxc_P) {
+      // Translate dxc_P into -E and -o.
+      DAL->AddFlagArg(nullptr, Opts.getOption(options::OPT_E));
+      // The -o part is done at clang::driver::Driver::GetNamedOutputPath.
+      A->claim();
+      if (Args.getLastArg(options::OPT_o))
+        getDriver().Diag(diag::warn_drv_dxc_ignore_output_for_preprocess);
+      continue;
+    }
     DAL->append(A);
   }
   // Add default validator version if not set.
Index: clang/lib/Driver/ToolChains/Clang.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -3515,7 +3515,9 @@
                                          options::OPT_emit_llvm,
                                          options::OPT_disable_llvm_passes,
                                          options::OPT_fnative_half_type,
-                                         options::OPT_hlsl_entrypoint};
+                                         options::OPT_hlsl_entrypoint,
+                                         options::OPT_E,
+                                         options::OPT_dxc_P};
 
   for (const auto &Arg : ForwardedArguments)
     if (const auto *A = Args.getLastArg(Arg))
Index: clang/lib/Driver/Driver.cpp
===================================================================
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -5636,6 +5636,12 @@
   }
 
   llvm::PrettyStackTraceString CrashInfo("Computing output path");
+
+  // For dxc_P,Output to user requested destination.
+  // When dxc_P is set, -Fo (which is aliased to OPT_o) will be ignored.
+  if (Arg *FinalOutput = C.getArgs().getLastArg(options::OPT_dxc_P))
+    return C.addResultFile(FinalOutput->getValue(), &JA);
+
   // Output to a user requested destination?
   if (AtTopLevel && !isa<DsymutilJobAction>(JA) && !isa<VerifyJobAction>(JA)) {
     if (Arg *FinalOutput = C.getArgs().getLastArg(options::OPT_o))
Index: clang/include/clang/Driver/Options.td
===================================================================
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -6918,3 +6918,6 @@
                      Group<dxc_Group>,
                      Flags<[DXCOption, NoXarchOption]>,
                      HelpText<"Entry point name">;
+def dxc_P : Option<["--", "/", "-"], "P", KIND_SEPARATE>,
+  Group<dxc_Group>, Flags<[DXCOption, NoXarchOption]>,
+  HelpText<"Preprocess to file, cannot used with other output options like -Fo.">;
Index: clang/include/clang/Basic/DiagnosticDriverKinds.td
===================================================================
--- clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -678,6 +678,9 @@
 def err_drv_invalid_empty_dxil_validator_version : Error<
   "invalid validator version : %0\n"
   "If validator major version is 0, minor version must also be 0.">;
+def warn_drv_dxc_ignore_output_for_preprocess : Warning<
+  "output compiler options like -Fo ignored with Preprocess">,
+  InGroup<OptionIgnored>;
 
 def warn_drv_sarif_format_unstable : Warning<
   "diagnostic formatting in SARIF mode is currently unstable">,
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to